fix(shader): broadcast Wave32 readfirstlane on narrow subgroups #25660
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25660"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-22T13:39:44Z.
What
Broadcast
v_readfirstlane_b32over the complete guest Wave32 when a compute shader runs on host subgroups narrower than 32 lanes. Each invocation publishes its source in workgroup memory, active guest lanes atomically elect the lowest lane within their own 32-lane guest wave, and all invocations read that guest-wave slot after a workgroup barrier. Separate slots keep multiple guest waves in the same workgroup independent, including a partial final wave.The workgroup exchange is only emitted for Wave32 compute on a host subgroup below 32 lanes. The emitted module is checked with the existing barrier-uniformity analysis; if a
ReadFirstLaneexchange sits in per-invocation divergent control flow, compilation retries with the existing subgroup-local shuffle instead of risking an incomplete workgroup barrier. That divergent case therefore keeps the previous narrow-subgroup limitation rather than hanging. Fault-capable shaders (usesDmaorusesFaultBuffer) also keep the existing subgroup-local path, so this PR does not introduce workgroup barriers into the separate barrier-safe BDA fault problem tracked by #7392.This addresses the unequal-input
V_READFIRSTLANE_B32reproduction discussed in #25298, including the ISA lane-0 fallback whenEXECis empty. #25419 covers the separate complete-VCC-word problem; the execution fixture here intentionally stops before scalar-word-to-VCC selection so the two fixes remain independently testable. #25609 changesReadFirstLanewhen a guest wave already fits inside one host subgroup and explicitly falls back to the shuffle when the guest wave is wider than the host subgroup, so the narrow-host path here is separate.Tested
Windows 11 Education build 26200, WinLibs GCC 15.2.0, CMake/Ninja Release; rebased onto current main
0f107f9812. Rebased head:6c99e1b164.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repositorySummary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-22T13:39:53Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T13:50:31Z.
Review: COMMENTED
Reviewed — comments
The narrow-subgroup exchange is guarded by the barrier uniformity check and the added code generation and execution tests cover a full and partial guest wave; subgroup-8 execution itself was not verified on hardware.
What I ran
6bfa63a2c3f53dd595754363a6d5785945d57f3band the prepared diff; no commands or tests were run in this review.ShaderMemory.cpptest range throughrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas read only at the changed test range; its remaining contents were not reviewed. No changed files were excluded by rule, but that file's full text was omitted from the review folder because it was too large.To get this to a good state
Nothing is required. The optional subgroup-8 runtime validation above would strengthen coverage.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T14:17:08Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the code reviewed; the reported runtime and compile checks were not run in this review.
What I ran
6425a75b0f430d2eaf51c9f35121dc9927e08b1dusing the prepared diff and pinned repository reader.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the review folder because it was too large; only the changed region was read through the repository reader. All other changed files listed inreview/manifest.jsonwere read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T06:33:05Z.
Review: CHANGES_REQUESTED
The narrow-subgroup exchange needs to participate in the existing Workgroup-memory budget before it is enabled. Vulkan requires the sum of all
Workgroupvariables and padding in a compute module to stay withinmaxComputeSharedMemorySize(VUID-RuntimeSpirv-Workgroup-06530).A supported boundary case exceeds it on this head: 128 invocations, subgroup size 8, 63 guest LDS blocks (
ldsSizeDwords=8064, 32,256 bytes), and a 32,768-byte host limit.DeviceMemoryLdsBytescurrently keeps that LDS inWorkgroupbecause it budgets onlybytes + 4. This exchange then declares128 + ceil(128/32) = 132dwords (528 bytes), for 32,784 total—16 bytes over the device limit. The guest LDS block count is accepted byShaderInputState.cpp, and ordinary live DS access keeps the guest LDS allocation present.Please reserve the exchange together with guest LDS (for example, make the combined budget move guest LDS to its existing device-memory path when required) and add a host regression at the boundary with both live DS access and convergent ReadFirstLane.
LdsLockBudget.cpp::workgroupBytesalready parses and sums all Workgroup variables. The new 45-thread fixture hasldsSizeDwords=0, so the otherwise useful subgroup-8 coverage cannot catch this coexistence case.This is a static review of exact head
a252ab14051e1700253dd4dddbaf1cc980af5212; I did not run a GPU or shader binary for this finding.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T06:46:30Z.
Review: CHANGES_REQUESTED
The production budget now covers the original boundary for ordinary nonzero compute dimensions, but the new regression does not exercise the exchange whose coexistence caused the bug.
The fixture ends with
v_readfirstlane_b32 s8, v1followed immediately bys_endpgm;s8is never consumed. SSA/DCE can remove that pure ReadFirstLane before SPIR-V emission, soSpirvAnalysisnever enablesnarrowReadFirstLaneExchange. The new frontend reservation nevertheless scans the raw decoded opcode and moves guest LDS to device memory. Both assertions then pass:workgroupMemoryDwordsreflects the raw reservation, andworkgroupBytes <= limitaccepts a module with no exchange at all.Please make the RFL result live and observable after the read (with a lane-dependent source and a following DS/buffer use), then positively assert that both threshold arms contain the
wave32_readfirstlane_exchangefootprint—such as its named Workgroup variable /OpAtomicUMin/ expected exchange byte lower bound. At the combined boundary, the test should prove guest LDS and the 528-byte exchange coexist; just below it, it should prove the exchange remains while guest LDS spills.A secondary implementation note is that the raw-opcode reservation is intentionally a conservative superset of the live emitter gate, so dead, fault-gated, or fallback RFL instructions may spill LDS unnecessarily. Aligning the reservation with the live requirement would avoid that cost, but the blocking request here is a regression that actually pins the correctness boundary.
Static review of exact head
541e7950417c590716fd909521bbbbf3dc9426ad; no GPU or shader executable was run.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T06:56:12Z.
Review: COMMENTED
Reviewed — comments
The exchange can exceed the device’s shared-memory limit for workgroups whose size differs from the compile-time estimate, so please resolve the sizing mismatch before merge.
What I ran
Reviewed head
541e7950417c590716fd909521bbbbf3dc9426ad. No commands or tests were run; the repository reader was used for targeted source reads.Results
Findings
Blocking
None verified.
Non-blocking
Recompiler.cpp:181-184sizes the reserved exchange fromrequest.context.compute->numThreads, whileSpirvAluEmitterMath.cpp:1807-1810allocates it usingWorkgroupLocalSize. If those values differ, the LDS spill decision can under-reserve shared memory. Please confirm they are guaranteed to match for this compilation path, or calculate both estimates from the same source.Not verified
The full text for
ShaderMemory.cppwas excluded as too large by the review bundle; the changed test section was read through the reader. The complete contents offiles.jsonwere not available through the reader. Remaining changed-file text and build/test wiring were not inspected. Tests and hardware execution were not run; results in the PR description are author-reported.To get this to a good state
Nothing is required. Please consider clarifying or unifying the workgroup-size source used for shared-memory budgeting and exchange allocation.
Imported from boykopovar/AnyPS5. Originally posted by throny on 2026-11-23T07:01:30Z.
Review: COMMENTED
GPU re-run: ✅ no new failures or validation errors on Windows / NVIDIA
Basis: built and ran · this PR's head
541e795041merged ontomain337a948bf1· Windows 11 Pro 26300, RTX 4080 (10de:2704, driver 610.88), WinLibs GCC 15.2.0 r7, ReleaseChecked
agc_*teststools/select_tests.pyselects for this change: 2062 of 2063 passed, run withANYPS5_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).Insert instance layer "VK_LAYER_KHRONOS_validation"1895 times and neverwas not found but was requested by env var VK_INSTANCE_LAYERS.VUID-messages, the same as a fullagc_*run ofmain337a948bf1on this machine with the same settings (2061 of 2062 passed there; the extra test is new in this PR).agc_driver_wave32_unequal_buffer_read_first_lanepasses (it is not onmain).agc_driver_store_over_untracked, which also fails intermittently onmainhere (#22670), not this change.Findings: none from this run; this is a correctness run on a GPU, not a code review or a speed measurement.
AI-assisted test run (Claude Code) · head
541e795041· basemain337a948bf1Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T09:18:17Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
a910b4c40f769bcf8b0c920b4b3ee69e8705117e. The new commit resolves my earlier regression-test blocker: the ReadFirstLane value is now consumed, and both budget arms positively contain the named 528-bytewave32_readfirstlane_exchange. That part no longer blocks.A separate production sizing mismatch remains.
NarrowReadFirstLaneExchangeBytescomputes the reservation from rawrequest.context.compute->numThreads, treating zero X/Y dimensions as 1. The emitter computes the actual array fromWorkgroupLocalSize, which treats zero X/Y as 2 when compute derivatives are required. Therefore the budget and emitted module can disagree.Concrete static witness for Wave32 on a subgroup-8 host: raw
{128, 0, 1}with compute derivatives is budgeted as 128 threads, so the frontend reserves(128 + 4) * 4 = 528bytes. The emitter's effective local size is 256 threads and allocates(256 + 8) * 4 = 1056bytes. With 31,744 bytes of guest LDS, the frontend sees31,744 + 528 + 4 <= 32,768and keeps it in Workgroup memory, while the emitted guest LDS plus exchange is 32,800 bytes. Please derive both decisions from the same effective local-size calculation and add this derivatives/zero-dimension boundary toLdsLockBudget.The updated fixture uses
{128,1,1}without derivatives, so its two calculations agree and it cannot catch this mismatch. The current head otherwise changes only that fixture; the production sizing paths are unchanged. The R9700 hardware report correctly notes that its subgroup 32/64 device never takes this narrow-host exchange. My check is source/arithmetic plus exact-head diff/CI inspection; I did not run a local GPU test. Hosted exact-head jobs are still queued.The independently observed dead-ReadFirstLane reservation can cause an unnecessary LDS spill, but I treat that as a separate non-blocking performance follow-up.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T09:31:06Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
1b541dd5891560d81a11ce9e7139043df8bf1e2b. The new two-pass translation usefully resolves the non-blocking dead-ReadFirstLane spill: it now reserves the exchange only after a liveIrOpcode::ReadFirstLanesurvives simplification. The prior fixture-liveness fix also remains.The blocking dimension mismatch is unchanged. The second-pass decision still computes
exchangeBytesthroughNarrowReadFirstLaneExchangeBytes, which treats raw zero X/Y dimensions as 1, while the eventual emitter'sWorkgroupLocalSizesubstitutes 2 for zero X/Y when compute derivatives are required. The same concrete witness therefore skips the new retranslation entirely:{128,0,1}, compute derivatives, guest LDS 31,744 bytes, limit 32,768;DeviceMemoryLdsBytes(..., 528)returns zero and theifis not entered;Please compute the reservation from the same effective local size used by the emitter (including derivative defaults/lane transforms), then add this zero-dimension derivatives boundary to
LdsLockBudget. The current{128,1,1}non-derivative case still makes both calculations agree and cannot catch it.This review is source/arithmetic on the exact delta; the relevant sizing functions are otherwise unchanged from the previous head. Fresh hosted checks are queued. I did not run a GPU test, and the reported subgroup-32/64 hardware cannot enter the narrow-host path.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T09:32:01Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the narrow-subgroup runtime rerun remains unverified and is an optional follow-up.
What I ran
Reviewed head
1b541dd5891560d81a11ce9e7139043df8bf1e2b. I read the prepared description, commits, diff, manifest, and all included changed files, then inspected the changed code paths and relevant callers withrepo_read.py. No tests or builds were run. The fullShaderMemory.cpptext was excluded because it exceeded the review-folder size limit; the relevant changed hunk was available in the diff.Results
Findings
Blocking
None.
Non-blocking
Not verified
ShaderMemory.cppcontents; only the changed diff hunk was inspected.files.jsonwere not available for review. The prepared manifest marks nine changed files as included; eight full files were read, andShaderMemory.cppwas excluded by size.To get this to a good state
Nothing is required. Optional: run
agc_driver_wave32_unequal_buffer_read_first_laneon a subgroup-8 Vulkan device and report the result.Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T13:24:51Z.
Review: APPROVED
Re-reviewed exact head
c0065b712b90ca51a5e2c4564ba86e81a3745fe5. This resolves my remaining sizing blocker.After simplification, the resource pass now derives both liveness inputs from the surviving IR and calls the same
WorkgroupLocalSizehelper as the emitter. For the reported{128,0,1}compute-derivative case it therefore uses the effective{128,2,1}size: 256 invocations, 8 guest waves, and a 1,056-byte exchange. With 31,744 bytes of guest LDS, the combined budget selects the existing device-memory LDS path instead of emitting 32,800 bytes of Workgroup storage.I independently compiled the exact helper/callsite and compared the sizing arms: this head reserves 1,056 bytes and spills the 31,744-byte LDS; the parent behavior and an intentional
computeDerivatives=falsecontrol reserve 528 bytes and incorrectly keep it; a dead-ReadFirstLane control reserves nothing. The checked-in boundary arithmetic passes and the exact-head hosted Windows run executesagc_lds_lock_budgetsuccessfully (227/227 selected tests overall).The checked-in derivative addition tests the shared helper and boundary arithmetic rather than recompiling a derivative shader, so an end-to-end SPIR-V assertion would make the regression stronger, but I do not consider that a remaining correctness blocker after the production-path and negative-control checks above.
My local exact target compiled and linked, but Microsoft Defender quarantined the generated AGC test executable before execution under a heuristic that has also affected other locally built AGC test binaries. I did not restore, allow, exclude, or execute it, so I am not claiming a local binary run.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-24T23:27:29Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
c0065b712b90ca51a5e2c4564ba86e81a3745fe5using the pinnedrepo_read.pytools. No build or tests were run in this environment.description.md,commits.md,manifest.json, anddiff.patch. Inspected the changed shader emission, LDS budgeting and fallback paths, the relevant tests, and confirmed execution tests are globbed fromtests/execution/*.cpp.Results
Findings
Blocking
None.
Non-blocking
Not verified
ShaderMemory.cppviarepo_read.py; did not read unrelated portions of large files.files.jsonwas not available as a review document;list_filesshowed all changed files and identifiedShaderMemory.cppas too large to include in the bundle.To get this to a good state
Nothing is required. Optional: run
agc_driver_wave32_unequal_buffer_read_first_laneon a subgroup-8 Vulkan device.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T09:17:38Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the code inspected; the narrow-subgroup runtime behavior remains unverified.
What I ran
Reviewed PR head
6c99e1b164747b3c3937f5a828d987d54e3b4d7busing the prepared diff and pinnedrepo_read.pyreader. No commands or tests were run. The description reports Windows 11, GCC 15.2, and focused test runs on NVIDIA subgroup 32 and AMD subgroup 64; those are author-reported results.Results
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/Recompiler.cpp:955retries with the existing subgroup-local shuffle, which preserves the known narrow-subgroup limitation for those shaders.Not verified
The full text of
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded by the review-folder size rule; its changed hunk was inspected indiff.patch. No tests were run, and narrow-host runtime behavior was not verified. Other repository files outside the targeted implementation and test context were not inspected.To get this to a good state
Nothing is required. Optional: make the divergent-flow fallback visible to callers or diagnostics.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T09:22:03Z.
Review: COMMENTED
Architecture findings (1)
Advisory architecture findings (1)
951e0444-d8bf-46f6-8c30-b6ba9b924033Reviewing files that changed from the base of the PR and between
0f107f9812and6c99e1b164.core/libs/prx/libSceAgcDriver/tests/LdsLockBudget.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/execution/ReadFirstLane.cppcore/libs/prx/libSceAgcDriver/tests/execution/Wave32UnequalBufferReadFirstLane.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvAnalysis.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cppcore/shader/recompiler/SpirvBackend/src/SpirvAnalysis.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:31:35Z.
Review: COMMENTED
The unequal-input fixture checks both guest waves in a 45-thread workgroup, including the partial final wave. Please run it on a Vulkan device that actually selects a subgroup below 32, and include the chosen subgroup width with the result. The synthetic SPIR-V and LDS-budget checks confirm emission and accounting. The listed hardware runs have subgroup sizes 32 and 64, so the narrow exchange's workgroup barriers and observed results still need runtime evidence. I queued the common tests and unequal-input fixture on lavapipe.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.