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

Merged
oneandonlydean merged 1 commit from upstream-pr/6247 into main 2026-10-15 09:47:16 +00:00
oneandonlydean commented 2026-10-15 07:07:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-15T07:07:17Z.


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/AnyPS5#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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4869565525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6247). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-15T07:07:17Z. --- ### 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/AnyPS5#3. Rebased onto current `main`, which already has the `FillClear` flag from #5560. The environment switch is dropped. ### Checklist - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Unblocks: none (performance) - [x] GPUs tested: NVIDIA GeForce RTX 4090, driver 610.57.04, Linux; NVIDIA GeForce RTX 5080, Windows 11 (DotDebian) - [x] AI-assisted: yes
milescoviello commented 2026-10-15 10:26:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T10:26:26Z.


agc_pending_key_stores fails on main e49ec591d 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 042eb7c80: it passes at 2848b55b9 and fails from 2c4574adf (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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6189922105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6247#issuecomment-6189922105). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-15T10:26:26Z. --- `agc_pending_key_stores` fails on `main` e49ec591d 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 042eb7c80: it passes at 2848b55b9 and fails from 2c4574adf (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 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!6247
No description provided.