Skip to content

Commit 0dd6ccb

Browse files
sagudevVecvec
authored andcommitted
Revert: Workaround for some builtins not implemented as constant expression
Signed-off-by: sagudev <[email protected]>
1 parent dd2b7cd commit 0dd6ccb

File tree

1 file changed

+8
-49
lines changed

1 file changed

+8
-49
lines changed

naga/src/proc/constant_evaluator.rs

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ struct FunctionLocalData<'a> {
363363

364364
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
365365
pub enum ExpressionKind {
366-
/// If const is also implemented as const
367-
ImplConst,
368366
Const,
369367
Override,
370368
Runtime,
@@ -392,21 +390,13 @@ impl ExpressionKindTracker {
392390
}
393391

394392
pub fn is_const(&self, h: Handle<Expression>) -> bool {
395-
matches!(
396-
self.type_of(h),
397-
ExpressionKind::Const | ExpressionKind::ImplConst
398-
)
399-
}
400-
401-
/// Returns `true` if naga can also evaluate expression as const
402-
pub fn is_impl_const(&self, h: Handle<Expression>) -> bool {
403-
matches!(self.type_of(h), ExpressionKind::ImplConst)
393+
matches!(self.type_of(h), ExpressionKind::Const)
404394
}
405395

406396
pub fn is_const_or_override(&self, h: Handle<Expression>) -> bool {
407397
matches!(
408398
self.type_of(h),
409-
ExpressionKind::Const | ExpressionKind::Override | ExpressionKind::ImplConst
399+
ExpressionKind::Const | ExpressionKind::Override
410400
)
411401
}
412402

@@ -427,14 +417,13 @@ impl ExpressionKindTracker {
427417
}
428418

429419
fn type_of_with_expr(&self, expr: &Expression) -> ExpressionKind {
430-
use crate::MathFunction as Mf;
431420
match *expr {
432421
Expression::Literal(_) | Expression::ZeroValue(_) | Expression::Constant(_) => {
433-
ExpressionKind::ImplConst
422+
ExpressionKind::Const
434423
}
435424
Expression::Override(_) => ExpressionKind::Override,
436425
Expression::Compose { ref components, .. } => {
437-
let mut expr_type = ExpressionKind::ImplConst;
426+
let mut expr_type = ExpressionKind::Const;
438427
for component in components {
439428
expr_type = expr_type.max(self.type_of(*component))
440429
}
@@ -445,16 +434,13 @@ impl ExpressionKindTracker {
445434
Expression::Access { base, index } => self.type_of(base).max(self.type_of(index)),
446435
Expression::Swizzle { vector, .. } => self.type_of(vector),
447436
Expression::Unary { expr, .. } => self.type_of(expr),
448-
Expression::Binary { left, right, .. } => self
449-
.type_of(left)
450-
.max(self.type_of(right))
451-
.max(ExpressionKind::Const),
437+
Expression::Binary { left, right, .. } => self.type_of(left).max(self.type_of(right)),
452438
Expression::Math {
453-
fun,
454439
arg,
455440
arg1,
456441
arg2,
457442
arg3,
443+
..
458444
} => self
459445
.type_of(arg)
460446
.max(
@@ -468,42 +454,16 @@ impl ExpressionKindTracker {
468454
.max(
469455
arg3.map(|arg| self.type_of(arg))
470456
.unwrap_or(ExpressionKind::Const),
471-
)
472-
.max(
473-
if matches!(
474-
fun,
475-
Mf::Dot
476-
| Mf::Outer
477-
| Mf::Distance
478-
| Mf::Length
479-
| Mf::Normalize
480-
| Mf::FaceForward
481-
| Mf::Reflect
482-
| Mf::Refract
483-
| Mf::Ldexp
484-
| Mf::Modf
485-
| Mf::Mix
486-
| Mf::Frexp
487-
) {
488-
ExpressionKind::Const
489-
} else {
490-
ExpressionKind::ImplConst
491-
},
492457
),
493-
Expression::As { convert, expr, .. } => self.type_of(expr).max(if convert.is_some() {
494-
ExpressionKind::ImplConst
495-
} else {
496-
ExpressionKind::Const
497-
}),
458+
Expression::As { expr, .. } => self.type_of(expr),
498459
Expression::Select {
499460
condition,
500461
accept,
501462
reject,
502463
} => self
503464
.type_of(condition)
504465
.max(self.type_of(accept))
505-
.max(self.type_of(reject))
506-
.max(ExpressionKind::Const),
466+
.max(self.type_of(reject)),
507467
Expression::Relational { argument, .. } => self.type_of(argument),
508468
Expression::ArrayLength(expr) => self.type_of(expr),
509469
_ => ExpressionKind::Runtime,
@@ -797,7 +757,6 @@ impl<'a> ConstantEvaluator<'a> {
797757
span: Span,
798758
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
799759
match self.expression_kind_tracker.type_of_with_expr(&expr) {
800-
ExpressionKind::ImplConst => self.try_eval_and_append_impl(&expr, span),
801760
ExpressionKind::Const => {
802761
let eval_result = self.try_eval_and_append_impl(&expr, span);
803762
// We should be able to evaluate `Const` expressions at this

0 commit comments

Comments
 (0)