Shaders: mask ops in a pixel/vertex program never read the high ballot half, so a 64-lane host wave loses lanes 32-63 #125
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#125
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@Luislariosss on GitHub · 2026-11-24 00:42 UTC · original
What I see in the code
For a pixel or vertex program,
Lowersetsmask_data = MaskData::Hostand leavess.wave_sizeatNone(
crates/victory-shader/src/emit/lower.rs:472-476). The doc on that variant (lower.rs:226-231) says ballots aretaken "over the host's wave, whatever its size" and that only uses which mean the same on any wave are allowed.
mask_dword(lower.rs:1153-1189) doeswaveActiveBallotand returnsif high { y } else { x }. With a consolewave32 program nothing goes into
st.highs, so every mask read returns the low dword,x.The mask uses then go through
src32, which also returnsxonly:s_bcnt1_i32_b32/s_ff1_i32_b32(lower.rs:2549-2557): oneunaryBits.i32overx.v_mbcnt_lo_u32_b32(lower.rs:4879-4927): readsxonly, and clamps to 32 forlane >= 32.s_cmp_eq_u32/s_cmp_lg_u32(lower.rs:2322-2353): compares the low halves only.The 64-bit forms right above them (
s_bcnt1_i32_b64,s_ff1_i32_b64,lower.rs:2363-2397) already work on a pair,so they are not affected.
Why it looks wrong on AMD
Nothing forces a wave size outside compute, so the host picks one. On an AMD RX 9060 XT (RDNA4, Windows), a vertex
shader is not necessarily wave32: if the host runs the shader at 64 lanes,
waveActiveBallotreturns a real 64-bitmask, and reading only
xdrops lanes 32-63 from every count, fromv_mbcnt, and from mask equality. AMD is alsothe vendor where pixel and vertex stages default to different wave sizes, so the same shader can hit both cases.
I have not run the title (I do not have the game), so I cannot say how often the emitted code takes this path in
practice. I can only show that the lowering does not use the high half at all.
A test that fails on main
A synthetic wave32 pixel program with
MaskData::Hostands.wave_size == None, built throughir::build(&code, false, 8)and the usual pipeline, usingexec_loas the mask:Counting how many times the high half of the cached ballot pair is referenced, the assertion fails on
main:The question
Is the intended semantics for
MaskData::Hostthe host wave (so a 64-lane host counts all 64 active lanes and thehigh half must be used), or is a mask from a console wave32 program deliberately capped at 32 bits whatever the host
wave is?
If it is the host wave, the fix is four sites and I can send it with the test above:
s_bcnt1_i32_b32ands_ff1_i32_b32delegate to the_b64logic when the operand is a tracked mask,s_cmp_eq/lg_u32compare(x, y)pairs, andv_mbcnt_lo_u32_b32counts over both halves for a mask (and lowers-1straight towaveGetLaneIndex()), which is exact on any wave size. If it is the cap, then the code is right as it stands and Iwill drop it.
I would rather ask than send a change that touches the mask paths of every translated pixel and vertex shader on an
assumption.
AI-assisted.
@Luislariosss on GitHub · 2026-11-24 00:42 UTC · original
The test-only reproduction is on the fork: branch
verify/wave32-maskat https://github.com/Luislariosss/VIctory/tree/verify/wave32-mask (commit7c5abba, two files,#[cfg(test)]only, no production change).cargo test -p victory-shader host_wave32on that branch:It adds
Module::uses_ofunder#[cfg(test)]so the assertion can count operands, and builds the wave32 pixel program from hand-written GFX10 words. The rest of the crate is untouched:cargo test -p victory-shader -- --skip host_wave32still passes.@Luislariosss on GitHub · 2026-11-24 00:47 UTC · original
Rebased onto
main9aef3d9c0(27 commits later) and re-run: the reproduction still fails, atlower.rs:6682now.Branch
verify/wave32-maskat7004dfe3b, still test-only, still 0 commits behind main.One thing worth knowing before this is fixed: #54 touches
crates/victory-shader/src/emit/lower.rstoo (+990/-21) and addsemit/wave_tests.rs, so whichever lands second will need a rebase. #54 is about forcingWaveSize(32)for small compute groups, which does not change the pixel/vertex path this report is about.@TheHoracio on GitHub · 2026-11-24 00:59 UTC · original
Measured on AMD RDNA3: on this GPU the host does run plain vertex and pixel shaders at 64 lanes, so the path in this report is taken in practice. This answers the "how often in practice" part; it does not settle the semantics question.
Environment: RX 7800 XT (driver 32.0.32015.7029), Windows 11 Pro 10.0.26300, DXC 1.9.2602.17, SM 6.6, no
WaveSizeattribute, default PSO flags.Probe: a full-screen triangle drawn with hand-written HLSL (not VIctory output, no game data). The VS passes
WaveGetLaneCount()andWaveActiveCountBits(true)to the PS asnointerpolationvalues, and the PS writes its own two values next to them. I ran two pixel shaders: a trivial one and one with a 64-iteration ALU loop. Targets were 16×16, 64×64 and 256×256.WaveGetLaneCount()in PS / VSA PS wave here had all 64 lanes active, so a ballot taken over the host wave has real bits in its high dword. Reading only
x(s_bcnt1_i32_b32,s_ff1_i32_b32,v_mbcnt_lo_u32_b32,s_cmp_eq/lg_u32as listed above) drops lanes 32-63 for a console wave32 program on this GPU. The VS draw had 3 vertices, so it shows only the wave size (64), not a full wave.Not tested: VIctory's own translated shaders on the GPU (no harness for that here), RDNA2 and RDNA4, and whether the driver ever picks 32 lanes for VS/PS under other conditions, such as larger PS input counts or other PSO states.
AI use: Claude Code (Claude Opus 5.5) wrote the probe, ran it and drafted this comment; the numbers come from a real run on the GPU above.
@TheHoracio on GitHub · 2026-11-24 01:19 UTC · original
A GPU test for this, run on the RX 7800 XT (RDNA3, driver 32.0.32015.7029, Windows 11 26300, Rust 1.98.1 from
rust-toolchain.toml, debug). It draws a synthetic console wave32 pixel program (hand-written GFX10 words, no game data) throughlower::lowerandHost::draw, with a full-screen triangle from a PC-compiledvs_6_6. It checks two things in every pixel:v_mbcnt_lo_u32_b32(exec_lo, 0) < s_bcnt1_i32_b32(exec_lo). This must hold on any host wave size.v_mbcnt_lo_u32_b32(-1, 0)reaches the widest wave's last lane, so lanes past 31 do not share an index.Results, with the test appended to each tree:
maind2a4baepixel 256: v_mbcnt_lo(exec) = 32 is not below s_bcnt1(exec) = 32 (lane 32 …)ecc4eb635caba4v_mbcnt_lo(-1)still clamps to 32 for lanes 32-63So on this GPU, #145 fixes both checks, while #147 fixes the mask counts but not
v_mbcnt_loof -1. Whether lanes past 31 should get their own index is the semantics question asked above. The test makes that choice visible either way.On a host that runs pixel shaders 32 lanes wide, both checks hold trivially. The test skips without a hardware SM 6.6 device or a PC
dxc.exe(VICTORY_PC_DXC, else next todxil.dll).The test (appended to
crates/victory-shader/src/emit/valu_tests.rs)Not tested: RDNA2 / RDNA4, NVIDIA, Intel; the vertex stage; a release build.
AI use: Claude Code (Claude Opus 5.5) wrote the test, ran it on the GPU above and drafted this comment.
@Marvisak on GitHub · 2026-11-25 01:44 UTC · original
Automated triage for the maintainers.
Confirmed on current
main(line numbers have moved since the report). Incrates/victory-shader/src/emit/lower.rs, pixel and vertex programs useMaskData::Host, whose doc says ballots are taken over the host's wave "whatever its size".Lower::mask_dwordreturns the high ballot dword only for a value inst.highs, so for a wave32 program every mask read gets the low dword. The 32-bit forms built on it (s_bcnt1_i32_b32/s_ff1_i32_b32insop,s_cmp_eq/lg_u32, andv_mbcnt_lo_u32_b32invalu, which also clamps the count at lane 32) never see lanes 32-63 of a 64-lane host wave. The RDNA3 measurements in the comments above show pixel shaders do run 64 lanes wide on that GPU, so this code path is taken in practice.The open design question (count over the host wave, or cap at the console's 32 lanes) is for the maintainers. Two open PRs take different answers: #145 reads both ballot halves (and lowers
v_mbcnt_loof -1 to the host lane index), and #434 picks each lane's own half of the ballot (it treats the upper 32 host lanes as a second console wave). Both currently need a rebase. #131, by the same reporter, describes the same defect; this issue is where it is tracked.Generated by Claude Code