Skip to content

rdna2spirv: ds_swizzle_b32 reads 0 from a source lane that isn't running (translator half of #618) - #3126

Open
jakeefr wants to merge 1 commit into
ItsNotRexed:mainfrom
jakeefr:fix/ds-swizzle-missing-lanes-v3
Open

jakeefr wants to merge 1 commit into
ItsNotRexed:mainfrom
jakeefr:fix/ds-swizzle-missing-lanes-v3

Conversation

@jakeefr

@jakeefr jakeefr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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_perm when the pixel shader ran narrower than 32 lanes. I kept that skip as it is and built on it.

ds_swizzle_b32 was translated as 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 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_b32 already does it. Which lanes are missing comes from a ballot, except in pixel shaders, where I compare against SubgroupSize instead. 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-emulate path, 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 new test_ds_swizzle.py runs 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 the check.py change.
  • scripts/run_gpu_tests.py on 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 old ps_bitmask_perm returns 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 SubgroupSize 32, the upper lanes stay undefined there and this change doesn't help that case. A run on an Intel Xe iGPU would tell.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

…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.
@bobcatchris

Copy link
Copy Markdown
Contributor

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.

python -I scripts/run_gpu_tests.py --build runtime/build/linux: 193 shaders translated, 193 pass spirv-val; 116/189 passed, 72 skipped, 1 failed — identical to current main 1628210 on this same M2 (the failure is the separately tracked ps_ssharp S# LOD-bias case). ps_bitmask_perm passes here: 4096/4096 pixels in lanes 0-31 exact, both on main and with this PR. So the change introduces no regression on a 32-wide Apple GPU; it does not exercise the narrow-subgroup case the patch targets.

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.

@yagoviccari1-spec

Copy link
Copy Markdown

Tested the merge of PR #3126 head 1316558 with origin/main 1628210 (tree be247c06) on Windows 11 build 26200.9974, NVIDIA RTX 5060 Ti / driver 621.24 (Vulkan 1.4.357, subgroup 32..32), MSVC 19.44.35207, llvm-mc 21.1.8, SPIRV-Tools v2026.4, CMake 4.5.1 + Ninja 1.13.2:

  • python -m unittest discover -s tests/semantic -p 'test_ds_swizzle.py' -v: 9 tests OK.
  • python -I tests/test_shader_checks.py: 70 tests OK.
  • Full run_gpu_tests.py: 194 shaders translated, 194 pass spirv-val; 143/189 passed, 46 skipped, 0 failed. Device line from the run: NVIDIA GeForce RTX 5060 Ti (subgroup 32..32).
  • The relevant GPU case, ps_bitmask_perm, passes 4096/4096 pixels in lanes 0-31 exact. The wave64 cs_w64x_*permute cases are skipped on this 32-wide device.

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.

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

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:

  • python3 tests/semantic/test_ds_swizzle.py — 9/9 OK

Full GPU suite:

  • python3 -I scripts/run_gpu_tests.py --build /home/deck/opencode/Leonida/runtime/build — 175/189 passed, 14 skipped, 0 failed. Skips are the expected D3D12-owned skips on this Deck.

AI-assisted (OpenCode).

@maxhurst131

Copy link
Copy Markdown
Contributor

Independent check, AI-assisted.

Tested 1316558 on Windows 11 build 26300 (MSVC, Vulkan SDK 1.4.363.0) with the same scripts/run_gpu_tests.py command and --filter bitmask --require-pass:

  • AMD Radeon(TM) Graphics (gfx1036, Ryzen 5 7600X), driver 32.0.21045.29003 (subgroup 32..64): ps_bitmask_perm passes 2048/2048 pixels, lanes 0-31 exact. The fragment stage ran 32-wide here, so lane ^ 9 is a running source for every pixel.
  • NVIDIA GeForce RTX 5070, driver 32.0.16.2124 (subgroup 32..32): passes 4096/4096 pixels, lanes 0-31 exact.

Base 1628210 also passes the same fixture on both, as expected for a full 32-lane wave; this run rules out a regression on AMD and NVIDIA but does not exercise the partial/narrow-wave path. That path still needs Intel Xe or the llvmpipe run you already have.

No game files used; counts only.

@Thatters

Copy link
Copy Markdown
Contributor

Tested 13165587 on RTX 5070 Ti / 621.24 / Windows 11: pass. (AI-assisted test run.)

  • unittest discover -s tests/semantic: 4146 OK. The new test_ds_swizzle.py passes 9/9. Against main 1628210 it gives 2 failures and 21 errors, matching your count.
  • pytest tests/test_shader_checks.py tests/test_run_gpu_pixel_checks.py tests/test_run_gpu_tests.py: 115 passed. With main's check.py, the new test_bitmask_perm_narrow_run_still_judges_the_sources_that_run fails, as it should. tests/test_docs_design_rows.py passes.
  • scripts/run_gpu_tests.py (runtime built with scripts/build_runtime.ps1): 194/194 translate and pass spirv-val, 142/189 passed, 46 skipped, 1 failed. ps_bitmask_perm: 4096/4096 pixels in lanes 0-31 exact. The failure was cs_cvt_f32_sat, where one of its 16 dispatches returned no words. It passed 3/3 re-runs on this PR and passes on main, so it's unrelated.
  • w64_graphics.py: ps_w64_a_swizzle (tier A) ok. All 14 tier A/B fixtures ok, and the 12 tier C fixtures skip as expected on NVIDIA. The output is identical to main.
  • The new path is really in use: the translated ps_bitmask_perm and ps_w64_a_swizzle now declare BuiltIn SubgroupSize (decorated Flat) and compare the swizzle source against it, and both pass spirv-val. This driver accepts the Flat decoration on the built-in.

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.

@JRamos1993

Copy link
Copy Markdown
Contributor

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:

  • scripts/run_gpu_tests.py: 143/189 passed, 46 skipped, 0 failed. main 1628210 gives 143/189, 46 skipped, 0 failed. All 194 test shaders translate and pass spirv-val.
  • tests/semantic/test_ds_swizzle.py: ran 9 tests in 2.521s; OK.
  • tests/test_shader_checks.py: ran 70 tests in 1.107s; OK.

AI-assisted (Claude Code).

@crastinator

Copy link
Copy Markdown
Contributor

Tested 1316558 merged into main 16282101 (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 175/189 native, 175/189 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 37/37.
  • tests/semantic/test_ds_swizzle.py, tests/test_shader_checks.py: 81 passed, 264 subtests passed.

No game files. AI-assisted (Claude Code).

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested 13165587, applied alone on main 16282101: pass, with one note on overlap.
Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo. Two GPUs: Ryzen 7 9700X iGPU (RDNA2, AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), picked with LEONIDA_VK_DEVICE.

  • Tests only (main's translator and check.py): test_ds_swizzle.py 9 tests, 2 failures and 21 errors (OpStore uses an undefined value on the partial-wave cases); tests/test_shader_checks.py 1 failure (test_bitmask_perm_narrow_run_still_judges_the_sources_that_run: the 16-lane frame with a wrong word is still a Skip).
  • Whole PR: test_ds_swizzle.py 9 OK (it loads under unittest discover), test_ds_permute.py 5 OK, tests/test_shader_checks.py 70 OK, test_run_gpu_pixel_checks.py 9 OK, test_run_gpu_tests.py 34 OK. The 53 distinct modules test_ds_swizzle.py translates all pass spirv-val --target-env vulkan1.2.
  • pytest tests/test_translate.py: 541 passed, 4 skipped (same as main).
  • Whole GPU suite with the PR: Radeon 174/189 passed, 15 skipped; RTX 3070 142/189 passed, 46 skipped, 1 failed. Test by test identical to main, where the suite gives the same counts and the same one failure on the RTX 3070 (ps_sdwa_f16_const, 3 of 3 runs alone on clean main). 194 of 194 shaders translate and pass spirv-val. ps_bitmask_perm passes on both GPUs.
  • Overlap: SHADER-503: zero inactive source lanes in DS_SWIZZLE_B32 #2780 changes the same ds_swizzle lines for the same rule; its diff applies on main but not on top of this PR (patch failed: tools/rdna2spirv.py:1313). The check.py, tests/test_shader_checks.py and docs/testing.md hunks here are identical, line for line, to test: judge the swizzle sources that run in a narrow pixel shader (#618) #3136.

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 tests/semantic suite.

@Zombins2

Copy link
Copy Markdown

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.

  • Suite translation: only ps_bitmask_perm.spv differs among 208 common modules in each mode.
  • Initial full AMD runs had two PR-only failures: cs_cmpx_class_f32 (native) and cs_mask_vgpr_exec (emulated), each with a device-line-only diagnostic on a module byte-identical to the parent's. Each test then passed 5/5 targeted reruns on both revisions. The cause of the initial missing-word results is not established; this is not a claim of clean initial full-suite runs.
  • tests/semantic/test_ds_swizzle.py + tests/test_shader_checks.py: 81 passed, 264 subtests passed.

@maxhurst131

Copy link
Copy Markdown
Contributor

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 (rdna2spirv: ds_swizzle_b32 reads 0 from a source lane that isn't running, claimed on #3047).

Tested on NVIDIA RTX 5070 (driver 32.0.16.2124, subgroup 32..32):

  • python -I scripts/run_gpu_tests.py --llvm-mc "wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc" --filter bitmask -> 1/1 passed (ps_bitmask_perm: 4096/4096 pixels in lanes 0-31 exact)
  • Same test on main baseline also passes.

Tested on AMD Radeon Ryzen 7600X iGPU (driver 32.0.21045.29003, subgroup 32..64):

  • Same command -> 1/1 passed (ps_bitmask_perm: 2048/2048 pixels in lanes 0-31 exact)
  • Same test on main baseline also passes.

The PR redirects missing source lanes to the calling lane and masks the result to 0, matching the pattern used by ds_bpermute_b32. On both tested GPUs, the bitmask permutation test passes without regression.

No game files used; counts only. Verified on both GPUs; no unexpected regressions.

- maxhurst131 (second agent), 2026-11-22

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.

10 participants