perf(agc): keep the 10-bit scanout resident and present it with the guest path's pixels #278

Merged
oneandonlydean merged 1 commit from upstream-pr/278 into main 2026-10-03 07:00:02 +00:00
oneandonlydean commented 2026-10-01 21:36:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-01T21:36:46Z.


What

A title that composites into a 10-bit scanout (COLOR_2_10_10_10 with the alternate swap, A2R10G10B10) never presents from a resident image. No guest texture format matches that color format, so the target stays non-resident. Every frame's composite draw then runs synchronously, and the flip reads the frame back through guest memory. On main, ResidentPresentable also only accepts an image in exactly the display's format, and it would blit a 10-bit image. A blit rounds where the guest-memory path drops each channel's low two bits.

  • Resident target. The blue-low 10-bit color target now keeps its bits in the storage image of its surface's red-low 2-10-10-10 format, the same way B8G8R8A8 targets map to R8G8B8A8 (FindGuestColorTargetFormat).
  • Display format. DisplayFormat.cpp names a display buffer's texel order as the guest-memory path reads it: red low for the R8G8B8A8 base, otherwise blue low, with A2B10G10R10 or A2R10G10B10 for the 10-bit variant. The bit-56 and R8G8B8A8 checks that VulkanDevice.cpp repeated in two places now use it.
  • Present path. ResidentPresentPath blits a resident image only when it holds the display's 8-bit texel format and can be a blit source, which makes it an exact copy. It converts instead when the image is 10-bit, holds the other 8-bit order or is an sRGB type that a blit would decode. GpuColorTransfer::DetileImage copies the image's texels raw into the color transfer's buffer and runs the guest path's own conversion shader on them, so both paths present the same pixels. A converted present uses the shared transfer and scaler source, so it waits for the slots like the guest-memory path (PresentWaitsForSlots).
  • Write-back. The image's write-back is unchanged. Its results stay pending like any resident target's and are stored when a reader of the memory flushes them.

This builds on the recorder's resident presentation path (ResidentPresentable / PresentableResident, from #5) and @boykopovar's GPU color transfer (7ed9ef1e). DetileImage reuses GpuColorTransfer's buffers and pipeline. convert was split into the copy and a dispatch so the image path skips the guest upload.

Measured in PPSA21564 on my integration branch: the final composite renders into 4K A2R10G10B10 scanout buffers. Before this change that composite ran synchronously, about 11 ms each, 143 times per 10 s at the title, plus a guest-memory readback for every flip. With this change the scanout stays resident, so the composite is recorded like any other draw and the flip presents from the image through the conversion, with no readback.

Tested

  • Linux (CachyOS, RTX 4090). New tests/ResidentPresent.cpp, run from agc_driver_recorder_tests (a GPU test, built but not part of ctest):
    • It checks the format decision for both 8-bit and both 10-bit orders.
    • It checks that the blue-low 10-bit color target has a storage format.
    • It converts a random image in each order through DetileImage. The result must equal both the CPU decode (DecodeDisplayBuffer) and the GPU detile of the same words in guest memory.
  • The decision and conversion functions are new, so the test has no main counterpart. Instead I confirmed that each part fails without its change:
    • Without the TextureFormat.cpp line it fails with "the blue-low 10-bit color target has no storage format".
    • With main's rule (blit a 10-bit A2B10G10R10 image) it fails with "a 10-bit image is blitted (the blit rounds where the guest path truncates)".
    • Converting the raw words as tiled fails with "the resident image presents other pixels than guest memory".
  • ctest --test-dir build --timeout 120: 96/96 pass on current main with this branch. agc_driver_recorder_tests, agc_driver_graphics_tests and agc_structurizer_tests pass when run directly, and the libs target builds.
  • Exercised in PPSA21564 on my integration branch (numbers above), which passes my visual regression check of the title, menu and level frames.

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4709926031 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/278). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-01T21:36:46Z. --- ### What A title that composites into a 10-bit scanout (`COLOR_2_10_10_10` with the alternate swap, A2R10G10B10) never presents from a resident image. No guest texture format matches that color format, so the target stays non-resident. Every frame's composite draw then runs synchronously, and the flip reads the frame back through guest memory. On main, `ResidentPresentable` also only accepts an image in exactly the display's format, and it would blit a 10-bit image. A blit rounds where the guest-memory path drops each channel's low two bits. - **Resident target.** The blue-low 10-bit color target now keeps its bits in the storage image of its surface's red-low 2-10-10-10 format, the same way B8G8R8A8 targets map to R8G8B8A8 (`FindGuestColorTargetFormat`). - **Display format.** `DisplayFormat.cpp` names a display buffer's texel order as the guest-memory path reads it: red low for the R8G8B8A8 base, otherwise blue low, with A2B10G10R10 or A2R10G10B10 for the 10-bit variant. The bit-56 and R8G8B8A8 checks that `VulkanDevice.cpp` repeated in two places now use it. - **Present path.** `ResidentPresentPath` blits a resident image only when it holds the display's 8-bit texel format and can be a blit source, which makes it an exact copy. It converts instead when the image is 10-bit, holds the other 8-bit order or is an sRGB type that a blit would decode. `GpuColorTransfer::DetileImage` copies the image's texels raw into the color transfer's buffer and runs the guest path's own conversion shader on them, so both paths present the same pixels. A converted present uses the shared transfer and scaler source, so it waits for the slots like the guest-memory path (`PresentWaitsForSlots`). - **Write-back.** The image's write-back is unchanged. Its results stay pending like any resident target's and are stored when a reader of the memory flushes them. This builds on the recorder's resident presentation path (`ResidentPresentable` / `PresentableResident`, from #5) and @boykopovar's GPU color transfer (7ed9ef1e). `DetileImage` reuses `GpuColorTransfer`'s buffers and pipeline. `convert` was split into the copy and a `dispatch` so the image path skips the guest upload. Measured in PPSA21564 on my integration branch: the final composite renders into 4K A2R10G10B10 scanout buffers. Before this change that composite ran synchronously, about 11 ms each, 143 times per 10 s at the title, plus a guest-memory readback for every flip. With this change the scanout stays resident, so the composite is recorded like any other draw and the flip presents from the image through the conversion, with no readback. ### Tested - Linux (CachyOS, RTX 4090). New `tests/ResidentPresent.cpp`, run from `agc_driver_recorder_tests` (a GPU test, built but not part of ctest): - It checks the format decision for both 8-bit and both 10-bit orders. - It checks that the blue-low 10-bit color target has a storage format. - It converts a random image in each order through `DetileImage`. The result must equal both the CPU decode (`DecodeDisplayBuffer`) and the GPU detile of the same words in guest memory. - The decision and conversion functions are new, so the test has no main counterpart. Instead I confirmed that each part fails without its change: - Without the `TextureFormat.cpp` line it fails with "the blue-low 10-bit color target has no storage format". - With main's rule (blit a 10-bit A2B10G10R10 image) it fails with "a 10-bit image is blitted (the blit rounds where the guest path truncates)". - Converting the raw words as tiled fails with "the resident image presents other pixels than guest memory". - `ctest --test-dir build --timeout 120`: 96/96 pass on current main with this branch. `agc_driver_recorder_tests`, `agc_driver_graphics_tests` and `agc_structurizer_tests` pass when run directly, and the `libs` target builds. - Exercised in PPSA21564 on my integration branch (numbers above), which passes my visual regression check of the title, menu and level frames. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [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!278
No description provided.