diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 466df7a..2cfdb2c 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -122,34 +122,15 @@ pub fn find_memorytype_index( memory_prop: &vk::PhysicalDeviceMemoryProperties, flags: vk::MemoryPropertyFlags, ) -> Option { - // Try to find an exactly matching memory flag - let best_suitable_index = - find_memorytype_index_f(memory_req, memory_prop, flags, |property_flags, flags| { - property_flags == flags - }); - if best_suitable_index.is_some() { - return best_suitable_index; - } - // Otherwise find a memory flag that works - find_memorytype_index_f(memory_req, memory_prop, flags, |property_flags, flags| { - property_flags & flags == flags - }) -} - -pub fn find_memorytype_index_f bool>( - memory_req: &vk::MemoryRequirements, - memory_prop: &vk::PhysicalDeviceMemoryProperties, - flags: vk::MemoryPropertyFlags, - f: F, -) -> Option { - let mut memory_type_bits = memory_req.memory_type_bits; - for (index, ref memory_type) in memory_prop.memory_types.iter().enumerate() { - if memory_type_bits & 1 == 1 && f(memory_type.property_flags, flags) { - return Some(index as u32); - } - memory_type_bits >>= 1; - } - None + memory_prop + .memory_types + .iter() + .enumerate() + .find(|(index, memory_type)| { + (1 << index) & memory_req.memory_type_bits != 0 + && memory_type.property_flags & flags == flags + }) + .map(|(index, _memory_type)| index as _) } pub struct ExampleBase {