mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 06:21:13 +01:00
fix(naga): Implement constant matrix add/sub/mul (#9162)
* fix(naga): Implement constant matrix operations Implement binary operations in naga constant evaluator - multiplication on vector-matrix, matrix-vector, and matrix-matrix - addition/subtraction on matrix-matrix * Related CTS webgpu:shader,validation,expression,matrix,* : 1678/1881 (89.21%) -> 1737/1881 (92.34%) > remaining fail : overflow/underflow (126), atomic (18) * naga snapshots updated automatically * chore: Update naga snapshots
This commit is contained in:
1 parent
35db26b2c6
commit
eb3bc87b21
7 files changed
+1174
-701
No files matched your search
+1
-1
@@ -154,7 +154,7 @@ webgpu:shader,validation,expression,call,builtin,unpack4xI8:* // 75%, missing co
|
||||
webgpu:shader,validation,expression,call,builtin,unpack4xU8:* // 75%, missing const eval (#4507)
|
||||
webgpu:shader,validation,expression,call,builtin,value_constructor:* // 92%, value constructors lack must-use validation + abstract-float matrix validation issues
|
||||
webgpu:shader,validation,expression,early_evaluation:* // 67%, mixed override/runtime composite evaluation
|
||||
webgpu:shader,validation,expression,matrix,* // 83%, #5474, #8790, #8868
|
||||
webgpu:shader,validation,expression,matrix,* // 92%, #5474, #8868, overflow/underflow/atomic
|
||||
webgpu:shader,validation,expression,precedence:* // 76%, https://github.com/gfx-rs/wgpu/issues/4536
|
||||
webgpu:shader,validation,expression,unary,* // 99%, atomics #5474
|
||||
webgpu:shader,validation,extension,dual_source_blending:blend_src_usage:* // 61%, @blend_src validation gaps
|
||||
|
||||
@@ -2776,32 +2776,24 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
left_components,
|
||||
self.expressions,
|
||||
self.types,
|
||||
);
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
let right_flattened = crate::proc::flatten_compose(
|
||||
right_ty,
|
||||
right_components,
|
||||
self.expressions,
|
||||
self.types,
|
||||
);
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// `flatten_compose` doesn't return an `ExactSizeIterator`, so
|
||||
// make a reasonable guess of the capacity we'll need.
|
||||
let mut flattened = Vec::with_capacity(left_components.len());
|
||||
flattened.extend(left_flattened.zip(right_flattened));
|
||||
|
||||
match (&self.types[left_ty].inner, &self.types[right_ty].inner) {
|
||||
(
|
||||
&TypeInner::Vector {
|
||||
size: left_size, ..
|
||||
},
|
||||
&TypeInner::Vector {
|
||||
size: right_size, ..
|
||||
},
|
||||
) if left_size == right_size => {
|
||||
self.binary_op_vector(op, left_size, &flattened, left_ty, span)?
|
||||
}
|
||||
_ => return Err(ConstantEvaluatorError::InvalidBinaryOpArgs),
|
||||
}
|
||||
self.binary_op_compose(
|
||||
op,
|
||||
&left_flattened,
|
||||
&right_flattened,
|
||||
left_ty,
|
||||
right_ty,
|
||||
span,
|
||||
)?
|
||||
}
|
||||
_ => return Err(ConstantEvaluatorError::InvalidBinaryOpArgs),
|
||||
};
|
||||
@@ -2827,11 +2819,105 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn binary_op_compose(
|
||||
&mut self,
|
||||
op: BinaryOperator,
|
||||
left_components: &[Handle<Expression>],
|
||||
right_components: &[Handle<Expression>],
|
||||
left_ty: Handle<Type>,
|
||||
right_ty: Handle<Type>,
|
||||
span: Span,
|
||||
) -> Result<Expression, ConstantEvaluatorError> {
|
||||
match (&self.types[left_ty].inner, &self.types[right_ty].inner) {
|
||||
// Binary operation on vector-vector
|
||||
(
|
||||
&TypeInner::Vector {
|
||||
size: left_size, ..
|
||||
},
|
||||
&TypeInner::Vector {
|
||||
size: right_size, ..
|
||||
},
|
||||
) if left_size == right_size => self.binary_op_vector(
|
||||
op,
|
||||
left_size,
|
||||
left_components,
|
||||
right_components,
|
||||
left_ty,
|
||||
span,
|
||||
),
|
||||
// Binary operation on vector-matrix
|
||||
(
|
||||
&TypeInner::Vector { size, .. },
|
||||
&TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
scalar,
|
||||
},
|
||||
) if op == BinaryOperator::Multiply && size == rows => self.multiply_vector_matrix(
|
||||
left_components,
|
||||
right_components,
|
||||
columns,
|
||||
scalar,
|
||||
span,
|
||||
),
|
||||
// Binary operation on matrix-vector
|
||||
(
|
||||
&TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
scalar,
|
||||
},
|
||||
&TypeInner::Vector { size, .. },
|
||||
) if op == BinaryOperator::Multiply && size == columns => {
|
||||
self.multiply_matrix_vector(left_components, right_components, rows, scalar, span)
|
||||
}
|
||||
// Binary operation on matrix-matrix
|
||||
(
|
||||
&TypeInner::Matrix {
|
||||
columns: left_columns,
|
||||
rows: left_rows,
|
||||
scalar,
|
||||
},
|
||||
&TypeInner::Matrix {
|
||||
columns: right_columns,
|
||||
rows: right_rows,
|
||||
..
|
||||
},
|
||||
) => match op {
|
||||
BinaryOperator::Add | BinaryOperator::Subtract
|
||||
if left_columns == right_columns && left_rows == right_rows =>
|
||||
{
|
||||
let components = left_components
|
||||
.iter()
|
||||
.zip(right_components)
|
||||
.map(|(&left, &right)| self.binary_op(op, left, right, span))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(Expression::Compose {
|
||||
ty: left_ty,
|
||||
components,
|
||||
})
|
||||
}
|
||||
BinaryOperator::Multiply if left_columns == right_rows => self
|
||||
.multiply_matrix_matrix(
|
||||
left_components,
|
||||
right_components,
|
||||
left_rows,
|
||||
right_columns,
|
||||
scalar,
|
||||
span,
|
||||
),
|
||||
_ => Err(ConstantEvaluatorError::InvalidBinaryOpArgs),
|
||||
},
|
||||
_ => Err(ConstantEvaluatorError::InvalidBinaryOpArgs),
|
||||
}
|
||||
}
|
||||
|
||||
fn binary_op_vector(
|
||||
&mut self,
|
||||
op: BinaryOperator,
|
||||
size: crate::VectorSize,
|
||||
components: &[(Handle<Expression>, Handle<Expression>)],
|
||||
left_components: &[Handle<Expression>],
|
||||
right_components: &[Handle<Expression>],
|
||||
left_ty: Handle<Type>,
|
||||
span: Span,
|
||||
) -> Result<Expression, ConstantEvaluatorError> {
|
||||
@@ -2872,14 +2958,167 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
}
|
||||
};
|
||||
|
||||
let components = components
|
||||
let components = left_components
|
||||
.iter()
|
||||
.map(|&(left, right)| self.binary_op(op, left, right, span))
|
||||
.zip(right_components)
|
||||
.map(|(&left, &right)| self.binary_op(op, left, right, span))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok(Expression::Compose { ty, components })
|
||||
}
|
||||
|
||||
fn multiply_vector_matrix(
|
||||
&mut self,
|
||||
vec_components: &[Handle<Expression>],
|
||||
mat_components: &[Handle<Expression>],
|
||||
mat_columns: crate::VectorSize,
|
||||
scalar: crate::Scalar,
|
||||
span: Span,
|
||||
) -> Result<Expression, ConstantEvaluatorError> {
|
||||
let ty = self.types.insert(
|
||||
Type {
|
||||
name: None,
|
||||
inner: TypeInner::Vector {
|
||||
size: mat_columns,
|
||||
scalar,
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
let components = mat_components
|
||||
.iter()
|
||||
.map(|&column| {
|
||||
let Expression::Compose { ref components, .. } = self.expressions[column] else {
|
||||
unreachable!()
|
||||
};
|
||||
self.dot_exprs(
|
||||
vec_components.iter().cloned(),
|
||||
components.clone().into_iter(),
|
||||
span,
|
||||
)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(Expression::Compose { ty, components })
|
||||
}
|
||||
|
||||
fn multiply_matrix_vector(
|
||||
&mut self,
|
||||
mat_components: &[Handle<Expression>],
|
||||
vec_components: &[Handle<Expression>],
|
||||
mat_rows: crate::VectorSize,
|
||||
scalar: crate::Scalar,
|
||||
span: Span,
|
||||
) -> Result<Expression, ConstantEvaluatorError> {
|
||||
let ty = self.types.insert(
|
||||
Type {
|
||||
name: None,
|
||||
inner: TypeInner::Vector {
|
||||
size: mat_rows,
|
||||
scalar,
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
|
||||
let flatten = self.flatten_matrix(mat_components);
|
||||
let nr = mat_rows as usize;
|
||||
let components = (0..nr)
|
||||
.map(|r| {
|
||||
let row = flatten.iter().skip(r).step_by(nr).cloned();
|
||||
self.dot_exprs(row, vec_components.iter().cloned(), span)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(Expression::Compose { ty, components })
|
||||
}
|
||||
|
||||
fn multiply_matrix_matrix(
|
||||
&mut self,
|
||||
left_components: &[Handle<Expression>],
|
||||
right_components: &[Handle<Expression>],
|
||||
left_rows: crate::VectorSize,
|
||||
right_columns: crate::VectorSize,
|
||||
scalar: crate::Scalar,
|
||||
span: Span,
|
||||
) -> Result<Expression, ConstantEvaluatorError> {
|
||||
let left_nc = left_components.len();
|
||||
let left_nr = left_rows as usize;
|
||||
let right_nc = right_columns as usize;
|
||||
let right_nr = left_nc;
|
||||
|
||||
let mut result = Vec::with_capacity(right_nc);
|
||||
let result_ty = self.types.insert(
|
||||
Type {
|
||||
name: None,
|
||||
inner: TypeInner::Matrix {
|
||||
columns: right_columns,
|
||||
rows: left_rows,
|
||||
scalar,
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
let result_column_ty = self.types.insert(
|
||||
Type {
|
||||
name: None,
|
||||
inner: TypeInner::Vector {
|
||||
size: left_rows,
|
||||
scalar,
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
|
||||
let left_flattened = self.flatten_matrix(left_components);
|
||||
let right_flattened = self.flatten_matrix(right_components);
|
||||
for c in 0..right_nc {
|
||||
let result_column = (0..left_nr)
|
||||
.map(|r| {
|
||||
let row = left_flattened.iter().skip(r).step_by(left_nr);
|
||||
let column = right_flattened.iter().skip(c * right_nr).take(right_nr);
|
||||
self.dot_exprs(row.cloned(), column.cloned(), span)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let expr = Expression::Compose {
|
||||
ty: result_column_ty,
|
||||
components: result_column,
|
||||
};
|
||||
let handle = self.register_evaluated_expr(expr, span)?;
|
||||
result.push(handle);
|
||||
}
|
||||
Ok(Expression::Compose {
|
||||
ty: result_ty,
|
||||
components: result,
|
||||
})
|
||||
}
|
||||
|
||||
fn flatten_matrix(&self, columns: &[Handle<Expression>]) -> ArrayVec<Handle<Expression>, 16> {
|
||||
let mut flattened = ArrayVec::<_, 16>::new();
|
||||
for &column in columns {
|
||||
let Expression::Compose { ref components, .. } = self.expressions[column] else {
|
||||
unreachable!()
|
||||
};
|
||||
flattened.extend(components.iter().cloned());
|
||||
}
|
||||
flattened
|
||||
}
|
||||
|
||||
fn dot_exprs(
|
||||
&mut self,
|
||||
left: impl Iterator<Item = Handle<Expression>>,
|
||||
right: impl Iterator<Item = Handle<Expression>>,
|
||||
span: Span,
|
||||
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
|
||||
let mut acc = None;
|
||||
for (l, r) in left.zip(right) {
|
||||
let result = self.binary_op(BinaryOperator::Multiply, l, r, span)?;
|
||||
match acc.as_mut() {
|
||||
Some(acc) => *acc = self.binary_op(BinaryOperator::Add, *acc, result, span)?,
|
||||
None => acc = Some(result),
|
||||
}
|
||||
}
|
||||
Ok(acc.unwrap())
|
||||
}
|
||||
|
||||
fn relational(
|
||||
&mut self,
|
||||
fun: RelationalFunction,
|
||||
@@ -3534,8 +3773,8 @@ mod tests {
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
use crate::{
|
||||
Arena, Constant, Expression, Literal, ScalarKind, Type, TypeInner, UnaryOperator,
|
||||
UniqueArena, VectorSize,
|
||||
Arena, BinaryOperator, Constant, Expression, FastHashMap, Handle, Literal, ScalarKind,
|
||||
Type, TypeInner, UnaryOperator, UniqueArena, VectorSize,
|
||||
};
|
||||
|
||||
use super::{Behavior, ConstantEvaluator, ExpressionKindTracker, WgslRestrictions};
|
||||
@@ -3673,6 +3912,265 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn matrix_op() {
|
||||
let mut helper = MatrixTestHelper::new();
|
||||
|
||||
for nc in 2..=4 {
|
||||
for nr in 2..=4 {
|
||||
// Validates multiplication on vector-matrix.
|
||||
// vecR(0, 1, .., r) * matCxR(0, 1, .., nc * nr)
|
||||
let evaluated = helper.eval_vector_multiply_matrix(nc, nr);
|
||||
let expected = (0..nc)
|
||||
.map(|c| (0..nr).map(|r| (r * (c * nr + r)) as f32).sum())
|
||||
.collect::<Vec<f32>>();
|
||||
assert_eq!(evaluated, expected);
|
||||
|
||||
// Validates multiplication on matrix-vector.
|
||||
// matCxR(0, 1, .., nc * nr) * vecC(0, 1, .., nc)
|
||||
let evaluated = helper.eval_matrix_multiply_vector(nc, nr);
|
||||
let expected = (0..nr)
|
||||
.map(|r| (0..nc).map(|c| (c * (c * nr + r)) as f32).sum())
|
||||
.collect::<Vec<f32>>();
|
||||
assert_eq!(evaluated, expected);
|
||||
|
||||
for k in 2..=4 {
|
||||
// Validates multiplication on matrix-matrix.
|
||||
// matKxR(0, 1, .., k * nr) * matCxK(0, 1, .., nc * k)
|
||||
let evaluated = helper.eval_matrix_multiply_matrix(nr, nc, k);
|
||||
let expected = (0..nc)
|
||||
.flat_map(|c| {
|
||||
(0..nr).map(move |r| {
|
||||
(0..k).map(|v| ((v * nr + r) * (c * k + v)) as f32).sum()
|
||||
})
|
||||
})
|
||||
.collect::<Vec<f32>>();
|
||||
assert_eq!(evaluated, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Test fixture providing pre-built f32 vector and matrix constant
|
||||
/// expressions with sequential element values, used to evaluate and verify
|
||||
/// matrix operations.
|
||||
struct MatrixTestHelper {
|
||||
types: UniqueArena<Type>,
|
||||
expressions: Arena<Expression>,
|
||||
/// Vector expressions from [0, 1] to [0, 1, 2, 3].
|
||||
vec_exprs: FastHashMap<usize, Handle<Expression>>,
|
||||
/// Matrix expressions from [0, .., 3] to [0, .., 15].
|
||||
mat_exprs: FastHashMap<(usize, usize), Handle<Expression>>,
|
||||
}
|
||||
|
||||
impl MatrixTestHelper {
|
||||
fn new() -> Self {
|
||||
let mut types = UniqueArena::new();
|
||||
let mut expressions = Arena::new();
|
||||
let span = crate::Span::default();
|
||||
|
||||
let (mut vec_tys, mut mat_tys) = (FastHashMap::default(), FastHashMap::default());
|
||||
for c in 2..=4 {
|
||||
let vec_ty = types.insert(
|
||||
Type {
|
||||
name: None,
|
||||
inner: TypeInner::Vector {
|
||||
size: Self::int_to_vector_size(c),
|
||||
scalar: crate::Scalar::F32,
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
vec_tys.insert(c, vec_ty);
|
||||
for r in 2..=4 {
|
||||
let mat_ty = types.insert(
|
||||
Type {
|
||||
name: None,
|
||||
inner: TypeInner::Matrix {
|
||||
columns: Self::int_to_vector_size(c),
|
||||
rows: Self::int_to_vector_size(r),
|
||||
scalar: crate::Scalar::F32,
|
||||
},
|
||||
},
|
||||
span,
|
||||
);
|
||||
mat_tys.insert((c, r), mat_ty);
|
||||
}
|
||||
}
|
||||
|
||||
let mut lit_exprs = FastHashMap::default();
|
||||
for i in 0..16 {
|
||||
let expr = expressions.append(Expression::Literal(Literal::F32(i as f32)), span);
|
||||
lit_exprs.insert(i, expr);
|
||||
}
|
||||
|
||||
let mut vec_exprs = FastHashMap::default();
|
||||
for c in 2..=4 {
|
||||
let expr = expressions.append(
|
||||
Expression::Compose {
|
||||
ty: *vec_tys.get(&c).unwrap(),
|
||||
components: (0..c)
|
||||
.map(|i| *lit_exprs.get(&i).unwrap())
|
||||
.collect::<Vec<_>>(),
|
||||
},
|
||||
span,
|
||||
);
|
||||
vec_exprs.insert(c, expr);
|
||||
}
|
||||
|
||||
let mut mat_exprs = FastHashMap::default();
|
||||
for c in 2..=4 {
|
||||
for r in 2..=4 {
|
||||
let mut columns = Vec::with_capacity(c);
|
||||
for cc in 0..c {
|
||||
let start = cc * r;
|
||||
let expr = expressions.append(
|
||||
Expression::Compose {
|
||||
ty: *vec_tys.get(&r).unwrap(),
|
||||
components: (start..start + r)
|
||||
.map(|i| *lit_exprs.get(&i).unwrap())
|
||||
.collect::<Vec<_>>(),
|
||||
},
|
||||
span,
|
||||
);
|
||||
columns.push(expr);
|
||||
}
|
||||
|
||||
let expr = expressions.append(
|
||||
Expression::Compose {
|
||||
ty: *mat_tys.get(&(c, r)).unwrap(),
|
||||
components: columns,
|
||||
},
|
||||
span,
|
||||
);
|
||||
mat_exprs.insert((c, r), expr);
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
types,
|
||||
expressions,
|
||||
vec_exprs,
|
||||
mat_exprs,
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluates vec[0..nr] * mat[0..nc*nr] and returns the result as f32s.
|
||||
fn eval_vector_multiply_matrix(&mut self, nc: usize, nr: usize) -> Vec<f32> {
|
||||
let expression_kind_tracker = &mut ExpressionKindTracker::from_arena(&self.expressions);
|
||||
let mut solver = ConstantEvaluator {
|
||||
behavior: Behavior::Wgsl(WgslRestrictions::Const(None)),
|
||||
types: &mut self.types,
|
||||
constants: &Arena::new(),
|
||||
overrides: &Arena::new(),
|
||||
expressions: &mut self.expressions,
|
||||
expression_kind_tracker,
|
||||
layouter: &mut crate::proc::Layouter::default(),
|
||||
};
|
||||
|
||||
let result = solver
|
||||
.try_eval_and_append(
|
||||
Expression::Binary {
|
||||
op: BinaryOperator::Multiply,
|
||||
left: *self.vec_exprs.get(&nr).unwrap(),
|
||||
right: *self.mat_exprs.get(&(nc, nr)).unwrap(),
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
self.flatten(result)
|
||||
}
|
||||
|
||||
/// Evaluates mat[0..nc*nr] * vec[0..nc] and returns the result as f32s.
|
||||
fn eval_matrix_multiply_vector(&mut self, nc: usize, nr: usize) -> Vec<f32> {
|
||||
let expression_kind_tracker = &mut ExpressionKindTracker::from_arena(&self.expressions);
|
||||
let mut solver = ConstantEvaluator {
|
||||
behavior: Behavior::Wgsl(WgslRestrictions::Const(None)),
|
||||
types: &mut self.types,
|
||||
constants: &Arena::new(),
|
||||
overrides: &Arena::new(),
|
||||
expressions: &mut self.expressions,
|
||||
expression_kind_tracker,
|
||||
layouter: &mut crate::proc::Layouter::default(),
|
||||
};
|
||||
|
||||
let result = solver
|
||||
.try_eval_and_append(
|
||||
Expression::Binary {
|
||||
op: BinaryOperator::Multiply,
|
||||
left: *self.mat_exprs.get(&(nc, nr)).unwrap(),
|
||||
right: *self.vec_exprs.get(&nc).unwrap(),
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
self.flatten(result)
|
||||
}
|
||||
|
||||
/// Evaluates mat[0..k*l_nr] * mat[0..r_nc*k] and returns the result as
|
||||
/// f32s.
|
||||
fn eval_matrix_multiply_matrix(&mut self, l_nr: usize, r_nc: usize, k: usize) -> Vec<f32> {
|
||||
let expression_kind_tracker = &mut ExpressionKindTracker::from_arena(&self.expressions);
|
||||
let mut solver = ConstantEvaluator {
|
||||
behavior: Behavior::Wgsl(WgslRestrictions::Const(None)),
|
||||
types: &mut self.types,
|
||||
constants: &Arena::new(),
|
||||
overrides: &Arena::new(),
|
||||
expressions: &mut self.expressions,
|
||||
expression_kind_tracker,
|
||||
layouter: &mut crate::proc::Layouter::default(),
|
||||
};
|
||||
|
||||
let result = solver
|
||||
.try_eval_and_append(
|
||||
Expression::Binary {
|
||||
op: BinaryOperator::Multiply,
|
||||
left: *self.mat_exprs.get(&(k, l_nr)).unwrap(),
|
||||
right: *self.mat_exprs.get(&(r_nc, k)).unwrap(),
|
||||
},
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
self.flatten(result)
|
||||
}
|
||||
|
||||
fn flatten(&self, expr: Handle<Expression>) -> Vec<f32> {
|
||||
let Expression::Compose {
|
||||
ref components,
|
||||
ref ty,
|
||||
} = self.expressions[expr]
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
match self.types[*ty].inner {
|
||||
TypeInner::Vector { .. } => components
|
||||
.iter()
|
||||
.map(|&comp| {
|
||||
let Expression::Literal(Literal::F32(v)) = self.expressions[comp] else {
|
||||
unreachable!()
|
||||
};
|
||||
v
|
||||
})
|
||||
.collect(),
|
||||
TypeInner::Matrix { .. } => components
|
||||
.iter()
|
||||
.flat_map(|&comp| self.flatten(comp))
|
||||
.collect(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn int_to_vector_size(int: usize) -> VectorSize {
|
||||
match int {
|
||||
2 => VectorSize::Bi,
|
||||
3 => VectorSize::Tri,
|
||||
4 => VectorSize::Quad,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cast() {
|
||||
let mut types = UniqueArena::new();
|
||||
@@ -4105,7 +4603,7 @@ mod tests {
|
||||
let solved_add = solver
|
||||
.try_eval_and_append(
|
||||
Expression::Binary {
|
||||
op: crate::BinaryOperator::Add,
|
||||
op: BinaryOperator::Add,
|
||||
left: zero_splat,
|
||||
right: five_splat,
|
||||
},
|
||||
|
||||
@@ -201,15 +201,15 @@ void arithmetic() {
|
||||
vec2 rem4_1 = (vec2(2.0) - vec2(1.0) * trunc(vec2(2.0) / vec2(1.0)));
|
||||
vec2 rem5_1 = (vec2(2.0) - vec2(1.0) * trunc(vec2(2.0) / vec2(1.0)));
|
||||
}
|
||||
mat3x3 add = (mat3x3(0.0) + mat3x3(0.0));
|
||||
mat3x3 sub = (mat3x3(0.0) - mat3x3(0.0));
|
||||
mat3x3 add = mat3x3(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0));
|
||||
mat3x3 sub = mat3x3(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0));
|
||||
mat3x3 mul_scalar0_ = (mat3x3(0.0) * 1.0);
|
||||
mat3x3 mul_scalar1_ = (2.0 * mat3x3(0.0));
|
||||
vec3 mul_vector0_ = (mat4x3(0.0) * vec4(1.0));
|
||||
vec4 mul_vector1_ = (vec3(2.0) * mat4x3(0.0));
|
||||
mat3x3 mul = (mat4x3(0.0) * mat3x4(0.0));
|
||||
int _e175 = prevent_const_eval;
|
||||
wgpu_7437_ = (_e175 + -2147483648);
|
||||
mat3x3 mul = mat3x3(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0));
|
||||
int _e205 = prevent_const_eval;
|
||||
wgpu_7437_ = (_e205 + -2147483648);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,10 +207,6 @@ float4x3 ZeroValuefloat4x3() {
|
||||
return (float4x3)0;
|
||||
}
|
||||
|
||||
float3x4 ZeroValuefloat3x4() {
|
||||
return (float3x4)0;
|
||||
}
|
||||
|
||||
void arithmetic()
|
||||
{
|
||||
int prevent_const_eval = (int)0;
|
||||
@@ -281,15 +277,15 @@ void arithmetic()
|
||||
float2 rem4_1 = naga_mod((2.0).xx, (1.0).xx);
|
||||
float2 rem5_1 = naga_mod((2.0).xx, (1.0).xx);
|
||||
}
|
||||
float3x3 add = (ZeroValuefloat3x3() + ZeroValuefloat3x3());
|
||||
float3x3 sub = (ZeroValuefloat3x3() - ZeroValuefloat3x3());
|
||||
float3x3 add = float3x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0));
|
||||
float3x3 sub = float3x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0));
|
||||
float3x3 mul_scalar0_ = mul(1.0, ZeroValuefloat3x3());
|
||||
float3x3 mul_scalar1_ = mul(ZeroValuefloat3x3(), 2.0);
|
||||
float3 mul_vector0_ = mul((1.0).xxxx, ZeroValuefloat4x3());
|
||||
float4 mul_vector1_ = mul(ZeroValuefloat4x3(), (2.0).xxx);
|
||||
float3x3 mul_ = mul(ZeroValuefloat3x4(), ZeroValuefloat4x3());
|
||||
int _e175 = prevent_const_eval;
|
||||
wgpu_7437_ = asint(asuint(_e175) + asuint(int(-2147483647 - 1)));
|
||||
float3x3 mul_ = float3x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0));
|
||||
int _e205 = prevent_const_eval;
|
||||
wgpu_7437_ = asint(asuint(_e205) + asuint(int(-2147483647 - 1)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -263,15 +263,15 @@ void arithmetic(
|
||||
metal::float2 rem4_1 = metal::fmod(metal::float2(2.0), metal::float2(1.0));
|
||||
metal::float2 rem5_1 = metal::fmod(metal::float2(2.0), metal::float2(1.0));
|
||||
}
|
||||
metal::float3x3 add = metal::float3x3 {} + metal::float3x3 {};
|
||||
metal::float3x3 sub = metal::float3x3 {} - metal::float3x3 {};
|
||||
metal::float3x3 add = metal::float3x3(metal::float3(0.0, 0.0, 0.0), metal::float3(0.0, 0.0, 0.0), metal::float3(0.0, 0.0, 0.0));
|
||||
metal::float3x3 sub = metal::float3x3(metal::float3(0.0, 0.0, 0.0), metal::float3(0.0, 0.0, 0.0), metal::float3(0.0, 0.0, 0.0));
|
||||
metal::float3x3 mul_scalar0_ = metal::float3x3 {} * 1.0;
|
||||
metal::float3x3 mul_scalar1_ = 2.0 * metal::float3x3 {};
|
||||
metal::float3 mul_vector0_ = metal::float4x3 {} * metal::float4(1.0);
|
||||
metal::float4 mul_vector1_ = metal::float3(2.0) * metal::float4x3 {};
|
||||
metal::float3x3 mul = metal::float4x3 {} * metal::float3x4 {};
|
||||
int _e175 = prevent_const_eval;
|
||||
wgpu_7437_ = as_type<int>(as_type<uint>(_e175) + as_type<uint>((-2147483647 - 1)));
|
||||
metal::float3x3 mul = metal::float3x3(metal::float3(0.0, 0.0, 0.0), metal::float3(0.0, 0.0, 0.0), metal::float3(0.0, 0.0, 0.0));
|
||||
int _e205 = prevent_const_eval;
|
||||
wgpu_7437_ = as_type<int>(as_type<uint>(_e205) + as_type<uint>((-2147483647 - 1)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -196,15 +196,15 @@ fn arithmetic() {
|
||||
let rem4_1 = (vec2(2f) % vec2(1f));
|
||||
let rem5_1 = (vec2(2f) % vec2(1f));
|
||||
}
|
||||
let add = (mat3x3<f32>() + mat3x3<f32>());
|
||||
let sub = (mat3x3<f32>() - mat3x3<f32>());
|
||||
let add = mat3x3<f32>(vec3<f32>(0f, 0f, 0f), vec3<f32>(0f, 0f, 0f), vec3<f32>(0f, 0f, 0f));
|
||||
let sub = mat3x3<f32>(vec3<f32>(0f, 0f, 0f), vec3<f32>(0f, 0f, 0f), vec3<f32>(0f, 0f, 0f));
|
||||
let mul_scalar0_ = (mat3x3<f32>() * 1f);
|
||||
let mul_scalar1_ = (2f * mat3x3<f32>());
|
||||
let mul_vector0_ = (mat4x3<f32>() * vec4(1f));
|
||||
let mul_vector1_ = (vec3(2f) * mat4x3<f32>());
|
||||
let mul = (mat4x3<f32>() * mat3x4<f32>());
|
||||
let _e175 = prevent_const_eval;
|
||||
wgpu_7437_ = (_e175 + i32(-2147483648));
|
||||
let mul = mat3x3<f32>(vec3<f32>(0f, 0f, 0f), vec3<f32>(0f, 0f, 0f), vec3<f32>(0f, 0f, 0f));
|
||||
let _e205 = prevent_const_eval;
|
||||
wgpu_7437_ = (_e205 + i32(-2147483648));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user