fix(libc): register guest heap blocks without GPU access #3213

Merged
Raghav314 merged 1 commit from upstream-pr/3213 into main 2026-10-11 07:14:14 +00:00
Raghav314 commented 2026-10-11 01:33:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-11T01:33:34Z.


What

This is the follow-up #1905 left open: AnyPS5's own libc heap without GPU access. @TheAggie measured what it costs today in #1905: vkQuake (PPSA99010, homebrew, RADV) makes about 10,000 small blocks through this heap, every address-based build refreshes a heap mirror for each, and leaving only those blocks out took the demo from about 22 to 44 FPS, with correct rendering and no BDA faults.

AnyPS5's libc heap registered every block it hands out with GPU access, so every address-based build imported or mirrored each of the title's malloc blocks. On the console the heap is not GPU memory: a title's own libc.prx maps it with sceKernelMapNamedFlexibleMemoryInternal and protection 3 (CPU read and write, no GPU bits). PPSA36082's bundled libc.prx does this at both of its heap mapping sites (+0xb2eb, +0xb4fd).

  • Heap blocks are registered without GPU access, so address-based builds leave them out.
  • Reallocating or realigning a block keeps the access it had.
  • A title that hands memory to the GPU still has to map or protect it with GPU bits, as it does on the console; nothing changes for that memory.
  • AvPlayer's fallback for a title that passes no texture allocator stands in for that allocator, whose memory the GPU reads. It now allocates through a new GuestHeapAlignForGpu, which registers the block with GPU access.

Of the local changes I listed in #1905, this is the libc heap part of the first one (GPU read and write kept apart), taken alone because of that measurement. The rest stay local. In particular, paths other than address-based builds (DMA copies, textures) still import a heap block if a title points them at one; making every path follow GPU access was the second change listed there.

Tested

Linux, RTX 4090, NVIDIA 615.71.09, local run of the Linux CI job (SPIRV tools on): ctest 754/755. The failure, agc_driver_dcc_keys_first_write, fails the same way on main.

  • agc_driver_graphics (tests/BdaResources.cpp): a plain heap block has no GPU access and is left out of an address-based build, a block from GuestHeapAlignForGpu has it and is in the build, and both keep their access through a reallocation. Registering plain blocks with GPU access again, as main does, fails it. The cached-address-space test and agc_driver's copy into host memory model memory the GPU reads, so they now allocate it with GPU access.
  • I ran PPSA36082 on my machine (it uses its own bundled libc.prx, so I expected no change): boot and the hub, no BDA faults, the same frame rate within noise (34.0 / 34.5 fps).

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:4815789910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3213). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-11T01:33:34Z. --- ### What This is the follow-up #1905 left open: AnyPS5's own libc heap without GPU access. @TheAggie measured what it costs today [in #1905](https://github.com/boykopovar/AnyPS5/pull/1905#issuecomment-6083694623): vkQuake (PPSA99010, homebrew, RADV) makes about 10,000 small blocks through this heap, every address-based build refreshes a heap mirror for each, and leaving only those blocks out took the demo from about 22 to 44 FPS, with correct rendering and no BDA faults. AnyPS5's libc heap registered every block it hands out with GPU access, so every address-based build imported or mirrored each of the title's malloc blocks. On the console the heap is not GPU memory: a title's own `libc.prx` maps it with `sceKernelMapNamedFlexibleMemoryInternal` and protection `3` (CPU read and write, no GPU bits). PPSA36082's bundled `libc.prx` does this at both of its heap mapping sites (`+0xb2eb`, `+0xb4fd`). - Heap blocks are registered without GPU access, so address-based builds leave them out. - Reallocating or realigning a block keeps the access it had. - A title that hands memory to the GPU still has to map or protect it with GPU bits, as it does on the console; nothing changes for that memory. - AvPlayer's fallback for a title that passes no texture allocator stands in for that allocator, whose memory the GPU reads. It now allocates through a new `GuestHeapAlignForGpu`, which registers the block with GPU access. Of the local changes I listed in #1905, this is the libc heap part of the first one (GPU read and write kept apart), taken alone because of that measurement. The rest stay local. In particular, paths other than address-based builds (DMA copies, textures) still import a heap block if a title points them at one; making every path follow GPU access was the second change listed there. ### Tested Linux, RTX 4090, NVIDIA 615.71.09, local run of the Linux CI job (SPIRV tools on): ctest 754/755. The failure, `agc_driver_dcc_keys_first_write`, fails the same way on main. - `agc_driver_graphics` (`tests/BdaResources.cpp`): a plain heap block has no GPU access and is left out of an address-based build, a block from `GuestHeapAlignForGpu` has it and is in the build, and both keep their access through a reallocation. Registering plain blocks with GPU access again, as main does, fails it. The cached-address-space test and `agc_driver`'s copy into host memory model memory the GPU reads, so they now allocate it with GPU access. - I ran PPSA36082 on my machine (it uses its own bundled `libc.prx`, so I expected no change): boot and the hub, no BDA faults, the same frame rate within noise (34.0 / 34.5 fps). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
Silverash-i8 commented 2026-10-11 01:51:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:51:15Z.


Windows run, since the PR has no Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto main d31b57a4 in one build with #3213, #3159, #3158, #3142, #3141 and #2977, on an RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).

  • agc_driver_bda_device, agc_driver_bda_span_reads (BdaResources.cpp) and agc_driver (Submit.cpp) pass on both GPUs. With main + this PR alone, agc_driver_dcc_keys_first_write also passes on both.

In the full ctest of that build, the only failure not also on plain main is agc_driver_dcc_keys_first_write, which I bisected to #3158 alone (reported there).

AI-assisted (Claude Code); I ran this on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104356196 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3213#issuecomment-6104356196). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T01:51:15Z. --- Windows run, since the PR has no Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto `main` d31b57a4 in one build with #3213, #3159, #3158, #3142, #3141 and #2977, on an RTX 5060 Laptop and the Arrow Lake iGPU (`ANYPS5_GPU=Intel`). - `agc_driver_bda_device`, `agc_driver_bda_span_reads` (`BdaResources.cpp`) and `agc_driver` (`Submit.cpp`) pass on both GPUs. With `main` + this PR alone, `agc_driver_dcc_keys_first_write` also passes on both. In the full `ctest` of that build, the only failure not also on plain `main` is `agc_driver_dcc_keys_first_write`, which I bisected to #3158 alone (reported there). AI-assisted (Claude Code); I ran this on my machine.
adriadam10 commented 2026-10-11 07:14:11 +00:00 (Migrated from github.com)

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


Checked the diff: heap blocks register without GPU access, realloc/realign keep it, GuestHeapAlignForGpu is used only where the GPU reads (AvPlayer texture fallback). Build + ctest of AgcDriver, AvPlayer and libc pass (402/402); the updated tests don't build without the change. Thanks @Silverash-i8 for the Windows run. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106571152 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3213#issuecomment-6106571152). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:14:11Z. --- Checked the diff: heap blocks register without GPU access, realloc/realign keep it, `GuestHeapAlignForGpu` is used only where the GPU reads (AvPlayer texture fallback). Build + ctest of AgcDriver, AvPlayer and libc pass (402/402); the updated tests don't build without the change. Thanks @Silverash-i8 for the Windows run. Merging.
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!3213
No description provided.