Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
CouchRiv:fix-agc-completion-label-pm4
Oct 10, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
CouchRiv:fix-agc-completion-label-pm4

Conversation

@CouchRiv

@CouchRiv CouchRiv commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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 6b57386 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 PPSA21567: submission stops on "unsupported PM4 packet type: header 0x00000001" where a RELEASE_MEM header is expected #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

A label in memory the device has no host import of was stored when its
batch was reaped, after later labels the GPU had already made visible.
A title that reused that memory saw its next command buffer overwritten
by the stale value (boykopovar#1458). Wait for the recorded work and store it then.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@rmz-24

rmz-24 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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. c9ab6a7 cherry-picked onto current main d70b899 (applies cleanly).

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

AI-assisted: yes

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

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

@oneandonlydean
oneandonlydean merged commit 17874f1 into boykopovar:main Oct 10, 2026
6 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…abel-pm4

fix(agc): store labels the GPU cannot reach in stream order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants