mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-26 08:45:59 +00:00
Return an error from trim() if extension is not enabled
This commit is contained in:
parent
94bacfa3bd
commit
2a448197cf
@ -10,6 +10,8 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::vec::IntoIter as VecIntoIter;
|
||||
use smallvec::SmallVec;
|
||||
@ -21,6 +23,7 @@ use device::Device;
|
||||
use OomError;
|
||||
use VulkanObject;
|
||||
use VulkanPointers;
|
||||
use Error;
|
||||
use check_errors;
|
||||
use vk;
|
||||
|
||||
@ -110,13 +113,16 @@ impl UnsafeCommandPool {
|
||||
///
|
||||
/// Command buffers allocated from the pool are not affected by trimming.
|
||||
#[inline]
|
||||
pub fn trim(&self) -> () {
|
||||
assert!(self.device.loaded_extensions().khr_maintenance1); //TODO return error?
|
||||
pub fn trim(&self) -> Result<(), CommandPoolTrimError> {
|
||||
if !self.device.loaded_extensions().khr_maintenance1 {
|
||||
return Err(CommandPoolTrimError::Maintenance1ExtensionNotEnabled);
|
||||
}
|
||||
unsafe {
|
||||
let flags = 0;
|
||||
let vk = self.device.pointers();
|
||||
vk.TrimCommandPoolKHR(self.device.internal_object(), self.pool, flags);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Allocates `count` command buffers.
|
||||
@ -216,3 +222,34 @@ impl Iterator for UnsafeCommandPoolAllocIter {
|
||||
}
|
||||
|
||||
impl ExactSizeIterator for UnsafeCommandPoolAllocIter {}
|
||||
|
||||
/// Error that can happen when trimming command pools.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum CommandPoolTrimError {
|
||||
/// The `KHR_maintenance1` extension was not enabled.
|
||||
Maintenance1ExtensionNotEnabled,
|
||||
}
|
||||
|
||||
impl error::Error for CommandPoolTrimError {
|
||||
#[inline]
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
CommandPoolTrimError::Maintenance1ExtensionNotEnabled => "the `KHR_maintenance1` \
|
||||
extension was not enabled",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for CommandPoolTrimError {
|
||||
#[inline]
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(fmt, "{}", error::Error::description(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for CommandPoolTrimError {
|
||||
#[inline]
|
||||
fn from(err: Error) -> CommandPoolTrimError {
|
||||
panic!("unexpected error: {:?}", err)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// according to those terms.
|
||||
|
||||
//! Low-level implementation of images and images views.
|
||||
//!
|
||||
//!
|
||||
//! This module contains low-level wrappers around the Vulkan image and image view types. All
|
||||
//! other image or image view types of this library, and all custom image or image view types
|
||||
//! that you create must wrap around the types in this module.
|
||||
@ -528,7 +528,7 @@ impl UnsafeImage {
|
||||
/// The layout is invariant for each image. However it is not cached, as this would waste
|
||||
/// memory in the case of non-linear-tiling images. You are encouraged to store the layout
|
||||
/// somewhere in order to avoid calling this semi-expensive function at every single memory
|
||||
/// access.
|
||||
/// access.
|
||||
///
|
||||
/// Note that while Vulkan allows querying the array layers other than 0, it is redundant as
|
||||
/// you can easily calculate the position of any layer.
|
||||
@ -864,7 +864,7 @@ impl UnsafeImageView {
|
||||
format: image.format,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/// Creates a new view from an image.
|
||||
///
|
||||
/// Note that you must create the view with identity swizzling if you want to use this view
|
||||
|
Loading…
Reference in New Issue
Block a user