Skip to content

perf(libSceAgcDriver): stop the idle store for a thread blocked on the GPU mutex - #20145

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
xXPBSXx:k/agc-idle-store-yield2
Nov 15, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
xXPBSXx:k/agc-idle-store-yield2

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

What

When queue 0 has nothing queued, the queue worker stores the pending storage-image results back to guest memory (VulkanDevice::StoreIdleResults, which calls StorageTexture::FlushAllPendingUntil in pieces of 4 MiB) while holding GuestMemory::GpuMutex. Its stop test looks only at the queue state, so a title thread that is blocked on the mutex and therefore has queued nothing does not make it stop: the store runs on, and the title waits behind it.

In Slay The Princess (PPSA24423) on main the title waited behind the idle store for up to 348 to 373 ms (single waits in the 20 s capture windows), and the worker sat in idle_and_completion_poll for up to 1.5 s. This PR adds two things. GpuMutexType::Waiters() counts the threads blocked in lock(), spinning included (a relaxed atomic that is only counted, nothing waits on it). YieldToGpuMutexWaiters(stop) wraps the stop predicate: it never stops before the first piece has been stored, and after that stops as soon as another thread is blocked on the mutex. StoreIdleResults passes it to FlushAllPendingUntil. The rest of the pending results is stored in the next idle round, as before.

Side effects. The counter changes no ordering and cannot deadlock (no thread waits for it). The first piece is always stored, so a mutex that is always contended does not starve the store; a store that yields stores its remaining images in later idle rounds, so the number of submits per image can grow (not measured separately). #16011 makes FlushPending wait for the recorder after a piece of an idle flush, under the mutex; it does not touch this predicate and merges with this change without a conflict, but each piece it stores then holds the mutex for that wait too. #20015 ends the 50 ms quiet-period wait of queue 0 in QueueWorker.cpp when a completion is pending; it is the same idle path but another wait (this change stops a store that is already running for a thread blocked on the mutex), and it merges with this change without a conflict. The tests of #20015 and #16011 were not run on a tree with this change.

What is not claimed: the frames are not free of stalls. With this change, residual stalls remain in some intervals (see the table), for example a 246 ms frame in one capture window where the worker was in idle_and_completion_poll for 239 ms while the title was not blocked on the mutex; I do not know their source.

Tested

Windows 10 Pro, AMD Ryzen 7 5800X3D, NVIDIA GeForce RTX 4080 SUPER (driver NVIDIA 610.74 as shown in the summary lines) and AMD Radeon RX 6400 for the tests. WinLibs GCC Release.

Tests. Two pairs, each test commit failing on main and the following fix commit passing, on the RTX 4080 SUPER: the new CountsMutexWaiters (GpuMutexType::Waiters() is 0 without a waiter and while holding, 1 while a thread is blocked, 0 again afterwards) and StopsForMutexWaiter (with a thread blocked on the mutex an idle store stops after exactly one of two pending images and reports it is not finished; with none it stores both; the result of both stores is in guest memory). Without the fix agc_driver_idle_store_yields aborts, with it it passes; the pairs were run again on main 0f4538fa022 as the base (the series was rebased from 0d2db33e0d5; git range-diff shows the two fix commits unchanged and the two test commits differing only by two comments removed from GuestMemory.hpp), on the RTX 4080 SUPER. With the validation layer (VK_LAYER_KHRONOS_validation, inserted into the device as VK_LOADER_DEBUG=layer shows) the new test program on this head passes on the RTX 4080 SUPER and on the RX 6400 with 0 VUID- lines, and the test commit without the fix aborts at the same place as without the layer on both GPUs. ctest of the 279 tests of agc_driver_* whose name contains draw, pipeline, present, label, recorder, commit, frame_replay, idle, store or mutex, on main 0f4538fa022 and on this head, once each on both GPUs, without the validation layer: the same result in all four runs: one test (agc_driver_write_data_written_ahead_draw_pipeline) fails the same way on main and on this head in all four full runs, but passes in 12 of 12 separate runs of that test alone (3 per arm and GPU), so it depends on the run of the whole group and not on this change; three tests were not run in the full runs because their programs were not built (agc_driver_batch_cap_wait_draw_pipeline, agc_driver_color_write_mask_dynamic_in_pipeline, agc_driver_prepared_shaders_abi_deferred_background_draw) and pass when built and run (3 of 3 on each arm and GPU); and agc_driver_present_upscale and agc_driver_partially_committed_volume_page_samples skip themselves (on the RX 6400 agc_driver_copied_writer_label_order and _drain skip as well). On the earlier base 0d2db33e0d5 the same run over 267 tests had no failing test (24 programs not built in the first pass passed in a second pass on each arm and GPU). The validation layer crashes in most of the other tests on the base too, so I do not claim that no new validation message appears outside the new test program.

Frame stalls, PPSA24423, measured on the earlier base 0d2db33e0d5 (A) and the head before the rebase 0a74e649147 (B), 1920x1080, 600 s runs, APS5_TRACE_SUMMARY_EVERY=10, APS5_TRACE_SECONDS=300:20, APS5_TRACE_EVENTS=2097152, no APS5_PROFILE_DRAW, arms interleaved (B A B A B A B A), same session. A stall interval is a 10 s interval from 60 s on whose longest frame is over 40 ms; the scene differs between runs (title state, not controlled), so the share per run varies from 24 to 83 %.

run arm intervals stall intervals share longest frame, median of intervals (ms) title wait on the GPU mutex over 50 ms in the capture window (count, longest)
1 head 47 18 38 % 17 0 (4 ms)
2 main 49 37 76 % 490 1 (348 ms)
3 head 49 38 78 % 225 0 (18 ms)
4 main 46 38 83 % 566 3 (373 ms)
5 head 51 33 65 % 121 0 (4 ms)
6 main 49 35 71 % 470 0 (11 ms)
7 head 38 9 24 % 18 0 (19 ms)
8 main 51 32 63 % 442 0 (4 ms)

Over the four pairs there were fewer stall intervals with the change (the rebased series differs only by two removed comments): 98 of 185 (53 %) against 142 of 195 (73 %), and the head is lower in all four pairs (38 against 76, 78 against 83, 65 against 71, 24 against 63 %). In the capture windows (one 20 s window per run) the title waited on the mutex for more than 50 ms in two of the four main windows (1 and 3 waits, up to 348 and 373 ms) and in none of the four head windows (up to 19 ms); in the other two main windows it did not wait either (up to 11 ms) although those runs had stall intervals, so stalls also have other sources. The longest wait of the worker in idle_and_completion_poll in a window was 238 ms with the change and 1548 ms on main. Presents per 10 s: medians 544 to 600 with the change, 530 to 572 on main; frame time p50 about 16.7 to 16.9 ms in all runs (the title runs at 60 fps between stalls).

VK_ERROR_DEVICE_LOST: 0 of the 8 runs ended that way (title and arm). The GPU was also used by other jobs of the machine's owner: nvidia-smi every 30 s for runs 5 to 8: mean 18, 27, 15 and 20 % (single readings 1 to 45 %); there are no readings for runs 1 to 4 (the log of that series was overwritten). Working set maximum of the process in runs 5 to 8: 3978 and 4192 MiB with the change (runs 7 and 5) against 4106 and 4639 MiB on main (runs 8 and 6), so it is not larger with the change.

The summary line of one capture window of each commit (main run 2, head run 1) and the digests are below; the traces are attached.

{"commit":"0d2db33e0d50","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_EVENTS":"2097152","APS5_TRACE_SECONDS":"300:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 610.74","os":"Windows 10.0.19045","cpu":"AMD Ryzen 7 5800X3D 8-Core Processor","cpu_threads":16,"memory_mib":65459,"title_id":"PPSA24423","title":"Slay The Princess","content_version":"02.003.000","resolution":"1920x1080","window":{"spec":"seconds 300:20","first_present":13613,"ms":20003.381},"presents":1117,"frame_ms":{"p50":16.943,"p90":17.017,"p99":17.086,"max":1362.647},"gpu_busy_ms_per_present":0.691,"worker_busy_pct":{"queue worker 0x0":87.218},"phase_totals_ms":{"Driver.Completion":0.802,"Driver.Draw":4752.441,"Driver.Draw.device_setup":238.515,"Driver.Draw.draw_enqueued":1075.831,"Driver.Draw.post_compile_prepare":48.264,"Driver.Draw.prepare":313.123,"Driver.Draw.shader_compile_and_link":2983.305,"Driver.EndSubmission":1.041,"Driver.Packet":17444.543,"Driver.Packet.device_lock":43.407,"Driver.Packet.draw":4820.134,"Driver.Packet.execute":262.693,"Driver.Packet.flip_flush":71.328,"Driver.Packet.flush_between_packets":144.222,"Driver.Packet.pipeline_drain":327.45,"Driver.Packet.pipeline_prepare":74.109,"Driver.Packet.prepare_memory":72.405,"Driver.Packet.rendering_wait":11560.889,"Driver.Present":365.468,"Driver.Present.acquire_image":17.538,"Driver.Present.device_setup":0.596,"Driver.Present.gpu_mutex_wait":2.552,"Driver.Present.inflight_wait":3.832,"Driver.Present.present_display_buffer":133.697,"Driver.Present.queue_present":105.013,"Driver.Present.release_and_callback":4.795,"Driver.Present.render_fence_wait":94.377,"Driver.Present.resize":1.777,"Driver.Present.validate":0.454,"Driver.Suspend":0.217,"GpuMutex.wait.draw":1.813,"GpuMutex.wait.end":0.0,"GpuMutex.wait.other":347.77,"GpuMutex.wait.present":0.313,"GpuMutex.wait.wait":27.129,"Graphics.Draw":5072.271,"Graphics.Draw.draw_and_resource_release":2498.637,"Graphics.Draw.index_upload":823.872,"Graphics.Draw.validate":245.117,"Graphics.Draw.vertex_upload":1436.688,"Graphics.Submit":1.127,"Graphics.Submit.command_end":0.064,"Graphics.Submit.queue_submit":1.048,"Graphics.Wait":230.413,"Graphics.Wait.fence_wait":230.37,"Recorder.Reap":24.88,"Recorder.Submit":188.458,"Recorder.WaitSerial":417.008,"Resources.Complete":89.821,"Resources.Prepare":16.837,"Shader.DrawStage":1616.536,"Shader.DrawStage.capture_resources":475.528,"Shader.DrawStage.materialize":734.904,"Shader.DrawStage.prepared_invocation":386.46,"Shader.ResolveAbi":979.222,"Shader.ResolveGraphicsAbi":1243.86,"Shader.ResolveGraphicsStagesAbi":1529.436,"VideoOut.Flip":18027.448,"VideoOut.Flip.completion_mutex_wait":1.821,"VideoOut.Flip.config_mutex_wait":0.169,"VideoOut.Flip.frame_limit":3.121,"VideoOut.Flip.notify_game":72.301,"VideoOut.Flip.present":370.055,"VideoOut.Flip.validate":1.343,"VideoOut.Flip.vblank_wait":17503.812,"VideoOut.Flip.window_prepare":1.915,"VideoOut.Flip.window_title":71.724,"VideoOut.Readiness":2.583,"VideoOut.Readiness.locks_validate":0.808,"Vulkan.Acquire":16.412,"Vulkan.Acquire.acquire_fence_wait":2.74,"Vulkan.Acquire.acquire_image":10.312,"Vulkan.Acquire.fence_reset":2.392,"Vulkan.Acquire.retired_swapchains":0.599,"Vulkan.Present":86.214,"Vulkan.Present.command_record_scale":37.164,"Vulkan.Present.pixel_upload":2.498,"Vulkan.Present.queue_submit":45.454,"Vulkan.QueuePresent":103.009,"Vulkan.QueuePresent.queue_present":101.126,"Vulkan.Retire":94.641,"Vulkan.Retire.wait":88.309},"top_phases_ms_per_frame":{"VideoOut.Flip":16.139,"VideoOut.Flip.vblank_wait":15.67,"Driver.Packet":15.617,"Driver.Packet.rendering_wait":10.35,"Graphics.Draw":4.541,"Driver.Packet.draw":4.315,"Driver.Draw":4.255,"Driver.Draw.shader_compile_and_link":2.671},"owned_draw_counts":{"OwnedDraw.evicted_other":4876},"graphics_track":{"Graphics.Barrier.draw":7897,"Graphics.Barrier.label-run":2224,"Graphics.Barrier.present-blit":4468,"Graphics.Barrier.shadow-publish":1,"Graphics.Barrier.storage-upload":212,"Graphics.Barrier.storage-writeback":33,"Graphics.BarrierMerged.shadow-publish":1,"Graphics.BarrierMerged.storage-writeback":1,"Graphics.Copy":56,"Graphics.Copy.bytes":2359820288,"Graphics.RenderPass":2668,"Graphics.RenderPass.Close.command":102,"Graphics.RenderPass.Close.new-batch":2566,"Graphics.RenderPass.Continued":110554},"trace_dropped":false,"trace":"aps5-trace-0d2db33e0d50-32260.json.gz"}
{"commit":"0a74e649147e","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PLAYGO_UNLISTED_CHUNKS":"absent","APS5_TRACE_EVENTS":"2097152","APS5_TRACE_SECONDS":"300:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 610.74","os":"Windows 10.0.19045","cpu":"AMD Ryzen 7 5800X3D 8-Core Processor","cpu_threads":16,"memory_mib":65459,"title_id":"PPSA24423","title":"Slay The Princess","content_version":"02.003.000","resolution":"1920x1080","window":{"spec":"seconds 300:20","first_present":14410,"ms":20003.836},"presents":1199,"frame_ms":{"p50":16.71,"p90":17.0,"p99":17.057,"max":17.378},"gpu_busy_ms_per_present":0.47,"worker_busy_pct":{"queue worker 0x0":95.292},"phase_totals_ms":{"Driver.Completion":0.896,"Driver.Draw":2432.054,"Driver.Draw.device_setup":104.839,"Driver.Draw.draw_enqueued":1441.18,"Driver.Draw.post_compile_prepare":21.716,"Driver.Draw.prepare":153.067,"Driver.Draw.shader_compile_and_link":659.491,"Driver.EndSubmission":0.988,"Driver.Packet":19059.955,"Driver.Packet.device_lock":18.425,"Driver.Packet.draw":2459.856,"Driver.Packet.execute":119.215,"Driver.Packet.flip_flush":67.129,"Driver.Packet.flush_between_packets":62.976,"Driver.Packet.memory_wait":0.036,"Driver.Packet.pipeline_drain":387.315,"Driver.Packet.pipeline_prepare":30.396,"Driver.Packet.prepare_memory":30.085,"Driver.Packet.rendering_wait":15657.053,"Driver.Present":419.885,"Driver.Present.acquire_image":19.584,"Driver.Present.device_setup":0.636,"Driver.Present.gpu_mutex_wait":15.193,"Driver.Present.inflight_wait":3.619,"Driver.Present.present_display_buffer":150.657,"Driver.Present.queue_present":113.377,"Driver.Present.release_and_callback":5.743,"Driver.Present.render_fence_wait":107.558,"Driver.Present.resize":2.039,"Driver.Present.validate":0.483,"Driver.Suspend":0.23,"GpuMutex.wait.draw":2.443,"GpuMutex.wait.end":0.188,"GpuMutex.wait.flush":0.151,"GpuMutex.wait.label":0.01,"GpuMutex.wait.present":12.54,"GpuMutex.wait.wait":0.398,"Graphics.Draw":2692.947,"Graphics.Draw.draw_and_resource_release":1665.175,"Graphics.Draw.index_upload":427.892,"Graphics.Draw.validate":88.466,"Graphics.Draw.vertex_upload":486.034,"Graphics.DrawWithRecipe":229.571,"Graphics.DrawWithRecipe.draw_and_resource_release":171.018,"Graphics.DrawWithRecipe.index_upload":24.595,"Graphics.DrawWithRecipe.validate":2.716,"Graphics.DrawWithRecipe.vertex_upload":29.982,"Recorder.Reap":13.489,"Recorder.Submit":161.623,"Recorder.Sync":91.191,"Recorder.WaitSerial":366.768,"Resources.Complete":98.091,"Resources.Prepare":32.313,"Shader.DrawStage":238.214,"Shader.DrawStage.capture_resources":67.106,"Shader.DrawStage.materialize":118.39,"Shader.DrawStage.prepared_invocation":50.044,"Shader.ResolveAbi":395.124,"Shader.ResolveGraphicsAbi":516.995,"Shader.ResolveGraphicsStagesAbi":666.129,"VideoOut.Flip":19447.665,"VideoOut.Flip.completion_mutex_wait":2.29,"VideoOut.Flip.config_mutex_wait":0.173,"VideoOut.Flip.frame_limit":3.547,"VideoOut.Flip.notify_game":26.431,"VideoOut.Flip.present":424.771,"VideoOut.Flip.validate":1.486,"VideoOut.Flip.vblank_wait":18908.251,"VideoOut.Flip.window_prepare":2.696,"VideoOut.Flip.window_title":77.329,"VideoOut.Readiness":2.318,"VideoOut.Readiness.locks_validate":0.697,"Vulkan.Acquire":18.246,"Vulkan.Acquire.acquire_fence_wait":3.057,"Vulkan.Acquire.acquire_image":11.33,"Vulkan.Acquire.fence_reset":2.699,"Vulkan.Acquire.retired_swapchains":0.657,"Vulkan.DrawFromRecipe":231.416,"Vulkan.Present":99.602,"Vulkan.Present.command_record_scale":41.217,"Vulkan.Present.pixel_upload":3.092,"Vulkan.Present.queue_submit":54.023,"Vulkan.QueuePresent":111.076,"Vulkan.QueuePresent.queue_present":109.19,"Vulkan.Retire":107.522,"Vulkan.Retire.wait":100.675},"top_phases_ms_per_frame":{"VideoOut.Flip":16.22,"Driver.Packet":15.897,"VideoOut.Flip.vblank_wait":15.77,"Driver.Packet.rendering_wait":13.058,"Graphics.Draw":2.246,"Driver.Packet.draw":2.052,"Driver.Draw":2.028,"Graphics.Draw.draw_and_resource_release":1.389},"owned_draw_counts":{"OwnedDraw.evicted_other":1984},"graphics_track":{"Graphics.Barrier.draw":7504,"Graphics.Barrier.label-run":3640,"Graphics.Barrier.present-blit":4796,"Graphics.Barrier.shadow-publish":58,"Graphics.Barrier.storage-upload":2964,"Graphics.Barrier.storage-writeback":557,"Graphics.BarrierMerged.shadow-publish":56,"Graphics.BarrierMerged.storage-writeback":65,"Graphics.RenderPass":4149,"Graphics.RenderPass.Close.command":918,"Graphics.RenderPass.Close.image":855,"Graphics.RenderPass.Close.key":576,"Graphics.RenderPass.Close.new-batch":1800,"Graphics.RenderPass.Continued":38417},"trace_dropped":false,"trace":"aps5-trace-0a74e649147e-18376.json.gz"}

Overlap: the 97 other open pull requests that change one of the four files of this branch (found by reading the changed files of all 1542 open pull requests at about 16:28 UTC; nearly all of them through VulkanDevice.cpp) were test-merged on 2026-11-14 at about 16:35 UTC against main 32a2f1e1d73 (the branch is based on 0f4538fa022, which is an ancestor of it); the branch merges into main without a conflict. 55 of them already conflict with main without this change and still conflict with it, 42 merge cleanly with and without it; none conflicts only with this change. Three pull requests that touch the same code path through other files were merged with this branch separately, against main 0a32f988315 at about 16:43 UTC: #16011 (Texture.cpp) and #20015 (QueueWorker.cpp, the quiet period's wait) merge cleanly with and without it, #13963 already conflicts with main. The tests of #20015 and #16011 were not run on a tree with this change.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4080 SUPER (driver 32.0.16.1074, NVIDIA 610.74 in the trace summary lines) and AMD Radeon RX 6400 (driver 32.0.21033.3005), versions as reported by Windows, Windows 10 Pro 10.0.19045
  • AI-assisted: yes

xXPBSXx and others added 4 commits November 14, 2026 14:05
…ked on it

The mutex gets a Waiters() reading that stays 0 until the next commit counts the blocked threads.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ked on the GPU mutex

YieldToGpuMutexWaiters returns the stop predicate it is given until the next commit makes it yield.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e GPU mutex

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Attachments for the measurements in the description.

AI-assisted (Claude Code).

@github-actions github-actions Bot added perf Performance change agc libSceAgc* labels Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 1395 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4040 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4472 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4847 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5925 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6192 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6209 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6804 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7002 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7449 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7464 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7643 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8004 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10351 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10652 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10678 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10867 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 11435 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 11436 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 11483 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 12828 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 12904 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 13148 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 14217 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 14218 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 15136 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 15548 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 16372 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 16831 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 17056 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 17611 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 17786 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 18029 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 18078 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 18082 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 18173 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 18293 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 18390 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 18515 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 19071 core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hpp
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 19722 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the implementation and its targeted tests support merging, though I did not run the reported checks myself.

What I ran

Reviewed head 645c18f94226de139809028b89e7ef10e0806907. I read the prepared description, commits, manifest, and diff, plus the changed GuestMemory.hpp, GuestMemory.cpp, and IdleStoreYields.cpp and targeted context in Mutex.hpp, HandoffSpin.hpp, Texture.cpp, and VulkanDevice.cpp. VulkanDevice.cpp was excluded from the prepared full-text files but its changed function was read through the pinned reader. No commands or tests were run.

Results

Check Result Note
Change and call path review passed Waiter count and flush stop behavior inspected
Tests not run Test results in the description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the build, tests, or GPU measurements. The reported Windows and GPU results were not independently verified. Files reviewed: GuestMemory.hpp, GuestMemory.cpp, VulkanDevice.cpp changed function, and IdleStoreYields.cpp; targeted context: Mutex.hpp, HandoffSpin.hpp, and Texture.cpp. No changed files were excluded from source inspection; VulkanDevice.cpp was omitted from the prepared full-text bundle because it was too large, then read through the repository reader.

To get this to a good state

Nothing is required.

@hamdanpor-ctrl

Copy link
Copy Markdown
Contributor

Test report, NVIDIA on Windows: no regressions; agc_driver_idle_store_yields (which this PR extends) passes.

  • GPU: NVIDIA GeForce RTX 3050 Laptop GPU, driver 617.42, Windows 11 Pro (10.0.26300)
  • Build: WinLibs GCC 15.2.0 r7 UCRT, Release, all AGC execution tests built
  • Compared: main at 4da77d3 with fix(tests): set the upload cache test's environment with _putenv_s on Windows #19899 merged (current main does not build on MinGW: UploadCacheReadOnlyFlush.cpp:177: 'setenv' was not declared), and the same tree with 645c18f merged (git merge --no-ff, clean)
  • Environment: ANYPS5_GPU=NVIDIA, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Vulkan SDK 1.4.363.0)
  • Command: ctest --test-dir build -V --parallel 4 -R "^agc_|^request_serializer|shader"
main main + this PR
Passed 1763 1763
Failed 0 0
Skipped 18 18
VUID- lines 0 0
Validation messages 61 61, same IDs
  • agc_driver_idle_store_yields passes on both (1.86 s and 1.85 s), and agc_driver_idle_store_over_unmap passes on both.
  • Every other test has the same result on both sides. The layer loads in both logs and neither reports it missing.
  • No title or trace run, so this is a correctness check only, not a speed measurement.

Single run each. AI-assisted (Claude Code).

@oneandonlydean
oneandonlydean merged commit ef4b938 into boykopovar:main Nov 15, 2026
14 checks passed
@Tamalero

Copy link
Copy Markdown
Contributor

Ironically was checking this same issue and came with a similar resolution for Ratchet and Clank Rift Apart, which causes severe audio desync.
Will test your fix!

VID of the issue: https://youtu.be/C6KJ6T3aJLU

@Tamalero

Copy link
Copy Markdown
Contributor

A second title for this one: Ratchet & Clank: Rift Apart (PPSA01474). It has the same idle-store wait as Slay The Princess, but much longer holds, and I measured it on an RTX 4090 and an AMD V620. With this PR the long holds at the stall are gone on NVIDIA and mostly gone on AMD, and an audible symptom in the opening cutscene mostly goes away.

Where it shows. In the opening cutscene, at the cut that triggers an autosave, the game streams in the next scene. Without this PR, queue 0's idle store writes back hundreds of storage images under GpuMutex there, and the title thread waits behind it. The game nearly stops presenting, and its audio feed starves. Ratchet's and Clank's lines are separate clips cued by the animation. When the animation catches up after the stall, Clank's next line lands on top of Ratchet's.

A/B. Both builds are main eef73731fc with #16053 reverted, because #16053 turns Ratchet's text upside down (#20835). One build has this PR (470f3e7919); the other also reverts it (bf27779f56, git revert -m 1 ef4b9389b6). Both ran with APS5_PROFILE_DRAW=1; the hold times below come from its [lock] queue 0x0 lines (Flush site).

without this PR with it
RTX 4090, at the cut (one driven run each, warm cache)
longest single Flush hold by queue 0, per 10 s 1167–1887 ms in 4 consecutive intervals 18–52 ms
idle write-backs at the cut 814 / 8.9 GiB in one interval none
digital silence in the recorded audio, the minute around the cut 10.3 s 0 s
frame rate around the cut 0.5–0.9 FPS for ~15 s ~1.1–1.6 FPS, briefly
Clank's line over Ratchet's about 5 s about 1.5 s
V620, after the first 400 s (one hands-free run each)
longest single Flush hold 3889 ms 1078 ms
10 s intervals with a hold over 1 s 9 of 46 1 of 46

The remaining long holds with the PR on the 4090 are at boot: 849 ms at about 10 s and 449 ms at about 30 s. For comparison, an older build (main 2cebbe43ee) with APS5_NO_IDLE_STORE=1 had at most 103 ms on the V620 and no interval over 1 s. So the one ~1 s hold left there still comes from somewhere.

The ~1.5 s of overlap left on the 4090 matches the short dip that remains at that cut. It looks like the scene load itself, not the idle store.

Systems and runs
  • Desktop: Linux (kernel 7.3.3), RTX 4090 (24 GB), NVIDIA 620.70.06, GCC 16.2.1, Release. Driven by hand, new game each run, with OBS recording; the silence figure is the count of quarter-seconds below -90 dB in the recorded audio.
  • V620: Ubuntu 24.04 VM (kernel 7.0.0), AMD Radeon Pro V620, Mesa 25.2.8 RADV. Hands-free, Cross every 5 s from about 90 s, new game each run, 900 s cap.
  • Switches in all runs: APS5_PROFILE_DRAW=1. On the V620 also APS5_MAX_COMPUTE_SPIRV_WORDS=2000000 APS5_SKIP_REFUSED_DISPATCHES=1 APS5_HOST_IMPORT_MIB=12288 APS5_PROFILE_GPU=1; no dispatch was dropped.

Tested and written by Claude (AI assistant) on a contributor's machine.

@Tamalero

Copy link
Copy Markdown
Contributor

Follow-up on the "~1 s hold left on the V620" in my comment above: it isn't a gap in this PR. I timed the phases of every idle store that held the GPU mutex for 300 ms or more, in one hands-free Ratchet run on the V620 with this PR (470f3e7919, i.e. #20845's tree).

held 4 MiB pieces slowest piece first waiter seen at stop fired at
895 ms 41 70 ms 894.4 ms 894.4 ms
869 ms 61 41 ms 869.1 ms 869.1 ms
812 ms 51 51 ms 812.2 ms 812.2 ms
544 ms 45 34 ms 543.8 ms 543.8 ms
1,965 ms 72 61 ms 1,963.7 ms 1,963.7 ms

In every case no thread was blocked on the mutex until the end. The first waiter turned up at the piece boundary where the stop fired, so a waiter waits at most for the piece in progress: up to 70 ms here. The lease took at most 7.5 ms and the final submit at most 1.4 ms.

My earlier reading came from the waited behind (holder/site ms) field of the [lock] lines. That field counts holds that ended during a thread's waits, not how long the thread waited, so a waiter that arrives at the end of a 1 s idle store is charged the whole second.

The one tuning point I'd note is the piece time on this GPU: up to 70 ms per 4 MiB piece, which is the longest a waiter can now be held up.

How

A local diagnostic, not proposed: StoreIdleResults wraps the stop test (called before every piece) to time the gaps between calls and sample GpuMutex().Waiters() there, and prints one line for any idle store that holds the mutex for 300 ms or more. AMD Radeon Pro V620, Mesa 25.2.8 RADV, Ubuntu 24.04 VM, 900 s hands-free run with APS5_PROFILE_DRAW=1.

Tested and written by Claude (AI assistant) on a contributor's machine.

@Tamalero

Copy link
Copy Markdown
Contributor

@xXPBSXx a follow-up on the waits that are left, with a piece-size A/B on the AMD V620. The short version: a smaller piece doesn't shorten them, and most of the measurable wait left comes from the first piece, which always runs.

Setup. main de0f3967af (has this PR and #16011), Release, AMD Radeon Pro V620 (RADV, Mesa 25.2.8), Ratchet & Clank: Rift Apart (PPSA01474), hands-free runs of 15 min through the same route. Two local commits, not for upstream: a timing line for every idle store that holds the GPU mutex for 50 ms or more (pieces, the longest piece, when a waiter was first seen, when it stopped), and a switch that replaces the 4 MiB in FlushAllPendingUntil with another size. Each run logged the size it used. One warm-up run, then 4 MiB, 1 MiB, 256 KiB and 4 MiB again.

Piece Stores ≥ 50 ms Longest single piece per store Average per piece in the long stores (0.7–1.6 s) Pieces in those stores
4 MiB (two runs) 21 23–68 ms 13–27 ms 32–67
1 MiB 4 36–75 ms 10–23 ms 31–92
256 KiB 6 25–59 ms 10–21 ms 34–84

A piece 16 times smaller doesn't make the longest piece or the average one shorter, and the number of pieces per store hardly changes. So a step's work isn't bounded by the byte range it is given; it looks like each step writes back a unit (a texture or a level of one) larger than the piece. The shortest wait a waiter can get is then about the largest such write-back, 40–75 ms on this GPU, whatever the piece size.

Where the measurable wait is. In all 13 long stores nothing was waiting until the end, and the store stopped within one piece of a waiter arriving, as intended. The waits are in the short stores: in 8 of the 31 stores a thread was already waiting while the store took its lease (seen 2–10 ms in), and it still waited for the whole first piece, 43–59 ms. That's the first flag in YieldToGpuMutexWaiters, which lets one piece through before waiters are checked so that every store makes progress.

If forward progress can be kept another way, for example by skipping the free first piece when the previous idle store already made progress, those 43–59 ms waits would go. I haven't tried that change. Happy to run it on the same route if you'd like a measurement.

Tested and written by Claude (AI assistant) on a contributor's machine.

@JJenkx

JJenkx commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

For the record: a bisect over Another Crab's Treasure (PPSA20423), AMD RX 6700 XT on Windows, lands on this merge (ef4b9389b6). The cost is in the YieldToGpuMutexWaiters wrapper on the idle store.

On current main (786bc3afa1), passing stop to FlushAllPendingUntil again changes the beach's frame p50 from 88-99 ms to 74-76 ms. Those are three alternated runs per arm, same scene and settings.

With the yield, storage images are left pending in this scene. That fails the fast revalidation proof with pending image, and the T1 refresh replaces the templates the draw recipes point at. About 69k recipe draws per 10 s then miss with template gone, and recipe hits fall from about 129k to 25k.

Full data, the bisect boundary and two untested ideas are in #25535. I'm not asking for a revert, given the Slay The Princess and Ratchet & Clank gains measured here.

AI-assisted: yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants