Require that Function and Private variables be CONSTRUCTIBLE.

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.
This commit is contained in:
Jim Blandy authored and Teodor Tanasoaia committed 2023-10-09 12:27:05 +02:00
1 parent fa0fed100e
commit fe484b3a1b
4 files changed
+24 -8

No files matched your search

+1 -4
View File
@@ -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));
}
+2 -3
View File
@@ -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(
+4 -1
View File
@@ -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 {
+17
View File
@@ -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]