fix(agc): order the stores of a label run against each other #17999

Merged
kaiffeetasse merged 3 commits from upstream-pr/17999 into main 2026-11-16 02:14:09 +00:00
kaiffeetasse commented 2026-11-10 03:14:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kaiffeetasse on 2026-11-10T03:14:31Z.


What

Recorder::closeStoreRun records the stores of a batch's label run back to back and puts a transfer-to-transfer barrier between two of them only when the later one overlaps an earlier one in the same buffer. Two stores into different buffers therefore have no ordering between them, and a host that polls the later label and then reads the earlier one can see the earlier store missing — agc_driver_unregistered_label_on_gpu fails that way (10 of 1000 runs on Windows, #17937; after WaitIdle the value is there, so it is late and not lost).

Every store after the first of its group now takes that barrier, so a run's stores reach the host in program order. Following the review note below, that barrier also names VK_PIPELINE_STAGE_HOST_BIT and VK_ACCESS_HOST_READ_BIT as its destination, which is the availability operation a polling host needs before it may read the earlier store while the batch is still running — the batch-end barrier only covers the host at submission end. The overlap case keeps its WAW barrier and its storeWawBarriers counter; the new case counts in barriers only, which is what CountBarriers(CommandClass::LabelRun, …) reports. docs/dev/debt/libSceAgcDriver.md records that the run's own stores are now ordered and host-visible to each other, and that the batch-to-host ordering behind the batch's earlier writes still rests on driver behaviour.

The cost is one barrier per store of a run beyond the first of its group, and it was not measured: the issue's local change (one barrier per later store, behind an environment variable) took the failing test from 5 of 500 to 0 of 500 on an RTX 5080, which is what this PR makes unconditional. Say if you would rather have the run split or flushed per label instead.

Tested

Linux, Ubuntu 24.04, GCC 13.3.0, Mesa 25.2.8 llvmpipe (CPU device — no hardware GPU on this machine), ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (layer 1.3.275, loaded: no was not found but was requested line, no VUID- line), on head ba05419c80:

  • agc_recorder_kept_bytes, agc_driver_recorder, agc_recorder_stored_bytes, agc_driver_unregistered_label_on_gpu: 4 of 4 passed.
  • New test SeparateStoresOfOneRunAreOrdered: mock device records vkCmdUpdateBuffer/vkCmdPipelineBarrier in order; two stores of one run into different buffers must have a barrier between them, and that barrier's destination must name the host stage and HOST_READ. With the HOST bits removed from the two barriers again the test fails with both messages (… does not make the earlier store available to the host stage, … does not make the earlier store readable by the host); with them it passes. On a branch without the barrier at all it fails with the stores of a run into different buffers are not separated by a barrier.
  • agc_driver_unregistered_label_on_gpu: 300 runs without the fix, 300 runs with it, 0 failures — llvmpipe does not lose the order the way the reporter's NVIDIA driver does, so the run count is not evidence either way here.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.
  • tools/pr_overlap.py --branch … fails closed (exit 2) with 25 open PRs sharing these files; all 25 were compared by hand for the construct this PR changes: none adds, removes or renames a store-run barrier (only #13863 and #13920 call closeStoreRun(true) from elsewhere).
  • Windows, checked independently by JJenkx on head cf35cb8179 merged onto main 017bd95f5f (clean merge): Windows 11 Enterprise 22621, WinLibs GCC 15.2.0 UCRT r7, Release, Vulkan hidden — agc_recorder_kept_bytes passed in 3 of 3 runs, none skipped.
  • The reporter's machine, checked independently by adam25136 on head cf35cb8179 merged into main (Windows 10 22H2, RTX 5080, driver 621.14, WinLibs GCC 15.2.0, no validation layer): agc_driver_unregistered_label_on_gpu failed 1 of 500 and 6 of 2,000 runs on main (all 7 with the message from #17937) and 0 of 2,500 with this PR. That is the reproduction the fix was written for.
  • Linux NVIDIA, checked independently by milescoviello (Ubuntu 26.04, RTX 4070 Ti, driver 615.71.09, GCC 15.2, 500 runs per build, Vulkan required): 0 failures on the merge base 356ba02b5f and 0 on head cf35cb8179 — the flake does not reproduce there, so those runs show the change does not disturb this test on that driver rather than confirming the fix. The HOST stage and access bits came from that review note.
  • Windows NVIDIA, checked independently by NathanFahey23 on head ba05419c80 merged onto main bab5bc6b98 (Windows 11 Home 26300, i9-13900K, WinLibs GCC 15.2.0, RTX 4080, driver 32.0.16.2101, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1): agc_driver_unregistered_label_on_gpu failed 2 of 500 runs on main, both with the message from #17937, and 0 of 494 on the merge. The GPU set with the validation layer (tests whose names start with agc_, shader, video_out or guest_video, --parallel 4) was 1740/1740 on main and 1739/1740 on the merge, with 0 VUID- lines on both; the one failure, agc_driver_job_manager_compute_capacity, also fails on main alone.
  • Windows NVIDIA, checked independently by Gag21 on head ba05419c80 merged onto main aa5f2b541a (Windows 11 Pro 10.0.26300, i5-6600K, WinLibs GCC 16.2.0, RTX 3070, driver 621.01, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1): agc_driver_unregistered_label_on_gpu 0 failures of 1,000 on main and 0 of 1,000 on the merge, and agc_recorder_kept_bytes, agc_driver_recorder, agc_recorder_stored_bytes pass on both — the flake does not reproduce on that card, so this run neither confirms nor contradicts the fix; it does show the HOST-stage change builds and passes there, which had not been rerun. No validation layer on that machine, so no VUID- comparison from it.
  • The overlap bot names #16753 (perf(agc): remove fixed per-draw clock reads, owner copies and allocations, opened 07.11.) on the same test file at the two anchors this PR also uses: it appends two tests after SharedOwnerCountsOncePerBatch() and adds their calls at the same place in main(). Whichever of the two merges second needs a one-hunk rebase in RecorderKeptBytes.cpp; #16753 reworks the retained-owner API, not the store-run barrier, so they are not the same topic.

Not tested: any hardware GPU on this machine, and whether the console orders two labels of one queue, which the test assumes. The two independent checks above cover Windows (RTX 5080, the reporter's machine) and Linux NVIDIA (RTX 4070 Ti); both are on cf35cb8179, before the HOST bits were added.

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: Fixes #17937
  • Unblocks: none
  • GPUs tested: none — Mesa llvmpipe (Mesa 25.2.8, Ubuntu 24.04, CPU) here; independent runs by others on RTX 5080 (Windows), RTX 4080 (Windows) and RTX 4070 Ti (Linux NVIDIA) are quoted above
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5235140951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17999). Originally posted by [kaiffeetasse](https://github.com/kaiffeetasse) on 2026-11-10T03:14:31Z. --- ### What `Recorder::closeStoreRun` records the stores of a batch's label run back to back and puts a transfer-to-transfer barrier between two of them only when the later one overlaps an earlier one in the same buffer. Two stores into different buffers therefore have no ordering between them, and a host that polls the later label and then reads the earlier one can see the earlier store missing — `agc_driver_unregistered_label_on_gpu` fails that way (10 of 1000 runs on Windows, #17937; after `WaitIdle` the value is there, so it is late and not lost). Every store after the first of its group now takes that barrier, so a run's stores reach the host in program order. Following the review note below, that barrier also names `VK_PIPELINE_STAGE_HOST_BIT` and `VK_ACCESS_HOST_READ_BIT` as its destination, which is the availability operation a polling host needs before it may read the earlier store while the batch is still running — the batch-end barrier only covers the host at submission end. The overlap case keeps its WAW barrier and its `storeWawBarriers` counter; the new case counts in `barriers` only, which is what `CountBarriers(CommandClass::LabelRun, …)` reports. `docs/dev/debt/libSceAgcDriver.md` records that the run's own stores are now ordered and host-visible to each other, and that the batch-to-host ordering behind the batch's earlier writes still rests on driver behaviour. The cost is one barrier per store of a run beyond the first of its group, and it was not measured: the issue's local change (one barrier per later store, behind an environment variable) took the failing test from 5 of 500 to 0 of 500 on an RTX 5080, which is what this PR makes unconditional. Say if you would rather have the run split or flushed per label instead. ### Tested Linux, Ubuntu 24.04, GCC 13.3.0, Mesa 25.2.8 `llvmpipe` (CPU device — no hardware GPU on this machine), `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (layer 1.3.275, loaded: no `was not found but was requested` line, no `VUID-` line), on head `ba05419c80`: - `agc_recorder_kept_bytes`, `agc_driver_recorder`, `agc_recorder_stored_bytes`, `agc_driver_unregistered_label_on_gpu`: 4 of 4 passed. - New test `SeparateStoresOfOneRunAreOrdered`: mock device records `vkCmdUpdateBuffer`/`vkCmdPipelineBarrier` in order; two stores of one run into different buffers must have a barrier between them, and that barrier's destination must name the host stage and `HOST_READ`. With the HOST bits removed from the two barriers again the test fails with both messages (`… does not make the earlier store available to the host stage`, `… does not make the earlier store readable by the host`); with them it passes. On a branch without the barrier at all it fails with `the stores of a run into different buffers are not separated by a barrier`. - `agc_driver_unregistered_label_on_gpu`: 300 runs without the fix, 300 runs with it, 0 failures — `llvmpipe` does not lose the order the way the reporter's NVIDIA driver does, so the run count is not evidence either way here. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - `tools/pr_overlap.py --branch …` fails closed (exit 2) with 25 open PRs sharing these files; all 25 were compared by hand for the construct this PR changes: none adds, removes or renames a store-run barrier (only #13863 and #13920 call `closeStoreRun(true)` from elsewhere). - Windows, checked independently by JJenkx on head `cf35cb8179` merged onto `main` `017bd95f5f` (clean merge): Windows 11 Enterprise 22621, WinLibs GCC 15.2.0 UCRT r7, Release, Vulkan hidden — `agc_recorder_kept_bytes` passed in 3 of 3 runs, none skipped. - The reporter's machine, checked independently by adam25136 on head `cf35cb8179` merged into `main` (Windows 10 22H2, RTX 5080, driver 621.14, WinLibs GCC 15.2.0, no validation layer): `agc_driver_unregistered_label_on_gpu` failed 1 of 500 and 6 of 2,000 runs on `main` (all 7 with the message from #17937) and 0 of 2,500 with this PR. That is the reproduction the fix was written for. - Linux NVIDIA, checked independently by milescoviello (Ubuntu 26.04, RTX 4070 Ti, driver 615.71.09, GCC 15.2, 500 runs per build, Vulkan required): 0 failures on the merge base `356ba02b5f` and 0 on head `cf35cb8179` — the flake does not reproduce there, so those runs show the change does not disturb this test on that driver rather than confirming the fix. The HOST stage and access bits came from that review note. - Windows NVIDIA, checked independently by NathanFahey23 on head `ba05419c80` merged onto `main` `bab5bc6b98` (Windows 11 Home 26300, i9-13900K, WinLibs GCC 15.2.0, RTX 4080, driver 32.0.16.2101, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`): `agc_driver_unregistered_label_on_gpu` failed 2 of 500 runs on `main`, both with the message from #17937, and 0 of 494 on the merge. The GPU set with the validation layer (tests whose names start with `agc_`, `shader`, `video_out` or `guest_video`, `--parallel 4`) was 1740/1740 on `main` and 1739/1740 on the merge, with 0 `VUID-` lines on both; the one failure, `agc_driver_job_manager_compute_capacity`, also fails on `main` alone. - Windows NVIDIA, checked independently by Gag21 on head `ba05419c80` merged onto `main` `aa5f2b541a` (Windows 11 Pro 10.0.26300, i5-6600K, WinLibs GCC 16.2.0, RTX 3070, driver 621.01, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`): `agc_driver_unregistered_label_on_gpu` 0 failures of 1,000 on `main` and 0 of 1,000 on the merge, and `agc_recorder_kept_bytes`, `agc_driver_recorder`, `agc_recorder_stored_bytes` pass on both — the flake does not reproduce on that card, so this run neither confirms nor contradicts the fix; it does show the HOST-stage change builds and passes there, which had not been rerun. No validation layer on that machine, so no `VUID-` comparison from it. - The overlap bot names #16753 (*perf(agc): remove fixed per-draw clock reads, owner copies and allocations*, opened 07.11.) on the same test file at the two anchors this PR also uses: it appends two tests after `SharedOwnerCountsOncePerBatch()` and adds their calls at the same place in `main()`. Whichever of the two merges second needs a one-hunk rebase in `RecorderKeptBytes.cpp`; #16753 reworks the retained-owner API, not the store-run barrier, so they are not the same topic. Not tested: any hardware GPU on this machine, and whether the console orders two labels of one queue, which the test assumes. The two independent checks above cover Windows (RTX 5080, the reporter's machine) and Linux NVIDIA (RTX 4070 Ti); both are on `cf35cb8179`, before the HOST bits were added. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: Fixes #17937 - [x] Unblocks: none - [x] GPUs tested: none — Mesa `llvmpipe` (Mesa 25.2.8, Ubuntu 24.04, CPU) here; independent runs by others on RTX 5080 (Windows), RTX 4080 (Windows) and RTX 4070 Ti (Linux NVIDIA) are quoted above - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
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!17999
No description provided.