fix(shader): record a BDA lookup's fault from one call site #5814
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5814"
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 MarcZX10 on 2026-10-14T12:03:13Z.
What
Follow up on #3655 and the compiler-pressure measurements in #2972. The BDA page-table lookup currently emits separate
record_bda_faultcall sites for its table checks, unmapped index, and range checks. Collapse those branches to one fault-recording exit per lookup. The first failing check, check order, guarded table reads, and recorded reason/address/size/instruction stay unchanged; non-recording probe lookups remain non-recording.This carries Miles Coviello's follow-up commit from his public branch, preserving the original author and commit metadata.
Measured
The original author compared this follow-up on Intel Arrow Lake with Mesa 26.1.8 ANV, after #3655:
flat_storemasked_global_storeflat_loads_x2_x3These are the author's cold-compile measurements, not a local run. The change is a measured compile-time reduction; it does not claim a new correctness fix for current Mesa versions.
A later Intel HD Graphics 520 / Mesa 25.2.8 ANV report on DOOM Shareware found the opposite runtime tradeoff on the title's presentation dispatch: the median rose from about 527 ms on
mainto about 874 ms with this change, and 5/6 runs with the change hit an i915 reset and device loss versus 0/6 onmain. The reporter's shader dump attributes this to increased register pressure and spills after replacing multiple fault exits with a merged exit. This PR is therefore not a general runtime performance improvement; the compile-time benefit comes with a measured regression on this Gen9 workload.Tested
agc_shader_memoryrequires exactly one lookup fault-recording call site.mainda4d5f2e6on Ubuntu 24.04 with GCC 13.3, Release, and an RTX 4070 Ti (NVIDIA 580.142).agc_shader_memorypassed 3/3, including the new assertion.agc_*tests passed;agc_host_import_sparse,agc_driver_sparse_dma_buf_import, andagc_driver_stencil_ref_exportwere skipped on that machine. The only failure,agc_driver_waterfall_images, also fails on unmodifiedmainda4d5f2e6with the sameVUID-StandaloneSpirv-DerivativeGroupQuadsKHR-10151validation error.git diff --checkpasses.Checklist
main; the original commit is a one-commit follow-up to merged #3655Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T12:10:31Z.
Thanks for carrying it. I built the commit cherry-picked onto
mainda4d5f2e6(it applies cleanly; the branch itself is 37 commits behind): Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti with NVIDIA 580.142.agc_shader_memorypasses 3 of 3, with the new assertion that a lookup has one fault-recording call site.agc_*tests pass;agc_host_import_sparse,agc_driver_sparse_dma_buf_importandagc_driver_stencil_ref_exportare skipped on this machine.agc_driver_waterfall_images, fails the same way onmainda4d5f2e6without this commit (VUID-StandaloneSpirv-DerivativeGroupQuadsKHR-10151: local size 32×1 with the quad derivative group), so it is not from this change.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T12:18:06Z.
Thanks for building the commit and checking the baseline. I added the
agc_shader_memory3/3 result, the 530/531 AGC suite count, skips, and the same failure on unmodifiedmainto the Tested section of the PR description.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T13:30:12Z.
odntht has since run this commit on the hardware #2972 is about, in https://github.com/boykopovar/AnyPS5/issues/5437#issuecomment-6169333279: an Intel HD Graphics 520 with Mesa 25.2.8 ANV, DOOM Shareware homebrew (PPSA99666) on
mainc7601b7.main: 8 of 8 runs fall back to the CPU scaler, 2 of them after an i915 preemption reset.main+ 934348f2: no reset in 4 runs, and 2 of them stay on GPU presentation. The title's presentation kernel takes about 472 ms per dispatch, against about 690 ms onmain, below i915's 640 ms preemption timeout.My results above are NVIDIA only, so this is the first run of the change on an Intel GPU.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T14:06:37Z.
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.cppL13-22, L40-45, L52-57, L126-127Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T17:56:48Z.
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.cppL13-22, L40-45, L52-57, L126-127Imported from boykopovar/AnyPS5. Originally posted by odntht on 2026-10-14T18:45:27Z.
Gen9 data for this commit, and it has a cost on the HD 520 that the compile numbers do not show.
Setup: Intel HD Graphics 520 (Skylake GT2, 0x1916), Mesa 25.2.8 ANV (Ubuntu 24.04 container), Debian 13 host, kernel 6.12 (i915,
preempt_timeout_ms640), Weston headless with the GL renderer plus Xwayland.main5adefa6f8againstmain+abfc62077(merged locally, no conflict), Release,BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF.Cold compile, median of 3 runs, Mesa cache emptied before every run,
ANYPS5_NO_SHADER_CACHE=1,ANYPS5_GPU="HD Graphics 520":c7601b7(before #3655, 1 run)mainmain+ this PRagc_driver_flat_storeagc_driver_masked_global_storeagc_driver_flat_loads_x2_x3agc_shader_memorypasses on both, including the new assertion. So the compile gain on Gen9 matches the Arrow Lake numbers above.Runtime is the other way. DOOM Shareware homebrew (PPSA99666 v1.1.1, relinked with
--to-intel), the case from #5437. 6 runs of each build, alternated main / PR, warm Mesa cache,APS5_TRACE_GPU=1. The duration is fromexecute serial=3to itsWAIT_REG_MEM, which is the title's presentation kernel (0x202c81800):mainmain+ this PRGPU HANG(Resetting rcs0 for preemption time out)vkWaitForFences present: Vulkan result -45 earlier back-to-back runs of each gave the same split (0 of 5 against 4 of 5 resets).
So on this GPU the single fault-recording exit makes that dispatch about 66% slower and pushes it past the 640 ms preemption timeout. On
mainit stays below it and the title only falls back to the CPU scaler. My guess is that the merged exit costs more at run time than the separate call sites did on Gen9, but I have not checked the generated code. I can dump the SPIR-V for0x202c81800from both builds if that helps.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by odntht on 2026-10-14T18:51:13Z.
Follow-up with the shader dump I offered above. It points at register pressure in the Intel backend, not at the SPIR-V size.
Same machine and builds. The title creates one compute pipeline, captured with
APS5_DUMP_COMPUTE_PIPELINESandANYPS5_NO_SHADER_CACHE=1. ANV statistics come fromINTEL_DEBUG=cswith an empty Mesa cache, one run each:mainmain+ this PROpFunctionCallOpReturnValueOpPhiThe module grows by under 1%. The single exit trades 9 call sites and 20 returns for 30 more phis. After NIR the backend needs 52 more registers, emits 17% more instructions and about 45% more spills and fills. On Gen9 those go to scratch memory, which fits the dispatch going from ~527 ms to ~874 ms. Fewer sends with more spills also fits the faster compile in the table above, with a slower result.
I have the two
capture.aps5cpfiles and the fullINTEL_DEBUG=csoutput for both builds, and can attach them if useful.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T02:06:55Z.
Thanks for the follow-up shader dump. The Gen9 run changes the tradeoff: the one-exit form cuts cold compile time in the cited tests, but on this real dispatch it increases latency from about 527 ms to 874 ms, raises spills/fills and register count, and crosses the reported 640 ms preemption threshold. I have updated the PR description to state the author-reported compile-time gain only; this should not be treated as a general performance improvement. Would maintainers prefer to close this follow-up or consider a separately gated/reworked form? I will leave the implementation unchanged pending that direction.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:08:00Z.
Closing: the PR's own measurements show a runtime regression that outweighs the compile-time gain.
mainto ~874 ms with this change, and 5 of 6 runs hit an i915 preemption reset (Resetting rcs0 for preemption time out,vkWaitForFencesresult -4) against 0 of 6 onmain.OpPhi; the backend then needs 52 more registers, emits 17% more instructions and ~45% more spills/fills.flat_store139.6 s → 108.7 s on HD 520, 65 s → 51 s on Arrow Lake) but it only affects the cold compile of those tests, and a device loss at run time is not a trade we can take for it.You are welcome to reopen with a variant that keeps the compile-time gain without raising register pressure on Gen9 (for example a lookup that avoids the extra phis), with the HD 520 dispatch time and reset counts in the description.
Pull request closed