Skip to content

perf(agc): test the occasional write flag before the trapped overlap scan at a label - #28681

Open
GabbeHags wants to merge 1 commit into
boykopovar:mainfrom
GabbeHags:perf/agc-label-occasional-flag-first
Open

GabbeHags wants to merge 1 commit into
boykopovar:mainfrom
GabbeHags:perf/agc-label-occasional-flag-first

Conversation

@GabbeHags

@GabbeHags GabbeHags commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What

At a label, StorageTexture::StoreReadbackBeforeLabel goes through the pending tiled images of 64 KiB to 1 MiB and stores those written only occasionally. With label read traps on, it first scanned the whole pending list for a trapped image that overlaps, and only then tested writtenOccasionally. Nearly every image fails that test, so the scan was wasted. This PR tests the flag first.

  • Same images stored: an image without the flag was skipped before too. An image with the flag still goes through the scan, and keeps its flag when it covers a trapped image.
  • Where it applies: the scan is compiled on Windows and macOS. On Windows the traps over host pointer imports are set only on NVIDIA's proprietary driver (perf(agc): trap CPU reads of label readbacks and drawn linear targets on Windows #26699), so other Windows drivers gain little or nothing. Linux has no scan here and only gets a load before the exchange.
  • How it was found: perf(agc): trap CPU reads of label readbacks and drawn linear targets on Windows #26699 made Mafia: Definitive Edition's city slower on Windows. In an instrumented build of 5cf487d168 this loop took about 2,400 ms per 10 s, on the thread that commits draws. It visited 11 to 16 million images in that time and 50 to 70 of them had the flag set. With the flag tested first it took 77 ms.
  • Not covered: with traps on, an import over a run that holds a trapped page is still refused, and the buffer is copied instead. That is a separate change.

No new test: the stored images do not change, and agc_driver_recorder and agc_small_tiled_shadow_label already cover labels with large and small images under traps.

tools/pr_overlap.py --branch could not compare 30 open PRs that conflict with main. I checked their diffs of Texture.cpp: two edit this function. #9508 changes the header of the same loop (it iterates over a candidate list) and #20183 changes another loop. Neither makes this change.

Tested

Windows 11 (10.0.26200), NVIDIA GeForce RTX 2070 SUPER, driver 617.14, 3840x2160, AMD Ryzen 7 7800X3D. WinLibs GCC, Release.

Mafia: Definitive Edition (PPSA36458, 01.002.000), loading a save into the city, with Cross pressed every second as the only input. main is 4131f5185a and the change is d8d603d4f5, both clean builds with their full library set. The order was change, main, main, change. Each run had APS5_TRACE_SUMMARY_EVERY=2, APS5_TRACE_SECONDS=100:10 and APS5_TRACE_EVENTS=1048576.

main this PR
city, median fps of the 2 s intervals 4.91 / 5.00 7.09 / 7.34
seconds 100:10, frame p50 220.3 / 208.3 ms 138.3 / 128.8 ms
seconds 100:10, frame p99 230.1 / 232.6 ms 161.1 / 147.5 ms
seconds 100:10, Driver.Packet per frame 217.5 / 206.3 ms 127.4 / 122.0 ms
seconds 100:10, render passes closed by a new batch, per frame 713 / 612 160 / 296

The city medians use the intervals below 12 fps with more than 40 ms of GPU time per present, without the first five. Both runs of the change are faster than both runs of main. The traces are attached.

Focused tests on main and this PR with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer (validation layer 1.4.363), ctest -R "^(agc_driver_label_ordered_flush|agc_driver_linear_target_completion|agc_read_trap|agc_recorder|agc_driver_recorder|agc_small_tiled|windows_read_trap|agc_driver_small_tiled)" -V: 37 of 37 pass on both. Each log shows Insert instance layer "VK_LAYER_KHRONOS_validation" 27 times, no was not found line and no VUID-. tools/check_conventions.py passes.

Not run: Linux, macOS, other GPUs, the full test suite.

Summary lines (change 1, main 1, main 2, change 2)
{"commit":"d8d603d4f5f2","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_NET_DISCONNECTED":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"100:10","APS5_TRACE_SUMMARY_EVERY":"2"},"gpu":"NVIDIA GeForce RTX 2070 SUPER","driver":"NVIDIA 617.14","os":"Windows 10.0.26200","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32418,"title_id":"PPSA36458","title":"Mafia: Definitive Edition for PS5®","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"seconds 100:10","first_present":3363,"ms":10028.561},"presents":72,"frame_ms":{"p50":138.265,"p90":143.070,"p99":161.131,"max":161.131},"gpu_busy_ms_per_present":107.658,"worker_busy_pct":{"queue worker 0x0":91.633},"phase_totals_ms":{"DrawPipeline.Drain.packet.flip":55.008,"DrawPipeline.Drain.packet.metadata_pass":648.877,"DrawPipeline.Drain.packet.not_candidate":451.277,"DrawPipeline.Drain.packet.rendering":8.768,"DrawPipeline.Drain.submission.suspend":18.097,"Driver.Completion":0.303,"Driver.Dispatch":1881.320,"Driver.Dispatch.capture_resources":47.762,"Driver.Dispatch.decode_key_device_setup":460.059,"Driver.Dispatch.lookup_cache":4.517,"Driver.Dispatch.materialize":15.867,"Driver.Dispatch.prepared_invocation":8.548,"Driver.Draw":5451.224,"Driver.Draw.device_setup":132.367,"Driver.Draw.draw_enqueued":2234.889,"Driver.Draw.post_compile_prepare":57.928,"Driver.Draw.prepare":381.786,"Driver.Draw.shader_compile_and_link":1919.976,"Driver.EndSubmission":17.514,"Driver.FinisherDrain":0.400,"Driver.MemoryWait.entry.store.queue_0x0":0.046,"Driver.Packet":9171.254,"Driver.Packet.device_lock":42.119,"Driver.Packet.dispatch":1884.230,"Driver.Packet.draw":5487.198,"Driver.Packet.execute":175.721,"Driver.Packet.flip_flush":0.164,"Driver.Packet.flush_between_packets":168.427,"Driver.Packet.memory_wait":0.071,"Driver.Packet.pipeline_drain":111.528,"Driver.Packet.pipeline_prepare":59.065,"Driver.Packet.prepare_memory":52.398,"Driver.Packet.rendering_wait":0.169,"Driver.Present":699.978,"Driver.Present.acquire_image":0.868,"Driver.Present.device_setup":0.029,"Driver.Present.gpu_mutex_wait":2.473,"Driver.Present.inflight_wait":0.162,"Driver.Present.present_display_buffer":10.333,"Driver.Present.queue_present":31.852,"Driver.Present.release_and_callback":0.103,"Driver.Present.render_fence_wait":653.987,"Driver.Present.resize":0.109,"Driver.Present.validate":0.020,"Driver.Suspend":0.011,"GpuMutex.wait.dispatch":0.034,"GpuMutex.wait.draw":1.586,"GpuMutex.wait.end":1.543,"GpuMutex.wait.fill":0.648,"GpuMutex.wait.flush":0.332,"GpuMutex.wait.hook":298.878,"GpuMutex.wait.label":7.976,"GpuMutex.wait.present":2.332,"GpuMutex.wait.wait":586.293,"Graphics.Draw":5702.570,"Graphics.Draw.draw_and_resource_release":4287.779,"Graphics.Draw.index_upload":378.615,"Graphics.Draw.validate":209.692,"Graphics.Draw.vertex_upload":792.811,"Graphics.DrawWithRecipe":9.306,"Graphics.DrawWithRecipe.draw_and_resource_release":8.597,"Graphics.DrawWithRecipe.index_upload":0.170,"Graphics.DrawWithRecipe.validate":0.146,"Graphics.DrawWithRecipe.vertex_upload":0.350,"Graphics.Submit":0.170,"Graphics.Submit.command_end":0.012,"Graphics.Submit.queue_submit":0.157,"Graphics.Wait":13.949,"Graphics.Wait.fence_wait":13.815,"Recorder.Reap":369.267,"Recorder.Submit":443.504,"Recorder.Sync":509.201,"Recorder.WaitSerial":0.683,"Resources.Complete":943.322,"Resources.Prepare":14.005,"Shader.DrawStage":1391.961,"Shader.DrawStage.capture_resources":742.176,"Shader.DrawStage.materialize":422.360,"Shader.DrawStage.prepared_invocation":210.453,"Shader.ResolveAbi":141.450,"Shader.ResolveGraphicsAbi":403.054,"Shader.ResolveGraphicsStagesAbi":315.543,"VideoOut.Flip":703.357,"VideoOut.Flip.completion_mutex_wait":0.052,"VideoOut.Flip.config_mutex_wait":0.517,"VideoOut.Flip.frame_limit":0.144,"VideoOut.Flip.notify_game":0.582,"VideoOut.Flip.present":701.312,"VideoOut.Flip.validate":0.101,"VideoOut.Flip.vblank_wait":0.058,"VideoOut.Flip.window_prepare":0.103,"VideoOut.Flip.window_title":0.419,"VideoOut.Readiness":0.341,"VideoOut.Readiness.locks_validate":0.150,"Vulkan.Acquire":0.795,"Vulkan.Acquire.acquire_fence_wait":0.143,"Vulkan.Acquire.acquire_image":0.462,"Vulkan.Acquire.fence_reset":0.135,"Vulkan.Acquire.retired_swapchains":0.033,"Vulkan.Dispatch":1033.495,"Vulkan.Dispatch.command_record":45.239,"Vulkan.Dispatch.shader_resources":986.851,"Vulkan.DispatchRecipe":48.809,"Vulkan.DispatchRecipe.command_record":48.729,"Vulkan.DrawFromRecipe":9.378,"Vulkan.Present":5.541,"Vulkan.Present.command_record_scale":2.183,"Vulkan.Present.pixel_upload":0.648,"Vulkan.Present.queue_submit":2.662,"Vulkan.QueuePresent":31.701,"Vulkan.QueuePresent.queue_present":31.622,"Vulkan.Retire":653.976,"Vulkan.Retire.wait":652.644},"top_phases_ms_per_frame":{"Driver.Packet":127.379,"Graphics.Draw":79.202,"Driver.Packet.draw":76.211,"Driver.Draw":75.711,"Graphics.Draw.draw_and_resource_release":59.552,"Driver.Draw.draw_enqueued":31.040,"Driver.Draw.shader_compile_and_link":26.666,"Driver.Packet.dispatch":26.170},"owned_draw_counts":{"OwnedDraw.arm_attempt":578,"OwnedDraw.arm_blocks_requested":578,"OwnedDraw.arm_refused":578},"graphics_track":{"Graphics.Barrier.copy":1899,"Graphics.Barrier.dcc-clear":3072,"Graphics.Barrier.dcc-keys":1894,"Graphics.Barrier.dispatch-lead":3225,"Graphics.Barrier.dispatch-trail":5352,"Graphics.Barrier.draw":100578,"Graphics.Barrier.fill":2157,"Graphics.Barrier.input-mirror":35737,"Graphics.Barrier.label-run":85533,"Graphics.Barrier.present-blit":144,"Graphics.Barrier.shadow-publish":341,"Graphics.Barrier.staging-in":571,"Graphics.Barrier.staging-out":216,"Graphics.Barrier.storage-upload":878,"Graphics.Barrier.storage-writeback":1617,"Graphics.BarrierMerged.dispatch-lead":2127,"Graphics.BarrierMerged.fill":1107,"Graphics.BarrierMerged.shadow-publish":341,"Graphics.BarrierMerged.staging-in":221,"Graphics.BarrierMerged.staging-out":216,"Graphics.BarrierMerged.storage-writeback":335,"Graphics.Copy":36249,"Graphics.Copy.bytes":4768824832,"Graphics.RenderPass":49787,"Graphics.RenderPass.Close.command":26679,"Graphics.RenderPass.Close.image":2773,"Graphics.RenderPass.Close.key":8561,"Graphics.RenderPass.Close.new-batch":11553,"Graphics.RenderPass.Close.waw":181,"Graphics.RenderPass.Continued":137043},"trace_dropped":false,"trace":"aps5-trace-d8d603d4f5f2-4616.json.gz"}
{"commit":"4131f5185afb","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_NET_DISCONNECTED":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"100:10","APS5_TRACE_SUMMARY_EVERY":"2"},"gpu":"NVIDIA GeForce RTX 2070 SUPER","driver":"NVIDIA 617.14","os":"Windows 10.0.26200","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32418,"title_id":"PPSA36458","title":"Mafia: Definitive Edition for PS5®","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"seconds 100:10","first_present":3181,"ms":10142.702},"presents":46,"frame_ms":{"p50":220.327,"p90":224.931,"p99":230.080,"max":230.080},"gpu_busy_ms_per_present":68.437,"worker_busy_pct":{"queue worker 0x0":99.002},"phase_totals_ms":{"DrawPipeline.Drain.packet.flip":108.644,"DrawPipeline.Drain.packet.metadata_pass":634.710,"DrawPipeline.Drain.packet.not_candidate":737.680,"DrawPipeline.Drain.packet.rendering":32.916,"DrawPipeline.Drain.submission.suspend":16.975,"Driver.Completion":0.289,"Driver.Dispatch":1563.057,"Driver.Dispatch.capture_resources":29.215,"Driver.Dispatch.decode_key_device_setup":743.135,"Driver.Dispatch.lookup_cache":2.540,"Driver.Dispatch.materialize":10.267,"Driver.Dispatch.prepared_invocation":5.334,"Driver.Draw":4561.319,"Driver.Draw.device_setup":87.441,"Driver.Draw.draw_enqueued":2197.322,"Driver.Draw.post_compile_prepare":40.640,"Driver.Draw.prepare":261.946,"Driver.Draw.shader_compile_and_link":1305.958,"Driver.EndSubmission":37.556,"Driver.FinisherDrain":0.243,"Driver.Packet":10003.392,"Driver.Packet.device_lock":28.714,"Driver.Packet.dispatch":1564.880,"Driver.Packet.draw":4587.431,"Driver.Packet.execute":163.247,"Driver.Packet.flip_flush":1.276,"Driver.Packet.flush_between_packets":73.259,"Driver.Packet.pipeline_drain":173.544,"Driver.Packet.pipeline_prepare":40.788,"Driver.Packet.prepare_memory":36.585,"Driver.Packet.rendering_wait":0.119,"Driver.Present":20.136,"Driver.Present.acquire_image":0.532,"Driver.Present.device_setup":0.021,"Driver.Present.gpu_mutex_wait":3.904,"Driver.Present.inflight_wait":0.099,"Driver.Present.present_display_buffer":6.921,"Driver.Present.queue_present":5.221,"Driver.Present.release_and_callback":0.049,"Driver.Present.render_fence_wait":3.271,"Driver.Present.resize":0.074,"Driver.Present.validate":0.017,"Driver.Suspend":0.010,"GpuMutex.wait.dispatch":0.013,"GpuMutex.wait.draw":0.280,"GpuMutex.wait.end":4.172,"GpuMutex.wait.fill":0.468,"GpuMutex.wait.flush":7.283,"GpuMutex.wait.hook":197.821,"GpuMutex.wait.label":10.337,"GpuMutex.wait.other":0.045,"GpuMutex.wait.present":3.818,"GpuMutex.wait.wait":395.051,"Graphics.Draw":3909.512,"Graphics.Draw.draw_and_resource_release":3111.728,"Graphics.Draw.index_upload":191.810,"Graphics.Draw.validate":175.898,"Graphics.Draw.vertex_upload":403.268,"Graphics.DrawWithRecipe":2.563,"Graphics.DrawWithRecipe.draw_and_resource_release":2.276,"Graphics.DrawWithRecipe.index_upload":0.084,"Graphics.DrawWithRecipe.validate":0.053,"Graphics.DrawWithRecipe.vertex_upload":0.135,"Graphics.Submit":0.045,"Graphics.Submit.command_end":0.004,"Graphics.Submit.queue_submit":0.041,"Graphics.Wait":1.014,"Graphics.Wait.fence_wait":0.981,"Recorder.Reap":226.011,"Recorder.Submit":1110.126,"Recorder.Sync":335.378,"Recorder.WaitSerial":0.443,"Resources.Complete":586.653,"Resources.Prepare":5.999,"Shader.DrawStage":917.231,"Shader.DrawStage.capture_resources":469.852,"Shader.DrawStage.materialize":290.384,"Shader.DrawStage.prepared_invocation":145.307,"Shader.ResolveAbi":90.581,"Shader.ResolveGraphicsAbi":267.054,"Shader.ResolveGraphicsStagesAbi":206.430,"VideoOut.Flip":24.037,"VideoOut.Flip.completion_mutex_wait":0.033,"VideoOut.Flip.config_mutex_wait":0.708,"VideoOut.Flip.frame_limit":0.061,"VideoOut.Flip.notify_game":1.271,"VideoOut.Flip.present":21.343,"VideoOut.Flip.validate":0.058,"VideoOut.Flip.vblank_wait":0.035,"VideoOut.Flip.window_prepare":0.070,"VideoOut.Flip.window_title":0.368,"VideoOut.Readiness":0.193,"VideoOut.Readiness.locks_validate":0.086,"Vulkan.Acquire":0.486,"Vulkan.Acquire.acquire_fence_wait":0.083,"Vulkan.Acquire.acquire_image":0.285,"Vulkan.Acquire.fence_reset":0.083,"Vulkan.Acquire.retired_swapchains":0.022,"Vulkan.Dispatch":632.768,"Vulkan.Dispatch.command_record":26.360,"Vulkan.Dispatch.shader_resources":605.564,"Vulkan.DispatchRecipe":27.589,"Vulkan.DispatchRecipe.command_record":27.547,"Vulkan.DrawFromRecipe":2.586,"Vulkan.Present":4.141,"Vulkan.Present.command_record_scale":1.389,"Vulkan.Present.pixel_upload":0.818,"Vulkan.Present.queue_submit":1.863,"Vulkan.QueuePresent":5.111,"Vulkan.QueuePresent.queue_present":5.066,"Vulkan.Retire":3.265,"Vulkan.Retire.wait":2.184},"top_phases_ms_per_frame":{"Driver.Packet":217.465,"Driver.Packet.draw":99.727,"Driver.Draw":99.159,"Graphics.Draw":84.989,"Graphics.Draw.draw_and_resource_release":67.646,"Driver.Draw.draw_enqueued":47.768,"Driver.Packet.dispatch":34.019,"Driver.Dispatch":33.980},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":1569,"Graphics.Barrier.dcc-clear":1932,"Graphics.Barrier.dcc-keys":1196,"Graphics.Barrier.dispatch-lead":2056,"Graphics.Barrier.dispatch-trail":3404,"Graphics.Barrier.draw":83809,"Graphics.Barrier.fill":1342,"Graphics.Barrier.input-mirror":3493,"Graphics.Barrier.label-run":121206,"Graphics.Barrier.present-blit":92,"Graphics.Barrier.shadow-publish":198,"Graphics.Barrier.staging-in":324,"Graphics.Barrier.staging-out":138,"Graphics.Barrier.storage-upload":498,"Graphics.Barrier.storage-writeback":883,"Graphics.BarrierMerged.dispatch-lead":1348,"Graphics.BarrierMerged.fill":598,"Graphics.BarrierMerged.shadow-publish":198,"Graphics.BarrierMerged.staging-in":182,"Graphics.BarrierMerged.staging-out":138,"Graphics.BarrierMerged.storage-writeback":156,"Graphics.Copy":3819,"Graphics.Copy.bytes":1095478059,"Graphics.RenderPass":42196,"Graphics.RenderPass.Close.command":3791,"Graphics.RenderPass.Close.image":1198,"Graphics.RenderPass.Close.key":4283,"Graphics.RenderPass.Close.new-batch":32778,"Graphics.RenderPass.Close.waw":139,"Graphics.RenderPass.Continued":78335},"trace_dropped":false,"trace":"aps5-trace-4131f5185afb-4608.json.gz"}
{"commit":"4131f5185afb","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_NET_DISCONNECTED":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"100:10","APS5_TRACE_SUMMARY_EVERY":"2"},"gpu":"NVIDIA GeForce RTX 2070 SUPER","driver":"NVIDIA 617.14","os":"Windows 10.0.26200","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32418,"title_id":"PPSA36458","title":"Mafia: Definitive Edition for PS5®","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"seconds 100:10","first_present":3164,"ms":10053.458},"presents":48,"frame_ms":{"p50":208.320,"p90":221.558,"p99":232.643,"max":232.643},"gpu_busy_ms_per_present":81.706,"worker_busy_pct":{"queue worker 0x0":99.004},"phase_totals_ms":{"DrawPipeline.Drain.packet.flip":102.269,"DrawPipeline.Drain.packet.metadata_pass":625.827,"DrawPipeline.Drain.packet.not_candidate":784.825,"DrawPipeline.Drain.packet.rendering":31.541,"DrawPipeline.Drain.submission.suspend":16.082,"Driver.Completion":0.261,"Driver.Dispatch":1663.107,"Driver.Dispatch.capture_resources":32.142,"Driver.Dispatch.decode_key_device_setup":790.452,"Driver.Dispatch.lookup_cache":2.861,"Driver.Dispatch.materialize":10.233,"Driver.Dispatch.prepared_invocation":5.473,"Driver.Draw":4629.264,"Driver.Draw.device_setup":90.600,"Driver.Draw.draw_enqueued":2205.800,"Driver.Draw.post_compile_prepare":41.755,"Driver.Draw.prepare":271.433,"Driver.Draw.shader_compile_and_link":1331.327,"Driver.EndSubmission":47.938,"Driver.FinisherDrain":0.292,"Driver.Packet":9904.792,"Driver.Packet.device_lock":29.691,"Driver.Packet.dispatch":1664.993,"Driver.Packet.draw":4656.700,"Driver.Packet.execute":156.219,"Driver.Packet.flip_flush":1.585,"Driver.Packet.flush_between_packets":77.945,"Driver.Packet.pipeline_drain":166.810,"Driver.Packet.pipeline_prepare":42.841,"Driver.Packet.prepare_memory":37.398,"Driver.Packet.rendering_wait":0.074,"Driver.Present":21.692,"Driver.Present.acquire_image":0.560,"Driver.Present.device_setup":0.023,"Driver.Present.gpu_mutex_wait":4.544,"Driver.Present.inflight_wait":0.104,"Driver.Present.present_display_buffer":7.661,"Driver.Present.queue_present":4.879,"Driver.Present.release_and_callback":0.053,"Driver.Present.render_fence_wait":3.746,"Driver.Present.resize":0.075,"Driver.Present.validate":0.018,"Driver.Suspend":0.009,"GpuMutex.wait.dispatch":0.384,"GpuMutex.wait.draw":0.600,"GpuMutex.wait.end":3.607,"GpuMutex.wait.fill":0.461,"GpuMutex.wait.flush":7.515,"GpuMutex.wait.hook":74.621,"GpuMutex.wait.label":12.693,"GpuMutex.wait.other":0.020,"GpuMutex.wait.present":4.449,"GpuMutex.wait.wait":375.339,"Graphics.Draw":4116.099,"Graphics.Draw.draw_and_resource_release":3187.628,"Graphics.Draw.index_upload":236.074,"Graphics.Draw.validate":175.484,"Graphics.Draw.vertex_upload":490.132,"Graphics.DrawWithRecipe":4.865,"Graphics.DrawWithRecipe.draw_and_resource_release":4.598,"Graphics.DrawWithRecipe.index_upload":0.067,"Graphics.DrawWithRecipe.validate":0.054,"Graphics.DrawWithRecipe.vertex_upload":0.130,"Recorder.Reap":225.863,"Recorder.Submit":989.032,"Recorder.Sync":369.386,"Recorder.WaitSerial":0.482,"Resources.Complete":609.139,"Resources.Prepare":10.197,"Shader.DrawStage":935.932,"Shader.DrawStage.capture_resources":479.101,"Shader.DrawStage.materialize":297.373,"Shader.DrawStage.prepared_invocation":147.529,"Shader.ResolveAbi":93.432,"Shader.ResolveGraphicsAbi":266.065,"Shader.ResolveGraphicsStagesAbi":207.467,"VideoOut.Flip":25.742,"VideoOut.Flip.completion_mutex_wait":0.037,"VideoOut.Flip.config_mutex_wait":0.290,"VideoOut.Flip.frame_limit":0.069,"VideoOut.Flip.notify_game":1.715,"VideoOut.Flip.present":23.003,"VideoOut.Flip.validate":0.067,"VideoOut.Flip.vblank_wait":0.032,"VideoOut.Flip.window_prepare":0.103,"VideoOut.Flip.window_title":0.381,"VideoOut.Readiness":0.248,"VideoOut.Readiness.locks_validate":0.109,"Vulkan.Acquire":0.515,"Vulkan.Acquire.acquire_fence_wait":0.091,"Vulkan.Acquire.acquire_image":0.301,"Vulkan.Acquire.fence_reset":0.089,"Vulkan.Acquire.retired_swapchains":0.019,"Vulkan.Dispatch":654.460,"Vulkan.Dispatch.command_record":28.013,"Vulkan.Dispatch.shader_resources":625.596,"Vulkan.DispatchRecipe":30.642,"Vulkan.DispatchRecipe.command_record":30.586,"Vulkan.DrawFromRecipe":4.890,"Vulkan.Present":4.433,"Vulkan.Present.command_record_scale":1.426,"Vulkan.Present.pixel_upload":1.101,"Vulkan.Present.queue_submit":1.872,"Vulkan.QueuePresent":4.697,"Vulkan.QueuePresent.queue_present":4.650,"Vulkan.Retire":3.740,"Vulkan.Retire.wait":2.279},"top_phases_ms_per_frame":{"Driver.Packet":206.350,"Driver.Packet.draw":97.015,"Driver.Draw":96.443,"Graphics.Draw":85.752,"Graphics.Draw.draw_and_resource_release":66.409,"Driver.Draw.draw_enqueued":45.954,"Driver.Packet.dispatch":34.687,"Driver.Dispatch":34.648},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":1650,"Graphics.Barrier.dcc-clear":2064,"Graphics.Barrier.dcc-keys":1286,"Graphics.Barrier.dispatch-lead":2144,"Graphics.Barrier.dispatch-trail":3576,"Graphics.Barrier.draw":88215,"Graphics.Barrier.fill":1505,"Graphics.Barrier.input-mirror":12000,"Graphics.Barrier.label-run":114859,"Graphics.Barrier.present-blit":96,"Graphics.Barrier.shadow-publish":230,"Graphics.Barrier.staging-in":348,"Graphics.Barrier.staging-out":150,"Graphics.Barrier.storage-upload":608,"Graphics.Barrier.storage-writeback":1139,"Graphics.BarrierMerged.dispatch-lead":1432,"Graphics.BarrierMerged.fill":661,"Graphics.BarrierMerged.shadow-publish":230,"Graphics.BarrierMerged.staging-in":198,"Graphics.BarrierMerged.staging-out":150,"Graphics.BarrierMerged.storage-writeback":198,"Graphics.Copy":12348,"Graphics.Copy.bytes":2078156309,"Graphics.RenderPass":44349,"Graphics.RenderPass.Close.command":8676,"Graphics.RenderPass.Close.image":1459,"Graphics.RenderPass.Close.key":4718,"Graphics.RenderPass.Close.new-batch":29353,"Graphics.RenderPass.Close.waw":136,"Graphics.RenderPass.Continued":80466},"trace_dropped":false,"trace":"aps5-trace-4131f5185afb-16468.json.gz"}
{"commit":"d8d603d4f5f2","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_NET_DISCONNECTED":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"100:10","APS5_TRACE_SUMMARY_EVERY":"2"},"gpu":"NVIDIA GeForce RTX 2070 SUPER","driver":"NVIDIA 617.14","os":"Windows 10.0.26200","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32418,"title_id":"PPSA36458","title":"Mafia: Definitive Edition for PS5®","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"seconds 100:10","first_present":3269,"ms":10036.081},"presents":77,"frame_ms":{"p50":128.775,"p90":139.271,"p99":147.461,"max":147.461},"gpu_busy_ms_per_present":81.147,"worker_busy_pct":{"queue worker 0x0":93.815},"phase_totals_ms":{"DrawPipeline.Drain.packet.flip":52.724,"DrawPipeline.Drain.packet.metadata_pass":678.225,"DrawPipeline.Drain.packet.not_candidate":419.194,"DrawPipeline.Drain.packet.rendering":9.739,"DrawPipeline.Drain.submission.suspend":25.732,"Driver.Completion":0.315,"Driver.Dispatch":1802.947,"Driver.Dispatch.capture_resources":48.399,"Driver.Dispatch.decode_key_device_setup":428.421,"Driver.Dispatch.lookup_cache":6.065,"Driver.Dispatch.materialize":16.459,"Driver.Dispatch.prepared_invocation":8.453,"Driver.Draw":5595.582,"Driver.Draw.device_setup":138.523,"Driver.Draw.draw_enqueued":2270.425,"Driver.Draw.post_compile_prepare":62.452,"Driver.Draw.prepare":397.051,"Driver.Draw.shader_compile_and_link":1997.100,"Driver.EndSubmission":21.755,"Driver.FinisherDrain":0.386,"Driver.Packet":9392.845,"Driver.Packet.device_lock":45.337,"Driver.Packet.dispatch":1805.931,"Driver.Packet.draw":5634.671,"Driver.Packet.execute":191.966,"Driver.Packet.flip_flush":0.122,"Driver.Packet.flush_between_packets":177.745,"Driver.Packet.pipeline_drain":113.186,"Driver.Packet.pipeline_prepare":63.549,"Driver.Packet.prepare_memory":56.046,"Driver.Packet.rendering_wait":0.185,"Driver.Present":475.188,"Driver.Present.acquire_image":0.919,"Driver.Present.device_setup":0.031,"Driver.Present.gpu_mutex_wait":3.093,"Driver.Present.inflight_wait":0.165,"Driver.Present.present_display_buffer":10.653,"Driver.Present.queue_present":45.438,"Driver.Present.release_and_callback":0.084,"Driver.Present.render_fence_wait":414.615,"Driver.Present.resize":0.122,"Driver.Present.validate":0.027,"Driver.Suspend":0.011,"GpuMutex.wait.dispatch":6.418,"GpuMutex.wait.draw":4.297,"GpuMutex.wait.end":5.933,"GpuMutex.wait.fill":0.715,"GpuMutex.wait.flush":2.820,"GpuMutex.wait.hook":343.035,"GpuMutex.wait.label":7.693,"GpuMutex.wait.other":4.718,"GpuMutex.wait.present":2.942,"GpuMutex.wait.wait":699.859,"Graphics.Draw":5642.771,"Graphics.Draw.draw_and_resource_release":4534.388,"Graphics.Draw.index_upload":258.473,"Graphics.Draw.validate":236.480,"Graphics.Draw.vertex_upload":576.592,"Graphics.DrawWithRecipe":16.298,"Graphics.DrawWithRecipe.draw_and_resource_release":14.880,"Graphics.DrawWithRecipe.index_upload":0.346,"Graphics.DrawWithRecipe.validate":0.288,"Graphics.DrawWithRecipe.vertex_upload":0.698,"Graphics.Submit":0.065,"Graphics.Submit.command_end":0.006,"Graphics.Submit.queue_submit":0.057,"Graphics.Wait":1.419,"Graphics.Wait.fence_wait":1.376,"Recorder.Reap":311.120,"Recorder.Submit":763.711,"Recorder.Sync":575.407,"Recorder.WaitSerial":0.692,"Resources.Complete":982.417,"Resources.Prepare":10.853,"Shader.DrawStage":1434.860,"Shader.DrawStage.capture_resources":732.262,"Shader.DrawStage.materialize":458.005,"Shader.DrawStage.prepared_invocation":226.426,"Shader.PrepareArtifact":33.784,"Shader.Register":1.637,"Shader.ResolveAbi":151.596,"Shader.ResolveGraphicsAbi":421.207,"Shader.ResolveGraphicsStagesAbi":336.819,"VideoOut.Flip":479.436,"VideoOut.Flip.completion_mutex_wait":0.063,"VideoOut.Flip.config_mutex_wait":1.372,"VideoOut.Flip.frame_limit":0.094,"VideoOut.Flip.notify_game":0.592,"VideoOut.Flip.present":476.602,"VideoOut.Flip.validate":0.106,"VideoOut.Flip.vblank_wait":0.050,"VideoOut.Flip.window_prepare":0.112,"VideoOut.Flip.window_title":0.414,"VideoOut.Readiness":0.365,"VideoOut.Readiness.locks_validate":0.172,"Vulkan.Acquire":0.841,"Vulkan.Acquire.acquire_fence_wait":0.146,"Vulkan.Acquire.acquire_image":0.496,"Vulkan.Acquire.fence_reset":0.142,"Vulkan.Acquire.retired_swapchains":0.034,"Vulkan.Dispatch":1071.820,"Vulkan.Dispatch.command_record":45.709,"Vulkan.Dispatch.shader_resources":1024.800,"Vulkan.DispatchRecipe":28.461,"Vulkan.DispatchRecipe.command_record":28.199,"Vulkan.DrawFromRecipe":16.437,"Vulkan.GraphicsPipeline":1.976,"Vulkan.GraphicsPipeline.modules_and_state":1.903,"Vulkan.GraphicsPipelinePrebuild":2.020,"Vulkan.Present":6.332,"Vulkan.Present.command_record_scale":2.239,"Vulkan.Present.pixel_upload":1.410,"Vulkan.Present.queue_submit":2.632,"Vulkan.QueuePresent":45.288,"Vulkan.QueuePresent.queue_present":45.202,"Vulkan.Retire":414.598,"Vulkan.Retire.wait":413.106},"top_phases_ms_per_frame":{"Driver.Packet":121.985,"Graphics.Draw":73.283,"Driver.Packet.draw":73.178,"Driver.Draw":72.670,"Graphics.Draw.draw_and_resource_release":58.888,"Driver.Draw.draw_enqueued":29.486,"Driver.Draw.shader_compile_and_link":25.936,"Driver.Packet.dispatch":23.454},"owned_draw_counts":{"OwnedDraw.arm_attempt":999,"OwnedDraw.arm_blocks_requested":999,"OwnedDraw.arm_refused":999},"graphics_track":{"Graphics.Barrier.copy":1701,"Graphics.Barrier.dcc-clear":3234,"Graphics.Barrier.dcc-keys":1980,"Graphics.Barrier.dispatch-lead":3408,"Graphics.Barrier.dispatch-trail":5698,"Graphics.Barrier.draw":85643,"Graphics.Barrier.fill":2181,"Graphics.Barrier.input-mirror":6956,"Graphics.Barrier.label-run":118100,"Graphics.Barrier.present-blit":154,"Graphics.Barrier.shadow-publish":346,"Graphics.Barrier.staging-in":492,"Graphics.Barrier.staging-out":183,"Graphics.Barrier.storage-upload":882,"Graphics.Barrier.storage-writeback":1511,"Graphics.BarrierMerged.dispatch-lead":2290,"Graphics.BarrierMerged.fill":1075,"Graphics.BarrierMerged.shadow-publish":346,"Graphics.BarrierMerged.staging-in":211,"Graphics.BarrierMerged.staging-out":183,"Graphics.BarrierMerged.storage-writeback":322,"Graphics.Copy":7422,"Graphics.Copy.bytes":1118512214,"Graphics.RenderPass":43333,"Graphics.RenderPass.Close.command":8355,"Graphics.RenderPass.Close.image":2970,"Graphics.RenderPass.Close.key":9077,"Graphics.RenderPass.Close.new-batch":22830,"Graphics.RenderPass.Close.waw":46,"Graphics.RenderPass.Continued":158746},"trace_dropped":false,"trace":"aps5-trace-d8d603d4f5f2-12844.json.gz"}

aps5-trace-d8d603d4f5f2-4616.json.gz
aps5-trace-d8d603d4f5f2-12844.json.gz
aps5-trace-4131f5185afb-4608.json.gz
aps5-trace-4131f5185afb-16468.json.gz

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 2070 SUPER, driver 617.14, Windows 11 (10.0.26200)
  • AI-assisted: yes

🤖 Generated with Claude Code

…scan at a label

At a label, StoreReadbackBeforeLabel scanned every pending image for a
trapped overlap for each pending tiled image of 64 KiB to 1 MiB, and only
then tested whether the image was written occasionally. Most images are
not, so test the flag first. The same images are stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the agc libSceAgc* label Dec 2, 2026
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Occasional Readback Guard

Layer / File(s) Summary
Filter occasional-store candidates
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
StoreReadbackBeforeLabel skips candidates when writtenOccasionally is false. Other candidates continue through the existing checks and exchange.

Possibly related issues

Suggested labels: perf

Suggested reviewers: marczx10, jjenkx

Change: Refactor

Merge Risk: Minimal · up to d8d60

This change skips a costly scan for images that were not written occasionally, which should improve frame rates. The images that get stored are unchanged. No concrete defect was found, and the author's focused tests passed.

Security architecture risk: Minimal · up to d8d60

AgcDriver now skips the trapped-overlap scan for textures that are not marked for occasional readback. Textures that pass the new check still face the same trap protection, and skipped textures remain eligible for the existing pending-writeback paths.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: beb0817f-f087-41e1-ad79-3bbee2267923
Commits

Reviewing files that changed from the base of the PR and between b535a7e and d8d603d.

Files selected for processing: 1

  • core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions github-actions Bot added the perf Performance change label Dec 2, 2026

@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 — no blocking findings

The changed path has no verified blocking defect; the performance evidence available here does not include digest output for independent review.

What I ran

Reviewed head d8d603d4f5f2166835fe8608a5a407aa3c2a074b using repo_read.py and the prepared review artifacts. No build or tests were run.

repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 6530 6685
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 5300 5380
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 5095 5135
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp 1039 1039
repo_read.py cat docs/dev/GAME_TESTING.md 90 110
repo_read.py cat docs/dev/TRACING.md 85 105

Read description.md, commits.md, manifest.json, files.json, and diff.patch. The manifest lists one changed file; its full text was too large for files/. I read the changed function and relevant flag update/declaration context in Texture.cpp and Texture.hpp.

Results

Check Result Note
Changed-path inspection passed Early flag check precedes overlap scan
Build and tests not run Author reports results; not independently run
Performance evidence not run Captures and summaries are author-provided

Negative control

Not run; no test was modified or executed.

Findings

Blocking

None.

Non-blocking

None.

Sources

Changed function at the reviewed commit shows the flag check before the trapped-overlap scan, with the existing atomic exchange retained before queuing the store. Performance testing guidance describes the capture and digest workflow.

Not verified

The remainder of Texture.cpp was not read. The description's Windows performance measurements, focused test results, and conventions check were not rerun. Linux, macOS, other GPUs, and the full test suite were not checked. The supplied description includes baseline/change captures and summary records, but no trace digest output was available here.

To get this to a good state

Nothing is required. Optional: include the trace digest or comparison output alongside the captures and summary records to make the performance comparison easier to audit.

@github-actions

github-actions Bot commented Dec 2, 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/Graphics/src/Texture.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6192 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6209 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6280 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 7085 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 8246 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 10743 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 12746 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 12792 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13251 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 15136 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 16953 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 18173 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 20041 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 20183 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 20728 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 22531 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 28119 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 28176 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 28470 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I downloaded all four attached traces and ran tools/trace_digest.py against their matching summary lines. The two main captures had 46 and 48 presents at 220.3 and 208.3 ms median frame time. The PR captures had 72 and 77 presents at 138.3 and 128.8 ms. All four report the same capture window specification, GPU, driver, OS, and resolution, with no dropped events. I also compared the benchmarked commits. The early flag check is their only source difference.

This verifies the attached ten-second captures. I did not rerun the title or the Windows Vulkan tests.

AI-assisted: yes

@Plyxen Plyxen 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.

I read the diff at d8d603d4f5. An image without the flag was skipped by the exchange below anyway, so the early test changes no stored image; only the cost of the scan goes away. A concurrent set of the flag between the two reads is picked up at the next label, as with the old order.

Windows 11, GCC 15.2, merged into main at cde48b5800e together with other open PRs (so not an isolated build): agc_driver_recorder and agc_small_tiled_shadow_label pass on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2) with VK_LAYER_KHRONOS_validation, without a VUID- or SYNC-HAZARD line.

Not checked: the time saved in Mafia.

AI-assisted: yes (Claude Code)

@videogamer10293

Copy link
Copy Markdown
Contributor

Nearly every image fails that test, so the scan was wasted.

(PR description)

That holds in a second title, PPSA21564 at Crash Site, on Windows with NVIDIA: in the last 120 s of a run not one scanned image had the flag, and with this PR the scan did not run at all in that window. The saving is small in this title, though: the scan took at most 8.4 ms per second summed over threads, under 1 % of one thread's time, where the description measured the loop at 2,400 ms per 10 s (about 24 %) in Mafia: Definitive Edition, on a different machine and build.

Counter. Local print lines (patches below, not pushed) at the any_of in StoreReadbackBeforeLabel, and on the PR build also at the new flag test. Both builds on main 64386d72c5; the PR build is a local merge of d8d603d4f5 into it. RTX 5070 Ti (driver 621.24), Ryzen 5 7600X, Windows 10 19045, guest 3840x2160, -lvl hub_crashsite, no input, one 300 s run each.

last 120 s of one run main this PR
images tested for writtenOccasionally at the new check, per present (no check) 6,905, none with the flag
overlap scans, per present 6,227, none for an image with the flag 0
time in the scans, per present (upper bound: each timed span includes a clock read) 0.85 ms none

The main count includes only calls with read traps on; the PR count includes every image that reaches the flag test. On main the pending list held 88.4 images on average at each scan in that window. Over the whole run, 425 of 20,690,280 scans on main were for an image with the flag, 423 of them within about 30 s of the first scan. On this PR, 312 images passed the flag test and were scanned, all but 2 within about 20 s of the first check, and 24,831,746 were skipped.

My 3 A/B pairs on the older main daa61711af (its libSceAgcDriver differs only in a test file; frame p50 87.08 to 98.25 ms over both sides) cannot resolve a cost this size, so I give no speed figure.

Not covered: one scene and one machine, NVIDIA only. Only the steady part is measured; on main the scan ran more often early on (2.32 M scans in the second 10 s, 0.47 to 0.63 M per 10 s after the third print). The scan runs under pending.mutex; I did not check which thread runs it here or whether it holds up other threads.

Counter patch on main (local diagnostic)
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
index c0e3fc8..2084b38 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
@@ -1,3 +1,4 @@
+#include <iterator>
 #include "prx/libc/include/HostThreadSlot.hpp"
 #include "prx/libSceAgcDriver/Graphics/include/MemoryAccounting.hpp"
 #include "prx/libSceAgcDriver/Execution/include/AsyncLog.hpp"
@@ -6698,7 +6699,24 @@ void StorageTexture::StoreReadbackBeforeLabel(const char* reason, VkDevice devic
             if (device != VK_NULL_HANDLE && texture->context.device != device) continue;
 #if defined(__APPLE__) || defined(_WIN32)
             const auto coversTrapped = [&](const StorageTexture* other) { return other != texture && other->readTrapped.load(std::memory_order_acquire) && other->overlaps(texture->descriptor.baseAddress, static_cast<std::size_t>(texture->guestBytes)); };
-            if (trap && std::any_of(pending.textures.begin(), pending.textures.end(), coversTrapped)) continue;
+            static std::atomic<std::uint64_t> diagScans{0}, diagUnflagged{0}, diagVisited{0}, diagNs{0};
+            static std::atomic<long long> diagLast{0};
+            bool diagHit = false;
+            if (trap) {
+                const auto diagT0 = std::chrono::steady_clock::now();
+                diagHit = std::any_of(pending.textures.begin(), pending.textures.end(), coversTrapped);
+                const auto diagT1 = std::chrono::steady_clock::now();
+                diagScans.fetch_add(1, std::memory_order_relaxed);
+                if (!texture->writtenOccasionally.load(std::memory_order_relaxed)) diagUnflagged.fetch_add(1, std::memory_order_relaxed);
+                diagVisited.fetch_add(static_cast<std::uint64_t>(std::distance(pending.textures.begin(), pending.textures.end())), std::memory_order_relaxed);
+                diagNs.fetch_add(static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(diagT1 - diagT0).count()), std::memory_order_relaxed);
+                const auto diagNow = std::chrono::duration_cast<std::chrono::seconds>(diagT1.time_since_epoch()).count();
+                auto diagSeen = diagLast.load(std::memory_order_relaxed);
+                if (diagSeen == 0) diagLast.compare_exchange_strong(diagSeen, diagNow);
+                else if (diagNow - diagSeen >= 10 && diagLast.compare_exchange_strong(diagSeen, diagNow))
+                    std::fprintf(stderr, "[diag-label-scan] t=%lld scans=%llu unflagged=%llu visited=%llu scan_ms=%.1f\n", static_cast<long long>(diagNow), static_cast<unsigned long long>(diagScans.load()), static_cast<unsigned long long>(diagUnflagged.load()), static_cast<unsigned long long>(diagVisited.load()), diagNs.load() / 1e6);
+            }
+            if (diagHit) continue;
 #endif
             if (!texture->writtenOccasionally.exchange(false, std::memory_order_relaxed)) continue;
             occasionalLabelStores.fetch_add(1, std::memory_order_relaxed);
Counter patch on this PR (local diagnostic, applied after the merge)
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
index c5494d9..eba1244 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
@@ -1,3 +1,4 @@
+#include <iterator>
 #include "prx/libc/include/HostThreadSlot.hpp"
 #include "prx/libSceAgcDriver/Graphics/include/MemoryAccounting.hpp"
 #include "prx/libSceAgcDriver/Execution/include/AsyncLog.hpp"
@@ -6696,10 +6697,40 @@ void StorageTexture::StoreReadbackBeforeLabel(const char* reason, VkDevice devic
         for (auto* texture : pending.textures) {
             if (texture->descriptor.tileMode == TextureTileMode::kLinear || texture->guestBytes <= SmallStoreBytes || texture->guestBytes > OccasionalStoreBytes) continue;
             if (device != VK_NULL_HANDLE && texture->context.device != device) continue;
-            if (!texture->writtenOccasionally.load(std::memory_order_relaxed)) continue;
+            static std::atomic<std::uint64_t> diagCand{0}, diagCandSkip{0}, diagScansB{0};
+            static std::atomic<long long> diagCandLast{0};
+            {
+                const bool diagSkip = !texture->writtenOccasionally.load(std::memory_order_relaxed);
+                diagCand.fetch_add(1, std::memory_order_relaxed);
+                if (diagSkip) diagCandSkip.fetch_add(1, std::memory_order_relaxed);
+                else if (trap) diagScansB.fetch_add(1, std::memory_order_relaxed);
+                const auto diagNowC = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
+                auto diagSeenC = diagCandLast.load(std::memory_order_relaxed);
+                if (diagSeenC == 0) diagCandLast.compare_exchange_strong(diagSeenC, diagNowC);
+                else if (diagNowC - diagSeenC >= 10 && diagCandLast.compare_exchange_strong(diagSeenC, diagNowC))
+                    std::fprintf(stderr, "[diag-label-cand] t=%lld candidates=%llu skipped_unflagged=%llu scans_after=%llu\n", static_cast<long long>(diagNowC), static_cast<unsigned long long>(diagCand.load()), static_cast<unsigned long long>(diagCandSkip.load()), static_cast<unsigned long long>(diagScansB.load()));
+                if (diagSkip) continue;
+            }
 #if defined(__APPLE__) || defined(_WIN32)
             const auto coversTrapped = [&](const StorageTexture* other) { return other != texture && other->readTrapped.load(std::memory_order_acquire) && other->overlaps(texture->descriptor.baseAddress, static_cast<std::size_t>(texture->guestBytes)); };
-            if (trap && std::any_of(pending.textures.begin(), pending.textures.end(), coversTrapped)) continue;
+            static std::atomic<std::uint64_t> diagScans{0}, diagUnflagged{0}, diagVisited{0}, diagNs{0};
+            static std::atomic<long long> diagLast{0};
+            bool diagHit = false;
+            if (trap) {
+                const auto diagT0 = std::chrono::steady_clock::now();
+                diagHit = std::any_of(pending.textures.begin(), pending.textures.end(), coversTrapped);
+                const auto diagT1 = std::chrono::steady_clock::now();
+                diagScans.fetch_add(1, std::memory_order_relaxed);
+                if (!texture->writtenOccasionally.load(std::memory_order_relaxed)) diagUnflagged.fetch_add(1, std::memory_order_relaxed);
+                diagVisited.fetch_add(static_cast<std::uint64_t>(std::distance(pending.textures.begin(), pending.textures.end())), std::memory_order_relaxed);
+                diagNs.fetch_add(static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(diagT1 - diagT0).count()), std::memory_order_relaxed);
+                const auto diagNow = std::chrono::duration_cast<std::chrono::seconds>(diagT1.time_since_epoch()).count();
+                auto diagSeen = diagLast.load(std::memory_order_relaxed);
+                if (diagSeen == 0) diagLast.compare_exchange_strong(diagSeen, diagNow);
+                else if (diagNow - diagSeen >= 10 && diagLast.compare_exchange_strong(diagSeen, diagNow))
+                    std::fprintf(stderr, "[diag-label-scan] t=%lld scans=%llu unflagged=%llu visited=%llu scan_ms=%.1f\n", static_cast<long long>(diagNow), static_cast<unsigned long long>(diagScans.load()), static_cast<unsigned long long>(diagUnflagged.load()), static_cast<unsigned long long>(diagVisited.load()), diagNs.load() / 1e6);
+            }
+            if (diagHit) continue;
 #endif
             if (!texture->writtenOccasionally.exchange(false, std::memory_order_relaxed)) continue;
             occasionalLabelStores.fetch_add(1, std::memory_order_relaxed);

AI-assisted: yes.

@Ducengarth

Copy link
Copy Markdown
Contributor

Measured on a third title: Star Wars Jedi: Fallen Order (PPSA02199, 01.003.000), Windows 11 10.0.26300, RTX 3090 Ti (NVIDIA 621.14, so the traps are on), i9-9900K, 3840x2160. Throughput goes up by about 6 %. The cost moves only in the label commits. Slow frames from the title thread waiting on GpuMutex showed up in 5 of the 6 runs with this change and in 1 of the 6 without it. I could not find the cause; details below.

Setup. main is d076e78c26 plus #28838 and #22382, which the title needs to reach gameplay. The change is the same tree plus this PR's one line (15dfee6f12). Only libSceAgcDriver.prx differs between the arms. Each run restores the same shader and pipeline cache snapshot, then plays the same save for 205 s with APS5_DRAW_PIPELINE=1 APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1 APS5_PIPELINE_STATS=y. The arms alternate in two batches of three pairs.

tools/trace_digest.py, APS5_TRACE_SECONDS=130:60 (batch 2):

run presents p50 p90 p99 max GPU busy / present
main 1 380 147.4 202.6 250.0 279.0 72.7
main 2 385 146.0 199.6 232.6 276.5 72.4
main 3 378 148.5 202.1 238.3 259.8 76.0
PR 1 399 139.0 192.9 245.9 529.7 71.2
PR 2 412 135.6 181.2 226.9 665.4 70.8
PR 3 405 136.6 190.3 238.7 558.4 70.9

Batch 1 (130:30) gave the same picture:

  • main: 175 / 174 / 181 presents, p50 157.9 / 155.7 / 151.7 ms.
  • PR: 185 / 179 / 187 presents, p50 144.3 / 150.1 / 145.9 ms.

Where the time goes. These are the committer's [commits] by kind lines from the 10 s windows with more than 60k draws, scaled to 1780 draws per frame. Draw commits cost the same in both arms, 64-68 us each.

main (6 runs) PR (6 runs)
non-draw commits, ms per frame 28.3-31.5 20.1-21.1
endofpipe 10.6-13.2 5.9-6.1
dmawrite 4.7-5.5 3.2-3.4

In an offline replay of a 10-frame capture of the same scene (agc_frame_replay, four alternated pairs), the non-draw commits drop from 16.4-16.6 to 15.4-15.6 ms per frame. Pixels are identical between the arms. The replay starts with fewer pending images than the game, so the saving there is smaller.

Slow frames. In 5 of the 6 PR runs, 2 or 3 frames of 395-665 ms show up 19-27 s into the window. Only 1 of the 6 main runs had them, at 315-408 ms. In each of these frames trace_digest lists GpuMutex.wait.other on the title thread:

  • In PR run 2, the title thread waited 47 times for 850 ms in total, all between 19 and 23.5 s, with single waits of up to 43 ms.
  • In the main runs of batch 2 the title thread logged only GpuMutex.wait.hook waits, about 1 ms each.

Two more PR runs with APS5_PROFILE_DRAW=1 had no such frames (max 250 and 269 ms), so I could not see which holder the title waited behind. The diff stores the same images, so I read this as a timing effect rather than a behaviour change. My guess is that a read of a trapped image resolves through ResolveLabelTrap → FlushGpuWrites while the committer is further ahead, but that is not confirmed.

@Ducengarth

Copy link
Copy Markdown
Contributor

Follow-up to my measurement above: I found where the slow frames come from. The title thread's GpuMutex.wait.other waits all come from the GPU map observer in Driver::Driver(). When the import of a new GPU mapping without the lock refuses, the observer waits for the GPU lock on the game's mapping thread. With this PR the committer keeps the lock busier, so the waits show up more often. They do not come from this PR's change itself.

#28882 lets that import fall back to first use when the lock is held. With this PR plus #28882, 0 of 6 runs had the stall, against 16 of 26 with this PR alone. Throughput is unchanged.

This branch has not been deployed

No deployments
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