perf(shader): cache BDA ranges in span reads #14260
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14260"
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 kiansaeidnia on 2026-11-01T05:05:31Z.
What
Draft: not ready for review yet. The change and the results below are real; the open items are listed at the end of this section.
Address-based (BDA) span reads walk the BDA table (
probe_bda_pointer) on every access. A program that runs as one wave pays every walk on its critical path, because nothing else is resident to hide the latency. In Ghost of Yotei's opening cinematic, the single-wave program 0x807b90a100 spends 94 % of its time in a triangle loop of six runtime-format buffer loads. Shader-clock instrumentation of that loop shows the table walk is about a third of each load (~2,950 of ~8,400 cycles); the data load itself is ~220 cycles.Each invocation now keeps the last four ranges its span reads found, as
(begin, bound, device base)entries.bda_anchor_range, with the same checks as the probe) and replaces the oldest entry with the range it finds.The entries are separate variables indexed only by constants. A first version indexed 16 slots by pc; its dynamically indexed array added 512 bytes of local memory per thread on NVIDIA, and that showed up as 270 MB more VRAM in the frame replay. The four-entry version adds 176 bytes and about 40 MB.
APS5_NO_BDA_RANGE_CACHE=1walks the table for every read, as before.Still to do before this is ready:
main-vs-PR summary from the same machine and scene. Ghost of Yotei only runs on the Celegans12yotei/bestfork, so the in-game numbers below come from that fork, not frommain. I still need a title or homebrew that runs onmainand exercises address-based span reads.BdaSpanReadResultTypeand the stop handling) for a different purpose, masking writes after faults. Whichever lands second needs a rebase.Overlap: the pr-overlap bot could not compare 54 open PRs that conflict with
main, so I reviewed them by hand.docs/dev/ENVIRONMENT.md(rows in the variable table).SpirvEmitterState.hpp, where this PR adds one field (bdaRangeCache). Their additions there are unrelated: fault masking (#6751, #7392), device image tables and samplers (#7642, #10193, #13928, #13929), the mesh fallback (#9356, #9387), spanned-wave subgroups (#8004), stencil export (#10351), MoltenVK image atomics (#10652), f16/f64 modes (#11351, #11483), and the ARM64 AOT consolidation (#5021).SpirvBdaRead.cpp(see above).Tested
Windows 11 Pro 10.0.26200, RTX 3080 Ti, NVIDIA 616.92.
New
agc_driver_bda_range_cachetest. Eight loads over five guest blocks: A, A again (a hit), then B, C and D (misses), E (evicts A), A (evicts B) and B. It runs on wave32, wave64 and split wave64, with and withoutglc, and also passes withAPS5_NO_BDA_RANGE_CACHE=1.Focused tests on this branch rebased onto
main6fe120d11b, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(ctest -R "bda_range_cache|bda_span_reads|bda_anchor_reads|bda_device|global_loads|gpu_buffer_format|buffer_format|descriptor_web_faults|buffer_load_store" -V):main: 15/15 passed.VUID-line or a missing-layer message.spirv-val --target-env vulkan1.3passes for the five largest captured Ghost of Yotei programs (on the earlier base).Frame replay (
agc_frame_replay, exact mode) of a captured cinematic frame, alternating runs with the cache off and on. These runs used the first, pc-indexed version; the four-entry version gives 0x807b90a100 122.5 ms in the same replay. Output buffers are byte-identical in every run.Shader-clock cycles of 0x807b90a100 and 0x807b925400 drop 34 % with the first version. With four entries, 1 of 42,846 reads walks the table.
In game, Ghost of Yotei (PPSA26344), on the
yotei/bestfork's runtime (see above). The change build also carried a spanned-ballot change that measured −1 to −6 % on these programs. Warm shader cache,tools/trace_digest.pyofaps5-summary.jsonl: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 CnRJay on 2026-11-01T19:42:48Z.
Review: COMMENTED
Marked draft, so this is early feedback. The idea is sound for a single-wave loop of dependent loads, where the table walk is on the critical path. The cost lands on every shader with address-based span reads.
1. Local memory per thread is added to every program with a span read. Four
(begin, bound, base)entries are 176 bytes per invocation, and the description's own first attempt showed what that costs: 270 MB more VRAM in the frame replay, and about 40 MB for the four-entry version. On NVIDIA that is also register or local-memory pressure for every wave, which lowers occupancy for programs that have many waves resident and do not need the cache. The win quoted is for a program that runs as one wave. Please apply the cache only where it can pay: a span read inside a loop, or a program whose launch is a single wave, and keep the table walk for the rest. Report the register or local-memory change for the largest captured programs from the replay.2. The hit rate is not shown. Eight loads over five blocks test correctness. What decides the value is how often a real shader's reads hit one of four ranges. Please add hit and miss counters under the existing
APS5_NO_BDA_RANGE_CACHEswitch and report the ratio for the Yotei program and for two more titles. A 4-entry cache with oldest-replacement thrashes on a loop that cycles through five buffers.3. Misses cost more than before. Each miss is a walk plus a replace, where before it was a walk. For a program with a low hit rate this is a regression. Show the replay time with the cache on and off for a program with scattered reads.
4. The numbers are on a different tree. The in-game table comes from the Celegans12 fork and the first version of the change, as the open items say. For the evidence to be usable, rerun it on exactly this commit, and on
mainfor at least one title that runs there.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T19:34:53Z.
Review: COMMENTED
Reviewed — comments
The review covered the changed implementation, its new execution test, and the documentation at head
8630fa906d675132ad2741f997c275edb36434f9; performance results and focused test runs are author-reported, and I did not run checks.What I ran
No commands or tests were run. I read
review/description.md,review/commits.md,review/manifest.json, andreview/diff.patch, plus the full text of all four changed files through the pinned reader. The supplied reader wasrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp:393caches the environment-variable decision in a function-localstatic. ChangingAPS5_NO_BDA_RANGE_CACHEafter the first shader compilation will not change behavior for later compilations in that process. This may be fine if runtime switches are intentionally process-start settings, but the new toggle's expected lifetime is not specified in the change description.maincomparison and exact-commit captures remain outstanding. Those results therefore do not establish the performance or memory impact of this exact head.Not verified
I did not execute tests or reproduce performance captures. The test and source files were read; no changed files were excluded according to
manifest.json.review/files.jsonwas not available through the reader, so its exclusion list could not be independently checked. I did not verify behavior on physical console hardware or other host platforms.To get this to a good state
Nothing is required. Optional: clarify whether the environment switch is process-start-only, and provide exact-head performance captures and a matched
maincomparison when available.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.