fix(agc): check registered image views in one registry lookup #15971

Merged
ItsJustChrisE merged 1 commit from upstream-pr/15971 into main 2026-11-05 23:14:01 +00:00
ItsJustChrisE commented 2026-11-05 04:20:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ItsJustChrisE on 2026-11-05T04:20:34Z.


What

registeredImageViewsCurrent (ShaderResources.cpp) and CaptureRegisteredViewsCurrent (DispatchCache.hpp, also used by ShaderMemory::snapshotCurrent) looked each registered image view up one at a time. They accepted the result only if the global GuestAllocationsGeneration counter didn't move during the pass, with two attempts. Every mutation of any guest allocation, on any thread, bumps that counter. So a title that maps and unmaps memory continuously fails the check even when none of the views changed. buildComplete then throws registered image range changed after resource preparation, which aborts the title.

Street Fighter 6 (PPSA02632) hits this about a minute after start-up, while its eight ResourceManager::parallelProc threads stream data. A temporary probe showed that the single view matched its captured range on every pass while the counter moved 35–58 times per pass, until both attempts were used up.

The fix adds GuestAllocationsLookupEach_nid_postfix to libc. It looks up a list of addresses while holding the registry lock once, using the same rule as GuestAllocationsLookup without next. Both helpers now compare all views against that one snapshot, so they no longer depend on the counter. A real change is still detected: a view's range removed, remapped with a new backing serial, or changed in extent or protection. The two helpers stay separate copies, as before.

New test agc_shader_registered_view_churn (agc_shader_memory_tests --registered-view-churn): one thread maps and unmaps an unrelated range nonstop while the main thread checks three views of one registered range 20,000 times. Every check must accept. The test then removes the range, maps it again, and checks views with the old and the new backing serial.

Tested

Windows 11 Pro 10.0.26300, Ryzen 7 7700X, NVIDIA GeForce RTX 3080 (driver 610.88), WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, ANYPS5_AGC_EXECUTION_TESTS=ImageArrayRowsPastLayerLimit;ImageTableCache;ImageTable;GuardedNullPointer.

Focused tests on main 8bfe082f60 with only the new test added, and on this change on the same base, each run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_GPU="RTX 3080" (Vulkan SDK 1.4.363.1):

Test main + test change
agc_shader_registered_view_churn Failed: 147 of 20000 checks rejected unchanged views Passed
agc_shader_memory Passed Passed
agc_shader_nested_snapshot_retry Passed Passed
agc_shader_table_snapshot_reuse Passed Passed
agc_shader_table_snapshot_reuse_unmasked Passed Passed
agc_driver_image_array_rows_past_layer_limit Passed Passed
agc_driver_image_table Passed Passed
agc_driver_image_table_cache Passed Passed
agc_driver_guarded_null_pointer Passed Passed

With VK_LOADER_DEBUG=all the loader reported Insert instance layer "VK_LAYER_KHRONOS_validation". Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS (the runs used VK_LOADER_DEBUG=error, so the loader would have printed it), and neither log contains a VUID- line or a Validation Error/Warning line. After rebasing onto 4639eff7f4, agc_shader_registered_view_churn, agc_shader_memory and agc_driver_image_array_rows_past_layer_limit were rebuilt and passed again with validation, with no VUID- lines.

Street Fighter 6 (PPSA02632, 01.000.000) on Windows, with #15945 for its Party.prx. Cross was sent through APS5_PAD_INPUT_FILE every 15 s after the first minute, same machine and GPU, warm shader cache:

  • main acac7c8541 + #15945, with a logging-only probe in registeredImageViewsCurrent: aborted after 66 s with registered image range changed after resource preparation (0xc0000409). An earlier manual run of the same build without the probe aborted the same way after the Capcom logo.
  • This change on 8bfe082f60, with Party.prx from #15945: ran for the full 480 s cap with no abort and no not implemented line, ending at about 93 presents per 10 s.

tools/check_conventions.py --base origin/main passed. tools/pr_overlap.py lists 12 open PRs that share these files. I checked their diffs: none changes either helper or adds a batch lookup. #13809, #13928 and #13929 read GuestAllocationsGeneration only for their own cache stamps.

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: PPSA02632 https://github.com/boykopovar/AnyPS5/discussions/8229 (together with #15945)
  • GPUs tested: NVIDIA GeForce RTX 3080, driver 610.88, Windows 11 Pro 10.0.26300
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5166075480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15971). Originally posted by [ItsJustChrisE](https://github.com/ItsJustChrisE) on 2026-11-05T04:20:34Z. --- ### What `registeredImageViewsCurrent` (ShaderResources.cpp) and `CaptureRegisteredViewsCurrent` (DispatchCache.hpp, also used by `ShaderMemory::snapshotCurrent`) looked each registered image view up one at a time. They accepted the result only if the global `GuestAllocationsGeneration` counter didn't move during the pass, with two attempts. Every mutation of any guest allocation, on any thread, bumps that counter. So a title that maps and unmaps memory continuously fails the check even when none of the views changed. `buildComplete` then throws `registered image range changed after resource preparation`, which aborts the title. Street Fighter 6 (PPSA02632) hits this about a minute after start-up, while its eight `ResourceManager::parallelProc` threads stream data. A temporary probe showed that the single view matched its captured range on every pass while the counter moved 35–58 times per pass, until both attempts were used up. The fix adds `GuestAllocationsLookupEach_nid_postfix` to libc. It looks up a list of addresses while holding the registry lock once, using the same rule as `GuestAllocationsLookup` without `next`. Both helpers now compare all views against that one snapshot, so they no longer depend on the counter. A real change is still detected: a view's range removed, remapped with a new backing serial, or changed in extent or protection. The two helpers stay separate copies, as before. New test `agc_shader_registered_view_churn` (`agc_shader_memory_tests --registered-view-churn`): one thread maps and unmaps an unrelated range nonstop while the main thread checks three views of one registered range 20,000 times. Every check must accept. The test then removes the range, maps it again, and checks views with the old and the new backing serial. ### Tested Windows 11 Pro 10.0.26300, Ryzen 7 7700X, NVIDIA GeForce RTX 3080 (driver 610.88), WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, `ANYPS5_AGC_EXECUTION_TESTS=ImageArrayRowsPastLayerLimit;ImageTableCache;ImageTable;GuardedNullPointer`. Focused tests on `main` 8bfe082f60 with only the new test added, and on this change on the same base, each run with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_GPU="RTX 3080"` (Vulkan SDK 1.4.363.1): | Test | main + test | change | |---|---|---| | `agc_shader_registered_view_churn` | **Failed**: 147 of 20000 checks rejected unchanged views | Passed | | `agc_shader_memory` | Passed | Passed | | `agc_shader_nested_snapshot_retry` | Passed | Passed | | `agc_shader_table_snapshot_reuse` | Passed | Passed | | `agc_shader_table_snapshot_reuse_unmasked` | Passed | Passed | | `agc_driver_image_array_rows_past_layer_limit` | Passed | Passed | | `agc_driver_image_table` | Passed | Passed | | `agc_driver_image_table_cache` | Passed | Passed | | `agc_driver_guarded_null_pointer` | Passed | Passed | With `VK_LOADER_DEBUG=all` the loader reported `Insert instance layer "VK_LAYER_KHRONOS_validation"`. Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS` (the runs used `VK_LOADER_DEBUG=error`, so the loader would have printed it), and neither log contains a `VUID-` line or a `Validation Error/Warning` line. After rebasing onto 4639eff7f4, `agc_shader_registered_view_churn`, `agc_shader_memory` and `agc_driver_image_array_rows_past_layer_limit` were rebuilt and passed again with validation, with no `VUID-` lines. Street Fighter 6 (PPSA02632, 01.000.000) on Windows, with #15945 for its `Party.prx`. Cross was sent through `APS5_PAD_INPUT_FILE` every 15 s after the first minute, same machine and GPU, warm shader cache: - `main` acac7c8541 + #15945, with a logging-only probe in `registeredImageViewsCurrent`: aborted after 66 s with `registered image range changed after resource preparation` (`0xc0000409`). An earlier manual run of the same build without the probe aborted the same way after the Capcom logo. - This change on 8bfe082f60, with `Party.prx` from #15945: ran for the full 480 s cap with no abort and no `not implemented` line, ending at about 93 presents per 10 s. `tools/check_conventions.py --base origin/main` passed. `tools/pr_overlap.py` lists 12 open PRs that share these files. I checked their diffs: none changes either helper or adds a batch lookup. #13809, #13928 and #13929 read `GuestAllocationsGeneration` only for their own cache stamps. ### 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 - [x] Fixes: none - [x] Unblocks: PPSA02632 https://github.com/boykopovar/AnyPS5/discussions/8229 (together with #15945) - [x] GPUs tested: NVIDIA GeForce RTX 3080, driver 610.88, Windows 11 Pro 10.0.26300 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-05 15:13:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-05T15:13:41Z.

Review: APPROVED


@ItsJustChrisE looks right. Looking every view up under one hold of the registry lock gives the same consistent snapshot the generation check was after, without depending on unrelated mappings. The field comparison that catches a real change is unchanged, and so are the reads of the returned ranges after the lock is released. I see no new lock ordering: GuestAllocationsLookupEach_nid_postfix takes the same registry mutex GuestAllocationsLookup_nid_postfix took.

What I ran

Head 5f67111fe4 merged onto main 78e4248fea (clean merge), Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (AMD Software 26.10.2, driver 32.0.32015.12012). Your nine tests, ctest -V with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, test executables rebuilt:

this PR main's DispatchCache.hpp and ShaderResources.cpp, with your test
agc_shader_registered_view_churn passed failed: 80 of 20000 checks rejected unchanged views
the other seven passed passed
agc_driver_image_array_rows_past_layer_limit skipped: the device allows every array a T# can describe skipped, the same
missing-layer lines, VUID- none none

check_conventions.py passes. pr_overlap.py --branch finds no PR it could compare; the 60 that share these files conflict with main.

Non-blocking: both helpers now allocate two vectors per check. If that ever shows up in a dispatch-heavy trace, a small fixed buffer for the common one-to-three-view case would avoid it; I haven't measured it.

Approving.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5787242616 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15971#pullrequestreview-5787242616). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-05T15:13:41Z. **Review:** APPROVED --- @ItsJustChrisE looks right. Looking every view up under one hold of the registry lock gives the same consistent snapshot the generation check was after, without depending on unrelated mappings. The field comparison that catches a real change is unchanged, and so are the reads of the returned ranges after the lock is released. I see no new lock ordering: `GuestAllocationsLookupEach_nid_postfix` takes the same registry mutex `GuestAllocationsLookup_nid_postfix` took. ## What I ran Head `5f67111fe4` merged onto `main` `78e4248fea` (clean merge), Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (AMD Software 26.10.2, driver 32.0.32015.12012). Your nine tests, `ctest -V` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, test executables rebuilt: | | this PR | `main`'s `DispatchCache.hpp` and `ShaderResources.cpp`, with your test | |---|---|---| | `agc_shader_registered_view_churn` | passed | **failed**: 80 of 20000 checks rejected unchanged views | | the other seven | passed | passed | | `agc_driver_image_array_rows_past_layer_limit` | skipped: the device allows every array a T# can describe | skipped, the same | | missing-layer lines, `VUID-` | none | none | `check_conventions.py` passes. `pr_overlap.py --branch` finds no PR it could compare; the 60 that share these files conflict with `main`. Non-blocking: both helpers now allocate two vectors per check. If that ever shows up in a dispatch-heavy trace, a small fixed buffer for the common one-to-three-view case would avoid it; I haven't measured it. Approving. AI-assisted: yes (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!15971
No description provided.