perf(recompiler): select guest memory loads instead of branching around them #4048
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4048"
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 Mouad-Scriptz-0 on 2026-10-11T22:07:01Z.
What
Every guarded guest memory load in the SPIR-V backend (
LoadWord,LoadSubword,LoadWideSharedinSpirvMemoryInstructions.cpp,readBufferandEmitRuntimeScalarBufferLoadinSpirvRuntimeBuffer.cpp) opened a selection per guard: one for the lane's exec bit and one for the bounds check, four blocks each, and once more per lane half for wave64 on a 32-wide host. Sony's PSP wrapper (Killzone: Liberation, PPSA11142) runs its GE vertex processing in a 3176-word merged wave64 program with 249s_buffer_load, 229 LDS and 20 scratch accesses; it recompiled to 16,983 blocks, 11,274 of them deadOpUnreachableblocks left by the guards' arms, and 1,710 conditional branches in 484,166 words.active && index < length), perform the load either way and select 0 as the result. The load is pointed at a location no write can race with, so the extra access adds no data race (Vulkan memory model): scratch reads its own element 0; storage buffers (direct buffers, GDS) read element 0xfffffffe, whichrobustBufferAccess2turns into a zero load with no memory access. The aligned high word of a buffer read re-reads the low word's own element.VulkanDevice.cppenablesrobustBufferAccess2when the device has it, and the recompiler target carries the flag (cache key included). Without it those loads keep their selections as onmain; LDS loads, stores, atomics, formatted and physical-address (BDA) accesses always do. LDS stays branched because NVIDIA predicates the branched load at no cost while the select form costs about 2.5 instructions per dword and splitsds_read_b128into four loads (@karanvora2599's RTX 4060 counts below); the sentinel dword earlier revisions appended to the LDS array is gone with it, and the device-memory decision reserves the lock alone.agc_shader_replay --robust2emits for such a device.agc_guarded_memory_loads(new, built on @jweidenh's access tracer from the review) follows the emitted control flow for LDS word/subword/wide, GDS, coherent buffer and scratch loads in both device modes and records which guest elements each masked, in-range, out-of-range, invalid-descriptor and misaligned case reads;agc_lds_lock_budgetandagc_driver_lds_lock_budget(@jweidenh) check the device-memory decision at the lock boundary.main7a84b222: 15,323 blocks / 1,295 conditional branches withoutrobustBufferAccess2, 6,563 / 1,032 with it (main: 16,983 / 1,710; words 484,166 → 455,017).buffer_load_dworddrop from 24.0 to 10.5,dwordx4from 95.5 to 42.0,s_buffer_load_dwordfrom 16.5 to 10.0; LDS reads stay atmain's cost.agc_driver_flat_apertures_5hangs that driver with this PR because the selected loads reach the BDA span-read pattern of #3291, and the split proposed there resolves it; CI does not run on NVIDIA.The title still stalls on this program on Intel's Mesa driver for a separate reason, Mesa's register allocator spill loop on the wave64-sized instruction stream (every sample of the busy thread is in
ra_get_best_spill_node/spill_reg; reported to Mesa), so this does not make PPSA11142 playable on that GPU by itself. It is a generic saving for every shader with guarded loads.Tested
Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, Intel Arc Meteor Lake iGPU, Mesa 26.2.3, which exposesrobustBufferAccess2), branch rebased onmain2cf23fcc5(2026-10-13; the#3291span-read split is onmainthrough #4759 and #5022, so the NVIDIAflat_apertures_5hang karanvora2599 saw has its fix underneath this branch now; the debt entry lives indocs/dev/debt/shader.md):agc_guarded_memory_loads,agc_shader_memory,agc_shader_disk_cache,agc_vector_window,agc_driver_buffer_load_store,agc_driver_buffer_unaligned_base,agc_driver_lds_read_write,agc_driver_lds_beyond_device_limit,agc_driver_gds_append_consume,agc_driver_flat_loads,agc_driver_relative_indexingandagc_driver_scalar_relative_indexingpass. Before the correction, the 130-test memory subset (ctest -R 'lds|scratch|buffer|flat|global|scalar|relative|dpp16|shared|load|store|spirv|memory|aperture|wave64|masked|interp') passed with 1 skip.tools/check_conventions.py --base origin/mainandgit diff --checkpass. Block and word counts fromagc_shader_replay --spvon the dumped draw. Not tested on Windows.Host recompile time of the PPSA11142 shader dumps on this machine (
agc_shader_replay, best of 3 wall-clock runs per request, process start included; SPIR-V emission only, the driver's pipeline compile is not part of it): all 15 requests 699 ms onmain(2a5eca11c), 672 ms with this PR, 643 ms with--robust2; the 478,843-word program alone 296 ms onmain, 253 ms with this PR, 243 ms with--robust2. Frame time withrobustBufferAccess2on and off still owed: the device enables it for every pipeline, so it needs a title capture per the performance form, which is queued behind a Minecraft start-up hang I'm bisecting.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by jweidenh on 2026-10-11T22:59:21Z.
I found an unsafe extra-read case in head
13918b235d11157c3a6cb7e23f04fdeaabe22001and prepared a tested correction.For an aligned coherent buffer load at byte offset 8, the emitted path reads word 2 and performs a Volatile load from word 0 for the unused high half. Selecting zero afterward does not remove that access. Masked or out-of-range LDS/GDS/direct-buffer reads can likewise reach element zero. A concurrent write there can create a data race absent from the guarded program; addressability and robust access do not establish race freedom. See the Vulkan memory model.
The correction preserves index/result selects for invocation-private Function scratch, restores execution guards for shared reads and direct-buffer bounds, and loads the high word only for an unaligned base. It also updates TechnicalDebt to remove compile-time figures that no longer describe the narrowed optimization. Compile-time impact of the retained guards has not been measured.
Patch: test and correction together. The two commits are the regression and the fix, on
jweidenh:codex/guarded-shader-loads.The CPU regression follows concrete control-flow paths in emitted SPIR-V and records guest-memory load indices. On the test-only baseline, all six expected failure groups reproduced: LDS word/subword/wide, GDS word, coherent buffer bounds, and aligned high-word access. The last reported
guest reads: 2 0; expected: 2. Private scratch remained a passing control. The baseline was not dispatched on the GPU.Windows 11, RTX 5090, NVIDIA driver 617.42, Release build: all seven candidate CTests passed without skips, with the six native controls selecting the RTX 5090. Full
libsbuild and local conventions checks also passed. Shader caching was disabled and each case used fresh cache directories. Times below are test wall times, not performance comparisons.agc_driver_buffer_load_storeagc_driver_buffer_unaligned_baseagc_driver_gds_append_consumeagc_driver_lds_beyond_device_limitagc_driver_lds_mixed_width_atomicsagc_driver_lds_read_writeagc_guarded_memory_loadsThe seven CPU groups all pass with the fix, including active/inactive and bounds cases, conditional high-word reads, Volatile preservation, and an explicit Function-storage check for scratch. Baseline and candidate use identical test files.
Windows build dependency: both arms include only the reviewed Socket.cpp guard from #4021 at 121b16f. Actual validation pins are baseline 283ad65 and candidate 33d462e; each differs from its published shader revision only in that build fix. The proposed correction does not include it.
Limits: scalar-buffer lowering is restored but has no dedicated case in the new CPU fixture. Non-atomic GDS reads have CPU access-trace coverage; the native GDS test covers append/consume atomics. Linux was not rerun because the local runner still lacks the required SDL audio development packages. No retail-title crash, startup latency, shader compile-time reduction, or FPS improvement has been demonstrated.
AI-assisted contribution.
Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-11T23:16:13Z.
Thanks, the extra access is real and the memory model's rule is on your side: a load that the guarded program would not perform is an access, whatever happens to its value. Rather than narrow the selects to scratch,
70b27ed5keeps them and points every selected load at a location that no write can race with:robustBufferAccess2turns into a zero load with no memory access;VulkanDevice.cppnow enablesrobustBufferAccess2when the device has it and the recompiler target carries the flag (cache key andagc_shader_disk_cacheupdated). Without it, and for LDS kept in device memory, those loads keep their selections exactly as onmain;Your
GuardedMemoryLoads.cpptracer is in the branch asagc_guarded_memory_loads(thanks, it is a good fixture), run in both device modes: withrobustBufferAccess2the masked and out-of-range reads record the sentinel (LDS) or0xfffffffe(GDS, buffers, including the invalid-descriptor and misaligned cases), without it they record no read, and scratch records 0 either way.agc_shader_replaygained--robust2to emit for such a device.On the dumped PPSA11142 program, now on current
mainwith #3856: 14,667 blocks / 1,131 conditional branches withoutrobustBufferAccess2, 5,907 / 868 with it (main: 16,983 / 1,710). Tested on Fedora 44 / Intel Arc Meteor Lake (Mesa 26.2.3, which exposesrobustBufferAccess2):agc_guarded_memory_loads,agc_shader_memory,agc_shader_disk_cache,agc_vector_window,agc_driver_buffer_load_store,agc_driver_buffer_unaligned_base,agc_driver_lds_read_write,agc_driver_lds_beyond_device_limit,agc_driver_gds_append_consume,agc_driver_flat_loads,agc_driver_relative_indexingandagc_driver_scalar_relative_indexingpass; conventions andgit diff --checkpass. Not tested on Windows.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by jweidenh on 2026-10-12T00:47:25Z.
I reviewed and tested the revised
70b27ed5implementation on Windows 11 / RTX 5090. The sentinel strategy addresses the extra shared reads from my previous report, but I found a compute LDS budgeting boundary that still needs correction.EnsureLdsStoragenow declares guest LDS + a lock dword when required + the sentinel dword.DeviceMemoryLdsBytesstill reserves only four bytes. A shader using the 64-bit LDS lock can therefore remain in Workgroup storage while declaring four bytes beyondmaxWorkgroupSharedMemoryBytes.The correction reserves eight bytes in the runtime and diagnostic recompilation decisions. It preserves your load-selection/robustness strategy and the existing device-memory fallback layout. This is conservative worst-case accounting, consistent with the existing fixed-overhead approach. The existing source-content cache version automatically invalidates old compiled artifacts.
Patch: tests and correction, on
jweidenh:codex/guarded-load-sentinel-budget. The test-only baseline is 00e3a14ec; e638f90b contains only the two production budget-line changes. Test files and registrations are identical between both arms.Negative control: the CPU fixture recompiles a small locked-LDS shader with 64 bytes of guest LDS and limits of 64, 68 and 72 bytes, for wave32 and wave64. On the test-only baseline, exactly the two 68-byte cases fail with
declared 72 Workgroup bytes exceeds limit 68; the other four controls pass. All six pass with the correction. No baseline shader was dispatched on the GPU.Native boundary proof: the new mode of the existing mixed-width-atomics test reads the actual device target. On this RTX 5090 / driver 617.42 it reports
robustBufferAccess2=1and a 49,152-byte shared-memory limit. Before dispatch it verifies the emitted allocation, then checks results across all 256 lanes:Windows results: Release, supported WinLibs GCC 15.2.0 r7, full
libstarget built. Thirteen of fourteen selected CTests passed; one executable was blocked before process creation by the machine's existing Windows Code Integrity signing policy. That test is not run, not a pass. The policy was not changed and the blocked test was not retried. All nine completed native cases selected the RTX 5090. The table gives test wall times, not performance measurements.agc_driver_buffer_unaligned_baseagc_driver_flat_loadsagc_driver_gds_append_consumeagc_driver_lds_beyond_device_limitagc_driver_lds_mixed_width_atomicsagc_driver_lds_read_writeagc_driver_lds_sentinel_budgetagc_driver_relative_indexingagc_driver_scalar_relative_indexingagc_guarded_memory_loadsagc_lds_sentinel_budgetagc_shader_disk_cacheagc_shader_memoryagc_driver_buffer_load_storeThe revised access tracer passed all seven groups, which exercise robustness2 disabled and enabled internally. The native boundary test explicitly verifies enabled robustness2; the other native cases identify the GPU without their own feature banner. Tests use isolated cache locations; the disk-cache test intentionally enables its own temporary cache. Source, test inventory, raw JUnit/logs, and allocation/readback evidence were independently audited. Conventions and
git diff --checkpass. The overall fourteen-test validation remains incomplete because of the policy-blocked executable.Build dependency: although #4021 has now merged, the tested PR base predates it. Both arms add exactly its reviewed Socket.cpp guard at
121b16fb4bbd47ff4ce9302c40631bab858e3e71, separately from this correction. Actual Windows pins are baseline e85cfad9 and candidate 08522f5f.Limits: Linux was not rerun because the local runner still lacks SDL audio development packages. The unchanged historical
agc_vector_windowfixture was excluded because its missing observable output had already caused a known failure; it is not counted as passing. This correction covers compute budgeting; overall mesh Workgroup budgeting and shader-request serialization of the new robustness flag are outside it. The diagnostic recompilation budget change was source-reviewed, with no separate CLI execution test. No retail title, startup latency, shader compilation-time improvement or FPS improvement has been demonstrated.AI-assisted contribution.
Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-12T01:18:17Z.
Right, the fallback decision still budgeted the lock alone. Your three commits are on the branch as they are (
15168cc0,bcf90fa9,d6f57526, your authorship):DeviceMemoryLdsBytesand the deserializer now reserve eight bytes for the lock and the sentinel, and the two tests are registered.On Fedora 44 / Intel Arc Meteor Lake (Mesa 26.2.3,
robustBufferAccess2=1, 49,152-byte shared-memory limit, the same as your 5090):agc_lds_sentinel_budget(the six CPU boundary cases),agc_driver_lds_sentinel_budget(both native boundaries, readback checked across all lanes),agc_driver_lds_mixed_width_atomics,agc_guarded_memory_loadsandagc_shader_memorypass;tools/check_conventions.py --base origin/mainandgit diff --checkpass. Thanks for the boundary proof on the 5090 as well.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-12T07:54:55Z.
Measurements on NVIDIA for d6f57526a merged onto
maind146ec1b6. Setup: RTX 4060 Laptop (Ada, driver 591.86), Windows 11, MinGW-w64 GCC 15.2.0, Release.Code size. SASS instructions per guest instruction come from the
APS5_PIPELINE_STATSbinary size: a wave32 compute program with 16 of the instruction, minus the same program with the instruction replaced by moves (FLOAT_MODE0xc0).mainbuffer_load_dword,buffer_load_dwordglcbuffer_load_ubyte,buffer_load_ushortbuffer_load_dwordx4s_buffer_load_dword, and per dword ofx4/x16ds_read_b32ds_read_b64ds_read_b128Stores, atomics and
buffer_load_format_xyzwmove by 1 at most.Why the LDS reads grow.
main, a guarded LDS read is a branch around the load. NVIDIA's compiler turns that into a predicatedLDS, which is nearly free, andds_read_b128stays one 128-bit load.ds_read_b128can also no longer be merged into one.With LDS reads left branched. I made
LoadsSelectablereturn false forResourceKind::Lds. LDS then takes theEmitValueOrZeroIfConditionpath that LDS in device memory already uses. Results:ds_read_b32is 0.0,ds_read_b640.5 andds_read_b1281.0, which ismain's cost or less.ds_read_b32drops from 20.3 to 15.3. Butds_read_b64rises from 31.6 to 34.1, andds_read_b128from 66.1 to 82.6. So on Intel the static count favours the select for wide reads. I haven't measured run time on either GPU.agc_driver_lds_*execution test,agc_lds_sentinel_budget,agc_driver_lds_sentinel_budgetandagc_shader_memory.agc_guarded_memory_loadsfails only its three "LDS … reads its sentinel" checks, which pin the select form.If LDS stays branched, no LDS load reads the sentinel any more. The sentinel dword and the eight-byte budget from d6f57526a would then not be needed for LDS.
Tests with the PR as it is, on the RTX 4060.
agc_guarded_memory_loads,agc_lds_sentinel_budget,agc_driver_lds_sentinel_budgetandagc_driver_lds_mixed_width_atomicspass.agc_driver_flat_apertures_5hangs the GPU, twice in a row. The log showsrecorded batch still running on the GPU after 20 s, then the test aborts. It passed in amainrun on the same machine.main, this driver already hangs onflat_apertures_2and on theflat_loads/global_loadstests (#3291).flat_apertures_5andflat_apertures_2both pass in 2.6 s.agc_driver_prepared_shaders_registered_workgroup_syncfailed once in a full suite run and passes when run alone. I don't think it's related.Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-12T09:08:27Z.
Thanks for the SASS and GEN counts; they settle it. LDS loads keep the branch of
mainagain, everywhere (workgroup, function and device memory), and the sentinel dword goes with them: nothing reads it once LDS is branched, so the LDS array is the program's dwords plus the lock again and the device-memory decision reserves the lock alone (DeviceMemoryLdsBytesand the deserializer back to 4 bytes). Buffer, scalar-buffer and scratch loads keep the select form your table shows halving. Commit 5d18a4d9, on the branch rebased ontomainc36fd0a0(the conflicts were the newregistrationModulestarget fields next torobustBufferAccess2).LoadsSelectablereturns false forResourceKind::Lds, as in your experiment;GuardedElementIndexthrows if LDS ever reaches it.agc_lds_sentinel_budgetandagc_driver_lds_sentinel_budgetbecomeagc_lds_lock_budgetandagc_driver_lds_lock_budget: the CPU cases now expect device memory below 68 bytes (16 dwords + lock) and a Workgroup allocation at and above it; the native cases check the exact fit atlimit - 4and the fallback atlimit.agc_guarded_memory_loadspins the branch for LDS word, subword and wide reads (masked and out-of-range cases read nothing; the x4 edge case reads element 15 only) and checks the LDS array declares exactly the program's dwords.Counts on the same PPSA11142 program (
agc_shader_replay --spv), measured on the previous base7a84b222, this change against the sentinel version: withoutrobustBufferAccess215,323 blocks / 1,295 conditional branches / 478,491 words (was 14,667 / 1,131), with it 6,563 / 1,032 / 455,017 (was 5,907 / 868 / 452,397);mainis 16,983 / 1,710 / 484,166.On the
flat_apertures_5hang: the description now notes that NVIDIA reaches the BDA span-read pattern of #3291 through the selected loads and that the split proposed there resolves it; thanks for isolating that.Fedora 44 / Intel Arc Meteor Lake (Mesa 26.2.3,
robustBufferAccess2=1):agc_guarded_memory_loads,agc_lds_lock_budget,agc_driver_lds_lock_budget,agc_driver_lds_mixed_width_atomics,agc_shader_memorypass;tools/check_conventions.py --base origin/mainandgit diff --checkpass.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:19:00Z.
Three things before this can be tested:
core/shader/recompiler/CacheKey.hppandRecompiler.hpp, and the TechnicalDebt entry now belongs indocs/dev/debt/shader.md.agc_driver_flat_apertures_5hangs the GPU on NVIDIA with this PR and passes on main on the same machine (karanvora2599's run). A note in the description doesn't cover that. The split from #3291 has to be in main first, with this PR listing it under Depends on.robustBufferAccess2on and off, sinceVulkanDevice.cpp:1574turns it on for every pipeline on devices that have it (#218).Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-13T14:01:51Z.
Rebased on current
main(7f83869b3): the conflicts were the newfloat16DenormPreserveandvertexSubgroupsfields next torobustBufferAccess2, and the debt entry moved todocs/dev/debt/shader.md. The span-read split from #3291 is onmainthrough #4759 and #5022, so this branch now sits on it; @karanvora2599, if you can rerunagc_driver_flat_apertures_5on the RTX 4060 with this head, that settles whether the hang was that pattern. With this branch the sentinel test mode is gone along with the sentinel, soagc_driver_lds_sentinel_budgetis unregistered here;agc_lds_sentinel_budgetand the LDS execution tests pass.Compile time, as asked (host recompile only,
agc_shader_replay, best of 3 wall-clock runs, Meteor Lake): the PPSA11142 dumps total 699 ms onmain, 672 ms with this PR, 643 ms with--robust2; the 478,843-word program 296 / 253 / 243 ms. The driver's pipeline compile is outside the tool. A title frame time withrobustBufferAccess2on and off is still owed; it needs the trace capture from the performance form and is queued behind a Minecraft start-up hang I'm bisecting on this machine.Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-13T22:45:43Z.
@Mouad-Scriptz-0, I can't rerun it on the RTX 4060 right now. When I saw the hang with your earlier head, the #3291 span split alone fixed it, and that split is now under your branch, so I expect
agc_driver_flat_apertures_5to pass. An NVIDIA run ofctest -R agc_driver_flat_apertureson this head would settle it. No title is needed: on driver 591.86 the test alone hung.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-13T23:23:38Z.
NVIDIA follow-up on exact rebased head
7f83869b374e37c5239d32a26727789f52f84639, with no additional source changes: all 14 flat-aperture modes pass three consecutive runs on RTX 3090, includingagc_driver_flat_apertures_5.Linux x86-64, Release, NVIDIA 595.99.02, subgroup32, bundled dependencies,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON. Pinned the NVIDIA ICD and setANYPS5_GPU=NVIDIA,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1. Serial CTest, unchanged 30-second per-test timeout.Result: 16 fixtures × 3 = 48 passes, 33.91 seconds total. The extra two are the CPU guarded-load and LDS-lock-budget checks. Logs select the RTX 3090 throughout; no internal skips or
recorded batch still running on the GPUmessages were printed.This supplies NVIDIA execution coverage for the current head with the span-read split underneath it. It does not retest the original RTX 4060 / 591.86 combination or establish a title frame-time improvement; those claims remain separate.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T04:20:31Z.
agc_driver_flat_apertures_5passes twice on 7f83869b3 merged onto main30f961266, as on main, with no hang or Xid; so doagc_guarded_memory_loads,agc_lds_lock_budget,agc_driver_lds_lock_budget,agc_driver_lds_mixed_width_atomicsandagc_shader_memory. RTX 4090, NVIDIA 610.57.04, Linux, Release, SPIRV-Tools OFF. That matches simonbbby's run above; the earlier hang was on 591.86, which neither covers.Two things left: rebase, since it now conflicts with main in
docs/dev/debt/shader.md(keep both entries), and the frame time withrobustBufferAccess2on and off.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T21:33:17Z.
Two things from 10-14 are still open: a rebase for the
docs/dev/debt/shader.mdconflict (keep both entries), and the frame time withrobustBufferAccess2on and off. The NVIDIA hang is settled, so those are all that's left.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:06:06Z.
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/Execution/src/VulkanDevice.cppL3495-3496core/shader/recompiler/CacheKey.hppL264core/shader/recompiler/Recompiler.cppL533core/shader/recompiler/Recompiler.hppL271core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppL28core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppL109core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppL262docs/dev/debt/shader.mdL156core/libs/prx/libSceAgcDriver/CMakeLists.txtL1726docs/dev/debt/shader.mdL156core/shader/recompiler/CacheKey.hppL264core/shader/recompiler/Recompiler.hppL271core/shader/recompiler/Recompiler.cppL533core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppL28core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppL109docs/dev/debt/shader.mdL156Some 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/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tools/ShaderReplay.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvBufferAccess.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tools/ShaderReplay.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppdocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-16T14:08:31Z.
@oneandonlydean asked for the frame time with
robustBufferAccess2on and off. Here it is on Intel, where the two differ.Setup. Intel Arc (Meteor Lake iGPU), Mesa 26.2.3 ANV, Fedora 44 (kernel 7.2.10), GCC 16.2.1, Release.
APS5_TRACE_FRAMES=20:30), 3840x2160, warm caches.main65d56a297with three local changes:PipelineJournal.cppsize asserts dropped so it compiles (#6784);BAD_CHUNK_IDfor the files my dump lacks;APS5_NO_LIBRARY_PREBUILD=1in every run, because of the startup crash in #6805.33f191da8merged onto that base;state->robustBufferAccess2 = false, so the loads keep their selections.mainrobustBufferAccess2onWith it on, GPU time drops about 14% and frame p50 about 15%. Off is within about 2% of
main. The p90 of the "on" runs is higher, from a few slow frames in both captures.One more data point, for the cost of the feature itself. Before finding this PR, I wrote a local variant of the same idea for
readBufferandEmitRuntimeScalarBufferLoad's direct path, withoutrobustBufferAccess2:OpArrayLength;On the same base and scene it gave 561.0 / 558.3 ms p50 and 378.1 / 356.1 ms GPU busy per present, which is lower than "on". The constant-buffer-heavy compute
0x2011050000went from 0.59 to 0.25 ms per dispatch againstmain.So on ANV, enabling
robustBufferAccess2seems to cost part of what the select form saves. That fits ANV bounds-checking every buffer access once the feature is on. I haven't isolated that cost on its own.The clamped read has the problem your description avoids: element 0 can be written by another invocation while the discarded read happens, which is a data race under the memory model even though the value is never used. So I'm not proposing it as is; I'm only noting the cost of the feature on this driver.
Traces,
trace_digest.pyoutput and the clamped-read diff:ThatsLeo:evidence/4048-stray(main/,robust2-on/,robust2-off/,clamped/).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-16T22:49:44Z.
@ThatsLeo's run answers the frame-time question on this head: with the feature on, GPU time drops by about 14% on ANV (p50 −15%), and with it off it's within 2% of main. What's left is the rebase: CacheKey, Recompiler, SpirvEmitter, ShaderReplay, the ShaderDiskCache test and the shader debt file conflict with main now. I'll rebase it onto current main. #6177 enables the same feature for stores and formatted accesses, so I'd like the enable and the cache key to land once, here, with #6177 building on it.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T01:33:25Z.
Rebased onto main (resolutions: adjacent additions only); GPU lds tests 17/17.
Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-18T11:11:34Z.
@ThatsLeo thanks, that closes the frame-time question @oneandonlydean asked for, and it points the same way as the SASS and GEN counts: the select form wins where the guard is paid per load. Dean, thanks for carrying the rebase and the merge.
On the clamped variant: the clamp to element 0 is the reason this PR reads element 0xfffffffe under
robustBufferAccess2instead. A read of element 0 races with any invocation that stores there, discarded value or not, which is the memory-model point in the description. So the variant is not a candidate as it is, but its GPU-busy numbers against the "on" build do suggest the feature costs something on ANV by itself, separate from the select.One run would isolate that, if you have the setup still warm:
mainwith the enable alone (state->robustBufferAccess2 = trueand no select changes) on the same Stray window. Ifmainplus the enable is slower thanmain, the cost is the driver's per-access check and not the select form, and the enable should become per driver or per access kind rather than unconditional. That matters for #6177 too, which extends the same enable to stores and formatted accesses. I will file a follow-up issue with the ANV numbers once that run exists, or now if you would rather track it separately.Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-19T00:06:18Z.
@Mouad-Scriptz-0 Here is the run you asked for. It isolates the enable, and it corrects what I suggested above: on ANV the feature costs nothing measurable by itself. The whole gain is the select form.
Setup.
APS5_TRACE_FRAMES=20:30, 3840x2160).APS5_NO_LIBRARY_PREBUILD=1(#6805) andAPS5_PLAYGO_UNLISTED_CHUNKS=absentin every run.mainat this PR's merge,63da333b7, with one local switch, inswitch.diff, so all three variants share one build:main: as merged. The device enablesrobustBufferAccess2and the loads use the select form.robustBufferAccess2, but the recompiler target is told it is off, so the loads keep their selections as before this PR.What changed from my earlier runs. I found my first runs were not comparable: under this load the package reaches 97–99 °C and the GPU drops to 1550–1750 MHz despite the 2250 MHz minimum. So these are four interleaved rounds, each capture started below 55 °C.
main(enable + select)That also means my clamped-variant numbers above should not be read as a cost of the feature. They came from runs where the thermal state wasn't controlled.
So from ANV there is no reason to make the enable per-driver. That leaves #6177 free to extend it here as planned. I can't speak for other drivers.
48b394d1ealready keeps it off on AMD's proprietary driver, but for a different reason.Traces,
trace_digest.pyoutput and the switch:ThatsLeo:evidence/4048-robust2-only(main/,dev/= enable only,none/).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-20T19:58:11Z.
@ThatsLeo thanks for the controlled rounds. With the enable alone inside the spread of "neither", there is no per-access cost to track on ANV, so I'm not opening the follow-up issue I offered: it would have no claim to make. Recording the conclusion here instead: the enable can stay unconditional on ANV, the gain is the select form, and #6177 is free to extend the enable to stores and formatted accesses on this evidence.