mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[wgsl-in] Restore error in the case of bad scalar widths.
This commit is contained in:
committed by
Teodor Tanasoaia
parent
ad536ce0df
commit
0b60f410ab
@@ -128,6 +128,8 @@ pub enum LayoutErrorInner {
|
|||||||
InvalidArrayElementType(Handle<crate::Type>),
|
InvalidArrayElementType(Handle<crate::Type>),
|
||||||
#[error("Struct member[{0}] type {1:?} doesn't exist")]
|
#[error("Struct member[{0}] type {1:?} doesn't exist")]
|
||||||
InvalidStructMemberType(u32, Handle<crate::Type>),
|
InvalidStructMemberType(u32, Handle<crate::Type>),
|
||||||
|
#[error("Type width must be a power of two")]
|
||||||
|
NonPowerOfTwoWidth,
|
||||||
#[error("Array size is a bad handle")]
|
#[error("Array size is a bad handle")]
|
||||||
BadHandle(#[from] BadHandle),
|
BadHandle(#[from] BadHandle),
|
||||||
}
|
}
|
||||||
@@ -178,26 +180,35 @@ impl Layouter {
|
|||||||
.try_size(constants)
|
.try_size(constants)
|
||||||
.map_err(|error| LayoutErrorInner::BadHandle(error).with(ty_handle))?;
|
.map_err(|error| LayoutErrorInner::BadHandle(error).with(ty_handle))?;
|
||||||
let layout = match ty.inner {
|
let layout = match ty.inner {
|
||||||
Ti::Scalar { width, .. } | Ti::Atomic { width, .. } => TypeLayout {
|
Ti::Scalar { width, .. } | Ti::Atomic { width, .. } => {
|
||||||
size,
|
let alignment = Alignment::new(width as u32)
|
||||||
alignment: Alignment::from_width(width),
|
.ok_or(LayoutErrorInner::NonPowerOfTwoWidth.with(ty_handle))?;
|
||||||
},
|
TypeLayout { size, alignment }
|
||||||
|
}
|
||||||
Ti::Vector {
|
Ti::Vector {
|
||||||
size: vec_size,
|
size: vec_size,
|
||||||
width,
|
width,
|
||||||
..
|
..
|
||||||
} => TypeLayout {
|
} => {
|
||||||
|
let alignment = Alignment::new(width as u32)
|
||||||
|
.ok_or(LayoutErrorInner::NonPowerOfTwoWidth.with(ty_handle))?;
|
||||||
|
TypeLayout {
|
||||||
size,
|
size,
|
||||||
alignment: { Alignment::from(vec_size) * Alignment::from_width(width) },
|
alignment: Alignment::from(vec_size) * alignment,
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Ti::Matrix {
|
Ti::Matrix {
|
||||||
columns: _,
|
columns: _,
|
||||||
rows,
|
rows,
|
||||||
width,
|
width,
|
||||||
} => TypeLayout {
|
} => {
|
||||||
|
let alignment = Alignment::new(width as u32)
|
||||||
|
.ok_or(LayoutErrorInner::NonPowerOfTwoWidth.with(ty_handle))?;
|
||||||
|
TypeLayout {
|
||||||
size,
|
size,
|
||||||
alignment: { Alignment::from(rows) * Alignment::from_width(width) },
|
alignment: Alignment::from(rows) * alignment,
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Ti::Pointer { .. } | Ti::ValuePointer { .. } => TypeLayout {
|
Ti::Pointer { .. } | Ti::ValuePointer { .. } => TypeLayout {
|
||||||
size,
|
size,
|
||||||
alignment: Alignment::ONE,
|
alignment: Alignment::ONE,
|
||||||
|
|||||||
Reference in New Issue
Block a user