perf(agc): skip CPU-path indirect draws that draw nothing before buil… #7930
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7930"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by AnthonyClemens on 2026-10-19T14:40:30Z.
What
An indirect draw read its count and records only after every stage had been captured, compiled and cached. When culling leaves a draw's records empty (no vertices or no instances), the whole stage build ran and then the record loop drew nothing. GPU-side culling in RE Engine leaves many of these draws.
With this change, when the front program's last indirect draw took the CPU path,
Driver::drawreads the count and records first and returns before the stage build if no record draws. The read uses the same path as the CPU-path read:recordQueuedLabelsBeforeRead, thenPm4::ReadDrawCountandPm4::ReadDrawArgumentsthrough the flush hook. A record draws when its count and instances are non-zero, and for an indexed draw when its first index is inside the index buffer; these are the same conditions the record loop uses.ClassifyIndirectDraw) needs the compiled front stage, so each queue worker remembers the last decision per front program code address. Only a front program whose last indirect draw went the CPU path is read early, so GPU-side indirect draws never read their records on the CPU. If a remembered decision is stale, the only cost is one extra CPU read; the draw still takes the normal path when a record draws.APS5_NO_EMPTY_INDIRECT_SKIP=1builds the stages as before.[draws]profile line (APS5_PROFILE_DRAW) counts the skipped draws, and their reads are added to the argument read time.It doesn't overlap #6931 (CPU-path indirect draws queued on the draw pipeline). #6931 still drains at entry when the arguments overlap a queued write, and the early read comes after that drain. #6931 also skips empty records in its loop, but only after the stage build.
Tested
Windows 11 (10.0.26200), AMD Radeon RX 9070 XT, AMD proprietary driver 26.9.1 (LLPC), WinLibs GCC 15.2.0, Release.
New test,
agc_driver_empty_indirect_skip(about 3 s). It submits four CPU-pathDRAW_INDIRECTdraws with the same programs: one record that draws 3 vertices, one with no instances, one with no vertices, then the first again. It checks:With
APS5_NO_EMPTY_INDIRECT_SKIP=1it fails with0 of the 2 indirect draws whose records draw nothing were skipped before their stages were built. It passed 25 of 25 repeated runs.Existing tests pass:
indirect_patched_stage,rect_list_indirect,sparse_indirect_indices,sparse_indirect_indices_unreadable,indirect_arguments_written_ahead,indirect_arguments_pending_producer.tools/check_conventions.pypasses.Resident Evil 2 (PPSA04288), standing at the start of gameplay in front of the gas station,
APS5_TRACE_SECONDS=240:60. The caches were warm, and no other trace or profile switch was set.Why the base isn't plain
main: RE2 aborts during boot onmainonGetImageResource dword 0 is not a valid runtime valuein a compute shader (the class of #7345 and #7459). Both captures are from a local branch that merges currentmain(7a015c094) into the branch that reaches gameplay. That branch also carries a recompiler fix for that shader and other RE2-specific changes.71c176b5b, that branch with this change reverted.f8b39b41c, the same branch with this change.The two trees differ only by this change, and both builds were clean.
Earlier, before an unrelated fix let RE2's occlusion pass work, most of the scene was culled and many more indirect draws were empty. In that scene, presents per 10 s went from 37 to 57 with this change. That was counted from the
[present]log line, not a trace.Summary lines:
Traces: attached (
aps5-trace-71c176b5bfe5-31456.json.gzbase,aps5-trace-f8b39b41cc57-1816.json.gzwith the change).aps5-trace-f8b39b41cc57-1816.json.gz
aps5-trace-71c176b5bfe5-31456.json.gz
tools/trace_digest.py, baseseconds 240:60 from present 1589: 168 presents, frame p50 354.8 / p90 370.8 / p99 442.6 / max 451.0 ms, GPU busy 85.2 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.9.1 (LLPC), Windows 10.0.26200, 3840x2160, commit 71c176b5bfe5, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 1338.8, Driver.Packet.memory_wait 867.1, Committer.Commit 244.4, Driver.Packet.draw 241.9, Driver.Draw 241.0, Graphics.Draw 225.8, Driver.Packet.dispatch 218.7, Driver.Dispatch 217.8, Graphics.Draw.draw_and_resource_release 214.6, GpuMutex.wait.dispatch 113.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py, with the changeseconds 240:60 from present 1373: 174 presents, frame p50 342.9 / p90 352.2 / p99 421.6 / max 428.3 ms, GPU busy 85.5 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.9.1 (LLPC), Windows 10.0.26200, 3840x2160, commit f8b39b41cc57, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 1280.0, Driver.Packet.memory_wait 827.5, Committer.Commit 252.9, Graphics.Draw 231.1, Driver.Packet.draw 224.7, Driver.Draw 224.0, Graphics.Draw.draw_and_resource_release 219.4, Driver.Packet.dispatch 216.1, Driver.Dispatch 215.1, GpuMutex.wait.dispatch 110.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T14:40:44Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-20T22:13:58Z.
Tested on Demon's Souls (PPSA01341 v1.07), NVIDIA on Linux. Short version: this is the largest single CPU win we've measured on DS in a while.
Setup. Our DS stack (main
676269473plus a few of our open fixes) with1ee299682cherry-picked on top, no other changes. Only libSceAgcDriver.prx differs between the two arms. 3 runs with the patch and 3 without, alternated on the same day, same save, same in-level path, warm shader cache, 56 level windows per run.Spread across runs was small (queue-0 899-919 with the patch, 988-1031 without, ratio of sums). No crashes, Xids or aborts, and all six runs exited normally. With the patch,
[draws]reports 12.3k-13.4k "empty skipped before their stages" per 10 s, about 1,200 per present. Without it the count is 0.Why it helps so much on DS. We traced 8,561 0x24 packets. All of them are single-record 4-vertex quads (particles, 0 to 10,557 instances), and none of them hit the draw cache, so every packet builds its stages from scratch. 2,871 of them had 0 instances and still paid the full build. That was 648 of the 1,271 ms per 10 s that DRAW_INDIRECT cost. Two of the particle vertex programs (0x248a7de00 and 0x248a8f900) also resolve a runtime image table of about 55k keys on each build. That was 5-30 ms per packet in the worst cases, and the patch skips it entirely when the draw is empty. Re-reading the patched SGPR per record turned out to be cheap (about 0.01 ms), so it wasn't the cause.
Correctness. The skip conditions match the record loop: count, instances, and firstIndex < indexCount for indexed draws. The read happens after the same Drain(Indirect) and label flush. The draws it skips drew nothing without the patch either. Hook waits and argument-read times are about the same in both arms. The new
empty_indirect_skiptest passes on lavapipe, along withdraw_offset_indicesandindirect_patched_stage. We didn't get screenshots from these particular runs, so this is not a visual comparison.The remaining 0x24 cost (about 45 ms per present) is the non-empty particle draws rebuilding that image table. That would be a separate change.
AI-assisted: yes