Skip to content

perf(agc): read the timeline before polling a batch fence in Recorder::Reap - #22787

Closed
AlexFigas wants to merge 1 commit into
boykopovar:mainfrom
AlexFigas:perf/agc-reap-timeline
Closed

AlexFigas wants to merge 1 commit into
boykopovar:mainfrom
AlexFigas:perf/agc-reap-timeline

Conversation

@AlexFigas

Copy link
Copy Markdown
Contributor

What

Recorder::Reap retires the batches the GPU has finished. The draw committer calls it before each occlusion counter dump and each label it writes on the GPU for queue 0 (DumpSamplesOnGpu and WriteLabelOnGpu, through OpportunisticReap). Each call polls the oldest batch's fence with vkGetFenceStatus, even when no batch has finished since the last call.

Every submitted batch also signals the recorder's timeline semaphore with its serial. Reap now reads the timeline value first. While it is below the oldest batch's serial, Reap stops without polling the fence. A batch is still retired only once its fence is signaled. Without a timeline, or when reading it fails, Reap polls the fence as before.

Overlap with #20066. #20066 (open, meh7an) changes the same Reap lines and goes further: it drops the fence per batch and asks the timeline everywhere. This PR is the narrower variant: it keeps the fences, adds no switch and changes no other function. I measured both on the same level and posted the numbers on that thread: Recorder.Reap per frame was 8.6 ms on main, 3.5 with this change and 3.3 with #20066, and the frame went from 227.4 to 222.8 and 222.9 ms. I am not claiming this PR is better. If #20066 merges first, this one should be closed; whichever merges second has to resolve the conflict in Reap.

On this machine's NVIDIA driver, vkGetFenceStatus takes 214 to 217 ns per call and vkGetSemaphoreCounterValue 23 ns, whether the work is pending or done (a standalone loop, fencebench.cpp in the gist). On the level below, one 10 s APS5_PROFILE_DRAW=1 report on main eb20410673 counts 838,146 counter dumps and 470,818 end-of-pipe labels on the committer, next to 609,977 draws.

The new test in RecorderKeptBytes.cpp gives a mock recorder a timeline and checks four things: no fence poll while the timeline has reached no batch, no retire while a reached batch's fence is unsignaled, the retire of exactly the batch both report finished, and the fence fallback when the timeline read fails.

Tested

Windows 10.0.26300, AMD Ryzen 5 9600X (12 threads, 31861 MiB), NVIDIA GeForce RTX 5070 Ti, driver 621.14, display 2560x1440 at 164 Hz, AC power, 2026-11-18. PPSA21564 01.007.000, default settings, 3840x2160 output, no input, caches warm. Unless a line says otherwise, the timings compare main a37edff43c with d36706e188 (this PR on that main), both built here and run from the same relinked executable. The head, 26332fb29e, is d36706e188 rebased onto 0d15c76106: tools/rebase_verify.py keeps every line, none of the commits in between touches core/libs/prx/libSceAgcDriver or core/shader, and agc_recorder_kept_bytes passes on the rebased head. I did not time the rebased head.

Why this level. I ran 84 levels of PPSA21564 (-lvl <name>, 120 s each, one run, APS5_PROFILE_DRAW=1, main eb20410673). Then I ran the 12 slowest, and speedrun_inflator, twice more for 150 s with warm caches. shuriken_ninja_castle was the slowest in both runs: frame p50 247 and 250 ms over the last six 10 s intervals. Next were big_hand_pirate_island (243, 244) and spring_punch_monster_cave (206, 204). speedrun_inflator stopped in an access violation on the title's Draw Geometry thread in all three runs (28, 46 and 60 s after start), and path_maker_mana_tree aborted 34 s after start in both runs of the second pass, so I could not rank them. The tables are in level-sweep.txt in the gist.

Where the time goes. On this level the GPU is busy about 117 ms of a 228 ms frame. Queue 0's packet worker and the draw committer share the rest: about 15,000 draws per frame, plus the dumps and labels above. Without the opportunistic reap (APS5_NO_OPPORTUNISTIC_REAP=1) the level is slower, at 251 ms per frame against 228 ms (two runs each on eb20410673). So the reap has to stay; this change only makes it cheaper. A sampler on the committer (APS5_SAMPLE_COMMITTER, about 80 s per side, on eb20410673 with and without the code change) put 478 of 5,124 samples inside the NVIDIA driver under Reap on main, and 0 with the change. That sampler overcounts time spent in kernel calls, so these counts only show that the poll is gone, not its share of the frame.

PPSA21564 -lvl shuriken_ninja_castle: frame p50 went from 225.8 to 220.5 ms and the mean frame from 233.7 to 227.2 ms, in four alternating window captures; every run of the change had a lower p50 than every run of main.

  • Scene: -lvl shuriken_ninja_castle, no input (the level plays on by itself). The window is 60 to 68 s after the first present.
  • Capture: APS5_TRACE_SECONDS=60:8 and APS5_TRACE_DIR, no other APS5_TRACE_* or APS5_PROFILE_* switch, ANYPS5_GPU=NVIDIA, ANYPS5_DISPLAY_INDEX=0, ANYPS5_VOLUME=0, and APS5_PAD_INPUT_FILE pointing at a file nothing wrote. One warm-up run per side, then the order main, change, four times (always main first). Each run was stopped 96 s after start; no trace dropped events.
  • Libraries: 8 of the 418 staged files differ between the two sets: libSceAgcDriver (the change), and libc, libkernel, libSceAgc, libSceGnmDriver, libSceJobManager, libSceSystemService, libSceVideoOut (the commit they embed).
run commit presents frame p50 p90 p99 mean frame GPU busy per present
main 1 a37edff43cfa 34 227.2 239.8 477.3 235.4 119.4
change 1 d36706e1889b 36 219.2 235.3 459.7 226.5 119.8
main 2 a37edff43cfa 35 223.3 241.5 475.5 232.0 117.5
change 2 d36706e1889b 36 219.0 228.1 453.0 223.4 114.9
main 3 a37edff43cfa 35 226.2 239.4 470.6 233.3 118.8
change 3 d36706e1889b 35 223.0 235.5 464.9 230.3 117.2
main 4 a37edff43cfa 35 226.2 243.0 477.4 234.2 118.9
change 4 d36706e1889b 35 220.8 233.1 467.1 228.7 117.8

Summary lines of round 2 (all eight lines, the two traces of round 2, their trace_digest.py output and the performance_compare.py report are in this gist):

{"commit":"a37edff43cfa","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"60:8"},"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 60:8","first_present":719,"ms":8119.837},"presents":35,"frame_ms":{"p50":223.339,"p90":241.508,"p99":475.466,"max":475.466},"gpu_busy_ms_per_present":117.469,"worker_busy_pct":{"queue worker 0x0":95.810,"queue worker 0x40":97.522,"queue worker 0x48":96.514,"queue worker 0x46":0.612},"phase_totals_ms":{"Driver.Completion":4.661,"Driver.Dispatch":1272.591,"Driver.Dispatch.capture_resources":91.049,"Driver.Dispatch.decode_key_device_setup":183.750,"Driver.Dispatch.lookup_cache":13.365,"Driver.Dispatch.materialize":259.202,"Driver.Dispatch.prepared_invocation":10.942,"Driver.Draw":4352.095,"Driver.Draw.device_setup":289.704,"Driver.Draw.draw_enqueued":1143.538,"Driver.Draw.post_compile_prepare":42.936,"Driver.Draw.prepare":687.432,"Driver.Draw.shader_compile_and_link":2014.855,"Driver.EndSubmission":36.201,"Driver.Packet":23542.783,"Driver.Packet.device_lock":72.669,"Driver.Packet.dispatch":1280.263,"Driver.Packet.draw":4422.559,"Driver.Packet.execute":310.156,"Driver.Packet.flip_flush":1.346,"Driver.Packet.flush_between_packets":174.807,"Driver.Packet.memory_wait":15105.195,"Driver.Packet.pipeline_drain":109.392,"Driver.Packet.pipeline_prepare":99.107,"Driver.Packet.prepare_memory":576.739,"Driver.Packet.rendering_wait":0.089,"Driver.Present":41.813,"Driver.Present.acquire_image":0.486,"Driver.Present.device_setup":0.015,"Driver.Present.gpu_mutex_wait":0.075,"Driver.Present.inflight_wait":0.091,"Driver.Present.present_display_buffer":5.016,"Driver.Present.queue_present":23.586,"Driver.Present.release_and_callback":0.033,"Driver.Present.render_fence_wait":12.416,"Driver.Present.resize":0.068,"Driver.Present.validate":0.010,"Driver.Suspend":1.119,"GpuMutex.wait.dispatch":34.177,"GpuMutex.wait.draw":130.450,"GpuMutex.wait.end":8.185,"GpuMutex.wait.fill":0.118,"GpuMutex.wait.flush":2.123,"GpuMutex.wait.hook":7.236,"GpuMutex.wait.indirect":0.750,"GpuMutex.wait.label":21.869,"GpuMutex.wait.present":0.011,"GpuMutex.wait.wait":4.689,"Graphics.Draw":2272.240,"Graphics.Draw.draw_and_resource_release":1518.631,"Graphics.Draw.index_upload":175.496,"Graphics.Draw.validate":141.007,"Graphics.Draw.vertex_upload":181.624,"Graphics.DrawWithRecipe":1285.364,"Graphics.DrawWithRecipe.draw_and_resource_release":1196.526,"Graphics.DrawWithRecipe.index_upload":10.543,"Graphics.DrawWithRecipe.validate":44.767,"Graphics.DrawWithRecipe.vertex_upload":16.733,"Recorder.Reap":292.783,"Recorder.Submit":394.746,"Recorder.WaitSerial":204.162,"Resources.Complete":53.634,"Resources.Prepare":41.164,"Shader.DrawStage":1354.662,"Shader.DrawStage.capture_resources":884.974,"Shader.DrawStage.materialize":322.732,"Shader.DrawStage.prepared_invocation":131.487,"Shader.PrepareArtifact":2.822,"Shader.ResolveAbi":6.641,"Shader.ResolveGraphicsAbi":2.030,"Shader.ResolveGraphicsStagesAbi":65.222,"VideoOut.Flip":44.199,"VideoOut.Flip.completion_mutex_wait":0.035,"VideoOut.Flip.config_mutex_wait":0.003,"VideoOut.Flip.frame_limit":0.019,"VideoOut.Flip.notify_game":1.563,"VideoOut.Flip.present":40.560,"VideoOut.Flip.validate":0.036,"VideoOut.Flip.vblank_wait":0.020,"VideoOut.Flip.window_prepare":0.062,"VideoOut.Flip.window_title":1.876,"VideoOut.Readiness":0.084,"VideoOut.Readiness.locks_validate":0.036,"Vulkan.Acquire":0.450,"Vulkan.Acquire.acquire_fence_wait":0.056,"Vulkan.Acquire.acquire_image":0.311,"Vulkan.Acquire.fence_reset":0.058,"Vulkan.Acquire.retired_swapchains":0.012,"Vulkan.Dispatch":451.807,"Vulkan.Dispatch.command_record":127.640,"Vulkan.Dispatch.shader_resources":322.596,"Vulkan.DispatchRecipe":17.228,"Vulkan.DispatchRecipe.command_record":17.136,"Vulkan.DrawFromRecipe":1341.136,"Vulkan.GraphicsPipeline":6.476,"Vulkan.GraphicsPipeline.create":3.087,"Vulkan.GraphicsPipeline.modules_and_state":3.379,"Vulkan.GraphicsPipelineLibrary":2.755,"Vulkan.GraphicsPipelineLink":0.153,"Vulkan.Present":3.502,"Vulkan.Present.command_record_scale":1.601,"Vulkan.Present.pixel_upload":0.084,"Vulkan.Present.queue_submit":1.794,"Vulkan.QueuePresent":23.541,"Vulkan.QueuePresent.queue_present":23.503,"Vulkan.Retire":12.413,"Vulkan.Retire.wait":11.636},"top_phases_ms_per_frame":{"Driver.Packet":672.651,"Driver.Packet.memory_wait":431.577,"Driver.Packet.draw":126.359,"Driver.Draw":124.346,"Graphics.Draw":64.921,"Driver.Draw.shader_compile_and_link":57.567,"Graphics.Draw.draw_and_resource_release":43.389,"Shader.DrawStage":38.705},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":715,"Graphics.Barrier.dcc-clear":370,"Graphics.Barrier.dcc-keys":370,"Graphics.Barrier.dispatch-lead":8552,"Graphics.Barrier.dispatch-trail":14149,"Graphics.Barrier.draw":50368,"Graphics.Barrier.fill":1686,"Graphics.Barrier.fill-clear":686,"Graphics.Barrier.indirect-args":315,"Graphics.Barrier.input-mirror":2803,"Graphics.Barrier.label-run":411416,"Graphics.Barrier.present-blit":70,"Graphics.Barrier.shadow-publish":370,"Graphics.Barrier.staging-in":34517,"Graphics.Barrier.staging-out":14351,"Graphics.Barrier.storage-upload":2102,"Graphics.Barrier.storage-writeback":6295,"Graphics.BarrierMerged.dispatch-lead":6227,"Graphics.BarrierMerged.fill":362,"Graphics.BarrierMerged.label-run":43,"Graphics.BarrierMerged.shadow-publish":254,"Graphics.BarrierMerged.staging-in":11118,"Graphics.BarrierMerged.staging-out":14351,"Graphics.BarrierMerged.storage-writeback":909,"Graphics.Copy":37573,"Graphics.Copy.bytes":4452626480,"Graphics.RenderPass":17275,"Graphics.RenderPass.Close.command":11557,"Graphics.RenderPass.Close.image":187,"Graphics.RenderPass.Close.key":125,"Graphics.RenderPass.Close.label":43,"Graphics.RenderPass.Close.new-batch":5363,"Graphics.RenderPass.Continued":499166},"trace_dropped":false,"trace":"aps5-trace-a37edff43cfa-23184.json.gz"}
{"commit":"d36706e1889b","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"60:8"},"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 60:8","first_present":722,"ms":8041.937},"presents":36,"frame_ms":{"p50":218.981,"p90":228.093,"p99":452.971,"max":452.971},"gpu_busy_ms_per_present":114.941,"worker_busy_pct":{"queue worker 0x0":95.786,"queue worker 0x40":97.527,"queue worker 0x48":96.666,"queue worker 0x46":0.590},"phase_totals_ms":{"Driver.Completion":4.703,"Driver.Dispatch":1311.792,"Driver.Dispatch.capture_resources":93.151,"Driver.Dispatch.decode_key_device_setup":192.264,"Driver.Dispatch.lookup_cache":12.958,"Driver.Dispatch.materialize":256.524,"Driver.Dispatch.prepared_invocation":11.346,"Driver.Draw":4356.592,"Driver.Draw.device_setup":284.942,"Driver.Draw.draw_enqueued":1150.682,"Driver.Draw.post_compile_prepare":43.548,"Driver.Draw.prepare":683.525,"Driver.Draw.shader_compile_and_link":2018.340,"Driver.EndSubmission":39.926,"Driver.Packet":23320.595,"Driver.Packet.device_lock":72.817,"Driver.Packet.dispatch":1319.386,"Driver.Packet.draw":4428.893,"Driver.Packet.execute":310.998,"Driver.Packet.flip_flush":1.336,"Driver.Packet.flush_between_packets":172.914,"Driver.Packet.memory_wait":14939.114,"Driver.Packet.pipeline_drain":109.490,"Driver.Packet.pipeline_prepare":93.989,"Driver.Packet.prepare_memory":598.002,"Driver.Packet.rendering_wait":0.046,"Driver.Present":42.788,"Driver.Present.acquire_image":0.515,"Driver.Present.device_setup":0.015,"Driver.Present.gpu_mutex_wait":0.097,"Driver.Present.inflight_wait":0.093,"Driver.Present.present_display_buffer":5.428,"Driver.Present.queue_present":23.078,"Driver.Present.release_and_callback":0.035,"Driver.Present.render_fence_wait":13.432,"Driver.Present.resize":0.069,"Driver.Present.validate":0.010,"Driver.Suspend":2.127,"GpuMutex.wait.dispatch":49.691,"GpuMutex.wait.draw":127.810,"GpuMutex.wait.end":9.442,"GpuMutex.wait.fill":0.170,"GpuMutex.wait.flush":1.967,"GpuMutex.wait.hook":4.418,"GpuMutex.wait.indirect":0.878,"GpuMutex.wait.label":21.430,"GpuMutex.wait.present":0.030,"GpuMutex.wait.wait":4.075,"Graphics.Draw":2317.599,"Graphics.Draw.draw_and_resource_release":1551.303,"Graphics.Draw.index_upload":179.470,"Graphics.Draw.validate":146.257,"Graphics.Draw.vertex_upload":184.518,"Graphics.DrawWithRecipe":1299.984,"Graphics.DrawWithRecipe.draw_and_resource_release":1212.267,"Graphics.DrawWithRecipe.index_upload":10.640,"Graphics.DrawWithRecipe.validate":44.470,"Graphics.DrawWithRecipe.vertex_upload":16.142,"Recorder.Reap":123.091,"Recorder.Submit":392.967,"Recorder.WaitSerial":225.081,"Resources.Complete":50.996,"Resources.Prepare":37.922,"Shader.DrawStage":1356.568,"Shader.DrawStage.capture_resources":886.535,"Shader.DrawStage.materialize":321.916,"Shader.DrawStage.prepared_invocation":132.248,"Shader.PrepareArtifact":3.585,"Shader.ResolveAbi":7.024,"Shader.ResolveGraphicsAbi":3.938,"Shader.ResolveGraphicsStagesAbi":66.303,"VideoOut.Flip":45.398,"VideoOut.Flip.completion_mutex_wait":0.036,"VideoOut.Flip.config_mutex_wait":0.004,"VideoOut.Flip.frame_limit":0.020,"VideoOut.Flip.notify_game":2.095,"VideoOut.Flip.present":41.224,"VideoOut.Flip.validate":0.036,"VideoOut.Flip.vblank_wait":0.022,"VideoOut.Flip.window_prepare":0.062,"VideoOut.Flip.window_title":1.875,"VideoOut.Readiness":0.084,"VideoOut.Readiness.locks_validate":0.035,"Vulkan.Acquire":0.478,"Vulkan.Acquire.acquire_fence_wait":0.062,"Vulkan.Acquire.acquire_image":0.324,"Vulkan.Acquire.fence_reset":0.065,"Vulkan.Acquire.retired_swapchains":0.015,"Vulkan.Dispatch":467.257,"Vulkan.Dispatch.command_record":126.973,"Vulkan.Dispatch.shader_resources":338.670,"Vulkan.DispatchRecipe":19.614,"Vulkan.DispatchRecipe.command_record":19.516,"Vulkan.DrawFromRecipe":1356.091,"Vulkan.GraphicsPipeline":6.667,"Vulkan.GraphicsPipeline.create":3.147,"Vulkan.GraphicsPipeline.modules_and_state":3.509,"Vulkan.GraphicsPipelineLibrary":2.776,"Vulkan.GraphicsPipelineLink":0.169,"Vulkan.Present":3.702,"Vulkan.Present.command_record_scale":1.645,"Vulkan.Present.pixel_upload":0.102,"Vulkan.Present.queue_submit":1.927,"Vulkan.QueuePresent":23.024,"Vulkan.QueuePresent.queue_present":22.986,"Vulkan.Retire":13.428,"Vulkan.Retire.wait":12.680},"top_phases_ms_per_frame":{"Driver.Packet":647.794,"Driver.Packet.memory_wait":414.975,"Driver.Packet.draw":123.025,"Driver.Draw":121.016,"Graphics.Draw":64.378,"Driver.Draw.shader_compile_and_link":56.065,"Graphics.Draw.draw_and_resource_release":43.092,"Shader.DrawStage":37.682},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":717,"Graphics.Barrier.dcc-clear":384,"Graphics.Barrier.dcc-keys":384,"Graphics.Barrier.dispatch-lead":8744,"Graphics.Barrier.dispatch-trail":14563,"Graphics.Barrier.draw":49064,"Graphics.Barrier.fill":1743,"Graphics.Barrier.fill-clear":706,"Graphics.Barrier.indirect-args":324,"Graphics.Barrier.input-mirror":2888,"Graphics.Barrier.label-run":412294,"Graphics.Barrier.present-blit":72,"Graphics.Barrier.shadow-publish":382,"Graphics.Barrier.staging-in":35308,"Graphics.Barrier.staging-out":14679,"Graphics.Barrier.storage-upload":2184,"Graphics.Barrier.storage-writeback":6512,"Graphics.BarrierMerged.dispatch-lead":6467,"Graphics.BarrierMerged.fill":371,"Graphics.BarrierMerged.label-run":43,"Graphics.BarrierMerged.shadow-publish":266,"Graphics.BarrierMerged.staging-in":11354,"Graphics.BarrierMerged.staging-out":14679,"Graphics.BarrierMerged.storage-writeback":932,"Graphics.Copy":37949,"Graphics.Copy.bytes":4742966282,"Graphics.RenderPass":17291,"Graphics.RenderPass.Close.command":11635,"Graphics.RenderPass.Close.image":203,"Graphics.RenderPass.Close.key":128,"Graphics.RenderPass.Close.label":43,"Graphics.RenderPass.Close.new-batch":5282,"Graphics.RenderPass.Continued":501834},"trace_dropped":false,"trace":"aps5-trace-d36706e1889b-12368.json.gz"}

A second series with APS5_TRACE_SUMMARY_EVERY=10 (no trace; mean over the last six 10 s intervals of 150 s runs), same scene, three alternating rounds: mean frame 228.5, 228.2 and 228.4 ms on main, 224.8, 224.0 and 222.9 ms with the change. GPU busy was 117.1 to 117.5 ms per present on both sides. Two more rounds with the order reversed (change first) gave 226.1 and 227.6 ms on main against 222.7 and 224.2 ms with the change, so the gain does not follow the run order. In those summary runs Recorder.Reap took 8.55 to 8.60 ms per frame on main and 3.50 to 3.61 ms with the change (phase_totals_ms over the same intervals, in the tables.txt of the #20066 gist); in the window captures 8.35 to 8.43 against 3.47 to 3.50. On the second slowest level, big_hand_pirate_island, two alternating rounds gave 219.2 and 206.2 ms on main, 200.7 and 202.8 ms with the change: no slowdown, but too noisy to claim a gain.

Tests.

  • The new test: with the test kept, I broke each part of the change in turn: Reap as on main, stopping at the reached serial too (>=), retiring without the fence check, no fence fallback after a failed timeline read, and the timeline read never resolved. Each break failed agc_recorder_kept_bytes. The unchanged branch passed before and after.
  • GPU tests under validation: I ran the 56 tests matching ^(agc_.*(recorder|label|sample_dump|kept_bytes)|video_out_flip_labels) on main and on the change, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, VK_LOADER_LAYERS_DISABLE=~implicit~ and validation layer 1.4.368. Both passed 56 of 56. Each log shows the loader inserting the layer (65 times) and never reports it missing, and neither has a VUID- message. The GPU line is Selected GPU name=NVIDIA GeForce RTX 5070 Ti vendor=0x10de device=0x2c05 subgroup=32.
  • Selected tests: tools/select_tests.py picked 3224 tests for the changed files. Both sides failed the same 99 tests and no others. 75 did not run because their executables were not built here: Windows Defender flagged freshly linked AGC test executables (objcopy then fails with Invalid argument), and UploadCacheReadOnlyFlush.cpp calls setenv, which this MinGW does not declare. The other 24 fail on main too. One of them, agc_driver_store_over_untracked, fails at random under parallel load: run six at a time on eb20410673, it failed 18 of 120 runs on main and 23 of 120 with the change, always in its "second store" case.

Not covered. Only this machine and GPU: not the AMD iGPU, not Linux, not lavapipe. Only PPSA21564, and timings on two levels. Reap can now miss a batch whose fence is signaled while the timeline value read just before it was still below its serial; that batch is retired at the next Reap. I did not measure how often that happens. The other fence polls in Recorder.cpp (signaled, unsignaled and the pending-write lookup) are unchanged.

Checklist

  • Based on current main; no other open PR implements the same functions (perf(agc): drop per-batch fences when a timeline tracks completion #20066 overlaps; see What)
  • 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 5070 Ti, driver 621.14, Windows 10.0.26300
  • AI-assisted: yes

…::Reap

Every submitted batch signals the recorder's timeline semaphore with its serial. Reap now reads the timeline value first and stops without calling vkGetFenceStatus while the front batch's serial has not been reached; the fence is still checked before a batch is retired. Without a timeline, or when reading it fails, Reap polls the fence as before.

@milescoviello milescoviello 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 head 26332fb29e by reading; I didn't build or run it.

Checked in Recorder.cpp:

  • The skip is safe. Every batch reaches inFlight only through the one push_back after vkQueueSubmit, and that submit signals timeline with the batch's serial whenever timeline exists. A timeline value below the front batch's serial therefore means that batch hasn't completed, and nothing is skipped that the fence would have reported done.
  • Retirement is unchanged. A batch still retires only on its fence, so an out-of-order or failed timeline read can delay a reap but never retire a batch early.
  • The fallbacks hold. A failed vkGetSemaphoreCounterValueKHR (for example on device loss) sets reached to the maximum and drops back to polling the fence. Without timeline semaphores, or when creating the semaphore fails, the pointer stays null and Reap behaves as on main. The new early return in the constructor only skips the lookup on that failure path.
  • reached is re-read only when the next front serial passes it, so the loop makes at most one extra counter read per retired batch.

No changes needed from my side. The overlap with #20066 in Reap is already noted in the body.

AI-assisted: yes

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

github-actions Bot commented Nov 18, 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 5609 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9289 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9712 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 11587 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13809 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 15136 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 15548 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 15570 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 16427 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
PR 16879 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 17611 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 17943 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 18029 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 18173 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 18185 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 20041 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 20172 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 20519 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 21923 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 22029 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/RecorderKeptBytes.cpp
PR 22190 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 22424 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 22697 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/RecorderKeptBytes.cpp
PR 22944 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 23058 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 23919 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 24327 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 25010 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 26613 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 26691 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 27312 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 27343 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/RecorderKeptBytes.cpp
PR 27875 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 27979 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 27984 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 28142 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 28195 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 28214 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 28237 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 28290 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/RecorderKeptBytes.cpp
PR 28291 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/RecorderKeptBytes.cpp
PR 28292 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/RecorderKeptBytes.cpp
PR 28293 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/RecorderKeptBytes.cpp
PR 28396 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 28411 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/RecorderKeptBytes.cpp
PR 28470 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp

@Colewiz7

Copy link
Copy Markdown
Contributor

Head 26332fb29e merged onto main d89f26516c as ab1d683ff4, no conflict. Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036).

No new failures and no new validation messages on either GPU.

RX 7900 XT iGPU
tests run (6171 on the 7900 XT, the 2007 GPU ones on the iGPU), new failures vs main none none
-R '^agc' (1940 tests) with the layer, new failures vs main none none
VUID- / SYNC-HAZARD lines 0 / 0 0 / 0

Layer runs used VK_LAYER_KHRONOS_validation 1.4.363.1 with VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; the loader inserted the layer in every run, and the validation message set matches main.

AI-assisted: yes

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 19, 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 — comments

The timeline gate appears consistent with the submission serials and retains the fence check, but I did not run the checks needed to support a formal approval.

What I ran

Reviewed head 26332fb29e3f0c18b3e1a1d6877338eb7cce709d using the prepared description, commit list, manifest, diff, and targeted reads through repo_read.py. No tests or builds were run.

Results

Check Result Note
Changed code review passed Three changed files inspected
Build and tests not run Author-reported results were not rerun

Findings

Blocking

None verified.

Non-blocking

None.

Not verified

The changed files’ full texts were included in the review bundle, but only relevant ranges were read. files.json was not available; the manifest and file listing show all three changed files included, with no excluded changed files. Build, tests, runtime behavior, and the reported performance measurements were not independently verified.

To get this to a good state

Nothing is required.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

This passed review on 26332fb, but it now conflicts with main in Recorder.cpp, RecorderKeptBytes.cpp. Please merge main into the branch and push; it goes back to the merge queue on the new head.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Main now retires batches from the timeline without polling a fence by default (#20066), so the timeline read before the fence poll here only affects the APS5_BATCH_FENCES path. If you still want that path faster, please merge main, keep the change to the fence path only, and post a before and after from the same machine and scene with APS5_BATCH_FENCES=1. I will review it on the new head.

@AlexFigas

Copy link
Copy Markdown
Contributor Author

@oneandonlydean About your comment:

If you still want that path faster, please merge main, keep the change to the fence path only, and post a before and after from the same machine and scene with APS5_BATCH_FENCES=1. I will review it on the new head.

Thanks for the offer. I'm closing this PR instead, as its description proposed: "If #20066 merges first, this one should be closed".

  • Default path. On main, Reap reads the timeline and polls no fence. On my run on #20066, before it merged, Recorder.Reap took 8.55 to 8.60 ms per frame on main a37edff43c, 3.50 to 3.61 ms with this change (d36706e188, the same patch as 26332fb29e) and 3.25 to 3.30 ms with perf(agc): drop per-batch fences when a timeline tracks completion #20066's head 8d0508a319, the head that merged.
  • Fence path. On main a recorder with a timeline polls fences only when APS5_BATCH_FENCES is set; the constructor sets fenceless from that switch alone. perf(agc): drop per-batch fences when a timeline tracks completion #20066 describes the switch as the old behaviour, so I'd rather leave that path unchanged than speed up a path such a recorder does not take by default.
  • Not measured. I did not measure anything with APS5_BATCH_FENCES set.

Thanks for the reviews and the test run.

@AlexFigas AlexFigas closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* needs rebase Conflicts with main, rebase needed perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants