GPU: depth twins share their scratch buffers (~280 MB video memory) #2160

Merged
desplmfao merged 1 commit from upstream-pr/2162 into main 2026-11-25 21:55:14 +00:00
desplmfao commented 2026-11-25 06:42:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T06:42:01Z.


Problem

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::copy starts 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;
  • lists execute one after another on the host's single queue, so copies in different lists don't overlap either.

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):

main this PR
twin scratch buffers 315 buffers, 325 MB 6 buffers, 43 MB
game video memory, menu 5,843 MB 5,568 MB
frame time in the world 428–452 ms 430–460 ms

The 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-gpu tests on the RTX 5080 under Proton: 129 passed, 13 failed, the same as main on this setup. twin::tests::copies_follow_the_side_each_use_needs passes.
  • Merges without conflicts with the other open PRs that touch twin.rs (#1964, #2093).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6598843204 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2162). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T06:42:01Z. --- ## Problem 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::copy` starts 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; - lists execute one after another on the host's single queue, so copies in different lists don't overlap either. 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): | | `main` | this PR | |---|---|---| | twin scratch buffers | 315 buffers, 325 MB | 6 buffers, 43 MB | | game video memory, menu | 5,843 MB | 5,568 MB | | frame time in the world | 428–452 ms | 430–460 ms | The 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-gpu` tests on the RTX 5080 under Proton: 129 passed, 13 failed, the same as `main` on this setup. `twin::tests::copies_follow_the_side_each_use_needs` passes. - Merges without conflicts with the other open PRs that touch `twin.rs` (#1964, #2093). AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-25 08:06:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T07:17:30Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Depth twins share scratch buffers (~280 MB video memory saved) — scratch-memory dedup; big win if correct, check aliasing between twin formats.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053349914 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2162#pullrequestreview-6053349914). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T07:17:30Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Depth twins share scratch buffers (~280 MB video memory saved) — scratch-memory dedup; big win if correct, check aliasing between twin formats.
Marvisak commented 2026-11-25 13:02:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T12:34:53Z.


Automated triage for the maintainers.

Merge candidate. Depth twins in crates/victory-gpu/src/twin.rs now 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 to COPY_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 check passes, and the branch merges cleanly with main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162570325 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2162#issuecomment-7162570325). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T12:34:53Z. --- <!-- victory-triage v1 head=542154a99a9d53724e5717698eed7cc4515547c0 verdict=merge-candidate at=2026-11-25T13:33:00Z --> Automated triage for the maintainers. **Merge candidate.** Depth twins in `crates/victory-gpu/src/twin.rs` now 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 to `COPY_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 `check` passes, and the branch merges cleanly with `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 22:03:30 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2160
No description provided.