test(agc): hold the idle-yield fixture's queue until it takes the GPU mutex #14066
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14066"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-31T17:31:09Z.
What
A test-only fix for
agc_driver_idle_store_yields(tests/execution/IdleStoreYields.cpp), the test @beardsciences added in #13621. It fails intermittently on main. As @MarcZX10 asked on #13621, this is a separate PR, with the reproduction details and results below.The test races the queue twice. Waiting for the driver to go idle, the first approach linked on #13621, fixes the first race but exposes the second. This PR's single commit fixes both.
Race 1: the check runs before the second dispatch is recorded (lines at main
73f4f7e06e):StopsWithinAnImagesubmits one packet with two dispatches over the same 8 MiB surface:StoreRowZeroCodewrites row 0, in the first 4 MiB piece;StoreFarRowCodewrites row 1000, in the second piece.SubmitAndWaitForPending(IdleStoreYields.cpp:110-117) returned 5 ms afterStorageTexture::AnyPending()turned true. That happens once the row-0 dispatch is recorded.Driver::dispatchbuilds its pipeline (PrepareDispatch,Dispatch.cpp:586) before it takes the GPU mutex (:608). Without a warm pipeline cache, that build takes longer than 5 ms.Contains(split, end)(:172) can read guest memory before that row lands.StopsBetweenImageshas already prepared row 0's shader, so as the second dispatch it's quick.Race 2: the queue's own idle store takes the GPU mutex first. The first approach, 3a3ec595b6 (the commit linked on #13621), waits with
AgcDriverWaitIdle_nid_postfix(). On GitHub's Linux runner that exposed a second race:QueueWorker.cpp:282,:293). After plain dispatches nothing else is pending, so its 50 msIdleResultsQuietPeriod(QueueWorker.cpp:20,:203-216) starts at once, at the pointWaitIdle's drain returns.Driver::WaitIdle(Lifecycle.cpp:237-250) then takes the GPU mutex and callsVulkanDevice::WaitIdle, whoseRecorder::Syncsubmits the packet's open batch and waits for the device to run it. Timed on lavapipe with the shader cache off and the CPU loaded, that took 12.4–168.2 ms (median 47.5).StoreDrawnLinearstored nothing, andvkDeviceWaitIdletook at most 4.6 ms.StoreIdleResults(QueueWorker.cpp:219) and waits on the mutex. WhenWaitIdlereleases it, the idle store can win and store both images, and the test fails with "the queue-idle store ran before the fixture could take the GPU mutex".WaitIdlereturned 52.5 ms or more after it.The change: the packet now ends with a
WAIT_REG_MEMon a label in the test, the same packetFlip.cpp:242,Submit.cpp:323andWaitShutdown.cpp:40use.SubmitAndWaitForPendingbecomesSubmitAndWaitHeld. It pollsAgcDriverAwaitedWaits_nid_postfixuntil the queue waits on that label. The queue gets there only after recording both dispatches, which fixes race 1.~QueueHoldalso stores the label, so a failed check never leaves the queue blocked. The labels are static, so they outlive the queue's last read.archive/agc-idle-store-yields-two-commitsbranch.Related: #13621
Tested
Linux, on a 4-vCPU Xeon (Ubuntu 24.04, GCC 13.3, Release, CI flags, lavapipe, as an unprivileged user,
ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx). Each cell is 30 direct runs ofagc_driver_idle_store_yields_tests, pass / fail / crash, all three from the same tree and driver library. This PR's column ran on 24598aa0a4, which has the same tree as this PR's commit:73f4f7e06eANYPS5_NO_SHADER_CACHE=1 APS5_NO_PIPELINE_JOURNAL=1)MESA_SHADER_CACHE_DISABLE=true ANYPS5_NO_SHADER_CACHE=1)ctest -R '^agc_driver_idle_store_yields$' --repeat until-fail:30: 100%.agc_driver_store_idle_results,_wake,agc_driver_idle_store_over_unmap,agc_driver_queue_zero_idle_wait,agc_driver_queued_index_read_order,agc_driver_storage_read_during_idle_storeand this one) pass-j4 --repeat until-fail:10, 70 of 70.GitHub's runners,
agc_driver_idle_store_yieldswith--repeat until-fail:30:73f4f7e06eOn @Dextroid17's devices (comment), the first approach with the shader cache off passed 10 of 10 on an RTX 3080 Ti and 10 of 10 on llvmpipe. That's the setup where main failed 40 of 40.
This PR's commit on the same setup (review),
0a676f3ebdonmain73f4f7e06e, with every pipeline built cold:ANYPS5_NO_SHADER_CACHE=1:ANYPS5_NO_SHADER_CACHE=0: 5 of 5 on both.TechLevelZero's NVIDIA GPU test (report) passed at
0a676f3ebd, on an RTX 2000 Ada Generation (595.99.02): 813 passed, 0 new failures, and no new validation IDs in 397 GPU tests.TechLevelZero's NVIDIA GPU test at
7cbafff1b8(report), merged ontomaine6f5730, on the same RTX 2000 Ada Generation (595.99.02): 833 passed, 0 new failures (1 fails onmaintoo) and 0 skipped, with no new validation IDs in 406 GPU tests.agc_driver_idle_store_yieldspassed (8.12 s). The bot's report on #12745 of 10-31 (report,main0836dfd) lists that test as failing onmainon this machine.On @bunbeans2-arch's AMD RDNA 4 (comment): Radeon RX 9070 XT, Windows 11 Pro 10.0.22631, MSYS2 UCRT64 GCC 16.1.0, Release, validation layer on,
ANYPS5_NO_SHADER_CACHE=1. This PR (0a676f3ebdonmain16452da934) passed 10 of 10 (0.67 to 0.73 s each), with no validation errors.mainalso passed 10 of 10 there, so the race didn't show on that card in 10 runs. These runs show the change doesn't break the test there, not that it fixes the race.On @JJenkx's Windows AMD GPU (comment): Radeon RX 6700 XT, AMD's driver 26.10.1, Windows 11 Enterprise 10.0.22621, WinLibs GCC 15.2.0 UCRT, Release, Vulkan Validation Layers 1.4.363. This PR's head
7cbafff1b8, merged cleanly ontomain5bae1a4bc2, passedagc_driver_idle_store_yields3 of 3 (--repeat until-fail:3), with no VUIDs.mainwasn't run there, so this shows the change works on that card on currentmain, not that it fixes the race there.On @JJenkx's Linux AMD GPU (comment): Radeon RX 6650 XT, RADV (Mesa 26.2.6), Ryzen 9 7950X, Linux 7.2.11, GCC 16.2.1, Release, with the shader cache off, Vulkan required and the Khronos validation layer.
main's own fixture segfaulted once againstmainb28bb77217and once against the same runtime with #8932. The fixture at this PR's head7cbafff1b8, built once, passed once against each of those two runtime builds, with no VUIDs and no skips. That's one run per arm, not a measured change in the failure rate.Validation, CONTRIBUTING's AGC check (run):
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andctest -V. It ran on 24598aa0a4, which has the same tree as this PR's commit.VUID-VkDeviceCreateInfo-pNext-pNext, which is on main too.Checks:
tools/check_conventions.py --base 73f4f7e06e: all passed.tools/check_test_registration.py build: none new.Not in this PR:
Driver::WaitIdleholds the GPU mutex throughRecorder::Syncwhile the queue's quiet period runs. A caller that waits idle and then expects results to still be pending can lose to the idle store the same way. Nothing in the driver relies on that; this test was the only one.Checklist
main; no other open PR implements the same functions (no open PR touchesIdleStoreYields.cpp)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file: n/a, test-only.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T17:38:36Z.
Review: APPROVED
Reviewed — looks good
The queue hold removes the fixture’s timing window, and the exact-tree Linux repeat and paired validation runs support the change; I found no blocking issue.
What I ran
Reviewed head
0a676f3ebdabc1b378d0f158030d70415b475e8. GitHub records PR base0c5ccb21439524e4da09b6c99c9ae3e701978c9f; I also checked the merge preview against the newer livemaintip0f302813cebfc09e3e0b6f8fced15262d186879e, which was clean. Local environment: Debian Linux 6.1, Python 3.11.2, GCC 12.2.0. I did not build or run CTest locally.Results
main49154a0ef6f01d6c98bcd940147095200b081108tests/execution/*.cppthroughGLOB CONFIGURE_DEPENDSagc_driver_idle_store_yieldspassed all 30 repetitions on llvmpipeUnedited check output
Negative control
agc_driver_idle_store_yieldswith the original fixture on the baseline implementationWAIT_REG_MEMhold, then releases it only after taking the GPU mutexFindings
Blocking
None.
Non-blocking
None.
Sources
CONFIGURE_DEPENDSglob at currentmainNot verified
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-31T17:59:46Z.
Review: APPROVED
Ran this head (
0a676f3ebd, on main73f4f7e06e) on the setup that failedagc_driver_idle_store_yields40 of 40 times on main earlier today (#13621), where every pipeline is built cold:Direct runs of the test binary, build log shows
IdleStoreYields.cppcompiled at this head. On the mechanism: the hold is a wait on a label the fixture owns, released only after it holds the GPU mutex, so neither the pipeline build time nor the queue's own idle store can get ahead of the check; that closes both races (the 5 ms wait, and the oneWaitIdleopened on the Linux runner). Approving.AI-assisted: yes