From 80ab3a829ea209a4b30e898cdae830f505081f13 Mon Sep 17 00:00:00 2001 From: Aspen Date: Fri, 15 Sep 2023 13:22:55 -0700 Subject: [PATCH] Add interface entry for color index, check during overlap testing (#2333) --- vulkano/src/shader/mod.rs | 4 ++++ vulkano/src/shader/reflect.rs | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/vulkano/src/shader/mod.rs b/vulkano/src/shader/mod.rs index 71dfa88ffa..a18ee0080e 100644 --- a/vulkano/src/shader/mod.rs +++ b/vulkano/src/shader/mod.rs @@ -1314,6 +1314,10 @@ pub struct ShaderInterfaceEntry { /// The location slot that the variable starts at. pub location: u32, + /// The index within the location slot that the variable is located. + /// Only meaningful for fragment outputs. + pub index: u32, + /// The component slot that the variable starts at. Must be in the range 0..=3. pub component: u32, diff --git a/vulkano/src/shader/reflect.rs b/vulkano/src/shader/reflect.rs index d44e55ecb7..f0d65774e6 100644 --- a/vulkano/src/shader/reflect.rs +++ b/vulkano/src/shader/reflect.rs @@ -1197,12 +1197,23 @@ fn shader_interface( _ => None, }) .unwrap_or(0); + let index = id_info + .iter_decoration() + .find_map(|instruction| match *instruction { + Instruction::Decorate { + decoration: Decoration::Index { index }, + .. + } => Some(index), + _ => None, + }) + .unwrap_or(0); let ty = shader_interface_type_of(spirv, result_type_id, ignore_first_array); assert!(ty.num_elements >= 1); Some(ShaderInterfaceEntry { location, + index, component, ty, name, @@ -1213,11 +1224,12 @@ fn shader_interface( // Checking for overlapping elements. for (offset, element1) in elements.iter().enumerate() { for element2 in elements.iter().skip(offset + 1) { - if element1.location == element2.location - || (element1.location < element2.location - && element1.location + element1.ty.num_locations() > element2.location) - || (element2.location < element1.location - && element2.location + element2.ty.num_locations() > element1.location) + if element1.index == element2.index + && (element1.location == element2.location + || (element1.location < element2.location + && element1.location + element1.ty.num_locations() > element2.location) + || (element2.location < element1.location + && element2.location + element2.ty.num_locations() > element1.location)) { panic!( "The locations of attributes `{:?}` ({}..{}) and `{:?}` ({}..{}) overlap",