fix(shader): keep faulting invocations in their wave and mask their later writes #6416
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6416"
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 Celegans12 on 2026-10-15T14:31:05Z.
What
Stopping a faulting invocation can leave wave ballots unable to converge and stop its healthy partner lane. Eligible non-pixel programs with two lanes per invocation, ballots or shuffles now keep voting with the failed read's zero and mask that lane's later writes, atomics and exports. Existing spanned-wave, barrier and mesh exclusions remain.
Continuing exposed a guarded-SRT reporting regression: the second word of a null pointer replaced the first fault record. Adopt ThatsLeo's first-fault latch from #7922, adapted so masked lanes count as continuing. The existing guarded-pointer runtime oracle stays unchanged, and its host checks require compare-from-zero latches without unconditional overwrites. No spanned-wave policy from #7922 is included.
Masking adds work even without faults. Astro Bot's reported startup delay remains unexplained; no performance claim. The barrier-safe extension and subgroup-specific skip remain separate in #7392 and #6751.
Tested
Based on
mainb4a82720a8(rebased 2026-11-13 as one commit; the only conflict was the cache format, nowShaderDiskCache::FormatVersion90). On that tip, 61 focused host and NVIDIA tests (fault, guarded-pointer and guarded-load, faulting-wave, BDA span and anchor reads, GPU buffer format, wave decoding, shader memory and shader cache) passed three times with validation 1.4.363 loaded and no VUIDs or skips.Earlier rounds, on
maine6f57307fa: Windows 11, MinGW-w64 GCC 15.2.0: Release, -DBUILD_TESTING=ON, SPIR-V Tools ON. Before repair, main passesagc_driver_guarded_null_pointer; the merged PR fails 3/3 at address4 instead of0, PC0x24. One diagnostic run confirms the overwrite.Repaired head
771c8bdae4: 13/13 focused processes pass: host shader-memory; NVIDIA guarded-pointer x3, faulting-wave, GPU-buffer-format, BDA-device and span-reads; the same five GPU tests once on Windows lavapipe. All GPU runs require Vulkan, disable application shader caching and load validation 1.4.363; zero skips, timeouts or validation diagnostics. Lavapipe subgroup8 does not establish paired wave64-on32 behavior. Test registration, conventions and source review pass.Earlier baseline
e2df06e661plus the faulting-wave fixture fails on main because partner lane37 stays untouched. Not tested: current-head Linux, AMD/Intel hardware, console behavior or titles.On the merge with main
98346b748c, the wave invocation case initially failed on the hardware-spanning wave path. The follow-up keeps those lanes active but masks writes after a fault, and guards byte loads when the lane continues. Six selected fault, guarded-load, wave-decode and cache tests passed twice on Windows with an NVIDIA RTX 3080 Laptop GPU and Vulkan validation enabled. The updated emitter, BDA read and shader-cache sources also passed Linux C++ syntax and layout-guard compilation. No Linux GPU run was performed.Checklist
main; the first-fault latch from #7922 is adopted with attributionNotImplemented_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 Pipodi on 2026-10-15T17:36:18Z.
@Celegans12 a data point from Ghost of Yōtei (PPSA26344): RTX 4090, driver 617.42, Windows 11. This PR on main
0dab493f5+ #5815 #5781 #6227 #5405 #6402 #6174, withAPS5_SPANNED_WAVE=1(#5405) and a cold shader cache (our run163).In our base, this PR conflicted in
SpirvEmitter.cppwith a local change that kept spanned programs out of the BDA stop. I took this PR's version and countedspannedWaveas a wave operation (waveOperations = ... || state.spannedWave), so spanned programs take the write-masking path.It still loses the device, at ~1,460 s (frame ~817):
vkQueueSubmit recorder: Vulkan result -4;That's the same signature as our earlier spanned runs without this PR.
The non-spanned build of 0x80001e5f00 (839,036 words) dispatched fine. The spanned pipeline (838,306 words) was created about 5 minutes before the loss, but the log has no dispatch line for it. After it came several minutes of cold compiles of new 0x801d* programs, and the loss hit while 0x801d29eb00 was being created. So I can't tell whether that program or another spanned one hung. With spanned waves off, the same base runs well past that point.
If you have a suspect, I can rerun with more logging.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-15T19:23:19Z.
A cost I measured tonight that reviewers should know about: on NVIDIA, the write mask roughly doubles pipeline compile time for PPSA26344's giant two-lane compute programs.
Compiled side by side on the same machine, compute 0x801cdd2700 (about 1.75M SPIR-V words) takes 700 s with the earlier "reads continue, nothing masked" version and 1,411 s with this PR. The module is only about 0.5% bigger: roughly 90 more branches and about 550 more stores and loads of the per-lane faulted flag. So the extra time looks like NVIDIA's compiler handling a flag that stays live across the whole program, not the extra code itself.
For now our game branch keeps the older version, so our precompiles don't take twice as long. I'll look at making the mask cheaper, for example only guarding writes that a fault can reach, or keeping the flag in a form the compiler handles better, and post numbers here. If anyone has a preferred shape for this, I'm happy to hear it before I start.
Details
agc_shader_replay --pipeline-onlyinto an empty VkPipelineCache and an empty NVIDIA store, both builds compiling concurrently.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T19:59:49Z.
Tested on Linux with lavapipe, the CI device: llvmpipe (Mesa 26.2.4, LLVM 23.1.1), CachyOS, GCC 16.2.1, CMake 4.4.3, default build type, full build with
BUILD_TESTING=ON. Each run used a clean environment (env -iwithHOME,PATH,VK_ICD_FILENAMESandGALLIUM_OVERRIDE_CPU_CAPS=avx).This PR (
b5a0c1ff7merged intomain44df21632, no conflicts):agc_driver_faulting_wave_invocationandagc_driver_gpu_buffer_format: pass, 3 runs out of 3.mainand its tests kept, both still pass, 3 runs out of 3. So on lavapipe the new test passes without the fix.The reason, from the code: lavapipe reports 8-wide subgroups (
minSubgroupSize=maxSubgroupSize= 8). Two lanes per invocation only happens when the host subgroup is 32 (SpirvEmitter.cpp:265,laneCountis 2 only whenhostSubgroupSize == 32u). The write mask itself is still enabled there, since the execz branch makes the program need ballots. But the failures the test checks (the execz loop that never ends, and the partner lane 37 stopping with lane 5) need two lanes per invocation. So the description's "onmainit fails" holds on 32-wide subgroups but not on lavapipe, and CI would stay green if the fix regressed.Wave32Subgroup.cpp:73skips with a reason when the subgroup does not fit. Something similar here, for example:would make lavapipe report a device-limited skip (
tools/check_skips.pyaccepts reasons that mention subgroups) instead of a pass. Only a suggestion; whether a 64-wide device should run it is your call.This may be useful for the mask rework you mention: on lavapipe the test passes even with the fix reverted, so it can't show whether a cheaper mask still handles the two-lane cases. That can only be checked on a 32-wide device, such as your RTX 3080 Laptop GPU.
Merged together with #6402 (on
main44df21632, no conflicts): full ctest: 2 of 1269 fail, 57 skipped (the same skips asmain). The two failures are not from either PR:agc_driver_mesh_index_cachesegfaults onmaintoo (and 5 runs out of 5 on the merge).agc_frame_dump_io(from #5800) also fails on plainmain, in 13 of 200 runs on an idle machine:closed pipe pixel write was accepted. Reading the test, its 128×128×4 = 65,536 pixel bytes are exactly Linux's default pipe buffer, so if the reader drains the 54-byte header before the pixel write starts, the empty pipe takes the whole write and it succeeds before the reader closes. Not measured beyond that.Apart from those, the failed and skipped lists match
main's full run.Not tested: NVIDIA, AMD, Intel, PPSA26344.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-16T05:10:08Z.
Barrier-program follow-up: #6689.
I reproduced later guest writes after an unmapped BDA read plus
s_barrieron otherwise unchanged main. Main plus your current headb5a0c1ff79eb52bd52fea0ba6d0434e072190b99still reproduces it in 5/5 runs on each of an RTX 5080 and AMD Radeon iGPU (Windows).bdaFaultMasksWritescurrently requiresbdaStopsInvocations, which excludes the barrier programs.Proposed follow-up reuses your per-lane mask, keeps the invocations at their barriers, and carries the checked BDA helper's fault result back to the correct lane half. All-fault and mixed valid/faulting lane tests pass 5/5 per GPU. The full Windows build and focused checks passed, but broader regression/static-analysis gates remain incomplete; the current checkpoint and remaining checks are recorded in #6689. This prototype is deferred while we pivot to PR maintenance.
Proposed ordering is #6416 first, then this compute follow-up. If you prefer to incorporate it here, the focused commit is available to take. No competing upstream PR is open.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T05:54:14Z.
While preparing the barrier follow-up, I checked the narrow-subgroup case raised in the review. The current
agc_driver_faulting_wave_invocationpasses on llvmpipe with subgroup size 8, and the review reports it also passes with the implementation reverted there; that device does not exercise the two-lane EXEC case the test is meant to cover. A device-limitation skip when subgroup size is not 32 would make that coverage status explicit. The follow-up mixed-lane control had the same assumption: on subgroup 8 it reported 63 mismatches. I have a local test-only guard for that mixed control on subgroup != 32; the two focused CTests then pass on llvmpipe (with the host CPU capability guard temporarily bypassed). The 32-lane mixed case still needs a suitable device, as your Windows NVIDIA/AMD runs provide.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T09:35:35Z.
I opened stacked follow-up #6751 for the test-only subgroup guard discussed here. The
agc_driver_faulting_wave_invocationcase now reports a device-limited skip unless the host subgroup is exactly 32 lanes, because narrower/wider subgroups do not exercise the two-lanes-per-invocation wave64 case. #6751 carries your current PR commits unchanged and depends on #6416; Linux target build and conventions passed locally. The focused CTest cannot reach Vulkan on my Xeon because it lacks the required CPU instruction sets.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T14:42:04Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One conflict inSpirvEmitter.cpp:mainadded!state.spannedWaveto thebdaStopsInvocationscondition while this PR adds thebdaFaultMasksWritescomputation after it — the merged version keepsmain's condition and layers your fault-masking computation.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
48482f629.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T12:51:57Z.
Thanks. Main has moved under this PR: since
bd6ed97f6d,bdaStopsInvocationsis false in spanned waves (a single-wave wave64 compute program on a 32-lane host with full subgroups, 80e3d90ed60/7a6cc717863). BecausebdaFaultMasksWritesrequiresbdaStopsInvocationsandStopBdaInvocationIfreturns early without it, a straight rebase turns the masking off for every single-wave program, including the test here, which I'd expect to fail on an NVIDIA or full-subgroup AMD device after the rebase. Since masking keeps invocations running, could it apply in spanned waves too (record the fault inStopBdaInvocationIfbefore the!bdaStopsInvocationsreturn, and gate masking on the fault kinds rather than on stopping), with the test covering a spanned single wave and a two-wave workgroup? Pipodi still sees spanned wave64 dispatches hang in PPSA26344, so a run of the rebased head there would tell us whether this is the remaining cause.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T14:21:59Z.
Correction to my earlier note: spanned waves are opt-in on
main(APS5_SPANNED_WAVE, VulkanDevice.cpp:1784), so by default this PR's test runs the two-lane path with masking on and passes, and it fails with masking forced off, so the rebase ontomainis fine as is. I pushed it to this branch (9c768176) and started a full CI run. The gap I described applies only withAPS5_SPANNED_WAVE=1: therebdaStopsInvocationsis false, masking is off, and the test fails with "lane 5 stored after its read faulted". Not a blocker for this PR; as a follow-up, could the masking also cover spanned waves (record the fault before the!bdaStopsInvocationsreturn) and the test run once withAPS5_SPANNED_WAVE=1? That may be what still hangs PPSA26344's spanned runs.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T02:19:09Z.
Review: COMMENTED
Apple GPU / MoltenVK run. Apple's subgroup size is exactly 32, the case
agc_driver_faulting_wave_invocationneeds (see #6751): red without the fix, green with it, and no other change.Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Head 9c768176f, PR diff applied cleanly. Driver: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0),
subgroup=32.Tested: the tree is
maina373e85e5+ mugurc's macOS series (ci/macos-series-2) + the PRs needed to build on macOS (#6667, #6668, #7524, #6969, and two files of #7332), not plainmain(it doesn't build on macOS yet). Base on that tree: 40^agcfailures, the same known failures in every run below unless noted.agc_driver_faulting_wave_invocationwith the PR: passes 3 of 3.lane 0 left the EXEC loop after 100 passes, expected 4 (the loop stops at 100).^agcsuite with the PR: 40 of 728 fail, the same 40 as the base.About the spanned-wave gap @oneandonlydean described: it can't occur on MoltenVK today. With
APS5_SPANNED_WAVE=1the driver logsspans two full 32-lane subgroups: 0, because MoltenVK doesn't give full compute subgroups, so wave64 always takes the two-lane path here and the masking stays on.GPUs tested: Apple M2 Max (MoltenVK 1.4.2)
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T23:49:32Z.
@oneandonlydean, thanks for doing the rebase and for sorting out the spanned-wave question. Yes, I'll take the spanned-wave masking as a follow-up PR once this one is in. The plan is what you describe: record the fault in
StopBdaInvocationIfbefore the!bdaStopsInvocationsreturn, gate the masking on the fault kinds rather than on stopping, and run the test once more withAPS5_SPANNED_WAVE=1, for a single spanned wave and for a two-wave workgroup. @jotitadev's run shows the gap can't happen on MoltenVK, so the follow-up is about NVIDIA and full-subgroup AMD.About Yōtei: our runs do use
APS5_SPANNED_WAVE=1, but they don't carry this PR's masking yet, because of the compile-time cost I mentioned earlier. So I can't tell yet whether this is what still hangs the spanned runs. I'll try it in a game run with the follow-up once the machine is free.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:49:15Z.
Review: APPROVED
Reviewed — approved
The merge with
mainis clean and builds. The focused tests pass with no new validation IDs, and the updated guarded-pointer host check fails without the production change. This machine's lavapipe cannot run the wave64 two-lane path or the spanned-wave path, so for those paths I rely on the NVIDIA runs that other people reported.What I ran
Head
19eddecba1143143bb4c5b750f51632a4cf2eef8,main9090972b7e91fd266819cbd77a8b058e177b5682, merged tree8d69bdea97d7ba1a41e27e654c4ef880fb16bf9c(--no-ff). Machine: Debian 13 VM, 2× Xeon Gold 6136, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19, subgroup 8).Results
git diff --checkcheck_conventions.pymainfailures (agc_driver_division, denormal-mode tests,unwrap_self,vector_constant_factor_tininess).agc_driver_runtime_formatted_storepassed on reruncheck_skips.py)main(script)agc_shader_memory8.7 s, every other test under 3.4 stests/execution/*.cppglob asagc_driver_faulting_wave_invocationNew test on lavapipe
Negative control
I restored the 8 production files from
mainand kept the PR's tests:ShaderDiskCache.hpp,SpirvBda.hpp,SpirvEmitterState.hpp,SpirvBdaFault.cpp,SpirvBdaRead.cpp,SpirvEmitter.cpp,SpirvFlowEmitter.cppandSpirvMemoryInstructions.cpp. Then I rebuilt the three affected test executables.agc_shader_memoryfails as it should:guarded pointer: a continuing guarded read must latch its first fault without overwriting the guard word or calling record_bda_fault.agc_driver_faulting_wave_invocationstill passes. That is expected on this device: with 8-wide subgroups,laneCountis 1 and no wave spans subgroups, so neither the two-lane path nor the spanned path is reached. This confirms with my own run what Dextroid17 and MarcZX10 reported for lavapipe. The red-without/green-with evidence for this test comes from jotitadev (MoltenVK, subgroup 32), from cookie42073-cmd (RTX 4070 SUPER, UHD 770) and from the author.agc_driver_guarded_null_pointerpasses in both arms on lavapipe.After restoring the merged files and rebuilding, all three tests pass again and
git status --porcelainis empty.Findings
Blocking
None.
Non-blocking
19eddecba1removes!state.spannedWavefrombdaStopsInvocations(core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp:331). It then enables write masking for spanned waves through(waveOperations || state.spannedWave)(SpirvEmitter.cpp:335). Spanned waves are on by default onmainfor devices with full 32-lane compute subgroups: they are disabled only byAPS5_NO_SPANNED_WAVE, inVulkanDevice.cpp:2098. So on NVIDIA this is now the main path that the new test exercises. This is in effect the spanned-wave follow-up that oneandonlydean asked for. Please update the "What" paragraph so reviewers know that spanned compute waves now continue with masked writes instead of being excluded. Pipodi's PPSA26344 report of a device loss with spanned waves plus masking was made on an earlier version, so a rerun with this head would be useful.docs/dev/debt/shader.md:47says an unlinked call "records theUnlinkedCallfault ... and stops the invocation, or continues after the call in programs whose faults do not stop invocations". With this PR,EmitUnlinkedCall(SpirvFlowEmitter.cpp:959) →StopBdaInvocationIf(SpirvBdaFault.cpp:132) no longer stops in masked programs. The invocation instead continues past the call with its later guest writes masked. A one-clause update of that entry would keep the debt file accurate.Not verified
StopBdaInvocationIfcaller that may now continue in a masked program guards its later accesses. The byte-load path is guarded inSpirvBdaRead.cpp:44-45. I read the runtime-buffer and overflow callers, and they look guarded or zero-valued, but I did not check all of them exhaustively.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T18:43:15Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: please confirm the invocation fault mask is correct for memory writes that happen inside emitted helper functions.
What I ran
Reviewed head
ab3e21c97c54ce34cff2611cc5dd33f3bb02fb3ausing the prepared diff and the pinnedrepo_read.pyreader. No build or tests were run by me; test results in the PR description are author reported.Results
Findings
Blocking
None verified.
Non-blocking
EmitUnlessInvocationFaultedapplies only to instructions emitted directly from the structured block. Please verify that writes performed by helper functions called from a later instruction are also suppressed after a lane faults. I did not trace all helper call paths, so this is a question for follow-up rather than a verified defect. The relevant dispatch is atcore/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp:837.Not verified
ShaderMemory.cppwas read through the pinned reader around the changed guarded-pointer checks; the rest of that large file was not read. All other changed source files listed as included in the manifest were read in targeted sections, along with the addedFaultingWaveInvocation.cpp.repo_read.pyreportsShaderMemory.cppas excluded from the review folder for size; the remaining changed files were included.files.jsonwas unavailable as a review-folder file, so exclusions are reported from the manifest and reader listing.description.mdare author reported.To get this to a good state
Nothing is required. Optional: confirm and, if needed, test that helper-function writes are masked after the faulting read.