Skip to content

Commit

Permalink
Added Result return type for creating the vulkan Allocator.
Browse files Browse the repository at this point in the history
  • Loading branch information
manon-traverse committed May 31, 2021
1 parent 161fe7b commit fdacfde
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion examples/vulkan-buffer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ fn main() {
device: device.clone(),
physical_device: pdevice,
debug_settings: Default::default(),
});
})
.unwrap();

// Test allocating GPU Only memory
{
Expand Down
3 changes: 2 additions & 1 deletion examples/vulkan-visualization/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ fn main() {
device: device.clone(),
physical_device: pdevice,
debug_settings: Default::default(),
});
})
.unwrap();

let fence_create_info =
vk::FenceCreateInfo::builder().flags(vk::FenceCreateFlags::SIGNALED);
Expand Down
2 changes: 2 additions & 0 deletions src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub enum AllocationError {
NoCompatibleMemoryTypeFound,
#[error("Invalid AllocationCreateDesc")]
InvalidAllocationCreateDesc,
#[error("Invalid AllocatorCreateDesc {0}")]
InvalidAllocatorCreateDesc(String),
#[error("Internal error {0}")]
Internal(String),
}
Expand Down
12 changes: 9 additions & 3 deletions src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,13 @@ pub struct Allocator {
}

impl Allocator {
pub fn new(desc: &AllocatorCreateDesc) -> Self {
pub fn new(desc: &AllocatorCreateDesc) -> Result<Self> {
if desc.physical_device == ash::vk::PhysicalDevice::null() {
return Err(AllocationError::InvalidAllocatorCreateDesc(
"AllocatorCreateDesc field `physical_device` is null.".into(),
));
}

let mem_props = unsafe {
desc.instance
.get_physical_device_memory_properties(desc.physical_device)
Expand Down Expand Up @@ -519,14 +525,14 @@ impl Allocator {

let granularity = physical_device_properties.limits.buffer_image_granularity;

Self {
Ok(Self {
memory_types,
#[cfg(feature = "visualizer")]
memory_heaps,
device: desc.device.clone(),
buffer_image_granularity: granularity,
debug_settings: desc.debug_settings,
}
})
}

pub fn allocate(&mut self, desc: &AllocationCreateDesc) -> Result<Allocation> {
Expand Down

0 comments on commit fdacfde

Please sign in to comment.