#![doc(html_logo_url = "https://raw.githubusercontent.com/vulkano-rs/vulkano/master/logo.png")]
#![allow(dead_code)] #![allow(unused_variables)]
pub use ash::vk::Handle;
pub use half;
use std::{
error, fmt,
ops::Deref,
sync::{Arc, MutexGuard},
};
pub use version::Version;
#[macro_use]
mod tests;
#[macro_use]
mod extensions;
pub mod buffer;
pub mod command_buffer;
pub mod descriptor_set;
pub mod device;
pub mod format;
mod version;
#[macro_use]
pub mod render_pass;
mod fns;
pub mod image;
pub mod instance;
pub mod memory;
pub mod pipeline;
pub mod query;
pub mod range_set;
pub mod sampler;
pub mod shader;
pub mod swapchain;
pub mod sync;
pub use ash::vk::DeviceSize;
pub unsafe trait SafeDeref: Deref {}
unsafe impl<'a, T: ?Sized> SafeDeref for &'a T {}
unsafe impl<T: ?Sized> SafeDeref for Arc<T> {}
unsafe impl<T: ?Sized> SafeDeref for Box<T> {}
pub unsafe trait VulkanObject {
type Object: ash::vk::Handle;
fn internal_object(&self) -> Self::Object;
}
pub unsafe trait SynchronizedVulkanObject {
type Object: ash::vk::Handle;
fn internal_object_guard(&self) -> MutexGuard<Self::Object>;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum OomError {
OutOfHostMemory,
OutOfDeviceMemory,
}
impl error::Error for OomError {}
impl fmt::Display for OomError {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(
fmt,
"{}",
match *self {
OomError::OutOfHostMemory => "no memory available on the host",
OomError::OutOfDeviceMemory => "no memory available on the graphical device",
}
)
}
}
impl From<Error> for OomError {
#[inline]
fn from(err: Error) -> OomError {
match err {
Error::OutOfHostMemory => OomError::OutOfHostMemory,
Error::OutOfDeviceMemory => OomError::OutOfDeviceMemory,
_ => panic!("unexpected error: {:?}", err),
}
}
}
#[derive(Debug, Copy, Clone)]
#[repr(i32)]
enum Success {
Success = ash::vk::Result::SUCCESS.as_raw(),
NotReady = ash::vk::Result::NOT_READY.as_raw(),
Timeout = ash::vk::Result::TIMEOUT.as_raw(),
EventSet = ash::vk::Result::EVENT_SET.as_raw(),
EventReset = ash::vk::Result::EVENT_RESET.as_raw(),
Incomplete = ash::vk::Result::INCOMPLETE.as_raw(),
Suboptimal = ash::vk::Result::SUBOPTIMAL_KHR.as_raw(),
}
#[derive(Debug, Copy, Clone)]
#[repr(i32)]
pub(crate) enum Error {
OutOfHostMemory = ash::vk::Result::ERROR_OUT_OF_HOST_MEMORY.as_raw(),
OutOfDeviceMemory = ash::vk::Result::ERROR_OUT_OF_DEVICE_MEMORY.as_raw(),
InitializationFailed = ash::vk::Result::ERROR_INITIALIZATION_FAILED.as_raw(),
DeviceLost = ash::vk::Result::ERROR_DEVICE_LOST.as_raw(),
MemoryMapFailed = ash::vk::Result::ERROR_MEMORY_MAP_FAILED.as_raw(),
LayerNotPresent = ash::vk::Result::ERROR_LAYER_NOT_PRESENT.as_raw(),
ExtensionNotPresent = ash::vk::Result::ERROR_EXTENSION_NOT_PRESENT.as_raw(),
FeatureNotPresent = ash::vk::Result::ERROR_FEATURE_NOT_PRESENT.as_raw(),
IncompatibleDriver = ash::vk::Result::ERROR_INCOMPATIBLE_DRIVER.as_raw(),
TooManyObjects = ash::vk::Result::ERROR_TOO_MANY_OBJECTS.as_raw(),
FormatNotSupported = ash::vk::Result::ERROR_FORMAT_NOT_SUPPORTED.as_raw(),
SurfaceLost = ash::vk::Result::ERROR_SURFACE_LOST_KHR.as_raw(),
NativeWindowInUse = ash::vk::Result::ERROR_NATIVE_WINDOW_IN_USE_KHR.as_raw(),
OutOfDate = ash::vk::Result::ERROR_OUT_OF_DATE_KHR.as_raw(),
IncompatibleDisplay = ash::vk::Result::ERROR_INCOMPATIBLE_DISPLAY_KHR.as_raw(),
ValidationFailed = ash::vk::Result::ERROR_VALIDATION_FAILED_EXT.as_raw(),
OutOfPoolMemory = ash::vk::Result::ERROR_OUT_OF_POOL_MEMORY_KHR.as_raw(),
InvalidExternalHandle = ash::vk::Result::ERROR_INVALID_EXTERNAL_HANDLE.as_raw(),
FullScreenExclusiveLost = ash::vk::Result::ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT.as_raw(),
}
fn check_errors(result: ash::vk::Result) -> Result<Success, Error> {
match result {
ash::vk::Result::SUCCESS => Ok(Success::Success),
ash::vk::Result::NOT_READY => Ok(Success::NotReady),
ash::vk::Result::TIMEOUT => Ok(Success::Timeout),
ash::vk::Result::EVENT_SET => Ok(Success::EventSet),
ash::vk::Result::EVENT_RESET => Ok(Success::EventReset),
ash::vk::Result::INCOMPLETE => Ok(Success::Incomplete),
ash::vk::Result::ERROR_OUT_OF_HOST_MEMORY => Err(Error::OutOfHostMemory),
ash::vk::Result::ERROR_OUT_OF_DEVICE_MEMORY => Err(Error::OutOfDeviceMemory),
ash::vk::Result::ERROR_INITIALIZATION_FAILED => Err(Error::InitializationFailed),
ash::vk::Result::ERROR_DEVICE_LOST => Err(Error::DeviceLost),
ash::vk::Result::ERROR_MEMORY_MAP_FAILED => Err(Error::MemoryMapFailed),
ash::vk::Result::ERROR_LAYER_NOT_PRESENT => Err(Error::LayerNotPresent),
ash::vk::Result::ERROR_EXTENSION_NOT_PRESENT => Err(Error::ExtensionNotPresent),
ash::vk::Result::ERROR_FEATURE_NOT_PRESENT => Err(Error::FeatureNotPresent),
ash::vk::Result::ERROR_INCOMPATIBLE_DRIVER => Err(Error::IncompatibleDriver),
ash::vk::Result::ERROR_TOO_MANY_OBJECTS => Err(Error::TooManyObjects),
ash::vk::Result::ERROR_FORMAT_NOT_SUPPORTED => Err(Error::FormatNotSupported),
ash::vk::Result::ERROR_SURFACE_LOST_KHR => Err(Error::SurfaceLost),
ash::vk::Result::ERROR_NATIVE_WINDOW_IN_USE_KHR => Err(Error::NativeWindowInUse),
ash::vk::Result::SUBOPTIMAL_KHR => Ok(Success::Suboptimal),
ash::vk::Result::ERROR_OUT_OF_DATE_KHR => Err(Error::OutOfDate),
ash::vk::Result::ERROR_INCOMPATIBLE_DISPLAY_KHR => Err(Error::IncompatibleDisplay),
ash::vk::Result::ERROR_VALIDATION_FAILED_EXT => Err(Error::ValidationFailed),
ash::vk::Result::ERROR_OUT_OF_POOL_MEMORY_KHR => Err(Error::OutOfPoolMemory),
ash::vk::Result::ERROR_INVALID_EXTERNAL_HANDLE => Err(Error::InvalidExternalHandle),
ash::vk::Result::ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT => {
Err(Error::FullScreenExclusiveLost)
}
ash::vk::Result::ERROR_INVALID_SHADER_NV => panic!(
"Vulkan function returned \
VK_ERROR_INVALID_SHADER_NV"
),
c => unreachable!("Unexpected error code returned by Vulkan: {}", c),
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct NonExhaustive(pub(crate) ());