| 1 |
//! <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_NV_ray_tracing.html> |
| 2 |
|
| 3 |
use crate::prelude::*; |
| 4 |
use crate::vk; |
| 5 |
use crate::RawPtr; |
| 6 |
use alloc::vec::Vec; |
| 7 |
use core::mem; |
| 8 |
|
| 9 |
impl crate::nv::ray_tracing::Device { |
| 10 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreateAccelerationStructureNV.html> |
| 11 |
#[inline] |
| 12 |
pub unsafe fn create_acceleration_structure( |
| 13 |
&self, |
| 14 |
create_info: &vk::AccelerationStructureCreateInfoNV<'_>, |
| 15 |
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, |
| 16 |
) -> VkResult<vk::AccelerationStructureNV> { |
| 17 |
let mut accel_struct = mem::MaybeUninit::uninit(); |
| 18 |
(self.fp.create_acceleration_structure_nv)( |
| 19 |
self.handle, |
| 20 |
create_info, |
| 21 |
allocation_callbacks.as_raw_ptr(), |
| 22 |
accel_struct.as_mut_ptr(), |
| 23 |
) |
| 24 |
.assume_init_on_success(accel_struct) |
| 25 |
} |
| 26 |
|
| 27 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDestroyAccelerationStructureNV.html> |
| 28 |
#[inline] |
| 29 |
pub unsafe fn destroy_acceleration_structure( |
| 30 |
&self, |
| 31 |
accel_struct: vk::AccelerationStructureNV, |
| 32 |
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, |
| 33 |
) { |
| 34 |
(self.fp.destroy_acceleration_structure_nv)( |
| 35 |
self.handle, |
| 36 |
accel_struct, |
| 37 |
allocation_callbacks.as_raw_ptr(), |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetAccelerationStructureMemoryRequirementsNV.html> |
| 42 |
#[inline] |
| 43 |
pub unsafe fn get_acceleration_structure_memory_requirements( |
| 44 |
&self, |
| 45 |
info: &vk::AccelerationStructureMemoryRequirementsInfoNV<'_>, |
| 46 |
) -> vk::MemoryRequirements2KHR<'_> { |
| 47 |
let mut requirements = Default::default(); |
| 48 |
(self.fp.get_acceleration_structure_memory_requirements_nv)( |
| 49 |
self.handle, |
| 50 |
info, |
| 51 |
&mut requirements, |
| 52 |
); |
| 53 |
requirements |
| 54 |
} |
| 55 |
|
| 56 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkBindAccelerationStructureMemoryNV.html> |
| 57 |
#[inline] |
| 58 |
pub unsafe fn bind_acceleration_structure_memory( |
| 59 |
&self, |
| 60 |
bind_info: &[vk::BindAccelerationStructureMemoryInfoNV<'_>], |
| 61 |
) -> VkResult<()> { |
| 62 |
(self.fp.bind_acceleration_structure_memory_nv)( |
| 63 |
self.handle, |
| 64 |
bind_info.len() as u32, |
| 65 |
bind_info.as_ptr(), |
| 66 |
) |
| 67 |
.result() |
| 68 |
} |
| 69 |
|
| 70 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdBuildAccelerationStructureNV.html> |
| 71 |
#[inline] |
| 72 |
pub unsafe fn cmd_build_acceleration_structure( |
| 73 |
&self, |
| 74 |
command_buffer: vk::CommandBuffer, |
| 75 |
info: &vk::AccelerationStructureInfoNV<'_>, |
| 76 |
instance_data: vk::Buffer, |
| 77 |
instance_offset: vk::DeviceSize, |
| 78 |
update: bool, |
| 79 |
dst: vk::AccelerationStructureNV, |
| 80 |
src: vk::AccelerationStructureNV, |
| 81 |
scratch: vk::Buffer, |
| 82 |
scratch_offset: vk::DeviceSize, |
| 83 |
) { |
| 84 |
(self.fp.cmd_build_acceleration_structure_nv)( |
| 85 |
command_buffer, |
| 86 |
info, |
| 87 |
instance_data, |
| 88 |
instance_offset, |
| 89 |
if update { vk::TRUE } else { vk::FALSE }, |
| 90 |
dst, |
| 91 |
src, |
| 92 |
scratch, |
| 93 |
scratch_offset, |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdCopyAccelerationStructureNV.html> |
| 98 |
#[inline] |
| 99 |
pub unsafe fn cmd_copy_acceleration_structure( |
| 100 |
&self, |
| 101 |
command_buffer: vk::CommandBuffer, |
| 102 |
dst: vk::AccelerationStructureNV, |
| 103 |
src: vk::AccelerationStructureNV, |
| 104 |
mode: vk::CopyAccelerationStructureModeNV, |
| 105 |
) { |
| 106 |
(self.fp.cmd_copy_acceleration_structure_nv)(command_buffer, dst, src, mode); |
| 107 |
} |
| 108 |
|
| 109 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdTraceRaysNV.html> |
| 110 |
#[inline] |
| 111 |
pub unsafe fn cmd_trace_rays( |
| 112 |
&self, |
| 113 |
command_buffer: vk::CommandBuffer, |
| 114 |
raygen_shader_binding_table_buffer: vk::Buffer, |
| 115 |
raygen_shader_binding_offset: vk::DeviceSize, |
| 116 |
miss_shader_binding_table_buffer: vk::Buffer, |
| 117 |
miss_shader_binding_offset: vk::DeviceSize, |
| 118 |
miss_shader_binding_stride: vk::DeviceSize, |
| 119 |
hit_shader_binding_table_buffer: vk::Buffer, |
| 120 |
hit_shader_binding_offset: vk::DeviceSize, |
| 121 |
hit_shader_binding_stride: vk::DeviceSize, |
| 122 |
callable_shader_binding_table_buffer: vk::Buffer, |
| 123 |
callable_shader_binding_offset: vk::DeviceSize, |
| 124 |
callable_shader_binding_stride: vk::DeviceSize, |
| 125 |
width: u32, |
| 126 |
height: u32, |
| 127 |
depth: u32, |
| 128 |
) { |
| 129 |
(self.fp.cmd_trace_rays_nv)( |
| 130 |
command_buffer, |
| 131 |
raygen_shader_binding_table_buffer, |
| 132 |
raygen_shader_binding_offset, |
| 133 |
miss_shader_binding_table_buffer, |
| 134 |
miss_shader_binding_offset, |
| 135 |
miss_shader_binding_stride, |
| 136 |
hit_shader_binding_table_buffer, |
| 137 |
hit_shader_binding_offset, |
| 138 |
hit_shader_binding_stride, |
| 139 |
callable_shader_binding_table_buffer, |
| 140 |
callable_shader_binding_offset, |
| 141 |
callable_shader_binding_stride, |
| 142 |
width, |
| 143 |
height, |
| 144 |
depth, |
| 145 |
); |
| 146 |
} |
| 147 |
|
| 148 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreateRayTracingPipelinesNV.html> |
| 149 |
/// |
| 150 |
/// Pipelines are created and returned as described for [Multiple Pipeline Creation]. |
| 151 |
/// |
| 152 |
/// [Multiple Pipeline Creation]: https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#pipelines-multiple |
| 153 |
#[inline] |
| 154 |
pub unsafe fn create_ray_tracing_pipelines( |
| 155 |
&self, |
| 156 |
pipeline_cache: vk::PipelineCache, |
| 157 |
create_infos: &[vk::RayTracingPipelineCreateInfoNV<'_>], |
| 158 |
allocation_callbacks: Option<&vk::AllocationCallbacks<'_>>, |
| 159 |
) -> Result<Vec<vk::Pipeline>, (Vec<vk::Pipeline>, vk::Result)> { |
| 160 |
let mut pipelines = Vec::with_capacity(create_infos.len()); |
| 161 |
let err_code = (self.fp.create_ray_tracing_pipelines_nv)( |
| 162 |
self.handle, |
| 163 |
pipeline_cache, |
| 164 |
create_infos.len() as u32, |
| 165 |
create_infos.as_ptr(), |
| 166 |
allocation_callbacks.as_raw_ptr(), |
| 167 |
pipelines.as_mut_ptr(), |
| 168 |
); |
| 169 |
pipelines.set_len(create_infos.len()); |
| 170 |
match err_code { |
| 171 |
vk::Result::SUCCESS => Ok(pipelines), |
| 172 |
_ => Err((pipelines, err_code)), |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetRayTracingShaderGroupHandlesNV.html> |
| 177 |
#[inline] |
| 178 |
pub unsafe fn get_ray_tracing_shader_group_handles( |
| 179 |
&self, |
| 180 |
pipeline: vk::Pipeline, |
| 181 |
first_group: u32, |
| 182 |
group_count: u32, |
| 183 |
data: &mut [u8], |
| 184 |
) -> VkResult<()> { |
| 185 |
(self.fp.get_ray_tracing_shader_group_handles_nv)( |
| 186 |
self.handle, |
| 187 |
pipeline, |
| 188 |
first_group, |
| 189 |
group_count, |
| 190 |
data.len(), |
| 191 |
data.as_mut_ptr().cast(), |
| 192 |
) |
| 193 |
.result() |
| 194 |
} |
| 195 |
|
| 196 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetAccelerationStructureHandleNV.html> |
| 197 |
#[inline] |
| 198 |
pub unsafe fn get_acceleration_structure_handle( |
| 199 |
&self, |
| 200 |
accel_struct: vk::AccelerationStructureNV, |
| 201 |
) -> VkResult<u64> { |
| 202 |
let mut handle = mem::MaybeUninit::<u64>::uninit(); |
| 203 |
(self.fp.get_acceleration_structure_handle_nv)( |
| 204 |
self.handle, |
| 205 |
accel_struct, |
| 206 |
mem::size_of_val(&handle), |
| 207 |
handle.as_mut_ptr().cast(), |
| 208 |
) |
| 209 |
.assume_init_on_success(handle) |
| 210 |
} |
| 211 |
|
| 212 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdWriteAccelerationStructuresPropertiesNV.html> |
| 213 |
#[inline] |
| 214 |
pub unsafe fn cmd_write_acceleration_structures_properties( |
| 215 |
&self, |
| 216 |
command_buffer: vk::CommandBuffer, |
| 217 |
structures: &[vk::AccelerationStructureNV], |
| 218 |
query_type: vk::QueryType, |
| 219 |
query_pool: vk::QueryPool, |
| 220 |
first_query: u32, |
| 221 |
) { |
| 222 |
(self.fp.cmd_write_acceleration_structures_properties_nv)( |
| 223 |
command_buffer, |
| 224 |
structures.len() as u32, |
| 225 |
structures.as_ptr(), |
| 226 |
query_type, |
| 227 |
query_pool, |
| 228 |
first_query, |
| 229 |
); |
| 230 |
} |
| 231 |
|
| 232 |
/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCompileDeferredNV.html> |
| 233 |
#[inline] |
| 234 |
pub unsafe fn compile_deferred(&self, pipeline: vk::Pipeline, shader: u32) -> VkResult<()> { |
| 235 |
(self.fp.compile_deferred_nv)(self.handle, pipeline, shader).result() |
| 236 |
} |
| 237 |
} |