Repository navigation
Game: fix stencil write-mask reachability for NEVER/ALWAYS funcs - #3131
fuzeofficlal wants to merge 2 commits into
Conversation
|
Independent local verification of head
Synthetic pipeline state only; no game assets or DRM material used. AI-assisted (Hy4 flash). |
Dukestar69
left a comment
There was a problem hiding this comment.
Verified against origin/main (63bcca4):
cargo test -p victory-game -- --test-threads=1: 16/16 passed (includingpipelines::tests::stencil_write_mask_requires_a_reachable_op).cargo clippy -p victory-game --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Cleanly accounts for NEVER/ALWAYS comparison functions when determining stencil write-mask reachability.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
AurumCarlos
left a comment
There was a problem hiding this comment.
Looks right to me, and much easier to read than the old nested condition. With a face as [FailOp, DepthFailOp, PassOp, Func]:
- fail: reachable when the stencil test can fail (
Func != ALWAYS). - depth fail: reachable when the stencil can pass (
Func != NEVER) and the depth test can fail, which needs depth on andDepthFunc != ALWAYS. With depth off the depth test always passes, soDepthFailOpnever runs. - pass: reachable when both tests can pass (
Func != NEVER, and depth off orDepthFunc != NEVER).
That's the D3D12 rule for each op, and both cases from the description were real on main. For case 1, the old branch returned depth_fail != KEEP && … without looking at Func == NEVER. I checked the test table against these three rules, front and back.
c[0] != 0 for DepthEnable is also right: depth_stencil_desc writes c[0] as-is into a D3D12 BOOL, where any nonzero value is TRUE.
The same applies to StencilEnable, which still uses c[3] == 1 (in the last line of stencil_writes). Since depth_stencil_desc also passes c[3] through unchanged as a BOOL, a title that sets stencil enable to some other nonzero value gets stencil enabled on the host, but stencil_writes returns false, so the write mask is zeroed and its stencil writes are silently dropped. That's pre-existing, but it's the same class of bug as the c[0] & 1 you just fixed, so c[3] != 0 would fit in this PR, with one more test row (e.g. stencil enable 2 with a reachable op → WRITE_MASK).
Nit: in the description, "Replace the branch condition with direct per-operation reachability checks matching D3D12 rules:" ends with a colon but no list follows.
Match depth_stencil_desc's D3D12 BOOL semantics for StencilEnable (c[3] != 0) instead of checking c[3] == 1, and cover non-1 non-zero values (2 and u8::MAX) as well as 0 in stencil_write_mask_requires_a_reachable_op.
|
Good catch, thanks @AurumCarlos! Pushed |
|
NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, since none of them names a GPU run. Tested exact head Tested
Not tested
AI use
|
|
One additional reachability case on the current Follow-up commit I compared the reconstructed write mask to an independent CPU model across 768 generated states, covering both faces, all three stencil operations, eight comparisons, four depth settings and four read masks. Current main I also verified the comparison rule directly with a one-sample draw and occlusion queries on WARP 1.0.22 with Agility 1.620.2. With reference 1 and stored stencil 0, a zero read mask passed EQUAL, LESS_EQUAL, GREATER_EQUAL and ALWAYS. The one-bit control instead passed GREATER, NOT_EQUAL, GREATER_EQUAL and ALWAYS. Sixteen GPU queries agreed with the expected values with the debug layer off and on. The GPU diagnostics suite with the probe included had 247 passes and one ignored in both modes. Please retain the Git author if cherry-picking the follow-up. If folding it into another commit, please add |
Summary
pipelines::stencil_writes(crates/victory-game/src/pipelines.rs) previously misclassified two unreachable stencil operations when deciding whetherD3D12_DEPTH_STENCIL_DESC1.StencilWriteMaskcan be cleared to zero:StencilFuncisNEVER(1) withStencilFailOp == KEEP(1) and a non-KEEPStencilDepthFailOp, it checkeddepth_fail != KEEPand returnedtrueeven though the stencil test never passes.StencilFunccan pass,StencilPassOp != KEEP, andDepthEnable != 0withDepthFunc == NEVER(1), it fell through toelse { true }even though the depth test never passes.Fix
fail:StencilFailOp != KEEP && StencilFunc != ALWAYSdepth_fail:StencilDepthFailOp != KEEP && StencilFunc != NEVER && depth_enabled && DepthFunc != ALWAYSpass:StencilPassOp != KEEP && StencilFunc != NEVER && (!depth_enabled || DepthFunc != NEVER)depth_enabled(c[0] != 0) withdepth_stencil_desc.stencil_write_mask_requires_a_reachable_opcovering unreachable and reachable ops on both front and back faces (fails onmainreturning0x0Finstead of0).Verification
cargo test -p victory-game --locked: 16 passed, 0 failed.cargo clippy -p victory-game --all-targets --locked -- -D warningsand--all-features: clean.rustfmt --check --edition 2024 --config skip_children=true crates/victory-game/src/pipelines.rs: clean.cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.