Skip to content

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

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
desplmfao:fix/twin-shared-scratch
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
desplmfao:fix/twin-shared-scratch

Conversation

@desplmfao

Copy link
Copy Markdown
Contributor

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

AI-assisted (Claude Code).

🤖 Generated with 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 <noreply@anthropic.com>

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

juanfariasdev pushed a commit to juanfariasdev/VIctory that referenced this pull request Nov 25, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
The previous main (old upstream base) is the first parent; the second is
upstream main with the current heads of our pull requests merged in:
Marvisak#2143, Marvisak#1849 (carried onto main's per-region runtime_pages), Marvisak#259, Marvisak#491,
Marvisak#2153, Marvisak#2099, Marvisak#2071 (main covers it), Marvisak#2162, Marvisak#2218, Marvisak#2088, Marvisak#2389, Marvisak#177's
element-type key on main's three handle maps, and the README. Marvisak#2112
(opt-in, in place) stays in the renderer branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@Marvisak
Marvisak merged commit 9a12a45 into Marvisak:main Nov 25, 2026
1 check passed
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…erged)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	README.md
#	crates/victory-gpu/src/descriptor.rs
#	crates/victory-gpu/src/pipeline.rs
#	crates/victory-gpu/src/pipeline/library.rs
#	crates/victory-hle/src/modules/gameinput.rs
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
Upstream main merged Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906 and Marvisak#1152 and took up what
Marvisak#1769 (LDS bounds, Marvisak#1949) and Marvisak#1763 (typed UAV formats, Marvisak#2462) did; main's
code is kept for those.
- emit/lower.rs: ds_bpermute within each half (main's Marvisak#573, same as
  Marvisak#439's); LDS bounds as main's Marvisak#1949 (Marvisak#1769's test-only counter kept, its
  and_guard dropped); title-memory marks: main's straddling-write lookup
  (Marvisak#2484) with Marvisak#2167's current head (3cb308d, rebased on 63bcca4): guarded
  dirty atomics, raw_dword2, memory_null, synthetic_mark_dxil in
  lower/mark_tests.rs; the old Marvisak#2167 head taken out first.
- emit/host.rs: main's shared WARP device and lock (Marvisak#244) with Marvisak#439's
  adapter list and Host::on (create_device takes an optional adapter).
- descriptor/host.rs: main's Marvisak#2462 format checks; Marvisak#1763's tests kept.
- gpu host.rs: main's multi-plane present with Marvisak#2310's crumbed copy.
- pipeline.rs: Marvisak#2118/Marvisak#2311's builder and BVH checks with main's skip
  hashes (Marvisak#1320); draw.rs, shadow.rs, main.rs: both sides.
- Tests main added since get Marvisak#439's Parts fields and emit's Target.
- README: base 63bcca4; rows of PRs merged upstream, superseded or closed
  taken out, with a note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
The previous renderer (old upstream base 940d32f) is the first parent and
is also kept as the branch renderer-2026-11-25-oldbase; the second parent
is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with
the renderer stack merged on it: Marvisak#439 (on main: update/439-main's
resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292,
Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small
windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes.
Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by
main: Marvisak#1769, Marvisak#1763, Marvisak#2366.

The picture on this base still shows the overlay that plain upstream main
shows too; that is being looked into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants