Skip to content

Commit ff3764f

Browse files
committed
[spv-in] Improve detection of ImageClass
1 parent 3f02781 commit ff3764f

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

naga/src/front/spv/error.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ pub enum Error {
107107
InvalidGlobalVar(crate::Expression),
108108
#[error("invalid image/sampler expression {0:?}")]
109109
InvalidImageExpression(crate::Expression),
110-
#[error("image write without format is not currently supported. See https://github.com/gfx-rs/wgpu/issues/6797")]
111-
InvalidImageWriteType,
110+
#[error("cannot create a OpTypeImage as both a depth and storage image")]
111+
InvalidImageDepthStorage,
112+
#[error("image read/write without format is not currently supported. See https://github.com/gfx-rs/wgpu/issues/6797")]
113+
InvalidStorageImageWithoutFormat,
112114
#[error("invalid image base type {0:?}")]
113115
InvalidImageBaseType(Handle<crate::Type>),
114116
#[error("invalid image {0:?}")]

naga/src/front/spv/mod.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,15 +2597,31 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
25972597

25982598
let inner = crate::TypeInner::Image {
25992599
class: if is_depth == 1 {
2600+
if is_sampled == 2 {
2601+
return Err(Error::InvalidImageDepthStorage);
2602+
}
2603+
26002604
crate::ImageClass::Depth { multi: is_msaa }
2601-
} else if format != 0 {
2605+
}
2606+
// If we have an unknown format and storage texture, this is
2607+
// StorageRead/WriteWithoutFormat. We don't currently support
2608+
// this.
2609+
else if is_sampled == 2 && format == 0 {
2610+
return Err(Error::InvalidStorageImageWithoutFormat);
2611+
}
2612+
// If we have explicit class information (is_sampled = 2 = Storage), use it.
2613+
//
2614+
// If we have unknown class information (is_sampled = 0 = Unknown), infer the
2615+
// class from the presence of an explicit format.
2616+
else if format != 0 && (is_sampled == 0 || is_sampled == 2) {
26022617
crate::ImageClass::Storage {
26032618
format: map_image_format(format)?,
26042619
access: crate::StorageAccess::default(),
26052620
}
2606-
} else if is_sampled == 2 {
2607-
return Err(Error::InvalidImageWriteType);
2608-
} else {
2621+
}
2622+
// We will hit this case either when sampled is 1, or if we have unknown
2623+
// sampling information or when sampled is 0 and we have no explicit format.
2624+
else {
26092625
crate::ImageClass::Sampled {
26102626
kind,
26112627
multi: is_msaa,

naga/src/valid/expression.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ pub enum ExpressionError {
8787
InvalidDerivative,
8888
#[error("Image array index parameter is misplaced")]
8989
InvalidImageArrayIndex,
90-
#[error("Inappropriate sample or level-of-detail index for texel access")]
91-
InvalidImageOtherIndex,
90+
#[error("Cannot textureLoad from a specific multisample sample on a non-multisampled image.")]
91+
InvalidImageSampleSelector,
92+
#[error("Cannot textureLoad from a multisampled image without specifying a sample.")]
93+
MissingImageSampleSelector,
9294
#[error("Image array index type of {0:?} is not an integer scalar")]
9395
InvalidImageArrayIndexType(Handle<crate::Expression>),
9496
#[error("Image sample or level-of-detail index's type of {0:?} is not an integer scalar")]
@@ -715,8 +717,11 @@ impl super::Validator {
715717
return Err(ExpressionError::InvalidImageOtherIndexType(sample));
716718
}
717719
}
718-
_ => {
719-
return Err(ExpressionError::InvalidImageOtherIndex);
720+
(Some(_), false) => {
721+
return Err(ExpressionError::InvalidImageSampleSelector);
722+
}
723+
(None, true) => {
724+
return Err(ExpressionError::MissingImageSampleSelector);
720725
}
721726
}
722727

@@ -729,7 +734,8 @@ impl super::Validator {
729734
}) => {}
730735
_ => return Err(ExpressionError::InvalidImageArrayIndexType(level)),
731736
},
732-
_ => {
737+
e => {
738+
std::dbg!(e, class);
733739
return Err(ExpressionError::InvalidImageOtherIndex);
734740
}
735741
}

0 commit comments

Comments
 (0)