fix(agc): keep RADV's descriptor pool overrun inside the pool's pages #1065

Merged
alfalfa-star merged 1 commit from upstream-pr/1065 into main 2026-10-08 05:49:39 +00:00
alfalfa-star commented 2026-10-07 07:19:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-07T07:19:10Z.


What

The descriptor cache's chain pools are created with two more storage buffer descriptors than a set may take (ChainPoolCreateSizes). This keeps a RADV overrun inside the pool's pages. A TechnicalDebt line records the workaround.

RADV (Mesa 26.0 and later, since 849d41db "radv: implement a new descriptor sets allocator") sets up a FREE_DESCRIPTOR_SET pool's allocator with

util_vma_heap_init(&pool->bo_heap, RADV_POOL_HEAP_OFFSET, bo_size + RADV_POOL_HEAP_OFFSET);

util_vma_heap_init takes a start and a size, so the heap ends 32 bytes past the pool's buffer, and a set can be placed up to 32 bytes past its end. Mesa main still has this. The chain pools come out at exactly 0x26000 bytes, a page multiple, so those 32 bytes are an unmapped page:

  • On the GPU, a shader's scalar load of a descriptor in the set's last 32 bytes raises a gfxhub page fault (SQC (data)). The gfx ring times out and is reset, and the recorder then waits on a fence that never signals. In PPSA14632, Unreal aborts after 120 s with GameThread timed out waiting for RenderThread. A RADV_DEBUG=hang dump shows a 160-byte set at offset 0x25f80, with an s_load_b128 of its storage buffer descriptor at 0x26000.
  • On the CPU, vkUpdateDescriptorSets can write there. Under GPU-assisted validation this segfaulted in radv_write_sampler_descriptor, with the destination exactly at the end of a 0x26000-byte /dev/dri/renderD128 mapping.

With two more storage buffers the pool is 0x26020 bytes. The 16-byte slack RADV adds per set is already capped by maxSets, so the only change is the 32 bytes. The buffer then spans 0x27000 bytes and the overrun stays in mapped memory. The other pools in the driver are linear (no FREE_DESCRIPTOR_SET), and RADV bounds those correctly.

Standalone repro on RADV, no AnyPS5 needed: a pool for four sampled images (128 bytes, maxSets 1).

Set linear pool FREE_DESCRIPTOR_SET pool
4 images (128 bytes) 0 0
5 images (160 bytes) VK_ERROR_OUT_OF_POOL_MEMORY 0
6 images (192 bytes) VK_ERROR_OUT_OF_POOL_MEMORY VK_ERROR_FRAGMENTED_POOL

Tested

Linux 7.2.9 (Arch), Mesa 26.2.4 RADV, RX 9070 XT (RDNA4).

  • PPSA14632 (LEGO Horizon Adventures), with #943's imports: before, 6 of 6 runs page-faulted and hung within 1.5 to 3 minutes. With this change, a 5-minute run has no fault and keeps 15 presents per 10 s.
  • ctest on this branch: 382 of 382 pass.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4769317701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1065). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-07T07:19:10Z. --- ### What The descriptor cache's chain pools are created with two more storage buffer descriptors than a set may take (`ChainPoolCreateSizes`). This keeps a RADV overrun inside the pool's pages. A TechnicalDebt line records the workaround. RADV (Mesa 26.0 and later, since 849d41db "radv: implement a new descriptor sets allocator") sets up a `FREE_DESCRIPTOR_SET` pool's allocator with ```c util_vma_heap_init(&pool->bo_heap, RADV_POOL_HEAP_OFFSET, bo_size + RADV_POOL_HEAP_OFFSET); ``` `util_vma_heap_init` takes a start and a size, so the heap ends 32 bytes past the pool's buffer, and a set can be placed up to 32 bytes past its end. Mesa main still has this. The chain pools come out at exactly 0x26000 bytes, a page multiple, so those 32 bytes are an unmapped page: - On the GPU, a shader's scalar load of a descriptor in the set's last 32 bytes raises a gfxhub page fault (`SQC (data)`). The gfx ring times out and is reset, and the recorder then waits on a fence that never signals. In PPSA14632, Unreal aborts after 120 s with `GameThread timed out waiting for RenderThread`. A `RADV_DEBUG=hang` dump shows a 160-byte set at offset 0x25f80, with an `s_load_b128` of its storage buffer descriptor at 0x26000. - On the CPU, `vkUpdateDescriptorSets` can write there. Under GPU-assisted validation this segfaulted in `radv_write_sampler_descriptor`, with the destination exactly at the end of a 0x26000-byte `/dev/dri/renderD128` mapping. With two more storage buffers the pool is 0x26020 bytes. The 16-byte slack RADV adds per set is already capped by `maxSets`, so the only change is the 32 bytes. The buffer then spans 0x27000 bytes and the overrun stays in mapped memory. The other pools in the driver are linear (no `FREE_DESCRIPTOR_SET`), and RADV bounds those correctly. Standalone repro on RADV, no AnyPS5 needed: a pool for four sampled images (128 bytes, `maxSets` 1). | Set | linear pool | `FREE_DESCRIPTOR_SET` pool | |---|---|---| | 4 images (128 bytes) | 0 | 0 | | 5 images (160 bytes) | `VK_ERROR_OUT_OF_POOL_MEMORY` | **0** | | 6 images (192 bytes) | `VK_ERROR_OUT_OF_POOL_MEMORY` | `VK_ERROR_FRAGMENTED_POOL` | ### Tested Linux 7.2.9 (Arch), Mesa 26.2.4 RADV, RX 9070 XT (RDNA4). - PPSA14632 (LEGO Horizon Adventures), with #943's imports: before, 6 of 6 runs page-faulted and hung within 1.5 to 3 minutes. With this change, a 5-minute run has no fault and keeps 15 presents per 10 s. - `ctest` on this branch: 382 of 382 pass. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-07 07:35:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T07:35:01Z.


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
#1051 docs/dev/TechnicalDebt.md L255
#1184 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L2155-2156
#1237 docs/dev/TechnicalDebt.md L255
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6033234214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1065#issuecomment-6033234214). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T07:35:01Z. --- <!-- 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 | |---|---|---|---| | #1051 | `docs/dev/TechnicalDebt.md` [L255](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/docs/dev/TechnicalDebt.md#L255) | | | | #1184 | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` [L2155-2156](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L2155-L2156) | | | | #1237 | `docs/dev/TechnicalDebt.md` [L255](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/docs/dev/TechnicalDebt.md#L255) | | |
adriadam10 commented 2026-10-08 05:49:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T05:49:35Z.


Checked: build + ctest on the merge with current main (415/415), CI green, and the RADV util_vma_heap_init(bo_size + RADV_POOL_HEAP_OFFSET) claim against Mesa main (radv_descriptor_pool.c). The pool size arithmetic (0x26000 → 0x26020) matches, and ChainPoolSizes still drives the capacity check. Merging.

Note for #1184: it rewrites the same poolInfo lines in ShaderResources.cpp, so whichever lands second needs a rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6053294262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1065#issuecomment-6053294262). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T05:49:35Z. --- Checked: build + ctest on the merge with current `main` (415/415), CI green, and the RADV `util_vma_heap_init(bo_size + RADV_POOL_HEAP_OFFSET)` claim against Mesa main (`radv_descriptor_pool.c`). The pool size arithmetic (0x26000 → 0x26020) matches, and `ChainPoolSizes` still drives the capacity check. Merging. Note for #1184: it rewrites the same `poolInfo` lines in `ShaderResources.cpp`, so whichever lands second needs a rebase.
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!1065
No description provided.