Skip to content

perf(agc): keep label stores larger than 64 bytes out of the label table - #627

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:perf/agc-large-label-stores
Oct 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:perf/agc-large-label-stores

Conversation

@oneandonlydean

@oneandonlydean oneandonlydean commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

What

Recorder::NoteLabel enters every dword of a recorded label store in the pending-label table. A store larger than 64 bytes (the bound the driver's own label history already uses) now enters one range instead of its dwords:

  • table entries inside the range are removed, as the store replaced them: a lookup there finds no value and falls back to the pending-write path, where it used to find the store's value;
  • the range leaves with its batch, like the dword entries;
  • PendingLabelIn sees the range, and the write-evidence check, which syncs a capture read over any pending label dword, now also syncs over a pending range (Recorder::WideLabelIn).

The store is still a pending write of the open batch (the flush hook syncs CPU readers), still starts the label flush deadline, and is recorded exactly as before. Stores of 64 bytes or less are unchanged.

Why it is exact: the table serves WAIT_REG_MEM values and CPU pollers, which read 4 or 8 bytes. Inside a wide store's range such a reader now takes the pending-write path, which waits for the store instead of taking its value from the table.

Why

PPSA21564 clears each occlusion query slot with a 256-byte WRITE_DATA before its begin dump, about 8,400 times per frame in one level. That clear is larger than a deferred label, so it is recorded at once, and each one cost 64 map inserts, 64 batch entries and 64 group entries, then 64 lookups when the label group closes and 64 erases when the batch is reaped. A replay of that pattern (21 clears per batch, 20 batches in flight) costs 1.6 us for the inserts, 0.7 us for the close and 1.3 us for the erases per clear; the new path costs 0.07 us per clear.

Measured in that level on my integration branch, together with #628 (the query entry points). The FPS gain was only measured with both; each packet's time is its own:

before with both
fps (2 runs each) 3.78 4.48 (+18.5%)
WRITE_DATA ms per present (this PR; profiled runs) 33.1 5.5
EVENT_WRITE ms per present (#628; profiled runs) 28.4 10.6
graphics worker busy, ms per present (profiled runs) 276.9 225.3

Tested

  • Linux (CachyOS, x86-64, GCC): full build with BUILD_TESTING=ON; ctest passes (268/268).
  • agc_driver_recorder_tests (needs a GPU, not in ctest) passes, with the new largeLabelTests:
    • a 256-byte label enters no dwords, and removes the older entry under it but not the one beside it;
    • its range, pending write and flush deadline;
    • a later 4-byte label over it is served;
    • a 64-byte label is entered in full and served;
    • nothing is left after the batch.
  • With the old behaviour forced back (every store enters its dwords), largeLabelTests fails.
  • PPSA21564 with both PRs: my visual regression check passes twice with equal or higher FPS in every scene, and 0 GPU faults in the 15 runs of that session.

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 (pays off together with perf(agc): resolve the recorder's query and fold entry points once #628)
  • AI-assisted: yes

PPSA21564 clears each occlusion query slot with a 256-byte WRITE_DATA
before its begin dump, about 8,400 times per frame in one level. The
clear is larger than a deferred label, so it is recorded at once, and
Recorder::NoteLabel entered all 64 of its dwords in the pending-label
table: 64 map inserts, 64 batch dword entries and 64 group entries, then
64 lookups in CloseLabelGroup and 64 erases when the batch is reaped. A
replay of that pattern (21 clears per batch, 20 batches in flight) costs
1.6 us for the inserts, 0.7 us for the close and 1.3 us for the erases
per clear, about 31 ms of the graphics worker per frame there. The new
path costs 0.07 us per clear in the same replay.

The table serves WAIT_REG_MEM values and CPU pollers, which read 4 or 8
bytes. A store larger than 64 bytes (the bound the driver's own label
history already uses) now enters one range instead of its dwords:
- table entries inside the range are removed, as the store replaced
  them before: a lookup there finds no value and falls back to the
  pending-write path, where it used to find the store's value;
- the range leaves with its batch, like the dword entries;
- PendingLabelIn sees the range, and the write-evidence check, which
  syncs a capture read over any pending label dword, now also syncs
  over a pending range (Recorder::WideLabelIn).
The store is still a pending write of the open batch (the flush hook
syncs CPU readers), still starts the label flush deadline and is
recorded exactly as before. Stores of 64 bytes or less are unchanged.

Test: agc_driver_recorder_tests largeLabelTests (a 256-byte label enters
no dwords and removes the older entry under it but not one beside it,
its range, pending write and deadline, a later 4-byte label over it,
a 64-byte label entered in full, everything gone after the batch).
@oneandonlydean
oneandonlydean merged commit c760129 into boykopovar:main Oct 5, 2026
3 checks passed
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 5, 2026
Takes upstream's merged versions of our boykopovar#586 boykopovar#611 boykopovar#612 boykopovar#505 boykopovar#490 boykopovar#619
boykopovar#503 boykopovar#627 boykopovar#628 boykopovar#618 and drops astrobot's local copies, plus gate-batch-3
(boykopovar#469 boykopovar#500 boykopovar#504 boykopovar#509 boykopovar#510 boykopovar#514 boykopovar#525 boykopovar#526 boykopovar#528), round o/p (boykopovar#617 boykopovar#620
boykopovar#621 boykopovar#622 boykopovar#623 boykopovar#624 boykopovar#501 boykopovar#508 boykopovar#629 boykopovar#630 boykopovar#631).

Conflicts:
- SpirvAnalysis.hpp/.cpp, SpirvBufferAccess.cpp: upstream's boykopovar#586/boykopovar#612.
  The 64-bit LDS atomics keep the full array (f27d6e5 no longer needed).
- SpirvMemoryInstructions.cpp: upstream's constant slot plus offset;
  astrobot's split-wave append/consume kept.
- GuestTextureResource.cpp, TextureTiling.cpp and their tests: upstream's
  boykopovar#490/boykopovar#503 (astrobot had no other change there).
- MaskedSelect.cpp test, ShaderMemory.cpp LDS test: upstream's.
- State.cpp: upstream's boykopovar#505 export count and boykopovar#469 null pixel program;
  astrobot's depth export rejection and depth target model kept.
- Pipeline.cpp: upstream's pipeline key; astrobot's depth attachment and
  blend check (a trailing unused attachment stays valid, as
  colorGapPipelineTests expects).
- Draw.cpp, Recorder.cpp, ShaderResources.cpp: astrobot's (renderPassKey
  with depth, moved sample functions, residency maintenance), which
  already hold the merged boykopovar#505/boykopovar#628/boykopovar#490 changes.
- ShaderInputState.cpp: both register sets.
- State.hpp: the duplicate exportIndex member from the auto-merge removed.
- CMakeLists.txt: astrobot's test list (a superset of upstream's).
- tests/Graphics.cpp: upstream's CompactedExportTests replaces astrobot's
  inline copy; tests/Recorder.cpp: upstream's viewPastLastMipTests added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant