fix(recompiler): run vertex programs as one-lane waves without vertex subgroups #4470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4470"
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 overlordxrz-source on 2026-10-12T12:50:47Z.
What
On lavapipe and MoltenVK every vertex program that declares a subgroup capability is refused by the driver's shader validation (
ShaderValidation.cpp:205):Capability 61 is
GroupNonUniformand stage 1 isVK_SHADER_STAGE_VERTEX_BIT. Most vertex programs declare it, because the entry EXEC is a ballot. Neither driver lists the vertex stage insubgroupSupportedStages:FRAGMENT | COMPUTE | TASK_EXT | MESH_EXT(lvp_device.c, Mesamain)FRAGMENT | COMPUTE, plusTESSELLATION_CONTROLwhen tessellation is on (MVKDevice.mm,populateSubgroupProperties). #1565 measured the same set on an M1 Pro and skippedagc_driver_exec_host_lanes's vertex draw there.The validation is right to refuse these modules, so this PR changes what the recompiler emits for vertex programs on such devices.
How.
SpirvTarget::vertexSubgroups(defaulttrue) records whether the device'ssubgroupSupportedStageshasVK_SHADER_STAGE_VERTEX_BIT.VulkanDevice::buildTargetsets it. It is part of the cache key and of the serialized request (version 17 → 18; older requests read astrue).false,HostSubgroupSizegives vertex and local programs a host subgroup of 1 lane. The existing narrow-host machinery takes it from there, so each invocation runs as a wave of one lane:s3is1 | 1 << 8(one vertex, one primitive), next to the32 | 32 << 8that #3546 added for 32-lane hosts;SubgroupLocalInvocationIdis declared;(p ? 1 : 0, 0, 0, 0), the find-LSB of a ballot isFindILsbof its first word, a shuffle returns the invocation's own value, an elect istrue;GroupNonUniform*instructions now go through four helpers inSpirvSubgroup.cpp(EmitSubgroupBallot,EmitSubgroupBallotFindLsb,EmitSubgroupShuffle,EmitSubgroupElect), which emit the subgroup instruction as before or the one-lane form. The call sites keep their ID allocation order.Why results are right for the lanes that exist. Each lowering is what the subgroup instruction returns in a subgroup of exactly one invocation. A wave with one vertex is also a wave the console launches, and
s3now says so. EXEC starts asballot(true)= lane 0, sov_mbcnt,s_ff1/v_readlanewaterfalls,v_readfirstlane, saveexec and branches compute what they compute for lane 0 of such a wave. Cross-lane reads keep the rules narrow hosts already have (TechnicalDebt, "lanes outside the host subgroup"):v_readlane_b32of lane ≥ 1 andv_permlanex16_b32throw (... is outside the 1-lane host subgroup ...), as they do on 8-lane hosts today;v_permlane16_b32without fetch-inactive,ds_swizzle,ds_bpermuteand DPP take any other lane as inactive (old value or 0).Limits.
s_mov_b64 exec, -1) and reads them still differs from the console, as on any narrow host. The Unreal NGG culling scan from #2783 is such a program. On these devices it now throws atv_permlanex16_b32in the recompiler instead of at shader validation; matching it on one lane would need the #3546 proofs redone fors3 = 1, which is not in this PR.subgroupSupportedStages; I kept this PR to the vertex stage the error names.Related: #3891 (draft, Apple ARM64 AOT) folds away a constant
LaneId < 32mask so its cube shader avoids the vertex capability on MoltenVK. That removes the capability for one shape only; this PR covers any vertex program.Tested
Rig evidence (before this change): our Linux sweep on
mainb42ef24ewith Mesa lavapipe stops eight homebrew titles at the error above: Stremio Plus, ProsperoStore, EVO Player, OpenNOW, PS5VR, Jelly5, Emby5 and Nuvio PS5. They have not been rerun with this change, so whether they get further, and where they stop next, is unknown until a rig rerun.This change, on
main3d8ffeb27, in an aarch64 Linux sandbox with zig 0.17 (clang) and no GPU:agc_shader_memory, newverifySingleLaneVertexWave:vertexSubgroups = false, a lane-op program (v_mbcnt_lo/hi,v_readfirstlane_b32,v_readlane_b32lane 0) and ans_ff1_i32_b64waterfall build with noGroupNonUniform*capability, instruction or subgroup built-in; withtrueboth use them;s3is0x101without vertex subgroups (the same module for device subgroup sizes 4 and 32), and0x4040with them on 64 lanes;outside the 1-lane host subgroup, and builds on a 32-lane vertex subgroup;ShaderMemory.cppbuilt natively. 35 of the 36agc_shader_memoryfunctions pass, includingverifyLanesOutsideHostSubgroup,verifyHalfWaveReduction,verifyNarrowVertexWaveand the new one.verifyGuardedNullPointerscan't run in that harness: it reads guest memory through a stubbedGuestMemory.v_permlane16_b32,v_permlanex16_b32, the #2783 culling scan) as vertex and pixel programs × wave32/64 × subgroup sizes 4/8/32/64, 128 compilations with vertex subgroups on (the default): all 96 modules that build are byte-identical tomain's. The 32 that throw give the same messages; only the request version embedded in the message changes.spirv-val --target-env vulkan1.1(SPIRV-Tools 2026.4) and use no subgroup capability. The 28 that throw are the constant lane ≥ 1 andv_permlanex16_b32reads above. The pixel modules are byte-identical tomain's.-fsyntax-onlyof every changed.cpp(includingVulkanDevice.cppandShaderMemory.cpp): no errors, no warnings on changed lines.tools/check_conventions.py --base origin/mainpasses.Not tested: a Windows build or run, any run on lavapipe, MoltenVK or another GPU, and any title.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)last provoking vertex with explicit per-vertex flat interpolation is unsupported; EVO Player, OpenNOW, PS5VR, Jelly5 and Emby5 run past the 120 s timeout with no stop; Nuvio PS5 throwsstd::logic_errorfrom a later stageImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T14:35:13Z.
Review: COMMENTED
PPSA28997 gets past this wall on lavapipe with this PR's libs. The case this body describes — a device whose vertex stage has no subgroups — is the one here:
Selected GPU name=llvmpipe (LLVM 23.1.1, 256 bits) vendor=0x10005 device=0x0 subgroup=8, on which the run used to abort with exactly that error.Same relinked
app.elfand the same staged tree for both runs; onlylibs/was replaced. Logs:~/rea-work/gow-run4.log(before) and~/rea-work/gow-run5.log(after), launched the same way:Before — libs from a main-era build (
33ae282e4),gow-run4.log:152-158:That is 12 s of run (09:55:03 → 09:55:15), 10
StorageTexturelines and one rect-list draw, dead at the first presentation — before the shader cache flushed any totals, which is why there is none to compare below.After — this PR rebased onto
57dc13602(applied without conflicts,048b59c3a) and built,gow-run5.log:subgroup capabilityerror and any[videoout] presentation failedline are absent from the after log altogether (0 occurrences each, against 2 and 1 before).StorageTexturelines — 11×1920x1080, 10×2048x1088, 10×1024x544, 8×128x1 and smaller, vk formats 37×11, 9×10, 16×10, 76×8, 122×4, 100×1 — one rect-list draw, tenAvPlayerResource FreeDirectMemoryINFO lines, a pad connect.run5 exit=124, 10:05:33 → 10:15:43); the timeout path dumps core, so that is a kill rather than a clean exit.…/shader_cache/7ec63b111d1bd1ac (source version 7ec63b111d1bd1ac, format 27)where the before run's was2169f238263a0f90— those areShaderCacheVersionsource versions, not commits — and the totals are(totals: 0 hits, 90 misses, 90 writes)with 0 load and 0 write failures in that interval. A new key selects a new empty directory; the old one is still on disk with its 86 files.CacheKey.hppis in this diff, so the move is expected.Attribution.
git log 0ef9dc928..57dc13602 -- core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp core/shader/recompiler core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppis empty (19 commits in that span), so for these paths the two builds differ only by this PR. The two builds do also differ by main's nine other commits in between, which I did not control — so this shows the change is enough to get past the wall here, not that nothing else contributed.The SHAs, for whoever re-checks: before-sha
33ae282e4; PR head0bcff53b2(parent0ef9dc928); the rebase tested,048b59c3a(parent57dc13602, currentmain). The before libs are no longer in the staged tree — it was rebuilt at 10:02, so onlygow-run4.logcarries that state.Caveats. Not gameplay: after the pad line the log has three teardown lines and then the kill, so this is "past the wall, title alive".
AvPlayershows only that repeated free-memory INFO line, so "the intro video is playing" would be an inference the log does not support. All of it is lavapipe — no real-GPU comparison. And this title needed its own PSN plugin parked (run-gow/.disabled/PSN.prx.guest.prx) before it reached presentation at all; that is a separate crash in that plugin's initialiser, unrelated to this change.Posting as an observation only — nothing requested, and I have no PR against this path.
Written with AI assistance.
Hermes Agent 🤖 at your service
Imported from boykopovar/AnyPS5. Originally posted by Xabilimon1 on 2026-10-12T15:31:27Z.
Tested this PR on MoltenVK, since the description lists that as not tested.
Setup: Apple M3, macOS 27.0.1 (26A434), x86-64 under Rosetta, Vulkan SDK 1.4.363.0 with MoltenVK 1.4.2.
vulkaninforeportssubgroupSize = 32andsubgroupSupportedStages=TESSELLATION_CONTROL | FRAGMENT | COMPUTE.Base:
mugurc:macos-port(de3ef5d53) merged withmain0ef9dc928(this PR's base), then this PR (0bcff53b2) on top. Two things in that base are mine and not in either branch:mainadded since the last re-stack does not compile on macOS:O_DIRECTinDescriptorControl.cpp, the physical-span blocks inDirectMemory.cpp(__linux__only, whileWatchMappingalso builds on__APPLE__), and missing<initializer_list>/<sys/mman.h>includes inGuestGetrlimit.cppandGuestKernelStackProtect.cpp;macos-portin five recompiler files: its commit47bf3675aalready routes shuffles and ballots throughEmitLaneShuffle/EmitLaneBallot(results stored viaEmitConvergentResult). I kept those helpers and made them emit throughEmitSubgroupShuffle/EmitSubgroupBallot. @mugurc, this will need the same merge whenmacos-portis re-stacked.Results (
ctest -j1 --timeout 30, withoutlds_atomics64,flipandvideo_out, 920 tests, same set of skips in both runs):agc_driver_ngg_vertex_wave_infofails without the PR (subgroup capability 61 is unsupported for shader stage 1) and passes with it (3 of 3 runs alone).patched_librariestimed out at 30 s in the run without the PR and passed in 3 s in the run with it. @DavidSamir reported it timing out under load on #1, so I don't count it as an effect of this PR.With the vertex-subgroup skips removed locally from the tests (not part of this PR):
agc_driver_exec_host_lanes: the vertex draw passes, 3 of 3.agc_driver_ngg_vertex_wave_reduction:v_permlanex16_b32 from lanes 16-31 is outside the 1-lane host subgroup that runs this wave64 program at one lane per invocation, 3 of 3. That is the limit described in the PR, so its skip should stay.Not tested: any title, lavapipe, Windows.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-12T16:34:04Z.
Serialization coordination completed: #4470 is merged. #4451 is now rebased on main
2f4cc8983at3040cd741. It writes version 19 and preserves original #4470 version 18 requests for subgroup support both off/on. Original-serializer fixtures and the malformed-reader fault control pass; full NVIDIA suite: 990 passed, 0 failed, 7 skipped.Correction to the earlier GPU matrix: setting
APS5_NO_GPL=0disables GPL too. Actual GPL-on testing leaves it unset. The corrected matrix has remaining AMD runtime failures, so the earlier all-green GPL claim is withdrawn. These failures, controls and fresh-build retesting are maintained in #4451; serializer compatibility itself is separately validated.The proposed #4470-first sequence is complete. #423/#4031 still independently allocate different version 18 layouts and need adaptation to the canonical merged format; this is a source audit, not combined-head validation.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T17:46:18Z.
Confirmed from both heads, and the silent half is real. Read at this PR's
0bcff53b2and at #4451's4edc8d326:core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp, this PR:if (version >= 18u) result.request.target.vertexSubgroups = reader.ReadBool();if (version >= 18u) info.ditheredAlphaToCoverage = reader.ReadBool();Both also write
18uand raise the ceiling to18u. The two new reads sit in different functions — the target section andreadPixelInfo— so the serializer merges with no textual conflict at all, and the only thing that conflicts is the tests' prefix assertion (NVNQQREAAAA=→NVNQQRIAAAA=). That is the part that matters: a version-18 blob written by either head is not the layout the other expects, and after a merged landing both readers accept 18. A clean "no conflicts" report will not show it, which is why the version number itself has to carry the decision.I have no stake in which lands first, but the rule the evidence supports is one version per layout change: whichever is second takes 19, and both bodies should state the order so the second is not merged on a mergeability report. Your sequencing — this PR first, the alpha fields rebased to 19 with a v18 fixture retained — does that, and retaining the fixture is the part that keeps the v18 blob readable afterwards.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T17:50:18Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL1640, L1645core/shader/recompiler/CacheKey.hppL245core/shader/recompiler/Recompiler.hppL234core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cppL190-193core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppL119-121, L159-164core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cppL134-136core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cppL1183-1185core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cppL186-188core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cppL190-193core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppL119-121, L159-164core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cppL134-136core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cppL1183-1185core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvSubgroup.cppL186-188core/shader/recompiler/ControlFlow/src/RequestSerializer.cppL739, L760, L769, L791core/shader/recompiler/Recompiler.hppL234Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-12T17:52:46Z.
A run on two real GPUs, since the description's run had none.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head
0bcff53b2merged intomain2a5eca11c.As built: both GPUs have subgroup arithmetic in vertex shaders (
agc_driver_ngg_vertex_wave_reductionruns instead of skipping), so the one-lane path isn't taken.agc_shader_memory(withverifySingleLaneVertexWave),agc_driver_graphics,agc_driver_vertex_fetch, theflat_aperturesparts and the wave64 tests pass on both GPUs with--repeat until-fail:3.ctest --timeout 120 --parallel 4): 973 of 973 on the RTX 4070. On the iGPU 972 of 973; the one failure,agc_driver_f32_dot2_rounding, fails the same way onmain(noshaderFloat64, #4528).With the one-lane path forced: to run it on real hardware, I set
target.vertexSubgroups = falseinVulkanDevice::buildTargetlocally (not a proposal) and reran the full suite on both GPUs.agc_driver_ngg_vertex_wave_reduction(and, on the iGPU, the dot2 test above). That covers all the draw tests, with vertex and local programs running as one-lane waves.agc_driver_ngg_vertex_wave_reductionis refused at recompile:v_permlanex16_b32 from lanes 16-31 is outside the 1-lane host subgroup that runs this wave64 program at one lane per invocation. That test skips on a device without vertex subgroups, so it only ran because of the forced flag, and the program is refused, not computed wrong.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T18:24:08Z.
Two details in your run worth pinning to the head you built.
1. The one-lane lowering is exercised without your local flag. The tests added here take
vertexSubgroupsas an argument instead of reading it from the device (core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp:1480on0bcff53b2), andverifySingleLaneVertexWave()is called unconditionally from the test's mode list (ShaderMemory.cpp:3198), so the recompiler builds the one-lane form wherever that test binary runs, whatever the host device is. What your localbuildTargetchange was needed for is the driver route, where the value comes from the device — and that route is the case my earlier run covers:Selected GPU name=llvmpipe (LLVM 23.1.1, 256 bits) … subgroup=8has no subgroup arithmetic in the vertex stage, so the flag is computed false by itself and PPSA28997 gets past the presentation abort. Your two GPUs and that title run bracket the same path from both ends: with vertex subgroups nothing moves (your 973/973), without them the one-lane form is what carries a title.2. The refusal you forced is not reachable from a device. The flag is computed as
target.vertexSubgroups = (state->subgroup.supportedStages & VK_SHADER_STAGE_VERTEX_BIT) != 0(core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:2968on this head), andNggVertexWaveReduction.cpp:135-137skips on exactly that predicate —skipped, the device has no subgroup arithmetic in vertex shaders. A device can only produce the false flag where that test does not run, so the refusal you saw under the forced flag guards a configuration no device reaches, and it is still a refusal rather than a wrong result. Reporting it as a guard rather than as a wall is the accurate reading, and holding the hack back from the PR is the right call: the driver-level behaviour of a subgroup-less device is what the title run stands on, and it is not reproducible on either of your GPUs.Written with AI assistance.