mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 15:31:03 +01:00
fix(naga): avoid vector splat construction from invalid scalar type (#8829)
This commit is contained in:
1 parent
0cd51d20f3
commit
cb02f74aa4
12 files changed
+56
-14
No files matched your search
@@ -65,6 +65,7 @@ Bottom level categories:
|
||||
#### naga
|
||||
|
||||
- Reject zero-value construction of a runtime-sized array with a validation error. Previously it would crash in the HLSL backend. By @mooori in [#8741](https://github.com/gfx-rs/wgpu/pull/8741).
|
||||
- Reject splat vector construction if the argument type does not match the type of the vector's scalar. Previously it would succeed. By @mooori in [#8829](https://github.com/gfx-rs/wgpu/pull/8829).
|
||||
|
||||
### Documentation
|
||||
|
||||
|
||||
+2
-1
@@ -247,12 +247,13 @@ webgpu:shader,validation,expression,binary,short_circuiting_and_or:invalid_types
|
||||
webgpu:shader,validation,expression,binary,short_circuiting_and_or:scalar_vector:op="%26%26";lhs="bool";rhs="bool"
|
||||
webgpu:shader,validation,expression,call,builtin,all:arguments:test="ptr_deref"
|
||||
webgpu:shader,validation,expression,call,builtin,max:values:*
|
||||
// FAIL: others in `value_constructor` due to #8815, #8442, #4720, possibly more
|
||||
// FAIL: others in `value_constructor` due to https://github.com/gfx-rs/wgpu/issues/4720, possibly more
|
||||
webgpu:shader,validation,expression,call,builtin,value_constructor:array_value:*
|
||||
webgpu:shader,validation,expression,call,builtin,value_constructor:matrix_zero_value:*
|
||||
webgpu:shader,validation,expression,call,builtin,value_constructor:scalar_zero_value:*
|
||||
webgpu:shader,validation,expression,call,builtin,value_constructor:scalar_value:*
|
||||
webgpu:shader,validation,expression,call,builtin,value_constructor:struct_value:*
|
||||
webgpu:shader,validation,expression,call,builtin,value_constructor:vector_splat:*
|
||||
webgpu:shader,validation,expression,call,builtin,value_constructor:vector_zero_value:*
|
||||
// NOTE: This is supposed to be an exhaustive listing underneath
|
||||
// `webgpu:shader,validation,expression,call,builtin,workgroupUniformLoad:*`, so exceptions can be
|
||||
|
||||
@@ -7,7 +7,7 @@ use alloc::{
|
||||
};
|
||||
use core::num::NonZeroU32;
|
||||
|
||||
use crate::common::wgsl::TypeContext;
|
||||
use crate::common::wgsl::{TryToWgsl, TypeContext};
|
||||
use crate::front::wgsl::lower::{ExpressionContext, Lowerer};
|
||||
use crate::front::wgsl::parse::ast;
|
||||
use crate::front::wgsl::{Error, Result};
|
||||
@@ -315,14 +315,33 @@ impl<'source> Lowerer<'source, '_> {
|
||||
(
|
||||
Components::One {
|
||||
mut component,
|
||||
ty_inner: &crate::TypeInner::Scalar(_),
|
||||
..
|
||||
ty_inner: &crate::TypeInner::Scalar(component_scalar),
|
||||
span,
|
||||
},
|
||||
Constructor::Type((_, &crate::TypeInner::Vector { size, scalar })),
|
||||
Constructor::Type((
|
||||
type_handle,
|
||||
&crate::TypeInner::Vector {
|
||||
size,
|
||||
scalar: vec_scalar,
|
||||
},
|
||||
)),
|
||||
) => {
|
||||
// Splat only allows automatic conversions of the component's scalar.
|
||||
if !component_scalar.automatically_converts_to(vec_scalar) {
|
||||
let component_ty = &ctx.typifier()[component];
|
||||
let arg_ty = ctx.type_resolution_to_string(component_ty);
|
||||
return Err(Box::new(Error::WrongArgumentType {
|
||||
function: ctx.type_to_string(type_handle),
|
||||
call_span: ty_span,
|
||||
arg_span: span,
|
||||
arg_index: 0,
|
||||
arg_ty,
|
||||
allowed: vec![vec_scalar.to_wgsl_for_diagnostics()],
|
||||
}));
|
||||
}
|
||||
ctx.convert_slice_to_common_leaf_scalar(
|
||||
core::slice::from_mut(&mut component),
|
||||
scalar,
|
||||
vec_scalar,
|
||||
)?;
|
||||
expr = crate::Expression::Splat {
|
||||
size,
|
||||
|
||||
@@ -58,5 +58,5 @@ fn render_vertex(
|
||||
v_in: VertexInput,
|
||||
) -> VertexOutput
|
||||
{
|
||||
return VertexOutput(vec4f(v_in.v_uint8));
|
||||
return VertexOutput(vec4f(v_in.v_float32));
|
||||
}
|
||||
@@ -58,5 +58,5 @@ fn render_vertex(
|
||||
v_in: VertexInput,
|
||||
) -> VertexOutput
|
||||
{
|
||||
return VertexOutput(vec4f(v_in.v_uint8.x));
|
||||
return VertexOutput(vec4f(v_in.v_float32.x));
|
||||
}
|
||||
@@ -58,5 +58,5 @@ fn render_vertex(
|
||||
v_in: VertexInput,
|
||||
) -> VertexOutput
|
||||
{
|
||||
return VertexOutput(vec4f(v_in.v_uint8.x));
|
||||
return VertexOutput(vec4f(v_in.v_float32.x));
|
||||
}
|
||||
@@ -58,5 +58,5 @@ fn render_vertex(
|
||||
v_in: VertexInput,
|
||||
) -> VertexOutput
|
||||
{
|
||||
return VertexOutput(vec4f(v_in.v_uint8.x));
|
||||
return VertexOutput(vec4f(v_in.v_float32.x));
|
||||
}
|
||||
@@ -366,6 +366,27 @@ fn vector_constructor_incorrect_component_count() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_constructor_type_mismatch() {
|
||||
check(
|
||||
r#"
|
||||
fn x(a: u32) -> vec2f {
|
||||
return vec2f(a);
|
||||
}
|
||||
"#,
|
||||
r#"error: wrong type passed as argument #1 to `vec2<f32>`
|
||||
┌─ wgsl:3:24
|
||||
│
|
||||
3 │ return vec2f(a);
|
||||
│ ^^^^^ ^ argument #1 has type `u32`
|
||||
│
|
||||
= note: `vec2<f32>` accepts the following types for argument #1:
|
||||
= note: allowed type: f32
|
||||
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_texture_sample_type() {
|
||||
check(
|
||||
|
||||
@@ -302,6 +302,6 @@ vertex render_vertexOutput render_vertex(
|
||||
v_unorm8x4_bgra = unpackUnorm8x4Bgra(vb_1_elem.data[640], vb_1_elem.data[641], vb_1_elem.data[642], vb_1_elem.data[643]).x;
|
||||
}
|
||||
const VertexInput v_in = { v_uint8_, v_uint8x2_, v_uint8x4_, v_sint8_, v_sint8x2_, v_sint8x4_, v_unorm8_, v_unorm8x2_, v_unorm8x4_, v_snorm8_, v_snorm8x2_, v_snorm8x4_, v_uint16_, v_uint16x2_, v_uint16x4_, v_sint16_, v_sint16x2_, v_sint16x4_, v_unorm16_, v_unorm16x2_, v_unorm16x4_, v_snorm16_, v_snorm16x2_, v_snorm16x4_, v_float16_, v_float16x2_, v_float16x4_, v_float32_, v_float32x2_, v_float32x3_, v_float32x4_, v_uint32_, v_uint32x2_, v_uint32x3_, v_uint32x4_, v_sint32_, v_sint32x2_, v_sint32x3_, v_sint32x4_, v_unorm10_10_10_2_, v_unorm8x4_bgra };
|
||||
const auto _tmp = VertexOutput {metal::float4(static_cast<float>(v_in.v_uint8_))};
|
||||
const auto _tmp = VertexOutput {metal::float4(v_in.v_float32_)};
|
||||
return render_vertexOutput { _tmp.position };
|
||||
}
|
||||
@@ -302,6 +302,6 @@ vertex render_vertexOutput render_vertex(
|
||||
v_unorm8x4_bgra = unpackUnorm8x4Bgra(vb_1_elem.data[640], vb_1_elem.data[641], vb_1_elem.data[642], vb_1_elem.data[643]).xy;
|
||||
}
|
||||
const VertexInput v_in = { v_uint8_, v_uint8x2_, v_uint8x4_, v_sint8_, v_sint8x2_, v_sint8x4_, v_unorm8_, v_unorm8x2_, v_unorm8x4_, v_snorm8_, v_snorm8x2_, v_snorm8x4_, v_uint16_, v_uint16x2_, v_uint16x4_, v_sint16_, v_sint16x2_, v_sint16x4_, v_unorm16_, v_unorm16x2_, v_unorm16x4_, v_snorm16_, v_snorm16x2_, v_snorm16x4_, v_float16_, v_float16x2_, v_float16x4_, v_float32_, v_float32x2_, v_float32x3_, v_float32x4_, v_uint32_, v_uint32x2_, v_uint32x3_, v_uint32x4_, v_sint32_, v_sint32x2_, v_sint32x3_, v_sint32x4_, v_unorm10_10_10_2_, v_unorm8x4_bgra };
|
||||
const auto _tmp = VertexOutput {metal::float4(static_cast<float>(v_in.v_uint8_.x))};
|
||||
const auto _tmp = VertexOutput {metal::float4(v_in.v_float32_.x)};
|
||||
return render_vertexOutput { _tmp.position };
|
||||
}
|
||||
@@ -311,6 +311,6 @@ vertex render_vertexOutput render_vertex(
|
||||
v_unorm8x4_bgra = unpackUnorm8x4Bgra(vb_1_elem.data[640], vb_1_elem.data[641], vb_1_elem.data[642], vb_1_elem.data[643]).xyz;
|
||||
}
|
||||
const VertexInput v_in = { v_uint8_, v_uint8x2_, v_uint8x4_, v_sint8_, v_sint8x2_, v_sint8x4_, v_unorm8_, v_unorm8x2_, v_unorm8x4_, v_snorm8_, v_snorm8x2_, v_snorm8x4_, v_uint16_, v_uint16x2_, v_uint16x4_, v_sint16_, v_sint16x2_, v_sint16x4_, v_unorm16_, v_unorm16x2_, v_unorm16x4_, v_snorm16_, v_snorm16x2_, v_snorm16x4_, v_float16_, v_float16x2_, v_float16x4_, v_float32_, v_float32x2_, v_float32x3_, v_float32x4_, v_uint32_, v_uint32x2_, v_uint32x3_, v_uint32x4_, v_sint32_, v_sint32x2_, v_sint32x3_, v_sint32x4_, v_unorm10_10_10_2_, v_unorm8x4_bgra };
|
||||
const auto _tmp = VertexOutput {metal::float4(static_cast<float>(v_in.v_uint8_.x))};
|
||||
const auto _tmp = VertexOutput {metal::float4(v_in.v_float32_.x)};
|
||||
return render_vertexOutput { _tmp.position };
|
||||
}
|
||||
@@ -300,6 +300,6 @@ vertex render_vertexOutput render_vertex(
|
||||
v_unorm8x4_bgra = unpackUnorm8x4Bgra(vb_1_elem.data[640], vb_1_elem.data[641], vb_1_elem.data[642], vb_1_elem.data[643]);
|
||||
}
|
||||
const VertexInput v_in = { v_uint8_, v_uint8x2_, v_uint8x4_, v_sint8_, v_sint8x2_, v_sint8x4_, v_unorm8_, v_unorm8x2_, v_unorm8x4_, v_snorm8_, v_snorm8x2_, v_snorm8x4_, v_uint16_, v_uint16x2_, v_uint16x4_, v_sint16_, v_sint16x2_, v_sint16x4_, v_unorm16_, v_unorm16x2_, v_unorm16x4_, v_snorm16_, v_snorm16x2_, v_snorm16x4_, v_float16_, v_float16x2_, v_float16x4_, v_float32_, v_float32x2_, v_float32x3_, v_float32x4_, v_uint32_, v_uint32x2_, v_uint32x3_, v_uint32x4_, v_sint32_, v_sint32x2_, v_sint32x3_, v_sint32x4_, v_unorm10_10_10_2_, v_unorm8x4_bgra };
|
||||
const auto _tmp = VertexOutput {metal::float4(static_cast<float>(v_in.v_uint8_.x))};
|
||||
const auto _tmp = VertexOutput {metal::float4(v_in.v_float32_.x)};
|
||||
return render_vertexOutput { _tmp.position };
|
||||
}
|
||||
Reference in new issue
Block a user