Skip to content

fix(shader): use guest lane for compute masks - #25404

Draft
DonRyuzaki wants to merge 4 commits into
boykopovar:mainfrom
DonRyuzaki:codex/wave32-vcc-lane-id-20261122
Draft

DonRyuzaki wants to merge 4 commits into
boykopovar:mainfrom
DonRyuzaki:codex/wave32-vcc-lane-id-20261122

Conversation

@DonRyuzaki

Copy link
Copy Markdown
Contributor

What

For a compute shader whose guest Wave32 spans 8-lane Vulkan subgroups, EmitLaneId used the host subgroup invocation ID. A scalar s_mov_b32 to VCC_LO then selected bits 0–7 again for guest lanes 8–31. This changes the compute path with one host invocation per guest lane to use gl_LocalInvocationIndex modulo the guest wave size. Other shader stages keep their existing mapping.

The regression fixture was posted by mihiii1337 on #25298; its original commit and authorship are preserved as the first commit in this branch. The added debt fragment narrows the existing small-subgroup limitation to the remaining non-compute cases. Cross-subgroup ballots and shuffles are outside this change.

Tested

Ubuntu 24.04 WSL2, GCC 13.3, Release, Mesa llvmpipe LLVM 20.1.2 (software Vulkan device, subgroup 8). Built agc_driver_wave32_scalar_vcc_mask_tests on upstream 851212fb98 plus the fixture, then with this patch. The focused CTest used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, APS5_NO_PIPELINE_JOURNAL=1, the lavapipe ICD, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, and VK_LOADER_DEBUG=layer on both sides.

  • Baseline: failed at guest lane 8; observed VCC selection mask 0xa5a5a5a5, expected 0x96a596a5.
  • Final branch: passed; observed 0x96a596a5.
  • Both logs show the Khronos validation layer 1.4.367 inserted, no missing-layer message, and zero VUID- lines.
  • tools/check_conventions.py --base upstream/main and git diff --check pass against current upstream 27646a6172f. tools/debt_fold.py --check remains blocked by two unrelated libkernel_sys fragments already on main (#25307); this branch's shader fragment produces no fold error.

No PS5 title or physical GPU was run.

Checklist

  • Merges cleanly with current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Mesa llvmpipe LLVM 20.1.2, software Vulkan device, subgroup 8, Ubuntu 24.04 WSL2; no physical GPU
  • AI-assisted: yes

mihiii1337 and others added 2 commits November 22, 2026 00:29
Host subgroup IDs wrap at eight on llvmpipe, so scalar VCC writes alias guest lanes 8-31. Use the workgroup index only when one host invocation carries one guest compute lane.

Refs boykopovar#25298
@throny

throny commented Nov 22, 2026

Copy link
Copy Markdown

GPU test run: ✅ no new failures or validation errors on Windows / NVIDIA

Basis: built and ran · this PR's head f432125076 merged onto main 851212fb98 · Windows 11 Pro 26300, RTX 4080 (10de:2704, driver 610.88), WinLibs GCC 15.2.0 r7, Release

Checked

  • The agc_* tests tools/select_tests.py selects for this change: 1967 of 1968 passed, run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer (Khronos validation layer, nightly 1.4.369, newer than the 1.4.335 minimum).
  • The loader logged Insert instance layer "VK_LAYER_KHRONOS_validation" 1891 times and never was not found but was requested by env var VK_INSTANCE_LAYERS.
  • 0 VUID- messages, the same as a full agc_* run of main 851212fb98 on this machine with the same settings.
  • The failure is agc_driver_store_over_untracked, which also fails intermittently on main here (agc_driver_store_over_untracked is flaky on Windows: the second-store case sometimes finds no saved guest bytes #22670), not this change.
  • New in this PR, passing on NVIDIA: agc_driver_wave32_scalar_vcc_mask.

Findings: none from this run; this is a GPU run, not a code review.

AI-assisted test run (Claude Code) · head f432125076 · base main 851212fb98

@mihiii1337

Copy link
Copy Markdown
Contributor

I reproduced two mask regressions with the shader delta from head f432125076 on the same 5b308313c3 baseline as #25419. Windows 11, subgroup-8 lavapipe (Mesa 26.2.6), Khronos validation 1.4.369, caches disabled. Each result repeated 3/3 with no VUID or sync-hazard diagnostics.

Case 5b308313c3 With #25404
Literal mask Repeats low byte Correct
Compare ballot → SGPR → XOR 0 → VCC 0x7b36c4a9 0x000000a9
SCC select → VCC, previously correct lane readback 0xffffffff 0x000000ff

The two standalone regression fixtures use v_cndmask_b32 and store the lane-selection bits. The later lanes of the compare ballot are lost when the guest lane index is applied to a host-subgroup mask word.

AI-assisted: yes

@DonRyuzaki
DonRyuzaki marked this pull request as draft November 22, 2026 04:04
@Gonic0

Gonic0 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent macOS check of f432125076 on a 32-lane subgroup device. Apple M5 Pro, macOS 27.3, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0, subgroup size 32), x86_64 Release under Rosetta 2. The tree was main ea07e039a9 plus #17425 and #11049, which main still needs to build on macOS; this pull request applied without conflicts. Every run used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer; each log shows the loader inserting the layer and none reports it missing.

  • Wave32 and lane regression set (ctest -R "wave32|scalar_select|vcc|read_lane|exec_mask|subgroup|shader_ssa|shader_disk_cache|lane", 104 tests): all pass on main and with this pull request (2 skipped on both), with no VUID- in either log.
  • agc_driver_wave32_scalar_vcc_mask: passes 3 of 3 runs with this pull request (observed 0x96a596a5), no VUID-.
  • The same test on main's code also passes 3 of 3 here, with the same mask. That fits the description: the bug needs a guest Wave32 split across smaller host subgroups (llvmpipe's 8), and with 32-lane subgroups the host subgroup invocation ID and the guest lane coincide. So this run shows no regression on 32-lane hardware but does not exercise the fix.

Not tested with a title.

@MarcZX10 MarcZX10 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.

Reviewed — looks good

The compute lane mapping change is supported by the focused regression fixture; no verified defect blocks merging.

What I ran

Reviewed head f432125076f9bde43be50ad34fef2f5e8ad04d75. I read the prepared description, commits, manifest and diff, all three changed files, and the relevant lane ID emitter, input declaration and execution-test registration code through repo_read.py. No build or tests were run during this review.

Results

Check Result Note
Changed code and context passed Three changed files and targeted callers read
Build and tests not run Author reports the focused fixture passed

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the build, CTest, conventions check or debt-fold check; their reported results are from the PR description. I did not verify physical GPU or console behavior. All files listed as reviewed in the manifest were read; no changed files were excluded.

To get this to a good state

Nothing is required.

@Doorriiaann

Copy link
Copy Markdown

NVIDIA run on Linux: the new agc_driver_wave32_scalar_vcc_mask passes with NVIDIA's 32-wide subgroups, and the other wave32, VCC and scalar select tests do not regress.

Setup: RTX 3070 8 GB, NVIDIA 610.57.04, Ryzen 5 5600X, Debian 13 (kernel 6.12.115), GCC 13.3.0 Release, validation layer 1.4.335. Base is the merge-base 851212f, head is f432125. ANYPS5_GPU=NVIDIA ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -R '(wave32|scalar_select_mask|vcc)' -V, 3 runs each.

base this PR
agc_driver_wave32_scalar_vcc_mask (new) 3/3 pass
the other 50 matching tests 150/150 pass 150/150 pass

Every Vulkan test's log selects the RTX 3070 and shows the layer inserted, none reports it missing, and no log has a VUID- line.

AI-assisted: yes

@mihiii1337

Copy link
Copy Markdown
Contributor

Follow-up on the buffer-fed VCC case from #25660. I compared its GitHub test merge 1084b0fc718b7a5d27805c25e8bee8ce0d2a3ad2 (head 6425a75b0f43) with the same tree plus only the EmitLaneId hunk from f432125076f9bde43be50ad34fef2f5e8ad04d75. The original 45-thread readback and comparison/SCC fixtures were byte-identical in both builds.

Windows, lavapipe Mesa 26.2.6 / LLVM 23.1.4 (software Vulkan subgroup 8), three identical repeats per arm:

Output #25660 #25660 + LaneId hunk
Buffer-fed VCC, full wave 0xa9a9a9a9 (15 mismatches) 0x7b36c4a9 (0)
Buffer-fed VCC, partial 13-lane wave 0x00001393 (3 mismatches) 0x00001e93 (0)
Compare ballot → SGPR → XOR 0 → VCC 0x7b36c4a9 (0) 0x000000a9 (13)
SCC select → VCC 0xffffffff (0) 0x000000ff (24)

Both builds returned the correct raw scalar for all 45 lanes and left the inactive output intact. The literal mask also passes with the hunk. Both revised ReadFirstLane tests and the EXEC-lane control pass in every run. This reproduces the earlier ballot/SCC regressions on the newer base while showing exactly which remaining dynamic case the guest-lane index fixes.

On Intel UHD and RTX 4070 Laptop, both at subgroup 32, all seven tests passed in all three runs per adapter and build. Every run required Vulkan with shader caching off and loaded the Khronos validation layer. There were no VUID or synchronization diagnostics.

AI-assisted: yes

mihiii1337 and others added 2 commits November 22, 2026 19:50
Preserve the readback fixtures from a05bcb6.
Using the guest lane for every mask drops ballot-derived bits
above the first host subgroup. Use it for scalar mask bit tests
whose words do not depend on subgroup ballots.
@mihiii1337

Copy link
Copy Markdown
Contributor

I applied the exact #25404 production delta from 446e5b0a132930dffcf8f311f517099ea926d479 onto the current #25660 head 0b4aa2f6fc39939646ee0e90016b2e83e7cc9014. It applied without conflict or manual adaptation. This checks the interaction of the two current changes, not standalone #25404.

Windows 11, pinned lavapipe LLVM 23.1.4 (subgroup 8), WinLibs Release, forced Vulkan, shader and pipeline caches disabled, Khronos Validation 1.4.369. Three runs per arm used byte-identical fixtures and the same exchange lab gate.

Case #25660 #25660 + current #25404
literal/UserData VCC mask 0/3 3/3
UserData/XOR-AND and ballot-dependent control 0/3 3/3
SCC/EXEC/ReadFirstLane/fallback controls 12/12 12/12
dynamic 45-thread buffer-fed VCC 0/3 0/3

The new ballot fixture had zero scalar or selected-bit mismatches in both guest waves. The SCC and EXEC controls remained unchanged and passed in both arms, so the earlier ballot/SCC regressions did not recur on this stack.

The historical 45-thread case remains unchanged from the previous result. Its raw scalar words are correct for the full and 13-lane partial guest waves, but VCC selection stays 0xa9a9a9a9 and 0x00001393, with 15 and 3 bit mismatches; the guest-wave expectations are 0x7b36c4a9 and 0x00001e93.

For the disabled-exchange control I changed only its lane-8 sentinel so host-local and guest-lane indexing differ. Both arms retained the host-local result 0x84c93ba9 / 0x00000193; the diagnostic fixture therefore failed against its wave-wide oracle by design. The natural divergent and BDA fallback SPIR-V was byte-identical to the forced-disabled compile control and contained no workgroup exchange. This confirms subgroup-local selection in this fixture even when the enabled exchange produced the correct scalar; the logs do not identify which rewrite guard prevented guest-lane indexing.

All 48 targeted Vulkan invocations selected llvmpipe subgroup 8 and inserted Khronos Validation. There were no skips, missing-layer messages, VUIDs, or synchronization diagnostics.

The latest delta fixes the literal/user-data mask and ballot fixture failures while preserving the unavailable-exchange fallback. Could you update the PR's What section to describe the provenance-limited rewrite, and note that the buffer-fed ReadFirstLane case still needs exchange-aware follow-up? The current text still says the compute path generally uses the guest lane, which is broader than the tested head.

AI-assisted: yes.

@MarcZX10 MarcZX10 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.

Reviewed — looks good

Nothing blocks this change; the author’s reported results are consistent with the code I reviewed.

What I ran

Reviewed head 446e5b0a132930dffcf8f311f517099ea926d479. I did not run commands or tests. The author reports a focused CTest on Ubuntu 24.04 WSL2 with GCC 13.3 and Mesa llvmpipe, including a failing baseline and passing final branch; these were not run by me.

Results

Check Result Note
Source review passed All seven changed files read
Build and tests not run Author-reported results only
Physical console behavior not run No console or physical GPU reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

I reviewed all seven files listed in the manifest, and none were excluded by the review bundle. I did not independently verify the author’s test output, run a build or test, or verify behavior on a physical GPU or PS5 title.

To get this to a good state

Nothing is required.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 12324 core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants