perf(shader): read the slow paths of BDA dword and span reads in loops #4976
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4976"
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 poonasor on 2026-10-13T07:01:49Z.
What
Follow-up to #4931 (see my correction there): the other half of what a commercial title needs to get past the first main-menu frame on AMD's Windows driver.
AMD's compiler inlines the BDA read helpers at every call site (
DontInlineis not honoured), so the size of a helper body is paid once per read site. Two bodies are unrolled today:read_bda_dword_bytes*loads the four bytes of a dword with four copies of the byte lookup and load.read_bda_span*(the span is not mapped as one aligned piece) callsread_bda_dword_bytes*from four sites, one per dword.Both become one loop over a function-local index: the byte read shifts each loaded byte into the result, the span fallback inserts each dword with
OpVectorInsertDynamicand still stops the invocation when a dword read reports a stop. The in-place path of the span read (f1b2e605e) is unchanged. Values, fault records and the order of reads are the same; only the shape of the two helper bodies changes.Measured with the title on an RX 6700 XT (Adrenalin 25.10, amdvlk64),
main7e181fcc3plus the title's other fixes from my fork:[gpu] pipeline link took 140101 ms.I have not measured this change without #4931.
Tested
Windows 11, MinGW-w64 GCC 15.2, AMD RX 6700 XT.
agc_shader_memory, "BDA read functions": the byte read function must contain one byte load (four onmain), and the span read must call the byte read from one site (four onmain). WithSpirvBdaRead.cppfrommainthe test fails with "the looped byte load does not keep the access's coherence"; with the change it passes.ctest -R "^agc_shader|^shader|agc_graphics|agc_driver_bda": 16 of 16 pass (on my fork branch, which is7e181fcc3plus this and other commits).python tools/check_conventions.py --base origin/mainpasses.c2565f014) was not built; the cherry-pick was clean.Not tested: NVIDIA, Intel, Linux, macOS; whether other drivers gain or lose compile time or run time from the loops.
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)ShaderMemory.cpp's "BDA read functions" test, so the second to merge needs a rebase)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-13T08:29:01Z.
Independent build/test of the standalone PR head
a4a0f6cda570661c76159bad4df6e1da2239d95con Linux, without the title integration or #4931.The set is
agc_shader_memory,agc_driver_bda_device,agc_driver_bda_span_reads,agc_driver_pixel_interlock, andagc_driver_flat_apertures_0through_13. Serial ctest, 30 s per-test bound, no skips or timeouts. The two device-loss tests from #4975 pass on this NVIDIA/Linux configuration; that does not establish a fix on the failing Windows drivers, and I did not run a matched-parent comparison here.Each leg restricts
VK_DRIVER_FILESto one ICD and setsANYPS5_GPU,ANYPS5_REQUIRE_VULKAN=1, andANYPS5_NO_SHADER_CACHE=1. Verbose native logs identify the intended device. The BDA-device helper therefore cannot silently select NVIDIA during the RADV/lavapipe legs.Ubuntu 24.04, Linux 7.0, Ryzen 9 9950X, GCC 13.3, Release/Ninja,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON, bundled dependencies. XRandR headers/link files were supplied through a private extracted prefix; no system package installation or source/test edits. The worktree is clean. Logs and build results are retained.No title run, NVIDIA driver-cache coldness control, full-suite run, Windows/macOS/Intel test, or compile/runtime performance measurement. This adds standalone Linux/NVIDIA/RADV correctness coverage, not validation of the claimed title speedup.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:40:16Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main
534451426together with six other open GPU PRs (their own commits applied, no merge conflicts), so only the tests that belong to this PR say something about it:tests/ShaderMemory.cpp(targetagc_shader_memory_tests), whichctestruns asagc_shader_memory,agc_shader_bindless,agc_shader_srt_read_patching,agc_shader_frontend_pairandagc_shader_frontend_pair_off: 3 of 3 runs passed for each.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by poonasor on 2026-10-13T11:54:38Z.
Rebased onto
main2f969f147(it conflicted with8c04efcfb, which moved the in-place loads intoload_bda_span*).One change beyond the conflict: the span fallback loop no longer keeps its index and result in function-local variables.
main's "BDA read functions" test now requires that a span read function contains noOpLoad/OpAtomicLoadat all, and the variables were loaded there. The loop carries both values asOpPhiin its header instead; the in-place path still goes through the oneload_bda_span*call.Tested on the rebased commit (Windows 11, MinGW-w64 GCC 15.2, RX 6700 XT):
agc_shader_memory,agc_shader_bindless,agc_shader_srt_read_patching,agc_shader_frontend_pair,agc_shader_frontend_pair_off: pass.agc_driver_bda_span_reads,agc_driver_bda_device(GPU execution): pass.python tools/check_conventions.py --base origin/main: passes.Not re-run on this commit: the rest of the suite, and the title (the 140 s link number in the description is from the variable-based loop on
7e181fcc3).AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-13T12:25:05Z.
Retested the new
OpPhi-based span fallback at exact heade7249d38a1058549f6e2f2c1cb77ddb10875e3bf, standalone on Linux (Ubuntu 24.04 / Linux 7.0, GCC 13.3, Ninja Release, SPIRV-Tools ON).The set contains the five
agc_shader_memory_testsmodes named in the rebase comment,agc_driver_bda_device,agc_driver_bda_span_reads,agc_driver_pixel_interlock, andagc_driver_flat_apertures_0through_13. Each leg pins one ICD withVK_DRIVER_FILES,ANYPS5_GPU,ANYPS5_REQUIRE_VULKAN=1, andANYPS5_NO_SHADER_CACHE=1; verbose logs confirm the selected device. Serial execution, 30 s per-test limit, no failures or timeouts.Production-only negative control: replaced
SpirvBdaRead.cppwith its exact parent version from2f969f147b3cb54f63fc4e4e08a5a32456450ca6, retaining/rebuilding the PR's test.agc_shader_memoryfails withBDA read functions: the looped byte load does not keep the access's coherence. Restored the PR file byte-for-byte, rebuilt the test and driver, then ran the matrix above. The checkout is clean.Coverage detail: lavapipe's
agc_driver_bda_devicereturns success while reporting that BDA read/multi-dword write execution is not tested; the fourteen flat-aperture modes omit wave64 rows on its subgroup size 8. These are not CTest-level skips. The same limitations appear in my earlier lavapipe logs, so that earlier pass count should also be read with this qualification. Neither hardware leg printed those exclusions.No title run, full-suite run, driver-cache coldness control, or compile/runtime speedup measurement. This verifies the rebased implementation's focused Linux correctness, without establishing a fix for the failing Windows configurations in #4975.
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T14:58:51Z.
First NVIDIA and Intel run, which the description lists as not tested. The BDA read tests pass on both GPUs. That includes NVIDIA 595.97, which lost the device with the read shape from #4759 until #5022.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU (NVIDIA 595.97) and an Intel Raptor Lake-S iGPU (32.0.101.6790). The head e7249d38a merged cleanly into
main0f2683cb7, which includes #5022 and passes 1069 of 1069 on both GPUs.--repeat until-fail:3:agc_shader_memory,agc_driver_bda_span_reads,agc_driver_pixel_interlock,agc_driver_bda_device,agc_driver_scalar_wide_loads,agc_driver_flat_apertures_0to13, and the sixflat_loadsandglobal_loadstests. All 25 pass on both GPUs.ShaderMemory.cppincluded.SpirvBdaRead.cppfrommain,agc_shader_memoryfails on both GPUs withBDA read functions: the looped byte load does not keep the access's coherence, and the other 24 pass.I didn't measure compile time or run time.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T00:59:39Z.
Review: COMMENTED
The diagnosis is right. AMD's LLPC/amdvlk (like Mesa's NIR) inlines every SPIR-V function regardless of
DontInline, so helper body size is multiplied by the number of call sites, and a 510K-word pixel shader with 34 span reads hits that badly.One run-time point to check before this lands, since the change trades unrolled straight-line code for a loop with a dynamic index:
OpVectorInsertDynamicwith a loop-variant index. If the driver doesn't unroll the 4-iteration loop (and if it did, the compile-time gain would mostly disappear), a dynamic index into auvec4is lowered either as a select chain or, on some compilers, by spilling the vector to scratch memory and indexing it there. Scratch use in a pixel shader costs memory bandwidth and can reduce occupancy for the whole pipeline, not only for the fallback path. Building the result with a constant-index insert per iteration (OpCompositeInsertinside aswitchon the index), or shifting into scalars and assembling the vector after the loop, keeps the loop and avoids the dynamic index.LogPipelineStatisticsprints (VK_KHR_pipeline_executable_properties: scratch bytes and VGPRs) for the NHL 27 main-menu pipeline with and without this change on the RX 6700 XT, plus one NVIDIA or RADV device. A frame-time A/B would also show whether the menu frame got slower once it compiles.The fallback is the rare path (spans not mapped as one aligned piece), so the run-time cost may well be negligible. The point is to show it, since
perf(changes to shader emission affect every title's shaders.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-14T01:23:22Z.
Refreshed the Linux run for new head
3ab89c3e52c1bc1b97ed01f747f5bbec3c8dc97d, standalone on its recorded parentce5c8395333fbd4bfacdc35065f886333162caa5; no extra source changes.Release, GCC 13.3, bundled dependencies, SPIRV-Tools ON. Same 22-test set as my earlier report: the five shader-memory/bindless/SRT/frontend modes, BDA device and span reads, pixel interlock, and flat-aperture modes 0..13.
1002:13c0), RADV Mesa 25.2.8Each leg pinned its ICD, selected its GPU explicitly, required Vulkan execution and disabled the application shader cache. Serial CTest, unchanged 30-second limit. No internal skips or “not tested” messages in either log. These elapsed times are test-run totals, not a performance comparison.
Repeated the production-only negative control against this head's own parent: restoring only
SpirvBdaRead.cppfromce5c8395333while retaining the PR test makesagc_shader_memoryfail withBDA read functions: the looped byte load does not keep the access's coherence. Restored the PR file byte-for-byte, rebuilt, then ran the GPU matrix above. Checkout is clean.Lavapipe was not rerun for this head. No title run or pipeline-performance measurement in this report.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:16:48Z.
Closing as a duplicate of merged work: #3655 (merged today,
2d3a970da) already puts both changes onmain.EmitBdaByteLoopinSpirvBdaRead.cpploops the byte read over oneEmitBdaByte, carrying index and result inOpPhi(this PR does the same with function-local variables).DefineBdaSpanReadFunctionalready loops over the four dwords withOpPhiandOpVectorInsertDynamic, calling the byte read from one site and stopping the invocation on a stop, same as here.The PR now conflicts in
SpirvBdaRead.cppandShaderMemory.cpp, and once resolved againstmainnothing is left to add. If you still see a compile-time gap on NHL 27 withmainas it is, a measurement on currentmain(and a different change, e.g. for the dynamic insert CnRJay raised) would be welcome as a new PR.Pull request closed