fix(shader): keep each BDA page-table walk to one inlined copy per read #3655
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3655"
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 EdouardSence on 2026-10-11T14:54:58Z.
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 onmaina11c8f7fwith #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
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T15:19:35Z.
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,
BUILD_TESTING=ON.tools/check_conventions.py --base origin/mainpasses.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T15:23:35Z.
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.
failFirstiterates its checks in reverse and folds each intoreasonwithOpSelect, so the last write wins — and because the iteration is reversed, that last write is the first check in the original order. The earliest failing check's reason therefore survives exactly as before, while the module's lookup records its fault from at most fourrecord_bda_faultcall sites — which is what the test'slookupFaults <= 4pins. The!recordFaultspath returning zero, and the two guards that still return on their own, keep their original behaviour.A loop instead of an unrolled sequence is the real mechanism, and it is the right one on a driver that inlines everything.
EmitBdaBytesemitted the bytes as straight-line code, so every byte carried its own copy of the page-table search andnir_opt_copy_prop_varspaid for each one.EmitBdaByteLoopputs the phis and theOpLoopMergein, which leaves the search as one code copy however many bytes are read. The test pins that structurally instead of by timing:readerLoadsfrom4uto1u,lookupFaults <= 4,lookupVariables == 0,readerLookups == 1.That structural test is what makes this reviewable at all. Counting the calls to
get_bda_pointerandrecord_bda_faultin the emitted SPIR-V is deterministic on the host — no GPU, no Mesa version, no timing — so "onmainit fails" is a real RED rather than a flake, and it keeps failing if the unrolled emission ever comes back. Worth as much as the fix.Two things worth stating before this merges.
DefineBdaLookup, and its cached-rangePrivatevariables are exactly what a copy-set rescan clones — which you say you have not measured. Landing this first and re-measuring with #2837 keeps the improvement attributable; rebasing #2837 onto a design already chosen for copy-propagation cost may be what makes its own cost visible.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.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T17:04:25Z.
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 (
ANYPS5_NO_SHADER_CACHE=1,MESA_SHADER_CACHE_DISABLE=true), 3 runs each (1 for the timeout):agc_driver_flat_storeagc_driver_masked_global_storeagc_driver_flat_loads_x2_x3maina11c8f7f2d3a970dFull
cteston Intel with this PR: 830/834. The four failures (emulated_color_compare#3526,gated_dispatch_captureand_short_timeout#3345,vop1_float_unary#2114) fail the same way onmain.flat_storestill takes 65 s on a cold compile here, over the 30 s test limit. Recording the lookup's fault from one site instead of four (on top of this PR, guarding the rest of the lookup with selections and passing the reason through phis, still with no function variables) brings it to 51 s and roughly halves the spills ANV reports for its compute pipeline (593 → 275 spills, 1516 → 802 fills), andmasked_global_storeto 3.8 s. I'll open that as a follow-up once this is merged.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T17:25:45Z.
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
maina11c8f7fthe BDA read tests hang the GPU there the way #3291 describes (and closed #3087 did on 591.86).agc_driver_flat_loads,_x2_x3and_x4,agc_driver_global_loads,_x2_x3and_x4, andagc_driver_flat_apertures_2and_4printrecorded batch still running on the GPU after 10 sand abort after about 65 s withguest allocation ... is still pinned by GPU work or an import (waited 60000 ms for the lease).agc_driver_pixel_interlockfails withvkDeviceWaitIdle: Vulkan result -4.With this PR (
2d3a970d) all of them pass in 0.2 to 3.6 s, along withagc_driver_flat_apertures_1,_3and_5. So this likely fixes #3291 as well, at least on this driver.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-11T19:22:30Z.
@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
mainthe same session dies in pipeline creation, so there is no baseline to compare against either.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
read_bda_span. I'd rather add it with a measurement than without one.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.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T20:48:09Z.
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
SpirvBdaLookup.cpp,SpirvBdaFault.cpp, and shader memory tests, so merge order may require a rebase. The issue includes the contributor's Intel and NVIDIA test results; my local Linux build did not complete.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T04:16:32Z.
Windows/Blackwell cross-test: #3655
2d3a970d+ #3656 369928dc/6aaae039 applied cleanly on our007 runtime-image-table integration, public combined head bc46e2d6f: 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).
Imported from boykopovar/AnyPS5. Originally posted by rebelittle on 2026-10-12T05:23:18Z.
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
ANYPS5_ENABLE_SPIRV_TOOLS=ONas on Linux CI, andMESA_SHADER_CACHE_DISABLE=true, onmaine013f8c9cwithout and with this PR (2d3a970da) merged:mainmainagc_driver_bda_span_readsagc_driver_masked_global_storeagc_driver_global_vcc_baseagc_driver_flat_storeAll 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.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T05:02:26Z.
Needs a rebase: #4759 is merged and this now conflicts with it in
core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp. The full build of2d3a970dawas green before that merge, so it goes in on a green build of the rebased head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T08:31:44Z.
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
libSceAgcDriversucceeds;agc_shader_memorypasses (1/1, 0.34 s), andtools/check_conventions.py --base upstream/mainpasses. I pushed the rebased commit to my branchcodex/rebase-bda-compact-3655because the original head branch is in your fork and is not writable from this account. Please switch the PR head toMarcZX100:codex/rebase-bda-compact-3655when convenient.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T08:55:10Z.
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
load_bda_span, a DontInline function with no calls, andread_bda_spanis one selection between calling it and the byte fallback.MarcZX100:codex/rebase-bda-compact-3655(8f57bc736) keeps the separate selections and conflicts with main inSpirvBdaRead.cpp. Please rebase onto #5022 keeping its shape (the "BDA read functions" check inagc_shader_memorypins it), and runagc_driver_scalar_wide_loads,agc_driver_flat_apertures_0,agc_driver_bda_span_readsandagc_driver_pixel_interlockon an NVIDIA 595+ driver, with and without SPIRV-Tools.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T21:34:28Z.
I merged
blawesom:rebase/3656's #3655 commit (805be46cf) onto main0aa4cb1c2, which includes #5022. The merge is clean, and it leavesload_bda_spanand theread_bda_spanselection as #5022 has them.I tested it together with #3656 on lavapipe 26.2.4 with SPIRV-Tools OFF.
agc_shader_memory(the "BDA read functions" check) passes, and so do the four tests you named.The NVIDIA 595+ runs, with and without SPIRV-Tools, are not done. Details: https://github.com/boykopovar/AnyPS5/pull/3656#issuecomment-6155680022
AI-assisted: yes (Claude).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T04:20:30Z.
The NVIDIA runs are done: on
2d3a970damerged onto main30f961266,agc_shader_memory("BDA read functions"),agc_driver_bda_span_reads,agc_driver_pixel_interlock,agc_driver_scalar_wide_loadsandagc_driver_flat_apertures_0pass twice each with SPIRV-Tools ON and OFF, with no hang or Xid. RTX 4090, NVIDIA 610.57.04, Linux, Release.After #5022 the current head merges cleanly, to the same tree as 805be46cf, and keeps
load_bda_spanand theread_bda_spanselection as they are on main. So no rebase is needed; keep this head and leave outcodex/rebase-bda-compact-3655, which keeps the two selections.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T09:06: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/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL3095-3096, L3120, L3129core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cppL207-223, L225-226