perf(agc): draw an indirect rect list from its records on the GPU #5979
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5979"
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 alfalfa-star on 2026-10-14T18:01:42Z.
What
ClassifyIndirectDrawsends every indirect rect-list draw to the CPU path (non-vertex path), which reads the records on the CPU. When the GPU writes those records earlier in the frame, the read waits for every batch up to the producer. In Kena: Bridge of Spirits (PPSA01802) that is oneDRAW_INDIRECTrect list about once per frame, each waiting 3 to 15 ms for the producing batch ([syncwait] ... indirect-args 127/995msin one 10 s window, 116/1744ms in another).A rect list on the vertex path is drawn by its generated tessellation stages from three-vertex patches. Those stages use no draw-dependent constants, so the records can be consumed on the GPU like any vertex-path draw, including the existing argument rewrite for constant offsets.
Graphics::Drawno longer requires the driver to resolve indirect rect lists.APS5_NO_RECT_INDIRECT=1restores the CPU path.Tested
Arch Linux (kernel 7.2.9), AMD Radeon RX 9070 XT, RADV Mesa 26.2.4, Release build of this branch on
maind92a8dad3.agc_driver_rect_list_indirect. It requires every indirect draw on the GPU path (read from the indirect-draw counters, the records in imported guest memory), so it fails withAPS5_NO_RECT_INDIRECT=1or without the driver change. Each indirect draw must also write the same bytes as its direct counterpart:DRAW_INDIRECTrecord{3, 1, 0, 0}, and a record without vertices that must draw nothing;{6, 2, 0, 0}againstNUM_INSTANCES 2+DRAW_INDEX_AUTO 6). The vertex shader puts patchvertex id / 3 + 2 × instance idin its own slot, and all four slots must be filled;DRAW_INDEX_INDIRECT{6, 1, 0, 0, 0}againstDRAW_INDEX_2, 16-bit indices{6, 7, 8, 3, 4, 5}). Only slots 1 and 2 may be filled. The classifier lets indexed indirect rect lists through as well.agc_driver_draw_offset_indices: an auto indirect rect-list record whose packet names no offset registers must be classified to the GPU. It fails withAPS5_NO_RECT_INDIRECT=1.ctest -R "agc_|shader|recompiler": 575 of 576 pass (3 skipped).agc_driver_tessellationsegfaults on this machine without this change as well.Kena on plain
maindoes not reach the title scene (it needs unmerged GPU PRs and stand-ins), so this is not a main-vs-PR capture. Same change on my local Kena stack, same save,APS5_TRACE_SECONDS=50:10, switch off (CPU path) and on, alternating:DRAW_INDIRECTtime / 10 sindirect-argswaits / 10 sThe wait goes away. The frame-time effect is within this scene's run-to-run variance in these four runs; queue worker 0 is about 97 % busy on both paths. The four summary lines, the traces and a per-phase breakdown are in this comment. Run 1 on the GPU path was its first run and compiled the new pipeline variants cold (
shader_compile_and_link258 ms against 16 to 19 ms in the other runs).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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T19:16:54Z.
Review: COMMENTED
Removing a CPU read that waits 3–15 ms on the producing batch once per frame is worthwhile, and the classifier change is small.
On the evidence: the two pairs disagree. Run 1 is slower on the GPU path (p50 60.5 → 69.9 ms) and run 2 is faster (65.5 → 54.6 ms). They come from a local stack, not
main, and as the description says, that is within the scene's variance. The traces were offered on request. Attaching the fouraps5-summary.jsonllines and traces would let a maintainer check whether theindirect-argstime moved somewhere else on queue 0 (for example intomemory_waitorflush_between_packets), since the worker stays at about 97 % either way.On coverage: the new test draws one rect from a
{3, 1, 0, 0}record. Two cases would pin the GPU path where rect lists differ from triangle lists:firstInstancego through the generated tessellation stages; andDRAW_INDEX_INDIRECT), if the classifier lets it through. If it doesn't, a line in the description saying so would do.Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-15T06:20:59Z.
@CnRJay thanks. Both points are addressed; rebased onto
maind92a8dad3(17ca45319).Coverage.
agc_driver_rect_list_indirectnow has a second vertex shader that places each rectangle in its own 16-pixel slot. The slot isvertex id / 3 + 2 × instance id, so a dropped patch or instance leaves a slot empty, and a misplaced one fills the wrong slot. Two new cases:NUM_INSTANCES 2+DRAW_INDEX_AUTO 6must fill all four slots (32 pixels each). ADRAW_INDIRECTrecord{6, 2, 0, 0}must write the same bytes.DRAW_INDEX_INDIRECTrect lists through. A directDRAW_INDEX_2with 16-bit indices{6, 7, 8, 3, 4, 5}must fill only slots 2 and 1 (0 32 32 0), which a non-indexed reading would not produce. ADRAW_INDEX_INDIRECTrecord{6, 1, 0, 0, 0}must write the same bytes.With
APS5_TRACE_INDIRECT_DRAWS=1, all four indirect draws in the test classify asgpu vertex=const 0 instance=const 0. WithAPS5_NO_RECT_INDIRECT=1they classify ascpu (non-vertex path), and the test passes both ways. The records keepfirstInstance0. A non-zero start instance with no start-instance register would test the existing constant-instance rule shared with triangle lists, not something specific to rect lists, so I left it out.Evidence. The four summary lines are below, and the traces are attached here. Per-present time on queue worker 0x0, from the traces:
Driver.PacketDriver.Packet.drawDriver.Packet.prepare_memoryRecorder.WaitSerialinside itDriver.Packet.flush_between_packetsDriver.Packet.device_lockmemory_waitin the summary lines is on queue worker 0x20 (38.8 / 45.1 / 44.5 / 34.3 ms/present), not queue 0.Driver.Draw.draw_and_resource_release, about one per present. That is the record read waiting for its producer. It is gone in run 2 on the GPU path.flush_between_packetsdoes not grow on the GPU path.Recorder.WaitSerialruns exactly once per present insideprepare_memoryon both paths, so the removed wait did not move there. Its higher average in GPU run 1 comes from 6 waits over 15 ms.shader_compile_and_linktook 258 ms in it against 16 to 19 ms in the other three runs, and its 98 long draws aredraw_prepared_on_pool, which is consistent with the new pipeline variants compiling cold. Run 2 had a warm cache.So run 1's slower GPU numbers look like a cold pipeline cache rather than the wait moving elsewhere. Two pairs are still too few to claim a frame-time gain, and the description still says only that the wait goes away.
aps5-summary.jsonl lines (CPU 1, GPU 1, CPU 2, GPU 2)
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:12:40Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppL1037Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T19:58:52Z.
Review: CHANGES_REQUESTED
Checked build + ctest on the PR merged onto current
main:agc_driver_draw_offset_indicesandagc_driver_rect_list_indirectpass. One thing to fix before merging:core/libs/prx/libSceAgcDriver/tests/execution/RectListIndirect.cpp: the test passes with the non-test changes reverted (IndirectDraw.cpp,Draw.cpp), because the CPU path writes the same bytes as the direct draw. It checks the output is equal, not that the indirect draw took the GPU path, so the 6-vertex/2-instance, indexed and empty-record cases would pass onmaintoo. Only the single non-offset case inDrawOffsetIndices.cppfails without the change. Please pin the route for each of those draws (classify withClassifyIndirectDrawasDrawOffsetIndices.cppdoes and require the GPU, or assert on the indirect-draw trace/counter), and check that the test fails withAPS5_NO_RECT_INDIRECT=1.Not blocking, for the record: the frame-time numbers are within variance (run 1 slower, run 2 faster), so the claim here is the removed
indirect-argswait only.Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-16T21:21:03Z.
@adriadam10 thanks, you were right, and it was worse than the test missing a check: the end-to-end draws never took the GPU path at all. The records were in a static array that isn't guest memory, so all four indirect draws got past
ClassifyIndirectDraw(which is what my earlierAPS5_TRACE_INDIRECT_DRAWSlines showed) and then fell back to the CPU inDrawasnot imported.Fixed in
ac64ea452(pushed on top, no rebase):DrawOffsetIndices.cppdoes it.APS5_PROFILE_DRAWand reads the indirect-draw counters through a newGraphics::IndirectDrawCounts(), a read of the counters the[draws]line already prints. It requires all four indirect draws (plain, empty record, 6 vertices × 2 instances, indexed) ongpu-side, with no CPU path.Linux (Arch), RX 9070 XT (RADV, Mesa 26.2.4), Release:
agc_driver_rect_list_indirectAPS5_NO_RECT_INDIRECT=1indirect rect-list draws read their records on the CPU: 4 non-vertex pathIndirectDraw.cppandDraw.cppchanges reverted... 4 non-vertex path... 4 not importedagc_driver_draw_offset_indicesstill passes, andtools/check_conventions.pypasses. Agreed on the frame-time numbers: the claim is the removedindirect-argswait only.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:10:41Z.
Review: APPROVED
Re-checked
ac64ea452: the records now live in a registered guest allocation and the test reads the indirect-draw counters, requiring 4 GPU draws and 0 CPU-path draws.agc_driver_rect_list_indirect,agc_driver_draw_offset_indicesandagc_driver_graphicspass on RADV and on CI's lavapipe; withAPS5_NO_RECT_INDIRECT=1both new tests fail ("read their records on the CPU: 4 non-vertex path" / "expected the GPU"). Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-17T12:37:10Z.
Since this PR, PPSA15304 renders bright red, blue and magenta blotches between the tree canopies at the start position of the first area, and red light patches on the tree trunks.
APS5_NO_RECT_INDIRECT=1removes both, so the GPU path for indirect rect lists draws something differently from the CPU path here.main40255d774, with upstream merged up to #6008 (c9cabcaf8), is clean. Merged up to this PR (49f5dc1a5) it shows the blotches, and the same build withAPS5_NO_RECT_INDIRECT=1is clean again.mainbf2053816: blotches present; withAPS5_NO_RECT_INDIRECT=1they are gone (the scene there is also too dark, which is #454 and unrelated to this PR). Frame dumps (APS5_DUMP_FRAMES) of the same save at the same camera position, so it is the title's output, not the window.APS5_PROFILE_DRAW, one 10 s window in that scene): with the GPU path,indirect: gpu-side 7356 (7356 rewritten), cpu-side 0; with the switch,gpu-side 4877 (4877 rewritten), cpu-side 1820 (non-vertex path 1820), CPU argument reads 64.6 ms. So about 1800 indirect rect-list draws per 10 s, all of which take the argument rewrite on the GPU path.Ubuntu 24.04, kernel 7.0.0, NVIDIA GeForce RTX 5080, driver 595.99.02, Release build.
I have not found which part of those draws differs yet (records, the rewritten constant, or the generated rect-list stages with indirect counts). I can trace one of the draws if you tell me which values you want; the frame dumps of both runs are available.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-17T17:22:28Z.
Thanks for the bisect, the frame dumps and the counters.
APS5_NO_RECT_INDIRECT=1is the workaround until this is fixed.On the GPU path these draws take the same record rules as indirect triangle lists (
ClassifyIndirectDraw,recordIndirectArguments). The only difference is the generated rect-list control and evaluation stages. So the first thing to settle is whether the GPU draw reads the same records as the CPU path. Could you run the same 10 s window twice withAPS5_TRACE_INDIRECT_DRAWS=1:APS5_CHECK_INDIRECT_ARGS=1: the[draw] indirect 0x… args 0x… stride … count … -> gpu vertex=… instance=…lines, and the[draw] indirect record 0x…: count … instances … first … vertexOffset … startInstance …read-backs thatAPS5_CHECK_INDIRECT_ARGSprints for the sameargsaddresses (it prints the first 16), plus itsindirect records checked …, with a value in a Constant dimension …line.APS5_NO_RECT_INDIRECT=1: the-> cpu (non-vertex path)lines and the[draw] record N: count … instances … first … vertexOffset … startInstance …lines after them.A few draws with the same
argsaddress in both runs are enough. If the counts, instances and constants match, the difference is in how the draw runs (patch-list draw against the per-record direct draws), and I'll look there next.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-17T18:18:42Z.
@alfalfa-star The records match.
Same save, same camera position, plain
mainbf2053816with #7050 merged, one 10 s window after the scene is reached,APS5_TRACE_INDIRECT_DRAWS=1in all runs:APS5_CHECK_INDIRECT_ARGS=1): blotches present.APS5_NO_RECT_INDIRECT=1): clean; 905-> cpu (non-vertex path)draws in the window.The rect-list draws are
DRAW_INDEX_INDIRECT, stride 20, count 1,base=none inst=none idx=none,-> gpu vertex=const 0 instance=const 0on the GPU path. Theirargssit in one buffer of 179 records at a 32-byte spacing (offsets 0x0 to 0x1640); the buffer's base address differs between runs (0x335aaa0000CPU,0x33a13c0000GPU), the offsets are identical, so I matched the draws by offset.APS5_CHECK_INDIRECT_ARGSprinted its 16 read-backs during loading (stride 32, count 384, not these draws), so for the GPU side I made a third run with a local build that prints every read-back (the< 16limit removed, nothing else changed). In that window, for the 179 rect-list offsets:Example, same offset:
indirect records checked 139520, with a value in a Constant dimension 0. The instance counts per record change from frame to frame (the title writes them on the GPU), so they are compared as distributions, not draw by draw.So the GPU draw reads the same kind of records with the same constants; about 60% of them have zero instances, the rest up to about 300.
Ubuntu 24.04, kernel 7.0.0, NVIDIA GeForce RTX 5080, driver 595.99.02, Release build.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-18T12:05:18Z.
@ee6aba54 Thanks, that settles the records: same count, first index, offsets and instance distribution, and no value in a Constant dimension.
That leaves the draw itself. With
vertex=const 0 instance=const 0and no base/instance/draw-index locations, both routes use the same pipeline (the generated rect-list control and evaluation stages), the same index buffer and the same values. The CPU route issues onevkCmdDrawIndexedper record afterPm4::ReadDrawArguments. The GPU route issues one indexed indirect draw from the rewritten copy. So I see two remaining differences:decideinDraw.cpp: pending images, labels and copied writers over the arguments). The title writes the instance counts on the GPU, so the per-instance data probably comes from the same pass. If any of it is still in flight when the draw is recorded, the draw reads last frame's or unwritten instances. That fits colored blotches that change with the instance count. The read-backs you compared were taken at batch completion, so they can't rule this out.vkCmdDrawIndexedIndirectagainst per-recordvkCmdDrawIndexed. That is whatRectListIndirectcovers, but only with instanced or indexed draws, never both together as here.One run separates them: the GPU route (no
APS5_NO_RECT_INDIRECT) withAPS5_SYNC_DRAWS=1, same save and camera. Each draw then waits for the work recorded before it. If the blotches go away, it is (1), and I'll extend the GPU route's check to the vertex-buffer ranges the draw fetches. If they stay, it is (2), and I'll add an indexed instanced case toRectListIndirectto reproduce it.APS5_SYNC_DRAWSis slow, but a single frame dump at that camera position is enough.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-18T22:59:14Z.
@alfalfa-star With
APS5_SYNC_DRAWS=1the blotches are gone.Same save and camera position, GPU route (no
APS5_NO_RECT_INDIRECT),main07377573fwith #7050 (a714d1b37) merged and #6270 reverted (with #6270 this title aborts at startup, reported there). One frame dump (APS5_DUMP_FRAMES, 960x540) per run; blotch pixels are the strongly saturated red, blue or magenta ones, mean gray is 0-255:APS5_SYNC_DRAWS=1For comparison, the earlier runs on
bf2053816+ #7050: GPU route 6291 (1.21%) and 3734 (0.72%) in two runs, CPU route (APS5_NO_RECT_INDIRECT=1) 0.Ubuntu 24.04, kernel 7.0.0, NVIDIA GeForce RTX 5080, driver 595.99.02, Release build.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-19T17:03:33Z.
@ee6aba54 Thanks, that settles it: the draw call is fine, and the GPU route reads something before it is final.
I need to correct my last comment, though. Extending
decideto the vertex ranges wouldn't change anything. Those ranges already get the same checks when the draw binds them in place (InPlaceDrawInputinDraw.cpp: pending images, labels, copied writers and the recorder's pending writes, plus a barrier). The shader's buffer reads get the same checks inShaderResources. So I don't know yet which read is early, and I don't want to guess at the fix. Two things differ between the routes:main's defaultAPS5_PIPELINED_DRAWS(depth 8), it is also prepared ahead of the submit thread.Could you do two more runs on the GPU route (no
APS5_NO_RECT_INDIRECT), same save, camera and frame dump as before, and count the blotch pixels:APS5_NO_DRAW_INPUTS_IN_PLACE=1: vertex and index ranges are copied instead of read from the host import. If this is clean, the in-place vertex read is the early one.APS5_PIPELINED_DRAWS=0: draws are recorded inline instead of prepared ahead. If this is clean, the draw is decided before the work that writes its data has been recorded.If both still show blotches, it is a shader buffer read, and I'll send a build that logs which one overlaps work still in flight.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-20T19:26:13Z.
@alfalfa-star On current
main84870f8aathe blotches are gone without any switch.Same save and camera position, GPU route (no
APS5_NO_RECT_INDIRECT), plainmain84870f8aa. One frame dump (APS5_DUMP_FRAMES, 960x540) per run, blotch pixels counted as before;indirectline fromAPS5_PROFILE_DRAW, one 10 s window in the scene:indirectAPS5_NO_DRAW_INPUTS_IN_PLACE=1APS5_PIPELINED_DRAWS=0The last build with blotches was
main07377573f+ #7050, #6270 reverted (6495 blotch pixels, see above). Between07377573fand84870f8aathere are 723 merges; I have not bisected them.Ubuntu 24.04, kernel 7.0.0, NVIDIA GeForce RTX 5080, driver 595.99.02, Release build.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-21T16:18:20Z.
@ee6aba54 Thanks for checking. If plain
main84870f8aais clean on the GPU route, and stays clean with both switches, then there's no early read left on this route. Something in those 723 merges fixed it. I'm closing the blotch follow-up for #5979 with no change. If the blotches come back on a latermain, a bisect over that range would be the next step, and I can help with it.AI-assisted: yes (Claude Code)