From e57d877dbc83b0517d33c0550b9ee07d2ac7e3f7 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 28 Sep 2020 01:40:35 -0400 Subject: [PATCH] [spv] fix storage buffer detection --- src/front/spv/mod.rs | 26 +++++++++++++++++--------- src/proc/validator.rs | 1 + 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index d88f6ec1d..3b42f1092 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -315,6 +315,7 @@ pub struct Parser { handle_sampling: FastHashMap, SamplingFlags>, lookup_type: FastHashMap, lookup_void_type: FastHashSet, + lookup_storage_buffer_types: FastHashSet>, // Lookup for samplers and sampled images, storing flags on how they are used. lookup_constant: FastHashMap, lookup_variable: FastHashMap, @@ -339,6 +340,7 @@ impl> Parser { lookup_member_type_id: FastHashMap::default(), lookup_type: FastHashMap::default(), lookup_void_type: FastHashSet::default(), + lookup_storage_buffer_types: FastHashSet::default(), lookup_constant: FastHashMap::default(), lookup_variable: FastHashMap::default(), lookup_expression: FastHashMap::default(), @@ -1964,11 +1966,12 @@ impl> Parser { inst.expect_at_least(2)?; let id = self.next()?; let parent_decor = self.future_decor.remove(&id); - if let Some(ref decor) = parent_decor { - if decor.block.is_some() { - // do nothing - } - } + let is_buffer_block = parent_decor + .as_ref() + .map_or(false, |decor| match decor.block { + Some(Block { buffer }) => buffer, + _ => false, + }); let mut members = Vec::with_capacity(inst.wc as usize - 2); let mut member_type_ids = Vec::with_capacity(members.capacity()); @@ -1993,6 +1996,9 @@ impl> Parser { inner, }); + if is_buffer_block { + self.lookup_storage_buffer_types.insert(ty_handle); + } for (i, type_id) in member_type_ids.into_iter().enumerate() { self.lookup_member_type_id .insert((ty_handle, i as u32), type_id); @@ -2225,7 +2231,7 @@ impl> Parser { inst.expect_at_least(4)?; let type_id = self.next()?; let id = self.next()?; - let storage = self.next()?; + let storage_class = self.next()?; if inst.wc != 4 { inst.expect(5)?; let _init = self.next()?; //TODO @@ -2235,7 +2241,7 @@ impl> Parser { .future_decor .remove(&id) .ok_or(Error::InvalidBinding(id))?; - let class = map_storage_class(storage)?; + let class = map_storage_class(storage_class)?; let binding = match (class, &module.types[lookup_type.handle].inner) { (crate::StorageClass::Input, &crate::TypeInner::Struct { .. }) | (crate::StorageClass::Output, &crate::TypeInner::Struct { .. }) => None, @@ -2243,8 +2249,10 @@ impl> Parser { }; let is_storage = match module.types[lookup_type.handle].inner { crate::TypeInner::Struct { .. } => match class { - crate::StorageClass::StorageBuffer | crate::StorageClass::Constant => true, // careful with `Constant` here! - _ => false, + crate::StorageClass::StorageBuffer => true, + _ => self + .lookup_storage_buffer_types + .contains(&lookup_type.handle), }, crate::TypeInner::Image { class: crate::ImageClass::Storage(_), diff --git a/src/proc/validator.rs b/src/proc/validator.rs index 694e23f84..cf6029d93 100644 --- a/src/proc/validator.rs +++ b/src/proc/validator.rs @@ -296,6 +296,7 @@ impl Validator { } }; if !allowed_usage.contains(usage) { + log::debug!("\tAllowed usage: {:?}", allowed_usage); return Err(EntryPointError::InvalidGlobalUsage(var_handle, usage)); }