Repository navigation
perf(agc): draw mesh-stage indirect draws on the GPU - #460
Merged
oneandonlydean merged 1 commit intoOct 4, 2026
Merged
Conversation
oneandonlydean
force-pushed
the
perf/agc-gpu-mesh-indirect
branch
from
October 3, 2026 14:02
b13db4e to
276e377
Compare
A mesh program took its draw's index count from push constants, so an indirect mesh-path (NGG) draw needed the CPU to read its record first, waiting for the GPU to finish everything recorded before. In PPSA21564 that was about 170 waits per 10 s at the title, menu and level (about 1 s), and one per frame in the intro (2.2 s per 10 s). The two free mesh push dwords now carry the device address of an argument record (a VkDrawMeshTasksIndirectCommandEXT followed by the index count and first index). When the address is set, the prologue takes the index count and the first index from the record (the new MeshArgument IR value, a load through a physical storage buffer pointer) and offsets its index reads by the first index; a direct draw leaves the address 0 and draws as before. Mesh modules declare the physical storage buffer capability for it, and the driver's SPIR-V validation accepts the extension in mesh modules. An indexed mesh draw with one record that patches no user SGPR now stays on the GPU. A one-thread compute pass (Graphics/shaders/MeshArguments.comp) turns the record, read in place from its host import, into the draw's argument record: the groups and instances of vkCmdDrawMeshTasksIndirectEXT and the index count and first index the mesh program reads, with the CPU path's rules (count clamped to the index buffer, nothing for an empty record or past the device's group limits). The index buffer descriptor covers the whole buffer and the program offsets by the first index. When the records cannot be read in place, the CPU reads them and fills the same argument record (ResolveMeshArguments).
oneandonlydean
force-pushed
the
perf/agc-gpu-mesh-indirect
branch
from
October 4, 2026 03:06
276e377 to
fb55cb2
Compare
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Depends on #440 (triangle fans as NGG geometry input): this branch carries #440's commit, rebased onto current
main, so please review only the last commit. Both change the mesh-path group count inDraw.cppandInstructionTranslator.cpp, and the argument rules here treat a fan like a strip (input step 1). Once #440 is merged I will rebase and its commit drops out.An indirect draw on the mesh path (NGG) reads its record on the CPU, because the mesh program takes the draw's index count from push constants. Reading the record waits for the GPU to finish everything recorded before it. In PPSA21564 that was about 170 waits per 10 s at the title, menu and level (about 1 s), and one per frame in the intro (2.2 s per 10 s).
An indexed mesh draw with one record that patches no user SGPR now stays on the GPU:
VkDrawMeshTasksIndirectCommandEXTfollowed by the index count and first index). When the address is set, the prologue takes the index count and the first index from the record (the newMeshArgumentIR value, a load through a physical storage buffer pointer) and offsets its index reads by the first index. A direct draw leaves the address 0 and draws as before. Mesh modules declare the physical storage buffer capability for this, and the driver's SPIR-V validation accepts that extension in mesh modules.Graphics/shaders/MeshArguments.comp) turns the record, read in place from its host import, into the argument record: the groups and instances forvkCmdDrawMeshTasksIndirectEXT, and the index count and first index for the mesh program. It applies the CPU path's rules: the count is clamped to the index buffer, and an empty record or one past the device's group limits draws nothing. The index buffer descriptor covers the whole buffer and the program offsets by the first index. When the record cannot be read in place, the CPU reads it and fills the same argument record (ResolveMeshArguments).Tested
BUILD_TESTING=ONandctestpass (145/145).meshArgumentTestsinagc_driver_graphics_tests(the rules, shared by the compute pass and the CPU path): full and partial groups for lists, strips and fans, the count clamped to the index buffer, a first index past it, zero instances or indices, the device's group and instance limits, and a first index near the end of an index buffer of 2^32 - 1 indices.agc_driver_mesh_tests(GPU, run by hand): an indexed triangle list drawn from a record, a record that draws triangles 5 to 14 through its first index, a count past the end of the index buffer, three empty records that draw nothing, and an indexed triangle fan. All seven take the GPU path. With the first-index offset removed from the prologue, the index range case fails ("indirect index range: triangle 0 ...").Draw.cpp,Recorder.*,ShaderValidation.cppor the IR opcode list (feat(libSceAgcDriver): back the global data share with driver-owned guest memory #285, feat(agc): host import windows, least-recent eviction under the budget #290, perf(agc): draw cache keys on the user words a program reads, memoizes failures, serves data-only hits #291, fix(agc): color targets with gaps between written MRT slots, depth array slices #294, feat(shader): implement ds_permute_b32 #334, feat(shader): implement the missing integer image atomics #368, feat(agc): depth bounds test and depth bias #376, feat(agc): 4 KiB standard color targets and color views of one array slice #377, test(shader): cover integer image atomics #381, perf(agc): copy the interleaved attributes of a vertex buffer once per draw #410, perf(agc): draw templates rebind moved read-only buffers and data words #424, feat(shader): implement basic f64 VALU ops #446 and others) merge cleanly with this branch.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 repository (attach them to this PR)