Skip to content

Commit

Permalink
add override field to 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 bf89b36
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion naga/src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ impl<'a, W: Write> Writer<'a, W> {
crate::ArraySize::Constant(size) => {
write!(self.out, "{size}")?;
}
crate::ArraySize::Pending(_) => unreachable!(),
crate::ArraySize::Pending(..) => unreachable!(),
crate::ArraySize::Dynamic => (),
}

Expand Down
2 changes: 1 addition & 1 deletion naga/src/back/hlsl/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl crate::TypeInner {
let count = match size {
crate::ArraySize::Constant(size) => size.get(),
// A dynamically-sized array has to have at least one element
crate::ArraySize::Pending(_) => unreachable!(),
crate::ArraySize::Pending(..) => unreachable!(),
crate::ArraySize::Dynamic => 1,
};
let last_el_size = gctx.types[base].inner.size_hlsl(gctx);
Expand Down
2 changes: 1 addition & 1 deletion naga/src/back/hlsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
crate::ArraySize::Constant(size) => {
write!(self.out, "{size}")?;
}
crate::ArraySize::Pending(_) => unreachable!(),
crate::ArraySize::Pending(..) => unreachable!(),
crate::ArraySize::Dynamic => unreachable!(),
}

Expand Down
2 changes: 1 addition & 1 deletion naga/src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3742,7 +3742,7 @@ impl<W: Write> Writer<W> {
)?;
writeln!(self.out, "}};")?;
}
crate::ArraySize::Pending(_) => {
crate::ArraySize::Pending(..) => {
unreachable!()
}
crate::ArraySize::Dynamic => {
Expand Down
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(size_expr, _),
stride,
} = ty.inner
{
Expand Down
4 changes: 2 additions & 2 deletions naga/src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ impl Writer {
let length_id = self.get_index_constant(length.get());
Instruction::type_array(id, type_id, length_id)
}
crate::ArraySize::Pending(_) => unreachable!(),
crate::ArraySize::Pending(..) => unreachable!(),
crate::ArraySize::Dynamic => Instruction::type_runtime_array(id, type_id),
}
}
Expand All @@ -982,7 +982,7 @@ impl Writer {
let length_id = self.get_index_constant(length.get());
Instruction::type_array(id, type_id, length_id)
}
crate::ArraySize::Pending(_) => unreachable!(),
crate::ArraySize::Pending(..) => unreachable!(),
crate::ArraySize::Dynamic => Instruction::type_runtime_array(id, type_id),
}
}
Expand Down
4 changes: 2 additions & 2 deletions naga/src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ impl<W: Write> Writer<W> {
self.write_type(module, base)?;
write!(self.out, ", {len}")?;
}
crate::ArraySize::Pending(_) => {
crate::ArraySize::Pending(..) => {
unreachable!();
}
crate::ArraySize::Dynamic => {
Expand All @@ -537,7 +537,7 @@ impl<W: Write> Writer<W> {
self.write_type(module, base)?;
write!(self.out, ", {len}")?;
}
crate::ArraySize::Pending(_) => {
crate::ArraySize::Pending(..) => {
unreachable!();
}
crate::ArraySize::Dynamic => {
Expand Down
6 changes: 3 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(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(mut size_expr, ident),
stride,
} = ty.inner
{
Expand All @@ -230,7 +230,7 @@ pub fn compact(module: &mut crate::Module) {
name: None,
inner: crate::TypeInner::Array {
base,
size: crate::ArraySize::Pending(size_expr),
size: crate::ArraySize::Pending(size_expr, ident),
stride,
},
},
Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/glsl/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn calculate_offset(

let span = match size {
crate::ArraySize::Constant(size) => size.get() * stride,
crate::ArraySize::Pending(_) => unreachable!(),
crate::ArraySize::Pending(..) => unreachable!(),
crate::ArraySize::Dynamic => stride,
};

Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
crate::TypeInner::Array { size, .. } => {
let size = match size {
crate::ArraySize::Constant(size) => size.get(),
crate::ArraySize::Pending(_) => {
crate::ArraySize::Pending(..) => {
unreachable!();
}
// A runtime sized array is not a composite type
Expand Down
15 changes: 11 additions & 4 deletions naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3060,11 +3060,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
if let Err(Error::ConstantEvaluatorError(ref ty, _)) = err {
match **ty {
crate::proc::ConstantEvaluatorError::OverrideExpr => {
crate::ArraySize::Pending(self.array_size_override(
let (size_expr, ident) = self.array_size_override(
expr,
&mut ctx.as_override(),
span,
)?)
)?;
crate::ArraySize::Pending(size_expr, ident)
}
_ => {
err?;
Expand All @@ -3087,10 +3088,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<(Handle<crate::Expression>, Option<Handle<crate::Override>>), 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((expr, {
if let crate::Expression::Override(handle) = ctx.module.global_expressions[expr] {
Some(handle)
} else {
None
}
})),
_ => Err(Error::ExpectedConstExprConcreteIntegerScalar(span)),
}
}
Expand Down
4 changes: 2 additions & 2 deletions naga/src/front/wgsl/to_wgsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl crate::TypeInner {
let base = base.to_wgsl(gctx);
match size {
crate::ArraySize::Constant(size) => format!("array<{base}, {size}>"),
crate::ArraySize::Pending(_) => unreachable!(),
crate::ArraySize::Pending(..) => unreachable!(),
crate::ArraySize::Dynamic => format!("array<{base}>"),
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ impl crate::TypeInner {
let base = member_type.name.as_deref().unwrap_or("unknown");
match size {
crate::ArraySize::Constant(size) => format!("binding_array<{base}, {size}>"),
crate::ArraySize::Pending(_) => unreachable!(),
crate::ArraySize::Pending(..) => unreachable!(),
crate::ArraySize::Dynamic => format!("binding_array<{base}>"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion naga/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pub enum ArraySize {
/// The array size is constant.
Constant(std::num::NonZeroU32),
/// The array size is an override-expression.
Pending(Handle<Expression>),
Pending(Handle<Expression>, Option<Handle<Override>>),
/// The array size can change at runtime.
Dynamic,
}
Expand Down
2 changes: 1 addition & 1 deletion naga/src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ impl<'a> ConstantEvaluator<'a> {
let expr = Expression::Literal(Literal::U32(len.get()));
self.register_evaluated_expr(expr, span)
}
ArraySize::Pending(_) => Err(ConstantEvaluatorError::ArrayLengthOverridden),
ArraySize::Pending(..) => Err(ConstantEvaluatorError::ArrayLengthOverridden),
ArraySize::Dynamic => Err(ConstantEvaluatorError::ArrayLengthDynamic),
},
_ => Err(ConstantEvaluatorError::InvalidArrayLengthArg),
Expand Down
2 changes: 1 addition & 1 deletion naga/src/proc/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl crate::ArraySize {
) -> Result<IndexableLength, IndexableLengthError> {
Ok(match self {
Self::Constant(length) => IndexableLength::Known(length.get()),
Self::Pending(_) => IndexableLength::Pending,
Self::Pending(..) => IndexableLength::Pending,
Self::Dynamic => IndexableLength::Dynamic,
})
}
Expand Down
2 changes: 1 addition & 1 deletion naga/src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl super::TypeInner {
super::ArraySize::Constant(count) => count.get(),
// any struct member or array element needing a size at pipeline-creation time
// must have a creation-fixed footprint
super::ArraySize::Pending(_) => 0,
super::ArraySize::Pending(..) => 0,
// A dynamically-sized array has to have at least one element
super::ArraySize::Dynamic => 1,
};
Expand Down
2 changes: 1 addition & 1 deletion naga/src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ impl Validator {
})?;
if !self.allow_overrides {
if let crate::TypeInner::Array {
size: crate::ArraySize::Pending(_),
size: crate::ArraySize::Pending(..),
..
} = ty.inner
{
Expand Down
4 changes: 2 additions & 2 deletions naga/src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl super::Validator {
| TypeFlags::CONSTRUCTIBLE
| TypeFlags::CREATION_RESOLVED
}
crate::ArraySize::Pending(_) => {
crate::ArraySize::Pending(..) => {
TypeFlags::DATA
| TypeFlags::SIZED
| TypeFlags::COPY
Expand Down Expand Up @@ -719,7 +719,7 @@ impl super::Validator {
crate::ArraySize::Constant(_) => {
TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE | TypeFlags::CREATION_RESOLVED
}
crate::ArraySize::Pending(_) => TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE,
crate::ArraySize::Pending(..) => TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE,
crate::ArraySize::Dynamic => {
// Final type is non-sized
TypeFlags::HOST_SHAREABLE | TypeFlags::CREATION_RESOLVED
Expand Down

0 comments on commit bf89b36

Please sign in to comment.