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

Open
BastienRodz wants to merge 1 commit from upstream-pr/2882 into main
BastienRodz commented 2026-11-25 23:01:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T23:01:11Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6615510544 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2882). Originally posted by [BastienRodz](https://github.com/BastienRodz) on 2026-11-25T23:01:11Z. --- ## 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)
BastienRodz commented 2026-11-25 23:06:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T23:04:44Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7177121079 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2882#issuecomment-7177121079). Originally posted by [BastienRodz](https://github.com/BastienRodz) on 2026-11-25T23:04:44Z. --- 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.
kotekompotek commented 2026-11-26 00:02:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:34:14Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066470658 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2882#pullrequestreview-6066470658). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:34:14Z. **Review:** COMMENTED --- 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.
fuzeofficlal commented 2026-11-26 00:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:10:38Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177231674 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2882#issuecomment-7177231674). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:10:38Z. --- 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.
BastienRodz commented 2026-11-26 01:03:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-26T00:18:24Z.


In-game evidence from @wilu222 on #2896, which stacks this PR's commit (RTX 5070, Windows 10, VICTORY_D3D12_DEBUG=1): https://github.com/Marvisak/VIctory/pull/2896#issuecomment-7178595855

  • 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7178618252 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2882#issuecomment-7178618252). Originally posted by [BastienRodz](https://github.com/BastienRodz) on 2026-11-26T00:18:24Z. --- In-game evidence from @wilu222 on #2896, which stacks this PR's commit (RTX 5070, Windows 10, `VICTORY_D3D12_DEBUG=1`): https://github.com/Marvisak/VIctory/pull/2896#issuecomment-7178595855 - `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.
Marvisak commented 2026-11-26 05:04:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:27:56Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182618942 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2882#issuecomment-7182618942). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:27:56Z. --- <!-- 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)_
Dukestar69 commented 2026-11-26 10:04:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T09:49:36Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6071848696 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2882#pullrequestreview-6071848696). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T09:49:36Z. **Review:** APPROVED --- 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).
fuzeofficlal commented 2026-11-26 11:03:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T10:22:51Z.

Review: APPROVED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6072345651 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2882#pullrequestreview-6072345651). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T10:22:51Z. **Review:** APPROVED --- 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 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/2882:upstream-pr/2882'
git switch 'upstream-pr/2882'

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/2882'
git switch 'upstream-pr/2882'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2882'
git switch 'upstream-pr/2882'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2882'
git switch 'main'
git merge --squash 'upstream-pr/2882'
git switch 'main'
git merge --ff-only 'upstream-pr/2882'
git switch 'main'
git merge 'upstream-pr/2882'
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
Marvisak/VIctory!2880
No description provided.