Repository navigation
Shaders: a pixel shader writing SV_StencilRef declares StencilRef - #382
Merged
Merged
Conversation
exp mrtz's channel y is lowered to an SV_StencilRef output, but the module's shader flags never had StencilRef (bit 11) and SFI0 never had D3D_SHADER_FEATURE_STENCIL_REF (0x200). DXC sets both for a pixel shader whose output signature has the stencil reference, and the validator checks the flags against the module. Both are now set when a pixel shader outputs SV_StencilRef.
muhammed-aksoy
pushed a commit
to muhammed-aksoy/VIctory
that referenced
this pull request
Nov 24, 2026
edsuuu
referenced
this pull request
in edsuuu/VI-BR-PORT
Nov 24, 2026
… StencilRef Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks @Dufftwt for fixing the stencil export metadata. I tested head Result: 1 passed, 0 failed (69 filtered out). The synthetic shader emission test writes |
Closed
suirentakamura
referenced
this pull request
in suirentakamura/victory-suiren
Nov 24, 2026
Shaders: a pixel shader writing SV_StencilRef declares StencilRef
itsonlysimbo
pushed a commit
to itsonlysimbo/VIctory
that referenced
this pull request
Nov 24, 2026
Shaders: a pixel shader writing SV_StencilRef declares StencilRef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
exp mrtzchannel y, the stencil value a pixel shader exports, is lowered to anSV_StencilRefoutput (lower.rs). But the module never declares it:StencilRef, bit 11;SFI0part never hasD3D_SHADER_FEATURE_STENCIL_REF,0x200.DXC sets both for any pixel shader whose output signature contains
SV_StencilRef(DxilShaderFlags.cpp), and the DXIL validator checks the module's flags against what it actually uses (ValidateShaderFlags, "Flags must match usage"). Our translation of a stencil-exporting pixel shader therefore contradicts itself. The validator rejects it, and the runtime isn't told that the shader needs the stencil-reference output feature.What the fix does
flags::STENCIL_REF = 1 << 11is added toemit/shader.rs's flag list.Shadersets it when a pixel shader has an output of kind 20 (SV_StencilRef).SFI0features map it to0x200, like the other flags already mapped there (0x800for typed UAV loads, and so on).How it behaves after the fix
Pixel shaders that export a stencil reference declare
StencilRefin their flags andSFI0, as DXC would. Every other shader is unchanged.Tests
The new test
a_stencil_export_declares_the_stencil_ref_feature(inemit/mod.rs) translatesexp mrtz v0, v1(depth and stencil). The output signature hasSV_DepthandSV_StencilRef, and the test checks thatSFI0has0x200.Where
dxil.dllis available, as on GitHub's Windows runner, the test also passes the shader through the validator, asstub_pipeline_is_createdandconstant_color_validatesalready do.I ran
cargo test --workspaceon GitHub'swindows-latestwith Rust 1.98.1 fromrust-toolchain.toml, and the shader crate's tests on Linux:dxil.dllaccepts the shader.victory-shaderhas 70 passed, the other crates have 0 failed.main:SFI0is0x0, anddxil.dllreports:StencilRef.)--test-threads=1. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (Tests: victory-shader tests crash (0xC0000005) when several tests use WARP devices in parallel #181, Shaders: share and serialize WARP host operations across threads #244).Not tested: a title's stencil-exporting shaders on a GPU.
Related: #294 adds two other feature bits right next to this one in
SFI0. Whichever merges second needs a trivial rebase.