Repository navigation
perf(agc): copy back staged writes by groups of eight words, reading the import only where the shader wrote - #21338
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The shader changes appear internally consistent, but I could not run the reported checks or independently verify the performance captures, so a formal approval is not justified.
What I ran
No commands or tests were run. I read the prepared description, commits, manifest, diff, both changed shaders, the changed Recorder.cpp ranges, the changed test ranges, and the debt entry at head dd038373bc58547dd2bcadc5d2ba0a4703b22089. core/libs/prx/libSceAgcDriver/tests/Recorder.cpp was excluded from the review bundle; I read the ranges containing its changed lines through repo_read.py.
Results
| Check | Result | Note |
|---|---|---|
| Diff review | passed | Changed code and relevant callers inspected |
| Tests | not run | Test results in the description are author-reported |
| Performance evidence | not run | Captures and traces were not independently inspected |
Findings
Blocking
None identified in the code inspected.
Non-blocking
- The new kernels store every valid word in any eight-word group with a shader change. That matches the stated optimization, while preserving the existing byte merge and counter calculation. The potential lost CPU store in the load-to-store window is documented in the description and debt entry. Consider measuring this behavior in representative titles before closing the debt.
Sources
- StagingCopyBack.comp at the reviewed head
- StagingCopyBackBound.comp at the reviewed head
- Recorder.cpp at the reviewed head
Not verified
- I did not run tests or reproduce performance measurements. The test results, mutation checks, timing summaries, and trace availability described in the PR remain author-reported.
- I did not read the full 17,396-line test file; I read the ranges containing the changed lines and relevant changed-copy test logic. No other changed files were excluded; all five changed files and their changed hunks were read.
- Behavior on other GPUs, drivers, operating systems, titles, and CPU writes during the load-to-store window was not verified.
To get this to a good state
Nothing is required. Optional: independently inspect the performance captures and measure whether titles write into the documented load-to-store window.
|
This pull request is labeled |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
…the import only where the shader wrote The changed-byte copy-back kernels load the target word, which lies in the host import in system memory, and store it back word by word, so a group of neighbouring words is written as scattered 4-byte stores. Each group of eight words is now handled by eight lanes: it is left alone unless the shader changed a byte in it, and otherwise the lanes store all eight words, the untouched ones with the value just loaded, so the stores to the import are adjacent words of one group. What the kernels store for a changed byte, and what they count, is unchanged, and APS5_CHANGED_COPY_ALWAYS still stores every word. The bound kernel's dispatches are a multiple of 64 words, so a split never cuts a group. A word of a written group that the shader left alone, or whose changed bytes the CPU had changed too, is now stored back with the value loaded a moment earlier, so a CPU store to it between the load and the store is lost. The debt file records it. The two kernels are now also tested with long stretches where the shader changes nothing.
dd03837 to
b7a3334
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The reviewed change is internally consistent with its stated group writeback behavior; I found no verified blocking defect in the inspected code.
What I ran
- Reviewed head
b7a3334fc731e8b5156cbf51248daef4382a5048usingrepo_read.pyto inspect the prepared description, manifest, diff, both changed shaders, the affectedRecorder.cppfunctions, and the debt entry. - No tests or builds were run. The description reports author-run checks; those are not checks performed for this review.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed code | passed | Kernels, dispatch sizing, tests, and debt entry inspected |
| Build and tests | not run | Author-reported runs only |
| Files outside inspected ranges | not run | Large test file not read |
Findings
Blocking
None verified in the inspected code.
Non-blocking
- The kernels store every word in an active eight-word group, so a concurrent CPU write to an otherwise untouched word can be overwritten by the value loaded immediately before the store. This behavior is documented in the PR description and debt entry; its occurrence rate was not measured.
Not verified
- The changed test hunks in
core/libs/prx/libSceAgcDriver/tests/Recorder.cppwere not read because the full file was excluded from the review bundle. The author reports the test runs in the description, but they were not independently verified. - No build or test commands were run. Performance measurements, generated SPIR-V correspondence, and behavior on other GPUs, drivers, operating systems, titles, and physical consoles were not independently verified.
- Files read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch,StagingCopyBack.comp,StagingCopyBackBound.comp, selected ranges ofGraphics/src/Recorder.cpp, andperf-agc-copy-back-whole-lines.md. - Excluded from inspection: changed test file
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp(full text excluded for size). Nofiles.jsonwas available through the reader.
To get this to a good state
Nothing is required. Optional: measure how often CPU writes overlap the load-to-store window described above.
62b13aa to
b105ab6
Compare
|
@MarcZX10 About your review of b7a3334fc7:
I measured it on one level. The new bullet "The load-to-store window" in the description's Tested section has the method and the numbers. The patch and the counter lines are in the gist (
b105ab6 changes only the debt fragment: it replaces "were not measured" with "measured once, with a diagnostic" and what that leaves open, and it drops the closing condition "or a title's writes into the window are shown not to occur", since one scene does not close the gap. The kernels, |
|
Linux NVIDIA run with the Khronos validation layer of the current head, since the description's runs are on Windows. Setup: Arch Linux, kernel 7.3.4, GCC 16.2.1 Release, NVIDIA GeForce RTX 4090 (10de:2684), driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head
The set holds the same 17 tests on both sides, among them No new AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head b105ab6836cd98744da87dc71131484b1ec99870 from the prepared diff and repository reader. No tests or builds were run in this review.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed code | passed | Reviewed all five changed files |
| Build and tests | not run | Author reports runs in the PR description |
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/shaders/StagingCopyBack.comp:43andcore/libs/prx/libSceAgcDriver/Graphics/shaders/StagingCopyBackBound.comp:44write every word in a changed group, including words with no shader-written bytes. This matches the documented tradeoff and is covered in the debt fragment, but it expands the CPU/GPU load-to-store race window to those words. The submitted diagnostic measures one level on NVIDIA with the bound kernel; it does not quantify CPU-write races, other GPUs, or the address-based kernel.
Not verified
- I read the prepared description, commits, manifest, diff, README, both shader files, the changed
Recorder.cppranges, the changed test ranges, and the full debt fragment. The full test file was accessed throughrepo_read.pybecause it was excluded from the review folder for size; no other changed files were excluded. - I did not run builds or tests, verify author-reported results, or inspect performance traces. Those results are reported in the PR description only.
- Behavior on other GPUs, drivers, operating systems, titles, and the address-based kernel's load-to-store window was not verified.
To get this to a good state
Nothing is required. The optional point above records the documented race-window limitation.
|
Linux NVIDIA timing, since the runs in the description are on Windows. The copy-back time drops 5 to 7 times here too, and every run of this change had less GPU time per present than every run of Setup: ASTRO BOT (PPSA21564) 01.007.000,
Not checked: the validation layer, and the CPU-store window the description records as debt. AI-assisted. |
What
The changed-byte copy-back kernels (StagingCopyBack.comp, StagingCopyBackBound.comp) merge the shader's result into the host import word by word: each lane loads the target word from the import (system memory) and stores it back if a byte changed. Where the shader changed few words, the import is hit with scattered 4-byte loads and stores.
Each group of eight words (32 bytes) is now handled by eight lanes. The group is left alone unless the shader changed a byte in it. Otherwise the lanes store all eight words, the untouched ones with the value just loaded, so the stores to the import are adjacent words of one group instead of scattered single words. What the kernels store for a changed byte and what they count is unchanged, and
APS5_CHANGED_COPY_ALWAYSstill stores every word. The bound kernel's dispatches are sized to a multiple of 64 words so a split never cuts a group.One behaviour is new. In a written group, every word is stored, also a word the shader left alone and a word whose changed bytes the CPU had changed too (the old kernel stored nothing for these), with the value loaded from the import a moment earlier. A CPU store to such a word between that load and the store is lost. The old whole-range copy (
APS5_NO_CHANGED_COPY_BACK) overwrote every word of the range. I measured the window on one level only (see Tested); what that leaves open is recorded in a debt fragment (docs/dev/debt/changes/perf-agc-copy-back-whole-lines.md). The guarded store (if (stored != 0u)) with the same group skipping is one line per kernel; an earlier build of that variant hadstaging-outat 54 to 64 ms per present against 66 to 72 ms onmain(same method, two runs each, on themainbefore #20292), against 7 to 8 ms with the unguarded store below.This replaces the per-word early return of #20292 (merged): on this level that early return alone did not change the frame time in the one run I measured (p50 343 to 370 ms, as on
main).The two tests of the kernels now also use shader changes that leave whole groups untouched. The tests check the stored values and the counter, not which words are loaded or stored.
Tested
Windows 10.0.26300, AMD Ryzen 5 9600X, NVIDIA GeForce RTX 5070 Ti, driver 621.14, display 2560x1440 at 164 Hz, AC power, 2026-11-16. The timings compare
mainac29a0c26cwith416ae4616f(thatmainplus this change as first written). The head,b105ab6836, isb7a3334fc7plus one commit that changes only the debt fragment;b7a3334fc7is the change as first written, rebased ondcf3d15978with two edits that leave the compiled kernels the same (a trailing newline and a blank line in the shaders) and one that only matters when a copy-back is split into several dispatches (their size is a multiple of 64 words). No commit betweenac29a0c26canddcf3d15978touches the two kernels or the two tests. The tests below were run again onad5d92582c(the head before the last rebase, over four commits that touchlibSceLibcInternal,libclocale support andtools/performance_bisect.py) and on its basee04bd77e7f.Why this level. One run each of 26 normal levels of PPSA21564 01.007.000 (
-lvl <file>, 90 s, no input,APS5_PROFILE_DRAW=1, onmainef4b9389b6, which predates #20292; one level wrote no summary) rankedspeedrun_inflatorfirst by the mean frame p50 of the 10 s intervals from 40 s on (406 ms). The next werehub_crashsiteat 338 ms, only because of one 856 ms interval while the level started (its last two intervals were 87 and 71 ms), thensponge_dirty_bathat 227 andpath_maker_mana_treeat 214. Onspeedrun_inflatorthe GPU is busy 88 to 96% of the frame from 20 s on, and one class dominates:staging-out(the copy-backs) takes 61 to 68 ms per present in the profile below.PPSA21564
-lvl speedrun_inflator: the frame p50 went from 363 to 301 ms, GPU busy from 328 to 264 ms per present, in four alternating window captures; every run of the change was faster than every run ofmain.-lvl speedrun_inflator, default settings, 3840x2160 output, caches warm, no input (the level flies on by itself). The window is 32 to 40 s after the first present.APS5_TRACE_SECONDS=32:8andAPS5_TRACE_DIR, no otherAPS5_TRACE_*orAPS5_PROFILE_*switch,ANYPS5_GPU=NVIDIA,ANYPS5_DISPLAY_INDEX=0,ANYPS5_VOLUME=0. Order main, change, four times. Each run was stopped 64 s after start (62 s asked for); no trace dropped events.libSceAudioPropagation.prxbuilt from fix(libSceAudioPropagation): find no path without rays and set audio paths #19326, as in perf(agc): read the import only for words a staged copy-back changes #20292.libSceAgcDriver(the kernels), andlibc,libkernel,libSceVideoOut,libSceJson2(the commit or link time they embed).ac29a0c26c20416ae4616fa5ac29a0c26c20416ae4616fa5ac29a0c26c20416ae4616fa5ac29a0c26c20416ae4616fa5Summary lines of round 2 (all eight lines, the traces of round 2 and their
trace_digest.pyoutput are in this gist):{"commit":"ac29a0c26c20","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":316,"ms":8360.503},"presents":23,"frame_ms":{"p50":360.580,"p90":389.573,"p99":533.325,"max":533.325},"gpu_busy_ms_per_present":313.014,"worker_busy_pct":{"queue worker 0x0":99.174,"queue worker 0x40":95.824,"queue worker 0x48":95.286,"queue worker 0x46":0.156},"phase_totals_ms":{"Driver.Completion":3.189,"Driver.Dispatch":3362.480,"Driver.Dispatch.capture_resources":1198.204,"Driver.Dispatch.decode_key_device_setup":15.776,"Driver.Dispatch.lookup_cache":11.983,"Driver.Dispatch.materialize":180.126,"Driver.Dispatch.prepared_invocation":11.436,"Driver.Draw":6863.254,"Driver.Draw.device_setup":32.555,"Driver.Draw.draw_enqueued":6080.055,"Driver.Draw.post_compile_prepare":7.153,"Driver.Draw.prepare":80.019,"Driver.Draw.shader_compile_and_link":593.303,"Driver.EndSubmission":19.706,"Driver.Packet":24259.403,"Driver.Packet.device_lock":11.913,"Driver.Packet.dispatch":3529.384,"Driver.Packet.draw":6871.731,"Driver.Packet.execute":44.654,"Driver.Packet.flip_flush":0.832,"Driver.Packet.flush_between_packets":45.001,"Driver.Packet.memory_wait":13291.432,"Driver.Packet.pipeline_drain":206.864,"Driver.Packet.pipeline_prepare":15.946,"Driver.Packet.prepare_memory":158.938,"Driver.Packet.rendering_wait":0.083,"Driver.Present":19.644,"Driver.Present.acquire_image":0.349,"Driver.Present.device_setup":0.009,"Driver.Present.gpu_mutex_wait":0.048,"Driver.Present.inflight_wait":0.058,"Driver.Present.present_display_buffer":3.355,"Driver.Present.queue_present":8.262,"Driver.Present.release_and_callback":0.020,"Driver.Present.render_fence_wait":7.480,"Driver.Present.resize":0.044,"Driver.Present.validate":0.007,"Driver.Suspend":0.006,"GpuMutex.wait.dispatch":1308.235,"GpuMutex.wait.draw":100.262,"GpuMutex.wait.end":4.170,"GpuMutex.wait.fill":0.151,"GpuMutex.wait.flush":0.559,"GpuMutex.wait.hook":7.886,"GpuMutex.wait.indirect":0.469,"GpuMutex.wait.label":12.059,"GpuMutex.wait.present":0.003,"GpuMutex.wait.wait":14.879,"Graphics.Draw":6903.740,"Graphics.Draw.draw_and_resource_release":842.700,"Graphics.Draw.index_upload":50.845,"Graphics.Draw.validate":48.524,"Graphics.Draw.vertex_upload":5954.062,"Graphics.DrawWithRecipe":11.683,"Graphics.DrawWithRecipe.draw_and_resource_release":10.900,"Graphics.DrawWithRecipe.index_upload":0.018,"Graphics.DrawWithRecipe.validate":0.121,"Graphics.DrawWithRecipe.vertex_upload":0.600,"Recorder.Reap":24.262,"Recorder.Submit":74.296,"Recorder.WaitSerial":80.997,"Resources.Complete":146.738,"Resources.Prepare":75.925,"Shader.DrawStage":474.505,"Shader.DrawStage.capture_resources":254.877,"Shader.DrawStage.materialize":172.081,"Shader.DrawStage.prepared_invocation":42.669,"Shader.ResolveAbi":3.334,"Shader.ResolveGraphicsAbi":0.954,"Shader.ResolveGraphicsStagesAbi":24.271,"VideoOut.Flip":22.934,"VideoOut.Flip.completion_mutex_wait":0.030,"VideoOut.Flip.config_mutex_wait":0.002,"VideoOut.Flip.frame_limit":0.012,"VideoOut.Flip.notify_game":2.143,"VideoOut.Flip.present":19.343,"VideoOut.Flip.validate":0.025,"VideoOut.Flip.vblank_wait":0.016,"VideoOut.Flip.window_prepare":0.039,"VideoOut.Flip.window_title":1.309,"VideoOut.Readiness":0.069,"VideoOut.Readiness.locks_validate":0.023,"Vulkan.Acquire":0.323,"Vulkan.Acquire.acquire_fence_wait":0.043,"Vulkan.Acquire.acquire_image":0.223,"Vulkan.Acquire.fence_reset":0.039,"Vulkan.Acquire.retired_swapchains":0.010,"Vulkan.Dispatch":405.297,"Vulkan.Dispatch.command_record":98.649,"Vulkan.Dispatch.shader_resources":303.857,"Vulkan.DispatchRecipe":21.246,"Vulkan.DispatchRecipe.command_record":21.099,"Vulkan.DrawFromRecipe":11.763,"Vulkan.Present":2.345,"Vulkan.Present.command_record_scale":1.075,"Vulkan.Present.pixel_upload":0.078,"Vulkan.Present.queue_submit":1.177,"Vulkan.QueuePresent":8.231,"Vulkan.QueuePresent.queue_present":8.204,"Vulkan.Retire":7.479,"Vulkan.Retire.wait":7.073},"top_phases_ms_per_frame":{"Driver.Packet":1054.757,"Driver.Packet.memory_wait":577.888,"Graphics.Draw":300.163,"Driver.Packet.draw":298.771,"Driver.Draw":298.402,"Driver.Draw.draw_enqueued":264.350,"Graphics.Draw.vertex_upload":258.872,"Driver.Packet.dispatch":153.451},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":494,"Graphics.Barrier.dcc-clear":276,"Graphics.Barrier.dcc-keys":276,"Graphics.Barrier.dispatch-lead":4381,"Graphics.Barrier.dispatch-trail":21283,"Graphics.Barrier.draw":15006,"Graphics.Barrier.fill":728,"Graphics.Barrier.fill-clear":396,"Graphics.Barrier.indirect-args":161,"Graphics.Barrier.input-mirror":1868,"Graphics.Barrier.label-run":6978,"Graphics.Barrier.present-blit":46,"Graphics.Barrier.shadow-publish":230,"Graphics.Barrier.staging-in":26639,"Graphics.Barrier.staging-out":12505,"Graphics.Barrier.storage-upload":1298,"Graphics.Barrier.storage-writeback":4156,"Graphics.BarrierMerged.dispatch-lead":17224,"Graphics.BarrierMerged.fill":194,"Graphics.BarrierMerged.label-run":2,"Graphics.BarrierMerged.shadow-publish":184,"Graphics.BarrierMerged.staging-in":12570,"Graphics.BarrierMerged.staging-out":12505,"Graphics.BarrierMerged.storage-writeback":645,"Graphics.Copy":28617,"Graphics.Copy.bytes":19145412656,"Graphics.RenderPass":6874,"Graphics.RenderPass.Close.command":5467,"Graphics.RenderPass.Close.image":135,"Graphics.RenderPass.Close.key":95,"Graphics.RenderPass.Close.label":2,"Graphics.RenderPass.Close.new-batch":1175,"Graphics.RenderPass.Continued":51130},"trace_dropped":false,"trace":"aps5-trace-ac29a0c26c20-17960.json.gz"} {"commit":"416ae4616fa5","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":333,"ms":8096.110},"presents":28,"frame_ms":{"p50":291.312,"p90":319.426,"p99":372.494,"max":372.494},"gpu_busy_ms_per_present":253.101,"worker_busy_pct":{"queue worker 0x0":98.905,"queue worker 0x40":97.249,"queue worker 0x48":97.273,"queue worker 0x46":0.216},"phase_totals_ms":{"Driver.Completion":3.720,"Driver.Dispatch":3328.549,"Driver.Dispatch.capture_resources":1332.076,"Driver.Dispatch.decode_key_device_setup":19.593,"Driver.Dispatch.lookup_cache":15.642,"Driver.Dispatch.materialize":15.836,"Driver.Dispatch.prepared_invocation":13.495,"Driver.Draw":6663.495,"Driver.Draw.device_setup":43.792,"Driver.Draw.draw_enqueued":5405.154,"Driver.Draw.post_compile_prepare":10.014,"Driver.Draw.prepare":111.058,"Driver.Draw.shader_compile_and_link":1010.581,"Driver.EndSubmission":415.028,"Driver.Packet":23354.950,"Driver.Packet.device_lock":15.790,"Driver.Packet.dispatch":3536.636,"Driver.Packet.draw":6674.875,"Driver.Packet.execute":57.971,"Driver.Packet.flip_flush":1.018,"Driver.Packet.flush_between_packets":51.785,"Driver.Packet.memory_wait":12622.665,"Driver.Packet.pipeline_drain":82.278,"Driver.Packet.pipeline_prepare":20.798,"Driver.Packet.prepare_memory":198.387,"Driver.Packet.rendering_wait":0.036,"Driver.Present":42.762,"Driver.Present.acquire_image":0.400,"Driver.Present.device_setup":0.011,"Driver.Present.gpu_mutex_wait":0.052,"Driver.Present.inflight_wait":0.076,"Driver.Present.present_display_buffer":4.420,"Driver.Present.queue_present":11.701,"Driver.Present.release_and_callback":0.029,"Driver.Present.render_fence_wait":25.982,"Driver.Present.resize":0.069,"Driver.Present.validate":0.009,"Driver.Suspend":0.008,"GpuMutex.wait.dispatch":1184.317,"GpuMutex.wait.draw":117.488,"GpuMutex.wait.end":393.911,"GpuMutex.wait.fill":0.290,"GpuMutex.wait.flush":1.214,"GpuMutex.wait.hook":2.536,"GpuMutex.wait.indirect":0.628,"GpuMutex.wait.label":13.565,"GpuMutex.wait.wait":0.427,"Graphics.Draw":6391.543,"Graphics.Draw.draw_and_resource_release":1043.335,"Graphics.Draw.index_upload":66.231,"Graphics.Draw.validate":73.030,"Graphics.Draw.vertex_upload":5198.065,"Graphics.DrawWithRecipe":21.902,"Graphics.DrawWithRecipe.draw_and_resource_release":20.572,"Graphics.DrawWithRecipe.index_upload":0.084,"Graphics.DrawWithRecipe.validate":0.203,"Graphics.DrawWithRecipe.vertex_upload":0.965,"Recorder.Reap":28.728,"Recorder.Submit":90.628,"Recorder.WaitSerial":123.011,"Resources.Complete":217.636,"Resources.Prepare":92.679,"Shader.DrawStage":845.183,"Shader.DrawStage.capture_resources":389.181,"Shader.DrawStage.materialize":388.347,"Shader.DrawStage.prepared_invocation":60.611,"Shader.ResolveAbi":3.969,"Shader.ResolveGraphicsAbi":1.231,"Shader.ResolveGraphicsStagesAbi":32.786,"VideoOut.Flip":44.142,"VideoOut.Flip.completion_mutex_wait":0.034,"VideoOut.Flip.config_mutex_wait":0.003,"VideoOut.Flip.frame_limit":0.015,"VideoOut.Flip.notify_game":0.674,"VideoOut.Flip.present":41.590,"VideoOut.Flip.validate":0.031,"VideoOut.Flip.vblank_wait":0.022,"VideoOut.Flip.window_prepare":0.053,"VideoOut.Flip.window_title":1.704,"VideoOut.Readiness":0.071,"VideoOut.Readiness.locks_validate":0.032,"Vulkan.Acquire":0.368,"Vulkan.Acquire.acquire_fence_wait":0.047,"Vulkan.Acquire.acquire_image":0.251,"Vulkan.Acquire.fence_reset":0.048,"Vulkan.Acquire.retired_swapchains":0.013,"Vulkan.Dispatch":466.021,"Vulkan.Dispatch.command_record":120.619,"Vulkan.Dispatch.shader_resources":342.098,"Vulkan.DispatchRecipe":26.987,"Vulkan.DispatchRecipe.command_record":26.791,"Vulkan.DrawFromRecipe":22.024,"Vulkan.Present":3.162,"Vulkan.Present.command_record_scale":1.379,"Vulkan.Present.pixel_upload":0.051,"Vulkan.Present.queue_submit":1.714,"Vulkan.QueuePresent":11.664,"Vulkan.QueuePresent.queue_present":11.631,"Vulkan.Retire":25.979,"Vulkan.Retire.wait":25.400},"top_phases_ms_per_frame":{"Driver.Packet":834.105,"Driver.Packet.memory_wait":450.809,"Driver.Packet.draw":238.388,"Driver.Draw":237.982,"Graphics.Draw":228.269,"Driver.Draw.draw_enqueued":193.041,"Graphics.Draw.vertex_upload":185.645,"Driver.Packet.dispatch":126.308},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":619,"Graphics.Barrier.dcc-clear":336,"Graphics.Barrier.dcc-keys":336,"Graphics.Barrier.dispatch-lead":5361,"Graphics.Barrier.dispatch-trail":25935,"Graphics.Barrier.draw":18944,"Graphics.Barrier.fill":883,"Graphics.Barrier.fill-clear":504,"Graphics.Barrier.indirect-args":196,"Graphics.Barrier.input-mirror":2327,"Graphics.Barrier.label-run":8416,"Graphics.Barrier.present-blit":56,"Graphics.Barrier.shadow-publish":309,"Graphics.Barrier.staging-in":31569,"Graphics.Barrier.staging-out":14928,"Graphics.Barrier.storage-upload":1642,"Graphics.Barrier.storage-writeback":5223,"Graphics.BarrierMerged.dispatch-lead":20966,"Graphics.BarrierMerged.fill":237,"Graphics.BarrierMerged.label-run":3,"Graphics.BarrierMerged.shadow-publish":253,"Graphics.BarrierMerged.staging-in":14956,"Graphics.BarrierMerged.staging-out":14928,"Graphics.BarrierMerged.storage-writeback":763,"Graphics.Copy":33723,"Graphics.Copy.bytes":21593947394,"Graphics.RenderPass":8734,"Graphics.RenderPass.Close.command":7064,"Graphics.RenderPass.Close.image":224,"Graphics.RenderPass.Close.key":128,"Graphics.RenderPass.Close.label":3,"Graphics.RenderPass.Close.new-batch":1315,"Graphics.RenderPass.Continued":69805},"trace_dropped":false,"trace":"aps5-trace-416ae4616fa5-6252.json.gz"}A second series with
APS5_TRACE_SUMMARY_EVERY=10(no trace; mean over the 10 s intervals at 20 to 50 s after start), same scene, six alternating rounds: main frame p50 364.5 ms and GPU busy 334.0 ms per present over the 3 runs that lasted that long, change 292.6 and 260.2 over 6 runs. Three of the sixmainruns ended early in an access violation on the title'sDraw Geometrythread (24, 28 and 64 s after start); no run of the change did. The same access violation also ended runs ofmainand of the change in earlier series on this level (the same thread; I did not find its cause and do not claim the change affects it). The interval lines are in the gist.GPU time by class, one run per side with
APS5_PROFILE_GPU=1(it adds timestamp queries; not part of the comparison), the three 10 s windows inside the level, per present:staging-out67.7, 61.2 and 61.9 ms onmain, 7.6, 7.4 and 7.8 ms with the change. The other classes stayed within a few ms (dispatch-trail142 to 172 against 159 to 165,staging-inabout 9 against 8.5,draw10 to 13).staging-outcopied back 283 to 322 MiB per present onmain. The[gputime]lines are in the gist.Other levels, same method (interval summaries, three alternating rounds, mean p50 over the 10 s intervals at 20 to 50 s; round 1 of
mainstarted its level late and is left out):timestop_casino64.0 and 65.0 ms onmain, 64.2, 63.5 and 64.0 ms with the change (that second run of the change ended in a device-lost abort,vkWaitSemaphoresKHRresult -4, after about 50 s; nomainrun did);hub_crashsite65.8 and 66.4 ms onmain, 65.3, 65.2 and 65.5 ms with the change. Those two levels spend little time in these kernels and did not move beyond the run-to-run spread.Tests:
tools/select_tests.pyfor the five changed files, one04bd77e7fandad5d92582c: 3068 tests each; the same tests fail or do not run on both:pr_overlap_tools,conventions_doc_linksandtitle_runfail, andagc_driver_upload_cache_read_only_flushdoes 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' -Von both commits (17 tests each), 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. The loader inserts the layer in 15 of the 17 tests on each side (agc_adaptive_stagingandagc_buffer_pool_small_device_no_stagingmake no Vulkan instance; the others showInsert instance layer "VK_LAYER_KHRONOS_validation"), and no log showswas not foundor anyVUID-message. The same 17 tests andpatched_librariespass onb7a3334fc7(the head before the debt-only commit) with the same settings (the loader inserts the layer in the same 15 tests; no log showswas not foundorVUID-);mainwas not run again for this rebase.agc_changed_copy,agc_bound_changed_copyand their_alwaysvariants check every word and the counter against a CPU model, with words both sides changed, bytes that mix, and now long stretches where the shader changed nothing. Breaking the change each in turn (the commit passes all four): reading the group flag of group 0 for every lane failsagc_changed_copyandagc_bound_changed_copy; a flag that ignores the shader's changes fails all four; leavingAPS5_CHANGED_COPY_ALWAYSout of the flag fails the two_alwaystests; skipping a lane whose own word is unchanged (the previous per-word behaviour) fails the two_alwaystests and passes the others, since its stored bytes are the same.b7a3334fc7, not committed (window-diagnostic.patchin the gist): inStagingCopyBackBound.compthe store of a word in a written group became anatomicCompSwapfrom the loaded value. Counters: stores to words the shader changed a byte of, stores to words it left alone, failed swaps (the word differed from the loaded value when the swap ran), and words left alone that differed from the snapshot when loaded. The stores counted can only come from the push-descriptor kernel, which therefore ran on this GPU;StagingCopyBack.compwas not measured. Three runs of about 75 s on-lvl speedrun_inflator(no input,ANYPS5_GPU=NVIDIA,ANYPS5_VOLUME=0,APS5_TRACE_COPY_BACK=1, the libraries ofmaindcf3d15978with this change and the diagnostic): 626,836,635 stores, 364,275,227 to words the shader changed and 262,561,408 to words it left alone. No swap failed in either group, and every word left alone equalled the snapshot when loaded. After each successful swap on a word the shader changed, a read of the word found the stored value every time. Control (window-control.txtin the gist): with one extra line that overwrites each word just before the swap, the failures equal the stores in both groups (one 45 s run: 64,815,109 and 41,469,714). The counter lines and the summary are in the gist (window-*).Limits: the swap and the counters change the timing of the kernel, so this is not the rate of the kernel as committed; the control shows that the counters and the swap work on this memory, not that a CPU store racing with the GPU is caught (the control overwrites from the GPU; I added no CPU writer of my own, the game's own threads ran as usual); equal values do not exclude a store of the same value or two stores that cancel. Not compared with the old kernel's overlap.
Not covered: other GPUs and drivers (AMD, Intel), Linux and macOS, other titles, and the load-to-store window in any scene but the one measured above or in
StagingCopyBack.comp.tools/pr_overlap.py --branchfound no PR that shares lines with this one. It could not compare 36 PRs that conflict withmainand share a file; I read their diffs for the changed functions and kernels. The only ones that mention them: #13863 and #13920 have a hunk right after the end ofRecordBoundChangedCopy(not the lines changed here), and #15548, #17611 and #18515 callRecordChangedCopy(#18515 adds a call on a written-back resident buffer, which would get the behaviour described above). #6186 listsStagingCopyBack.componly to wire it into CMake.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)