perf(shader): record a BDA fault with one atomic claim and branch-free stores #20870
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20870"
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 Ketz7 on 2026-11-15T17:15:00Z.
What
record_bda_faultis called at every guest-memory access that can fault. It is markedDontInline, but AMD's Windows compiler (LLPC) inlines it anyway: removing the flag from a captured module changes nothing (75.8 s against 76.7 s). In vkQuake's ray-traced shadow compute shader (PPSA99010, program0x20c60f400) it ends up about 1,540 times in the inlined module, from 326 call sites, many of them inside other inlined helpers.otherFaultsinside a branch, a compare-exchange lock onstate, six stores inside a second branch, and a release atomic store ofReady. That pipeline takes 75–85 s to create on an RX 7900 XT, well past any title's GPU wait, so vkQuake shows no frame on a cold cache.claimword in place ofotherFaults, plusdiscardandreservedwords (32 → 40 bytes):claimsets bit 0 (claimed) and, unless the reason isUnaligned, bit 1 (another fault). The caller that finds bit 0 clear in the old value wins.Readygo to the record. Every other caller writes the same values todiscardinstead, through anOpSelected index, so the function has no branches.stateis written only by the winner, so no plain store races an atomic. The losers' stores todiscardrace only with each other, and nothing reads that word.BdaResources::checkFaultreads the other-fault flag fromclaimthroughBdaAbi::OtherFaults, and checksclaimwhere it checkedotherFaults.OtherFaultsis added to the shader-cache reviewed names: it only reads a record on the host.SpirvFaultReportOnlyaccepts an access-chain index that is anOpSelectof two constants in the record. Without this, every shader would lose its report-only fault slot.BdaExecutionandBdaResourcesread the flag throughOtherFaults, andShaderMemory's "fault recorded outsiderecord_bda_fault" check counts the claim OR.checkFaultline changed here. Whichever merges second keeps both lines.StopBdaInvocationIfin the same file but not the recorder.Tested
How the recorder was found, on SPIR-V captured from vkQuake with
APS5_DUMP_COMPUTE_PIPELINESand edited by hand. Each variant was timed withagc_compute_pipeline_replay, AMD's driver cache moved aside before every compile:record_bda_faultout took the pipeline from 76.7 s to 28.4 s. Every load and store stayed in the module.otherFaultsas a separate atomic OR took 55.2–56.3 s against 47.7–50.0 s without it.Readystore: 75.2 s;This branch (
4003dfc383) againstmain(03dc6b3020), on modules captured from vkQuake built from each:record_bda_fault: 39 → 37 instructions, 3 → 1 atomics.mainand the other 13 helpers are instruction-for-instruction identical, and both passspirv-val.pipeline_create, two runs each in alternating order, driver cache moved aside each time:main77.9 s and 91.7 s, this branch 56.0 s and 59.9 s (about 32% less).Vulkan tests with
ANYPS5_REQUIRE_VULKAN=1, every test fromagc_driver_bda_device_tests,agc_shader_memory_tests,agc_driver_graphics_tests,agc_rect_list_position_invariant_tests,agc_spirv_lds_atomic_lock_testsandagc_bda_atomics_tests:BdaExecution.tools/check_conventions.pypasses.tools/pr_overlap.py --branch: #12840 is the only line overlap, described above. The PRs it could not compare are the descriptor-heap stack (#9508, #7642, #10193, #13928, #13929), which carries merges ofmain, plus #7392 and older PRs that only share test files.Performance (Performance report form): AMD Radeon RX 7900 XT, AMD proprietary driver 26.10.1 (LLPC), Windows 11 Pro 26H2 (build 26300), Ryzen 9 7900X.
r_rtshadows 1), AMD's driver cache moved aside,APS5_PROFILE_DRAW=1. The driver's own line for the ray-traced shadow compute pipeline (program0x20c60f400):mainb7aeb6f406:[dispatch] created a pipeline for 152566 SPIR-V words in 83856 ms4003dfc383:[dispatch] created a pipeline for 152602 SPIR-V words in 56888 msAPS5_TRACE_SECONDS=10:20and no otherAPS5_TRACE_*orAPS5_PROFILE_*switch. Frame p50/p90/p99/max is 16.684/16.902/16.994/17.155 ms onmainand 16.686/16.881/16.979/17.103 ms here, 1,199 presents each (vsync at 60 Hz). Traces attached.main(eef73731fc):This PR (
4003dfc383):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)