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).

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.

5 participants