Skip to content

Commit a0344cc

Browse files
committed
[naga valid]: Clean up validation of Statement::ImageStore.
Ensure that the type we obtain for the `image` operand is correct: "see through" a binding array to its element type only when `image` is actually an `Access` or `AccessIndex` expression. (This changes the set of programs the validator will pass, but it turns out not to affect the set of WGSL programs that Naga will accept, since the WGSL front end is already checking the types of the `texture` arguments to `textureStore` function calls, in order to decide which overload applies.) Rename the variables to better reflect their values.
1 parent 87d9ffe commit a0344cc

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

naga/src/valid/function.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,12 @@ impl super::Validator {
10121012
} => {
10131013
//Note: this code uses a lot of `FunctionError::InvalidImageStore`,
10141014
// and could probably be refactored.
1015-
let var = match *context.get_expression(image) {
1015+
let global_var;
1016+
let image_ty;
1017+
match *context.get_expression(image) {
10161018
crate::Expression::GlobalVariable(var_handle) => {
1017-
&context.global_vars[var_handle]
1019+
global_var = &context.global_vars[var_handle];
1020+
image_ty = global_var.ty;
10181021
}
10191022
// The `image` operand is indexing into a binding array,
10201023
// so punch through the `Access`* expression and look at
@@ -1029,7 +1032,18 @@ impl super::Validator {
10291032
)
10301033
.with_span_handle(image, context.expressions));
10311034
};
1032-
&context.global_vars[var_handle]
1035+
global_var = &context.global_vars[var_handle];
1036+
1037+
// The global variable must be a binding array.
1038+
let Ti::BindingArray { base, .. } = context.types[global_var.ty].inner
1039+
else {
1040+
return Err(FunctionError::InvalidImageStore(
1041+
ExpressionError::ExpectedBindingArrayType(global_var.ty),
1042+
)
1043+
.with_span_handle(global_var.ty, context.types));
1044+
};
1045+
1046+
image_ty = base;
10331047
}
10341048
_ => {
10351049
return Err(FunctionError::InvalidImageStore(
@@ -1039,24 +1053,18 @@ impl super::Validator {
10391053
}
10401054
};
10411055

1042-
// Punch through a binding array to get the underlying type.
1043-
let global_ty = match context.types[var.ty].inner {
1044-
Ti::BindingArray { base, .. } => &context.types[base].inner,
1045-
ref inner => inner,
1046-
};
1047-
10481056
// The `image` operand must be an `Image`.
10491057
let Ti::Image {
10501058
class,
10511059
arrayed,
10521060
dim,
1053-
} = *global_ty
1061+
} = context.types[image_ty].inner
10541062
else {
10551063
return Err(FunctionError::InvalidImageStore(
1056-
ExpressionError::ExpectedImageType(var.ty),
1064+
ExpressionError::ExpectedImageType(global_var.ty),
10571065
)
10581066
.with_span()
1059-
.with_handle(var.ty, context.types)
1067+
.with_handle(global_var.ty, context.types)
10601068
.with_handle(image, context.expressions));
10611069
};
10621070

0 commit comments

Comments
 (0)