Recompiler: export SV_StencilRef from exp mrtz channel 1 with adapter gating #3296

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3296 into main
Kalmarv commented 2026-11-29 06:20:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T06:20:47Z.


What is in it

Exports pixel-shader SV_StencilRef (system_value == 69) from exp mrtz (tgt == 8) channel 1 in both the default Direct DXIL backend (crates/xcl/src/gpu/dxil/kernel.rs, crates/xcl/src/gpu/dxil/lower_gfx.rs) and the HLSL backend (crates/xcl/src/gpu/recomp/emit.rs), matching Mesa ac_nir_lower_ps_late.c::emit_ps_mrtz_export, with adapter capability gating in crates/xcl/src/gpu/recomp/pso.rs:

  • Uncompressed 32-bit MRTZ (SPI_SHADER_32_GR / 32_ABGR, COMPR=0, EN & 2): reads VSRC1[7:0] (& 0xFF).
  • Compressed 16-bit MRTZ (SPI_SHADER_UINT16_ABGR, COMPR=1, EN & 3): reads VSRC0[23:16] ((VSRC0 >> 16) & 0xFF), and guards depth writes with !compr so compressed MRTZ never overwrites SV_Depth.
  • Declaration & dummy-target hygiene: only declares SV_StencilRef when both OSG1 declares system_value == 69 and an exp mrtz enables channel 1 (avoiding false positives on GFX10 SPI_SHADER_32_AR MRT0-alpha exports or depth-only exports), and omits the dummy SV_Target7 for stencil-only pixel shaders.
  • Adapter capability gating (PSSpecifiedStencilRefSupported): probes D3D12_FEATURE_DATA_D3D12_OPTIONS::PSSpecifiedStencilRefSupported inside pso::graphics_wave32_for_device. On adapters that report FALSE (such as NVIDIA D3D12 drivers, which reject PSOs declaring SV_StencilRef with E_INVALIDARG), strips system_value == 69 before translation and isolates disk/RAM cache keys (_nostencil) for those shaders only so existing caches stay untouched.
  • Tests:
    • ps_mrtz_stencil_ref_writes_sv_stencil_ref (recomp/tests.rs): HLSL codegen + DXC 1.9 compilation across uncompressed, depth+stencil, compressed, compressed+coverage, unused, stencil-only, and undeclared cases.
    • ps_mrtz_stencil_ref_direct_and_gpu (dxil/core_tests.rs): Direct DXIL dxil.dll validation + SFI0 0x200 flag checks across all cases, plus end-to-end 3-pass D3D12 D24_UNORM_S8_UINT stencil-buffer draw verification (StencilPassOp = REPLACE with decoy OMSetStencilRef(0x11), followed by EQUAL pass on expected ref and EQUAL negative check on decoy) for all 4 combinations (Direct DXIL + HLSL, COMPR=0 + COMPR=1), falling back to WARP when the hardware adapter lacks PSSpecifiedStencilRefSupported.
    • ps_stencil_ref_gating_strips_and_splits_cache_filename (recomp/pso.rs): verifies capability stripping and _nostencil cache filename isolation.

Tested

Hardware: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (Build 26200), rustc 1.99.0 (b940084d7), XCL_DXC_DIR with DXC 1.9.2609.5.

  • cargo check --workspace --all-targets: 0 errors.
  • Targeted unit & D3D12 stencil-buffer draw tests (ps_mrtz_stencil_ref_writes_sv_stencil_ref, ps_mrtz_stencil_ref_direct_and_gpu on WARP because RTX 5070 Ti reports PSSpecifiedStencilRefSupported = FALSE, ps_stencil_ref_gating_strips_and_splits_cache_filename): 3 passed, 0 failed (0 skips).
  • Full workspace GPU test suite (cargo test --workspace -- --test-threads=4): 2611 passed, 0 failed, 49 ignored (26 SKIPPED: 21 no wave64 on NVIDIA wave32, 3 pre-existing #1426 f16 refusals, 2 no heap windows).

Regression run

main-ancestor baseline (f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB

This branch (537d0a06fb7a87dbe235821e7e9e554fccf4c773, 0 minidumps, 0 System display events):

xcl-smoke v1
commit: 537d0a06fb7a87dbe235821e7e9e554fccf4c773
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1929 (PresentX 1929)
presents per 2 s (last 3): 34 0 0
device removals: 0
crashes: 0
peak commit: 32161 MB

Not tested

  • Hardware AMD / Intel GPUs with PSSpecifiedStencilRefSupported = TRUE (end-to-end D3D12 stencil-buffer draw verification executed on Microsoft WARP D3D12 device because NVIDIA D3D12 drivers report PSSpecifiedStencilRefSupported = FALSE).
  • Native wave64 GPU hardware (21 wave64-only tests skipped on wave32 NVIDIA hardware).
  • Console STENCIL_OP_VAL (VSRC1[15:8]) and STENCIL_WRITE_MASK (VSRC1[23:16]), which D3D12/DXIL has no pixel-shader output semantic for.

AI use

Written, verified, and tested with an AI coding assistant (Antigravity), with all unit tests, DXIL validation, WARP D3D12 stencil-buffer draw tests, full workspace GPU tests, and 150 s xcl-smoke runs executed on local hardware.

<!-- greyfinch-sync:ivall/xcl:issue:5548222008 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3296). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T06:20:47Z. --- **What is in it** Exports pixel-shader `SV_StencilRef` (`system_value == 69`) from `exp mrtz` (`tgt == 8`) channel 1 in both the default Direct DXIL backend (`crates/xcl/src/gpu/dxil/kernel.rs`, `crates/xcl/src/gpu/dxil/lower_gfx.rs`) and the HLSL backend (`crates/xcl/src/gpu/recomp/emit.rs`), matching Mesa `ac_nir_lower_ps_late.c::emit_ps_mrtz_export`, with adapter capability gating in `crates/xcl/src/gpu/recomp/pso.rs`: - **Uncompressed 32-bit MRTZ (`SPI_SHADER_32_GR` / `32_ABGR`, `COMPR=0`, `EN & 2`)**: reads `VSRC1[7:0]` (`& 0xFF`). - **Compressed 16-bit MRTZ (`SPI_SHADER_UINT16_ABGR`, `COMPR=1`, `EN & 3`)**: reads `VSRC0[23:16]` (`(VSRC0 >> 16) & 0xFF`), and guards depth writes with `!compr` so compressed MRTZ never overwrites `SV_Depth`. - **Declaration & dummy-target hygiene**: only declares `SV_StencilRef` when both `OSG1` declares `system_value == 69` and an `exp mrtz` enables channel 1 (avoiding false positives on GFX10 `SPI_SHADER_32_AR` MRT0-alpha exports or depth-only exports), and omits the dummy `SV_Target7` for stencil-only pixel shaders. - **Adapter capability gating (`PSSpecifiedStencilRefSupported`)**: probes `D3D12_FEATURE_DATA_D3D12_OPTIONS::PSSpecifiedStencilRefSupported` inside `pso::graphics_wave32_for_device`. On adapters that report `FALSE` (such as NVIDIA D3D12 drivers, which reject PSOs declaring `SV_StencilRef` with `E_INVALIDARG`), strips `system_value == 69` before translation and isolates disk/RAM cache keys (`_nostencil`) for those shaders only so existing caches stay untouched. - **Tests**: - `ps_mrtz_stencil_ref_writes_sv_stencil_ref` (`recomp/tests.rs`): HLSL codegen + DXC 1.9 compilation across uncompressed, depth+stencil, compressed, compressed+coverage, unused, stencil-only, and undeclared cases. - `ps_mrtz_stencil_ref_direct_and_gpu` (`dxil/core_tests.rs`): Direct DXIL `dxil.dll` validation + `SFI0` `0x200` flag checks across all cases, plus end-to-end 3-pass D3D12 `D24_UNORM_S8_UINT` stencil-buffer draw verification (`StencilPassOp = REPLACE` with decoy `OMSetStencilRef(0x11)`, followed by `EQUAL` pass on expected ref and `EQUAL` negative check on decoy) for all 4 combinations (Direct DXIL + HLSL, `COMPR=0` + `COMPR=1`), falling back to WARP when the hardware adapter lacks `PSSpecifiedStencilRefSupported`. - `ps_stencil_ref_gating_strips_and_splits_cache_filename` (`recomp/pso.rs`): verifies capability stripping and `_nostencil` cache filename isolation. **Tested** Hardware: `NVIDIA GeForce RTX 5070 Ti` (driver `32.0.16.1074`), `AMD Ryzen 9 9950X`, `Windows 11 Pro (Build 26200)`, `rustc 1.99.0 (b940084d7)`, `XCL_DXC_DIR` with DXC `1.9.2609.5`. - `cargo check --workspace --all-targets`: 0 errors. - Targeted unit & D3D12 stencil-buffer draw tests (`ps_mrtz_stencil_ref_writes_sv_stencil_ref`, `ps_mrtz_stencil_ref_direct_and_gpu` on WARP because RTX 5070 Ti reports `PSSpecifiedStencilRefSupported = FALSE`, `ps_stencil_ref_gating_strips_and_splits_cache_filename`): 3 passed, 0 failed (0 skips). - Full workspace GPU test suite (`cargo test --workspace -- --test-threads=4`): 2611 passed, 0 failed, 49 ignored (26 `SKIPPED`: 21 `no wave64` on NVIDIA wave32, 3 pre-existing `#1426` f16 refusals, 2 `no heap windows`). **Regression run** `main`-ancestor baseline (`f0e8fdd5c3942ddd399d5ee11384c8595c5aacff`): ``` xcl-smoke v1 commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1695 (PresentX 1695) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31546 MB ``` This branch (`537d0a06fb7a87dbe235821e7e9e554fccf4c773`, 0 minidumps, 0 System display events): ``` xcl-smoke v1 commit: 537d0a06fb7a87dbe235821e7e9e554fccf4c773 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1929 (PresentX 1929) presents per 2 s (last 3): 34 0 0 device removals: 0 crashes: 0 peak commit: 32161 MB ``` **Not tested** - Hardware AMD / Intel GPUs with `PSSpecifiedStencilRefSupported = TRUE` (end-to-end D3D12 stencil-buffer draw verification executed on Microsoft WARP D3D12 device because NVIDIA D3D12 drivers report `PSSpecifiedStencilRefSupported = FALSE`). - Native wave64 GPU hardware (21 wave64-only tests skipped on wave32 NVIDIA hardware). - Console `STENCIL_OP_VAL` (`VSRC1[15:8]`) and `STENCIL_WRITE_MASK` (`VSRC1[23:16]`), which D3D12/DXIL has no pixel-shader output semantic for. **AI use** Written, verified, and tested with an AI coding assistant (`Antigravity`), with all unit tests, DXIL validation, WARP D3D12 stencil-buffer draw tests, full workspace GPU tests, and 150 s `xcl-smoke` runs executed on local hardware.
Foniass commented 2026-11-29 14:59:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T14:59:06Z.


Review (head 537d0a06, diff read, not a merge-check):

  • The export and the capability gating look right.
  • It conflicts with #3252 (git merge-tree gives conflicts in lower_gfx.rs and core_tests.rs), and the two use different designs. Whichever merges second needs to add stencil_ref.is_none() to #3252's dummy-target condition.
  • ps_stencil_ref_allowed() is true until a device probe says otherwise, and xcl shaders --precompile never probes, so on NVIDIA (which reports the capability FALSE) the precompiled pixel shaders keep SV_StencilRef and miss the _nostencil cache key at run time, as far as I can see.
  • The export has not run on real hardware: the RTX 5070 Ti reports PSSpecifiedStencilRefSupported = FALSE, so the draw test ran only on WARP (the description says so).
  • +598 lines; AI use names no model.

Suggested verdict: not yet (rebase against #3252 or the other way round).

(Review written with Claude Code, Claude Opus 5.5.)

<!-- greyfinch-sync:ivall/xcl:comment:7257728150 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3296#issuecomment-7257728150). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T14:59:06Z. --- Review (head 537d0a06, diff read, not a merge-check): - The export and the capability gating look right. - **It conflicts with #3252** (`git merge-tree` gives conflicts in `lower_gfx.rs` and `core_tests.rs`), and the two use different designs. Whichever merges second needs to add `stencil_ref.is_none()` to #3252's dummy-target condition. - `ps_stencil_ref_allowed()` is true until a device probe says otherwise, and `xcl shaders --precompile` never probes, so on NVIDIA (which reports the capability FALSE) the precompiled pixel shaders keep `SV_StencilRef` and miss the `_nostencil` cache key at run time, as far as I can see. - The export has not run on real hardware: the RTX 5070 Ti reports `PSSpecifiedStencilRefSupported = FALSE`, so the draw test ran only on WARP (the description says so). - +598 lines; AI use names no model. Suggested verdict: not yet (rebase against #3252 or the other way round). (Review written with Claude Code, Claude Opus 5.5.)
bmjask commented 2026-12-01 21:17:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:17:31Z.

Review: COMMENTED


Review of 537d0a06: 2 finding(s). 2 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6140318476 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3296#pullrequestreview-6140318476). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T21:17:31Z. **Review:** COMMENTED --- Review of `537d0a06`: 2 finding(s). 2 are inline. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-01 21:17:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:17:32Z.

Code review location: crates/xcl/src/gpu/recomp/pso.rs; line 1573

@@ -1498,8 +1513,64 @@ pub fn wave32_only_for_device(device: &ID3D12Device) -> bool {
     split_wave64_forced() || wave_range(device).is_none_or(|(min, max)| wave32_only(min, max))
 }
 
+/// Cached `D3D12_FEATURE_DATA_D3D12_OPTIONS::PSSpecifiedStencilRefSupported`:
+/// 0 = unprobed (allow by default for offline/direct tests), 1 = unsupported (e.g. NVIDIA), 2 = supported.
+static PS_STENCIL_REF_SUPPORTED: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0);
+
+/// Probe and cache whether `device` supports pixel-shader `SV_StencilRef` (`PSSpecifiedStencilRefSupported`).
+pub fn ps_stencil_ref_for_device(device: &ID3D12Device) -> bool {
+    let mut options = D3D12_FEATURE_DATA_D3D12_OPTIONS::default();
+    let supported = unsafe {
+        device.CheckFeatureSupport(
+            D3D12_FEATURE_D3D12_OPTIONS,
+            &mut options as *mut _ as _,
+            std::mem::size_of_val(&options) as u32,
+        )
+    }
+    .is_ok()
+        && options.PSSpecifiedStencilRefSupported.as_bool();
+    PS_STENCIL_REF_SUPPORTED.store(if supported { 2 } else { 1 }, std::sync::atomic::Ordering::Relaxed);
+    supported
+}
+
+/// Whether translated pixel shaders should emit `SV_StencilRef` for the active device.
+/// Returns `false` only after a device probe explicitly reported `PSSpecifiedStencilRefSupported == FALSE`
+/// (e.g. NVIDIA D3D12 drivers, which reject PSOs declaring `SV_StencilRef` with `E_INVALIDARG`).
+pub fn ps_stencil_ref_allowed() -> bool {
+    PS_STENCIL_REF_SUPPORTED.load(std::sync::atomic::Ordering::Relaxed) != 1
+}
+
+fn strip_stencil_ref_with(blob: &[u8], stage: Stage, allowed: bool) -> bool {
+    stage == Stage::Pixel
+        && !allowed
+        && crate::gpu::dxbc::signatures(blob).1.iter().any(|e| e.system_value == 69)
+}
+
+fn strip_stencil_ref(blob: &[u8], stage: Stage) -> bool {
+    strip_stencil_ref_with(blob, stage, ps_stencil_ref_allowed())
+}
+
+fn strip_ps_stencil_ref_with(ps: &mut super::PsInterface, allowed: bool) -> bool {
+    if allowed {
+        return false;
+    }
+    let before = ps.outputs.len();
+    ps.outputs.retain(|e| e.system_value != 69);
+    ps.outputs.len() != before
+}
+
+fn strip_ps_stencil_ref_if_unsupported(ps: &mut super::PsInterface) {
+    if strip_ps_stencil_ref_with(ps, ps_stencil_ref_allowed()) {
+        static LOGGED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+        if !LOGGED.swap(true, std::sync::atomic::Ordering::Relaxed) {
+            crate::xlog_info!("[SHADER] adapter lacks PSSpecifiedStencilRefSupported; omitting PS SV_StencilRef export");
+        }
+    }
+}
+
 /// `graphics_wave32` for the device: the split flag for a wave64 VS / PS. Unknown: assume so.
 pub fn graphics_wave32_for_device(device: &ID3D12Device) -> bool {
+    let _ = ps_stencil_ref_for_device(device);

The PSSpecifiedStencilRefSupported check only runs as a side effect of graphics_wave32_for_device, and when it hasn't run the default is "allowed". xcl shaders --precompile with no startup device (shaders.rs:3421 uses runner::graphics_wave32, which never checks), or with an explicit --split (the unwrap_or_else skips the closure), leaves PS_STENCIL_REF_SUPPORTED at 0. Every PS declaring system_value 69 is then stored with SV_StencilRef under <hash>_Pixel_..._0.bin. At runtime on NVIDIA the value becomes 1, translated::file adds _nostencil and misses, so all those shaders are translated again at draw time. Tools on the runner device that build pixel PSOs get SV_StencilRef PSOs that NVIDIA rejects with E_INVALIDARG.

<!-- greyfinch-sync:ivall/xcl:review-comment:4761123021 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3296#discussion_r4761123021). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T21:17:32Z. **Code review location:** `crates/xcl/src/gpu/recomp/pso.rs`; line 1573 ~~~~diff @@ -1498,8 +1513,64 @@ pub fn wave32_only_for_device(device: &ID3D12Device) -> bool { split_wave64_forced() || wave_range(device).is_none_or(|(min, max)| wave32_only(min, max)) } +/// Cached `D3D12_FEATURE_DATA_D3D12_OPTIONS::PSSpecifiedStencilRefSupported`: +/// 0 = unprobed (allow by default for offline/direct tests), 1 = unsupported (e.g. NVIDIA), 2 = supported. +static PS_STENCIL_REF_SUPPORTED: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0); + +/// Probe and cache whether `device` supports pixel-shader `SV_StencilRef` (`PSSpecifiedStencilRefSupported`). +pub fn ps_stencil_ref_for_device(device: &ID3D12Device) -> bool { + let mut options = D3D12_FEATURE_DATA_D3D12_OPTIONS::default(); + let supported = unsafe { + device.CheckFeatureSupport( + D3D12_FEATURE_D3D12_OPTIONS, + &mut options as *mut _ as _, + std::mem::size_of_val(&options) as u32, + ) + } + .is_ok() + && options.PSSpecifiedStencilRefSupported.as_bool(); + PS_STENCIL_REF_SUPPORTED.store(if supported { 2 } else { 1 }, std::sync::atomic::Ordering::Relaxed); + supported +} + +/// Whether translated pixel shaders should emit `SV_StencilRef` for the active device. +/// Returns `false` only after a device probe explicitly reported `PSSpecifiedStencilRefSupported == FALSE` +/// (e.g. NVIDIA D3D12 drivers, which reject PSOs declaring `SV_StencilRef` with `E_INVALIDARG`). +pub fn ps_stencil_ref_allowed() -> bool { + PS_STENCIL_REF_SUPPORTED.load(std::sync::atomic::Ordering::Relaxed) != 1 +} + +fn strip_stencil_ref_with(blob: &[u8], stage: Stage, allowed: bool) -> bool { + stage == Stage::Pixel + && !allowed + && crate::gpu::dxbc::signatures(blob).1.iter().any(|e| e.system_value == 69) +} + +fn strip_stencil_ref(blob: &[u8], stage: Stage) -> bool { + strip_stencil_ref_with(blob, stage, ps_stencil_ref_allowed()) +} + +fn strip_ps_stencil_ref_with(ps: &mut super::PsInterface, allowed: bool) -> bool { + if allowed { + return false; + } + let before = ps.outputs.len(); + ps.outputs.retain(|e| e.system_value != 69); + ps.outputs.len() != before +} + +fn strip_ps_stencil_ref_if_unsupported(ps: &mut super::PsInterface) { + if strip_ps_stencil_ref_with(ps, ps_stencil_ref_allowed()) { + static LOGGED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + if !LOGGED.swap(true, std::sync::atomic::Ordering::Relaxed) { + crate::xlog_info!("[SHADER] adapter lacks PSSpecifiedStencilRefSupported; omitting PS SV_StencilRef export"); + } + } +} + /// `graphics_wave32` for the device: the split flag for a wave64 VS / PS. Unknown: assume so. pub fn graphics_wave32_for_device(device: &ID3D12Device) -> bool { + let _ = ps_stencil_ref_for_device(device); ~~~~ --- The PSSpecifiedStencilRefSupported check only runs as a side effect of `graphics_wave32_for_device`, and when it hasn't run the default is "allowed". `xcl shaders --precompile` with no startup device (shaders.rs:3421 uses `runner::graphics_wave32`, which never checks), or with an explicit `--split` (the `unwrap_or_else` skips the closure), leaves PS_STENCIL_REF_SUPPORTED at 0. Every PS declaring system_value 69 is then stored with SV_StencilRef under `<hash>_Pixel_..._0.bin`. At runtime on NVIDIA the value becomes 1, `translated::file` adds `_nostencil` and misses, so all those shaders are translated again at draw time. Tools on the runner device that build pixel PSOs get SV_StencilRef PSOs that NVIDIA rejects with E_INVALIDARG.
bmjask commented 2026-12-01 21:17:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:17:32Z.

Code review location: crates/xcl/src/gpu/recomp/pso.rs; line 1518

@@ -1498,8 +1513,64 @@ pub fn wave32_only_for_device(device: &ID3D12Device) -> bool {
     split_wave64_forced() || wave_range(device).is_none_or(|(min, max)| wave32_only(min, max))
 }
 
+/// Cached `D3D12_FEATURE_DATA_D3D12_OPTIONS::PSSpecifiedStencilRefSupported`:
+/// 0 = unprobed (allow by default for offline/direct tests), 1 = unsupported (e.g. NVIDIA), 2 = supported.
+static PS_STENCIL_REF_SUPPORTED: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0);

The strip decision is one process-wide atomic that the last checked device overwrites, and it's read separately for the RAM key, each disk filename and the translation. If a translation starts at 0 (no _nostencil in its ShaderKey or file path) and another thread's first PSO sets it to 1 while DXC is compiling, strip_ps_stencil_ref_if_unsupported strips the shader, or a store re-runs file() and picks the other name. Either way the output is cached under the name meant for the other adapter. With two devices in one process (WARP next to hardware, or several adapters), whichever was checked last decides every later translation. Passing the capability explicitly, like split_wave64, would remove the race and also fix the precompile case above.

<!-- greyfinch-sync:ivall/xcl:review-comment:4761123029 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3296#discussion_r4761123029). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T21:17:32Z. **Code review location:** `crates/xcl/src/gpu/recomp/pso.rs`; line 1518 ~~~~diff @@ -1498,8 +1513,64 @@ pub fn wave32_only_for_device(device: &ID3D12Device) -> bool { split_wave64_forced() || wave_range(device).is_none_or(|(min, max)| wave32_only(min, max)) } +/// Cached `D3D12_FEATURE_DATA_D3D12_OPTIONS::PSSpecifiedStencilRefSupported`: +/// 0 = unprobed (allow by default for offline/direct tests), 1 = unsupported (e.g. NVIDIA), 2 = supported. +static PS_STENCIL_REF_SUPPORTED: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(0); ~~~~ --- The strip decision is one process-wide atomic that the last checked device overwrites, and it's read separately for the RAM key, each disk filename and the translation. If a translation starts at 0 (no `_nostencil` in its ShaderKey or file path) and another thread's first PSO sets it to 1 while DXC is compiling, `strip_ps_stencil_ref_if_unsupported` strips the shader, or a store re-runs `file()` and picks the other name. Either way the output is cached under the name meant for the other adapter. With two devices in one process (WARP next to hardware, or several adapters), whichever was checked last decides every later translation. Passing the capability explicitly, like `split_wave64`, would remove the race and also fix the precompile case above.
Kalmarv commented 2026-12-02 19:38:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:38:57Z.


Closing: conflicts with merged #3252 (7ac333736), SV_StencilRef cannot run on NVIDIA, and precompile cache keys would miss.

<!-- greyfinch-sync:ivall/xcl:comment:7356505441 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3296#issuecomment-7356505441). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T19:38:57Z. --- Closing: conflicts with merged #3252 (`7ac333736`), `SV_StencilRef` cannot run on NVIDIA, and precompile cache keys would miss.

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
xcl-dev/xcl!3296
No description provided.