From b5d433baaa815c336f19ca1302ce6d50ca297673 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 4 Mar 2021 12:18:34 +0100 Subject: [PATCH] vkd3d: Implement RTAS clone and compact copy operations. Signed-off-by: Hans-Kristian Arntzen --- libs/vkd3d/acceleration_structure.c | 49 +++++++++++++++++++++++++++++ libs/vkd3d/command.c | 15 +++++++-- libs/vkd3d/vkd3d_private.h | 4 +++ libs/vkd3d/vulkan_procs.h | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d/acceleration_structure.c b/libs/vkd3d/acceleration_structure.c index 69cc095b..2a639ba6 100644 --- a/libs/vkd3d/acceleration_structure.c +++ b/libs/vkd3d/acceleration_structure.c @@ -341,3 +341,52 @@ void vkd3d_acceleration_structure_emit_immediate_postbuild_info( vkd3d_acceleration_structure_end_barrier(list); } + +static bool convert_copy_mode( + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode, + VkCopyAccelerationStructureModeKHR *vk_mode) +{ + switch (mode) + { + case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_CLONE: + *vk_mode = VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR; + return true; + case D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_COMPACT: + *vk_mode = VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR; + return true; + default: + FIXME("Unsupported RTAS copy mode #%x.\n", mode); + return false; + } +} + +void vkd3d_acceleration_structure_copy( + struct d3d12_command_list *list, + D3D12_GPU_VIRTUAL_ADDRESS dst, D3D12_GPU_VIRTUAL_ADDRESS src, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) +{ + const struct vkd3d_vk_device_procs *vk_procs = &list->device->vk_procs; + VkAccelerationStructureKHR dst_as, src_as; + VkCopyAccelerationStructureInfoKHR info; + + dst_as = vkd3d_va_map_place_acceleration_structure(&list->device->memory_allocator.va_map, list->device, dst); + if (dst_as == VK_NULL_HANDLE) + { + ERR("Invalid dst address #%"PRIx64" for RTAS copy.\n", dst); + return; + } + + src_as = vkd3d_va_map_place_acceleration_structure(&list->device->memory_allocator.va_map, list->device, src); + if (src_as == VK_NULL_HANDLE) + { + ERR("Invalid src address #%"PRIx64" for RTAS copy.\n", src); + return; + } + + info.sType = VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_INFO_KHR; + info.pNext = NULL; + info.dst = dst_as; + info.src = src_as; + if (convert_copy_mode(mode, &info.mode)) + VK_CALL(vkCmdCopyAccelerationStructureKHR(list->vk_command_buffer, &info)); +} diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index f91dae78..9996f6ec 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -8334,8 +8334,19 @@ static void STDMETHODCALLTYPE d3d12_command_list_CopyRaytracingAccelerationStruc D3D12_GPU_VIRTUAL_ADDRESS dst_data, D3D12_GPU_VIRTUAL_ADDRESS src_data, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode) { - FIXME("iface %p, dst_data %#"PRIx64", src_data %#"PRIx64", mode %u stub!\n", - iface, dst_data, src_data, mode); + struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList(iface); + + TRACE("iface %p, dst_data %#"PRIx64", src_data %#"PRIx64", mode %u\n", + iface, dst_data, src_data, mode); + + if (!d3d12_device_supports_ray_tracing_tier_1_0(list->device)) + { + WARN("Acceleration structure is not supported. Calling this is invalid.\n"); + return; + } + + d3d12_command_list_end_current_render_pass(list, true); + vkd3d_acceleration_structure_copy(list, dst_data, src_data, mode); } static void STDMETHODCALLTYPE d3d12_command_list_SetPipelineState1(d3d12_command_list_iface *iface, diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 176c855a..10b891f2 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -2856,6 +2856,10 @@ void vkd3d_acceleration_structure_emit_immediate_postbuild_info( struct d3d12_command_list *list, uint32_t count, const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC *desc, VkAccelerationStructureKHR vk_acceleration_structure); +void vkd3d_acceleration_structure_copy( + struct d3d12_command_list *list, + D3D12_GPU_VIRTUAL_ADDRESS dst, D3D12_GPU_VIRTUAL_ADDRESS src, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE mode); #define VKD3D_VENDOR_ID_NVIDIA 0x10DE #define VKD3D_VENDOR_ID_AMD 0x1002 diff --git a/libs/vkd3d/vulkan_procs.h b/libs/vkd3d/vulkan_procs.h index ee74c6a6..f915c30f 100644 --- a/libs/vkd3d/vulkan_procs.h +++ b/libs/vkd3d/vulkan_procs.h @@ -212,6 +212,7 @@ VK_DEVICE_EXT_PFN(vkDestroyAccelerationStructureKHR) VK_DEVICE_EXT_PFN(vkGetAccelerationStructureDeviceAddressKHR) VK_DEVICE_EXT_PFN(vkCmdBuildAccelerationStructuresKHR) VK_DEVICE_EXT_PFN(vkCmdWriteAccelerationStructuresPropertiesKHR) +VK_DEVICE_EXT_PFN(vkCmdCopyAccelerationStructureKHR) /* VK_KHR_fragment_shading_rate */ VK_INSTANCE_PFN(vkGetPhysicalDeviceFragmentShadingRatesKHR)