ray_tracing_pipeline: Pass SBT regions as reference instead of slice (#350)

The API for vkCmdTraceRaysKHR mandates a single non-null pointer per SBT
region to a VkStridedDeviceAddressRegionKHR. While providing more than
one such region isn't harmful, passing a slice of length 0 will cause
reads in uninitialized memory and undefined behaviour.

Converting these parameters from slices to references rids the
unnecessary confusion and prevents zero regions from being passed.
This commit is contained in:
Marijn Suijten 2020-12-29 12:09:46 +01:00 committed by GitHub
parent 1661b37cd2
commit 84624fddd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,20 +39,20 @@ impl RayTracingPipeline {
pub unsafe fn 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],
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,
) {
self.ray_tracing_fn.cmd_trace_rays_khr(
command_buffer,
raygen_shader_binding_tables.as_ptr(),
miss_shader_binding_tables.as_ptr(),
hit_shader_binding_tables.as_ptr(),
callable_shader_binding_tables.as_ptr(),
raygen_shader_binding_tables as *const _,
miss_shader_binding_tables as *const _,
hit_shader_binding_tables as *const _,
callable_shader_binding_tables as *const _,
width,
height,
depth,