Skip to content

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

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/samplers-ours-not-lost-marker
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/samplers-ours-not-lost-marker

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

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:

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

Marvisak#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 Marvisak#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 <noreply@anthropic.com>
@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

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

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.

Copy link
Copy Markdown
Owner

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

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU: after a cut, a list using our view heap and our sampler heap never binds them again (SAMPLERS_OURS equals the lost-state marker)

5 participants