Repository navigation
Shaders: lane-indexed ops on a wide host wave use the own console wave - #599
NolanCotter wants to merge 4 commits into
Conversation
For MaskData::Host (pixel and vertex stages, whose programs declare no WaveSize) a host wave may have 64 lanes; its upper half is a second console wave whose bits land in the ballot's second dword. mask_dword returned the first dword for every lane, so mask reads as data (s_bcnt1_i32_*, s_ff1_i32_*, v_mbcnt_*, s_cmp_eq/lg_u32/u64) gave the upper half's lanes the lower console wave's mask values. mask_dword now selects the ballot half by the reader's host lane. v_mbcnt_lo counts bits of the lane's own half below its lane in it, and v_mbcnt_hi is src1 alone on wave32, whose mask has no high half. Both are unchanged when the host wave is 32 lanes. Fixes Marvisak#131. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…names The wave32 mask-read test now asserts the pick's shape: an unsigned `lane >= 32` compare selecting the ballot's second dword over the first, `lane & 31` for v_mbcnt_lo, and a bit count of a constant zero for v_mbcnt_hi. A second test covers the paths that must not pick: wave64 programs (own dwords) and compute (the whole host wave is the console's). emit::bitcode::Module gains a test-only inst_lines dump to support that. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Under MaskData::Host a wave32 program's lane numbers stay host lanes, so a v_mbcnt_lo rank of the upper half's console wave takes its 32-lane base: v_mbcnt_lo(-1) still reports the lane index, and the value composes with host-lane reads like v_readlane. The mask itself stays per console wave, so s_bcnt1, s_ff1 and s_cmp keep their own wave's count and the first wave's divergence never feeds a second wave's scalars. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
For MaskData::Host a wave32 program's 64-lane host wave is two console
waves, but the lane-indexed ops either refused or read the wrong wave:
- v_readlane at a constant lane errored ("a cross-lane operation
outside compute"), even for wave64 programs where the lane is
already a host lane; on wave32 the console's lane k of the lane's
own wave is host lane k | (lane & 32).
- v_writelane refused on every pixel and vertex program; on host
lanes the equality is already host-space for a computed lane.
- v_readfirstlane read the host wave's first active lane - the first
console wave's lane - for lanes 32-63; it now reads the low set bit
of the lane's own half of the exec ballot, renumbered to a host
lane.
Closes Marvisak#593.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Tested offline against main
AI-assisted. |
|
GPU check of the three lane ops on two hosts: correct on every pixel, but both hosts ran the pixel program 32 lanes wide, so the 64-lane case is still unexercised. What ran. This head (on #434) merged with
So the PR turns a refused program into one that gives the right lanes on 32-lane hosts, NVIDIA and AMD. This RDNA2 iGPU's driver picked 32-lane waves for the pixel shader, unlike the RDNA3 card in #125, so the AI use: Claude Code (Claude Opus 5.5) wrote the local test, ran it on both GPUs and drafted this comment. |
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Tested on Windows 11 with MSVC Rust 1.98.1. All 72 unit tests pass!
However, cargo clippy -p victory-shader --tests -- -D warnings surfaces two warnings in the new unit test in crates/victory-shader/src/emit/lower.rs:
- Line 6813: unused variable i:
ust .filter(|(_i, s)| { - Line 6889: clippy::useless_format:
ust .any(|i| i.starts_with("call f") && i.contains("k117, ")),
Once those two warnings are resolved, this is ready to approve!
|
Tested this stack on an RX 6600 XT (RDNA 2, driver 32.0.21045.5002), Ryzen 5 5600X, Windows 11 22631, Rust 1.98.1. Confirmed that pixel shaders run in wave64 on this GPU. Added 11 regression tests covering wave32 mask and lane operations, partial coverage and divergent control flow, with pixel-by-pixel validation against expected wave32 semantics. Results on actual hardware
With #599, all translated test programs produced zero incorrect pixels. Stability: 20/20 regression suite runs and 10/10 full shader library suite runs (83 tests), without hangs. Interestingly, #145 makes the EXEC count worse on this GPU, returning 64 instead of 32. Regression testsTests only, stacked on #599: qntic@614f68b Happy to submit these tests upstream or have them cherry-picked into this PR. No game data used. Title behavior not tested. |
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Tested and verified on Windows 11 MSVC (Rust 1.98.1).
- \�_wave32_lane_op_uses_its_own_console_wave\ passes cleanly.
- Constant console lanes now correctly compute the 32-lane base (\k | (lane & 32)) for wide host waves on wave32 graphics stages, and \�_readfirstlane\ correctly resolves the low bit of its own ballot half.
- Eliminates erroneous \� cross-lane operation outside compute\ refusals.
- Asset policy is 100% compliant (\cargo xtask policy\ ok: 151 files).
#599 + qntic's
|
| Test | main ba7d873 (first / lane / value) |
#599 3823462 (first / lane / value) |
|---|---|---|
| exec counts and ranks | 2048 / 2048 / 2048 | 0 / 2048 / 2048 |
| compare masks | 2048 / 2048 / 2009 | 0 / 2048 / 2048 |
first set lane (s_ff1) |
2048 / 2048 / 1472 | 0 / 2048 / 0 |
| readlane (constant lane) | not translated: "a cross-lane operation outside compute" | 0 / 2048 / 0 |
narrowed exec (s_and_saveexec) |
2048 / 2048 / 764 | 0 / 2048 / 764 |
| readlane at a computed lane | 2048 / 2048 / 2048 | driver crash (see 3) |
| writelane | not translated | 0 / 2048 / 64 |
| any / all | 2048 / 2048 / 736 | 0 / 2048 / 0 |
mbcnt lo / hi |
2048 / 2048 / 2048 | 0 / 2048 / 2048 |
| lanes leaving a loop | 2048 / 2048 / 1102 | 0 / 2048 / 0 |
| encodings | ok | ok |
What this shows
1. #599 is a big improvement on a true 64-lane host.
v_readfirstlane/ first lane is now right on every pixel (2048 wrong before, 0 now).- Constant-lane readlane and writelane now translate instead of being refused.
- The
s_ff1, any/all and loop values are now all correct.
2. Every remaining "lane" error is exactly +32, in the upper half of the host wave. Example: pixel 256, got [256, 32, 2080], wanted [256, 0, 2048]. That's #599's documented choice in the v_mbcnt lowering ("lane numbers stay host lanes: a second wave's rank takes its 32-lane base"), while qntic's tests expect console lanes 0–31. The mbcnt, exec-rank and compare values are off by the same 32. It would help to settle which convention is intended:
- Console code that uses
v_mbcnt_lo(mask)as a rank (stream compaction,base + rankinto LDS or a UAV) would write 32 slots too far in the second console wave. - Keeping host numbering does make computed-lane
readlane/writelanework without remapping, but see the next point.
3. The two numbering conventions conflict, with a concrete failure. In writelane_writes_the_console_waves_lane, the lane comes from s_ff1(vcc). That result is console-space (the ff1 test's values are right), but the writelane me == lane test is host-space. So the upper console wave never matches. The 64 wrong values are exactly the upper half's targeted lanes: pixel 256 got 0, wanted 9.
4. AMD driver crash on #599's computed-lane v_readlane. readlane_at_a_computed_lane_reads_the_console_waves_lane crashes with STATUS_ACCESS_VIOLATION (0xC0000005) inside CreateGraphicsPipelineState for the translated pixel shader. Instrumented: both layout-probe pipelines are created and drawn, then the process dies creating the third pipeline. The DXIL passes dxil.dll 1.9.2602.17, so this is a driver bug, but it's reproducible. On main the same program creates its pipeline and draws (with wrong values). So it's #599's new waveReadLaneAt with a per-lane-computed lane, or the own-half ballot path, that this compiler can't handle. Worth knowing because a crash in pipeline creation takes down the whole app, not just one draw. A workaround might be to make the lane wave-uniform before waveReadLaneAt (e.g. waveReadLaneFirst of the lane within each half), which may also be what the driver expects.
5. Why the 6600 XT passed 11/11 (a guess). RDNA2 picks wave32 or wave64 per shader. qntic's layout_ps can run 64 wide while the translated program runs 32 wide, in which case the upper-half paths never run. Only GCN (or forcing wave64) guarantees they do. I haven't verified this.
Happy to rerun on this card after changes, or to test a minimal shader for the crash in (4).
AI-assisted (test runs, analysis and write-up); every number above is from a real run on my machine, with no game data.
|
Thanks for running my tests on Polaris! This is exactly the kind of cross-architecture validation I was hoping for. Your findings regarding per-shader wave size selection on RDNA2 are particularly interesting. I'll investigate whether the translated shaders actually execute in wave32 or wave64 on my RX 6600 XT, rather than relying solely on the layout probe. The +32 lane numbering mismatch and the writelane inconsistency definitely deserve further investigation. Thanks for the detailed results! |
|
@qntic, anything discovered so far based on my tests along with yours? |
|
the layout probe confirmed wave64 but i havent checked the wave size inside each translated shader yet. gonna test that and see if your theory is right |
|
you were right, i added wave size instrumentation inside each translated pixel shader. on my 6600 xt main reports wave64 but #599 reports wave32 across all tested pixel programs. so my previous 11/11 result didnt actually cover the two console waves in one host wave case. ive updated the tests to report that case as not exercised. thanks for catching this |
…s in The pixel wave tests took the host's wave layout from a native probe shader, but a driver chooses the wave size per pixel shader. On an RX 6600 XT (RDNA 2) the translated programs of main ran 64 lanes wide, the same programs translated with Marvisak#599 32 lanes wide: their results then say nothing about a host wave holding two console waves. Each test now draws its translated program a second time with the w channel of its colour export replaced by WaveGetLaneCount (a test-only switch in the pixel export lowering, LANE_COUNT_IN_W) and logs the lane counts it saw. Where they are not all 64, the test says the case was not exercised and skips its checks. Run on main, the same hook reports 64 for every program, so the hook itself does not make the driver choose 32.
|
Thank you for validating my theory, i appreciate it alot. Makes me happy lol :) |
|
No problem man 😁 |
…arvisak#599 part 3) Renumber second console wave v_mbcnt_lo rank to host lanes and make v_readlane_b32, v_writelane_b32, and v_readfirstlane_b32 operate on the reader's own console wave half under MaskData::Host.
|
for reference, here's the instrumentation behind my previous wave size results. it replaces the pixel shader's w output with WaveGetLaneCount() in test builds. measured wave64 on main and wave32 on this pr. |
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
Depends on: #434 (uses its
mask_dwordhalf-select and theinst_lines/lower_programtest helpers).Closes #593. Same
MaskData::Hostfamily as #131 (#434): for wave32 pixel/vertex programs the host wave can be 64 lanes, whose upper half is a second console wave — but the lane-indexed ops either refused translation or read the wrong wave.What changed (
crates/victory-shader/src/emit/lower.rs)v_readlane_b32: a constant lane operand tookcross_lane(false)→a cross-lane operation outside compute, so the whole program was refused — including wave64 programs where a constant lane is already a valid host lane. Now: host lanes read directly (unchanged), constant lanes readk | (lane & 32)— the console lane of the lane's own wave — on wave32 programs, and plainlykon wave64.v_writelane_b32: refused unconditionally on PS/VS. Now: on host lanes theme == lanetest is already host-space for computed lanes; a constant lane gets the same| (lane & 32)base.v_readfirstlane_b32:waveReadLaneFirstreturns the host wave's first active lane — wave A's — for lanes 32-63. On wave32 programs it now finds the low set bit of the lane's own half of the exec ballot and renumbers it to a host lane, thenwaveReadLaneAts it.Test
a_wave32_lane_op_uses_its_own_console_wave(synthetic wave32 GFX10 pixel program, no game files): assertswaveReadLaneAtis emitted with lane5 | (lane & 32)for both readlane and writelane's equality test, and that readfirstlane picks the low bit of the lane's own ballot half before renumbering. The wave64 lowering of the same program is asserted to emit directwaveReadLaneAt(lane 5)/waveReadLaneFirstwith no renumbering. The test fails on the pre-change lowering (the ops refuse or emit nothing).cargo test -p victory-shader: 59/59.cargo fmt --check: clean.No game files. AI-assisted.