gpu: add D3D12 meshlet amplification and mesh shader pipeline with vertex fallback #2454
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2462"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-25T17:22:54Z.
Change
Implements a self-contained Direct3D 12 / HLSL meshlet and amplification/mesh shader pipeline (
as_6_5+ms_6_5+ps_6_0) with an automatic fallback to the classic Input-Assembler vertex pipeline (vs_6_0+ps_6_0) whenD3D12_MESH_SHADER_TIER_1or Shader Model 6.5 is unavailable.Architecture decisions
src/meshlet_builder.h,src/meshlet_builder.cpp):kMaxMeshletVertices = 64andkMaxMeshletPrimitives = 126(hardware limits up to 256/256), deduplicating per-meshlet vertices intounique_vertex_indicesand packing local triangle indices into 32-bit words (packed_primitives).MeshletBounds(48-byte GPU-aligned): bounding sphere (center,radius) and left-handed CW normal cone (cone_apex,cone_cutoff,cone_axis), disabling cone culling (cone_cutoff = 2.0f) when triangle normals oppose or span too wide a cone.source_indicesalongside meshlet buffers so the vertex fallback renders the exact same geometry without re-conversion.src/shaders/meshlet_pipeline.hlsl):ASMain(as_6_5,[numthreads(32, 1, 1)]) performs per-meshlet frustum sphere culling against 6 frustum planes and normal-cone backface culling, records statistics ing_cull_stats(u0), compacts visible meshlet IDs into agroupsharedpayload, and invokesDispatchMesh.MSMain(ms_6_5,[outputtopology("triangle")],[numthreads(64, 1, 1)]) reads the compacted meshlet ID from the payload, callsSetMeshOutputCounts, transforms vertices viaview_proj, and unpacks triangle indices.VSMain(vs_6_0) andPSMain(ps_6_0) provide the matching classic vertex/pixel path sharing the sameSceneConstants(b0) andMeshletVertexstride (48 bytes).src/mesh_shader_pipeline.h,src/mesh_shader_pipeline.cpp):query_mesh_shader_capabilitiesinspectsD3D12_FEATURE_D3D12_OPTIONS7(MeshShaderTier),D3D12_FEATURE_SHADER_MODEL(probing SM 6.5+), andID3D12Device2.D3D12_PIPELINE_STATE_STREAM_DESCstream (equivalent toD3DX12_MESH_SHADER_PIPELINE_STATE_DESC, with separateAS+MS+PSandMS+PSstream structs so an empty AS subobject is never passed) and dispatches viaID3D12GraphicsCommandList6::DispatchMesh.D3D12_GRAPHICS_PIPELINE_STATE_DESCvertex pipeline (DrawIndexedInstancedwith matchingCULL_MODE_BACK,FrontCounterClockwise = FALSE, andLESS_EQUALdepth) inAutomode when unsupported or whenForceVertexFallbackis requested.Verification
56967492(feat/mesh-shaders)10.0.26300.0), MSVC 19.44, DXC1.9.2602.17, D3D12 debug layer enabledNVIDIA GeForce RTX 5080(vendor=10de device=2c02, driver32.0.16.2124)Microsoft Basic Render Driver(vendor=1414 device=008c, driver10.0.26100.9818)Commands and observed results:
meshlet_builder: Passed (0.03s) — single triangle, multi-meshlet grid partitioning, double-sided cone disable, 4-meshlet culling scene, and negative controls.offscreen_capability_table_self_test: Passed (0.03s).mesh_shader_pipeline_hardware: Passed (0.42s) —mesh_shader_tier=10 shader_model=0x66 mode=mesh,cull_stats tested=4 frustum_culled=1 backface_culled=1 dispatched=2,fallback_parity=exact,debug_errors=0 debug_warnings=0.mesh_shader_pipeline_fallback_hardware: Passed (0.23s) —mesh_shader_tier=10 mode=vertex_fallback,debug_errors=0 debug_warnings=0.mesh_shader_pipeline_warp: Passed (0.05s) —mesh_shader_tier=10 shader_model=0x66 mode=mesh,cull_stats tested=4 frustum_culled=1 backface_culled=1 dispatched=2,fallback_parity=exact,debug_errors=0 debug_warnings=0.mesh_shader_pipeline_fallback_warp: Passed (0.04s) —mesh_shader_tier=10 mode=vertex_fallback,debug_errors=0 debug_warnings=0.Also verified existing mesh amplification and root signature tests after final edits:
desktop_root_signature: Passed (0.02s).mesh_amplified_draw_hardware: Passed (1.37s,debug_errors=0 debug_warnings=0).mesh_amplified_draw_warp: Passed (0.43s,debug_errors=0 debug_warnings=0).Evidence and follow-up
tests/meshlet_builder_check.cpp,tests/mesh_shader_pipeline_draw.cpp) use original source-built synthetic geometry (build_culling_test_scene()) with 4 meshlets (2 visible front-facing quads, 1 back-facing quad, 1 frustum-culled quad).std::invalid_argumenton non-multiple-of-3 indices, out-of-range vertex index, invalid vertex/primitive limits) and pixel-level rejection of culled red/yellow meshlets on GPU readback.MeshShaderTier < 1,MeshShaderPipelineMode::Autoselects the classic vertex pipeline automatically; forced fallback parity is verified against the mesh shader output on both RTX 5080 and WARP.Checklist
AI-assisted contribution.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:17:07Z.
Review: COMMENTED
Review of head
56967492(comment only, no merge).Not mergeable by us yet
update-branchand a fresh check first.What I checked
src/meshlet_builder.cppplustests/meshlet_builder_check.cppbuild and pass on Linux with plain g++ (meshlet_builder_check: PASS).python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.pyandgit diff --check origin/main...HEADare clean.src/shaders/meshlet_pipeline.hlsl) reads correctly.DispatchMeshis called from all threads outside the cull branch. The payload slot count (32) matches the group size. The row-vectormulis the same inMSMainandVSMain.Findings
compute_boundsand the builder test still passed in both cases:src/meshlet_builder.cpp(if (min_dot <= 0.1f)): changed the threshold to-2.0f.src/meshlet_builder.cpp(result.cone_cutoff = std::sqrt(...)): replaced it with a constant1.0f.tests/meshlet_builder_check.cpponly asserts that opposing normals givecone_cutoff > 1.0f(line 138). Please add a case with a known flat patch where the expectedcone_cutoffand apex are computed by hand. Also add a case where a meshlet just over the threshold must stay culled or kept.build_meshletsacceptsmax_verticesandmax_primitivesup to 256.MSMaindeclaresverts[64]andtris[126], andnumthreads(64). Any caller using more than 64 vertices or 126 primitives would overrun the output arrays. Please clamp the public limits to 64/126, or document and assert it inmesh_shader_pipeline.cpp.tests/mesh_shader_pipeline_draw.cppdoes check GPU pixels against the vertex fallback and checks the cull stats ({4,1,1,2}). I could not run it here. A Win2025 WARP run is still needed to confirm WARP supports mesh shader tier 1 and that the test skips cleanly when it does not.Merge
This is shared GPU runtime code and is not tied to a game startup claim. Once findings 1 and 2 are addressed and the branch is updated, it can be re-reviewed and run on Win2025. I did not merge.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T19:34:28Z.
Built and run here: 5/5 pass on WARP and a physical GPU, and the five mutations split along the builder-versus-pipeline line
The four pipeline cases are worth what they cost: the same work on hardware and on WARP, each with and without the
fallback path, so an amplification-shader/draw-shader pair is exercised on two implementations.
meshlet_builderisthe CPU side and runs device-free.
Built with
cmake --build --preset dev --target meshlet_builder_checkand… --target offscreen_check; the pipelinecases drive
offscreen_check.exe <adapter> --mesh-shader-pipeline, not a separate executable, which is worth knowingbefore hunting for a
mesh_shader_pipeline_drawtarget that does not exist.Five mutations of
src/meshlet_builder.cpp2.0f→1.0f(enables backface cone culling by default)planes.empty() || !normalize(…)→false)1e-12f→1e-30fmin_dot <= 0.1f→-0.1fThe two caught ones are the ones a reader would most want pinned.
cone_cutoff = 2.0fwith the comment "> 1.0disables backface cone culling by default" is a deliberate, non-obvious default — flipping it to
1.0fsilently cullsbackfacing cones, and the fixture notices. And dropping the degenerate-axis refusal means a meshlet is emitted with a
cone axis that was never normalised, which the fixture also notices.
The three survivors, each with the input it would need
1e-12fepsilon. Reached only by a triangle whose cross product is near zero. The fixture's shapes arenon-degenerate, so a threshold change from
1e-12to1e-30cannot change any verdict it takes. A singledegenerate triangle (three collinear vertices) would pin it, and that is the case the guard exists for.
vertex_count == 0. No meshlet in the fixture has zero vertices. Whether the early return is load-bearing isthe interesting part: without it the loops do not run, and control falls through to the cone computation, where
planes.empty()would refuse — so the two paths may well differ in the returned cone, not just in speed. Worth anexplicit case either way.
min_dot <= 0.1f. The threshold decides when a cone is too wide to be worth culling. No fixture meshlet lands inthe band
(-0.1, 0.1], so widening the acceptance is invisible. A meshlet whose triangles sweep most of ahemisphere would pin it.
None of the three is a defect I can demonstrate: both guards read correctly, and each simply has no input whose
behaviour would change if it were removed or loosened. All three are cheap CPU-side cases in a device-free test.
One measurement I could not make
offscreen_check.exein this repository is a shared harness —tests/offscreen_check.cppgains 12 lines in this PR toadd the pipeline mode. So the pipeline cases assert whatever that mode asserts, which I ran but did not read closely.
If the mode's assertions are "the draw produced a non-empty image" rather than "these pixels", say so and I will read
that file rather than infer from the pass.
Environment
Windows 11 build 26300.9974; adapters: the installed physical GPU and Microsoft Basic Render Driver (WARP); the
fallbackcases run the same work without the amplification path. Each mutation was built, run, reverted and rebuilt;final state 5/5 green.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T20:37:30Z.
Hardware run at head
56967492. The branch is behindmain; this run tests the head as it stands, without a merge. This adds the adapter, driver and printed values to the earlier 5/5 report on this head.Environment: NVIDIA GeForce RTX 3070 Ti (
vendor=10de device=2482), driver 32.0.16.2101 (NVIDIA 621.01), Windows 11 Pro build 26300.9974,devpreset (MSVC). The runs were serial (-j1). Every offscreen test printsdebug_layer=enabledanddebug_errors=0 debug_warnings=0.Command:
ctest --preset dev --no-tests=error -j1 -V -R 'meshlet_builder|mesh_shader_pipeline'Result: 5/5 passed, 0 failed. By suffix: 2
_hardware, 2_warp, 1 other (meshlet_builder, CPU only:meshlet_builder_check: PASS). 0 capability skips (77).mesh_shader_pipeline_hardware(test 567):mesh_shader_tier=10 shader_model=0x66 mode=meshcull_stats tested=4 frustum_culled=1 backface_culled=1 dispatched=2fallback_parity=exactmesh_shader_pipeline_fallback_hardware(568) printsmesh_shader_tier=10 mode=vertex_fallback.WARP (
Microsoft Basic Render Driver,1414:008c, driver 10.0.26100.9818) prints the samemode,cull_statsandfallback_parityvalues.Not covered by this run: AMD, and any test outside the filter above.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:06:53Z.
Pushed
1be1f6ffeto this branch: a merge of currentmain(no rebase) plus one test commit.What I added, answering the weak cone-test point:
tests/meshlet_builder_check.cppnow has two cases.cutoff = sin(60 deg), a wide cone (87 deg) disables culling, and a cone at 80 deg still culls. This pins themin_dot <= 0.1fthreshold.1e-12fguard.Mutations (each makes the new test fail; the previous test still passed
-0.1f):min_dot <= 0.1f->-0.1for0.5flen_sq <= 1e-12f->1e-30fThe
vertex_count == 0early return is not reachable throughbuild_meshlets(a meshlet is only flushed with at least one primitive), so I did not add a case for it.Verification:
g++ -std=c++17 -Isrc tests/meshlet_builder_check.cpp src/meshlet_builder.cpp-> PASS; the three mutations above -> FAIL as listed.56967492:ctest --preset dev -R 'meshlet_builder|mesh_shader_pipeline'5/5 passed;ctest --preset releasesame selection 5/5 passed.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T07:06:26Z.
Review: APPROVED
Fixed the shader capacity mismatch identified in the earlier review. The general builder can make wider meshlets, but GPU upload on the mesh path now refuses more than 64 vertices or 126 primitives. Before the fix the new valid-input control exposed the issue on both WARP and RTX 4060 Laptop. With the fix, all 8 Windows Release CTests passed serially, including cone width and sliver coverage, mesh and vertex fallback on both adapters, and the adjacent amplification tests. Zero skips and no debug-layer warnings or errors.