Draw cache misses on almost every draw when a guest driver puts per-draw pointers in the user data (RADV titles) #4054

Closed
opened 2026-10-11 22:18:04 +00:00 by TheAggie · 1 comment
TheAggie commented 2026-10-11 22:18:04 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-11T22:18:04Z.


Summary

Titles that render through RADV on the PS5 GPU (RetroArch PPSA99169 with the Flycast core here) get almost no draw-cache hits in moving scenes. The draw worker is then CPU-bound at about 48 µs per draw, and a scene with around 15,000 draws per second runs at a third of full speed.

The cause is narrow: the register key includes two user-data words that RADV fills with pointers it allocates again for each draw. The data behind those pointers repeats; only the addresses change.

  • #494 (draft) already reuses a shape's decode and stages when a draw differs only in user data, as long as each stage's captured reads still hold at the same addresses. What I measured here is the case where they do not: the pointer moves, so the reads are at new addresses with the same contents.
  • #3985 stops inserting keys that never repeat. That removes the insert churn in this scene but not the captures.
  • #1193 (draft) makes each capture cheaper.

What follows is meant as data for that work and a possible extension on top of #494, not a competing design. I would rather build on #494 than beside it.

Measurements

Main at a11c8f7f7, Windows 11, NVIDIA GPU (device 10de:2c05), APS5_PROFILE_DRAW=1. Scene: Crazy Taxi attract demo in Flycast, 1280x960 internal resolution, RADV_DEBUG=nonggc so the draws take the plain vertex path.

Draw cache, one 10 s window:

[draw-cache] 164991 lookups (10 s): 157058 no entry, 7933 validated in 6.4 us each ...: 7599 hits ...
  157391 inserts (314719 variants inserted ...), 4096 entries, 820999 evictions in total

Driver phases for the same window:

[draw] driver phases (10 s, 165178 draw packets, 165178 drawn, 315174 captures), us per packet:
  decode 4.2  capture 14.5  recompile 4.3  key/lookup/validate 5.3  Graphics::Draw 15.8  total 47.8 (7895.5 ms)

So the worker spends 7.9 s of every 10 s on draws, and about 23 µs of each draw is the miss path (decode, two captures, materialize, insert).

For comparison, a static menu in the same title hits on every lookup (23,960 of 23,960), because RADV's allocations then land on the same addresses every frame.

Which key words differ

I counted distinct keys over windows of 100,000 draws, once as built today and once leaving out two shader-bank user words:

Window Distinct keys today Distinct keys without 0x08c and 0x00f
1 87,378 2,297
2 92,964 3,212
3 91,932 2,006

Distinct values per user word in one window:

Register Stage, user word Distinct values Example
0x08c vertex, word 0 15,112 0x34c54480
0x00f pixel, word 3 3,495 0x3463b360
0x00e pixel, word 2 88 0x34600680
0x08d vertex, word 1 286
others 1 to 8

Words 0x08c and 0x00f are guest addresses. RADV allocates the block behind 0x08c from its command-buffer upload buffer for each draw, and Flycast allocates the descriptor set behind 0x00f from a pool it resets every frame. The same contents therefore show up at a different address on most draws.

An approach that works here

I have this running on a local branch based on a11c8f7f7 (so without #494) and would like your view on the shape, and on how to layer it over #494, before opening any PR.

  • Recompiler: the SRT evaluator records, for each raw read, the user-data word its address is based on when the handle's low word is a plain GetUserData. A word that is also evaluated as a value is marked. A word that was only ever a read base is relocatable for that capture: moving it and finding the same words at the shifted addresses reproduces the same evaluation.
  • Variant: each cached run is tagged with its base word. A word is dropped from the relocatable set if any of its reads is unaligned, missing from the captured regions, or shared with another origin, or if the stage decoded vertex inputs through user data.
  • Lookup: per shader set, the driver learns which registers are relocatable and which relative reads they have. On a miss it builds a second key in which those registers are replaced by a hash of the contents behind them. An entry found that way has its tagged runs shifted by the pointer delta and goes through the normal validation.
  • Result: the compiled result names the user word behind each shader-data dword, so a relocated hit patches exactly those push-constant words.

Same scene, same machine:

Main With the changes
Draw-cache hits 5% 96%
Captures per draw 1.9 0.08
Driver time per draw 47.8 us 19.4 to 19.9 us
Draws per 10 s about 158,000 about 290,000

Three further steps got from 72% to 96% hits:

  • Stages are found independently. A stage's cached variant is keyed by its prepared shader handle, its own user words and the contents behind its relocatable words, so a texture learned under one state serves every state.
  • Buffer base addresses are data. The evaluator marks raw reads that are used as an operand; a captured word that is only ever a buffer descriptor's dword 0 is listed with the binding slots it lands in (the GuestBuffers element and its flat SRT slot). Validation masks those words through the existing live mechanism, and a hit that differs only there patches the new address into a copy of the result, provided old and new are non-zero and agree in their low two bits (the only properties of that word the binding plan and specialization read). In this title the fragment uniform buffer's address changes every frame and was the only unique word in 99.7% of pixel-stage captures.
  • Smaller costs on the hit path: unchanged dynamic state is not set again between draws of an open pass, AnyPendingOverlaps consults the pending image range index, and draw snapshots are reused when nothing was written since they were last checked.

Checks so far: with APS5_VERIFY_DRAW_ENTRIES=1 (extended to compare address-to-word contents, forwarded user words and binding descriptors) every hit is captured again; no difference in several hundred thousand hits on the vertex path, the mesh path, a static test suite and the frontend menu. 377 of 379 AGC and shader tests pass; the two failures are a provoking-vertex rejection I removed in an unrelated local commit and agc_driver_emulated_color_compare, which also fails on main on this GPU. Separately, agc_driver_prepared_shaders_debug exits with 0xc0000374 at thread exit in 2 of 20 runs on main here, which looks like #3171.

Open points: there is no unit test for it yet, and the shader-set identity needed the program address registers mixed in because raw programs all resolve to one registry entry.

A smaller second finding from stack sampling the worker in the same scene: 27 of 119 busy samples were inside RtlAllocateHeap or RtlFreeHeap, spread over the whole draw path with no single dominant caller.

Reproducing

Any RADV-based homebrew with a moving scene should show it. With APS5_PROFILE_DRAW=1, compare "no entry" against lookups in the [draw-cache] line. I can share the small counting patch used for the table above.

I can split this into PRs (the evaluator reporting first, then the driver side) once the shape and the relation to #494 are settled.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5805758108 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4054). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-11T22:18:04Z. --- ## Summary Titles that render through RADV on the PS5 GPU (RetroArch PPSA99169 with the Flycast core here) get almost no draw-cache hits in moving scenes. The draw worker is then CPU-bound at about 48 µs per draw, and a scene with around 15,000 draws per second runs at a third of full speed. The cause is narrow: the register key includes two user-data words that RADV fills with pointers it allocates again for each draw. The data behind those pointers repeats; only the addresses change. ## Related open work - #494 (draft) already reuses a shape's decode and stages when a draw differs only in user data, as long as each stage's captured reads still hold at the same addresses. What I measured here is the case where they do not: the pointer moves, so the reads are at new addresses with the same contents. - #3985 stops inserting keys that never repeat. That removes the insert churn in this scene but not the captures. - #1193 (draft) makes each capture cheaper. What follows is meant as data for that work and a possible extension on top of #494, not a competing design. I would rather build on #494 than beside it. ## Measurements Main at a11c8f7f7, Windows 11, NVIDIA GPU (device 10de:2c05), `APS5_PROFILE_DRAW=1`. Scene: Crazy Taxi attract demo in Flycast, 1280x960 internal resolution, `RADV_DEBUG=nonggc` so the draws take the plain vertex path. Draw cache, one 10 s window: ``` [draw-cache] 164991 lookups (10 s): 157058 no entry, 7933 validated in 6.4 us each ...: 7599 hits ... 157391 inserts (314719 variants inserted ...), 4096 entries, 820999 evictions in total ``` Driver phases for the same window: ``` [draw] driver phases (10 s, 165178 draw packets, 165178 drawn, 315174 captures), us per packet: decode 4.2 capture 14.5 recompile 4.3 key/lookup/validate 5.3 Graphics::Draw 15.8 total 47.8 (7895.5 ms) ``` So the worker spends 7.9 s of every 10 s on draws, and about 23 µs of each draw is the miss path (decode, two captures, materialize, insert). For comparison, a static menu in the same title hits on every lookup (23,960 of 23,960), because RADV's allocations then land on the same addresses every frame. ## Which key words differ I counted distinct keys over windows of 100,000 draws, once as built today and once leaving out two shader-bank user words: | Window | Distinct keys today | Distinct keys without 0x08c and 0x00f | |---|---|---| | 1 | 87,378 | 2,297 | | 2 | 92,964 | 3,212 | | 3 | 91,932 | 2,006 | Distinct values per user word in one window: | Register | Stage, user word | Distinct values | Example | |---|---|---|---| | 0x08c | vertex, word 0 | 15,112 | 0x34c54480 | | 0x00f | pixel, word 3 | 3,495 | 0x3463b360 | | 0x00e | pixel, word 2 | 88 | 0x34600680 | | 0x08d | vertex, word 1 | 286 | | | others | | 1 to 8 | | Words 0x08c and 0x00f are guest addresses. RADV allocates the block behind 0x08c from its command-buffer upload buffer for each draw, and Flycast allocates the descriptor set behind 0x00f from a pool it resets every frame. The same contents therefore show up at a different address on most draws. ## An approach that works here I have this running on a local branch based on a11c8f7f7 (so without #494) and would like your view on the shape, and on how to layer it over #494, before opening any PR. - **Recompiler:** the SRT evaluator records, for each raw read, the user-data word its address is based on when the handle's low word is a plain `GetUserData`. A word that is also evaluated as a value is marked. A word that was only ever a read base is relocatable for that capture: moving it and finding the same words at the shifted addresses reproduces the same evaluation. - **Variant:** each cached run is tagged with its base word. A word is dropped from the relocatable set if any of its reads is unaligned, missing from the captured regions, or shared with another origin, or if the stage decoded vertex inputs through user data. - **Lookup:** per shader set, the driver learns which registers are relocatable and which relative reads they have. On a miss it builds a second key in which those registers are replaced by a hash of the contents behind them. An entry found that way has its tagged runs shifted by the pointer delta and goes through the normal validation. - **Result:** the compiled result names the user word behind each shader-data dword, so a relocated hit patches exactly those push-constant words. Same scene, same machine: | | Main | With the changes | |---|---|---| | Draw-cache hits | 5% | 96% | | Captures per draw | 1.9 | 0.08 | | Driver time per draw | 47.8 us | 19.4 to 19.9 us | | Draws per 10 s | about 158,000 | about 290,000 | Three further steps got from 72% to 96% hits: - **Stages are found independently.** A stage's cached variant is keyed by its prepared shader handle, its own user words and the contents behind its relocatable words, so a texture learned under one state serves every state. - **Buffer base addresses are data.** The evaluator marks raw reads that are used as an operand; a captured word that is only ever a buffer descriptor's dword 0 is listed with the binding slots it lands in (the GuestBuffers element and its flat SRT slot). Validation masks those words through the existing `live` mechanism, and a hit that differs only there patches the new address into a copy of the result, provided old and new are non-zero and agree in their low two bits (the only properties of that word the binding plan and specialization read). In this title the fragment uniform buffer's address changes every frame and was the only unique word in 99.7% of pixel-stage captures. - **Smaller costs on the hit path:** unchanged dynamic state is not set again between draws of an open pass, `AnyPendingOverlaps` consults the pending image range index, and draw snapshots are reused when nothing was written since they were last checked. Checks so far: with `APS5_VERIFY_DRAW_ENTRIES=1` (extended to compare address-to-word contents, forwarded user words and binding descriptors) every hit is captured again; no difference in several hundred thousand hits on the vertex path, the mesh path, a static test suite and the frontend menu. 377 of 379 AGC and shader tests pass; the two failures are a provoking-vertex rejection I removed in an unrelated local commit and `agc_driver_emulated_color_compare`, which also fails on main on this GPU. Separately, `agc_driver_prepared_shaders_debug` exits with 0xc0000374 at thread exit in 2 of 20 runs on main here, which looks like #3171. Open points: there is no unit test for it yet, and the shader-set identity needed the program address registers mixed in because raw programs all resolve to one registry entry. A smaller second finding from stack sampling the worker in the same scene: 27 of 119 busy samples were inside `RtlAllocateHeap` or `RtlFreeHeap`, spread over the whole draw path with no single dominant caller. ## Reproducing Any RADV-based homebrew with a moving scene should show it. With `APS5_PROFILE_DRAW=1`, compare "no entry" against lookups in the `[draw-cache]` line. I can share the small counting patch used for the table above. I can split this into PRs (the evaluator reporting first, then the driver side) once the shape and the relation to #494 are settled. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-16 23:53:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-16T23:53:43Z.


#4943 (f8d4ce340) is on main: a draw that differs from a cached one only in pointer words that are read through now finds the cached entry through an alias key. Closing this one. If [draw-cache] still shows "no entry" on most draws on RADV with current main, reopen with the APS5_PROFILE_DRAW=1 line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226915749 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4054#issuecomment-6226915749). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-16T23:53:43Z. --- #4943 (f8d4ce340) is on main: a draw that differs from a cached one only in pointer words that are read through now finds the cached entry through an alias key. Closing this one. If `[draw-cache]` still shows "no entry" on most draws on RADV with current main, reopen with the `APS5_PROFILE_DRAW=1` line.
Sign in to join this conversation.
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#4054
No description provided.