agc: the idle flush does not wait for its unit-shadow publish, so a CPU store made before the copy runs is lost (Demon's Souls New Game stall) #7983

Closed
opened 2026-10-19 16:53:43 +00:00 by fisherjoey · 0 comments
fisherjoey commented 2026-10-19 16:53:43 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T16:53:43Z.


What happens

Demon's Souls (PPSA01341 v1.07, Linux, RTX 5070 Ti, NVIDIA 595.91.07): after New Game the level load never starts. Frames keep rendering at about 60 fps on the menu scene for the full 900 s run, and nothing fails or crashes. On our test set it happened in 3 of 4 runs.

Where

The idle flush publishes unit shadows into the host import and does not wait for the copies:

  • VulkanDevice::StoreIdleResults (VulkanDevice.cpp:2171) calls StorageTexture::FlushAllPending("idle") and then SubmitRecorded, which submits without waiting.
  • FlushPending ends with PublishShadow (Texture.cpp:3736). When no image is pending it calls PublishShadowsOnly instead (Texture.cpp:3686, 3899).
  • publishUnits (UnitShadow.cpp:296) collects the tracker, drops every unit the CPU wrote since the retile, and picks the rest. recordCopies (UnitShadow.cpp:227) records the slab to import vkCmdCopyBuffer into the open batch and notes the ranges as pending writes.

The choice of units is made on the CPU, but the bytes reach guest memory only when the GPU runs the copy. A guest store made after the decision and before the copy runs is overwritten with the older shadow bytes. Nothing reads the range through the flush hook at that point, so nothing waits for the pending write. The memory-access hook is different: FlushForAccess waits through SyncThrough right after its flush (Recorder.cpp:1065), before the accessing thread continues.

This is not the window #6364 closed. #6364 waits for unfinished GPU writers before the decision; this window is CPU stores after it. #6960 (@romainveurrier, open) handles the same decision-then-copy window for StorageTexture::writeBackLayers and does not touch UnitShadow.cpp or the publish. #5934 (SONIC SUPERSTARS, guest heap overwritten with texel data) looks like the same family.

Evidence

All runs: Demon's Souls PPSA01341 v1.07, Linux (Nobara, kernel 7.2), RTX 5070 Ti, driver 595.91.07, 900 s from boot through New Game.

The test base is not current main. It is main 93e54cedd plus these local patches: a stencil-export workaround (APS5_IGNORE_STENCIL_EXPORT=1, never upstream), #6280, a cherry-pick of #6567 (merged since), a sampled-texture snapshot sharing patch, an ImportWatched page-digest fix, a port of KytyPS5's job-worker idle sleep (enabled with APS5_JOB_IDLE_SLEEP=1 in all runs below), and a diagnostic that logs CPU stores into blocks a GPU-timeline store had just covered (APS5_TRACE_WB_REUSE=1).

  • Without a wait (4 runs): the level load started in 1 run and stalled in 3. Each stalled run had a single idle or hook publish, during New Game, that stored 67 to 73 64 KiB blocks the CPU wrote afterwards (the diagnostic checked them 252 ms after the decision). The run that loaded had about 16 such blocks. The diagnostic cannot tell whether each CPU store came before or after the copy ran.
  • With the idle and memory-access publishes waiting for their copies under the GPU mutex (4 runs, otherwise the same set): the level load started in 4 of 4. The New Game burst was still there (50 to 62 blocks on one image), with no stall. The largest waited publish was 1034 units, 64.6 MiB, 8.6 to 8.8 ms.
  • A fuller guard that re-checks each block before storing it also gave 4 of 4. It never kept a CPU block, so the wait is what made the difference.
  • Cost: 12.34 presents per 10 s with the wait and 12.34 without (measuring runs, same set family). No measurable difference.

Two crashes on related sets fit the same mechanism, but we have not proven that this path caused them. On main ccb0c0926 with #6567 and the stencil workaround, a SIGSEGV in guest code read pointers from a 64 KiB block filled with RGBA8 texels (0x320e60000, inside a 2048x2048 storage image whose memory the title had reused for heap). On the test base above without the digest fix, the title's allocator asked for 60.88 GiB, a size read from corrupted memory. Neither happened in the 4 runs with the wait, which is too few to rule them out.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5927950034 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7983). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-19T16:53:43Z. --- ### What happens Demon's Souls (PPSA01341 v1.07, Linux, RTX 5070 Ti, NVIDIA 595.91.07): after New Game the level load never starts. Frames keep rendering at about 60 fps on the menu scene for the full 900 s run, and nothing fails or crashes. On our test set it happened in 3 of 4 runs. ### Where The idle flush publishes unit shadows into the host import and does not wait for the copies: - `VulkanDevice::StoreIdleResults` ([VulkanDevice.cpp:2171](https://github.com/boykopovar/AnyPS5/blob/dbac9fa15b6144958d9718c9ee6a649d8ceb8a43/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp#L2171-L2177)) calls `StorageTexture::FlushAllPending("idle")` and then `SubmitRecorded`, which submits without waiting. - `FlushPending` ends with `PublishShadow` ([Texture.cpp:3736](https://github.com/boykopovar/AnyPS5/blob/dbac9fa15b6144958d9718c9ee6a649d8ceb8a43/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L3736)). When no image is pending it calls `PublishShadowsOnly` instead ([Texture.cpp:3686](https://github.com/boykopovar/AnyPS5/blob/dbac9fa15b6144958d9718c9ee6a649d8ceb8a43/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L3686), [3899](https://github.com/boykopovar/AnyPS5/blob/dbac9fa15b6144958d9718c9ee6a649d8ceb8a43/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp#L3899-L3903)). - `publishUnits` ([UnitShadow.cpp:296](https://github.com/boykopovar/AnyPS5/blob/dbac9fa15b6144958d9718c9ee6a649d8ceb8a43/core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp#L296)) collects the tracker, drops every unit the CPU wrote since the retile, and picks the rest. `recordCopies` ([UnitShadow.cpp:227](https://github.com/boykopovar/AnyPS5/blob/dbac9fa15b6144958d9718c9ee6a649d8ceb8a43/core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp#L227)) records the slab to import `vkCmdCopyBuffer` into the open batch and notes the ranges as pending writes. The choice of units is made on the CPU, but the bytes reach guest memory only when the GPU runs the copy. A guest store made after the decision and before the copy runs is overwritten with the older shadow bytes. Nothing reads the range through the flush hook at that point, so nothing waits for the pending write. The memory-access hook is different: `FlushForAccess` waits through `SyncThrough` right after its flush ([Recorder.cpp:1065](https://github.com/boykopovar/AnyPS5/blob/dbac9fa15b6144958d9718c9ee6a649d8ceb8a43/core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp#L1065-L1078)), before the accessing thread continues. This is not the window #6364 closed. #6364 waits for unfinished GPU writers before the decision; this window is CPU stores after it. #6960 (@romainveurrier, open) handles the same decision-then-copy window for `StorageTexture::writeBackLayers` and does not touch `UnitShadow.cpp` or the publish. #5934 (SONIC SUPERSTARS, guest heap overwritten with texel data) looks like the same family. ### Evidence All runs: Demon's Souls PPSA01341 v1.07, Linux (Nobara, kernel 7.2), RTX 5070 Ti, driver 595.91.07, 900 s from boot through New Game. The test base is not current main. It is main 93e54cedd plus these local patches: a stencil-export workaround (`APS5_IGNORE_STENCIL_EXPORT=1`, never upstream), #6280, a cherry-pick of #6567 (merged since), a sampled-texture snapshot sharing patch, an `ImportWatched` page-digest fix, a port of KytyPS5's job-worker idle sleep (enabled with `APS5_JOB_IDLE_SLEEP=1` in all runs below), and a diagnostic that logs CPU stores into blocks a GPU-timeline store had just covered (`APS5_TRACE_WB_REUSE=1`). - Without a wait (4 runs): the level load started in 1 run and stalled in 3. Each stalled run had a single idle or hook publish, during New Game, that stored 67 to 73 64 KiB blocks the CPU wrote afterwards (the diagnostic checked them 252 ms after the decision). The run that loaded had about 16 such blocks. The diagnostic cannot tell whether each CPU store came before or after the copy ran. - With the idle and memory-access publishes waiting for their copies under the GPU mutex (4 runs, otherwise the same set): the level load started in 4 of 4. The New Game burst was still there (50 to 62 blocks on one image), with no stall. The largest waited publish was 1034 units, 64.6 MiB, 8.6 to 8.8 ms. - A fuller guard that re-checks each block before storing it also gave 4 of 4. It never kept a CPU block, so the wait is what made the difference. - Cost: 12.34 presents per 10 s with the wait and 12.34 without (measuring runs, same set family). No measurable difference. Two crashes on related sets fit the same mechanism, but we have not proven that this path caused them. On main ccb0c0926 with #6567 and the stencil workaround, a SIGSEGV in guest code read pointers from a 64 KiB block filled with RGBA8 texels (0x320e60000, inside a 2048x2048 storage image whose memory the title had reused for heap). On the test base above without the digest fix, the title's allocator asked for 60.88 GiB, a size read from corrupted memory. Neither happened in the 4 runs with the wait, which is too few to rule them out. AI-assisted: yes
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#7983
No description provided.