Skip to content

Commit

Permalink
diag(naga): clarify ImageStore type mismatch cases (#6791)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler authored Jan 29, 2025
1 parent d977735 commit e0ebd1b
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 @@ -137,8 +137,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 @@ -1007,8 +1016,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 @@ -1165,9 +1181,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 e0ebd1b

Please sign in to comment.