fix(agc): fall back when a shared import alias is refused #14976

Merged
liskeee merged 3 commits from upstream-pr/14976 into main 2026-11-04 08:32:45 +00:00
liskeee commented 2026-11-02 07:19:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by liskeee on 2026-11-02T07:19:54Z.


What

I make a refused single-range alias of shared guest memory record a failed host import and use the existing copied-buffer upload and write-back path. Previously, a resident direct-memory run extending outside the requested alias range could make dispatch preparation throw and abort the driver.

I add regressions for both overhanging edges, repeated refusal without a live import, successful retry with the complete range, and repeated compute dispatches with changed inputs, correct write-back and unchanged neighboring bytes. I document the remaining alias limitation and failure caching in technical debt.

Tested

I built and tested main (66e1f7f993), main with the regression tests only, and this change on the same Windows 11 machine with an NVIDIA GeForce RTX 4080, driver 610.88, using Ninja Release, MinGW GCC and BUILD_TESTING=ON.

I rebased this change onto main (4569fe654a) and re-tested it with the same result: 15 passed, 0 failed, 1 Windows skip, zero VUID- lines and zero missing-layer warnings. I keep the main baseline and main + regression tests results below as measured on 66e1f7f993.

I ran the same focused selection with validation enabled and the shader cache disabled:

$env:ANYPS5_REQUIRE_VULKAN='1'
$env:ANYPS5_NO_SHADER_CACHE='1'
$env:VK_INSTANCE_LAYERS='VK_LAYER_KHRONOS_validation'
ctest --test-dir build -R "^(agc_host_import.*|agc_driver_(partial_resident_alias|host_import_.*|alias_copy_label))$" -j 1 -V
Build Selected Passed Failed Skipped
Main 15 14 0 1
Main + regression tests only 16 12 3 1
Main + change 16 15 0 1

I reproduced the resident-run bounds refusal in agc_driver_host_import_failure_handles, agc_driver_partial_resident_alias and agc_host_import_retire on main with the regression tests; all three pass with the fix. I count skips separately: agc_host_import_sparse skips on Windows because udmabuf imports are Linux-only.

I checked all three logs: each contains zero VUID- lines and zero was not found but was requested by env var VK_INSTANCE_LAYERS warnings. I found no new validation errors compared with main.

I checked the committed change with python -B tools/check_conventions.py --base origin/main (all checks passed) and git diff --check origin/main..HEAD (passed). tools/pr_overlap.py --branch fix/agc-shared-import-alias-fallback finds one line conflict, with #10333 in docs/dev/debt/libSceAgcDriver.md. It could not compare 46 pull requests that conflict with main; I read the titles of those that touch GuestBufferMemory.cpp or the host-import tests, and none of them handles this refusal.

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
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4080 (driver 610.88), Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5116541979 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14976). Originally posted by [liskeee](https://github.com/liskeee) on 2026-11-02T07:19:54Z. --- ### What I make a refused single-range alias of shared guest memory record a failed host import and use the existing copied-buffer upload and write-back path. Previously, a resident direct-memory run extending outside the requested alias range could make dispatch preparation throw and abort the driver. I add regressions for both overhanging edges, repeated refusal without a live import, successful retry with the complete range, and repeated compute dispatches with changed inputs, correct write-back and unchanged neighboring bytes. I document the remaining alias limitation and failure caching in technical debt. ### Tested I built and tested main (`66e1f7f993`), main with the regression tests only, and this change on the same Windows 11 machine with an NVIDIA GeForce RTX 4080, driver 610.88, using Ninja Release, MinGW GCC and `BUILD_TESTING=ON`. I rebased this change onto main (`4569fe654a`) and re-tested it with the same result: 15 passed, 0 failed, 1 Windows skip, zero `VUID-` lines and zero missing-layer warnings. I keep the main baseline and main + regression tests results below as measured on `66e1f7f993`. I ran the same focused selection with validation enabled and the shader cache disabled: ```powershell $env:ANYPS5_REQUIRE_VULKAN='1' $env:ANYPS5_NO_SHADER_CACHE='1' $env:VK_INSTANCE_LAYERS='VK_LAYER_KHRONOS_validation' ctest --test-dir build -R "^(agc_host_import.*|agc_driver_(partial_resident_alias|host_import_.*|alias_copy_label))$" -j 1 -V ``` | Build | Selected | Passed | Failed | Skipped | |---|---:|---:|---:|---:| | Main | 15 | 14 | 0 | 1 | | Main + regression tests only | 16 | 12 | 3 | 1 | | Main + change | 16 | 15 | 0 | 1 | I reproduced the resident-run bounds refusal in `agc_driver_host_import_failure_handles`, `agc_driver_partial_resident_alias` and `agc_host_import_retire` on main with the regression tests; all three pass with the fix. I count skips separately: `agc_host_import_sparse` skips on Windows because udmabuf imports are Linux-only. I checked all three logs: each contains zero `VUID-` lines and zero `was not found but was requested by env var VK_INSTANCE_LAYERS` warnings. I found no new validation errors compared with main. I checked the committed change with `python -B tools/check_conventions.py --base origin/main` (all checks passed) and `git diff --check origin/main..HEAD` (passed). `tools/pr_overlap.py --branch fix/agc-shared-import-alias-fallback` finds one line conflict, with #10333 in `docs/dev/debt/libSceAgcDriver.md`. It could not compare 46 pull requests that conflict with main; I read the titles of those that touch `GuestBufferMemory.cpp` or the host-import tests, and none of them handles this refusal. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: NVIDIA GeForce RTX 4080 (driver 610.88), Windows 11 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-02 11:42:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T11:42:46Z.

Review: APPROVED


Looks right to me, and it reproduces on AMD too.

A refused single-range alias now records failedImport(), as the multi-range branch already did, so dispatch falls back to the copied-buffer upload and write-back instead of throwing out of preparation.

Tested on Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (driver 32.0.32015.7029), with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, at head 61002db367 (it currently conflicts with main in docs/dev/debt/libSceAgcDriver.md, so I tested the head itself):

  • With the change, every selected test I built passes, including agc_driver_host_import_failure_handles, agc_driver_partial_resident_alias and agc_host_import_retire. agc_host_import_sparse skips on Windows. The log has no VUID- or SYNC-HAZARD line.
  • With only that line put back to throw;, the same three tests fail. That matches your NVIDIA table.
  • agc_driver_alias_copy_label and agc_driver_host_import_at_map/proofs/teardown weren't built in my run, so I didn't check them.

Non-blocking: the catch takes any std::runtime_error from GuestArenaMapAlias_nid_postfix, not only the "resident run of direct memory extends outside the range" refusal. A different mapping failure would now be cached as a failed import and fall back silently rather than surface. The multi-range path already behaves that way, so it's consistent, but matching the refusal specifically (or noting it in the debt entry) would keep other failures visible. The debt conflict needs a rebase before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5736009508 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14976#pullrequestreview-5736009508). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T11:42:46Z. **Review:** APPROVED --- Looks right to me, and it reproduces on AMD too. A refused single-range alias now records `failedImport()`, as the multi-range branch already did, so dispatch falls back to the copied-buffer upload and write-back instead of throwing out of preparation. Tested on Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (driver 32.0.32015.7029), with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, at head `61002db367` (it currently conflicts with `main` in `docs/dev/debt/libSceAgcDriver.md`, so I tested the head itself): - With the change, every selected test I built passes, including `agc_driver_host_import_failure_handles`, `agc_driver_partial_resident_alias` and `agc_host_import_retire`. `agc_host_import_sparse` skips on Windows. The log has no `VUID-` or `SYNC-HAZARD` line. - With only that line put back to `throw;`, the same three tests fail. That matches your NVIDIA table. - `agc_driver_alias_copy_label` and `agc_driver_host_import_at_map/proofs/teardown` weren't built in my run, so I didn't check them. Non-blocking: the `catch` takes any `std::runtime_error` from `GuestArenaMapAlias_nid_postfix`, not only the "resident run of direct memory extends outside the range" refusal. A different mapping failure would now be cached as a failed import and fall back silently rather than surface. The multi-range path already behaves that way, so it's consistent, but matching the refusal specifically (or noting it in the debt entry) would keep other failures visible. The debt conflict needs a rebase before merge.
BunnyFl commented 2026-11-02 20:53:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T20:53:06Z.

Review: APPROVED


Thanks, this addresses it. At 395e976d78, boundsRefused is set only on the "resident run of direct memory extends outside the range" refusal in WindowsMappings::MapAlias, which happens in its first, read-only pass over the pages, before any mapping is changed. The single-range catch in GuestBufferMemory.cpp now falls back only when that flag is set and rethrows (throw;) otherwise, and the multi-range handling is unchanged.

Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto main, after rebuilding every executable behind these tests: all 9 agc_driver_host_import* tests pass, including the new agc_driver_host_import_alias_failure.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5743169740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14976#pullrequestreview-5743169740). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T20:53:06Z. **Review:** APPROVED --- Thanks, this addresses it. At `395e976d78`, `boundsRefused` is set only on the "resident run of direct memory extends outside the range" refusal in `WindowsMappings::MapAlias`, which happens in its first, read-only pass over the pages, before any mapping is changed. The single-range `catch` in `GuestBufferMemory.cpp` now falls back only when that flag is set and rethrows (`throw;`) otherwise, and the multi-range handling is unchanged. Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto `main`, after rebuilding every executable behind these tests: all 9 `agc_driver_host_import*` tests pass, including the new `agc_driver_host_import_alias_failure`.
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!14976
No description provided.