use crate::raw::bindings::VkResult;
mod acceleration_structure;
mod allocator;
pub mod auto;
mod buffer;
mod command;
mod debug;
mod descriptor;
pub(crate) mod device;
mod extensions;
mod external_memory;
mod external_semaphore;
mod features;
mod flags;
mod graphics_pipeline;
mod image;
mod instance;
mod memory;
#[cfg(feature = "naga")]
pub mod naga;
mod physical;
mod pipeline;
pub mod pnext;
mod query;
mod ray_tracing_pipeline;
mod render_pass;
mod shader;
#[cfg(feature = "shaderc")]
pub mod shaderc;
mod shaders;
#[cfg(feature = "slang")]
pub mod slang;
mod surface;
mod swapchain;
mod sync;
pub use acceleration_structure::{
AccelerationStructure, AccelerationStructureBuildFlags, AccelerationStructureBuildMode,
AccelerationStructureBuildType, AccelerationStructureCreateInfo, AccelerationStructureGeometry,
AccelerationStructureType, BuildRange, BuildSizes,
};
pub use allocator::{
Allocation, AllocationCreateInfo, AllocationStatistics, AllocationStrategy, AllocationUsage,
Allocator, DefragmentationMove, DefragmentationPlan, FitStatus, PoolCreateInfo, PoolHandle,
PressureCallbackId, PressureEvent, PressureKind,
};
pub use auto::{
CommandBufferRecordingExt, CommandBufferRecordingSafeExt, DeviceExt, DeviceSafeExt,
InstanceExt, InstanceSafeExt, PhysicalDeviceExt, PhysicalDeviceSafeExt, QueueExt, QueueSafeExt,
};
pub use buffer::{Buffer, BufferCreateInfo, BufferUsage, MemoryRequirements};
pub use command::{
BufferCopy, ClearValue, CommandBuffer, CommandBufferRecording, CommandPool,
DescriptorBufferBinding, PipelineBindPoint, PushDescriptorWrite, RenderingAttachment,
RenderingInfo,
};
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 extensions::{DeviceExtensions, InstanceExtensions};
#[cfg(windows)]
pub use external_memory::Win32Handle;
#[cfg(unix)]
pub use external_semaphore::SemaphoreImportFd;
#[cfg(windows)]
pub use external_semaphore::SemaphoreImportWin32;
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, ExtensionProperties, Instance, InstanceCreateInfo, KHRONOS_VALIDATION_LAYER,
LayerProperties,
};
pub use memory::{DeviceMemory, MappedMemory, MemoryAllocateInfo, MemoryPropertyFlags};
pub use physical::{
CooperativeMatrixProperties, MemoryBudget, MemoryHeap, MemoryHeapFlags, MemoryType,
PhysicalDevice, PhysicalDeviceGroup, PhysicalDeviceProperties, PhysicalDeviceType,
QueueFamilyProperties, QueueFlags, ShaderIntegerDotProductProperties,
};
pub use pipeline::{
ComputePipeline, ComputePipelineOptions, PipelineCache, PipelineLayout, PushConstantRange,
SpecializationConstants,
};
pub use pnext::PNextChain;
pub use query::{PipelineStatisticsFlags, QueryPool, QueryType};
pub use ray_tracing_pipeline::{
RayTracingPipeline, RayTracingPipelineProperties, RayTracingShaderStage, RayTracingStage,
ShaderBindingRegion, ShaderGroup,
};
pub use render_pass::{
AttachmentDescription, AttachmentLoadOp, AttachmentStoreOp, Framebuffer, RenderPass,
RenderPassCreateInfo,
};
pub use shader::ShaderModule;
pub use shaders::{ShaderLoadError, ShaderRegistry, ShaderSource};
pub use surface::{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),
ShaderLoad(ShaderLoadError),
#[cfg(feature = "naga")]
NagaCompile(String),
#[cfg(feature = "shaderc")]
ShadercCompile(String),
#[cfg(feature = "slang")]
SlangCompile(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}"),
Self::ShaderLoad(e) => write!(f, "shader load failed: {e}"),
#[cfg(feature = "naga")]
Self::NagaCompile(s) => write!(f, "GLSL compilation failed: {s}"),
#[cfg(feature = "shaderc")]
Self::ShadercCompile(s) => write!(f, "shaderc compilation failed: {s}"),
#[cfg(feature = "slang")]
Self::SlangCompile(s) => write!(f, "Slang 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),
Self::ShaderLoad(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))
}
}