AGC: agc_driver_unregistered_label_on_gpu fails now and then: two stores of one label run have no barrier between them #17937

Closed
opened 2026-11-10 00:02:58 +00:00 by adam25136 · 0 comments
adam25136 commented 2026-11-10 00:02:58 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by adam25136 on 2026-11-10T00:02:58Z.


What happens

agc_driver_unregistered_label_on_gpu failed 10 of 1,000 runs here with unregistered label: the label held 0x00000000 when a later label had landed, 0x5a5a0001 after the device went idle, and 0 of 500 with a local barrier between the stores of a label run.

Title, test or build step

ctest agc_driver_unregistered_label_on_gpu (target agc_driver_unregistered_label_on_gpu_tests, added by #9898)

AnyPS5 commit

main adce651bbd, no pull requests merged on top (the last batch below had one local, inactive-by-default change, shown at the end)

System

Windows 10 Pro 22H2 (19045), Intel Core i9-12900KF, NVIDIA GeForce RTX 5080 (NVIDIA 621.14), WinLibs GCC 15.2.0 r7 (UCRT), CMake 4.3.1, Ninja, Release

Steps to reproduce

cmake --build build --target agc_driver_unregistered_label_on_gpu_tests
for i in $(seq 1 500); do ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build --no-tests=error -R '^agc_driver_unregistered_label_on_gpu$' > /dev/null || echo "run $i failed"; done

One run at a time (Git Bash here), nothing else running; each ctest call takes about 0.7 s. The other arms below set APS5_NO_LABEL_RUNS=1, APS5_LABEL_RUNS_INLINE=1 or, with the local change built in, APS5_LOCAL_RUN_ORDER_BARRIER=1 in front of ctest. The loop adds ANYPS5_REQUIRE_VULKAN=1 and --no-tests=error so that a skip or a missing test does not pass silently; the batches below ran without them and counted a run as passed only when it printed unregistered label tests passed. On Windows the test loads the libSceAgcDriver.prx copy in build/tests, which a rebuild of the library alone does not refresh (#17895), so after changing only the library, copy build/core/libs/libs/unpatched/libSceAgcDriver.prx there before rerunning.

Log

1852: AGC graphics: unregistered label: the label held 0x00000000 when a later label had landed, 0x5a5a0001 after the device went idle
1/1 Test #1852: agc_driver_unregistered_label_on_gpu ...***Failed    0.55 sec

All 17 failures below printed this line, with the same two values.

What was checked

Runs. Each run is a separate ctest of this one test; the arms of a batch alternate run by run.

batch arm runs failed
1 as built 500 5
1 APS5_NO_LABEL_RUNS=1 500 0
2 APS5_NO_LABEL_RUNS=1 1,000 0
3 as built 500 5
3 APS5_LABEL_RUNS_INLINE=1 500 7
3 local barrier between the stores of a run (diff below) 500 0

Earlier on this PC it failed with the same message in 1 of 150 runs on an older main (#17850's Tested section).

What the test checks. It stores 0x5a5a0001 through WriteLabelOnGpu into host memory that is not registered as a guest allocation (line 125), then 0x5a5a0004 into a registered block (line 138); both are stored on the GPU (reason 0). After the submit it polls the second label from the CPU and requires the first to hold its value once the second has landed (lines 141-149). In the failing runs the first label held 0 at that point and 0x5a5a0001 after WaitIdle: late, not lost.

Where the order is lost. Both stores go through Recorder::RecordStore (VulkanDevice.cpp line 3087) into the batch's queued run (Recorder.cpp lines 2021-2040). closeStoreRun records the run's stores back to back and puts a barrier between two of them only when the later one overlaps an earlier one in the same buffer, or between groups after queued sample-count dumps (lines 2159-2177). So any two stores of a run that do not overlap, these two labels included, have nothing ordering them. The comment in Recorder.hpp first says such a store is "ordered after everything recorded before it" (lines 301-303), then that within a run a store overlapping an earlier one gets a transfer-to-transfer barrier first, and names none for the others (lines 311-314); and the comment at VulkanDevice.cpp lines 3081-3085 says RecordStore "orders the stores of a run against each other".

The batch 3 arms narrow down the cause. APS5_LABEL_RUNS_INLINE=1 records the stores in place instead of queuing them for Submit, still with no barrier between them, and still fails. APS5_NO_LABEL_RUNS=1 changes several things at once (each store gets its own barrier pair and is recorded at once), so batch 1 and 2 alone do not say which part matters. The local change adds only one transfer-to-transfer barrier before every store of a per-batch run after the first, and keeps the run; with it, 0 of 500 failed. That it was enough for the host here is a measurement on this GPU; the debt entry below notes that Vulkan makes device writes visible to the host through a fence or event wait. Its cost for label-heavy batches was not measured.

Related. The debt entry "A label stored on the GPU is ordered behind the batch's earlier writes, for a host that polls it, only by driver behavior" in docs/dev/debt/libSceAgcDriver.md applies, but inside one run these stores have no barrier at all. #10318 named the same missing barrier for #10199's test and was closed: in that test no store run was open or queued when its label was recorded, and a flush before every label would give one barrier pair per label; #11886 fixed #10199 instead. The local change keeps one run per batch and adds one barrier per later store; whether that cost is acceptable is for whoever fixes it.

The same test also failed in #17573 (AMD Radeon RX 7900 GRE, Windows 11) and #16420 (NVIDIA GeForce RTX 5090, Windows 11), with no error text there.

Not checked: Linux; other GPUs; whether a title polls one label and then reads an earlier one of the same batch. Whether two labels of one queue land in order on a PS5 was not measured here; the test assumes it.

The local change of batch 3 (not proposed as is; active only with APS5_LOCAL_RUN_ORDER_BARRIER=1)
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
@@ -2107,6 +2107,7 @@ void Recorder::flushPendingStore() {
 bool Recorder::closeStoreRun(bool atSubmit) {
     flushDeferredDispatch();
     auto& run = open->run;
+    static const bool localRunOrderBarrier = std::getenv("APS5_LOCAL_RUN_ORDER_BARRIER") != nullptr;
     if (LabelRunsPerBatch()) {
         auto stores = std::move(run.queued);
         run.queued.clear();
@@ -2170,6 +2171,9 @@ bool Recorder::closeStoreRun(bool atSubmit) {
                     recordBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT);
                     ++barriers;
                     storeWawBarriers.fetch_add(1, std::memory_order_relaxed);
+                } else if (localRunOrderBarrier && !run.recorded.empty()) {
+                    recordBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT);
+                    ++barriers;
                 }
                 update(commands, store.buffer, store.offset, store.bytes.size(), store.bytes.data());
                 run.recorded.emplace_back(store.buffer, store.offset, storeEnd);

AI-assisted: yes. Claude Code wrote the loop script and the local change, ran the loops, read the code and drafted this issue; Claude Code review agents checked it.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6297227231 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/17937). Originally posted by [adam25136](https://github.com/adam25136) on 2026-11-10T00:02:58Z. --- ### What happens `agc_driver_unregistered_label_on_gpu` failed 10 of 1,000 runs here with `unregistered label: the label held 0x00000000 when a later label had landed, 0x5a5a0001 after the device went idle`, and 0 of 500 with a local barrier between the stores of a label run. ### Title, test or build step ctest `agc_driver_unregistered_label_on_gpu` (target `agc_driver_unregistered_label_on_gpu_tests`, added by #9898) ### AnyPS5 commit `main` `adce651bbd`, no pull requests merged on top (the last batch below had one local, inactive-by-default change, shown at the end) ### System Windows 10 Pro 22H2 (19045), Intel Core i9-12900KF, NVIDIA GeForce RTX 5080 (NVIDIA 621.14), WinLibs GCC 15.2.0 r7 (UCRT), CMake 4.3.1, Ninja, Release ### Steps to reproduce ``` cmake --build build --target agc_driver_unregistered_label_on_gpu_tests for i in $(seq 1 500); do ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build --no-tests=error -R '^agc_driver_unregistered_label_on_gpu$' > /dev/null || echo "run $i failed"; done ``` One run at a time (Git Bash here), nothing else running; each `ctest` call takes about 0.7 s. The other arms below set `APS5_NO_LABEL_RUNS=1`, `APS5_LABEL_RUNS_INLINE=1` or, with the local change built in, `APS5_LOCAL_RUN_ORDER_BARRIER=1` in front of `ctest`. The loop adds `ANYPS5_REQUIRE_VULKAN=1` and `--no-tests=error` so that a skip or a missing test does not pass silently; the batches below ran without them and counted a run as passed only when it printed `unregistered label tests passed`. On Windows the test loads the `libSceAgcDriver.prx` copy in `build/tests`, which a rebuild of the library alone does not refresh (#17895), so after changing only the library, copy `build/core/libs/libs/unpatched/libSceAgcDriver.prx` there before rerunning. ### Log ```text 1852: AGC graphics: unregistered label: the label held 0x00000000 when a later label had landed, 0x5a5a0001 after the device went idle 1/1 Test #1852: agc_driver_unregistered_label_on_gpu ...***Failed 0.55 sec ``` All 17 failures below printed this line, with the same two values. ### What was checked **Runs.** Each run is a separate `ctest` of this one test; the arms of a batch alternate run by run. | batch | arm | runs | failed | |---|---|---|---| | 1 | as built | 500 | 5 | | 1 | `APS5_NO_LABEL_RUNS=1` | 500 | 0 | | 2 | `APS5_NO_LABEL_RUNS=1` | 1,000 | 0 | | 3 | as built | 500 | 5 | | 3 | `APS5_LABEL_RUNS_INLINE=1` | 500 | 7 | | 3 | local barrier between the stores of a run (diff below) | 500 | 0 | Earlier on this PC it failed with the same message in 1 of 150 runs on an older `main` (#17850's Tested section). **What the test checks.** It stores `0x5a5a0001` through `WriteLabelOnGpu` into host memory that is not registered as a guest allocation ([line 125](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/tests/execution/UnregisteredLabelOnGpu.cpp#L125)), then `0x5a5a0004` into a registered block ([line 138](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/tests/execution/UnregisteredLabelOnGpu.cpp#L138)); both are stored on the GPU (reason 0). After the submit it polls the second label from the CPU and requires the first to hold its value once the second has landed ([lines 141-149](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/tests/execution/UnregisteredLabelOnGpu.cpp#L141-L149)). In the failing runs the first label held 0 at that point and `0x5a5a0001` after `WaitIdle`: late, not lost. **Where the order is lost.** Both stores go through `Recorder::RecordStore` ([`VulkanDevice.cpp` line 3087](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp#L3087)) into the batch's queued run ([`Recorder.cpp` lines 2021-2040](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L2021-L2040)). `closeStoreRun` records the run's stores back to back and puts a barrier between two of them only when the later one overlaps an earlier one in the same buffer, or between groups after queued sample-count dumps ([lines 2159-2177](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L2159-L2177)). So any two stores of a run that do not overlap, these two labels included, have nothing ordering them. The comment in `Recorder.hpp` first says such a store is "ordered after everything recorded before it" ([lines 301-303](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp#L301-L303)), then that within a run a store overlapping an earlier one gets a transfer-to-transfer barrier first, and names none for the others ([lines 311-314](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp#L311-L314)); and the comment at [`VulkanDevice.cpp` lines 3081-3085](https://github.com/boykopovar/AnyPS5/blob/adce651bbda0a1e37b7c8a3140afd4ec47917387/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp#L3081-L3085) says `RecordStore` "orders the stores of a run against each other". The batch 3 arms narrow down the cause. `APS5_LABEL_RUNS_INLINE=1` records the stores in place instead of queuing them for `Submit`, still with no barrier between them, and still fails. `APS5_NO_LABEL_RUNS=1` changes several things at once (each store gets its own barrier pair and is recorded at once), so batch 1 and 2 alone do not say which part matters. The local change adds only one transfer-to-transfer barrier before every store of a per-batch run after the first, and keeps the run; with it, 0 of 500 failed. That it was enough for the host here is a measurement on this GPU; the debt entry below notes that Vulkan makes device writes visible to the host through a fence or event wait. Its cost for label-heavy batches was not measured. **Related.** The debt entry "A label stored on the GPU is ordered behind the batch's earlier writes, for a host that polls it, only by driver behavior" in `docs/dev/debt/libSceAgcDriver.md` applies, but inside one run these stores have no barrier at all. #10318 named the same missing barrier for #10199's test and was closed: in that test no store run was open or queued when its label was recorded, and a flush before every label would give one barrier pair per label; #11886 fixed #10199 instead. The local change keeps one run per batch and adds one barrier per later store; whether that cost is acceptable is for whoever fixes it. The same test also failed in #17573 (AMD Radeon RX 7900 GRE, Windows 11) and #16420 (NVIDIA GeForce RTX 5090, Windows 11), with no error text there. **Not checked:** Linux; other GPUs; whether a title polls one label and then reads an earlier one of the same batch. Whether two labels of one queue land in order on a PS5 was not measured here; the test assumes it. <details><summary>The local change of batch 3 (not proposed as is; active only with APS5_LOCAL_RUN_ORDER_BARRIER=1)</summary> ```diff --- a/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp @@ -2107,6 +2107,7 @@ void Recorder::flushPendingStore() { bool Recorder::closeStoreRun(bool atSubmit) { flushDeferredDispatch(); auto& run = open->run; + static const bool localRunOrderBarrier = std::getenv("APS5_LOCAL_RUN_ORDER_BARRIER") != nullptr; if (LabelRunsPerBatch()) { auto stores = std::move(run.queued); run.queued.clear(); @@ -2170,6 +2171,9 @@ bool Recorder::closeStoreRun(bool atSubmit) { recordBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT); ++barriers; storeWawBarriers.fetch_add(1, std::memory_order_relaxed); + } else if (localRunOrderBarrier && !run.recorded.empty()) { + recordBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT); + ++barriers; } update(commands, store.buffer, store.offset, store.bytes.size(), store.bytes.data()); run.recorded.emplace_back(store.buffer, store.offset, storeEnd); ``` </details> AI-assisted: yes. Claude Code wrote the loop script and the local change, ran the loops, read the code and drafted this issue; Claude Code review agents checked it.
Sign in to join this conversation.
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#17937
No description provided.