mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 16:31:11 +01:00
fix(naga): Use wrapping arithmetic for dot on concrete ints (#9142)
This commit is contained in:
1 parent
68b26a65f6
commit
3dc03bc23f
3 files changed
+24
-2
No files matched your search
@@ -186,6 +186,7 @@ depth_stencil: Some(wgpu::DepthStencilState::stencil(
|
||||
- Fixed constant evaluation for `sign()` builtin to return zero when the argument is zero. By @mandryskowski in [#8942](https://github.com/gfx-rs/wgpu/pull/8942).
|
||||
- Allow array generation to compile with the macOS 10.12 Metal compiler. By @madsmtm in [#8953](https://github.com/gfx-rs/wgpu/pull/8953)
|
||||
- Naga now detects bitwise shifts by a constant exceeding the operand bit width at compile time, and disallows scalar-by-vector and vector-by-scalar shifts in constant evaluation. By @andyleiserson in [#8907](https://github.com/gfx-rs/wgpu/pull/8907).
|
||||
- Naga uses wrapping arithmetic when evaluating dot products on concrete integer types (`u32` and `i32`). By @BKDaugherty in [#9142](https://github.com/gfx-rs/wgpu/pull/9142).
|
||||
|
||||
#### Validation
|
||||
|
||||
|
||||
@@ -299,6 +299,15 @@ webgpu:api,validation,texture,rg11b10ufloat_renderable:*
|
||||
|
||||
webgpu:shader,execution,expression,call,builtin,atan2:f16:*
|
||||
webgpu:shader,execution,expression,call,builtin,atan2:f32:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:abstract_int_vec2:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:abstract_int_vec3:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:abstract_int_vec4:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:i32_vec2:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:i32_vec3:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:i32_vec4:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:u32_vec2:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:u32_vec3:*
|
||||
webgpu:shader,execution,expression,call,builtin,dot:u32_vec4:*
|
||||
//FAIL: webgpu:shader,execution,expression,call,builtin,select:*
|
||||
// - Fails with `const`/abstract int cases on all platforms because of <https://github.com/gfx-rs/wgpu/issues/4507>.
|
||||
// - Fails with `vec3` & `f16` cases on macOS because of <https://github.com/gfx-rs/wgpu/issues/5262>.
|
||||
|
||||
@@ -1718,7 +1718,7 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
return Err(ConstantEvaluatorError::InvalidMathArg);
|
||||
}
|
||||
|
||||
fn int_dot<P>(a: &[P], b: &[P]) -> Result<P, ConstantEvaluatorError>
|
||||
fn int_dot_checked<P>(a: &[P], b: &[P]) -> Result<P, ConstantEvaluatorError>
|
||||
where
|
||||
P: num_traits::PrimInt + num_traits::CheckedAdd + num_traits::CheckedMul,
|
||||
{
|
||||
@@ -1737,9 +1737,21 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
))
|
||||
}
|
||||
|
||||
fn int_dot_wrapping<P>(a: &[P], b: &[P]) -> P
|
||||
where
|
||||
P: num_traits::PrimInt + num_traits::WrappingAdd + num_traits::WrappingMul,
|
||||
{
|
||||
a.iter()
|
||||
.zip(b.iter())
|
||||
.map(|(&aa, bb)| aa.wrapping_mul(bb))
|
||||
.fold(P::zero(), |acc, x| acc.wrapping_add(&x))
|
||||
}
|
||||
|
||||
let result = match_literal_vector!(match (e1, e2) => Literal {
|
||||
Float => |e1, e2| { e1.iter().zip(e2.iter()).map(|(&aa, &bb)| aa * bb).sum() },
|
||||
Integer => |e1, e2| { int_dot(e1, e2)? },
|
||||
AbstractInt => |e1, e2 | { int_dot_checked(e1, e2)? },
|
||||
I32 => |e1, e2| { int_dot_wrapping(e1, e2) },
|
||||
U32 => |e1, e2| { int_dot_wrapping(e1, e2) },
|
||||
})?;
|
||||
self.register_evaluated_expr(Expression::Literal(result), span)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user