Skip to content

Shaders: run wave32 pixel and vertex wave operations per 32-lane half - #318

Open
mynzjerko wants to merge 1 commit into
fxceless:mainfrom
mynzjerko:fix/amd-wave32-host-halves
Open

mynzjerko wants to merge 1 commit into
fxceless:mainfrom
mynzjerko:fix/amd-wave32-host-halves

Conversation

@mynzjerko

@mynzjerko mynzjerko commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

In SM 6.6, WaveSize can only be declared on compute shaders. On AMD RDNA GPUs (native 32/64-lane waves), the driver can launch console wave32 pixel (and vertex) shaders as 64-lane waves (observed on RDNA 4 / RX 9070).

In crates/victory-shader/src/emit/lower.rs, MaskData::Host wave operations on console wave32 shaders assumed a 32-lane host wave:

  • mask_dword (waveActiveBallot) always returned dword 0 (lanes 0..31), so upper-half lanes 32..63 read the lower half's ballot mask.
  • v_mbcnt_lo_u32_b32 used the raw host lane index (32..63 in the upper half), saturating the mask to 0xFFFFFFFF and returning 32 instead of 0..31.
  • v_readlane_b32 read from lane (0..31) instead of offsetting into the caller's 32-lane half (32..63).
  • first_lane (v_readfirstlane_b32) picked from all 64 lanes instead of the caller's 32-lane half.

When a driver schedules a wave32 pixel/vertex shader in 64-lane waves, this breaks wave-based loops and cross-lane reads. Note: this PR specifically fixes the wave32-on-wave64 lowering semantics; as confirmed by testing on RX 9070 XT, remaining magenta/purple NaN patches in #3 have an additional independent NaN source beyond this bug.

Fix

For self.mask_data == MaskData::Host && !self.x.p.wave64 in crates/victory-shader/src/emit/lower.rs, keep each 32-lane half independent:

  • mask_dword: select ballot dword 1 when lane >= 32, else dword 0.
  • v_mbcnt_lo_u32_b32: mask lane with 31.
  • v_readlane_b32: target (lane & 31) | (me & !31).
  • first_lane: ballot within the caller's 32-lane half and read (me & !31) | firstbitlow(half).

On 32-lane hosts (NVIDIA, WARP, or RDNA3 when the driver picks Wave32) lane < 32 is always true, so behavior is unchanged.

Verification

  • Added hardware GPU pixel-shader test wave32_pixel_shader_runs_as_32_lane_halves_on_wave64_hosts in crates/victory-shader/src/emit/wave64_tests.rs (renders a 16x16 full-screen triangle verifying v_mbcnt_lo, waveActiveBallot + s_ff1 + v_readlane_b32, and guarded v_readfirstlane_b32 across all 256 pixels):
    • Before fix on AMD Radeon RX 9070: failed immediately at pixel 64: v_mbcnt_lo gave lane 32 >= 32.
    • After fix on AMD Radeon RX 9070: passes (8 distinct 32-lane halves across 256 pixels).
  • Confirmed no regression on RX 7800 XT (RDNA 3, driver 32.0.32029.2010): 211 passed, 0 failed.
  • cargo test -p victory-shader (211 passed, 0 failed), cargo clippy -p victory-shader --all-targets -- -D warnings, and cargo xtask policy all pass.

AI-assisted (Antigravity); verified locally on an AMD Radeon RX 9070. No game data.

@Frtuchinno

Copy link
Copy Markdown

An RDNA3 data point for this PR, since the description covers RDNA 3/4 and the test was run on an RX 9070.

Setup: AMD Radeon RX 7800 XT (RDNA3), driver 32.0.32029.2010, Windows 11 Pro build 26300, Rust 1.98.1. I tested this PR's head 507c307 and the same tree with crates/victory-shader/src/emit/lower.rs reset to 2119b0e, in separate target directories.

Tree wave32_pixel_shader_runs_as_32_lane_halves_on_wave64_hosts
without the fix (lower.rs from 2119b0e) passes: ran on the hardware device: 8 distinct 32-lane halves across 256 pixels
with the fix (507c307) passes, same line

Without the fix, no pixel gets v_mbcnt_lo ≥ 32. On this card and driver, the test's pixel shader therefore runs in 32-lane waves and the bug doesn't show up, unlike the RX 9070's pixel 64: v_mbcnt_lo gave lane 32 >= 32. That doesn't rule out the driver picking 64-lane waves for other pixel shaders on RDNA3. It only means this test doesn't exercise the fix here.

With the change, cargo test -p victory-shader --locked on this branch gives 211 passed, 0 failed, 2 ignored. On a host that already runs 32-lane pixel waves the change causes no regression.

AI-assisted (Claude Code): it ran both trees on my machine and drafted this.

@IxMxAMAR

Copy link
Copy Markdown

Three runs on an RX 9070 XT (driver 32.0.32029.2010):

  • fd021bf + this PR, no NaN guard: purple and magenta blocks still on the bedding, posters and a floor strip in the dormitory cutscene.
  • 19feca8 + this PR + PastiiJay's NaN guard on colour exports and typed stores (klbf-amd 0e5f4b2): small purple spots left, one appearing while standing still.
  • c96b4f2 + this PR + the same NaN guard (and Shaders: no REUSE pass for compute programs (AMD compiler crash, #145) #195): no purple in 14 minutes, through the dormitory and the yard view.

So on this card this PR alone was not enough; with the NaN guard on current main it was.

@mynzjerko

Copy link
Copy Markdown
Author

Thanks @Frtuchinno and @IxMxAMAR for the data points on RX 7800 XT and RX 9070 XT!

I've updated the PR description to clarify the scope:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants