Skip to content

fix(agc): satisfy label waits from stores made after their submission - #178

Merged
boykopovar merged 2 commits into
boykopovar:mainfrom
oneandonlydean:fix/agc-label-waits-after-submission
Oct 1, 2026
Merged

boykopovar merged 2 commits into
boykopovar:mainfrom
oneandonlydean:fix/agc-label-waits-after-submission

Conversation

@oneandonlydean

@oneandonlydean oneandonlydean commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

What

Two commits on the same topic: when a WAIT_REG_MEM counts as satisfied.

Stores made after the wait's submission. A title may reclaim a label (reset it to 0) as soon as the submission that released it is done, trusting every queue waiting on it to have passed its WAIT_REG_MEM within microseconds: the CP polls from the moment it reaches the wait. Our queue workers can reach a later wait of a submission much later (they record and compile in between), find the reset label and time out. A memory wait now also passes when:

  • a label store the driver committed after the wait's submission (recorded on the GPU, as a completion action, or on the CPU; Driver::noteLabelStore keeps the last four stores per dword with their eventSerial stamps) gave the awaited bytes a value the wait accepts (Driver::storedSince). Such a store belongs to this use of the label or a later one, since the title reset it before submitting. A store made before the submission never satisfies the wait.
  • the awaited bytes held such a value when the game submitted, and no earlier packet of the same queue (earlier in the submission, or in one still queued or running) stores to them (noteHeldAtSubmit, checked under the submit mutex; the unfinished stores are counted per worker and forgotten when their submission completes).

The ordering argument is the one the recorder's label table already uses for Submission::received.

64-bit waits. A WAIT_REG_MEM_64 whose mask leaves the high dword out compares the low dword alone, but the wait paths looked for all eight bytes: the recorder's label table and the stores above want an entry for each dword, while a producer's RELEASE_MEM/WRITE_DATA stores 32 bits. Pm4::WaitAwaitedBytes gives the bytes that decide the compare (4 for WAIT_REG_MEM and for a WAIT_REG_MEM_64 with a zero high mask dword, else 8), and the wait paths use it. The timeout report now prints a 64-bit wait's reference and mask (it printed the reference's two halves as "ref" and "mask").

In PPSA21564 the async compute submissions wait on the same label up to five times between dispatches, and wait with WAIT_REG_MEM_64 (mask ffffffff:0) on queue 0's 32-bit labels. The intro stalled on 1 s GPU wait timeouts (15 in 200 s).

Rebased onto current main after #138: the CPU fallback in Driver.cpp now notes a label store after Pm4::Execute and then delivers #138's end-of-pipe interrupt, and the new tests sit after testEndOfPipeInterrupts in tests/Submit.cpp.

Tested

  • Linux (CachyOS, RTX 4090): agc_driver (tests/Submit.cpp) gets three cases that submit to a compute queue held behind a gate, let a graphics-queue WRITE_DATA store the label, reset the label from the CPU, then open the gate:
    • testLabelStoredSinceSubmission: the consumer passes within 500 ms; a wait submitted after the store still times out (about 1 s).
    • testLabelHeldAtSubmission: a wait whose value memory held at submission passes after a reset; one behind its own queue's earlier store to the label does not.
    • testWideLabelStoredSinceSubmission: a low-dword 64-bit wait passes on a 32-bit store; with the high dword in its mask it does not.
  • On main the first case fails with "a label stored after the wait's submission did not satisfy it". With the first commit only, the third fails with "a 32-bit label stored after a low-dword 64-bit wait's submission did not satisfy it". Skipping heldAtSubmit makes the second fail.
  • Exercised in PPSA21564 on our integration branch: the intro, title and NEW GAME menu run with no GPU wait timeout.
  • ctest: 79/79 pass on current main. agc_driver_recorder_tests, agc_driver_graphics_tests and agc_driver_pm4_tests pass.

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Sep 30, 2026
…, boykopovar#129) into astrobot

Conflicts resolved:
- Shader disk cache (boykopovar#129 as merged upstream): upstream's version, plus
  astrobot's imageDepthCompare and waveLayout fields (format 3).
- Shader fusion: upstream's fd4700b replaces astrobot's boykopovar#124 version.
- -KRzWekV120: upstream's export replaces astrobot's; its test now calls
  sceAgcUnknown__MKRzWekV120.
- Misaligned buffer views: upstream's push-constant adjustment (3dec6ce)
  replaces astrobot's view aliases; GuestBufferMemory is the rebased boykopovar#121
  version (write watch on shared direct memory).
- DirectMemory: rebased boykopovar#121 (re-register after the shared-backing remap,
  aliased pages leave the watch) plus boykopovar#164's per-piece unmap.
- Depth: astrobot's DepthTarget model is kept for attachments; upstream's
  DepthSurface module is dropped (it would duplicate it). Upstream's
  mip-chain colour targets, CB_COLOR_VIEW MIP_LEVEL at bits 26-29 and
  export formats are taken into DecodeColorBuffer.
- GPU-selected V#s: upstream's gpuDescriptor replaces astrobot's opt-in
  runtimeDescriptor; image_bvh_intersect_ray is upstream's.
- Occlusion counter dumps: upstream's Vulkan occlusion queries replace
  astrobot's always-visible PIXEL_PIPE_STAT dump.
- AudioOut2 DualSense ports: rebased boykopovar#180 on upstream's 16-bit ports.
- Pixel stage decode: rebased boykopovar#136; mesh push constants: rebased boykopovar#133.
- Label waits (boykopovar#178): noteHeldAtSubmit moved into reserveOutputs.
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed agc libSceAgc* labels Sep 30, 2026
A title may reclaim a label (reset it to 0) as soon as the submission
that released it is done, trusting every queue waiting on it to have
passed its WAIT_REG_MEM within microseconds, as the CP polls from the
moment it reaches the wait. A worker that reaches a later wait of the
same submission long after (it records and compiles in between) found
the reset label and timed out.

A memory wait now also passes when
- a label store the driver committed (recorded on the GPU, as a
  completion action, or on the CPU) after the wait's submission gave the
  awaited bytes a value the wait accepts (the last four stores per dword,
  with their eventSerial stamps). Such a store belongs to this use of the
  label or a later one, since the title reset it before submitting.
- the awaited bytes held such a value when the game submitted, and no
  earlier packet of the queue (in the submission, or one still queued or
  running) stores to them.

A store made before the submission never satisfies a wait.
A WAIT_REG_MEM_64 whose mask leaves the high dword out compares the low
dword alone, but the wait paths looked for all eight bytes: the
recorder's label table and the stores committed since the submission
want an entry for each dword, while a producer's RELEASE_MEM or
WRITE_DATA stores 32 bits, so neither ever satisfied such a wait, and the
held-at-submission check refused it when an earlier packet stored the
unrelated high dword.

Pm4::WaitAwaitedBytes gives the bytes that decide the compare (4 for
WAIT_REG_MEM and for a WAIT_REG_MEM_64 whose high mask dword is zero,
else 8), and the wait paths use it. The timeout report now prints a
64-bit wait's reference and mask (it printed the reference's two halves
as "ref" and "mask").
@oneandonlydean
oneandonlydean force-pushed the fix/agc-label-waits-after-submission branch from ab8ec68 to a36ef52 Compare September 30, 2026 19:48
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Sep 30, 2026
@boykopovar
boykopovar merged commit e0b9236 into boykopovar:main Oct 1, 2026
3 checks passed
@oneandonlydean
oneandonlydean deleted the fix/agc-label-waits-after-submission branch October 1, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants