Update naga with the new usage validation

This commit is contained in:
Dzmitry Malyshau 2020-09-28 10:18:35 -04:00
parent 49cf466dc4
commit c18ac58fd8
3 changed files with 35 additions and 52 deletions

2
Cargo.lock generated
View File

@ -836,7 +836,7 @@ dependencies = [
[[package]] [[package]]
name = "naga" name = "naga"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/gfx-rs/naga?rev=b278e10ea7c144b2387585c4e81c1d86db8e2def#b278e10ea7c144b2387585c4e81c1d86db8e2def" source = "git+https://github.com/gfx-rs/naga?rev=8323521b838cf7a7cb4163c84f0f4ff237622f9a#8323521b838cf7a7cb4163c84f0f4ff237622f9a"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"fxhash", "fxhash",

View File

@ -40,8 +40,8 @@ gfx-memory = "0.2"
[dependencies.naga] [dependencies.naga]
version = "0.2" version = "0.2"
git = "https://github.com/gfx-rs/naga" git = "https://github.com/gfx-rs/naga"
rev = "b278e10ea7c144b2387585c4e81c1d86db8e2def" rev = "8323521b838cf7a7cb4163c84f0f4ff237622f9a"
features = ["spirv-in", "spirv-out", "wgsl-in"] features = ["spv-in", "spv-out", "wgsl-in"]
[dependencies.wgt] [dependencies.wgt]
path = "../wgpu-types" path = "../wgpu-types"

View File

@ -65,11 +65,6 @@ pub enum BindingError {
dim: naga::ImageDimension, dim: naga::ImageDimension,
is_array: bool, is_array: bool,
}, },
#[error("component type {binding:?} of a sampled texture doesn't match the shader {shader:?}")]
WrongTextureComponentType {
binding: naga::ScalarKind,
shader: naga::ScalarKind,
},
#[error("texture class {binding:?} doesn't match the shader {shader:?}")] #[error("texture class {binding:?} doesn't match the shader {shader:?}")]
WrongTextureClass { WrongTextureClass {
binding: naga::ImageClass, binding: naga::ImageClass,
@ -98,9 +93,9 @@ pub enum StageError {
InvalidModule, InvalidModule,
#[error("unable to find an entry point at {0:?} stage")] #[error("unable to find an entry point at {0:?} stage")]
MissingEntryPoint(wgt::ShaderStage), MissingEntryPoint(wgt::ShaderStage),
#[error("error matching global binding at index {binding} in set {set} against the pipeline layout: {error}")] #[error("error matching global binding at index {binding} in group {group} against the pipeline layout: {error}")]
Binding { Binding {
set: u32, group: u32,
binding: u32, binding: u32,
error: BindingError, error: BindingError,
}, },
@ -283,7 +278,6 @@ fn check_binding_use(
_ => Err(BindingError::WrongType), _ => Err(BindingError::WrongType),
}, },
naga::TypeInner::Image { naga::TypeInner::Image {
kind,
dim, dim,
arrayed, arrayed,
class, class,
@ -329,7 +323,7 @@ fn check_binding_use(
component_type, component_type,
multisampled, multisampled,
} => { } => {
let (expected_scalar_kind, comparison) = match component_type { let (kind, comparison) = match component_type {
wgt::TextureComponentType::Float => (naga::ScalarKind::Float, false), wgt::TextureComponentType::Float => (naga::ScalarKind::Float, false),
wgt::TextureComponentType::Sint => (naga::ScalarKind::Sint, false), wgt::TextureComponentType::Sint => (naga::ScalarKind::Sint, false),
wgt::TextureComponentType::Uint => (naga::ScalarKind::Uint, false), wgt::TextureComponentType::Uint => (naga::ScalarKind::Uint, false),
@ -337,18 +331,13 @@ fn check_binding_use(
(naga::ScalarKind::Float, true) (naga::ScalarKind::Float, true)
} }
}; };
if kind != expected_scalar_kind { let class = if comparison {
return Err(BindingError::WrongTextureComponentType {
binding: expected_scalar_kind,
shader: kind,
});
}
let class = if multisampled {
naga::ImageClass::Multisampled
} else if comparison {
naga::ImageClass::Depth naga::ImageClass::Depth
} else { } else {
naga::ImageClass::Sampled naga::ImageClass::Sampled {
kind,
multi: multisampled,
}
}; };
(class, naga::GlobalUse::LOAD) (class, naga::GlobalUse::LOAD)
} }
@ -810,7 +799,6 @@ fn derive_binding_type(
} }
naga::TypeInner::Sampler { comparison } => BindingType::Sampler { comparison }, naga::TypeInner::Sampler { comparison } => BindingType::Sampler { comparison },
naga::TypeInner::Image { naga::TypeInner::Image {
kind,
dim, dim,
arrayed, arrayed,
class, class,
@ -823,22 +811,16 @@ fn derive_binding_type(
naga::ImageDimension::Cube if arrayed => wgt::TextureViewDimension::CubeArray, naga::ImageDimension::Cube if arrayed => wgt::TextureViewDimension::CubeArray,
naga::ImageDimension::Cube => wgt::TextureViewDimension::Cube, naga::ImageDimension::Cube => wgt::TextureViewDimension::Cube,
}; };
let component_type = match kind { match class {
naga::ImageClass::Sampled { multi, kind } => BindingType::SampledTexture {
dimension,
component_type: match kind {
naga::ScalarKind::Float => wgt::TextureComponentType::Float, naga::ScalarKind::Float => wgt::TextureComponentType::Float,
naga::ScalarKind::Sint => wgt::TextureComponentType::Sint, naga::ScalarKind::Sint => wgt::TextureComponentType::Sint,
naga::ScalarKind::Uint => wgt::TextureComponentType::Uint, naga::ScalarKind::Uint => wgt::TextureComponentType::Uint,
naga::ScalarKind::Bool => unreachable!(), naga::ScalarKind::Bool => unreachable!(),
};
match class {
naga::ImageClass::Sampled => BindingType::SampledTexture {
dimension,
component_type,
multisampled: false,
}, },
naga::ImageClass::Multisampled => BindingType::SampledTexture { multisampled: multi,
dimension,
component_type,
multisampled: true,
}, },
naga::ImageClass::Depth => BindingType::SampledTexture { naga::ImageClass::Depth => BindingType::SampledTexture {
dimension, dimension,
@ -871,30 +853,31 @@ pub fn check_stage<'a>(
) -> Result<StageInterface<'a>, StageError> { ) -> Result<StageInterface<'a>, StageError> {
// Since a shader module can have multiple entry points with the same name, // Since a shader module can have multiple entry points with the same name,
// we need to look for one with the right execution model. // we need to look for one with the right execution model.
let shader_stage = match stage_bit {
wgt::ShaderStage::VERTEX => naga::ShaderStage::Vertex,
wgt::ShaderStage::FRAGMENT => naga::ShaderStage::Fragment,
wgt::ShaderStage::COMPUTE => naga::ShaderStage::Compute,
_ => unreachable!(),
};
let entry_point = module let entry_point = module
.entry_points .entry_points
.iter() .get(&(shader_stage, entry_point_name.to_string()))
.find(|entry_point| {
entry_point.name == entry_point_name
&& stage_bit.contains(match entry_point.stage {
naga::ShaderStage::Vertex { .. } => wgt::ShaderStage::VERTEX,
naga::ShaderStage::Fragment { .. } => wgt::ShaderStage::FRAGMENT,
naga::ShaderStage::Compute { .. } => wgt::ShaderStage::COMPUTE,
})
})
.ok_or(StageError::MissingEntryPoint(stage_bit))?; .ok_or(StageError::MissingEntryPoint(stage_bit))?;
let function = &module.functions[entry_point.function];
let mut outputs = StageInterface::default(); let mut outputs = StageInterface::default();
for ((_, var), &usage) in module.global_variables.iter().zip(&function.global_usage) { for ((_, var), &usage) in module
.global_variables
.iter()
.zip(&entry_point.function.global_usage)
{
if usage.is_empty() { if usage.is_empty() {
continue; continue;
} }
match var.binding { match var.binding {
Some(naga::Binding::Descriptor { set, binding }) => { Some(naga::Binding::Resource { group, binding }) => {
let result = match group_layouts { let result = match group_layouts {
IntrospectionBindGroupLayouts::Given(ref layouts) => layouts IntrospectionBindGroupLayouts::Given(ref layouts) => layouts
.get(set as usize) .get(group as usize)
.and_then(|map| map.get(&binding)) .and_then(|map| map.get(&binding))
.ok_or(BindingError::Missing) .ok_or(BindingError::Missing)
.and_then(|entry| { .and_then(|entry| {
@ -913,7 +896,7 @@ pub fn check_stage<'a>(
} }
}), }),
IntrospectionBindGroupLayouts::Derived(ref mut layouts) => layouts IntrospectionBindGroupLayouts::Derived(ref mut layouts) => layouts
.get_mut(set as usize) .get_mut(group as usize)
.ok_or(BindingError::Missing) .ok_or(BindingError::Missing)
.and_then(|set| { .and_then(|set| {
let ty = derive_binding_type(module, var, usage)?; let ty = derive_binding_type(module, var, usage)?;
@ -937,7 +920,7 @@ pub fn check_stage<'a>(
}; };
if let Err(error) = result { if let Err(error) = result {
return Err(StageError::Binding { return Err(StageError::Binding {
set, group,
binding, binding,
error, error,
}); });