Shaders: follow lane writes and scalar steps in whole-wave sections #308
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!308
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/308/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?
@AntoninMichelq on GitHub · 2026-11-24 02:13 UTC · original
AntoninMichelq:up/whole-wave-steps→main· +343 −38 · 2 files · 3 commits · closed without mergingRequested by 4nto · project thread
Summary
The whole-wave section simulation now follows more of the steps the console compiler uses in wave reductions and prefix sums. Lane-local code that the compiler schedules into a section is lowered as it would be outside one. Before, these programs failed with "a whole-wave section step the simulation does not follow".
What changed
emit/wave.rs: the simulation now also follows:v_writelane_b32with a constant or known-uniform lane. This covers the exclusive prefix sum that carries lane 15 into lane 16 (and 31/47 into 32/48 on Wave64).s_mov_b32copies;s_add/min/max/and/or/xorcombining twov_readlaneresults (the two halves of a Wave64 reduction, read at lanes 0 and 32);s_movcopies of a mask derived from the saved EXEC.v_readlane_b32with an SGPR lane the simulation knows (lane bits masked to the wave size), andv_readfirstlane_b32.A lane's own value from before the section, once moved to another lane by DPP,
v_permlanex16orv_readlane, is now unknown. Before, it was wrongly taken as the reading lane's own value.emit/lower.rs: some values have no shape in the simulation but are computed only by steps that read no other lane: scalar code and loads, or vector code without DPP, permutes, lane reads/writes or EXEC operands. The lanes active on entry now compute those values under their own EXEC.Adapted to main: main does not model
v_permlane16(#98 adds it), so only thev_permlanex16arm is touched. No dependency on other open PRs.How it was tested
cargo test -p victory-shaderon Linux: all tests pass. New tests:emit::wave::tests::writelane_carries_a_row_total_into_an_exclusive_prefixemit::wave::tests::wave64_halves_combine_in_a_scalar_addemit::wave::tests::another_lanes_own_value_is_not_the_lanes_ownemit::lower::tests::scalar_code_inside_a_whole_wave_section_is_loweredAll test programs were assembled with llvm-mc for gfx1030.
cargo check -p victory-shader --target x86_64-pc-windows-msvcpasses.On the game's 26,148 programs, "a whole-wave section step the simulation does not follow" went from 51 to 14. This was measured with
victory translateon the integration stack.Where 3D rendering stands on an RX 7600 (Windows 11)
These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Values a whole-wave section leaves were unknown when the section used a step the simulation did not model ("a whole-wave section step the simulation does not follow"). The simulation now also follows: - v_writelane_b32 (a constant or known-uniform lane takes the scalar, whatever EXEC holds): the exclusive prefix sum that carries lane 15 into lane 16 (and 31/47 into 32/48 on Wave64) with v_readlane/v_writelane. - scalar ALU on uniforms: s_mov_b32 copies, and s_add/min/max/and/or/xor combining two v_readlane results (the halves of a Wave64 reduction read at lanes 0 and 32); s_mov copies of a mask derived from the saved EXEC. - v_readlane_b32 with an SGPR lane the simulation knows, lane bits masked to the wave size, and v_readfirstlane_b32 (the first lane EXEC holds). A lane's own value of a VGPR from before the section moved to another lane (DPP, v_permlanex16, v_readlane) was still taken as the reading lane's own value; it is now unknown. The lowering computes a value the simulation found no shape for, when the steps that make it read no other lane (scalar code and loads scheduled into the section, lane-local vector code without DPP, permutes or lane reads/writes, and no EXEC operand), as it would outside a section: the lanes active on entry compute it as under their own EXEC. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66@jeremygold02 on GitHub · 2026-11-24 04:18 UTC · original
Tested PR #308 at head
3fba97c7c5ced2cb7f91883d31b82f72063d79b2(state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at3fba97c7c5ced2cb7f91883d31b82f72063d79b2.cargo test --locked -p victory-shader scalar_code_inside_a_whole_wave_section_is_lowered— passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 72 filtered out; finished in 0.00s ); cases: emit::lower::tests::scalar_code_inside_a_whole_wave_section_is_lowered.cargo test --locked -p victory-shader writelane_carries_a_row_total_into_an_exclusive_prefix— passed (ok. 1 passed; 0 failed; 0 ignored; 0 measured; 72 filtered out; finished in 0.00s ); cases: emit:👋:tests::writelane_carries_a_row_total_into_an_exclusive_prefix.Behavior covered: Checks scalar carry propagation inside whole-wave sections and lane-write prefix behavior in the wave lowering path.
Code: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/wave.rs
@alexdeliu on GitHub · 2026-11-24 17:23 UTC · original
Merged onto
main@ffe310eb, this PR (3fba97c7) no longer compiles its tests.crates/victory-shader/src/emit/lower.rs:7135calls thelowers(&words)test helper. Since25b0f888it islowers(words, rsrc2); main's tests pass0.Checked with CI's steps (both clippy runs with
-D warnings,cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87@alexdeliu on GitHub · 2026-11-24 18:34 UTC · original
@AntoninMichelq rechecked
6b303847merged ontomain@ffe310ebon the RX 9070: both CI clippy runs are clean andcargo test --workspacepasses (346 tests).@CaravelaLabs on GitHub · 2026-11-24 21:04 UTC · original
@AntoninMichelq the all-lanes case is still right on
6b303847.v_mov_b32 v1, 7thenv_readfirstlane_b32 s1, v1insides_or_saveexec_b32 s0, -1comes out as the constant 7. Thanks @alexdeliu for confirming the suite is green on this head. This is a separate case.This one panics. Wave32:
llvm-mc gfx1030 matches those words.
sections()dies withindex out of bounds: the len is 32 but the index is 32, at thex[l]in the readfirstlane arm.exec.trailing_zeros()is 32, and that index is not masked.v_readlanemasks withwave - 1. Seegithub.com/Marvisak/VIctory@6b303847ed/crates/victory-shader/src/emit/wave.rs (L383-L392)Wave32 uses only EXEC bits 31-0; the upper half is ignored. With exec_lo clear, EXEC is zero, and
V_READFIRSTLANE_B32is lane 0 (FindFirst1fromLSB, lane 0 if exec is zero), not a crash. The new tests don't cover a narrowed EXEC.AI-assisted; llvm-mc gfx1030 and a Linux shader-lib probe, run on this machine.
@Marvisak on GitHub · 2026-11-25 00:26 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/emit/lower.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
Pull request closed