Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use slices of proper size with PhysicalDeviceMemoryProperties #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,13 @@ impl Device {
pub fn memory_type_index(&self, type_filter: u32, properties: ::MemoryPropertyFlags)
-> VdResult<u32> {
let mem_props = self.physical_device().memory_properties();
let mem_types = mem_props.memory_types();

for i in 0..mem_props.memory_type_count() {
for (i, mem_type) in mem_types.iter().enumerate() {
if (type_filter & (1 << i)) != 0 &&
(mem_props.memory_types()[i as usize].property_flags() & properties) == properties
(mem_type.property_flags() & properties) == properties
{
return Ok(i);
return Ok(i as u32);
}
}
panic!("failed to find suitable memory type index with: type_filter: '{}', properties: '{:?}'",
Expand Down
10 changes: 4 additions & 6 deletions src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2290,20 +2290,18 @@ impl PhysicalDeviceMemoryProperties {
PhysicalDeviceMemoryProperties { raw, }
}

pub fn memory_type_count<'a>(&'a self) -> u32 {
self.raw.memoryTypeCount.into()
}

pub fn memory_types<'a>(&'a self) -> &[MemoryType] {
unsafe { slice::from_raw_parts(&self.raw.memoryTypes as *const vks::VkMemoryType as *const _, vks::VK_MAX_MEMORY_TYPES as usize) }
let count = self.raw.memoryTypeCount as usize;
unsafe { std::mem::transmute(&self.raw.memoryTypes[..count]) }
}

pub fn memory_heap_count<'a>(&'a self) -> u32 {
self.raw.memoryHeapCount.into()
}

pub fn memory_heaps<'a>(&'a self) -> &[MemoryHeap] {
unsafe { slice::from_raw_parts(&self.raw.memoryHeaps as *const vks::VkMemoryHeap as *const _, vks::VK_MAX_MEMORY_HEAPS as usize) }
let count = self.raw.memoryHeapCount as usize;
unsafe { std::mem::transmute(&self.raw.memoryHeaps[..count]) }
}

pub fn set_memory_type_count<'m>(&mut self, memory_type_count: u32) {
Expand Down