Shaders: a loop that leaves to a no-output end is no discard #2306
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!2306
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2306/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?
@wbkepler on GitHub · 2026-11-25 10:15 UTC · original
wbkepler:shader/loop-exit-not-discard→main· +100 −21 · 1 files · 1 commits · merged 2026-11-25 21:56 UTCWhat
Structurisation took a loop's ordinary exit test for a pixel discard. A pixel program with no color output (it writes only through atomics) ends with
exp null, off, off, off, off done vm. When its last loop leaves through the usual test on its own exit mask,s_andn2 X, X, execfollowed bys_cbranch_scc1 <loop>, that has the same shape as a discard's "no live lane is left" exit (discards+kill_exit). The translation then:w = Bool::TRUEfor a kill),discardinstead of letting them leave,In the DXIL this showed up as
discard(i+1 > n); br i1 true, label %loop, ....kill_exitnow takes the discard's live-mask register. A path that first gives EXEC a saved mask other than that one (s_mov exec, s[saved]) marks the lanes it exports as valid, so it is a normal program end and not a kill exit. A real discard's exit is unchanged: plainexp null ... done, ors_mov exec, 0/the emptied live mask first.Measured (Windows 11, NVIDIA RTX 5090)
On a world scene of the title, with
VICTORY_GPU_TIMINGand every command timestamped:br i1 (i+1 > n), %exit, %loop).victory translate --cacheof the title: 25,985 containers, 25,851 translated, 134 refused (the same as before).Relation to #2043
#2043 addresses the same draw by lowering programs with a "discard in a loop" in the killing form. This change argues that the program has no discard at all: the "kill" is a misread loop exit. With the exit read correctly the helper/killing question does not arise, derivatives keep the helper form, and other programs whose loop leaves to a no-output end are fixed too. The two do not conflict. If this lands, #2043's
traps_discardedshould no longer match this program.Tests
structure::tests::a_loop_exit_to_a_null_export_is_no_discard: such a loop has no discards, and its back edge is a per-lane condition, not "always".structure::tests::a_forward_exit_to_a_null_export_is_a_discard: a forward discard to a plain null export is still one.cargo clippy -p victory-shader --all-targets -- -D warningsandcargo clippy -p victory --features diagnostics --all-targets -- -D warningsare clean, andcargo xtask policypasses.cargo test -p victory-shader: 246 passed. 3 hardware tests fail identically onmainon this host (stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware).Host: Windows 11, NVIDIA RTX 5090.
🤖 Generated with Claude Code
@Marvisak on GitHub · 2026-11-25 15:22 UTC · original
Automated triage for the maintainers.
Merge candidate (worth a look). In
crates/victory-shader/src/structure.rs,discardsnow returns the live-mask register andkill_exittakes it, so an exit path that first restores EXEC from a different saved SGPR is read as a normal end of the program, not as a discard. Before, a loop that leaves ons_andn2 X, X, exec/s_cbranch_sccto anexp null doneend was taken for a kill, its back edge was always taken, and every lane ran to the loop limit (about 200 ms per draw by the author's timings). I checked that the second use, in the lane-exit lowering, behaves as before (killsis only filled wherediscardsmatched), that a real discard exit is still a kill (s_mov exec, 0is an inline constant, so the new arm does not catch it), and that the test encodings and branch offsets decode as commented. Evidence: the title's own program shape, DXIL before and after, and RTX 5090 timings. It may change what #2043 needs to match. CI: passing.Generated by Claude Code