perf(shader): probe 32-bit BDA stores and share the write fallback #1282
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1282"
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 Swastik-51 on 2026-10-07T21:55:47Z.
Depends on #1280 (which builds on #1265). Until they merge, this branch includes their commits; the last commit adds the 32-bit probe and fallback sharing.
32-bit BDA stores previously emitted both an aligned 4-byte store and four unaligned byte stores at every store site, each with a lookup and a page-write probe sequence. With note_bda_write inlined by drivers, programs like agc_driver_flat_store ballooned into dozens of lookups, hundreds of atomic CAS probes, and over 134K GEN instructions on Intel.
Probe the 4-byte span once with Write permission, storing directly when mapped and aligned. The unaligned and faulting fallback is shared across write sites via write_bda_dword_bytes, marked DontInline. note_bda_write is also marked DontInline.
Closes #1256 .
What
probe_bda_write_pointer(recordFaults = false,BdaAbi::Write) to probe the 4-byte span once. When mapped and 4-aligned,EmitBdaStoreemits a single 4-byte store directly and notes the write.write_bda_dword_bytes(with a coherent variant) marked withspv::FunctionControlDontInlineMaskto handle unaligned accesses, cross-range accesses, and faults without duplicating per-byte lookups at every store site.note_bda_write: Changedspv::FunctionControlMaskNonetospv::FunctionControlDontInlineMaskinDefineBdaNoteWriteso drivers do not inline its atomic CAS probes into dozens of call sites.verifyBdaWriteFallbackFunctionstoShaderMemory.cppto verify thatnote_bda_writeandwrite_bda_dword_byteshaveDontInlineMask,mainhas 0 inlineget_bda_write_pointercalls, coherence is preserved, and SPIR-V code size delta per site is kept small.Tested
python tools/check_conventions.py --base origin/mainpassed with 0 errors.verifyBdaWriteFallbackFunctionsinShaderMemory.cpp.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)Imported from boykopovar/AnyPS5. Originally posted by hashaam1217 on 2026-10-08T02:09:32Z.
On Linux this does not keep #1265's gain. Intel Iris Xe, Mesa 25.2.8 ANV, applied to
2cc5735d, cold caches:flat_store's first pipeline compiles to 54,375 GEN instructions, close to main's 55,929; #1265 and #1280 give about 26,000–28,000.The cause is the
DontInlinein e63cc309. Mesa inlines every function in Vulkan shaders and does not check that bit: ANV throughvk_spirv_to_nir→nir_inline_functions, and RADV through the same pass. Sowrite_bda_dword_bytesandnote_bda_writeare copied back into every store site, next to the new probe. The SPIR-V gets smaller while the compiled shader does not. Keeping the fallback in a loop, as #1265 does for the byte stores, is what kept it small here.Measurements and Mesa source links: https://github.com/boykopovar/AnyPS5/issues/1256#issuecomment-6050724960
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T03:53:16Z.
DontInlinedoesn't hold on Mesa: ANV and RADV inline every function invk_spirv_to_nir, sowrite_bda_dword_bytesandnote_bda_writeend up back at every store site and the secondflat_storepipeline runs past 7 GiB (hashaam1217's numbers above). Please dropDontInlineand keep the shared fallback in a loop, the way #1265 does for the byte stores, so the compiled shader stays small without relying on it.Then please add numbers for this commit alone on top of #1280: GEN instruction count and compile memory for
agc_driver_flat_store, plus a full ctest run.Imported from boykopovar/AnyPS5. Originally posted by Swastik-51 on 2026-10-08T07:59:24Z.
Updated commit
fe567b52with the requested changes:DontInlinefromnote_bda_write: Reverted back tospv::FunctionControlMaskNoneinDefineBdaNoteWrite.write_bda_dword_bytes: DroppedDefineBdaDwordWriteFunctionsand its unrolled stores.write_bda_bytes:EmitBdaStorenow routes unaligned and probe-rejected stores throughstoreBytes()(write_bda_bytes, in a loop) so that driver inlining does not duplicate byte store sequences across store sites.verifyBdaWriteFallbackFunctionsinShaderMemory.cppnow verifies that fallback byte stores route throughwrite_bda_bytesand keep access coherence with 1 store inside the loop.python tools/check_conventions.py --base origin/mainwith 0 errors.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T12:29:23Z.
agc_shader_memoryfails at fe567b52, both on its own (basec5e10184) and merged intomain1081602d:It is the new
verifyBdaWriteFallbackFunctions, in the non-coherent case:write_bda_byteshas 3OpStores withoutVolatile, and the check atShaderMemory.cpp:1450expects exactly one. The coherent case doesn't run, because the loop stops at the first case. Windows 11, MinGW-w64 GCC 15.2.0, Release; the test doesn't use the GPU.This PR has no CI checks yet, which is probably why it hasn't shown up. The rest of the suite is unchanged on a Radeon 860M (AMD numbers for the three PRs are in #1256).
Tested with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Swastik-51 on 2026-10-08T13:04:53Z.
Could you please run the Github CI please as i need maintainer approval to run it
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T13:14:48Z.
I can't approve workflow runs here; GitHub only lets maintainers do that for first-time contributors. You don't need CI for this one, though: the test doesn't touch the GPU, so it reproduces on any build with
ctest --test-dir build -R '^agc_shader_memory$' --output-on-failure. Once it passes locally, I can rerun the AMD measurements on the new head if that helps.Imported from boykopovar/AnyPS5. Originally posted by Swastik-51 on 2026-10-08T14:43:29Z.
Fixed the
agc_shader_memorytest issue in515df443.The test was counting the two function-local loop counter
OpStores as non-volatile stores becauselength > 3uwas part of the array-index expression. It now filterslength > 3ubefore counting, so only the physical buffer store is checked.python tools/check_conventions.py --base origin/mainpasses with 0 errors.I unfortunately can't run the full
ctestsuite or the requestedagc_driver_flat_storemeasurements locally because I don't currently have a C++ build toolchain or an Intel/Mesa ANV environment. In particular, I can't produce the requested GEN instruction count or peak compile-memory measurement.Could someone with the Intel/Mesa setup rerun the
agc_driver_flat_storebenchmark on515df443? If possible, I'd also appreciate a test-suite run on the updated head.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T14:52:14Z.
Ran it on
515df443merged intomain9f4bd71c: Radeon 860M (RDNA 3.5), Windows driver 32.0.13058.8001, Windows 11, MinGW-w64 GCC 15.2.0, Release.agc_shader_memorypasses.ctestwithANYPS5_REQUIRE_VULKAN=1 --repeat until-fail:3: 455/457. The two failures also fail onmainon this machine.agc_driver_vopc_compare_tableis the AMD driver bug in #825.agc_driver_shader_clockis flaky here (memtime: lane 0 went back from 1030876 to 1354, 11 of 60 runs onmain, 25 of 60 with this PR). The value wraps at 2^20, the 20-bit subgroup clock that #1383 handles only for RADV, while this GPU runs AMD's own driver. I'll follow that up separately.Cold AMD timings, measured as in #1256 (fresh executable name per run so the AMD driver cache misses,
ANYPS5_NO_SHADER_CACHE=1, median of 3, whole test):flat_storeglobal_store_addtidglobal_vcc_basemain9f4bd71cThe KiB column is the size of the AMD driver's pipeline cache file for the run. I can't produce the Intel GEN instruction count from here; that still needs someone with an Intel GPU.
Measured with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Swastik-51 on 2026-10-08T14:54:24Z.
Thanks! Great to see agc_shader_memory passing and the full suite results confirming the two failures are pre-existing on main.
The AMD numbers also look good, especially flat_store improving from 3.9s to 3.3s with 25 vs 28 VGPRs and the pipeline cache dropping from 128 KiB to 64 KiB.
That leaves only the Intel/Mesa ANV GEN instruction and compile-memory measurements requested in the review. I don't have access to that environment, so hopefully someone with Intel/Mesa can rerun the benchmark on 515df443.
Imported from boykopovar/AnyPS5. Originally posted by hashaam1217 on 2026-10-08T18:14:35Z.
Intel numbers for 515df443, the commit alone on top of #1280, as requested above. Intel Iris Xe (Alder Lake GT2), Mesa 25.2.8 ANV, Linux. Each variant was merged onto this PR's base,
c5e10184, because the head currently conflicts with main inSpirvBdaLookup.cppandSpirvEmitterState.hpp. Cold runs withANYPS5_NO_SHADER_CACHE=1 MESA_SHADER_CACHE_DISABLE=true APS5_PIPELINE_STATS=1, one test at a time in a cgroup limited to 7 GiB:agc_driver_flat_store(passes in all three, no spills):c5e10184)1dca7b4f)Other store-heavy tests. Both fail on this device for the subgroup reason fixed by #1185, which is not in this base; the compile numbers still apply:
global_store_addtidGEN instructionsglobal_vcc_baseGEN instructions, peak RSSTests at the same base:
agc_shader_memorypasses.flat_storeandglobal_vcc_base: the same 33 failures as #1280, which are also exactly main's failures at2cc5735d.So with
DontInlinegone and the fallback looping, this commit now makes the compiled shader smaller on Mesa ANV than #1280 alone, not larger as the first version did.Imported from boykopovar/AnyPS5. Originally posted by Swastik-51 on 2026-10-08T20:44:02Z.
Closing this PR for now because the branch has accumulated significant merge conflicts with the current
main, particularly aroundSpirvBdaLookup.cppandSpirvEmitterState.hpp.The implementation and measurements are still useful, and the latest results look good after the requested changes. Rather than resolving the conflicts on top of the current dependency stack, I'll preserve the work and rebase/cherry-pick the relevant changes onto the latest
mainonce the dependent PRs land, then open a clean follow-up PR.Thanks everyone for the reviews, testing, and especially the Intel/Mesa measurements.
Pull request closed