fix(agc): relaunch the frame replay when a host region blocks a captured GPU range #12696

Merged
chitters2004 merged 22 commits from upstream-pr/12696 into main 2026-11-05 23:14:26 +00:00
chitters2004 commented 2026-10-29 02:50:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-10-29T02:50:09Z.


What

Review only df74f29c46, 89db2b5ae2, 93123ef32c and 9a2b40f233. The rest is #11436 (at 752958c135), merged in because it lands first, as agreed with Sam-mon7. Whichever of the two lands first, the other needs a merge of main.

On Windows, agc_frame_replay fails about 1 run in 30 at startup with fixed guest mapping 0x2324a0000+0x133d80000 overlaps a host region in the guest arena. #3371 diagnosed the cause: the main thread's stack and the loader's thread stacks exist before libc reserves the guest arena, and with HIGH_ENTROPY_VA Windows places them anywhere in the first TiB, so the arena keeps them as host holes. A title can avoid them. #3683 moved the AMM ranges to the highest free window for that reason. A replay can't, because it has to map each captured range at its captured address. A host hole inside a GPU-visible range is fatal, while other ranges are skipped.

  • After the capture's index is read and before any memory is mapped, relaunchIfHostRegionBlocks checks the GPU-visible captured ranges with GuestArenaHostRegionOverlaps_nid_postfix. If one overlaps a host region, the replay prints the range, starts its own command line again (the new process gets a fresh ASLR layout), waits for it and exits with its exit code. APS5_FRAME_REPLAY_ATTEMPT counts the attempts; after 8 the replay continues as it does today and reports the overlap. The count must be a whole number from 0 to 8, otherwise the replay stops with an error, and a relaunch stops if the count cannot be passed to the next process.
  • #11435, #11436, #12567 and #12568 also insert code just above run(), and the logic doesn't overlap. This branch now includes #11436, with that conflict resolved by keeping both insertions.
  • 93123ef32c is part of this PR: SKIP_RETURN_CODE 77 on agc_driver_frame_replay, _cold_pipelines, _reservation_error and _concurrent, so they skip on a runner with no Vulkan driver.
  • Windows only. Linux keeps its mappings near 0x7f…, and #3371 saw no collisions there.
  • Turning off HIGH_ENTROPY_VA for the replay, as #679 did for relinked titles, doesn't help: it moves the stacks to about 0x5ff000-0x1c6f000, inside the title image range at 0x400000 (#9332) that every capture maps. That range is not GPU-visible, so the replay then skipped 51.7 MiB of it on every run, where it normally skips none.

Tested

Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0, Release, RTX 3080, GTA V (PPSA04263) frame capture.

  • Without this change: 1 of 30 warm replays failed at startup with the message above.
  • With it: 30 of 30 replays finished, skipped_mib 0.0, exit 0. Run 16 hit the same range, 0x2324a0000+0x133d80000, relaunched once and finished normally.
  • Forced collision: with the GPU-visible condition removed and the replay linked with --disable-high-entropy-va, every attempt overlaps the 0x400000 range. It relaunched 8 times, then continued down the normal path and exited 0. All 9 processes wrote to the same redirected log, and none was left running.
  • python3 tools/check_conventions.py --base origin/main passes.
  • Paired run with #11436 merged in, same machine and GPU, full builds with submodules synced, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R '^agc_(frame_capture|driver_frame_capture_eop|driver_frame_replay)' -V: main at 466bf10f7f: 11 tests, all passed, 0 VUID- lines; this branch at 501b4fdf2d merged into it (e022558084): 18 tests, all passed, 0 VUID- lines. Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
  • Exact head 4c144e8108 (merged with main 5bae1a4bc2), RTX 3080, with the command above: 19 of 19 tests passed, 0 VUID- lines, no missing-layer message. Without the layer, 18 of 19: agc_driver_frame_replay_reservation_error times out, which is the Windows exit hang #14100 fixes.
  • New Windows test agc_driver_frame_replay_relaunch: linked with --disable-high-entropy-va, so its stack is an arena host region in every process. It relaunches eight times and then continues, with the count seen by each process checked; passes a failing exit code (42) back through all nine processes; relaunches once from 7 and not at all from 8; and exits 2 without relaunching for -1, -2147483648, 9, 99999999999, abc, 1x, 1 and +1. It passed 5 of 5 runs. Negative control: with the old atoi line restored it fails with -1: exited with 0. It skips with 77 if the stack is not a host region. A failed _putenv_s is not covered.
  • Four tests from 93123ef32c: on the previous head f2ba0a7c78, with the RTX 3080 they ran and passed; with VK_DRIVER_FILES and VK_ICD_FILENAMES pointing at a missing file, all four reported Skipped. That no-Vulkan run was not repeated on 9a2b40f233 or 4c144e8108, which do not touch them.
  • Not tested: Linux and macOS (the change is under _WIN32).

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: #11436 (merge order agreed: #11436 lands first)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080, driver 621.01, Windows 11 Pro 26220
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5061243678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12696). Originally posted by [chitters2004](https://github.com/chitters2004) on 2026-10-29T02:50:09Z. --- ### What **Review only [`df74f29c46`](https://github.com/boykopovar/AnyPS5/pull/12696/commits/df74f29c46), [`89db2b5ae2`](https://github.com/boykopovar/AnyPS5/pull/12696/commits/89db2b5ae2), [`93123ef32c`](https://github.com/boykopovar/AnyPS5/pull/12696/commits/93123ef32c) and [`9a2b40f233`](https://github.com/boykopovar/AnyPS5/pull/12696/commits/9a2b40f233).** The rest is #11436 (at `752958c135`), merged in because it lands first, as agreed with Sam-mon7. Whichever of the two lands first, the other needs a merge of `main`. On Windows, `agc_frame_replay` fails about 1 run in 30 at startup with `fixed guest mapping 0x2324a0000+0x133d80000 overlaps a host region in the guest arena`. #3371 diagnosed the cause: the main thread's stack and the loader's thread stacks exist before libc reserves the guest arena, and with `HIGH_ENTROPY_VA` Windows places them anywhere in the first TiB, so the arena keeps them as host holes. A title can avoid them. #3683 moved the AMM ranges to the highest free window for that reason. A replay can't, because it has to map each captured range at its captured address. A host hole inside a GPU-visible range is fatal, while other ranges are skipped. - After the capture's index is read and before any memory is mapped, `relaunchIfHostRegionBlocks` checks the GPU-visible captured ranges with `GuestArenaHostRegionOverlaps_nid_postfix`. If one overlaps a host region, the replay prints the range, starts its own command line again (the new process gets a fresh ASLR layout), waits for it and exits with its exit code. `APS5_FRAME_REPLAY_ATTEMPT` counts the attempts; after 8 the replay continues as it does today and reports the overlap. The count must be a whole number from 0 to 8, otherwise the replay stops with an error, and a relaunch stops if the count cannot be passed to the next process. - #11435, #11436, #12567 and #12568 also insert code just above `run()`, and the logic doesn't overlap. This branch now includes #11436, with that conflict resolved by keeping both insertions. - `93123ef32c` is part of this PR: `SKIP_RETURN_CODE 77` on `agc_driver_frame_replay`, `_cold_pipelines`, `_reservation_error` and `_concurrent`, so they skip on a runner with no Vulkan driver. - Windows only. Linux keeps its mappings near `0x7f…`, and #3371 saw no collisions there. - Turning off `HIGH_ENTROPY_VA` for the replay, as #679 did for relinked titles, doesn't help: it moves the stacks to about 0x5ff000-0x1c6f000, inside the title image range at 0x400000 (#9332) that every capture maps. That range is not GPU-visible, so the replay then skipped 51.7 MiB of it on every run, where it normally skips none. ### Tested Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0, Release, RTX 3080, GTA V (PPSA04263) frame capture. - Without this change: 1 of 30 warm replays failed at startup with the message above. - With it: 30 of 30 replays finished, `skipped_mib` 0.0, exit 0. Run 16 hit the same range, 0x2324a0000+0x133d80000, relaunched once and finished normally. - Forced collision: with the GPU-visible condition removed and the replay linked with `--disable-high-entropy-va`, every attempt overlaps the 0x400000 range. It relaunched 8 times, then continued down the normal path and exited 0. All 9 processes wrote to the same redirected log, and none was left running. - `python3 tools/check_conventions.py --base origin/main` passes. - Paired run with #11436 merged in, same machine and GPU, full builds with submodules synced, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R '^agc_(frame_capture|driver_frame_capture_eop|driver_frame_replay)' -V`: `main` at `466bf10f7f`: 11 tests, all passed, 0 `VUID-` lines; this branch at `501b4fdf2d` merged into it (`e022558084`): 18 tests, all passed, 0 `VUID-` lines. Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`. - Exact head `4c144e8108` (merged with `main` `5bae1a4bc2`), RTX 3080, with the command above: 19 of 19 tests passed, 0 `VUID-` lines, no missing-layer message. Without the layer, 18 of 19: `agc_driver_frame_replay_reservation_error` times out, which is the Windows exit hang #14100 fixes. - New Windows test `agc_driver_frame_replay_relaunch`: linked with `--disable-high-entropy-va`, so its stack is an arena host region in every process. It relaunches eight times and then continues, with the count seen by each process checked; passes a failing exit code (42) back through all nine processes; relaunches once from 7 and not at all from 8; and exits 2 without relaunching for `-1`, `-2147483648`, `9`, `99999999999`, `abc`, `1x`, ` 1` and `+1`. It passed 5 of 5 runs. Negative control: with the old `atoi` line restored it fails with `-1: exited with 0`. It skips with 77 if the stack is not a host region. A failed `_putenv_s` is not covered. - Four tests from `93123ef32c`: on the previous head `f2ba0a7c78`, with the RTX 3080 they ran and passed; with `VK_DRIVER_FILES` and `VK_ICD_FILENAMES` pointing at a missing file, all four reported `Skipped`. That no-Vulkan run was not repeated on `9a2b40f233` or `4c144e8108`, which do not touch them. - Not tested: Linux and macOS (the change is under `_WIN32`). ### 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: #11436 (merge order agreed: #11436 lands first) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3080, driver 621.01, Windows 11 Pro 26220 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/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!12696
No description provided.