From 451c5dd801c539aa6ef05ebd3a817fe80c00891c Mon Sep 17 00:00:00 2001 From: "Felipe A. Costa" Date: Wed, 16 Aug 2023 21:47:06 -0300 Subject: [PATCH] [spv-out] Fix intermediate access expression on buffer pointers Allows compilation of this kind of access: ``` struct OtherStruct { data: float, } struct MyBuffer { sub_buf: ptr } struct PushConstants { buf: ptr, } var pc: PushConstants; var d = (*(*pc.buf).sub_buf).data; ``` Before you would have to use intermediate variables: ``` var b = (*pc.buf); var d = (*b.sub_buf).data; ``` --- src/back/spv/block.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/back/spv/block.rs b/src/back/spv/block.rs index ca1fb2235b..53f6100b31 100644 --- a/src/back/spv/block.rs +++ b/src/back/spv/block.rs @@ -213,6 +213,22 @@ impl<'w> BlockContext<'w> { let arg = &self.ir_function.arguments[index as usize]; self.ir_module.types[arg.ty].inner.pointer_space().is_some() } + crate::Expression::Load { pointer } => { + match *self.fun_info[pointer].ty.inner_with(&self.ir_module.types) { + crate::TypeInner::Pointer { base, .. } => { + if let crate::TypeInner::Pointer { + space: crate::AddressSpace::PhysicalStorage { .. }, + .. + } = self.ir_module.types[base].inner + { + true + } else { + false + } + } + _ => false, + } + } // The chain rule: if this `Access...`'s `base` operand was // previously omitted, then omit this one, too.