Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for acceleration structures and ray queries #2213

Merged
merged 9 commits into from
Jun 2, 2023
1,654 changes: 1,654 additions & 0 deletions vulkano/src/acceleration_structure.rs

Large diffs are not rendered by default.

90 changes: 89 additions & 1 deletion vulkano/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ use self::{
};
use crate::{
device::{Device, DeviceOwned},
macros::vulkan_bitflags,
macros::{vulkan_bitflags, vulkan_enum},
memory::{
allocator::{
AllocationCreateInfo, AllocationCreationError, AllocationType, DeviceLayout,
Expand Down Expand Up @@ -1123,3 +1123,91 @@ pub struct ExternalBufferProperties {
/// The properties for external memory.
pub external_memory_properties: ExternalMemoryProperties,
}

vulkan_enum! {
#[non_exhaustive]

/// An enumeration of all valid index types.
IndexType = IndexType(i32);

/// Indices are 8-bit unsigned integers.
U8 = UINT8_EXT {
device_extensions: [ext_index_type_uint8],
},

/// Indices are 16-bit unsigned integers.
U16 = UINT16,

/// Indices are 32-bit unsigned integers.
U32 = UINT32,
}

impl IndexType {
/// Returns the size in bytes of indices of this type.
#[inline]
pub fn size(self) -> DeviceSize {
match self {
IndexType::U8 => 1,
IndexType::U16 => 2,
IndexType::U32 => 4,
}
}
}

/// A buffer holding index values, which index into buffers holding vertex data.
#[derive(Clone, Debug)]
pub enum IndexBuffer {
/// An index buffer containing unsigned 8-bit indices.
///
/// The [`index_type_uint8`] feature must be enabled on the device.
///
/// [`index_type_uint8`]: crate::device::Features::index_type_uint8
U8(Subbuffer<[u8]>),

/// An index buffer containing unsigned 16-bit indices.
U16(Subbuffer<[u16]>),

/// An index buffer containing unsigned 32-bit indices.
U32(Subbuffer<[u32]>),
}

impl IndexBuffer {
#[inline]
pub fn index_type(&self) -> IndexType {
match self {
Self::U8(_) => IndexType::U8,
Self::U16(_) => IndexType::U16,
Self::U32(_) => IndexType::U32,
}
}

#[inline]
pub(crate) fn as_bytes(&self) -> &Subbuffer<[u8]> {
match self {
IndexBuffer::U8(buffer) => buffer.as_bytes(),
IndexBuffer::U16(buffer) => buffer.as_bytes(),
IndexBuffer::U32(buffer) => buffer.as_bytes(),
}
}
}

impl From<Subbuffer<[u8]>> for IndexBuffer {
#[inline]
fn from(value: Subbuffer<[u8]>) -> Self {
Self::U8(value)
}
}

impl From<Subbuffer<[u16]>> for IndexBuffer {
#[inline]
fn from(value: Subbuffer<[u16]>) -> Self {
Self::U16(value)
}
}

impl From<Subbuffer<[u32]>> for IndexBuffer {
#[inline]
fn from(value: Subbuffer<[u32]>) -> Self {
Self::U32(value)
}
}
12 changes: 5 additions & 7 deletions vulkano/src/buffer/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,15 @@ vulkan_bitflags! {
device_extensions: [ext_conditional_rendering],
},*/

/* TODO: enable
// TODO: document
ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR = ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR {
/// The buffer can be used as input data for an acceleration structure build operation.
ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY = ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR {
device_extensions: [khr_acceleration_structure],
},*/
},

/* TODO: enable
// TODO: document
/// An acceleration structure can be created from the buffer.
ACCELERATION_STRUCTURE_STORAGE = ACCELERATION_STRUCTURE_STORAGE_KHR {
device_extensions: [khr_acceleration_structure],
},*/
},

/* TODO: enable
// TODO: document
Expand Down
11 changes: 5 additions & 6 deletions vulkano/src/command_buffer/auto/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{
SubmitState,
};
use crate::{
buffer::{Buffer, Subbuffer},
buffer::{Buffer, IndexBuffer, Subbuffer},
command_buffer::{
allocator::{CommandBufferAllocator, StandardCommandBufferAllocator},
sys::{CommandBufferBeginInfo, UnsafeCommandBuffer, UnsafeCommandBufferBuilder},
Expand All @@ -35,14 +35,14 @@ use crate::{
graphics::{
color_blend::LogicOp,
depth_stencil::{CompareOp, StencilOps},
input_assembly::{IndexType, PrimitiveTopology},
input_assembly::PrimitiveTopology,
rasterization::{CullMode, DepthBias, FrontFace, LineStipple},
subpass::PipelineRenderingCreateInfo,
viewport::{Scissor, Viewport},
},
ComputePipeline, DynamicState, GraphicsPipeline, PipelineBindPoint, PipelineLayout,
},
query::{QueryControlFlags, QueryType},
query::{QueryControlFlags, QueryPool},
range_map::RangeMap,
range_set::RangeSet,
render_pass::{Framebuffer, Subpass},
Expand Down Expand Up @@ -1664,7 +1664,7 @@ pub(in crate::command_buffer) struct CommandBufferBuilderState {

// Bind/push
pub(in crate::command_buffer) descriptor_sets: HashMap<PipelineBindPoint, DescriptorSetState>,
pub(in crate::command_buffer) index_buffer: Option<(Subbuffer<[u8]>, IndexType)>,
pub(in crate::command_buffer) index_buffer: Option<IndexBuffer>,
pub(in crate::command_buffer) pipeline_compute: Option<Arc<ComputePipeline>>,
pub(in crate::command_buffer) pipeline_graphics: Option<Arc<GraphicsPipeline>>,
pub(in crate::command_buffer) vertex_buffers: HashMap<u32, Subbuffer<[u8]>>,
Expand Down Expand Up @@ -2080,9 +2080,8 @@ pub(in crate::command_buffer) struct StencilOpStateDynamic {
}

pub(in crate::command_buffer) struct QueryState {
pub(in crate::command_buffer) query_pool: ash::vk::QueryPool,
pub(in crate::command_buffer) query_pool: Arc<QueryPool>,
pub(in crate::command_buffer) query: u32,
pub(in crate::command_buffer) ty: QueryType,
pub(in crate::command_buffer) flags: QueryControlFlags,
pub(in crate::command_buffer) in_subpass: bool,
}
Loading