perf(agc): hand pending results over to an image whose DCC keys are a clear code #7427
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7427"
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 parl0v on 2026-10-18T05:57:40Z.
What
StorageTexture::Refreshstores every other image whose results are still pending in the image's memory before it uploads (FlushPending(..., "storage refresh")). When the refreshed image's DCC keys are a clear code, its upload is a GPU clear (upload,IsDccClear+ClearColorFor) that reads none of that memory, so those stores are dead for it. Unreal's render graph hits this constantly: it hands the memory of a transient texture whose results are still pending to a new texture that it fast-clears.On Minecraft Dungeons II (PPSA16064) I counted this at the title screen (RTX 4060, 3072 MiB storage cache, per 10 s): 86,776 storage refreshes, 20,298 of them over memory where other images still had results pending, and 44.3 of those 49.2 GB of pending results (90 %) sat under a refreshed image whose keys were a clear code. None of them reached past the refreshed image. The
storage refreshwrite-backs alone were 53.7 GB per 10 s, about 15 ms of GPU time per frame.perf:
StorageTexture::clearHandOver(called byRefreshbefore its flush) leaves those results pending instead of storing them, when:ProvedKeys()returns a clear code thatClearColorForaccepts.The path is chosen from the keys read before any flush, and only when no flush runs at all, so no store can change the keys between the decision and the upload.
Refreshthen reuses those keys instead of reading them again.What happens to the results afterwards:
markLayersPending), the handed-over results in that unit are dropped, the same way the existing borrow path drops an alias's units: the image's write-back stores every byte of the unit.APS5_NO_CLEAR_HAND_OVER=1stores the results first, as before. WithAPS5_PROFILE_DRAWthe[storage]line counts the hand-overs and the units dropped.test:
agc_storage_clear_hand_over(agc_driver_recorder_tests --clear-hand-over-only). An RGBA8 image A has results over four 64 KiB units; an image B of another format and shape lies over the first two, with DCC keys that are a clear code. Four orders run with the hand-over on and off: A never read again, A read before B writes, A written again after the hand-over, and a CPU store into one of A's units under B before B writes. Each must leave the same texels in B and the same guest bytes as the old order. With the hand-over on, B's refresh must store nothing, A must stay pending, and B's write must drop A's two units under B. The test runs in watched memory (its host import kept watched) and in compared memory, where no hand-over may happen. The test layout is close to the one in #4286, which tried a broader hand-over and was closed when it showed no gain in a default configuration.Tested
Windows 10 19045, MinGW GCC, Release. Minecraft Dungeons II (PPSA16064) title screen. FPS is presents per 10 s, averaged over each row's last windows. Rows alternate between
mainandmain+ this commit (mainb39d90bf1for these runs), with the same relinked executable.RTX 3060 12 GB (i5-12400F, NVIDIA 617.42), default settings (automatic storage budget), 215 s rows (FPS over the last 100 s),
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1:mainRTX 4060 8 GB (i5-14400F, NVIDIA 617.42),
APS5_TEXTURE_CACHE_MIB=3072, 150 s rows (FPS over the last 60 s),APS5_PROFILE_DRAW=1:mainstorage refreshwrite-backs per 10 sOn the RTX 4060 with its automatic budget (1.5-1.8 GB on 8 GB) the frame is bound by storage cache evictions, and this change makes no difference: 3.07 / 3.05 FPS on
mainagainst 3.12 / 2.90 with this PR.On this branch, rebased on
main66e71b63d, the 61 tests that runagc_driver_recorder_tests,agc_dcc_key_sharing_testsandagc_driver_sampled_cache_budget_testspass on the RTX 4060. That coversagc_storage_clear_hand_over, everyagc_storage_*test,agc_unit_shadow,agc_pending_key_stores,agc_shadowed_key_stores,agc_dcc_key_sharingandagc_driver_resource_cache_*;agc_import_settle_first_useskips on this machine.tools/check_conventions.py --base origin/mainpasses.Performance capture (as the Performance report form describes): Minecraft Dungeons II (PPSA16064) title screen, RTX 3060 12 GB (i5-12400F), NVIDIA 617.42, Windows 10.0.19045, 3840x2160 output. Only
APS5_TRACE_SECONDS=120:12set, caches warm (the title ran once on the build and was restarted), stderr not redirected.main48d61f53b4against this PR's head 9371b6b498e8:Frame and GPU times (ms):
Top phases (ms per frame):
Traces:
aps5-trace-48d61f53b46f-9720.json.gz(main) andaps5-trace-9371b6b498e8-6060.json.gz(this PR), attached below.trace_digest.py, main
seconds 120:12 from present 2158: 99 presents, frame p50 117.2 / p90 145.0 / p99 158.4 / max 158.4 ms, GPU busy 100.7 ms per present
NVIDIA GeForce RTX 3060, NVIDIA 617.42, Windows 10.0.19045, 3840x2160, commit
48d61f53b4, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 235.3, batch 100.7, Driver.Packet.dispatch 86.1, Driver.Dispatch 85.2, Driver.Packet.memory_wait 68.0, Vulkan.Dispatch 39.4, Vulkan.Dispatch.shader_resources 37.1, Driver.Packet.device_lock 32.2, Driver.Packet.prepare_memory 27.8, Recorder.Sync 20.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, this PR
seconds 120:12 from present 2225: 109 presents, frame p50 104.9 / p90 145.0 / p99 150.8 / max 151.2 ms, GPU busy 92.3 ms per present
NVIDIA GeForce RTX 3060, NVIDIA 617.42, Windows 10.0.19045, 3840x2160, commit 9371b6b498e8, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 212.9, batch 91.4, Driver.Packet.dispatch 77.8, Driver.Dispatch 76.9, Driver.Packet.memory_wait 60.4, Vulkan.Dispatch 34.4, Vulkan.Dispatch.shader_resources 31.9, Driver.Packet.device_lock 31.0, Driver.Packet.prepare_memory 23.2, Recorder.WaitSerial 19.9
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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 MarcZX10 on 2026-10-18T06:00:28Z.
Review: COMMENTED
I found a bounds issue in the new regression fixture:
surfaceBis 128 × 128 × 8 = 131,072 bytes, and it starts ataddress + surfaceA, butbytes(the allocation and registered/imported extent) is onlysurfaceA + 65,536. That leaves the second half of image B outside the allocated guest block. The readback and final flush still cover the full 131,072-byte image, so the test can access memory beyond the fixture allocation. Could you size/register the block throughsurfaceA + surfaceB(and keep any intentional overlap explicit), then rerun the focused test?Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T06:03:44Z.
@MarcZX100 thanks for reading the fixture closely. B doesn't start at
address + surfaceA:surface()setsbaseAddress = addressfor both images, and its fourth argument is the DCC key address (resource.dccAddress = dcc). The layout is:[address, address + 256 KiB), four 64 KiB units, no DCC keys.[address, address + 128 KiB), over A's first two units on purpose; that overlap is the hand-over under test.surfaceB / 256= 512 bytes ataddress + surfaceA, inside the 64 KiB after A.The allocation, the guest registration and the host import are all
surfaceA + 65536= 320 KiB, so they cover A, B and the keys.readImagecopies out of B'sVkImage, not guest memory, and the finalFlushPending(address, bytes)andreadMemory(address, surfaceA)stay inside the block. I'll add astatic_assertto the fixture so the overlap and the key placement are stated in the code rather than implied.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T06:06:45Z.
You are right. I misread the fourth
surface()argument as the base address, but it setsdccAddress; both image resources start ataddress. The fixture intentionally overlaps B over A’s first two 64 KiB units, and the 320 KiB allocation covers A, B, and B’s key bytes. My bounds finding was incorrect; please disregard it. Thanks for correcting me.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T06:07:01Z.
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)docs/dev/ENVIRONMENT.mdL195core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL2071core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL2071core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppL104-105, L158core/libs/prx/libSceAgcDriver/tests/Recorder.cppL9374Some 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/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T06:54:36Z.
Converting this to a draft. With this change I'm seeing a crash during Minecraft Dungeons II level loads (2 of 4 in-game loads on my RTX 4060: a game worker thread reads a garbage pointer, the same function both times), which I haven't seen on
mainin the same runs. I'm testing whether the commit I just pushed (23b8ddd81, a CPU store into a handed-over unit before the receiving image writes now keeps the CPU's bytes, as onmain) closes it, with the hand-over on and off in the same build. I'll mark it ready again only with clean repeated loads.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T07:14:22Z.
Ready for review again. The crash isn't this change. It's Minecraft Dungeons II's world-load crash from late storage write-backs (#1970, the "Pending storage-image results" entry in
docs/dev/debt/libSceAgcDriver.md), and it shows up on currentmainas well. Interleaved in-game loads on the RTX 4060 (APS5_TEXTURE_CACHE_MIB=3072), 4 each:main66e71b63dAPS5_NO_CLEAR_HAND_OVER=1All three crash with the same two signatures: a loading thread or a background worker reads a garbage pointer during the level load. With the hand-over switched off the build does what
maindoes, and it crashes as often as with it on. I'm checking separately whether this crash got more frequent on currentmainthan in my earlier runs; that isn't specific to this PR.The PR's numbers on current
main(66e71b63d), title screen:mainAPS5_TEXTURE_CACHE_MIB=3072, 3 roundsOn the RTX 4060 the
storage refreshwrite-backs go from 59–63 GB to 14.7 GB per 10 s (about 4,800 hand-overs per 10 s). The full build on66e71b63dhas no errors, and the 68 storage, DCC, depth and graphics tests pass.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T09:04:00Z.
Gameplay check on the RTX 4060 8 GB with the automatic cache: Minecraft Dungeons II loaded into a level, standing still for 90 s, FPS over the last 60 s. Five alternating rounds of
main66e71b63d, this PR, and this PR withAPS5_NO_CLEAR_HAND_OVER=1:mainStorage refreshes are rare in gameplay (about 14 per 10 s, 10 MiB), and the hand-over fired 0 times in every PR row, so the PR doesn't change anything there. The 3.1 to 3.5 rows show up on
maintoo: GPU busy stays the same and the idle gaps grow from 150 ms to 210–236 ms per frame. The gain is on the title screen, where clear-key write-backs make up 90 % of the storage-refresh bytes.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T19:52:02Z.
The on/off byte comparison in
agc_storage_clear_hand_overis a good test when it runs. ButclearHandOverTestsreturns normally on every path where it can't run: no host imports, imports compared on the device, no write watch, import refused, or the block leaving the watch.--clear-hand-over-onlythen returns 0, so the ctest shows Passed even when the watched case, the only one that hands over, never ran.SKIP_RETURN_CODE 77is set but never reached.Could those paths return a "not tested" result that makes the binary exit 77? At least the watched run's should, since the compared run alone only checks that no hand-over happens. Then a Passed result on CI means the hand-over was exercised.
Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T20:19:22Z.
Done in 1d8072a2f (now on top of the rebase onto current
main):clearHandOverTestsreturns whether it ran, and--clear-hand-over-onlyexits 77 when the watched run can't run (no host imports, imports compared on the device, no write watch, the import refused, or the block leaving the watch), so CI reports it as skipped instead of passed. The compared run still runs first and checks that nothing is handed over there. On my RTX 4060 (Windows) the watched run runs and the test passes.The rebase also needed a row for
APS5_NO_CLEAR_HAND_OVERindocs/dev/ENVIRONMENT.md, whichcheck_conventionsnow asks for.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T20:19:30Z.
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 oneandonlydean on 2026-10-18T20:51:51Z.
Thanks for the exit-77 change, it closes the false pass. One more line is needed so the Linux job accepts the skip.
tools/check_skips.pyfails the Linux job for any skipped test whose output has noskipped, <device limitation>line matching itsDEVICE_LIMITATIONpattern.--clear-hand-over-onlynow exits 77 but prints only "host imports are compared on this device: clear-key hand-over (watched) not tested", which doesn't match. On lavapipe, where host-pointer imports are compared rather than watched, the job would then fail atcheck_skips.--shadowed-key-stores-onlyhandles the same condition this way:Could
--clear-hand-over-onlyprint a line like that before returning 77? "the device imports no" is in the pattern.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T21:01:04Z.
Added in a5dcb105b: when the watched run can't run,
--clear-hand-over-onlynow prints "skipped, the device imports no watched host memory for the clear-key hand-over" before returning 77, the same wording as--shadowed-key-stores-only, and it matchesDEVICE_LIMITATION. On my RTX 4060 the watched run still runs and the test passes. The performance capture in the description is on 9371b6b49; this commit only touches the test.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T22:09:06Z.
Traces of the performance capture in the description (they open in ui.perfetto.dev):
main48d61f53b: aps5-trace-48d61f53b46f-9720.json.gz