Skip to content

Commit fd53ea9

Browse files
committed
[naga] Let constant evaluation of As preserve Splat expressions.
When asked to evaluate an `Expression::As` cast applied to a `Splat` expression, change `ConstantEvaluator::cast` to preserve the `Splat`, rather than expanding it out to a `Compose` expression.
1 parent 666f681 commit fd53ea9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

naga/src/proc/constant_evaluator.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,22 @@ impl<'a> ConstantEvaluator<'a> {
863863
}
864864
}
865865

866+
/// Lower [`ZeroValue`] expressions to [`Literal`] and [`Compose`] expressions.
867+
///
868+
/// [`ZeroValue`]: Expression::ZeroValue
869+
/// [`Literal`]: Expression::Literal
870+
/// [`Compose`]: Expression::Compose
871+
fn eval_zero_value(
872+
&mut self,
873+
expr: Handle<Expression>,
874+
span: Span,
875+
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
876+
match self.expressions[expr] {
877+
Expression::ZeroValue(ty) => self.eval_zero_value_impl(ty, span),
878+
_ => Ok(expr),
879+
}
880+
}
881+
866882
/// Lower [`ZeroValue`] expressions to [`Literal`] and [`Compose`] expressions.
867883
///
868884
/// [`ZeroValue`]: Expression::ZeroValue
@@ -953,7 +969,7 @@ impl<'a> ConstantEvaluator<'a> {
953969
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
954970
use crate::Scalar as Sc;
955971

956-
let expr = self.eval_zero_value_and_splat(expr, span)?;
972+
let expr = self.eval_zero_value(expr, span)?;
957973

958974
let expr = match self.expressions[expr] {
959975
Expression::Literal(literal) => {
@@ -1022,6 +1038,14 @@ impl<'a> ConstantEvaluator<'a> {
10221038

10231039
Expression::Compose { ty, components }
10241040
}
1041+
Expression::Splat { size, value } => {
1042+
let value_span = self.expressions.get_span(value);
1043+
let cast_value = self.cast(value, target, value_span)?;
1044+
Expression::Splat {
1045+
size,
1046+
value: cast_value,
1047+
}
1048+
}
10251049
_ => return Err(ConstantEvaluatorError::InvalidCastArg),
10261050
};
10271051

naga/tests/out/wgsl/900-implicit-conversions.frag.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn implicit_dims_3(v_6: vec4<f32>) {
5757
fn main_1() {
5858
exact_1(1);
5959
implicit(1.0);
60-
implicit_dims_2(vec3<f32>(1.0, 1.0, 1.0));
60+
implicit_dims_2(vec3(1.0));
6161
return;
6262
}
6363

0 commit comments

Comments
 (0)