Skip to content

Commit

Permalink
Fix #2203
Browse files Browse the repository at this point in the history
  • Loading branch information
Rua committed Aug 9, 2023
1 parent db0b02a commit 6233ba0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
7 changes: 6 additions & 1 deletion vulkano-shaders/src/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
},
Expand Down
38 changes: 19 additions & 19 deletions vulkano/src/shader/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn inspect_entry_point(
chain: [fn(&Spirv, Id) -> Option<Id>; N],
id: Id,
) -> Option<(&mut DescriptorBindingVariable, Option<u32>)> {
let id = chain
let mut id = chain
.into_iter()
.try_fold(id, |id, func| func(self.spirv, id))?;

Expand All @@ -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
Expand Down

0 comments on commit 6233ba0

Please sign in to comment.