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

Open
ByFxbian wants to merge 2 commits from upstream-pr/1316 into main
ByFxbian commented 2026-11-26 14:06:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ByFxbian on 2026-11-26T14:06:36Z.


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.
<!-- greyfinch-sync:fxceless/victory-fork:issue:5511489212 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1316). Originally posted by [ByFxbian](https://github.com/ByFxbian) on 2026-11-26T14:06:36Z. --- ## 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.
grosterr commented 2026-11-26 21:45:13 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by grosterr on 2026-11-26T21:45:13Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7204026080 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1316#issuecomment-7204026080). Originally posted by [grosterr](https://github.com/grosterr) on 2026-11-26T21:45:13Z. --- 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.
akimfomin commented 2026-11-26 22:15:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by akimfomin on 2026-11-26T22:15:37Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7204512012 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1316#issuecomment-7204512012). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-26T22:15:37Z. --- 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.
KainanP commented 2026-11-27 15:13:45 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-27T15:13:45Z.


Independent A/B of this PR on the RTX 4060 Laptop, against its own merge base 58de9bf (the PR is 43 commits behind main and conflicts).

Bench: pipeline::list_bench::table_bench (KainanP/victory-fork bench/desc-tables, #[ignore]) ports the draw sequence of our VIctory list bench to the fork. Each draw binds a material table (one constant buffer view and five textures the title placed in memory), and each table sits at its own place in the title's heap. A list has 2,000 tables, and half of them repeat the contents of an earlier one, as in #1379. A list is closed (timed) and reset every 2,000 draws. Cells are ns per draw for the whole sequence (table, root CBV, 4 constants, index buffer, draw), each the median of 7 interleaved processes, each process the best of 5. RTX 4060 Laptop, i7-14650HX. A headless Chrome from other work used about 2 cores. This bench times recording only: lists are not submitted, so fills done at submission do not show here.

build 1 thread 5 threads (per thread)
base 58de9bf 10,321 16,054
PR c5b0898, switch off 10,451 16,069
PR, VICTORY_CBV_SNAPSHOT_REUSE=1 10,435 16,954

An earlier run of 7 gave the same picture: base 11,919 / 24,308, on 12,107 / 26,944. The PR with the switch off was 20,439 / 29,379 in that run, but its single runs ranged from 11.5 to 34 µs, so that cell is noise.

So on the recording threads it is neutral within noise. That is expected: the saving is the snapshot fills at submission (your 22,000 → 64 fills), which this bench does not time. It does not touch the part #1379 measured as most of the 18-21 µs. In a diagnostics build here, of a 6-slot table, the five texture views take about 10 µs, making the entries readable about 6 µs, and the constant view 0.6 µs.

Correctness. With VICTORY_CBV_SNAPSHOT_REUSE=1:

  • our tables_show_their_views passes: every texture slot of the tables made for 64 draws, in three lists, holds the descriptor the host makes of its view, and holds its host texture;
  • a_cut_records_a_new_snapshot_even_with_the_same_table, constant_snapshots_observe_copy_epochs_and_fall_back_for_partial_views and copy_join_title_work_reset_and_pending_gpu_write_preserve_cbv_snapshots pass;
  • bench_cbv_snapshot_bindings stops at its precondition here (it needs SM 6.6 dxil.dll and VICTORY_LATE_WAIT=3), so I did not run it.

For the texture-view part, #1484 copies views from a cache with exact invalidation: −20 % table time at 1 thread, −27 % at 5.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7221792472 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1316#issuecomment-7221792472). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T15:13:45Z. --- Independent A/B of this PR on the RTX 4060 Laptop, against its own merge base `58de9bf` (the PR is 43 commits behind `main` and conflicts). **Bench:** `pipeline::list_bench::table_bench` ([KainanP/victory-fork `bench/desc-tables`](https://github.com/KainanP/victory-fork/commit/8099f728afae8ed80ac4deff2f471ae3683aa589), `#[ignore]`) ports the draw sequence of our VIctory list bench to the fork. Each draw binds a material table (one constant buffer view and five textures the title placed in memory), and each table sits at its own place in the title's heap. A list has 2,000 tables, and half of them repeat the contents of an earlier one, as in #1379. A list is closed (timed) and reset every 2,000 draws. Cells are ns per draw for the whole sequence (table, root CBV, 4 constants, index buffer, draw), each the median of 7 interleaved processes, each process the best of 5. RTX 4060 Laptop, i7-14650HX. A headless Chrome from other work used about 2 cores. This bench times **recording only**: lists are not submitted, so fills done at submission do not show here. | build | 1 thread | 5 threads (per thread) | |---|---|---| | base `58de9bf` | 10,321 | 16,054 | | PR `c5b0898`, switch off | 10,451 | 16,069 | | PR, `VICTORY_CBV_SNAPSHOT_REUSE=1` | 10,435 | 16,954 | An earlier run of 7 gave the same picture: base 11,919 / 24,308, on 12,107 / 26,944. The PR with the switch off was 20,439 / 29,379 in that run, but its single runs ranged from 11.5 to 34 µs, so that cell is noise. So on the recording threads it is neutral within noise. That is expected: the saving is the snapshot fills at submission (your 22,000 → 64 fills), which this bench does not time. It does not touch the part #1379 measured as most of the 18-21 µs. In a diagnostics build here, of a 6-slot table, the five texture views take about 10 µs, making the entries readable about 6 µs, and the constant view 0.6 µs. **Correctness.** With `VICTORY_CBV_SNAPSHOT_REUSE=1`: - our `tables_show_their_views` passes: every texture slot of the tables made for 64 draws, in three lists, holds the descriptor the host makes of its view, and holds its host texture; - `a_cut_records_a_new_snapshot_even_with_the_same_table`, `constant_snapshots_observe_copy_epochs_and_fall_back_for_partial_views` and `copy_join_title_work_reset_and_pending_gpu_write_preserve_cbv_snapshots` pass; - `bench_cbv_snapshot_bindings` stops at its precondition here (it needs SM 6.6 `dxil.dll` and `VICTORY_LATE_WAIT=3`), so I did not run it. For the texture-view part, #1484 copies views from a cache with exact invalidation: −20 % table time at 1 thread, −27 % at 5. _AI use: Claude Code (Claude Opus 5.5)._
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1316:upstream-pr/1316'
git switch 'upstream-pr/1316'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1316'
git switch 'upstream-pr/1316'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1316'
git switch 'upstream-pr/1316'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1316'
git switch 'main'
git merge --squash 'upstream-pr/1316'
git switch 'main'
git merge --ff-only 'upstream-pr/1316'
git switch 'main'
git merge 'upstream-pr/1316'
git push origin 'main'
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
fxceless/victory-fork!1313
No description provided.