Repository navigation
feat(agc): copy HLE for the 16-byte stream copy kernel - #5281
Conversation
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for the measurements. The match rests on a 16-word kernel that nothing in the PR lets us check on Linux, so I'd like a test before merging:
- Add a test in
core/libs/prx/libSceAgcDriver/tests(registered in ctest) that dispatches the 16 code words of this kernel with the user data frommatchesStreamCopyKerneland checks the destination bytes after the copy. It should show that thread t of group g really copies elementsg*128+tandg*128+64+t, and thatmatchesStreamCopyKernelaccepts it. The code words also pinkernelHash, so a reviewer can verify it. - Include rows for the refusals: source record count below
groups × 128(userData[2] < elements), destination smaller thangroups × 128(clamped byuserData[6]), 0 bytes, above 16 MiB, and a base that isn't 16-byte aligned. Each should fall back to the shader path with the destination unchanged by the HLE. - The test must fail without the change (the kernel runs as a shader today, so assert the HLE path, e.g. via the
[copy]counters).
Locally, the build and libSceAgcDriver ctest show no regression from this diff: agc_recorder_kept_bytes and agc_driver_tessellation crash here with or without it.
A 16-word compute kernel copies a buffer in 16-byte elements: 64 threads a group, thread t of group g loads elements g*128+t and g*128+64+t from the index-addressed buffer in s[0:3] and stores them at the same indices of s[4:7]. Run as a shader against host imports it costs 11.8 ms of GPU per present in PPSA25344's main menu on an RTX 4060. Matched like the existing copy kernel, by its code hash and its descriptors (16-byte stride and no swizzle on both, the same word 3), it becomes one copy through the existing copy HLE path: the elements the kernel stores, min of groups * 128 and the destination's record count, when the source's record count covers them all. APS5_NO_COPY_HLE turns it off with the other kernel.
The stream copy kernel is matched by its 16 code words instead of a hash, and the match and its range checks become free functions (MatchesStreamCopyKernel, StreamCopyRange) so a test can reach them. Its loads and stores are format instructions, so the match also requires the descriptor the pattern fill takes: 32_32_32_32_UINT, XYZW selects, no add-tid, out-of-bounds mode 0, type 0. Copy paths are counted in copyPathCounts whether or not APS5_PROFILE_DRAW is set. agc_driver_stream_copy checks the match against every word with a bit flipped, the descriptor and dispatch refusals, the range clamp and refusals, and runs nine dispatches through the driver: four must take the HLE path and copy elements g*128+t and g*128+64+t, five must be refused for their shape and leave the shader's result.
a6bfc99 to
fa4fc23
Compare
|
@adriadam10 added in fa4fc23, rebased onto current Match by code words. The kernel is now compared word for word, as
The loads and stores are format instructions, so the copy is bit-exact only for a 16-byte format with identity selects. The match now also requires what the pattern fill does: format The kernel match and its range checks are now free functions (
It fails without the change: without this PR's functions it doesn't build. With Tested on Windows 10 19045, RTX 4060 (driver 617.42), MinGW-w64 GCC 15.2: |
|
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.
|
adriadam10
left a comment
There was a problem hiding this comment.
Checked the new agc_driver_stream_copy: it matches the kernel by its 16 code words (every single-bit flip is refused), covers the descriptor/dispatch refusals and runs nine dispatches through the driver asserting the HLE path via copyPathCounts and every destination word. It passes here, and without the change it doesn't even build, so it can't pass on main. The element indices (g*128+t, g*128+64+t) match what the HLE copies. Merging once the full Build is green.
What
A second copy kernel for the existing copy HLE. It is a 16-word compute kernel that copies a buffer in 16-byte elements. Each group has 64 threads, and thread t of group g loads elements g128+t and g128+64+t from the index-addressed buffer in s[0:3], then stores them at the same indices of s[4:7].
PPSA25344 runs it every frame on its title screen to copy 3 MiB. Run as a shader against host imports, it costs ~11 ms of GPU per present on an RTX 4060 (the top program in
APS5_PROFILE_GPU).MatchesStreamCopyKernel(BufferCopy.hpp) matches it by its 16 code words, asMatchZeroDwordFilldoes, with 64×1×1 threads, group id x and 8 user-data words. Its loads and stores are format instructions, so both descriptors must have a 16-byte stride, no swizzle and the same word 3, with what the pattern fill takes there: 32_32_32_32_UINT, XYZW selects, no add-tid, out-of-bounds mode 0, type 0.copyBufferthen copies the elements the kernel stores as one copy through the existing GPU/CPU copy paths: min(groups × 128, the destination's record count), fromStreamCopyRange.CopyOverlappingrefusal.APS5_NO_COPY_HLEturns it off together with the existing kernel.countCopycounts each copy path incopyPathCountswhether or notAPS5_PROFILE_DRAWis set, so a test can tell the HLE from the shader.Tested
New
agc_driver_stream_copy(Windows 10 19045, RTX 4060, driver 617.42): the match against every code word with a bit flipped and each descriptor and dispatch refusal; the range clamp and refusals; nine dispatches through the driver, four taking the HLE path and five refused for their shape, checking every destination word. It passes, also withAPS5_NO_COPY_HLE=1, and fails withcopyBufferrefusing the kernel. 516 of 517agc_tests pass;agc_shader_disk_cachefails on this machine because Windows denies removing its cache directory. Rebased onmain(145cb82f3);tools/check_conventions.py --base origin/mainpasses.Windows 10 19045 (MinGW-w64 GCC 15.2):
libsbuilds;tools/check_conventions.py --base origin/mainpasses. Fork CI (thebuild.ymlsteps on GitHub runners): Windows passes. Linux passes 1,066 of 1,067; the one failure isguest_math, which also fails on plainmainon that runner (fix(libc): return the x86 default NaN from acosf for |x| > 1 #5154).PPSA25344 title screen,
main(60fb61870) against this branch, same relinked executable,APS5_PROFILE_DRAW=1. Mean of the last twelve 10 s windows of a 300 s run, after a warm-up run:[copy]with the change: 1,431 copy kernels matched, 954 done as GPU copies (2,862 MiB). Onmainthe line never appears. Frame dumps: mean difference 0.07 (of 255) betweenmainand this PR, against 0.06 between two runs of this PR, so the picture is unchanged within run noise.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)