Formats: speed up GFX10 tiled texture copies up to 2.4x #2736
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2736
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2736"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@brainbudt on GitHub · 2026-11-25 19:22 UTC · original
brainbudt:perf/texture-detile→main· +291 −64 · 1 files · 1 commits · openLayout::detileandLayout::tilepreviously inspected every column to build a run list and visited each row and depth slice independently, revisiting tiled blocks on adjacent rows and volume slices.What changed
detile_throughputbenchmark and extend copy tests against per-elementLayout::offsetacross all addressable swizzles, element sizes, padding, odd dimensions, mip tails, array slices, 3D slabs, and error precedence.Benchmark (
detile_throughput, median of 5 release runs on Apple M4, MB/s)64KB_D64KB_S64KB_D64KB_D4KB_S64KB_D4KB_SVerification
cargo test --release -p victory-formats texture(17 tests) andcargo clippy -p victory-formats --all-targets -- -D warningspassed.cargo test --release -p victory-formats detile_throughput -- --ignored --nocapture.Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
@fuzeofficlal on GitHub · 2026-11-25 20:10 UTC · original
Reviewed and benchmarked
d3310473on Windows 11 againstmain(13f91ca).Code review
unsafe, and all bounds/overflow checks (mip/slice/3Dslice == 0,addressable(),checked_mul/checked_add,row_pitch/depth_pitch,tiled_len/linear_len) run inwalkbefore writing any output bytes (covered bycopy_errors_precede_writes_in_both_directions).walk_runs::<N>specializations against all 15MICROentries (Thin S/Thin D/Thick 3D× 1/2/4/8/16B): contiguous x-run widths always fall in{4, 8, 16, 32}bytes, everyBLOCK_256_2D/BLOCK_256_3Dentry has evenmicro[1]sotail.yis always even for therows = 2paired path (N < 32), andcolumns+ trailinglast/copy.spanhandle empty columns, single-row mips, odd widths, and unaligned pitches without out-of-bounds slicing.Verification & same-machine
--releasebenchmark (rustc 1.98.1MSVC)cargo test -p victory-formats --locked: 39 passed, 0 failed, 6 ignored (byte-exact round-trip vsLayout::offsetacrossLINEAR/256B/4KB/64KBS/D, 1..16B bpp, odd259x19, 8-mip tail chain, arrays, and 3D).victory-gpuWARP (--features diagnostics):texture::tests2/2,draw::tests --test-threads=111/11.cargo clippy -p victory-formats --all-targets --locked -- -D warnings: 0 warnings;cargo xtask policy: 184 files ok; cleangit merge-treeagainst13f91caand#2735.detile_throughput(--release, same machine vs13f91ca):BC7 64KB_D: detile9,317->13,471 MB/s(1.45x) | tile12,646->15,430 MB/s(1.22x)BC7 64KB_S: detile9,354->12,430 MB/s(1.33x) | tile10,307->14,856 MB/s(1.44x)BC1 64KB_D: detile19,254->33,089 MB/s(1.72x) | tile25,347->44,560 MB/s(1.76x)RGBA8 64KB_D: detile15,925->32,770 MB/s(2.06x) | tile12,847->40,079 MB/s(3.12x)RGBA8 4KB_S: detile15,445->32,479 MB/s(2.10x) | tile13,660->35,579 MB/s(2.60x)BC7 64KB_D tail: detile29,747->48,344 MB/s(1.63x) | tile28,035->49,428 MB/s(1.76x)RGBA8 3D 4KB_S: detile12,117->29,495 MB/s(2.43x) | tile6,690->17,379 MB/s(2.60x)@kotekompotek on GitHub · 2026-11-25 20:36 UTC · original
Solid rewrite: the contiguous-prefix detection (take_while on the x pattern) yields the compile-time run width N, columns are precomputed once in N-byte units, and the row-pair trick for narrow runs keeps writes to nearby tiled addresses together. The unreachable! on run width is safe per the GFX10 pattern shape. One coverage question: do the texture tests (or a fixture elsewhere) round-trip tile/detile across the swizzle modes and mip tails? The tail-run + second-row edge cases in walk_runs are exactly the spots where a copy could silently misalign.
@oni-swr on GitHub · 2026-11-25 20:58 UTC · original
Independent WARP/CPU verification of
d3310473(#2736).Review: Only
victory-formats/src/texture.rschanges.walknow validates everything before any write (it was already doing that, andcopy_errors_precede_writes_in_both_directionsnow pins it), and tiled copies go through aBuffersenum with monomorphised run widths (4/8/16/32). Linear layouts take a plain row copy. I found nounsafe, and slicing stays bounds-checked. Odd widths (a short last run) and odd heights (an unpaired row) are handled throughlastandsecond. I found no correctness problems.Results (CPU):
origin/main:cargo test -p victory-formats --lib: 38 passed, 5 ignored.detile_throughputbenchmark; I did not re-measure the 2.4x claim).cargo clippy --locked -p victory-formats --all-targets [--all-features] -- -D warnings: clean.cargo test -p xtask(policy): 6 passed.Negative control (mutating the PR head):
last = None):addresses_are_a_bijection_and_copies_round_tripfails.second = None):addresses_are_a_bijection_and_copies_round_tripanddepth_pitch_accepts_exact_and_padded_slicesfail.So the new odd-size and cross-block cases catch breakage in the new fast path.
Method: no physical GPU.
VICTORY_WARP=1,VICTORY_D3D12_WARP=1, Windows SDK 10.0.26100dxil.dllonPATH, Windows 11, rustc 1.98.1 MSVC,--locked. Comparedorigin/main(13f91ca) with the PR head. The PR merges cleanly onto that main. No game files, dumps, shader names or retail hashes were used or are needed.AI disclosure: this verification was done by Claude Code / Claude Sonnet 5.5.
@Marvisak on GitHub · 2026-11-25 23:22 UTC · original
Automated triage for the maintainers.
This reworks
Layout::walkincrates/victory-formats/src/texture.rsfortile/detile: the contiguous run width is derived once frompattern[0], copies are monomorphised per width (walk_runs::<N>), narrow runs pair adjacent rows usingpattern[1][1], and thick 3D slabs walk their depth slices together. By reading I checked the assumptions againstMICRO: every addressable kind/element size gives a run of 4, 8, 16 or 32 bytes (so theunreachable!holds), y bits always sit above the run bits (so the paired-row offset is a whole number of chunks), micro tiles are at least 2 rows tall (tail origins stay on even y), and all validation still precedes the first write. The round-trip test now compares the whole tiled buffer against per-elementLayout::offsetover all addressable swizzles, element sizes, odd sizes, arrays and volumes. CI (check) passes.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
@DenRakEiw on GitHub · 2026-11-26 00:49 UTC · original · approved these changes
Verified against
origin/main(63bcca4):victory-formatsunit tests (includingaddresses_are_a_bijection_and_copies_round_trip,layouts_match_addrlib, andlayouts_share_identical_swizzle_tables).cargo clippy -p victory-formats --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@futurepro62 on GitHub · 2026-11-26 12:42 UTC · original
NVIDIA full-suite run, to go with the reports above by fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head
d331047(on its base13f91ca).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 774 passed, 0 failed, 10 ignored.copy_errors_precede_writes_in_both_directions.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
@fuzeofficlal on GitHub · 2026-11-26 14:42 UTC · original · approved these changes
The contiguous run widths (
4,8,16, and32bytes incrates/victory-formats/src/texture.rs:705-761) cover all currently addressableMICROpatterns and element sizes (1..=16B), every full-runcolumn()offset andpattern[1][1]second-row delta is an exact multiple ofN, row pairs stay within a block height (bothyandtail.yare even), 3Dslabalignment holds sinceslice == 0forTex3d, narrow/odd tails fall back cleanly tospan(), and all validation checks precede writes in both directions. Verified address equivalence across 60 layouts / 717 subresources / 999,986 element addresses (including 231 tail and 88bytes < Nsubresources) with zero mismatches.Local verification at
d3310473(and merged ontoorigin/mainat8a82b503):xtask policy(184 files ok),cargo clippy -p victory-formats --all-targets(defaultand--all-features, 0 warnings), andcargo test -p victory-formats(debug and--release:39 passed, 0 failed, 6 ignored; merged ontoorigin/main:47 passed, 0 failed, 6 ignored) all passed. Releasedetile_throughputon a Ryzen 9 9950X vsorigin/main(63bcca43) improved across all 14 cases by 1.43x–4.35x (e.g.,BC7 64KB_D detile8,278.7 -> 16,452.3 MB/s,BC7 64KB_S tile12,000.7 -> 21,391.2 MB/s,RGBA8 64KB_D detile9,937.6 -> 43,266.9 MB/s,RGBA8 4KB_S tile13,255.4 -> 52,662.9 MB/s,RGBA8 3D 4KB_S tile7,311.3 -> 18,624.0 MB/s). Approving.@rezioliver-collab on GitHub · 2026-11-26 18:02 UTC · original
I measured the odd-pitch case separately on Apple M1. Adding 37 bytes to each linear row and 19 bytes between depth slices still gave a speedup in both directions, including on a 3D volume with an odd depth.
I compared
13f91caewithd3310473using coordinate-dependent bytes. Tight rows and rows rounded up to 256 bytes were additional controls. The PR had a faster median in all 18 combinations of surface, pitch and copy direction. I built a tiled reference one element at a time withLayout::offset, then compared whole buffers in both directions, including row padding, guard bytes and the untouched array slice. Every comparison matched.The table uses median base/PR ratios from 12 alternating release pairs on macOS 14.7, Rust 1.98.1.
@Desamodeth on GitHub · 2026-11-26 18:41 UTC · original · reviewed
I compared #2026 (
1ec3877) and this PR (d331047) against main (63bcca4) on the same Ryzen 7 9800X3D. I would prioritize #2736 for its performance in both copy directions. One exception worth preserving in future benchmarks is detiling a rotating set of 1080p surfaces: #2026 was faster there in both processes.Median µs per complete subresource copy on Windows x64. Columns are main / #2026 / #2736, first process:
The second process reversed the version order. The 1080p tile slowdown on #2026 repeated (380 / 741 / 188 µs), as did its advantage over #2736 for rotating 1080p detile (696 / 448 / 484 µs). The rotating BC7 detile ranking between the two PRs flipped; that case does not give a dependable winner. The linear 1080p control was within 2% across versions in each process.
Each version's actual
texture.rswas compiled as a separate optimized Rust 1.98.1 MSVC library. The module on #2736's older base is byte-identical to current main. Same buffers for all three versions, all six orders, two warm-up batches and twelve measured batches. Before timing I compared each direction independently against buffers built with main's per-elementLayout::offset, including padding, an untouched array slice and a small mip. The module's active tests passed on all three. CPU copies only; no game frame or GPU measurement. Coordination. AI-assisted with Codex.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.