GPU: a tracked texture write detiles and copies only the rows it touches (#1135) #2985
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!2985
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2985"
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?
@wwwwwwww3333333 on GitHub · 2026-11-26 02:17 UTC · original
wwwwwwww3333333:fix/texture-rows→main· +633 −63 · 5 files · 4 commits · openPorts the idea of #1135 to current main (
63bcca4). Credit to @talakasse, whose patch #1135 carries, to @divyeshganta, who opened #1135, and to @akimfomin, whose comment there points the same way for the GPU copy.Main already reads and detiles only the subresources a tracked write reaches. It still re-reads and detiles each of those whole: one 64 KiB page written into mip 0 of a 4K BC7 texture costs all 16 MiB of that mip.
What changes
victory-formats:Layout::touched_rowsreturns the rows of a subresource whose tiled bytes overlap the written ranges, and the tiled bytes those rows read.Layout::detile_rowsdetiles only those rows.walktakes an optional row range; its run computation moved intoLayout::runs, unchanged.victory-gpu(texture.rs): for a subresource that owns a written page (the path that already skips hashing), only the band's tiled bytes are read, only its rows are detiled, and only those rows are copied, through aD3D12_BOX. Staging buffers come from a shared pool, so the rows outside the band hold stale bytes and are never copied. Subresources on shared pages, untracked memory and layouts the layout code cannot address keep the whole-subresource path.Uploadnow carries(subresource, Option<rows>).Tests (RX 6750 XT, i5-13400F, Windows 11, Rust 1.98.1 MSVC, on
63bcca4)detiling_the_touched_rows_matches_detiling_all(victory-formats): 7 layouts (linear, 256B/4KB/64KB S and D, BC, arrays, 3D), random pages written. A change stays inside the rows reported, and detiling those rows from only the reported bytes (the rest garbage) matches a full detile. It asserts that more than 50 cases are partial bands.a_write_into_one_page_uploads_its_rows_alone(victory-gpu, on hardware): a 512x512 texture, one page written then another. The written rows arrive, the other rows keep their earlier contents, and one subresource is copied each time.cargo clippy -p victory-formats -p victory-gpu --all-targets -- -D warnings: clean.Timing (release, ignored test
detile_the_rows_of_one_written_page_of_a_4k_bc7_texture): 4096x4096 BC7, one 64 KiB page in mip 0. Whole mip: 2.73 ms. Touched rows (64 of 1024, 1 MiB of tiled memory read instead of 16 MiB): 0.086 ms. CPU detile only; the smaller read and GPU copy are not timed.Not measured: the effect on a frame in a title.
Unit tests only, no game files.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
@pickles976 on GitHub · 2026-11-26 02:44 UTC · original
Independent Wine/vkd3d-proton 3.2.0 verification, exact head
632d05e1:detiling_the_touched_rows_matches_detiling_all1/1 passed;a_write_into_one_page_uploads_its_rows_alone1/1 passed on the physical RTX 4060 Laptop GPU (NVIDIA 590.48.1, vendor masking disabled), including GPU readback showing unchanged rows retain their prior contents across two page writes. No in-title frame-time or host-RAM peak measured; this does not clear our loading RAM guard. Logs.compat-runtime/logs/verify-pr2985-wine-{touched-rows-parity,rtx4060-partial-texture-upload}.log.@steven-seagull27 on GitHub · 2026-11-26 02:57 UTC · original
The conflict with #2626 is resolved on
codex/pr2985-packed-rows. Its parents are this PR at632d05eand #2626 atc8cc83e. The packed path expands tiled spans directly into RGBA8 staging and keeps the copy limited to the rows populated. To try it from this PR, rungit fetch https://github.com/steven-seagull27/VIctory.git codex/pr2985-packed-rowsthengit merge --ff-only FETCH_HEAD.The committed
packed_page_updates_respect_texture_ownershiptest reads 64 × 1,536 pixels through normal descriptor-table submission. On both RTX 5080 (621.40) and Windows WARP, native sampled B5G5R5A1 and B4G4R4A4 initialized correctly, then updated rows 256–511 and 0–255 on successive writes. All other rows retained their colors, with zero wrong pixels in three runs per adapter. In a separate control I prefilled staging with a sentinel and widened each partial copy to the full mip. Exactly 81,920 pixels outside each 256-row band then failed, on both adapters and both formats.On the RTX the writable versions used RGBA8 and took their initial pixels from title memory once. They kept those pixels after the two later guest writes, as #2626 intends. WARP used native writable formats. The two existing partial-copy and padding tests from #2626 also passed three times on each adapter.
For the BC and pitched-copy question in the review, a separate test drove the staging and copy routines directly. Each adapter matched 81,084 packed texels and 1,278 BC1 blocks across 3D mips and array slices, including the last rows of 34×18 and 17×9 BC mips and an untouched middle array slice. These are synthetic Windows readbacks. I’m checking mixed tracking coverage and retry behavior separately. Format suite 47 passed, six ignored. Strict Clippy and asset policy passed.
AI-assisted with Codex.
@steven-seagull27 on GitHub · 2026-11-26 03:14 UTC · original
@fuzeofficlal I confirmed both review findings on the RTX 5080 and Windows WARP.
2fa3f3dfixes both in one commit directly on this PR’s632d05e. It also merges cleanly with the separate packed-format integration.Each row below gives wrong pixels out of 49,152, identical on both adapters in three runs each. Page A and page B belong to the same sampled RGBA8 mip.
63bcca4632d05e2fa3f3dThe test checks the live tracker’s coverage and reads every pixel through the ordinary descriptor table. The retry fixture returns
Noneonce from the detile step after the dirty ranges have been taken, so it’s repeatable without exhausting GPU memory. Mixed-coverage mips now use the full-subresource hash path. A failed stage requeues the tracked pages alongside later writes. An unchanged follow-up submission issued zero copies. The existing fully tracked sparse-upload test still passes on both adapters.To apply on the current PR head:
Final committed tests passed three times per adapter. Strict Clippy, asset policy and the format suite passed (47 tests, six ignored). AI-assisted with Codex.
@wwwwwwww3333333 on GitHub · 2026-11-26 03:15 UTC · original
Note for whoever merges this together with #2639: #2639 adds the tracker's untracked parts (
loose) as candidates. With both, a subresource that owns a changed tracked page and also overlaps a changed untracked part would take the row path here, andtouched_rowssees only the tracked ranges, so the rows of the untracked part would not be read again. The fix for whichever lands second is to take the row path only where the subresource overlaps nolooserange (the whole-subresource path then reads and hashes it, as #2639 does). I can rebase this onto #2639 with that rule if it lands first.@steven-seagull27 on GitHub · 2026-11-26 03:32 UTC · original
Your proposed
looseoverlap guard fixes the mixed-write case. I combined this PR (632d05e) with @BastienRodz's #2639 (2f98c15), which supplies the ordinary-memory candidate ranges. I used one fully resident, three-page mip: the first page is ordinary memory and the other two are write-watched.After confirming the old values, I changed the ordinary page from
0x99to0x55and the adjacent tracked page from0x33to0x77before one normal submission. With just the two PRs combined, the tracked and untouched pages were correct, but all 16,384 texels on the ordinary page still sampled as0x99. The next unchanged submit caught up by copying the mip again. With the overlap exclusion, all 49,152 texels matched on the first submit (one copy), and the unchanged submit copied nothing. The RTX 5080 and Windows built-in WARP gave these results in three fresh processes each. The earlier ordinary-only, fully tracked and deferred-staging checks also passed on the fixed branch.I put the optional combined branch and simultaneous-write test on my fork. It retains both original PR histories and
2fa3f3d. Candidate selection uses #2639'slooseranges, the row shortcut excludes mips overlapping them, and a deferred upload retries consumed tracked pages. The branch is available for comparing either eventual rebase. BastienRodz's corresponding note on #2639.@wwwwwwww3333333 on GitHub · 2026-11-26 04:11 UTC · original
Thanks @fuzeofficlal and @steven-seagull27. Both findings are confirmed and fixed on this branch.
91284ea, taken as is with his authorship, including the loose-overlap rule for #2639.cf6d7ee: the new test freed its three pools at the end. The guards of their tracked pages outlive the textures, so a later test whose pool got the same addresses never saw its writes.a_copy_is_refreshed_once_per_submission_by_the_pages_writtenthen failed in 4 of 6 full runs of the suite (0 changed bytes, expected 65536). The new test now leaves its pools allocated, like the other draw tests. With that, the full victory-gpu suite passed 4 of 4 runs, then victory-formats and clippy too. This is not tested in a title.@steven-seagull27: you may want the same change in your branch if you carry the test there.
@Marvisak on GitHub · 2026-11-26 05:33 UTC · original
Automated triage for the maintainers.
Merge candidate. When a tracked write lands on pages a subresource owns alone,
Staging::refresh_nowinvictory-gpu/src/texture.rsnow reads, detiles and copies only the rows those pages reach. It usesLayout::touched_rows/detile_rowsinvictory-formatsand aD3D12_BOXincopies. Shared pages, untracked memory and layouts the layout code cannot address still take the whole-subresource path.Both findings from the earlier review are fixed in
91284ea:own);Tracked::retryinwatch.rs).The format test checks that a row-limited detile matches a full one over 7 layouts, including BC and 3D. Independent runs on NVIDIA and WARP in the comments agree.
Worth knowing:
Tracked::untrackeddocuments.cf6d7eeleaves pools allocated because tracked-page guards outlive their textures. That is existing behaviour, but worth an issue.CI: passing. Recommending a look, not approving.
Generated by Claude Code
@steven-seagull27 on GitHub · 2026-11-26 05:48 UTC · original
@wwwwwwww3333333 Thanks for catching the pool lifetime in my test. I carried your
cf6d7eecorrection, with your authorship, onto both branches. The standalone tree now has the same file contents as your current head. The combined #2639 tree also keeps @BastienRodz’s candidate-range changes and the simultaneous tracked/ordinary write check.I ran
mixed_pages_and_deferred_rows_reach_the_sampled_texturefollowed bya_copy_is_refreshed_once_per_submission_by_the_pages_writtenin the same test process, with one test thread. On each branch the pair passed in 6/6 fresh processes on the RTX 5080 and 6/6 on built-in Windows WARP. The D3D12 debug layer and an adapter identity check were enabled in every process. On the combined branch, the mixed-page test still checks all 49,152 texels after the simultaneous writes and expects zero new copies on the next unchanged submission.Your four full-suite runs cover the broader ordering. My rerun targeted the two tests you identified. AI-assisted with Codex.
@MeMako on GitHub · 2026-11-26 06:28 UTC · original
Verified
#2985(cf6d7ee) on AMD RDNA 4 (Windows 1110.0.26200, Ryzen 9 7950X, RX 9070 XT, driver32.0.32029.2010, 32 GB RAM).Tests & Microbenchmark
cargo clippy -p victory-formats -p victory-gpu --all-targets --locked -- -D warnings: clean.victory-formats: 47/47 passed (includingdetiling_the_touched_rows_matches_detiling_all).victory-gpu: 272/272 passed (includinga_write_into_one_page_uploads_its_rows_aloneandmixed_pages_and_deferred_rows_reach_the_sampled_texture).detile_the_rows_of_one_written_page_of_a_4k_bc7_texture(--release, 4096×4096 BC7 mip 0, 1 written 64 KiB page):Live Title Verification (RX 9070 XT)
main63bcca4+#2051+#2472+#2918+#1010+#2130with VRAM upload flags off +#3055+#2914), adding#2985+#2849+#3035together in the same live run (n=54world frames /n=38heavy frames vs.n=51/n=38baseline).6,186draws vs.5,290draws in baseline):fpslog line): 9.4 ms / 11.8 MB/frame → 6.2 ms / 3.0 MB/frame (-34% time, -75% upload bandwidth)bindless::uploadsstage: median 24.9 → 20.9 ms (avg 30.1 → 25.2 ms)#2985+#2849+#3035together): steady-tail frame time dropped 453.3 → 423.6 ms (2.20 → 2.40 fps), even with +17% more draws; the texture upload timers above isolate#2985's share cleanly from thewatch.rs(prep → deferred/copy_back) gains.Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.
@kotekompotek on GitHub · 2026-11-26 02:33 UTC · original · reviewed
Verified: touched_rows over-approximates a row's tiled byte span via the run extent [min start, max end), which is exact for packed layouts and conservative for padded ones — a hit between row extents yields an empty range and correctly detiles nothing. detile_rows keeps linear offsets at original y so the copy box maps staging rows 1:1 onto texture rows. The test is properly discriminating: one dirty page moves only its rows, untouched rows provably keep prior host content, and >50 genuinely-partial cases are asserted.
@fuzeofficlal on GitHub · 2026-11-26 02:41 UTC · original · reviewed
Reviewed
632d05e1againstmain(63bcca43) — row geometry, BC 4-texel Y-interval alignment, mip/slice bounds, and sorted disjoint dirty ranges look solid, but there are two subtle partial-upload data-corruption bugs worth fixing before merge:First upload can omit initialized rows in a partially tracked mip (
crates/victory-gpu/src/texture.rs:588-636,watch.rs:331-365):watch.rsallows tracking to cover only part of a texture's allocation. Becausetexture.rs:588-636builds its row plan solely from tracked dirty ranges, if a mip overlaps at least one full tracked page (own(i)enables partial upload) alongside adjacent rows living on untracked pages, the first upload copies only the tracked rows and omits valid initialized data on the untracked pages (mainuploaded the whole touched mip).A failed staging upload can leave rows permanently stale after a later write (
crates/victory-gpu/src/texture.rs:594, 681-685):594before staging succeeds, while the staging-failure path at681-685only clears hashes.main, B's upload re-copied the full mip and healed A).(Minor test note: the GPU test in
crates/victory-gpu/src/draw.rs:3152-3202uses RGBA8 and counts subresources, which a full-mip upload could also satisfy — adding a BC GPU test verifying partial copy bounds would lock in the 4×4 block-aligned copy path.)@Dukestar69 on GitHub · 2026-11-26 06:13 UTC · original · approved these changes
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):CopyTextureRegionboxes cleanly avoids full-texture detiles/uploads for partial tracked writes (#1135).cargo test -p victory-formats texture: 17 passed, 0 failed (includingdetiling_the_touched_rows_matches_detiling_all).cargo test -p victory-gpu texture::tests -- --test-threads=1: 2 passed, 0 failed.cargo test -p victory-gpu tracked_rows -- --test-threads=1(RTX 5090 & WARP): 1 passed, 0 failed on both (mixed_pages_and_deferred_rows_reach_the_sampled_texture).cargo clippy -p victory-formats -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@wwwwwwww3333333 on GitHub · 2026-11-26 09:18 UTC · original
Added a GPU test for the block-compressed case you mentioned (
block_compressed_rows_keep_their_block_alignment_across_pages, next to the existing tracked-rows test, commitaca9f15): a 64-wide BC1 texture over three pages, in both the mixed and the tracked pool. It checks that each page decodes to its own color, that a page rewritten in place (including a deferred upload) updates alone while the others keep their previous content, and that the subresource copy counts match. Ran on an RX 6750 XT: the new test and the rest of the victory-gpu suite pass (234 passed, 1 ignored) and clippy is clean with-D warnings. It does not measure how many rows a copy carries, only that the sampled result is right.@fuzeofficlal on GitHub · 2026-11-26 09:51 UTC · original · approved these changes
Re-reviewed at
aca9f15a(including91284ea9..aca9f15a). The follow-up commits cleanly address the untracked-page, deferred-staging retry (Tracked::retry), and BCn block-row alignment cases:own(i)excludes subresources overlappinguntrackedpages so mixed tracked/untracked textures stay on the full-subresource hash path.detilefailure requeues taken pages viat.retry(&ranges)and clearslast.hashes[i], preventing dropped page updates.copies()scales element row ranges bystaging.layout.desc.block.max(1)(clamped tof.Height) and falls back toNonewhen the full subresource is touched;Layout::touched_rows/detile_rowspreserve slice/3D depth alignment.Verified locally on Windows 11 (RTX 5090 + WARP +
VICTORY_D3D12_DEBUG=1,git merge-treeagainst63bcca43clean):cargo clippy --workspace --all-targets [--all-features] -- -D warnings: clean;cargo xtask policy:192 files okvictory-formats:detiling_the_touched_rows_matches_detiling_allpassed; release benchmark on 4096x4096 BC7 mip 0:1.582 mswhole vs57.7 usfor 64 touched rows (rows 512..576, 1024 KiB read, 27.4x faster)texture::+watch::+tracked_rows::+a_write_into_one_page_uploads_its_rows_alone— 20/20 passedVICTORY_D3D12_DEBUG=1:tracked_rows::+a_write_into_one_page_uploads_its_rows_alone— 3/3 passed (zero debug layer errors on BC1 block-rowCopyTextureRegionboxes)--features diagnostics,VICTORY_D3D12_WARP=1) +VICTORY_D3D12_DEBUG=1: 5/5 passedLGTM.
@steven-seagull27 on GitHub · 2026-11-26 09:57 UTC · original
@wwwwwwww3333333 I measured the row counts left open in your BC1 test update. On
aca9f15a, changing the middle tracked page issued a single D3D12 copy withtop=1024, bottom=2048. That is exactly 256 BC1 block rows out of 768. Both the RTX 5080 and Windows WARP recorded the same copy.I logged the source box at the production
CopyTextureRegioncall and kept the test’s original pixel and copy-count assertions. Two fresh processes per adapter, seven submissions per run. Each adapter returned 2,752,512 sampled pixels, zero mismatches. DXGI identified the RTX 5080 and the Microsoft Basic Render Driver. The D3D12 debug layer was enabled. AI-assisted instrumentation and write-up, using the synthetic fixture.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.