perf(agc): handle the dword pattern-fill kernel as a buffer fill #2081

Merged
orbz22 merged 1 commit from upstream-pr/2081 into main 2026-10-10 07:46:39 +00:00
orbz22 commented 2026-10-09 07:11:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-09T07:11:40Z.


What

Astro's Playroom (PPSA01325) runs a 64-thread compute kernel (69 dwords) every frame to fill DCC keys, HTILE and other metadata. It ran as a shader. Before the fill, every key read of those surfaces waited for a drain (on the UI target 0x534830000, among others).

What the kernel does, read from its code and confirmed by the new test against the translated kernel:

  • It covers every i below min(launched threads, s8, num_records). The group id is in s10, so the kernel has exactly 10 user SGPRs.
  • Into dword i of a 4-byte-stride buffer (s[0:3]) it stores pattern[min(i % s9, 3)], where the pattern is s4..s7 and s9 is the period.
  • The modulo is computed with a float reciprocal. Remainders 0, 1 and 2 select s4, s5 and s6; anything else stores s7.

MatchDwordPatternFill (new header Driver/Memory/DwordPatternFill.hpp) recognizes the exact code and accepts only one shape:

  • a direct, non-partial 1-D dispatch;
  • a 4-byte-stride, unswizzled, non-add-tid buffer;
  • a period of 1, 2 or 4 dwords;
  • whole 16-byte units into a 16-byte aligned destination.

That shape is a 16-byte pattern fill, and fillBuffer takes it the same way it takes the existing fill kernel: clear path, FillBuffer, key memo. Everything else still runs the kernel. APS5_NO_FILL_HLE turns both matchers off.

#1335 recognizes a different, typed pattern-fill kernel (18 dwords, pattern and control read from buffers). Both PRs touch fillBuffer, so whichever merges second needs a small rebase.

Tested

Windows 11, WinLibs GCC 15.2, RTX 3060 Laptop:

  • New agc_driver_dword_pattern_fill_tests (tests/execution/DwordPatternFill.cpp):
    • the matcher accepts the kernel, and refuses every single-bit change of its code, a truncated copy, periods other than 1/2/4, partial units, unaligned destinations, add-tid descriptors, other user SGPR counts, partial dispatches and a missing group id;
    • it clamps to the descriptor's records;
    • ten cases run through Submit: matched ones and unmatched ones (periods 3 and 5, a count of 250, a partial dispatch).
  • The test passes as is. With APS5_NO_FILL_HLE=1, the translated kernel meets the same expectations, which is where the min(i % s9, 3) reading comes from.
  • agc_driver_tests and agc_driver_pm4_tests pass, and tools/check_conventions.py --base upstream/main passes.
  • PPSA01325, A/B on the title screen with this commit as the only difference: 12.68 -> 13.96 FPS (78.9 -> 71.6 ms per frame), mean of three runs per side, B ahead in every pair. Current main does not reach the title, so both sides ran on an integration branch; details and per-run numbers are in the comments.

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 (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4797298265 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2081). Originally posted by [orbz22](https://github.com/orbz22) on 2026-10-09T07:11:40Z. --- ### What Astro's Playroom (PPSA01325) runs a 64-thread compute kernel (69 dwords) every frame to fill DCC keys, HTILE and other metadata. It ran as a shader. Before the fill, every key read of those surfaces waited for a drain (on the UI target `0x534830000`, among others). What the kernel does, read from its code and confirmed by the new test against the translated kernel: - It covers every `i` below `min(launched threads, s8, num_records)`. The group id is in `s10`, so the kernel has exactly 10 user SGPRs. - Into dword `i` of a 4-byte-stride buffer (`s[0:3]`) it stores `pattern[min(i % s9, 3)]`, where the pattern is `s4..s7` and `s9` is the period. - The modulo is computed with a float reciprocal. Remainders 0, 1 and 2 select `s4`, `s5` and `s6`; anything else stores `s7`. `MatchDwordPatternFill` (new header `Driver/Memory/DwordPatternFill.hpp`) recognizes the exact code and accepts only one shape: - a direct, non-partial 1-D dispatch; - a 4-byte-stride, unswizzled, non-add-tid buffer; - a period of 1, 2 or 4 dwords; - whole 16-byte units into a 16-byte aligned destination. That shape is a 16-byte pattern fill, and `fillBuffer` takes it the same way it takes the existing fill kernel: clear path, `FillBuffer`, key memo. Everything else still runs the kernel. `APS5_NO_FILL_HLE` turns both matchers off. #1335 recognizes a different, typed pattern-fill kernel (18 dwords, pattern and control read from buffers). Both PRs touch `fillBuffer`, so whichever merges second needs a small rebase. ### Tested Windows 11, WinLibs GCC 15.2, RTX 3060 Laptop: - New `agc_driver_dword_pattern_fill_tests` (`tests/execution/DwordPatternFill.cpp`): - the matcher accepts the kernel, and refuses every single-bit change of its code, a truncated copy, periods other than 1/2/4, partial units, unaligned destinations, add-tid descriptors, other user SGPR counts, partial dispatches and a missing group id; - it clamps to the descriptor's records; - ten cases run through `Submit`: matched ones and unmatched ones (periods 3 and 5, a count of 250, a partial dispatch). - The test passes as is. With `APS5_NO_FILL_HLE=1`, the translated kernel meets the same expectations, which is where the `min(i % s9, 3)` reading comes from. - `agc_driver_tests` and `agc_driver_pm4_tests` pass, and `tools/check_conventions.py --base upstream/main` passes. - PPSA01325, A/B on the title screen with this commit as the only difference: 12.68 -> 13.96 FPS (78.9 -> 71.6 ms per frame), mean of three runs per side, B ahead in every pair. Current `main` does not reach the title, so both sides ran on an integration branch; details and per-run numbers are in the comments. ### 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 (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-09 09:23:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:23:02Z.


Could you measure main against main plus this PR alone on PPSA01325, frame time on the same scene over a few runs? Perf PRs need numbers for the change itself (#218); the 40-57 ms is the cost on main, and the after run had other changes in it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078131948 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2081#issuecomment-6078131948). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:23:02Z. --- Could you measure main against main plus this PR alone on PPSA01325, frame time on the same scene over a few runs? Perf PRs need numbers for the change itself (#218); the 40-57 ms is the cost on main, and the after run had other changes in it.
orbz22 commented 2026-10-09 12:35:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-09T12:35:03Z.


@oneandonlydean measured as an A/B with only this change between the two sides. PPSA01325 title screen, the same scene in every run; frames counted over 111-202 s of each run, three runs per side, A and B alternating.

Current main does not reach the title in PPSA01325. It stops in turn on:

  • missing static shader ABI register 201 (#1836);
  • rectangle ABI refers to a replaced shader header (#1837);
  • DB_RENDER_CONTROL depth clear draws (#1395);
  • vertex fetch exceeds descriptor record count (no PR yet);
  • the null pixel program (#1902);
  • rect-list rectangle artifacts (#1928);
  • a read through a null SRT pointer at +0x28 (#757-#759, which no longer apply to current main).

So both sides run on my integration branch: main from 2026-10-08 plus those PRs, with the same build and the same switches on both sides. The only difference is the fill kernel:

  • A: the branch's earlier local matcher for this kernel is turned off (APS5_NO_DWORD_FILL_HLE=1), so the kernel runs as a dispatch, as on main;
  • B: this PR's commit cherry-picked on top (it replaces that local matcher).
run A (kernel dispatched) B (this PR)
1 13.93 FPS, 71.8 ms 14.80 FPS, 67.6 ms
2 11.90 FPS, 84.0 ms 13.96 FPS, 71.7 ms
3 12.22 FPS, 81.8 ms 13.12 FPS, 76.2 ms
mean 12.68 FPS, 78.9 ms 13.96 FPS, 71.6 ms

About 7 ms per frame, with B ahead in every pair. That is far below the 40-57 ms in the description. Those were the cost of the waits on 0x534830000 measured on main, not an A/B, so I've replaced them in the description with these numbers.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080995595 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2081#issuecomment-6080995595). Originally posted by [orbz22](https://github.com/orbz22) on 2026-10-09T12:35:03Z. --- @oneandonlydean measured as an A/B with only this change between the two sides. PPSA01325 title screen, the same scene in every run; frames counted over 111-202 s of each run, three runs per side, A and B alternating. Current `main` does not reach the title in PPSA01325. It stops in turn on: - `missing static shader ABI register 201` (#1836); - `rectangle ABI refers to a replaced shader header` (#1837); - `DB_RENDER_CONTROL` depth clear draws (#1395); - `vertex fetch exceeds descriptor record count` (no PR yet); - the null pixel program (#1902); - rect-list rectangle artifacts (#1928); - a read through a null SRT pointer at +0x28 (#757-#759, which no longer apply to current `main`). So both sides run on my integration branch: `main` from 2026-10-08 plus those PRs, with the same build and the same switches on both sides. The only difference is the fill kernel: - A: the branch's earlier local matcher for this kernel is turned off (`APS5_NO_DWORD_FILL_HLE=1`), so the kernel runs as a dispatch, as on `main`; - B: this PR's commit cherry-picked on top (it replaces that local matcher). | run | A (kernel dispatched) | B (this PR) | |---|---|---| | 1 | 13.93 FPS, 71.8 ms | 14.80 FPS, 67.6 ms | | 2 | 11.90 FPS, 84.0 ms | 13.96 FPS, 71.7 ms | | 3 | 12.22 FPS, 81.8 ms | 13.12 FPS, 76.2 ms | | mean | 12.68 FPS, 78.9 ms | 13.96 FPS, 71.6 ms | About 7 ms per frame, with B ahead in every pair. That is far below the 40-57 ms in the description. Those were the cost of the waits on `0x534830000` measured on `main`, not an A/B, so I've replaced them in the description with these numbers.
oneandonlydean commented 2026-10-10 05:17:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:17:42Z.


Conflicts with main in BufferFill.cpp now that #1335 is in; please rebase. It matches a different kernel from #1335, so both stay.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094136573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2081#issuecomment-6094136573). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:17:42Z. --- Conflicts with main in `BufferFill.cpp` now that #1335 is in; please rebase. It matches a different kernel from #1335, so both stay.
adriadam10 commented 2026-10-10 07:41:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:41:51Z.


Rebased onto current main as @oneandonlydean asked (conflict in fillBuffer with #1335; both kernels stay). The dword pattern-fill match is evaluated first and feeds the same clear / FillBuffer / key-memo path; MatchesPatternFillKernel and the 16-byte kernel are untouched. Checked: local build and ctest of libSceAgcDriver green (306/306), agc_driver_dword_pattern_fill and agc_driver_pattern_buffer_fill pass. Merging once CI is green on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095222701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2081#issuecomment-6095222701). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:41:51Z. --- Rebased onto current `main` as @oneandonlydean asked (conflict in `fillBuffer` with #1335; both kernels stay). The dword pattern-fill match is evaluated first and feeds the same clear / `FillBuffer` / key-memo path; `MatchesPatternFillKernel` and the 16-byte kernel are untouched. Checked: local build and ctest of libSceAgcDriver green (306/306), `agc_driver_dword_pattern_fill` and `agc_driver_pattern_buffer_fill` pass. Merging once CI is green on the rebased head.
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!2081
No description provided.