GPU: refresh written-to textures by rows of layout blocks #4809
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!4809
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4808"
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?
@Jineggegg on GitHub · 2026-12-01 09:33 UTC · original
Jineggegg:texture-partial-update→main· +1100 −24 · 3 files · 15 commits · closed without mergingBased on
mainate1251c31; one commit.Problem
A title texture in write-watched memory is refreshed as a whole whenever any of its pages is written:
Staging::refresh_timedaskswatch::writes_sinceonly whether anything changed.copy_mapped, andStaging::detiledetiles every subresource.record_upload,CopyTextureRegion(..., None)).So a title that streams a texture in, or draws into an atlas a page at a time, pays for the whole texture on every change. Take one 64 KiB page written into a 1024×1024 RGBA8 texture with a full mip chain (about 5.3 MiB): it costs a 5.3 MiB read, a 5.3 MiB detile and a 5.3 MiB upload copy. The module doc already marks this as a shortcut: "a change detiles the whole texture, not the pages written".
Reproduction
diagnostics,TexWatchedgrows by the texture's whole size every frame, and the upload records one copy per subresource.The ignored measurement
texture::gpu_row_tests::texture_row_refresh_costs(see Performance) reproduces this without a title.How it works
Where the bytes live (
victory-formats)Layout::subresource_bytes(mip, slice)describes where a subresource's tiled bytes lie in a 2D layout:stridebytes androwselement rows high (a linear layout has one element row per block row);Layout::detile_rows(tiled, mip, slice, rows, linear, pitch)detiles only the requested element rows. It goes through the samewalkasLayout::detile, now with an optional row range, so the bytes are identical and no addressing code is duplicated.NoneorUnsupported.What changed since the last refresh
refresh_timed, the newwatch::pages_sinceasks the same journal aswrites_since(the page epoch table where the journal keeps one). It also returns which pages were written after the previous asking (since).written_ranges). This happens only when the staging buffer still holds the whole memory as ofsince(Last::complete).row_planmaps the byte ranges onto parts:RowParts::detilewrites the rows in place in the resident staging buffer, at the offsets the whole detile would use.What gets copied
Staging::changed(Changed) collects the rows detiled since a submitted copy last took them.copy_plancaptures(serial, rows):D3D12_BOX, when the host rows match the title's row for row (boxed);dirtynow callsChanged::taken(serial, whole):dirtyset for the next list;What keeps the old path
BAKING), levels on demand,exactrefreshes,oncetextures, guarded or hashed (view) memory, partly mapped memory, unlocked refreshes,VICTORY_REFRESH_LOCKLESS, and the card's detiling (VICTORY_GPU_DETILE, which needs the raw bytes). Every whole detile callsChanged::note_all.VICTORY_PRELUDE_UPLOADS=1, off by default) still copy every part whole.PreludeUpload::finish_refreshclears what is pending under the same lock asclaim_upload. Row copies from the prelude would be a natural follow-up, since there the plan is known exactly at submission.Switch.
VICTORY_TEXTURE_ROWS=0restores the previous behaviour.Tests
No GPU needed:
victory-formats:rows_of_blocks_detile_as_the_whole_mip_does_from_their_own_bytes. Covers RGBA8 arrays at odd sizes, BC (8 and 16 bytes per block), SW_256B, 4 KiB, 64 KiB, S and D modes, linear, and mip tails. For every subresource it checks that a whole detile reads nothing outsidesubresource_bytes; thatdetile_rowsfrom a buffer where only its block rows are real matches the whole mip byte for byte; thatrows_inround-trips; and that non-tail subresources do not overlap.a_byte_range_names_the_rows_of_blocks_it_touches.row_detiling_refuses_what_it_cannot_do, including a configured XOR layout (it must refuse: XOR picks the pipe with address bits above the block).victory-gpu(texture::row_tests, no device):rows_detiled_since_are_kept_until_a_copy_takes_them:Changed's serial, union and keep rules.written_pages_become_ranges_from_the_texture_start: unaligned start, merged runs, a page past the end.a_plan_reads_rows_of_blocks_and_whole_tails.rows_detiled_after_page_writes_match_a_whole_detile_and_their_copies_the_host: simulates page writes on four layouts (RGBA8 array with tail, BC, 4 KiB array, linear) in a texture that starts partway into a page. After the row refresh, the staging buffer equals a fresh whole detile, and applying the planned row copies to a "host" image makes every visible row equal.Needs a D3D12 device (marked
#[ignore]):texture::gpu_row_tests::rows_the_title_writes_reach_the_host_texture_and_are_copied_alone. The texture is an RGBA8 1024×512 with three mips and two array slices, in write-watched memory. The test writes into mip 0 of slice 1; then into mip 1 and the last texel of mip 0 of slice 0; then into the last row of mip 2. After each write it checks that the plan names exactly the written parts, that the next list copies them and clearsdirty, and that a full readback of every subresource equals a CPU detile of the title bytes.texture::gpu_row_tests::texture_row_refresh_costs: the measurement below.Results on Windows (toolchain pinned in
rust-toolchain.toml, Rust 1.98.1; RTX 5090, driver 621.14):main(e1251c31) does not pass-D warningsat the moment: 4 warnings without--all-features(fieldloop_capsis never read incrates/victory-shader/src/emit/lower.rs; manual implementation of.is_multiple_of()incrates/victory-gpu/src/host.rs; match can be simplified with.unwrap_or_default()incrates/victory-hle/src/modules/xmem.rs; methodrangedis never used incrates/victory-gpu/src/shadow.rs) and 5 with it (also functionmbis never used incrates/victory-gpu/src/copystat.rs). Both CI configurations were therefore run without-Dand compared withmain's diagnostics. This branch adds none, in either configuration.cargo test --workspace --locked --no-fail-faston the GPU: 2527 passed, 5 failed, 98 ignored (main: 2520 passed, 5 failed, 96 ignored). No new failure: the failures are the onesmainhas itself (list::thin::tests::bindings_record_no_work,shader_cache::tests::every_switch_of_the_translator_is_in_the_key,modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it,emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity,policy::tests::repository_passes_policy).texture::gpu_row_tests::rows_the_title_writes_reach_the_host_texture_and_are_copied_alone(ignored, run by name on the GPU): passed (1 passed, 0 failed).Performance
In short:
texture_partial): with rows on, the mean time per iteration drops by 26% (small textures), 88% (medium) and 94% (large), lower in every pair, and each run reads 4× (small), 21× (medium) and 85× (large) fewer bytes.texture_whole): rows on is within half a percent of rows off and ofmainfor the small and medium loads (the intervals touch or cross zero). For the large load its mean is 9% lower, with the same p95 and p99.VICTORY_TEXTURE_ROWS=0(A) matchesmain(M) within 2% in every case, so the switch restores the previous behaviour.maintexture_partialtexture_wholetexture_whole, B vs M (main)texture_partialtexture_wholetexture_whole, B vs M (main)texture_partialtexture_wholetexture_whole, B vs M (main)Method:
VICTORY_TEXTURE_ROWS=0, B = default.mainthat carries only this measurement. It shows that the whole-rewrite case did not get slower.texture_partial: each iteration writes 8 KiB into mip 0 of every texture, then submits the list whose check finds the write and the list that copies it.texture_whole: the same, but each iteration rewrites every texture whole.For reference only: the original implementation in another tree, measured on its own hot-path fixture, made the same 8 KiB title write copy 1 MiB instead of 32 MiB and cut partial-update time by about 90%. Those numbers do not carry over to this tree's resident staging buffer and record-time copies.
Risks
since. These are the same askings the existing skip (w <= last.asked) already trusts. Anything that changes the bytes without a reported write leavescomplete = falseand takes the whole path. A remap is one such case (it resetsasked); so are guarded memory and partly mapped memory.TexInAir). Row refreshes write less of it, and a planned copy covers only rows whose writes have finished.D3D12_BOXcopies. Box copies are limited to colour formats with one texel per element and native row sizes. The GPU readback test above covers them.Provenance and credits
This reimplements the partial texture upload from
Jineggegg/VIctory(commits72c2620, "stream tracked texture uploads by dirty rows of swizzle blocks", andc6301f4, "require native plane rows for partial texture copies") for this tree's resident staging buffer and record-time copies. It is not a cherry-pick.The original also packed compact copy footprints, following
Marvisak/VIctory#3136. That part does not apply here, because staging buffers are resident.Related work with a different scope:
Marvisak/VIctory#2985marks dirty element rows but still stages the whole texture.Marvisak/VIctory#2358is opt-in and handles a single mip and slice.Layout::detilewalks wide non-XOR textures (block columns), in the samewalkthis branch extends with a row range. The two conflict textually there (checked withgit merge-tree), so whichever lands second needs a small rebase; they do not overlap in purpose. Open #4031 changes the partly-mapped refresh path, which this branch leaves on the whole path; it merges with this branch cleanly.AI assistance: the change, its tests and this description were prepared with an AI coding assistant (Claude Code) and checked by the results above.
🤖 Generated with Claude Code
5fabb46e) into texture-partial-update f029d7662e@tillo88 on GitHub · 2026-12-01 15:26 UTC · original
Measured this PR (head
f029d766,VICTORY_TEXTURE_ROWSat its default, on) merged on top of v2026.11.30.03 (it applied without conflicts), 2 runs, against the release as it is.a host command list did not close (0x80070057)at +2:38 after the log starts, about 20 s after the prison → plane cutscene cut. That is the known crash of #2237 (the bare release stops near that cut in 9 of 42 runs on this bench), so it does not point at this PR. Both measured runs completed.Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing off. Same save restored before each run (start of the game), prison cutscene, plane cutscene, first boat section, about 6 minutes; warm-up run not counted for speed.
Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.
@trustno1-coder on GitHub · 2026-12-01 18:31 UTC · original
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed