#![doc(html_logo_url = "https://raw.githubusercontent.com/vulkano-rs/vulkano/master/logo.png")]
#![allow(dead_code)] #![allow(unused_variables)]
extern crate crossbeam;
extern crate fnv;
#[macro_use]
extern crate lazy_static;
extern crate shared_library;
extern crate smallvec;
extern crate vk_sys as vk;
pub extern crate half;
#[macro_use]
mod tests;
#[macro_use]
mod extensions;
mod features;
mod version;
pub mod buffer;
pub mod command_buffer;
pub mod descriptor;
pub mod device;
pub mod format;
#[macro_use]
pub mod framebuffer;
pub mod image;
pub mod instance;
pub mod memory;
pub mod pipeline;
pub mod query;
pub mod sampler;
pub mod swapchain;
pub mod sync;
use std::error;
use std::fmt;
use std::ops::Deref;
use std::sync::Arc;
use std::sync::MutexGuard;
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 trait VulkanHandle {
fn value(&self) -> u64;
}
impl VulkanHandle for usize {
#[inline]
fn value(&self) -> u64 { *self as u64 }
}
impl VulkanHandle for u64 {
#[inline]
fn value(&self) -> u64 { *self }
}
pub unsafe trait VulkanObject {
type Object: VulkanHandle;
const TYPE: vk::ObjectType;
fn internal_object(&self) -> Self::Object;
}
pub unsafe trait SynchronizedVulkanObject {
type Object: VulkanHandle;
fn internal_object_guard(&self) -> MutexGuard<Self::Object>;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum OomError {
OutOfHostMemory,
OutOfDeviceMemory,
}
impl error::Error for OomError {
#[inline]
fn description(&self) -> &str {
match *self {
OomError::OutOfHostMemory => "no memory available on the host",
OomError::OutOfDeviceMemory => "no memory available on the graphical device",
}
}
}
impl fmt::Display for OomError {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(fmt, "{}", error::Error::description(self))
}
}
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(u32)]
enum Success {
Success = vk::SUCCESS,
NotReady = vk::NOT_READY,
Timeout = vk::TIMEOUT,
EventSet = vk::EVENT_SET,
EventReset = vk::EVENT_RESET,
Incomplete = vk::INCOMPLETE,
Suboptimal = vk::SUBOPTIMAL_KHR,
}
#[derive(Debug, Copy, Clone)]
#[repr(u32)]
pub(crate) enum Error {
OutOfHostMemory = vk::ERROR_OUT_OF_HOST_MEMORY,
OutOfDeviceMemory = vk::ERROR_OUT_OF_DEVICE_MEMORY,
InitializationFailed = vk::ERROR_INITIALIZATION_FAILED,
DeviceLost = vk::ERROR_DEVICE_LOST,
MemoryMapFailed = vk::ERROR_MEMORY_MAP_FAILED,
LayerNotPresent = vk::ERROR_LAYER_NOT_PRESENT,
ExtensionNotPresent = vk::ERROR_EXTENSION_NOT_PRESENT,
FeatureNotPresent = vk::ERROR_FEATURE_NOT_PRESENT,
IncompatibleDriver = vk::ERROR_INCOMPATIBLE_DRIVER,
TooManyObjects = vk::ERROR_TOO_MANY_OBJECTS,
FormatNotSupported = vk::ERROR_FORMAT_NOT_SUPPORTED,
SurfaceLost = vk::ERROR_SURFACE_LOST_KHR,
NativeWindowInUse = vk::ERROR_NATIVE_WINDOW_IN_USE_KHR,
OutOfDate = vk::ERROR_OUT_OF_DATE_KHR,
IncompatibleDisplay = vk::ERROR_INCOMPATIBLE_DISPLAY_KHR,
ValidationFailed = vk::ERROR_VALIDATION_FAILED_EXT,
OutOfPoolMemory = vk::ERROR_OUT_OF_POOL_MEMORY_KHR,
}
fn check_errors(result: vk::Result) -> Result<Success, Error> {
match result {
vk::SUCCESS => Ok(Success::Success),
vk::NOT_READY => Ok(Success::NotReady),
vk::TIMEOUT => Ok(Success::Timeout),
vk::EVENT_SET => Ok(Success::EventSet),
vk::EVENT_RESET => Ok(Success::EventReset),
vk::INCOMPLETE => Ok(Success::Incomplete),
vk::ERROR_OUT_OF_HOST_MEMORY => Err(Error::OutOfHostMemory),
vk::ERROR_OUT_OF_DEVICE_MEMORY => Err(Error::OutOfDeviceMemory),
vk::ERROR_INITIALIZATION_FAILED => Err(Error::InitializationFailed),
vk::ERROR_DEVICE_LOST => Err(Error::DeviceLost),
vk::ERROR_MEMORY_MAP_FAILED => Err(Error::MemoryMapFailed),
vk::ERROR_LAYER_NOT_PRESENT => Err(Error::LayerNotPresent),
vk::ERROR_EXTENSION_NOT_PRESENT => Err(Error::ExtensionNotPresent),
vk::ERROR_FEATURE_NOT_PRESENT => Err(Error::FeatureNotPresent),
vk::ERROR_INCOMPATIBLE_DRIVER => Err(Error::IncompatibleDriver),
vk::ERROR_TOO_MANY_OBJECTS => Err(Error::TooManyObjects),
vk::ERROR_FORMAT_NOT_SUPPORTED => Err(Error::FormatNotSupported),
vk::ERROR_SURFACE_LOST_KHR => Err(Error::SurfaceLost),
vk::ERROR_NATIVE_WINDOW_IN_USE_KHR => Err(Error::NativeWindowInUse),
vk::SUBOPTIMAL_KHR => Ok(Success::Suboptimal),
vk::ERROR_OUT_OF_DATE_KHR => Err(Error::OutOfDate),
vk::ERROR_INCOMPATIBLE_DISPLAY_KHR => Err(Error::IncompatibleDisplay),
vk::ERROR_VALIDATION_FAILED_EXT => Err(Error::ValidationFailed),
vk::ERROR_OUT_OF_POOL_MEMORY_KHR => Err(Error::OutOfPoolMemory),
vk::ERROR_INVALID_SHADER_NV => panic!("Vulkan function returned \
VK_ERROR_INVALID_SHADER_NV"),
c => unreachable!("Unexpected error code returned by Vulkan: {}", c),
}
}