perf(shader): name a poisoned guarded SRT read in the fault buffer #6785
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6785"
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 milescoviello on 2026-10-16T11:46:43Z.
What
A
ReadConstof a guarded flattened-SRT slot (#759) loads the slot's flag and, when it is set, callsrecord_bda_faultwith the poison record's pc and address, then stops the invocation. Each of those calls is expensive for NVIDIA's compiler in a large module. Crimson Desert (PPSA25286) creates compute pipelines from modules of up to 1.9 million SPIR-V words, and every one I captured has guarded reads. The largest has 2,769 of them (679 guards), and its pipeline takes about 104 s and 5.65 GiB of host memory to create. That compile is where my 16 GiB runs of the title ended: at 643 s the process held 11,237 MiB of anonymous memory and 5,114 MiB of guest memory when the cap killed it.I tried other shapes of the same check on that module (capture replay,
vkCreateComputePipelinestime / peak RSS of the replay):main: callrecord_bda_fault(reason, address, bytes, pc)DontInlinehelper that loads the record itselfrecord_bda_faultwith an empty body (calls kept)DontInlinemainThe cost is the call sites, not the record's body or arguments. For the write itself, an
OpAtomicStoretakes 73.9 s / 3.12 GiB, the same as the plain store; anOpAtomicCompareExchangetakes 81.2 s / 3.62 GiB and anOpAtomicUMax82.2 s / 3.59 GiB. Folding the checks away when a capture has no poison would be cheapest, but #759 keeps poisoned and clean captures on one variant, specialization and pipeline, so this PR keeps that.How
BdaAbi::SrtGuardWord, after the written-page list) with a relaxed device-scopeOpAtomicStore, and stops as before. There is no call.ShaderResourceskeeps the flattened SRT of each stage with poisoned reads. When that word is set,BdaResources::CheckFaultreads the pc and address from it and throws the sameBDA access failed: address=… instruction=… bytes=4 stage=… reason=1.record_bda_fault's record, so modules cached before this change keep working.record_bda_faultin the same dispatch is reported first. Either way the dispatch throws an Unmapped fault for a poisoned read that ran, with that read's own pc and address. MarcZX100 pointed out that my first version used a plain store, which is a data race.Tested
Linux (Ubuntu 24.04, GCC 13.3, Release), RTX 4070 Ti, NVIDIA 595.99.
agc_shader_memory: the guarded-pointer case now also requires each guarded read's site to store to the guard word once and not callrecord_bda_fault(one guard for the branch program, three for the pointer chain). Withmain's emitter it fails 3 of 3:a guarded read calls record_bda_fault 1 times in main and stores its record to the fault buffer's guard word 0 times. With this change it passes 3 of 3.agc_driver_guarded_null_pointer(GPU), which checks the faults' pc, address and reason, and that skipped reads don't fault: passes 3 of 3 withANYPS5_NO_SHADER_CACHE=1. It now also dispatches two workgroups, one reading through a null pointer (pc 0x2c) and one through an unmapped one (pc 0x38). The reported fault must be exactly one of the two records, with its own pc and address; here it was the unmapped one in 10 of 10 runs.^agc_driver_|^agc_vertex_barrier|recompiler|shader_cache|request_serializer|spirv|^agc_shader|bda|journal, 501 tests,ANYPS5_ENABLE_SPIRV_TOOLS=ON), rebased ontomaineb901bcf4: 499 pass.agc_driver_store_over_untrackedfails the same way onmain(#6385 addresses it), and so doesagc_driver_graphicsin a case #5804 added (#6789 fixes it).Crimson Desert (PPSA25286, 01.000.568), 900 s limit, 16 GiB cap, scripted pad input. On
mainthe title stops 14 s in, on the refusal #6612 removes, so both runs use my test stack: #6612, #6613, #6706, #6708, #6748 and #6178. They differ only in this change.Anonymous memory peaked at 8,927 MiB during module C's compile. The later stop is a compute shader's DIM 2D
image_storeto a cube T#, which I'll take up separately. With the three modules captured from these runs, replayingvkCreateComputePipelinesalone (3 runs each, the replay's peak RSS):These runs and replays were made with the plain store of 38a04fd69. On the prototype of module C, the atomic store costs the same (73.9 s against 73 s).
Validated on Windows 11 with an AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001) by @LeandroLP23 (comment), in one build of
main6efb7261bwith this head and 13 other pull requests:agc_driver_graphics,agc_driver_guarded_null_pointer,agc_driver_store_over_untrackedandagc_shader_memorypass 3 runs of 3. 713 of 716agc_*tests pass; the 3 that fail fail the same way onmainthere.Not checked on a console.
Title capture
As the
perflabel asks, these are captures of one title and scene on one machine. MXGP26 (PPSA30839) ran from boot withAPS5_TRACE_SECONDS=0:60,ANYPS5_NO_SHADER_CACHE=1and a fresh run directory (cold AnyPS5 and NVIDIA caches), so the shaders compile inside the window. NVIDIA RTX 4070 Ti (595.99.02), Ubuntu 24.04, release libs, Xvfb display, no input.maindbac9fa15bwas captured five times: before the PR captures, after them, and three more times in a row after that. Each PR capture and the first twomaincaptures followed a rebuild of the release libraries; the last threemaincaptures did not, and they came out lower. The change ismainwith this PR merged on top as a local merge commit (a97e59c0c062). The time is the wall time of theShader.PrepareArtifactslices on theshader preparethreads in each trace.main1main2main3main4main5The five
maincaptures span 17.7% in total prepare time, and the 13 prepare threads run in parallel with the title, so a title capture can't resolve a recompiler change of a few percent. The replay measurement above is this change's measurement. This PR's capture is above all fivemaincaptures in total prepare time. With one capture of the change I can't tell that apart from noise, and the replay measurement above points the other way. I can repeat the capture if that would help.main1 trace, digest,main2 trace, digest,main3 trace, digest,main4 trace, digest,main5 trace, digest, this PR trace, digestVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -R '^agc_' -Vonmaine2a2914aa1and onmain+ this PR (c76299f217, a local merge).main: 815 of 815 pass; with this PR: 815 of 815 pass. Neither log reports the layer missing. VUIDs onmain:VUID-VkImageViewCreateInfo-usage-02275×6,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605×18,VUID-vkCmdCopyBuffer-srcBuffer-00118×2,VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285×2,VUID-vkCmdWaitEvents-srcStageMask-01158×2,VUID-vkSetEvent-event-09543×2; with this PR:VUID-VkImageViewCreateInfo-usage-02275×6,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605×18,VUID-vkCmdCopyBuffer-srcBuffer-00118×2,VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285×2,VUID-vkCmdWaitEvents-srcStageMask-01158×2,VUID-vkSetEvent-event-09543×2. None is new with this PR.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T11:47:53Z.
Review: CHANGES_REQUESTED
The new guard path can have multiple invocations in one dispatch store different stage/record values to the same
SrtGuardWord:EmitReadConstemits a plainOpStore, then only stops the current invocation. The description explicitly says the record is whichever stored last when a program does not stop invocations. Unordered non-atomic writes to one storage-buffer word are a Vulkan shader memory-model data race, so the winner is not defined by Vulkan. Please select a record with an atomic operation (for example, an atomic compare-exchange for first-writer-wins) or otherwise synchronize the writers, and add a regression that exercises multiple invocations faulting through distinct guard records.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T11:54:21Z.
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/execution/GuardedNullPointer.cppL120Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/execution/GuardedNullPointer.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/BdaResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/BdaAbi.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/BdaResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/BdaAbi.hppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppImported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T12:01:26Z.
Thanks, you're right: the plain stores race. 37d8a8843 writes the guard word with a relaxed device-scope
OpAtomicStore, so the reported record is one of the writers' whole records, whichever is last in the word's modification order.I measured the options on the 1,916,980-word module before choosing:
vkCreateComputePipelinesOpAtomicStoreOpAtomicCompareExchange(first writer wins)OpAtomicUMaxI kept the store because the host reports one poisoned read that ran either way, and which invocation writes first isn't ordered either. If you'd rather have first-writer-wins, I can switch to the compare-exchange.
For the regression,
agc_driver_guarded_null_pointernow dispatches two workgroups: one reads through a null pointer (pc 0x2c), the other through an unmapped one (pc 0x38). The reported fault must be exactly one of the two records with its own pc and address. It passes 3 of 3 (10 of 10 reported the unmapped one here). Withmainplus #6784 so that it builds, the 498-test area run has onlyagc_driver_graphics(the #5804 case noted in #6784) andagc_driver_store_over_untrackedfailing, both as onmain.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T12:03:24Z.
Review: APPROVED
The follow-up replaces the competing plain stores to
SrtGuardWordwith a device-scope relaxed atomic store, so one complete guard record wins modification order without introducing an inter-invocation data race. The added two-workgroup regression exercises different null and unmapped guards and requires exactly one corresponding record. I also checked that the host decodes the winning record using the encoded stage and flattened-SRT offset. The required checks pass; platform build/runtime jobs were skipped by path filters, so this approval is based on source review and the reported local regression run.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:33:15Z.
AMD on Windows: the tests this PR names pass on an RDNA 3.5 GPU.
Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release.
main6efb7261bwith this PR (a4fc2cfea) merged, together with #7296, #7446, #7377, #7445, #6708, #6748, #6706, #6613, #7449, #7391, #7489, #7484, #7514. They were built once, so the result is for the combination; each merge was clean.agc_driver_graphics,agc_driver_guarded_null_pointer,agc_driver_store_over_untracked,agc_shader_memory: pass, 3 runs of 3.agc_*test on the combined build: 713 of 716 pass. The 3 that fail,agc_driver_host_import_lifetime,agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gpl, fail the same way on unchangedmainhere, so none comes from these PRs.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T18:45:59Z.
Thanks @LeandroLP23 for the AMD run on Windows. I added it to the description.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T21:35:39Z.
The title capture the
perflabel asks for is now in the description, with both summary lines, the traces and the digests: MXGP26 from boot, a cold shader cache,maindbac9fa15bagainstmain+ this PR (a97e59c0c062). The fivemaincaptures span 17.7% in total shader prepare time, so the capture can't resolve this change, and the replay measurement in the description is still its measurement. This PR's capture is above all fivemaincaptures in total prepare time. With one capture of the change I can't tell that apart from noise, and the replay measurement above points the other way. I can repeat the capture if that would help.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T03:06:43Z.
Rebased onto
maina020d02560(nowc76299f217). #6373 renamed the fault record's last field fromreservedtootherFaults. That made one conflict, inBdaResources::CheckFault. The empty-record check now usesmain'sotherFaults == 0and still callscheckSrtGuard()before it returns.agc_shader_memory,agc_driver_graphics,agc_driver_guarded_null_pointerandagc_driver_store_over_untrackedpass, also under Khronos validation 1.4.363, with no VUIDs and no layer-missing lines.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T21:01:19Z.
Re-checked against current main: the guard word encoding (record never 0, stage in the top 8 bits, emit-time failure past 2^24), the host decode bounds, the untouched fault-buffer offsets, the relaxed atomic store, and that both new test checks fail on
main. The merge with current main is clean and the PR's hunks are unchanged; merged.