Simplify example memory selection (#329)
According to specs for Device Memory (section 10.2), memory types are topologically sorted by their property flags so the two-pass memory type selection is unnecessary. Co-authored-by: Steve Wooster <s.f.m.wooster@gmail.com>
This commit is contained in:
parent
ef8b5490c5
commit
61476184e0
1 changed files with 9 additions and 28 deletions
|
@ -122,34 +122,15 @@ pub fn find_memorytype_index(
|
||||||
memory_prop: &vk::PhysicalDeviceMemoryProperties,
|
memory_prop: &vk::PhysicalDeviceMemoryProperties,
|
||||||
flags: vk::MemoryPropertyFlags,
|
flags: vk::MemoryPropertyFlags,
|
||||||
) -> Option<u32> {
|
) -> Option<u32> {
|
||||||
// Try to find an exactly matching memory flag
|
memory_prop
|
||||||
let best_suitable_index =
|
.memory_types
|
||||||
find_memorytype_index_f(memory_req, memory_prop, flags, |property_flags, flags| {
|
.iter()
|
||||||
property_flags == flags
|
.enumerate()
|
||||||
});
|
.find(|(index, memory_type)| {
|
||||||
if best_suitable_index.is_some() {
|
(1 << index) & memory_req.memory_type_bits != 0
|
||||||
return best_suitable_index;
|
&& memory_type.property_flags & flags == flags
|
||||||
}
|
})
|
||||||
// Otherwise find a memory flag that works
|
.map(|(index, _memory_type)| index as _)
|
||||||
find_memorytype_index_f(memory_req, memory_prop, flags, |property_flags, flags| {
|
|
||||||
property_flags & flags == flags
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn find_memorytype_index_f<F: Fn(vk::MemoryPropertyFlags, vk::MemoryPropertyFlags) -> bool>(
|
|
||||||
memory_req: &vk::MemoryRequirements,
|
|
||||||
memory_prop: &vk::PhysicalDeviceMemoryProperties,
|
|
||||||
flags: vk::MemoryPropertyFlags,
|
|
||||||
f: F,
|
|
||||||
) -> Option<u32> {
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExampleBase {
|
pub struct ExampleBase {
|
||||||
|
|
Loading…
Add table
Reference in a new issue