From 807accd7ded15dd8589c93f5f42c5a0076b0f728 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 13 Sep 2021 15:34:33 -0400 Subject: [PATCH] wgsl-in: require storage class to be given --- src/back/wgsl/writer.rs | 12 +++++++++--- src/front/wgsl/mod.rs | 19 +------------------ tests/in/skybox.wgsl | 2 +- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/back/wgsl/writer.rs b/src/back/wgsl/writer.rs index 1406d1a29..07e4bed05 100644 --- a/src/back/wgsl/writer.rs +++ b/src/back/wgsl/writer.rs @@ -1035,9 +1035,15 @@ impl Writer { // operator necessary to correct that. let plain = plain_form_indirection(expr, module, func_ctx); let opened_paren = match (requested, plain) { - (Indirection::Ordinary, Indirection::Reference) => { write!(self.out, "&")?; false }, - (Indirection::Reference, Indirection::Ordinary) => { write!(self.out, "(*")?; true }, - (_, _) => { false }, + (Indirection::Ordinary, Indirection::Reference) => { + write!(self.out, "&")?; + false + } + (Indirection::Reference, Indirection::Ordinary) => { + write!(self.out, "(*")?; + true + } + (_, _) => false, }; let expression = &func_ctx.expressions[expr]; diff --git a/src/front/wgsl/mod.rs b/src/front/wgsl/mod.rs index 84018f534..b4eeeaac8 100644 --- a/src/front/wgsl/mod.rs +++ b/src/front/wgsl/mod.rs @@ -3850,27 +3850,10 @@ impl Parser { (Token::Word("var"), _) => { let pvar = self.parse_variable_decl(lexer, &mut module.types, &mut module.constants)?; - let class = match pvar.class { - Some(c) => c, - None => match module.types[pvar.ty].inner { - crate::TypeInner::Struct { .. } if binding.is_some() => { - crate::StorageClass::Uniform - } - crate::TypeInner::Array { .. } if binding.is_some() => { - crate::StorageClass::Storage { - access: crate::StorageAccess::LOAD, - } - } - crate::TypeInner::Image { .. } | crate::TypeInner::Sampler { .. } => { - crate::StorageClass::Handle - } - _ => crate::StorageClass::Private, - }, - }; let var_handle = module.global_variables.append( crate::GlobalVariable { name: Some(pvar.name.to_owned()), - class, + class: pvar.class.unwrap_or(crate::StorageClass::Handle), binding: binding.take(), ty: pvar.ty, init: pvar.init, diff --git a/tests/in/skybox.wgsl b/tests/in/skybox.wgsl index 0c00ebf72..33a110840 100644 --- a/tests/in/skybox.wgsl +++ b/tests/in/skybox.wgsl @@ -9,7 +9,7 @@ struct Data { view: mat4x4; }; [[group(0), binding(0)]] -var r_data: Data; +var r_data: Data; [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {