mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-25 08:51:05 +01:00
validate variable initializer for address spaces (#2513)
This commit is contained in:
1 parent
a17a93ef8f
commit
f72489be00
2 files changed
+24
No files matched your search
@@ -33,6 +33,8 @@ pub enum GlobalVariableError {
|
||||
),
|
||||
#[error("Initializer doesn't match the variable type")]
|
||||
InitializerType,
|
||||
#[error("Initializer can't be used with address space {0:?}")]
|
||||
InitializerNotAllowed(crate::AddressSpace),
|
||||
#[error("Storage address space doesn't support write-only access")]
|
||||
StorageAddressSpaceWriteOnlyNotSupported,
|
||||
}
|
||||
@@ -572,6 +574,13 @@ impl super::Validator {
|
||||
}
|
||||
|
||||
if let Some(init) = var.init {
|
||||
match var.space {
|
||||
crate::AddressSpace::Private | crate::AddressSpace::Function => {}
|
||||
_ => {
|
||||
return Err(GlobalVariableError::InitializerNotAllowed(var.space));
|
||||
}
|
||||
}
|
||||
|
||||
let decl_ty = &gctx.types[var.ty].inner;
|
||||
let init_ty = mod_info[init].inner_with(gctx.types);
|
||||
if !decl_ty.equivalent(init_ty, gctx.types) {
|
||||
|
||||
@@ -1606,6 +1606,21 @@ fn host_shareable_types() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn var_init() {
|
||||
check_validation! {
|
||||
"
|
||||
var<workgroup> initialized: u32 = 0u;
|
||||
":
|
||||
Err(
|
||||
naga::valid::ValidationError::GlobalVariable {
|
||||
source: naga::valid::GlobalVariableError::InitializerNotAllowed(naga::AddressSpace::WorkGroup),
|
||||
..
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn misplaced_break_if() {
|
||||
check(
|
||||
|
||||
Reference in new issue
Block a user