fix(agc): record large memory-to-memory DMA_DATA copies on the GPU in queue order #439

Merged
oneandonlydean merged 1 commit from upstream-pr/439 into main 2026-10-03 22:32:08 +00:00
oneandonlydean commented 2026-10-03 07:35:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-03T07:35:02Z.


What

A memory-to-memory DMA_DATA larger than the 64 KiB store limit drained the device and was then copied with a CPU memcpy on the submitting queue's worker thread. For a large range that copy takes milliseconds, and meanwhile another queue's worker records and runs work that reads the destination in place.

PPSA21564 copies each decoded frame of its intro video (a 3840x3240 R8 NV12 surface, 12 MiB) into one of two textures with a single DMA_DATA on an async queue, and samples the texture on queue 0 without waiting for that queue. On the console the DMA finishes in microseconds, so the title never needs to wait. Here the copy took 5 to 10 ms, and queue 0's upload of the texture ran while the copy was still writing it: a frame showed the new frame's luma over the chroma of the frame two before (torn video frames once the intro runs at about 56 fps).

  • Pm4::DecodeMemoryCopy recognises a memory-to-memory DMA_DATA: both selectors memory, both addresses incrementing, no GDS, immediate or register operand, ranges non-empty and disjoint.
  • In preparePacketMemory, such a copy above the store limit now goes through VulkanDevice::CopyBuffer, the path the copy kernel already uses, with no CPU path (cpuMax 0). It records a transfer between the host imports in queue order, with the source's pending storage results flushed first and pending write and read notes taken, so everything recorded after the packet reads the whole copy and work recorded before it reads the old bytes, as on hardware.
  • The drain and CPU copy stay the fallback when either range is not host-imported.

Tested

  • Linux (CachyOS, x86-64): full build with BUILD_TESTING=ON and ctest pass (126/126).
  • New testMemoryCopyDecode in agc_driver_pm4: a memory-to-memory copy decodes with its addresses and size; immediate fills, GDS on either side, register operands, non-incrementing addresses, an empty copy, overlapping ranges and COPY_DATA do not; adjacent ranges do. The function is new, so the test does not build without this change. The race itself depends on thread timing and has no deterministic test.
  • PPSA21564: a timeline of the copy and queue 0's recording showed the torn frames' draws recorded between the copy's start and end. With this change the intro video showed no torn frames in my visual regression check (0 torn frames at 56 to 58 fps, where it had 1 to 3 per run before), and the change has been on my integration branch through repeated passes of that check (checkpoint frames, flicker, shimmer, video tearing, FPS).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4724925818 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/439). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-03T07:35:02Z. --- ### What A memory-to-memory DMA_DATA larger than the 64 KiB store limit drained the device and was then copied with a CPU memcpy on the submitting queue's worker thread. For a large range that copy takes milliseconds, and meanwhile another queue's worker records and runs work that reads the destination in place. PPSA21564 copies each decoded frame of its intro video (a 3840x3240 R8 NV12 surface, 12 MiB) into one of two textures with a single DMA_DATA on an async queue, and samples the texture on queue 0 without waiting for that queue. On the console the DMA finishes in microseconds, so the title never needs to wait. Here the copy took 5 to 10 ms, and queue 0's upload of the texture ran while the copy was still writing it: a frame showed the new frame's luma over the chroma of the frame two before (torn video frames once the intro runs at about 56 fps). - `Pm4::DecodeMemoryCopy` recognises a memory-to-memory DMA_DATA: both selectors memory, both addresses incrementing, no GDS, immediate or register operand, ranges non-empty and disjoint. - In `preparePacketMemory`, such a copy above the store limit now goes through `VulkanDevice::CopyBuffer`, the path the copy kernel already uses, with no CPU path (`cpuMax` 0). It records a transfer between the host imports in queue order, with the source's pending storage results flushed first and pending write and read notes taken, so everything recorded after the packet reads the whole copy and work recorded before it reads the old bytes, as on hardware. - The drain and CPU copy stay the fallback when either range is not host-imported. ### Tested - Linux (CachyOS, x86-64): full build with `BUILD_TESTING=ON` and `ctest` pass (126/126). - New `testMemoryCopyDecode` in `agc_driver_pm4`: a memory-to-memory copy decodes with its addresses and size; immediate fills, GDS on either side, register operands, non-incrementing addresses, an empty copy, overlapping ranges and COPY_DATA do not; adjacent ranges do. The function is new, so the test does not build without this change. The race itself depends on thread timing and has no deterministic test. - PPSA21564: a timeline of the copy and queue 0's recording showed the torn frames' draws recorded between the copy's start and end. With this change the intro video showed no torn frames in my visual regression check (0 torn frames at 56 to 58 fps, where it had 1 to 3 per run before), and the change has been on my integration branch through repeated passes of that check (checkpoint frames, flicker, shimmer, video tearing, FPS). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!439
No description provided.