Skip to content

Commit

Permalink
diag(naga): clarify ImageStore type mismatch cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Jan 11, 2025
1 parent 4efc992 commit 63165e9
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions naga/src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,17 @@ pub enum FunctionError {
LastCaseFallTrough,
#[error("The pointer {0:?} doesn't relate to a valid destination for a store")]
InvalidStorePointer(Handle<crate::Expression>),
#[error("The value {0:?} can not be stored")]
InvalidStoreValue(Handle<crate::Expression>),
#[error("Image store texture parameter type mismatch")]
InvalidStoreTexture {
actual: Handle<crate::Expression>,
actual_ty: crate::TypeInner,
},
#[error("Image store value parameter type mismatch")]
InvalidStoreValue {
actual: Handle<crate::Expression>,
actual_ty: crate::TypeInner,
expected_ty: crate::TypeInner,
},
#[error("The type of {value:?} doesn't match the type stored in {pointer:?}")]
InvalidStoreTypes {
pointer: Handle<crate::Expression>,
Expand Down Expand Up @@ -1003,8 +1012,15 @@ impl super::Validator {
let value_ty = context.resolve_type(value, &self.valid_expression_set)?;
match *value_ty {
Ti::Image { .. } | Ti::Sampler { .. } => {
return Err(FunctionError::InvalidStoreValue(value)
.with_span_handle(value, context.expressions));
return Err(FunctionError::InvalidStoreTexture {
actual: value,
actual_ty: value_ty.clone(),
}
.with_span_context((
context.expressions.get_span(value),
format!("this value is of type {value_ty:?}"),
))
.with_span(span, "expects a texture argument"));
}
_ => {}
}
Expand Down Expand Up @@ -1161,9 +1177,22 @@ impl super::Validator {

// The value we're writing had better match the scalar type
// for `image`'s format.
if *context.resolve_type(value, &self.valid_expression_set)? != value_ty {
return Err(FunctionError::InvalidStoreValue(value)
.with_span_handle(value, context.expressions));
let actual_value_ty =
context.resolve_type(value, &self.valid_expression_set)?;
if actual_value_ty != &value_ty {
return Err(FunctionError::InvalidStoreValue {
actual: value,
actual_ty: actual_value_ty.clone(),
expected_ty: value_ty.clone(),
}
.with_span_context((
context.expressions.get_span(value),
format!("this value is of type {actual_value_ty:?}"),
))
.with_span(
span,
format!("expects a value argument of type {value_ty:?}"),
));
}
}
S::Call {
Expand Down

0 comments on commit 63165e9

Please sign in to comment.