mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 15:00:57 +01:00
fix(const_eval): handle non-vector Compose select args. (#10350)
Co-authored-by: Andy Leiserson <aleiserson@mozilla.com>
This commit is contained in:
1 parent
103a70e581
commit
b8bfc58e81
3 files changed
+86
-4
No files matched your search
@@ -222,6 +222,7 @@ By @sagudev in [#10109](https://github.com/gfx-rs/wgpu/pull/10109).
|
||||
- Reject `@location(…)`s in compute shaders. By @ErichDonGubler in [#10026](https://github.com/gfx-rs/wgpu/pull/10026).
|
||||
- Correctly emit primitive_index for the SPIR-V backend, handling mesh and raytracing shaders. Before, you could not use primitive_index with these shader types. An enable primitive_index statement is still required in wgsl shaders, in addition to enable wgpu_mesh_shader/enable wgpu_ray_tracing_pipeline. By @JMS55 in [#10153](https://github.com/gfx-rs/wgpu/pull/10153).
|
||||
- Prevent invalid IR from being generated when using a ray query in a loop. By @Vecvec in [#9945](https://github.com/gfx-rs/wgpu/pull/9945)
|
||||
- Raise a type error, rather than panic, for some cases of an invalid `select` argument type in WGSL constant evaluation. By @ErichDonGubler in [#10350](https://github.com/gfx-rs/wgpu/pull/10350).
|
||||
|
||||
#### DX12
|
||||
|
||||
|
||||
@@ -3740,13 +3740,17 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
},
|
||||
) => {
|
||||
let ty_deets = |ty| {
|
||||
let (size, scalar) = self.types[ty].inner.vector_size_and_scalar().unwrap();
|
||||
(size.unwrap(), scalar)
|
||||
self.types[ty]
|
||||
.inner
|
||||
.vector_size_and_scalar()
|
||||
.map(|(size, scalar)| {
|
||||
(size.expect("expected vector type, not scalar type"), scalar)
|
||||
})
|
||||
};
|
||||
|
||||
let expected_vec_size = {
|
||||
let [(reject_vec_size, _), (accept_vec_size, _)] =
|
||||
[reject_ty, accept_ty].map(ty_deets);
|
||||
[reject_ty, accept_ty].map(|ty| ty_deets(ty).unwrap());
|
||||
|
||||
if reject_vec_size != accept_vec_size {
|
||||
return Err(ConstantEvaluatorError::SelectVecRejectAcceptSizeMismatch {
|
||||
@@ -3765,7 +3769,10 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
ty: condition_ty,
|
||||
components: ref condition_components,
|
||||
} => {
|
||||
let (condition_vec_size, condition_scalar) = ty_deets(condition_ty);
|
||||
let Some((condition_vec_size, condition_scalar)) = ty_deets(condition_ty)
|
||||
else {
|
||||
return Err(ConstantEvaluatorError::SelectConditionNotAVecBool);
|
||||
};
|
||||
if condition_scalar.kind != ScalarKind::Bool {
|
||||
return Err(ConstantEvaluatorError::SelectConditionNotAVecBool);
|
||||
}
|
||||
|
||||
@@ -2784,6 +2784,80 @@ error: type mismatch for reject and accept values in `select` call
|
||||
│ │\x20\x20\x20\x20\x20\x20
|
||||
│ reject value of type `bool`
|
||||
|
||||
",
|
||||
),
|
||||
(
|
||||
"
|
||||
const cond: array<u32, 4> = array<u32, 4>();
|
||||
@compute @workgroup_size(1, 1)
|
||||
fn main() {
|
||||
// Bad: `cond` is an `array`, not a `bool` or a `vecN<bool>`.
|
||||
_ = select(vec4(0u), vec4(1u), cond);
|
||||
}
|
||||
",
|
||||
"\
|
||||
error: Expected boolean vector for condition arg., got something else
|
||||
┌─ wgsl:6:17
|
||||
│
|
||||
6 │ _ = select(vec4(0u), vec4(1u), cond);
|
||||
│ ^^^^^^ see msg
|
||||
|
||||
",
|
||||
),
|
||||
(
|
||||
"
|
||||
struct S { member: bool }
|
||||
const cond: S = S(true);
|
||||
@compute @workgroup_size(1, 1)
|
||||
fn main() {
|
||||
// Bad: `cond` is a `struct`, not a `bool` or a `vecN<bool>`.
|
||||
_ = select(vec2(0u), vec2(1u), cond);
|
||||
}
|
||||
",
|
||||
"\
|
||||
error: Expected boolean vector for condition arg., got something else
|
||||
┌─ wgsl:7:17
|
||||
│
|
||||
7 │ _ = select(vec2(0u), vec2(1u), cond);
|
||||
│ ^^^^^^ see msg
|
||||
|
||||
",
|
||||
),
|
||||
(
|
||||
"
|
||||
@compute @workgroup_size(1, 1)
|
||||
fn main() {
|
||||
// Bad: the condition is a matrix, not a `bool` or a `vecN<bool>`.
|
||||
_ = select(vec2(0.0f), vec2(1.0f), mat2x2f(1, 1, 1, 1));
|
||||
}
|
||||
",
|
||||
"\
|
||||
error: Expected boolean vector for condition arg., got something else
|
||||
┌─ wgsl:5:17
|
||||
│
|
||||
5 │ _ = select(vec2(0.0f), vec2(1.0f), mat2x2f(1, 1, 1, 1));
|
||||
│ ^^^^^^ see msg
|
||||
|
||||
",
|
||||
),
|
||||
(
|
||||
"
|
||||
const values: array<i32, 4> = array<i32, 4>(1, 2, 3, 4);
|
||||
@compute @workgroup_size(1, 1)
|
||||
fn main() {
|
||||
// Bad: `array` reject and accept values, even as const-expressions.
|
||||
_ = select(values, values, true);
|
||||
}
|
||||
",
|
||||
"\
|
||||
error: unexpected argument type for `select` call
|
||||
┌─ wgsl:6:24
|
||||
│
|
||||
6 │ _ = select(values, values, true);
|
||||
│ ^^^^^^ this value of type `array<i32, 4>`
|
||||
│
|
||||
= note: expected a scalar or a `vecN` of scalars
|
||||
|
||||
",
|
||||
),
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user