fix(recompiler): emit a GPU-selected formatted buffer access through one shared function #2349

Merged
Pipodi merged 1 commit from upstream-pr/2349 into main 2026-10-10 09:00:11 +00:00
Pipodi commented 2026-10-09 16:06:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-09T16:06:35Z.


What

#1959 moves the switch over every buffer format into one function per resource when the descriptor is prepared. It keeps the inline switch for GPU-selected descriptors (memory.gpuDescriptor). For those, every buffer_load_format_* / buffer_store_format_* still emits all 77 cases inline, and each case inlines the address computation, bounds checks and BDA reads of formatted().

A title with about 300 such accesses in one compute program (Ghost of Yōtei, PPSA26344, 0x8000289300, 102 guest blocks) compiles to 37.1M SPIR-V words: 292 OpSwitches, about 700k blocks, 287 distinct block shapes. Each pipeline takes 40 s or more to create on NVIDIA, and each shader disk-cache entry is up to ~300 MB. This is probably also the 13.4M-word module reported on #1183.

  • formattedGpuCall emits one DontInline SPIR-V function per component count, direction, d16, coherence, kind and stop mode, and runs formatSwitch inside it.
    • It takes the descriptor fields (base, records, stride, word 3, swizzle, valid), the index, offset, soffset and the access's PC. Each access is one call.
  • When BDA faults stop invocations, the function returns {value, stopped} (just stopped for a store). Inside it, a stop returns that through bdaStopValue, as read_bda_span does. The caller calls StopBdaInvocationIf on the flag, so the pixel-shader interlock and OpKill handling stay in the entry function.
  • BdaInstructionPc returns the instruction's PC, or the PC parameter inside the shared function (SpirvEmitterState::bdaPcOverride). The BDA read, write, store, atomic and overflow paths use it, so a fault records the PC of the access that faulted.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, RTX 4090 (driver 617.42).

  • agc_formatted_buffer_once gains a GPU-selected case: dword 3 of the V# comes from v_readfirstlane_b32 s11, v0.
    • It checks that two more loads add calls but no function, no switch and less than 10% words.
    • It fails on #1959 alone ("2 more format switches") and passes with this change.
  • Full ctest: 506/506 passed.
  • Ghost of Yōtei, same tree before and after:
    • 0x8000289300 goes from 37,110,613 to 1,447,831 words, and its recompile from 7.2 s to 0.25 s.
    • 0x800036e100 goes from 818,855 to 260,672 words; its pipeline now takes 2.4 s.
    • The average disk-cache entry drops below 1 MB.
    • The title reaches its first presented frames (the SIE intro card). Before, a 25-minute run was still creating the second and third 37M-word pipelines.

Checklist

  • Based on current main; no other open PR implements the same functions (stacked on #1959)
  • 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: #1959
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4802900030 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2349). Originally posted by [Pipodi](https://github.com/Pipodi) on 2026-10-09T16:06:35Z. --- ### What #1959 moves the switch over every buffer format into one function per resource when the descriptor is prepared. It keeps the inline switch for GPU-selected descriptors (`memory.gpuDescriptor`). For those, every `buffer_load_format_*` / `buffer_store_format_*` still emits all 77 cases inline, and each case inlines the address computation, bounds checks and BDA reads of `formatted()`. A title with about 300 such accesses in one compute program (Ghost of Yōtei, PPSA26344, 0x8000289300, 102 guest blocks) compiles to 37.1M SPIR-V words: 292 `OpSwitch`es, about 700k blocks, 287 distinct block shapes. Each pipeline takes 40 s or more to create on NVIDIA, and each shader disk-cache entry is up to ~300 MB. This is probably also the 13.4M-word module reported on #1183. - `formattedGpuCall` emits one `DontInline` SPIR-V function per component count, direction, d16, coherence, kind and stop mode, and runs `formatSwitch` inside it. - It takes the descriptor fields (base, records, stride, word 3, swizzle, valid), the index, offset, soffset and the access's PC. Each access is one call. - When BDA faults stop invocations, the function returns `{value, stopped}` (just `stopped` for a store). Inside it, a stop returns that through `bdaStopValue`, as `read_bda_span` does. The caller calls `StopBdaInvocationIf` on the flag, so the pixel-shader interlock and `OpKill` handling stay in the entry function. - `BdaInstructionPc` returns the instruction's PC, or the PC parameter inside the shared function (`SpirvEmitterState::bdaPcOverride`). The BDA read, write, store, atomic and overflow paths use it, so a fault records the PC of the access that faulted. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, RTX 4090 (driver 617.42). - `agc_formatted_buffer_once` gains a GPU-selected case: dword 3 of the V# comes from `v_readfirstlane_b32 s11, v0`. - It checks that two more loads add calls but no function, no switch and less than 10% words. - It fails on #1959 alone ("2 more format switches") and passes with this change. - Full ctest: 506/506 passed. - Ghost of Yōtei, same tree before and after: - 0x8000289300 goes from 37,110,613 to 1,447,831 words, and its recompile from 7.2 s to 0.25 s. - 0x800036e100 goes from 818,855 to 260,672 words; its pipeline now takes 2.4 s. - The average disk-cache entry drops below 1 MB. - The title reaches its first presented frames (the SIE intro card). Before, a 25-minute run was still creating the second and third 37M-word pipelines. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (stacked on #1959) - [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: #1959 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Kikoarl commented 2026-10-09 17:52:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T17:52:37Z.


Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at 0690a904:

  • Build: Built cleanly in RAM (/tmp/anyps5_build) with zero warnings/errors.
  • Conventions: python3 tools/check_conventions.py --base origin/main --head HEAD -> PASS (0 errors).
  • Verification: Verified FormattedBufferOnce.cpp test and SPIR-V emission deduplication in SpirvBda.hpp. Generates cleaner SPIR-V without code bloat.

LGTM!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086303700 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2349#issuecomment-6086303700). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T17:52:37Z. --- Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at `0690a904`: - **Build**: Built cleanly in RAM (`/tmp/anyps5_build`) with zero warnings/errors. - **Conventions**: `python3 tools/check_conventions.py --base origin/main --head HEAD` -> **PASS (0 errors)**. - **Verification**: Verified `FormattedBufferOnce.cpp` test and SPIR-V emission deduplication in `SpirvBda.hpp`. Generates cleaner SPIR-V without code bloat. LGTM!
adriadam10 commented 2026-10-10 08:44:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:44:59Z.


Rebased onto current main: dropped the first commit (the old version of #1959, already merged as f2bd6d4af) and resolved the conflicts in SpirvBdaRead.cpp (BDA byte-write functions on main now) and FormattedBufferOnce.cpp (Compile(loads, formattedStores, gpu)), plus one more BdaInstructionPc site in the BDA store probe path.

Checked on Linux (RADV) on the rebased tree: libSceAgc + libSceAgcDriver ctest green (334/335, the one failure is a stale registration not present on main). agc_formatted_buffer_once fails without the change and passes with it. The Ghost of Yōtei numbers and the NVIDIA/Windows runs are the author's and Kikoarl's (Linux, Intel); not reproduced here. Merging once CI is green on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095801027 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2349#issuecomment-6095801027). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T08:44:59Z. --- Rebased onto current `main`: dropped the first commit (the old version of #1959, already merged as f2bd6d4af) and resolved the conflicts in `SpirvBdaRead.cpp` (BDA byte-write functions on main now) and `FormattedBufferOnce.cpp` (`Compile(loads, formattedStores, gpu)`), plus one more `BdaInstructionPc` site in the BDA store probe path. Checked on Linux (RADV) on the rebased tree: libSceAgc + libSceAgcDriver ctest green (334/335, the one failure is a stale registration not present on `main`). `agc_formatted_buffer_once` fails without the change and passes with it. The Ghost of Yōtei numbers and the NVIDIA/Windows runs are the author's and Kikoarl's (Linux, Intel); not reproduced here. 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!2349
No description provided.