fix(agc): skip empty indirect draws of programs read on the CPU by memory state #28150
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28150"
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 AlexOnGidhup on 2026-11-28T19:51:42Z.
What
The problem. An indirect draw whose records are read on the CPU and turn out empty can be skipped before its stages and resources are built:
EmptyIndirectSkipinExecution/src/Driver/Draw/Draw.cppreads the records first. That check only applied to front programs whoseCpuIndirectPrograms()entry is true, and the entry came fromClassifyIndirectDrawalone.A program can also reach the CPU path later, inside
prepareDraw(Graphics/src/Draw.cpp), through the memory-state decision on its records:PendingImage,PendingLabelOrCopy,NotImported,Settled, orDisabledunderAPS5_NO_GPU_INDIRECT_DRAW. Such a program was never marked. So each of its empty draws:indirect draw with empty records;recorded && Reusable()) and ran synchronously.The next identical empty draw built the same set again.
The change.
prepareDrawnow records, per front program variant (RecompileResult::variantId), whether the memory-state decision read its records on the CPU with no writer pending:NoteIndirectRecordsRead/IndirectRecordsReadOnCpu.PendingImageandPendingLabelOrCopydo not count.CpuIndirectPrograms()entry. A programClassifyIndirectDrawmarked is checked before the build as before.IndirectRecordsPending): noStorageTexture::AnyPendingOverlapsimage result and no copied write-back of the device or ofDrawCopiedWriters(), read under the GPU mutex, covers them. Otherwise the draw takes the normal path.recordQueuedLabelsBeforeRead,FinishLeaseWritesBeforeRead, thenPm4::ReadDrawCount/Pm4::ReadDrawArgumentsthrough the flush hook.APS5_NO_EMPTY_INDIRECT_SKIProw indocs/dev/ENVIRONMENT.mdnow names both decisions.The test. New execution test
EmptyIndirectSkipMemoryPath. It uses a programClassifyIndirectDrawleaves on the GPU path, and setsAPS5_NO_GPU_INDIRECT_DRAW=1to send its records through the memory-state branch.EmptyIndirectDrawCount), and that the last one draws.On
mainthe test fails because the empty draws are not skipped before their stages.Analysis and measurements: #27759, from https://github.com/boykopovar/AnyPS5/issues/27759#issuecomment-7243339682 on.
Tested
Unit tests. Windows 11 Pro 22631, AMD Radeon RX 9070 XT, AMD driver 32.0.32029.2010 (
amdvlk64), WinLibs GCC 15.2.0.Branch at
0f4d55b2eb, on67d64e4e52.agc_driver_*indirect*andagc_driver_queued_*tests, run serially withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1: 30 pass, among themagc_driver_queued_indirect_read_order, which the second commit broke.agc_driver_gcn_indirect_draw_locationfails on this host withAPS5_NO_EMPTY_INDIRECT_SKIP=1as well ("the direct GCN draw with depth 0 covered 0 of 1024 bytes"), so it is not this change.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer(Vulkan SDK 1.4.363): all pass.agc_driver_empty_indirect_skip,agc_driver_empty_indirect_skip_memory_pathagc_driver_queued_indirect_read_order,agc_driver_settled_indirect_readagc_driver_indirect_draw_pending_producerand its_draw_pipeline,_plan_verifyand_gpu_indirect_disabledvariantsagc_driver_gpu_written_indirect_buffer_queued_writer,agc_driver_pipelined_indirect_drawwas not found but was requestedlines and noVUID-lines.main,ae0df0e03e, with the new test only:agc_driver_empty_indirect_skip_memory_pathfails as intended.python3 tools/check_conventions.pypasses.Title PPSA38500 01.002.001. Windows, same GPU,
APS5_PROFILE_DRAW=1 APS5_TRACE_DRAWS=1, 10 minutes each. The stack is this change on a local branch with other open GTA VI PRs, and with the title's heartbeat timeout disabled locally.0f4d55b2eb8dde612c75APS5_NO_EMPTY_INDIRECT_SKIP=1empty skipped before their stages[draws]lines)8dde612c75also read records that a pending writer still covered, which brokeagc_driver_queued_indirect_read_order.0f4d55b2eb, many of the title's records still have a pending image result or copied write when the draw is checked, so those draws take the normal path and run synchronously. Making that build reusable is a separate change.An earlier 25-minute boot with the same idea applied to every indirect draw had 769 synchronous draws without it and 0 with it, and
same key (not inserted or evicted)went from 898 to 457 (#27759). The title still stops presenting for other reasons, mainly large compute pipeline builds discussed in #27759, so this PR does not make it render.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)0f4d55b2eb, tested by @zeezey (https://github.com/boykopovar/AnyPS5/pull/28150#issuecomment-7247689018)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T19:59:44Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the changed code and test support merging.
What I ran
Reviewed head
a6b274413f1a4df5adce944d56dfadfd42f7cc18. No commands or tests were run; the test results below are author-reported. Read all five changed files listed as included inmanifest.json, including the full text of each. No changed files were excluded.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported 6/6 unit-test run, negative-control run on
main, validation-layer output, conventions check, and PPSA38500 measurements were not independently run or confirmed. No files were excluded from review.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T20:03:06Z.
Review: COMMENTED
da6ec5a2-8661-41ff-a342-d9d580ed332eReviewing files that changed from the base of the PR and between
67d64e4e52anda6b274413f.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/execution/EmptyIndirectSkipMemoryPath.cppdocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T20:12:43Z.
Review: APPROVED
Reviewed — looks good
The change tracks CPU reads of indirect records for the front program and uses that state to skip empty draws before stage construction; I found no concrete defect in the reviewed changes.
What I ran
Reviewed head
8dde612c75369337d4939e606dde5ba173b1ce11using the prepared diff and pinned reader. I did not run commands or tests; this review environment provides reader tools only.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Builds, tests, and runtime behavior were not independently verified. Reviewed files:
Execution/src/Driver/Draw/Draw.cpp,Graphics/include/Draw.hpp,Graphics/src/Draw.cpp,tests/execution/EmptyIndirectSkipMemoryPath.cpp, anddocs/dev/ENVIRONMENT.md. No changed files were excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T23:56:35Z.
Review: COMMENTED
Actionable comments posted: 1
61a55bf1-e7df-4bf1-952b-14faf47063d3Reviewing files that changed from the base of the PR and between
8dde612c75and0f4d55b2eb.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Draw.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppdocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T00:01:38Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing in the inspected changes shows a blocking defect; the stated behavior is consistent with the code paths reviewed.
What I ran
Reviewed head
0f4d55b2ebcfb3cf537f09b84975cc1286b23381from the prepared diff and pinned reader. No commands or tests were run.Results
Findings
Blocking
None identified in the inspected changes.
Non-blocking
None.
Not verified
The test source and documentation change were included in the diff but not read from their full files. No tests, build, hardware behavior, or author-reported results were independently verified. Changed files read:
Execution/src/Driver/Draw/Draw.cppand selected ranges ofGraphics/src/Draw.cpp,Graphics/include/Draw.hpp. Files listed as reviewed in the manifest: those three,tests/execution/EmptyIndirectSkipMemoryPath.cpp, anddocs/dev/ENVIRONMENT.md; the latter two were not read from their full files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T00:33:33Z.
Review: APPROVED
Reviewed — looks good
The change tracks CPU reads of indirect records by shader variant and skips empty draws early only when the records have no pending writers.
What I ran
e622114106630b61b8b629bb515997357fb05868; no test commands were run.files.jsonwas unavailable; the review folder listing showed all five changed files included. Excluded files: none reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Tests and runtime behavior were not independently verified. The description reports Windows 11 test runs and title measurements; these remain author-reported.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T06:05:44Z.
Review: APPROVED
I read the diff at
e622114106. Windows 11, GCC 15.2, merged intomainatcf556db18c3together with other open PRs (so not an isolated build), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationon an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).agc_driver_empty_indirect_skip_memory_path: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has aVUID-orSYNC-HAZARDline.main's): fails on both GPUs: "the first empty indirect draw after a draw whose records the memory-state decision read on the CPU was skipped before its stages 0 times, expected once".Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:21:41Z.
Review: COMMENTED
RecordReads().onCpustores a process-lifetime entry for each compiled variant used by an indirect draw, including variants discarded by the shader caches. The entries are never removed. Could the recorded path live with the variant or be bounded with the existing indirect-draw bookkeeping? The read-path hint is needed only for a currently reusable variant, and the extra state should remain bounded across shader churn and device replacement.Source inspection at
e622114106.On Linux lavapipe, the scalar-buffer and submit-progress controls passed on main
a9cbd48cb0and this head. The change-onlyagc_driver_empty_indirect_skip_memory_pathalso passed. All three logs show Khronos validation 1.4.369 inserted with shader caching disabled and no missing-layer messages or VUIDs. These fixtures do not track retained state across shader-cache churn.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.