perf(agc): draw templates rebind moved read-only buffers and data words #424

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/424 into main 2026-10-04 05:49:08 +00:00
MichonGoddijn231849 commented 2026-10-02 23:33:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-02T23:33:25Z.


What

A draw resource template is keyed by every descriptor word of its stages. Titles that stream constants and vertices through rings move their buffers on every draw, so the V# base and size of read-only buffers, and the ShaderData/FlattenedSrt words, differ for each draw. Templates then never hit, and every draw built its resources from scratch.

  • Key: ContentKey gains movableBuffers. Read-only GuestBuffers elements are keyed by their layout bits only ({0, w1 & 0xffff0000, 0, w3}), and data-role words leave the key.
  • Hit: MovedReadOnlyBuffers compares the template's bindings with the draw's:
    • a moved read-only buffer is rebound from its new address, keeping the template's push adjustment, when it is accessible and no write, pending storage write or shadowed write overlaps it;
    • changed data words get a fresh data buffer with the template's data patches applied.
    • If any buffer cannot be rebound, the draw counts as a miss and builds fresh. A template that no longer validates is removed as before.
  • Record: PrepareDrawBindings takes the moved buffers and snapshots them from their new ranges. A draw that is not recorded lean rebuilds its resources, so nothing changes for synchronous draws.

APS5_NO_MOVED_BUFFER_TEMPLATES=1 keys the words as before.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • ctest: all tests pass.
  • GTA V (PPSA04264), Prologue, APS5_PROFILE_DRAW=1:
    • template hits went from almost none to 99% of draws;
    • Graphics::Draw dropped from 37.6 to 26.1 µs per draw packet;
    • together with flat register banks (the idea of #408), unprofiled fps went from 10.5 to 14.5;
    • the scene renders as before.
    • Measured on my branch that combines this change with my other open PRs.

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4722561482 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/424). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-02T23:33:25Z. --- ### What A draw resource template is keyed by every descriptor word of its stages. Titles that stream constants and vertices through rings move their buffers on every draw, so the V# base and size of read-only buffers, and the ShaderData/FlattenedSrt words, differ for each draw. Templates then never hit, and every draw built its resources from scratch. - **Key:** `ContentKey` gains `movableBuffers`. Read-only `GuestBuffers` elements are keyed by their layout bits only (`{0, w1 & 0xffff0000, 0, w3}`), and data-role words leave the key. - **Hit:** `MovedReadOnlyBuffers` compares the template's bindings with the draw's: - a moved read-only buffer is rebound from its new address, keeping the template's push adjustment, when it is accessible and no write, pending storage write or shadowed write overlaps it; - changed data words get a fresh data buffer with the template's data patches applied. - If any buffer cannot be rebound, the draw counts as a miss and builds fresh. A template that no longer validates is removed as before. - **Record:** `PrepareDrawBindings` takes the moved buffers and snapshots them from their new ranges. A draw that is not recorded lean rebuilds its resources, so nothing changes for synchronous draws. `APS5_NO_MOVED_BUFFER_TEMPLATES=1` keys the words as before. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - `ctest`: all tests pass. - GTA V (PPSA04264), Prologue, `APS5_PROFILE_DRAW=1`: - template hits went from almost none to 99% of draws; - `Graphics::Draw` dropped from 37.6 to 26.1 µs per draw packet; - together with flat register banks (the idea of #408), unprofiled fps went from 10.5 to 14.5; - the scene renders as before. - Measured on my branch that combines this change with my other open PRs. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!424
No description provided.