Skip to content

Commit

Permalink
add override enum for ArraySize::Pending
Browse files Browse the repository at this point in the history
  • Loading branch information
kentslaney committed Dec 9, 2024
1 parent 922f735 commit 1958c2b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion naga/src/back/pipeline_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn process_pending(
for (handle, ty) in module.types.clone().iter() {
if let crate::TypeInner::Array {
base,
size: crate::ArraySize::Pending(size_expr),
size: crate::ArraySize::Pending(crate::PendingArraySize::Expression(size_expr)),
stride,
} = ty.inner
{
Expand Down
8 changes: 5 additions & 3 deletions naga/src/compact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn compact(module: &mut crate::Module) {

for (_, ty) in module.types.iter() {
if let crate::TypeInner::Array {
size: crate::ArraySize::Pending(size_expr),
size: crate::ArraySize::Pending(crate::PendingArraySize::Expression(size_expr)),
..
} = ty.inner
{
Expand Down Expand Up @@ -219,7 +219,7 @@ pub fn compact(module: &mut crate::Module) {
for (handle, ty) in module.types.clone().iter() {
if let crate::TypeInner::Array {
base,
size: crate::ArraySize::Pending(mut size_expr),
size: crate::ArraySize::Pending(crate::PendingArraySize::Expression(mut size_expr)),
stride,
} = ty.inner
{
Expand All @@ -230,7 +230,9 @@ pub fn compact(module: &mut crate::Module) {
name: None,
inner: crate::TypeInner::Array {
base,
size: crate::ArraySize::Pending(size_expr),
size: crate::ArraySize::Pending(crate::PendingArraySize::Expression(
size_expr,
)),
stride,
},
},
Expand Down
10 changes: 8 additions & 2 deletions naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3087,10 +3087,16 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
size_expr: Handle<ast::Expression<'source>>,
ctx: &mut ExpressionContext<'source, '_, '_>,
span: Span,
) -> Result<Handle<crate::Expression>, Error<'source>> {
) -> Result<crate::PendingArraySize, Error<'source>> {
let expr = self.expression(size_expr, ctx)?;
match resolve_inner!(ctx, expr).scalar_kind().ok_or(0) {
Ok(crate::ScalarKind::Sint) | Ok(crate::ScalarKind::Uint) => Ok(expr),
Ok(crate::ScalarKind::Sint) | Ok(crate::ScalarKind::Uint) => Ok({
if let crate::Expression::Override(handle) = ctx.module.global_expressions[expr] {
crate::PendingArraySize::Override(handle)
} else {
crate::PendingArraySize::Expression(expr)
}
}),
_ => Err(Error::ExpectedConstExprConcreteIntegerScalar(span)),
}
}
Expand Down
11 changes: 10 additions & 1 deletion naga/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,15 @@ pub struct Scalar {
pub width: Bytes,
}

#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub enum PendingArraySize {
Expression(Handle<Expression>),
Override(Handle<Override>),
}

/// Size of an array.
#[repr(u8)]
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
Expand All @@ -497,7 +506,7 @@ pub enum ArraySize {
/// The array size is constant.
Constant(std::num::NonZeroU32),
/// The array size is an override-expression.
Pending(Handle<Expression>),
Pending(PendingArraySize),
/// The array size can change at runtime.
Dynamic,
}
Expand Down

0 comments on commit 1958c2b

Please sign in to comment.