fix(shader): keep waves that end early at their workgroup's later barriers #26756
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26756"
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 androidbaklava on 2026-11-24T20:09:12Z.
What
In a guest compute program, a wave can branch to
s_endpgmwhile the other waves of its workgroup still reach ans_barrier. On AMD hardware the ended wave simply stops counting at the barrier. The recompiler emits that branch as a structured selection whose merge is the program exit, so the laterOpControlBarriersits in control flow that only some invocations reach. Vulkan leaves that undefined. NVIDIA's and AMD's drivers happen to tolerate it, but Intel's Windows driver waits for the invocations that left: the device is lost about 3 s later (vkWaitSemaphoresKHR ...: Vulkan result -4).This change keeps such a wave in the program instead. When a compute program with more than one wave per workgroup has a branch whose one side is the merge of its selection, the merge ends the program (no writes, no barrier), and the other side reaches an
s_barrier, the branch always enters the body and records the leaving waves in a per-invocation flag. Every LDS, GDS, buffer, image and memory write is then emitted under that flag through the existingEmitUnlessInvocationFaultedpath, so an ended wave changes nothing but reaches each barrier at the same instruction as the other waves. Programs without that pattern compile exactly as before. The new debt entry lists what this does not cover (an exit from inside a loop, or one reached through other blocks).Found with Photo Splat VR (PPSA99770, from the homebrew catalog). On
mainit loses the device in every run at compute shader0x200540500, the prefix scan of its splat radix sort: after its loop,s_cbranch_execzsends waves 4 to 7 tos_endpgmand waves 0 to 3 run two more barriers. Replaying that shader alone in a local test hung with one workgroup too. Edits to its SPIR-V showed that making all waves run the post-loop section, or removing both of its barriers, stops the hang, while giving the leaving waves the same number of barriers at a different instruction does not, so the waves have to reach the same barriers.Tested
Windows 11 Home 10.0.26300, i7-13620H, Intel UHD Graphics
8086:a7a8(Raptor Lake), driver 101.7084, WinLibs GCC 15.2.0 r7 UCRT, Release.main2711791787against this change from the same build tree.New test
agc_driver_ended_wave_barrier: eight waves (wave32, then wave64), waves 4 to 7 branch tos_endpgm, waves 0 to 3 write LDS, pass a barrier, read it back, pass a barrier and store. It checks the live threads' values and that the ended waves' outputs stay untouched. Onmainit loses the device in every run (3 of 3, plus the A/B run below); with this change it passes 3 of 3, both wave sizes.Focused tests with
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer(Khronos validation 1.4.363),ctest -R '^agc_driver_(ended_wave_barrier|lds_.*|ds_.*|wave.*|divergent_device_atomic_barrier|look_back_scan|relative_dpp|presentation_fsr|runtime_buffer_spans_fault_barrier)$' -V:mainended_wave_barrierfailed (Vulkan result -4)VUID-/SYNC-HAZARDlinesBoth logs show
Insert instance layer "VK_LAYER_KHRONOS_validation"for all 32 tests and neither showswas not found but was requested.Full
ctest -R ^agc -j 4with this change: 2117 tests, 12 failed. Eleven are the Intel failures a fullmainrun (5e9ad5f57b) has on this machine, covered by #20831, #21683, #21713, #21741, #21749, #24072 and #25608, plushost_import_failure_handles, which fails there too under parallel load. The twelfth,agc_driver_presentation_fsr, timed out once in that run; it passed 7 of 7 alone and 2 of 2 next to the heaviest AGC tests, and none of its shaders takes the new path (checked with a local print, not committed). The 29 non-GPU recompiler tests pass.Photo Splat VR with this change: the radix sort runs and no device loss occurs. The title then stops at the known missing-barycentrics limit of this GPU (
a pixel shader on the mesh path reads barycentrics, and this device has neither VK_KHR_fragment_shader_barycentric nor mesh shaders), so it is not playable here.Not tested on NVIDIA or AMD, where the old SPIR-V did not hang. A program with this pattern now runs the rest of the program for the ended waves with their writes masked, which costs some time in those programs only.
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 mihiii1337 on 2026-11-24T20:59:07Z.
Review: CHANGES_REQUESTED
The production change is strongly supported by a physical Intel/NVIDIA A/B, but the new fixture should dispatch one workgroup before it can be relied on as a deterministic regression test.
EndedWaveBarrier.cppallocatesOutput[Waves * 64], derives every store address only fromLocalInvocationId, and disables all workgroup-ID inputs. WithGroups = 16, all 16 workgroups therefore perform non-atomic stores to the same single-group output slots. The test only needs one group:Threads = 512still gives eight waves and both workgroup barriers, including the early-ended waves. Please changeGroupsto 1 (or give each group a disjoint output region and validate all groups).I tested exact head
d1532fdeeb8fbcc820eb782b33d0c145c6d2e2b3, cleanly merged onto then-livemain61cce6e86b9bbafa91551f7eb46af8f94f00bcc4, with a local test-only one-lineGroups=1fixture applied identically to main and the candidate. Windows 11 build 26300, WinLibs GCC 15.2.0 r7, Release, shader cache disabled, pinned physical ICD, Khronos validation 1.4.369 with synchronization validation:8086:a78b, driver 101.6127 / Vulkan 1.3.295: main failed Wave32 in 3/3 fresh processes at round 0, thread 0 (0xdeadbeef, expected 1). The candidate passed Wave32 and Wave64 in 3/3 processes, including all live values and inactive sentinels.Groups=1fixture, only the Wave32 call omitted so fail-fast could not hide Wave64) failed on main in 3/3 processes at the same first live value and passed the candidate in 3/3, all 16 rounds.10de:2860, driver 621.01 / Vulkan 1.4.357: main and candidate both passed Wave32 and Wave64 in 3/3 processes, providing the no-regression control.Across the 18 primary and Wave64-control processes, the intended physical device and validation layer were confirmed, with no skips, fallback,
VUID-,SYNC-HAZARD, missing-layer, or device-loss result. The newer main commits after61cce6e8do not touch AGC, shaders, or this fixture, and the head remains unchanged.The stock
Groups=16binary was built and archived but is not counted in this A/B because of the shared-output race. After the one-line fixture correction, the hardware evidence supports the production fix.No PS5/title run was performed.
AI-assisted: yes (OpenAI Codex); exact heads/merge trees, fixture blobs, binary hashes, device/layer selection, every CTest/JUnit result, live values, and sentinels were checked directly.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T14:18:49Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected change blocks merging; the behavior is narrowly gated and the author reports focused Intel Vulkan validation coverage.
What I ran
Reviewed head
d1532fdeeb8fbcc820eb782b33d0c145c6d2e2b3against the prepared diff. I did not run commands or tests. Read the description, commits, manifest, diff, and all six changed files; no changed files were excluded in the manifest.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author-reported tests and Intel device behavior were not independently reproduced. NVIDIA and AMD behavior was not tested, as the description also notes. No files were excluded by rule.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T15:16:27Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed diff has no verified blocking defect; the reported test results are author supplied, and I did not run checks or read every changed file in full.
What I ran
Reviewed head
ead3617311702434bece640927611dd8d150b1e9using the prepared diff andrepo_read.py. No commands or tests were run. The description reports Windows 11 and Intel UHD Graphics test results; these were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed the prepared diff and repository context at the pinned head. Behavior claims about the implementation are limited to the code inspected; no external sources were used.
Not verified
Did not independently verify the reported test runs or console behavior. Read the full new test file and targeted ranges in
SpirvFlowEmitter.cpp,SpirvEmitter.cpp, andSpirvBdaFault.cpp. Reviewed the diff for all seven changed files. Did not read the full text ofSpirvEmitterState.hpp,SpirvFlowEmitter.hpp,SpirvFlowEmitter.cpp, or the debt document.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-25T15:58:06Z.
Review: CHANGES_REQUESTED
I re-reviewed exact head
ead3617311702434bece640927611dd8d150b1e9. The three points from my previous review are addressed: the fixture uses one workgroup, ended invocations no longer publish ordinaryrecord_bda_faultrecords, and loop headers make the transformation ineligible.Focused Windows verification on the physical notebook adapters:
8086:a78b, driver 32.0.101.6127):agc_driver_ended_wave_barrierpassed, including Wave32 and Wave64;10de:2860, driver 32.0.16.2101): the same test passed, including Wave32 and Wave64;VUID-and 0SYNC-HAZARDlines;main's recompiler still fails on Intel, while the previous PR headd1532fdefails on both adapters with the expected deferredBDA access failed: address=0x0 instruction=0x2crecord. This confirms the new ordinary-fault gate, not just a no-regression run.I found two remaining control-flow blockers.
The new ended-invocation check is confined to
record_bda_faultinSpirvBdaFault.cpp. Guarded scalar SRT reads do not use that function:EmitReadConstwritesBdaAbi::SrtGuardWorddirectly withOpAtomicStoreorOpAtomicCompareExchangeinSpirvMemoryInstructions.cpp:1705-1716, then callsStopBdaInvocationIf.BdaResources.cpp:483-486checks that guard even when the ordinary fault record is empty. ExistingShaderMemory.cppassertions at 11984 and 12071 explicitly confirm that this path latches without callingrecord_bda_fault. Therefore a wave kept after an earlys_endpgmcan still publish a host-visible SRT guard fault if it reaches a poisoned guarded scalar read. Please gate this path with the ended-wave state as well, or conservatively reject programs with such reads, and add a regression. This is a static emitter/control-flow finding; I did not claim a hardware reproduction of the poisoned-SRT variant.ReachesBarrierWithoutLoopBeforesets onebarrierflag while traversing every successor and returns true when any reachable block contains a barrier. A nested conditional may therefore have one arm that reaches the barrier and another that reaches the merge without it. The transformed early-ended waves retain their old SCC/VCC state and can take the no-barrier arm while live waves take the barrier arm, so the debt statement that every invocation reaches eachOpControlBarrieris not guaranteed. Please either require every reachable path to encounter the relevant barrier before the merge, or keep this transformation to genuinely straight-line regions by rejecting nested conditional/indirect branching. A regression with a nested branch that bypasses the barrier would distinguish the two cases.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T21:43:31Z.
Review: APPROVED
Reviewed — looks good
The targeted review of head
e61e854e5a7d27dcdfe5de1ed2b6598fb32fcb3cfound no verified blocking defect; reported test results are author supplied and were not run here.What I ran
Read the prepared diff and all changed files at the pinned head using
repo_read.py. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run. The prepared bundle's
files.jsonwas not available through the reader; the file listing and manifest show all eight changed files as included, and each was read. No additional files were excluded according to the prepared manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:18:16Z.
Review: COMMENTED
The new test checks early-ended waves, a guarded read and a CFG shape where a branch can bypass the barrier. Could it also run a partially populated final wave through the same fixture?
endedWavesStaytracks the logical end per invocation, and that case would exercise participation of the host lanes that represent the tail of a guest workgroup.Source review at
e61e854e5a. The head trial-merges onto192c4e45a0. Paired Linux checks are queued.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.