Skip to content

Commit 24a9f7d

Browse files
committed
Define TypeInner::is_constructible; use it in front::wgsl.
1 parent 6357bd7 commit 24a9f7d

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

naga/src/front/wgsl/lower/construction.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,9 @@ impl<'source> Lowerer<'source, '_> {
152152

153153
let expr;
154154
match (components, constructor) {
155-
// Zero-value constructor with explicit type. Not everything this
156-
// matches is constructible, but the non-constructible types not
157-
// excluded by `!is_dynamically_sized` are rejected by the
158-
// parser.
155+
// Zero-value constructor with explicit type.
159156
(Components::None, Constructor::Type((result_ty, inner)))
160-
if !inner.is_dynamically_sized(&ctx.module.types) =>
157+
if inner.is_constructible(&ctx.module.types) =>
161158
{
162159
expr = crate::Expression::ZeroValue(result_ty);
163160
}
@@ -535,11 +532,11 @@ impl<'source> Lowerer<'source, '_> {
535532
expr = crate::Expression::Compose { ty, components };
536533
}
537534

538-
// Array constructor, explicit type. Override- and runtime-sized arrays are not constructible.
535+
// Array constructor, explicit type.
539536
(
540537
components,
541538
Constructor::Type((ty, inner @ &crate::TypeInner::Array { base, .. })),
542-
) if !inner.is_dynamically_sized(&ctx.module.types) => {
539+
) if inner.is_constructible(&ctx.module.types) => {
543540
let mut components = components.into_components_vec();
544541
ctx.try_automatic_conversions_slice(&mut components, &Tr::Handle(base), ty_span)?;
545542
expr = crate::Expression::Compose { ty, components };
@@ -549,7 +546,7 @@ impl<'source> Lowerer<'source, '_> {
549546
(
550547
components,
551548
Constructor::Type((ty, inner @ &crate::TypeInner::Struct { ref members, .. })),
552-
) if !inner.is_dynamically_sized(&ctx.module.types) => {
549+
) if inner.is_constructible(&ctx.module.types) => {
553550
let mut components = components.into_components_vec();
554551
let struct_ty_span = ctx.module.types.get_span(ty);
555552

naga/src/proc/type_methods.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,34 @@ impl crate::TypeInner {
364364
}
365365
}
366366

367+
/// Returns true if `self` is a constructible type.
368+
pub fn is_constructible(&self, types: &crate::UniqueArena<crate::Type>) -> bool {
369+
use crate::TypeInner as Ti;
370+
match *self {
371+
Ti::Array { size, .. } => match size {
372+
ir::ArraySize::Constant(_) => true,
373+
ir::ArraySize::Pending(_) |
374+
ir::ArraySize::Dynamic => false,
375+
}
376+
Ti::Struct { ref members, .. } => members
377+
.last()
378+
.map(|last| !types[last.ty].inner.is_dynamically_sized(types))
379+
.unwrap_or(true),
380+
Ti::Atomic(_) |
381+
Ti::Pointer { .. } |
382+
Ti::ValuePointer { .. } |
383+
Ti::Image { .. } |
384+
Ti::Sampler { .. } |
385+
Ti::AccelerationStructure { .. } |
386+
Ti::BindingArray { .. } => false,
387+
Ti::Scalar(_) |
388+
Ti::Vector { .. } |
389+
Ti::Matrix { .. } |
390+
Ti::RayQuery { .. } |
391+
Ti::CooperativeMatrix { .. } => true,
392+
}
393+
}
394+
367395
pub const fn components(&self) -> Option<u32> {
368396
Some(match *self {
369397
Self::Vector { size, .. } => size as u32,

0 commit comments

Comments
 (0)