diff --git a/src/front/spv/function.rs b/src/front/spv/function.rs index 387b472909..75ca695882 100644 --- a/src/front/spv/function.rs +++ b/src/front/spv/function.rs @@ -136,7 +136,7 @@ impl> super::Parser { let mut flow_graph = FlowGraph::new(); let mut function_info = FunctionInfo { - parameters_sampling: vec![None; fun.arguments.len()], + parameters_sampling: vec![super::image::SamplingFlags::empty(); fun.arguments.len()], }; // Scan the blocks and add them as nodes diff --git a/src/front/spv/image.rs b/src/front/spv/image.rs index bd952edaf4..a4b1c9fbd7 100644 --- a/src/front/spv/image.rs +++ b/src/front/spv/image.rs @@ -456,8 +456,7 @@ impl> super::Parser { global_arena[handle].ty } crate::Expression::FunctionArgument(i) => { - let flags = function_info.parameters_sampling[i as usize] - .get_or_insert(SamplingFlags::empty()); + let flags = &mut function_info.parameters_sampling[i as usize]; *flags |= sampling_bit; arguments[i as usize].ty @@ -469,8 +468,7 @@ impl> super::Parser { *self.handle_sampling.get_mut(&handle).unwrap() |= sampling_bit } crate::Expression::FunctionArgument(i) => { - let flags = function_info.parameters_sampling[i as usize] - .get_or_insert(SamplingFlags::empty()); + let flags = &mut function_info.parameters_sampling[i as usize]; *flags |= sampling_bit; } ref other => return Err(Error::InvalidGlobalVar(other.clone())), diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 9dad738ad2..d03ea8b33a 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -372,7 +372,7 @@ impl Default for Options { } struct FunctionInfo { - parameters_sampling: Vec>, + parameters_sampling: Vec, } pub struct Parser { @@ -2314,24 +2314,29 @@ impl> Parser { for (i, arg) in arguments.iter().enumerate() { let callee_info = &self.function_info[handle.index()]; - if let Some(flags) = callee_info.parameters_sampling.get(i).and_then(|e| *e) - { - match expressions[*arg] { - crate::Expression::GlobalVariable(handle) => { - *self.handle_sampling.get_mut(&handle).unwrap() |= flags + let flags = match callee_info.parameters_sampling.get(i) { + Some(&flags) => flags, + _ => continue, + }; + + if flags.is_empty() { + continue; + } + + match expressions[*arg] { + crate::Expression::GlobalVariable(handle) => { + if let Some(sampling) = self.handle_sampling.get_mut(&handle) { + *sampling |= flags } - crate::Expression::FunctionArgument(i) => { - if let Some(handle) = function { - let function_info = - self.function_info.get_mut(handle.index()).unwrap(); - let caller_flags = function_info.parameters_sampling - [i as usize] - .get_or_insert(image::SamplingFlags::empty()); - *caller_flags |= flags; - } - } - ref other => return Err(Error::InvalidGlobalVar(other.clone())), } + crate::Expression::FunctionArgument(i) => { + if let Some(handle) = function { + let function_info = + self.function_info.get_mut(handle.index()).unwrap(); + function_info.parameters_sampling[i as usize] |= flags; + } + } + ref other => return Err(Error::InvalidGlobalVar(other.clone())), } } diff --git a/src/valid/analyzer.rs b/src/valid/analyzer.rs index 2d68d322f3..2655736cb2 100644 --- a/src/valid/analyzer.rs +++ b/src/valid/analyzer.rs @@ -168,11 +168,11 @@ enum GlobalOrArgument { } impl crate::Expression { - fn to_global_or_argument(&self) -> Option { - Some(match *self { + fn to_global_or_argument(&self) -> Result { + Ok(match *self { crate::Expression::GlobalVariable(var) => GlobalOrArgument::Global(var), crate::Expression::FunctionArgument(i) => GlobalOrArgument::Argument(i), - _ => return None, + _ => return Err(ExpressionError::ExpectedGlobalOrArgument), }) } } @@ -315,12 +315,9 @@ impl FunctionInfo { GlobalOrArgument::Global(var) => GlobalOrArgument::Global(var), GlobalOrArgument::Argument(i) => { let handle = arguments[i as usize]; - expression_arena[handle].to_global_or_argument().ok_or( - FunctionError::Expression { - handle, - error: ExpressionError::ExpectedGlobalOrArgument, - }, - )? + expression_arena[handle] + .to_global_or_argument() + .map_err(|error| FunctionError::Expression { handle, error })? } }; @@ -328,12 +325,9 @@ impl FunctionInfo { GlobalOrArgument::Global(var) => GlobalOrArgument::Global(var), GlobalOrArgument::Argument(i) => { let handle = arguments[i as usize]; - expression_arena[handle].to_global_or_argument().ok_or( - FunctionError::Expression { - handle, - error: ExpressionError::ExpectedGlobalOrArgument, - }, - )? + expression_arena[handle] + .to_global_or_argument() + .map_err(|error| FunctionError::Expression { handle, error })? } }; @@ -466,24 +460,14 @@ impl FunctionInfo { level, depth_ref, } => { - let image_storage = expression_arena[image] - .to_global_or_argument() - .ok_or(ExpressionError::ExpectedGlobalOrArgument)?; - let sampler_storage = expression_arena[sampler] - .to_global_or_argument() - .ok_or(ExpressionError::ExpectedGlobalOrArgument)?; + let image_storage = expression_arena[image].to_global_or_argument()?; + let sampler_storage = expression_arena[sampler].to_global_or_argument()?; match (image_storage, sampler_storage) { (GlobalOrArgument::Global(image), GlobalOrArgument::Global(sampler)) => { self.sampling_set.insert(SamplingKey { image, sampler }); } - (GlobalOrArgument::Argument(_), _) => { - self.sampling.insert(Sampling { - image: image_storage, - sampler: sampler_storage, - }); - } - (_, GlobalOrArgument::Argument(_)) => { + _ => { self.sampling.insert(Sampling { image: image_storage, sampler: sampler_storage,