Draw: VICTORY_ROOT_BIND_CACHE=1 leaves out root bindings a list already has #3068

Closed
github-bot wants to merge 2 commits from github-bot/gh-3068 into main AGit
Owner

@⁠Adriwin06 on GitHub · 2026-11-29 19:52 UTC · original
Adriwin06:root-bind-cache → main · +251 −95 · 1 files · 2 commits · closed without merging

What it changes

Off by default. With VICTORY_ROOT_BIND_CACHE=1 a list remembers, per
graphics and compute root, the root constants and root resources
(tables, CBV/SRV/UAV addresses) it last set, and a SetRoot call that
would set the same value again is not recorded. The constants are
compared as a slice in a buffer reused in place, so the check allocates
nothing. What is remembered is cleared when the root signature changes,
when the tables are done, on reset and on replay.

Tests: draw::root_binding_tests.

Ported from stellarr-studio/kelvaroq patch 0031 (translated-root-state),
GPL-3.0-or-later.

How it was tested

  • GPU and profile: RTX 4070 SUPER, Ryzen 7 5800X. Not measured in the title on these commits by themselves: they come from a fork of mine that carries them with the rest of this set, and the title ran there. What is below is the unit tests on this branch.
  • Before: n/a (no in-title measurement on this branch)
  • After: n/a
  • cargo test passed for the crates it touches:
    • this change: yes, cargo test -p victory-gpu --lib -- draw::: 27 passed
  • cargo clippy --workspace --all-targets --locked: no finding that main does not already have (main has 34 of its own, which is why the Clippy step of CI is red on main itself).
  • cargo xtask policy: no new finding (main fails it on crates/victory-loader/src/heap_sites/frame_users.rs).
  • With all eleven of my pull requests merged together: cargo clippy also with --all-features adds no finding, and cargo test --workspace --locked fails only tests main also fails on this machine: the five shader tests that fail on main here too (WARP's SM 6.2 and the validator) (barycentric_tests::first_half_values_render_on_hardware_and_warp, hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves, rect::tests::rectangles_are_drawn_whole, rect::tests::the_rectangle_stage_is_a_geometry_shader) and xtask's repository_passes_policy (frame_users.rs). 2208 passed, including five that fail on main (three BCPack oracle tests, the menu save race, the shader key test).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:
    None found for VICTORY_ROOT_BIND_CACHE or skipping repeated root bindings.

🤖 Generated with Claude Code

**@⁠Adriwin06** on GitHub · 2026-11-29 19:52 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3068) `Adriwin06:root-bind-cache` → `main` · +251 −95 · 1 files · 2 commits · closed without merging ## What it changes Off by default. With VICTORY_ROOT_BIND_CACHE=1 a list remembers, per graphics and compute root, the root constants and root resources (tables, CBV/SRV/UAV addresses) it last set, and a Set*Root* call that would set the same value again is not recorded. The constants are compared as a slice in a buffer reused in place, so the check allocates nothing. What is remembered is cleared when the root signature changes, when the tables are done, on reset and on replay. Tests: draw::root_binding_tests. Ported from stellarr-studio/kelvaroq patch 0031 (translated-root-state), GPL-3.0-or-later. ## How it was tested - GPU and profile: RTX 4070 SUPER, Ryzen 7 5800X. Not measured in the title on these commits by themselves: they come from a fork of mine that carries them with the rest of this set, and the title ran there. What is below is the unit tests on this branch. - Before: n/a (no in-title measurement on this branch) - After: n/a - `cargo test` passed for the crates it touches: - this change: yes, `cargo test -p victory-gpu --lib -- draw::`: 27 passed - `cargo clippy --workspace --all-targets --locked`: no finding that main does not already have (main has 34 of its own, which is why the Clippy step of CI is red on main itself). - `cargo xtask policy`: no new finding (main fails it on crates/victory-loader/src/heap_sites/frame_users.rs). - With all eleven of my pull requests merged together: `cargo clippy` also with `--all-features` adds no finding, and `cargo test --workspace --locked` fails only tests main also fails on this machine: the five shader tests that fail on main here too (WARP's SM 6.2 and the validator) (barycentric_tests::first_half_values_render_on_hardware_and_warp, hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves, rect::tests::rectangles_are_drawn_whole, rect::tests::the_rectangle_stage_is_a_geometry_shader) and xtask's repository_passes_policy (frame_users.rs). 2208 passed, including five that fail on main (three BCPack oracle tests, the menu save race, the shader key test). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: None found for VICTORY_ROOT_BIND_CACHE or skipping repeated root bindings. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Off by default. With VICTORY_ROOT_BIND_CACHE=1 a list remembers, per
graphics and compute root, the root constants and root resources
(tables, CBV/SRV/UAV addresses) it last set, and a Set*Root* call that
would set the same value again is not recorded. The constants are
compared as a slice in a buffer reused in place, so the check allocates
nothing. What is remembered is cleared when the root signature changes,
when the tables are done, on reset and on replay.

Tests: draw::root_binding_tests.

Ported from stellarr-studio/kelvaroq patch 0031 (translated-root-state),
GPL-3.0-or-later.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 19:59:40 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-29 19:56 UTC · original · reviewed

A critical cache invalidation bug can retain a prior thread limit and suppress lanes in subsequent group-counted dispatches, requiring a cache update or invalidation and a regression test.

1 open issue
What changed in this PR

Adds an opt-in cache to the GPU draw path that skips redundant host D3D12 root-binding calls. The optimization is disabled by default.

Changes:

  • Tracks constants, descriptor tables, and resource addresses separately for graphics and compute roots.
  • Clears cached bindings on root-signature changes, table retirement, reset, and replay.
  • Adds unit tests for argument reuse, constant comparisons, and invalidation.
File Description
crates/​victory-gpu/​src/​draw.rs Implements VICTORY_ROOT_BIND_CACHE, integrates cached setters, and adds focused tests.

Review effort: Balanced

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-29 19:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3068#pullrequestreview-6104531999) · **reviewed** <!-- ccr-overview-v2 --> ### 🟡 Changes recommended A critical cache invalidation bug can retain a prior thread limit and suppress lanes in subsequent group-counted dispatches, requiring a cache update or invalidation and a regression test. <details open> <summary><strong>1 open issue</strong></summary> - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Invalidate root bind cache after thread-counted dispatch](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/3068) · New </details> <details> <summary><strong>What changed in this PR</strong></summary> Adds an opt-in cache to the GPU draw path that skips redundant host D3D12 root-binding calls. The optimization is disabled by default. **Changes:** - Tracks constants, descriptor tables, and resource addresses separately for graphics and compute roots. - Clears cached bindings on root-signature changes, table retirement, reset, and replay. - Adds unit tests for argument reuse, constant comparisons, and invalidation. | File | Description | | ---- | ----------- | | `crates/​victory-gpu/​src/​draw.rs` | Implements `VICTORY_ROOT_BIND_CACHE`, integrates cached setters, and adds focused tests. | </details> <sub>Review effort: Balanced</sub>
@ -2822,0 +2959,4 @@
&mut self.root_bindings[usize::from(compute)].constants,
param,
values,
root_bind_cache(),
Author
Owner

@⁠Copilot on GitHub · 2026-11-29 19:56 UTC · original

With VICTORY_ROOT_BIND_CACHE=1, this cache becomes stale after a thread-counted dispatch: dispatch directly overwrites USER_DISPATCH_THREADS_X via SetComputeRoot32BitConstant (line 4879), but the remembered slice still contains zero. A subsequent group-counted dispatch with otherwise identical arguments skips this full setter and retains the previous thread limit, suppressing lanes that should run. Update or invalidate the cached parameter after the partial write, and add a regression test for a thread-counted dispatch followed by a group-counted dispatch on the same root signature.

**@⁠Copilot** on GitHub · 2026-11-29 19:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3068#discussion_r4732921710) With `VICTORY_ROOT_BIND_CACHE=1`, this cache becomes stale after a thread-counted dispatch: `dispatch` directly overwrites `USER_DISPATCH_THREADS_X` via `SetComputeRoot32BitConstant` (line 4879), but the remembered slice still contains zero. A subsequent group-counted dispatch with otherwise identical arguments skips this full setter and retains the previous thread limit, suppressing lanes that should run. Update or invalidate the cached parameter after the partial write, and add a regression test for a thread-counted dispatch followed by a group-counted dispatch on the same root signature.
A dispatch counted in threads writes USER_DISPATCH_THREADS_X into the
bound root constants by itself (SetComputeRoot32BitConstant), after the
bind that set the word to 0. With VICTORY_ROOT_BIND_CACHE=1 the cache
still held 0 there, so the next dispatch with the same constants
(counted in groups) skipped its bind and ran with the previous
dispatch's thread limit, leaving lanes out. The dispatch now forgets
what the cache holds for that parameter, and the next bind sets it
whole again.

Every other write of a list's root state outside the bind path
(indirect batches and clamps, the ambient pass, mesh rests, descriptor
heaps) already resets host_roots, which clears the cache on the next
bind (change_root).

Test: draw::root_binding_tests::constants_written_behind_the_cache_are_bound_whole_again.
Found by Copilot's review of #3068.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ -2822,0 +2990,4 @@
&mut self.root_bindings[usize::from(compute)].constants,
param,
values,
root_bind_cache(),
Author
Owner

@⁠Adriwin06 on GitHub · 2026-11-29 20:01 UTC · original

Good catch, fixed in 58255583: the dispatch now forgets the cached constants for that parameter after its own SetComputeRoot32BitConstant, so the next bind re-emits them (the word goes back to 0). Every other write of the list's root state outside the bind path already resets host_roots, which clears the cache in change_root. Regression test: draw::root_binding_tests::constants_written_behind_the_cache_are_bound_whole_again.

**@⁠Adriwin06** on GitHub · 2026-11-29 20:01 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3068#discussion_r4732939385) Good catch, fixed in 58255583: the dispatch now forgets the cached constants for that parameter after its own `SetComputeRoot32BitConstant`, so the next bind re-emits them (the word goes back to 0). Every other write of the list's root state outside the bind path already resets `host_roots`, which clears the cache in `change_root`. Regression test: `draw::root_binding_tests::constants_written_behind_the_cache_are_bound_whole_again`.
Author
Owner

@⁠dyshay on GitHub · 2026-11-29 20:46 UTC · original

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.

**@⁠dyshay** on GitHub · 2026-11-29 20:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3068#issuecomment-7262353959) Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.
Author
Owner

@⁠tillo88 on GitHub · 2026-11-30 12:44 UTC · original

Measured with VICTORY_ROOT_BIND_CACHE=1 on top of v2026.11.29.05, 2 runs, against 18 runs of the release as it is.

fps ms/frame submitting thread ms refresh ms p95 ms p99 ms
v2026.11.29.05, 18 runs (mean) 29.40 37.4 31.4 8.21 57.3 138.7
with #3068, run 1 29.69 37.0 31.0 8.31 55.4 140.6
with #3068, run 2 30.37 35.6 30.6 8.10 55.7 136.7

Mean +2.1% fps (30.03 vs 29.40), with the submitting thread about 0.6 ms shorter. That is at the edge of what this bench can resolve: single baseline runs range from 27.8 to 30.6 fps (sd 0.7), so read it as "no loss, maybe a small gain". No crash in the 2 measured runs (the warm-up run ended in the known #2237 crash at +2:17, which about one in three runs of the release also hit; see #2237).

Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing off. Same save restored before each run (start of the game), prison cutscene, plane cutscene, first boat section, about 6 minutes; warm-up run not counted.

Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.

**@⁠tillo88** on GitHub · 2026-11-30 12:44 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3068#issuecomment-7278865350) Measured with `VICTORY_ROOT_BIND_CACHE=1` on top of **v2026.11.29.05**, 2 runs, against 18 runs of the release as it is. | | fps | ms/frame | submitting thread ms | refresh ms | p95 ms | p99 ms | |---|---|---|---|---|---|---| | v2026.11.29.05, 18 runs (mean) | 29.40 | 37.4 | 31.4 | 8.21 | 57.3 | 138.7 | | with #3068, run 1 | 29.69 | 37.0 | 31.0 | 8.31 | 55.4 | 140.6 | | with #3068, run 2 | 30.37 | 35.6 | 30.6 | 8.10 | 55.7 | 136.7 | Mean +2.1% fps (30.03 vs 29.40), with the submitting thread about 0.6 ms shorter. That is at the edge of what this bench can resolve: single baseline runs range from 27.8 to 30.6 fps (sd 0.7), so read it as "no loss, maybe a small gain". No crash in the 2 measured runs (the warm-up run ended in the known #2237 crash at +2:17, which about one in three runs of the release also hit; see #2237). Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing off. Same save restored before each run (start of the game), prison cutscene, plane cutscene, first boat section, about 6 minutes; warm-up run not counted. Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.
github-bot closed this pull request 2026-12-01 18:59:16 +00:00

Pull request closed

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/trustno1-coder--VIctory-NVIDIA!3068
No description provided.