Revert: Workaround for some builtins not implemented as constant expression

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev
2025-03-08 18:31:10 +01:00
committed by Jim Blandy
parent 6e6675a73c
commit d937fabcd5

View File

@@ -363,8 +363,6 @@ struct FunctionLocalData<'a> {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub enum ExpressionKind {
/// If const is also implemented as const
ImplConst,
Const,
Override,
Runtime,
@@ -392,21 +390,13 @@ impl ExpressionKindTracker {
}
pub fn is_const(&self, h: Handle<Expression>) -> bool {
matches!(
self.type_of(h),
ExpressionKind::Const | ExpressionKind::ImplConst
)
}
/// Returns `true` if naga can also evaluate expression as const
pub fn is_impl_const(&self, h: Handle<Expression>) -> bool {
matches!(self.type_of(h), ExpressionKind::ImplConst)
matches!(self.type_of(h), ExpressionKind::Const)
}
pub fn is_const_or_override(&self, h: Handle<Expression>) -> bool {
matches!(
self.type_of(h),
ExpressionKind::Const | ExpressionKind::Override | ExpressionKind::ImplConst
ExpressionKind::Const | ExpressionKind::Override
)
}
@@ -427,14 +417,13 @@ impl ExpressionKindTracker {
}
fn type_of_with_expr(&self, expr: &Expression) -> ExpressionKind {
use crate::MathFunction as Mf;
match *expr {
Expression::Literal(_) | Expression::ZeroValue(_) | Expression::Constant(_) => {
ExpressionKind::ImplConst
ExpressionKind::Const
}
Expression::Override(_) => ExpressionKind::Override,
Expression::Compose { ref components, .. } => {
let mut expr_type = ExpressionKind::ImplConst;
let mut expr_type = ExpressionKind::Const;
for component in components {
expr_type = expr_type.max(self.type_of(*component))
}
@@ -445,16 +434,13 @@ impl ExpressionKindTracker {
Expression::Access { base, index } => self.type_of(base).max(self.type_of(index)),
Expression::Swizzle { vector, .. } => self.type_of(vector),
Expression::Unary { expr, .. } => self.type_of(expr),
Expression::Binary { left, right, .. } => self
.type_of(left)
.max(self.type_of(right))
.max(ExpressionKind::Const),
Expression::Binary { left, right, .. } => self.type_of(left).max(self.type_of(right)),
Expression::Math {
fun,
arg,
arg1,
arg2,
arg3,
..
} => self
.type_of(arg)
.max(
@@ -468,33 +454,8 @@ impl ExpressionKindTracker {
.max(
arg3.map(|arg| self.type_of(arg))
.unwrap_or(ExpressionKind::Const),
)
.max(
if matches!(
fun,
Mf::Dot
| Mf::Outer
| Mf::Distance
| Mf::Length
| Mf::Normalize
| Mf::FaceForward
| Mf::Reflect
| Mf::Refract
| Mf::Ldexp
| Mf::Modf
| Mf::Mix
| Mf::Frexp
) {
ExpressionKind::Const
} else {
ExpressionKind::ImplConst
},
),
Expression::As { convert, expr, .. } => self.type_of(expr).max(if convert.is_some() {
ExpressionKind::ImplConst
} else {
ExpressionKind::Const
}),
Expression::As { expr, .. } => self.type_of(expr),
Expression::Select {
condition,
accept,
@@ -502,8 +463,7 @@ impl ExpressionKindTracker {
} => self
.type_of(condition)
.max(self.type_of(accept))
.max(self.type_of(reject))
.max(ExpressionKind::Const),
.max(self.type_of(reject)),
Expression::Relational { argument, .. } => self.type_of(argument),
Expression::ArrayLength(expr) => self.type_of(expr),
_ => ExpressionKind::Runtime,
@@ -797,7 +757,6 @@ impl<'a> ConstantEvaluator<'a> {
span: Span,
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
match self.expression_kind_tracker.type_of_with_expr(&expr) {
ExpressionKind::ImplConst => self.try_eval_and_append_impl(&expr, span),
ExpressionKind::Const => {
let eval_result = self.try_eval_and_append_impl(&expr, span);
// We should be able to evaluate `Const` expressions at this