Skip to content

Commit

Permalink
Require that Function and Private variables be CONSTRUCTIBLE.
Browse files Browse the repository at this point in the history
Change the validator to enforce WGSL's requirement that all variables
in the `function` and `private` address spaces must have constructible
types.

Mark the `RayQuery` type as `CONSTRUCTIBLE`, since it is intended to
be used for local variables.

Add a regression test.
  • Loading branch information
jimblandy authored and teoxoy committed Oct 9, 2023
1 parent fa0fed1 commit fe484b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,10 +948,7 @@ impl super::Validator {
.types
.get(var.ty.index())
.ok_or(LocalVariableError::InvalidType(var.ty))?;
if !type_info
.flags
.contains(super::TypeFlags::DATA | super::TypeFlags::SIZED)
{
if !type_info.flags.contains(super::TypeFlags::CONSTRUCTIBLE) {
return Err(LocalVariableError::InvalidType(var.ty));
}

Expand Down
5 changes: 2 additions & 3 deletions src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,8 @@ impl super::Validator {

(TypeFlags::empty(), true)
}
crate::AddressSpace::Private | crate::AddressSpace::WorkGroup => {
(TypeFlags::DATA | TypeFlags::SIZED, false)
}
crate::AddressSpace::Private => (TypeFlags::CONSTRUCTIBLE, false),
crate::AddressSpace::WorkGroup => (TypeFlags::DATA | TypeFlags::SIZED, false),
crate::AddressSpace::PushConstant => {
if !self.capabilities.contains(Capabilities::PUSH_CONSTANT) {
return Err(GlobalVariableError::UnsupportedCapability(
Expand Down
5 changes: 4 additions & 1 deletion src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,10 @@ impl super::Validator {
}
Ti::RayQuery => {
self.require_type_capability(Capabilities::RAY_QUERY)?;
TypeInfo::new(TypeFlags::DATA | TypeFlags::SIZED, Alignment::ONE)
TypeInfo::new(
TypeFlags::DATA | TypeFlags::CONSTRUCTIBLE | TypeFlags::SIZED,
Alignment::ONE,
)
}
Ti::BindingArray { base, size } => {
if base >= handle {
Expand Down
17 changes: 17 additions & 0 deletions tests/wgsl-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,23 @@ fn invalid_local_vars() {
})
if local_var_name == "not_okay"
}

check_validation! {
"
fn f() {
var x: atomic<u32>;
}
":
Err(naga::valid::ValidationError::Function {
source: naga::valid::FunctionError::LocalVariable {
name: local_var_name,
source: naga::valid::LocalVariableError::InvalidType(_),
..
},
..
})
if local_var_name == "x"
}
}

#[test]
Expand Down

0 comments on commit fe484b3

Please sign in to comment.