perf(shader): try the last resolved range first in BDA lookups #2837
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2837"
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 DotDebian on 2026-10-10T16:21:52Z.
What
Every guest access by address calls a BDA lookup that binary-searches the range table: about 11 dependent steps over ~1200 ranges, 34 table loads per access. Since #639 every buffer access goes through it, and a draw's accesses usually stay inside a few ranges.
The emitted lookups (read, probe, write, atomic) now keep the last range a search of the invocation resolved, in four
Privatevariables (guest begin and end, device base, permissions), initialized to an empty range. An access inside that range with the wanted permissions returnsbase + (address - begin)without touching the table. Anything else (another range, a missing permission, an unmapped, zero-byte or wrapping access) takes the existing search with every check and fault it records today, and a successful search refills the cache. The variables only repeat what the table says, and no shader writes the table, so a hit returns what the search would have returned.APS5_NO_BDA_LOOKUP_CACHE=1emits the lookups as before. Being a recompilerAPS5_*switch, it is part of the shader disk cache key, and the source hash already separates the old and new emission, so the disk cache format version is unchanged.Tested
-DBUILD_TESTING=ON: ctest 709/709 passed (10 skipped as usual).agc_driver_bda_deviceruns the BDA execution tests on the GPU.BdaExecutiongains two reads after a cached hit: one starting in the cached range and ending in the next range (must not use the cached device address), one starting in the last range and ending past the table (must still fault as unmapped).-R "bda|global", 14 tests) also pass withAPS5_NO_BDA_LOOKUP_CACHE=1and no shader disk cache.astrobotbranch (where reads by address mostly hit VRAM snapshots), with an earlier version of this change that also skipped the table header checks on the search path; this version keeps every check. Numbers and context in discussion #357: https://github.com/boykopovar/AnyPS5/discussions/357Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:56:59Z.
Review: CHANGES_REQUESTED
Thanks, the change looks correct. Checked on the PR merged onto main (Linux, RADV):
agc_driver_bda_device,agc_driver_bda_span_readsand the global load/atomic/store tests pass with and withoutAPS5_NO_BDA_LOOKUP_CACHE=1. Removing theaccessEnd <= cacheEndterm from the hit (SpirvBdaLookup.cpp:60) makesagc_driver_bda_devicefail, so the two new rows do pin the cached-range edges.One thing is missing:
astrobotbranch. Please post before/after numbers for this exact head against currentmain(same title/scene, several runs, median), as perf PRs require in CONTRIBUTING. If the gain disappears once the header checks are kept, say so and we can decide whether the extra Private variables are worth it.Once the numbers are in this is ready to merge.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T02:10:50Z.
Windows run, since the PR has no Intel results: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto
maind31b57a4, RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).agc_driver_bda_device(which buildsBdaExecution.cpp) andagc_driver_bda_span_readspass on both GPUs, and nothing else in theagc_*suite changed.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T08:45:57Z.
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/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cppL4, L27-31, L53, L75-76, L94, L111Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:54:06Z.
Review: COMMENTED
Agree it's correct. On the "whether the extra Private variables are worth it" question, two GPU-side effects to look for in the numbers:
Privatevariables become registers after inlining. Small shaders won't notice. For the large compute programs other PRs mention (1M+ SPIR-V words), that can cost a wave of occupancy. The pipeline statistics thatLogPipelineStatisticsalready prints (VGPR count) for a few large shaders, before and after, would show whether that happens.If the gain on current
mainturns out to be mostly in draws with coherent access, limiting the cache to graphics stages, or to modules below some register count, would keep it where it helps.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:27:50Z.
Closing: adriadam10's request from 2026-10-10 for before/after numbers on this head against current
mainhas had no reply or push. CnRJay's review above lists what those numbers should cover: a scene with both wave-coherent and scattered per-lane lookups, and the register cost of the cached values. Reopen it with them when they're in.Pull request closed