fix(agc): read CPU indirect draw records without storing a pending image over them #21059
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21059"
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 XIIYAZ on 2026-11-15T19:49:06Z.
What
On MoltenVK,
agc_driver_queued_indirect_read_ordertimes out in its count-indirect case:MoltenVK has no
drawIndirectCount, soClassifyIndirectDrawsends a count-indirect draw down the CPU feature-gap path. That path reads the count word and the records withPm4::ReadDrawCountandPm4::ReadDrawArguments. Both go through the flush hook, which first stores the pending image covering the range. The draw then reads the image's texels as its count and records. In the test, that is a count of 1275088896 and 1006651136 instances, and the draw never finishes. The GPU-indirect path reads the old records, which is what the test checks for both cases.Two changes make the CPU path match the GPU-indirect path:
ReadIndirectRecordsreads the count and records for both CPU-path sites inDraw.cpp(the finisher and the empty-indirect skip). When a pending image covers the count word or the records, it first waits for the recorded GPU writes over that range (VulkanDevice::SyncRecordedWrites), then reads guest memory without the hook (Pm4::ReadDrawCountUnsynced,Pm4::ReadDrawArgumentsUnsynced). Earlier GPU writes to the records still land first, and the image is not stored by the read. With no pending image over the range, the read is unchanged: it still goes through the hook, so the draw does not take the GPU mutex when nothing needs it.FlushPendingstores the image under them, and the draw reads the texels as vertices. It now passesQueuedDrawReadRangesfor the record, like a queued direct draw. The image stays pending until the draw has read, as on the GPU-indirect path.Test: on a device without indirect count draws, the count case skips the gate and the held-read checks, because its arguments are read on the CPU before the draw is queued, so no queued read of them exists. It prints that and still checks the triangle and the image landing afterwards (
LandPool). Devices with indirect count draws run the case as before.#20528 skips the count case on such devices and leaves the fallback as it is. This change fixes the fallback instead, so the case keeps running on MoltenVK.
Tested
Setup:
-DCMAKE_OSX_ARCHITECTURES=x86_64; tests run under RosettaANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1mainwith the open macOS build fixes appliedResults:
agc_driver_queued_indirect_read_ordertimes out before this change and passes after it in 3 of 3 runs, with both cases drawing the triangle. With only the record read changed, it still failed: the queued commit stored the image under the vertex buffer (APS5_TRACE_FLUSH:imported buffer region), so nothing was drawn. That is why the queued draw now holds its reads.ctest -R 'indirect|pm4|draw_offset|pipelin'(137 tests) passes. A first version always took the GPU mutex for the sync, and that madeagc_driver_pipelined_indirect_drawdrain the pipeline. The sync now runs only over a pending image.ctest -R '^(agc|shader|job)'(1578 tests,-j 1) and compared it with the same run before this change:agc_driver_queued_indirect_read_orderis fixed and nothing that passed before fails because of this change.agc_driver_gds_dma_fillfailed once in that run; it passed in 5 of 5 reruns and also failed once in an earlier run without this change.Not run on lavapipe, AMD or NVIDIA. Devices with
drawIndirectCounttake the GPU path for this draw, so for them only the empty-indirect skip and the CPU path for other feature gaps change.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T03:23:19Z.
Review: COMMENTED
Tested on an Apple M4 (macOS 27.2, MoltenVK 1.4.2 from the LunarG SDK 1.4.363.1, x86-64 build under Rosetta).
This PR doesn't merge cleanly into current
main(bb95654123).git merge-treereports a conflict incore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp. I didn't resolve it. I tested the PR's merge-base3e1b183e43against the PR head839a1dbc62, with no changes to either side. Both built apart fromlibcurl.prx(#17425) and two guest test objects that fail identically on both sides (GuestAudiodecNative.cpp,GuestUserServiceKratos.cpp).The test set is the 29
agc_driver_*tests that fail on currentmainon this Mac (ds_permute,f32_denormal_flush,image_sample_lod_*,label_*,pixel_sample_*,provoking_vertex,queued_indirect_read_order,tessellation, and others); the 26 of them that exist at the merge-base ran. Environment:ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer, three runs per side. Every test process loggedInsert instance layer "VK_LAYER_KHRONOS_validation"(layer 1.4.363), and none logged the missing-layer message.agc_driver_queued_indirect_read_orderagc_driver_label_after_import_copyVUID-lines per runqueued_indirect_read_orderaborts withAGC graphics: vkWaitForFences graphics: Vulkan result 2. With this PR, the M4 (nodrawIndirectCount) logsthe count-indirect draw whose arguments and count word the image covers: the device has no indirect count draws, so the arguments are read on the CPU before the draw is queued; only its result is checked, and then passes.label_after_import_copyis timing-sensitive on this Mac and flips onmaintoo, so I don't count it either way.VUID-lines are the same on both sides: 4VUID-VkDeviceCreateInfo-sType-unique(fromRecorder.cpp, addressed by #21965) and 6VUID-VkSamplerCreateInfo-samplerMipLodBias-04467. No regressions.Overlap: #20528 targets the same test on the same kind of device by skipping the count-indirect case when
VK_KHR_draw_indirect_countis missing. This PR instead runs that case through the CPU read. Both editQueuedIndirectReadOrder.cpp.I didn't test this on Linux, Windows or another GPU vendor.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T17:11:04Z.
Review: APPROVED
Reviewed — looks good
The change at head
839a1dbc62329dcd09d95821604566848fa44f63addresses CPU fallback reads overlapping pending image writes; the inspected code supports the change, but the full test suite was not run by this reviewer.What I ran
Read the prepared description, commits, manifest, diff, and changed source at the pinned head. No commands or tests were run. The full text of
VulkanDevice.cppwas excluded from the bundle; I read its changed region through the reader. The suppliedfiles.jsonwas unavailable through the reader, so its exclusions could not be enumerated.Results
files.jsonexclusionsFindings
Blocking
None.
Non-blocking
None.
Not verified
files.jsoncould not be read;VulkanDevice.cppwas reviewed at the changed region, and all six manifest entries were inspected.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T11:23:01Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed read ordering and queued draw handling look consistent with the stated CPU indirect fallback fix; one changed implementation file was excluded from the review bundle, so approval is not justified.
What I ran
2ca49c78f925dc933dceccbd3352d0f504f52566and targeted changed source ranges usingrepo_read.py.Results
Findings
Blocking
None verified in the code inspected.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppwas excluded from the prepared bundle because it was too large. Its addedSyncRecordedWritesimplementation was visible in the diff, but surrounding implementation and callers were not reviewed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T07:34:19Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
990f6471552ab7f09115df08d88490bcc7ce9661using the prepared diff andrepo_read.pyfor targeted source context. No build or tests were run; the test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build and runtime behavior were not verified. The PR description reports tests on Apple M4 with MoltenVK; those results were not independently run here. Read all changed files in
manifest.json, includingVulkanDevice.cppthrough the pinned reader;files.jsonwas unavailable through the reader.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T07:41:29Z.
Review: COMMENTED
Actionable comments posted: 1
Architecture findings (2)
Advisory architecture findings (2)
9a959518-a298-4810-9820-6ffea4a3105fReviewing files that changed from the base of the PR and between
611e7805f4and990f647155.core/libs/prx/libSceAgcDriver/Execution/include/Pm4.hppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Pm4.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/execution/QueuedIndirectReadOrder.cppIncluded 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 coderabbitai[bot] on 2026-11-30T08:37:20Z.
Review: COMMENTED
Architecture findings (1)
Advisory architecture findings (1)
7b8de474-5090-485a-bc7d-323d4f876c62Reviewing files that changed from the base of the PR and between
990f647155and36f4aae58a.core/libs/prx/libSceAgcDriver/tests/execution/QueuedIndirectReadOrder.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T08:41:00Z.
Review: APPROVED
Reviewed — looks good
Nothing in the reviewed changes shows a blocking defect; the submitted test results are author-reported and were not rerun here.
What I ran
36f4aae58a78b5557eb00a432be9c867b9741364using the pinned PR reader.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppwas excluded from the review folder because it was too large. Its changed implementation was inspected at the five changed lines through the reader, but the full file was not read.Pm4.hpp,VulkanDevice.hpp,Draw.cpp,Pm4.cpp, andQueuedIndirectReadOrder.cppwas not read; relevant changed sections and context were inspected.To get this to a good state
Nothing is required.