perf(agc): replace the indexed 16-byte copy kernel with a buffer copy #7968
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7968"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by saarthakpant on 2026-10-19T16:26:48Z.
What
Unreal Engine 4 titles copy GPU buffers with a compute kernel that moves 16-byte elements from a source V# to a destination V#, with the element count and the source and destination offsets in a one-record constant buffer. The copy HLE knew two other copy kernels (the hashed dword copy and the stream copy) but not this one, so it ran as a real dispatch: 64-thread groups, one 16-byte load and store per thread, over host-imported guest memory. On Ghostrunner 2 (PPSA09911) that was about 28 ms of GPU time per dispatch, four dispatches per frame.
MatchesIndexedCopyKernelrecognises the kernel by its 19 instruction words and the descriptors (stride 16, not swizzled, no add-tid, raw out-of-bounds mode, type 0, equal word 3 on source and destination, a record descriptor of stride 16 with at least one record).IndexedCopyRangereads{count, sourceOffset, destinationOffset}from the record, clamps the count to the launched threads, refuses windows past either descriptor's records, copies above 16 MiB and unaligned bases, andDriver::copyBufferthen takes the same path as the other kernels (the record is read only when nothing is pending over it, and the copy goes throughVulkanDevice::CopyBufferwith the existing CPU and GPU limits, overlap and label checks). The two dispatch call sites treat the kernel like the other copy kernels.Tested
Windows 11 (10.0.26200), MinGW-w64 GCC 15.2.0 UCRT, Release.
agc_driver_indexed_copy: the kernel matches; every one-word alteration, a truncated kernel, other strides, a swizzled descriptor, differing formats, add-tid, raw out-of-bounds, another descriptor type, an empty record descriptor, another user-SGPR count, 32-thread groups and a dispatch without the group id do not; range arithmetic with offsets, count below and above the launch, windows past the records, 0 elements, 0 groups, 16 MiB accepted and above refused, misaligned bases refused; eight dispatches over real memory, five taking the HLE path and three (windows past the records, above 16 MiB) running the kernel, all with the expected destination contents.agc_driver_indexed_copy_gpu_parameters(from eliasbruno124-dev's review): an address-based dispatch writes the copy's record in the same submission; the HLE now waits for leased writers (FinishLeaseWork, asreadDispatchArgumentsdoes) before reading it. Failed at destination word 16 before the wait, passes with it.agc_driver_stream_copy,agc_driver_indexed_copyandagc_driver_indexed_copy_gpu_parameterswithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1(ctest -V) onmain(stream copy only, the other two are new) and on this branch: all pass, the layer was found, noVUID-lines in either log.Performance, same machine, same session, warm caches, idle in-game scene (death screen),
APS5_TRACE_SECONDS=120:60, no other switches. The base ismain4b462ef60plus #7687, becausemainalone stops this title before gameplay (#7017); this change does not depend on #7687.main + #7687 (db0cb30aa):
this change (7d798795d):
GPU busy per present 208.6 ms → 96.3 ms. The frame time does not move (p50 309.9 → 306.1 ms): both queue workers stay at 99 %, and the compute queue spends most of each frame in
Driver.Packet.memory_waiton labels the graphics queue writes, so this title is bound by that path, not by the GPU. The max of 4204 ms in the second capture is one shader compile at the start of the window (Driver.Draw.shader_compile_and_link). Both traces are attached; their event buffers filled after 13 s and 9 s of the window (trace_dropped), the summary counters are complete.Digest of each trace:
python3 tools/trace_digest.py <trace>output attached asdigest-base.txtanddigest-change.txt.tools/pr_overlap.pyreports no open pull request changing the same lines. It could not compare eight pull requests that conflict withmainand touch the same files: #6292 and #6615 change the type ofcountsMutexinBufferCopy.cpp; #5925, #7201, #7233, #7332, #7446 and #7642 change other parts ofDispatch.cpp. None of them touches the copy-kernel recognition.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:46:00Z.
Review: COMMENTED
I reviewed the matcher and range checks. The HLE is restricted to the exact instruction sequence, descriptor layout, launch shape and record format; record visibility, pending labels, descriptor bounds, overlap and the 16 MiB cap are checked before the shared copy path runs. The test fixture also compares actual destination contents for both HLE and rejected-kernel cases. The performance report distinguishes the GPU-time reduction from the unchanged frame-time bottleneck. I did not independently run the Windows tests or title capture.
Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-19T17:27:36Z.
I reproduced a parameter-visibility failure in
1a6b03bc1, applied unchanged to maindbac9fa15.An address-based GPU dispatch writes
{count=23, sourceOffset=17, destinationOffset=29}, followed by this indexed copy in the same submission. The record initially contains{1, 0, 0}. The producer is deferred, and the HLE reads the old parameters: the regression reportsGPU parameter copy differs at word 16. It also verifies that the producer eventually wrote all three expected values, so the failure is in the dependent copy.Calling
Graphics::FinishLeaseWork()before reading the indexed record, under the existing GPU lock, fixes this case. The existing snapshot/texture/label checks remain in place. The wait finishes the newest leased batch, so its performance cost still needs measurement.Minimal correction and standalone regression are available for reuse; that single commit adds the wait, its include and
IndexedCopyGpuParameters.cpp. I have not opened a competing PR for the kernel.APS5_NO_COPY_HLE=1Windows 11 10.0.26300, GCC 15.2.0 UCRT, Release, NVIDIA RTX 3060 Laptop GPU, driver 617.42. All runs used
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1and the actually loaded Khronos validation layer, with zero skips and zeroVUID-lines. The corrected tests took 15.31 s, 15.06 s and 0.64 s respectively. Conventions and whitespace checks pass. Linux and other GPU vendors were not tested, and this is a correctness regression, not a title-performance claim.Prepared with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by saarthakpant on 2026-10-19T19:36:39Z.
Thanks for the reproduction and the fix. You are right: the record checks covered snapshot writes, pending storage results and labels, but not a deferred address-based batch that writes the record, and the indirect-dispatch path already waits for exactly that (
readDispatchArgumentscallsFinishLeaseWorkbefore reading the arguments).Your commit is on the branch as it is (c60f65539, your authorship kept). On Windows 11 (10.0.26200), RTX 2060 SUPER, NVIDIA 617.42, GCC 15.2.0, with
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(ctest -V):agc_driver_indexed_copy,agc_driver_indexed_copy_gpu_parametersandagc_driver_stream_copypass (7.9 s, 1.6 s, 8.5 s), the layer was found, noVUID-lines.On the cost:
FinishLeaseWorkreturns at once unless an address-based batch is newer than what the recorder has completed, so it only waits while such a batch is in flight. I have not got a clean A/B on Ghostrunner 2 yet (the one run I made was not the same scene as the baseline); I will add one when I have it.Imported from boykopovar/AnyPS5. Originally posted by saarthakpant on 2026-10-19T19:54:05Z.
Cost of the wait on Ghostrunner 2 (PPSA09911), RTX 2060 SUPER, NVIDIA 617.42, Windows 11 (10.0.26200): no measurable cost.
Two runs of the same build (local base:
main4b462ef60+ #7687 + #5372 + this branch, with and without c60f65539), identical scripted input (Space through the loading screen, then a fixed key cycle with the respawn key),APS5_PROFILE_GPU=1 APS5_PROFILE_DRAW=1, 26 ten-second windows each. Scripted runs still die and respawn at different moments, so the windows are matched by GPU load rather than compared end to end:The recorder's totals over each run: 8,758 syncs waiting 17.1 s for the GPU without the wait, 7,822 syncs waiting 16.5 s with it (the
otherandaddress-basedsources, where this wait would count, went from 31 / 0.5 s and 11 / 0.1 s to 27 / 0.4 s and 2 / 0.0 s). 1,110 and 902 indexed copies went through the HLE in the two runs, all on the GPU path. So on this title the wait almost never has a newer address-based batch to finish, and the frame rate at equal GPU load is the same within run-to-run noise.