Skip to content

perf(agc): draw mesh-stage indirect draws on the GPU - #460

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:perf/agc-gpu-mesh-indirect
Oct 4, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
oneandonlydean:perf/agc-gpu-mesh-indirect

Conversation

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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 in Draw.cpp and InstructionTranslator.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:

  • Recompiler: the two free mesh push dwords 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 this, and the driver's SPIR-V validation accepts that extension in mesh modules.
  • Driver: a one-thread compute pass (Graphics/shaders/MeshArguments.comp) turns the record, read in place from its host import, into the argument record: the groups and instances for vkCmdDrawMeshTasksIndirectEXT, 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).
  • Draws with several records, an indirect count, or a base vertex, start instance or draw index patched into user SGPRs still read their records on the CPU, as now.

Tested

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: feat(agc): take triangle fans as NGG geometry shader input #440; review only the last commit
  • AI-assisted: yes

@oneandonlydean
oneandonlydean force-pushed the perf/agc-gpu-mesh-indirect branch from b13db4e to 276e377 Compare October 3, 2026 14:02
@github-actions github-actions Bot added build shader core/shader agc libSceAgc* labels Oct 3, 2026
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).
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 4, 2026
@oneandonlydean
oneandonlydean force-pushed the perf/agc-gpu-mesh-indirect branch from 276e377 to fb55cb2 Compare October 4, 2026 03:06
@oneandonlydean
oneandonlydean merged commit 33a2f90 into boykopovar:main Oct 4, 2026
3 checks passed
@oneandonlydean
oneandonlydean deleted the perf/agc-gpu-mesh-indirect branch October 4, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build needs rebase Conflicts with main, rebase needed shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant