Skip to content

SHADER-503: zero inactive source lanes in DS_SWIZZLE_B32 - #2780

Merged
ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/ds-swizzle-exec
Nov 22, 2026
Merged

ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/ds-swizzle-exec

Conversation

@evilclanker9000

@evilclanker9000 evilclanker9000 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as SHADER-503.

What and why

A fragment that swizzles in a disabled neighbor's color could receive the old VGPR contents. If the source invocation was absent, the subgroup shuffle produced an undefined value. Use the same guarded read as backward permute for both DS swizzle patterns. A disabled destination keeps its previous color. The published gfx1036 and gfx1150 measurements confirm that a source disabled by EXEC supplies zero.

Related tracker item SHADER-207 links to #618, the closed Intel subgroup-width report. The full-width reproduction here exercises a disabled source within an otherwise complete subgroup. The seven-invocation CPU case models an absent source. Its result on hardware is unverified.

Tested

  • A handwritten fragment shader sets the source to 0.75 and destination to 0.5, disables lane 1 of each group of four, swaps adjacent values, restores EXEC, then exports the result and writes the same register to a per-lane readback buffer. Tested quad-permute and bitmask encodings.
  • On main at ec8ec4c each pattern produced 24/32 correct lane values, including a stale 0.75 where the source should supply zero. With seven invocations the interpreter rejected an undefined value. On this branch both patterns produced 32/32 and 7/7 correct values. The repeating four-lane result is 0, 0.5, 0.75, 0.75.
  • LLVM assembled the two fragment shaders and their two wave64-emulated compute counterparts for gfx1030. All four translated and passed Vulkan 1.2 spirv-val both before and after. The fragment results were checked with the CPU interpreter. No local GPU or driver was used.
  • The targeted DS permute, wave64 subgroup and wave64 half-wave suites passed 78 tests and 39 subtests.

AI-assisted with Codex.

Checklist

  • No game data, keys or decryption, including in logs or reports quoted here.
  • The translator rule and its verification are in the contract table of docs/design.md.

Neighbor colors can remain in a disabled lane. Use the same masked lane read as backward permute so an active fragment gets zero for a disabled or absent neighbor while a disabled destination keeps its previous value.
Both DS callers pass a decoded VGPR operand to the destination writer.
@tupacfan04

Copy link
Copy Markdown
Contributor

Code read of 2c87d6db (I didn't run it; the newest commit only changes a type hint). Looks right. ds_swizzle_b32 now goes through the same guarded read as ds_bpermute_b32: an EXEC-off source gives 0 via the OpSelect before the shuffle, and an absent subgroup lane is redirected to the caller's own lane before OpGroupNonUniformShuffle, then masked to 0. So no undefined shuffle result is ever consumed, and the bitwise masks keep MSL from turning it into a short-circuit. The ds_bpermute refactor keeps the old behaviour. In emulation sub_lane returns wave_lane(), so half | src still picks the right 32-lane half.

AI-assisted review (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Linux (WSL2 Ubuntu, Python 3.12) and native Windows 11 (Python 3.13.1), CPU only: pass. Merges cleanly with main. tests/semantic/test_ds_permute.py: Linux 6 tests OK, Windows 6 tests OK, 0 skips on both. Negative control (tools/rdna2spirv.py restored to main, Linux): fails (2 failures, 2 errors), so the new test covers the change. Trial merges with #2739, #2742, #2722 and #2778 are clean; the docs/design.md row it edits is also edited by many other open PRs, so expect rebases there.

@padhossein

Copy link
Copy Markdown
Contributor

Independent DS swizzle Vulkan A/B (2c87d6db). I dispatched a handcrafted compute program on Mesa llvmpipe 26.1.6 (one 8-wide subgroup). It writes source values 33–40, disables lane 0 in EXEC, swizzles each quad from its first source lane, then re-enables lane 0 for readback. Base returned [0x12345678,33,33,33,37,37,37,37]; this head returns [0x12345678,0,0,0,37,37,37,37], matching the disabled-source rule and preserving the inactive destination. Both modules passed spirv-val and had no Vulkan validation diagnostics.

Synthetic inputs only. AI-assisted (Codex).

@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested 2c87d6d on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 175/189 passed, 14 skipped, 0 failed on both GPUs. Compared with the same suite at the merge base ec8ec4c on the same machine, every test has the same result.
  • python -m unittest discover -s tests/semantic: 4138 OK

No game files. AI-assisted.

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested 2c87d6d on Steam Deck LCD (AMD Custom GPU 0405 "Van Gogh" / RDNA2, RADV Mesa 26.2.0-devel, Vulkan 1.4.350, SteamOS 3.9.5): pass.

  • PYTHONPATH=.:tests:tests/semantic:tools python3 tests/semantic/test_ds_permute.py — 6/6 OK.
  • python3 -I scripts/run_gpu_tests.py --build /home/deck/opencode/Leonida/runtime/build — 175/189 passed, 14 skipped, 0 failed (all skips D3D12-owned fixtures).

AI-assisted (OpenCode).

@SashaTun

Copy link
Copy Markdown
Contributor

Checked 2c87d6db on Windows 11 with an NVIDIA RTX 5060 (driver 621.01), a third platform for this change (Linux llvmpipe and AMD RADV are already covered).

  • python -m unittest discover -s tests/semantic on the branch: 4138 tests, OK. tests/semantic/test_ds_permute.py: 6 tests OK, 0 skips.
  • Negative control: with tools/rdna2spirv.py reverted to main (ec8ec4c) and this branch's test and fixture in place, SwizzleExecTests fails (2 failures, 2 errors): the stale 0.75 where the source should supply zero, and the interpreter rejecting an undefined value in the 7-lane case. So the new test is a real regression test.
  • python -I scripts/run_gpu_tests.py --build runtime/build: 143/189 passed, 46 skipped, 0 failed — the same counts as main on the same machine. ps_bitmask_perm (the only GPU test that uses ds_swizzle): 4096/4096 pixels in lanes 0-31 exact, the same as main — as expected, since a 32-wide full wave has no absent lane and no lane off in EXEC.
  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build: 174/189 passed, 15 skipped, 0 failed, the same count as main with the emulation on. That exercises the emulated branch of ds_lane_read (the value zeroing), so the emulated words are unchanged.
  • The branch is 3 commits on main ec8ec4c and 6 behind origin/main (77444fa). The six new commits touch tools/psin_data.py, tools/tex_headers.py and two test files, so there is no conflict; a rebase is enough.

Review of the change:

  • The rule matches AMD GPUOpen's cross-lane pseudocode for both swizzle modes, thread_out[i] = thread_valid[j] ? thread_in[j] : 0, and the same rule is already in docs/design.md for ds_bpermute_b32, measured on gfx1036. A disabled destination keeps its value: dst(..., eager=True) masks the write with EXEC and preserves the old word.
  • The ds_bpermute_b32 refactor is behaviour-preserving: the lane arithmetic ((addr + offset) >> 2, & 31, the wave64 | (lane & 32) half) and the ballot/shuffle/mask sequence are the ones the merged code already used, only factored into ds_lane_read.
  • g_shuffle lost its zero_inactive parameter; the three remaining callers (v_readlane, v_permlane16, the quad read) never passed it, so nothing else changes.

Not covered here: on a 32-wide subgroup the GPU tests cannot reach the new path (no absent lane), so the EXEC-off source case rests on the CPU interpreter test, and the narrow pixel-shader case (Intel subgroups of 8 or 16) is still unmeasured on hardware.

AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

Tested at the head on Windows 11 / Python 3.13.0: unittest discover -s tests/semantic 4143 OK, 0 skips, versus 4142 on main; merge clean. On main both patterns return the stale 0.75, and the 7-lane case raises "undefined value", so the fixture is a real regression test.

The rule matches the hardware record: docs/shader_validation.md:461-463,499-509 (gfx1150 and gfx1036, 12,000 programs) says an off source lane reads 0. ds_lane_read (rdna2spirv.py:3389-3407) zeroes by EXEC before the shuffle and uses a ballot to redirect absent lanes; the ds_bpermute refactor is behaviour-preserving as far as the suite can tell.

Nits:

  • docs/design.md:297 cites only the CPU test; it should cite the hardware measurement above, which is the actual confirmation.
  • The semantic test covers QUAD_PERM and SWAP; REVERSE, BROADCAST and BITMASK_PERM go through the same helper but are not asserted.
  • The "absent" (7-lane) half is still a hypothesis (partial waves cannot launch); the row should say so.

Approve. AI-assisted review, no game files, no GPU.

The hardware runs control EXEC in full waves. The seven-invocation interpreter case instead selects an absent lane. Distinguish those observations so the CPU fixture cannot be mistaken for a measurement on silicon.
@evilclanker9000

Copy link
Copy Markdown
Contributor Author

The hardware record confirms that an existing source lane disabled by EXEC supplies zero on gfx1036 and gfx1150. In the separate CPU case there are only seven invocations, and lane 6 selects the absent lane 7. That fixture verifies the translator's zero fallback. The corresponding hardware result is unknown.

I corrected the contract, test comment and PR description, and linked the hardware measurements. The fixture specifically uses QUAD_PERM and SWAP. The three focused Windows suites passed 78 tests and 39 subtests, including both patterns at 32 and seven invocations. Documentation change

@kacper-serewis

Copy link
Copy Markdown
Contributor

SHADER-517: AI-assisted synthetic RTX5070 / driver616.56 validation of #2780 with emulated Wave64 and asymmetric EXEC masks (low0x536db7c9, high0xa9c656b3). Parent ec8ec4c matched QUAD reversal46/64 and BITMASK XOR17 52/64. Requested2c87d6db and currentdc612fdc both matched64/64 for each. All30 parent failures were active destinations reading disabled sources (QUAD9+9, BITMASK7+5 across halves); both heads returned zero. All56 disabled destinations preserved their values and all42 enabled-source copies matched on every revision. All six modules passed spirv-val Vulkan1.2. This covers existing but EXEC-disabled source lanes, not absent hardware invocations. No game inputs; raw readbacks private.

Keep the targeted regression and the intervening upstream changes together for review.
@daemosofchaos

Copy link
Copy Markdown
Contributor

Independent synthetic A/B on Windows 11 build 26300, NVIDIA RTX 5070 Ti / driver 621.24, Python 3.12, LLVM 21.1.8. I reran the reported SHADER-678 case with the same lds_fuzz.py source on base f847748c and this PR's head 2704c78e:

--programs 27 --only 26 --seed 3221 --wave 32 --extended --oracle translator
  • Base: the fuzzer reported a hypothesis mismatch in the one program, with 20 output words differing from its model; the displayed mismatches were attributed to the EXEC-masked swizzle.
  • PR head: the same program matched the model, with no skips, untranslated programs or harness errors.
  • Both generated modules independently passed Vulkan 1.2 spirv-val. The fuzzer returns exit 0 for hypothesis-only mismatches, so the base result above comes from its summary, not the process exit code.

This is one NVIDIA wave32 case, not an independent AMD hardware-oracle measurement or a full-corpus result. No game files were used.

— LocalFirst-AI

@ItsNotRexed
ItsNotRexed merged commit 4ec15a3 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
ps_bitmask_perm is skipped when a driver runs the wave32 pixel shader narrower
than 32 lanes (#1318), because the "pippi" pattern reads lanes 16-31, which
then do not run and have no defined value. The skip excused the whole test,
including the sources that do run: at 16 lanes wide every lane reads lane ^ 9,
which is inside the running lanes for lanes 0-7, so a wrong word there went
unnoticed on Intel.

The skip now excuses only the sources that are not there. Where the source
lane runs, its word has to be right, so a narrow run is judged instead of
skipped. At 8 lanes wide every "pippi" source is lane 8 or above, nothing can
be judged, and the test still skips.

The translator change this depends on is #2780: a source lane that is not
running reads 0 instead of an undefined value, which is what makes the narrow
run judgeable at all. Until it lands the note in docs/testing.md describes a
behaviour that main does not have yet.

Tested: python -I tests/test_shader_checks.py (70 tests, OK, on main
1628210). No GPU, no game files.

AI-assisted.
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