From ede0dd994f035f922654fe4e18fecbaf71e68df5 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Thu, 24 Aug 2023 00:45:27 +0200 Subject: [PATCH] cleanup --- src/front/wgsl/lower/mod.rs | 49 +++---------------------------------- src/valid/expression.rs | 16 ++++++------ 2 files changed, 12 insertions(+), 53 deletions(-) diff --git a/src/front/wgsl/lower/mod.rs b/src/front/wgsl/lower/mod.rs index aa84ccf5a9..5420e9d278 100644 --- a/src/front/wgsl/lower/mod.rs +++ b/src/front/wgsl/lower/mod.rs @@ -503,45 +503,6 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> { } } - /// Insert splats, if needed by the non-'*' operations. - /// - /// See the "Binary arithmetic expressions with mixed scalar and vector operands" - /// table in the WebGPU Shading Language specification for relevant operators. - /// - /// Multiply is not handled here as backends are expected to handle vec*scalar - /// operations, so inserting splats into the IR increases size needlessly. - fn binary_op_splat( - &mut self, - op: crate::BinaryOperator, - left: &mut Handle, - right: &mut Handle, - ) -> Result<(), Error<'source>> { - if false && matches!(op, crate::BinaryOperator::Modulo) { - self.grow_types(*left)?.grow_types(*right)?; - - match (self.resolved_inner(*left), self.resolved_inner(*right)) { - (&crate::TypeInner::Vector { size, .. }, &crate::TypeInner::Scalar { .. }) => { - *right = self.append_expression( - crate::Expression::Splat { - size, - value: *right, - }, - self.get_expression_span(*right), - ); - } - (&crate::TypeInner::Scalar { .. }, &crate::TypeInner::Vector { size, .. }) => { - *left = self.append_expression( - crate::Expression::Splat { size, value: *left }, - self.get_expression_span(*left), - ); - } - _ => {} - } - } - - Ok(()) - } - /// Add a single expression to the expression table that is not covered by `self.emitter`. /// /// This is useful for `CallResult` and `AtomicResult` expressions, which should not be covered by @@ -1231,7 +1192,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let expr = self.expression_for_reference(target, ctx.as_expression(block, &mut emitter))?; - let mut value = self.expression(value, ctx.as_expression(block, &mut emitter))?; + let value = self.expression(value, ctx.as_expression(block, &mut emitter))?; if !expr.is_reference { let ty = ctx.invalid_assignment_type(expr.handle); @@ -1245,8 +1206,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let value = match op { Some(op) => { let mut ctx = ctx.as_expression(block, &mut emitter); - let mut left = ctx.apply_load_rule(expr); - ctx.binary_op_splat(op, &mut left, &mut value)?; + let left = ctx.apply_load_rule(expr); ctx.append_expression( crate::Expression::Binary { op, @@ -1438,9 +1398,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { } ast::Expression::Binary { op, left, right } => { // Load both operands. - let mut left = self.expression(left, ctx.reborrow())?; - let mut right = self.expression(right, ctx.reborrow())?; - ctx.binary_op_splat(op, &mut left, &mut right)?; + let left = self.expression(left, ctx.reborrow())?; + let right = self.expression(right, ctx.reborrow())?; (crate::Expression::Binary { op, left, right }, false) } ast::Expression::Call { diff --git a/src/valid/expression.rs b/src/valid/expression.rs index 5eefcf795b..e71573110f 100644 --- a/src/valid/expression.rs +++ b/src/valid/expression.rs @@ -631,16 +631,16 @@ impl super::Validator { let good = match op { Bo::Add | Bo::Subtract => match (left_inner, right_inner) { ( - Ti::Scalar { + &Ti::Scalar { kind: kind_left, .. } - | Ti::Vector { + | &Ti::Vector { kind: kind_left, .. }, - Ti::Scalar { + &Ti::Scalar { kind: kind_right, .. } - | Ti::Vector { + | &Ti::Vector { kind: kind_right, .. }, ) if kind_left == kind_right => true, @@ -655,16 +655,16 @@ impl super::Validator { Sk::Bool => false, }, */ ( - Ti::Scalar { + &Ti::Scalar { kind: kind_left, .. } - | Ti::Vector { + | &Ti::Vector { kind: kind_left, .. }, - Ti::Scalar { + &Ti::Scalar { kind: kind_right, .. } - | Ti::Vector { + | &Ti::Vector { kind: kind_right, .. }, ) if kind_left == kind_right => true,