mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 05:51:03 +01:00
[core] Combine ShaderModuleState with ShaderMetaData.
In `wgpu_core::pipeline`, delete `ShaderMetaData` and turn `ShaderModuleState` into the equivalent enum, giving both the `NagaModule` and `Passthrough` variants their own `raw` field. Arrange for uses of `ShaderModuleState` to extract the raw `wgpu_hal` module in the `match` expression that handles the two variants. In isolation, this change looks like mere rearrangement, not a cleanup, but hopefully either way it's easy to see that it has no effect on behavior. Subsequent commits will remove `raw` from the `NagaModule` variant; this refactor will allow that to affect only the `NagaModule` `match` arms, leaving the passthrough code unaffected.
This commit is contained in:
1 parent
00583c146b
commit
4f4581fdff
2 files changed
+75
-57
No files matched your search
@@ -47,7 +47,6 @@ use crate::{
|
||||
lock::{rank, Mutex, RwLock},
|
||||
pipeline::{
|
||||
self, shader_module_error_into_compilation_info, ColorStateError, PassthroughInterface,
|
||||
ShaderMetaData,
|
||||
},
|
||||
pool::ResourcePool,
|
||||
resource::{
|
||||
@@ -2719,10 +2718,7 @@ impl Device {
|
||||
};
|
||||
|
||||
let module = pipeline::ShaderModule {
|
||||
state: ResourceState::Valid(pipeline::ShaderModuleState {
|
||||
raw,
|
||||
interface: ShaderMetaData::NagaModule { interface },
|
||||
}),
|
||||
state: ResourceState::Valid(pipeline::ShaderModuleState::NagaModule { raw, interface }),
|
||||
device: self.clone(),
|
||||
label: desc.label.to_string(),
|
||||
compilation_info: wgt::CompilationInfo::default(),
|
||||
@@ -2879,16 +2875,14 @@ impl Device {
|
||||
};
|
||||
|
||||
let module = pipeline::ShaderModule {
|
||||
state: ResourceState::Valid(pipeline::ShaderModuleState {
|
||||
state: ResourceState::Valid(pipeline::ShaderModuleState::Passthrough {
|
||||
raw,
|
||||
interface: ShaderMetaData::Passthrough {
|
||||
interface: PassthroughInterface {
|
||||
entry_point_names: descriptor
|
||||
.entry_points
|
||||
.iter()
|
||||
.map(|e| e.name.to_string())
|
||||
.collect(),
|
||||
},
|
||||
interface: PassthroughInterface {
|
||||
entry_point_names: descriptor
|
||||
.entry_points
|
||||
.iter()
|
||||
.map(|e| e.name.to_string())
|
||||
.collect(),
|
||||
},
|
||||
}),
|
||||
device: self.clone(),
|
||||
@@ -4570,6 +4564,7 @@ impl Device {
|
||||
let mut io = validation::StageIo::default();
|
||||
let mut binding_layout_source;
|
||||
let final_entry_point_name;
|
||||
let module;
|
||||
|
||||
{
|
||||
let stage = validation::ShaderStageForValidation::Compute;
|
||||
@@ -4585,8 +4580,8 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
|
||||
match shader_module_state.interface {
|
||||
ShaderMetaData::NagaModule { ref interface } => {
|
||||
match shader_module_state {
|
||||
pipeline::ShaderModuleState::NagaModule { ref interface, raw } => {
|
||||
binding_layout_source = match pipeline_layout {
|
||||
Some(pipeline_layout) => {
|
||||
validation::BindingLayoutSource::Provided(pipeline_layout)
|
||||
@@ -4604,18 +4599,26 @@ impl Device {
|
||||
None,
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
|
||||
module = &**raw;
|
||||
}
|
||||
ShaderMetaData::Passthrough { .. } => match pipeline_layout {
|
||||
Some(pipeline_layout) => {
|
||||
binding_layout_source =
|
||||
validation::BindingLayoutSource::Provided(pipeline_layout);
|
||||
pipeline::ShaderModuleState::Passthrough { raw, .. } => {
|
||||
match pipeline_layout {
|
||||
Some(pipeline_layout) => {
|
||||
binding_layout_source =
|
||||
validation::BindingLayoutSource::Provided(pipeline_layout);
|
||||
}
|
||||
None => {
|
||||
return Err(pipeline::CreatePipelineError::Implicit(
|
||||
pipeline::ImplicitLayoutError::Passthrough(
|
||||
wgt::ShaderStages::COMPUTE,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return Err(pipeline::CreatePipelineError::Implicit(
|
||||
pipeline::ImplicitLayoutError::Passthrough(wgt::ShaderStages::COMPUTE),
|
||||
));
|
||||
}
|
||||
},
|
||||
|
||||
module = &**raw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4650,7 +4653,7 @@ impl Device {
|
||||
label: desc.label.to_hal(self.instance_flags),
|
||||
layout: pipeline_layout.raw()?,
|
||||
stage: hal::ProgrammableStage {
|
||||
module: shader_module_state.raw.as_ref(),
|
||||
module,
|
||||
entry_point: final_entry_point_name.as_ref(),
|
||||
constants: &desc.stage.constants,
|
||||
zero_initialize_workgroup_memory: desc.stage.zero_initialize_workgroup_memory,
|
||||
@@ -5203,8 +5206,9 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
|
||||
match vertex_shader_module_state.interface {
|
||||
ShaderMetaData::NagaModule { ref interface } => {
|
||||
let module;
|
||||
match vertex_shader_module_state {
|
||||
pipeline::ShaderModuleState::NagaModule { ref interface, raw } => {
|
||||
io = interface
|
||||
.check_stage(
|
||||
&mut binding_layout_source,
|
||||
@@ -5216,14 +5220,16 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
validated_stages |= stage_bit;
|
||||
module = &**raw;
|
||||
}
|
||||
ShaderMetaData::Passthrough { .. } => {
|
||||
pipeline::ShaderModuleState::Passthrough { raw, .. } => {
|
||||
passthrough_stages |= stage_bit;
|
||||
module = &**raw;
|
||||
}
|
||||
}
|
||||
|
||||
Some(hal::ProgrammableStage {
|
||||
module: vertex_shader_module_state.raw.as_ref(),
|
||||
module,
|
||||
entry_point: &_vertex_entry_point_name,
|
||||
constants: &stage_desc.constants,
|
||||
zero_initialize_workgroup_memory: stage_desc
|
||||
@@ -5257,8 +5263,9 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
|
||||
match task_shader_module_state.interface {
|
||||
ShaderMetaData::NagaModule { ref interface } => {
|
||||
let module;
|
||||
match task_shader_module_state {
|
||||
pipeline::ShaderModuleState::NagaModule { ref interface, raw } => {
|
||||
io = interface
|
||||
.check_stage(
|
||||
&mut binding_layout_source,
|
||||
@@ -5270,14 +5277,16 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
validated_stages |= stage_bit;
|
||||
module = &**raw;
|
||||
}
|
||||
ShaderMetaData::Passthrough { .. } => {
|
||||
pipeline::ShaderModuleState::Passthrough { raw, .. } => {
|
||||
passthrough_stages |= stage_bit;
|
||||
module = &**raw;
|
||||
}
|
||||
}
|
||||
|
||||
Some(hal::ProgrammableStage {
|
||||
module: task_shader_module_state.raw.as_ref(),
|
||||
module,
|
||||
entry_point: &_task_entry_point_name,
|
||||
constants: &stage_desc.constants,
|
||||
zero_initialize_workgroup_memory: stage_desc
|
||||
@@ -5309,8 +5318,9 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
|
||||
match mesh_shader_module_state.interface {
|
||||
ShaderMetaData::NagaModule { ref interface } => {
|
||||
let module;
|
||||
match mesh_shader_module_state {
|
||||
pipeline::ShaderModuleState::NagaModule { ref interface, raw } => {
|
||||
io = interface
|
||||
.check_stage(
|
||||
&mut binding_layout_source,
|
||||
@@ -5322,14 +5332,16 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
validated_stages |= stage_bit;
|
||||
module = &**raw;
|
||||
}
|
||||
ShaderMetaData::Passthrough { .. } => {
|
||||
pipeline::ShaderModuleState::Passthrough { raw, .. } => {
|
||||
passthrough_stages |= stage_bit;
|
||||
module = &**raw;
|
||||
}
|
||||
}
|
||||
|
||||
Some(hal::ProgrammableStage {
|
||||
module: mesh_shader_module_state.raw.as_ref(),
|
||||
module,
|
||||
entry_point: &_mesh_entry_point_name,
|
||||
constants: &stage_desc.constants,
|
||||
zero_initialize_workgroup_memory: stage_desc
|
||||
@@ -5370,8 +5382,9 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
|
||||
match shader_module_state.interface {
|
||||
ShaderMetaData::NagaModule { ref interface } => {
|
||||
let module;
|
||||
match shader_module_state {
|
||||
pipeline::ShaderModuleState::NagaModule { ref interface, raw } => {
|
||||
io = interface
|
||||
.check_stage(
|
||||
&mut binding_layout_source,
|
||||
@@ -5383,14 +5396,16 @@ impl Device {
|
||||
)
|
||||
.map_err(stage_err)?;
|
||||
validated_stages |= stage_bit;
|
||||
module = &**raw;
|
||||
}
|
||||
ShaderMetaData::Passthrough { .. } => {
|
||||
pipeline::ShaderModuleState::Passthrough { raw, .. } => {
|
||||
passthrough_stages |= stage_bit;
|
||||
module = &**raw;
|
||||
}
|
||||
}
|
||||
|
||||
Some(hal::ProgrammableStage {
|
||||
module: shader_module_state.raw.as_ref(),
|
||||
module,
|
||||
entry_point: &fragment_entry_point_name,
|
||||
constants: &fragment_state.stage.constants,
|
||||
zero_initialize_workgroup_memory: fragment_state
|
||||
|
||||
+17
-14
@@ -75,15 +75,15 @@ pub struct PassthroughInterface {
|
||||
// box the standard interface though.
|
||||
#[expect(clippy::large_enum_variant)]
|
||||
#[derive(Debug)]
|
||||
pub enum ShaderMetaData {
|
||||
NagaModule { interface: validation::Interface },
|
||||
Passthrough { interface: PassthroughInterface },
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ShaderModuleState {
|
||||
pub(crate) raw: Box<dyn hal::DynShaderModule>,
|
||||
pub(crate) interface: ShaderMetaData,
|
||||
pub enum ShaderModuleState {
|
||||
NagaModule {
|
||||
raw: Box<dyn hal::DynShaderModule>,
|
||||
interface: validation::Interface,
|
||||
},
|
||||
Passthrough {
|
||||
raw: Box<dyn hal::DynShaderModule>,
|
||||
interface: PassthroughInterface,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -112,8 +112,11 @@ impl Drop for ShaderModule {
|
||||
else {
|
||||
return;
|
||||
};
|
||||
unsafe {
|
||||
self.device.raw().destroy_shader_module(state.raw);
|
||||
match state {
|
||||
ShaderModuleState::NagaModule { raw, .. }
|
||||
| ShaderModuleState::Passthrough { raw, .. } => unsafe {
|
||||
self.device.raw().destroy_shader_module(raw);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,11 +173,11 @@ impl ShaderModule {
|
||||
entry_point: Option<&str>,
|
||||
) -> Result<String, validation::StageError> {
|
||||
let state = self.state()?;
|
||||
match state.interface {
|
||||
ShaderMetaData::NagaModule { ref interface } => {
|
||||
match state {
|
||||
ShaderModuleState::NagaModule { ref interface, .. } => {
|
||||
interface.finalize_entry_point_name(stage, entry_point)
|
||||
}
|
||||
ShaderMetaData::Passthrough { ref interface } => {
|
||||
ShaderModuleState::Passthrough { ref interface, .. } => {
|
||||
finalize_passthrough_entry_point_name(interface, entry_point)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user