Skip to content

airconv, d3d11, d3d12: several geometry shader invocations per mesh threadgroup - #347

Merged
dttdrv merged 3 commits into
dttdrv:mainfrom
aaf2tbz:gs/packed-mesh-threadgroups
Nov 26, 2026
Merged

dttdrv merged 3 commits into
dttdrv:mainfrom
aaf2tbz:gs/packed-mesh-threadgroups

Conversation

@aaf2tbz

@aaf2tbz aaf2tbz commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Each geometry shader invocation was a mesh threadgroup of one thread. Metal Shader Converter packs several into one; this does too, in two stages. It is the "several geometry shader primitives per mesh threadgroup" item #341 left out.

This builds on #343 for the geometry payload change, which it rewrites around. Its first six commits are #343's; the last two are this PR's, and it can be rebased onto main once #343 is merged.

What changes

  1. airconv, d3d11, d3d12: a geometry draw's mesh threadgroups have a thread for each invocation they run. This is plumbing, with no change in what is drawn.
    • MTL_GEOMETRY_SHADER_REFLECTION's new MeshInvocations is how many invocations a mesh threadgroup runs where the pipeline rasterizes what the shader emits as it is.
    • SM50GeometryMeshInvocations gives a pipeline's count: 1 where it is conservative or streams output. The converter and the runtime both take it from there, so they cannot disagree.
    • The object stage starts a mesh threadgroup for that many of its primitives, rounded up, for each instance.
    • Every path that draws geometry gives each mesh threadgroup that many threads: D3D11's direct, indirect and DrawAuto draws, D3D12's direct draws and ExecuteIndirect, and the Metal 3 and Metal 4 indirect paths (wmtcmd_render_mullion_geometry_draw_indirect gains mesh_threads).
    • The mesh budget (get_gs_max_object_threadgroups) counts one mesh for each mesh threadgroup. host_geometry_budget now covers 1, 2, 3 and 32 invocations a threadgroup.
    • Every shader reports one in this commit.
  2. airconv: a geometry pipeline's mesh threadgroup runs as many invocations as fit its mesh.
    • The count is the most, up to 32, whose vertex slots (maxvertexcount each, at most 256) fit the mesh's 256 vertices and 512 primitives, and whose mesh fits the 16 KB the budget counts a mesh threadgroup. A points-to-quads GS (maxvertexcount 4) runs 32 a threadgroup, one of 16 vertices 16, one of 256 one.
    • Thread t takes the warp's primitive tg.x * MeshInvocations + t; a thread past the warp's last runs none.
    • Its vertices and primitives start at t times its slots. SV_PrimitiveID, the per-primitive outputs, cull-distance culling and the collapse of culled lines follow, as they are written at those indices.
    • The slots an invocation leaves are culled, each ending at its first vertex, so the mesh's primitive count is all of them, which the first thread gives. No thread waits for another.
    • MULLION_AIRCONV_SKIP=gs-packing gives the old output. AIRCONV_VERSION is 127.
    • host_geometry_packing checks the count, the mesh each mesh function declares, and the mesh threadgroups each object function starts. It covers points, lines and triangles, a mesh the vertex limit sizes and one its bytes do, and the conservative fallback. With MULLION_AIRCONV_SKIP=gs-packing, 14 of its checks fail.

Not packed yet, each a stage of its own:

  • Stream output: each invocation's place in the scratch counts comes from its threadgroup alone.
  • Conservative output: three vertices a triangle.
  • After a tessellator: the mesh threadgroup's threads are the domain stage's.
  • GS instances: these stay on the grid's y rather than sharing threads.
  • A warp of fewer primitives than the count: this leaves threads idle. Capping the count at the warp's primitives needs the vertex shader's registers and the topology on both sides.

Evidence

Mac mini, Apple M6, macOS 27.3. MetalSharp Wine 8.0 (arm64 with FEX), copied with --clone. ARM64EC build with -Denable_nvngx=true -Denable_nvapi=true -Denable_tests=true.

  • Both commits build on their own. Host suite: 27 OK, 1 skipped (host_dxbc_hash, which needs MULLION_HASHED).
  • tests/run.py --family native with the GS tests (d3d11_geometry d3d11_gs d3d11_streamout d3d11_drawauto d3d11_queries d3d12_geometry d3d12_streamout d3d12_conservative d3d12_cull_mesh d3d12_viewport_index d3d12_layers d3d12_wide d3d12_pipeline_statistics d3d12_indirect_shared d3d10): 63 passed, 5 failed, on both commits. The five (d3d10_block_values, d3d10_depth_stencil, d3d10_dxbc_arithmetic, d3d10_raster, d3d10_raster_bias) fail on main with the same digests.
  • The same GS tests except d3d10, under --validate on every default family (native, 9, 8, 7 and the three Metal 3 ones):
    • main and this branch both give 263 passed, 66 failed. The 66 are the same tests, families and digests on both.
    • So packing adds no validation failure, and it does not fix those already there. None of them comes from the one-thread design:
      • d3d12_layers reads the wrong cube faces;
      • d3d12_streamout_arguments stops at a counter heap descriptor assertion;
      • d3d12_cull_mesh (the mesh-only path, which this leaves alone) and d3d12_pipeline_statistics hang under GPU validation.

Speed (performance probe)

Bottom line: packing makes the points-to-quads scenes, the case it is for, about 10% cheaper on the CPU and about 2% on the GPU. It makes the pass-through scene about 1.5% more expensive on the CPU (explained below).

How it was measured:

  • Mullion's performance probe (tests/perf) draws small test scenes and times every frame.
  • Each scene ran on the same build with packing on, then with MULLION_AIRCONV_SKIP=gs-packing (packing off), six times over.
  • Each value is the average, over the six rounds, of the median frame time, in milliseconds. Lower is better.
  • "Faster in" counts the rounds where packing on was faster.

GPU time per frame

Scene What it draws Packing off Packing on Change Faster in
gs_quads_dxbc 20,000 points, each expanded into a quad by a geometry shader 0.327 ms 0.310 ms 4.9% less 5 of 6 rounds
gs_quads_dxil the same, with the shader compiled as DXIL 0.331 ms 0.312 ms 5.6% less 5 of 6 rounds
gs_passthrough 5,000 small triangles through a geometry shader that passes them on 1.876 ms 1.937 ms 3.2% more 2 of 6 rounds
xfb_gs_dxbc stream output, which this does not pack (the control) 1.851 ms 1.790 ms 3.3% less 6 of 6 rounds

CPU time per frame

Scene Packing off Packing on Change Faster in
gs_quads_dxbc 0.125 ms 0.112 ms 10.4% less 6 of 6 rounds
gs_quads_dxil 0.124 ms 0.110 ms 11.2% less 6 of 6 rounds
gs_passthrough 1.058 ms 1.074 ms 1.5% more 0 of 6 rounds
xfb_gs_dxbc (the control) 1.606 ms 1.585 ms 1.3% less 4 of 6 rounds

How to read it:

  • The control. xfb_gs_dxbc runs the same code either way, yet measured 3.3% faster on the GPU with packing on. Packing on ran first in each round, and that alone moved the GPU times by about 3%. So the quad scenes' GPU gain beyond that bias is about 2%. Their CPU gain, about 10% against the control's 1%, stands.
  • The pass-through scene got slightly slower on the CPU in every round, about 1.5%.
    • Its triangle warps hold 10 primitives, but its mesh threadgroups have 32 threads, so 22 threads in each sit idle and cull their slots.
    • Its GPU average includes one outlier round (+21.6%); the other five were between −2.4% and +1.3%.
    • Capping the count at the warp's primitives, listed above as a later stage, removes the idle threads.

Not run

  • x86_64 was not built, and no 32-bit test ran (this Wine runs no i386 programs).
  • Only the M6 ran; the other families are MULLION_GPU_FAMILY masks of it.

…ead for each invocation they run

A geometry shader invocation is a mesh threadgroup of one thread: the object stage starts one for each of its
primitives and instances, and every draw gives each mesh threadgroup one thread. So that a mesh threadgroup can run
several invocations, a thread each, the converter now says how many it runs, and everything that starts one asks:

- MTL_GEOMETRY_SHADER_REFLECTION's MeshInvocations is how many a mesh threadgroup runs where the pipeline rasterizes
  what the shader emits as it is, and SM50GeometryMeshInvocations a pipeline's, one where it is conservative or
  streams output. The converter and the runtime both take a pipeline's from it.
- The object stage starts a mesh threadgroup for that many of its primitives, rounded up, for each instance.
- D3D11's direct, indirect and DrawAuto geometry draws, D3D12's direct ones and ExecuteIndirect give the mesh
  threadgroups that many threads, as the Metal 3 and Metal 4 indirect draws now can
  (wmtcmd_render_mullion_geometry_draw_indirect's mesh_threads).
- The mesh budget counts a mesh for each mesh threadgroup (get_gs_max_object_threadgroups).

Every shader still reports one, so nothing draws differently yet. host_geometry_budget checks the budget at 1, 2, 3
and 32 invocations a threadgroup.
…ons as fit its mesh

Each geometry shader invocation was a mesh threadgroup of one thread, where Metal Shader Converter packs several
into one. Now, where a pipeline rasterizes what the shader emits as it is (not conservative, no stream output, not
after a tessellator), a mesh threadgroup runs MeshInvocations of them, a thread each.

MeshInvocations is the most, up to a SIMD group's 32, whose vertex slots fit the mesh:
- each invocation has as many slots as the rasterized stream takes of it (maxvertexcount, at most 256);
- they must fit the mesh's 256 vertices and 512 primitives;
- the mesh must fit the 16 KB the draw's budget counts a mesh threadgroup, each vertex its position, varyings,
  point size and clip distances, and each primitive four words.
So a GS of points to quads (maxvertexcount 4) runs 32 a threadgroup, one of 16 vertices 16, and one of 256 one.

How a mesh threadgroup runs its invocations:
- Thread t takes the warp's primitive tg.x * MeshInvocations + t, and a thread past the warp's last runs none.
- Its vertices and primitives start at t times its slots: a strip's counters start there, and a point list's
  points are placed from there. SV_PrimitiveID, the per-primitive outputs, cull-distance culling and the collapse
  of culled lines all follow, as they are written at those indices.
- The slots an invocation leaves are culled, each ending at its first vertex, so the mesh's primitive count is all
  of them, which the first thread gives. No thread waits for another.

MULLION_AIRCONV_SKIP=gs-packing gives each invocation a mesh threadgroup of its own, as before. AIRCONV_VERSION is
127. host_geometry_packing checks the invocations, the mesh each mesh function declares, and the mesh threadgroups
each object function starts, for points, lines and triangles, for a mesh the vertex limit sizes and one its bytes
do, and conservatively; with MULLION_AIRCONV_SKIP=gs-packing 14 of them are wrong.
@dttdrv
dttdrv merged commit 40c68ee into dttdrv:main Nov 26, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants