perf(recompiler): leave the descriptor-range comparison out of direct buffer loads when the device zeroes past the range #7484
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7484"
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 AlxcBTW on 2026-10-18T09:08:51Z.
What
A direct (non-BDA) buffer load in
readBuffer(SpirvRuntimeBuffer.cpp) has two zero conditions: the guest V# bound (byteAddress().inBounds, passed in asenable) and the descriptor range, which the shader compares with theOpArrayLengthof the storage-buffer block (EmitMemoryElementInBounds). WithrobustBufferAccess2the load is already a select (GuardedElementIndexpoints a refused load at element 0xfffffffe, where the device returns zero), but theOpArrayLengthstill reads the descriptor and the compare and the selects cost time on every load.The recompiler now leaves the descriptor-range comparison out of a direct buffer load when all of this holds:
robustBufferAccess2enabled (State::robustBufferAccess2: the device reports the feature androbustBufferAccessis enabled; since #8267mainno longer switches it off on AMD's proprietary driver, and this PR no longer refers to that check) and reportsrobustStorageBufferAccessSizeAlignment == 1(queried throughVkPhysicalDeviceRobustness2PropertiesEXT);APS5_NO_EXACT_ROBUST_LOADSis not set (like the otherAPS5_NO_*switches: set at all means off);LoadsSelectable, the same condition the select form has today).Then the load still selects on the guest V# bound (
enable), and the device produces the zero past the descriptor range. For a buffer that can be misaligned the high word keeps its comparison with the length (!unaligned || next < length;unalignedis a specialization constant, so an aligned pipeline folds the term and theOpArrayLengthaway). Where the device lacks the feature or the alignment is not 1, or the switch is set, the checked form is emitted as before. Stores, atomics, the coherent 64-bit load, GDS, LDS, scratch and BDA loads are not touched.The flag travels as
SpirvTarget::exactRobustLoadsintoSpirvTargetOptionsand the emitter state and is part of the shader cache key (CacheKey.hpp).ShaderResources::wholeDwordRangerounds the descriptor range of a guest buffer and of a draw snapshot down to whole dwords when the flag is on (ranges of 4 bytes or more;Context::exactRobustLoads). The entry "Guest memory load guards" indocs/dev/debt/shader.mdsays so, anddocs/dev/ENVIRONMENT.mdhas a row forAPS5_NO_EXACT_ROBUST_LOADS.Why the result is the same bytes:
floor(range / 4), and the device returns zero for a 32-bit load that leaves the range. The guest V# bound stays in the shader and selects the same fallback index, so the guest sees the same zero for raw, structured and swizzled loads as before.robustStorageBufferAccessSizeAlignmentreturns zero, and an access is out of bounds if any part of it is. With an alignment of 1 there is no padding in which the device could return memory contents, which is why the path needs the alignment to be 1. The bound is the descriptor range (VkDescriptorBufferInfo::range), not the size of theVkBuffer.floor) and, with alignment 1, outside for the device ("any part"); the host rounding of the range down to a multiple of 4 makes both agree even for an implementation that treats it differently. It removes no word a direct access can reach: every direct access (word load, word store, byte store through the u8 block, 64-bit access through the u64 block) is already gated byfloor(range / 4).Limits: equivalence to console behaviour is not measured on console hardware. The shader-side comparison of both variants on a device ("verify") is not in this PR; the argument above and the interpreter test below are.
Tested
main(the last is16259face, base0c6a5bd59), at 5095da616 (the PR head16259faceplus the CI scaffolding commit; run 39678131804, ctest regexguarded_memory_loads|shader_disk_cache|recompiler|spirv): 20 of 20 passed, none skipped, among themagc_guarded_memory_loads(0.05 s),agc_shader_disk_cache(2.05 s) andagc_shader_disk_cache_large_file. This is a narrower set than the 712 tests of the earlier run (the wholeagc_*andshader_*set) at the pre-merge head, which are not repeated here. Not run on Windows.agc_guarded_memory_loadshas a new case, "exact robust loads read what the checked variant reads": the SPIR-V interpreter of that test runs the checked and the exact module of a raw 32-bit buffer load over 432 combinations (active or not, offsets 0 to 4092, 32 to 128 records, base misalignment 0 to 3, valid and invalid V#) and requires the same effective reads, where an index at or past the 16-word array counts as the device's zero. It also checks that an exact request withoutrobustBufferAccess2leaves the plain variant unchanged.agc_shader_disk_cachehas a new key case, "exact robust loads": the flag changes the cache key.lab/libs-robust2), arm a without the switch and arm b with it on (the lab switch for this change), so the change is the only difference between the arms. The device reportsrobustBufferAccess2true androbustStorageBufferAccessSizeAlignment1. All rowsAPS5_TEXTURE_CACHE_MIB=3072,APS5_NO_PAD_INPUT=1,APS5_PROFILE_GPU=1, and the same lab-only settings in both arms (a refresh lever and the depth clear HLE). The counters of the b rows say the change was taken: every direct load was compiled without the descriptor-range check (65536 without, 0 with).At the title the GPU busy time per present is 67.04 to 67.29 ms without the change and 64.86 to 65.13 ms with it in every row, about 2.2 ms less. That is the only figure I claim. Mean FPS at the title is 9.13 without and 9.21 with it, inside the spread of the rows: the title is CPU bound on this machine (frame p50 105 to 112 ms against 65 ms of GPU busy time), so a shorter GPU time barely moves the frame rate. The gameplay rows are memory noisy (31 GiB, two rows per arm): GPU busy 58.5 and 56.6 ms without, 53.4 and 53.4 ms with, which agrees in direction but I claim nothing from it. Pictures were not compared. Traces are on the lab machine and I can attach them on request.
python3 tools/check_conventions.py --base origin/mainpasses. Based on0c6a5bd59(merged into the branch).tools/pr_overlap.pylists open PRs that touch some of the same files (#6947 and #6946ShaderResources, #6977, #7332 and #7201VulkanDevice.cpp,Recompiler.cppandSpirvRuntimeBuffer.cpp, #6924, #7223 and #7395ShaderDiskCache.cpp, #7426Recompiler.hpp); none of them implements the same function.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:33:39Z.
AMD on Windows: the tests this PR names pass on an RDNA 3.5 GPU.
Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release.
main6efb7261bwith this PR (fd1714a65) merged, together with #7296, #7446, #7377, #7445, #6708, #6748, #6785, #6706, #6613, #7449, #7391, #7489, #7514. They were built once, so the result is for the combination; each merge was clean.agc_guarded_memory_loads,agc_shader_disk_cache: pass, 3 runs of 3.agc_*test on the combined build: 713 of 716 pass. The 3 that fail,agc_driver_host_import_lifetime,agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gpl, fail the same way on unchangedmainhere, so none comes from these PRs.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:07:49Z.
Rebase handoff — rebased onto current
main(both commits, authorship unchanged). The GPU-stages target-option conflicts resolved:main'sfloat32FlushToZero/depthRangeRemapfields kept alongside yourexactRobustLoads(including itsrobustBufferAccess2conjunction), andmain's newer sub-range snapshot descriptor (snapshot.offset/snapshot.bytes) kept with yourwholeDwordRangerounding applied to it — worth your eye, since the rounding now coversmain's sub-range rather than the whole-buffer form you wrote against. NoFormatVersionbump (the flag is cache-key-only, matchingmain's treatment ofrobustBufferAccess2).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
1048ac448.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T08:53:28Z.
Thanks @blawesom. I checked
1048ac448against the current head2d9224813: every file's added and removed lines are the same as before, tests and docs included, so the conflicts were resolved purely by keepingmain's side around the PR's lines. On the rounding:mainalready used the sub-range snapshot descriptor (snapshot.offset,snapshot.bytes) when this PR was written, sowholeDwordRangecovers the same range as before. It only trimsrangeto whole dwords and leaves the offset alone.@AlxcBTW since this is a rebase rather than a fast-forward,
git merge --ff-only FETCH_HEADwill refuse on your branch.git fetch https://github.com/blawesom/AnyPS5 rebase/7484 && git reset --hard FETCH_HEAD, then a force-push, picks it up.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T21:21:37Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by CPritch on 2026-10-22T12:33:31Z.
Ran this on GTA V (PPSA04263 01.010.002), Linux 7.2.8-zen1-2-zen, NVIDIA GeForce RTX 5060 Laptop GPU, NVIDIA 615.71.09 (
robustBufferAccess2true,robustStorageBufferAccessSizeAlignment1), Graphics Mode Performance, the Story prologue after Resume Story, with no input.main
0c6a5bd59(the main this head is based on) against main + #7484 at16259face, same machine and session, two runs each in the order A B A B, window frames 3400:700, APS5_TRACE_EVENTS=4194304,APS5_NO_EXACT_ROBUST_LOADSnot set. Each side was warmed until it stopped building pipelines, and no timed run built one.Frame p50: main 77.1, 77.6 ms, with #7484 75.4, 75.9 ms (-1.7 ms, -2.2 %). GPU busy per present: 62.4, 62.3 -> 60.4, 59.8 ms, 2.3 ms less, close to the 2.2 ms in the description.
p99: main 107.7, 108.2 ms, with #7484 108.0, 116.6 ms. The second run's slowest 1 % of frames was slower; what those frames hold was not examined.
Not tested: other scenes, Fidelity mode, other GPUs, Windows. Pictures were not compared.
AI-assisted: yes
Summary lines (main, then the PR):