GPU: reuse submit-time snapshots for repeated table CBVs #1316

Open
github-bot wants to merge 2 commits from github-bot/gh-1316 into main AGit
Owner

@⁠ByFxbian on GitHub · 2026-11-26 14:06 UTC · original
ByFxbian:perf/cbv-snapshot-reuse → main · +631 −17 · 7 files · 2 commits · open

Summary

Reuse submit-time constant-buffer snapshots when multiple descriptor table
bindings reference the same source range within a recording epoch.

Opt-in via VICTORY_CBV_SNAPSHOT_REUSE=1 (off by default).

The existing copied snapshot semantics, shader ABI and shader cache
compatibility are preserved.

Changes

  • Reuse scratch snapshots for matching table CBVs.
  • Invalidate reuse on deferred title-memory writes and copies.
  • Evict scratch-backed descriptor tables across command-list cuts.
  • Preserve pending GPU-write checks.
  • Retain the copied fallback for partial views.
  • Bound cache growth and expose diagnostic counters for hits, misses,
    avoided bytes and invalidations.

Performance

Windows, Ryzen 5 5600X, RTX 3070 8 GB, 32 GB RAM, ReBAR enabled.

22,000 synthetic constant-buffer bindings through the production
descriptor-table path.

Median CPU preparation and enqueue time:

Distinct sources Off On
64 15.131 ms 0.135 ms
1,024 14.934 ms 0.746 ms
4,096 15.008 ms 2.768 ms
22,000 14.890 ms 14.990 ms

With 64 distinct sources:

  • Fills: 22,000 -> 64
  • Copied bytes: 5,632,000 -> 16,384
  • GPU execution: approximately 1.327 ms in both modes

With entirely unique sources, median recording time increases from
36.288 to 40.761 ms. The benefit depends on the actual reuse rate,
which is why the optimization remains opt-in.

Validation

  • Native shader execution on a physical RTX 3070.
  • DXIL validation and exact GPU readback.
  • D3D12 debug layer and GPU-based validation.
  • Scalar/vector loads, guest alignment and boundary accesses.
  • CPU writes between submissions.
  • GPU test suites reproduced only the existing upstream Windows
    event-log permission failure.
  • Existing heap capability probe emits D3D12 message 645.
  • Asset policy and git diff --check passed.

Gameplay testing

No gameplay FPS improvement is claimed.

An A/B test with VICTORY_CBV_SNAPSHOT_REUSE=0 and 1 would
establish the actual reuse rate and whether the reduction in submission
work outweighs the recording overhead.

  • #1212 - repeated root-CBV staging reuse.
  • #742 - scratch-backed descriptor lifetime across command-list cuts.
**@⁠ByFxbian** on GitHub · 2026-11-26 14:06 UTC · [original](https://github.com/fxceless/victory-fork/pull/1316) `ByFxbian:perf/cbv-snapshot-reuse` → `main` · +631 −17 · 7 files · 2 commits · open ## Summary Reuse submit-time constant-buffer snapshots when multiple descriptor table bindings reference the same source range within a recording epoch. Opt-in via `VICTORY_CBV_SNAPSHOT_REUSE=1` (off by default). The existing copied snapshot semantics, shader ABI and shader cache compatibility are preserved. ## Changes - Reuse scratch snapshots for matching table CBVs. - Invalidate reuse on deferred title-memory writes and copies. - Evict scratch-backed descriptor tables across command-list cuts. - Preserve pending GPU-write checks. - Retain the copied fallback for partial views. - Bound cache growth and expose diagnostic counters for hits, misses, avoided bytes and invalidations. ## Performance Windows, Ryzen 5 5600X, RTX 3070 8 GB, 32 GB RAM, ReBAR enabled. 22,000 synthetic constant-buffer bindings through the production descriptor-table path. Median CPU preparation and enqueue time: | Distinct sources | Off | On | | ---: | ---: | ---: | | 64 | 15.131 ms | 0.135 ms | | 1,024 | 14.934 ms | 0.746 ms | | 4,096 | 15.008 ms | 2.768 ms | | 22,000 | 14.890 ms | 14.990 ms | With 64 distinct sources: - Fills: 22,000 -> 64 - Copied bytes: 5,632,000 -> 16,384 - GPU execution: approximately 1.327 ms in both modes With entirely unique sources, median recording time increases from 36.288 to 40.761 ms. The benefit depends on the actual reuse rate, which is why the optimization remains opt-in. ## Validation - Native shader execution on a physical RTX 3070. - DXIL validation and exact GPU readback. - D3D12 debug layer and GPU-based validation. - Scalar/vector loads, guest alignment and boundary accesses. - CPU writes between submissions. - GPU test suites reproduced only the existing upstream Windows event-log permission failure. - Existing heap capability probe emits D3D12 message 645. - Asset policy and git diff --check passed. ## Gameplay testing No gameplay FPS improvement is claimed. An A/B test with `VICTORY_CBV_SNAPSHOT_REUSE=0` and `1` would establish the actual reuse rate and whether the reduction in submission work outweighs the recording overhead. ## Related work - #1212 - repeated root-CBV staging reuse. - #742 - scratch-backed descriptor lifetime across command-list cuts.
Share fully covered, equal address-and-size table CBV snapshots within a
recording epoch when VICTORY_CBV_SNAPSHOT_REUSE=1. Keep the first fill for
submission dependency checks. Invalidate on deferred title writes and
evict scratch-backed table snapshots at cuts. Keep root CBV binding and
the shader ABI intact.

Adapt the snapshot approach from the NVIDIA integration, informed by
nicolasveilleux’s bounded root-CBV cache in fxceless/victory-fork#1212.
Credit AscilCH’s scratch-backed table eviction in fxceless/victory-fork#742.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:11:54 +00:00
Author
Owner

@⁠grosterr on GitHub · 2026-11-26 21:45 UTC · original

A heads-up for whoever merges this together with #860: the two do not conflict textually, but the result does not compile its tests. #860 changes fill_ahead::on() to fill_ahead::on(src, len) (whether a fill of len bytes at src may read ahead). This PR's copy_join_title_work_reset_and_pending_gpu_write_preserve_cbv_snapshots still calls fill_ahead::on():

error[E0061]: this function takes 2 arguments but 0 arguments were supplied
  if fill_ahead::on() { None } else { Some(WHY_READ) }

With #860 in, the test should ask about the same fill that blocked_by looks at, the 256 bytes at address:

if fill_ahead::on(address, 256) { None } else { Some(WHY_READ) }

With that one change, all 290 victory-gpu lib tests pass on our tree (fork main 52ac4ec + #1316 + #860 + others, Windows, RTX 3060). The release build is not affected, since only the test calls it that way.

**@⁠grosterr** on GitHub · 2026-11-26 21:45 UTC · [original](https://github.com/fxceless/victory-fork/pull/1316#issuecomment-7204026080) A heads-up for whoever merges this together with #860: the two do not conflict textually, but the result does not compile its tests. #860 changes `fill_ahead::on()` to `fill_ahead::on(src, len)` (whether a fill of `len` bytes at `src` may read ahead). This PR's `copy_join_title_work_reset_and_pending_gpu_write_preserve_cbv_snapshots` still calls `fill_ahead::on()`: ``` error[E0061]: this function takes 2 arguments but 0 arguments were supplied if fill_ahead::on() { None } else { Some(WHY_READ) } ``` With #860 in, the test should ask about the same fill that `blocked_by` looks at, the 256 bytes at `address`: ```rust if fill_ahead::on(address, 256) { None } else { Some(WHY_READ) } ``` With that one change, all 290 `victory-gpu` lib tests pass on our tree (fork main `52ac4ec` + #1316 + #860 + others, Windows, RTX 3060). The release build is not affected, since only the test calls it that way.
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 22:15 UTC · original · edited 2026-11-26 22:42 UTC

A source check against Zignixx’s current nvidia-wip (90fe3144a4c5fe8ca4e6ce1b5f0e42f4fb28696b) found that it does not contain VICTORY_CBV_SNAPSHOT_REUSE. Applying this PR’s 58de9bf..c5b0898 delta in a three-way check conflicts in copystat.rs, draw.rs, host.rs and list.rs. This is separate from grosterr’s #860 test helper note.

For the gameplay comparison mentioned in the description, I prepared a matched six-run checklist and tested the aggregate script on fixed inputs. It reports frame times and 1% lows plus the fraction of eligible lookups that hit. It flags missing ON diagnostics. I shared the optional check in #1379 with one person who already ran the scene. No scene result yet. Checklist and reproduction

AI-assisted source comparison and test tooling (Codex).

Update: I built the pinned diagnostic head and independently ran the same synthetic regression with reuse OFF and ON on RTX 4070 Ti SUPER (617.14). Both passed. Exact build, per-case measurements and analyzer controls. The game-scene A/B remains open.

**@⁠akimfomin** on GitHub · 2026-11-26 22:15 UTC · [original](https://github.com/fxceless/victory-fork/pull/1316#issuecomment-7204512012) · edited 2026-11-26 22:42 UTC A source check against Zignixx’s current `nvidia-wip` (`90fe3144a4c5fe8ca4e6ce1b5f0e42f4fb28696b`) found that it does not contain `VICTORY_CBV_SNAPSHOT_REUSE`. Applying this PR’s `58de9bf..c5b0898` delta in a three-way check conflicts in `copystat.rs`, `draw.rs`, `host.rs` and `list.rs`. This is separate from grosterr’s #860 test helper note. For the gameplay comparison mentioned in the description, I prepared a matched six-run checklist and tested the aggregate script on fixed inputs. It reports frame times and 1% lows plus the fraction of eligible lookups that hit. It flags missing ON diagnostics. I shared the optional check in #1379 with one person who already ran the scene. No scene result yet. [Checklist and reproduction](https://github.com/akimfomin/PortBridge/blob/e4963fffb7dd5188e9b54f60c67665f314a3ce14/audit/evidence/victory-cbv-ab.md) AI-assisted source comparison and test tooling (Codex). Update: I built the pinned diagnostic head and independently ran the same synthetic regression with reuse OFF and ON on RTX 4070 Ti SUPER (617.14). Both passed. [Exact build, per-case measurements and analyzer controls](https://github.com/akimfomin/PortBridge/blob/e4963fffb7dd5188e9b54f60c67665f314a3ce14/audit/evidence/victory-cbv-ab.md). The game-scene A/B remains open.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1316/head:github-bot/gh-1316'
git switch 'github-bot/gh-1316'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1316'
git switch 'github-bot/gh-1316'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1316'
git switch 'github-bot/gh-1316'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1316'
git switch 'main'
git merge --squash 'github-bot/gh-1316'
git switch 'main'
git merge --ff-only 'github-bot/gh-1316'
git switch 'main'
git merge 'github-bot/gh-1316'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.