Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Raghav314:fix/libc-heap-without-gpu
Oct 11, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Raghav314:fix/libc-heap-without-gpu

Conversation

@Raghav314

Copy link
Copy Markdown
Contributor

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

AnyPS5's libc heap registered every block with GPU access, so every
address-based build imported or mirrored each malloc block the title had
made. The console's libc.prx maps its heap with protection 3 (CPU read
and write, no GPU bits), so the GPU never sees it there either.

Heap blocks are now registered without GPU access; reallocating keeps the
block's access. The AvPlayer fallback for a title that passes no texture
allocator stands in for that allocator, which hands out memory the GPU
reads, so it allocates through a new GuestHeapAlignForGpu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Silverash-i8

Copy link
Copy Markdown
Contributor

Windows run, since the PR has no Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto main d31b57a 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

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit 19a3d0c into boykopovar:main Oct 11, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants