Repository navigation
rdna2spirv: ds_swizzle_b32 reads 0 from a source lane that isn't running (translator half of #618) - #3126
rdna2spirv: ds_swizzle_b32 reads 0 from a source lane that isn't running (translator half of #618)#3126jakeefr wants to merge 1 commit into
Conversation
…ing (ItsNotRexed#618) ds_swizzle was a bare OpGroupNonUniformShuffle. A shuffle from an invocation that isn't running is undefined in SPIR-V, and a swizzle asks for exactly that in the missing lanes of a partial wave, and in the upper lanes where a driver runs a wave32 pixel shader narrower than 32. I now redirect a missing source to the calling lane and mask the result to 0, the way ds_bpermute_b32 already does. Which lanes are missing comes from a ballot of the running invocations, except in a pixel shader, where I compare the source lane with the SubgroupSize built-in. The quad swizzles of a derivative read helper pixels, and whether a helper invocation counts in a ballot is the implementation's choice before SPIR-V 1.6, so a ballot could zero a neighbour the hardware reads. A pixel shader's waves are never partial. The --wave64-emulate path is unchanged, and so is a source lane that runs but is off in EXEC (not measured on hardware; noted as open in design.md). This is the translator half of ItsNotRexed#618. The test half is ItsNotRexed#1318, which skips ps_bitmask_perm when the pixel shader ran narrower than 32 lanes. On top of that skip I added one condition: where the "pippi" source lane does run (every lane at 16 wide), its word still has to be right, so a narrow run only excuses the sources that are missing. - tests/semantic/test_ds_swizzle.py: nine patterns on full wave32 and wave64 and on 16-, 18-, 20-, 31- and 40-thread groups, plus the shape of the pixel-shader form. It fails on the old translator. - docs/design.md: a contract row. docs/testing.md: a note on ps_bitmask_perm on Intel. On Mesa llvmpipe 25.2.8 (subgroup 8) the old ps_bitmask_perm returns the lane index modulo 8, pixel (0, 1, 1, 0) at lane 0; the new one (lane, 0, 0, 0) on every pixel. Not run on Intel or AMD hardware.
|
Apple M2 no-regression data (the PR body notes no Intel/AMD hardware was available; this is an Apple/32-wide data point only). Tested head 1316558 on Apple M2 (Mac14,3), macOS 26.4 (25E246), MoltenVK 1.4.2 (direct), subgroup 4..32, llvm-mc 23.1.6, Python 3.13.18.
Build note: full build fails on AppleClang 17 at vk_pipeline_check.cpp:567 (BUILD-822, fixed by open PR #2927); GPU binaries built, so the suite above is valid. Head fetched unchanged into a separate worktree; no rebase/edit/push. Synthetic shaders and counts only; no game files. AI-assisted. |
|
Tested the merge of PR #3126 head 1316558 with
Scope: functional checks only; I did not independently re-derive the inactive-lane rule or test it on a 64-wide device. No game files used. Ran with an AI agent on my machine. |
|
Tested 1316558 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass. Semantic tests:
Full GPU suite:
AI-assisted (OpenCode). |
|
Independent check, AI-assisted. Tested
Base No game files used; counts only. |
|
Tested
On this device the fragment subgroup is always 32, so the narrow-run case (#618) can't happen here. This run shows the new form gives the same results on a full-width device. It doesn't exercise the zeroing itself; that needs Intel as you say. No game files used. |
|
Tested 1316558 merged onto main 1628210 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:
AI-assisted (Claude Code). |
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested
Not checked: a device that runs the pixel shader 8 or 16 lanes wide (both GPUs here ran it at 32 lanes or wider, so the narrow-run path was only exercised on the CPU), and the complete |
|
AI-assisted. No game files used. AMD fixture/checker clarification for 1316558 against parent ec8ec4c. Ryzen 5 7600X iGPU (gfx1036, AMD 26.10.1, supported subgroup range 32..64), Windows 11 build 26200; test programs built from the parent with MSVC 19.50. A detail about interpreting the 7600X report's 2048/2048 count: stock check_bitmask_perm first requires a 64x64 frame, then skips pixels whose exported lane word is >=32. Thus 2048/2048 means 2048 of 4096 pixels were judged; it is not evidence of a smaller frame or, by itself, a 32-wide fragment subgroup. In our four AMD frames (PR/parent, native/emulated), exactly 2048 pixels carry lane word 32 and 2048 carry values 0-31. With the fixture's v_mbcnt_lo(-1,0), that pattern is consistent with a 64-wide subgroup: upper-half invocations count all 32 low bits. An ordinary 32-wide execution of this unchanged fixture would put every exported lane word below 32, so the checker would judge all 4096 pixels. The other report uses a different driver, so our frames do not independently measure its actual subgroup width; its count and the stated 32-wide interpretation need distinguishing. Our complete 4096-pixel frame is byte-identical between PR and parent in both modes. The 2048 judged pixels are exact; the upper-half pixels are unjudged, not claimed correct. This run does not test the narrow/partial-wave behavior targeted by the PR and is not a full correctness verdict.
|
|
Independent check, AI-assisted, two GPUs, main branch baseline. Environment: Windows 11 build 26300, Vulkan SDK 1.4.363.0, MSVC RelWithDebInfo, llvm-mc 21.1.8 (WSL Ubuntu). PR #3126 ( Tested on NVIDIA RTX 5070 (driver 32.0.16.2124, subgroup 32..32):
Tested on AMD Radeon Ryzen 7600X iGPU (driver 32.0.21045.29003, subgroup 32..64):
The PR redirects missing source lanes to the calling lane and masks the result to 0, matching the pattern used by No game files used; counts only. Verified on both GPUs; no unexpected regressions.
|
Claimed in the coordination issue as: #1218 (comment)
What and why
This is the translator half of #618. The test half already landed in #1318, which skips
ps_bitmask_permwhen the pixel shader ran narrower than 32 lanes. I kept that skip as it is and built on it.ds_swizzle_b32was translated as a bareOpGroupNonUniformShuffle. A shuffle from an invocation that isn't running is undefined in SPIR-V, and a swizzle asks for exactly that in two cases: the missing lanes of a partial wave, and the upper lanes when a driver runs a wave32 pixel shader narrower than 32. So the skip in #1318 hides a value that is undefined, not just unchecked.Now a missing source lane is redirected to the calling lane and the result is masked to 0, the way
ds_bpermute_b32already does it. Which lanes are missing comes from a ballot, except in pixel shaders, where I compare againstSubgroupSizeinstead. Derivative code swizzles from helper pixels, and before SPIR-V 1.6 it's up to the implementation whether a helper counts in a ballot, so a ballot could zero a neighbour the hardware actually reads. Pixel shader waves are never partial, so the size is the only question there.Not changed: the
--wave64-emulatepath, and a source lane that runs but is off in EXEC (not measured on hardware, noted as open in design.md).One small addition to #1318's skip, in
bitmask_perm_narrow_skip: where the "pippi" source lane (lane ^ 9) does run, its word still has to be right. At 16 lanes that is every pixel, at 8 lanes none. Before this, a 16-wide run with a wrong "pippi" word was skipped. #1318's own tests pass unchanged.Tested
python -m unittest discover -s tests/semantic: all pass on main at ec8ec4c. The newtest_ds_swizzle.pyruns nine patterns on full wave32 and wave64 and on 16-, 18-, 20-, 31- and 40-thread groups. With main's translator it gives 2 failures and 21 errors (the partial-wave cases store an undefined value).tests/test_shader_checks.py,tests/test_run_gpu_pixel_checks.py,tests/test_run_gpu_tests.py: 115 pass. The one new test fails without thecheck.pychange.scripts/run_gpu_tests.pyon Mesa llvmpipe 25.2.8 (LLVM 20, subgroup 8), llvm-mc 18.1.3, run on main at f85582e: 137 of 137 translate and pass spirv-val, 83/133 passed, 50 skipped, the same with main's translator and with this one. On llvmpipe the oldps_bitmask_permreturns the lane index modulo 8 (pixel(0, 1, 1, 0)at lane 0); the new one gives(lane, 0, 0, 0)on every pixel.What I couldn't check: no Intel or AMD hardware here. If an Intel driver runs the shader 16 wide but reports
SubgroupSize32, the upper lanes stay undefined there and this change doesn't help that case. A run on an Intel Xe iGPU would tell.Checklist
docs/design.md, with how it was confirmed.