Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
Strip DATA out of binding arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Apr 16, 2023
1 parent 2508eab commit a067ea5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ tree.
clippy::match_like_matches_macro,
clippy::collapsible_if,
clippy::derive_partial_eq_without_eq,
clippy::needless_borrowed_reference
clippy::needless_borrowed_reference,
clippy::single_match
)]
#![warn(
trivial_casts,
Expand Down
52 changes: 24 additions & 28 deletions src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,11 @@ impl super::Validator {
use super::TypeFlags;

log::debug!("var {:?}", var);
let type_info = &self.types[var.ty.index()];
let inner_ty = match types[var.ty].inner {
crate::TypeInner::BindingArray { base, .. } => base,
_ => var.ty,
};
let type_info = &self.types[inner_ty.index()];

let (required_type_flags, is_resource) = match var.space {
crate::AddressSpace::Function => {
Expand Down Expand Up @@ -437,22 +441,8 @@ impl super::Validator {
)
}
crate::AddressSpace::Handle => {
match types[var.ty].inner {
crate::TypeInner::Image { .. }
| crate::TypeInner::Sampler { .. }
| crate::TypeInner::BindingArray { .. }
| crate::TypeInner::AccelerationStructure
| crate::TypeInner::RayQuery => {}
_ => {
return Err(GlobalVariableError::InvalidType(var.space));
}
};
let inner_ty = match &types[var.ty].inner {
&crate::TypeInner::BindingArray { base, .. } => &types[base].inner,
ty => ty,
};
if let crate::TypeInner::Image {
class:
match types[inner_ty].inner {
crate::TypeInner::Image { class, .. } => match class {
crate::ImageClass::Storage {
format:
crate::StorageFormat::R16Unorm
Expand All @@ -462,17 +452,23 @@ impl super::Validator {
| crate::StorageFormat::Rgba16Unorm
| crate::StorageFormat::Rgba16Snorm,
..
},
..
} = *inner_ty
{
if !self
.capabilities
.contains(Capabilities::STORAGE_TEXTURE_16BIT_NORM_FORMATS)
{
return Err(GlobalVariableError::UnsupportedCapability(
Capabilities::STORAGE_TEXTURE_16BIT_NORM_FORMATS,
));
} => {
if !self
.capabilities
.contains(Capabilities::STORAGE_TEXTURE_16BIT_NORM_FORMATS)
{
return Err(GlobalVariableError::UnsupportedCapability(
Capabilities::STORAGE_TEXTURE_16BIT_NORM_FORMATS,
));
}
}
_ => {}
},
crate::TypeInner::Sampler { .. }
| crate::TypeInner::AccelerationStructure
| crate::TypeInner::RayQuery => {}
_ => {
return Err(GlobalVariableError::InvalidType(var.space));
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,10 @@ impl super::Validator {
return Err(TypeError::UnresolvedBase(base));
}
let type_info_mask = match size {
crate::ArraySize::Constant(_) => {
TypeFlags::DATA | TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE
}
crate::ArraySize::Constant(_) => TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE,
crate::ArraySize::Dynamic => {
// Final type is non-sized
TypeFlags::DATA | TypeFlags::HOST_SHAREABLE
TypeFlags::HOST_SHAREABLE
}
};
let base_info = &self.types[base.index()];
Expand Down
8 changes: 8 additions & 0 deletions tests/wgsl-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,3 +1820,11 @@ fn function_returns_void() {
"###,
)
}

#[test]
fn binding_array_local() {
check_validation! {
"fn f() { var x: binding_array<i32, 4>; }":
Err(_)
}
}

0 comments on commit a067ea5

Please sign in to comment.