From bdbb8e5796d5a38343d55667bba52c3e419ba103 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 22 Sep 2023 15:48:49 -0700 Subject: [PATCH] Require new `Capabilities::BINDING_ARRAY` for `binding_array` type. Introduce a new `Capabilities::BINDING_ARRAY` flag, which enables use of the Naga `TypeInner::BindingArray` type. Adjust tests that exercise binding arrays to pass this flag. --- src/valid/mod.rs | 2 ++ src/valid/type.rs | 1 + tests/in/binding-buffer-arrays.param.ron | 2 +- tests/in/spv/binding-arrays.dynamic.param.ron | 3 ++ tests/in/spv/binding-arrays.static.param.ron | 3 ++ tests/wgsl-errors.rs | 35 ++++++++++++------- 6 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 tests/in/spv/binding-arrays.dynamic.param.ron create mode 100644 tests/in/spv/binding-arrays.static.param.ron diff --git a/src/valid/mod.rs b/src/valid/mod.rs index f99a2055ce..1b6ea03923 100644 --- a/src/valid/mod.rs +++ b/src/valid/mod.rs @@ -114,6 +114,8 @@ bitflags::bitflags! { const RAY_QUERY = 0x1000; /// Support for generating two sources for blending from fragement shaders const DUAL_SOURCE_BLENDING = 0x2000; + /// Support for binding arrays. + const BINDING_ARRAY = 0x4000; } } diff --git a/src/valid/type.rs b/src/valid/type.rs index f8ceb463c6..762a15c5a1 100644 --- a/src/valid/type.rs +++ b/src/valid/type.rs @@ -569,6 +569,7 @@ impl super::Validator { TypeInfo::new(TypeFlags::DATA | TypeFlags::SIZED, Alignment::ONE) } Ti::BindingArray { base, size } => { + self.require_type_capability(Capabilities::BINDING_ARRAY)?; if base >= handle { return Err(TypeError::InvalidArrayBaseType(base)); } diff --git a/tests/in/binding-buffer-arrays.param.ron b/tests/in/binding-buffer-arrays.param.ron index 4f653bb21b..12d5c55234 100644 --- a/tests/in/binding-buffer-arrays.param.ron +++ b/tests/in/binding-buffer-arrays.param.ron @@ -1,5 +1,5 @@ ( - god_mode: false, + god_mode: true, spv: ( version: (1, 1), binding_map: { diff --git a/tests/in/spv/binding-arrays.dynamic.param.ron b/tests/in/spv/binding-arrays.dynamic.param.ron new file mode 100644 index 0000000000..d91d0b135e --- /dev/null +++ b/tests/in/spv/binding-arrays.dynamic.param.ron @@ -0,0 +1,3 @@ +( + god_mode: true, +) diff --git a/tests/in/spv/binding-arrays.static.param.ron b/tests/in/spv/binding-arrays.static.param.ron new file mode 100644 index 0000000000..d91d0b135e --- /dev/null +++ b/tests/in/spv/binding-arrays.static.param.ron @@ -0,0 +1,3 @@ +( + god_mode: true, +) diff --git a/tests/wgsl-errors.rs b/tests/wgsl-errors.rs index 48318f2804..a098d7d568 100644 --- a/tests/wgsl-errors.rs +++ b/tests/wgsl-errors.rs @@ -853,10 +853,10 @@ fn matrix_with_bad_type() { /// Unless you are generating code programmatically, the /// `check_validation_error` macro will probably be more convenient to /// use. -macro_rules! check_one_validation { - ( $source:expr, $pattern:pat $( if $guard:expr )? ) => { +macro_rules! check_one_validation_with_capabilities { + ( $capabilities:expr, $source:expr, $pattern:pat $( if $guard:expr )? ) => { let source = $source; - let error = validation_error($source); + let error = validation_error($source, $capabilities); if ! matches!(&error, $pattern $( if $guard )? ) { eprintln!("validation error does not match pattern:\n\ source code: {}\n\ @@ -875,6 +875,15 @@ macro_rules! check_one_validation { } } +macro_rules! check_one_validation { + ( $source:expr, $pattern:pat $( if $guard:expr )? ) => { + check_one_validation_with_capabilities!( + naga::valid::Capabilities::default(), + $source, $pattern $( if $guard )? + ); + } +} + macro_rules! check_validation { // We want to support an optional guard expression after the pattern, so // that we can check values we can't match against, like strings. @@ -893,7 +902,10 @@ macro_rules! check_validation { } } -fn validation_error(source: &str) -> Result { +fn validation_error( + source: &str, + capabilities: naga::valid::Capabilities, +) -> Result { let module = match naga::front::wgsl::parse_str(source) { Ok(module) => module, Err(err) => { @@ -901,12 +913,9 @@ fn validation_error(source: &str) -> Result x: binding_array;": + use naga::valid::Capabilities; + check_one_validation_with_capabilities! { + Capabilities::default() | Capabilities::BINDING_ARRAY, + "var x: binding_array;", Err(naga::valid::ValidationError::Type { source: naga::valid::TypeError::BindingArrayBaseTypeNotStruct(_), ..