From 6233ba0bf0182f66f9be2069cdd9265e894c87f7 Mon Sep 17 00:00:00 2001 From: Rua Date: Wed, 9 Aug 2023 14:17:39 +0200 Subject: [PATCH] Fix #2203 --- vulkano-shaders/src/entry_point.rs | 7 +++++- vulkano/src/shader/reflect.rs | 38 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/vulkano-shaders/src/entry_point.rs b/vulkano-shaders/src/entry_point.rs index d3c02408d4..18b03a0301 100644 --- a/vulkano-shaders/src/entry_point.rs +++ b/vulkano-shaders/src/entry_point.rs @@ -299,6 +299,11 @@ fn write_interface(interface: &ShaderInterface) -> TokenStream { name, }| { let base_type = format_ident!("{}", format!("{:?}", base_type)); + let name = if let Some(name) = name { + quote! { ::std::option::Option::Some(::std::borrow::Cow::Borrowed(#name)) } + } else { + quote! { ::std::option::Option::None } + }; quote! { ::vulkano::shader::ShaderInterfaceEntry { @@ -310,7 +315,7 @@ fn write_interface(interface: &ShaderInterface) -> TokenStream { num_elements: #num_elements, is_64bit: #is_64bit, }, - name: ::std::option::Option::Some(::std::borrow::Cow::Borrowed(#name)), + name: #name, } } }, diff --git a/vulkano/src/shader/reflect.rs b/vulkano/src/shader/reflect.rs index f46e3014a5..9177694230 100644 --- a/vulkano/src/shader/reflect.rs +++ b/vulkano/src/shader/reflect.rs @@ -264,7 +264,7 @@ fn inspect_entry_point( chain: [fn(&Spirv, Id) -> Option; N], id: Id, ) -> Option<(&mut DescriptorBindingVariable, Option)> { - let id = chain + let mut id = chain .into_iter() .try_fold(id, |id, func| func(self.spirv, id))?; @@ -275,24 +275,24 @@ fn inspect_entry_point( return Some((variable, Some(0))); } - let (id, indexes) = match *self.spirv.id(id).instruction() { - Instruction::AccessChain { - base, ref indexes, .. - } => (base, indexes), - _ => return None, - }; - - if let Some(variable) = self.global.get(&id) { - // Variable was accessed with an access chain. - // Retrieve index from instruction if it's a constant value. - // TODO: handle a `None` index too? - let index = match *self.spirv.id(*indexes.first().unwrap()).instruction() { - Instruction::Constant { ref value, .. } => Some(value[0]), - _ => None, - }; - let variable = self.result.entry(id).or_insert_with(|| variable.clone()); - variable.reqs.stages = self.stage.into(); - return Some((variable, index)); + while let Instruction::AccessChain { + base, ref indexes, .. + } = *self.spirv.id(id).instruction() + { + id = base; + + if let Some(variable) = self.global.get(&id) { + // Variable was accessed with an access chain. + // Retrieve index from instruction if it's a constant value. + // TODO: handle a `None` index too? + let index = match *self.spirv.id(*indexes.first().unwrap()).instruction() { + Instruction::Constant { ref value, .. } => Some(value[0]), + _ => None, + }; + let variable = self.result.entry(id).or_insert_with(|| variable.clone()); + variable.reqs.stages = self.stage.into(); + return Some((variable, index)); + } } None