GPU: detile only texture subresources affected by writes #1135
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!1135
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1135"
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?
@divyeshganta on GitHub · 2026-11-24 16:06 UTC · original
divyeshganta:perf/partial-texture-detile→main· +296 −20 · 2 files · 1 commits · openFixes #915.
When title memory changes, only re-read the changed 64 KiB pages on the write-watched path (or hash individual pages on the fallback path), then detile only the mips and slices whose tiled extents overlap those pages. The first detile and full host-texture upload remain unchanged.
Patch by talakasse (
af4fef40372e4e1bf75b1d1600c36656b4b3ad26), carried with its original authorship.The contributor reports Windows 10 MSVC checks:
victory-formats24 passed / 4 ignored; GPU diagnostics 56 passed / 1 ignored, including the new texture tests. A synthetic WARP fixture covered changed mips and slices plus both hash and write-watch paths. It did not submit a draw or measure in-game performance. I have not rerun these checks locally.Known limitation from the report: a page decommitted without a write can leave stale bytes in the kept copy, although this gap existed before the change. The refresh path also has textual overlap with #143, #388, #401, and #641, so it may need rebasing if one of those merges first.
@Zipettte on GitHub · 2026-11-24 18:01 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
af4fef4:cargo test -p victory-formats -p victory-gpupasses, 77 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Marvisak on GitHub · 2026-11-25 00:36 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-gpu/src/texture.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
@wwwwwwww3333333 on GitHub · 2026-11-25 00:48 UTC · original
This PR no longer merges with main (
70564ae0): main moved texture tracking towatch::Tracked, which conflicts with this PR incrates/victory-gpu/src/texture.rs. I ported your approach onto main's model and took it a bit further. Tested on AMD.What the port does (credit for the idea and the
Layout::extentspart, taken as is with its test, goes to this PR):Tracked::takealready returns the written page runs; only those are read again into the copy. The first refresh reads everything.extentsoverlap the written bytes are detiled again.Layout::detile_rangescopies only the bytes in the written ranges. It skips whole rows whose tiled span misses them, through awalk_rowsthatwalknow calls. Without this, a write into mip 0 (about 75% of a 4K texture) still costs most of a full detile.upload_changedpath (bindless, recorded at submission), only the subresources detiled again are copied; the host texture already holds the rest. Theuploadpath still copies every subresource, because it records before the refresh. The module's shortcut note now says so.Results on
70564ae0+ this, RX 6750 XT, i5-13400F, Windows 11, Rust 1.98.1 MSVC.Timing (release, ignored test
detile_one_written_page_of_a_4k_bc7_texture): a 4096x4096 BC7 texture (21 MiB, full chain) with one 64 KiB page written in the middle of mip 0.New tests:
extents_hold_what_a_subresource_detiles(from this PR) anddetiling_ranges_matches_detiling_the_merged_memory.detiling_the_changed_subresources_matches_detiling_all, over 5 layouts × 6 sets of written pages, including 3D and linear. Partial detiling onto the old result is byte-identical to detiling everything.changed_chunks_name_the_chunks_written.Suites and clippy:
cargo clippy -p victory-formats -p victory-gpu --all-targets -- -D warnings: clean.Not measured: how much of a frame this saves in a title. That needs a world run, which I can't do here.
Patch against
70564ae0Unit tests only, no game files. AI-assisted (Claude ported and extended it; I ran it on my machine).
@wwwwwwww3333333 on GitHub · 2026-11-25 01:03 UTC · original
Update: main has moved to
42363ab6, and the port above conflicted with two changes merged since:copy_runsinLayout::walk.subresource_len(4fc9d70), which keeps the staging slice inside the buffer when the last row isn't padded.Here it is rebased.
walk_rowskeeps thecopy_runsspecialisation and only adds the row-span skip.Partnow carries its length fromsubresource_len, and the staging slice isself.size, so the partial path keeps that bounds fix. Without it, the port would have read past the buffer on such textures.Results on
42363ab6+ this, RX 6750 XT, i5-13400F, Windows 11, Rust 1.98.1 MSVC:42363ab6subresource_lenandcommittedtests.cargo clippy -p victory-formats -p victory-gpu --all-targets -- -D warnings: clean.Patch against
42363ab6Unit tests only, no game files. AI-assisted (Claude rebased it; I ran it on my machine).
@akimfomin on GitHub · 2026-11-25 03:21 UTC · original · edited 2026-11-25 04:39 UTC
The selective detile work by talakasse and wwwwwwww3333333 suggests a separate step for
upload_changed: use the dirty tiled page ranges to limit the GPU copy after the destination already has valid prior contents. PortBridge prototyped that mapping with the existing open GFX10 layout as the oracle.On a synthetic 512×512 RGBA8 texture, one 64 KiB dirty tile generated one
CopyTextureRegionbox. D3D12 on RTX 4070 Ti SUPER issued a 65,536-byte update instead of 1,048,576 bytes, and full readback matched on every byte. The CPU verifier covered 1,592 dirty-range cases including unchanged slices, odd dimensions and mip tails. The prototype keeps full copies for uncertain eligibility, dense changes, and the first upload.Planner source, GPU fixture and raw results. This is a standalone follow-up for a persistent staging buffer and initialized texture. Runtime integration remains open.
Follow-up on the same RTX card: four fresh processes and 48 order-balanced pairs per RGBA8 shape. The warmed GPU copy medians were 25.648 → 2.080 µs for one box, 24.256 → 5.616 µs for four adjacent tiles merged to one box, 24.400 → 5.728 µs for four separate boxes, and 24.640 → 10.176 µs for eight. Both final textures matched their whole reference in every shape. The four-separated set retains one slow outlier. Timing source and raw pairs.
An independent BC7 fixture also requested 64 KiB instead of 1 MiB for one aligned box in slice 1, mip 0. All 2,621,440 bytes per arm matched across both slices and both mips, including the 159,744 untouched compressed blocks. BC7 fixture and guarded readback. The timings cover repeated GPU copy commands on initialized resources. They do not include staging, detiling, or frame time. AI-assisted PortBridge verification (OpenAI Codex).
A CPU follow-up updates just one 64 KiB tile in already initialized staging. The 160 tile positions gave identical full images and row padding both against main
940d32fand against 0xkn0wh3r3's faster whole detile in #2026. On 1024×1024 RGBA8 the #2026 whole CPU detile was 320.00 µs versus 279.55 µs for the partial step with a byte check outside the tile, or 7.10 µs for that tile alone. On 2048×2048 BC7 those were 324.80, 276.15 and 7.10 µs. Additive helper, pin and eight process logs. These timings start with snapshots already in memory. The regional caller still needs an initialized staging buffer and a confirmed prior copy.@wwwwwwww3333333 on GitHub · 2026-11-26 02:19 UTC · original
Main (
63bcca4) now detiles only the subresources a tracked write reaches, which covers most of this PR. I opened #2985 on top of it for the part that is left: inside such a subresource, only the rows the written pages touch are read, detiled and copied to the host texture (aD3D12_BOX, since staging buffers now come from a shared pool). On an RX 6750 XT, one 64 KiB page written into mip 0 of a 4096x4096 BC7 texture: whole mip 2.73 ms, touched rows 0.086 ms (CPU detile only).@akimfomin that is also the GPU copy you suggested limiting, done per row band rather than per tiled page range. If your
upload_changedstep goes further, I am happy to rebase #2985 on it or drop the copy part.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.