GPU: clear cached bindings after an inline indirect clamp #251

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

@⁠loyodea on GitHub · 2026-11-26 12:40 UTC · original
loyodea:victory-serial-indirect → main · +76 −5 · 3 files · 2 commits · open

Related to #106. The inline indirect clamp binds its own pipeline and compute root signature. Invalidate the cached host bindings immediately after the clamp records, so returning early from rejected indexed-rectangle expansion cannot leave stale state for the next draw.

Tested

  • The synthetic indexed-rectangle regression reproduced a nonzero cached PSO after rejection on the previous code. It passed after the fix on a Radeon RX 9060 XT.
  • Seven indirect tests passed with VICTORY_HOIST_CLAMPS=0 and seven passed with the default mode 7.
  • The serial victory-gpu library suite reported 113 passed, one failed, and four ignored. Clean main 4f62c2a failed the same write-watch assertion.

Indexed rectangles use the inline path in both modes. The reported mode-0-only retail crash remains unverified. Codex helped implement and test this patch.

**@⁠loyodea** on GitHub · 2026-11-26 12:40 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/251) `loyodea:victory-serial-indirect` → `main` · +76 −5 · 3 files · 2 commits · open Related to #106. The inline indirect clamp binds its own pipeline and compute root signature. Invalidate the cached host bindings immediately after the clamp records, so returning early from rejected indexed-rectangle expansion cannot leave stale state for the next draw. **Tested** - The synthetic indexed-rectangle regression reproduced a nonzero cached PSO after rejection on the previous code. It passed after the fix on a Radeon RX 9060 XT. - Seven indirect tests passed with VICTORY_HOIST_CLAMPS=0 and seven passed with the default mode 7. - The serial victory-gpu library suite reported 113 passed, one failed, and four ignored. Clean main 4f62c2a failed the same write-watch assertion. Indexed rectangles use the inline path in both modes. The reported mode-0-only retail crash remains unverified. Codex helped implement and test this patch.
Invalidate the shared PSO and compute root immediately after recording the clamp, including when indexed rectangle expansion later rejects the draw. Cover the cache with an original D3D12 regression. Related to #106.

Co-authored-by: Codex <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:40:50 +00:00
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:25 UTC · original · reviewed

AI-assisted review. I inspected the inline-clamp invalidation path and its focused test statically; I did not run tests or a GPU/game build. This review suggests checking the following draw state.

**@⁠gut0to** on GitHub · 2026-11-26 16:25 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/251#pullrequestreview-6077522278) · **reviewed** AI-assisted review. I inspected the inline-clamp invalidation path and its focused test statically; I did not run tests or a GPU/game build. This review suggests checking the following draw state.
@ -2188,0 +2220,4 @@
assert!(!ran);
assert_eq!(
state.host_pipeline, 0,
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:25 UTC · original

AI-assisted review; I did not run tests. Could the test call prepare again after the rejected indexed rectangle and assert the graphics PSO cache is populated again before closing the list? The current assertion proves the cache was invalidated, but not that the next ordinary draw rebinds the pipeline that the clamp replaced.

**@⁠gut0to** on GitHub · 2026-11-26 16:25 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/251#discussion_r4711083668) AI-assisted review; I did not run tests. Could the test call `prepare` again after the rejected indexed rectangle and assert the graphics PSO cache is populated again before closing the list? The current assertion proves the cache was invalidated, but not that the next ordinary draw rebinds the pipeline that the clamp replaced.
@ -2188,0 +2220,4 @@
assert!(!ran);
assert_eq!(
state.host_pipeline, 0,
Author
Owner

@⁠loyodea on GitHub · 2026-11-26 18:53 UTC · original

Agreed. The current test verifies that the rejected indexed rectangle clears the cached PSO. Preparing an ordinary triangle draw on the same list and checking that it restores the original graphics PSO would cover the next draw's rebind.

**@⁠loyodea** on GitHub · 2026-11-26 18:53 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/251#discussion_r4712406383) Agreed. The current test verifies that the rejected indexed rectangle clears the cached PSO. Preparing an ordinary triangle draw on the same list and checking that it restores the original graphics PSO would cover the next draw's rebind.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 21:43 UTC · original

Tested natively on Windows 11, RX 7900 XT (RDNA3, driver 32.0.32029.2010). Head 2a6cca9, base 4f62c2a. Debug builds. Other heavy jobs were running on the machine.

Tests:

  • cargo test -p victory-gpu --lib: 4 runs each of base and PR, alternating. Clean runs: 113 passed on base, 114 on the PR, 4 ignored. The other runs failed only known flaky tests, seen on both sides (frame::tests::waits_end_on_ticks_and_count_frames, watch::tests, plus one query::tests on the PR and one pipeline::library on base).
  • With only the test applied to base, rejected_indexed_rectangle_leaves_the_inline_pipeline_cache_invalidated fails (cached PSO nonzero). It fails on the 7900 XT and on WARP (--features diagnostics, VICTORY_D3D12_WARP=1). With the PR it passes on both.
  • Clippy (-p victory-gpu --all-targets --no-deps): the same warnings on base and PR.

On the follow-up test from the review:

  • I wrote it locally. It prepares the next draw on the same list after the rejected rectangle and checks that the cache holds the original graphics PSO again. It passes with the PR.
  • It also passes on base. Base never clears the cache, so the cached value is already the original PSO, even though no SetPipelineState is recorded. So that check alone does not show a rebind happened. If it is added, the existing host_pipeline == 0 assertion should stay, because that is the one that catches this bug.
  • I also recorded that next draw and executed the list on WARP. On base, with the stale cache, the WARP device was not removed. No D3D12 debug layer is installed here, so I could not check the wrong-PSO draw with validation.

Scope of the fix (from reading the code; not covered by a test):

  • The clear now runs before indirect_rectangles. So it also covers non-indexed rectangle lists that are rejected after the clamp: a missing vertex view, a shadow not found, or rects::vertices / rects::records returning None. On main those also returned with the stale cache, and rects::vertices binds its own compute pipeline too.
  • The clamp does not call SetDescriptorHeaps and does not touch the graphics root. So clearing host_pipeline and host_roots[1] is enough.

With #212 and #227:

  • Hoisted clamps are recorded in the separate clamps list, so they do not touch the title list's cache.
  • Rectangle draws are never hoisted, so this path is inline in every VICTORY_HOIST_CLAMPS mode.
  • This PR merges cleanly with each of them (888d58a, acedbae).

Not tested: no game run, no #106 repro, no release build, no debug layer.

**@⁠adrianmjim** on GitHub · 2026-11-26 21:43 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/251#issuecomment-7204003829) Tested natively on Windows 11, RX 7900 XT (RDNA3, driver 32.0.32029.2010). Head 2a6cca9, base 4f62c2a. Debug builds. Other heavy jobs were running on the machine. Tests: - `cargo test -p victory-gpu --lib`: 4 runs each of base and PR, alternating. Clean runs: 113 passed on base, 114 on the PR, 4 ignored. The other runs failed only known flaky tests, seen on both sides (`frame::tests::waits_end_on_ticks_and_count_frames`, `watch::tests`, plus one `query::tests` on the PR and one `pipeline::library` on base). - With only the test applied to base, `rejected_indexed_rectangle_leaves_the_inline_pipeline_cache_invalidated` fails (cached PSO nonzero). It fails on the 7900 XT and on WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`). With the PR it passes on both. - Clippy (`-p victory-gpu --all-targets --no-deps`): the same warnings on base and PR. On the follow-up test from the review: - I wrote it locally. It prepares the next draw on the same list after the rejected rectangle and checks that the cache holds the original graphics PSO again. It passes with the PR. - It also passes on base. Base never clears the cache, so the cached value is already the original PSO, even though no SetPipelineState is recorded. So that check alone does not show a rebind happened. If it is added, the existing `host_pipeline == 0` assertion should stay, because that is the one that catches this bug. - I also recorded that next draw and executed the list on WARP. On base, with the stale cache, the WARP device was not removed. No D3D12 debug layer is installed here, so I could not check the wrong-PSO draw with validation. Scope of the fix (from reading the code; not covered by a test): - The clear now runs before `indirect_rectangles`. So it also covers non-indexed rectangle lists that are rejected after the clamp: a missing vertex view, a shadow not found, or `rects::vertices` / `rects::records` returning `None`. On main those also returned with the stale cache, and `rects::vertices` binds its own compute pipeline too. - The clamp does not call `SetDescriptorHeaps` and does not touch the graphics root. So clearing `host_pipeline` and `host_roots[1]` is enough. With #212 and #227: - Hoisted clamps are recorded in the separate clamps list, so they do not touch the title list's cache. - Rectangle draws are never hoisted, so this path is inline in every `VICTORY_HOIST_CLAMPS` mode. - This PR merges cleanly with each of them (888d58a, acedbae). Not tested: no game run, no #106 repro, no release build, no debug layer.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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