Shaders: a loop that leaves to a no-output end is no discard #2304
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2306"
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 wbkepler on 2026-11-25T10:15:11Z.
What
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
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:19:05Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 146 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — a loop leaving to a no-output end is no longer treated as discard.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T10:22:42Z.
Review: APPROVED
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:liveof thes_andn2 X, X, execmask indiscardsand rejectingkill_exitwhenEXECis restored from a different saved mask cleanly distinguishes a normal no-color-output pixel exit after a loop from an actual discard exit.cargo test -p victory-shader structure::tests: 13/13 passed on RTX 5090, 13/13 passed on WARP (includinga_loop_exit_to_a_null_export_is_no_discardanda_forward_exit_to_a_null_export_is_a_discard).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:22:17Z.
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