[wgsl-in] Restore error in the case of bad scalar widths.

This commit is contained in:
Jim Blandy 2022-06-16 16:09:17 -07:00 committed by Teodor Tanasoaia
parent ad536ce0df
commit 0b60f410ab

View File

@ -128,6 +128,8 @@ pub enum LayoutErrorInner {
InvalidArrayElementType(Handle<crate::Type>),
#[error("Struct member[{0}] type {1:?} doesn't exist")]
InvalidStructMemberType(u32, Handle<crate::Type>),
#[error("Type width must be a power of two")]
NonPowerOfTwoWidth,
#[error("Array size is a bad handle")]
BadHandle(#[from] BadHandle),
}
@ -178,26 +180,35 @@ impl Layouter {
.try_size(constants)
.map_err(|error| LayoutErrorInner::BadHandle(error).with(ty_handle))?;
let layout = match ty.inner {
Ti::Scalar { width, .. } | Ti::Atomic { width, .. } => TypeLayout {
size,
alignment: Alignment::from_width(width),
},
Ti::Scalar { width, .. } | Ti::Atomic { width, .. } => {
let alignment = Alignment::new(width as u32)
.ok_or(LayoutErrorInner::NonPowerOfTwoWidth.with(ty_handle))?;
TypeLayout { size, alignment }
}
Ti::Vector {
size: vec_size,
width,
..
} => TypeLayout {
} => {
let alignment = Alignment::new(width as u32)
.ok_or(LayoutErrorInner::NonPowerOfTwoWidth.with(ty_handle))?;
TypeLayout {
size,
alignment: { Alignment::from(vec_size) * Alignment::from_width(width) },
},
alignment: Alignment::from(vec_size) * alignment,
}
}
Ti::Matrix {
columns: _,
rows,
width,
} => TypeLayout {
} => {
let alignment = Alignment::new(width as u32)
.ok_or(LayoutErrorInner::NonPowerOfTwoWidth.with(ty_handle))?;
TypeLayout {
size,
alignment: { Alignment::from(rows) * Alignment::from_width(width) },
},
alignment: Alignment::from(rows) * alignment,
}
}
Ti::Pointer { .. } | Ti::ValuePointer { .. } => TypeLayout {
size,
alignment: Alignment::ONE,