feat(agc): emulate list primitive restart without VK_EXT_primitive_topology_list_restart #12180
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12180"
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 Gonic0 on 2026-10-28T01:26:57Z.
What
On a device without
VK_EXT_primitive_topology_list_restart(MoltenVK has none),precheckDrawrejects an indexed point, line or triangle list draw with primitive restart enabled. The pipeline already leavesprimitiveRestartEnableoff for lists on such a device, so this change does the restart on the CPU side instead:CompactListRestart(VertexInput.hpp) copies the indices as the primitive assembler reads them: each restart index drops the incomplete primitive before it, and an incomplete last primitive is dropped too. The draw uses the compacted count.IndirectDrawPath::FeatureGap), and each record's range is compacted into one new buffer, with its first index and count rewritten.Tests:
compactListRestartTestsintests/Graphics.cppchecks the compaction on the CPU. The newListRestartexecution test draws a triangle list0 R 3 4 5 0 1 2 3 4(R the restart index), directly and through indexed indirect records, and checks which of the two triangles reach the render target. On a device with the extension it checks the host's restart the same way. Without the extension it also draws the indirect records over an empty index range, and checks that nothing is drawn.Prior art: no open or closed PR emulates list restart. #115 added restart for strips, and for lists only with the extension; #2757 and #12125 handle restart in mesh-path strips and fans.
Overlap: #9875 (winstrex) edits the lines next to this change in
Graphics/src/Draw.cppandtests/Graphics.cppfor a different change (the index range of a draw). As agreed on #9875, it lands first and this PR rebases onto it: the compaction branch then takesDrawIndexRangeand theDrawIndexBoundsthatClampDrawIndicesreturns, and sets the draw's lowest index too. #6188 restructuresprecheckDrawand keeps the rejection.Tested
Apple M5 Pro, macOS 27.2, Apple clang 21.0.0, MoltenVK from Vulkan SDK 1.4.363 (no
primitiveTopologyListRestart), x86-64 Release under Rosetta 2.mainalone does not build libkernel or the driver on macOS. The tree ismaincccdaa2734plus only the open PRs it needs to build: #10552, #11447, #10669, #11554, #11437, #7631, #7804, andException.cppfrom #4630. #7631, #7804 and #4630 conflict withmain; I resolved them locally. This commit is on top.agc_driver_list_restart_testsagc_driver_graphics_testsGraphics/andExecution/restored frommainCompactListRestart)written = primitiveStart;removed fromCompactListRestartrecord.firstVertexOrIndex = cursor;removed fromCompactIndirectListRestartagc_driver_graphics_testssometimes stops at "two ranges under a budget for two were not imported", after MoltenVK refuses a host import (vkAllocateMemory-2). It did so in 2 of 10 runs with this commit and in 2 of 10 without it.The existing execution tests that draw with restart or indexed indirect records,
agc_driver_scalar_swappc_fetch_tests,agc_driver_stencil_replay_testsandagc_driver_draw_offset_indices_tests, pass 3 of 3 with this commit. On thede004fed72tree,agc_driver_tessellation_testsfailed with and without it, at the same check.With
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1,agc_driver_graphics_tests,agc_driver_stencil_replay_tests,agc_driver_scalar_swappc_fetch_tests,agc_driver_draw_offset_indices_testsandagc_driver_pixel_barycentric_emulation_testsreport noVUID-error onmainor with this change, and neither doesagc_driver_list_restart_testswith it. No log reports the layer as not found.ASTRO BOT (PPSA21564), on the same tree with
mainde004fed72(the change was identical), relinked with that tree's relinker (--macos --to-rosetta --macos-fixed-base 0x400000),ROSETTA_ADVERTISE_AVX=1 APS5_ASYNC_PIPELINES=1. The two library sets differ only inlibSceAgcDriver.prx. Runs in this order, each variant starting from an empty shader cache:The window stays black up to the mesh shader abort, so the title shows only that its draws are no longer rejected; the execution test is what checks the output.
Not tested on Linux or Windows. Where a driver has the extension, the emulation is not taken.
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 MarcZX10 on 2026-10-28T03:25:31Z.
Review: CHANGES_REQUESTED
I reviewed exact head
67ff0f666be6ec5c30a323e4cd89b7edb8489121. I found two blocking follow-ups:prepareDrawInputs, an indirect indexed draw with a zero-sized bound index range reachesstd::make_shared<Buffer>(context, indexBytes, ...)before the record ranges are compacted. The existing early return covers zerodraw.indexCountonly whenargs == nullptr;Bufferrejects size 0 (zero-sized GPU buffer). Such an indirect range has no valid indices and should become a no-op, but currently throws. Please handle the zero-byte case before constructing the buffer and cover it with a regression test.Draw.cppandGraphics.cpplines. CONTRIBUTING.md requires agreement on merge order and aDepends on: #Nentry for same-line overlaps. The PR body says the later one rebases, but does not record an agreed order/dependency. Please coordinate with #9875’s author and update the checklist; I am not asking either PR to be closed.The CPU compaction helper’s current unit cases cover restart positions and incomplete tails. Author-reported MoltenVK execution tests pass 3/3 and mutation controls fail as expected; the report also notes a separate
agc_driver_graphics_testshost-import flake at equal 2/10 rates with and without this change. Hosted policy checks pass; platform build jobs are skipped for these paths. I did not independently run the Apple GPU tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T10:00:40Z.
Review: APPROVED
Reviewed current head
beb5f7a309eb037970186a3d2c83db207e683681. The two blockers from my review of67ff0f666bare addressed: the zero-byte index range now returns a no-op before allocating the compacted buffer and has an execution regression case; and the overlap with #9875 now has explicit author agreement on merge order, aDepends on: #9875checklist entry, and the rebased implementation uses the updated index-range/bounds APIs. The author reports the focused macOS and validation-layer runs on this head, including the zero-sized-buffer negative control; hosted Windows and conventions checks pass. I did not independently reproduce the GPU runs in this environment. No further blocking issue found in the reviewed diff.