perf(agc): bind a read-only buffer only as far as its constant-offset scalar loads reach #28077
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28077"
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 DerKarussellbremser on 2026-11-28T11:46:35Z.
What
A guest buffer is bound, uploaded and snapshotted at the full size its V# declares. A title that binds one large range to read a few constants from it pays for the whole range at every draw.
Assassin's Creed Black Flag Resynced (PPSA28183, 01.006.038) does that from its first frames: its draws bind read-only buffers of 43.0 MiB (45,088,768 bytes) whose base moves with every object, in steps of a few hundred bytes. In the first 170 s of a run (
maina4ebd9084cwith the PRs named under Tested merged) the capture trace lists 11,067 draw snapshots of that size at about 400 different base addresses. The draw snapshot store keeps 1 GiB, so it holds 23 of them, and almost every draw copies 43 MiB again inShaderResources::PrepareDrawBindings: in a sampled profile of the draw committer 96 % of the time underrecordDrawis thatmemcpy.For a buffer the shader only reads through scalar loads at constant offsets, the reachable part is known when the program is recompiled:
ReadConstBufferwhose offset operand is an immediate) asstaticReadExtent, and setsdynamicAccessfor every access of another kind: a scalar load at a register offset, a vector load, a store, an atomic.bufferReadBoundfor a buffer that is neither written nor atomic and has no other access; every other buffer gets 0.ShaderResources::addGuestBuffersizes a read-only buffer by its bound, rounded up to a DWORD, when that is less than the V# declares. The clamped size is what is registered as readable, uploaded, imported in place and snapshotted.MovedReadOnlyBuffersandMovedDispatchBufferssize an element the same way, so a cached build compares an element with the size it was bound with and moves it at that size.The bound changes how much of a buffer is bound, never whether a draw is accepted: the check against the render target stays on the declared size, cut at the target as on
main, and the element is bound for the smaller of that size and the bound.CheckBufferAliases, which repeats the check for a cached build, is unchanged and decides as the build does.The resource tracker is the last pass that sees buffer accesses (only dead-code elimination and the image overwrite proofs follow), so no access can appear behind the bound. The shader's own run-time bounds check still uses the V#'s records and stride.
APS5_NO_BUFFER_READ_BOUNDrestores the declared size.The shader disk cache stores the two
BufferResourcefields and the bound, so its format version goes from 98 to 99.This is deliberately the narrowest rule that holds without looking at index ranges. It does not cover vector loads at a constant index and offset, or loads whose index is bounded by the draw; in the title such buffers still leave 62.0 MiB (65,011,712 bytes) and 43 MiB bindings from the first-boot dialogs on (see the trace under Tested). A local diagnostic build that logs the opcodes behind
dynamicAccessshows them read byLoadBufferU32,LoadBufferU32x2,x3andx4and byReadConstBufferat a register offset. The 62.0 MiB buffer stays at one address and a draw commit takes 0.28 ms in that phase, so its snapshot is reused, not copied again.#9897 and #14032 bound a read-only buffer whose every access is an
IDXENload indexed by the vertex or instance index, by the draw's vertex or instance range (bufferVertexExtent). They leave a buffer read by scalar loads whole, and this PR leaves theirs whole (anIDXENload setsdynamicAccess), so the three cover different buffers; all of them size the element inaddGuestBuffer, so whichever lands later has to be rebased over the others. #19852 and #14944 go the other way for formatted reads: they keep a minimum extent (bufferReadExtent) where the view was too small.Tested
Windows 11 Home 10.0.26200, i7-10750H, 16 GB, NVIDIA GeForce RTX 2060 6 GB, driver 610.91, WinLibs GCC 15.2.0 r7 UCRT, Release, on
main69d574e9a2.agc_shader_disk_cache:verifyStaticReadBoundrecompiles a compute program with ones_buffer_load_dwordand a store. With the load at offset 0x40 the read buffer's bound is 0x44 and the stored buffer's is 0; with the same load at a register offset the bound is 0.verifyBindingPlanSelectionchecks that the plan bounds a read-only buffer by itsstaticReadExtent, and does not bound an atomic buffer, a written one or one withdynamicAccess.a buffer read by one scalar load at offset 0x40 is not bounded at 0x44; with the plan always passing 0,binding plan did not bound a read-only buffer by its static reads, or bounded an atomic one.agc_driver_recorder: a read-only 12 MiB element with a read bound of 66 bytes is bound for 68 bytes (copied bytes plus in-place read ranges); without a bound, and with a bound past its end, it is bound whole.addGuestBuffersizing by the V#,a read-only 12 MiB element the shader reads 66 bytes of was not bound for 68 bytes.MovedDispatchBuffersandMovedReadOnlyBuffersat its own address, and is listed with 68 bytes 256 bytes further on. WithAPS5_NO_BUFFER_READ_BOUNDit has to be bound for at least its 12 MiB.APS5_ALL_BUFFERS_WRITTENturns the bound off as well (review,69c620c454): the build took the bound from the binding's own written flag before the switch made the element written. Newagc_read_written_staging_all_written(fbdfd5edc8) runs the staging tests with the switch set and requires the element with a read bound of 66 bytes to be noted as written for its 12 MiB. Red without the fix:an element with a read bound that APS5_ALL_BUFFERS_WRITTEN notes as written was not bound at its declared size. Atfbdfd5edc8with the validation layer loaded:agc_read_written_staging, the new test,agc_driver_recorder,agc_driver_graphicsandagc_shader_disk_cachepass, noVUID-line. The title runs were not repeated.a read-bounded element at its own address was taken as moved by a dispatch.agc_driver_graphics, next to the existing checks of a strided read-only buffer in front of the render target (stride 60, 4 records):aliases the render targetalthough its read bound of 64 bytes ends before the target, asCheckBufferAliasesrefuses it for a cached build;MovedReadOnlyBuffersdoes not list it as moved for the same words and target.MovedReadOnlyBufferssizes an element withguestBufferBytesfor that, as the build andMovedDispatchBuffersdo; an element without a bound whose declaration lies past the limit, which this path refused before, is thereby an exact hit at its own address too. Red without the source change of the fourth commit (dda5bd7dda):an unchanged V# the build cut to its allocation end was taken as moved by a draw whose read bound lies past that end.3bd55db2a6, for the two checks before: the first of the two fails withexpected graphics rejection: aliases the render target; with that check taken out, the second fails at its build withshader buffer aliases the render target.ctest -R "unaligned|buffer_format|formatted|runtime_buffer_spans|guarded_memory_loads|shader_disk_cache|dispatch_move|^agc_driver_graphics|agc_driver_recorder|shader_memory|draw_cache|pipelined_dispatch"on this branch: 89 of 89 pass (27 test programs). I did not build the remaining execution tests.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -V(validation layer of Vulkan SDK 1.4.363.1), onmain69d574e9a2and on this branch atdda5bd7dda: 89 of 89 pass on both, the loader logsInsert instance layer "VK_LAYER_KHRONOS_validation"107 times in each run, and neither log has a line withVUID-.main483b81fb5ais merged ina065267929. The one conflict is the comparison insameBindingoftests/ShaderDiskCache.cpp, which now hasmain'simageUintStorageand this branch'sbufferReadBound; apart from that line the diff againstmainis the same as before. The selection above, again with the validation layer, at that commit on Windows: 90 of 90 pass, the loader logsInsert instance layer "VK_LAYER_KHRONOS_validation"108 times, no line withVUID-. I did not repeat the performance captures and title runs for the merge.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branch perf/agc-bind-read-only-buffer-static-extent, run again for the third commit (c4d6105f13; the fourth changes one line in each of two files already in the list): of 2,116 open PRs 325 share a file with the branch (the third commit addstests/Graphics.cpp, which many PRs touch). 20 conflict in lines; 18 of those only in the bookkeeping every metadata change touches (the cacheFormatVersion, the encoder'ssizeofand field-count assertions, thevectorBytessum, the test'ssameBinding), the other two are #19852 (see above) and #22628 (a line next to the newBufferResourcefields). #20519, rebased since, now sets the sameFormatVersionand is a nineteenth of that kind. None conflicts intests/Graphics.cpp. 166 conflict withmainthemselves and could not be compared. For the first commit I searched the diffs of the 123 of the then 158 that share a code file foraddGuestBuffer,guestBufferBytes,bufferExtentandmaxByteExtent: 13 touch one of them, and of those only #9897, #14032 and #14944 change how a guest buffer is sized (see above). The 15 that are new in that list share only a test file ordocs/dev/ENVIRONMENT.mdwith the branch; none of the 14 with a test file touches the checks this PR adds or changes.APS5_TRACE_SECONDS=5:30, no other trace or profile switch, log not redirected. Each side ran the scene once before (340 s, which fills its shader cache) and was restarted.main69d574e9a2against this branch atdda5bd7dda, nothing else merged:main69d574e9a2dda5bd7ddaGraphics.Drawper frameWith the change the scene sits at the title's 30 fps limit: the presenter waits 27.3 ms per frame for the vertical blank. The window is this early because the branch alone stops 44.5 s after its first present with
guest memory is not readable at 0x42347a0000, the stop #27451 is about;maindoes not get that far in the same time. The 900 s runs below have #27451 merged on both sides.Summary lines
tools/performance_compare.pyon the two lines gives the frame times above;tools/trace_digest.pyon the traces gives the thread and slice rows. The two traces (aps5-trace-69d574e9a2cc-57592.json.gz,aps5-trace-dda5bd7dda11-47796.json.gz) follow in a comment.APS5_NO_BUFFER_READ_BOUND=1) and on again:These three runs are of
3bd55db2a6. The two commits after it only change the check against the render target back to whatmainchecks, the size of a buffer that overhangs the target by less than a stride, and the size of a moved buffer whose declaration lies past the range limit; I did not repeat the runs for them.Screenshots taken every 60 s at the same times of three such runs of the first commit: the still dialog pages of
onandoffdiffer by a mean of 0.01 to 0.03 of 255 per channel, inside one 50 by 50 pixel animated icon that differs the same way between the twoonruns; the moving scenes differ between the twoonruns as much as betweenonandoff. I see no difference I can attribute to the change.Draw snapshot trace (one entry per binding a draw takes from a snapshot, copied or reused): without the change the first 138 s of a run hold 11,067 entries of 43 MiB; with it the same 138 s hold 1,104, and the whole 868 s hold 2,867 of 43 MiB and 28,364 of 62.0 MiB, the latter all at one address from the first-boot dialogs on (80 s).
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)🤖 Generated with Claude Code
https://claude.ai/code/session_011TXsSW8zeAgKgHLCFsYwM3
Summary by CodeRabbit
APS5_NO_BUFFER_READ_BOUNDsetting, which preserves full-size handling for read-only buffers.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T11:56:07Z.
Review: COMMENTED
Actionable comments posted: 2
3ba02105-72a3-4834-aefd-61521e8a2e66Reviewing files that changed from the base of the PR and between
045b7d7813and09cd11dc97.core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppdocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T12:12:00Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes contain no verified blocking defect, but I could not run the reported checks, so a formal approval is not justified.
What I ran
Reviewed head
09cd11dc97293a273cbdc991fd44ed160fade08ausing the prepared review bundle andrepo_read.pyreader. No commands or tests were run.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
No tests, builds, or conventions checks were run in this review. The PR description reports 89 passing tests and a passing conventions check; those results were not independently confirmed. The full text for
ShaderResources.cppandRecorder.cppwas excluded from the review folder; their changed hunks and relevant context were read through the reader. Other changed files were reviewed at the relevant hunks; their full contents were not read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T13:52:37Z.
Review: COMMENTED
Actionable comments posted: 1
105c83a5-4507-4e6a-8f47-88723e58d711Reviewing files that changed from the base of the PR and between
09cd11dc97and3bd55db2a6.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T14:09:31Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
3bd55db2a6fddf002445858218c00c77c0f1f86efrom the prepared diff and targeted source reads throughrepo_read.py. No commands or tests were run by me; the checks below are reported in the PR description.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not execute tests, conventions checks, or title captures. The author's reported results and hardware observations were not independently verified. Reviewed all 12 files listed as changed in
review/manifest.json; onlyShaderResources.cppandRecorder.cppfull texts were excluded from the review folder, and were read throughrepo_read.py. The prepared diff omitted lockfiles, minified files,dist/,build/, and.svgfiles;review/files.jsonwas not available through the review reader, so excluded-file details beyond the prepared diff are not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T17:17:35Z.
Review: COMMENTED
Reviewed — no blocking findings
The change at head
c4d6105f135ce5e6cd16a2376a59f87a53dbcf02appears internally consistent, but I could not run the reported checks independently, so a formal approval is not justified. Nothing blocks this; the points below are optional.What I ran
Read the prepared diff and targeted source excerpts at the exact head. No build or tests were run;
repo_read.pywas used only to inspect files.Results
Negative control
Not run independently; the description reports negative-control tests, but I did not verify their output.
Findings
Blocking
None identified in the inspected changes.
Non-blocking
Sources
The prepared diff and targeted excerpts from
ResourceTracker.cpp,DescriptorBindingBuilder.cpp,ShaderResources.cpp, and the changed test files at the pinned head. The reported 89-test run and performance measurements are author-reported, not independently confirmed.Not verified
I read the changed hunks for all 13 changed files. I read targeted repository excerpts from
ShaderResources.hpp,ShaderResources.cpp,Graphics.cpp,Recorder.cpp,ShaderDiskCache.cpp(tests),DescriptorBindingBuilder.cpp,ResourceTracker.cpp, andShaderDiskCache.cpp(recompiler cache). I did not read full texts of changed files. Build, tests, platform coverage, and runtime behavior were not verified.To get this to a good state
Nothing is required. Optional: independently run the reported checks on this head before relying on the reported results.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T17:19:07Z.
Review: COMMENTED
Actionable comments posted: 1
9da4057e-301f-46d9-9095-8aee8617b7fdReviewing files that changed from the base of the PR and between
3bd55db2a6andc4d6105f13.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T19:41:37Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the checked tracker and binding logic support the stated bound for read-only constant-offset scalar loads.
What I ran
Reviewed head
dda5bd7dda113d2e4dfce6a7dfcb314a50d51b64. I read the prepared description, commits, manifest and diff, then inspected the changedResourceTracker.cppandShaderResources.cpplogic through the pinned reader. No build or tests were run by me; reported test results are author supplied.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Full text was included and reviewed for
ShaderResources.hpp,ShaderDiskCache.cpp(tests),Resources.hpp,DescriptorBindingBuilder.cpp,ResourceTracker.cpp,Recompiler.cpp,Recompiler.hpp,ShaderDiskCache.cpp,ShaderDiskCache.hpp, andENVIRONMENT.md. The changedShaderResources.cpp,Graphics.cpp, andRecorder.cppwere excluded from the review folder; I read only the relevantShaderResources.cpprange. The excluded test files were not read. No tests were run; the hardware and performance claims were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T07:34:31Z.
Review: COMMENTED
Reviewed — no blocking findings
The diff for head
a065267929d1f92d39ee74fb3698865d7c4e38d5shows a narrowly scoped static read bound with safeguards for dynamic accesses, writes, atomics, render target aliasing, and cached buffer moves; full source review was incomplete, so I cannot recommend a formal approval.What I ran
python3 repo_read.py catfor source context. The reader returned theResourceTracker.cpprange, then could not log the next call because the workspace is read-only.Results
Findings
Blocking
None identified in the inspected diff.
Non-blocking
None.
Sources
files.jsonlists no excluded files.Not verified
To get this to a good state
Nothing is required. Optional: complete source-context review and rerun relevant checks before making a formal approval decision.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T07:43:32Z.
Review: COMMENTED
🏛️ Architecture findings (1)
Advisory architecture findings (1)
💬 Code review
bcdffefa-5dfb-4c54-8624-45602a076ddcReviewing files that changed from the base of the PR and between
dda5bd7ddaanda065267929.core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:26:33Z.
Review: COMMENTED
addGuestBufferappliesReadBoundBytesbeforeAPS5_ALL_BUFFERS_WRITTENchanges the effectivewrittenflag. With that switch, a scalar-only V# can therefore enter the writable path with the reduced range, even though the switch restores the old all-writable behavior. Could the bound use the effective flag and add coverage that the writable override preserves the declared range? The existing recorder case compares the default withAPS5_NO_BUFFER_READ_BOUND.Source review at
a065267929. Paired Vulkan execution is pending.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T01:07:59Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
fbdfd5edc8db57a066fe28986f42a4cf500d8f9ausing the prepared description, commit list, manifest, and diff. No tests or builds were run. The pinned reader command failed before returning source context because it could not append its run log under the read-only filesystem.Results
Negative control
Not run. No non-compiling negative control was available in the prepared artifacts.
Findings
Blocking
None identified in the inspected diff.
Non-blocking
None identified in the inspected diff.
Sources
The inspected changes add static-read tracking and carry its bound into the binding plan and buffer sizing: ResourceTracker.cpp, DescriptorBindingBuilder.cpp, ShaderResources.cpp.
Not verified
ShaderResources.cpp,Graphics.cpp, andRecorder.cppwas not available infiles/; only their changed diff hunks were inspected.files.jsonlists no policy-excluded files.files/; their relevant changed sections were inspected.To get this to a good state
Nothing is required. For a formal approval, complete the source-context review of the three large files and run relevant non-compiling checks on this head.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.