perf(agc): retile linear write-backs into host-memory imports on request #21536
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21536"
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 LloydNicholson on 2026-11-16T11:14:43Z.
What
A whole-layer write-back of a linear storage image into a host import retiles into device scratch and then copies the rows into the import with
vkCmdCopyBuffer, unless the import is in a device-local heap (unified memory), where it retiles into the import directly. For linear rows the retile writes the same bytes to the import as the copy, so on a discrete GPU the direct route moves no more data over the bus and drops the scratch buffer, a barrier and avkCmdCopyBufferper write-back. RADV looks up its copy pipeline for every region (vk_meta_get_pipeline_layout,memcmpof the key), which showed up on the draw committer.APS5_LINEAR_IMPORT_RETILE_HOST=1lets such write-backs retile into a host-memory import as well. Off by default; documented indocs/dev/ENVIRONMENT.md.APS5_PIPELINE_STATS, an[import-writeback]line counts import write-backs by route every 10 s: retiled into the import, eligible but copied (host-memory import), other.agc_storage_write_back_host_retileruns the storage write-back test with the switch on, and the test's route expectations account for it.On the Astro Bot world map the committer was the busiest thread (about 84 % of 10 s). With
APS5_PIPELINE_STATS=2(separate runs, not the captures below): about 1,200 of 2,300 import write-backs per 10 s took the scratch route and were eligible; with the switch, all of them retiled directly, end-of-pipe commits went from 27-31 to about 22 us each and draw commits from 52-58 to 46-49 us each on the committer.Tested
Linux 7.3.4 (Nobara, Fedora 44), AMD Radeon RX 9060 XT (RADV GFX1200, Mesa 27.0.0-devel), Ryzen 7 5700X.
Astro Bot (PPSA21564), world map, standing at the same spot, warm caches,
APS5_TRACE_SECONDS=180:20, no otherAPS5_TRACE_*orAPS5_PROFILE_*switch, log not redirected. Both captures come from the same session and the same converted title, both withAPS5_LINEAR_IMPORT_RETILE_HOST=1set (main does not read it), so the summary lines differ only in commit; onlylibSceAgcDriver.prxdiffers between the runs.e4caa07950f8023ea7bc27dfAn earlier capture of main in the same session without the variable gave 276 presents, p50 / p90 / p99 / max 72.5 / 76.1 / 78.2 / 81.1 ms (
aps5-trace-e4caa07950f8-3424790.json.gz), so the gain is 13-20 % depending on which main capture it is compared with. The 134.6 ms maximum is the first present of the window (present 3549, at 0 ms). All traces filled the queue worker's and the committer's event buffers before the window closed (dropped: yes); the summary statistics are unaffected.Summary lines:
Traces (attached in a comment):
aps5-trace-e4caa07950f8-3542653.json.gz(main),aps5-trace-023ea7bc27df-3434660.json.gz(this PR), and the earlier main captureaps5-trace-e4caa07950f8-3424790.json.gz.tools/trace_digest.py, maine4caa07950f8seconds 180:20 from present 3071: 261 presents, frame p50 76.5 / p90 81.0 / p99 88.3 / max 91.7 ms, GPU busy 47.0 ms per present
AMD Radeon RX 9060 XT (RADV GFX1200), radv Mesa 27.0.0-devel, Linux 7.3.4-201.nobara.fc44.x86_64, 3840x2160, commit
e4caa07950, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 173.0, Driver.Packet.memory_wait 127.3, Driver.WorkerWait 79.0, Driver.WorkerWait.dequeue_order 63.6, batch 47.0, Driver.Packet.dispatch 20.7, Graphics.Draw 19.7, Graphics.Draw.draw_and_resource_release 15.5, Driver.WorkerWait.idle_and_completion_poll 15.4, Recorder.Submit 14.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py, this PR023ea7bc27dfseconds 180:20 from present 3549: 313 presents, frame p50 63.7 / p90 67.5 / p99 71.9 / max 134.6 ms, GPU busy 41.7 ms per present
AMD Radeon RX 9060 XT (RADV GFX1200), radv Mesa 27.0.0-devel, Linux 7.3.4-201.nobara.fc44.x86_64, 3840x2160, commit
023ea7bc27, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 140.8, Driver.Packet.memory_wait 108.9, Driver.WorkerWait 68.3, Driver.WorkerWait.dequeue_order 55.8, batch 41.9, Graphics.Draw 15.3, Recorder.Submit 12.9, Driver.WorkerWait.idle_and_completion_poll 12.4, Driver.Packet.dispatch 12.4, Graphics.Draw.draw_and_resource_release 12.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Focused tests on main and on this PR, same machine and GPU, with
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V -R "agc_storage_write_back|agc_copied_write_back|agc_storage_split_writeback|agc_storage_writeback_blocks|agc_storage_import_segment_memo|agc_unwatch_snapshot_scope_linear", validation layer 1.4.341 (/usr/lib64/libVkLayer_khronos_validation.so): main 8/8 passed, this PR 9/9 passed; every log showsInsert instance layer "VK_LAYER_KHRONOS_validation", none reportswas not found but was requested, and neither has aVUID-line.Not covered: on this machine the storage write-back test's linear cases do not reach the import route (
GuestMemory::Watchedis false for them), so the test checks that the switch leaves the other routes unchanged, not the retile into a host import itself. The direct route was checked in game only (no visible difference on the world map) and on one GPU.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-17T02:49:37Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
The opt-in route is correct by reading at head
023ea7bc27, and the default path is unchanged while the switch is off.What I ran
Head
023ea7bc27df33d1ba15c3b40f8565aea1cd1501, basemain. No build and no test was run here; the reader was used to read the repository at head.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp:9706: the host-retile expectation applies only when the surface is watched and linear. The description says those cases do not reach the import route on this machine. Soagc_storage_write_back_host_retiledoes not check that the new route retiles into the import; with the switch set, the checks at lines 9707 and 9709 cannot fail for it. The test shows that the other routes are unchanged, nothing more.core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:148: the[import-writeback] (10 s)line prints the counts since the last print. After a quiet gap it covers more than 10 s, and the last window before traffic stops is never printed. The label or the window logic should match.docs/dev/ENVIRONMENT.md:243: "(discrete GPUs)" is an inference from the heap flag thatHostImportDeviceLocalchecks. "outside a device-local heap" alone is what the code tests.Sources
github.com/boykopovar/AnyPS5@023ea7bc27/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp (L7652-L7660)github.com/boykopovar/AnyPS5@023ea7bc27/core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp (L60-L62)github.com/boykopovar/AnyPS5@023ea7bc27/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp (L757-L771)Not verified
vk_meta_get_pipeline_layoutcost is in Mesa, not in this repository.aps5-trace-e4caa07950f8-3424790.json.gz, are not in the review folder. The performance figures were checked only against the digests in the description, and the separateAPS5_PIPELINE_STATS=2counts were not checked.Texture.cpp(the changed hunks, head 130-155 and 7600-7760, and the import helpers they call);Recorder.cpp(the changed hunk and head 9690-9715); the cmake file andENVIRONMENT.mdin full from the diff. Not read: the rest ofTexture.cpp(7,988 lines) and ofRecorder.cpp(17,860 lines). Excluded by rule: none.To get this to a good state
Nothing is required.