#![warn(missing_docs)]
use std::sync::Arc;
use erupt::vk;
pub use {
acceleration_structure::AccelerationStructure,
buffer::{Buffer, BufferView},
command::{
CommandBufferSemaphore, ComputeCommandBuffer, ComputeCommandEncoder, ComputeCommandPool,
GraphicsCommandBuffer, GraphicsCommandEncoder, GraphicsCommandPool, RenderPassEncoder,
TransferCommandBuffer, TransferCommandEncoder, TransferCommandPool,
},
deferred_operation::DeferredOperation,
descriptor::{DescriptorPool, DescriptorSet, DescriptorSetLayout},
device::{BarSupport, Device, DeviceConfiguration, QueueConfiguration, Queues},
error::AscheError,
fence::Fence,
image::{Image, ImageView, Sampler},
instance::{Instance, InstanceConfiguration},
query::QueryPool,
queue::{ComputeQueue, GraphicsQueue, TransferQueue},
semaphore::{BinarySemaphore, TimelineSemaphore},
swapchain::{Swapchain, SwapchainFrame},
vk_alloc::MemoryLocation,
};
use crate::context::Context;
pub(crate) mod acceleration_structure;
pub(crate) mod buffer;
pub(crate) mod command;
pub(crate) mod context;
pub(crate) mod deferred_operation;
pub(crate) mod descriptor;
pub(crate) mod device;
pub(crate) mod error;
pub(crate) mod fence;
pub(crate) mod image;
pub(crate) mod instance;
pub(crate) mod query;
pub(crate) mod queue;
pub(crate) mod semaphore;
pub(crate) mod swapchain;
#[cfg(debug_assertions)]
pub(crate) mod vk_debug;
pub(crate) type Result<T> = std::result::Result<T, AscheError>;
#[derive(Copy, Clone, Debug)]
pub(crate) enum QueueType {
Compute = 0,
Graphics,
Transfer,
}
impl std::fmt::Display for QueueType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
QueueType::Compute => f.write_str("Compute"),
QueueType::Graphics => f.write_str("Graphics"),
QueueType::Transfer => f.write_str("Transfer"),
}
}
}
#[derive(Debug)]
pub struct RenderPass {
pub raw: vk::RenderPass,
context: Arc<Context>,
}
impl Drop for RenderPass {
fn drop(&mut self) {
unsafe {
self.context
.device
.destroy_render_pass(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct PipelineLayout {
pub raw: vk::PipelineLayout,
context: Arc<Context>,
}
impl Drop for PipelineLayout {
fn drop(&mut self) {
unsafe {
self.context
.device
.destroy_pipeline_layout(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct GraphicsPipeline {
pub raw: vk::Pipeline,
context: Arc<Context>,
}
impl Drop for GraphicsPipeline {
fn drop(&mut self) {
unsafe {
self.context.device.destroy_pipeline(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct ComputePipeline {
pub raw: vk::Pipeline,
context: Arc<Context>,
}
impl Drop for ComputePipeline {
fn drop(&mut self) {
unsafe {
self.context.device.destroy_pipeline(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct RayTracingPipeline {
pub raw: vk::Pipeline,
context: Arc<Context>,
}
impl Drop for RayTracingPipeline {
fn drop(&mut self) {
unsafe {
self.context.device.destroy_pipeline(Some(self.raw), None);
};
}
}
#[derive(Debug)]
pub struct ShaderModule {
pub raw: vk::ShaderModule,
context: Arc<Context>,
}
impl Drop for ShaderModule {
fn drop(&mut self) {
unsafe {
self.context
.device
.destroy_shader_module(Some(self.raw), None);
};
}
}
#[derive(Clone, Debug)]
pub struct BufferDescriptor<'a> {
pub name: &'a str,
pub usage: vk::BufferUsageFlags,
pub memory_location: vk_alloc::MemoryLocation,
pub sharing_mode: vk::SharingMode,
pub queues: vk::QueueFlags,
pub size: vk::DeviceSize,
pub flags: Option<vk::BufferCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct BufferViewDescriptor<'a> {
pub name: &'a str,
pub buffer: &'a Buffer,
pub format: vk::Format,
pub offset: vk::DeviceSize,
pub range: u64,
pub flags: Option<vk::BufferViewCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct ImageDescriptor<'a> {
pub name: &'a str,
pub usage: vk::ImageUsageFlags,
pub memory_location: vk_alloc::MemoryLocation,
pub sharing_mode: vk::SharingMode,
pub queues: vk::QueueFlags,
pub image_type: vk::ImageType,
pub format: vk::Format,
pub extent: vk::Extent3D,
pub mip_levels: u32,
pub array_layers: u32,
pub samples: vk::SampleCountFlagBits,
pub tiling: vk::ImageTiling,
pub initial_layout: vk::ImageLayout,
pub flags: Option<vk::ImageCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct ImageViewDescriptor<'a> {
pub name: &'a str,
pub image: &'a Image,
pub view_type: vk::ImageViewType,
pub format: vk::Format,
pub components: vk::ComponentMapping,
pub subresource_range: vk::ImageSubresourceRange,
pub flags: Option<vk::ImageViewCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct SamplerDescriptor<'a> {
pub name: &'a str,
pub mag_filter: vk::Filter,
pub min_filter: vk::Filter,
pub mipmap_mode: vk::SamplerMipmapMode,
pub address_mode_u: vk::SamplerAddressMode,
pub address_mode_v: vk::SamplerAddressMode,
pub address_mode_w: vk::SamplerAddressMode,
pub mip_lod_bias: vk::SamplerMipmapMode,
pub anisotropy_enable: bool,
pub max_anisotropy: f32,
pub compare_op: Option<vk::CompareOp>,
pub min_lod: f32,
pub max_lod: f32,
pub border_color: Option<vk::BorderColor>,
pub unnormalized_coordinates: bool,
pub flags: Option<vk::SamplerCreateFlags>,
}
impl<'a> Default for SamplerDescriptor<'a> {
fn default() -> Self {
Self {
name: "",
mag_filter: vk::Filter::LINEAR,
min_filter: vk::Filter::LINEAR,
mipmap_mode: vk::SamplerMipmapMode::LINEAR,
address_mode_u: vk::SamplerAddressMode::CLAMP_TO_EDGE,
address_mode_v: vk::SamplerAddressMode::CLAMP_TO_EDGE,
address_mode_w: vk::SamplerAddressMode::CLAMP_TO_EDGE,
mip_lod_bias: vk::SamplerMipmapMode::LINEAR,
anisotropy_enable: false,
max_anisotropy: 0.0,
compare_op: Some(vk::CompareOp::LESS_OR_EQUAL),
min_lod: 0.0,
max_lod: std::f32::MAX,
border_color: None,
unnormalized_coordinates: false,
flags: None,
}
}
}
#[derive(Clone, Debug)]
pub struct DescriptorPoolDescriptor<'a> {
pub name: &'a str,
pub max_sets: u32,
pub pool_sizes: &'a [vk::DescriptorPoolSizeBuilder<'a>],
pub flags: Option<vk::DescriptorPoolCreateFlags>,
}
#[derive(Clone, Debug)]
pub struct RenderPassColorAttachmentDescriptor {
pub attachment: vk::ImageView,
pub clear_value: Option<vk::ClearValue>,
}
#[derive(Clone, Debug)]
pub struct RenderPassDepthAttachmentDescriptor {
pub attachment: vk::ImageView,
pub clear_value: Option<vk::ClearValue>,
}