Shaders: run wave32 pixel and vertex wave operations per 32-lane half #318
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!318
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-318"
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?
@mynzjerko on GitHub · 2026-11-24 23:30 UTC · original
mynzjerko:fix/amd-wave32-host-halves→main· +291 −0 · 2 files · 1 commits · openProblem
In SM 6.6,
WaveSizecan 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::Hostwave operations on console wave32 shaders assumed a 32-lane host wave:mask_dword(waveActiveBallot) always returned dword 0 (lanes 0..31), so upper-half lanes32..63read the lower half's ballot mask.v_mbcnt_lo_u32_b32used the raw host lane index (32..63in the upper half), saturating the mask to0xFFFFFFFFand returning32instead of0..31.v_readlane_b32read fromlane(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.wave64incrates/victory-shader/src/emit/lower.rs, keep each 32-lane half independent:mask_dword: select ballot dword 1 whenlane >= 32, else dword 0.v_mbcnt_lo_u32_b32: masklanewith31.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 < 32is always true, so behavior is unchanged.Verification
wave32_pixel_shader_runs_as_32_lane_halves_on_wave64_hostsincrates/victory-shader/src/emit/wave64_tests.rs(renders a 16x16 full-screen triangle verifyingv_mbcnt_lo,waveActiveBallot+s_ff1+v_readlane_b32, and guardedv_readfirstlane_b32across all 256 pixels):pixel 64: v_mbcnt_lo gave lane 32 >= 32.8 distinct 32-lane halves across 256 pixels).cargo test -p victory-shader(211 passed, 0 failed),cargo clippy -p victory-shader --all-targets -- -D warnings, andcargo xtask policyall pass.AI-assisted (Antigravity); verified locally on an AMD Radeon RX 9070. No game data.
@Frtuchinno on GitHub · 2026-11-25 01:38 UTC · original
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
507c307and the same tree withcrates/victory-shader/src/emit/lower.rsreset to2119b0e, in separate target directories.wave32_pixel_shader_runs_as_32_lane_halves_on_wave64_hostslower.rsfrom2119b0e)ran on the hardware device: 8 distinct 32-lane halves across 256 pixels507c307)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'spixel 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 --lockedon 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 on GitHub · 2026-11-25 02:37 UTC · original
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-amd0e5f4b2): small purple spots left, one appearing while standing still.c96b4f2+ this PR + the same NaN guard (and #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 on GitHub · 2026-11-25 03:16 UTC · original
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:
main.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.