Skip to content

perf(agc): clear a register fast clear without waiting for a known key store - #6247

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:carry/register-clear-wait
Oct 15, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:carry/register-clear-wait

Conversation

@oneandonlydean

Copy link
Copy Markdown
Collaborator

What

materializeRegisterClear (Graphics/src/Draw.cpp) clears the resident image to CB_COLOR_CLEAR_WORD when the target's DCC keys read as the register clear code. Usually those keys come from a key store the driver recorded itself (NoteKeysFillOnGpu) that the GPU has not run yet. FillClear then refuses with keys pending, and the fallback calls Recorder::SyncThrough and waits for that store.

The wait does nothing when the newest recorded writer of the whole key range is that noted store. ProvedCurrentDccKeys has already answered from the same memo (PendingStoreKeys), so the keys the GPU will hold are known, and they are the code this clear stands for. The image clear and the "uncompressed" key store after it go into the same queue behind that store and land after it, which is the order the wait gave.

KnownPendingDccKeys exposes that proof, and the register clear passes it as FillClear's allowRegisterClear (added by #5560 for the metadata pass). The flag skips only the keys pending refusal, and the key scan still runs. Any other pending writer keeps the wait: a title kernel, a later partial or wider write, or a shadowed range.

Related: #5497 notes the keys of a fill kernel's fast clear (the writer side). This PR is the reader side of the register clear and does not overlap it.

Tested

Linux (CachyOS), RTX 4090, driver 610.57.04, Release, SPIRV-Tools on.

  • Tests in tests/Recorder.cpp. agc_pending_key_stores: the proof answers only for a pending noted store that covers the range, not for a wider range, a later writer or an unwritten range. agc_metadata_pass: a clear recorded behind a pending register clear key store is refused without the proof, is taken with it without waiting, and leaves the clear word in memory and uncompressed keys. Both fail to build on main (no KnownPendingDccKeys).
  • ctest -R 'agc_|pm4|recorder': 572 of 573 pass. agc_driver_preparation_scope_settle failed once under -j4 and passes 3 of 3 alone, on main and with this change.
  • tools/check_conventions.py passes.

A 3D title, title screen, menu and first level, 4 gate runs in ABBA order (warm caches, APS5_PROFILE_DRAW=1). Waits from this site (recorded store source, refreshResidentTarget):

run syncs wait
main 1 2042 2.9 s
this 1 0 0
this 2 0 0
main 2 359 0.3 s

Frame rate does not move outside the noise here. For level frames 100..600 the times are 31.8 / 52.0 / 38.8 / 39.2 ms per present (main, this, this, main). Thirteen other main runs of the same commit range from 31.8 to 49.2 ms. Video check passes on all four runs, with 0 torn or stale frames.

A 2D title passes its reference run: menu 24.0 fps, gameplay 25.7 fps, 0 skipped draws, 0 flashes.

DotDebian measured it on Windows 11 (Core Ultra 9 285K, RTX 5080) in the same 3D title: the CPU wait of this path dropped from about 145 to 4 ms per frame, with the same image.

Carried from DotDebian's oneandonlydean#3. Rebased onto current main, which already has the FillClear flag from #5560. The environment switch is dropped.

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 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: none
  • Unblocks: none (performance)
  • GPUs tested: NVIDIA GeForce RTX 4090, driver 610.57.04, Linux; NVIDIA GeForce RTX 5080, Windows 11 (DotDebian)
  • AI-assisted: yes

…y store

materializeRegisterClear clears the resident image to CB_COLOR_CLEAR_WORD
when the target's DCC keys read as the register clear code. Most of the
time those keys come from a key store the driver recorded itself
(NoteKeysFillOnGpu) and the GPU has not run it yet, so FillClear refused
with "keys pending" and the fallback waited for that store (SyncThrough).

The wait buys nothing when the newest recorded writer of the whole key
range is the noted store: ProvedCurrentDccKeys already answered from the
same memo (PendingStoreKeys), so the keys the GPU will hold are known and
are the code this clear stands for. The image clear and the
"uncompressed" key store after it are recorded into the same queue behind
that store and land after it, the order the wait gave.
KnownPendingDccKeys exposes that proof, and the register clear passes it
as FillClear's allowRegisterClear, which skips only the "keys pending"
refusal; the key scan still runs. Any other pending writer (a title
kernel, a later partial or wider write, a shadowed range) keeps the wait.

Tests: the proof answers only for a pending noted store covering the
range, and a clear recorded behind a pending register clear key store
leaves the clear word in memory and uncompressed keys.
@oneandonlydean oneandonlydean self-assigned this Oct 15, 2026
@github-actions github-actions Bot added the agc libSceAgc* label Oct 15, 2026
@oneandonlydean
oneandonlydean merged commit 2c4574a into boykopovar:main Oct 15, 2026
9 checks passed
@milescoviello

Copy link
Copy Markdown
Contributor

agc_pending_key_stores fails on main e49ec59 on Linux (Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti, NVIDIA 595.99), 3 of 3 runs, at the check this PR added:

AGC graphics: a range wider than the pending fill was known, or waited for

Building each first-parent merge since 042eb7c: it passes at 2848b55 and fails from 2c4574a (this merge).

With a temporary print before that line (not committed), KnownPendingDccKeys(address, 2 * surfaceBytes) returns DccKeys::Mixed (keyCount 256), not std::nullopt. Reading PendingStoreKeys, no memo store covers the wider range, so it falls through to KeysAfterPendingWrites, which sees the pending 0001 fill in the first 256 bytes and different bytes after it, and returns Mixed. In materializeRegisterClear that still compares unequal to ClearRegister, so the draw path looks unaffected. Only the test's !has_value() expectation trips.

Inferred, not checked: on a machine where the host import of the test block is refused, the test prints "pending key stores not tested" and returns before this check, which may be why it passed where it was run.

AI-assisted: yes

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.

3 participants