[wgsl-in] don't treat let declarations as const declarations

This commit is contained in:
teoxoy authored and Teodor Tanasoaia committed 2023-10-12 13:13:26 +02:00
1 parent 3d346977e5
commit 55dd0e1fbc
24 files changed
+926 -931

No files matched your search

+17 -5
View File
@@ -363,11 +363,16 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
fn const_access(&self, handle: Handle<crate::Expression>) -> Option<u32> {
match self.expr_type {
ExpressionContextType::Runtime(ref ctx) => self
.module
.to_ctx()
.eval_expr_to_u32_from(handle, ctx.naga_expressions)
.ok(),
ExpressionContextType::Runtime(ref ctx) => {
if !ctx.expression_constness.is_const(handle) {
return None;
}
self.module
.to_ctx()
.eval_expr_to_u32_from(handle, ctx.naga_expressions)
.ok()
}
ExpressionContextType::Constant => self.module.to_ctx().eval_expr_to_u32(handle).ok(),
}
}
@@ -404,6 +409,12 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
) -> Result<crate::SwizzleComponent, Error<'source>> {
match self.expr_type {
ExpressionContextType::Runtime(ref rctx) => {
if !rctx.expression_constness.is_const(expr) {
return Err(Error::ExpectedConstExprConcreteIntegerScalar(
component_span,
));
}
let index = self
.module
.to_ctx()
@@ -1076,6 +1087,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
emitter.start(ctx.naga_expressions);
let value = self.expression(l.init, ctx.as_expression(block, &mut emitter))?;
ctx.expression_constness.force_non_const(value);
let explicit_ty =
l.ty.map(|ty| self.resolve_ast_type(ty, ctx.as_global()))
+5
View File
@@ -37,6 +37,11 @@ impl ExpressionConstnessTracker {
}
}
/// Forces the the expression to not be const
pub fn force_non_const(&mut self, value: Handle<Expression>) {
self.inner.remove(value.index());
}
fn insert(&mut self, value: Handle<Expression>) {
self.inner.insert(value.index());
}
+1 -1
View File
@@ -612,7 +612,7 @@ impl GlobalCtx<'_> {
self.eval_expr_to_literal_from(handle, self.const_expressions)
}
pub(crate) fn eval_expr_to_literal_from(
fn eval_expr_to_literal_from(
&self,
handle: crate::Handle<crate::Expression>,
arena: &crate::Arena<crate::Expression>,