Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Plyxen:fix/agc-settle-without-settle-queue
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Plyxen:fix/agc-settle-without-settle-queue

Conversation

@Plyxen

@Plyxen Plyxen commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 (Windows: agc_driver_linear_target_import_creation fails every run since #10443 (private gate expects a 1 MiB settle floor) #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 fix(agc): settle small private color target imports #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 Windows AMD: agc_driver_native_multisample_depth fails about one run in five since #10443 (settleImport locks a null settle-queue mutex) #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

On Windows an import of private writable memory above the settle floor
called settleImport whenever the cached watch decision said private
imports settle, without looking at the context's own settle queue.
settleImport locks *context.settleQueueMutex, so a context with no
settle queue threw std::system_error (EPERM) from the lock.

The decision is cached under the VkDevice handle and outlives the
device. A bare test device created at the handle of a destroyed driver
device inherits "private imports settle" while having no settle queue.
Since the settle floor went from 1 MiB to just over 64 KiB, the 128 KiB
import of agc_driver_native_multisample_depth takes that path, and the
test failed whenever the AMD driver reused the handle.

Whether private imports settle now also asks the context for a settle
queue and its mutex, as the deferred settle and dma-buf settle paths
already do. Such an import stays compared and queues no deferred settle.

agc_import_settle_deferred imports 128 KiB through a copy of its
context without the settle queue and requires a compared import and no
settle. The cached decision outliving its device is recorded as debt.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added docs agc libSceAgc* fix error Closes an issue (Fixes #N) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 1395 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 5372 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5925 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6188 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6192 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6209 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6481 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7085 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 9712 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 9852 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 10442 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 10492 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10497 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 12157 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 12840 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 12944 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 13148 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 13251 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 14262 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 15136 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 15295 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 15296 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 15297 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 15570 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 15621 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 16831 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 16879 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 18173 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 18390 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 19697 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 20186 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 20315 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 20580 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 21238 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 21649 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 22190 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 22550 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 23058 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 25610 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp

@upipibi

upipibi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Correction: as @Plyxen points out below, agc_driver_recorder does not go through the changed path, so this run says nothing about this PR. A rerun with agc_import_settle_deferred, agc_import_settle_deferred_other_family and agc_driver_native_multisample_depth follows.

RTX 3070 run of `ccafed0d8f`, merged with `--no-ff` onto `main` `5e9ad5f57b`, against `main` alone.

**Tested**
- NVIDIA GeForce RTX 3070 (driver 616.56, subgroup 32), Windows 11 Pro 26100, WinLibs GCC 15.2.0, Ninja, Release; `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`.
- `ctest -R "^agc_driver_recorder$"`, 3 runs each:
  - `main`: 1/1 passed in all 3 runs.
  - this PR: 1/1 passed in all 3 runs.
- Validation layer inserted in every Vulkan test (1 per run on the PR side), 0 `VUID-` messages. Build: 0 failed targets.

**Not tested:** AMD, titles.

AI-assisted (Claude Code).

@JJenkx

JJenkx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Windows check on a discrete AMD GPU, next to the gfx1036 iGPU in #26649. The bug reproduces here too, more often, and this head fixes it.

Setup: Windows 11 Enterprise 22621, AMD Radeon RX 6700 XT (RDNA2, AMD proprietary driver 26.11.2), WinLibs GCC 15.2 UCRT r7, Release, built at this head ccafed0d8f. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, one ctest -R '^<test>$' -V per run, every run selecting the RX 6700 XT. The control is the same build with Graphics/src/GuestBufferMemory.cpp from the parent eb4300802c.

Test This head Control (parent GuestBufferMemory.cpp)
agc_driver_native_multisample_depth 20 of 20 passed 12 of 20 failed
agc_import_settle_deferred 3 of 3 passed 3 of 3 failed
agc_import_settle_deferred_other_family 3 of 3 passed 3 of 3 failed
agc_driver_recorder 3 of 3 passed 3 of 3 passed

All 12 multisample-depth failures and all 6 deferred-settle failures are the one in #26649, at the same offset:

FATAL: C++ exception St12system_error raised on thread N cannot be delivered: libSceAgcDriver.prx+0xd897e5 has no unwind data

So the handle reuse isn't limited to the iGPU: on this card the bare device inherits the decision in more than half of the runs. Your new case (d) catches it every time. (agc_driver_recorder itself doesn't run deferredSettleTests, which is why it passes on both sides.)

AI-assisted: yes.

@Plyxen

Plyxen commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both.

@JJenkx that answers something I could not: the handle reuse is not an iGPU effect, and at 12 of 20 on the RX 6700 XT it is more frequent than the 2 of 20 I saw. Good to see the new case fail on the parent in agc_import_settle_deferred_other_family as well; I had only run agc_import_settle_deferred.

@upipibi thanks for the RTX 3070 build and run. One note for anyone repeating it: agc_driver_recorder does not go through the changed path. The tests that do are agc_import_settle_deferred (and _other_family), which carry the new case, and agc_driver_native_multisample_depth, which is the one that failed. On my RTX 5080 the new case fails 3 of 3 on main and passes with this change, while the depth test passes either way, as the NVIDIA driver did not reuse the handle there.

AI-assisted: yes (Claude Code)

@zedekvdb

Copy link
Copy Markdown
Contributor

NVIDIA run on Windows, next to the AMD logs in #26649: nothing regresses, but I couldn't reproduce the failure on this GPU in a loop.

Setup: Windows 11 Pro 10.0.26300, NVIDIA Quadro P3200 (Pascal, 10de:1bbb), driver 582.42, Vulkan API 1.4.312, WinLibs GCC 15.2.0 r7, Release, main 7f99fbd60d. VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ANYPS5_GPU="Quadro P3200", ctest -j 1 -V. There are no VUID- messages.

main 7f99fbd60d This head (ccafed0d8f)
agc_driver_native_multisample_depth, alone in a loop 40 of 40 40 of 40
agc_import_settle_deferred, agc_driver_recorder pass

In a sweep of the 108 import, settle and write-watch tests on main, agc_driver_native_multisample_depth failed once and passed on --rerun-failed. That run wasn't verbose, so I don't have its message and can't say it was this EPERM. On this NVIDIA driver the handle reuse seems to be rare at most.

AI-assisted: yes (Claude Code)

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

The rerun with the tests that go through the changed path, as @Plyxen pointed out. RTX 3070 run of ccafed0d8f, merged with --no-ff onto main 45fc4e23bb, against main alone.

Tested

  • NVIDIA GeForce RTX 3070 (driver 616.56, subgroup 32), Windows 11 Pro 26100, WinLibs GCC 15.2.0, Ninja, Release; ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.
  • ctest -R "^agc_import_settle_deferred(_other_family)?$|^agc_driver_native_multisample_depth$", 3 runs each:
    • main: 3/3 passed in all 3 runs.
    • this PR: 3/3 passed in all 3 runs.
  • Validation layer inserted in every Vulkan test (7 per run on the PR side), 0 VUID- messages. Build: 0 failed targets.

The main side runs main's own agc_import_settle_deferred, without this PR's new case, so main passing here says nothing against @Plyxen's RTX 5080 result (the new case fails on main there). agc_driver_native_multisample_depth also passed 20 of 20 on main 6fde67a5eb here, matching that the NVIDIA driver does not reuse the handle.

Not tested: AMD, titles.

AI-assisted (Claude Code).

@mihiii1337 mihiii1337 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oneandonlydean
oneandonlydean merged commit a957ce8 into boykopovar:main Nov 27, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs fix error Closes an issue (Fixes #N)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows AMD: agc_driver_native_multisample_depth fails about one run in five since #10443 (settleImport locks a null settle-queue mutex)

7 participants