Repository navigation
perf(agc): read the import only for words a staged copy-back changes - #20292
oneandonlydean merged 1 commit into
Conversation
The changed-byte copy-back kernels read the target word, which lies in the host import, for every word of the range. Where the shader changed no byte of a word nothing is stored and nothing is counted, whatever the target holds, so the kernels now return before that read. APS5_CHANGED_COPY_ALWAYS still stores every word; the copy-back tests now also run with it set.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the optional performance evidence is noted below.
What I ran
Reviewed head deb34c9adc3bb167149f36de8a93aad9ab000a2d. No commands or tests were run; I reviewed the prepared diff and targeted source ranges using repo_read.py.
Results
| Check | Result | Note |
|---|---|---|
| Changed shader logic | passed | Early return preserves always-copy path |
| Test additions | passed | Always-copy expectation and CTest setup inspected |
| Runtime checks | not run | Results in the description are author-reported |
Findings
Blocking
None.
Non-blocking
- The reported performance comparison and test results are author-provided; I did not independently run or inspect their traces.
Not verified
- Read:
StagingCopyBack.comp,StagingCopyBackBound.comp,Recorder.cpplines 1115–1245, andagc_driver_recorder_tests.cmakelines 385–405. - Excluded: full
Recorder.cppbeyond the targeted range and all unchanged repository files. The prepared bundle lists all four changed files; the diff and relevant ranges were inspected. - Runtime behavior, test execution, and performance claims were not independently verified.
To get this to a good state
Nothing is required. The author-reported runtime and performance evidence is optional context.
|
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.
|
|
Verified on two real AMD generations with a negative control (Mesa 26.2.6, validation 1.4.363, Correctness — all four changed-copy tests, 2 runs/gen:
The early-return is correctness-preserving — it fires only when Negative control (proves the two new
Restoring the guard rebuilt the SPV back to the original checksums and all four pass again. So the always-mode tests fail precisely when the early-return is mis-scoped and pass when it isn't — they genuinely cover the path the optimization bypasses. Head at deb34c9. AI-assisted: yes |
What
The changed-byte copy-back kernels (StagingCopyBack.comp, StagingCopyBackBound.comp) load the target word for every word of a staged range. The target is in the host import, in system memory. Where the shader changed no byte of a word, the kernel stores nothing and counts nothing, whatever the target holds. The kernels now return before that load for such words. What they store and count is unchanged.
APS5_CHANGED_COPY_ALWAYSstill loads and stores every word.agc_changed_copy_alwaysandagc_bound_changed_copy_alwaysrun the two existing copy-back tests with it set.Tested
Windows 10.0.26300, AMD Ryzen 5 9600X, NVIDIA GeForce RTX 5070 Ti, driver 621.14, 2026-11-14. The title runs compare
main4aa2f8b694with6ac4cb33af(thatmainplus this commit). The head,deb34c9adc, is that commit rebased one4742e6522, plus the WindowsPATHsetting for the two new tests; no commit in between touches the files this PR changes.PPSA21564 01.007.000: over four alternating runs per side, the mean frame p50 went from 83.8 to 78.8 ms and the mean GPU busy time from 66.7 to 60.9 ms per present. Every run of the change was faster than every run of
main.-lvl timestop_casino, default settings, 3840x2160 output, caches warm. The window falls in the ship flight that opens the level, the only part of the level my runs reach before the device lost (next item). Input only to get there: from 10 to 27 s after start, Cross, then L2+R2 held for 3.5 s, about every 5 s (tools/pad_input.py). In every run the last 3.5 s hold was queued 25.9 s after start; the window starts 32 s after the first present, so more than 32 s after start. The flight follows the controller: of two runs ofmainwith a frame dumped every 50 presents, the one with input to the end was about 100 presents further along (its dumps 16 and 17 match dumps 18 and 19 of the other; screenshots in the gist). Without input it flies on by itself, so the window measures the flight with no input.APS5_TRACE_SECONDS=32:8andAPS5_TRACE_DIR, no otherAPS5_TRACE_*orAPS5_PROFILE_*switch, log not redirected,ANYPS5_GPU=NVIDIA,ANYPS5_DISPLAY_INDEX=1,ANYPS5_VOLUME=0. The NVIDIA output reported 2560x1440 at 164 Hz. Order main, change, four times; no trace dropped events. Each run was stopped 62 s after start: the level ends inVK_ERROR_DEVICE_LOSTonmaintoo (4 runs on this machine ended with it, 75 to 123 s after start).libSceAudioPropagation.prxbuilt from fix(libSceAudioPropagation): find no path without rays and set audio paths #19326 (head43a3893170). With its own librarymainstopped at the level on the title's assert aftersceAudioPropagationSourceCalculateAudioPaths failed : 0x8a700001(one run onaf13412d22, 51 s after start).libSceAgcDriver.prxdiffers in behaviour between the two library sets.libc,libkernelandlibSceVideoOutdiffer by the commit they embed for the run report,libSceJson2by its link timestamp only.4aa2f8b694476ac4cb33afb64aa2f8b694476ac4cb33afb64aa2f8b694476ac4cb33afb64aa2f8b694476ac4cb33afb6Summary lines of round 2 (all eight lines, the traces and their
trace_digest.pyoutput are in this gist):{"commit":"4aa2f8b69447","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"32: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 32:8","first_present":790,"ms":8035.956},"presents":95,"frame_ms":{"p50":84.168,"p90":89.151,"p99":113.239,"max":113.239},"gpu_busy_ms_per_present":66.972,"worker_busy_pct":{"queue worker 0x0":97.698,"queue worker 0x40":99.209,"queue worker 0x48":95.660,"queue worker 0x46":1.621},"phase_totals_ms":{"Driver.Completion":9.173,"Driver.Dispatch":1140.884,"Driver.Dispatch.capture_resources":111.316,"Driver.Dispatch.decode_key_device_setup":20.101,"Driver.Dispatch.lookup_cache":17.473,"Driver.Dispatch.materialize":7.942,"Driver.Dispatch.prepared_invocation":6.307,"Driver.Draw":4019.003,"Driver.Draw.device_setup":173.243,"Driver.Draw.draw_enqueued":1235.830,"Driver.Draw.post_compile_prepare":28.418,"Driver.Draw.prepare":490.758,"Driver.Draw.shader_compile_and_link":1947.864,"Driver.EndSubmission":100.712,"Driver.Packet":23530.935,"Driver.Packet.device_lock":45.874,"Driver.Packet.dispatch":1632.428,"Driver.Packet.draw":4064.279,"Driver.Packet.execute":208.564,"Driver.Packet.flip_flush":3.592,"Driver.Packet.flush_between_packets":230.712,"Driver.Packet.memory_wait":14697.921,"Driver.Packet.pipeline_drain":140.005,"Driver.Packet.pipeline_prepare":62.427,"Driver.Packet.prepare_memory":1674.758,"Driver.Packet.rendering_wait":0.113,"Driver.Present":57.600,"Driver.Present.acquire_image":1.363,"Driver.Present.device_setup":0.041,"Driver.Present.gpu_mutex_wait":0.396,"Driver.Present.inflight_wait":0.245,"Driver.Present.present_display_buffer":14.428,"Driver.Present.queue_present":35.089,"Driver.Present.release_and_callback":0.103,"Driver.Present.render_fence_wait":5.689,"Driver.Present.resize":0.164,"Driver.Present.validate":0.034,"Driver.Suspend":0.066,"GpuMutex.wait.dispatch":102.161,"GpuMutex.wait.draw":358.411,"GpuMutex.wait.end":16.698,"GpuMutex.wait.fill":1.490,"GpuMutex.wait.flush":1.803,"GpuMutex.wait.hook":24.946,"GpuMutex.wait.indirect":0.029,"GpuMutex.wait.label":73.879,"GpuMutex.wait.present":0.171,"GpuMutex.wait.wait":3.284,"Graphics.Draw":3113.249,"Graphics.Draw.draw_and_resource_release":2491.932,"Graphics.Draw.index_upload":156.862,"Graphics.Draw.validate":169.379,"Graphics.Draw.vertex_upload":180.222,"Graphics.DrawWithRecipe":506.541,"Graphics.DrawWithRecipe.draw_and_resource_release":475.911,"Graphics.DrawWithRecipe.index_upload":3.929,"Graphics.DrawWithRecipe.validate":12.996,"Graphics.DrawWithRecipe.vertex_upload":9.226,"Recorder.Reap":204.724,"Recorder.Submit":295.233,"Recorder.WaitSerial":1184.787,"Resources.Complete":85.113,"Resources.Prepare":130.047,"Shader.DrawStage":1406.019,"Shader.DrawStage.capture_resources":970.171,"Shader.DrawStage.materialize":264.352,"Shader.DrawStage.prepared_invocation":153.663,"Shader.PrepareArtifact":0.010,"Shader.ResolveAbi":15.851,"Shader.ResolveGraphicsAbi":5.158,"Shader.ResolveGraphicsStagesAbi":90.834,"VideoOut.Flip":71.705,"VideoOut.Flip.completion_mutex_wait":0.113,"VideoOut.Flip.config_mutex_wait":0.008,"VideoOut.Flip.frame_limit":0.057,"VideoOut.Flip.notify_game":8.470,"VideoOut.Flip.present":56.888,"VideoOut.Flip.validate":0.102,"VideoOut.Flip.vblank_wait":0.060,"VideoOut.Flip.window_prepare":0.143,"VideoOut.Flip.window_title":5.773,"VideoOut.Readiness":0.234,"VideoOut.Readiness.locks_validate":0.090,"Vulkan.Acquire":1.264,"Vulkan.Acquire.acquire_fence_wait":0.166,"Vulkan.Acquire.acquire_image":0.853,"Vulkan.Acquire.fence_reset":0.175,"Vulkan.Acquire.retired_swapchains":0.042,"Vulkan.Dispatch":427.130,"Vulkan.Dispatch.command_record":107.965,"Vulkan.Dispatch.shader_resources":317.566,"Vulkan.DispatchRecipe":37.733,"Vulkan.DispatchRecipe.command_record":37.521,"Vulkan.DrawFromRecipe":520.405,"Vulkan.Present":10.091,"Vulkan.Present.command_record_scale":4.352,"Vulkan.Present.pixel_upload":0.220,"Vulkan.Present.queue_submit":5.442,"Vulkan.QueuePresent":34.950,"Vulkan.QueuePresent.queue_present":34.802,"Vulkan.Retire":5.654,"Vulkan.Retire.wait":4.029},"top_phases_ms_per_frame":{"Driver.Packet":247.694,"Driver.Packet.memory_wait":154.715,"Driver.Packet.draw":42.782,"Driver.Draw":42.305,"Graphics.Draw":32.771,"Graphics.Draw.draw_and_resource_release":26.231,"Driver.Draw.shader_compile_and_link":20.504,"Driver.Packet.prepare_memory":17.629},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":1140,"Graphics.Barrier.dcc-clear":950,"Graphics.Barrier.dcc-keys":950,"Graphics.Barrier.dispatch-lead":8811,"Graphics.Barrier.dispatch-trail":8455,"Graphics.Barrier.draw":232759,"Graphics.Barrier.fill":2666,"Graphics.Barrier.fill-clear":1520,"Graphics.Barrier.indirect-args":665,"Graphics.Barrier.label-run":27322,"Graphics.Barrier.present-blit":190,"Graphics.Barrier.shadow-publish":570,"Graphics.Barrier.staging-in":11622,"Graphics.Barrier.staging-out":5014,"Graphics.Barrier.storage-upload":3420,"Graphics.Barrier.storage-writeback":15771,"Graphics.BarrierMerged.dispatch-lead":974,"Graphics.BarrierMerged.fill":750,"Graphics.BarrierMerged.label-run":58,"Graphics.BarrierMerged.shadow-publish":380,"Graphics.BarrierMerged.staging-in":3610,"Graphics.BarrierMerged.staging-out":5014,"Graphics.BarrierMerged.storage-writeback":2451,"Graphics.Copy":64492,"Graphics.Copy.bytes":46502897056,"Graphics.RenderPass":50913,"Graphics.RenderPass.Close.command":47024,"Graphics.RenderPass.Close.image":253,"Graphics.RenderPass.Close.key":269,"Graphics.RenderPass.Close.label":58,"Graphics.RenderPass.Close.new-batch":3309,"Graphics.RenderPass.Continued":201644},"trace_dropped":false,"trace":"aps5-trace-4aa2f8b69447-852.json.gz"} {"commit":"6ac4cb33afb6","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"32: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 32:8","first_present":796,"ms":8025.189},"presents":101,"frame_ms":{"p50":78.269,"p90":84.308,"p99":92.555,"max":107.611},"gpu_busy_ms_per_present":61.092,"worker_busy_pct":{"queue worker 0x0":97.658,"queue worker 0x40":99.223,"queue worker 0x48":95.466,"queue worker 0x46":1.653},"phase_totals_ms":{"Driver.Completion":9.416,"Driver.Dispatch":1203.041,"Driver.Dispatch.capture_resources":111.445,"Driver.Dispatch.decode_key_device_setup":18.888,"Driver.Dispatch.lookup_cache":18.000,"Driver.Dispatch.materialize":8.337,"Driver.Dispatch.prepared_invocation":6.503,"Driver.Draw":4164.892,"Driver.Draw.device_setup":172.522,"Driver.Draw.draw_enqueued":1318.477,"Driver.Draw.post_compile_prepare":28.809,"Driver.Draw.prepare":497.198,"Driver.Draw.shader_compile_and_link":2000.811,"Driver.EndSubmission":109.576,"Driver.Packet":23474.995,"Driver.Packet.device_lock":48.398,"Driver.Packet.dispatch":1717.020,"Driver.Packet.draw":4209.080,"Driver.Packet.execute":214.809,"Driver.Packet.flip_flush":3.676,"Driver.Packet.flush_between_packets":261.057,"Driver.Packet.memory_wait":14589.588,"Driver.Packet.pipeline_drain":142.649,"Driver.Packet.pipeline_prepare":65.292,"Driver.Packet.prepare_memory":1413.458,"Driver.Packet.rendering_wait":0.211,"Driver.Present":61.701,"Driver.Present.acquire_image":1.427,"Driver.Present.device_setup":0.041,"Driver.Present.gpu_mutex_wait":0.402,"Driver.Present.inflight_wait":0.255,"Driver.Present.present_display_buffer":15.286,"Driver.Present.queue_present":36.536,"Driver.Present.release_and_callback":0.103,"Driver.Present.render_fence_wait":7.402,"Driver.Present.resize":0.168,"Driver.Present.validate":0.032,"Driver.Suspend":0.034,"GpuMutex.wait.dispatch":121.729,"GpuMutex.wait.draw":396.639,"GpuMutex.wait.end":23.363,"GpuMutex.wait.fill":1.700,"GpuMutex.wait.flush":2.537,"GpuMutex.wait.hook":46.378,"GpuMutex.wait.label":75.841,"GpuMutex.wait.other":0.001,"GpuMutex.wait.present":0.220,"GpuMutex.wait.wait":3.917,"Graphics.Draw":3269.286,"Graphics.Draw.draw_and_resource_release":2588.329,"Graphics.Draw.index_upload":165.539,"Graphics.Draw.validate":179.405,"Graphics.Draw.vertex_upload":192.357,"Graphics.DrawWithRecipe":497.004,"Graphics.DrawWithRecipe.draw_and_resource_release":466.504,"Graphics.DrawWithRecipe.index_upload":3.794,"Graphics.DrawWithRecipe.validate":13.278,"Graphics.DrawWithRecipe.vertex_upload":8.883,"Recorder.Reap":202.714,"Recorder.Submit":307.465,"Recorder.WaitSerial":859.877,"Resources.Complete":98.370,"Resources.Prepare":133.259,"Shader.DrawStage":1444.182,"Shader.DrawStage.capture_resources":995.201,"Shader.DrawStage.materialize":277.590,"Shader.DrawStage.prepared_invocation":152.937,"Shader.PrepareArtifact":0.009,"Shader.ResolveAbi":16.395,"Shader.ResolveGraphicsAbi":5.112,"Shader.ResolveGraphicsStagesAbi":93.385,"VideoOut.Flip":70.969,"VideoOut.Flip.completion_mutex_wait":0.114,"VideoOut.Flip.config_mutex_wait":0.007,"VideoOut.Flip.frame_limit":0.054,"VideoOut.Flip.notify_game":3.655,"VideoOut.Flip.present":61.226,"VideoOut.Flip.validate":0.114,"VideoOut.Flip.vblank_wait":0.070,"VideoOut.Flip.window_prepare":0.150,"VideoOut.Flip.window_title":5.506,"VideoOut.Readiness":0.244,"VideoOut.Readiness.locks_validate":0.096,"Vulkan.Acquire":1.320,"Vulkan.Acquire.acquire_fence_wait":0.174,"Vulkan.Acquire.acquire_image":0.892,"Vulkan.Acquire.fence_reset":0.179,"Vulkan.Acquire.retired_swapchains":0.043,"Vulkan.Dispatch":453.003,"Vulkan.Dispatch.command_record":111.674,"Vulkan.Dispatch.shader_resources":339.527,"Vulkan.DispatchRecipe":37.938,"Vulkan.DispatchRecipe.command_record":37.710,"Vulkan.DrawFromRecipe":511.011,"Vulkan.Present":10.654,"Vulkan.Present.command_record_scale":4.543,"Vulkan.Present.pixel_upload":0.235,"Vulkan.Present.queue_submit":5.796,"Vulkan.QueuePresent":36.395,"Vulkan.QueuePresent.queue_present":36.248,"Vulkan.Retire":7.370,"Vulkan.Retire.wait":5.864},"top_phases_ms_per_frame":{"Driver.Packet":232.426,"Driver.Packet.memory_wait":144.451,"Driver.Packet.draw":41.674,"Driver.Draw":41.237,"Graphics.Draw":32.369,"Graphics.Draw.draw_and_resource_release":25.627,"Driver.Draw.shader_compile_and_link":19.810,"Driver.Packet.dispatch":17.000},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":1212,"Graphics.Barrier.dcc-clear":1010,"Graphics.Barrier.dcc-keys":1010,"Graphics.Barrier.dispatch-lead":9368,"Graphics.Barrier.dispatch-trail":8989,"Graphics.Barrier.draw":231070,"Graphics.Barrier.fill":2838,"Graphics.Barrier.fill-clear":1616,"Graphics.Barrier.indirect-args":707,"Graphics.Barrier.label-run":28838,"Graphics.Barrier.present-blit":202,"Graphics.Barrier.shadow-publish":606,"Graphics.Barrier.staging-in":12345,"Graphics.Barrier.staging-out":5336,"Graphics.Barrier.storage-upload":3636,"Graphics.Barrier.storage-writeback":16766,"Graphics.BarrierMerged.dispatch-lead":1035,"Graphics.BarrierMerged.fill":798,"Graphics.BarrierMerged.label-run":29,"Graphics.BarrierMerged.shadow-publish":404,"Graphics.BarrierMerged.staging-in":3865,"Graphics.BarrierMerged.staging-out":5336,"Graphics.BarrierMerged.storage-writeback":2626,"Graphics.Copy":64737,"Graphics.Copy.bytes":49528344024,"Graphics.RenderPass":51033,"Graphics.RenderPass.Close.command":46652,"Graphics.RenderPass.Close.image":572,"Graphics.RenderPass.Close.key":279,"Graphics.RenderPass.Close.label":29,"Graphics.RenderPass.Close.new-batch":3501,"Graphics.RenderPass.Continued":211624},"trace_dropped":false,"trace":"aps5-trace-6ac4cb33afb6-22896.json.gz"}One more run per side with
APS5_PROFILE_GPU=1(input to 35 s after start, stopped 59 s after start), not part of the comparison: in the three 10 s windows inside the level, thestaging-outclass took 8.5, 9.3 and 9.4 ms per present onmainand 3.7, 4.4 and 4.3 ms with the change. Its copy-back ranges covered 222 to 235 MiB per present on both sides; the traffic itself was not measured. The other classes stayed within 1 ms per present. The[gputime]lines are in the gist.Tests:
tools/select_tests.pyfor the four changed files: 2969 tests on the change and 2967 onmain(the change adds two). The same three fail on both:pr_overlap_tools,conventions_doc_links, andagc_driver_upload_cache_read_only_flush, which does not build on Windows (setenv; fix(tests): set the upload cache test's environment with _putenv_s on Windows #19899 is open for it).ctest -R 'changed_copy|staging|copy_back|copied_write' -Von4aa2f8b694ande4742e6522(15 tests) and on6ac4cb33afanddeb34c9adc(17, with the two new ones), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer, implicit layers disabled, validation layer 1.4.368: all pass in all four.agc_adaptive_stagingandagc_buffer_pool_small_device_no_stagingmake no Vulkan instance; every other test's log showsInsert instance layer "VK_LAYER_KHRONOS_validation". No log showswas not foundor anyVUID-message.agc_changed_copyandagc_bound_changed_copycheck every word and the counter, including words the shader left alone and the CPU changed. Four wrong early returns in each kernel (return when changed, return always, return unless the whole word changed, return without checkingalways) each fail at least one of that kernel's two tests; the commit passes them.tools/pr_overlap.py --branchfound no overlap with the 61 open PRs it could merge. It could not compare 36 that conflict withmainand share the test files; I read their diffs, and none has a hunk in the two changed-copy tests. One of them, #6186, also listsStagingCopyBack.comp, but its copy is the filemainalready has (bloba950cfef8d).Not covered: other GPUs, Linux, and other titles. How many words the kernels skip was not counted.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)