Shaders: split comparison and non-comparison immediate static samplers #1108

Closed
mgunes1311-lab wants to merge 3 commits from upstream-pr/1108 into main
mgunes1311-lab commented 2026-11-24 15:47:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-24T15:47:58Z.


Summary

Split immediate/constant samplers by (words, comparison) so a single GPU sampler descriptor used for both standard and comparison sampling gets separate D3D12 static sampler slots rather than forcing a shared sampler into comparison mode.

Fixes

  • Separate comparison vs non-comparison static samplers: Key Lower::samplers by ([u32; 4], bool) instead of [u32; 4] alone, and pass comparison directly to Shader::sampler_handle. This prevents non-comparison image_sample_* operations from being bound to a SamplerComparisonState static sampler.
  • Remove the 64-sampler bitmask limit: Replace cmp_samplers: u64 in Lowered and Shader with Vec<bool> (Shader::samplers: Vec<bool>), avoiding bit-shift overflow when a shader uses more than 64 immediate samplers.
  • Preserve reduction-type bits cleanly: Extract build_static_samplers in emit/mod.rs and set s.filter = (s.filter & !0x180) | 0x80 for comparison samplers instead of |= 0x80, so MINIMUM (0x100) becomes COMPARISON (0x80) rather than MAXIMUM (0x180).

Files Changed

  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/shader.rs
  • crates/victory-shader/src/emit/mod.rs

Tests Added

  • emit::tests::constant_sampler_used_with_and_without_comparison_splits_into_two_static_samplers (covers both cmp_first = false/true, DXIL validation + WARP dispatch on Windows, and MINIMUM reduction override)
  • emit::tests::more_than_64_immediate_samplers_do_not_overflow (66 immediate samplers)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6585724780 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1108). Originally posted by [mgunes1311-lab](https://github.com/mgunes1311-lab) on 2026-11-24T15:47:58Z. --- ## Summary Split immediate/constant samplers by `(words, comparison)` so a single GPU sampler descriptor used for both standard and comparison sampling gets separate D3D12 static sampler slots rather than forcing a shared sampler into comparison mode. ### Fixes - **Separate comparison vs non-comparison static samplers:** Key `Lower::samplers` by `([u32; 4], bool)` instead of `[u32; 4]` alone, and pass `comparison` directly to `Shader::sampler_handle`. This prevents non-comparison `image_sample_*` operations from being bound to a `SamplerComparisonState` static sampler. - **Remove the 64-sampler bitmask limit:** Replace `cmp_samplers: u64` in `Lowered` and `Shader` with `Vec<bool>` (`Shader::samplers: Vec<bool>`), avoiding bit-shift overflow when a shader uses more than 64 immediate samplers. - **Preserve reduction-type bits cleanly:** Extract `build_static_samplers` in `emit/mod.rs` and set `s.filter = (s.filter & !0x180) | 0x80` for comparison samplers instead of `|= 0x80`, so `MINIMUM` (`0x100`) becomes `COMPARISON` (`0x80`) rather than `MAXIMUM` (`0x180`). ### Files Changed - `crates/victory-shader/src/emit/lower.rs` - `crates/victory-shader/src/emit/shader.rs` - `crates/victory-shader/src/emit/mod.rs` ### Tests Added - `emit::tests::constant_sampler_used_with_and_without_comparison_splits_into_two_static_samplers` (covers both `cmp_first = false/true`, DXIL validation + WARP dispatch on Windows, and `MINIMUM` reduction override) - `emit::tests::more_than_64_immediate_samplers_do_not_overflow` (66 immediate samplers)
MichaelSmithAI commented 2026-11-24 16:05:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T15:50:51Z.


We extended the 66-sampler test on a0206d1 through compute dispatch and readback on an RTX 4090 under Wine/GE 3.2. With one R32_FLOAT texel set to 0.5, every ordinary sample returned 0.5 and every comparison sample returned 1.0. We checked all 66 output words, including slots 64 and 65 beyond the old mask.

The mixed-use shader also validated and returned [0.5, 1.0, 0.0] in both declaration orders. These are test-only fixture changes. The MINIMUM-to-COMPARISON filter conversion was checked in the emitted sampler metadata. Title use remains unmeasured.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136712364 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1108#issuecomment-7136712364). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T15:50:51Z. --- We extended the 66-sampler test on `a0206d1` through compute dispatch and readback on an RTX 4090 under Wine/GE 3.2. With one R32_FLOAT texel set to 0.5, every ordinary sample returned 0.5 and every comparison sample returned 1.0. We checked all 66 output words, including slots 64 and 65 beyond the old mask. The mixed-use shader also validated and returned [0.5, 1.0, 0.0] in both declaration orders. These are test-only fixture changes. The MINIMUM-to-COMPARISON filter conversion was checked in the emitted sampler metadata. Title use remains unmeasured.
Zipettte commented 2026-11-24 18:06:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:01:50Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at a0206d1: cargo test -p victory-shader passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140055225 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1108#issuecomment-7140055225). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T18:01:50Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at a0206d1: `cargo test -p victory-shader` passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-25 01:05:35 +00:00
Marvisak commented 2026-11-25 01:08:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:32:25Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1477. One immediate sampler used with and without comparison gets two static samplers: the same fix as #1477 (clean, 104 lines; also #1493), here with a Vec refactor and unrelated reformatting.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148612376 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1108#issuecomment-7148612376). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:32:25Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1477. One immediate sampler used with and without comparison gets two static samplers: the same fix as #1477 (clean, 104 lines; also #1493), here with a Vec<bool> refactor and unrelated reformatting. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1108
No description provided.