Skip to content

Commit

Permalink
Require that Function variables have CONSTRUCTIBLE types.
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` address space 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 committed Oct 8, 2023
1 parent c671603 commit d038488
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 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: 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 d038488

Please sign in to comment.