fix(agc): import registered ranges larger than the device's largest allocation in pieces #7292

Merged
billythemenace2 merged 1 commit from upstream-pr/7292 into main 2026-10-23 14:21:48 +00:00
billythemenace2 commented 2026-10-17 21:41:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-17T21:41:30Z.


Requested by billy

What

An address-based build (AcquireRegistered) imports each registered range as one host import. On a device whose maxMemoryAllocationSize is smaller than the range, that import fails at vkAllocateMemory. AMD's Windows driver reports 2 GiB, and the import fails with VK_ERROR_INVALID_EXTERNAL_HANDLE. The build then asks for a heap mirror of the same size, which fails as well and stops the title. Astro's Playroom (PPSA01325) on an RX 5700 XT stops this way a few seconds in, on a 6.4 GiB range:

[gpu] host import of 0x108a800000+0x199000000 failed at vkAllocateMemory (-1000072003); falling back to copies
what(): compute shader 0x500195100: AGC graphics: heap mirror of 0x108a800000+0x199000000: vkAllocateMemory buffer: allocation=6861881344 memoryType=2 ... Vulkan result -13
  • The device reads VkPhysicalDeviceMaintenance3Properties::maxMemoryAllocationSize next to the host import properties and passes it to SetHostImportMaxBytes.
  • An address-based build imports a registered range larger than the limit in pieces (importPieces). Each piece is a run of the range window's cells no larger than the limit, imported through importAllocation with an end, as access windows already are. Each piece is a region of its own with its own BDA table entry, served in place. If any piece can't be imported, the build falls back to the existing path, as before.
  • importRunAt no longer attempts a single import larger than the limit, which the driver would refuse anyway.

Tested

  • Windows 11, RX 5700 XT. agc_driver_graphics, agc_driver_bda_device and agc_driver_bda_span_reads pass. The new importPiecesOverAllocationLimitTests registers a 5-window range with the limit at 3 windows. It checks that the BDA table covers the range with entries no larger than the limit, each served in place by an import within the limit. It fails without the change ("a BDA table entry of a range over the allocation limit is larger than the limit").
  • Astro's Playroom, with APS5_HOST_IMPORT_MIB=12288 and APS5_TRACE_HOST_IMPORT=1: its 2.2 GiB range 0x1000000000+0x8a800000 is now imported as 0x7c000000 + 0xe800000, where before it was refused or mirrored. The first 1.9 GiB piece of the 6.4 GiB range is then refused by the driver at 5.8 GiB of live imports, because the host heap on this machine is 7.6 GiB (15 GiB RAM). So the title still stops at the same heap mirror here. A machine with more RAM should get past it, but I can't test that.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none (related: #7047, where heap mirrors and imports exhaust a small host heap)
  • Unblocks: partly PPSA01325 (see Tested)
  • GPUs tested: AMD Radeon RX 5700 XT, AMD driver 32.0.21045.5002, Windows 11 26200
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4904165753 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-17T21:41:30Z. --- <!-- claude-projects-attribution --> _Requested by **billy**_ ### What An address-based build (`AcquireRegistered`) imports each registered range as one host import. On a device whose `maxMemoryAllocationSize` is smaller than the range, that import fails at `vkAllocateMemory`. AMD's Windows driver reports 2 GiB, and the import fails with `VK_ERROR_INVALID_EXTERNAL_HANDLE`. The build then asks for a heap mirror of the same size, which fails as well and stops the title. Astro's Playroom (PPSA01325) on an RX 5700 XT stops this way a few seconds in, on a 6.4 GiB range: ``` [gpu] host import of 0x108a800000+0x199000000 failed at vkAllocateMemory (-1000072003); falling back to copies what(): compute shader 0x500195100: AGC graphics: heap mirror of 0x108a800000+0x199000000: vkAllocateMemory buffer: allocation=6861881344 memoryType=2 ... Vulkan result -13 ``` - The device reads `VkPhysicalDeviceMaintenance3Properties::maxMemoryAllocationSize` next to the host import properties and passes it to `SetHostImportMaxBytes`. - An address-based build imports a registered range larger than the limit in pieces (`importPieces`). Each piece is a run of the range window's cells no larger than the limit, imported through `importAllocation` with an end, as access windows already are. Each piece is a region of its own with its own BDA table entry, served in place. If any piece can't be imported, the build falls back to the existing path, as before. - `importRunAt` no longer attempts a single import larger than the limit, which the driver would refuse anyway. ### Tested - Windows 11, RX 5700 XT. `agc_driver_graphics`, `agc_driver_bda_device` and `agc_driver_bda_span_reads` pass. The new `importPiecesOverAllocationLimitTests` registers a 5-window range with the limit at 3 windows. It checks that the BDA table covers the range with entries no larger than the limit, each served in place by an import within the limit. It fails without the change ("a BDA table entry of a range over the allocation limit is larger than the limit"). - Astro's Playroom, with `APS5_HOST_IMPORT_MIB=12288` and `APS5_TRACE_HOST_IMPORT=1`: its 2.2 GiB range `0x1000000000+0x8a800000` is now imported as `0x7c000000` + `0xe800000`, where before it was refused or mirrored. The first 1.9 GiB piece of the 6.4 GiB range is then refused by the driver at 5.8 GiB of live imports, because the host heap on this machine is 7.6 GiB (15 GiB RAM). So the title still stops at the same heap mirror here. A machine with more RAM should get past it, but I can't test that. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none (related: #7047, where heap mirrors and imports exhaust a small host heap) - [x] Unblocks: partly PPSA01325 (see Tested) - [x] GPUs tested: AMD Radeon RX 5700 XT, AMD driver 32.0.21045.5002, Windows 11 26200 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fma-rc commented 2026-10-17 23:38:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-17T23:38:07Z.


I ran the new test on a Radeon 680M (RADV, Linux) against current main 98c251fc62, 3 runs each. With only the test and the SetHostImportMaxBytes setter applied (the setter stores the limit, nothing reads it), agc_driver_graphics fails every run with a BDA table entry of a range over the allocation limit is larger than the limit. With the whole PR it passes 3/3, and main without the test passes 3/3.

So the test does catch the missing split. RADV here reports maxMemoryAllocationSize = 0xfffffffc (the RTX 5080 reports no limit), so Linux AMD is under the 6.4 GiB range too. A 180 s Playroom boot on main on the 680M logged no failed host import, though. I'll run Playroom on main and on this PR on the 680M for longer and add what it shows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243178682 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6243178682). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-17T23:38:07Z. --- I ran the new test on a Radeon 680M (RADV, Linux) against current main 98c251fc62, 3 runs each. With only the test and the `SetHostImportMaxBytes` setter applied (the setter stores the limit, nothing reads it), `agc_driver_graphics` fails every run with `a BDA table entry of a range over the allocation limit is larger than the limit`. With the whole PR it passes 3/3, and main without the test passes 3/3. So the test does catch the missing split. RADV here reports `maxMemoryAllocationSize` = 0xfffffffc (the RTX 5080 reports no limit), so Linux AMD is under the 6.4 GiB range too. A 180 s Playroom boot on main on the 680M logged no failed host import, though. I'll run Playroom on main and on this PR on the 680M for longer and add what it shows.
blawesom commented 2026-10-18 10:24:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T10:24:20Z.


Rebase handoff — rebased onto current main (authorship unchanged). One conflict in GuestBufferMemory.hpp: main's newer SetHostImportDeferredSettles declaration kept alongside your SetHostImportMaxBytes.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the known main regression (agc_driver_tessellation segfault — Mesa, #5444), not this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7292
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is c1d5a013b.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6248723169 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6248723169). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-18T10:24:20Z. --- **Rebase handoff** — rebased onto current `main` (authorship unchanged). One conflict in `GuestBufferMemory.hpp`: `main`'s newer `SetHostImportDeferredSettles` declaration kept alongside your `SetHostImportMaxBytes`. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; conventions pass; **full suite green apart from the known `main` regression** (`agc_driver_tessellation` segfault — Mesa, #5444), not this PR. **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/7292 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `c1d5a013b`.
billythemenace2 commented 2026-10-18 15:24:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-18T15:24:23Z.


@fma-rc thank you, that's the check this needed: the test fails with only the setter applied and passes with the whole PR. Good to know RADV on the 680M reports 0xfffffffc, so ranges over 4 GiB hit this on Linux AMD too. A longer Playroom run on main and on this PR would be very welcome.

@blawesom thank you for the rebase. I redid it here on main e5f18ea99 with the same resolution, keeping SetHostImportDeferredSettles beside SetHostImportMaxBytes. The patch is identical to your c1d5a013b. agc_driver_graphics and the conventions check pass on the RX 5700 XT. The branch is now at 0a98bd0a5.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251643866 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6251643866). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-18T15:24:23Z. --- @fma-rc thank you, that's the check this needed: the test fails with only the setter applied and passes with the whole PR. Good to know RADV on the 680M reports `0xfffffffc`, so ranges over 4 GiB hit this on Linux AMD too. A longer Playroom run on main and on this PR would be very welcome. @blawesom thank you for the rebase. I redid it here on `main` `e5f18ea99` with the same resolution, keeping `SetHostImportDeferredSettles` beside `SetHostImportMaxBytes`. The patch is identical to your `c1d5a013b`. `agc_driver_graphics` and the conventions check pass on the RX 5700 XT. The branch is now at `0a98bd0a5`. AI-assisted (Claude Code).
billythemenace2 commented 2026-10-19 16:29:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-19T16:29:19Z.


Rebased onto main 32004dfa5. The only conflict was in GuestBufferMemory.hpp: main's new HostImportBudget declaration now sits beside SetHostImportMaxBytes. agc_driver_graphics and the conventions check pass on the RX 5700 XT. The branch is at 4a27917d0.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6272028571 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6272028571). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-19T16:29:19Z. --- Rebased onto `main` `32004dfa5`. The only conflict was in `GuestBufferMemory.hpp`: `main`'s new `HostImportBudget` declaration now sits beside `SetHostImportMaxBytes`. `agc_driver_graphics` and the conventions check pass on the RX 5700 XT. The branch is at `4a27917d0`. AI-assisted (Claude Code).
billythemenace2 commented 2026-10-20 15:52:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-20T15:52:03Z.


Rebased onto main d073fe6a1, now at fa61ee5dc. main added the covering-import shortcut and the ImportRequester argument in the meantime. A range still served by the covering import of an earlier range keeps that import. A range over the allocation limit goes to importPieces, whose importAllocation calls pass ImportRequester::Build. The size guard in importRunAt sits before the new stepDown failure check. agc_driver_graphics, agc_driver_bda_device, agc_driver_bda_span_reads and the conventions check pass on the RX 5700 XT.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6295042342 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6295042342). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-20T15:52:03Z. --- Rebased onto `main` `d073fe6a1`, now at `fa61ee5dc`. `main` added the covering-import shortcut and the `ImportRequester` argument in the meantime. A range still served by the covering import of an earlier range keeps that import. A range over the allocation limit goes to `importPieces`, whose `importAllocation` calls pass `ImportRequester::Build`. The size guard in `importRunAt` sits before the new `stepDown` failure check. `agc_driver_graphics`, `agc_driver_bda_device`, `agc_driver_bda_span_reads` and the conventions check pass on the RX 5700 XT. AI-assisted (Claude Code).
LeandroLP23 commented 2026-10-21 08:14:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-21T08:14:48Z.


Verified on a second AMD Windows driver branch: Radeon 860M (RDNA 3.5, 1002:1114, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0, Release. vulkaninfo reports maxMemoryAllocationSize = 0x80000000, the same 2 GiB as the RX 5700 XT.

I merged fa61ee5dc onto main ec7eacc62 (clean merge, one auto-merge in BdaResources.cpp). With ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1, agc_driver_graphics passes, including importPiecesOverAllocationLimitTests, and so do agc_driver_bda_device and agc_driver_bda_span_reads. No title I have here registers a range over 2 GiB, so I have no title run to add.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311326502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6311326502). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-21T08:14:48Z. --- Verified on a second AMD Windows driver branch: Radeon 860M (RDNA 3.5, `1002:1114`, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0, Release. `vulkaninfo` reports `maxMemoryAllocationSize` = 0x80000000, the same 2 GiB as the RX 5700 XT. I merged `fa61ee5dc` onto `main` `ec7eacc62` (clean merge, one auto-merge in `BdaResources.cpp`). With `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`, `agc_driver_graphics` passes, including `importPiecesOverAllocationLimitTests`, and so do `agc_driver_bda_device` and `agc_driver_bda_span_reads`. No title I have here registers a range over 2 GiB, so I have no title run to add.
billythemenace2 commented 2026-10-21 19:18:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-21T19:18:08Z.


@LeandroLP23 thank you. A second AMD Windows driver branch (RDNA 3.5) reporting the same 2 GiB maxMemoryAllocationSize, with importPiecesOverAllocationLimitTests passing, is exactly the coverage this needed.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324471476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6324471476). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-21T19:18:08Z. --- @LeandroLP23 thank you. A second AMD Windows driver branch (RDNA 3.5) reporting the same 2 GiB `maxMemoryAllocationSize`, with `importPiecesOverAllocationLimitTests` passing, is exactly the coverage this needed. AI-assisted (Claude Code).
EagleBearerYS commented 2026-10-22 00:45:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T00:45:06Z.


@billythemenace2 a merge-order note: #9514 changes the plain import in AcquireRegistered, next to the branch this PR adds for a range larger than the device's largest allocation. When the host import budget refuses a range, #9514 retries the import with eviction, and only when copying the range would take the build past APS5_ADDRESS_COPY_MAX_MIB. Your piece import stays as it is, so the two should compose. As this one is a draft, #9514 proposes going first, and this PR would rebase over it. If you'd rather this one went first, say so and #9514 will list it under Depends on.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329888837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6329888837). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T00:45:06Z. --- @billythemenace2 a merge-order note: #9514 changes the plain import in `AcquireRegistered`, next to the branch this PR adds for a range larger than the device's largest allocation. When the host import budget refuses a range, #9514 retries the import with eviction, and only when copying the range would take the build past `APS5_ADDRESS_COPY_MAX_MIB`. Your piece import stays as it is, so the two should compose. As this one is a draft, #9514 proposes going first, and this PR would rebase over it. If you'd rather this one went first, say so and #9514 will list it under Depends on.
MarcZX10 commented 2026-10-22 02:05:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:05:43Z.


I am reviewing #9514, which changes AcquireRegistered adjacent to #7292’s piece-import path. Its author proposes #9514 first and then rebasing #7292, arguing that a piece-served range avoids the budget-refusal retry. Please confirm whether that order is safe for #7292, or specify the sequence you need, so the two PRs can record the agreed order before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330934298 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6330934298). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:05:43Z. --- I am reviewing #9514, which changes `AcquireRegistered` adjacent to #7292’s piece-import path. Its author proposes #9514 first and then rebasing #7292, arguing that a piece-served range avoids the budget-refusal retry. Please confirm whether that order is safe for #7292, or specify the sequence you need, so the two PRs can record the agreed order before merge.
billythemenace2 commented 2026-10-22 14:08:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-22T14:08:44Z.


@EagleBearerYS @MarcZX10 yes, #9514 first is safe, and I'll rebase this over it. The two paths don't overlap. This PR only changes the branch for a range larger than maxMemoryAllocationSize, which never reaches the plain importAllocation that #9514 retries with eviction. Its pieces go through importPieces, with evict false as before. If a piece is refused by the budget, the whole range falls back to the existing mirror and copy path, so the cap #9514 checks still applies there.

One possible follow-up once both are in: let importPieces use #9514's eviction retry for a refused piece. I'd keep that out of both PRs.

I'm marking this ready for review. It's been checked on two AMD Windows driver branches (RDNA1 and RDNA 3.5) and on RADV.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342808753 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7292#issuecomment-6342808753). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-22T14:08:44Z. --- @EagleBearerYS @MarcZX10 yes, #9514 first is safe, and I'll rebase this over it. The two paths don't overlap. This PR only changes the branch for a range larger than `maxMemoryAllocationSize`, which never reaches the plain `importAllocation` that #9514 retries with eviction. Its pieces go through `importPieces`, with `evict` false as before. If a piece is refused by the budget, the whole range falls back to the existing mirror and copy path, so the cap #9514 checks still applies there. One possible follow-up once both are in: let `importPieces` use #9514's eviction retry for a refused piece. I'd keep that out of both PRs. I'm marking this ready for review. It's been checked on two AMD Windows driver branches (RDNA1 and RDNA 3.5) and on RADV. AI-assisted (Claude Code).
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!7292
No description provided.