1 use crate::prelude::*; 2 use crate::vk; 3 use crate::RawPtr; 4 use crate::{Device, Instance}; 5 use std::ffi::CStr; 6 use std::mem; 7 8 #[derive(Clone)] 9 pub struct RayTracingPipeline { 10 handle: vk::Device, 11 ray_tracing_fn: vk::KhrRayTracingPipelineFn, 12 } 13 14 impl RayTracingPipeline { new(instance: &Instance, device: &Device) -> Self15 pub fn new(instance: &Instance, device: &Device) -> Self { 16 let ray_tracing_fn = vk::KhrRayTracingPipelineFn::load(|name| unsafe { 17 mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) 18 }); 19 Self { 20 handle: device.handle(), 21 ray_tracing_fn, 22 } 23 } 24 get_properties( instance: &Instance, pdevice: vk::PhysicalDevice, ) -> vk::PhysicalDeviceRayTracingPipelinePropertiesKHR25 pub unsafe fn get_properties( 26 instance: &Instance, 27 pdevice: vk::PhysicalDevice, 28 ) -> vk::PhysicalDeviceRayTracingPipelinePropertiesKHR { 29 let mut props_rt = vk::PhysicalDeviceRayTracingPipelinePropertiesKHR::default(); 30 { 31 let mut props = vk::PhysicalDeviceProperties2::builder().push_next(&mut props_rt); 32 instance.get_physical_device_properties2(pdevice, &mut props); 33 } 34 props_rt 35 } 36 37 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdTraceRaysKHR.html>"] cmd_trace_rays( &self, command_buffer: vk::CommandBuffer, raygen_shader_binding_tables: &vk::StridedDeviceAddressRegionKHR, miss_shader_binding_tables: &vk::StridedDeviceAddressRegionKHR, hit_shader_binding_tables: &vk::StridedDeviceAddressRegionKHR, callable_shader_binding_tables: &vk::StridedDeviceAddressRegionKHR, width: u32, height: u32, depth: u32, )38 pub unsafe fn cmd_trace_rays( 39 &self, 40 command_buffer: vk::CommandBuffer, 41 raygen_shader_binding_tables: &vk::StridedDeviceAddressRegionKHR, 42 miss_shader_binding_tables: &vk::StridedDeviceAddressRegionKHR, 43 hit_shader_binding_tables: &vk::StridedDeviceAddressRegionKHR, 44 callable_shader_binding_tables: &vk::StridedDeviceAddressRegionKHR, 45 width: u32, 46 height: u32, 47 depth: u32, 48 ) { 49 self.ray_tracing_fn.cmd_trace_rays_khr( 50 command_buffer, 51 raygen_shader_binding_tables as *const _, 52 miss_shader_binding_tables as *const _, 53 hit_shader_binding_tables as *const _, 54 callable_shader_binding_tables as *const _, 55 width, 56 height, 57 depth, 58 ); 59 } 60 61 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateRayTracingPipelinesKHR.html>"] create_ray_tracing_pipelines( &self, deferred_operation: vk::DeferredOperationKHR, pipeline_cache: vk::PipelineCache, create_info: &[vk::RayTracingPipelineCreateInfoKHR], allocation_callbacks: Option<&vk::AllocationCallbacks>, ) -> VkResult<Vec<vk::Pipeline>>62 pub unsafe fn create_ray_tracing_pipelines( 63 &self, 64 deferred_operation: vk::DeferredOperationKHR, 65 pipeline_cache: vk::PipelineCache, 66 create_info: &[vk::RayTracingPipelineCreateInfoKHR], 67 allocation_callbacks: Option<&vk::AllocationCallbacks>, 68 ) -> VkResult<Vec<vk::Pipeline>> { 69 let mut pipelines = vec![mem::zeroed(); create_info.len()]; 70 self.ray_tracing_fn 71 .create_ray_tracing_pipelines_khr( 72 self.handle, 73 deferred_operation, 74 pipeline_cache, 75 create_info.len() as u32, 76 create_info.as_ptr(), 77 allocation_callbacks.as_raw_ptr(), 78 pipelines.as_mut_ptr(), 79 ) 80 .result_with_success(pipelines) 81 } 82 83 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetRayTracingShaderGroupHandlesKHR.html>"] get_ray_tracing_shader_group_handles( &self, pipeline: vk::Pipeline, first_group: u32, group_count: u32, data_size: usize, ) -> VkResult<Vec<u8>>84 pub unsafe fn get_ray_tracing_shader_group_handles( 85 &self, 86 pipeline: vk::Pipeline, 87 first_group: u32, 88 group_count: u32, 89 data_size: usize, 90 ) -> VkResult<Vec<u8>> { 91 let mut data = Vec::<u8>::with_capacity(data_size); 92 let err_code = self 93 .ray_tracing_fn 94 .get_ray_tracing_shader_group_handles_khr( 95 self.handle, 96 pipeline, 97 first_group, 98 group_count, 99 data_size, 100 data.as_mut_ptr() as *mut std::ffi::c_void, 101 ); 102 data.set_len(data_size); 103 err_code.result_with_success(data) 104 } 105 106 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetRayTracingCaptureReplayShaderGroupHandlesKHR.html>"] get_ray_tracing_capture_replay_shader_group_handles( &self, pipeline: vk::Pipeline, first_group: u32, group_count: u32, data_size: usize, ) -> VkResult<Vec<u8>>107 pub unsafe fn get_ray_tracing_capture_replay_shader_group_handles( 108 &self, 109 pipeline: vk::Pipeline, 110 first_group: u32, 111 group_count: u32, 112 data_size: usize, 113 ) -> VkResult<Vec<u8>> { 114 let mut data: Vec<u8> = Vec::with_capacity(data_size); 115 116 self.ray_tracing_fn 117 .get_ray_tracing_capture_replay_shader_group_handles_khr( 118 self.handle, 119 pipeline, 120 first_group, 121 group_count, 122 data_size, 123 data.as_mut_ptr() as *mut _, 124 ) 125 .result_with_success(data) 126 } 127 128 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdTraceRaysIndirectKHR.html>"] cmd_trace_rays_indirect( &self, command_buffer: vk::CommandBuffer, raygen_shader_binding_table: &[vk::StridedDeviceAddressRegionKHR], miss_shader_binding_table: &[vk::StridedDeviceAddressRegionKHR], hit_shader_binding_table: &[vk::StridedDeviceAddressRegionKHR], callable_shader_binding_table: &[vk::StridedDeviceAddressRegionKHR], indirect_device_address: vk::DeviceAddress, )129 pub unsafe fn cmd_trace_rays_indirect( 130 &self, 131 command_buffer: vk::CommandBuffer, 132 raygen_shader_binding_table: &[vk::StridedDeviceAddressRegionKHR], 133 miss_shader_binding_table: &[vk::StridedDeviceAddressRegionKHR], 134 hit_shader_binding_table: &[vk::StridedDeviceAddressRegionKHR], 135 callable_shader_binding_table: &[vk::StridedDeviceAddressRegionKHR], 136 indirect_device_address: vk::DeviceAddress, 137 ) { 138 self.ray_tracing_fn.cmd_trace_rays_indirect_khr( 139 command_buffer, 140 raygen_shader_binding_table.as_ptr(), 141 miss_shader_binding_table.as_ptr(), 142 hit_shader_binding_table.as_ptr(), 143 callable_shader_binding_table.as_ptr(), 144 indirect_device_address, 145 ); 146 } 147 148 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetRayTracingShaderGroupStackSizeKHR.html>"] get_ray_tracing_shader_group_stack_size( &self, pipeline: vk::Pipeline, group: u32, group_shader: vk::ShaderGroupShaderKHR, ) -> vk::DeviceSize149 pub unsafe fn get_ray_tracing_shader_group_stack_size( 150 &self, 151 pipeline: vk::Pipeline, 152 group: u32, 153 group_shader: vk::ShaderGroupShaderKHR, 154 ) -> vk::DeviceSize { 155 self.ray_tracing_fn 156 .get_ray_tracing_shader_group_stack_size_khr(self.handle, pipeline, group, group_shader) 157 } 158 159 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdSetRayTracingPipelineStackSizeKHR.html>"] cmd_set_ray_tracing_pipeline_stack_size( &self, command_buffer: vk::CommandBuffer, pipeline_stack_size: u32, )160 pub unsafe fn cmd_set_ray_tracing_pipeline_stack_size( 161 &self, 162 command_buffer: vk::CommandBuffer, 163 pipeline_stack_size: u32, 164 ) { 165 self.ray_tracing_fn 166 .cmd_set_ray_tracing_pipeline_stack_size_khr(command_buffer, pipeline_stack_size); 167 } 168 name() -> &'static CStr169 pub fn name() -> &'static CStr { 170 vk::KhrRayTracingPipelineFn::name() 171 } 172 fp(&self) -> &vk::KhrRayTracingPipelineFn173 pub fn fp(&self) -> &vk::KhrRayTracingPipelineFn { 174 &self.ray_tracing_fn 175 } 176 device(&self) -> vk::Device177 pub fn device(&self) -> vk::Device { 178 self.handle 179 } 180 } 181