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

Closed
AntoninMichelq wants to merge 3 commits from upstream-pr/308 into main
AntoninMichelq commented 2026-11-24 02:13:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AntoninMichelq on 2026-11-24T02:13:31Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573052962 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/308). Originally posted by [AntoninMichelq](https://github.com/AntoninMichelq) on 2026-11-24T02:13:31Z. --- <!-- 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
jeremygold02 commented 2026-11-24 06:55:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:18:37Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121900492 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7121900492). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:18:37Z. --- 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)
alexdeliu commented 2026-11-24 18:05:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:23:38Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139125878 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7139125878). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:23:38Z. --- 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>
alexdeliu commented 2026-11-24 19:04:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T18:34:10Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140827817 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7140827817). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T18:34:10Z. --- @AntoninMichelq rechecked `6b303847` merged onto `main` @ `ffe310eb` on the RX 9070: both CI clippy runs are clean and `cargo test --workspace` passes (346 tests).
CaravelaLabs commented 2026-11-24 21:28:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CaravelaLabs on 2026-11-24T21:04:44Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144445915 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7144445915). Originally posted by [CaravelaLabs](https://github.com/CaravelaLabs) on 2026-11-24T21:04:44Z. --- @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.
Marvisak commented 2026-11-25 01:07:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:26:52Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148519165 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/308#issuecomment-7148519165). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:26:52Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-25 20:04:58 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!308
No description provided.