perf(agc): queue all records of a CPU-path indirect draw behind APS5_PIPELINE_INDIRECT #1896
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1896"
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 fisherjoey on 2026-10-08T22:55:17Z.
What
Most of what this PR set out to do is now in
main:So I cut this PR down to what
mainstill lacks. WithAPS5_PIPELINE_INDIRECT=1(off by default):maindon't drain here.e7b003afb6madeCompiledShader::registeredImageViewsa raw pointer into the capture, and the expanded loop copied the stages without re-pointing it.maindoes for the last record.Two smaller commits are unchanged: a
[committer]line underAPS5_PROFILE_DRAWthat counts inline draws, dispatches and drains per opcode, and capture drains now charged to the packet that reads.The GPU-path code, the old
Driver::drawoverlap drain and theDrawPipelineCommitstest are gone, sincemainhas its own versions. The_itemsregistrations (the indirect tests rerun with the knob on) now live in each test'stests/cmakefragment.Tested
Head
c195d1a938onmaina7ac923b80. Nobara 44 (Linux 7.2), GCC 16.2.1, Release with-DANYPS5_ENABLE_ASAN=ON, lavapipe (Mesa,VK_DRIVER_FILES=lvp_icd).agc_driver_pipelined_indirect_draw_itemsandagc_driver_indirect_patched_stage_itemspass under ASan. With the re-pointing line removed,agc_driver_indirect_patched_stage_itemsreports the same heap-use-after-free as in SleglJan's report (read inShaderResources::buildPrepareon the committer, freed inmaterializeDrawStage).ctest -R '^agc' -j6under ASan: 1539 of 1552 pass (84 of them skip on lavapipe). The other 13 also fail or skip onmaina7ac923b80built the same way: 11 fail there too (stack-use-after-scope in the test harness, an LLVM alloc-dealloc mismatch inside lavapipe,agc_driver_graphicsand friends),agcvsh_packet_writeris not built, andagc_driver_gcn_display_presenttimed out at-j6but skips when run alone, as it does onmain._itemstests plus the 3 other_itemstests: 10 repeated runs each under ASan, all pass. The 53 tests matching_items|indirect|pipelinedpass.tools/check_conventions.py --base origin/mainpasses.Demon's Souls (PPSA01341 v1.07, RTX 5070 Ti, NVIDIA 595.91.07): no valid numbers, so this stays a draft. Both arms were
mainplus a local hack that ignores the exported stencil reference, which DS needs on NVIDIA to reach the level. With the knob on, the title reached the level and then stopped about 100 s later with[gpu] driver failure: vector::_M_range_insert(std::length_error). That's the same symptom as the use-after-free above, so some path in the expanded loop still leaves a stale view pointer, or a different one breaks. The tests above don't reach it. Themainarm crashed with a segfault in title code before reaching the level, so I have no baseline line either. No summary lines yet.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:05:37Z.
Additional platform validation on standalone PR head
ae7542cde86d1ed7b0aad19cc1865a1899a24aee:Windows: passed — Windows 11, supported WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja.
Release /
BUILD_TESTING=ON: built the selected test targets; 3 CTest cases, 0 failures, 0 CTest skips.Tests:
agc_driver,agc_driver_pm4,agc_driver_graphics.Reproduce after building the test targets:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver($|_graphics$|_pm4$|_submit$)".Ran with
APS5_PIPELINE_INDIRECT=1to exercise indirect submission.Vulkan: native AMD RX 6900 XT, driver 32.0.21045.5002.
Integration limitation: a local merge against main
948a526c2has source conflicts; these results validate the standalone PR head, not a resolved merge.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:40:32Z.
Review: CHANGES_REQUESTED
Thanks for taking indirect draws from #1202. Not mergeable yet, for two reasons:
main. All the bases are still open drafts, and @MichonGoddijn231849 said on #1201 and #1747 that the stack is parked while it is ported onto the prepared-shader path from #639. This PR can only land after they do.Driver::drawmay need to move with it.What would help: keep this as a draft, and once the bases land (or the port is published) rebase onto
mainso the diff is onlyDraw.cpp,DrawPipeline.{hpp,cpp},WriteEvidence.cppandDrawPipelineCommits.cpp, tick "Based on currentmain", and rerun your Demon's Souls numbers on that head. We'll review it then.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-12T03:41:30Z.
Thanks, makes sense. I've moved this to draft. Once the #1201/#1202/#1747 stack lands on
main(or Michon publishes the port onto #639's prepared-shader path), I'll rebase so the diff is onlyDraw.cpp,DrawPipeline.{hpp,cpp},WriteEvidence.cppandDrawPipelineCommits.cpp, move the drain/overlap checks inDriver::drawif the port needs it, tick "Based on current main", and rerun the Demon's Souls numbers on that head.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-17T07:23:50Z.
@adriadam10 Rebased onto
main. Your points in order:The branch carried the #1201/#1202/#1747 stack and conflicted with
main. Those PRs are merged now (#1201 and #1202 on 10-15, #1747 on 10-16), so I rebuilt the branch onmain6a32550fdwith only this PR's commit,8ba9dda20. The diff is the five files you listed:Draw.cpp,DrawPipeline.{hpp,cpp},WriteEvidence.cpp,DrawPipelineCommits.cpp. It also merges cleanly into the currentmain17cfb1f4c. I had to resolve two conflicts inDrawPipeline.{hpp,cpp}, whereQueuedItems()sits next to the new functions, and bring the CPU-side indirect branch in line with howmain's inline loop works now:materializeDrawStagereturns ashared_ptr, andshaderMemoryis now aunique_ptr.compiledStagesandstageDataalive, because the stage pointers point into them.Whether the port onto #639's prepared-shader path moves the drain/overlap checks in
Driver::draw: onmain, decoding, the cache lookup and stage materialization all still happen inDriver::draw, before the enqueue. So the argument-overlap check and the validated-hit overlap check stay where they were. Nothing moved apart from the adjustments in point 1.Ticking "Based on current
main": the branch is based on currentmain, but I've left the box unticked for now. #6931, opened 10-16, queues CPU-path indirect draws on the pipeline, is on by default, and keeps GPU-side indirect draws draining. That overlaps the CPU-side half of this PR, and the two conflict inDraw.cpp. I haven't decided yet whether to drop the CPU-side part here and put the GPU-side part on top of #6931. That's still open.Demon's Souls numbers on the new head: not rerun yet. This head has only been tested on lavapipe:
ctest -R 'agc|pipelined|fill'(633 tests), 4 runs withAPS5_PIPELINE_INDIRECToff and 4 with it on. The only failure wasagc_driver_preparation_scope_settle, a shader-registration timing test that does no draws. Run alone it failed 3 of 10 times with the knob off and 5 of 10 with it on, while the machine was busy with another build. The new test,agc_driver_draw_pipeline_commits, plus thepipelined_*, fill and indirect tests passed 10 of 10 runs with the knob off and 10 of 10 with it on. The table in the description is still from the old stack and is labelled that way. I'll replace it once the game has been measured on this head.The PR stays a draft until 3 and 4 are sorted out.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T01:57:08Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
c195d1a93890f01a8e0e25324f9100031b13f231, basemain. No merged-preview check was run.Results
Findings
Blocking
None verified.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp:1214: every expanded record keeps its own copy of all captured memory regions initem.snapshots, andexpandedholds each record's materialized shaders until the committer runs. The inline path freed each record's snapshot after drawing it. Memory held therefore grows with the record count of the indirect draw. I did not measure the size. The knob is off by default.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cpp:311:NoteInlinedoes an atomic increment on every inline draw and dispatch, even whenAPS5_PROFILE_DRAWis unset. Only the profile report reads the counts. The cost is small, but gating the counting on the profile flag would remove it.Sources
Not verified
_itemstests) are the author's; I did not reproduce them.vector::_M_range_insert,std::length_error, about 100 s after the level loads, knob on). I could not reproduce it and did not find its cause. I found no stale view pointer in the expanded loop, but the author's suspicion is not settled.materializeDrawStage,KnownDrawRejection,capturedMemoryChanged,Pm4::ReadDrawArguments. I checked call sites and thecommitDrawsignature only._itemsregistrations were not checked; only the fragments were.To get this to a good state
Nothing is required.
Optional: the two non-blocking points above.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:17:16Z.
Review: COMMENTED
The trial merge onto
a1b75b0947conflicts in the draw-pipeline interface and implementation, dispatch variant validation, write evidence, andENVIRONMENT.md. When rebasing the opt-in indirect path, preserve the partway fallback where already expanded records commit before the remaining inline records. Keep zero-count and draw-index coverage with the argument-producer controls. The performance evidence should use pairedtrace_digest.pysummaries for the same scene and machine on the final revision.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.