GPU: share a scratch buffer for texture detiling instead of retaining one per Staging #1873
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!1873
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1873/head"
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?
@0xKaji on GitHub · 2026-11-24 23:58 UTC · original
0xKaji:fix/texture-staging-scratch→main· +12 −5 · 1 files · 2 commits · closed without mergingSummary
Staging::lastincrates/victory-gpu/src/texture.rskept aread: Vec<u8>buffer inside everyStaginginstance. On watched title textures,refresh_now()resizedlast.readtolayout.sizeand kept that allocation alive for the lifetime of theStagingobject — even thoughStaging::detileimmediately copies the detiled texels into the mapped D3D12 upload buffer andlast.readis never read again until the next refresh.Across hundreds/thousands of uploaded textures, each
Stagingpermanently retained a full-size CPU copy of the tiled texture alongside its mapped D3D12 upload buffer, adding unnecessary host RAM / commit pressure (especially noticeable on 16 GiB RAM systems).Change
read: Vec<u8>from per-StagingLast.static READ_SCRATCH: Mutex<Vec<u8>> = Mutex::new(Vec::new())inStaging::refresh_now()so detiling scratch memory isO(max_texture_size)rather thanO(sum of all uploaded texture sizes).Note:
Staging::refreshruns on the submission thread (serializingBatch::texture_duerefreshes), so a singleMutex<Vec<u8>>adds no contention on the hot path.Verified
cargo xtask policy:asset policy: 174 files okcargo xwin clippy -p victory-gpu --tests --target x86_64-pc-windows-msvc --offline -- -D warnings: 0 warningsresource::tests::buffer_data_reaches_the_host_texture --test-threads=1on Linux + Wine11.22+vkd3d-proton 3.2.0+ NVIDIA RTX 3060): 1 passed, 0 failed.3,953 MiBVRAM,0Xids).@sawetco on GitHub · 2026-11-25 00:33 UTC · original
On
crates/victory-gpu/src/texture.rsline 318 (outdated):A smaller texture shrinks the vector’s length while keeping its capacity. When the next upload is larger,
resize(size, 0)zeroes the tail immediately beforecopy_mappedfills it. Alternating 256² and 2048² RGBA8 textures writes an extra 15.75 MiB of zeros per pair after warm-up. Keeping the largest initialized length still uses one allocation and gives the detiler exactly the current texture’s bytes.I tested both paths on a Ryzen 5 7600X, native Windows 11, rustc 1.100.0 MSVC
-O. The single-thread harness reads synthetic, fully mapped RGBA8 buffers viaReadProcessMemoryand runs this commit’sLayout::detile(swizzle 10). Each fresh process alternated the two implementations, with 3 warm-up rounds and 10 measured rounds of 16 pairs. Across three processes, median time per mixed-size pair fell from 4.93 to 4.51 ms. The change was faster in 29/30 paired rounds. Two 2048² uploads gave 8.59 and 8.60 ms. The complete output buffers matched after large → small → large. These are CPU upload-preparation timings.I also applied the suggestion to
4eea047and ranresource::tests::buffer_data_reaches_the_host_texturewith a D3D12 device required. It passed.AI-assisted benchmark and review (Codex).
@Marvisak on GitHub · 2026-11-25 07:26 UTC · original · edited 2026-11-25 14:50 UTC
Automated triage for the maintainers.
Merge candidate. Re-checked at
81ebd7c, which is the same change rebased ontomain940d32f. It removes the per-textureLast::readbuffer incrates/victory-gpu/src/texture.rs. Before, every watchedStagingkept a CPU copy of its whole tiled texture for as long as it lived.Staging::refresh_nownow reads into one sharedREAD_SCRATCHbuffer, anddetilecopies out of it straight away, so nothing read the old per-texture copy afterwards. The scratch lock is always taken after the staging's ownlastlock, and nothing insidedetiletakes it again, so the lock order is consistent. The cost is that refreshes of different watched textures run one at a time, and the scratch buffer keeps the size of the largest texture read so far.Reply to @0xKaji: thanks for the rebase. CI
checknow passes on81ebd7c, so the earlier unrelatedvictory-shaderfailures are gone.CI: passing (
check).Generated by Claude Code
@0xKaji on GitHub · 2026-11-25 13:18 UTC · original
Rebased onto
main(940d32f) to pick up the hardware-test skip fixes and re-run CI. Verifiedcargo xtask policy(182 files ok) andcargo xwin clippy -p victory-gpu --tests --target x86_64-pc-windows-msvc --offline -- -D warnings(0 warnings).@0xKaji on GitHub · 2026-11-25 15:50 UTC · original
Superseded by
8f2a6f1on main, which already removes per-Staging Last::read and reuses a thread-local Scratch buffer with a 32 MiB retention cap.Pull request closed