perf(agc): clear integer-format storage images with DCC code 0000 on the GPU #3865

Merged
CnRJay merged 3 commits from upstream-pr/3865 into main 2026-10-12 20:28:17 +00:00
CnRJay commented 2026-10-11 18:10:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-11T18:10:35Z.


What

ClearColorFor refused every integer format, so a fast-cleared integer storage image (DCC keys 0000) never took the GPU clear in StorageTexture::upload. It went through the CPU path instead: GuestMemory::ReadCommitted of the whole surface, which first waits for the GPU writers of that memory (the flush hook), then FillDccClear's zero texels uploaded through a staging buffer and a waited batch.

PPSA28416 (STAR WARS: Galactic Racer, UE5) fast-clears R32_UINT, R16_UINT and R8_UINT surfaces up to 3840x2160 every frame, from compute shaders that write the keys. Those uploads took ~14 ms each, ~1.4 s per 10 s of indirect-dispatch time.

DCC code 0000 is zero bits in any format (FillDccClear writes zeros for it whatever the format), so for integer formats it now maps to a zero integer clear value. Other codes on integer formats are still refused and keep the CPU path. StorageClearAvailable follows, so the cleared-view path of a sampled integer surface with 0000 keys clears as well.

The two comments around the function described the old rule and are removed.

Tested

Windows 11, WinLibs GCC 15.2.0, Release, RTX 4080.

  • The 79 agc_*/guest_* test executables of libSceAgcDriver build on Windows: all pass.
  • PPSA28416: CPU-path uploads of the integer surfaces are gone; 4.9 -> 5.3 fps at the intro movie. The intro renders as before.

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:4821207175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3865). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-11T18:10:35Z. --- ### What `ClearColorFor` refused every integer format, so a fast-cleared integer storage image (DCC keys `0000`) never took the GPU clear in `StorageTexture::upload`. It went through the CPU path instead: `GuestMemory::ReadCommitted` of the whole surface, which first waits for the GPU writers of that memory (the flush hook), then `FillDccClear`'s zero texels uploaded through a staging buffer and a waited batch. PPSA28416 (STAR WARS: Galactic Racer, UE5) fast-clears `R32_UINT`, `R16_UINT` and `R8_UINT` surfaces up to 3840x2160 every frame, from compute shaders that write the keys. Those uploads took ~14 ms each, ~1.4 s per 10 s of indirect-dispatch time. DCC code `0000` is zero bits in any format (`FillDccClear` writes zeros for it whatever the format), so for integer formats it now maps to a zero integer clear value. Other codes on integer formats are still refused and keep the CPU path. `StorageClearAvailable` follows, so the cleared-view path of a sampled integer surface with `0000` keys clears as well. The two comments around the function described the old rule and are removed. ### Tested Windows 11, WinLibs GCC 15.2.0, Release, RTX 4080. - The 79 `agc_*`/`guest_*` test executables of `libSceAgcDriver` build on Windows: all pass. - PPSA28416: CPU-path uploads of the integer surfaces are gone; 4.9 -> 5.3 fps at the intro movie. The intro renders as before. ### 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](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
Dextroid17 commented 2026-10-12 00:29:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T00:29:47Z.


The shape of the change is right and it is the interesting part:

  • ClearColorFor gains exactly one accepted case — an integer format with DccKeys::Clear0000 → clear.uint32[0..3] = 0 — and every other key on an integer format is still refused, so 0000 is the only case that moves off the CPU path.
  • StorageClearAvailable is driven by the same predicate (Texture.cpp:842), so its two callers in the sampled path (ShaderResources.cpp:584, :1979) inherit the widening with no second rule to keep in sync.
  • Zero for 0000 is the only safe widening: the CPU path it replaces, FillDccClear, zero-fills for that code before it looks at the format at all (DccMetadata.cpp:549), so the GPU clear and the CPU clear agree byte for byte. That equivalence, not the fps figure, is what makes the move safe.
  • ClearColorFor has a second call site that widens with it — the keys-fill clear at Texture.cpp:3413 — which runs only under APS5_KEYS_FILL_CLEAR=1, so the default path is the upload one at Texture.cpp:1966.
  • Dropping the two comments that stated the old rule is correct under this project's comment convention.

Coverage is the gap. No case in tests/ references ClearColorFor or StorageClearAvailable, and the existing DCC-key fixtures all use guest format 56 (8_8_8_8 UNORM — DccKeysFirstWrite.cpp:44, FillCoverKeys.cpp:39), where ClearColorFor already returned true on main, so none of them can separate this head from the base. A case asserting that the uploaded keys are Clear0000 on an integer format would cover the new arm.

Worth knowing when reading the checks: linux and windows are skipped on this PR, and relinker builds with -DANYPS5_RELINKER_ONLY=ON, which returns before core/libs — so no job that ran compiled this file. The green checks do not cover the change, and the "79 executables pass" line is local evidence.

The 4.9 → 5.3 fps figure is one title on one Windows machine, and the body scopes it that way.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115615181 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3865#issuecomment-6115615181). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T00:29:47Z. --- The shape of the change is right and it is the interesting part: - `ClearColorFor` gains exactly one accepted case — an integer format with `DccKeys::Clear0000` → `clear.uint32[0..3] = 0` — and every other key on an integer format is still refused, so `0000` is the only case that moves off the CPU path. - `StorageClearAvailable` is driven by the same predicate (`Texture.cpp:842`), so its two callers in the sampled path (`ShaderResources.cpp:584`, `:1979`) inherit the widening with no second rule to keep in sync. - Zero for `0000` is the only safe widening: the CPU path it replaces, `FillDccClear`, zero-fills for that code before it looks at the format at all (`DccMetadata.cpp:549`), so the GPU clear and the CPU clear agree byte for byte. That equivalence, not the fps figure, is what makes the move safe. - `ClearColorFor` has a second call site that widens with it — the keys-fill clear at `Texture.cpp:3413` — which runs only under `APS5_KEYS_FILL_CLEAR=1`, so the default path is the upload one at `Texture.cpp:1966`. - Dropping the two comments that stated the old rule is correct under this project's comment convention. Coverage is the gap. No case in `tests/` references `ClearColorFor` or `StorageClearAvailable`, and the existing DCC-key fixtures all use guest format 56 (8_8_8_8 UNORM — `DccKeysFirstWrite.cpp:44`, `FillCoverKeys.cpp:39`), where `ClearColorFor` already returned true on `main`, so none of them can separate this head from the base. A case asserting that the uploaded keys are `Clear0000` on an integer format would cover the new arm. Worth knowing when reading the checks: `linux` and `windows` are skipped on this PR, and `relinker` builds with `-DANYPS5_RELINKER_ONLY=ON`, which returns before `core/libs` — so no job that ran compiled this file. The green checks do not cover the change, and the "79 executables pass" line is local evidence. The 4.9 → 5.3 fps figure is one title on one Windows machine, and the body scopes it that way. Written with AI assistance.
adriadam10 commented 2026-10-12 20:27:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:27:46Z.


Checked on the PR merged onto main: the change is as described (integer formats take only DCC code 0000, a zero clear value; every other code keeps the CPU path), and the AgcDriver ctest scope passes (461/461).

Added as our own commits on your branch:

  • Texture.hpp: removed the StorageClearAvailable comment, which said integer formats are always refused (no longer true; comments are only for technical debt).
  • Recorder.cpp/CMakeLists.txt: test agc_storage_integer_clear pins StorageClearAvailable on R8/R16/R32_UINT (0000 accepted, 0001/1111/register/uncompressed refused). It is a registered ctest mode (--integer-clear-only) and fails without the Texture.cpp change.

Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132053451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3865#issuecomment-6132053451). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:27:46Z. --- Checked on the PR merged onto main: the change is as described (integer formats take only DCC code `0000`, a zero clear value; every other code keeps the CPU path), and the AgcDriver ctest scope passes (461/461). Added as our own commits on your branch: - `Texture.hpp`: removed the `StorageClearAvailable` comment, which said integer formats are always refused (no longer true; comments are only for technical debt). - `Recorder.cpp`/`CMakeLists.txt`: test `agc_storage_integer_clear` pins `StorageClearAvailable` on R8/R16/R32_UINT (`0000` accepted, `0001`/`1111`/register/uncompressed refused). It is a registered ctest mode (`--integer-clear-only`) and fails without the `Texture.cpp` change. Merging once CI is green.
github-actions[bot] commented 2026-10-12 20:29:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T20:29:53Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
#4663 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp L5479
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132084948 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3865#issuecomment-6132084948). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T20:29:53Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4663 | `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp` [L5479](https://github.com/boykopovar/AnyPS5/blob/44ab0c39ee505f9434a6f7c56cdf50ba922760e2/core/libs/prx/libSceAgcDriver/tests/Recorder.cpp#L5479) | | |
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!3865
No description provided.