Shaders: follow lane writes and scalar steps in whole-wave sections #308

Closed
github-bot wants to merge 3 commits from gh-pr/308/head into gh-pr/308/base
Owner

@⁠AntoninMichelq on GitHub · 2026-11-24 02:13 UTC · original
AntoninMichelq:up/whole-wave-steps → main · +343 −38 · 2 files · 3 commits · closed without merging

Requested 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_b32 with 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).
  • Scalar ALU on uniforms:
    • s_mov_b32 copies;
    • s_add/min/max/and/or/xor combining two v_readlane results (the two 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.

A lane's own value from before the section, once moved to another lane by DPP, v_permlanex16 or v_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 the v_permlanex16 arm is touched. No dependency on other open PRs.

How it was tested

  • cargo test -p victory-shader on Linux: all tests pass. New tests:

    • emit::wave::tests::writelane_carries_a_row_total_into_an_exclusive_prefix
    • emit::wave::tests::wave64_halves_combine_in_a_scalar_add
    • emit::wave::tests::another_lanes_own_value_is_not_the_lanes_own
    • emit::lower::tests::scalar_code_inside_a_whole_wave_section_is_lowered

    All test programs were assembled with llvm-mc for gfx1030.

  • cargo check -p victory-shader --target x86_64-pc-windows-msvc passes.

  • 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 translate on the integration stack.

Where 3D rendering stands on an RX 7600 (Windows 11)

  • In the world's first cutscene, props, characters, cables and vehicle tyres now render (seen in a G-buffer view).
  • Ground, roads, buildings, textures, sky and lighting are still missing: the lighting/compose output is black.
  • No GPU hang (DXGI_ERROR_DEVICE_HUNG) in the last two ~4-minute world runs.
  • About 10,000 draws per frame, at well under 1 fps.

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

**@⁠AntoninMichelq** on GitHub · 2026-11-24 02:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/308) `AntoninMichelq:up/whole-wave-steps` → `main` · +343 −38 · 2 files · 3 commits · closed without merging <!-- claude-projects-attribution: {"github_login":"AntoninMichelq"} --> _Requested by **4nto** · [project thread](https://claude.ai/code/project/chan_01XYoPEzLL1bj63HP9pniGvs?thread=cmsg_01XYoPEzLL1bj63HP9pniGvsYRPS2v37oeDeGaCHT7dFsi)_ ## 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_b32` with 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). - Scalar ALU on uniforms: - `s_mov_b32` copies; - `s_add`/`min`/`max`/`and`/`or`/`xor` combining two `v_readlane` results (the two 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`. A lane's own value from before the section, once moved to another lane by DPP, `v_permlanex16` or `v_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 the `v_permlanex16` arm is touched. No dependency on other open PRs. ## How it was tested - `cargo test -p victory-shader` on Linux: all tests pass. New tests: - `emit::wave::tests::writelane_carries_a_row_total_into_an_exclusive_prefix` - `emit::wave::tests::wave64_halves_combine_in_a_scalar_add` - `emit::wave::tests::another_lanes_own_value_is_not_the_lanes_own` - `emit::lower::tests::scalar_code_inside_a_whole_wave_section_is_lowered` All test programs were assembled with llvm-mc for gfx1030. - `cargo check -p victory-shader --target x86_64-pc-windows-msvc` passes. - 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 translate` on the integration stack. ## Where 3D rendering stands on an RX 7600 (Windows 11) - In the world's first cutscene, props, characters, cables and vehicle tyres now render (seen in a G-buffer view). - Ground, roads, buildings, textures, sky and lighting are still missing: the lighting/compose output is black. - No GPU hang (DXGI_ERROR_DEVICE_HUNG) in the last two ~4-minute world runs. - About 10,000 draws per frame, at well under 1 fps. These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone. 🤖 Generated with [Claude Code](https://claude.com/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
Since 25b0f88 on main the helper takes the program's rsrc2; the
whole-wave scalar test passed only the words (reported on upstream
PR 308).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:46 +00:00
github-bot closed this pull request 2026-11-26 03:58:46 +00:00
Author
Owner

@⁠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 at 3fba97c7c5ced2cb7f91883d31b82f72063d79b2.

  • 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

**@⁠jeremygold02** on GitHub · 2026-11-24 04:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7121900492) Tested PR #308 at head `3fba97c7c5ced2cb7f91883d31b82f72063d79b2` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `3fba97c7c5ced2cb7f91883d31b82f72063d79b2`. - `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::wave::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](https://github.com/Marvisak/VIctory/blob/3fba97c7c5ced2cb7f91883d31b82f72063d79b2/crates/victory-shader/src/emit/lower.rs), [crates/victory-shader/src/emit/wave.rs](https://github.com/Marvisak/VIctory/blob/3fba97c7c5ced2cb7f91883d31b82f72063d79b2/crates/victory-shader/src/emit/wave.rs)
Author
Owner

@⁠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:7135 calls the lowers(&words) test helper. Since 25b0f888 it is lowers(words, rsrc2); main's tests pass 0.

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 17:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7139125878) Merged onto `main` @ `ffe310eb`, this PR (`3fba97c7`) no longer compiles its tests. `crates/victory-shader/src/emit/lower.rs:7135` calls the `lowers(&words)` test helper. Since 25b0f888 it is `lowers(words, rsrc2)`; main's tests pass `0`. <sub>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</sub>
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 18:34 UTC · original

@⁠AntoninMichelq rechecked 6b303847 merged onto main @ ffe310eb on the RX 9070: both CI clippy runs are clean and cargo test --workspace passes (346 tests).

**@⁠alexdeliu** on GitHub · 2026-11-24 18:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7140827817) @⁠AntoninMichelq rechecked `6b303847` merged onto `main` @ `ffe310eb` on the RX 9070: both CI clippy runs are clean and `cargo test --workspace` passes (346 tests).
Author
Owner

@⁠CaravelaLabs on GitHub · 2026-11-24 21:04 UTC · original

@⁠AntoninMichelq the all-lanes case is still right on 6b303847. v_mov_b32 v1, 7 then v_readfirstlane_b32 s1, v1 inside s_or_saveexec_b32 s0, -1 comes 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:

s_or_saveexec_b32 s0, -1
s_mov_b32 exec_lo, 0
s_mov_b32 exec_hi, 1
v_readfirstlane_b32 s1, v0
s_mov_b32 exec_lo, s0

llvm-mc gfx1030 matches those words. sections() dies with index out of bounds: the len is 32 but the index is 32, at the x[l] in the readfirstlane arm. exec.trailing_zeros() is 32, and that index is not masked. v_readlane masks with wave - 1. See github.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_B32 is 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.

**@⁠CaravelaLabs** on GitHub · 2026-11-24 21:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7144445915) @⁠AntoninMichelq the all-lanes case is still right on `6b303847`. `v_mov_b32 v1, 7` then `v_readfirstlane_b32 s1, v1` inside `s_or_saveexec_b32 s0, -1` comes 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: ``` s_or_saveexec_b32 s0, -1 s_mov_b32 exec_lo, 0 s_mov_b32 exec_hi, 1 v_readfirstlane_b32 s1, v0 s_mov_b32 exec_lo, s0 ``` llvm-mc gfx1030 matches those words. `sections()` dies with `index out of bounds: the len is 32 but the index is 32`, at the `x[l]` in the readfirstlane arm. `exec.trailing_zeros()` is 32, and that index is not masked. `v_readlane` masks with `wave - 1`. See https://github.com/Marvisak/VIctory/blob/6b303847ed870a568f1c0e5d2a3786a03af37cd0/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_B32` is 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.
Author
Owner

@⁠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

**@⁠Marvisak** on GitHub · 2026-11-25 00:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7148519165) <!-- victory-triage v1 head=6b303847ed870a568f1c0e5d2a3786a03af37cd0 verdict=needs-rebase at=2026-11-25T00:13:20Z --> 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](https://claude.ai/code)_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!308
No description provided.