Skip to content

perf(agc): store an unimported label at once when unfinished work leaves guest memory alone - #24162

Closed
LeandroLP23 wants to merge 19 commits into
boykopovar:mainfrom
LeandroLP23:perf/agc-early-labels
Closed

LeandroLP23 wants to merge 19 commits into
boykopovar:mainfrom
LeandroLP23:perf/agc-early-labels

Conversation

@LeandroLP23

Copy link
Copy Markdown
Contributor

What

Tested

Windows 11 (10.0.26300), AMD Radeon 860M (AMD 26.10.2, LLPC), WinLibs GCC 15.2.0 r7, Release. "Base" is this branch without the last commit (416d72bcb5: main e825fa1492 + #7464), "this PR" is bd5ab55c5a.

  • ctest -R '^agc_driver_(recorder|graphics|unimported_label_order|same_queue_label_wait|cpu_label_wake|copied_writer_label_order|pipelined_dma|host_import_windows)' -V with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer (layer 1.4.363): 18 of 18 pass on both builds, the layer inserted in every log, no was not found but was requested, 0 VUID- lines. agc_driver_copied_writer_label_order and its _drain form skip on both (this device).

  • SuperTuxKart (PPSA69421) menu through tools/title_run.py, 2 runs of 45 s per build, APS5_PROFILE_DRAW=1, steady-state 10 s windows:

    build presents per 10 s frame p50
    base 119–145 66–69 ms
    this PR 154–179 55–57 ms

    [early-labels]: 16,311 and 25,781 labels stored at once per run; 2,967 and 4,674 waited because unfinished work read guest memory in place, about 144 because it wrote it.

  • Traces (APS5_TRACE_SECONDS=20:8 APS5_TRACE_EVENTS=1048576, one run each, title_run's frame dumps on in both), tools/trace_digest.py:

    • base: 98 presents, frame p50 74.7 / p90 105.3 / p99 240.8 ms, draw committer busy 49 %, Recorder.Sync 26.9 ms per frame.
    • this PR: 150 presents, frame p50 53.2 / p90 57.1 / p99 62.6 ms, draw committer busy 31 %, Recorder.Sync no longer among its largest slices.

base (416d72bcb5):

{"commit":"416d72bcb5d5","dirty":false,"env":{"APS5_DUMP_FRAMES":"100000","APS5_DUMP_FRAMES_EVERY":"30","APS5_DUMP_SCALE":"8","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"20:8","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon(TM) 860M Graphics","driver":"AMD proprietary driver 26.10.2 (LLPC)","os":"Windows 10.0.26300","cpu":"AMD Ryzen AI 7 350 w/ Radeon 860M","cpu_threads":16,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 20:8","first_present":140,"ms":8030.275},"presents":98,"frame_ms":{"p50":74.722,"p90":105.25,"p99":240.849,"max":240.849},"gpu_busy_ms_per_present":12.36,"worker_busy_pct":{"queue worker 0x0":4.318},"trace_dropped":false,"trace":"aps5-trace-416d72bcb5d5-3340.json.gz"}

this PR (bd5ab55c5a):

{"commit":"bd5ab55c5a4f","dirty":false,"env":{"APS5_DUMP_FRAMES":"100000","APS5_DUMP_FRAMES_EVERY":"30","APS5_DUMP_SCALE":"8","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"20:8","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon(TM) 860M Graphics","driver":"AMD proprietary driver 26.10.2 (LLPC)","os":"Windows 10.0.26300","cpu":"AMD Ryzen AI 7 350 w/ Radeon 860M","cpu_threads":16,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 20:8","first_present":170,"ms":8047.335},"presents":150,"frame_ms":{"p50":53.173,"p90":57.064,"p99":62.552,"max":67.355},"gpu_busy_ms_per_present":14.229,"worker_busy_pct":{"queue worker 0x0":6.37},"trace_dropped":false,"trace":"aps5-trace-bd5ab55c5a4f-9588.json.gz"}

Not run: the whole CTest suite, other titles, other GPUs.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: perf(agc): keep unimported label stores on the CPU #7464
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon 860M, AMD 26.10.2 (LLPC), Windows 11 (10.0.26300)
  • AI-assisted: yes

Dripl1x and others added 19 commits October 22, 2026 09:35
…orts

An import covers a run of adjacent registered allocations. When
VirtualAlloc placed the temporary block right after the 128 KiB-aligned
labels block, the labels import also covered the temporary block, the
eight-byte label correctly went to the GPU and the case failed (4 of 12
runs in review). The temporary block is now registered between two
unregistered 64 KiB guards of its own allocation, so no import made for
another block can cover it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unimported label path synced the recorder: it submitted the open
batch and waited for every batch in flight under the GPU mutex, running
their completion actions. A compute worker must never run them (labels
from other queues only submit), and the sync waited forever on a batch
whose submit was held on a semaphore that only a later submission
releases: agc_driver_indirect_arguments_pending_producer timed out in
its argument-label case, which needs the label imported and recorded on
the GPU.

The path is now taken only for queue 0 while no submit is held (a hold
armed for the next submit, or a held batch the GPU has not finished).
Other labels import their memory and are recorded on the GPU, as on
main. UnimportedLabelOrder covers a compute-queue label and a label
behind a held batch, each of which must be recorded without a submit or
a wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eir own

The unimported path returned 1, the code of a label the CPU stores
because nothing is recorded, so the [sync] line counted its labels as
idle fallbacks and its stores as idle CPU stores. It now returns 7,
which every caller handles as it handles 1 (the CPU writes the bytes
without a device wait, and the label is noted and wakes short sleeps
where 1 does), and the [sync] line counts it separately as "no covering
import (recorder synced)" among the fallbacks and "on the CPU with no
covering import (recorder synced)" among the stores. PipelinedDma counts
these stores with the other committed ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rces

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since boykopovar#8180 a label of 8 bytes or less goes behind the completions while a
copied writer is listed or a completion store is pending: a completion
action stores it on the CPU when its batch is reaped, which needs no host
import. The unimported check ran first and synced the recorder for such a
label (reason 7), the wait boykopovar#8180 avoids.

The unimported path now takes the same completion gate first (reason 5, or
2 with APS5_DRAIN_COMPLETION_LABELS=1) and syncs only when it does not
apply; imported labels take it where they did.

CopiedWriterLabelOrder checks the imported paths boykopovar#8180 added, so its label
block is now imported before the passes (on main every label it stores
gets an import); a new pass stores a label to a block that stays
unimported (unregistered pages on both sides keep imports of its
neighbours off it) behind a copied writer and expects reason 5, or 2 with
the drain. Without the fix that pass fails with reason 7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	core/libs/prx/libSceAgcDriver/CMakeLists.txt
#	core/libs/prx/libSceAgcDriver/tests/execution/SameQueueLabelWait.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A label whose memory no guest range covers keeps the behaviour main
gives it: stored on the GPU through an import of the unregistered
memory when nothing is listed or pending, otherwise drained (reason
3), also for read-only memory. Only a label in guest memory that no
import covers takes the recorder-sync CPU path.
…Memory

PacketMemory.cpp: the CPU store branch takes the synced unimported store (reason 7) beside main's GPU-clock COPY_DATA store (reason 3 with no store pending over the range); reason 7 counts as a synced unimported store, the others as CPU stores.
SameQueueLabelWait.cpp: both sides' includes are kept.
Keep main's clock_getres entry and this branch's short sleeps entry.
# Conflicts:
#	core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp
…ves guest memory alone

An unimported queue-0 label synced the recorder before its CPU store, so
every batch had finished first. Only what that work does to guest memory
can tell the two orders apart: a batch that reads guest memory in place (a
store landing first would be read), writes it (the guest would read the old
bytes after seeing the label), or has completion actions. Work that leaves
guest memory alone, such as draws from copied inputs into host-side
targets, cannot be observed by the guest before or after the label.

Recorder::UnfinishedGuestTouch reports what the open batch and the in-flight
batches whose fences have not signaled still do: in-place reads, noted
writes and labels, stores or sample dumps still to record, and completion
actions (also of signaled batches, and of batches another thread is
finishing). WriteLabelOnGpu stores the label at once (reason 7) when nothing
is reported, and syncs as before otherwise. APS5_NO_EARLY_LABELS=1 always
syncs. APS5_PROFILE_DRAW prints an [early-labels] line with the counts by
reason.

The open batch is left open and the reap of finished batches is put off:
nothing depends on either before the store. The caller submits and reaps
through SubmitAfterEarlyLabel once the label is stored, its waiters woken
and an end-of-pipe interrupt delivered; every caller that stores a reason-7
label calls it (the committer's label commit through submitDueAfterCommit).
With no completion action in any unfinished batch the reap neither changes
the import table nor what the label waits for.

Draws noted every in-place region of their resources as read, also the
regions of read-only elements that PrepareDrawBindings bound to snapshots,
which the GPU never reads in place. MarkGpuWrites now leaves out a region
that only snapshotted allocations overlap (every buffer element is a
descriptor of one allocation; a BDA build gets no draw bindings and keeps
noting every region).

SuperTuxKart (PPSA69421) main menu without the tutorial prompt (about 33
draws a frame) on Windows 11, RTX 3070 Laptop, Ryzen 7 5800H; main 9d4fb4f with boykopovar#7464 and boykopovar#9402, this commit and three other
local changes (an idle spin of the queue worker and committer, Windows
imports over 64 KiB settled at the import, import refresh spans diffed in
place); protocol runs interleaved, 3 each. With APS5_NO_EARLY_LABELS=1:
58.69 / 59.28 / 57.44 FPS, 8 / 7 / 18 present intervals over 20 ms, and
38 / 171 / 8 of about 470 frames waited for their vblank. With early
labels: 59.94 FPS in all three (the title's vblank cap), no interval over
20 ms, every frame waited for its vblank, and the longest idle gap of
queue worker 0 and the committer per frame went from 0.4 ms to 6.7-7.0 ms
(median). APS5_PROFILE_DRAW, cumulative over a run: 27090 labels stored
at once, 58 waited (42 for an in-place read, 1 for a write, 15 for
completion actions). boykopovar#7464's branch on the same main (with boykopovar#7465 under it,
without boykopovar#9402 and the other changes): 48.75-49.89 FPS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Nov 20, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head bd5ab55c5a4fdfc2598cfcdacb9ee011482a1d01 using the prepared diff and repo_read.py. No test commands were run in this environment. The author reports 18/18 targeted CTest cases passing on both builds, with two device-specific skips, plus SuperTuxKart performance measurements; these results were not independently reproduced here.

Results

Check Result Note
Diff and targeted source review passed Core label and recorder paths inspected
Tests in this environment not run Author-reported results only
Full suite and other GPUs not run Not reported by author

Findings

Blocking

None.

Non-blocking

None.

Not verified

The review bundle includes full text for 13 of 16 changed files. VulkanDevice.cpp, ShaderResources.cpp, and tests/Recorder.cpp were excluded from the bundle as too large; relevant changed ranges in the first two were read through repo_read.py, but tests/Recorder.cpp was not read. No local tests, build, or hardware run was performed. The author reports the full CTest suite, other titles, and other GPUs were not tested.

To get this to a good state

Nothing is required.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@LeandroLP23 one gap in the early label check: a sampled texture built from host import copies (sources, filled from gpuSources in ShaderResources.cpp) reads the surface's guest range with CopyBuffer in the Texture constructor (Texture.cpp, the if (!sources.empty()) copy loop) but never notes a pending read. Once the batch that wrote that range has signalled, an unimported label can be stored while the open batch is still copying from it, and the guest may overwrite bytes the texture has not read yet.

The storage upload path already notes this (NotePendingRead(..., ReadKind::StorageUpload) near line 3637). I think the same line in the constructor's recorder branch closes it:

if (staging != nullptr || !sources.empty()) {
    ...
    if (!sources.empty()) recorder->NotePendingRead(descriptor.baseAddress, static_cast<std::size_t>(guestBytes), Recorder::ReadKind::StorageUpload);
}

A test with an import-sourced texture and an unimported label would pin it. Separately, the perf numbers would be easier to weigh as paired runs against the scene's noise floor.

@LeandroLP23

Copy link
Copy Markdown
Contributor Author

Thanks, confirmed: with #7464 alone the label waited for the recorder sync, so the copy had finished; storing it early opens this. Dripl1x asked to keep the review on #10442, so I'm closing this PR. The NotePendingRead in the constructor's recorder branch and a test with an import-sourced texture and an unimported label go on the branch for #10442, and I'll redo the numbers as interleaved pairs.

AI-assisted: yes (Claude Code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs perf numbers missing perf pull request without a before and after summary line perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants