fix(agc): keep the write-back ready barrier while hole copies are pending #8908

Merged
meh7an merged 1 commit from upstream-pr/8908 into main 2026-10-23 22:29:07 +00:00
meh7an commented 2026-10-21 05:39:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by meh7an on 2026-10-21T05:39:19Z.


What

StorageTexture::writeBackWindows records a write-back's seed, padding and hole copies, then the importReady/toRead barrier before the compute retile reads the slabs those copies wrote. #7489 lets that barrier be skipped when the batch's trailing barrier already covers it (Recorder::ElideCovered). The skip is allowed only with no seeds and no padding copies, but hole copies (padding moved into a unit-shadow slab, added in a8060b40e) are not checked. A covered mask taken before those copies does not order them, so the retile can read a slab before its hole copies land.

This PR also requires holeCopies.empty() before the barrier may be skipped.

Regressed by #7489 (ea5b81134). In Sonic Origins Plus (PPSA05324), the menu's button prompts and notice line lost parts of their glyphs, and which glyphs varied from run to run.

Tested

Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 2080 Ti, driver 617.14, on main fa9eb5cfa.

  • Sonic Origins Plus, Sonic 2 page of the main menu: full window captures taken in the session, three readings per build. The six crops are attached: rows 1-3 are main, rows 4-6 are this PR.

    • main: broken glyphs in all three captures.
    • this PR: all three clean.
    main-vs-fix
  • Bisect, first parent only, over main from 0a56aaaf4 (clean) to 1d4164552 (broken). Clean: 5e9074999, 0cc1cfa1c, 819ced2e1, feb74b65c, dc54701e4, 05b5d192f, 7f596df48. Broken: 463031845, 096279ed2, ea5b81134. 3a14fdb32 was skipped: it aborts at boot with "Thread destructor callback is already registered", which is unrelated. The first bad merge is ea5b81134 (#7489).

  • Main fa9eb5cfa with APS5_NO_BARRIER_BATCH=1 and no other change renders the prompts clean in all three captures.

  • With a temporary print (not in this PR), the barrier was skipped while hole copies were pending 36 times in one run of the menu page.

  • The full ctest suite on main plus this PR: 1827/1828. The one miss is agc_driver_image_array_window_past_layer_limit, which is Not Run on main too, because MinGW cannot build its alignas(65536).

  • ctest -R "agc_storage|agc_barrier_batch|write_back|writeback" -V (13 tests) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, on main and on this PR:

    • 13/13 passed in both.
    • Neither log has was not found but was requested by env var VK_INSTANCE_LAYERS. The loader debug output shows VkLayer_khronos_validation.dll loading.
    • Neither log has a VUID- line.
  • No new test. On this machine the storage write-back tests compare host imports instead of watching them ("host imports are compared, not watched"), so no window is retiled into a unit-shadow slab and no hole copy is recorded. A test of this path needs watched host imports.

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
  • GPUs tested: NVIDIA GeForce RTX 2080 Ti, driver 617.14, Windows 11 Pro 10.0.26300
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4946957548 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8908). Originally posted by [meh7an](https://github.com/meh7an) on 2026-10-21T05:39:19Z. --- ### What `StorageTexture::writeBackWindows` records a write-back's seed, padding and hole copies, then the `importReady`/`toRead` barrier before the compute retile reads the slabs those copies wrote. #7489 lets that barrier be skipped when the batch's trailing barrier already covers it (`Recorder::ElideCovered`). The skip is allowed only with no seeds and no padding copies, but hole copies (padding moved into a unit-shadow slab, added in a8060b40e) are not checked. A covered mask taken before those copies does not order them, so the retile can read a slab before its hole copies land. This PR also requires `holeCopies.empty()` before the barrier may be skipped. Regressed by #7489 (ea5b81134). In Sonic Origins Plus (PPSA05324), the menu's button prompts and notice line lost parts of their glyphs, and which glyphs varied from run to run. ### Tested Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 2080 Ti, driver 617.14, on main fa9eb5cfa. - Sonic Origins Plus, Sonic 2 page of the main menu: full window captures taken in the session, three readings per build. The six crops are attached: rows 1-3 are main, rows 4-6 are this PR. - main: broken glyphs in all three captures. - this PR: all three clean. <img width="418" height="558" alt="main-vs-fix" src="https://github.com/user-attachments/assets/61bdfb25-5996-44ef-9221-c723c8da04b9" /> - Bisect, first parent only, over main from 0a56aaaf4 (clean) to 1d4164552 (broken). Clean: 5e9074999, 0cc1cfa1c, 819ced2e1, feb74b65c, dc54701e4, 05b5d192f, 7f596df48. Broken: 463031845, 096279ed2, ea5b81134. 3a14fdb32 was skipped: it aborts at boot with "Thread destructor callback is already registered", which is unrelated. The first bad merge is ea5b81134 (#7489). - Main fa9eb5cfa with `APS5_NO_BARRIER_BATCH=1` and no other change renders the prompts clean in all three captures. - With a temporary print (not in this PR), the barrier was skipped while hole copies were pending 36 times in one run of the menu page. - The full `ctest` suite on main plus this PR: 1827/1828. The one miss is `agc_driver_image_array_window_past_layer_limit`, which is Not Run on main too, because MinGW cannot build its `alignas(65536)`. - `ctest -R "agc_storage|agc_barrier_batch|write_back|writeback" -V` (13 tests) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, on main and on this PR: - 13/13 passed in both. - Neither log has `was not found but was requested by env var VK_INSTANCE_LAYERS`. The loader debug output shows `VkLayer_khronos_validation.dll` loading. - Neither log has a `VUID-` line. - No new test. On this machine the storage write-back tests compare host imports instead of watching them ("host imports are compared, not watched"), so no window is retiled into a unit-shadow slab and no hole copy is recorded. A test of this path needs watched host imports. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 2080 Ti, driver 617.14, Windows 11 Pro 10.0.26300 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-21 05:40:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:40:29Z.

Review: APPROVED


Reviewed the changed path against the surrounding command sequence. holeCopies are issued with vkCmdCopyBuffer into the unit-shadow slabs immediately before the retile dispatch; importReady provides the transfer-write to compute-shader-read dependency. The prior ElideCovered decision only checked seeds and padding copies, so excluding pending hole copies is the missing guard. The PR description also reports a title repro, a bisect to #7489, and clean captures with this change. I could not reproduce the Windows/Vulkan title path in this environment, so this approval is based on the code path and your reported measurements.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5595404176 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8908#pullrequestreview-5595404176). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T05:40:29Z. **Review:** APPROVED --- Reviewed the changed path against the surrounding command sequence. `holeCopies` are issued with `vkCmdCopyBuffer` into the unit-shadow slabs immediately before the retile dispatch; `importReady` provides the transfer-write to compute-shader-read dependency. The prior `ElideCovered` decision only checked seeds and padding copies, so excluding pending hole copies is the missing guard. The PR description also reports a title repro, a bisect to #7489, and clean captures with this change. I could not reproduce the Windows/Vulkan title path in this environment, so this approval is based on the code path and your reported measurements.
Amoenus commented 2026-10-21 08:15:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-21T08:15:36Z.


@meh7an the focused regression now gives a repeatable red/green result on both GPUs.

Frozen base: main 3bd7173b77. The control is main production plus the new test, not an unchanged-main execution containing a pre-existing fixture.

Physical GPU Test-only control With your fix
RTX5080 /32.0.16.1062 Fails 3/3 Passes 3/3
Radeon Graphics/gfx1036 /32.0.21036.18 Fails 3/3 Passes 3/3

The fixture uses a watched, unseeded, 1000x700 single-mip R_X surface with padding. It records a valid prior barrier and marks its coverage, then observes five import-to-slab hole copies and one retile dispatch. The control observes one dispatch before those copies are ordered; with the fix that count is zero. The aggregate barrier count is one in both cases: the test checks its position relative to the read, not just its presence. That matches Vulkan's before/after submission scopes.

You can cherry-pick the test-only commit into this PR, which already contains your production fix. No duplicate fix PR opened. The fixture uses one legal physical mip and does not depend on our #7085 extra-mip backing work.

Validation setup and limits

agc_driver_unit_shadow and agc_storage_writeback_blocks each pass 3/3 per GPU on both compositions; CPU agc_barrier_batch passes3/3 on each. 36 positive processes plus six exact negative-control failures, no skips/timeouts/VUIDs/validation errors or warnings; maximum 0.563 s. The earlier four precondition processes retain their separate main338f pin and are not added to these counts.

Windows 11 Enterprise 26200, WinLibs GCC 15.2 r7/UCRT Release, SPIRV-Tools ON. Actual physical adapters (10de:2c02, 1002:13c0) and loaded Khronos 1.4.363 verified. Required Vulkan, application cache/journal disabled, verbose serial CTest with 30 s limits; driver caches/implicit layers uncontrolled. Selected targets build; conventions and whitespace pass. Cppcheck then clang-tidy complete with no parser failures/timeouts: 52 diagnostics, all seven-line contexts unchanged from main; none in the new fixture or changed guard. Existing advisories remain disclosed, without an analyzer-clean claim.

The observer follows the suite's nested-recorder lifetime pattern. Earlier fixture-development failures were retained locally and are excluded from the qualified counts. The assertions require a whole unseeded window, actual hole copies, a retile dispatch and correct ordering.

No full-default build, full-suite, title/FPS, Linux or console result. Newer checked main 27c88 has byte-identical Texture.cpp, recorder, import, unit-shadow, detiler and tiling implementation files; that is source review, not a new runtime pin. Our historical integration guard at b64afb remains separate context, not this control.

AI-assisted: yes (Codex); author responsible.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311340336 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8908#issuecomment-6311340336). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-21T08:15:36Z. --- @meh7an the focused regression now gives a repeatable red/green result on both GPUs. - **[Test-only commit `12986aa49b`](https://github.com/Amoenus/AnyPS5/commit/12986aa49b290f0b671aa75822d779011afe8a2c)** adds `agc_storage_hole_copy_barrier` to the recorder suite (two files, 166 added lines). - **[Fixed composition `18d206039e`](https://github.com/Amoenus/AnyPS5/commit/18d206039e96a480d65094406125d0f13b5b1aca)** adds your unchanged `849c71646f` on top, preserving Mehran's authorship; range-diff is `=`. The fixture blob is byte-identical. Frozen base: main `3bd7173b77`. The control is **main production plus the new test**, not an unchanged-main execution containing a pre-existing fixture. | Physical GPU | Test-only control | With your fix | |---|---:|---:| | RTX5080 /32.0.16.1062 | Fails 3/3 | Passes 3/3 | | Radeon Graphics/gfx1036 /32.0.21036.18 | Fails 3/3 | Passes 3/3 | The fixture uses a watched, unseeded, 1000x700 single-mip R_X surface with padding. It records a valid prior barrier and marks its coverage, then observes **five import-to-slab hole copies and one retile dispatch**. The control observes one dispatch before those copies are ordered; with the fix that count is zero. The aggregate barrier count is one in both cases: the test checks its position relative to the read, not just its presence. That matches [Vulkan's before/after submission scopes](https://docs.vulkan.org/refpages/latest/refpages/source/vkCmdPipelineBarrier.html). You can cherry-pick the **test-only commit** into this PR, which already contains your production fix. No duplicate fix PR opened. The fixture uses one legal physical mip and does not depend on our #7085 extra-mip backing work. <details> <summary>Validation setup and limits</summary> `agc_driver_unit_shadow` and `agc_storage_writeback_blocks` each pass 3/3 per GPU on both compositions; CPU `agc_barrier_batch` passes3/3 on each. **36 positive processes plus six exact negative-control failures**, no skips/timeouts/VUIDs/validation errors or warnings; maximum 0.563 s. The earlier four precondition processes retain their separate main338f pin and are not added to these counts. Windows 11 Enterprise 26200, WinLibs GCC 15.2 r7/UCRT Release, SPIRV-Tools ON. Actual physical adapters (`10de:2c02`, `1002:13c0`) and loaded Khronos 1.4.363 verified. Required Vulkan, application cache/journal disabled, verbose serial CTest with 30 s limits; driver caches/implicit layers uncontrolled. Selected targets build; conventions and whitespace pass. Cppcheck then clang-tidy complete with no parser failures/timeouts: 52 diagnostics, all seven-line contexts unchanged from main; none in the new fixture or changed guard. Existing advisories remain disclosed, without an analyzer-clean claim. The observer follows the suite's nested-recorder lifetime pattern. Earlier fixture-development failures were retained locally and are excluded from the qualified counts. The assertions require a whole unseeded window, actual hole copies, a retile dispatch and correct ordering. No full-default build, full-suite, title/FPS, Linux or console result. Newer checked main `27c88` has byte-identical `Texture.cpp`, recorder, import, unit-shadow, detiler and tiling implementation files; that is source review, not a new runtime pin. Our historical integration guard at `b64afb` remains separate context, not this control. </details> AI-assisted: yes (Codex); author responsible. <!-- codex-8908-watched-regression-followup -->
JJenkx commented 2026-10-21 16:27:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T16:27:43Z.


An independent data point from a different title, GPU vendor and OS. This change fixes a GPU hang I had been chasing in Echoes of the End (PPSA25636).

Setup

  • Arch Linux, kernel 7.2.9, RX 6650 XT (NAVI23), RADV on Mesa 26.2.4.
  • Integration branch: main 33a6d6bbfb plus #8089, #8762, #8091 and #4449, which the title needs to reach the scene. My private diagnostic commits are also in it; they do nothing unless their env vars are set, and none were set below.
  • Default unit-shadow budget (1 GiB). Echoes evicts heavily at that budget, about 120-150k slab evictions per 600-900 s.

Symptom without this change

  • 13 of 13 runs ended in a gfx_0.0.0 ring timeout at 170-410 s. Each was a soft ring reset with no VM page fault.
  • A RADV_DEBUG=hang dump places the hang inside a game compute CmdDispatchIndirect. Its loop bound comes from a txf of a utexture2D, so a stale value in that texture spins the waves until the timeout.

Bisect, same tree, one run each unless noted

Configuration Result
default hang, 13/13
APS5_NO_UNIT_SHADOW=1 clean, 480 s
APS5_UNIT_SHADOW_MIB=4096 (no evictions) clean, 482 s and 900 s
eviction of slabs idle >=120 presents only clean, 600 s, 33 evictions
APS5_FULL_BARRIERS=1 clean, 600 s, 120,119 evictions
APS5_NO_BARRIER_BATCH=1 clean, 600 s, 125,295 evictions
only the direct write-back's ElideCovered disabled clean, 600 s, 120,284 evictions
this PR's one-line change, nothing else clean, 900 s, 147,329 evictions, 0 amdgpu kernel events

This also explains why eviction triggers it here. A hole copy is recorded only when the padding's source is a buffer other than the destination slab. That happens routinely once evicted slabs are recreated, and rarely while slabs stay resident. With the 4 GiB budget the elision never meets a pending hole copy.

Not measured here: whether holeCopies.empty() costs any elisions in titles without eviction. Every clean run above used the same tree and only the configuration shown.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321009083 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8908#issuecomment-6321009083). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T16:27:43Z. --- An independent data point from a different title, GPU vendor and OS. This change fixes a GPU hang I had been chasing in Echoes of the End (PPSA25636). **Setup** - Arch Linux, kernel 7.2.9, RX 6650 XT (NAVI23), RADV on Mesa 26.2.4. - Integration branch: main `33a6d6bbfb` plus #8089, #8762, #8091 and #4449, which the title needs to reach the scene. My private diagnostic commits are also in it; they do nothing unless their env vars are set, and none were set below. - Default unit-shadow budget (1 GiB). Echoes evicts heavily at that budget, about 120-150k slab evictions per 600-900 s. **Symptom without this change** - 13 of 13 runs ended in a `gfx_0.0.0` ring timeout at 170-410 s. Each was a soft ring reset with no VM page fault. - A `RADV_DEBUG=hang` dump places the hang inside a game compute `CmdDispatchIndirect`. Its loop bound comes from a `txf` of a `utexture2D`, so a stale value in that texture spins the waves until the timeout. **Bisect, same tree, one run each unless noted** | Configuration | Result | |---|---| | default | hang, 13/13 | | `APS5_NO_UNIT_SHADOW=1` | clean, 480 s | | `APS5_UNIT_SHADOW_MIB=4096` (no evictions) | clean, 482 s and 900 s | | eviction of slabs idle >=120 presents only | clean, 600 s, 33 evictions | | `APS5_FULL_BARRIERS=1` | clean, 600 s, 120,119 evictions | | `APS5_NO_BARRIER_BATCH=1` | clean, 600 s, 125,295 evictions | | only the direct write-back's `ElideCovered` disabled | clean, 600 s, 120,284 evictions | | **this PR's one-line change**, nothing else | **clean, 900 s, 147,329 evictions, 0 amdgpu kernel events** | This also explains why eviction triggers it here. A hole copy is recorded only when the padding's source is a buffer other than the destination slab. That happens routinely once evicted slabs are recreated, and rarely while slabs stay resident. With the 4 GiB budget the elision never meets a pending hole copy. Not measured here: whether `holeCopies.empty()` costs any elisions in titles without eviction. Every clean run above used the same tree and only the configuration shown.
JJenkx commented 2026-10-21 16:35:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T16:35:52Z.


Second title for this fix on AMD/Linux, next to the Echoes validation above.

Setup

  • Code Violet (PPSA26528) 01.000.028, Linux 7.2.9, RX 6650 XT, RADV (Mesa 26.2.4).
  • The tree is main b5d763770a with #4449 merged locally, plus a local descriptor guard for its imports. This title needs #4449 to import its direct memory at all.
  • Default settings throughout: no APS5_UNIT_SHADOW_MIB and no barrier switches. Same inputs in every run.
Tree Result
without this PR (3 runs) ring gfx_0.0.0 timeout from the game at ~118, ~120 and ~150 s, then vkQueueSubmit … Vulkan result -4
without this PR, APS5_NO_BARRIER_BATCH=1 no timeout in 242 s
without this PR, APS5_UNIT_SHADOW_MIB=4096 no timeout in 242 s; reaches the main menu
with this PR (849c71646f merged on top) no timeout in 302 s, no kernel GPU events, 9725 host imports made and 0 refused

A RADV_DEBUG=hang dump of one of the hangs without this PR names a compute pipeline that runs out of time: a 32-thread workgroup with umax image atomics into an r32_uint 2D-array image. This is one run with the fix against three without it.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321185299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8908#issuecomment-6321185299). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T16:35:52Z. --- Second title for this fix on AMD/Linux, next to the Echoes validation above. **Setup** - Code Violet (PPSA26528) 01.000.028, Linux 7.2.9, RX 6650 XT, RADV (Mesa 26.2.4). - The tree is `main` b5d763770a with #4449 merged locally, plus a local descriptor guard for its imports. This title needs #4449 to import its direct memory at all. - Default settings throughout: no `APS5_UNIT_SHADOW_MIB` and no barrier switches. Same inputs in every run. | Tree | Result | |---|---| | without this PR (3 runs) | `ring gfx_0.0.0 timeout` from the game at ~118, ~120 and ~150 s, then `vkQueueSubmit … Vulkan result -4` | | without this PR, `APS5_NO_BARRIER_BATCH=1` | no timeout in 242 s | | without this PR, `APS5_UNIT_SHADOW_MIB=4096` | no timeout in 242 s; reaches the main menu | | **with this PR** (849c71646f merged on top) | **no timeout in 302 s**, no kernel GPU events, 9725 host imports made and 0 refused | A `RADV_DEBUG=hang` dump of one of the hangs without this PR names a compute pipeline that runs out of time: a 32-thread workgroup with `umax` image atomics into an `r32_uint` 2D-array image. This is one run with the fix against three without it. AI-assisted: yes (Claude Code); results above were run on this machine.
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!8908
No description provided.