Add metallib passthrough (#8886)

This commit is contained in:
Inner Daemons authored and GitHub committed 2026-01-30 13:52:05 -05:00
1 parent 1af73121f4
commit fab57513ec
26 files changed
+891 -154

No files matched your search

+56 -30
View File
@@ -29,7 +29,6 @@ fn compile_hlsl(device: &wgpu::Device, entry: &str, stage_str: &str) -> wgpu::Sh
std::fs::remove_file(out_path).unwrap();
unsafe {
device.create_shader_module_passthrough(wgpu::ShaderModuleDescriptorPassthrough {
entry_point: entry.to_owned(),
label: None,
num_workgroups: (1, 1, 1),
dxil: Some(std::borrow::Cow::Owned(file)),
@@ -38,10 +37,9 @@ fn compile_hlsl(device: &wgpu::Device, entry: &str, stage_str: &str) -> wgpu::Sh
}
}
fn compile_msl(device: &wgpu::Device, entry: &str) -> wgpu::ShaderModule {
fn compile_msl(device: &wgpu::Device) -> wgpu::ShaderModule {
unsafe {
device.create_shader_module_passthrough(wgpu::ShaderModuleDescriptorPassthrough {
entry_point: entry.to_owned(),
label: None,
msl: Some(std::borrow::Cow::Borrowed(include_str!("shader.metal"))),
num_workgroups: (1, 1, 1),
@@ -50,6 +48,53 @@ fn compile_msl(device: &wgpu::Device, entry: &str) -> wgpu::ShaderModule {
}
}
struct Shaders {
ts: wgpu::ShaderModule,
ms: wgpu::ShaderModule,
fs: wgpu::ShaderModule,
ts_name: &'static str,
ms_name: &'static str,
fs_name: &'static str,
}
fn get_shaders(device: &wgpu::Device, backend: wgpu::Backend) -> Shaders {
// In the case that the platform does support mesh shaders, the dummy
// shader is used to avoid requiring EXPERIMENTAL_PASSTHROUGH_SHADERS.
match backend {
wgpu::Backend::Vulkan => {
let compiled = compile_wgsl(device);
Shaders {
ts: compiled.clone(),
ms: compiled.clone(),
fs: compiled.clone(),
ts_name: "ts_main",
ms_name: "ms_main",
fs_name: "fs_main",
}
}
wgpu::Backend::Dx12 => Shaders {
ts: compile_hlsl(device, "Task", "as"),
ms: compile_hlsl(device, "Mesh", "ms"),
fs: compile_hlsl(device, "Frag", "ps"),
ts_name: "main",
ms_name: "main",
fs_name: "main",
},
wgpu::Backend::Metal => {
let compiled = compile_msl(device);
Shaders {
ts: compiled.clone(),
ms: compiled.clone(),
fs: compiled.clone(),
ts_name: "taskShader",
ms_name: "meshShader",
fs_name: "fragShader",
}
}
_ => unreachable!(),
}
}
pub struct Example {
pipeline: wgpu::RenderPipeline,
}
@@ -60,33 +105,14 @@ impl crate::framework::Example for Example {
device: &wgpu::Device,
_queue: &wgpu::Queue,
) -> Self {
let (ts, ms, fs, ts_name, ms_name, fs_name) = match adapter.get_info().backend {
wgpu::Backend::Vulkan => (
compile_wgsl(device),
compile_wgsl(device),
compile_wgsl(device),
"ts_main",
"ms_main",
"fs_main",
),
wgpu::Backend::Dx12 => (
compile_hlsl(device, "Task", "as"),
compile_hlsl(device, "Mesh", "ms"),
compile_hlsl(device, "Frag", "ps"),
"main",
"main",
"main",
),
wgpu::Backend::Metal => (
compile_msl(device, "taskShader"),
compile_msl(device, "meshShader"),
compile_msl(device, "fragShader"),
"main",
"main",
"main",
),
_ => panic!("Example can currently only run on vulkan, dx12 or metal"),
};
let Shaders {
ts,
ms,
fs,
ts_name,
ms_name,
fs_name,
} = get_shaders(device, adapter.get_info().backend);
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[],