Skip to content

fix(agc): stop the GPU progress watcher without destroying a condition variable - #16259

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Silverash-i8:fix/progress-watcher-teardown
Nov 7, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Silverash-i8:fix/progress-watcher-teardown

Conversation

@Silverash-i8

Copy link
Copy Markdown
Contributor

What

Recorder::ProgressWatcher stops its GPU wait thread with a std::condition_variable and a mutex that are destroyed together with the watcher. On Windows with winpthread, on an NVIDIA GPU, agc_driver_frame_replay_reservation_error never finishes: the replay tool prints its expected error, then the process stays alive with one thread inside ~Recorder until the ctest timeout. On main f7a91b6bc9 that happened 4 times out of 4 runs.

The watcher now wakes through a std::atomic<uint32_t> token (wait and notify_one) instead, so there is no condition variable to destroy. submitted and stop become atomics. The wait loop, the semaphore wait, the timeouts and the lifetime of the thread are the same. I did not find which exact winpthread path blocks, only that dropping the per-object condition variable removes the hang (below).

Tested

On main f7a91b6bc9, Windows 11 Home 26300, WinLibs GCC 15.2.0 r7, Release, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R agc_driver -V on both builds, same machine, same GPU selected with ANYPS5_GPU:

  • RTX 5060 Laptop (NVIDIA): main 27 of 29 pass. agc_driver_frame_replay_reservation_error times out and agc_driver_direct_write_completion fails. With this change 28 of 29 pass and only agc_driver_direct_write_completion fails (it fails on main too).
  • Intel Arrow Lake iGPU: main 27 of 29, with agc_driver_direct_write_completion and agc_driver_recorder failing. With this change the same two fail and the other 27 pass. Neither is touched by this change; I did not investigate them.
  • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS, and neither has a VUID- line, on both GPUs and both builds.
  • tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux, macOS, titles, a debug build. On Intel the hang does not show up on main either, so that run only shows nothing regressed.

Overlaps: #13863 and #13920 also edit the ProgressWatcher struct (a second watcher for a compute lane), so one of us will need a small rebase. #7464 and #11587 touch Recorder.cpp elsewhere.

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: none (fixes agc_driver_frame_replay_reservation_error hanging on NVIDIA Windows)
  • GPUs tested: AGC, shader recompiler and VideoOut: AGC tested on NVIDIA RTX 5060 Laptop and Intel Arrow Lake iGPU with validation layers; shader recompiler and VideoOut not touched
  • AI-assisted: yes (Claude Code); I ran the above on my machine.

https://claude.ai/code/session_012SLQbhAiexxW6TtjYToW8a

…n variable

The recorder's progress watcher stopped its thread with a std::condition_variable
it then destroyed together with the watcher. On Windows with winpthread, that
destruction blocks forever after the watcher thread was joined when the thread
was inside vkWaitSemaphores while the stop was signalled: the process stays alive
with one thread and never finishes ~Recorder. agc_driver_frame_replay_reservation_error
hit it every time on an NVIDIA GPU, because the replay tool prints its expected
error and then hangs at teardown until the test timeout.

The watcher now wakes through an atomic token (std::atomic::wait and notify_one),
which keeps no per-object synchronization primitive to destroy.

Claude-Session: https://claude.ai/code/session_012SLQbhAiexxW6TtjYToW8a
@github-actions github-actions Bot added the agc libSceAgc* label Nov 6, 2026
@oneandonlydean oneandonlydean self-assigned this Nov 6, 2026
@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head 9f1f068 merged onto main 82fcf46 · tested 2026-11-06 06:11 UTC · 20 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,904 passed · 4 failed (0 new, 3 also fail on main, 1 unstable on main) · 56 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,964 of 4,158 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 (979 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 120.1 s
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_pipeline_journal: failed in 1 of the last 10 main runs
Failing on main too (3, not counted against this PR)
agc_driver_image_table
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (9 IDs in 594 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (594 tests): agc_driver, agc_driver_address_draw_space_reuse, agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, and 586 more
VUID-VkShaderModuleCreateInfo-pCode-08737 (14 tests): agc_driver_dpp16_operands, agc_driver_dpp8_pk_fmac, agc_driver_dx10_clamp, agc_driver_f16_fma_denormal_modes, agc_driver_f16_fma_invalid_nan, agc_driver_float16_fma_rounding, agc_driver_float16_modifiers, agc_driver_float16_native, and 6 more
VUID-VkShaderModuleCreateInfo-pCode-08739 (14 tests): agc_driver_dpp16_operands, agc_driver_dpp8_pk_fmac, agc_driver_dx10_clamp, agc_driver_f16_fma_denormal_modes, agc_driver_f16_fma_invalid_nan, agc_driver_float16_fma_rounding, agc_driver_float16_modifiers, agc_driver_float16_native, and 6 more
VUID-VkShaderModuleCreateInfo-pCode-08741 (14 tests): agc_driver_dpp16_operands, agc_driver_dpp8_pk_fmac, agc_driver_dx10_clamp, agc_driver_f16_fma_denormal_modes, agc_driver_f16_fma_invalid_nan, agc_driver_float16_fma_rounding, agc_driver_float16_modifiers, agc_driver_float16_native, and 6 more
VUID-vkCmdCopyImage-srcImage-01548 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-vkCmdCopyImage-srcImage-01551 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
VUID-VkPipelineShaderStageCreateInfo-module-parameter (1 test): agc_driver_float16_unused_nan_payloads
VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849 (1 test): agc_driver_float16_unused_nan_payloads
Skipped (56)
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_gcn_display_present: skipped, no display: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
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_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_net_ctl_disconnected: 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_device_capability: 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_host_resolution_disabled: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_four_k: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_height_only: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_limit: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_malformed: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_width_only: 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_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_backtoback: 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_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 de
Reproduce
git fetch origin 9f1f068ebb2ee5e19b296b460e76636448f09959 82fcf46d250e0ec2f436ceffd607dd2ff04c62d7
git checkout 82fcf46d250e0ec2f436ceffd607dd2ff04c62d7 && git merge --no-ff 9f1f068ebb2ee5e19b296b460e76636448f09959
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.

@Superseabas

Copy link
Copy Markdown
Contributor

Windows run on an RTX 5070 Ti and an integrated Radeon. The hang doesn't reproduce on main here, so this checks the change for regressions and reads it, rather than confirming the fix.

Head 9f1f068ebb merged onto main ed41d86d32 (clean merge, local only). Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3, MinGW-w64 14.0.0), Release. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, ANYPS5_GPU selecting the device.

The hang. agc_driver_frame_replay_reservation_error, 5 runs each:

GPU main this PR
NVIDIA GeForce RTX 5070 Ti (10de:2c05), 621.01 5 of 5, 0.79-0.83 s 5 of 5, 0.80-0.83 s
AMD Radeon of a Ryzen 7 7700X (1002:164e), 26.10.2 5 of 5, 0.67-0.69 s 5 of 5, 0.67-0.68 s

It also passed on main in a parallel run of every agc test (-j 8). So it doesn't hang with this toolchain. Your runs used GCC 15.2.0 r7; I can't tell whether the toolchain is the difference. agc_driver_frame_replay_reservation_failure passes 5 of 5 on both trees and both GPUs.

Whole AGC set. ctest -R '^agc' -j 8 --timeout 300, 1,388 tests, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (no missing-layer line):

GPU main this PR
RTX 5070 Ti 1,386 pass 1,386 pass
Radeon iGPU 1,385 pass 1,385 pass

The failures are the same tests on both trees, all tracked: agc_driver_direct_write_completion (#15564), agc_driver_quad_pixel_mask on the RTX (#14341), and on the Radeon agc_driver_scratch_pool (#15566) and agc_driver_sample_order_grid_reference (#9503). No VUID- lines.

Reading. The watcher loads wakes before it checks stop and submitted, and both Submitted and the destructor store first, then bump wakes, then notify. A wake that lands between the checks and wakes.wait(token) changes the token, so the wait returns, and no wake is lost. submitted keeps the last stored serial, as the guarded assignment did.

check_conventions.py --base main passes.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor

Another Windows + NVIDIA data point: unlike the RTX 5070 Ti run above, the hang does reproduce here, and this PR fixes it.

  • Windows 11 Enterprise (build 26300), WinLibs GCC 15.2 (POSIX, UCRT), NVIDIA GeForce GT 1030, driver 582.78, Release, ANYPS5_REQUIRE_VULKAN=1
  • main at this PR's base f7a91b6bc9: agc_driver_frame_replay_reservation_error hits the 30 s ctest timeout in 3 of 3 runs
  • this PR at 9f1f068ebb: passes 3 of 3 (2.2 to 3.4 s)

Built agc_driver_frame_replay_tests agc_frame_replay libc, ran ctest -R '^agc_driver_frame_replay_reservation_error$' --output-on-failure.

AI-assisted: yes (Claude Code)

@github-actions

github-actions Bot commented Nov 7, 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 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7464 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7622 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9289 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 10249 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13793 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13809 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 15136 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 15548 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 15570 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp

@oneandonlydean
oneandonlydean merged commit e24325d into boykopovar:main Nov 7, 2026
13 checks passed
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