Skip to content

perf(agc): reuse cached draw stages when only buffer base addresses moved - #39

Open
Thimo188 wants to merge 8 commits into
mainfrom
upstream-pr/5609
Open

Thimo188 wants to merge 8 commits into
mainfrom
upstream-pr/5609

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#5609, originally opened by TheAggie.

Source commit: 09238da8206e0aa70d8966c69f822c297da36308. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Second step for boykopovar#4054, stacked on boykopovar#4943. That PR finds a cached draw when the user-data pointers moved and the data behind them is equal. A guest driver that keeps its buffer descriptors in a table reached through such a pointer (RADV's descriptor sets) still missed on every draw whose buffers moved, because the descriptor's base address is among the words a stage is validated against.

  • A stage whose captured words differ from the cached ones only in buffer base addresses is reused: the base words of the bound buffers are patched in the cached result, and the buffers themselves are read by the draw as usual, so their contents stay out of the match.
  • Cached stages are relocated one by one, keyed by their prepared shader, so a draw can take its vertex stage from one earlier draw and its pixel stage from another.
  • A patched stage replaces its donor, so the next draw with the same bases matches without another patch.
  • Reusing draw snapshots across draws that nothing wrote between was a commit of this PR; it landed on its own as perf(agc): reuse draw snapshots across draws that nothing wrote between boykopovar/AnyPS5#5906.
  • The second-sight admission (perf(agc): cache a draw key the second time it is seen boykopovar/AnyPS5#5216) counts a repeat of a stage's relocated contents as a second sighting, since a draw's stages are now matched one by one.
  • At their limit the stage donor and decode maps drop every other entry, not all of them.
  • The shader disk cache carries the new bufferBaseSlots field of a result, and its Linux-only size asserts expect the grown structs.
  • Two per-draw costs that showed up once the cache hit: the dynamic state of an open render pass is only set again when it changed, and AnyPendingOverlaps consults the pending image range index first. The state the filter compares against is kept per command buffer, in the recorder batch's open render pass: it is reset when a new pass starts and marked unknown after the back-face and second-channel splits and after stencil replay (which sets the stencil reference itself).
  • A stage that upstream's stage-data hits would verify (APS5_VERIFY_DRAW_DATA_HITS=1) is left to that verification instead of being reused.

APS5_NO_DRAW_RELOCATION=1 turns the relocation off, APS5_NO_DRAW_STATE_FILTER=1 the dynamic state filter.

Only the commits after boykopovar#4943's head are this PR.

Tested

Windows 11, NVIDIA GeForce RTX 5070 Ti, MinGW-w64 GCC 15.2.0, rebased on main 940eba9a2.

  • ctest: 1270 of 1292 pass, 14 skipped. guest_call_trace_abort, windows_backtrace_report and agc_driver_store_over_untracked fail, and fail the same way on plain main here. agc_driver_prepared_shaders_debug failed once in a parallel run and passes alone. Three newer tests, agc_driver_prepared_graphics_prebuild_0/_1 and undeliverable_host_exception, fail under my test runner because it skips their environment changes and pass pattern; run with those, all three pass.
  • The size asserts in ShaderDiskCache.cpp only compile on Linux. I have no Linux build; I compiled the structs under MinGW libstdc++ on x86_64, where all asserted sizes match. agc_shader_disk_cache's result round trip now also sets and compares bufferBaseSlots.
  • New test agc_driver_draw_cache_moved_buffer: a pixel shader loads a buffer descriptor through a user-data pointer and reads its colour from that buffer. Once the draw has been seen twice, drawing it again with the descriptor's base changed, with the same or other contents, hits the cached draw. It fails with APS5_NO_DRAW_RELOCATION=1.
  • On main 940eba9a2, this PR and perf(agc): find cached draws across moved user-data pointers boykopovar/AnyPS5#4943 against the same build without them (both with the same local changes the frontend needs to boot, immediate present, audio muted, three alternating unprofiled runs): audio produced at 34.5%, 35.7% and 35.6% of real time without, against 45.7%, 44.1% and 42.8% with.
  • RetroArch (PPSA99169) with its Flycast core running Crazy Taxi's attract demo, measured before the rebase, on main 4430780bd (without perf(agc): cache a draw key the second time it is seen boykopovar/AnyPS5#5216) plus local changes outside this PR that the frontend needs to boot. perf(agc): find cached draws across moved user-data pointers boykopovar/AnyPS5#4943 alone against perf(agc): find cached draws across moved user-data pointers boykopovar/AnyPS5#4943 plus this PR, same local base, one thread, ANYPS5_PRESENT_MODE=immediate, two unprofiled runs each: audio produced at 43.6% and 43.4% of real time against 57.6% and 57.9%. One profiled run each: queue worker 41.5 µs against 30.7 µs per draw packet; stage captures per 10 s 92,728 in 185,141 draws against 14,859 in 238,439; draws with every stage reused 75% against 96.8%.
  • Same demo and base with perf(agc): cache a draw key the second time it is seen boykopovar/AnyPS5#5216 cherry-picked, two unprofiled runs each: the chain without the admission 59.1% and 58.8%; with perf(agc): cache a draw key the second time it is seen boykopovar/AnyPS5#5216 as merged 51.0% and 50.7%; with the admission change of these two PRs 58.8% and 58.5%.
  • Same demo with APS5_VERIFY_DRAW_ENTRIES=1, which captures every hit again and compares: 0 stages differed in every report (118,722 hits in the largest).

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: perf(agc): find cached draws across moved user-data pointers boykopovar/AnyPS5#4943
  • AI-assisted: yes. Written with Claude Code under my direction.

🤖 Generated with Claude Code

TheAggie and others added 8 commits October 15, 2026 14:06
…; patch relocated push constants without copying the result

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

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

A stage's donor is found by its prepared shader, its own user words and the
contents behind its relocatable words, so a texture learned under one state
serves every state. A draw whose first stages validate reuses them when a later
stage misses, and a known decode is reused on a miss.

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

The recompiler reports the captured words that are a buffer descriptor's base
address and nothing else (never an operand of the walk), and where each lands in
the result. Validation masks them, and a hit that differs only there patches the
new addresses into a copy of the result.

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

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pixel shader loads a buffer descriptor through a user-data pointer and reads its colour from that buffer. Drawn again with the descriptor's base address changed, with the same or other contents, it hits the cached draw; with APS5_NO_DRAW_RELOCATION=1 it does not.

AI-assisted (Claude Code).

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Thimo188 Thimo188 closed this Dec 2, 2026
@Thimo188 Thimo188 reopened this Dec 2, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Dec 2, 2026
This was referenced Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed 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.

2 participants