Skip to content

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

Open
AntoninMichelq wants to merge 3 commits into
Marvisak:mainfrom
AntoninMichelq:up/whole-wave-steps
Open

AntoninMichelq wants to merge 3 commits into
Marvisak:mainfrom
AntoninMichelq:up/whole-wave-steps

Conversation

@AntoninMichelq

Copy link
Copy Markdown

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

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@jeremygold02

Copy link
Copy Markdown
Contributor

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, crates/victory-shader/src/emit/wave.rs

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…llow lane writes and scalar steps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexdeliu

Copy link
Copy Markdown

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 25b0f88 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

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@alexdeliu

Copy link
Copy Markdown

@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

Copy link
Copy Markdown
Contributor

@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

let l = if name == "v_readlane_b32" {
lane_sel(1)
} else {
// The first lane EXEC holds.
(exec != 0).then(|| exec.trailing_zeros())
};
let x = lanes(src, &vec, &uni);
if let Some(w) = inst.write(Reg::S(code)) {
// One lane's own value is no other lane's.
let s = match l.map(|l| x[l as usize]) {

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.

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 25, 2026
Where a fork-only change duplicates upstream's own version of a feature,
upstream's is kept and the fork's dropped:
- victory-shader is upstream's crate with the fork-only merges replayed
  onto it oldest first; those that do not apply onto upstream are dropped
  (37 of 63: among them Marvisak#704/raw views, gather4_l, the lane-mask and Marvisak#308
  ports, Marvisak#947, Marvisak#1022, Marvisak#1112, Marvisak#1090, Marvisak#1182). Marvisak#284 (legacy fused madds) and
  Marvisak#98 (permlane16 in whole-wave sections) are dropped too: the first
  disagrees with upstream's hardware-checked model, the second refused 46
  programs upstream translates.
- translate: upstream's --cache replaces Marvisak#254's write-cache and work queue;
  Marvisak#378, Marvisak#517, Marvisak#673 and the victory.toml console are re-applied.
- victory-gpu: upstream's stride table, page table and heap views replace
  the fork's Marvisak#704/stride-table wiring; fork-only fixes re-applied on top.

Package (shaders.rpf, translate --validate --list, counts): vertex/pixel
emitted 12559 -> 14295 of 14337, compute 2359 -> 2628 validated, mesh
2730 -> 2811 validated. Tests: the failures left (rect fourth corner,
two stride tests, row order, gather4 at a level, memory table, dynamic
heap slots) fail on upstream main as well on this host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants