Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require new Capabilities::BINDING_ARRAY for binding_array type. #2505

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
jimblandy marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
1 change: 1 addition & 0 deletions src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/in/binding-buffer-arrays.param.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
god_mode: false,
god_mode: true,
spv: (
version: (1, 1),
binding_map: {
Expand Down
3 changes: 3 additions & 0 deletions tests/in/spv/binding-arrays.dynamic.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(
god_mode: true,
)
3 changes: 3 additions & 0 deletions tests/in/spv/binding-arrays.static.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(
god_mode: true,
)
35 changes: 23 additions & 12 deletions tests/wgsl-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -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.
Expand All @@ -893,20 +902,20 @@ macro_rules! check_validation {
}
}

fn validation_error(source: &str) -> Result<naga::valid::ModuleInfo, naga::valid::ValidationError> {
fn validation_error(
source: &str,
capabilities: naga::valid::Capabilities,
) -> Result<naga::valid::ModuleInfo, naga::valid::ValidationError> {
let module = match naga::front::wgsl::parse_str(source) {
Ok(module) => module,
Err(err) => {
eprintln!("WGSL parse failed:");
panic!("{}", err.emit_to_string(source));
}
};
naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
naga::valid::Capabilities::default(),
)
.validate(&module)
.map_err(|e| e.into_inner()) // TODO: Add tests for spans, too?
naga::valid::Validator::new(naga::valid::ValidationFlags::all(), capabilities)
.validate(&module)
.map_err(|e| e.into_inner()) // TODO: Add tests for spans, too?
}

#[test]
Expand Down Expand Up @@ -1939,8 +1948,10 @@ fn binding_array_private() {

#[test]
fn binding_array_non_struct() {
check_validation! {
"var<storage> x: binding_array<i32, 4>;":
use naga::valid::Capabilities;
check_one_validation_with_capabilities! {
Capabilities::default() | Capabilities::BINDING_ARRAY,
"var<storage> x: binding_array<i32, 4>;",
Err(naga::valid::ValidationError::Type {
source: naga::valid::TypeError::BindingArrayBaseTypeNotStruct(_),
..
Expand Down