gfx-rs/wgpu
Mesh shading
wgpu exposes an experimental mesh-shading pipeline, mirroring DirectX 12 and Vulkan's mesh/task shader stages. Like ray tracing, it is experimental — the API is marked 🧪EXPERIMENTAL🧪 and the design is in flux.
docs/api-specs/mesh_shading.md is the authoritative spec.
What's exposed
A new pipeline shape with:
- An optional task stage (sometimes called amplification) that decides how many mesh-shader workgroups to dispatch per input primitive.
- A mesh stage that emits triangles directly, replacing the traditional vertex stage.
- An ordinary fragment stage as in the regular pipeline.
The relevant features in wgpu-types/src/features.rs:
Features::EXPERIMENTAL_MESH_SHADERFeatures::EXPERIMENTAL_MESH_SHADER_MULTIVIEW- Plus capability bits on
Limitsfor max mesh outputs, max payload size, etc.
Backend support
| Backend | Status |
|---|---|
| Vulkan | VK_EXT_mesh_shader. Requires a recent driver. |
| DX12 | DirectX 12 mesh shaders. Requires SM 6.5+ and an Agility SDK runtime. |
| Metal | Mesh shaders (added in Metal 3 / macOS 13+). Selectively enabled. |
| GLES | Not supported. |
| WebGPU (browser) | Not exposed in the spec yet; experimental on a per-browser basis. |
Implementation map
| Layer | Files |
|---|---|
wgpu API |
wgpu/src/api/render_pipeline.rs (mesh-shader pipeline descriptors), wgpu/src/api/render_pass.rs (draw_mesh_tasks*) |
wgpu-core |
render pipeline construction in wgpu-core/src/pipeline.rs and wgpu-core/src/command/render.rs (mesh-task dispatch path) |
wgpu-hal |
per-backend trait methods for dispatch_mesh_*; per-backend pipeline construction with a mesh stage |
wgpu-types |
Features bits, Limits fields |
naga |
EntryPoint's stage includes ShaderStage::Mesh and ShaderStage::Task; per-backend emission of mesh outputs |
Example
examples/features/src/mesh_shader/ is the canonical example. It demonstrates:
- Compiling mesh + task + fragment stages from a single WGSL file.
- Setting up a mesh-shader pipeline.
- Dispatching mesh tasks via
draw_mesh_taskson a render pass.
Naga support
Naga's IR has dedicated entry-point stages (ShaderStage::Mesh, ShaderStage::Task) and a Capabilities::MESH_SHADER / Capabilities::TASK_SHADER pair. Each shading-language backend emits the right pragmas/qualifiers:
- HLSL:
[OutputTopology("triangle")]+SetMeshOutputCounts+mesh structoutputs. - MSL: Mesh stage with
mesh_grid_properties+[[mesh]]attribute. - SPIR-V:
OpExtension VK_EXT_mesh_shader+OpCapability MeshShadingEXT.
The validator (naga/src/valid/interface.rs) checks that the entry-point I/O matches the stage rules: a mesh entry point must declare its output topology, a task entry point must dispatch to a mesh entry point, etc.
Testing
- The example doubles as an integration test (
cargo xtask test --bin wgpu-examples mesh_shader). - Adapter-level expectations gate the test on backends that support the feature.
- CTS coverage is limited; the WebGPU spec hasn't promoted mesh shading to a core extension yet.
Caveats
- Experimental. Expect breaking changes between wgpu releases.
- Driver maturity varies; mesh-shader code paths are newer than rasterization paths and have more outstanding driver bugs.
- HLSL output for mesh shaders is one of the more complex code paths in
naga::back::hlsl; checknaga/tests/in/wgsl/mesh_shader*.wgsland the corresponding.out/for the generated output.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.