mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[naga] Reduce indentation in ImageLoad expression validation.
In `naga::valid::expression::validate_expression`, use a let-else statement so that the outermost control flow follows the success path, and errors are close to the conditions that trigger them.
This commit is contained in:
parent
5304c3ca4a
commit
de1b9a0899
@ -631,64 +631,56 @@ impl super::Validator {
|
||||
level,
|
||||
} => {
|
||||
let ty = Self::global_var_ty(module, function, image)?;
|
||||
match module.types[ty].inner {
|
||||
Ti::Image {
|
||||
class,
|
||||
arrayed,
|
||||
dim,
|
||||
} => {
|
||||
match resolver[coordinate].image_storage_coordinates() {
|
||||
Some(coord_dim) if coord_dim == dim => {}
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidImageCoordinateType(
|
||||
dim, coordinate,
|
||||
))
|
||||
}
|
||||
};
|
||||
if arrayed != array_index.is_some() {
|
||||
return Err(ExpressionError::InvalidImageArrayIndex);
|
||||
}
|
||||
if let Some(expr) = array_index {
|
||||
match resolver[expr] {
|
||||
Ti::Scalar(Sc {
|
||||
kind: Sk::Sint | Sk::Uint,
|
||||
width: _,
|
||||
}) => {}
|
||||
_ => return Err(ExpressionError::InvalidImageArrayIndexType(expr)),
|
||||
}
|
||||
}
|
||||
let Ti::Image {
|
||||
class,
|
||||
arrayed,
|
||||
dim,
|
||||
} = module.types[ty].inner
|
||||
else {
|
||||
return Err(ExpressionError::ExpectedImageType(ty));
|
||||
};
|
||||
|
||||
match (sample, class.is_multisampled()) {
|
||||
(None, false) => {}
|
||||
(Some(sample), true) => {
|
||||
if resolver[sample].scalar_kind() != Some(Sk::Sint) {
|
||||
return Err(ExpressionError::InvalidImageOtherIndexType(
|
||||
sample,
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidImageOtherIndex);
|
||||
}
|
||||
}
|
||||
match resolver[coordinate].image_storage_coordinates() {
|
||||
Some(coord_dim) if coord_dim == dim => {}
|
||||
_ => return Err(ExpressionError::InvalidImageCoordinateType(dim, coordinate)),
|
||||
};
|
||||
if arrayed != array_index.is_some() {
|
||||
return Err(ExpressionError::InvalidImageArrayIndex);
|
||||
}
|
||||
if let Some(expr) = array_index {
|
||||
match resolver[expr] {
|
||||
Ti::Scalar(Sc {
|
||||
kind: Sk::Sint | Sk::Uint,
|
||||
width: _,
|
||||
}) => {}
|
||||
_ => return Err(ExpressionError::InvalidImageArrayIndexType(expr)),
|
||||
}
|
||||
}
|
||||
|
||||
match (level, class.is_mipmapped()) {
|
||||
(None, false) => {}
|
||||
(Some(level), true) => match resolver[level] {
|
||||
Ti::Scalar(Sc {
|
||||
kind: Sk::Sint | Sk::Uint,
|
||||
width: _,
|
||||
}) => {}
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidImageArrayIndexType(level))
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidImageOtherIndex);
|
||||
}
|
||||
match (sample, class.is_multisampled()) {
|
||||
(None, false) => {}
|
||||
(Some(sample), true) => {
|
||||
if resolver[sample].scalar_kind() != Some(Sk::Sint) {
|
||||
return Err(ExpressionError::InvalidImageOtherIndexType(sample));
|
||||
}
|
||||
}
|
||||
_ => return Err(ExpressionError::ExpectedImageType(ty)),
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidImageOtherIndex);
|
||||
}
|
||||
}
|
||||
|
||||
match (level, class.is_mipmapped()) {
|
||||
(None, false) => {}
|
||||
(Some(level), true) => match resolver[level] {
|
||||
Ti::Scalar(Sc {
|
||||
kind: Sk::Sint | Sk::Uint,
|
||||
width: _,
|
||||
}) => {}
|
||||
_ => return Err(ExpressionError::InvalidImageArrayIndexType(level)),
|
||||
},
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidImageOtherIndex);
|
||||
}
|
||||
}
|
||||
ShaderStages::all()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user