fix(agc): keep a context with no settle queue off the settle path #26652

Merged
Plyxen merged 1 commit from upstream-pr/26652 into main 2026-11-27 09:39:59 +00:00
Plyxen commented 2026-11-24 13:34:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-24T13:34:12Z.


What

On Windows importRunAt settled a private writable import at the import whenever the cached watch decision said private imports settle and the import was at or above the settle floor. It did not ask whether the context has a settle queue. settleImport starts by locking *context.settleQueueMutex, so a context without one threw std::system_error (EPERM) from the lock.

That context exists in the tests: a bare Device has no settle queue. It reached the settle path because decideImportWatch keeps its decision under the VkDevice handle and the decision outlives the device, so a bare device created at the handle of a destroyed driver device inherits "private imports settle". Since #10443 the floor is just over 64 KiB, and the 128 KiB import of agc_driver_native_multisample_depth takes that path whenever the AMD driver reuses the handle (#26649 has the logs).

settlesPrivateImports now asks the context for a settle queue and its mutex as well as the decision. It replaces state.watchPrivateImports at the two places that act on it for one import: the settle at the import (importWatching) and the queueing of a deferred settle. Such an import stays compared, which is what a context with no settle queue gets from a decision of its own. The deferred settle rounds and the dma-buf settle already made the same check.

agc_import_settle_deferred gains a case: it imports 128 KiB through a copy of its context with the settle queue cleared and requires a compared import and no settle.

The cached decision outliving its device is not changed here and is recorded in the debt fragment: resetting it in ClearHostImports would also drop a mode forced with SetImportWatch in tests that clear the imports afterwards.

Tested

Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release. The table was measured with main at e68be05111, before the rebase onto eb4300802c.

Radeon RTX 5080
agc_driver_native_multisample_depth, main fails 2 of 20 passes
agc_driver_native_multisample_depth, this PR passes 40 of 40 passes
new case on main (test only, no fix) fails 3 of 3, St12system_error fails 3 of 3, same
new case, this PR passes 3 of 3 passes 3 of 3
focused set, main 95 pass, 8 skip, 1 fail 95 pass, 8 skip, 1 fail
focused set, this PR 95 pass, 8 skip, 1 fail 95 pass, 8 skip, 1 fail
  • Focused set: ctest --test-dir build -R '^agc_.*(import|settle)|native_multisample_depth|native_depth|^windows_write_watch' -V -j 2 with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer, validation layer 1.4.363. Each of the four logs shows the loader inserting the layer 141 times, none has was not found but was requested, and none has a VUID- line.
  • After the rebase onto eb4300802c: agc_driver_native_multisample_depth passes 20 of 20 on the Radeon and 3 of 3 on the RTX 5080, the new case passes on both, and no log has a VUID- line. The focused set and the overlap check were not run again; the diff is the same.
  • The one failure is agc_driver_linear_target_import_creation, the same on main and here and on both GPUs (#26650). It passes with APS5_SETTLE_FLOOR_KIB=1024.
  • The 8 skips are the same tests in all four runs (two dma-buf import tests, agc_host_import_sparse, agc_host_import_retire_snapshot, the three agc_driver_msaa_dcc_compared_import tests and agc_driver_native_depth_driver_queued_fill).
  • python3 tools/check_conventions.py and python3 tools/debt_fold.py --check pass.
  • python3 tools/pr_overlap.py --names ClearHostImports decideImportWatch importWatching lists no export. --branch could not compare 46 pull requests that conflict with main. In their diffs only #22550 edits a line this PR edits (the settled condition in importWatching, where it adds a needsWatch term), and none adds the settle queue check.
  • Linux: Ubuntu 24.04.5 under WSL 2, GCC 13.3.0, Release, lavapipe (llvmpipe, LLVM 20.1.2), no validation layer (Ubuntu's is older than 1.4.335). main eb4300802c and this branch both build, and ctest -R '^agc_.*(import|settle)|native_multisample_depth|native_depth' gives the same result on both: 89 tests, 79 pass and the same 10 skip. The source change and the new case are inside #ifdef _WIN32, so this shows only that the branch builds there and changes nothing. Not built or run on macOS.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: Fixes #26649
  • Unblocks: none
  • GPUs tested: AMD Radeon gfx1036 iGPU 1002:13c0 (Adrenalin 26.11.2, Vulkan driver 2.0.353) and NVIDIA RTX 5080 (621.24), Windows 11; lavapipe (LLVM 20.1.2), Ubuntu 24.04.5 under WSL 2
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5473152826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26652). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-24T13:34:12Z. --- ### What On Windows `importRunAt` settled a private writable import at the import whenever the cached watch decision said private imports settle and the import was at or above the settle floor. It did not ask whether the context has a settle queue. `settleImport` starts by locking `*context.settleQueueMutex`, so a context without one threw `std::system_error` (`EPERM`) from the lock. That context exists in the tests: a bare `Device` has no settle queue. It reached the settle path because `decideImportWatch` keeps its decision under the `VkDevice` handle and the decision outlives the device, so a bare device created at the handle of a destroyed driver device inherits "private imports settle". Since #10443 the floor is just over 64 KiB, and the 128 KiB import of `agc_driver_native_multisample_depth` takes that path whenever the AMD driver reuses the handle (#26649 has the logs). `settlesPrivateImports` now asks the context for a settle queue and its mutex as well as the decision. It replaces `state.watchPrivateImports` at the two places that act on it for one import: the settle at the import (`importWatching`) and the queueing of a deferred settle. Such an import stays compared, which is what a context with no settle queue gets from a decision of its own. The deferred settle rounds and the dma-buf settle already made the same check. `agc_import_settle_deferred` gains a case: it imports 128 KiB through a copy of its context with the settle queue cleared and requires a compared import and no settle. The cached decision outliving its device is not changed here and is recorded in the debt fragment: resetting it in `ClearHostImports` would also drop a mode forced with `SetImportWatch` in tests that clear the imports afterwards. ### Tested <!-- 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. --> Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release. The table was measured with `main` at `e68be05111`, before the rebase onto `eb4300802c`. | | Radeon | RTX 5080 | |---|---|---| | `agc_driver_native_multisample_depth`, `main` | fails 2 of 20 | passes | | `agc_driver_native_multisample_depth`, this PR | passes 40 of 40 | passes | | new case on `main` (test only, no fix) | fails 3 of 3, `St12system_error` | fails 3 of 3, same | | new case, this PR | passes 3 of 3 | passes 3 of 3 | | focused set, `main` | 95 pass, 8 skip, 1 fail | 95 pass, 8 skip, 1 fail | | focused set, this PR | 95 pass, 8 skip, 1 fail | 95 pass, 8 skip, 1 fail | - Focused set: `ctest --test-dir build -R '^agc_.*(import|settle)|native_multisample_depth|native_depth|^windows_write_watch' -V -j 2` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer`, validation layer 1.4.363. Each of the four logs shows the loader inserting the layer 141 times, none has `was not found but was requested`, and none has a `VUID-` line. - After the rebase onto `eb4300802c`: `agc_driver_native_multisample_depth` passes 20 of 20 on the Radeon and 3 of 3 on the RTX 5080, the new case passes on both, and no log has a `VUID-` line. The focused set and the overlap check were not run again; the diff is the same. - The one failure is `agc_driver_linear_target_import_creation`, the same on `main` and here and on both GPUs (#26650). It passes with `APS5_SETTLE_FLOOR_KIB=1024`. - The 8 skips are the same tests in all four runs (two dma-buf import tests, `agc_host_import_sparse`, `agc_host_import_retire_snapshot`, the three `agc_driver_msaa_dcc_compared_import` tests and `agc_driver_native_depth_driver_queued_fill`). - `python3 tools/check_conventions.py` and `python3 tools/debt_fold.py --check` pass. - `python3 tools/pr_overlap.py --names ClearHostImports decideImportWatch importWatching` lists no export. `--branch` could not compare 46 pull requests that conflict with `main`. In their diffs only #22550 edits a line this PR edits (the `settled` condition in `importWatching`, where it adds a `needsWatch` term), and none adds the settle queue check. - Linux: Ubuntu 24.04.5 under WSL 2, GCC 13.3.0, Release, lavapipe (llvmpipe, LLVM 20.1.2), no validation layer (Ubuntu's is older than 1.4.335). `main` `eb4300802c` and this branch both build, and `ctest -R '^agc_.*(import|settle)|native_multisample_depth|native_depth'` gives the same result on both: 89 tests, 79 pass and the same 10 skip. The source change and the new case are inside `#ifdef _WIN32`, so this shows only that the branch builds there and changes nothing. Not built or run on macOS. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: Fixes #26649 - [x] Unblocks: none - [x] GPUs tested: AMD Radeon gfx1036 iGPU `1002:13c0` (Adrenalin 26.11.2, Vulkan driver 2.0.353) and NVIDIA RTX 5080 (621.24), Windows 11; lavapipe (LLVM 20.1.2), Ubuntu 24.04.5 under WSL 2 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mihiii1337 commented 2026-11-25 04:35:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-25T04:35:47Z.

Review: COMMENTED


Hardware coverage note only — no code verdict on exact head ccafed0d8f7d877e78d69def729ad38b8eb6adc8.

I built two isolated Windows 11 Release arms with WinLibs GCC 15.2/Ninja:

  • candidate: the exact PR head;
  • control: the same head and test sources, with only Graphics/src/GuestBufferMemory.cpp restored from parent eb4300802c52ef268e7e0c4038bd6f91ac4a2667.

On physical Intel RaptorLake-S Mobile/UHD (8086:a78b, Intel driver 32.0.101.6127), I ran agc_import_settle_deferred and agc_import_settle_deferred_other_family as three fresh serial CTest processes per test and arm (12 processes total). Every process selected the Intel device, inserted Khronos validation 1.4.369 at instance and device level, and had no missing-layer line, VUID or synchronization-hazard diagnostic.

All 12 were capability skips (SKIP_RETURN_CODE=77), not passes:

  • ordinary deferred settle, candidate and control 3/3 each: host imports within 64 KiB, a settle queue or write watching unavailable;
  • other-family case, candidate and control 3/3 each: no other queue family to settle imports on.

A separate pinned-ICD capability probe reported 4 KiB external-host-memory alignment and one combined graphics/compute/transfer queue family; the remaining families were video-decode only. Therefore neither arm reached the new queueless-settle assertion or production guard, and I did not run the optional repeated native-depth case. This Intel adapter cannot add a functional A/B verdict for this fix, but it identifies the exact third-vendor coverage limit.

The candidate and control source scope and all 47 dependency pins were rechecked after the runs. No console or title was exercised.

AI-assisted: yes (OpenAI Codex); exact source arms, isolated builds, artifact/source hashes, 12 fresh CTest/JUnit logs, GPU selection, driver/ICD capability, validation-layer insertion, skip markers and diagnostics were checked directly and independently reviewed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6051914819 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26652#pullrequestreview-6051914819). Originally posted by [mihiii1337](https://github.com/mihiii1337) on 2026-11-25T04:35:47Z. **Review:** COMMENTED --- Hardware coverage note only — no code verdict on exact head `ccafed0d8f7d877e78d69def729ad38b8eb6adc8`. I built two isolated Windows 11 Release arms with WinLibs GCC 15.2/Ninja: - candidate: the exact PR head; - control: the same head and test sources, with only `Graphics/src/GuestBufferMemory.cpp` restored from parent `eb4300802c52ef268e7e0c4038bd6f91ac4a2667`. On physical Intel RaptorLake-S Mobile/UHD (`8086:a78b`, Intel driver `32.0.101.6127`), I ran `agc_import_settle_deferred` and `agc_import_settle_deferred_other_family` as three fresh serial CTest processes per test and arm (12 processes total). Every process selected the Intel device, inserted Khronos validation 1.4.369 at instance and device level, and had no missing-layer line, VUID or synchronization-hazard diagnostic. All 12 were capability skips (`SKIP_RETURN_CODE=77`), not passes: - ordinary deferred settle, candidate and control 3/3 each: `host imports within 64 KiB, a settle queue or write watching unavailable`; - other-family case, candidate and control 3/3 each: `no other queue family to settle imports on`. A separate pinned-ICD capability probe reported 4 KiB external-host-memory alignment and one combined graphics/compute/transfer queue family; the remaining families were video-decode only. Therefore neither arm reached the new queueless-settle assertion or production guard, and I did not run the optional repeated native-depth case. This Intel adapter cannot add a functional A/B verdict for this fix, but it identifies the exact third-vendor coverage limit. The candidate and control source scope and all 47 dependency pins were rechecked after the runs. No console or title was exercised. AI-assisted: yes (OpenAI Codex); exact source arms, isolated builds, artifact/source hashes, 12 fresh CTest/JUnit logs, GPU selection, driver/ICD capability, validation-layer insertion, skip markers and diagnostics were checked directly and independently reviewed.
MarcZX10 commented 2026-11-25 05:09:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T05:09:46Z.

Review: APPROVED


Reviewed — looks good

Nothing in the inspected change shows a blocking defect; the new guard prevents private import settling when the context has no settle queue.

What I ran

Read the prepared diff and the changed source ranges at head ccafed0d8f7d877e78d69def729ad38b8eb6adc8 using repo_read.py tools. No tests or build commands were run during this review.

Results

Check Result Note
Diff and changed lines passed All three changed files read
Targeted source context passed Settle guard, import path and test context read
Tests run by reviewer not run Author-reported runs not repeated

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full 8,566-line GuestBufferMemory.cpp and 19,384-line Recorder.cpp were not read; only ranges relevant to the changed hunks were inspected. review/files.json was not available; the manifest identifies both source files as excluded from the prepared folder because they are too large, and the five-line debt fragment as included and read. Tests, build, CI results, and console behavior were not independently verified. Author-reported test results are in review/description.md.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6052157357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26652#pullrequestreview-6052157357). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T05:09:46Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the inspected change shows a blocking defect; the new guard prevents private import settling when the context has no settle queue. ## What I ran Read the prepared diff and the changed source ranges at head `ccafed0d8f7d877e78d69def729ad38b8eb6adc8` using `repo_read.py` tools. No tests or build commands were run during this review. ## Results | Check | Result | Note | |---|---|---| | Diff and changed lines | passed | All three changed files read | | Targeted source context | passed | Settle guard, import path and test context read | | Tests run by reviewer | not run | Author-reported runs not repeated | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full 8,566-line `GuestBufferMemory.cpp` and 19,384-line `Recorder.cpp` were not read; only ranges relevant to the changed hunks were inspected. `review/files.json` was not available; the manifest identifies both source files as excluded from the prepared folder because they are too large, and the five-line debt fragment as included and read. Tests, build, CI results, and console behavior were not independently verified. Author-reported test results are in `review/description.md`. ## To get this to a good state Nothing is required.
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!26652
No description provided.