feat(agc): support version initialization and raw compute programs #685

Merged
nicolasabosch merged 2 commits from upstream-pr/685 into main 2026-10-06 03:27:51 +00:00
nicolasabosch commented 2026-10-05 15:18:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-05T15:18:30Z.


What

Native homebrew initializes AGC with a single version argument and can submit a raw compute-program address without registering an AGC shader header. The existing sceAgcInit signature expects a state pointer, and dispatch rejects an unregistered address.

Expose the version-only sceAgcInit while retaining the existing two-argument export under NID 23LRUSvYu1M as sceAgcUnknownInitState, which remains visible to the progress and overlap scanners. Validate versions using the existing register-default tables. For unregistered compute addresses, capture a bounded snapshot of readable mapped code and decode through the reachable program end. Instruction literals and forward branches do not terminate the scan prematurely. Snapshots grow geometrically within a 1 MiB limit; invalid alignment, inaccessible memory, and unterminated programs fail explicitly. Raw snapshots are reused by address while their entire readable code still matches, preserving the dispatch-cache key and source-handle memos. The LRU is limited to 64 entries and 8 MiB of code; guest memory reads and flushes occur outside its mutex. Code changes replace the immutable snapshot, concurrent misses deduplicate, and inaccessible code is rejected. Registered shaders retain their existing path, and headerless requests omit empty header memory regions.

Tested

  • Windows 11, bundled MinGW, Release, rebased on main fe98276f: this branch builds and passes agc_driver and the newly registered agc_initialization CTest cases (2/2), each repeated three times. The unchanged-code snapshot regression fails before the cache fix. New tests cover stable identity, mutation, concurrent hits and misses, bounded eviction, a changed program end and revoked cached tail memory. The version-13 two-argument call preserves caller state, and both progress/overlap scanners recognize the renamed export. Raw-code tests cover literal end words, forward branch targets, immutable snapshots, misaligned/unmapped addresses, an inaccessible page boundary, an unterminated program, and an end instruction in the last readable dword. Initialization tests check both signatures and rejected versions.

  • The broader, previously unregistered agc_command_tests invocation without the defaults option fails an unrelated expected-exception check before reaching the initialization checks; no full-command-test pass is claimed.

  • Integration with #683 (runtime exports), #684 (import binding), and #553: the original integration based on af92452f built and passed 290/290 CTest tests on an RTX 4070, followed by the new initialization regression passing. DOOM Shareware homebrew PPSA99666 01.001.000 reached E1M1 with AGC compute presentation, movement, and shooting. Main already supplies FLAT/GLOBAL stores and #614; their implementations are not duplicated here.

  • Limits observed: a cold start during concurrent GPU tests exceeded the homebrew's frame deadline and activated its own CPU scaler. Restarting with the compiled shader cache used AGC presentation. A nonterminating UCRT invalid-parameter diagnostic is also present at startup. These are not claimed fixed. No FPS benchmark or audible audio verification claimed.

  • Updated integration on main fe98276f with the repaired #683/#684/#685 and #553: full build plus the runtime libs target succeeded; all nine focused integration tests passed. DOOM Shareware reached E1M1 again with movement and shooting through AGC compute presentation. Profiling recorded 3,798 dispatch-cache hits in 3,800 dispatches with zero evictions. This is cache-use evidence, not an FPS benchmark. Cold shader compilation can still exceed the homebrew frame deadline and trigger its CPU scaler; a warm restart used AGC. The startup UCRT diagnostic remains. Updated Linux and Windows CI pass.

Checklist

  • Based on main fe98276f; open PRs checked for these functions
  • One AGC compute-startup topic; new PR
  • No code comments, silent stubs, investigation artifacts, or third-party code added
  • Unsupported programs fail explicitly; generic behavior
  • Depends on: none for this change; the game integration requires the sibling fixes and #553
  • AI-assisted: yes

In-game screenshots

Two E1M1 gameplay captures from the integrated DOOM Shareware homebrew run, showing the final integration build and movement/shooting. The integration dependencies and limits are described above.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4747095994 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/685). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-05T15:18:30Z. --- ### What Native homebrew initializes AGC with a single version argument and can submit a raw compute-program address without registering an AGC shader header. The existing `sceAgcInit` signature expects a state pointer, and dispatch rejects an unregistered address. Expose the version-only `sceAgcInit` while retaining the existing two-argument export under NID `23LRUSvYu1M` as `sceAgcUnknownInitState`, which remains visible to the progress and overlap scanners. Validate versions using the existing register-default tables. For unregistered compute addresses, capture a bounded snapshot of readable mapped code and decode through the reachable program end. Instruction literals and forward branches do not terminate the scan prematurely. Snapshots grow geometrically within a 1 MiB limit; invalid alignment, inaccessible memory, and unterminated programs fail explicitly. Raw snapshots are reused by address while their entire readable code still matches, preserving the dispatch-cache key and source-handle memos. The LRU is limited to 64 entries and 8 MiB of code; guest memory reads and flushes occur outside its mutex. Code changes replace the immutable snapshot, concurrent misses deduplicate, and inaccessible code is rejected. Registered shaders retain their existing path, and headerless requests omit empty header memory regions. ### Tested - Windows 11, bundled MinGW, Release, rebased on main `fe98276f`: this branch builds and passes `agc_driver` and the newly registered `agc_initialization` CTest cases (2/2), each repeated three times. The unchanged-code snapshot regression fails before the cache fix. New tests cover stable identity, mutation, concurrent hits and misses, bounded eviction, a changed program end and revoked cached tail memory. The version-13 two-argument call preserves caller state, and both progress/overlap scanners recognize the renamed export. Raw-code tests cover literal end words, forward branch targets, immutable snapshots, misaligned/unmapped addresses, an inaccessible page boundary, an unterminated program, and an end instruction in the last readable dword. Initialization tests check both signatures and rejected versions. - The broader, previously unregistered `agc_command_tests` invocation without the `defaults` option fails an unrelated expected-exception check before reaching the initialization checks; no full-command-test pass is claimed. - Integration with #683 (runtime exports), #684 (import binding), and #553: the original integration based on `af92452f` built and passed 290/290 CTest tests on an RTX 4070, followed by the new initialization regression passing. DOOM Shareware homebrew PPSA99666 01.001.000 reached E1M1 with AGC compute presentation, movement, and shooting. Main already supplies FLAT/GLOBAL stores and #614; their implementations are not duplicated here. - Limits observed: a cold start during concurrent GPU tests exceeded the homebrew's frame deadline and activated its own CPU scaler. Restarting with the compiled shader cache used AGC presentation. A nonterminating UCRT invalid-parameter diagnostic is also present at startup. These are not claimed fixed. No FPS benchmark or audible audio verification claimed. - Updated integration on main `fe98276f` with the repaired #683/#684/#685 and #553: full build plus the runtime `libs` target succeeded; all nine focused integration tests passed. DOOM Shareware reached E1M1 again with movement and shooting through AGC compute presentation. Profiling recorded 3,798 dispatch-cache hits in 3,800 dispatches with zero evictions. This is cache-use evidence, not an FPS benchmark. Cold shader compilation can still exceed the homebrew frame deadline and trigger its CPU scaler; a warm restart used AGC. The startup UCRT diagnostic remains. Updated Linux and Windows CI pass. ### Checklist - [x] Based on main `fe98276f`; open PRs checked for these functions - [x] One AGC compute-startup topic; new PR - [x] No code comments, silent stubs, investigation artifacts, or third-party code added - [x] Unsupported programs fail explicitly; generic behavior - [x] Depends on: none for this change; the game integration requires the sibling fixes and #553 - [x] AI-assisted: yes ### In-game screenshots [Two E1M1 gameplay captures from the integrated DOOM Shareware homebrew run](https://github.com/boykopovar/AnyPS5/pull/685#issuecomment-5997547697), showing the final integration build and movement/shooting. The integration dependencies and limits are described above.
nicolasabosch commented 2026-10-05 15:25:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-05T15:25:04Z.


In-game screenshots from the DOOM Shareware homebrew integration described above (Windows 11 / RTX 4070, with #683, #684 and #553). E1M1 loaded successfully; movement and shooting were checked. These captures show the integrated game run, not a standalone result from this PR.

E1M1 on the final integration build:

DOOM E1M1 on the final integration build

E1M1 after moving and firing the pistol:

DOOM E1M1 after movement and shooting

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5997547697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/685#issuecomment-5997547697). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-05T15:25:04Z. --- In-game screenshots from the DOOM Shareware homebrew integration described above (Windows 11 / RTX 4070, with #683, #684 and #553). E1M1 loaded successfully; movement and shooting were checked. These captures show the integrated game run, not a standalone result from this PR. E1M1 on the final integration build: ![DOOM E1M1 on the final integration build](https://github.com/user-attachments/assets/444f5182-a973-47f7-998c-a5a0024a404b) E1M1 after moving and firing the pistol: ![DOOM E1M1 after movement and shooting](https://github.com/user-attachments/assets/2766a2f9-9bbb-4c10-9432-327193998866)
oneandonlydean commented 2026-10-05 19:45:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T19:45:47Z.


Thanks, this is a useful path for homebrew, and the registered-shader path stays as it was. I have one question about the dispatch cache and a small naming note.

Dispatch cache key for raw programs. ReadRawComputeShader builds a new ShaderSnapshot on every dispatch, and Dispatch.cpp mixes the snapshot pointer into the key (if (!stampValidate()) mix(reinterpret_cast<std::uintptr_t>(registeredShader.get()))). APS5_DISPATCH_STAMP_VALIDATE is off by default, so each raw dispatch gets a new key. That means:

  • a raw dispatch never hits the dispatch cache, so it reads, decodes and goes through insertDispatch again every time (up to 1 MiB of code read per dispatch);
  • every raw dispatch inserts a new entry, and since the cache is LRU-bounded (dispatchCacheEntries()), a homebrew that dispatches every frame keeps evicting the other entries.

This may be what you saw on the cold start that missed the homebrew's frame deadline. Would it work to keep the raw snapshots in a small map keyed by the address, and reuse one while its code words still match (or until the range is written)? Then the pointer stays stable and the key can hit.

Naming. sceAgcInitState_nid_no_patch keeps the 23LRUSvYu1M behaviour that PPSA21564 relies on: it calls that NID with a state pointer and version 13, and the behaviour is unchanged. But tools/progress.py and tools/pr_overlap.py skip every definition that ends in _nid_no_patch, so this export would drop out of the progress count and the overlap check. A name like sceAgcUnknownInitState (the same pattern as #651's sceAgcUnknownCreateInterpolantMapping) would avoid that. kW3GLb7QfPg does recompute to sceAgcInit, so that part looks right to me.

The rest looks right to me: the registered path picks the same snapshot as before, and the header region is still passed when it isn't empty.

Locally (Linux, GCC, NVIDIA): the new Submit cases don't build on main's code, and with the change agc_driver passes and agc_initialization passes 20 times in a row.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6001773798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/685#issuecomment-6001773798). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T19:45:47Z. --- Thanks, this is a useful path for homebrew, and the registered-shader path stays as it was. I have one question about the dispatch cache and a small naming note. **Dispatch cache key for raw programs.** `ReadRawComputeShader` builds a new `ShaderSnapshot` on every dispatch, and `Dispatch.cpp` mixes the snapshot pointer into the key (`if (!stampValidate()) mix(reinterpret_cast<std::uintptr_t>(registeredShader.get()))`). `APS5_DISPATCH_STAMP_VALIDATE` is off by default, so each raw dispatch gets a new key. That means: - a raw dispatch never hits the dispatch cache, so it reads, decodes and goes through `insertDispatch` again every time (up to 1 MiB of code read per dispatch); - every raw dispatch inserts a new entry, and since the cache is LRU-bounded (`dispatchCacheEntries()`), a homebrew that dispatches every frame keeps evicting the other entries. This may be what you saw on the cold start that missed the homebrew's frame deadline. Would it work to keep the raw snapshots in a small map keyed by the address, and reuse one while its code words still match (or until the range is written)? Then the pointer stays stable and the key can hit. **Naming.** `sceAgcInitState_nid_no_patch` keeps the `23LRUSvYu1M` behaviour that PPSA21564 relies on: it calls that NID with a state pointer and version 13, and the behaviour is unchanged. But `tools/progress.py` and `tools/pr_overlap.py` skip every definition that ends in `_nid_no_patch`, so this export would drop out of the progress count and the overlap check. A name like `sceAgcUnknownInitState` (the same pattern as #651's `sceAgcUnknownCreateInterpolantMapping`) would avoid that. `kW3GLb7QfPg` does recompute to `sceAgcInit`, so that part looks right to me. The rest looks right to me: the registered path picks the same snapshot as before, and the header region is still passed when it isn't empty. Locally (Linux, GCC, NVIDIA): the new Submit cases don't build on main's code, and with the change `agc_driver` passes and `agc_initialization` passes 20 times in a row.
github-actions[bot] commented 2026-10-06 01:52:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T01:52:33Z.


Progress report (fe98276 → e5191eb)

➖ System libraries: 81.6% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceAgc sceAgcUnknownInitState
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6007700043 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/685#issuecomment-6007700043). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T01:52:33Z. --- <!-- progress-report --> ### Progress report (fe98276 → e5191eb) ➖ **System libraries**: 81.6% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceAgc | `sceAgcUnknownInitState` | </details>
oneandonlydean commented 2026-10-06 03:27:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T03:27:20Z.


Thanks, both points are covered. Raw snapshots are now reused per address while their code still compares equal (after flushing GPU writes), so the dispatch key stays stable and a hit no longer reads and decodes again, and the cache is bounded at 64 entries and 8 MiB. The new cases (identity on unchanged code, a new snapshot on changed code, concurrent readers, eviction, and the Windows tail and revoke cases) cover what I was worried about. sceAgcUnknownInitState keeps 23LRUSvYu1M, and it stays visible to the progress and overlap tools now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6008722716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/685#issuecomment-6008722716). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T03:27:20Z. --- Thanks, both points are covered. Raw snapshots are now reused per address while their code still compares equal (after flushing GPU writes), so the dispatch key stays stable and a hit no longer reads and decodes again, and the cache is bounded at 64 entries and 8 MiB. The new cases (identity on unchanged code, a new snapshot on changed code, concurrent readers, eviction, and the Windows tail and revoke cases) cover what I was worried about. `sceAgcUnknownInitState` keeps `23LRUSvYu1M`, and it stays visible to the progress and overlap tools now.
github-actions[bot] commented 2026-10-06 03:28:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T03:28:02Z.


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
#757 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp L229
#758 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp L229
#759 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp L229
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6008729528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/685#issuecomment-6008729528). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T03:28:02Z. --- <!-- 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 | |---|---|---|---| | #757 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp` [L229](https://github.com/boykopovar/AnyPS5/blob/0d21b1dea4555d14b06ca0a9cb091c3fb584a061/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp#L229) | | | | #758 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp` [L229](https://github.com/boykopovar/AnyPS5/blob/0d21b1dea4555d14b06ca0a9cb091c3fb584a061/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp#L229) | | | | #759 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp` [L229](https://github.com/boykopovar/AnyPS5/blob/0d21b1dea4555d14b06ca0a9cb091c3fb584a061/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp#L229) | | |
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!685
No description provided.