perf(shader): span single-wave wave64 compute by default after a uniformity check #7922
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7922"
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 ThatsLeo on 2026-10-19T14:08:00Z.
What
#5405 runs a single-wave wave64 compute program at one guest lane per invocation, across two full 32-lane host subgroups. It is off unless
APS5_SPANNED_WAVEis set, because its cross-lane exchanges use workgroup barriers, and the emitter could not tell whether every invocation reaches them: its debt entry lists a manualspirv-disscan as the only check. This PR adds that check and turns the layout on by default.SpannedBarrierInDivergentFlow(SpirvSpannedUniformity.cpp) runs on every spanned module after emission. It marks the values that can differ between the invocations of a wave, iterating until nothing changes:LocalInvocationId/Index,GlobalInvocationId,SubgroupId,SubgroupLocalInvocationId, the subgroup masks);A selection is divergent when its condition is marked. A loop is divergent when its header condition is marked, or when it can be left from per-invocation control flow. The construct's blocks are read off the dominator tree: the header's subtree minus the merge's. A construct is also divergent when a per-invocation branch without a merge instruction leaves it or continues its loop. When a divergent construct returns or kills, everything reachable from its merge is divergent; when it branches past its merge, as a
continuedoes, the merge's subtree is.If an
OpControlBarrier, or a call that reaches one, sits in a divergent construct,EmitthrowsSpannedWaveUnsupported.Recompilealready catches that and emits the program at two lanes per invocation, so a rejected program runs as onmain. The check runs beforeSpirvEmitInfo::fullSubgroupsis set, so the fallback is not created withREQUIRE_FULL_SUBGROUPS.VulkanDeviceturns spanning on wherever it was available under the switch (computeFullSubgroupswith 32-lane compute subgroups).APS5_NO_SPANNED_WAVEturns it off;APS5_SPANNED_WAVEis gone.The analysis runs until nothing changes, so it cannot stop early and throw. It is skipped for a module with no
OpControlBarrier, and each function's flow graph is built once.Opcode,ResultandVisitIdOperandsmove unchanged fromSpirvSpecialization.cpptoSpirvInstructionOperands.hpp, templated on the instruction container, so both passes share the operand table.SpirvSpecialization.cppkeepsmain's arena-backedInstruction.Guarded SRT reads. A spanned wave does not stop an invocation after a fault (
bdaStopsInvocationsis false), so each later guarded read of a poisoned pointer wrote its record over the first.agc_driver_guarded_null_pointerthen reported the second dword of ans_load_dwordx2(address=0x4). Where invocations do not stop, the record is now written with a compare-exchange against 0, asrecord_bda_faultalready does, so the first fault is kept. Programs whose invocations stop keep the atomic store.The debt entry states what the check proves and what it does not: writes by other dispatches or queues, and the unexplained one-barrier ballot loss.
spanned_uniformity_testslinkslibcon MinGW, asspirv_validator_exit_testsdoes.Tested
Intel Arc (Meteor Lake), Mesa 26.2.4 ANV, Fedora 44, Linux 7.2.10, GCC 16.2.1, Release.
spanned_uniformity(new) builds twenty-one modules by hand:With
LocalInvocationIndexremoved from the per-invocation built-ins, the lane-dependent cases fail. Without the fence, early-exit, guest-memory and unmerged-continue rules, the cases they cover fail.Stray's compute requests: all 1,751 (PPSA02101) replayed through
agc_shader_replaywith a 32-lane target and spanning on, using a local switch that is not part of this PR. 1,117 programs span, the same with the guest-memory and unmerged-continue rules. The fence rule sends 13 programs back to two lanes per invocation that spanned without it (1,130). Stray's heaviest programs,0x2011300000and0x200e390000, still span. A Python prototype of the first analysis agreed with it.ctestonmain3bb15be09+ this PR:APS5_NO_SPANNED_WAVE=1:application_heap_scripting,application_heap_lazy,agc_driver_image_table_vouched_lookups,agc_driver_guest_memory_lifetime,agc_driver_multisample_retirement, plusguest_kernel_fcntl, which passes alone.application_heaptests fail.agc_driver_lds_mask_waterfallstill runs both modes and still spans.maineda7477ac, with #8004 on top: see #8004. The Arc and lavapipe failures also fail onmain, and the focused tests under the validation layer show noVUID-error.agc_driver_guarded_null_pointer, new onmain, failed with spanning on before the guarded-read fix and passes after it, 5 of 5 runs.Stray, frames 20 to 50 of the boot (
APS5_TRACE_FRAMES=20:30, 3840x2160).main+ #7811, againstmain+ this PR + #7811. Stray stops onmainwithout #7811 (#7693).128b8c1f8is this PR's first push. The final head differs from it only in the helper header's template parameters.main+ #7811trace_digest.py, first capture of each:aps5-summary.jsonllines,main+ #7811:This PR + #7811:
Traces, digests and summaries:
ThatsLeo:evidence/spanned-default.The fence and early-exit rules on Stray. Same scene and machine,
main559f35d68+ this PR (without, then with, the second commit) + #8004 + #7811. One warm run each, then four interleaved rounds. After a battery drain this laptop idled at 56 °C, so every capture started below 58 °C, not 55.The difference is inside the spread.
aps5-summary.jsonllinesTraces, digests and summaries:
ThatsLeo:evidence/spanned-fence.Runs by others, on earlier heads:
Not tested:
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 repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T14:08:14Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-19T17:49:08Z.
Review: COMMENTED
The Stray numbers are strong (GPU busy per present 303.4 to 173.1 ms, frame p50 449.3 to 331.5 ms, three interleaved rounds, spread small next to the gain), and the fallback to two lanes per invocation when the check rejects is the right shape. Turning this on by default for every device with 32-lane compute subgroups is where I don't agree yet.
OpControlBarrierdifferently is a hang orVK_ERROR_DEVICE_LOST, not a wrong picture. Please postspanned_uniformityplus the Stray (or any wave64-compute title) pair on an NVIDIA card and a Radeon, or keep the default off for vendors that haven't been run.APS5_SPANNED_WAVEis removed andAPS5_NO_SPANNED_WAVEadded. Is the spanning decision part of the shader disk cache key and the pipeline journal key? A cache written under the old switch must not serve a two-lane module to a spanned layout (or the other way round) after this default flips.Opcode,ResultandVisitIdOperandsbetween files alongside the new pass. Splitting the move out of the behavior change would make the pass reviewable.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-20T19:01:59Z.
This PR looks strictly contained in #8004: its single commit
753bb56e3("span single-wave wave64 compute by default after a uniformity check") is exactly the first commit of #8004's branch, which carries one more on top (2276a44aa, "let spanned waves run at any host subgroup size where it can be narrower than 32"). Both are from the same series opened ~3 hours apart.If the intent was one review thread, closing this in favour of #8004 would keep a single place for the maintainers to look — #8004 also has a verified rebase handoff onto current
main(includingmain'sWordArenainfrastructure kept, theVisitIdOperandsalias restored, andmain's fiveInsertMeshBarycentricFlagsites preserved across your version-bump rewrites).Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-20T20:43:06Z.
Tested enabling
spannedWaves(state->spannedWaves = state->computeFullSubgroups) on Windows 10 / NVIDIA GeForce RTX 3080 (driver 595.71,hostSubgroupSize = 32) with Demon's Souls (PPSA0134101.007.000), which dispatches dozens of heavy single-wavewave64compute shaders (workgroupSize <= 64,>213,000compute dispatches across boot, intro, and title screen):VK_ERROR_DEVICE_LOSTor hangs on NVIDIA across cold-cache and warm-cache runs.laneCount = 2unroll on single-wavewave64compute shaders (0x1ee14f3c0,0x1eeb34840, etc.) cuts the specialized SPIR-V word count andvkCreateComputePipelinescompile time innvgpucomp64.dllnearly in half.Also reviewed
SpirvSpannedUniformity.cppand noticed four technical points worth addressing when rebasing ontomain:OpReturn/break/continue) inside a divergentOpSelectionMerge(Construct, L215–227):Construct(flow, header, merge)stops atif (node == merge) continue;. If a branch inside a per-laneOpSelectionMergeexits early viaOpReturn(or jumps to an enclosing loop's merge/continue block instead ofmerge), only a subset of lanes reachesmerge. AnyOpControlBarrierplaced inmerge(or dominated bymergeafter an early return) executes under a divergent active lane mask, butinDivergentFlowwill currently befalseformerge.Analysis::Run()throwsstd::runtime_errorinstead of falling back (L148):If the 64-round cap is hit on a deep loop-carried
OpStore/OpLoadchain,Run()throwsstd::runtime_error("spanned wave uniformity did not settle")instead of returning a rejection reason forSpannedWaveUnsupported, which aborts shader compilation rather than falling back to unspannedwave64(laneCount = 2).OpControlBarrier:In
SpannedBarrierInDivergentFlow(words)/Analysis::Run(), if the module contains noOpControlBarrierinstructions (barriers.empty()),Parse(words)andRun()still allocate astd::vector<std::uint32_t>per instruction and run the fixed-point dataflow loop. Scanningwordsforspv::OpControlBarrierbeforeParse(words)(and checkingif (barriers.empty()) return std::nullopt;) avoids ~100k heap allocations on large 500k–850k word compute shaders that have no workgroup barriers.BuildFlow(function)insideVisit(function)(L238):BuildFlow(function)rebuilds the CFG postorder and dominator tree on every iteration of theroundloop inRun(), even though the CFG is static. PrecomputingFlowonce per function avoids repeating dominator intersection on large shaders.Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-20T23:46:23Z.
Rebased onto
main559f35d68, with two more commits. The description is updated.@CnRJay, on your two points:
The analysis gap is closed rather than documented. A load at a uniform address is now uniform only from memory the program never writes, or from workgroup memory that a barrier fences on every path since the last write. Image reads count as per-invocation when the program writes an image. Of Stray's 1,130 spanning programs, 1,117 still span, and the heaviest ones are among them. The 13 others fall back to two lanes per invocation. Four interleaved Stray rounds with and without the rule are inside each other's spread (GPU 114.1 against 114.8 ms per present, frame p50 274.8 against 278.6 ms).
Other vendors. I first restricted the default to Mesa's Intel driver. Then the runs here and on #8004 came in:
So I left it on wherever 32-lane full subgroups exist, with
APS5_NO_SPANNED_WAVEas the switch. If you'd still rather gate AMD until someone runs a title there, it's a one-line change.The one-barrier ballot loss from #5405 is still unexplained, and the debt entry says so.
@hamb3r, thanks for the run and the review:
continuedoes, makes the merge's subtree divergent. The tests cover a per-lane return and a per-lane continue (both rejected) and a uniform return (kept). The return case passed the old check.OpControlBarrieris skipped before it is parsed.The rebase also showed that
main's newagc_driver_guarded_null_pointerfailed with spanning on. A spanned wave doesn't stop an invocation after a fault, so the second dword of a poisoneds_load_dwordx2overwrote the first record. Where invocations don't stop, the record is now written only while the guard word is 0, asrecord_bda_faultalready does.@blawesom, thanks. I'd keep #7922 open because @CnRJay's review and the assignment are here. #8004 lists it under Depends on, and reviewing #8004 covers both.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T00:00:51Z.
@ThatsLeo Thanks for closing the analysis gap. I read
SpirvSpannedUniformity.cppagainst the emitter at 4d84eb2a1d and ran the analysis standalone with your test builder. Your seventeen cases pass, and mutants that dropLocalInvocationIndex, the fence reset or the early-exit rule each fail them. One gap needs a fix before this can be on by default, and two smaller points:WrittenandRacyonly ask whether the load's own class is written. But guest memory is reached through bothStorageBufferdescriptors and BDAPhysicalStorageBufferpointers (SpirvRuntimeBuffer.cppemits both forms for the same buffer atomic). So a program that stores only through a BDA pointer and loads at a uniform address through a buffer descriptor gets that load counted as uniform. Inside one spanned wave, the two host subgroups can then read different values, which is the hazard the rule exists for. A minimal module (uniformStorageBufferload,OpIEqual, barrier inside the selection, plus oneOpStorethrough anOpConvertUToPtrPSB pointer) is kept today. With the store going to theStorageBufferinstead, it's rejected. Could you treat the guest-memory classes as one class inWritten, add that case as a rejected test, and post the new span count for PPSA02101?continuewithout a selection merge. The loop rule only looks at branches to the loop's merge block, and selections are only found throughOpSelectionMerge. SoOpBranchConditional %lane %continue %restin a non-header block (valid structured SPIR-V;SpirvFlowEmitteremits no merge when the terminator has none) leaves a barrier in%restunflagged. If the emitter can never produce that with a per-invocation condition, a sentence saying why is enough. Otherwise, treating a non-uniform conditional branch to the continue target like a per-lane break would close it.Recompileruns after theSpannedWaveUnsupportedcatch and still spans. The check then runs on a different module, and a rejection there fails the compile instead of falling back. Wrapping it the same way, or re-emitting with spanning off, avoids that.The rest looks right to me: the fallback doesn't set
REQUIRE_FULL_SUBGROUPS, the operand table move is mechanical, and the first-fault compare-exchange is sound because the host zeroes the guard word.Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-21T00:14:15Z.
@oneandonlydean Thanks, all three are addressed. Both PRs are rebased onto
maineda7477ac.Uniform,StorageBufferandPhysicalStorageBuffernow count as one class for both writes and loads. Your case is a rejected test: a uniformStorageBufferload, a barrier under it, and one store through anOpConvertUToPtrpointer. Next to it, a kept test reads the same buffer with no store anywhere. PPSA02101 still has 1,117 spanned programs, including0x2011300000and0x200e390000. The check only accepts or rejects modules, so the spanned modules are byte-identical to the previous push and the Stray A/B in the description still applies.continue. The emitter can produce one:SpirvFlowEmitteremitsOpBranchConditionalwith no merge whenever the IR terminator has none. A construct is now divergent when a block inside it ends in a per-invocationOpBranchConditionalorOpSwitchwithout a merge instruction and targets the construct's merge or, for a loop, its continue target. The per-lane version of your example is rejected and the uniform one is kept. Before this commit the per-lane one was kept.registrationis only true for vertex and fragment stages (Recompiler.cpp:584), andSpirvEmitter.cppsetsspannedWaveonly for compute. The second emit therefore never carries a spanned module, so the check never runs there.Tests on the new heads:
main.application_heaptests fail.agc_driver_guarded_null_pointer, show noVUID-error.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T06:24:21Z.
A discrete RDNA 2 run with spanning on by default: RX 6700 XT (gfx1031), AMD's Windows driver 32.0.21045.5002, Windows 11 26200, MinGW GCC 15.2.0, Release. It compares
maina07e985c8withmainmerged with this head,8d4f48671(the merge is clean).single-wave wave64 compute spans two full 32-lane subgroups: 1, next toWave32 programs run on subgroups of 32: compute 1.ctest -R "agc|shader|spirv|recomp|subgroup" --parallel 4 --timeout 120,ANYPS5_REQUIRE_VULKAN=1. Both sides pass 868 of 870, and the same two tests miss on each:agc_driver_image_array_window_past_layer_limitwas not run, since it doesn't build with MinGW onmain(#8310).agc_driver_tessellationfails on AMD's Windows driver onmain(#8861, fixed by #8884).Not run: the Khronos validation layer, other AMD drivers, and titles.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T06:32:59Z.
@ThatsLeo a discrete RDNA 2 data point from @thuanquang: with spanning on by default on AMD's Windows driver, the device log confirms spanning is active, and
mainand this PR both pass 868 of 870 on the agc/shader/subgroup set, missing the same two known tests. Thanks @thuanquang.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-26T23:11:12Z.
Review: COMMENTED
@oneandonlydean I don't have a setup that runs these titles, so I can't rerun
4844a289c2on a GPU and won't post a result I haven't measured. My cross-vendor point was that every number came from one Intel/ANV machine; since then NVIDIA (@hamb3r, RTX 3080, Demon's Souls) and AMD (@thuanquang, RX 6700 XT, spanning confirmed active) runs have come in with no device loss, hang or corruption, which answers it. What the current head still needs from the people who have the hardware is a run of the same scene with and withoutAPS5_NO_SPANNED_WAVE=1on each vendor, with the GPU and driver, so the default has a paired result on NVIDIA and AMD and not only a clean boot.