perf(agc): read unit-shadow slabs in place for read-only address builds #24510
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24510"
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 ashwin280802 on 2026-11-20T18:17:03Z.
What
Before an address-based build runs,
GuestBufferMemory::UploadFinishcopies every live unit-shadow unit over the mapped heaps from its slab into the host import ("address-based heaps"). On Platform 8 (PPSA24944) that copy took about 17 ms of GPU time per frame.This PR skips that copy for a build that meets all three conditions:
bdaReadOnly);Instead, the live units are mapped read-only to their slab's device address in the build's BDA table. Slabs get
SHADER_DEVICE_ADDRESSwhen the device supports it.GpuMutexinto the same recorder and queue the copy used, andRecorder::Keepholds the slab.StorageTexture::writeBackWindowsrecord behind barriers with anALL_COMMANDSsource (Texture.cpparound lines 4528, 4553 and 4576).UploadFinishand the draw is now seen by the draw. It is recorded in the debt file.APS5_NO_SHADOW_READS=1restores the copy.Performance. Platform 8 (PPSA24944) in the idle scene from launch, an RTX 5070 with driver 621.24 at 3840x2160, audio muted. Six pairs of 150 s runs, alternating the order of main (
907fe8fd31) and this patch, with the median of the last ten 10 s windows of each run:In pair 2 the main arm presented nothing for about 80 s before recovering (the same presents stall I saw in earlier arms of main), so its median is 52. Without that pair:
Every pair is positive, GPU busy time per frame drops by 11 to 15 ms in every pair, and the gain is above 13% in each of the other five.
Performance trace. The measured commit is
164151fb99d9. The current head is the same commit rebased onto newermain: the two commits add and remove the same 297 lines in the same files. A 100 s capture of each build withAPS5_TRACE_SECONDS=60:20, this host and scene,mainfirst and the change second (the fulltools/trace_digest.pyoutput of both is in this gist; the traces are attached asmainand the change, 6.7 and 7.3 MB):Both traces overflowed their buffers (31,501 events lost on
main, 115,680 on this patch), so the summary lines are the evidence and slice timings cover retained events only.Overlap. #23234 narrows the same copy to the heap ranges and edits the same
UploadFinishlines. The two combine, and whichever lands second rebases that hunk. Among the open PRs whose titles mention shadows or publishes, only #23234 touches this path.Tested
Windows 11, MinGW-W64 GCC 15.2.0 (Release), RTX 5070 with driver 621.24. Commit
164151fb99.The new tests are
--bda-shadow-reads-in-place-onlyin three variants (the default,APS5_NO_ADDRESS_SPACE_CACHE=1andAPS5_NO_SHADOW_READS=1) and--bda-shadow-reads-in-place-retiles-onlyin two. They check:ShaderResources::ReadsShadowsInPlace) refuses a storing build and a space-reuse candidate;The tests that depend on
libSceAgcDriver(2,273) ran withctest --tests-from-file:Windows failures that also fail on origin/main
907fe8fd31on this machine:agc_driver_stencil_plane_memory,agc_driver_msaa_dcc_unwatch,agc_driver_bda_device,agc_driver_store_over_untracked, andagc_storage_write_back_host_retile(intermittent).agc_driver_cached_image_multisample_guardfails under parallel load and passes alone, here and on main.Vulkan validation used the same tests on main and on this change, with
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The new tests ran on the change alone.I changed 20 conditions and statements one at a time, and the tests failed on 14. The six that survive do not change which bytes a draw reads:
two
reservecalls;merging adjacent table pieces and adjacent slab runs (the same bytes in fewer entries);
an early return when unit shadows are off, which the registry makes redundant;
the live-unit count in
ShadowReadRuns, a hint that every reader re-checks per unit, so a count left too high costs a scan.Not covered by a test: the call site of the read-only gate in
ShaderResources::buildComplete. Only a full build reaches it, and no test runs a storing build over a live shadow. The gate's condition itself is tested.Not verified: Linux, which I did not run locally for the final commit (the Docker VM on my machine crashes under load), so I am relying on the project's Linux CI; AMD and Intel GPUs; and the performance on a base newer than
907fe8fd31.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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T19:04:58Z.
Review: COMMENTED
Reviewed — comments
The changed hunks reviewed show no verified blocking defect, but the sparse-mirror and copied-region overlay behavior still lacks test coverage.
What I ran
Reviewed head
986c002c362851fa929bb95590b4df77aaf9bf49using the prepared diff and pinned repository reader. I ran no build or tests; no merged-preview check was performed.Results
Findings
Blocking
None verified in the changed hunks reviewed.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp:8045).Sources
Not verified
No tests or builds were run by the reviewer, and console behavior was not verified. Reviewed changed hunks in all nine changed files. Full file text was included for six;
GuestBufferMemory.cpp,ShaderResources.cpp, andRecorder.cppwere excluded from the review folder as too large, so only targeted ranges were read through the pinned reader. The author reports Windows test and Vulkan validation results in the PR description; those results were not independently verified.To get this to a good state
Nothing is required. Optionally, add tests for sparse-mirror heaps and copied regions within mapped heaps.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T20:26:32Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
4cc78f4f6a4546b606cda191ea2e29d023d39a49using the prepared diff, manifest, description, commits, andrepo_read.pyat the pinned head. No build or tests were run; reported test and performance results are author supplied.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Full text was read for
GuestBufferMemory.hpp,ShaderResources.hpp,UnitShadow.hpp,UnitShadow.cpp,agc_driver_recorder_tests.cmake,ENVIRONMENT.md, andperf-agc-shadow-reads-in-place.md. Targeted ranges were read throughrepo_read.pyforGuestBufferMemory.cppandShaderResources.cpp; full text was not read.Recorder.cppwas not read; its full text was excluded from the review folder. The reviewer did not run build/tests or verify the reported Windows, Linux CI, Vulkan validation, console, or performance results.To get this to a good state
Nothing is required. The reported behavior and scope are covered by targeted code review; the build, tests, and measurements remain author-reported.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:46:04Z.
Review: COMMENTED
I followed the eligibility gate, clipping to mapped BDA coverage, and the recorder reference that retains a slab through execution. The retile-after-prepare case is especially important because the new path reads the live slab at execution instead of the published copy. Please keep that case alongside the disabled and per-build table controls. The paired recorder tests are queued on lavapipe. I did not repeat the title timing.
AI-assisted: yes.
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.