Skip to content

Commit b5bd5ae

Browse files
inner-daemonsWumpf
andauthored
Mesh shaders MSL writer (gfx-rs#8739)
* Single squashed commit * Updated changelog * Fixed stupid changelog thing * If I have to do this one more fucking time I'm gonna lose it * Removed some pub(super)'s * Thing --------- Co-authored-by: Andreas Reich <[email protected]>
1 parent 63727cf commit b5bd5ae

46 files changed

Lines changed: 1787 additions & 553 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Bottom level categories:
5454
#### Metal
5555

5656
- Unconditionally enable `Features::CLIP_DISTANCES`. By @ErichDonGubler in [#9270](https://github.com/gfx-rs/wgpu/pull/9270).
57+
- Added full support for mesh shaders, including in WGSL shaders. By @inner-daemons in [#8739](https://github.com/gfx-rs/wgpu/pull/8739).
5758

5859
#### DX12
5960

@@ -68,6 +69,7 @@ Bottom level categories:
6869
#### General
6970

7071
- `Features::CLIP_DISTANCE`, `naga::Capabilities::CLIP_DISTANCE`, and `naga::BuiltIn::ClipDistance` have been renamed to `CLIP_DISTANCES` and `ClipDistances` (viz., pluralized) as appropriate, to match the WebGPU spec. By @ErichDonGubler in [#9267](https://github.com/gfx-rs/wgpu/pull/9267).
72+
- Added more granular limits for mesh shaders. By @inner-daemons in [#8739](https://github.com/gfx-rs/wgpu/pull/8739).
7173
- Added new `InvalidWorkgroupSizeError`, which is now used by `DrawError::InvalidGroupSize` and `StageError::InvalidWorkgroupSize`. By @andyleiserson in [#9357](https://github.com/gfx-rs/wgpu/pull/9357).
7274

7375
#### Validation

examples/features/src/mesh_shader/mod.rs

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ fn compile_wgsl(device: &wgpu::Device) -> wgpu::ShaderModule {
1212
}
1313
}
1414

15-
fn compile_msl(device: &wgpu::Device) -> wgpu::ShaderModule {
16-
unsafe {
17-
device.create_shader_module_passthrough(wgpu::ShaderModuleDescriptorPassthrough {
18-
label: None,
19-
msl: Some(std::borrow::Cow::Borrowed(include_str!("shader.metal"))),
20-
num_workgroups: (1, 1, 1),
21-
..Default::default()
22-
})
23-
}
24-
}
25-
2615
struct Shaders {
2716
ts: wgpu::ShaderModule,
2817
ms: wgpu::ShaderModule,
@@ -32,33 +21,15 @@ struct Shaders {
3221
fs_name: &'static str,
3322
}
3423

35-
fn get_shaders(device: &wgpu::Device, backend: wgpu::Backend) -> Shaders {
36-
// In the case that the platform does support mesh shaders, the dummy
37-
// shader is used to avoid requiring PASSTHROUGH_SHADERS.
38-
match backend {
39-
wgpu::Backend::Vulkan | wgpu::Backend::Dx12 => {
40-
let compiled = compile_wgsl(device);
41-
Shaders {
42-
ts: compiled.clone(),
43-
ms: compiled.clone(),
44-
fs: compiled.clone(),
45-
ts_name: "ts_main",
46-
ms_name: "ms_main",
47-
fs_name: "fs_main",
48-
}
49-
}
50-
wgpu::Backend::Metal => {
51-
let compiled = compile_msl(device);
52-
Shaders {
53-
ts: compiled.clone(),
54-
ms: compiled.clone(),
55-
fs: compiled.clone(),
56-
ts_name: "taskShader",
57-
ms_name: "meshShader",
58-
fs_name: "fragShader",
59-
}
60-
}
61-
_ => unreachable!(),
24+
fn get_shaders(device: &wgpu::Device) -> Shaders {
25+
let compiled = compile_wgsl(device);
26+
Shaders {
27+
ts: compiled.clone(),
28+
ms: compiled.clone(),
29+
fs: compiled.clone(),
30+
ts_name: "ts_main",
31+
ms_name: "ms_main",
32+
fs_name: "fs_main",
6233
}
6334
}
6435

@@ -68,7 +39,7 @@ pub struct Example {
6839
impl crate::framework::Example for Example {
6940
fn init(
7041
config: &wgpu::SurfaceConfiguration,
71-
adapter: &wgpu::Adapter,
42+
_adapter: &wgpu::Adapter,
7243
device: &wgpu::Device,
7344
_queue: &wgpu::Queue,
7445
) -> Self {
@@ -79,7 +50,7 @@ impl crate::framework::Example for Example {
7950
ts_name,
8051
ms_name,
8152
fs_name,
82-
} = get_shaders(device, adapter.get_info().backend);
53+
} = get_shaders(device);
8354
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
8455
label: None,
8556
bind_group_layouts: &[],

examples/features/src/mesh_shader/shader.metal

Lines changed: 0 additions & 77 deletions
This file was deleted.

naga-cli/src/bin/naga.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ fn run() -> anyhow::Result<()> {
575575

576576
params.spv_out.mesh_shader_primitive_indices_clamp = args.validate_mesh_output;
577577
params.spv_out.task_dispatch_limits = args.task_limits.0;
578+
params.msl.mesh_shader_primitive_indices_clamp = args.validate_mesh_output;
579+
params.msl.task_dispatch_limits = args.task_limits.0;
578580
params.hlsl.mesh_shader_primitive_indices_clamp = args.validate_mesh_output;
579581
params.hlsl.task_dispatch_limits = args.task_limits.0;
580582

naga/src/back/msl/keywords.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ const RESERVED: &[&str] = &[
344344
// Naga utilities
345345
"DefaultConstructible",
346346
// Naga builtin names
347-
"__local_invocation_id",
347+
"__local_invocation_index",
348348
super::writer::FREXP_FUNCTION,
349349
super::writer::MODF_FUNCTION,
350350
super::writer::ABS_FUNCTION,

0 commit comments

Comments
 (0)