Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Aug 23, 2023
1 parent 016a856 commit bb43f64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 53 deletions.
49 changes: 4 additions & 45 deletions src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::Expression>,
right: &mut Handle<crate::Expression>,
) -> 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
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions src/valid/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit bb43f64

Please sign in to comment.