fix(agc): copy an imported range once a merge extends it past its import #1489

Merged
Celegans12 merged 1 commit from upstream-pr/1489 into main 2026-10-09 19:05:34 +00:00
Celegans12 commented 2026-10-08 09:08:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T09:08:02Z.


What

In an address-based build, a buffer view that runs from one host-imported registered range into the next is bound past the first range's import: UploadPrepare merges the view into that range's region and keeps the import (Region::direct). Descriptor then returns the import's buffer with offset + range past its size, and AddressRanges maps the whole region, the next range included, through the import's device address.

  • A merge that extends a region past its end now drops its import, so the region looks for an import that covers it and otherwise takes the copy path, as a range crossing an image mirror's end already does. Descriptor-only builds are unchanged.
  • Like every copied range, it is read-only to pointers: a pointer store into it now takes the BDA permission fault, where main stored into the first range in place.
  • With #1270's end check, PPSA26344 v1.008's G-buffer draws throw guest buffer view exceeds its GPU owner (190 skips in 3,000 s); a view across two imported ranges gives the same error, but the draws' V# comes from SRT memory and is not traced.
  • #1270 (ours) adds that end check. #1345 rewrites this merge loop in place and merges cleanly; #290, #1357, #1359, #1361, #1364 and #1366 edit other parts of UploadPrepare.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 9619edff: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 406/406 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 405/405 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • agc_driver_graphics (mock device, new vkGetMemoryHostPointerPropertiesEXT stub): a view across two imported ranges and one inside the second read their bytes in bounds; no BDA range runs past its buffer. Fails on main; with #1270 it fails at exceeds its GPU owner.
  • PPSA26344 v1.008: no "guest buffer view exceeds its GPU owner" skip in 3,600 s (13 in the 3,000 s run before).
  • Not tested: Linux (CI), console behaviour.

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:4784450526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1489). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-08T09:08:02Z. --- ### What In an address-based build, a buffer view that runs from one host-imported registered range into the next is bound past the first range's import: `UploadPrepare` merges the view into that range's region and keeps the import (`Region::direct`). `Descriptor` then returns the import's buffer with `offset + range` past its size, and `AddressRanges` maps the whole region, the next range included, through the import's device address. - A merge that extends a region past its end now drops its import, so the region looks for an import that covers it and otherwise takes the copy path, as a range crossing an image mirror's end already does. Descriptor-only builds are unchanged. - Like every copied range, it is read-only to pointers: a pointer store into it now takes the BDA permission fault, where `main` stored into the first range in place. - With #1270's end check, PPSA26344 v1.008's G-buffer draws throw `guest buffer view exceeds its GPU owner` (190 skips in 3,000 s); a view across two imported ranges gives the same error, but the draws' V# comes from SRT memory and is not traced. - #1270 (ours) adds that end check. #1345 rewrites this merge loop in place and merges cleanly; #290, #1357, #1359, #1361, #1364 and #1366 edit other parts of `UploadPrepare`. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 9619edff: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 406/406 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 405/405 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - `agc_driver_graphics` (mock device, new `vkGetMemoryHostPointerPropertiesEXT` stub): a view across two imported ranges and one inside the second read their bytes in bounds; no BDA range runs past its buffer. Fails on `main`; with #1270 it fails at `exceeds its GPU owner`. - PPSA26344 v1.008: no "guest buffer view exceeds its GPU owner" skip in 3,600 s (13 in the 3,000 s run before). - Not tested: Linux (CI), console behaviour. ### 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
EdouardSence commented 2026-10-08 13:18:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-08T13:18:13Z.


Tested on AMD under Linux, since this PR wasn't: RX 9070 XT (RDNA4, GFX1201), RADV / Mesa 26.2.4, Linux 7.2.9 (CachyOS), GCC Release build.

  • ctest: this PR merged onto main 07c2405c, all 452 tests pass with ctest -j8 (main alone: 452/452 on the same machine).
  • Astro Bot (PPSA21567, retail): built as main + #759 (needed to boot this title on main) + this PR, then one scripted run headless from boot through the title screen. No error and no amdgpu fault came from this change.
    • Presents per 10 s on the title screen: 250, 215, 228; with main + #759 alone: 226, 229, 226.
    • The run then stops, with and without this PR, on storage image access to depth/stencil surface ... is not implemented (the gap #425 fills). So nothing past the title screen is covered.

AI-assisted: the runs and this write-up were done by Claude (Claude Code) on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060747418 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1489#issuecomment-6060747418). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-08T13:18:13Z. --- Tested on AMD under Linux, since this PR wasn't: RX 9070 XT (RDNA4, GFX1201), RADV / Mesa 26.2.4, Linux 7.2.9 (CachyOS), GCC Release build. - **`ctest`**: this PR merged onto `main` 07c2405c, all 452 tests pass with `ctest -j8` (main alone: 452/452 on the same machine). - **Astro Bot (PPSA21567, retail)**: built as `main` + #759 (needed to boot this title on `main`) + this PR, then one scripted run headless from boot through the title screen. No error and no amdgpu fault came from this change. - Presents per 10 s on the title screen: 250, 215, 228; with `main` + #759 alone: 226, 229, 226. - The run then stops, with and without this PR, on `storage image access to depth/stencil surface ... is not implemented` (the gap #425 fills). So nothing past the title screen is covered. AI-assisted: the runs and this write-up were done by Claude (Claude Code) on my machine.
fisherjoey commented 2026-10-09 01:25:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T01:25:24Z.


Tested with Stray (PPSA02100 v1.05, Unreal Engine 4). It hits this bug, and this PR fixes it.

Setup: Linux (Nobara 44, kernel 7.2), RTX 5070 Ti, NVIDIA 595.91.07. Base is main 1be6f9f1 + #861 + #1836 + #1837 + #1893 + #1902 + #1904 + #1928 + #1934.

Without this PR, Stray aborts about 3 minutes in:

[videoout] presentation failed: compute shader 0x2010bb0000: AGC graphics: guest buffer view exceeds its GPU owner

The compute shader's buffer V# covers 0x2020230000 + 0x7f800. The registered allocation there is 0x50000 bytes and host imported. UploadPrepare merges the two regions into 0x2020230000 to 0x20202b0000 but keeps direct on the 0x50000 import. Descriptor then checks the view against the import's end at 0x2020280000 and throws on the second check. With this PR merged, that error no longer occurs and the run goes on to an unrelated one (#1409).

I also wrote the same case as a test on a real device (NVIDIA, through the recorder test binary):

real-device test agc_driver_graphics (this PR's mock test)
main fails: guest buffer view exceeds its GPU owner fails, same message
this PR passes passes

I checked whether a merged region can also drop below its import's base. Regions are sorted by begin, and a merge where the import sits on the later region keeps only the earlier region's fields, so the end-side check covers it.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6072355505 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1489#issuecomment-6072355505). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-09T01:25:24Z. --- Tested with Stray (PPSA02100 v1.05, Unreal Engine 4). It hits this bug, and this PR fixes it. Setup: Linux (Nobara 44, kernel 7.2), RTX 5070 Ti, NVIDIA 595.91.07. Base is `main` 1be6f9f1 + #861 + #1836 + #1837 + #1893 + #1902 + #1904 + #1928 + #1934. Without this PR, Stray aborts about 3 minutes in: ``` [videoout] presentation failed: compute shader 0x2010bb0000: AGC graphics: guest buffer view exceeds its GPU owner ``` The compute shader's buffer V# covers 0x2020230000 + 0x7f800. The registered allocation there is 0x50000 bytes and host imported. `UploadPrepare` merges the two regions into 0x2020230000 to 0x20202b0000 but keeps `direct` on the 0x50000 import. `Descriptor` then checks the view against the import's end at 0x2020280000 and throws on the second check. With this PR merged, that error no longer occurs and the run goes on to an unrelated one (#1409). I also wrote the same case as a test on a real device (NVIDIA, through the recorder test binary): | | real-device test | `agc_driver_graphics` (this PR's mock test) | |---|---|---| | `main` | fails: `guest buffer view exceeds its GPU owner` | fails, same message | | this PR | passes | passes | I checked whether a merged region can also drop below its import's base. Regions are sorted by `begin`, and a merge where the import sits on the later region keeps only the earlier region's fields, so the end-side check covers it. AI-assisted: yes
oneandonlydean commented 2026-10-09 09:56:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:56:03Z.


Could you rebase onto current main? The full build checks out this branch with main's workflow, and it stops at tools/check_test_registration.py not being on the branch yet, so nothing gets compiled. After a rebase it can get a full build and go in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078615253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1489#issuecomment-6078615253). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:56:03Z. --- Could you rebase onto current main? The full build checks out this branch with main's workflow, and it stops at `tools/check_test_registration.py` not being on the branch yet, so nothing gets compiled. After a rebase it can get a full build and go in.
Celegans12 commented 2026-10-09 10:00:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-09T10:00:39Z.


Rebased onto current main (43972e69a1), so the branch has the registration check now. It was a clean rebase. I built it here, and check_test_registration.py and agc_driver_graphics both pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078681690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1489#issuecomment-6078681690). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-09T10:00:39Z. --- Rebased onto current main (43972e69a1), so the branch has the registration check now. It was a clean rebase. I built it here, and `check_test_registration.py` and `agc_driver_graphics` both pass.
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!1489
No description provided.