def _get_memory_type_index(self, memory_type_flags): memory_types = self.memory_info["memory_types"] for type_index, memory_type in enumerate(memory_types): memory_type_properties = hvk.MemoryPropertyFlag( memory_type.property_flags) for memory_type_flag in memory_type_flags: if hvk.MemoryPropertyFlag( memory_type_flag) in memory_type_properties: return type_index raise ValueError( f"No memory type matches the requested flags: {memory_type_flags}")
def find_memory_type(heap_flags, type_flags): F, type_flags = IntFlag, hvk.MemoryPropertyFlag(type_flags) props = hvk.physical_device_memory_properties(api, physical_device) types = props.memory_types[:props.memory_type_count] heaps = props.memory_heaps[:props.memory_heap_count] # Find the memory heap that satisfy heap_flags heap_indices = tuple(i for i, h in enumerate(heaps) if F(heap_flags) in F(h.flags)) if heap_indices is None: return # Find a memory type in the selected heaps that satisfy type_flags type_index = None for i, memory_type in enumerate(types): heap_matches = memory_type.heap_index in heap_indices type_flags_matches = type_flags in hvk.MemoryPropertyFlag( memory_type.property_flags) if heap_matches and type_flags_matches: type_index = i break return type_index