Repository navigation
Conversation
Every access by guest address calls a lookup that binary-searches the BDA range table: about 11 dependent steps over ~1200 ranges, 34 table loads per access. Since boykopovar#639 every buffer access goes through it. The lookups (read, probe, write and atomic) now keep the last range a search of the invocation resolved in four private variables: guest begin and end, device base and permissions. An access inside that range with the wanted permissions returns base + (address - begin) at once. Anything else (another range, a missing permission, an unmapped, zero-byte or wrapping access) takes the full search with every check and fault it records today, and a successful search refills the cache. The variables only hold what the table says, and no shader writes the table, so the result is the search's own answer. Astro Bot (PPSA21564), Crash Site, Windows 11, Core Ultra 9 285K, RTX 5080: GPU time of the draws 59.5 -> 35 ms per frame. APS5_NO_BDA_LOOKUP_CACHE=1 emits the lookups without the cache. The switch is part of the shader disk cache key. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
adriadam10
left a comment
There was a problem hiding this comment.
Thanks, the change looks correct. Checked on the PR merged onto main (Linux, RADV): agc_driver_bda_device, agc_driver_bda_span_reads and the global load/atomic/store tests pass with and without APS5_NO_BDA_LOOKUP_CACHE=1. Removing the accessEnd <= cacheEnd term from the hit (SpirvBdaLookup.cpp:60) makes agc_driver_bda_device fail, so the two new rows do pin the cached-range edges.
One thing is missing:
- The perf claim is measured on a different version of the change (it still skipped the table header checks) and on a local stack based on the
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.
|
Windows run, since the PR has no Intel results: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto
AI-assisted (Claude Code); I ran this on my machine. |
|
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.
|
* fix(shader): keep each BDA page-table walk to one inlined copy per read RADV inlines every SPIR-V function, DontInline included, so every get_bda_pointer call site becomes its own copy of the page-table search, and NIR's copy propagation of variables grows with each copy. The lookup now keeps its search bounds in phis and records its header and range faults from one call site each, picking the first failing check; a byte read and the byte fallback of a span read loop over one lookup instead of unrolling one per byte or dword. (cherry picked from commit 2d3a970) Ported from upstream PR boykopovar#3655 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(shader): decode a GPU-selected formatted load from a format table A formatted load whose V# is selected on the GPU emitted all 77 format cases in its shared function, and drivers that inline every function, like RADV, copied all of them into each call site. The load now reads the format's component count, widths, byte and bit offsets and type from a constant table and runs one path for its four components, with the existing conversion of each (type, width) pair selected at run time. Stores and loads through a prepared V# keep the format switch. (cherry picked from commit 369928d) Ported from upstream PR boykopovar#3656 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(shader): pin GPU-selected formatted loads for every buffer format agc_driver_gpu_buffer_format loads the V#'s records and word3 from memory and moves them into SGPRs with v_readfirstlane, so the recompiler sees a GPU-selected descriptor and the load goes through the format table. It checks buffer_load_format x/xy/xyz/xyzw and d16_xyzw on two lanes for formats 1-77, selectors 0/1/4-7 on 1-, 2- and 4-component formats, loads with a component past NUM_RECORDS, and that formats 0 and 78 stop the invocation before its stores. The expected values were captured on the format switch (2d3a970) and are identical with the table. (cherry picked from commit 6aaae03) Ported from upstream PR boykopovar#3656 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(shader): try the last resolved range first in BDA lookups Every access by guest address calls a lookup that binary-searches the BDA range table: about 11 dependent steps over ~1200 ranges, 34 table loads per access. Since boykopovar#639 every buffer access goes through it. The lookups (read, probe, write and atomic) now keep the last range a search of the invocation resolved in four private variables: guest begin and end, device base and permissions. An access inside that range with the wanted permissions returns base + (address - begin) at once. Anything else (another range, a missing permission, an unmapped, zero-byte or wrapping access) takes the full search with every check and fault it records today, and a successful search refills the cache. The variables only hold what the table says, and no shader writes the table, so the result is the search's own answer. On one title's busiest scene (Windows, discrete GPU), GPU time of the draws 59.5 -> 35 ms per frame. APS5_NO_BDA_LOOKUP_CACHE=1 emits the lookups without the cache. The switch is part of the shader disk cache key. (cherry picked from commit 443583a) Ported from upstream PR boykopovar#2837 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(shader): read adjacent BDA dword loads of one block through one span read A scalar load of several dwords (s_load_dwordx8) becomes one LoadAddressU32 per dword, and each took its own span read: a probe of the page table and a fallback that looks every byte up. Loads in one block with equal address operands and offsets within 16 bytes of the first now share its span read. Instructions that write memory end a group; the address operands are compared by content, since each load carries its own GetAddressResource and SelectU32 values. A title's main-menu pixel shader goes from 136 span reads to 34. AMD's Windows compiler inlines the read helpers at every call, and did not finish that shader before. (cherry picked from commit 4577633) Ported from upstream PR boykopovar#4931 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(shader): read GPU-selected V#s of s_buffer_load as SMEM does An s_buffer_load_dword* whose V# the recompiler reads at run time (a GPU-selected V#, for example one built with v_readfirstlane) went through the vector buffer descriptor checks. A nonzero TYPE in word 3 made it return 0 and record an invalid-descriptor fault, and the base was used with its two low bits, so a base off a dword boundary read shifted bytes. SMEM uses only the base, stride and num_records of the V#, and the two low bits of the base and of the final address are ignored (AMD RDNA2 ISA guide, 30 November 2020, section 7.1 Table 27 SBASE and section 7.2.1 "Reads using Buffer Constant"). The capture-time evaluator already follows both rules, and the bound path already drops the two low bits. For scalar buffer loads the runtime path now masks the base and skips the TYPE check; vector, formatted and atomic accesses keep it. agc_driver_scalar_buffer_gpu_descriptor runs s_buffer_load_dword and s_buffer_load_dwordx2 through such a V# with the base 0 to 3 bytes off a dword and TYPE 0 to 3, in wave32 and wave64. (cherry picked from commit 86fdb52) Ported from upstream PR boykopovar#5161 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(recompiler): read the buffer stride and presence at run time in compute modules (cherry picked from commit 573ba3b) Ported from upstream PR boykopovar#5353 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: EdouardSence <103503538+EdouardSence@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: DotDebian <quentin.waguet@hotmail.fr> Co-authored-by: poonasor <rickypoon89@icloud.com> Co-authored-by: Niko <nikobilger2000@gmail.com> Co-authored-by: Alex Collini <pipodi93@gmail.com>
CnRJay
left a comment
There was a problem hiding this comment.
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:
- Divergence. The cache is per invocation, but the hit test is a branch. In a wave where some lanes hit and others miss, the hardware runs both the early return and the full search, so the wave pays the search plus the hit check. Access patterns that are coherent per wave (most constant and vertex data) should gain. Scattered per-lane accesses (indirection tables, BVH or particle data across many ranges) can get slightly slower, and every miss also stores four values back. A scene that uses both is a better test than a single favourable one.
- Register pressure. The cache keeps three 64-bit values and one 32-bit value live across every lookup call site: about 7 VGPRs for the whole shader, since
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 main turns 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.
|
Closing: adriadam10's request from 2026-10-10 for before/after numbers on this head against current |
|
Numbers for a scene with scattered per-lane lookups, as asked above. Result: no measurable gain there. Setup: Windows 10, RTX 5080 (driver 616.64), MinGW Release. The head ported onto Tests: Scene: GTA V (PPSA04263), prologue, about 3 FPS. 89 % of GPU time is one compute dispatch per frame, program 0x25b254a00 (wave64, 8x8x1). Its main loop chases pointers per lane: each
The difference stays inside the spread between intervals (135–169 ms), and frame times did not change. That is two runs with the cache and one without. Why: A Nsight Graphics GPU trace of the same scene (on
Long scoreboard accounts for 77 % of stalls, and L2 hits 97 % of requests. So even a perfect cache would remove at most about 16 % here. Successive reads in the chain touch different ranges, so one cached range per invocation probably keeps getting replaced. This is the scattered case CnRJay described. Register cost (CnRJay's second point): offline compile of 0x25b254a00 on the RTX 5080, from
The program is already at the 255 limit, so the cached values go to local memory (+32 B per thread) rather than costing occupancy. I can push the ported branch if a reopen with these numbers is wanted. AI-assisted (Claude Code); I ran the measurements on my machine. |
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 Astro Bot (PPSA21564) #357: Astro Bot (PPSA21564) #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