Game: fix stencil write-mask reachability for NEVER/ALWAYS funcs #3129
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3131"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:32:00Z.
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.Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T09:48:10Z.
Independent local verification of head
49fa81eon Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-game --lib pipelines::tests::stencil_write_mask_requires_a_reachable_op— 1 passed, 0 failed.git diff --check origin/main HEAD— clean.Synthetic pipeline state only; no game assets or DRM material used. AI-assisted (Hy4 flash).
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:30:44Z.
Review: APPROVED
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/ALWAYScomparison functions when determining stencil write-mask reachability.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T13:32:33Z.
Review: COMMENTED
Looks right to me, and much easier to read than the old nested condition. With a face as
[FailOp, DepthFailOp, PassOp, Func]:Func != ALWAYS).Func != NEVER) and the depth test can fail, which needs depth on andDepthFunc != ALWAYS. With depth off the depth test always passes, soDepthFailOpnever runs.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 returneddepth_fail != KEEP && …without looking atFunc == NEVER. I checked the test table against these three rules, front and back.c[0] != 0forDepthEnableis also right:depth_stencil_descwritesc[0]as-is into a D3D12BOOL, where any nonzero value is TRUE.The same applies to
StencilEnable, which still usesc[3] == 1(in the last line ofstencil_writes). Sincedepth_stencil_descalso passesc[3]through unchanged as aBOOL, a title that sets stencil enable to some other nonzero value gets stencil enabled on the host, butstencil_writesreturnsfalse, 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 thec[0] & 1you just fixed, soc[3] != 0would fit in this PR, with one more test row (e.g. stencil enable2with 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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T16:46:12Z.
Good catch, thanks @AurumCarlos! Pushed
8933db72changingStencilEnableinstencil_writesfromc[3] == 1toc[3] != 0so it matchesdepth_stencil_desc's D3D12BOOLhandling (just likeDepthEnable), and expandedstencil_write_mask_requires_a_reachable_opto coverStencilEnablevalues0,1,2, andu8::MAX.Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T11:33:59Z.
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
8933db7(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.stencil_write_mask_requires_a_reachable_op.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T14:09:51Z.
One additional reachability case on the current
8933db7head is a zero stencil read mask. It makes the two comparison operands equal, regardless of the stored value or stencil reference. LESS, GREATER and NOT_EQUAL then always fail. EQUAL, LESS_EQUAL and GREATER_EQUAL always pass.Follow-up commit
1343d0cis directly on your head. It uses that rule when deciding whether to keep the write mask. The emitted comparison enum and read mask are unchanged.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
63bcca4disagreed in 126 cases. Your head disagreed in 54, all with a zero read mask. The follow-up agreed in all 768. It merged cleanly with #3048 at79d344aand passed the same matrix there. The game crate passed 17 tests on the follow-up and 21 on the combination, with strict Clippy and asset policy passing on both.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
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>. AI-assisted with OpenAI Codex.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.