GPU: heaps are bound again after a cut when ours stand in for both kinds (#2881) #2882

Open
github-bot wants to merge 1 commit from github-bot/gh-2882 into main AGit
Owner

@⁠BastienRodz on GitHub · 2026-11-25 23:01 UTC · original
BastienRodz:gpu/samplers-ours-not-lost-marker → main · +18 −2 · 1 files · 1 commits · open

What's wrong

#1778 gave our fallback sampler heap the marker value usize::MAX. MEMORY_HEAP (our view heap for title memory) already had that value, and so did the [usize::MAX; 2] that State::host_state_lost leaves in host_heaps so the next draw or dispatch binds its heaps again.

The collision hits a list that binds no sampler heap and reads title memory or root views. It wants [MEMORY_HEAP, SAMPLERS_OURS], which equals the lost-state marker, so bind_heaps binds nothing after:

  • a cut at Wait32BitValueX/Wait64BitValueX. The new host list starts with no heaps, and its next root signature indexes both heaps directly with none bound: the debug layer's 1419, a device removal on NVIDIA (#1754).
  • external::record. The other recorder's heaps stay bound.

Before #1778 that list wanted [usize::MAX, 0] and always bound its heaps again.

DirectX-Specs, SM 6.6 Dynamic Resources: "SetDescriptorHeaps must be called, passing the corresponding heaps, before a call to SetGraphicsRootSignature or SetComputeRootSignature that uses either CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED or SAMPLER_HEAP_DIRECTLY_INDEXED flags."

What the fix does

SAMPLERS_OURS becomes usize::MAX - 1, a value neither a title heap address nor the lost-state marker takes. A comment says why it can't be usize::MAX. Nothing else compares against it by value.

Tests

New draw::tests::heaps_are_bound_again_after_the_host_state_is_lost: after host_state_lost, wanted(..) differs from host_heaps for every combination of title heaps and memory heap. It needs no device.

  • On main it fails: [0, 0], memory heap true, left and right both [18446744073709551615, 18446744073709551615].
  • With the fix it passes, as does a_list_without_a_sampler_heap_gets_ours.

Run under Wine and vkd3d-proton. The draw::, descriptor:: and twin:: tests, one per process, give the same results with and without the fix except for the new test. cargo clippy --workspace --all-targets --locked -- -D warnings is clean.

Not tested

On Windows hardware or in game. How often a world frame binds no sampler heap while reading title memory, right after a cut, is not measured.

Fixes #2881

No game data. Found and written with AI assistance (Claude Code), reviewed and run locally.

🤖 Generated with Claude Code

**@⁠BastienRodz** on GitHub · 2026-11-25 23:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2882) `BastienRodz:gpu/samplers-ours-not-lost-marker` → `main` · +18 −2 · 1 files · 1 commits · open ## What's wrong #1778 gave our fallback sampler heap the marker value `usize::MAX`. `MEMORY_HEAP` (our view heap for title memory) already had that value, and so did the `[usize::MAX; 2]` that `State::host_state_lost` leaves in `host_heaps` so the next draw or dispatch binds its heaps again. The collision hits a list that binds no sampler heap and reads title memory or root views. It wants `[MEMORY_HEAP, SAMPLERS_OURS]`, which equals the lost-state marker, so `bind_heaps` binds nothing after: - a cut at `Wait32BitValueX`/`Wait64BitValueX`. The new host list starts with no heaps, and its next root signature indexes both heaps directly with none bound: the debug layer's 1419, a device removal on NVIDIA (#1754). - `external::record`. The other recorder's heaps stay bound. Before #1778 that list wanted `[usize::MAX, 0]` and always bound its heaps again. DirectX-Specs, SM 6.6 Dynamic Resources: "SetDescriptorHeaps must be called, passing the corresponding heaps, before a call to SetGraphicsRootSignature or SetComputeRootSignature that uses either CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED or SAMPLER_HEAP_DIRECTLY_INDEXED flags." ## What the fix does `SAMPLERS_OURS` becomes `usize::MAX - 1`, a value neither a title heap address nor the lost-state marker takes. A comment says why it can't be `usize::MAX`. Nothing else compares against it by value. ## Tests New `draw::tests::heaps_are_bound_again_after_the_host_state_is_lost`: after `host_state_lost`, `wanted(..)` differs from `host_heaps` for every combination of title heaps and memory heap. It needs no device. - On main it fails: `[0, 0], memory heap true`, left and right both `[18446744073709551615, 18446744073709551615]`. - With the fix it passes, as does `a_list_without_a_sampler_heap_gets_ours`. Run under Wine and vkd3d-proton. The `draw::`, `descriptor::` and `twin::` tests, one per process, give the same results with and without the fix except for the new test. `cargo clippy --workspace --all-targets --locked -- -D warnings` is clean. ## Not tested On Windows hardware or in game. How often a world frame binds no sampler heap while reading title memory, right after a cut, is not measured. Fixes #2881 No game data. Found and written with AI assistance (Claude Code), reviewed and run locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
#1778 made the sampler heap we bind when the title binds none
SAMPLERS_OURS = usize::MAX. Our view heap for title memory, MEMORY_HEAP
(memory::OURS), is usize::MAX too, and host_state_lost marks the host
list's heaps unknown with [usize::MAX; 2]. A draw or dispatch that wants
both of ours (the title binds no heap, its shaders use title memory or
root views) then wants exactly that marker, so bind_heaps found nothing to
change: after a cut at a Wait32/64BitValueX the new host list starts with
no heaps and none were set before the root signature, which indexes both
directly (SetDescriptorHeaps must come first: the debug layer's 1419,
INVALID_CALL on NVIDIA); after external::record the heaps of the other
recorder stayed bound. Before #1778 such a list wanted [usize::MAX, 0].

SAMPLERS_OURS is now usize::MAX - 1, which neither a title heap nor the
marker takes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:38 +00:00
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 23:04 UTC · original

Windows run of this head (00d163a, on main 842b0cb) on windows-latest, WARP, cargo test --workspace --locked --no-fail-fast -- --test-threads=1: https://github.com/BastienRodz/VIctory/actions/runs/45718036015

  • victory-gpu lib: 232 passed, 0 failed, 1 ignored, including draw::tests::heaps_are_bound_again_after_the_host_state_is_lost and draw::tests::a_list_without_a_sampler_heap_gets_ours.
  • Every other crate in the workspace: no failures.
**@⁠BastienRodz** on GitHub · 2026-11-25 23:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2882#issuecomment-7177121079) Windows run of this head (`00d163a`, on `main` `842b0cb`) on `windows-latest`, WARP, `cargo test --workspace --locked --no-fail-fast -- --test-threads=1`: https://github.com/BastienRodz/VIctory/actions/runs/45718036015 - `victory-gpu` lib: 232 passed, 0 failed, 1 ignored, including `draw::tests::heaps_are_bound_again_after_the_host_state_is_lost` and `draw::tests::a_list_without_a_sampler_heap_gets_ours`. - Every other crate in the workspace: no failures.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:10 UTC · original

Reviewed and verified 00d163a9 on Windows 11 (RTX 5090 + WARP) against main (842b0cb):

  • Changing SAMPLERS_OURS from usize::MAX to usize::MAX - 1 cleanly removes the sentinel collision with State::host_state_lost()'s [usize::MAX; 2] when both heaps stand in as [MEMORY_HEAP, SAMPLERS_OURS], and no other code in draw.rs conflicts with usize::MAX - 1.
  • Local checks: RTX 5090 & WARP draw::tests 21/21 (including heaps_are_bound_again_after_the_host_state_is_lost) and list::tests 4/4 passed, cargo clippy --locked -p victory-gpu --all-targets (default & --features diagnostics) 0 warnings, cargo xtask policy (191 files ok).

Looks clean and ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2882#issuecomment-7177231674) Reviewed and verified `00d163a9` on Windows 11 (RTX 5090 + WARP) against `main` (`842b0cb`): - Changing `SAMPLERS_OURS` from `usize::MAX` to `usize::MAX - 1` cleanly removes the sentinel collision with `State::host_state_lost()`'s `[usize::MAX; 2]` when both heaps stand in as `[MEMORY_HEAP, SAMPLERS_OURS]`, and no other code in `draw.rs` conflicts with `usize::MAX - 1`. - Local checks: RTX 5090 & WARP `draw::tests` 21/21 (including `heaps_are_bound_again_after_the_host_state_is_lost`) and `list::tests` 4/4 passed, `cargo clippy --locked -p victory-gpu --all-targets` (default & `--features diagnostics`) 0 warnings, `cargo xtask policy` (`191 files ok`). Looks clean and ready to merge.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-26 00:18 UTC · original

In-game evidence from @⁠wilu222 on #2896, which stacks this PR's commit (RTX 5070, Windows 10, VICTORY_D3D12_DEBUG=1): #2896

  • main 842b0cb: the debug layer logs SetComputeRootSignature: SetDescriptorHeaps must be called to bind a sampler descriptor before setting a root signature with D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED flag. id=1419 about 4 s after start, in a menu run and in a world run.
  • main + #2882 + #2896: no 1419 in a 60 s menu run.

The message names the sampler heap. That is the half this PR fixes: after a cut, a list with our view heap and our sampler heap wanted the lost-state marker and was never bound again. #2896 adds the view-heap half.

**@⁠BastienRodz** on GitHub · 2026-11-26 00:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2882#issuecomment-7178618252) In-game evidence from @⁠wilu222 on #2896, which stacks this PR's commit (RTX 5070, Windows 10, `VICTORY_D3D12_DEBUG=1`): https://git.gtahub.st/github/Marvisak--VIctory/pulls/2896 - `main` `842b0cb`: the debug layer logs `SetComputeRootSignature: SetDescriptorHeaps must be called to bind a sampler descriptor before setting a root signature with D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED flag. id=1419` about 4 s after start, in a menu run and in a world run. - `main` + #2882 + #2896: no 1419 in a 60 s menu run. The message names the sampler heap. That is the half this PR fixes: after a cut, a list with our view heap and our sampler heap wanted the lost-state marker and was never bound again. #2896 adds the view-heap half.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:27 UTC · original

Automated triage for the maintainers.

Merge candidate. This fixes a real collision in draw.rs: SAMPLERS_OURS and MEMORY_HEAP were both usize::MAX, so State::wanted could return [usize::MAX; 2], the value host_state_lost uses for "unknown", and bind_heaps then skipped SetDescriptorHeaps after a cut. usize::MAX - 1 cannot be a title heap address, and the test checks every combination of title and memory heaps against the lost state.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2882#issuecomment-7182618942) <!-- victory-triage v1 head=00d163a98aa93c8bb7848c69604a9f78fbb7f02d verdict=merge-candidate at=2026-11-26T04:27:50Z --> Automated triage for the maintainers. **Merge candidate.** This fixes a real collision in `draw.rs`: `SAMPLERS_OURS` and `MEMORY_HEAP` were both `usize::MAX`, so `State::wanted` could return `[usize::MAX; 2]`, the value `host_state_lost` uses for "unknown", and `bind_heaps` then skipped `SetDescriptorHeaps` after a cut. `usize::MAX - 1` cannot be a title heap address, and the test checks every combination of title and memory heaps against the lost state. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 23:34 UTC · original · reviewed

Nice catch — SAMPLERS_OURS == usize::MAX collided with the lost-state sentinel [MAX, MAX], so a no-heap list after a cut compared wanted==host_heaps and never re-bound. MAX-1 keeps the stand-in address distinct. The test asserts the invariant across all heap combos. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 23:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2882#pullrequestreview-6066470658) · **reviewed** Nice catch — SAMPLERS_OURS == usize::MAX collided with the lost-state sentinel [MAX, MAX], so a no-heap list after a cut compared wanted==host_heaps and never re-bound. MAX-1 keeps the stand-in address distinct. The test asserts the invariant across all heap combos. LGTM.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 09:49 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 21/21 passed on RTX 5090 and WARP (including heaps_are_bound_again_after_the_host_state_is_lost).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Clean fix ensuring stand-in heaps are rebound after a cut when ours stand in for both kinds (#2881).

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 09:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2882#pullrequestreview-6071848696) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 21/21 passed on RTX 5090 and WARP (including `heaps_are_bound_again_after_the_host_state_is_lost`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Clean fix ensuring stand-in heaps are rebound after a cut when ours stand in for both kinds (`#2881`). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 10:22 UTC · original · approved these changes

Looks good — minimal, exact fix for the sentinel collision between [MEMORY_HEAP, SAMPLERS_OURS] and State::host_state_lost()'s [usize::MAX; 2] in crates/victory-gpu/src/draw.rs.

Verified all references to SAMPLERS_OURS, MEMORY_HEAP, and host_heaps in draw.rs (no other code relies on SAMPLERS_OURS == usize::MAX), and checked git merge-tree against origin/main (63bcca43): clean.

Native Windows 11 hardware & WARP verification

  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): clean; cargo xtask policy: 191 files ok.
  • RTX 5090 cargo test -p victory-gpu --lib -- draw::tests:: --test-threads=1: 21/21 passed (heaps_are_bound_again_after_the_host_state_is_lost + a_list_without_a_sampler_heap_gets_ours included).
  • RTX 5090 + VICTORY_D3D12_DEBUG=1 (--features diagnostics): 21/21 passed.
  • WARP + VICTORY_D3D12_DEBUG=1 (--features diagnostics): 21/21 passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 10:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2882#pullrequestreview-6072345651) · **approved these changes** Looks good — minimal, exact fix for the sentinel collision between `[MEMORY_HEAP, SAMPLERS_OURS]` and `State::host_state_lost()`'s `[usize::MAX; 2]` in `crates/victory-gpu/src/draw.rs`. Verified all references to `SAMPLERS_OURS`, `MEMORY_HEAP`, and `host_heaps` in `draw.rs` (no other code relies on `SAMPLERS_OURS == usize::MAX`), and checked `git merge-tree` against `origin/main` (`63bcca43`): clean. ### Native Windows 11 hardware & WARP verification - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default & `--all-features`): clean; `cargo xtask policy`: 191 files ok. - RTX 5090 `cargo test -p victory-gpu --lib -- draw::tests:: --test-threads=1`: **21/21 passed** (`heaps_are_bound_again_after_the_host_state_is_lost` + `a_list_without_a_sampler_heap_gets_ours` included). - RTX 5090 + `VICTORY_D3D12_DEBUG=1` (`--features diagnostics`): **21/21 passed**. - WARP + `VICTORY_D3D12_DEBUG=1` (`--features diagnostics`): **21/21 passed**.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2882/head:github-bot/gh-2882'
git switch 'github-bot/gh-2882'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2882'
git switch 'github-bot/gh-2882'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2882'
git switch 'github-bot/gh-2882'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2882'
git switch 'main'
git merge --squash 'github-bot/gh-2882'
git switch 'main'
git merge --ff-only 'github-bot/gh-2882'
git switch 'main'
git merge 'github-bot/gh-2882'
git push origin 'main'
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/Marvisak--VIctory!2882
No description provided.