Repository navigation
perf(libSceAgc): snapshot WRITE_DATA payloads without heap allocation - #19802
Conversation
WriteData copies the caller's payload before Allocate, because the out-of-space callback may rewrite or move the memory it points into. The copy was a std::vector, so every sceAgcDcbWriteData and sceAgcAcbWriteData call made one heap allocation. Payloads of up to 64 dwords are now copied into stack storage and larger ones into a heap buffer, still before the callback runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
This pull request is labeled |
|
Windows check of head
This is a correctness check only; I did not measure the performance effect. AI-assisted: yes. |
|
Some 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.
|
|
Performance captures for head Setup: ASTRO BOT (PPSA21564, content 01.007.000), Windows 11 Pro 26300, Ryzen 5 9600X, NVIDIA GeForce RTX 5070 Ti (driver 621.14), 3840x2160, Release, warm shader cache (0 misses). Same relinked
Result: no frame-time change I can claim. The change is never slower, but the paired p50 gap shrinks from 2.0 to 0.8 to 0.4 ms. GPU busy time per present is the same, and The traces are 4.3 to 4.4 MB each; I can attach them on request. main-3 aps5-summary.jsonl linechange-3 aps5-summary.jsonl linemain-3 trace_digest.pyseconds 200:20 from present 4992: 469 presents, frame p50 42.7 / p90 44.0 / p99 45.1 / max 50.3 ms, GPU busy 35.9 ms per present {"commit":"d36ce95e83f4","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"200:20"},"gpu":"NVIDIA GeForce RTX 5070 Ti","driver":"NVIDIA 621.14","os":"Windows 10.0.26300","cpu":"AMD Ryzen 5 9600X 6-Core Processor","cpu_threads":12,"memory_mib":31861,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"seconds 200:20","first_present":4992,"ms":20018.474},"presents":469,"frame_ms":{"p50":42.748,"p90":44.013,"p99":45.137,"max":50.305},"gpu_busy_ms_per_present":35.894,"worker_busy_pct":{"queue worker 0x0":99.007,"queue worker 0x40":99.778,"queue worker 0x48":94.633,"queue worker 0x3a":0.0},"phase_totals_ms":{"Driver.Completion":37.448,"Driver.Dispatch":3264.264,"Driver.Dispatch.capture_resources":261.852,"Driver.Dispatch.decode_key_device_setup":54.565,"Driver.Dispatch.lookup_cache":64.215,"Driver.Dispatch.materialize":10.335,"Driver.Dispatch.prepared_invocation":8.976,"Driver.Draw":5257.65,"Driver.Draw.device_setup":94.636,"Driver.Draw.draw_enqueued":2823.234,"Driver.Draw.post_compile_prepare":26.573,"Driver.Draw.prepare":242.172,"Driver.Draw.shader_compile_and_link":1877.595,"Driver.EndSubmission":369.01,"Driver.Packet":58331.121,"Driver.Packet.device_lock":62.91,"Driver.Packet.dispatch":4189.739,"Driver.Packet.draw":5283.647,"Driver.Packet.execute":532.686,"Driver.Packet.flip_flush":15.74,"Driver.Packet.flush_between_packets":538.022,"Driver.Packet.memory_wait":37385.252,"Driver.Packet.pipeline_drain":116.701,"Driver.Packet.pipeline_prepare":78.301,"Driver.Packet.prepare_memory":7637.726,"Driver.Packet.rendering_wait":0.487,"Driver.Present":1485.467,"Driver.Present.acquire_image":6.387,"Driver.Present.device_setup":0.161,"Driver.Present.gpu_mutex_wait":0.774,"Driver.Present.inflight_wait":1.125,"Driver.Present.present_display_buffer":65.464,"Driver.Present.queue_present":169.123,"Driver.Present.release_and_callback":0.535,"Driver.Present.render_fence_wait":1240.71,"Driver.Present.resize":0.794,"Driver.Present.validate":0.171,"Driver.Suspend":0.153,"GpuMutex.wait.dispatch":428.711,"GpuMutex.wait.draw":477.742,"GpuMutex.wait.end":142.736,"GpuMutex.wait.fill":68.66,"GpuMutex.wait.flush":81.874,"GpuMutex.wait.hook":0.554,"GpuMutex.wait.indirect":0.0,"GpuMutex.wait.label":297.053,"GpuMutex.wait.present":0.003,"GpuMutex.wait.wait":173.638,"Graphics.Draw":4668.918,"Graphics.Draw.draw_and_resource_release":4255.14,"Graphics.Draw.index_upload":98.382,"Graphics.Draw.validate":178.998,"Graphics.Draw.vertex_upload":110.043,"Graphics.DrawWithRecipe":30.174,"Graphics.DrawWithRecipe.draw_and_resource_release":28.108,"Graphics.DrawWithRecipe.index_upload":0.039,"Graphics.DrawWithRecipe.validate":0.337,"Graphics.DrawWithRecipe.vertex_upload":1.492,"Recorder.Reap":370.232,"Recorder.Submit":796.527,"Recorder.WaitSerial":6975.101,"Resources.Complete":366.107,"Resources.Prepare":736.961,"Shader.DrawStage":1411.467,"Shader.DrawStage.capture_resources":1059.201,"Shader.DrawStage.materialize":206.851,"Shader.DrawStage.prepared_invocation":137.812,"Shader.ResolveAbi":48.185,"Shader.ResolveGraphicsAbi":21.304,"Shader.ResolveGraphicsStagesAbi":172.854,"VideoOut.Flip":1520.221,"VideoOut.Flip.completion_mutex_wait":0.5,"VideoOut.Flip.config_mutex_wait":0.044,"VideoOut.Flip.frame_limit":0.242,"VideoOut.Flip.notify_game":6.533,"VideoOut.Flip.present":1483.177,"VideoOut.Flip.validate":0.5,"VideoOut.Flip.vblank_wait":0.299,"VideoOut.Flip.window_prepare":0.737,"VideoOut.Flip.window_title":27.938,"VideoOut.Readiness":1.055,"VideoOut.Readiness.locks_validate":0.411,"Vulkan.Acquire":5.923,"Vulkan.Acquire.acquire_fence_wait":0.838,"Vulkan.Acquire.acquire_image":3.966,"Vulkan.Acquire.fence_reset":0.771,"Vulkan.Acquire.retired_swapchains":0.212,"Vulkan.Dispatch":1427.05,"Vulkan.Dispatch.command_record":297.323,"Vulkan.Dispatch.shader_resources":1125.212,"Vulkan.DispatchRecipe":64.736,"Vulkan.DispatchRecipe.command_record":64.297,"Vulkan.DrawFromRecipe":30.436,"Vulkan.Present":45.576,"Vulkan.Present.command_record_scale":21.205,"Vulkan.Present.pixel_upload":0.822,"Vulkan.Present.queue_submit":23.253,"Vulkan.QueuePresent":168.505,"Vulkan.QueuePresent.queue_present":167.803,"Vulkan.Retire":1240.503,"Vulkan.Retire.wait":1232.649},"top_phases_ms_per_frame":{"Driver.Packet":124.373,"Driver.Packet.memory_wait":79.713,"Driver.Packet.prepare_memory":16.285,"Recorder.WaitSerial":14.872,"Driver.Packet.draw":11.266,"Driver.Draw":11.21,"Graphics.Draw":9.955,"Graphics.Draw.draw_and_resource_release":9.073},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":5628,"Graphics.Barrier.dcc-clear":5628,"Graphics.Barrier.dcc-keys":5628,"Graphics.Barrier.dispatch-lead":35087,"Graphics.Barrier.dispatch-trail":30485,"Graphics.Barrier.draw":54676,"Graphics.Barrier.fill":13343,"Graphics.Barrier.fill-clear":6566,"Graphics.Barrier.indirect-args":3283,"Graphics.Barrier.label-run":77063,"Graphics.Barrier.present-blit":938,"Graphics.Barrier.shadow-publish":2814,"Graphics.Barrier.staging-in":11706,"Graphics.Barrier.staging-out":3752,"Graphics.Barrier.storage-upload":15946,"Graphics.Barrier.storage-writeback":66598,"Graphics.BarrierMerged.dispatch-lead":1964,"Graphics.BarrierMerged.fill":3541,"Graphics.BarrierMerged.label-run":21,"Graphics.BarrierMerged.shadow-publish":1876,"Graphics.BarrierMerged.staging-in":482,"Graphics.BarrierMerged.staging-out":3752,"Graphics.BarrierMerged.storage-writeback":10945,"Graphics.Copy":24253,"Graphics.Copy.bytes":22725712344,"Graphics.RenderPass":21910,"Graphics.RenderPass.Close.command":8084,"Graphics.RenderPass.Close.image":2360,"Graphics.RenderPass.Close.key":1092,"Graphics.RenderPass.Close.label":21,"Graphics.RenderPass.Close.new-batch":10353,"Graphics.RenderPass.Continued":96847},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":13.31,"events_lost":143457,"totals_full":false}},"trace":"aps5-trace-d36ce95e83f4-13220.json.gz"}Incomplete 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 107.1, Driver.Packet.memory_wait 73.8, batch 35.9, Driver.Packet.prepare_memory 16.1, Recorder.WaitSerial 14.9, Graphics.Draw 8.2, Graphics.Draw.draw_and_resource_release 7.5, Driver.Packet.dispatch 6.7, Driver.Packet.draw 6.6, Driver.Draw 6.6 Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
change-3 trace_digest.pyseconds 200:20 from present 5032: 474 presents, frame p50 42.3 / p90 43.5 / p99 44.9 / max 47.1 ms, GPU busy 35.9 ms per present {"commit":"d36ce95e83f4","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"200:20"},"gpu":"NVIDIA GeForce RTX 5070 Ti","driver":"NVIDIA 621.14","os":"Windows 10.0.26300","cpu":"AMD Ryzen 5 9600X 6-Core Processor","cpu_threads":12,"memory_mib":31861,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"seconds 200:20","first_present":5032,"ms":20039.253},"presents":474,"frame_ms":{"p50":42.293,"p90":43.477,"p99":44.922,"max":47.144},"gpu_busy_ms_per_present":35.907,"worker_busy_pct":{"queue worker 0x0":99.006,"queue worker 0x40":99.791,"queue worker 0x48":93.978,"queue worker 0x3a":0.0},"phase_totals_ms":{"Driver.Completion":35.728,"Driver.Dispatch":3276.143,"Driver.Dispatch.capture_resources":273.685,"Driver.Dispatch.decode_key_device_setup":55.698,"Driver.Dispatch.lookup_cache":64.534,"Driver.Dispatch.materialize":10.183,"Driver.Dispatch.prepared_invocation":8.828,"Driver.Draw":4952.575,"Driver.Draw.device_setup":97.582,"Driver.Draw.draw_enqueued":2524.315,"Driver.Draw.post_compile_prepare":24.735,"Driver.Draw.prepare":241.939,"Driver.Draw.shader_compile_and_link":1867.426,"Driver.EndSubmission":362.098,"Driver.Packet":58271.913,"Driver.Packet.device_lock":63.214,"Driver.Packet.dispatch":4209.849,"Driver.Packet.draw":4979.295,"Driver.Packet.execute":558.606,"Driver.Packet.flip_flush":15.801,"Driver.Packet.flush_between_packets":582.566,"Driver.Packet.memory_wait":37252.9,"Driver.Packet.pipeline_drain":119.938,"Driver.Packet.pipeline_prepare":79.286,"Driver.Packet.prepare_memory":7925.086,"Driver.Packet.rendering_wait":0.507,"Driver.Present":1668.285,"Driver.Present.acquire_image":6.225,"Driver.Present.device_setup":0.158,"Driver.Present.gpu_mutex_wait":0.765,"Driver.Present.inflight_wait":1.139,"Driver.Present.present_display_buffer":64.549,"Driver.Present.queue_present":166.776,"Driver.Present.release_and_callback":0.536,"Driver.Present.render_fence_wait":1426.978,"Driver.Present.resize":0.798,"Driver.Present.validate":0.139,"Driver.Suspend":0.135,"GpuMutex.wait.dispatch":407.578,"GpuMutex.wait.draw":480.71,"GpuMutex.wait.end":167.284,"GpuMutex.wait.fill":77.895,"GpuMutex.wait.flush":84.016,"GpuMutex.wait.hook":0.017,"GpuMutex.wait.indirect":0.001,"GpuMutex.wait.label":293.191,"GpuMutex.wait.present":0.007,"GpuMutex.wait.wait":124.314,"Graphics.Draw":4643.904,"Graphics.Draw.draw_and_resource_release":4234.69,"Graphics.Draw.index_upload":98.033,"Graphics.Draw.validate":175.78,"Graphics.Draw.vertex_upload":109.418,"Graphics.DrawWithRecipe":31.77,"Graphics.DrawWithRecipe.draw_and_resource_release":29.535,"Graphics.DrawWithRecipe.index_upload":0.051,"Graphics.DrawWithRecipe.validate":0.389,"Graphics.DrawWithRecipe.vertex_upload":1.555,"Recorder.Reap":365.487,"Recorder.Submit":779.83,"Recorder.WaitSerial":7369.798,"Resources.Complete":378.179,"Resources.Prepare":725.901,"Shader.DrawStage":1401.151,"Shader.DrawStage.capture_resources":1057.699,"Shader.DrawStage.materialize":205.388,"Shader.DrawStage.prepared_invocation":130.349,"Shader.ResolveAbi":49.534,"Shader.ResolveGraphicsAbi":24.27,"Shader.ResolveGraphicsStagesAbi":180.905,"VideoOut.Flip":1721.233,"VideoOut.Flip.completion_mutex_wait":0.504,"VideoOut.Flip.config_mutex_wait":0.036,"VideoOut.Flip.frame_limit":0.247,"VideoOut.Flip.notify_game":23.447,"VideoOut.Flip.present":1666.789,"VideoOut.Flip.validate":0.47,"VideoOut.Flip.vblank_wait":0.318,"VideoOut.Flip.window_prepare":0.746,"VideoOut.Flip.window_title":28.289,"VideoOut.Readiness":1.049,"VideoOut.Readiness.locks_validate":0.421,"Vulkan.Acquire":5.778,"Vulkan.Acquire.acquire_fence_wait":0.766,"Vulkan.Acquire.acquire_image":3.879,"Vulkan.Acquire.fence_reset":0.822,"Vulkan.Acquire.retired_swapchains":0.182,"Vulkan.Dispatch":1444.401,"Vulkan.Dispatch.command_record":303.407,"Vulkan.Dispatch.shader_resources":1136.28,"Vulkan.DispatchRecipe":64.556,"Vulkan.DispatchRecipe.command_record":64.155,"Vulkan.DrawFromRecipe":32.106,"Vulkan.Present":44.834,"Vulkan.Present.command_record_scale":20.702,"Vulkan.Present.pixel_upload":0.831,"Vulkan.Present.queue_submit":22.997,"Vulkan.QueuePresent":166.175,"Vulkan.QueuePresent.queue_present":165.468,"Vulkan.Retire":1426.808,"Vulkan.Retire.wait":1418.899},"top_phases_ms_per_frame":{"Driver.Packet":122.937,"Driver.Packet.memory_wait":78.593,"Driver.Packet.prepare_memory":16.72,"Recorder.WaitSerial":15.548,"Driver.Packet.draw":10.505,"Driver.Draw":10.448,"Graphics.Draw":9.797,"Graphics.Draw.draw_and_resource_release":8.934},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":5688,"Graphics.Barrier.dcc-clear":5688,"Graphics.Barrier.dcc-keys":5688,"Graphics.Barrier.dispatch-lead":35452,"Graphics.Barrier.dispatch-trail":30810,"Graphics.Barrier.draw":55349,"Graphics.Barrier.fill":13466,"Graphics.Barrier.fill-clear":6636,"Graphics.Barrier.indirect-args":3318,"Graphics.Barrier.label-run":77815,"Graphics.Barrier.present-blit":948,"Graphics.Barrier.shadow-publish":2844,"Graphics.Barrier.staging-in":11811,"Graphics.Barrier.staging-out":3792,"Graphics.Barrier.storage-upload":16116,"Graphics.Barrier.storage-writeback":67308,"Graphics.BarrierMerged.dispatch-lead":1994,"Graphics.BarrierMerged.fill":3598,"Graphics.BarrierMerged.label-run":24,"Graphics.BarrierMerged.shadow-publish":1896,"Graphics.BarrierMerged.staging-in":505,"Graphics.BarrierMerged.staging-out":3792,"Graphics.BarrierMerged.storage-writeback":11035,"Graphics.Copy":24517,"Graphics.Copy.bytes":22967990752,"Graphics.RenderPass":22199,"Graphics.RenderPass.Close.command":8273,"Graphics.RenderPass.Close.image":2383,"Graphics.RenderPass.Close.key":1092,"Graphics.RenderPass.Close.label":24,"Graphics.RenderPass.Close.new-batch":10427,"Graphics.RenderPass.Continued":98891},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":13.851,"events_lost":123394,"totals_full":false}},"trace":"aps5-trace-d36ce95e83f4-20688.json.gz"}Incomplete 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 106.8, Driver.Packet.memory_wait 73.0, batch 36.0, Driver.Packet.prepare_memory 16.5, Recorder.WaitSerial 15.5, Graphics.Draw 8.0, Graphics.Draw.draw_and_resource_release 7.3, Driver.Packet.dispatch 6.8, Driver.Packet.draw 6.3, Driver.Draw 6.3 Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
On the overlap note: #19191 changes AI-assisted: yes. |
What
WriteData(behindsceAgcDcbWriteDataandsceAgcAcbWriteData) copies the caller's payload beforeAllocate, because the out-of-space callback may rewrite or move the memory the payload points into. The copy was astd::vector, so every call made one heap allocation. Payloads of up to 64 dwords are now copied into stack storage, larger ones into a heap buffer as before. The copy is still taken before the callback runs.testWriteDataReadsPayloadBeforeCallbackintests/CopyData.cppputs the payload inside the buffer that the callback clobbers, with 4, 64, 65 and 100 dwords (both sides of the inline limit), for DCB and ACB. It fails if the snapshot is removed.The same pattern in
WriteRegisterRange/WriteRegisters(Packet.cpp) is left alone: #18914 already changes it.Tested
Windows 11 Pro 26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (
x86_64-ucrt-posix-seh), Release.libSceAgcCTests pass, including the new case.libSceAgc.prxdiffers between the two runtimes:c9a1545e8c)sceAgcDcbWriteData(4 dwords)sceAgcDcbSetShRegisterDirect(unchanged, control)APS5_TRACE_SECONDS=200:20, three alternating main/change pairs on this machine with onlylibSceAgc.prxswapped. No frame-time change can be claimed (paired p50 gaps of 2.0, 0.8 and 0.4 ms that shrink with run order, and equal GPU busy time). Summary lines, the table andtrace_digest.pyoutput are in the comment below.agc_driver_frame_replay,agc_driver_pm4_replayandagc_driver_pm4_replay_toolon main and on this PR withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer, validation layer 1.4.368 (Khronos nightly 2026-11-13). Both logs showInsert instance layer "VK_LAYER_KHRONOS_validation"and neither containswas not found but was requested by env var VK_INSTANCE_LAYERS. Both runs pass with 0VUID-lines and 0 validation messages.Benchmark source (not committed)
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)