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

Manually merged
github merged 1 commit from gh-pr/2162/head into gh-pr/2162/base 2026-11-26 04:56:51 +00:00
Owner

@⁠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 UTC

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

**@⁠desplmfao** on GitHub · 2026-11-25 06:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2162) `desplmfao:fix/twin-shared-scratch` → `main` · +30 −2 · 1 files · 1 commits · merged 2026-11-25 21:55 UTC ## 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)
Each writable depth twin made a scratch buffer of its planes' size for
its copies and held it as long as the twin: about 325 MB of video memory
for Grand Theft Auto VI's 315 twins in the menu. The twins now take one
shared buffer per power-of-two size, at most twice the largest in all.

Every copy through a scratch buffer starts in the common state and
returns it there, so copies in one list are ordered by those transitions,
and lists run one after another on the host's single queue.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:50 +00:00
github manually merged commit 542154a99a into gh-pr/2162/base 2026-11-26 04:56:51 +00:00
Author
Owner

@⁠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.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

**@⁠Marvisak** on GitHub · 2026-11-25 12:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2162#issuecomment-7162570325) <!-- 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)_
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2162
No description provided.