perf(shader): load runtime-format buffer components in one loop #21973
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21973"
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 JJenkx on 2026-11-17T00:10:39Z.
What
A formatted buffer load whose V# is read from GPU memory goes through
load_formatted_gpu_buffer_x<n>, which decodes the format at run time (genericFormattedLoad). That function emitted the per-component read and conversion four times, once per component, and each copy holds a dword read and a narrow-byte read through the BDA page table. RADV inlines every function regardless ofDontInline, so a shader with many such loads becomes very large before NIR optimizes it.This emits the per-component work once, inside a SPIR-V loop over the component index (
DontUnroll). The loop picks the component's bit width, guest address and whether it is needed by index, then reads and converts it as before. The set of conversions is the union over components; each conversion is selected by type and bit width, so the result is the same. In the Ghost of Yōtei captures below,load_formatted_gpu_buffer_x4has 3595 instructions onmainand 958 with this PR, and its calls go from 17 to 8; themaincapture was not run through the SPIRV-Tools optimizer and this PR's was, so part of that difference is the optimizer.Evidence
Ghost of Yōtei (PPSA26344) never presents a frame on main. Its main thread waits while RADV compiles one compute pipeline. A stack of the compile thread (symbols from the Arch debuginfod for Mesa 26.2.7) shows
nir_opt_copy_prop_varsunderradv_optimize_nirfor minutes. The pipeline makes 112 calls toload_formatted_gpu_buffer_x4and 16 to_x1.Captured with
APS5_DUMP_COMPUTE_PIPELINESand compiled alone withagc_compute_pipeline_replay --inspect,RADV_DEBUG=nocache,MESA_SHADER_CACHE_DISABLE=true:ANYPS5_ENABLE_SPIRV_TOOLS=OFF)spirv-optoffline (SPIRV-Tools v2025.5, the passes of the default pipeline inSpirvOptimizer.cpp; 212893 words)libvulkan_radeon.so) after 847 sANYPS5_ENABLE_SPIRV_TOOLS=ON)On main, the same capture with only the two
load_formatted_gpu_bufferbodies replaced by a return compiled in 6.6 s, and with every loop markedDontUnrollit still did not finish in 300 s. So the inlined formatted loads are what makes it slow, not unrolling.With this PR the title gets past that pipeline during a 300 s run, then reaches two more formatted-load pipelines (32.3 s and 147.3 s to compile). It still presents no frame within 300 s. The remaining cost is mostly the page-table lookups each component still makes; that is follow-up work, not part of this PR.
Tested
Linux 7.2, AMD Ryzen 9 7950X, AMD Radeon RX 6650 XT (RADV, Mesa 26.2.7), Release, on
main963137c40642+ this PR, unless noted.8332b52dbf80+ the loop commit,ctest -j 12 -R "shader|Shader|spirv|Spirv|formatted|Formatted|runtime_buffer|bda|Bda|agc_driver_runtime": 180 of 180 pass, includingagc_formatted_buffer_*andagc_driver_runtime_fetch_*.APS5_DUMP_SHADERS=1andAPS5_DUMP_GRAPHICS_SHADERS=1and replayed withagc_shader_replayfrom an empty shader cache, builds with identical CMake options: 6.4 s onmain963137c40642, 6.3 s with this PR.main963137c40642against this PR merged onto it (97a3da262189), same CMake options: frame p50 / p90 40.8 / 43.2 and 40.7 / 43.0 ms onmain, 41.2 / 43.7 and 40.8 / 44.2 ms with this PR. No speed change is claimed. The head adds only the shader disk cache format bump to these sources.Performance
Summary lines (
main, then this PR), from the first alternated pair:python3 tools/trace_digest.py:The traces (
aps5-trace-963137c40642-576299.json.gz,aps5-trace-97a3da262189-572609.json.gz) are available on request; I cannot attach files from where I work.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 MarcZX10 on 2026-11-18T02:30:55Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the focused source review found no verified defect.
What I ran
Reviewed head
fa51fe019f7cdc48c15b01e7a3e7a83429b53825. No commands or tests were run. Readreview/description.md,review/commits.md,review/manifest.json,review/diff.patch,ShaderDiskCache.hpp,SpirvRuntimeBuffer.cpp, andSpirvBufferFormat.cpp. The review folder’s file listing confirmed both changed files were included;files.jsonwas not available through the reader.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported benchmark results and test runs were not independently reproduced. No test sources or other callers were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T03:58:06Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed loop appears to preserve the prior per-component load and conversion behavior; I did not run checks, so the evidence does not justify approval.
What I ran
Reviewed head
072a24657e962f20158d9b877a89d558a81e1df7. I readdescription.md,commits.md,manifest.json,diff.patch, and the changed code around the modified load logic. No commands or tests were run. The manifest lists two changed files, both included; I read the changed cache version file and relevant portions of the runtime buffer file, not either file in full. No excluded changed files were listed in the manifest.files.jsonwas not available in the review folder.Results
Negative control
Not run; no test assertion or code-under-test change was available to perform a negative control.
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Sources
core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp— modifiedgenericFormattedLoadand neighboring formatted load/store helpers.core/shader/recompiler/ShaderDiskCache.hpp— shader disk cache format version bump.core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/BufferFormat.hpp— format enum used to assess the conversion set.Not verified
The full contents of
core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp, test/build results on this head, and the reported runtime and performance measurements were not independently verified. The description reports test and capture results; I did not run them.To get this to a good state
Nothing is required. Optional: run the relevant shader and formatted-buffer tests on this head and share the results if seeking approval.