GPU: depth twins share their scratch buffers (~280 MB video memory) #2162
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!2162
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2162/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?
@desplmfao on GitHub · 2026-11-25 06:42 UTC · original
desplmfao:fix/twin-shared-scratch→main· +30 −2 · 1 files · 1 commits · merged 2026-11-25 21:55 UTCProblem
Every writable depth twin (
twin.rs: a depth texture the title also writes through unordered views) makes a scratch buffer for its copies between the depth texture and the twin. The buffer is the size of the twin's planes and lives as long as the twin. Grand Theft Auto VI makes 315 twins in the menu already, so that's about 325 MB of video memory in scratch buffers that only matter during a copy.Change
The twins share scratch buffers: one per power-of-two size class (64 KiB minimum), made the first time a twin of that class needs one (
shared_scratch). Together they hold at most twice the largest.Sharing is safe because:
Twin::copystarts every use of the scratch buffer from the common state and ends with a transition back to it, so two copies through the same buffer in one list are ordered by that transition;Nothing else changes: same routes, same copies, same conversion shader.
Measured
Grand Theft Auto VI (Series X 1.0.2.1), RTX 5080, Linux, proton-cachyos 11.0. Live video memory by creation site, tracked with private data on each resource (diagnostics, not part of this PR):
mainThe twin textures themselves (318, 314 MB) are unchanged. No visible change to depth, shadows or lights in the world.
Tested
cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.victory-gputests on the RTX 5080 under Proton: 129 passed, 13 failed, the same asmainon this setup.twin::tests::copies_follow_the_side_each_use_needspasses.twin.rs(#1964, #2093).AI-assisted (Claude Code).
🤖 Generated with Claude Code
@Marvisak on GitHub · 2026-11-25 12:34 UTC · original
Automated triage for the maintainers.
Merge candidate. Depth twins in
crates/victory-gpu/src/twin.rsnow share their scratch buffers, one per power-of-two size class (shared_scratch), instead of each twin holding its own. The PR estimates this saves about 280 MB of video memory.I checked that sharing is safe in
Twin::copy. Every copy through a scratch buffer ends with an explicit transition back to the common state. So a later copy in the same list, which implicitly promotes the buffer toCOPY_DEST, is ordered after the earlier copy's reads. The host executes on one queue (host.rs). The classes are bounded (all together at most twice the largest).CI
checkpasses, and the branch merges cleanly withmain.Generated by Claude Code