diag(naga): clarify ImageStore type mismatch cases (#6791)

This commit is contained in:
Erich Gubler
2025-01-29 11:13:36 -05:00
committed by GitHub
parent d9777355c9
commit e0ebd1b266

View File

@@ -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>,
@@ -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"));
}
_ => {}
}
@@ -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 {