From 69863648a87bd23737ef2a52b057542694264bc6 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Mon, 21 Sep 2026 18:13:12 -0700 Subject: [PATCH] [core] Turn `ShaderMetaData` into a Naga-vs.-passthrough enum. Rename the `ShaderMetaData::Interface` variant to `NagaModule`, and make it a struct-like variant. Delete `ShaderMetaData::interface`, and update its call sites to use a `match` expression directly on the enum instead. This makes the use sites clearer, by making it apparent which style of module we're processing. --- wgpu-core/src/device/resource.rs | 54 +++++++++++++++++++------------- wgpu-core/src/pipeline.rs | 4 +-- wgpu-core/src/validation.rs | 12 ++----- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index fbfebd991..6b4a2e8f5 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -2718,7 +2718,7 @@ impl Device { let module = pipeline::ShaderModule { state: ResourceState::Valid(pipeline::ShaderModuleState { raw, - interface: ShaderMetaData::Interface(interface), + interface: ShaderMetaData::NagaModule { interface }, }), device: self.clone(), label: desc.label.to_string(), @@ -2878,13 +2878,15 @@ impl Device { let module = pipeline::ShaderModule { state: ResourceState::Valid(pipeline::ShaderModuleState { raw, - interface: ShaderMetaData::Passthrough(PassthroughInterface { - entry_point_names: descriptor - .entry_points - .iter() - .map(|e| e.name.to_string()) - .collect(), - }), + interface: ShaderMetaData::Passthrough { + interface: PassthroughInterface { + entry_point_names: descriptor + .entry_points + .iter() + .map(|e| e.name.to_string()) + .collect(), + }, + }, }), device: self.clone(), label: descriptor.label.to_string(), @@ -4561,10 +4563,12 @@ impl Device { None => None, }; - if shader_module_state.interface.interface().is_none() && pipeline_layout.is_none() { - return Err(pipeline::CreatePipelineError::Implicit( - pipeline::ImplicitLayoutError::Passthrough(wgt::ShaderStages::COMPUTE), - )); + if let ShaderMetaData::Passthrough { .. } = shader_module_state.interface { + if pipeline_layout.is_none() { + return Err(pipeline::CreatePipelineError::Implicit( + pipeline::ImplicitLayoutError::Passthrough(wgt::ShaderStages::COMPUTE), + )); + } } let mut binding_layout_source = match pipeline_layout { @@ -4590,7 +4594,7 @@ impl Device { ) .map_err(stage_err)?; - if let Some(interface) = shader_module_state.interface.interface() { + if let ShaderMetaData::NagaModule { ref interface } = shader_module_state.interface { io = interface .check_stage( &mut binding_layout_source, @@ -5181,7 +5185,8 @@ impl Device { .map_err(stage_err)?; vertex_shader_module.same_device(self)?; - if vertex_shader_module_state.interface.interface().is_none() { + if let ShaderMetaData::Passthrough { .. } = vertex_shader_module_state.interface + { passthrough_stages |= stage_bit; } @@ -5192,7 +5197,9 @@ impl Device { ) .map_err(stage_err)?; - if let Some(interface) = vertex_shader_module_state.interface.interface() { + if let ShaderMetaData::NagaModule { ref interface } = + vertex_shader_module_state.interface + { io = interface .check_stage( &mut binding_layout_source, @@ -5233,7 +5240,7 @@ impl Device { .map_err(stage_err)?; task_shader_module.same_device(self)?; - if task_shader_module_state.interface.interface().is_none() { + if let ShaderMetaData::Passthrough { .. } = task_shader_module_state.interface { passthrough_stages |= stage_bit; } @@ -5244,7 +5251,9 @@ impl Device { ) .map_err(stage_err)?; - if let Some(interface) = task_shader_module_state.interface.interface() { + if let ShaderMetaData::NagaModule { ref interface } = + task_shader_module_state.interface + { io = interface .check_stage( &mut binding_layout_source, @@ -5283,7 +5292,7 @@ impl Device { .map_err(stage_err)?; mesh_shader_module.same_device(self)?; - if mesh_shader_module_state.interface.interface().is_none() { + if let ShaderMetaData::Passthrough { .. } = mesh_shader_module_state.interface { passthrough_stages |= stage_bit; } @@ -5294,7 +5303,9 @@ impl Device { ) .map_err(stage_err)?; - if let Some(interface) = mesh_shader_module_state.interface.interface() { + if let ShaderMetaData::NagaModule { ref interface } = + mesh_shader_module_state.interface + { io = interface .check_stage( &mut binding_layout_source, @@ -5338,7 +5349,7 @@ impl Device { .map_err(stage_err)?; shader_module.same_device(self)?; - if shader_module_state.interface.interface().is_none() { + if let ShaderMetaData::Passthrough { .. } = shader_module_state.interface { passthrough_stages |= stage_bit; } @@ -5353,7 +5364,8 @@ impl Device { ) .map_err(stage_err)?; - if let Some(interface) = shader_module_state.interface.interface() { + if let ShaderMetaData::NagaModule { ref interface } = shader_module_state.interface + { io = interface .check_stage( &mut binding_layout_source, diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 16dfe538e..8d84b02d6 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -158,10 +158,10 @@ impl ShaderModule { ) -> Result { let state = self.state()?; match state.interface { - ShaderMetaData::Interface(ref interface) => { + ShaderMetaData::NagaModule { ref interface } => { interface.finalize_entry_point_name(stage, entry_point) } - ShaderMetaData::Passthrough(ref interface) => { + ShaderMetaData::Passthrough { ref interface } => { finalize_passthrough_entry_point_name(interface, entry_point) } } diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index 4fb75b8d7..a56b0240f 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -412,16 +412,8 @@ pub struct PassthroughInterface { #[expect(clippy::large_enum_variant)] #[derive(Debug)] pub enum ShaderMetaData { - Interface(Interface), - Passthrough(PassthroughInterface), -} -impl ShaderMetaData { - pub fn interface(&self) -> Option<&Interface> { - match self { - Self::Interface(i) => Some(i), - Self::Passthrough(_) => None, - } - } + NagaModule { interface: Interface }, + Passthrough { interface: PassthroughInterface }, } #[derive(Clone, Debug, Error)]