Game: fix stencil write-mask reachability for NEVER/ALWAYS funcs #3131
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3131
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@fuzeofficlal on GitHub · 2026-11-26 09:32 UTC · original
fuzeofficlal:fix/game-pipelines-stencil-writes-reachability→main· +61 −6 · 1 files · 2 commits · openSummary
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.@cloph-dsp on GitHub · 2026-11-26 09:48 UTC · original
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).
@Dukestar69 on GitHub · 2026-11-26 13:30 UTC · original · approved these changes
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).
@AurumCarlos on GitHub · 2026-11-26 13:32 UTC · original · reviewed
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.
@fuzeofficlal on GitHub · 2026-11-26 16:46 UTC · original
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.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.