Repository navigation
fix(shader): keep each BDA page-table walk to one inlined copy per read - #3655
Conversation
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. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent pre-review on Linux (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
|
|
I checked the two things this fix could get wrong, and neither is wrong. The first is subtle enough to spell out. The fault reason is preserved, and the construction is what makes that work. Collapsing several failure checks into one recording site risks changing which reason is reported when more than one check fails — and the reason is guest-visible. A loop instead of an unrolled sequence is the real mechanism, and it is the right one on a driver that inlines everything. That structural test is what makes this reviewable at all. Counting the calls to Two things worth stating before this merges.
One question, on the runtime side of the trade. The loop form shrinks the module, which is what the wall needs, but it replaces straight-line code with phis and a per-iteration branch. Your measured cases do not show a regression — the zero-formatted-loads module at 4.1 s, and 35.8 s for the both-PRs run where the unrolled form ran out of memory — and on a driver that inlines everything, one inlined loop is inherently fewer copies than N unrolled ones, so this may already be settled. Worth confirming anyway: did the 4711-shader session or the four focused cases show the loop form slower anywhere hot, or is the count small enough that it cannot matter? If a long span ever is hot, that would be the argument for unrolling small counts and looping only over long spans. Written with AI assistance. |
|
Intel results, since this also fixes #2972 (the BDA tests timing out or failing to compile on Intel ANV). Arrow Lake iGPU, Mesa 26.1.8 ANV, Linux 7.2.8, GCC 15.3.0, Release. Every run is a cold compile (
Full
AI-assisted: yes |
|
One more data point, on NVIDIA this time: Ubuntu 24.04, GCC 13.3, RTX 4070 Ti, driver 580.142, Release with CI's configure flags. On With this PR (2d3a970) all of them pass in 0.2 to 3.6 s, along with AI-assisted: yes |
|
@Dextroid17 on the runtime question: not measured. Every number in this PR is compile time and compile memory. In the 300 s Yōtei session the title never presents a frame, so I have no frame time to compare. On What the loop changes at runtime: a span read that used to emit N unrolled page walks (one per dword, or one per byte for the unaligned fallback) now runs a loop of N iterations, with one walk and a phi per iteration. Reads of 4 bytes or less still take the single straight-line path. Only spans longer than that, and the byte fallback, loop. If someone has a title that draws frames through long BDA spans, a frame-time comparison with and without this PR would settle it. If it shows a cost, unrolling spans up to a small length and looping past it is a contained change in Agreed on sequencing: #3655 and #3656 should land together, and #2837 should be re-measured on top of them. Written by Claude (AI assistant) on a contributor's machine. |
|
I evaluated the independent single-fault-site change from issue #2972 and briefly submitted it as #3989, then closed that carry PR after reviewing the issue's note that the ready branch was offered for a maintainer to carry. Technically, the issue's change reduces fault-recording call sites and scratch pressure on older Intel Mesa; this PR reduces duplicated page-table walks. They have different goals but overlap in |
|
Windows/Blackwell cross-test: #3655 2d3a970 + #3656 369928d/6aaae039 applied cleanly on our007 runtime-image-table integration, public combined head bc46e2d: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-bda-compact-cross-test . Original author commits retained. Release, SPIRV-Tools OFF, RTX5070Ti/NVIDIA617.14, Vulkan required. Focused checks 6/6 pass,6.50s, no reported skips: agc_shader_memory0.36s, agc_driver_bda_device3.00s, agc_formatted_buffer_once0.17s, agc_driver_flat_loads0.48s, agc_driver_global_loads0.55s, agc_driver_gpu_buffer_format1.72s. This covers the emitted helper structure, native address/fault behavior and GPU-selected formats; not a full-suite result. Staging a separate007 run next. No game-output/FPS improvement claimed yet. AI-assisted: yes(Codex). |
|
This PR also cuts the lavapipe compile time behind the BDA execution tests that Linux CI reports as slower than 30 s. Measured on Windows 10 with lavapipe from Mesa 25.2.8 (the Mesa version in Ubuntu 24.04 updates; LLVM 21.1.7 in this build), a build with
All four pass with the PR merged. Mesa's disk cache is not active in this Windows build, so every dispatch compiles its pipeline, while on Linux CI a module that was already compiled can come from the cache; both columns here were measured the same way. The CI ranges are the slow-test annotations of runs 38140296210, 38168846650, 38169396667 and 38204420760. Measured with Claude Code. |
|
I rebased this onto current main after integrating #4759. The combined change keeps the in-place and fallback paths in separate selections, and retains the bounded loop for the unaligned dword fallback. The rebased Linux Release build of |
|
Heads-up before this is switched or rebased again: #5022 is merged and replaces the span-read shape from #4759. The two separate selections (in-place loads under the condition, fallback under its negation) hang NVIDIA 595.97 and newer (#4975; here also 610.57.04 on Linux, Xid 109, and a 3D title loses the device at level start), while the single selection from before #4759 hangs 591.86/590.48. On main the in-place loads now sit in
|
|
I merged I tested it together with #3656 on lavapipe 26.2.4 with SPIRV-Tools OFF. The NVIDIA 595+ runs, with and without SPIRV-Tools, are not done. Details: #3656 (comment) AI-assisted: yes (Claude). |
* 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>
|
The NVIDIA runs are done: on 2d3a970 merged onto main 30f9612, After #5022 the current head merges cleanly, to the same tree as 805be46, and keeps |
|
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.
|
Adopt EdouardSence's page-table lookup and bounded byte-read loops. Keep the original order of header, range and address fault checks while using phi search bounds and one inlined lookup per byte-read loop. Preserve the local written-page tracking fix on the game control branch. Source: boykopovar#3655 Donor commit: 2d3a970
What
On RADV, Ghost of Yōtei (PPSA26344) cannot create the pipeline of compute shader
0x8000289300:vkCreateComputePipelinestakes the process past 26 GB until it is OOM-killed. The title gets there onmaina11c8f7 with #757/#758 merged; onmainalone it stops earlier, at #2715. The diagnosis is in discussion #2884.RADV inlines every SPIR-V function,
DontInlineincluded. Everyget_bda_pointercall site therefore becomes its own copy of the page-table search, andnir_opt_copy_prop_vars(gdb, Mesa 26.2.4 with symbols) clones and rescans its copy set at each of these copies' loops, branches and fault stores. A byte read looked up once per byte, and the byte fallback of a span read did 4 dword reads of 4 lookups each.This PR keeps one inlined lookup per read, with the same results and faults:
DefineBdaLookupkeeps the search bounds in loop phis instead of twoFunctionvariables.length < 4andindex == 0) still return on their own.EmitBdaBytesloops over its bytes around oneEmitBdaByte.read_bda_spanloops over its 4 dwords around one dword read.Measured outside the title with a small Vulkan harness: the replayed module of
0x8000289300, RADV,MESA_SHADER_CACHE_DISABLE. To separate the cost of its formatted loads, those are cut after N:mainAll 128 still need #3656 (one formatted load path instead of 77 cases). With both, the module compiles in 35.8 s and 8.3 GB, and Yōtei runs a 300 s session, 4711 shaders compiled, without the OOM.
Tested
Linux (CachyOS), RX 9070 XT, RADV 26.2.4, GCC, Release.
import_auditfails because its source commit lookup does not work in a git worktree; it fails the same onmain.agc_shader_memorynow also checks thatget_bda_pointerrecords faults from at most 4 sites and has noOpVariable, and thatread_bda_dword_bytescalls the lookup once. Onmainit fails: one byte load per byte, 4 lookups.tools/check_conventions.pypasses.#2837 also changes
DefineBdaLookup(a cached last range inPrivatevariables) and will conflict with this. Its variable stores may also add to the RADV copy-propagation cost; I haven't measured that.Checklist
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)Tested and written by Claude (AI assistant) on a contributor's machine.
🤖 Generated with Claude Code