Skip to content

Shader: isolate wave32 pixel operations in 64-lane subgroups (SHADER-731) - #4225

Open
73N1X wants to merge 1 commit into
ItsNotRexed:mainfrom
73N1X:feat/shader-731-wave32-pixel-halves-pr
Open

73N1X wants to merge 1 commit into
ItsNotRexed:mainfrom
73N1X:feat/shader-731-wave32-pixel-halves-pr

Conversation

@73N1X

@73N1X 73N1X commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed as SHADER-731: #3918 (comment)
First refusal released to me: #3918 (comment)
Current tracking: #4084. Finding and hardware measurements: #3982.

What and why

A wave32 pixel shader can run in a 64-lane fragment subgroup on AMD Windows RDNA2, where the fragment stage cannot request subgroup size 32. Treating that subgroup as one guest wave leaks ballots, votes and lane reads across the two logical wave32 halves. The old ps_bitmask_perm checker judged only lanes 0–31 and could hide the other half's wrong results.

This keeps wave32 fragment operations local to their 32-lane half:

  • Logical lane IDs use SubgroupLocalInvocationId & 31; shuffle sources retain the caller's physical half.
  • Ballots and scalar mask reconstruction select that half's ballot word; Any/All votes and first-active-lane reads use that word.
  • Lane reads/writes, checked shuffles, permutations and the descriptor-index uniformity broadcast preserve the half.
  • Both GPU checkers judge every ps_bitmask_perm pixel. Synthetic semantic tests compare one 64-lane subgroup with two independent 32-lane subgroups using different inputs in each half.
  • Existing PS emission assertions follow the half-local ballot path; the runtime contract documents the measured scope. Compute/mesh emulation and subgroup-size selection are not changed.

Validation on this PR head

Base: main aa2988c. Head: 4f760c1. Windows, RX 5700 XT, driver 32.0.21045.5002. Synthetic fixtures only; no game files or corpus run.

  • 137/137 focused semantic tests passed across the new half-isolation tests and the affected control-flow, mbcnt, WQM, scalar and readfirstlane modules.
  • Behavioural negative control: the three new tests fail with the base translator specifically in the 64-lane cases; all pass with this change, including their 32-lane controls.
  • ps_bitmask_perm: 4,096/4,096 pixels exact, translation and spirv-val passed, with Vulkan validation and synchronization validation enabled. Used the existing main-compatible Vulkan harness; no C++ runtime changes are made here. This device reports default subgroup size 64 and cannot pin fragment size; the CPU tests explicitly exercise 64 lanes, so the GPU result is not presented as a live-width measurement.
  • GPU-runner checks: 56/56 passed (test_run_gpu_pixel_checks, test_run_gpu_tests, test_run_gpu_wavemask).
  • Docs/design rows, docs links, CI registration, text-write line endings, compileall and git diff --check: passed.

Existing main suite failures are separate

An additional diagnostic run of the full semantic suite with SHADER-731 plus local compatibility repairs completed 7,459 tests in 768.937 seconds: OK (1 skipped, 1 expected failure), zero failures/errors. Those repairs address the already-open #3883 (mutation anchor), #3885 (f64 malformed operands) and #3995 (outlined helper calls / structured emulation tests).

Those compatibility repairs are deliberately excluded from this PR to avoid duplicating their owners' work. The full-suite diagnostic is not a clean-full-suite claim for this PR head alone: the known baseline failures remain until those separate fixes land. spirv-as and spirv-val must also be on PATH for the validation-dependent test.

No Tier 3 work is included.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 4f760c1a on Windows 11, all eight affected suites:

  • test_wave32_pixel_subgroup64.py 3 OK (new), test_control_flow_exec.py 13 OK, test_control_flow_vcc.py 24 OK, test_mbcnt_lo_hi.py 28 OK, test_salu_wqm32.py 7 OK, test_scalar_alu_abs_neg.py 36 OK, test_scalar_bitcmp.py 21 OK, test_vs_readfirstlane.py 5 OK.
  • compileall and git diff --check clean.

The approach is consistent: a wave32 PS maps its logical lane to subgroup_lane & 31, maps a source lane back into the invocation's 32-lane half (half | (lane & 31)), takes the matching word of a 64-lane ballot, and limits votes/ballot-mask operations to that half. EXEC/VCC masks and cross-lane ops stay per-half, which is the documented wave32-in-64-lane-subgroup rule. I cannot run the 64-lane fragment case on this NVIDIA host (32-wide only); the new semantic cases drive it through the interpreter. No blocking issue.

@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 data point for the stricter checker. Tested head 4f760c1 on Apple M2 (Mac14,3), macOS 26.4, MoltenVK 1.4.2 (direct), subgroup 4..32, llvm-mc 23.1.6, clean full build on AppleClang 17 (exit 0).

python -I scripts/run_gpu_tests.py --filter ps_bitmask_perm --build runtime/build/linux: 1 shader translated, 1 pass spirv-val; 1/1 passed — 4096/4096 pixels exact with the updated all-pixel judgement. This device has 32-wide fragment subgroups (no 64-lane half to leak into), so it is a clean no-regression data point rather than a test of the AMD 64-lane case the PR targets. Head fetched read-only, no rebase/edit/push. Synthetic shader and counts only; no game files.

AI-assisted.

@AC-Storm-YT

Copy link
Copy Markdown
Contributor

Tested 4f760c1a on two AMD GPUs with AMD's Windows driver 26.11.2: Windows 11, Visual Studio 2026, Vulkan SDK 1.4.363.1, LEONIDA_VK_VALIDATION=1, test programs built from this branch. This includes a live 64-lane fragment run on RDNA2, which the description and the M2 run couldn't show.

run_gpu_tests.py --filter ps_bitmask_perm, with this PR's all-pixel checker in both runs:

GPU This PR's translator main aa2988cc's tools/rdna2spirv.py
Ryzen 7 9800X3D iGPU (RDNA2, gfx1036, driver 32.0.21045.29003) PASS, 4096/4096 exact FAIL, 2048/4096 wrong, first at (0,4): lane=32, got (32,32,0), want (41,17,0)
RX 9070 XT (RDNA4, gfx1201, driver 32.0.32029.2010) PASS, 4096/4096 exact PASS, 4096/4096 exact

From the raw frames:

  • iGPU with main: the lane word reaches 32, so the fragment subgroup really was wider than 32 lanes there, and exactly half the pixels are wrong.
  • iGPU with this PR: the lanes are 0..31 and every pixel is exact.
  • 9070 XT: lanes 0..31 with both translators, so it ran 32-wide and has no upper half to leak into. That makes it a no-regression point, like the M2.

python -I tests/semantic/test_wave32_pixel_subgroup64.py: 3 tests OK.

Synthetic shader only, no game files.

@MKmajster

Copy link
Copy Markdown

Tested 4f760c1 on NVIDIA GeForce RTX 3070 (fragment subgroup 32..32), driver 617.42, Windows 11 24H2. That's the other side of this change: a wave32 PS already gets exactly 32 lanes there, so the half-isolation must be neutral. It is.

  • Full run_gpu_tests.py, this branch vs main aa2988c on the same runtime build: 164/210 passed, 46 skipped (wave64), 0 failed on both. All 210 result lines are identical except ps_bitmask_perm: 4096/4096 pixels exact here vs 4096/4096 pixels in lanes 0-31 exact on main, i.e. the stricter checker described in the PR now judges every pixel and still passes.
  • build.py + w64_graphics.py from this branch: every tier A and B fixture ok (ps_w64_a_*, ps_w64_b_*, vs_w64_a_skip, vs_w64_b_*, gs_w64_a_ring). Tier C skipped as documented on a 32-only device.

No 64-lane fragment subgroup here, so the AMD Windows case itself isn't exercised. This only shows the change costs nothing on a 32-wide driver. No game files. AI-assisted (Claude).

@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 4f760c1a (base main aa2988cc) on AMD Radeon RX 7800 XT (RDNA3, gfx1101), AMD driver 26.11.2 (32.0.32029.2010, LLPC), Windows 10 Pro 22H2 build 19045.7846, Vulkan SDK / validation layer 1.4.363.0, llvm-mc 21.1.8, LEONIDA_VK_VALIDATION=1: pass. This adds the RDNA3 data point, including a forced live 64-lane fragment run.

On RDNA3 under AMD's Windows driver the fragment stage is requirable, unlike the RDNA2 case this fixes: subgroup sizes 32..64 (default 64), requirable in stages 0xf0 (FRAGMENT | COMPUTE | TASK | MESH, no VERTEX), subgroupSizeControl and computeFullSubgroups on. So vk_harness can pin a wave32 PS to 32 lanes here, and can also pin it to 64 to reproduce the RDNA2 condition.

ps_bitmask_perm, every pixel compared against the exact frame. I translated it with this PR's tools/rdna2spirv.py and then with main's, and ran vk_harness vs_tri.spv ps_bitmask_perm.spv <raw> (MSVC build of vk_harness, which prints fragment subgroup size: N when the requirement takes effect):

VKH_SUBGROUP_SIZE this PR's translator main aa2988cc's translator
32 4096/4096 exact, lanes 0..31 4096/4096 exact, lanes 0..31
64 4096/4096 exact, lanes 0..31 2048/4096 wrong, lanes reach 32; first at (0,4): got (32,32,32), want (0,9,17)

No validation errors in any of the four runs. Exit code 0 in all four.

  • python -I scripts/run_gpu_tests.py --filter ps_bitmask_perm (index subgroup_size 32, so the runner pins 32): PASS 4096/4096 with both translators, lanes 0..31 in both frames. So with the default pinning, RDNA3 has nothing to leak, like the RX 9070 XT run above, and the change is neutral there.
  • python -I tests/semantic/test_wave32_pixel_subgroup64.py: 3 tests OK.

So the half-isolation fixes a live 64-lane fragment subgroup on a second AMD architecture, and it gives the same result as main when the stage runs 32 wide.

AI-assisted (Claude Code). Synthetic shader only, no game files.

@memorypressure

Copy link
Copy Markdown

Verified on Linux (NVIDIA RTX 5080, driver 580.196.07): the pixel-shader GPU set gives an identical result set on the PR and on main (85 pass, 8 skip, 0 fail; my independent rerun of ps_bitmask_perm 1/1 and the cs_w32 set 13/13), ps_bitmask_perm is exact on all 4096 pixels under the new all-pixels judgment, and all wave32 semantic tests including the new test_wave32_pixel_subgroup64.py pass under python -I. Honest limitation: this device reports fragment subgroups 32..32, so the 64-lane-half isolation itself reduces to identity here — it stays covered by the CPU fixtures and the author's RX 5700 XT result, not exercised by this run. AI-assisted: yes. Tested on Linux (RTX 5080 host, GPU run).

@bielfreedom

Copy link
Copy Markdown

Full-corpus check on the game copy (Xbox Series 1.0.2.1; Windows 11, RX 9070 XT). Counts only, no shader names or data.

PR head 4f760c1a, merge-base aa2988cc (same commit as my baseline). All 26,503 disassembled shaders translated with --no-asm, 8 shards + --merge:

main aa2988cc this PR
translated 26,503 26,503
pass spirv-val 26,422 26,422
tier A / B / C (32-wide) 510 / 11 / 1,161 510 / 11 / 1,161
total .spv bytes — +0.30%
  • Changed modules: 12,588 .spv differ (PS 11,151, VS 1,242, GS 195). No CS or MS module changes, which matches "compute/mesh not changed".

  • index.json changes: only capabilities, and only on 206 PS entries:

    • 72 add GroupNonUniformBallot + GroupNonUniformShuffle
    • 29 add GroupNonUniformShuffle
    • 105 drop GroupNonUniformArithmetic

    This is consistent with Any/All votes now reading the half's ballot word instead of a subgroup-wide op.

  • VS/GS changes look cosmetic: on a sample of 60 changed VS/GS modules, the only opcode-count delta is extra OpCopyObject. That comes from the new non-fragment wave_lane() path, lane = OpCopyObject subgroup_lane. It has no semantic change, but it explains why VS/GS hashes move. If you want those stages byte-identical, return subgroup_lane directly there.

I did not run the GPU half-subgroup checkers on this head. This is the translator-side corpus check only.

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.

8 participants