Skip to content

D3D11: Metal's tessellator, and vertex stages after a pass's pixel writes - #344

Closed
aaf2tbz wants to merge 2 commits into
dttdrv:mainfrom
aaf2tbz:split/d3d11-rendering
Closed

aaf2tbz wants to merge 2 commits into
dttdrv:mainfrom
aaf2tbz:split/d3d11-rendering

Conversation

@aaf2tbz

@aaf2tbz aaf2tbz commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Two D3D11 rendering changes: one correctness fix that games hit, and D3D11 tessellation on Metal's own tessellator. Split out of #341, with the same commits.

What changes

  • d3d11: a draw whose vertex stages use what the pass's pixel shaders wrote starts the next render pass.
    • A draw sees what earlier draws wrote through UAVs (D3D11.3 5.3.5.1). But a tile-based GPU shades a pass's vertices before its fragments, and Metal has no fragment-to-vertex barrier inside a pass. So the encoder dropped the barrier (A fragment-vertex barrier is omitted) and the vertex shader read stale data.
    • The context now tracks what the pass's pixel shaders read and wrote. It ends the pass before a draw whose VS/HS/DS/GS, vertex or index buffers, indirect arguments or stream output conflict with it.
    • d3d11_fragment_vertex_order: without the change, all four cases (SRV and vertex buffer, immediate and deferred) read 0 instead of 7.
  • d3d11: tessellate through Metal's tessellator where it tessellates as Direct3D does. D3D12 already did (d3d12: Tessellate through Metal's tessellator on Metal 3 and in compute on Metal 4 #173); D3D11 always used the mesh emulation.
    • Draws that meet D3D12's conditions run the converter's existing hull kernel in a compute pass before the render pass, then drawPatches. The conditions: tri or quad domain to triangles, integer or pow2 partitioning, no GS, stream output, tested clip or cull distances, VS/HS UAVs or statistics, and direct draws.
    • Every other draw keeps the mesh path, and d3d11.nativeTessellation = False forces it.
    • At factor 64 a draw takes 4.3 ms instead of 8.8 ms (M6, medians of 15 samples, 3 alternating runs per build). At factor 8 the difference is within noise.
    • d3d11_tessellation_native checks every pixel on both paths and that 24 draws are native; before: 0 draws ran hull kernels, want 24. d3d11_tessellator's 256 native draws match the reference tessellator.

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.

Not run

  • x86_64 was not built, and no 32-bit test ran (this Wine runs no i386 programs).

…rote starts the next render pass

A draw sees what the draws before it wrote through UAVs (D3D11.3 5.3.5.1), in every
stage. A tile-based GPU shades every draw's vertices in a render pass before any of its
fragments, and Metal has no barrier from fragment to vertex work inside a pass, so the
encoder dropped such a barrier ("A fragment-vertex barrier is omitted") and the later
draw's vertex shader read what was there before. The context now records which
resources the pass's pixel shaders read and wrote, and a draw whose vertex, hull, domain
or geometry shader, vertex or index buffers, indirect arguments or stream output read
what one of them wrote, or write what one read, ends the pass first, as a draw that has
no room for its scissors does. The next pass loads what this one stored.

d3d11_fragment_vertex_order reads, in a second draw's vertex shader, a value the first
draw's pixel shader wrote, through a shader resource view and as a vertex buffer, on the
immediate and a deferred context: without this all four read 0.
… Direct3D does

every tessellated draw took the mesh emulation, whose object stage runs the vertex and hull shaders and whose mesh
stage tessellates and runs the domain shader, a patch's workloads to a threadgroup. D3D12 has drawn through Metal's
tessellator on Metal 3 encoders since c951e38, and D3D11's encoders are all Metal 3's.

a pipeline whose tessellator Metal's tessellates as Direct3D's does, a triangle or quad domain to triangles with
integer or pow2 partitioning (D3D11.3 11.7.7.1: the hull kernel rounds pow2's factors), with no geometry shader,
stream output, clip distances the pixel shader tests, cull distances, UAVs in its vertex or hull shader or pipeline
statistics, also has the converter's native functions (SM50_SHADER_PSO_TESSELLATOR_DATA's native, as D3D12's): a hull
kernel and a post-tessellation vertex function running the domain shader. its direct draws run the kernel in a
compute encoder before their pass, which waits for what the pass's vertex stages wait for and makes resident what the
vertex and hull shaders read, and the pass waits for it; drawPatches then draws the patches it wrote. indirect draws,
draws under pipeline statistics and draws after a pre-raster stage has written in the pass, which the kernel would
read before the pass, keep the mesh pipeline, as does a pipeline Metal does not make the tessellator of. the domain
shader's tables are the vertex stage's too, and the vertex and hull shaders' are kept for the kernel, so a pass mixes
the two. d3d11.nativeTessellation = False keeps the mesh emulation for every draw.

the encoder trace names the kernels' encoder "hull", with its draws, and counts drawPatches as tessellation draws:
d3d11_trace_encoders expects it before the pass of the two direct tessellated draws.

d3d11_tessellation_native draws tri and quad patches, integer, pow2 and fractional_odd, clockwise and
counter-clockwise, directly, through 16- and 32-bit indices with a base vertex and a start instance, and indirectly
between, with each stage's constant buffer and the domain shader's buffer: each pixel is checked, with each setting,
and the trace shows 24 native draws with it on and none off. it fails without the change (0 hull kernels).
d3d11_tessellator, whose triangles are the reference tessellator's, draws 256 of its draws natively.

a large draw (8 draws of 128 quad patches x 4 instances, integer; GPU time between timestamp queries, median of 15
per run, three runs, Apple M6, no validation): factor 64 takes 4.28-4.32 ms natively against 8.74-8.86 ms through the
mesh emulation (8.74-8.78 ms before the change), factor 8 0.97-1.20 ms against 1.14-1.33 ms.
@aaf2tbz

aaf2tbz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing; not a worthwhile change.

@aaf2tbz aaf2tbz closed this Nov 24, 2026
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.

1 participant