Repository navigation
D3D12 tessellation on the mesh pipeline alone, and tessellation templates - #356
Merged
Merged
Conversation
a tessellated pipeline drew its direct draws through Metal's tessellator where it tessellates as Direct3D does (c951e38): on Metal 3 encoders a hull kernel before the pass and drawPatches, on Metal 4 the compute tessellator (0aa66a0), whose count, scan and emit kernels made each pass's points and indices before the pass for an indexed draw, with a mesh draw after any draw the pass's arena had no room for. every other draw, indirect ones, those under pipeline statistics and those of pipelines the tessellator did not take (isolines, fractional partitioning on Metal 3, geometry shaders, conservative rasterization, clip and cull distances, UAVs in the vertex or hull shader) already took the mesh pipeline, whose object stage runs the vertex and hull shaders and whose mesh stage tessellates and runs the domain shader, and which every tessellated pipeline makes. now every draw does, as D3D11's do. the hull kernel and patch pipeline, the compute tessellator's kernels, batches, arena sizing and alias barrier, and the allocator's arena allocations that may fail go. the converter still makes the native functions; nothing asks for them. d3d12_shadercache's tessellated pipeline converts its two mesh functions, not four. d3d12_sampler_pipelines' fault is now that a draw keeps the pipeline it was set with, and d3d12_patch_ids' that a domain shader numbers its patch within its object threadgroup's group; d3d12_tessellator's eighth fault, in the compute tessellator, goes with it.
…ctions alone nothing asks for Metal's tessellator's functions since D3D12's draws all take the mesh pipeline: the hull kernel that wrote a native draw's patches and factors (SM50_SHADER_PSO_TESSELLATOR_DATA's native), the domain shader as a post-tessellation vertex function and, with compute, as the vertex function of the compute tessellator's indexed draw, the pixel shader's SV_PrimitiveID from SM50_PATCH_VARYING, the reflection's PatchGroupSize, their bindings, and the compute tessellator's numbering and emitting in air_tessellation.metal go, with winemetal's copies of the fields. AIRCONV_VERSION 128, for the reflection. host_tessellator checks the mesh stage's workloads, groups and zips as before, without the compute tessellator's buffers.
a benchmark (meson benchmark, run.py --benchmark): each frame is 8 draws of 128 patches in 4 instances over a 1024x1024 target, a domain shader that displaces its points with a few sines and passes a normal and coordinates on, for tri and quad domains, integer and fractional_odd partitioning, factors 4 to 64. a frame's GPU time is between two timestamp queries, the median of the frames less that of as many empty frames; all are recorded before any is read, a frame of a low factor repeats its draws to about 3 ms, and 300 ms of frames first raise the GPU's clock: without these an M6 reported low factors at twice their time, run to run. `culled` faces every triangle away, which leaves the stages before the rasterizer: at factor 64 most of a frame is rasterizing 33M one-pixel triangles. `plain` interpolates only, `declared=F` declares F the largest factor, `capture` records no frames before those measured, for a GPU capture, and `dump` writes the shaders for the converter's command line.
… of domain vertices of a size does --tessellator-vertex-size N gives the stage SM50_SHADER_PSO_TESSELLATOR_DATA, of factors up to 64 and a domain shader of N-byte vertices, without a geometry shader: the conversion a pipeline makes, with groups of workloads, where without it the command line made the stages of no pipeline.
…me points is drawn from a template a tessellated draw's mesh stage was integer-bound (78% on an M6) by the tessellator's bookkeeping, a vertex looking its workload up among its group's and placing its point, a triangle zipping its frame, and by evaluating 1.4 to 2 times the patch's points: a group of workloads shares only consecutive frames' edges, and at factor 64 a group was one workload of 132 vertices and 128 triangles. a patch whose factors (edges and inside) all have the same points, and so the same parity, is tessellated alike whatever their fractions, which only place its points (D3D11.3 11.7). the device makes once a process, from the tessellator's own source built for the host, a template for each domain and 2 to 65 points a side: meshlets of at most 128 vertices and 256 triangles in Morton order, each vertex its point's place (a quad's grid coordinates, a triangle's ring, side and place on it) and each triangle its corners, clockwise, a byte each; 2 MB, 37 ms. with groups, for a tessellator of triangles, the hull stage writes such a patch as its factors and its meshlets' groups (emit_template), and the mesh stage's thread places its vertex from the patch's factors and copies the meshlet's triangles. 0.68 vertices a triangle; the object stage writes no workloads for it. other patches, isolines, points, lines, geometry shaders and conservative rasterization keep the workloads. the templates are a buffer of the device's (D3D12: made with the first tessellation pipeline, resident with the device's; D3D11: of the context, used once a pass) at SM50_BINDING_INDEX_TESSELLATION_TEMPLATES for both stages; a mesh of a pipeline with templates has room for a meshlet. MULLION_AIRCONV_SKIP=tessellation-templates draws no patch from one. AIRCONV_VERSION 129. host_tessellation_templates checks every template against the reference tessellator: 5120693 triangles of 2024 uniform patches of every partitioning, whole and fractional factors, each meshlet within its limits; it fails with the triangles kept wound the other way (2024 wrong). d3d11_tessellator's second fault winds a meshlet's triangles the other way when they are put (1434624 wrong). 104 tessellation, geometry, patch id and pipeline tests pass on native and native-metal3; host suite 28 ok. d3d11_tessellation_bench (M6, median, the stages before the rasterizer, culled): 39.13 ms to 21.66 ms in all, 1.81x; every configuration 1.53x to 2.49x (quad integer 16 0.669 to 0.367 ms, tri integer 64 6.095 to 3.320 ms). drawn, with the rasterizer's work on 1-pixel triangles that every way of tessellating has: 124.3 ms to 100.0 ms, 1.04x to 1.46x.
the tessellation library links into a stage before its optimization, which inlines only the functions that must be (AlwaysInlinerPass): a lookup, a zip or a template's placing stayed a call, and what it was given by pointer (a group's edge bases, a zip) stayed on the stack. its functions are marked always-inline as they link. d3d11_tessellation_bench (M6, culled, with tessellation templates): quad integer 4 0.088 to 0.080 ms, 16 0.387 to 0.376 ms, tri integer 16 0.263 to 0.259 ms; without templates 2% to 6% on triangle domains. host suite and the tessellation tests pass.
…rior from a template a patch's rings but ring 0 depend on its inside factor alone: ring 0's frames join its edges, whatever their factors, to ring 1. so a patch whose edges' points differ from its inside's (a quad's two inside factors the same points) is its record, ring 0's frames as workloads, grouped as emit groups them, and the meshlets of the interior template of its inside's points: the device's templates now hold, for each domain and 7 to 65 points, the meshlets of the rings but ring 0 (template version 2, 4 MB); a smaller interior is drawn by its workloads, as its own mesh threadgroup costs more than it saves (factor 4: 0.97x to 1.02x with templates of 5 points and up, 0.85x to 0.97x before this limit). a quad of two inside factors of different points keeps the workloads. AIRCONV_VERSION 130, for the templates' layout and the inlined library before it. host_tessellation_templates also runs the hull stage's workloads and the mesh stage's groups a lane at a time, as the GPU does, for 3200 patches of mixed and uniform factors of every partitioning: 8045835 triangles as the reference's, 2283 patches with an interior template. d3d12_tessellator's eighth fault leaves ring 0's last frame out of such a patch (29528 wrong); d3d11_tessellator.2 and host_tessellation_templates are caught as before. 104 tessellation, geometry, patch id and pipeline tests pass on native and native-metal3; host suite 28 ok. d3d11_tessellation_bench mixed (each patch's edges 1, 0.75, 0.5 and 0.875 of its inside factor), against templates skipped: culled 40.70 ms to 23.77 ms, 1.71x (factor 16 1.35x to 1.57x, 64 1.72x to 2.00x, 8 1.09x to 1.57x); drawn 121.2 to 101.2 ms, 1.20x. uniform factors stay 1.76x culled.
# Conflicts: # src/airconv/airconv_public.h # src/d3d12/d3d12_command_allocator.cpp # src/mullion/mullion_command_constants.hpp
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.
Every D3D12 tessellated draw now takes the mesh pipeline, as D3D11's already do. The mesh stage then draws most patches from tessellation templates: meshlets the device builds once per domain and point count. On an M6 this makes the stages before the rasterizer 1.7x to 1.8x faster. AIRCONV_VERSION becomes 130, so shader caches are rebuilt once.
What changes
d3d12: every tessellated draw takes the mesh pipeline. Some direct draws went through Metal's tessellator (c951e38): a hull kernel and
drawPatcheson Metal 3, and the compute tessellator on Metal 4 (0aa66a0). Every other draw already took the mesh pipeline, and every tessellated pipeline makes it. Removed:d3d12_sampler_pipelines' andd3d12_patch_ids' faults are rewritten for the mesh path.d3d12_tessellator's eighth fault was in the compute tessellator, so it is replaced (see 6).airconv: a tessellation pipeline's stages are its object and mesh functions alone. The converter's native and compute tessellator functions go, along with the reflection's
PatchGroupSize, their bindings, and winemetal's copies of the fields. AIRCONV_VERSION 128.tests:
d3d11_tessellation_bench(a meson benchmark,run.py --benchmark).culledfaces every triangle away, which leaves the stages before the rasterizer.mixedgives each patch's edges 1, 0.75, 0.5 and 0.875 of its inside factor.airconv:
--tessellator-vertex-size Non the command line converts a tessellation stage as a pipeline does, for looking at the mesh functions.airconv, mullion, d3d11, d3d12: a patch whose factors all have the same points is drawn from a template. AIRCONV_VERSION 129.
air_tessellation.metalcompiled for the host (37 ms). There is one for each domain and 2 to 65 points a side: meshlets of at most 128 vertices and 256 triangles, in Morton order.SM50_BINDING_INDEX_TESSELLATION_TEMPLATESfor both stages. On D3D12 it is made with the first tessellation pipeline; on D3D11 it belongs to the context.MULLION_AIRCONV_SKIP=tessellation-templatesturns templates off.airconv, mullion, tests: a patch of mixed edge factors draws its interior from a template. AIRCONV_VERSION 130.
airconv: the tessellator's functions inline into a tessellation stage's. The library linked in before optimization, which inlines only always-inline functions, so lookups, zips and template placing stayed calls. They are now marked always-inline. This gains 3–10% with templates.
Still on the workloads: quads whose two inside factors have different point counts, isolines, point and line output, geometry shaders, and conservative rasterization.
Overlap with open PRs
d3d12_command_allocator.cpp. This PR removes that code. Whichever is merged second conflicts there.airconv_public.h. airconv, d3d11, d3d12: several geometry shader invocations per mesh threadgroup #347 also changesd3d12_command_list.cpp. Whichever is merged second conflicts on the version line, and the higher version resolves it. I'll rebase this PR on whichever lands first.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.-Denable_d3d12=false) build. Every commit builds on its own (ARM64EC).meson test --suite host): 23 OK, 1 skipped (host_dxbc_hash, which needsMULLION_HASHED).host_tessellation_templateschecks every template against the reference tessellator: 5120693 triangles of 2024 uniform patches, every partitioning, whole and fractional factors. It also runs the hull and mesh stage code one lane at a time, as the GPU does, for 3200 mixed and uniform patches: 8045835 triangles match the reference, 2283 of the patches through interior templates.tests/run.py --family native,native-metal3withd3d11_geometry d3d11_ia_patches d3d11_predication d3d11_primitiveid d3d11_tessellator d3d11_trace_encoders d3d12_conservative_hull d3d12_cull_mesh d3d12_deferred_pipelines d3d12_depthbounds d3d12_geometry d3d12_ia_patches d3d12_patch_ids d3d12_pipeline_statistics d3d12_predication d3d12_primitiveid d3d12_sampler_pipelines d3d12_shadercache d3d12_tessellation d3d12_tessellator: 104 passed, 0 failed.tests/faults.py, each fault caught:d3d12_tessellator.8(ring 0's last frame left out of a mixed patch): 29528 wrongd3d11_tessellator.2(a meshlet's triangles wound the other way): 1645399 wronghost_tessellation_templates(the generator winds the other way): 5107 wrongd3d12_patch_ids: 3 of 3 ways of drawing gave a pixel another patch's IDd3d12_sampler_pipelines: 4 of 8 reads wrongd3d11_tessellation_bench, the median of each configuration's frames, summed over all 16. The baseline is the same build withMULLION_AIRCONV_SKIP=tessellation-templates, which draws every patch from workloads.The drawn gain is smaller because at high factors most of a frame is rasterizing 1-pixel triangles, which this does not change. The lows of 0.98x and 0.99x are at factor 4, where mixed patches keep the workloads.
Not run
--validatewas not run.