fix(agc): store labels the GPU cannot reach in stream order #2044

Merged
CouchRiv merged 1 commit from upstream-pr/2044 into main 2026-10-10 04:16:20 +00:00
CouchRiv commented 2026-10-09 05:45:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T05:45:25Z.


What

For #1458. Astro Bot stops at submission validation after about 20 s when part of its command memory has no host import:

AGC driver: unsupported PM4 packet type: header 0x00000001 at DWORD 8730 of 10340

A label whose memory the device has no host import of was stored by a completion action of its batch, so it landed only when the batch was reaped. Labels recorded after it were stored by the GPU and became visible first. The title saw those, reused the earlier label's memory for its next command buffer, and the late store then wrote the label's 1 over a RELEASE_MEM header there (EdouardSence traced the write to Recorder::AfterCompletions with a watchpoint).

On the console the CP stores labels in stream order: a later RELEASE_MEM value is never visible before an earlier one. The Linux amdgpu driver relies on this. Its gfx10 fences are RELEASE_MEM writes (gfx_v10_0_ring_emit_fence), and amdgpu_fence_process signals every fence up to the last sequence number it reads.

As oneandonlydean diagnosed, a label the GPU can't store has to be stored at its place in the stream. WriteLabelOnGpu now answers "memory not imported" for such a label in every case, not only with APS5_DRAIN_COMPLETION_LABELS=1. The callers then wait for the recorded work and store it on the CPU. Labels in imported memory are unchanged, and so is a label behind a pending write-back, which the GPU also stores in order. The cost is one wait per label the GPU cannot reach. That is listed in TechnicalDebt. Open #1747 and #1896 add reason == 6 checks, which never match after this change; #1864 edits neighbouring lines in PacketMemory.cpp and DeferredLabels.cpp.

Which title needs it

PPSA21567 (Astro Bot, v01.019.000), from #1458. EdouardSence's runs were on main 6b573862 with #759 merged locally (without #759 it stops earlier, on another error) and APS5_HOST_IMPORT_MIB=64. There it stops at the line above in 3 runs out of 3, and with APS5_DRAIN_COMPLETION_LABELS=1 it runs to the 100 s timeout in 3 runs out of 3. That debug variable stores these labels the same way as this change, and it also turns off label queuing, which this change keeps. We do not have this title and could not run it with this change.

Tested

CachyOS Linux, GCC, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV).

  • New agc_driver_unimported_label_order test. It records a fill, then a label in memory the device has no import of, then a later label in imported memory, and waits for the later one to land. The guest then writes a RELEASE_MEM header over the first label's word, and the test waits for the device to go idle. On main the first label still holds 0 when the later one has landed, and the reused word ends up 0x00000001, the #1458 symptom (3 runs out of 3 on each GPU). With the change it passes 3 runs out of 3 on each GPU.
  • Full ctest: 498/498 on each GPU.
  • check_conventions.py --base origin/main and git diff --check: clean.
  • Not tested: the title itself.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796518577 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2044). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-09T05:45:25Z. --- ### What For #1458. Astro Bot stops at submission validation after about 20 s when part of its command memory has no host import: ``` AGC driver: unsupported PM4 packet type: header 0x00000001 at DWORD 8730 of 10340 ``` A label whose memory the device has no host import of was stored by a completion action of its batch, so it landed only when the batch was reaped. Labels recorded after it were stored by the GPU and became visible first. The title saw those, reused the earlier label's memory for its next command buffer, and the late store then wrote the label's `1` over a `RELEASE_MEM` header there (EdouardSence traced the write to `Recorder::AfterCompletions` with a [watchpoint](https://github.com/boykopovar/AnyPS5/issues/1458#issuecomment-6055410168)). On the console the CP stores labels in stream order: a later `RELEASE_MEM` value is never visible before an earlier one. The Linux amdgpu driver relies on this. Its gfx10 fences are `RELEASE_MEM` writes ([`gfx_v10_0_ring_emit_fence`](https://github.com/torvalds/linux/blob/6c377d19d4a5116d9bec5203aa3c6c11523e7898/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c)), and [`amdgpu_fence_process`](https://github.com/torvalds/linux/blob/6c377d19d4a5116d9bec5203aa3c6c11523e7898/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c) signals every fence up to the last sequence number it reads. As [oneandonlydean diagnosed](https://github.com/boykopovar/AnyPS5/issues/1458#issuecomment-6057226059), a label the GPU can't store has to be stored at its place in the stream. `WriteLabelOnGpu` now answers "memory not imported" for such a label in every case, not only with `APS5_DRAIN_COMPLETION_LABELS=1`. The callers then wait for the recorded work and store it on the CPU. Labels in imported memory are unchanged, and so is a label behind a pending write-back, which the GPU also stores in order. The cost is one wait per label the GPU cannot reach. That is listed in TechnicalDebt. Open #1747 and #1896 add `reason == 6` checks, which never match after this change; #1864 edits neighbouring lines in `PacketMemory.cpp` and `DeferredLabels.cpp`. ### Which title needs it PPSA21567 (Astro Bot, v01.019.000), from #1458. EdouardSence's [runs](https://github.com/boykopovar/AnyPS5/issues/1458#issuecomment-6059891851) were on `main` 6b573862 with #759 merged locally (without #759 it stops earlier, on another error) and `APS5_HOST_IMPORT_MIB=64`. There it stops at the line above in 3 runs out of 3, and with `APS5_DRAIN_COMPLETION_LABELS=1` it runs to the 100 s timeout in 3 runs out of 3. That debug variable stores these labels the same way as this change, and it also turns off label queuing, which this change keeps. We do not have this title and could not run it with this change. ### Tested CachyOS Linux, GCC, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV). - New `agc_driver_unimported_label_order` test. It records a fill, then a label in memory the device has no import of, then a later label in imported memory, and waits for the later one to land. The guest then writes a `RELEASE_MEM` header over the first label's word, and the test waits for the device to go idle. On `main` the first label still holds `0` when the later one has landed, and the reused word ends up `0x00000001`, the #1458 symptom (3 runs out of 3 on each GPU). With the change it passes 3 runs out of 3 on each GPU. - Full ctest: 498/498 on each GPU. - `check_conventions.py --base origin/main` and `git diff --check`: clean. - Not tested: the title itself. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
rmz-24 commented 2026-10-09 12:26:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T12:26:08Z.


Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build plus libs. c9ab6a72 cherry-picked onto current main d70b8998 (applies cleanly).

  • agc_driver_unimported_label_order passes.
  • Full ctest: 511/511.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080847044 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2044#issuecomment-6080847044). Originally posted by [rmz-24](https://github.com/rmz-24) on 2026-10-09T12:26:08Z. --- Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`, full build plus `libs`. c9ab6a72 cherry-picked onto current `main` d70b8998 (applies cleanly). - `agc_driver_unimported_label_order` passes. - Full ctest: 511/511. AI-assisted: yes
github-actions[bot] commented 2026-10-09 22:07:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:07:08Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1157 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/SynchronizationStatistics.cpp L42
#1864 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp L40-41, L120-121
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090052366 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2044#issuecomment-6090052366). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:07:08Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1157 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/SynchronizationStatistics.cpp` [L42](https://github.com/boykopovar/AnyPS5/blob/c72d5ce112194139b32f5587634c7cbaf4a6f9f3/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/SynchronizationStatistics.cpp#L42) | | | | #1864 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp` [L40-41](https://github.com/boykopovar/AnyPS5/blob/c72d5ce112194139b32f5587634c7cbaf4a6f9f3/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp#L40-L41), [L120-121](https://github.com/boykopovar/AnyPS5/blob/c72d5ce112194139b32f5587634c7cbaf4a6f9f3/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp#L120-L121) | | |
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!2044
No description provided.