perf(agc): drain for a depth render control only when it can update a surface #16168

Merged
JJenkx merged 1 commit from upstream-pr/16168 into main 2026-11-07 12:37:33 +00:00
JJenkx commented 2026-11-05 19:04:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-05T19:04:20Z.


What

Before a draw, DrawPrecheck drains the draw pipeline when the draw's DB_RENDER_CONTROL decodes as a depth render control and either:

  • it has an expand bit (0x60), or
  • any active depth surface starts at its address.

The drain exists so that NoteDepthRenderControl (the in-place expand tracking from 439557b223) updates a surface no queued draw still reads. NoteDepthRenderControl only changes active surfaces with more than one sample, the draw's sample count and the draw's address. It never changes anything for a single-sample control, and nothing for a clear-only control on a surface it does not match. Those draws drained for nothing.

The condition is now DepthRenderControlDrains:

  • A single-sample control never drains.
  • A control with more than one sample and an expand bit still always drains, so a surface a queued draw has not registered yet is still found.
  • Any other control drains only when an active surface matches its sample count and address.

Tested

Linux 7.2.11, GCC, Release, RX 6650 XT (RADV Mesa 26.2.6), on main fc23faa40a.

  • agc_driver_native_depth_expand_gate (CheckExpandGate) now checks the predicate. For a native multisample target it expects:

    • a drain for a clear at the target's address with its sample count;
    • a drain for an expand with more than one sample and no registered surface;
    • no drain for a single-sample clear or a single-sample expand at the target's address;
    • no drain for a clear at another address.

    All 6 cases ran (2, 4 and 8 samples, each with and without a stencil plane).

  • agc_driver_native_multisample_depth, agc_driver_native_depth_expand_gate, agc_driver_depth_copy_draw, agc_depth_copy_kept_bytes: 4 of 4 pass, 3 runs each.

  • ctest -R "^agc_|^video_out|vulkan": 1,368 of 1,368 pass.

Drains, from APS5_PROFILE_DRAW=1, one profiled run on each build per title, same base:

main this change
PPSA27616: draw (0x27) drains per 10 s 4,418 0
PPSA27616: all packet drains per 10 s 7,293 (7,683 ms) 1,979 (129.5 ms)
PPSA20423: draw (0x27) drains per 10 s 6,359 0
PPSA20423: all packet drains per 10 s 17,766 (552.7 ms) 6,738 (390.9 ms)

A local counter, not part of this change, attributed these drains: the depth render-control drain fired more than 131,000 times in a 95 s run. The metadata-pass drain fired about 1,000 to 2,000 times. Every sampled depth render-control drain had DB_RENDER_CONTROL 0x00000020 with a single sample.

No performance claim. Removing the drains did not measurably change frame rate. Eight unprofiled runs per title, alternating in two orders against main fc23faa40a:

Title, window main this change
PPSA27616, mean FPS 24–70 s 25.96, 26.56, 25.95, 27.79 (26.57) 27.21, 27.42, 26.18, 27.41 (27.06)
PPSA20423, mean FPS 70–120 s 19.05, 14.33, 18.87, 18.93 (17.80) 15.71, 16.07, 19.49, 19.22 (17.62)

On PPSA27616 the first order showed +4% and the reversed order −0.3%, so the +1.8% overall is not confirmed. On PPSA20423 the first order favoured main and the reversed order favoured this change; both builds range from 14 to 19.5 FPS. With fewer drains, the worker now runs while the committer records, instead of waiting for it. In these scenes the committer is the limit, so frames do not get shorter.

Screenshots at 115 s in PPSA20423 are identical apart from the animated water.

Performance

Summary lines of the second capture pair, PPSA27616 on the same machine and scene, main fc23faa40aa4 then this change a3ffd3196921 (APS5_TRACE_SECONDS=20:40). The capture comment has all four captures, the tools/performance_compare.py tables and the tools/trace_digest.py output. Mean frame time is about 1% shorter, close to the spread between captures of one build, so this is not a speedup claim.

{"commit":"fc23faa40aa4","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PLAYGO_UNLISTED_CHUNKS":"installed","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"20:40"},"gpu":"AMD Radeon RX 6650 XT (RADV NAVI23)","driver":"radv Mesa 26.2.6-arch1.1","os":"Linux 7.2.11-arch1-1","cpu":"AMD Ryzen 9 7950X 16-Core Processor","cpu_threads":32,"memory_mib":127901,"title_id":"PPSA27616","title":"Bendy and the Ink Machine","content_version":"01.000.002","resolution":"3840x2160","window":{"spec":"seconds 20:40","first_present":356,"ms":40030.107},"presents":1096,"frame_ms":{"p50":36.450,"p90":37.018,"p99":39.440,"max":40.216},"gpu_busy_ms_per_present":18.024,"worker_busy_pct":{"queue worker 0x0":79.399},"top_phases_ms_per_frame":{"Driver.Packet":28.998,"Driver.Packet.draw":28.211,"Driver.Draw":28.206,"Graphics.Draw":27.994,"Graphics.Draw.draw_and_resource_release":27.929,"Driver.Draw.device_setup":27.821,"Resources.Complete":27.369,"Recorder.Sync":10.881},"trace_dropped":false,"trace":"aps5-trace-fc23faa40aa4-2241957.json.gz"}
{"commit":"a3ffd3196921","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PLAYGO_UNLISTED_CHUNKS":"installed","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"20:40"},"gpu":"AMD Radeon RX 6650 XT (RADV NAVI23)","driver":"radv Mesa 26.2.6-arch1.1","os":"Linux 7.2.11-arch1-1","cpu":"AMD Ryzen 9 7950X 16-Core Processor","cpu_threads":32,"memory_mib":127901,"title_id":"PPSA27616","title":"Bendy and the Ink Machine","content_version":"01.000.002","resolution":"3840x2160","window":{"spec":"seconds 20:40","first_present":370,"ms":40030.983},"presents":1108,"frame_ms":{"p50":36.075,"p90":36.544,"p99":37.272,"max":40.510},"gpu_busy_ms_per_present":17.988,"worker_busy_pct":{"queue worker 0x0":79.198},"top_phases_ms_per_frame":{"Driver.Packet":28.612,"Graphics.Draw":27.912,"Graphics.Draw.draw_and_resource_release":27.845,"Resources.Complete":27.314,"Recorder.Sync":10.923,"VideoOut.Flip":7.647,"Driver.Present":7.607,"VideoOut.Flip.present":7.603},"trace_dropped":false,"trace":"aps5-trace-a3ffd3196921-2208627.json.gz"}

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD RX 6650 XT (RADV)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5177122669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16168). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-05T19:04:20Z. --- ### What Before a draw, `DrawPrecheck` drains the draw pipeline when the draw's `DB_RENDER_CONTROL` decodes as a depth render control and either: - it has an expand bit (`0x60`), or - any active depth surface starts at its address. The drain exists so that `NoteDepthRenderControl` (the in-place expand tracking from `439557b223`) updates a surface no queued draw still reads. `NoteDepthRenderControl` only changes active surfaces with more than one sample, the draw's sample count and the draw's address. It never changes anything for a single-sample control, and nothing for a clear-only control on a surface it does not match. Those draws drained for nothing. The condition is now `DepthRenderControlDrains`: - A single-sample control never drains. - A control with more than one sample and an expand bit still always drains, so a surface a queued draw has not registered yet is still found. - Any other control drains only when an active surface matches its sample count and address. ### Tested Linux 7.2.11, GCC, Release, RX 6650 XT (RADV Mesa 26.2.6), on `main` `fc23faa40a`. - `agc_driver_native_depth_expand_gate` (`CheckExpandGate`) now checks the predicate. For a native multisample target it expects: - a drain for a clear at the target's address with its sample count; - a drain for an expand with more than one sample and no registered surface; - no drain for a single-sample clear or a single-sample expand at the target's address; - no drain for a clear at another address. All 6 cases ran (2, 4 and 8 samples, each with and without a stencil plane). - `agc_driver_native_multisample_depth`, `agc_driver_native_depth_expand_gate`, `agc_driver_depth_copy_draw`, `agc_depth_copy_kept_bytes`: 4 of 4 pass, 3 runs each. - `ctest -R "^agc_|^video_out|vulkan"`: 1,368 of 1,368 pass. **Drains**, from `APS5_PROFILE_DRAW=1`, one profiled run on each build per title, same base: | | `main` | this change | |---|---|---| | PPSA27616: draw (`0x27`) drains per 10 s | 4,418 | 0 | | PPSA27616: all packet drains per 10 s | 7,293 (7,683 ms) | 1,979 (129.5 ms) | | PPSA20423: draw (`0x27`) drains per 10 s | 6,359 | 0 | | PPSA20423: all packet drains per 10 s | 17,766 (552.7 ms) | 6,738 (390.9 ms) | A local counter, not part of this change, attributed these drains: the depth render-control drain fired more than 131,000 times in a 95 s run. The metadata-pass drain fired about 1,000 to 2,000 times. Every sampled depth render-control drain had `DB_RENDER_CONTROL` `0x00000020` with a single sample. **No performance claim.** Removing the drains did not measurably change frame rate. Eight unprofiled runs per title, alternating in two orders against `main` `fc23faa40a`: | Title, window | `main` | this change | |---|---|---| | PPSA27616, mean FPS 24–70 s | 25.96, 26.56, 25.95, 27.79 (26.57) | 27.21, 27.42, 26.18, 27.41 (27.06) | | PPSA20423, mean FPS 70–120 s | 19.05, 14.33, 18.87, 18.93 (17.80) | 15.71, 16.07, 19.49, 19.22 (17.62) | On PPSA27616 the first order showed +4% and the reversed order −0.3%, so the +1.8% overall is not confirmed. On PPSA20423 the first order favoured `main` and the reversed order favoured this change; both builds range from 14 to 19.5 FPS. With fewer drains, the worker now runs while the committer records, instead of waiting for it. In these scenes the committer is the limit, so frames do not get shorter. Screenshots at 115 s in PPSA20423 are identical apart from the animated water. ### Performance Summary lines of the second capture pair, PPSA27616 on the same machine and scene, `main` `fc23faa40aa4` then this change `a3ffd3196921` (`APS5_TRACE_SECONDS=20:40`). The [capture comment](https://github.com/boykopovar/AnyPS5/pull/16168#issuecomment-6666863796) has all four captures, the `tools/performance_compare.py` tables and the `tools/trace_digest.py` output. Mean frame time is about 1% shorter, close to the spread between captures of one build, so this is not a speedup claim. ```json {"commit":"fc23faa40aa4","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PLAYGO_UNLISTED_CHUNKS":"installed","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"20:40"},"gpu":"AMD Radeon RX 6650 XT (RADV NAVI23)","driver":"radv Mesa 26.2.6-arch1.1","os":"Linux 7.2.11-arch1-1","cpu":"AMD Ryzen 9 7950X 16-Core Processor","cpu_threads":32,"memory_mib":127901,"title_id":"PPSA27616","title":"Bendy and the Ink Machine","content_version":"01.000.002","resolution":"3840x2160","window":{"spec":"seconds 20:40","first_present":356,"ms":40030.107},"presents":1096,"frame_ms":{"p50":36.450,"p90":37.018,"p99":39.440,"max":40.216},"gpu_busy_ms_per_present":18.024,"worker_busy_pct":{"queue worker 0x0":79.399},"top_phases_ms_per_frame":{"Driver.Packet":28.998,"Driver.Packet.draw":28.211,"Driver.Draw":28.206,"Graphics.Draw":27.994,"Graphics.Draw.draw_and_resource_release":27.929,"Driver.Draw.device_setup":27.821,"Resources.Complete":27.369,"Recorder.Sync":10.881},"trace_dropped":false,"trace":"aps5-trace-fc23faa40aa4-2241957.json.gz"} ``` ```json {"commit":"a3ffd3196921","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PLAYGO_UNLISTED_CHUNKS":"installed","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"20:40"},"gpu":"AMD Radeon RX 6650 XT (RADV NAVI23)","driver":"radv Mesa 26.2.6-arch1.1","os":"Linux 7.2.11-arch1-1","cpu":"AMD Ryzen 9 7950X 16-Core Processor","cpu_threads":32,"memory_mib":127901,"title_id":"PPSA27616","title":"Bendy and the Ink Machine","content_version":"01.000.002","resolution":"3840x2160","window":{"spec":"seconds 20:40","first_present":370,"ms":40030.983},"presents":1108,"frame_ms":{"p50":36.075,"p90":36.544,"p99":37.272,"max":40.510},"gpu_busy_ms_per_present":17.988,"worker_busy_pct":{"queue worker 0x0":79.198},"top_phases_ms_per_frame":{"Driver.Packet":28.612,"Graphics.Draw":27.912,"Graphics.Draw.draw_and_resource_release":27.845,"Resources.Complete":27.314,"Recorder.Sync":10.923,"VideoOut.Flip":7.647,"Driver.Present":7.607,"VideoOut.Flip.present":7.603},"trace_dropped":false,"trace":"aps5-trace-a3ffd3196921-2208627.json.gz"} ``` ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD RX 6650 XT (RADV) - [x] 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!16168
No description provided.