Shaders: the fused multiply-add probe binds a sampler heap #2920

Open
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/2922 into main
0xkn0wh3r3 commented 2026-11-26 00:10:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T00:10:18Z.


The problem

emit::host::Host::fuses_fmad runs once as the GPU host is made (victory-gpu's Host::new), to tell whether the GPU fuses mad. It records its dispatch with the root signature a translated program gets. That root signature, from root_signature_for, sets D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED, but the probe bound only the view heap. D3D12 requires a sampler heap to be bound before such a root signature is set; without one the behavior is undefined, and with the debug layer on every start reports:

id 1419: SetDescriptorHeaps must be called to bind a sampler descriptor before
setting a root signature with D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED

It is the first error of the run, so the debug layer's report of a later, unrelated failure can lead with it. The other probes in the file already bind a sampler heap.

The fix

The probe now binds a one-slot shader-visible sampler heap with its view heap. It samples nothing; the heap is there because the root signature requires it. It lives until the probe's fence wait completes, like the view heap.

Testing

There is no new test here. Checking for the error needs the debug layer enabled before the device is made, and the host is made once per process, so a test needs its own process; that harness stays in #2041. Coverage:

  • emit::semantics_tests::hosts_that_do_not_fuse_are_named runs fuses_fmad on WARP and the hardware adapter (no debug layer): passes, hardware adapter reports fused.
  • victory-gpu runs the probe while making its host, so with a diagnostics build and VICTORY_D3D12_DEBUG=1 the error above is what the debug layer reports at startup on main. With #2041's harness applied locally on top of this branch, host::tests::making_the_host_leaves_no_debug_layer_errors (with VICTORY_REQUIRE_DEBUG_LAYER=1, so a skip would fail) passes on an RTX 5070 Ti with the debug layer installed; with this commit's change reverted it fails with the error above. The harness is not part of this PR.
  • cargo test --release -p victory-shader --features host --lib on an RTX 5070 Ti: 298 passed. The 3 failures (emit::stride_tests::* x2, emit::synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way on main on this GPU (#1835); emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index was skipped (crashes the process on main here too).
  • cargo clippy -p victory-shader --all-targets, with and without --features host: clean. cargo xtask policy: ok.

Split out of #2041 at the triage's suggestion; #2041 keeps the debug-layer test harness.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6616442082 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2922). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T00:10:18Z. --- ## The problem `emit::host::Host::fuses_fmad` runs once as the GPU host is made (`victory-gpu`'s `Host::new`), to tell whether the GPU fuses `mad`. It records its dispatch with the root signature a translated program gets. That root signature, from `root_signature_for`, sets `D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED`, but the probe bound only the view heap. D3D12 requires a sampler heap to be bound before such a root signature is set; without one the behavior is undefined, and with the debug layer on every start reports: ``` id 1419: SetDescriptorHeaps must be called to bind a sampler descriptor before setting a root signature with D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED ``` It is the first error of the run, so the debug layer's report of a later, unrelated failure can lead with it. The other probes in the file already bind a sampler heap. ## The fix The probe now binds a one-slot shader-visible sampler heap with its view heap. It samples nothing; the heap is there because the root signature requires it. It lives until the probe's fence wait completes, like the view heap. ## Testing There is no new test here. Checking for the error needs the debug layer enabled before the device is made, and the host is made once per process, so a test needs its own process; that harness stays in #2041. Coverage: - `emit::semantics_tests::hosts_that_do_not_fuse_are_named` runs `fuses_fmad` on WARP and the hardware adapter (no debug layer): passes, hardware adapter reports fused. - `victory-gpu` runs the probe while making its host, so with a diagnostics build and `VICTORY_D3D12_DEBUG=1` the error above is what the debug layer reports at startup on `main`. With #2041's harness applied locally on top of this branch, `host::tests::making_the_host_leaves_no_debug_layer_errors` (with `VICTORY_REQUIRE_DEBUG_LAYER=1`, so a skip would fail) passes on an RTX 5070 Ti with the debug layer installed; with this commit's change reverted it fails with the error above. The harness is not part of this PR. - `cargo test --release -p victory-shader --features host --lib` on an RTX 5070 Ti: 298 passed. The 3 failures (`emit::stride_tests::*` x2, `emit::synthetic_tests::gathers_at_a_level_match_the_hardware`) fail the same way on `main` on this GPU (#1835); `emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index` was skipped (crashes the process on `main` here too). - `cargo clippy -p victory-shader --all-targets`, with and without `--features host`: clean. `cargo xtask policy`: ok. Split out of #2041 at the triage's suggestion; #2041 keeps the debug-layer test harness.
fuzeofficlal commented 2026-11-26 01:03:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:23:36Z.

Review: COMMENTED


Verified head cc785ae6 cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).

Code Review

  • Host::root_signature_for declares D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED, so binding a 1-slot shader-visible SAMPLER heap alongside views in fuses_fmad brings the probe in line with the draw and compute paths and satisfies the D3D12 debug layer / strict drivers.

Local Verification (VICTORY_D3D12_DEBUG=1)

  • cargo test --locked -p victory-shader --lib -- emit::host::tests emit::semantics_tests emit::flow_tests (RTX 5090 + WARP): 36/36 passed (1 pre-existing ignored), including semantics_tests::hosts_that_do_not_fuse_are_named.
  • cargo clippy --locked -p victory-shader --tests -- -D warnings (default and --all-features) & cargo xtask policy (191 files ok): clean.

Looks clean and ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066876859 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2922#pullrequestreview-6066876859). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:23:36Z. **Review:** COMMENTED --- Verified head `cc785ae6` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + `VICTORY_D3D12_DEBUG=1`). ### Code Review - `Host::root_signature_for` declares `D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED`, so binding a 1-slot shader-visible `SAMPLER` heap alongside `views` in `fuses_fmad` brings the probe in line with the `draw` and `compute` paths and satisfies the D3D12 debug layer / strict drivers. ### Local Verification (`VICTORY_D3D12_DEBUG=1`) - `cargo test --locked -p victory-shader --lib -- emit::host::tests emit::semantics_tests emit::flow_tests` (RTX 5090 + WARP): **36/36 passed** (1 pre-existing ignored), including `semantics_tests::hosts_that_do_not_fuse_are_named`. - `cargo clippy --locked -p victory-shader --tests -- -D warnings` (default and `--all-features`) & `cargo xtask policy` (`191 files ok`): clean. Looks clean and ready to merge.
kotekompotek commented 2026-11-26 01:03:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T00:26:30Z.

Review: COMMENTED


Same bug class as #2894's fix — the root signature flags SAMPLER_HEAP_DIRECTLY_INDEXED, so both heaps must be bound before SetComputeRootSignature even when nothing samples. Correct fix. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066896950 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2922#pullrequestreview-6066896950). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T00:26:30Z. **Review:** COMMENTED --- Same bug class as #2894's fix — the root signature flags SAMPLER_HEAP_DIRECTLY_INDEXED, so both heaps must be bound before SetComputeRootSignature even when nothing samples. Correct fix. LGTM.
Marvisak commented 2026-11-26 05:04:13 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Merge candidate. Host::fuses_fmad in emit/host.rs uses a root signature with SAMPLER_HEAP_DIRECTLY_INDEXED but bound only the view heap, which the debug layer reports as error 1419. The fix binds a one-slot shader-visible sampler heap as the other probes in the same file already do, and keeps it alive until the fence wait completes. Small and correct by my reading of the D3D12 rules.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182681973 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2922#issuecomment-7182681973). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:32:19Z. --- <!-- victory-triage v1 head=cc785ae686dbcccd76719c27dac39a6d9b5b637f verdict=merge-candidate at=2026-11-26T04:32:13Z --> Automated triage for the maintainers. **Merge candidate.** `Host::fuses_fmad` in `emit/host.rs` uses a root signature with `SAMPLER_HEAP_DIRECTLY_INDEXED` but bound only the view heap, which the debug layer reports as error 1419. The fix binds a one-slot shader-visible sampler heap as the other probes in the same file already do, and keeps it alive until the fence wait completes. Small and correct by my reading of the D3D12 rules. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 06:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:34:17Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • Diff review: Creating a 1-descriptor shader-visible sampler heap and binding it alongside views in Host::probe_fma satisfies D3D12's requirement when the root signature sets SAMPLER_HEAP_DIRECTLY_INDEXED, preventing debug-layer/driver validation errors even though the probe does not sample.
  • cargo test -p victory-shader emit::host -- --test-threads=1: 1 passed, 0 failed (parallel_warp_pipelines_and_draws).
  • cargo test -p victory-shader a_branch_to_fallthrough_keeps_both_values_at_a_join -- --test-threads=1 (RTX 5090 & WARP): 1 passed, 0 failed on both.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6069034001 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2922#pullrequestreview-6069034001). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T05:34:17Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - Diff review: Creating a 1-descriptor shader-visible sampler heap and binding it alongside `views` in `Host::probe_fma` satisfies D3D12's requirement when the root signature sets `SAMPLER_HEAP_DIRECTLY_INDEXED`, preventing debug-layer/driver validation errors even though the probe does not sample. - `cargo test -p victory-shader emit::host -- --test-threads=1`: 1 passed, 0 failed (`parallel_warp_pipelines_and_draws`). - `cargo test -p victory-shader a_branch_to_fallthrough_keeps_both_values_at_a_join -- --test-threads=1` (RTX 5090 & WARP): 1 passed, 0 failed on both. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/2922:upstream-pr/2922'
git switch 'upstream-pr/2922'

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