use crate::raw::bindings::VkResult;
mod allocator;
mod buffer;
mod command;
mod debug;
mod descriptor;
mod device;
mod features;
mod graphics_pipeline;
mod image;
mod flags;
mod instance;
mod memory;
#[cfg(feature = "naga")]
pub mod naga;
#[cfg(feature = "shaderc")]
pub mod shaderc;
mod physical;
mod pipeline;
mod query;
mod render_pass;
mod shader;
mod surface;
mod swapchain;
mod sync;
pub use allocator::{
Allocation, AllocationCreateInfo, AllocationStatistics, AllocationStrategy, AllocationUsage,
Allocator, DefragmentationMove, DefragmentationPlan, PoolCreateInfo, PoolHandle,
};
pub use buffer::{Buffer, BufferCreateInfo, BufferUsage};
pub use command::{BufferCopy, ClearValue, CommandBuffer, CommandBufferRecording, CommandPool};
pub use debug::{
DebugCallback, DebugMessage, DebugMessageSeverity, DebugMessageType, default_callback,
};
pub use descriptor::{
DescriptorPool, DescriptorPoolSize, DescriptorSet, DescriptorSetLayout,
DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags,
};
pub use device::{
Device, DeviceCreateInfo, Queue, QueueCreateInfo, SignalSemaphore, WaitSemaphore,
};
pub use features::DeviceFeatures;
pub use flags::{AccessFlags, AccessFlags2, PipelineStage, PipelineStage2};
pub use graphics_pipeline::{
CompareOp, CullMode, FrontFace, GraphicsPipeline, GraphicsPipelineBuilder,
GraphicsShaderStage, InputRate, PolygonMode, PrimitiveTopology, VertexInputAttribute,
VertexInputBinding,
};
pub use image::{
BufferImageCopy, Format, Image, Image2dCreateInfo, ImageBarrier, ImageLayout, ImageUsage,
ImageView, Sampler, SamplerAddressMode, SamplerCreateInfo, SamplerFilter, SamplerMipmapMode,
};
pub use instance::{
ApiVersion, DEBUG_UTILS_EXTENSION, ExtensionProperties, Instance, InstanceCreateInfo,
KHRONOS_VALIDATION_LAYER, LayerProperties,
};
pub use memory::{DeviceMemory, MappedMemory, MemoryPropertyFlags};
pub use physical::{
CooperativeMatrixProperties, MemoryBudget, MemoryHeap, MemoryHeapFlags, MemoryType,
PhysicalDevice, PhysicalDeviceGroup, PhysicalDeviceProperties, PhysicalDeviceType,
QueueFamilyProperties, QueueFlags,
};
pub use pipeline::{
ComputePipeline, PipelineCache, PipelineLayout, PushConstantRange, SpecializationConstants,
};
pub use query::{PipelineStatisticsFlags, QueryPool, QueryType};
pub use render_pass::{
AttachmentDescription, AttachmentLoadOp, AttachmentStoreOp, Framebuffer, RenderPass,
RenderPassCreateInfo,
};
pub use shader::ShaderModule;
pub use surface::{
EXT_METAL_SURFACE_EXTENSION, KHR_SURFACE_EXTENSION, KHR_SWAPCHAIN_EXTENSION,
KHR_WAYLAND_SURFACE_EXTENSION, KHR_WIN32_SURFACE_EXTENSION, KHR_XCB_SURFACE_EXTENSION,
KHR_XLIB_SURFACE_EXTENSION, PresentMode, Surface, SurfaceCapabilities, SurfaceFormat,
};
pub use swapchain::{Swapchain, SwapchainCreateInfo};
pub use sync::{Fence, Semaphore, SemaphoreKind};
#[derive(Debug)]
pub enum Error {
LibraryLoad(libloading::Error),
MissingFunction(&'static str),
Vk(VkResult),
InvalidString(std::ffi::NulError),
InvalidArgument(&'static str),
#[cfg(feature = "naga")]
NagaCompile(String),
#[cfg(feature = "shaderc")]
ShadercCompile(String),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::LibraryLoad(e) => write!(f, "failed to load Vulkan library: {e}"),
Self::MissingFunction(name) => write!(f, "Vulkan function not loaded: {name}"),
Self::Vk(result) => write!(f, "Vulkan call failed: {result:?}"),
Self::InvalidString(e) => write!(f, "invalid C string: {e}"),
Self::InvalidArgument(msg) => write!(f, "invalid argument: {msg}"),
#[cfg(feature = "naga")]
Self::NagaCompile(s) => write!(f, "GLSL compilation failed: {s}"),
#[cfg(feature = "shaderc")]
Self::ShadercCompile(s) => write!(f, "shaderc compilation failed: {s}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::LibraryLoad(e) => Some(e),
Self::InvalidString(e) => Some(e),
_ => None,
}
}
}
impl From<libloading::Error> for Error {
fn from(e: libloading::Error) -> Self {
Self::LibraryLoad(e)
}
}
impl From<VkResult> for Error {
fn from(e: VkResult) -> Self {
Self::Vk(e)
}
}
impl From<std::ffi::NulError> for Error {
fn from(e: std::ffi::NulError) -> Self {
Self::InvalidString(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;
pub(crate) fn check(result: VkResult) -> Result<()> {
if result == VkResult::SUCCESS {
Ok(())
} else {
Err(Error::Vk(result))
}
}