Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[naga] Let constant evaluation of As preserve Splat expressions. #4719

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion naga/src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,22 @@ impl<'a> ConstantEvaluator<'a> {
}
}

/// Lower [`ZeroValue`] expressions to [`Literal`] and [`Compose`] expressions.
///
/// [`ZeroValue`]: Expression::ZeroValue
/// [`Literal`]: Expression::Literal
/// [`Compose`]: Expression::Compose
fn eval_zero_value(
&mut self,
expr: Handle<Expression>,
span: Span,
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
match self.expressions[expr] {
Expression::ZeroValue(ty) => self.eval_zero_value_impl(ty, span),
_ => Ok(expr),
}
}

/// Lower [`ZeroValue`] expressions to [`Literal`] and [`Compose`] expressions.
///
/// [`ZeroValue`]: Expression::ZeroValue
Expand Down Expand Up @@ -953,7 +969,7 @@ impl<'a> ConstantEvaluator<'a> {
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
use crate::Scalar as Sc;

let expr = self.eval_zero_value_and_splat(expr, span)?;
let expr = self.eval_zero_value(expr, span)?;

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

Expression::Compose { ty, components }
}
Expression::Splat { size, value } => {
let value_span = self.expressions.get_span(value);
let cast_value = self.cast(value, target, value_span)?;
Expression::Splat {
size,
value: cast_value,
}
}
jimblandy marked this conversation as resolved.
Show resolved Hide resolved
_ => return Err(ConstantEvaluatorError::InvalidCastArg),
};

Expand Down
2 changes: 1 addition & 1 deletion naga/tests/out/wgsl/900-implicit-conversions.frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn implicit_dims_3(v_6: vec4<f32>) {
fn main_1() {
exact_1(1);
implicit(1.0);
implicit_dims_2(vec3<f32>(1.0, 1.0, 1.0));
implicit_dims_2(vec3(1.0));
return;
}

Expand Down
Loading