Skip to content

fix(agc): rewatch the ranges of compared host imports that ClearHostImports drops - #13013

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
SeaSunPT:fix/agc-rewatch-cleared-host-imports
Oct 30, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
SeaSunPT:fix/agc-rewatch-cleared-host-imports

Conversation

@SeaSunPT

Copy link
Copy Markdown
Contributor

What

Where host imports are compared rather than watched, creating an import takes its range off the write watch. On Windows that is every device without a second queue to settle imports on, such as the Intel UHD drivers in #12522, which log [write-watch] Windows direct host imports use comparisons (no second queue to settle imports on). On Linux it is the comparison mode the import probe chooses. Retiring an import (retireLeastRecent and the retire loop that also calls noteRetiredUnwatched) puts the range back through rewatchRetired. ClearHostImports, which VulkanDevice calls when a device is torn down, destroyed every import without doing that, so those ranges stayed unwatched: later CPU writes to them were not collected, and CollectWritesUncached over them returned 0.

ClearHostImports now notes the unwatched ranges of its imports with noteRetiredUnwatched before destroying them and calls rewatchRetired once the import map is empty, so the same rules apply as for a retired import: only ranges whose allocation still owns them are rewatched, and a range a live storage texture overlaps stays unwatched.

This fixes agc_driver_host_import_windows from #12522 (resident import collection failed). Its second pass collects the writes of memory the first pass imported and cleared. The other three failures in #12522 are not touched; the cause I found for agc_driver_msaa_dcc_clear_4 is in a comment on the issue.

Tested

Windows 11 Pro 26200, Intel Core i5-14600K, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on main 420b6a064e. After rebasing onto main 52f212ec05, agc_driver_host_import_windows was run again on both GPUs and passes, with 0 VUID- lines. Two GPUs in the same machine, chosen with ANYPS5_GPU: the CPU's integrated Intel UHD Graphics 770 (8086:a780, driver 32.0.101.6129, one queue, so imports are compared) and an NVIDIA GeForce RTX 5070 Ti (driver 610.88, which settles imports and keeps them watched). The validation layer is Khronos vulkan-sdk-1.4.363.0, built from source with the same GCC.

  • ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "^agc_driver_host_import_windows$" -V, 3 runs per GPU:
    • Intel UHD 770: fails on main with resident import collection failed; passes 3 of 3 with this change.
    • RTX 5070 Ti: passes 3 of 3 (it also passes on main, since its imports stay watched).
    • 0 VUID- lines and no was not found but was requested by env var VK_INSTANCE_LAYERS line in any log.
  • ctest -j 4 -R "^agc_" with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:
  • ctest -j 8 -E "^agc_": 1875 of 1876 pass; pe_import_first timed out once in that run and passes 3 of 3 alone, on main and on this branch.
  • No build warnings in GuestBufferMemory.cpp. python tools/check_conventions.py --base origin/main passes; git diff --check is clean.
  • python tools/pr_overlap.py --branch fix/agc-rewatch-cleared-host-imports: no overlap with the 49 comparable PRs. Of the 21 that conflict with main and share this file, only perf(agc): audit a cached template only after the host import set changed #9012 edits ClearHostImports, on its last line (++state.epoch), away from these lines.

No test catches this on a device that settles its imports: Windows always asks for a settle queue, and there is no switch to turn it off. On devices without one, agc_driver_host_import_windows is the regression test.

Not tested: Linux (the same code runs there in comparison mode), other Intel drivers, titles.

Checklist

🤖 Generated with Claude Code

…mports drops

Where host imports are compared rather than watched (Windows without a
second queue to settle them on, as Intel UHD drivers expose, and Linux
comparison mode), creating an import takes its range off the write
watch. Retiring an import puts the range back through
noteRetiredUnwatched and rewatchRetired, but ClearHostImports, which runs
when a Vulkan device is torn down, destroyed every import and left those
ranges unwatched, so later CPU writes to them were not collected.
ClearHostImports now notes the unwatched ranges of its imports and
rewatches them after the imports are gone, with the same checks
retirement uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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

The teardown path now re-watches still-owned ranges after clearing imports, and the reported Intel regression test plus the exact-head Windows CI pass support the fix.

What I ran

  • PR head: 6a84c011c4a8aeb0488a781671976f8705157fd4.
  • Base: upstream/main at d820fef1827f27247cd28da7b4eec7891904bae5; clean merge preview tree 689a18a135a92fa7a15db2e35c2eda834a9d3224.
  • Environment: Linux x86_64; no local build or GPU tests run.
git diff --check upstream/main...refs/review/pr-13013-head
git merge-tree --write-tree upstream/main refs/review/pr-13013-head
python tools/check_conventions.py --base upstream/main --head refs/review/pr-13013-head
git diff --name-only 52f212ec05...upstream/main -- core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp core/libs/prx/libSceAgcDriver/tests/execution/HostImportWindows.cpp

Results

Check Result
Patch whitespace Pass; command exited 0 with no output.
Current-main merge preview Pass; clean tree 689a18a135a92fa7a15db2e35c2eda834a9d3224.
Repository conventions Pass.
Current-base comparison No changes to the implementation or regression-test files since the author-reported base 52f212ec05.
Hosted CI Exact-head Windows product job, eligibility, conventions, intake, labels, and report checks passed. Linux and specialized jobs were skipped.
Focused GPU regression The PR reports agc_driver_host_import_windows failing on the Intel UHD 770 on main and passing 3/3 on this head; it passes on both main and this head on RTX 5070 Ti. The reports also show 0 VUIDs and a loaded validation layer. These runs are author-reported, not locally reproduced.
Unedited local command output

python tools/check_conventions.py --base upstream/main --head refs/review/pr-13013-head

All conventions checks passed.

git merge-tree --write-tree upstream/main refs/review/pr-13013-head

689a18a135a92fa7a15db2e35c2eda834a9d3224

git diff --check upstream/main...refs/review/pr-13013-head exited 0 and produced no output. The comparison of paths changed since 52f212ec05 also produced no output.

Negative control

Assertion Change under test Result
Clearing a comparison-mode import must restore watching so a subsequent collection sees resident writes. Author compared main with this fix on the Intel UHD 770. Author reports the test fails on main with resident import collection failed and passes 3/3 on this head. I did not run this control locally.

Not verified

  • I did not build or run GPU tests locally. Linux runtime behavior and other Intel drivers were not tested; the PR reports Linux as not tested.

@github-actions

github-actions Bot commented Oct 29, 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 2434 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 4449 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5372 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6185 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6481 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6548 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6918 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7457 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7514 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7844 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9012 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9898 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10026 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 12157 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@SeaSunPT thanks, the existing resident-import test does exercise the reported two-pass failure on a device using comparisons. One allocation-lifetime gap needs closing: the new lease at GuestBufferMemory.cpp:3729 is destroyed at the end of the if block, and state.imports.clear() at 3739 then releases the HostImport range pins before rewatchRetired uses the saved raw addresses. A concurrent allocation mutation can unmap/remap that address after the ownership check but before Rewatch; state.mutex serializes imports, not GuestAllocations mutations. Please retain the validated allocation lease through rewatchRetired (or revalidate under an equivalent lifetime guarantee), as the ordinary retirement path does with its caller-held lease. Moving the lease to function scope (for example a std::optional set inside the if) is enough; a deterministic test for the reuse window would be welcome if it is practical, but is not required for this fix. This is a source-derived race window; I have not reproduced a native crash. Please keep the current live-storage overlap exclusion and the existing two-pass Windows regression.

…mports

The lease that noteRetiredUnwatched checked the ranges against ended with
its block, before the imports were destroyed and rewatchRetired ran, so a
concurrent allocation mutation could unmap or remap a range between the
ownership check and the rewatch. The lease now lives until
ClearHostImports returns, as the caller-held lease does for retirement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SeaSunPT

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks, you're right: the lease ended with the if block, before state.imports.clear() and rewatchRetired. In f99b5496f7 the lease is declared at function scope (an empty GuestAllocations::Lease, assigned inside the if, the way ImportMappedRanges keeps current), so the ranges noteRetiredUnwatched validated stay owned through rewatchRetired. The live-storage overlap exclusion and the two-pass Windows regression are unchanged. I didn't add a deterministic test for the reuse window.

Rerun on this commit, same machine and setup as the description:

@adriadam10 adriadam10 self-assigned this Oct 30, 2026
@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head f99b549 merged onto main 02e8957 · tested 2026-10-30 01:54 UTC · 26 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,258 passed · 6 failed (0 new, 2 also fail on main, 4 unstable on main) · 41 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,305 of 2,949 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (861 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_bda_device 60.9 s
Intermittent validation messages (1, seen once in the parallel run, not reproduced when the test was re-run alone 2 times; not counted against this PR)
agc_driver_depth_clear_hle: VUID-vkCmdCopyBuffer-commonparent (6x)
Unstable on main (4, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_depth_clear_hle: failed in 1 of the last 7 main runs
agc_driver_submit_progress: failed in 5 of the last 7 main runs
agc_submit_progress: failed in 5 of the last 7 main runs
agc_submit_progress_no_timeline: failed in 6 of the last 7 main runs
Failing on main too (2, not counted against this PR)
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (4 IDs in 390 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (390 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alias_copy_label, agc_driver_array_layer_target_cpu, agc_driver_bda_span_reads_draw_pipeline, and 382 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (41)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_driver_vertex_elected_atomic_max: skipped, the device runs vertex programs in subgroups, so they keep their cross-lane reductions
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or plat
Reproduce
git fetch origin f99b5496f73369852453c6463f8388ddd911c8c2 02e89573e5b81146f173c5ef4f66950828686ae7
git checkout 02e89573e5b81146f173c5ef4f66950828686ae7 && git merge --no-ff f99b5496f73369852453c6463f8388ddd911c8c2
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@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.

Re-checked — new head, looks good

The allocation lease now remains alive until rewatchRetired finishes, closing the reviewed range-reuse window; exact-head GPU reports and current-main static checks show no blocking issue.

What I ran

Reviewed PR head f99b5496f73369852453c6463f8388ddd911c8c2, recorded PR base 52f212ec053f917455f2f87674ddb708dcc545d8, against current main 91a69952c10099966378a6a9006b8ef616ae22da. The merge preview is clean (tree 46d698eb2287a20ba13d022526096d2503f4d115). Environment: Linux x86_64, Git 2.39.5, Python 3.11.2; no compiler or project build was run.

git diff --check upstream/main...f99b5496f73369852453c6463f8388ddd911c8c2
python3 tools/check_conventions.py --base upstream/main --head f99b5496f73369852453c6463f8388ddd911c8c2
git merge-tree --write-tree upstream/main f99b5496f73369852453c6463f8388ddd911c8c2

Results

Check Result
Current-main merge preview Clean; tree 46d698eb2287a20ba13d022526096d2503f4d115.
git diff --check Passed; no output.
Conventions Passed.
Author-reported exact-head Windows GPU run agc_driver_host_import_windows: 3/3 on Intel UHD 770 and 3/3 on RTX 5070 Ti, with 0 VUID- lines.
Author-reported exact-head broader suites RTX 5070 Ti: 1,151/1,151 AGC tests passed. Intel UHD 770 had remaining failures reported as also failing on main. The non-AGC suite had one timeout that passed 3/3 when isolated on both main and the PR.
Latest external NVIDIA run Build passed; 2,258 tests passed, 6 baseline/unstable failures, 0 new failures, 41 skipped, and no new validation IDs. This run is a separate contributor report, not my local execution.
Hosted checks Windows, eligibility, conventions, labels, and report passed; Linux and specialized product jobs were skipped.
Unedited local command output
$ git diff --check upstream/main...f99b5496f73369852453c6463f8388ddd911c8c2
(no output; exit 0)

$ python3 tools/check_conventions.py --base upstream/main --head f99b5496f73369852453c6463f8388ddd911c8c2
All conventions checks passed.

$ git merge-tree --write-tree upstream/main f99b5496f73369852453c6463f8388ddd911c8c2
46d698eb2287a20ba13d022526096d2503f4d115

Negative control

The author reports agc_driver_host_import_windows fails on main with the Intel UHD 770 comparison-import path and passes 3/3 on the PR. The lease-reuse race itself has no deterministic negative-control test; the author notes that limitation, and I did not mutate the code to try to trigger it.

Findings

Blocking

None found in the reviewed head.

Non-blocking

The exact-head hardware runs are author-reported, not independently rerun here. The documented limitation remains that the regression test does not exercise this teardown path on devices using the settle-queue import mode.

Sources

Not verified

I did not build or run tests locally, test Linux/other Intel drivers, or test console behavior. I did not independently rerun the reported Windows or NVIDIA test matrices.

To get this to a good state

No further change is requested for this head. I will recheck the same commands and relevant tests if the PR head changes.

@github-actions github-actions Bot added the agc libSceAgc* label Oct 30, 2026
@adriadam10
adriadam10 merged commit 2e2d5da into boykopovar:main Oct 30, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the diff against noteRetiredUnwatched/rewatchRetired and the ordinary retire path: ClearHostImports now notes the unwatched ranges before destroying the imports and rewatches them once the map is empty, with the allocation lease held to function scope as @oneandonlydean asked (f99b5496f7). Windows job green on the head and the author's Intel UHD 770 / RTX 5070 Ti runs cover agc_driver_host_import_windows; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants