Shaders: a pixel discard in a loop kills its lanes, as the console does #2043
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!2043
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2043/head"
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?
@Deilach on GitHub · 2026-11-25 04:01 UTC · original
Deilach:linux-discard-loop→main· +144 −10 · 1 files · 2 commits · closed without mergingWhat
If a pixel program discards inside a loop, it is now lowered in the killing form (
structure::killing) first, falling back to the helper form if the killing form does not lower. Programs without a discard in a loop are lowered exactly as before.Why
A world light-volume pixel shader leaves a loop by killing its lanes:
s_andn2takes them out of the live mask, and the loop ends once no live lane is left. In the helper form, discarded lanes "run on as live lanes", so the only exit left for them is the loop limit, and each one runs the loop 2^20 times.When the host's
discardterminates lanes (the Windows AMD driver, apparently), this goes unnoticed. When it demotes them to helper lanes, as D3D12's discard allows and vkd3d-proton does (OpDemoteToHelperInvocation), every discarded lane spins to the limit. On Linux each draw of that box (36 indices) took 380–460 ms, nearly all of a world frame's GPU time.Testing
On Linux (RX 9070 XT, RADV, Wine 11.22 + vkd3d-proton master), with
VICTORY_GPU_TIMING:translate --cacheof the title: 25,985 containers, 307 refused, the same as before.cargo clippy --workspace --all-targets [--all-features] -- -D warningsis clean.victory-shadertests under Wine: identical tomain. The 75 tests that need WARP ordxil.dllfail in Wine onmaintoo.Trade-off, the one
structure::killingalready documents: derivatives taken after a discard inside a loop read killed lanes as the console does, rather than as helpers. I haven't tested on Windows. Programs without a discard in a loop are unaffected.🤖 Generated with Claude Code
@jeremygold02 on GitHub · 2026-11-25 04:03 UTC · original
Triage verdict — Keep the fix, preserve the full helper fallback (
2a95408)Evidence
lower::lower. Bothstructure::killingand the subsequentresource::trackuse?before that fallback, so a refusal there returns fromemit_witheven if the original helper path could succeed. Fallback selection · Cycle predicateChecks and limits
Next step
This verification was AI-assisted.
@Deilach on GitHub · 2026-11-25 04:20 UTC · original
Thanks for the review. Both points are addressed in
7686b6f:Predicate. The killing form is now chosen only when the discard sits in a loop that no lane can leave in the helper form, meaning no edge out of the loop through the discard's block is one a lane may take. A branch with a constant condition counts only on its open side. A loop with an exit of its own keeps the helper form.
Fallback.
structure::killing,resource::trackandlower::lowerare each fallible in the killing attempt. Any failure falls back to the original helper path.Tests. New
emit::tests::a_loop_left_only_by_killing_is_made_in_the_killing_form, with two programs:s_andn2 live, live, exec→ "no live lane left" exit). It is trapped and made in the killing form.quad_permread after it as the derivative. It keeps the helper form. The previous predicate would have switched this one to the killing form.Both programs also go through
emit_pixel.How broadly it applies, measured on the title. I translated all 25,985 containers with a temporary counter. 6,015 programs discard, and exactly one of them discards inside a loop: the light-volume shader. It is trapped under the new predicate, and its DXIL is byte-identical to the previous commit's. Refusals are unchanged at 307. So on this title the narrowing changes nothing; it only guards other titles and future shaders.
cargo clippy --workspace --all-targets [--all-features] -- -D warningsis clean.victory-shaderandvictory-gputests under Wine matchmainplus the new test. The 75 tests that need WARP ordxil.dllfail under Wine onmaintoo.@upipibi on GitHub · 2026-11-25 04:41 UTC · original
Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at
7686b6f.victory-shader: 245 passed, 3 failed, 3 ignored; the newa_loop_left_only_by_killing_is_made_in_the_killing_formpasses. The 3 failures are #1744's NVIDIA failures onmain. Same asmainon this hardware. Not run: a title.AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 09:18 UTC · original
Automated triage for the maintainers.
Merge candidate. In
crates/victory-shader/src/emit/mod.rs(emit_with), a pixel program is now lowered in the killing form thatmainalready has (structure::killing) whentraps_discardedfinds a discard in a loop that no lane can leave in the helper form. Onmain, discarded lanes stay live in that loop until they hit the loop limit. Every step of the killing attempt can now fail and fall back to the original helper path, which addresses the earlier review. Other programs are lowered exactly as before.The evidence is the title's own shader: the author's before/after GPU timings on vkd3d-proton, and a corpus run in which the light-volume shader is the only program affected and the refusal count is unchanged. The new test covers both a trapped loop and a bounded loop with a derivative after the discard, which keeps the helper form.
Recommending a look, not approving.
CI: not run. No check runs exist for this head, so the build has to be confirmed before a merge.
Generated by Claude Code
@sinan-cmyk on GitHub · 2026-11-25 09:33 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head
7686b6ffontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 22:05 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing in favour of #2306, which fixes the cause. The one title program with a "discard" inside a loop is a misread loop exit: it leaves on
s_andn2 X, X, exec; s_cbranch_sccand restores EXEC from a mask saved before the loop ahead of its null export, so on the console those lanes end as valid pixels.structure.rskill_exittakes that for a kill; #2306 corrects it, the back edge becomes per-lane and the cost goes away. This PR keeps the misreading and kills those lanes, which would discard pixels the console keeps.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed