perf(agc): share BDA fault buffers in a per-device arena, with 32-byte slots for report-only programs #8963
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8963"
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 EagleBearerYS on 2026-10-21T07:38:19Z.
What
Every
BdaResourcesowns a host-visible fault buffer ofBdaAbi::FaultBufferBytes: 24,620 bytes, which the buffer pool rounds to 32 KiB. A program uses only part of it:record_bda_fault(image-table faults, unlinked calls, the loop guard) and the rect-list checkA buffer lives as long as its owner: while the resource cache keeps a fault-only build, and while an address-based draw is in flight, which the recorder holds until its batch completes.
In a Village-shaped bench (
agc_driver_village_draw_cost_tests --cost 20, lavapipe,APS5_PROFILE_DRAW=1, two runs), the fault buffers were 97.7% of the driver's "shader data" host-visible memory:Every one of the 22,000 BDA builds there could write only the report.
The change, in two commits:
minStorageBufferOffsetAlignment.ShaderResources::prepareFaultSlotrewrites only the fault descriptor of the owner's own sets).BdaResources::NoteFinished).APS5_NO_SHARED_FAULT_SLOTS=1restores one full buffer per owner (documented indocs/dev/ENVIRONMENT.md).SpirvFaultReportOnly(words, set, binding), cached per module hash, proves that a program reaches its fault buffer only throughOpAccessChainwith constant member 0 and a constant word below 8, used only in loads, stores and atomics.prepareAddressBindingsANDs the proof over every stage. For such an owner,CheckFaultreads only the report, andmarkWrittenPagesandcheckSrtGuardare skipped: the program can't write those words, and they aren't in the slot.BdaAbi.hppis unchanged and no shader offset moves, so the shader cache isn't affected. The BDA read execution tests have always bound asizeof(Abi::Fault)buffer to read programs.Fault reports kept exactly:
Measured, same bench and runs:
Resident Evil Village (PPSA01556): one pair on an NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42, Windows 11), clocks not held, both arms with
APS5_PROFILE_DRAW=1,APS5_LAZY_SHADER_PREPARE=1,APS5_NO_GPL=1andAPS5_HOST_IMPORT_MIB=6400; 6 min at the static menu, then Yes and 4 min in control. Host-visible "shader data", where the fault buffers are allocated: 27.6 → 18.8 MiB and 24.4 → 15.9 MiB at the menu (after 1 and 5 min), and 12.4 → 2.8 MiB in control. No fault lines in either arm. After the load the two arms took different host-import paths (27,062 imports made without this PR, 44,814 with it). That moves the buffer pool and host copies, not the fault buffers, so total host-visible memory isn't compared here. An earlier pair at the static menu, before the give-back and the 32-byte slots, showed ~20 MiB with and without the change.The last summary line of each arm, in the control scene (without this PR, then with it). Both arms ran with
APS5_PROFILE_DRAW=1, each line is a single present, and the lines carry no memory fields, so they record the scene the memory figures above come from, not a speed. Their frame times (4.0 s and 8.1 s) aren't comparable: both arms were profiled, and they took different host-import paths after the load (see above):Overlap: checked with
git merge-treeagainst every open PR on the same files, onmainb77bd5880.LastRecordIndiceswhere this PR declaresSpirvFaultReportOnly, inShaderResources.hpp;tests/BdaResources.cpp;requireGuestBuffers(and #7002synchronizeGuestBuffers) where this PR addsprepareFaultSlot, inShaderResources.cpp. Agreed order with #6498: #6498 first (comment). #6498 has merged, and918b1eeb5dmergesmainthat way: #6498's native-MSAA buffer guard runs beforeprepareFaultSlot()inBind(), and, with the moved logical ranges, beforePrepareDrawBindings' early return.mainkeeps both sides' includes inBdaResources.hpp, as agreed on #10150.mainitself.mainthemselves.BdaResources.hpp/.cpp. Whichever merges second takes those spare records from this arena.Tested
agc_driver_graphics(faultSlotTests, mock device):BdaResourceshold fewer than 64 slots, and the reclaim count is non-zero;ShaderResourcesreclaimed under pressure takes a new slot onBindand reports its own address, while the build that took its old slot reports its own;agc_driver_bda_device(lavapipe):cfe73029e2, on GitHub's runners, each fix hunk reverted on its own there with the tests unchanged, one run ofagc_driver_graphicsandagc_driver_bda_deviceeach, with the other tests built from the changed files. Each fails on Linux and on Windows with its line:agc_driver_bda_devicealso fails with "two report-only BdaResources did not take 32-byte slots of one fault chunk";agc_driver_graphicsfails (on Linux its_maps_fallbackrun too), plusagc_driver_bda_devicewhere noted; the other tests pass, and on Windowsagc_driver_bda_deviceskips without a Vulkan device. The green at the same head is thecfe73029e2run below.agc_shader_srt_read_patchingincluded) pass ×10, with the same 2 skips asmain.agc_driver_graphics,agc_driver_bda_deviceandagc_shader_srt_read_patchingpass ×10 on Linux. On Windows (MinGW),agc_driver_graphicsandagc_shader_srt_read_patchingpass ×10 andagc_driver_bda_deviceskips without a Vulkan device. The run's other tests, which it picked from the changed files, pass too: 32 run on Linux and 31 on Windows in all.main's code the new tests don't build, because they use the arena's API. The red lines above come from reverting each fix hunk instead.maina07e985c8.mainalso failedagc_driver_sgpr_pattern_fill_keysunder load; it passes here, and 10 of 10 alone.check_skips.pymatch.mainon RADV:agc_driver_guest_memory_lifetime(#7784),agc_driver_tessellation(#5444, a crash with Mesa 26.2 and later; theirs is 26.2.5) andagc_driver_image_array_window_past_layer_limit(the expectation #8969 fixes). Their runs onmainand withAPS5_NO_SHARED_FAULT_SLOTS=1weren't posted.check_conventions.pypasses, with no comment lines added.1c7d058c4f, a merge ofmain0db47b263d. The only conflict was two declarations added at the same place inShaderResources.hpp: this branch'sSpirvFaultReportOnlyandmain'sShaderStoresThroughAddresses, and both are kept. The run linked here before didn't run this PR's tests (its name list matched none of them); the run undercfe73029e2below covers this merge's code.cfe73029e2, a merge ofmain2b1648419a. The only conflict was intests/BdaResources.cpp, where this branch'sfaultSlotTestsand #8380'spartialHeapImportBudgetTestswere added at the same place, and both are kept. The PR's added and removed lines are unchanged. On GitHub's runners, 10 runs (run): on Linux, this PR's tests,agc_driver_graphics,agc_driver_bda_device,agc_shader_srt_read_patching,agc_device_fault,agc_bda_staging,agc_driver_bda_reads_shadowed_resultsand its_per_buildrun,agc_driver_image_table_vouch_queued_drawsandagc_driver_image_table_vouched_lookups, pass, 9 of 9, and so do the 32 other tests built from the changed files: 41 run, 41 pass, 0 skip, 0 fail. On Windows,agc_driver_graphics,agc_shader_srt_read_patchingandagc_device_faultpass and the 6 device tests skip without a Vulkan device: 40 run, 33 pass, 7 skip (those 6 andagc_driver_host_import_failure_handles), 0 fail. The libc and libkernel suites pass on both (122 and 204 tests on Linux, 149 and 216 on Windows), run withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners. The run linked here before didn't run this PR's tests, so it's replaced.mainagainst this PR (CONTRIBUTING's AGC rule), on GitHub's Linux runner (llvmpipe, LLVM 20.1.2; run), withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andctest -V. The tests are the existing ones that build onmaintoo,agc_driver_bda_reads_shadowed_resultsand its_per_buildrun,agc_device_fault,agc_bda_staging,agc_driver_image_table_vouch_queued_draws,agc_driver_image_table_vouched_lookupsandagc_shader_srt_read_patching, with the other tests built from the changed files, once on each tree: 39 run, 39 pass with the change and onmain. The loader insertedVK_LAYER_KHRONOS_validation7 times on each tree, neither log haswas not found but was requested, and both report onlyVUID-VkDeviceCreateInfo-pNext-pNext. This PR adds noVUID-message. The new cases inagc_driver_graphicsandagc_driver_bda_devicedon't build withmain's code, so this comparison doesn't cover them.08392c098f, a merge ofmainfacac6a4c5(run). Three conflicts, each resolved by keeping both sides:BdaResources.hpp's include block (#10150's<memory>and this PR's includes);ShaderResources.hpp, where imellag's #11142 removedMovedWordBuffernext to this PR'sFaultDescriptorandprepareFaultSlot(), so the merge keeps this PR's members without the removed ones; anddocs/dev/ENVIRONMENT.md, with this PR'sAPS5_NO_SHARED_FAULT_SLOTSrow andmain's newAPS5_NO_SINGLE_PASS_COLLECTtext. This PR's added and removed lines are the same, except#include <memory>, whichmainnow has. The 13 tests named above, with the tests for the files the merge changes, pass 10 runs in a row. Linux: 49 run, 49 pass, 0 skip, 0 fail. Windows: 48 run, 38 pass, 10 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (166 and 264). On Windows libc passes (194) and libkernel passes 283 of 286:exec_arguments,guest_timed_join_import_libkernel_sysandguest_timed_join_import_libkernel_webfail at their setup in the verify's Windows build (FileNotFoundErrorstarting the title, or copying the libraries they load), and pass inmain's own Windows job at1829def9bf(job). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.92f08cb9c2, a merge ofmaind4cb89300f(run). The one conflict wasdocs/dev/ENVIRONMENT.md, where Astronaut10's #11696 addsAPS5_NO_SHAPE_MEMOon the line where this PR addsAPS5_NO_SHARED_FAULT_SLOTS; the merge keeps both rows, in order. This PR's other changed lines are the same. The BDA, fault-buffer, heap-mirror, pipeline-store and draw-state tests of this PR's earlier runs ran 10 times with no failure (each runner builds its own set). Linux: 50 run, 50 pass, 0 skip, 0 fail. Windows: 49 run, 39 pass, 10 skip (the Vulkan device tests), 0 fail. Suites: libc and libkernel pass on Linux (171 and 289). On Windows libc passes (199), and in the job's second attempt libkernel passes 309 of 312:exec_arguments,guest_timed_join_import_libkernel_sysandguest_timed_join_import_libkernel_webfail at their setup in the verify's Windows build (FileNotFoundErrorstarting the title, or copying the libraries they load), withmain's code too, and pass inmain's own Windows job at1829def9bf(job). In the first attempt, libkernel'sguest_filesystemalso aborted, right after it creates its test junctions: itsRequire(read > 0)aftersceKernelOpen(".", O_DIRECTORY)failed while other suite tests removed their folders from the same directory, the Windows directory-listing race that dantdmdarealguy's #12139 fixes. This PR touches no libkernel or filesystem code, the rerun passed it, andmain04fefebe90passes it 20 runs in a row on both runners (run). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.918b1eeb5d, a merge ofmain1189ec3003, which brings Amoenus's #6498 (run, validation run).ShaderResources::Bind(), where #6498 addsrequireGuestBuffers()and this PR addsprepareFaultSlot(). The merge keeps both, the guard first.PrepareDrawBindingsmerged on its own: #6498'srequireGuestBuffers(moved)runs before the early return, and this PR'sprepareFaultSlot()after it.agc_driver_sample_multisample_target(#6498's cases), with the tests for the files the merge changes.APS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.VERIFY_VALIDATION=1on GitHub's Linux runner, llvmpipe (LLVM 20.1.2), Mesa 25.2.8),main1189ec3003against this head, the same tests:VK_LAYER_KHRONOS_validation14 times on each, and neither log haswas not found;VUID-VkDeviceCreateInfo-pNext-pNext, so the merge adds none.d958699e8b, a merge ofmain6a691f69ee, which brings Celegans12's #8105 (run, validation run).Graphics/src/Recorder.cpp, where #8105 addsDepthSurface.hppon the line where this PR addsBdaResources.hpp. Both are kept.BdaResources.hpp/.cpp,ShaderResources.hpp/.cpp,tests/BdaDevice.cpp,tests/BdaResources.cppanddocs/dev/ENVIRONMENT.md. InbuildComplete,main'sUploadFinish(usesBda, htileClear)sits next to this PR'sfaultReportOnlyconstructor calls, andRecorder::finishkeeps this PR'sBdaResources::NoteFinished.agc_driver_bda_device_testsandagc_driver_graphics_tests, the binaries this PR's test files build into, and every^agc_driver_bda_test.agc_driver_graphics_maps_fallbackandagc_heap_mirror_unwatched_importare registered only off Windows.APS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.VERIFY_VALIDATION=1on GitHub's Linux runner),main6a691f69eeagainst this head, the same tests:VK_LAYER_KHRONOS_validation7 times on each, and neither log haswas not found;VUID-VkDeviceCreateInfo-pNext-pNext, so the merge adds none.ctest -R '^(agc|shader)'1,084 passed, 75 skipped, 0 failed.38f1f885ed, oneandonlydean's merge ofmain88e804b0a7. The one conflict wasRecorder.cpp's include block: this PR'sBdaResources.hppinclude andmain'sReferenceStorage.hppinclude, both kept. This PR's diff overmainis unchanged. On GitHub's runners (run, on e03545223d, a merge of the same two commits with the same tree),agc_driver_pipeline_journaland the^agc_driver_bdaand^agc_bdatests ran 10 times with no failure. Linux: 10 run, 10 pass, 0 skip, 0 fail. Windows: 10 run, 2 pass, 8 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (210 and 310) and on Windows (237 and 331). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.972242f204, oneandonlydean's merge ofmaina4eca2a056. The one conflict was the variable table indocs/dev/ENVIRONMENT.md, where this PR'sAPS5_NO_SHARED_FAULT_SLOTSrow and Gonic0'sAPS5_NO_SHARED_GDSrow from #13159 were added at the same place; the merge keeps both, in alphabetical order. This PR's diff overmainis unchanged. On GitHub's runners (run, on e78abd6e7c, our merge of the same two commits with the same tree),agc_driver_pipeline_journaland the^agc_driver_bdaand^agc_bdatests ran 10 times with no failure. Linux: 10 run, 10 pass, 0 skip, 0 fail. Windows: 10 run, 2 pass, 8 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (235 and 319) and on Windows (262 and 340). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.Checklist
main6a691f69ee(merged ind958699e8b); 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-21T07:38:34Z.
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 clairtonmichel on 2026-10-21T08:02:31Z.
Tested on Fedora Linux (AMD Ryzen 7 9800X3D, RX 7900 XTX, Mesa/RADV).
Clean compile, and out of 875 tests in the AGC/Video suite, 872 passed successfully (99%). However, I caught 3 failures during this run that you might want to look into for this BDA/fault buffer draft:
Great work on the host memory reduction overall! Let me know if you need any logs re-run for these specific failures.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T08:04:40Z.
@clairtonmichel, thanks for running it on the RX 7900 XTX. Two of the three fail on RADV without this PR too:
agc_driver_guest_memory_lifetimefails onmainon RADV with "guest prefix unmap failed" (#7784).agc_driver_tessellationsegfaulted on RADV with Mesa 26.2 and later inside Mesa'snir_opt_varyings(#5444).agc_driver_image_array_window_past_layer_limithas no report for RADV that I know of.To tell whether any of them comes from this PR, could you post:
maina07e985c8f, built the same way;APS5_NO_SHARED_FAULT_SLOTS=1, which turns the shared fault buffers off?If a test fails the same way on
mainas on this PR's head, it isn't this PR. If it fails only on this PR's head with the shared buffers on, its output line is what we need.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T08:06:08Z.
@clairtonmichel, one update on the third:
agc_driver_image_array_window_past_layer_limitfails onmainon RADV too, in the test's expectation rather than in the driver, and #8969 fixes it. If your failing line reads "thread 7 component 0 is 107.000000/255, expected 147/255", it's that one, and it doesn't need theAPS5_NO_SHARED_FAULT_SLOTS=1run. Themainrun and your Mesa version still help for the other two.Imported from boykopovar/AnyPS5. Originally posted by clairtonmichel on 2026-10-21T08:16:05Z.
Thanks for the guidance! Here is the data from my setup (AMD Ryzen 7 9800X3D, RX 7900 XTX):
agc_driver_guest_memory_lifetimeandagc_driver_tessellationfail on RADV due to the known upstream issues (#7784 and #5444), and the image array window test behaves according to the known expectation mismatch (#8969).Everything matches expected upstream behavior on RADV, confirming your shared fault buffer implementation is clean and introduces no new regressions!