Shaders/Emit: clear D3D12 filter reduction bits (0x180) before setting comparison bit (0x80) #2983

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

@⁠RVZO6 on GitHub · 2026-11-26 02:09 UTC · original
RVZO6:rvzo/cmp-sampler-reduction-mask → main · +106 −1 · 1 files · 1 commits · open

StaticSampler::from_words encodes D3D12_FILTER_REDUCTION_TYPE in bits 7..=8 (0x000 Standard, 0x080 Comparison, 0x100 Minimum, 0x180 Maximum).

emit::emit previously updated comparison-sampled immediate samplers with s.filter |= 0x80 without clearing bit 8 (0x100), which turned a Minimum-reduction immediate sampler (0x100) into 0x180 (D3D12_FILTER_MAXIMUM_*) instead of 0x080 (D3D12_FILTER_COMPARISON_*), and left a Maximum-reduction sampler at 0x180.

Mask out 0x180 before setting 0x80 (s.filter = (s.filter & !0x180) | 0x80), matching the reduction mask already used in StaticSampler::filter_for_host.

Verification

  • Negative control (before fix): immediate_comparison_sampler_clears_min_max_reduction_bits failed with left: 384 (0x180), right: 128 (0x080).
  • After fix: passes for both Minimum (1 << 29) and Maximum (2 << 29) reduction immediate samplers used with image_sample_c_lz, including dxil.dll validation.
  • Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + --tests + --features diagnostics clippy, xtask policy, full workspace tests): RVZO6/VIctory CI run #45738573777 (green, combined Wave 8 check on 63bcca4).
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon).

**@⁠RVZO6** on GitHub · 2026-11-26 02:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2983) `RVZO6:rvzo/cmp-sampler-reduction-mask` → `main` · +106 −1 · 1 files · 1 commits · open `StaticSampler::from_words` encodes `D3D12_FILTER_REDUCTION_TYPE` in bits `7..=8` (`0x000` Standard, `0x080` Comparison, `0x100` Minimum, `0x180` Maximum). `emit::emit` previously updated comparison-sampled immediate samplers with `s.filter |= 0x80` without clearing bit 8 (`0x100`), which turned a Minimum-reduction immediate sampler (`0x100`) into `0x180` (`D3D12_FILTER_MAXIMUM_*`) instead of `0x080` (`D3D12_FILTER_COMPARISON_*`), and left a Maximum-reduction sampler at `0x180`. Mask out `0x180` before setting `0x80` (`s.filter = (s.filter & !0x180) | 0x80`), matching the reduction mask already used in `StaticSampler::filter_for_host`. ### Verification - **Negative control (before fix):** `immediate_comparison_sampler_clears_min_max_reduction_bits` failed with `left: 384 (0x180), right: 128 (0x080)`. - **After fix:** passes for both Minimum (`1 << 29`) and Maximum (`2 << 29`) reduction immediate samplers used with `image_sample_c_lz`, including `dxil.dll` validation. - Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + `--tests` + `--features diagnostics` clippy, `xtask policy`, full workspace tests): [RVZO6/VIctory CI run #45738573777](https://github.com/RVZO6/VIctory/actions/runs/45738573777) (green, combined Wave 8 check on `63bcca4`). - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
StaticSampler::from_words encodes D3D12_FILTER_REDUCTION_TYPE in bits
7..=8 (0x000 Standard, 0x080 Comparison, 0x100 Minimum, 0x180 Maximum).
emit::emit previously updated comparison-sampled immediate samplers with
`s.filter |= 0x80` without clearing bit 8, which turned a MINIMUM
reduction sampler (0x100) into MAXIMUM (0x180) instead of COMPARISON
(0x080).

Mask out 0x180 before ORing 0x80 (`(s.filter & !0x180) | 0x80`),
matching the reduction mask already used in StaticSampler::filter_for_host.
Regression test verifies both MINIMUM (1 << 29) and MAXIMUM (2 << 29)
immediate samplers used with image_sample_c_lz (reproduced failure
left=0x180 vs right=0x080 before the fix; passes with DXIL validation
after).

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:18 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 02:33 UTC · original

Independent test report for head 840ad8b541a36b989f12a10f424a923e6da0b2b1 (parent 63bcca43c6a00a758510398fa43096ce7e4f7df0), per the claim in #1633.

Environment: Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, clean detached checkouts. CARGO_TARGET_DIR=D:\victory-2983-2980-warp-target, VICTORY_WARP=1, VICTORY_D3D12_WARP=1, VICTORY_DXIL=C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxil.dll (file version 1.8.2502.11). With VICTORY_WARP=1, emit::host::Host::new always creates its device on EnumWarpAdapter, so no physical GPU was used. The machine has one, but no test ran on it. Synthetic programs only, no game data.

Focused test (head): cargo test -j 4 --locked -p victory-shader emit::tests::immediate_comparison_sampler_clears_min_max_reduction_bits -- --exact: 1 passed, 0 failed.

  • Validator check: the same command with VICTORY_DXIL=C:\nonexistent\dxil.dll panics at the test's Validator::load(..).unwrap() (cannot load C:\nonexistent\dxil.dll). So the passing run really loaded the SDK dxil.dll and validated both reductions' DXIL.

Parent control (scratch, test-only): parent 63bcca4 plus only the new test hunk (no fix; s.filter |= 0x80 still in place). This tree is not a commit. The same command gave 1 failed: comparison sample slot must have D3D12_FILTER_REDUCTION_TYPE_COMPARISON (0x80), left: 384, right: 128.

Crate suite: cargo test -j 4 --locked --no-fail-fast -p victory-shader

  • head: lib 299 passed, 4 failed, 3 ignored; tests/resource_tracking.rs 3 passed, 1 ignored; doctests 0.
  • parent (clean): lib 298 passed, 4 failed, 3 ignored, with the same 4 failures.
  • The 4 failures are emit::synthetic_tests::{gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out, permutes_mask_high_address_bits_and_divergent_branches, a_mask_joined_with_data_at_a_uniform_loop_is_its_number}. They come from this environment, not from this PR: with VICTORY_WARP=1, their "hardware" iteration (Host::new(false)) also runs on WARP, so its hardware-only assertions fail ("no pipeline for a wave of 32", and the gather rounding check).

Lint: cargo clippy -j 4 --locked -p victory-shader --all-targets showed no warnings. rustfmt --check --edition 2024 on crates/victory-shader/src/emit/mod.rs reports 4 diffs on the head and 2 on the parent. The 2 new ones are in the added test, at the for (reduction_bits, ...) line and the aligned comments on the instruction words. They are formatting only.

Not run: any hardware GPU, the title, CI.

Result: on WARP, the fix makes the new regression test pass and DXIL validation succeed. The same test fails on the parent without the fix. No new failures in the crate suite.

AI use: Claude Code (Claude Opus 5.5), coordinated by Codex (gpt-6.2-sol). I ran the commands above and report their real output.

**@⁠oni-swr** on GitHub · 2026-11-26 02:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2983#issuecomment-7180917517) Independent test report for head `840ad8b541a36b989f12a10f424a923e6da0b2b1` (parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`), per the claim in #1633. **Environment:** Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, clean detached checkouts. `CARGO_TARGET_DIR=D:\victory-2983-2980-warp-target`, `VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, `VICTORY_DXIL=C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxil.dll` (file version 1.8.2502.11). With `VICTORY_WARP=1`, `emit::host::Host::new` always creates its device on `EnumWarpAdapter`, so no physical GPU was used. The machine has one, but no test ran on it. Synthetic programs only, no game data. **Focused test (head):** `cargo test -j 4 --locked -p victory-shader emit::tests::immediate_comparison_sampler_clears_min_max_reduction_bits -- --exact`: 1 passed, 0 failed. - Validator check: the same command with `VICTORY_DXIL=C:\nonexistent\dxil.dll` panics at the test's `Validator::load(..).unwrap()` (`cannot load C:\nonexistent\dxil.dll`). So the passing run really loaded the SDK `dxil.dll` and validated both reductions' DXIL. **Parent control (scratch, test-only):** parent `63bcca4` plus only the new test hunk (no fix; `s.filter |= 0x80` still in place). This tree is not a commit. The same command gave 1 failed: `comparison sample slot must have D3D12_FILTER_REDUCTION_TYPE_COMPARISON (0x80)`, `left: 384`, `right: 128`. **Crate suite:** `cargo test -j 4 --locked --no-fail-fast -p victory-shader` - head: lib 299 passed, 4 failed, 3 ignored; `tests/resource_tracking.rs` 3 passed, 1 ignored; doctests 0. - parent (clean): lib 298 passed, 4 failed, 3 ignored, with the same 4 failures. - The 4 failures are `emit::synthetic_tests::{gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out, permutes_mask_high_address_bits_and_divergent_branches, a_mask_joined_with_data_at_a_uniform_loop_is_its_number}`. They come from this environment, not from this PR: with `VICTORY_WARP=1`, their "hardware" iteration (`Host::new(false)`) also runs on WARP, so its hardware-only assertions fail ("no pipeline for a wave of 32", and the gather rounding check). **Lint:** `cargo clippy -j 4 --locked -p victory-shader --all-targets` showed no warnings. `rustfmt --check --edition 2024` on `crates/victory-shader/src/emit/mod.rs` reports 4 diffs on the head and 2 on the parent. The 2 new ones are in the added test, at the `for (reduction_bits, ...)` line and the aligned comments on the instruction words. They are formatting only. **Not run:** any hardware GPU, the title, CI. Result: on WARP, the fix makes the new regression test pass and DXIL validation succeed. The same test fails on the parent without the fix. No new failures in the crate suite. AI use: Claude Code (Claude Opus 5.5), coordinated by Codex (gpt-6.2-sol). I ran the commands above and report their real output.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 02:36 UTC · original

Confirmed the visible effect on a physical RTX 5080 and Microsoft WARP. Both drivers accepted the graphics pipeline with the old emitter, then produced different wrong pixels. With 840ad8b5, both returned the expected RGBA values on all 24 draws (384 pixels per adapter).

I drew a synthetic full-screen triangle to an RGBA32F target. Its translated pixel shader used the same immediate sampler descriptor for ordinary image_sample (R) and image_sample_c_lz (G/B/A). The root signature contained the two emitted static samplers. A 2×2 R32_FLOAT depth SRV held 0.125, 0.375, 0.625 and 0.875. Bilinear sampling at its center gives four equal weights, so for a reference of 0.375 the expected comparison result is 0.50 for LESS and 0.75 for LESS_EQUAL.

Minimum-reduction input, reference 0.375, LESS Ordinary sample Comparison sample
Old emitter on RTX 5080 0.125 0.875
Old emitter on WARP 0.125 1.0
PR head on both 0.125 0.50

Across standard, minimum and maximum reductions, two comparison functions and four reference depths, the old one-line behavior gave 256/384 incorrect pixels on RTX and 128/384 on WARP. The ordinary sample stayed at 0.50 (standard), 0.125 (minimum) or 0.875 (maximum) before and after the change. The DXIL validator accepted every shader in both runs.

The existing shader cache keys translations by the translator source hash, which includes this edit to emit/mod.rs. The pipeline prebuild tag includes that hash too. Shader source hashing · Shader cache key · Pipeline prebuild tag

**@⁠steven-seagull27** on GitHub · 2026-11-26 02:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2983#issuecomment-7180953436) Confirmed the visible effect on a physical RTX 5080 and Microsoft WARP. Both drivers accepted the graphics pipeline with the old emitter, then produced different wrong pixels. With `840ad8b5`, both returned the expected RGBA values on all 24 draws (384 pixels per adapter). I drew a synthetic full-screen triangle to an RGBA32F target. Its translated pixel shader used the **same immediate sampler descriptor** for ordinary `image_sample` (R) and `image_sample_c_lz` (G/B/A). The root signature contained the two emitted static samplers. A 2×2 R32_FLOAT depth SRV held 0.125, 0.375, 0.625 and 0.875. Bilinear sampling at its center gives four equal weights, so for a reference of 0.375 the expected comparison result is 0.50 for LESS and 0.75 for LESS_EQUAL. | Minimum-reduction input, reference 0.375, LESS | Ordinary sample | Comparison sample | |---|---:|---:| | Old emitter on RTX 5080 | 0.125 | 0.875 | | Old emitter on WARP | 0.125 | 1.0 | | PR head on both | 0.125 | 0.50 | Across standard, minimum and maximum reductions, two comparison functions and four reference depths, the old one-line behavior gave 256/384 incorrect pixels on RTX and 128/384 on WARP. The ordinary sample stayed at 0.50 (standard), 0.125 (minimum) or 0.875 (maximum) before and after the change. The DXIL validator accepted every shader in both runs. The existing shader cache keys translations by the translator source hash, which includes this edit to `emit/mod.rs`. The pipeline prebuild tag includes that hash too. [Shader source hashing](https://github.com/Marvisak/VIctory/blob/840ad8b541a36b989f12a10f424a923e6da0b2b1/crates/victory-shader/build.rs#L10-L40) · [Shader cache key](https://github.com/Marvisak/VIctory/blob/840ad8b541a36b989f12a10f424a923e6da0b2b1/crates/victory-gpu/src/shader_cache.rs#L52-L68) · [Pipeline prebuild tag](https://github.com/Marvisak/VIctory/blob/840ad8b541a36b989f12a10f424a923e6da0b2b1/crates/victory-gpu/src/pipeline/library.rs#L197-L212)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:29 UTC · original

Automated triage for the maintainers.

In emit::emit_with (emit/mod.rs), immediate samplers used for comparison sampling now clear the D3D12 filter-reduction field (bits 7..=8, 0x180) before they set COMPARISON (0x80). Before this change, |= 0x80 turned a Minimum sampler (0x100) into Maximum (0x180) and left Maximum unchanged, so the comparison was lost. The field layout matches the public D3D12 headers (reduction shift 7, mask 3) and the mask StaticSampler::filter_for_host already uses. The test builds image_sample and image_sample_c_lz with min and max reduction. It checks that the plain slot keeps its reduction, the comparison slot gets 0x80 with the other filter bits unchanged, and the output passes dxil.dll where available. The thread reports matching pixels on RTX 5080 and WARP. CI: passing.

Verdict: merge candidate. Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2983#issuecomment-7183531376) <!-- victory-triage v1 head=840ad8b541a36b989f12a10f424a923e6da0b2b1 verdict=merge-candidate at=2026-11-26T05:29:16Z --> Automated triage for the maintainers. In `emit::emit_with` (`emit/mod.rs`), immediate samplers used for comparison sampling now clear the D3D12 filter-reduction field (bits 7..=8, `0x180`) before they set COMPARISON (`0x80`). Before this change, `|= 0x80` turned a Minimum sampler (`0x100`) into Maximum (`0x180`) and left Maximum unchanged, so the comparison was lost. The field layout matches the public D3D12 headers (reduction shift 7, mask 3) and the mask `StaticSampler::filter_for_host` already uses. The test builds `image_sample` and `image_sample_c_lz` with min and max reduction. It checks that the plain slot keeps its reduction, the comparison slot gets `0x80` with the other filter bits unchanged, and the output passes `dxil.dll` where available. The thread reports matching pixels on RTX 5080 and WARP. CI: passing. **Verdict: merge candidate.** Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2983/head:github-bot/gh-2983'
git switch 'github-bot/gh-2983'

Merge

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