Repository navigation
airconv, d3d11, d3d12: several geometry shader invocations per mesh threadgroup - #347
Merged
Merged
Conversation
…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.
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.
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
mainonce #343 is merged.What changes
MTL_GEOMETRY_SHADER_REFLECTION's newMeshInvocationsis how many invocations a mesh threadgroup runs where the pipeline rasterizes what the shader emits as it is.SM50GeometryMeshInvocationsgives 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.wmtcmd_render_mullion_geometry_draw_indirectgainsmesh_threads).get_gs_max_object_threadgroups) counts one mesh for each mesh threadgroup.host_geometry_budgetnow covers 1, 2, 3 and 32 invocations a threadgroup.tg.x * MeshInvocations + t; a thread past the warp's last runs none.MULLION_AIRCONV_SKIP=gs-packinggives the old output. AIRCONV_VERSION is 127.host_geometry_packingchecks 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. WithMULLION_AIRCONV_SKIP=gs-packing, 14 of its checks fail.Not packed yet, each a stage of its own:
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.host_dxbc_hash, which needsMULLION_HASHED).tests/run.py --family nativewith 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 onmainwith the same digests.d3d10, under--validateon every default family (native, 9, 8, 7 and the three Metal 3 ones):mainand this branch both give 263 passed, 66 failed. The 66 are the same tests, families and digests on both.d3d12_layersreads the wrong cube faces;d3d12_streamout_argumentsstops at a counter heap descriptor assertion;d3d12_cull_mesh(the mesh-only path, which this leaves alone) andd3d12_pipeline_statisticshang 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:
tests/perf) draws small test scenes and times every frame.MULLION_AIRCONV_SKIP=gs-packing(packing off), six times over.GPU time per frame
gs_quads_dxbcgs_quads_dxilgs_passthroughxfb_gs_dxbcCPU time per frame
gs_quads_dxbcgs_quads_dxilgs_passthroughxfb_gs_dxbc(the control)How to read it:
xfb_gs_dxbcruns 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.Not run
MULLION_GPU_FAMILYmasks of it.