From fa70f8fa87b81ee7f0fe7b00ffc8d382d1ecd296 Mon Sep 17 00:00:00 2001 From: Cam Mannett Date: Tue, 27 Feb 2024 10:40:38 +0000 Subject: [PATCH] Ray Query API interception and serialisation Ignoring acceleration structure host-build for now, and by extension deferred operation handle functions are pass-though (i.e. ignored on replay). --- renderdoc/api/replay/rdcarray.h | 2 +- renderdoc/api/replay/replay_enums.h | 7 + renderdoc/driver/vulkan/vk_common.h | 61 ++- renderdoc/driver/vulkan/vk_core.cpp | 14 + renderdoc/driver/vulkan/vk_core.h | 66 +++ renderdoc/driver/vulkan/vk_debug.cpp | 8 + renderdoc/driver/vulkan/vk_debug.h | 1 + renderdoc/driver/vulkan/vk_hookset_defs.h | 90 +++- renderdoc/driver/vulkan/vk_info.cpp | 10 + renderdoc/driver/vulkan/vk_info.h | 13 + renderdoc/driver/vulkan/vk_initstate.cpp | 3 +- renderdoc/driver/vulkan/vk_next_chains.cpp | 89 +++- renderdoc/driver/vulkan/vk_resources.cpp | 3 + renderdoc/driver/vulkan/vk_resources.h | 15 + renderdoc/driver/vulkan/vk_serialise.cpp | 485 +++++++++++++++++- renderdoc/driver/vulkan/vk_stringise.cpp | 139 ++++- .../driver/vulkan/wrappers/vk_cmd_funcs.cpp | 406 +++++++++++++++ .../driver/vulkan/wrappers/vk_get_funcs.cpp | 40 ++ .../driver/vulkan/wrappers/vk_misc_funcs.cpp | 42 +- .../vulkan/wrappers/vk_resource_funcs.cpp | 122 +++++ renderdoc/serialise/serialiser.h | 72 +++ renderdoc/serialise/serialiser_tests.cpp | 178 +++++++ 22 files changed, 1818 insertions(+), 48 deletions(-) diff --git a/renderdoc/api/replay/rdcarray.h b/renderdoc/api/replay/rdcarray.h index 22f490a5bf..61e6828fe1 100644 --- a/renderdoc/api/replay/rdcarray.h +++ b/renderdoc/api/replay/rdcarray.h @@ -327,7 +327,7 @@ struct rdcarray { const size_t lastIdx = size(); reserve(size() + 1); - new(elems + lastIdx) T(std::forward(args)...); + new(elems + lastIdx) T(std::forward(args)...); setUsedCount(usedCount + 1); } diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index cf850b9897..f2dcab1a4a 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -657,6 +657,11 @@ API-specific concepts. An object which pools together other objects in an opaque way, either for runtime allocation and deallocation, or for caching purposes. + +.. data:: AccelerationStructure + + A structure used to carry implementation-defined spatial partitioning data and related + information, used to accelerate geometry intersection queries (e.g. for ray tracing). )"); enum class ResourceType : uint32_t { @@ -683,6 +688,8 @@ enum class ResourceType : uint32_t Query, Sync, Pool, + + AccelerationStructure, }; DECLARE_REFLECTION_ENUM(ResourceType); diff --git a/renderdoc/driver/vulkan/vk_common.h b/renderdoc/driver/vulkan/vk_common.h index 84914c9e7a..1e8b8fa8a3 100644 --- a/renderdoc/driver/vulkan/vk_common.h +++ b/renderdoc/driver/vulkan/vk_common.h @@ -981,6 +981,12 @@ enum class VulkanChunk : uint32_t vkCmdDrawMeshTasksEXT, vkCmdDrawMeshTasksIndirectEXT, vkCmdDrawMeshTasksIndirectCountEXT, + vkCmdBuildAccelerationStructuresIndirectKHR, + vkCmdBuildAccelerationStructuresKHR, + vkCmdCopyAccelerationStructureKHR, + vkCmdCopyAccelerationStructureToMemoryKHR, + vkCmdCopyMemoryToAccelerationStructureKHR, + vkCreateAccelerationStructureKHR, Max, }; @@ -1019,7 +1025,8 @@ DECLARE_REFLECTION_ENUM(VulkanChunk); SERIALISE_HANDLE(VkSwapchainKHR) \ SERIALISE_HANDLE(VkSurfaceKHR) \ SERIALISE_HANDLE(VkDescriptorUpdateTemplate) \ - SERIALISE_HANDLE(VkSamplerYcbcrConversion) + SERIALISE_HANDLE(VkSamplerYcbcrConversion) \ + SERIALISE_HANDLE(VkAccelerationStructureKHR) #define SERIALISE_HANDLE(type) DECLARE_REFLECTION_STRUCT(type) @@ -1028,6 +1035,15 @@ SERIALISE_VK_HANDLES(); // declare reflect-able types // pNext structs - always have deserialise for the next chain +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureBuildGeometryInfoKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureBuildSizesInfoKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureCreateInfoKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureDeviceAddressInfoKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureGeometryAabbsDataKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureGeometryInstancesDataKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureGeometryKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureGeometryTrianglesDataKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureVersionInfoKHR); DECLARE_REFLECTION_STRUCT(VkAcquireNextImageInfoKHR); DECLARE_REFLECTION_STRUCT(VkAcquireProfilingLockInfoKHR); DECLARE_REFLECTION_STRUCT(VkApplicationInfo); @@ -1064,11 +1080,14 @@ DECLARE_REFLECTION_STRUCT(VkCommandBufferSubmitInfo); DECLARE_REFLECTION_STRUCT(VkCommandPoolCreateInfo); DECLARE_REFLECTION_STRUCT(VkComputePipelineCreateInfo); DECLARE_REFLECTION_STRUCT(VkConditionalRenderingBeginInfoEXT); +DECLARE_REFLECTION_STRUCT(VkCopyAccelerationStructureInfoKHR); +DECLARE_REFLECTION_STRUCT(VkCopyAccelerationStructureToMemoryInfoKHR); DECLARE_REFLECTION_STRUCT(VkCopyBufferInfo2); DECLARE_REFLECTION_STRUCT(VkCopyBufferToImageInfo2); DECLARE_REFLECTION_STRUCT(VkCopyDescriptorSet); DECLARE_REFLECTION_STRUCT(VkCopyImageInfo2); DECLARE_REFLECTION_STRUCT(VkCopyImageToBufferInfo2); +DECLARE_REFLECTION_STRUCT(VkCopyMemoryToAccelerationStructureInfoKHR); DECLARE_REFLECTION_STRUCT(VkDebugMarkerMarkerInfoEXT); DECLARE_REFLECTION_STRUCT(VkDebugMarkerObjectNameInfoEXT); DECLARE_REFLECTION_STRUCT(VkDebugMarkerObjectTagInfoEXT); @@ -1187,6 +1206,8 @@ DECLARE_REFLECTION_STRUCT(VkPerformanceQuerySubmitInfoKHR); DECLARE_REFLECTION_STRUCT(VkPhysicalDevice16BitStorageFeatures); DECLARE_REFLECTION_STRUCT(VkPhysicalDevice4444FormatsFeaturesEXT); DECLARE_REFLECTION_STRUCT(VkPhysicalDevice8BitStorageFeatures); +DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceAccelerationStructureFeaturesKHR); +DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceAccelerationStructurePropertiesKHR); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceASTCDecodeFeaturesEXT); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT); @@ -1280,6 +1301,7 @@ DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceProtectedMemoryFeatures); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceProtectedMemoryProperties); DECLARE_REFLECTION_STRUCT(VkPhysicalDevicePushDescriptorPropertiesKHR); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT); +DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceRayQueryFeaturesKHR); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceRobustness2FeaturesEXT); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceRobustness2PropertiesEXT); @@ -1445,8 +1467,18 @@ DECLARE_REFLECTION_STRUCT(VkValidationFlagsEXT); DECLARE_REFLECTION_STRUCT(VkVertexInputAttributeDescription2EXT); DECLARE_REFLECTION_STRUCT(VkVertexInputBindingDescription2EXT); DECLARE_REFLECTION_STRUCT(VkWriteDescriptorSet); +DECLARE_REFLECTION_STRUCT(VkWriteDescriptorSetAccelerationStructureKHR); DECLARE_REFLECTION_STRUCT(VkWriteDescriptorSetInlineUniformBlock); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureBuildGeometryInfoKHR); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureBuildSizesInfoKHR); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureCreateInfoKHR); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureDeviceAddressInfoKHR); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureGeometryAabbsDataKHR); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureGeometryInstancesDataKHR); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureGeometryKHR); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureGeometryTrianglesDataKHR); +DECLARE_DESERIALISE_TYPE(VkAccelerationStructureVersionInfoKHR); DECLARE_DESERIALISE_TYPE(VkAcquireNextImageInfoKHR); DECLARE_DESERIALISE_TYPE(VkAcquireProfilingLockInfoKHR); DECLARE_DESERIALISE_TYPE(VkApplicationInfo); @@ -1481,11 +1513,14 @@ DECLARE_DESERIALISE_TYPE(VkCommandBufferSubmitInfo); DECLARE_DESERIALISE_TYPE(VkCommandPoolCreateInfo); DECLARE_DESERIALISE_TYPE(VkComputePipelineCreateInfo); DECLARE_DESERIALISE_TYPE(VkConditionalRenderingBeginInfoEXT); +DECLARE_DESERIALISE_TYPE(VkCopyAccelerationStructureInfoKHR); +DECLARE_DESERIALISE_TYPE(VkCopyAccelerationStructureToMemoryInfoKHR); DECLARE_DESERIALISE_TYPE(VkCopyBufferInfo2); DECLARE_DESERIALISE_TYPE(VkCopyBufferToImageInfo2); DECLARE_DESERIALISE_TYPE(VkCopyDescriptorSet); DECLARE_DESERIALISE_TYPE(VkCopyImageInfo2); DECLARE_DESERIALISE_TYPE(VkCopyImageToBufferInfo2); +DECLARE_DESERIALISE_TYPE(VkCopyMemoryToAccelerationStructureInfoKHR); DECLARE_DESERIALISE_TYPE(VkDebugMarkerMarkerInfoEXT); DECLARE_DESERIALISE_TYPE(VkDebugMarkerObjectNameInfoEXT); DECLARE_DESERIALISE_TYPE(VkDebugMarkerObjectTagInfoEXT); @@ -1602,6 +1637,8 @@ DECLARE_DESERIALISE_TYPE(VkPerformanceQuerySubmitInfoKHR); DECLARE_DESERIALISE_TYPE(VkPhysicalDevice16BitStorageFeatures); DECLARE_DESERIALISE_TYPE(VkPhysicalDevice4444FormatsFeaturesEXT); DECLARE_DESERIALISE_TYPE(VkPhysicalDevice8BitStorageFeatures); +DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceAccelerationStructureFeaturesKHR); +DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceAccelerationStructurePropertiesKHR); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceASTCDecodeFeaturesEXT); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT); @@ -1693,6 +1730,7 @@ DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceProtectedMemoryFeatures); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceProtectedMemoryProperties); DECLARE_DESERIALISE_TYPE(VkPhysicalDevicePushDescriptorPropertiesKHR); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT); +DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceRayQueryFeaturesKHR); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceRobustness2FeaturesEXT); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceRobustness2PropertiesEXT); @@ -1855,9 +1893,14 @@ DECLARE_DESERIALISE_TYPE(VkValidationFlagsEXT); DECLARE_DESERIALISE_TYPE(VkVertexInputAttributeDescription2EXT); DECLARE_DESERIALISE_TYPE(VkVertexInputBindingDescription2EXT); DECLARE_DESERIALISE_TYPE(VkWriteDescriptorSet); +DECLARE_DESERIALISE_TYPE(VkWriteDescriptorSetAccelerationStructureKHR); DECLARE_DESERIALISE_TYPE(VkWriteDescriptorSetInlineUniformBlock); // plain structs with no next chain +DECLARE_REFLECTION_STRUCT(VkAabbPositionsKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureBuildRangeInfoKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureGeometryDataKHR); +DECLARE_REFLECTION_STRUCT(VkAccelerationStructureInstanceKHR); DECLARE_REFLECTION_STRUCT(VkAllocationCallbacks); DECLARE_REFLECTION_STRUCT(VkAttachmentDescription); DECLARE_REFLECTION_STRUCT(VkAttachmentReference); @@ -1876,6 +1919,8 @@ DECLARE_REFLECTION_STRUCT(VkDescriptorImageInfo); DECLARE_REFLECTION_STRUCT(VkDescriptorPoolSize); DECLARE_REFLECTION_STRUCT(VkDescriptorSetLayoutBinding); DECLARE_REFLECTION_STRUCT(VkDescriptorUpdateTemplateEntry); +DECLARE_REFLECTION_STRUCT(VkDeviceOrHostAddressConstKHR); +DECLARE_REFLECTION_STRUCT(VkDeviceOrHostAddressKHR); DECLARE_REFLECTION_STRUCT(VkDispatchIndirectCommand); DECLARE_REFLECTION_STRUCT(VkDisplayModeParametersKHR); DECLARE_REFLECTION_STRUCT(VkDisplayModePropertiesKHR); @@ -1932,12 +1977,16 @@ DECLARE_REFLECTION_STRUCT(VkSubpassDependency); DECLARE_REFLECTION_STRUCT(VkSubpassDescription); DECLARE_REFLECTION_STRUCT(VkSurfaceCapabilitiesKHR); DECLARE_REFLECTION_STRUCT(VkSurfaceFormatKHR); +DECLARE_REFLECTION_STRUCT(VkTransformMatrixKHR); DECLARE_REFLECTION_STRUCT(VkVertexInputAttributeDescription); DECLARE_REFLECTION_STRUCT(VkVertexInputBindingDescription); DECLARE_REFLECTION_STRUCT(VkVertexInputBindingDivisorDescriptionEXT); DECLARE_REFLECTION_STRUCT(VkViewport); DECLARE_REFLECTION_STRUCT(VkXYColorEXT); +// rdcarray serialisation is generic but the stringification is not +DECLARE_STRINGISE_TYPE(rdcarray); + DECLARE_DESERIALISE_TYPE(VkDescriptorSetLayoutBinding); DECLARE_DESERIALISE_TYPE(VkPresentRegionKHR); DECLARE_DESERIALISE_TYPE(VkSparseBufferMemoryBindInfo); @@ -2033,6 +2082,10 @@ enum VkFormatFeatureFlagBits2 : uint64_t // enums +DECLARE_REFLECTION_ENUM(VkAccelerationStructureBuildTypeKHR); +DECLARE_REFLECTION_ENUM(VkAccelerationStructureCompatibilityKHR); +DECLARE_REFLECTION_ENUM(VkAccelerationStructureCreateFlagBitsKHR); +DECLARE_REFLECTION_ENUM(VkAccelerationStructureTypeKHR); DECLARE_REFLECTION_ENUM(VkAccessFlagBits); DECLARE_REFLECTION_ENUM(VkAccessFlagBits2); DECLARE_REFLECTION_ENUM(VkAcquireProfilingLockFlagBitsKHR); @@ -2044,6 +2097,8 @@ DECLARE_REFLECTION_ENUM(VkBlendOp); DECLARE_REFLECTION_ENUM(VkBorderColor); DECLARE_REFLECTION_ENUM(VkBufferCreateFlagBits); DECLARE_REFLECTION_ENUM(VkBufferUsageFlagBits); +DECLARE_REFLECTION_ENUM(VkBuildAccelerationStructureFlagBitsKHR); +DECLARE_REFLECTION_ENUM(VkBuildAccelerationStructureModeKHR); DECLARE_REFLECTION_ENUM(VkChromaLocation); DECLARE_REFLECTION_ENUM(VkColorComponentFlagBits); DECLARE_REFLECTION_ENUM(VkColorSpaceKHR); @@ -2056,6 +2111,7 @@ DECLARE_REFLECTION_ENUM(VkComponentSwizzle); DECLARE_REFLECTION_ENUM(VkCompositeAlphaFlagBitsKHR); DECLARE_REFLECTION_ENUM(VkConditionalRenderingFlagBitsEXT); DECLARE_REFLECTION_ENUM(VkConservativeRasterizationModeEXT); +DECLARE_REFLECTION_ENUM(VkCopyAccelerationStructureModeKHR); DECLARE_REFLECTION_ENUM(VkCullModeFlagBits); DECLARE_REFLECTION_ENUM(VkDebugReportFlagBitsEXT); DECLARE_REFLECTION_ENUM(VkDebugUtilsMessageSeverityFlagBitsEXT); @@ -2092,6 +2148,9 @@ DECLARE_REFLECTION_ENUM(VkFormatFeatureFlagBits); DECLARE_REFLECTION_ENUM(VkFormatFeatureFlagBits2); DECLARE_REFLECTION_ENUM(VkFragmentShadingRateCombinerOpKHR); DECLARE_REFLECTION_ENUM(VkFramebufferCreateFlagBits); +DECLARE_REFLECTION_ENUM(VkGeometryFlagBitsKHR); +DECLARE_REFLECTION_ENUM(VkGeometryInstanceFlagBitsKHR); +DECLARE_REFLECTION_ENUM(VkGeometryTypeKHR); DECLARE_REFLECTION_ENUM(VkGraphicsPipelineLibraryFlagBitsEXT); DECLARE_REFLECTION_ENUM(VkFrontFace); DECLARE_REFLECTION_ENUM(VkImageAspectFlagBits); diff --git a/renderdoc/driver/vulkan/vk_core.cpp b/renderdoc/driver/vulkan/vk_core.cpp index 6c9943e498..71e66f127b 100644 --- a/renderdoc/driver/vulkan/vk_core.cpp +++ b/renderdoc/driver/vulkan/vk_core.cpp @@ -3989,6 +3989,20 @@ bool WrappedVulkan::ProcessChunk(ReadSerialiser &ser, VulkanChunk chunk) return Serialise_vkCmdSetTessellationDomainOriginEXT(ser, VK_NULL_HANDLE, VK_TESSELLATION_DOMAIN_ORIGIN_MAX_ENUM); + case VulkanChunk::vkCmdBuildAccelerationStructuresIndirectKHR: + return Serialise_vkCmdBuildAccelerationStructuresIndirectKHR(ser, VK_NULL_HANDLE, 0, NULL, + NULL, NULL, NULL); + case VulkanChunk::vkCmdBuildAccelerationStructuresKHR: + return Serialise_vkCmdBuildAccelerationStructuresKHR(ser, VK_NULL_HANDLE, 0, NULL, NULL); + case VulkanChunk::vkCmdCopyAccelerationStructureKHR: + return Serialise_vkCmdCopyAccelerationStructureKHR(ser, VK_NULL_HANDLE, NULL); + case VulkanChunk::vkCmdCopyAccelerationStructureToMemoryKHR: + return Serialise_vkCmdCopyAccelerationStructureToMemoryKHR(ser, VK_NULL_HANDLE, NULL); + case VulkanChunk::vkCmdCopyMemoryToAccelerationStructureKHR: + return Serialise_vkCmdCopyMemoryToAccelerationStructureKHR(ser, VK_NULL_HANDLE, NULL); + case VulkanChunk::vkCreateAccelerationStructureKHR: + return Serialise_vkCreateAccelerationStructureKHR(ser, VK_NULL_HANDLE, NULL, NULL, NULL); + // chunks that are reserved but not yet serialised case VulkanChunk::vkResetCommandPool: case VulkanChunk::vkCreateDepthTargetView: diff --git a/renderdoc/driver/vulkan/vk_core.h b/renderdoc/driver/vulkan/vk_core.h index 854ba15103..6ef8fb9baa 100644 --- a/renderdoc/driver/vulkan/vk_core.h +++ b/renderdoc/driver/vulkan/vk_core.h @@ -2812,4 +2812,70 @@ class WrappedVulkan : public IFrameCapturer VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); + + // VK_KHR_deferred_host_operations + VkResult vkCreateDeferredOperationKHR(VkDevice device, const VkAllocationCallbacks *pAllocator, + VkDeferredOperationKHR *pDeferredOperation); + VkResult vkDeferredOperationJoinKHR(VkDevice device, VkDeferredOperationKHR operation); + void vkDestroyDeferredOperationKHR(VkDevice device, VkDeferredOperationKHR operation, + const VkAllocationCallbacks *pAllocator); + uint32_t vkGetDeferredOperationMaxConcurrencyKHR(VkDevice device, VkDeferredOperationKHR operation); + VkResult vkGetDeferredOperationResultKHR(VkDevice device, VkDeferredOperationKHR operation); + + // VK_KHR_acceleration_structure + VkResult vkBuildAccelerationStructuresKHR( + VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos); + IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdBuildAccelerationStructuresIndirectKHR, + VkCommandBuffer commandBuffer, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkDeviceAddress *pIndirectDeviceAddresses, + const uint32_t *pIndirectStrides, + const uint32_t *const *ppMaxPrimitiveCounts); + IMPLEMENT_FUNCTION_SERIALISED( + void, vkCmdBuildAccelerationStructuresKHR, VkCommandBuffer commandBuffer, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos); + VkResult vkCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, + const VkCopyAccelerationStructureInfoKHR *pInfo); + VkResult vkCopyAccelerationStructureToMemoryKHR( + VkDevice device, VkDeferredOperationKHR deferredOperation, + const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo); + VkResult vkCopyMemoryToAccelerationStructureKHR( + VkDevice device, VkDeferredOperationKHR deferredOperation, + const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo); + IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdCopyAccelerationStructureKHR, + VkCommandBuffer commandBuffer, + const VkCopyAccelerationStructureInfoKHR *pInfo); + IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdCopyAccelerationStructureToMemoryKHR, + VkCommandBuffer commandBuffer, + const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo); + IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdCopyMemoryToAccelerationStructureKHR, + VkCommandBuffer commandBuffer, + const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo); + void vkCmdWriteAccelerationStructuresPropertiesKHR( + VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, + const VkAccelerationStructureKHR *pAccelerationStructures, VkQueryType queryType, + VkQueryPool queryPool, uint32_t firstQuery); + IMPLEMENT_FUNCTION_SERIALISED(VkResult, vkCreateAccelerationStructureKHR, VkDevice device, + const VkAccelerationStructureCreateInfoKHR *pCreateInfo, + const VkAllocationCallbacks *pAllocator, + VkAccelerationStructureKHR *pAccelerationStructure); + IMPLEMENT_FUNCTION_SERIALISED(void, vkDestroyAccelerationStructureKHR, VkDevice device, + VkAccelerationStructureKHR accelerationStructure, + const VkAllocationCallbacks *pAllocator); + void vkGetAccelerationStructureBuildSizesKHR( + VkDevice device, VkAccelerationStructureBuildTypeKHR buildType, + const VkAccelerationStructureBuildGeometryInfoKHR *pBuildInfo, + const uint32_t *pMaxPrimitiveCounts, VkAccelerationStructureBuildSizesInfoKHR *pSizeInfo); + VkDeviceAddress vkGetAccelerationStructureDeviceAddressKHR( + VkDevice device, const VkAccelerationStructureDeviceAddressInfoKHR *pInfo); + void vkGetDeviceAccelerationStructureCompatibilityKHR( + VkDevice device, const VkAccelerationStructureVersionInfoKHR *pVersionInfo, + VkAccelerationStructureCompatibilityKHR *pCompatibility); + VkResult vkWriteAccelerationStructuresPropertiesKHR( + VkDevice device, uint32_t accelerationStructureCount, + const VkAccelerationStructureKHR *pAccelerationStructures, VkQueryType queryType, + size_t dataSize, void *pData, size_t stride); }; diff --git a/renderdoc/driver/vulkan/vk_debug.cpp b/renderdoc/driver/vulkan/vk_debug.cpp index 97d5de5867..8fd4e7ad2a 100644 --- a/renderdoc/driver/vulkan/vk_debug.cpp +++ b/renderdoc/driver/vulkan/vk_debug.cpp @@ -1798,6 +1798,14 @@ const VulkanCreationInfo::PipelineLayout &VulkanDebugManager::GetPipelineLayoutI return it->second; } +const VulkanCreationInfo::AccelerationStructure &VulkanDebugManager::GetAccelerationStructureInfo( + ResourceId as) const +{ + auto it = m_pDriver->m_CreationInfo.m_AccelerationStructure.find(as); + RDCASSERT(it != m_pDriver->m_CreationInfo.m_AccelerationStructure.end()); + return it->second; +} + const DescSetLayout &VulkanDebugManager::GetDescSetLayout(ResourceId dsl) const { auto it = m_pDriver->m_CreationInfo.m_DescSetLayout.find(dsl); diff --git a/renderdoc/driver/vulkan/vk_debug.h b/renderdoc/driver/vulkan/vk_debug.h index a5156ff81d..3dbe0aff2c 100644 --- a/renderdoc/driver/vulkan/vk_debug.h +++ b/renderdoc/driver/vulkan/vk_debug.h @@ -114,6 +114,7 @@ class VulkanDebugManager const VulkanCreationInfo::Framebuffer &GetFramebufferInfo(ResourceId fb) const; const VulkanCreationInfo::RenderPass &GetRenderPassInfo(ResourceId rp) const; const VulkanCreationInfo::PipelineLayout &GetPipelineLayoutInfo(ResourceId pp) const; + const VulkanCreationInfo::AccelerationStructure &GetAccelerationStructureInfo(ResourceId as) const; const DescSetLayout &GetDescSetLayout(ResourceId dsl) const; const WrappedVulkan::DescriptorSetInfo &GetDescSetInfo(ResourceId ds) const; diff --git a/renderdoc/driver/vulkan/vk_hookset_defs.h b/renderdoc/driver/vulkan/vk_hookset_defs.h index 0eebcebaa2..a16d238657 100644 --- a/renderdoc/driver/vulkan/vk_hookset_defs.h +++ b/renderdoc/driver/vulkan/vk_hookset_defs.h @@ -554,7 +554,10 @@ DeclExt(EXT_scalar_block_layout); \ DeclExt(KHR_vertex_attribute_divisor); \ DeclExt(KHR_line_rasterization); \ - DeclExt(KHR_calibrated_timestamps); + DeclExt(KHR_calibrated_timestamps); \ + DeclExt(KHR_deferred_host_operations); \ + DeclExt(KHR_acceleration_structure); \ + DeclExt(KHR_ray_query); // for simplicity and since the check itself is platform agnostic, // these aren't protected in platform defines @@ -679,7 +682,10 @@ CheckExt(EXT_scalar_block_layout, VK12); \ CheckExt(KHR_vertex_attribute_divisor, VKXX); \ CheckExt(KHR_line_rasterization, VKXX); \ - CheckExt(KHR_calibrated_timestamps, VKXX); + CheckExt(KHR_calibrated_timestamps, VKXX); \ + CheckExt(KHR_deferred_host_operations, VKXX); \ + CheckExt(KHR_acceleration_structure, VKXX); \ + CheckExt(KHR_ray_query, VKXX); #define HookInitVulkanInstanceExts_PhysDev() \ HookInitExtension(KHR_surface, GetPhysicalDeviceSurfaceSupportKHR); \ @@ -982,6 +988,27 @@ HookInitExtension(KHR_calibrated_timestamps, GetCalibratedTimestampsKHR); \ HookInitExtension(KHR_line_rasterization, CmdSetLineStippleKHR); \ HookInitExtensionEXTtoKHR(CmdSetLineStipple); \ + HookInitExtension(KHR_deferred_host_operations, CreateDeferredOperationKHR); \ + HookInitExtension(KHR_deferred_host_operations, DeferredOperationJoinKHR); \ + HookInitExtension(KHR_deferred_host_operations, DestroyDeferredOperationKHR); \ + HookInitExtension(KHR_deferred_host_operations, GetDeferredOperationMaxConcurrencyKHR); \ + HookInitExtension(KHR_deferred_host_operations, GetDeferredOperationResultKHR); \ + HookInitExtension(KHR_acceleration_structure, BuildAccelerationStructuresKHR); \ + HookInitExtension(KHR_acceleration_structure, CmdBuildAccelerationStructuresIndirectKHR); \ + HookInitExtension(KHR_acceleration_structure, CmdBuildAccelerationStructuresKHR); \ + HookInitExtension(KHR_acceleration_structure, CmdCopyAccelerationStructureKHR); \ + HookInitExtension(KHR_acceleration_structure, CmdCopyAccelerationStructureToMemoryKHR); \ + HookInitExtension(KHR_acceleration_structure, CmdCopyMemoryToAccelerationStructureKHR); \ + HookInitExtension(KHR_acceleration_structure, CmdWriteAccelerationStructuresPropertiesKHR); \ + HookInitExtension(KHR_acceleration_structure, CopyAccelerationStructureKHR); \ + HookInitExtension(KHR_acceleration_structure, CopyAccelerationStructureToMemoryKHR); \ + HookInitExtension(KHR_acceleration_structure, CopyMemoryToAccelerationStructureKHR); \ + HookInitExtension(KHR_acceleration_structure, CreateAccelerationStructureKHR); \ + HookInitExtension(KHR_acceleration_structure, DestroyAccelerationStructureKHR); \ + HookInitExtension(KHR_acceleration_structure, GetAccelerationStructureBuildSizesKHR); \ + HookInitExtension(KHR_acceleration_structure, GetAccelerationStructureDeviceAddressKHR); \ + HookInitExtension(KHR_acceleration_structure, GetDeviceAccelerationStructureCompatibilityKHR); \ + HookInitExtension(KHR_acceleration_structure, WriteAccelerationStructuresPropertiesKHR); \ HookInitExtension_Device_Win32(); \ HookInitExtension_Device_Linux(); \ HookInitExtension_Device_GGP(); \ @@ -1790,6 +1817,65 @@ uint64_t *, pMaxDeviation); \ HookDefine3(void, vkCmdSetLineStippleKHR, VkCommandBuffer, commandBuffer, uint32_t, \ lineStippleFactor, uint16_t, lineStipplePattern); \ + HookDefine3(VkResult, vkCreateDeferredOperationKHR, VkDevice, device, \ + const VkAllocationCallbacks *, pAllocator, VkDeferredOperationKHR *, \ + pDeferredOperation); \ + HookDefine2(VkResult, vkDeferredOperationJoinKHR, VkDevice, device, VkDeferredOperationKHR, \ + operation); \ + HookDefine3(void, vkDestroyDeferredOperationKHR, VkDevice, device, VkDeferredOperationKHR, \ + operation, const VkAllocationCallbacks *, pAllocator); \ + HookDefine2(uint32_t, vkGetDeferredOperationMaxConcurrencyKHR, VkDevice, device, \ + VkDeferredOperationKHR, operation); \ + HookDefine2(VkResult, vkGetDeferredOperationResultKHR, VkDevice, device, VkDeferredOperationKHR, \ + operation); \ + HookDefine5(VkResult, vkBuildAccelerationStructuresKHR, VkDevice, device, \ + VkDeferredOperationKHR, deferredOperation, uint32_t, infoCount, \ + const VkAccelerationStructureBuildGeometryInfoKHR *, pInfos, \ + const VkAccelerationStructureBuildRangeInfoKHR *const *, ppBuildRangeInfos); \ + HookDefine6(void, vkCmdBuildAccelerationStructuresIndirectKHR, VkCommandBuffer, commandBuffer, \ + uint32_t, infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *, pInfos, \ + const VkDeviceAddress *, pIndirectDeviceAddresses, const uint32_t *, \ + pIndirectStrides, const uint32_t *const *, ppMaxPrimitiveCounts); \ + HookDefine4(void, vkCmdBuildAccelerationStructuresKHR, VkCommandBuffer, commandBuffer, uint32_t, \ + infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *, pInfos, \ + const VkAccelerationStructureBuildRangeInfoKHR *const *, ppBuildRangeInfos); \ + HookDefine2(void, vkCmdCopyAccelerationStructureKHR, VkCommandBuffer, commandBuffer, \ + const VkCopyAccelerationStructureInfoKHR *, pInfo); \ + HookDefine2(void, vkCmdCopyAccelerationStructureToMemoryKHR, VkCommandBuffer, commandBuffer, \ + const VkCopyAccelerationStructureToMemoryInfoKHR *, pInfo); \ + HookDefine2(void, vkCmdCopyMemoryToAccelerationStructureKHR, VkCommandBuffer, commandBuffer, \ + const VkCopyMemoryToAccelerationStructureInfoKHR *, pInfo); \ + HookDefine6(void, vkCmdWriteAccelerationStructuresPropertiesKHR, VkCommandBuffer, commandBuffer, \ + uint32_t, accelerationStructureCount, const VkAccelerationStructureKHR *, \ + pAccelerationStructures, VkQueryType, queryType, VkQueryPool, queryPool, uint32_t, \ + firstQuery); \ + HookDefine3(VkResult, vkCopyAccelerationStructureKHR, VkDevice, device, VkDeferredOperationKHR, \ + deferredOperation, const VkCopyAccelerationStructureInfoKHR *, pInfo); \ + HookDefine3(VkResult, vkCopyAccelerationStructureToMemoryKHR, VkDevice, device, \ + VkDeferredOperationKHR, deferredOperation, \ + const VkCopyAccelerationStructureToMemoryInfoKHR *, pInfo); \ + HookDefine3(VkResult, vkCopyMemoryToAccelerationStructureKHR, VkDevice, device, \ + VkDeferredOperationKHR, deferredOperation, \ + const VkCopyMemoryToAccelerationStructureInfoKHR *, pInfo); \ + HookDefine4(VkResult, vkCreateAccelerationStructureKHR, VkDevice, device, \ + const VkAccelerationStructureCreateInfoKHR *, pCreateInfo, \ + const VkAllocationCallbacks *, pAllocator, VkAccelerationStructureKHR *, \ + pAccelerationStructure); \ + HookDefine3(void, vkDestroyAccelerationStructureKHR, VkDevice, device, VkAccelerationStructureKHR, \ + accelerationStructure, const VkAllocationCallbacks *, pAllocator); \ + HookDefine5(void, vkGetAccelerationStructureBuildSizesKHR, VkDevice, device, \ + VkAccelerationStructureBuildTypeKHR, buildType, \ + const VkAccelerationStructureBuildGeometryInfoKHR *, pBuildInfo, const uint32_t *, \ + pMaxPrimitiveCounts, VkAccelerationStructureBuildSizesInfoKHR *, pSizeInfo); \ + HookDefine2(VkDeviceAddress, vkGetAccelerationStructureDeviceAddressKHR, VkDevice, device, \ + const VkAccelerationStructureDeviceAddressInfoKHR *, pInfo); \ + HookDefine3(void, vkGetDeviceAccelerationStructureCompatibilityKHR, VkDevice, device, \ + const VkAccelerationStructureVersionInfoKHR *, pVersionInfo, \ + VkAccelerationStructureCompatibilityKHR *, pCompatibility); \ + HookDefine7(VkResult, vkWriteAccelerationStructuresPropertiesKHR, VkDevice, device, uint32_t, \ + accelerationStructureCount, const VkAccelerationStructureKHR *, \ + pAccelerationStructures, VkQueryType, queryType, size_t, dataSize, void *, pData, \ + size_t, stride); \ HookDefine_Win32(); \ HookDefine_Linux(); \ HookDefine_GGP(); \ diff --git a/renderdoc/driver/vulkan/vk_info.cpp b/renderdoc/driver/vulkan/vk_info.cpp index 5c43e64a91..5015821d56 100644 --- a/renderdoc/driver/vulkan/vk_info.cpp +++ b/renderdoc/driver/vulkan/vk_info.cpp @@ -2407,6 +2407,16 @@ void VulkanCreationInfo::DescSetPool::CreateOverflow(VkDevice device, overflow.push_back(pool); } +void VulkanCreationInfo::AccelerationStructure::Init( + VulkanResourceManager *resourceMan, VulkanCreationInfo &info, + const VkAccelerationStructureCreateInfoKHR *pCreateInfo) +{ + buffer = GetResID(pCreateInfo->buffer); + offset = pCreateInfo->offset; + size = pCreateInfo->size; + type = pCreateInfo->type; +} + void DescUpdateTemplate::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo) { diff --git a/renderdoc/driver/vulkan/vk_info.h b/renderdoc/driver/vulkan/vk_info.h index b85552d29d..910f5271eb 100644 --- a/renderdoc/driver/vulkan/vk_info.h +++ b/renderdoc/driver/vulkan/vk_info.h @@ -789,6 +789,18 @@ struct VulkanCreationInfo }; std::unordered_map m_QueryPool; + struct AccelerationStructure + { + void Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, + const VkAccelerationStructureCreateInfoKHR *pCreateInfo); + + ResourceId buffer; + uint64_t offset; + uint64_t size; + VkAccelerationStructureTypeKHR type; + }; + std::unordered_map m_AccelerationStructure; + std::unordered_map m_Names; std::unordered_map m_SwapChain; std::unordered_map m_DescSetLayout; @@ -813,6 +825,7 @@ struct VulkanCreationInfo m_ImageView.erase(id); m_ShaderModule.erase(id); m_DescSetPool.erase(id); + m_AccelerationStructure.erase(id); m_Names.erase(id); m_SwapChain.erase(id); m_DescSetLayout.erase(id); diff --git a/renderdoc/driver/vulkan/vk_initstate.cpp b/renderdoc/driver/vulkan/vk_initstate.cpp index c8052096d5..731c988df9 100644 --- a/renderdoc/driver/vulkan/vk_initstate.cpp +++ b/renderdoc/driver/vulkan/vk_initstate.cpp @@ -626,6 +626,7 @@ static rdcliteral NameOfType(VkResourceType type) case eResDeviceMemory: return "VkDeviceMemory"_lit; case eResBuffer: return "VkBuffer"_lit; case eResImage: return "VkImage"_lit; + case eResAccelerationStructureKHR: return "VkAccelerationStructureKHR"_lit; default: break; } return "VkResource"_lit; @@ -1693,7 +1694,7 @@ void WrappedVulkan::Create_InitialState(ResourceId id, WrappedVkRes *live, bool) GetResourceManager()->SetInitialContents(id, VkInitialContents(type, tag)); } - else if(type == eResDeviceMemory || type == eResBuffer) + else if(type == eResDeviceMemory || type == eResBuffer || type == eResAccelerationStructureKHR) { // ignore, it was probably dirty but not referenced in the frame } diff --git a/renderdoc/driver/vulkan/vk_next_chains.cpp b/renderdoc/driver/vulkan/vk_next_chains.cpp index 8d3a678f87..162946a53a 100644 --- a/renderdoc/driver/vulkan/vk_next_chains.cpp +++ b/renderdoc/driver/vulkan/vk_next_chains.cpp @@ -88,6 +88,18 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, // define structs that just need to be copied with no unwrapping at all, or only unwrapping some // members - easily shared between GetNextPatchSize and UnwrapNextChain #define PROCESS_SIMPLE_STRUCTS() \ + COPY_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR, \ + VkAccelerationStructureBuildSizesInfoKHR); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_AABBS_DATA_KHR, \ + VkAccelerationStructureGeometryAabbsDataKHR); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR, \ + VkAccelerationStructureGeometryInstancesDataKHR); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR, \ + VkAccelerationStructureGeometryKHR); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR, \ + VkAccelerationStructureGeometryTrianglesDataKHR); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_VERSION_INFO_KHR, \ + VkAccelerationStructureVersionInfoKHR); \ COPY_STRUCT(VK_STRUCTURE_TYPE_ACQUIRE_PROFILING_LOCK_INFO_KHR, VkAcquireProfilingLockInfoKHR); \ COPY_STRUCT(VK_STRUCTURE_TYPE_APPLICATION_INFO, VkApplicationInfo); \ COPY_STRUCT(VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2, VkAttachmentDescription2); \ @@ -210,6 +222,10 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, VkPhysicalDevice4444FormatsFeaturesEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES, \ VkPhysicalDevice8BitStorageFeatures); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR, \ + VkPhysicalDeviceAccelerationStructureFeaturesKHR); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR, \ + VkPhysicalDeviceAccelerationStructurePropertiesKHR); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ASTC_DECODE_FEATURES_EXT, \ VkPhysicalDeviceASTCDecodeFeaturesEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ATTACHMENT_FEEDBACK_LOOP_DYNAMIC_STATE_FEATURES_EXT, \ @@ -394,6 +410,8 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, VkPhysicalDevicePushDescriptorPropertiesKHR); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_EXT, \ VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR, \ + VkPhysicalDeviceRayQueryFeaturesKHR); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RGBA10X6_FORMATS_FEATURES_EXT, \ VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT, \ @@ -661,6 +679,15 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, COPY_STRUCT_CAPTURE_ONLY(VK_STRUCTURE_TYPE_SWAPCHAIN_COUNTER_CREATE_INFO_EXT, \ VkSwapchainCounterCreateInfoEXT); \ COPY_STRUCT_CAPTURE_ONLY(VK_STRUCTURE_TYPE_VALIDATION_FLAGS_EXT, VkValidationFlagsEXT); \ + UNWRAP_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR, \ + VkAccelerationStructureBuildGeometryInfoKHR, \ + UnwrapInPlace(out->srcAccelerationStructure), \ + UnwrapInPlace(out->dstAccelerationStructure)); \ + UNWRAP_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR, \ + VkAccelerationStructureCreateInfoKHR, UnwrapInPlace(out->buffer)); \ + UNWRAP_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR, \ + VkAccelerationStructureDeviceAddressInfoKHR, \ + UnwrapInPlace(out->accelerationStructure)); \ UNWRAP_STRUCT(VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO, VkBindBufferMemoryInfo, \ UnwrapInPlace(out->buffer), UnwrapInPlace(out->memory)); \ UNWRAP_STRUCT(VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO, VkBindImageMemoryInfo, \ @@ -684,8 +711,15 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, UnwrapInPlace(out->commandBuffer)); \ UNWRAP_STRUCT(VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT, \ VkConditionalRenderingBeginInfoEXT, UnwrapInPlace(out->buffer)); \ + UNWRAP_STRUCT(VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_INFO_KHR, \ + VkCopyAccelerationStructureInfoKHR, UnwrapInPlace(out->src), \ + UnwrapInPlace(out->dst)); \ + UNWRAP_STRUCT(VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_TO_MEMORY_INFO_KHR, \ + VkCopyAccelerationStructureToMemoryInfoKHR, UnwrapInPlace(out->src)); \ UNWRAP_STRUCT(VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, VkCopyDescriptorSet, \ UnwrapInPlace(out->srcSet), UnwrapInPlace(out->dstSet)); \ + UNWRAP_STRUCT(VK_STRUCTURE_TYPE_COPY_MEMORY_TO_ACCELERATION_STRUCTURE_INFO_KHR, \ + VkCopyMemoryToAccelerationStructureInfoKHR, UnwrapInPlace(out->dst)); \ UNWRAP_STRUCT(VK_STRUCTURE_TYPE_RENDERING_FRAGMENT_DENSITY_MAP_ATTACHMENT_INFO_EXT, \ VkRenderingFragmentDensityMapAttachmentInfoEXT, UnwrapInPlace(out->imageView)); \ UNWRAP_STRUCT(VK_STRUCTURE_TYPE_RENDERING_FRAGMENT_SHADING_RATE_ATTACHMENT_INFO_KHR, \ @@ -771,22 +805,13 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR: \ /* Output structure containing objects. Must be *wrapped* not unwrapped. */ \ /* So we treat this as unhandled in generic code and require specific handling. */ \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR: \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR: \ case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CAPTURE_DESCRIPTOR_DATA_INFO_EXT: \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR: \ case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_NV: \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR: \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_AABBS_DATA_KHR: \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR: \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR: \ case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_MOTION_TRIANGLES_DATA_NV: \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR: \ case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_INFO_NV: \ case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV: \ case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MOTION_INFO_NV: \ case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_TRIANGLES_OPACITY_MICROMAP_EXT: \ - case VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_VERSION_INFO_KHR: \ case VK_STRUCTURE_TYPE_AMIGO_PROFILING_SUBMIT_INFO_SEC: \ case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_2_ANDROID: \ case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_RESOLVE_PROPERTIES_ANDROID: \ @@ -812,12 +837,9 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_INDIRECT_BUFFER_INFO_NV: \ case VK_STRUCTURE_TYPE_COOPERATIVE_MATRIX_PROPERTIES_KHR: \ case VK_STRUCTURE_TYPE_COOPERATIVE_MATRIX_PROPERTIES_NV: \ - case VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_INFO_KHR: \ - case VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_TO_MEMORY_INFO_KHR: \ case VK_STRUCTURE_TYPE_COPY_COMMAND_TRANSFORM_INFO_QCOM: \ case VK_STRUCTURE_TYPE_COPY_IMAGE_TO_IMAGE_INFO_EXT: \ case VK_STRUCTURE_TYPE_COPY_IMAGE_TO_MEMORY_INFO_EXT: \ - case VK_STRUCTURE_TYPE_COPY_MEMORY_TO_ACCELERATION_STRUCTURE_INFO_KHR: \ case VK_STRUCTURE_TYPE_COPY_MEMORY_TO_IMAGE_INFO_EXT: \ case VK_STRUCTURE_TYPE_COPY_MEMORY_TO_MICROMAP_INFO_EXT: \ case VK_STRUCTURE_TYPE_COPY_MICROMAP_INFO_EXT: \ @@ -928,8 +950,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_PERFORMANCE_MARKER_INFO_INTEL: \ case VK_STRUCTURE_TYPE_PERFORMANCE_OVERRIDE_INFO_INTEL: \ case VK_STRUCTURE_TYPE_PERFORMANCE_STREAM_MARKER_INFO_INTEL: \ - case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR: \ - case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ADDRESS_BINDING_REPORT_FEATURES_EXT: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_AMIGO_PROFILING_FEATURES_SEC: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT: \ @@ -1016,7 +1036,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_ROBUSTNESS_FEATURES_EXT: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_ROBUSTNESS_PROPERTIES_EXT: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_BARRIER_FEATURES_NV: \ - case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_INVOCATION_REORDER_FEATURES_NV: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_INVOCATION_REORDER_PROPERTIES_NV: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_MAINTENANCE_1_FEATURES_KHR: \ @@ -1194,7 +1213,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_VIDEO_SESSION_MEMORY_REQUIREMENTS_KHR: \ case VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR: \ case VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_UPDATE_INFO_KHR: \ - case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR: \ case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_NV: size_t GetNextPatchSize(const void *pNext) @@ -1603,12 +1621,22 @@ size_t GetNextPatchSize(const void *pNext) memSize += info->descriptorCount * sizeof(VkDescriptorBufferInfo); break; case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: - // nothing to unwrap for inline uniform blocks, it's on the next chain + case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: + // nothing to unwrap for these, they're on the next chain break; default: RDCERR("Unhandled descriptor type unwrapping VkWriteDescriptorSet"); break; } break; } + case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR: + { + memSize += sizeof(VkWriteDescriptorSetAccelerationStructureKHR); + + VkWriteDescriptorSetAccelerationStructureKHR *info = + (VkWriteDescriptorSetAccelerationStructureKHR *)next; + memSize += info->accelerationStructureCount * sizeof(VkAccelerationStructureKHR); + break; + } // Android External Buffer Memory Extension #if ENABLED(RDOC_ANDROID) @@ -2771,6 +2799,7 @@ void UnwrapNextChain(CaptureState state, const char *structName, byte *&tempMem, break; } case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: + case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: { // nothing to do/patch break; @@ -2780,6 +2809,28 @@ void UnwrapNextChain(CaptureState state, const char *structName, byte *&tempMem, break; } + case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR: + { + const VkWriteDescriptorSetAccelerationStructureKHR *in = + (const VkWriteDescriptorSetAccelerationStructureKHR *)nextInput; + VkWriteDescriptorSetAccelerationStructureKHR *out = + (VkWriteDescriptorSetAccelerationStructureKHR *)tempMem; + + // append immediately so tempMem is incremented + AppendModifiedChainedStruct(tempMem, out, nextChainTail); + + // allocate unwrapped array + VkAccelerationStructureKHR *outAS = (VkAccelerationStructureKHR *)tempMem; + tempMem += sizeof(VkAccelerationStructureKHR) * in->accelerationStructureCount; + + *out = *in; + out->pAccelerationStructures = outAS; + + for(uint32_t i = 0; i < in->accelerationStructureCount; i++) + outAS[i] = Unwrap(in->pAccelerationStructures[i]); + + break; + } // Android External Buffer Memory Extension #if ENABLED(RDOC_ANDROID) @@ -3098,6 +3149,10 @@ void CopyNextChainForPatching(const char *structName, byte *&tempMem, VkBaseInSt case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET: CopyNextChainedStruct(sizeof(VkWriteDescriptorSet), tempMem, nextInput, nextChainTail); break; + case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR: + CopyNextChainedStruct(sizeof(VkWriteDescriptorSetAccelerationStructureKHR), tempMem, + nextInput, nextChainTail); + break; // Android External Buffer Memory Extension #if ENABLED(RDOC_ANDROID) diff --git a/renderdoc/driver/vulkan/vk_resources.cpp b/renderdoc/driver/vulkan/vk_resources.cpp index da118ee62c..f1c2f2d286 100644 --- a/renderdoc/driver/vulkan/vk_resources.cpp +++ b/renderdoc/driver/vulkan/vk_resources.cpp @@ -55,6 +55,7 @@ WRAPPED_POOL_INST(WrappedVkSwapchainKHR) WRAPPED_POOL_INST(WrappedVkSurfaceKHR) WRAPPED_POOL_INST(WrappedVkDescriptorUpdateTemplate) WRAPPED_POOL_INST(WrappedVkSamplerYcbcrConversion) +WRAPPED_POOL_INST(WrappedVkAccelerationStructureKHR) byte VkResourceRecord::markerValue[32] = { 0xaa, 0xbb, 0xcc, 0xdd, 0x88, 0x77, 0x66, 0x55, 0x01, 0x23, 0x45, 0x67, 0x98, 0x76, 0x54, 0x32, @@ -141,6 +142,8 @@ VkResourceType IdentifyTypeByPtr(WrappedVkRes *ptr) return eResDescUpdateTemplate; if(WrappedVkSamplerYcbcrConversion::IsAlloc(ptr)) return eResSamplerConversion; + if(WrappedVkAccelerationStructureKHR::IsAlloc(ptr)) + return eResAccelerationStructureKHR; RDCERR("Unknown type for ptr 0x%p", ptr); diff --git a/renderdoc/driver/vulkan/vk_resources.h b/renderdoc/driver/vulkan/vk_resources.h index 877dd7bcaf..398f7fa397 100644 --- a/renderdoc/driver/vulkan/vk_resources.h +++ b/renderdoc/driver/vulkan/vk_resources.h @@ -75,6 +75,7 @@ enum VkResourceType eResSurface, eResDescUpdateTemplate, eResSamplerConversion, + eResAccelerationStructureKHR, }; DECLARE_REFLECTION_ENUM(VkResourceType); @@ -559,6 +560,19 @@ struct WrappedVkSamplerYcbcrConversion : WrappedVkNonDispRes TypeEnum = eResSamplerConversion, }; }; +struct WrappedVkAccelerationStructureKHR : WrappedVkNonDispRes +{ + WrappedVkAccelerationStructureKHR(VkAccelerationStructureKHR obj, ResourceId objId) + : WrappedVkNonDispRes(obj, objId) + { + } + typedef VkAccelerationStructureKHR InnerType; + ALLOCATE_WITH_WRAPPED_POOL(WrappedVkAccelerationStructureKHR); + enum + { + TypeEnum = eResAccelerationStructureKHR, + }; +}; // VkDisplayKHR and VkDisplayModeKHR are both UNWRAPPED because there's no need to wrap them. // The only thing we need to wrap VkSurfaceKHR for is to get back the window from it later. @@ -661,6 +675,7 @@ UNWRAP_NONDISP_HELPER(VkSwapchainKHR) UNWRAP_NONDISP_HELPER(VkSurfaceKHR) UNWRAP_NONDISP_HELPER(VkDescriptorUpdateTemplate) UNWRAP_NONDISP_HELPER(VkSamplerYcbcrConversion) +UNWRAP_NONDISP_HELPER(VkAccelerationStructureKHR) // VkDisplayKHR and VkDisplayModeKHR are both UNWRAPPED because there's no need to wrap them. // The only thing we need to wrap VkSurfaceKHR for is to get back the window from it later. diff --git a/renderdoc/driver/vulkan/vk_serialise.cpp b/renderdoc/driver/vulkan/vk_serialise.cpp index a15aae1f76..96b6c2b6fb 100644 --- a/renderdoc/driver/vulkan/vk_serialise.cpp +++ b/renderdoc/driver/vulkan/vk_serialise.cpp @@ -167,6 +167,10 @@ DECL_VKFLAG_EXT(VkGraphicsPipelineLibrary, EXT); DECL_VKFLAG(VkRendering); DECL_VKFLAG_EXT(VkPresentScaling, EXT); DECL_VKFLAG_EXT(VkPresentGravity, EXT); +DECL_VKFLAG_EXT(VkAccelerationStructureCreate, KHR); +DECL_VKFLAG_EXT(VkBuildAccelerationStructure, KHR); +DECL_VKFLAG_EXT(VkGeometry, KHR); +DECL_VKFLAG_EXT(VkGeometryInstance, KHR); // serialise a member as flags - cast to the Bits enum for serialisation so the stringification // picks up the bitfield and doesn't treat it as uint32_t. Then we rename the type back to the base @@ -967,6 +971,38 @@ SERIALISE_VK_HANDLES(); PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES, \ VkPhysicalDevice16BitStorageFeatures) \ \ + /* VK_KHR_acceleration_structure */ \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR, \ + VkAccelerationStructureBuildGeometryInfoKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR, \ + VkAccelerationStructureBuildSizesInfoKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR, \ + VkAccelerationStructureCreateInfoKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR, \ + VkAccelerationStructureDeviceAddressInfoKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_AABBS_DATA_KHR, \ + VkAccelerationStructureGeometryAabbsDataKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR, \ + VkAccelerationStructureGeometryInstancesDataKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR, \ + VkAccelerationStructureGeometryKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR, \ + VkAccelerationStructureGeometryTrianglesDataKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_VERSION_INFO_KHR, \ + VkAccelerationStructureVersionInfoKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_INFO_KHR, \ + VkCopyAccelerationStructureInfoKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_TO_MEMORY_INFO_KHR, \ + VkCopyAccelerationStructureToMemoryInfoKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_COPY_MEMORY_TO_ACCELERATION_STRUCTURE_INFO_KHR, \ + VkCopyMemoryToAccelerationStructureInfoKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR, \ + VkPhysicalDeviceAccelerationStructureFeaturesKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR, \ + VkPhysicalDeviceAccelerationStructurePropertiesKHR) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR, \ + VkWriteDescriptorSetAccelerationStructureKHR) \ + \ /* VK_KHR_bind_memory2 */ \ PNEXT_STRUCT(VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO, VkBindBufferMemoryInfo) \ PNEXT_STRUCT(VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO, VkBindImageMemoryInfo) \ @@ -1260,6 +1296,10 @@ SERIALISE_VK_HANDLES(); PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR, \ VkPhysicalDevicePushDescriptorPropertiesKHR) \ \ + /* VK_KHR_ray_query */ \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR, \ + VkPhysicalDeviceRayQueryFeaturesKHR) \ + \ /* VK_KHR_sampler_ycbcr_conversion */ \ PNEXT_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO, \ VkSamplerYcbcrConversionCreateInfo) \ @@ -1659,23 +1699,6 @@ SERIALISE_VK_HANDLES(); /* VK_INTEL_shader_integer_functions2 */ \ PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_FUNCTIONS_2_FEATURES_INTEL) \ \ - /* VK_KHR_acceleration_structure */ \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_AABBS_DATA_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_VERSION_INFO_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_INFO_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_TO_MEMORY_INFO_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_COPY_MEMORY_TO_ACCELERATION_STRUCTURE_INFO_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR) \ - \ /* VK_KHR_cooperative_matrix */ \ PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_COOPERATIVE_MATRIX_PROPERTIES_KHR) \ PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_PROPERTIES_KHR) \ @@ -1724,9 +1747,6 @@ SERIALISE_VK_HANDLES(); /* VK_KHR_ray_tracing_position_fetch */ \ PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR) \ \ - /* VK_KHR_ray_query */ \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR) \ - \ /* VK_KHR_shader_expect_assume */ \ PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_EXPECT_ASSUME_FEATURES_KHR) \ \ @@ -11649,8 +11669,8 @@ void DoSerialise(SerialiserType &ser, VkQueryPoolPerformanceCreateInfoKHR &el) template <> void Deserialise(const VkQueryPoolPerformanceCreateInfoKHR &el) { - delete[] el.pCounterIndices; DeserialiseNext(el.pNext); + delete[] el.pCounterIndices; } template @@ -11684,7 +11704,416 @@ void Deserialise(const VkPerformanceQuerySubmitInfoKHR &el) DeserialiseNext(el.pNext); } +template +void DoSerialise(SerialiserType &ser, VkAabbPositionsKHR &el) +{ + SERIALISE_MEMBER(minX); + SERIALISE_MEMBER(minY); + SERIALISE_MEMBER(minZ); + SERIALISE_MEMBER(maxX); + SERIALISE_MEMBER(maxY); + SERIALISE_MEMBER(maxZ); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureBuildGeometryInfoKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(type).Important(); + SERIALISE_MEMBER_VKFLAGS(VkBuildAccelerationStructureFlagsKHR, flags); + SERIALISE_MEMBER(mode); + SERIALISE_MEMBER(srcAccelerationStructure); + SERIALISE_MEMBER(dstAccelerationStructure); + SERIALISE_MEMBER(geometryCount); + + // flatten the indirect array into single pGeometries-like list. Only one of ppGeometries or + // pGeometries can be NULL + VkAccelerationStructureGeometryKHR *pGeometries = + (VkAccelerationStructureGeometryKHR *)el.pGeometries; + if(ser.IsWriting() && el.ppGeometries) + { + pGeometries = new VkAccelerationStructureGeometryKHR[el.geometryCount]; + for(uint32_t i = 0; i < el.geometryCount; ++i) + { + pGeometries[i] = *(el.ppGeometries[i]); + } + } + + ser.Serialise("pGeometries"_lit, pGeometries, el.geometryCount, SerialiserFlags::AllocateMemory); + + if(ser.IsWriting() && el.ppGeometries) + delete[] pGeometries; + if(ser.IsReading()) + { + el.pGeometries = pGeometries; + el.ppGeometries = NULL; + } + + SERIALISE_MEMBER(scratchData); +} + +template <> +void Deserialise(const VkAccelerationStructureBuildGeometryInfoKHR &el) +{ + DeserialiseNext(el.pNext); + delete[] el.pGeometries; + delete[] el.ppGeometries; +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureBuildRangeInfoKHR &el) +{ + SERIALISE_MEMBER(primitiveCount).Important(); + SERIALISE_MEMBER(primitiveOffset).OffsetOrSize(); + SERIALISE_MEMBER(firstVertex); + SERIALISE_MEMBER(transformOffset).OffsetOrSize(); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureBuildSizesInfoKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(accelerationStructureSize).OffsetOrSize(); + SERIALISE_MEMBER(updateScratchSize).OffsetOrSize(); + SERIALISE_MEMBER(buildScratchSize).OffsetOrSize(); +} + +template <> +void Deserialise(const VkAccelerationStructureBuildSizesInfoKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureCreateInfoKHR &el) +{ + RDCASSERT(ser.IsReading() || el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER_VKFLAGS(VkAccelerationStructureCreateFlagsKHR, createFlags); + SERIALISE_MEMBER(buffer); + SERIALISE_MEMBER(offset).OffsetOrSize(); + SERIALISE_MEMBER(size).OffsetOrSize(); + SERIALISE_MEMBER(type); + SERIALISE_MEMBER(deviceAddress); +} + +template <> +void Deserialise(const VkAccelerationStructureCreateInfoKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureDeviceAddressInfoKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(accelerationStructure); +} + +template <> +void Deserialise(const VkAccelerationStructureDeviceAddressInfoKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureGeometryAabbsDataKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_AABBS_DATA_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(data); + SERIALISE_MEMBER(stride).OffsetOrSize(); +} + +template <> +void Deserialise(const VkAccelerationStructureGeometryAabbsDataKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureGeometryInstancesDataKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(arrayOfPointers); + SERIALISE_MEMBER(data); +} + +template <> +void Deserialise(const VkAccelerationStructureGeometryInstancesDataKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureGeometryKHR &el) +{ + RDCASSERT(ser.IsReading() || el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(geometryType).Important(); + SERIALISE_MEMBER(geometry); + SERIALISE_MEMBER_VKFLAGS(VkGeometryFlagsKHR, flags); +} + +template <> +void Deserialise(const VkAccelerationStructureGeometryKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureGeometryTrianglesDataKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(vertexFormat); + SERIALISE_MEMBER(vertexData); + SERIALISE_MEMBER(vertexStride).OffsetOrSize(); + SERIALISE_MEMBER(maxVertex); + SERIALISE_MEMBER(indexType); + SERIALISE_MEMBER(indexData); + SERIALISE_MEMBER(transformData); +} + +template <> +void Deserialise(const VkAccelerationStructureGeometryTrianglesDataKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureInstanceKHR &el) +{ + SERIALISE_MEMBER(transform); + + uint32_t instanceCustomIndex = el.instanceCustomIndex & 0xffffff; + ser.Serialise("instanceCustomIndex"_lit, instanceCustomIndex); + if(ser.IsReading()) + el.instanceCustomIndex = instanceCustomIndex & 0xff; + + uint32_t mask = el.mask & 0xff; + ser.Serialise("mask"_lit, mask); + if(ser.IsReading()) + el.mask = mask & 0xff; + + uint32_t instanceShaderBindingTableRecordOffset = + el.instanceShaderBindingTableRecordOffset & 0xffffff; + ser.Serialise("instanceShaderBindingTableRecordOffset"_lit, instanceShaderBindingTableRecordOffset) + .OffsetOrSize(); + if(ser.IsReading()) + el.instanceShaderBindingTableRecordOffset = instanceShaderBindingTableRecordOffset & 0xff; + + uint32_t flags = el.flags & 0xff; + ser.Serialise("flags"_lit, flags); + if(ser.IsReading()) + el.flags = flags & 0xff; + + SERIALISE_MEMBER(accelerationStructureReference); +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureVersionInfoKHR &el) +{ + RDCASSERT(ser.IsReading() || el.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_VERSION_INFO_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + ser.Serialise("pVersionData"_lit, el.pVersionData, 2 * VK_UUID_SIZE, + SerialiserFlags::AllocateMemory); +} + +template <> +void Deserialise(const VkAccelerationStructureVersionInfoKHR &el) +{ + delete[] el.pVersionData; + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkCopyAccelerationStructureInfoKHR &el) +{ + RDCASSERT(ser.IsReading() || el.sType == VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_INFO_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(src); + SERIALISE_MEMBER(dst); + SERIALISE_MEMBER(mode); +} + +template <> +void Deserialise(const VkCopyAccelerationStructureInfoKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkCopyAccelerationStructureToMemoryInfoKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_TO_MEMORY_INFO_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(src); + SERIALISE_MEMBER(dst); + SERIALISE_MEMBER(mode); +} + +template <> +void Deserialise(const VkCopyAccelerationStructureToMemoryInfoKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkCopyMemoryToAccelerationStructureInfoKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_COPY_MEMORY_TO_ACCELERATION_STRUCTURE_INFO_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(src); + SERIALISE_MEMBER(dst); + SERIALISE_MEMBER(mode); +} + +template <> +void Deserialise(const VkCopyMemoryToAccelerationStructureInfoKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkTransformMatrixKHR &el) +{ + float *data = &el.matrix[0][0]; + ser.Serialise("matrix"_lit, data, 3 * 4 * sizeof(float), SerialiserFlags::NoFlags); +} + +template +void DoSerialise(SerialiserType &ser, VkPhysicalDeviceAccelerationStructureFeaturesKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(accelerationStructure); + SERIALISE_MEMBER(accelerationStructureCaptureReplay); + SERIALISE_MEMBER(accelerationStructureIndirectBuild); + SERIALISE_MEMBER(accelerationStructureHostCommands); + SERIALISE_MEMBER(descriptorBindingAccelerationStructureUpdateAfterBind); +} + +template <> +void Deserialise(const VkPhysicalDeviceAccelerationStructureFeaturesKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkPhysicalDeviceAccelerationStructurePropertiesKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(maxGeometryCount); + SERIALISE_MEMBER(maxInstanceCount); + SERIALISE_MEMBER(maxPrimitiveCount); + SERIALISE_MEMBER(maxPerStageDescriptorAccelerationStructures); + SERIALISE_MEMBER(maxPerStageDescriptorUpdateAfterBindAccelerationStructures); + SERIALISE_MEMBER(maxDescriptorSetAccelerationStructures); + SERIALISE_MEMBER(maxDescriptorSetUpdateAfterBindAccelerationStructures); + SERIALISE_MEMBER(minAccelerationStructureScratchOffsetAlignment).OffsetOrSize(); +} + +template <> +void Deserialise(const VkPhysicalDeviceAccelerationStructurePropertiesKHR &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkWriteDescriptorSetAccelerationStructureKHR &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(accelerationStructureCount).Important(); + SERIALISE_MEMBER_ARRAY(pAccelerationStructures, accelerationStructureCount); +} + +template <> +void Deserialise(const VkWriteDescriptorSetAccelerationStructureKHR &el) +{ + DeserialiseNext(el.pNext); + delete[] el.pAccelerationStructures; +} + +template +void DoSerialise(SerialiserType &ser, VkAccelerationStructureGeometryDataKHR &el) +{ + SERIALISE_MEMBER(triangles); + SERIALISE_MEMBER(aabbs); + SERIALISE_MEMBER(instances); +} + +template +void DoSerialise(SerialiserType &ser, VkDeviceOrHostAddressConstKHR &el) +{ + // VkDeviceOrHostAddressConstKHR is a union where the deviceAddress is guaranteed to be 64bit, + // so no need to explicitly serialise hostAddress + SERIALISE_MEMBER(deviceAddress); +} + +template +void DoSerialise(SerialiserType &ser, VkDeviceOrHostAddressKHR &el) +{ + SERIALISE_MEMBER(deviceAddress); +} + +template +void DoSerialise(SerialiserType &ser, VkPhysicalDeviceRayQueryFeaturesKHR &el) +{ + RDCASSERT(ser.IsReading() || el.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(rayQuery); +} + +template <> +void Deserialise(const VkPhysicalDeviceRayQueryFeaturesKHR &el) +{ + DeserialiseNext(el.pNext); +} + // pNext structs - always have deserialise for the next chain +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureBuildGeometryInfoKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureBuildSizesInfoKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureCreateInfoKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureDeviceAddressInfoKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureGeometryAabbsDataKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureGeometryInstancesDataKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureGeometryKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureGeometryTrianglesDataKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureVersionInfoKHR); INSTANTIATE_SERIALISE_TYPE(VkAcquireNextImageInfoKHR); INSTANTIATE_SERIALISE_TYPE(VkAcquireProfilingLockInfoKHR); INSTANTIATE_SERIALISE_TYPE(VkApplicationInfo); @@ -11721,11 +12150,14 @@ INSTANTIATE_SERIALISE_TYPE(VkCommandBufferSubmitInfo); INSTANTIATE_SERIALISE_TYPE(VkCommandPoolCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkComputePipelineCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkConditionalRenderingBeginInfoEXT); +INSTANTIATE_SERIALISE_TYPE(VkCopyAccelerationStructureInfoKHR); +INSTANTIATE_SERIALISE_TYPE(VkCopyAccelerationStructureToMemoryInfoKHR); INSTANTIATE_SERIALISE_TYPE(VkCopyBufferInfo2); INSTANTIATE_SERIALISE_TYPE(VkCopyBufferToImageInfo2); INSTANTIATE_SERIALISE_TYPE(VkCopyDescriptorSet); INSTANTIATE_SERIALISE_TYPE(VkCopyImageInfo2); INSTANTIATE_SERIALISE_TYPE(VkCopyImageToBufferInfo2); +INSTANTIATE_SERIALISE_TYPE(VkCopyMemoryToAccelerationStructureInfoKHR); INSTANTIATE_SERIALISE_TYPE(VkDebugMarkerMarkerInfoEXT); INSTANTIATE_SERIALISE_TYPE(VkDebugMarkerObjectNameInfoEXT); INSTANTIATE_SERIALISE_TYPE(VkDebugMarkerObjectTagInfoEXT); @@ -11842,6 +12274,8 @@ INSTANTIATE_SERIALISE_TYPE(VkPerformanceQuerySubmitInfoKHR); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDevice16BitStorageFeatures); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDevice4444FormatsFeaturesEXT); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDevice8BitStorageFeatures); +INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceAccelerationStructureFeaturesKHR); +INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceAccelerationStructurePropertiesKHR); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceASTCDecodeFeaturesEXT) INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT); @@ -11932,6 +12366,7 @@ INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceProtectedMemoryFeatures); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceProtectedMemoryProperties); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDevicePushDescriptorPropertiesKHR); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesEXT); +INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceRayQueryFeaturesKHR); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceRobustness2FeaturesEXT); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceRobustness2PropertiesEXT); @@ -12097,8 +12532,13 @@ INSTANTIATE_SERIALISE_TYPE(VkValidationFlagsEXT); INSTANTIATE_SERIALISE_TYPE(VkVertexInputAttributeDescription2EXT); INSTANTIATE_SERIALISE_TYPE(VkVertexInputBindingDescription2EXT); INSTANTIATE_SERIALISE_TYPE(VkWriteDescriptorSet); +INSTANTIATE_SERIALISE_TYPE(VkWriteDescriptorSetAccelerationStructureKHR); // plain structs with no next chain +INSTANTIATE_SERIALISE_TYPE(VkAabbPositionsKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureBuildRangeInfoKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureGeometryDataKHR); +INSTANTIATE_SERIALISE_TYPE(VkAccelerationStructureInstanceKHR); INSTANTIATE_SERIALISE_TYPE(VkAllocationCallbacks); INSTANTIATE_SERIALISE_TYPE(VkAttachmentDescription); INSTANTIATE_SERIALISE_TYPE(VkAttachmentReference); @@ -12117,6 +12557,8 @@ INSTANTIATE_SERIALISE_TYPE(VkDescriptorImageInfo); INSTANTIATE_SERIALISE_TYPE(VkDescriptorPoolSize); INSTANTIATE_SERIALISE_TYPE(VkDescriptorSetLayoutBinding); INSTANTIATE_SERIALISE_TYPE(VkDescriptorUpdateTemplateEntry); +INSTANTIATE_SERIALISE_TYPE(VkDeviceOrHostAddressConstKHR); +INSTANTIATE_SERIALISE_TYPE(VkDeviceOrHostAddressKHR); INSTANTIATE_SERIALISE_TYPE(VkDispatchIndirectCommand); INSTANTIATE_SERIALISE_TYPE(VkDisplayModeParametersKHR); INSTANTIATE_SERIALISE_TYPE(VkDisplayModePropertiesKHR); @@ -12171,6 +12613,7 @@ INSTANTIATE_SERIALISE_TYPE(VkSubpassDependency); INSTANTIATE_SERIALISE_TYPE(VkSubpassDescription); INSTANTIATE_SERIALISE_TYPE(VkSurfaceCapabilitiesKHR); INSTANTIATE_SERIALISE_TYPE(VkSurfaceFormatKHR); +INSTANTIATE_SERIALISE_TYPE(VkTransformMatrixKHR); INSTANTIATE_SERIALISE_TYPE(VkVertexInputAttributeDescription); INSTANTIATE_SERIALISE_TYPE(VkVertexInputBindingDescription); INSTANTIATE_SERIALISE_TYPE(VkVertexInputBindingDivisorDescriptionEXT); diff --git a/renderdoc/driver/vulkan/vk_stringise.cpp b/renderdoc/driver/vulkan/vk_stringise.cpp index a046586bfb..0488754260 100644 --- a/renderdoc/driver/vulkan/vk_stringise.cpp +++ b/renderdoc/driver/vulkan/vk_stringise.cpp @@ -28,7 +28,7 @@ template <> rdcstr DoStringise(const VulkanChunk &el) { - RDCCOMPILE_ASSERT((uint32_t)VulkanChunk::Max == 1201, "Chunks changed without updating names"); + RDCCOMPILE_ASSERT((uint32_t)VulkanChunk::Max == 1207, "Chunks changed without updating names"); BEGIN_ENUM_STRINGISE(VulkanChunk) { @@ -233,6 +233,12 @@ rdcstr DoStringise(const VulkanChunk &el) STRINGISE_ENUM_CLASS(vkCmdDrawMeshTasksEXT) STRINGISE_ENUM_CLASS(vkCmdDrawMeshTasksIndirectEXT) STRINGISE_ENUM_CLASS(vkCmdDrawMeshTasksIndirectCountEXT) + STRINGISE_ENUM_CLASS(vkCmdBuildAccelerationStructuresIndirectKHR) + STRINGISE_ENUM_CLASS(vkCmdBuildAccelerationStructuresKHR) + STRINGISE_ENUM_CLASS(vkCmdCopyAccelerationStructureKHR) + STRINGISE_ENUM_CLASS(vkCmdCopyAccelerationStructureToMemoryKHR) + STRINGISE_ENUM_CLASS(vkCmdCopyMemoryToAccelerationStructureKHR) + STRINGISE_ENUM_CLASS(vkCreateAccelerationStructureKHR) STRINGISE_ENUM_CLASS_NAMED(Max, "Max Chunk"); } END_ENUM_STRINGISE() @@ -271,6 +277,9 @@ rdcstr DoStringise(const VkResourceType &el) STRINGISE_ENUM(eResSemaphore) STRINGISE_ENUM(eResSwapchain) STRINGISE_ENUM(eResSurface) + STRINGISE_ENUM(eResDescUpdateTemplate) + STRINGISE_ENUM(eResSamplerConversion) + STRINGISE_ENUM(eResAccelerationStructureKHR) } END_ENUM_STRINGISE(); } @@ -3903,3 +3912,131 @@ rdcstr DoStringise(const VkFullScreenExclusiveEXT &el) END_ENUM_STRINGISE(); } #endif + +template <> +rdcstr DoStringise(const VkAccelerationStructureBuildTypeKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkAccelerationStructureBuildTypeKHR); + { + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_BUILD_TYPE_HOST_KHR) + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR) + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_BUILD_TYPE_HOST_OR_DEVICE_KHR) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkAccelerationStructureCompatibilityKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkAccelerationStructureCompatibilityKHR); + { + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_COMPATIBILITY_COMPATIBLE_KHR) + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_COMPATIBILITY_INCOMPATIBLE_KHR) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkAccelerationStructureCreateFlagBitsKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkAccelerationStructureCreateFlagBitsKHR); + { + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_KHR) + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_CREATE_DESCRIPTOR_BUFFER_CAPTURE_REPLAY_BIT_EXT) + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_CREATE_MOTION_BIT_NV) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkAccelerationStructureTypeKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkAccelerationStructureTypeKHR); + { + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR) + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR) + STRINGISE_ENUM(VK_ACCELERATION_STRUCTURE_TYPE_GENERIC_KHR) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkBuildAccelerationStructureFlagBitsKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkBuildAccelerationStructureFlagBitsKHR); + { + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_BUILD_BIT_KHR) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_LOW_MEMORY_BIT_KHR) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_MOTION_BIT_NV) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_OPACITY_MICROMAP_UPDATE_EXT) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_DISABLE_OPACITY_MICROMAPS_EXT) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_OPACITY_MICROMAP_DATA_UPDATE_EXT) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_DATA_ACCESS_KHR) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkBuildAccelerationStructureModeKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkBuildAccelerationStructureModeKHR); + { + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR) + STRINGISE_ENUM(VK_BUILD_ACCELERATION_STRUCTURE_MODE_UPDATE_KHR) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkCopyAccelerationStructureModeKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkCopyAccelerationStructureModeKHR); + { + STRINGISE_ENUM(VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR) + STRINGISE_ENUM(VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR) + STRINGISE_ENUM(VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHR) + STRINGISE_ENUM(VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHR) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkGeometryFlagBitsKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkGeometryFlagBitsKHR); + { + STRINGISE_ENUM(VK_GEOMETRY_OPAQUE_BIT_KHR) + STRINGISE_ENUM(VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkGeometryInstanceFlagBitsKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkGeometryInstanceFlagBitsKHR); + { + STRINGISE_ENUM(VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR) + STRINGISE_ENUM(VK_GEOMETRY_INSTANCE_TRIANGLE_FLIP_FACING_BIT_KHR) + STRINGISE_ENUM(VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR) + STRINGISE_ENUM(VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR) + STRINGISE_ENUM(VK_GEOMETRY_INSTANCE_FORCE_OPACITY_MICROMAP_2_STATE_EXT) + STRINGISE_ENUM(VK_GEOMETRY_INSTANCE_DISABLE_OPACITY_MICROMAPS_EXT) + } + END_ENUM_STRINGISE(); +} + +template <> +rdcstr DoStringise(const VkGeometryTypeKHR &el) +{ + BEGIN_ENUM_STRINGISE(VkGeometryTypeKHR); + { + STRINGISE_ENUM(VK_GEOMETRY_TYPE_TRIANGLES_KHR) + STRINGISE_ENUM(VK_GEOMETRY_TYPE_AABBS_KHR) + STRINGISE_ENUM(VK_GEOMETRY_TYPE_INSTANCES_KHR) + } + END_ENUM_STRINGISE(); +} diff --git a/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp index 738979709c..7b1eae5769 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp @@ -22,6 +22,7 @@ * THE SOFTWARE. ******************************************************************************/ +#include "../vk_common.h" #include "../vk_core.h" #include "../vk_debug.h" #include "core/settings.h" @@ -7570,6 +7571,391 @@ void WrappedVulkan::vkCmdEndRendering(VkCommandBuffer commandBuffer) } } +VkResult WrappedVulkan::vkBuildAccelerationStructuresKHR( + VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) +{ + // CPU-side VK_KHR_acceleration_structure calls are not supported for now + return VK_ERROR_UNKNOWN; +} + +template +bool WrappedVulkan::Serialise_vkCmdBuildAccelerationStructuresIndirectKHR( + SerialiserType &ser, VkCommandBuffer commandBuffer, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides, + const uint32_t *const *ppMaxPrimitiveCounts) +{ + SERIALISE_ELEMENT(commandBuffer); + SERIALISE_ELEMENT(infoCount).Important(); + SERIALISE_ELEMENT_ARRAY(pInfos, infoCount); + SERIALISE_ELEMENT_ARRAY(pIndirectDeviceAddresses, infoCount); + SERIALISE_ELEMENT_ARRAY(pIndirectStrides, infoCount); + + // Convert the array of arrays for easier serialisation + rdcarray> maxPrimitives; + if(ser.IsWriting()) + { + maxPrimitives.reserve(infoCount); + + for(uint32_t i = 0; i < infoCount; ++i) + maxPrimitives.emplace_back(ppMaxPrimitiveCounts[i], pInfos[i].geometryCount); + } + + SERIALISE_ELEMENT(maxPrimitives); + + SERIALISE_CHECK_READ_ERRORS(); + + if(IsReplayingAndReading()) + { + size_t tempmemSize = sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + for(uint32_t i = 0; i < infoCount; ++i) + tempmemSize += GetNextPatchSize(&pInfos[i]); + + byte *memory = GetTempMemory(tempmemSize); + VkAccelerationStructureBuildGeometryInfoKHR *unwrappedInfos = + (VkAccelerationStructureBuildGeometryInfoKHR *)memory; + memory += sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + + for(uint32_t i = 0; i < infoCount; ++i) + unwrappedInfos[i] = *UnwrapStructAndChain(m_State, memory, &pInfos[i]); + + // Convert the maxPrimitives back to a C-style array-of-arrays + rdcarray tmpMaxPrimitiveCounts(NULL, infoCount); + for(uint32_t i = 0; i < infoCount; ++i) + tmpMaxPrimitiveCounts[i] = maxPrimitives[i].data(); + + ObjDisp(commandBuffer) + ->CmdBuildAccelerationStructuresIndirectKHR(Unwrap(commandBuffer), infoCount, + unwrappedInfos, pIndirectDeviceAddresses, + pIndirectStrides, tmpMaxPrimitiveCounts.data()); + } + + return true; +} + +void WrappedVulkan::vkCmdBuildAccelerationStructuresIndirectKHR( + VkCommandBuffer commandBuffer, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides, + const uint32_t *const *ppMaxPrimitiveCounts) +{ + { + size_t tempmemSize = sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + for(uint32_t i = 0; i < infoCount; ++i) + tempmemSize += GetNextPatchSize(&pInfos[i]); + + byte *memory = GetTempMemory(tempmemSize); + VkAccelerationStructureBuildGeometryInfoKHR *unwrappedInfos = + (VkAccelerationStructureBuildGeometryInfoKHR *)memory; + memory += sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + + for(uint32_t i = 0; i < infoCount; ++i) + unwrappedInfos[i] = *UnwrapStructAndChain(m_State, memory, &pInfos[i]); + + SERIALISE_TIME_CALL(ObjDisp(commandBuffer) + ->CmdBuildAccelerationStructuresIndirectKHR( + Unwrap(commandBuffer), infoCount, unwrappedInfos, + pIndirectDeviceAddresses, pIndirectStrides, ppMaxPrimitiveCounts)); + } + + if(IsCaptureMode(m_State)) + { + VkResourceRecord *record = GetRecord(commandBuffer); + + CACHE_THREAD_SERIALISER(); + ser.SetActionChunk(); + SCOPED_SERIALISE_CHUNK(VulkanChunk::vkCmdBuildAccelerationStructuresIndirectKHR); + Serialise_vkCmdBuildAccelerationStructuresIndirectKHR(ser, commandBuffer, infoCount, pInfos, + pIndirectDeviceAddresses, + pIndirectStrides, ppMaxPrimitiveCounts); + + record->AddChunk(scope.Get(&record->cmdInfo->alloc)); + + for(uint32_t i = 0; i < infoCount; ++i) + { + const VkAccelerationStructureBuildGeometryInfoKHR &geomInfo = pInfos[i]; + if(geomInfo.srcAccelerationStructure != VK_NULL_HANDLE) + GetResourceManager()->MarkResourceFrameReferenced( + GetResID(geomInfo.srcAccelerationStructure), eFrameRef_Read); + + GetResourceManager()->MarkResourceFrameReferenced(GetResID(geomInfo.dstAccelerationStructure), + eFrameRef_CompleteWrite); + } + } +} + +template +bool WrappedVulkan::Serialise_vkCmdBuildAccelerationStructuresKHR( + SerialiserType &ser, VkCommandBuffer commandBuffer, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) +{ + SERIALISE_ELEMENT(commandBuffer); + SERIALISE_ELEMENT(infoCount).Important(); + SERIALISE_ELEMENT_ARRAY(pInfos, infoCount); + + // Convert the array of arrays for easier serialisation + rdcarray> rangeInfos; + if(ser.IsWriting()) + { + rangeInfos.reserve(infoCount); + + for(uint32_t i = 0; i < infoCount; ++i) + rangeInfos.emplace_back(ppBuildRangeInfos[i], pInfos[i].geometryCount); + } + + SERIALISE_ELEMENT(rangeInfos); + + SERIALISE_CHECK_READ_ERRORS(); + + if(IsReplayingAndReading()) + { + size_t tempmemSize = sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + for(uint32_t i = 0; i < infoCount; ++i) + tempmemSize += GetNextPatchSize(&pInfos[i]); + + byte *memory = GetTempMemory(tempmemSize); + VkAccelerationStructureBuildGeometryInfoKHR *unwrappedInfos = + (VkAccelerationStructureBuildGeometryInfoKHR *)memory; + memory += sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + + for(uint32_t i = 0; i < infoCount; ++i) + unwrappedInfos[i] = *UnwrapStructAndChain(m_State, memory, &pInfos[i]); + + // Convert the rangeInfos back to a C-style array-of-arrays + rdcarray tmpBuildRangeInfos(nullptr, infoCount); + for(uint32_t i = 0; i < infoCount; ++i) + tmpBuildRangeInfos[i] = rangeInfos[i].data(); + + ObjDisp(commandBuffer) + ->CmdBuildAccelerationStructuresKHR(Unwrap(commandBuffer), infoCount, unwrappedInfos, + tmpBuildRangeInfos.data()); + } + + return true; +} + +void WrappedVulkan::vkCmdBuildAccelerationStructuresKHR( + VkCommandBuffer commandBuffer, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) +{ + { + size_t tempmemSize = sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + for(uint32_t i = 0; i < infoCount; ++i) + tempmemSize += GetNextPatchSize(&pInfos[i]); + + byte *memory = GetTempMemory(tempmemSize); + VkAccelerationStructureBuildGeometryInfoKHR *unwrappedInfos = + (VkAccelerationStructureBuildGeometryInfoKHR *)memory; + memory += sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + + for(uint32_t i = 0; i < infoCount; ++i) + unwrappedInfos[i] = *UnwrapStructAndChain(m_State, memory, &pInfos[i]); + + SERIALISE_TIME_CALL(ObjDisp(commandBuffer) + ->CmdBuildAccelerationStructuresKHR(Unwrap(commandBuffer), infoCount, + unwrappedInfos, ppBuildRangeInfos)); + } + + if(IsCaptureMode(m_State)) + { + VkResourceRecord *record = GetRecord(commandBuffer); + + CACHE_THREAD_SERIALISER(); + ser.SetActionChunk(); + SCOPED_SERIALISE_CHUNK(VulkanChunk::vkCmdBuildAccelerationStructuresKHR); + Serialise_vkCmdBuildAccelerationStructuresKHR(ser, commandBuffer, infoCount, pInfos, + ppBuildRangeInfos); + + record->AddChunk(scope.Get(&record->cmdInfo->alloc)); + + for(uint32_t i = 0; i < infoCount; ++i) + { + const VkAccelerationStructureBuildGeometryInfoKHR &geomInfo = pInfos[i]; + if(geomInfo.srcAccelerationStructure != VK_NULL_HANDLE) + GetResourceManager()->MarkResourceFrameReferenced( + GetResID(geomInfo.srcAccelerationStructure), eFrameRef_Read); + + GetResourceManager()->MarkResourceFrameReferenced(GetResID(geomInfo.dstAccelerationStructure), + eFrameRef_CompleteWrite); + } + } +} + +// CPU-side VK_KHR_acceleration_structure calls are not supported for now +VkResult WrappedVulkan::vkCopyAccelerationStructureKHR(VkDevice device, + VkDeferredOperationKHR deferredOperation, + const VkCopyAccelerationStructureInfoKHR *pInfo) +{ + return VK_ERROR_UNKNOWN; +} + +VkResult WrappedVulkan::vkCopyAccelerationStructureToMemoryKHR( + VkDevice device, VkDeferredOperationKHR deferredOperation, + const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) +{ + return VK_ERROR_UNKNOWN; +} + +VkResult WrappedVulkan::vkCopyMemoryToAccelerationStructureKHR( + VkDevice device, VkDeferredOperationKHR deferredOperation, + const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) +{ + return VK_ERROR_UNKNOWN; +} + +template +bool WrappedVulkan::Serialise_vkCmdCopyAccelerationStructureKHR( + SerialiserType &ser, VkCommandBuffer commandBuffer, + const VkCopyAccelerationStructureInfoKHR *pInfo) +{ + SERIALISE_ELEMENT(commandBuffer); + SERIALISE_ELEMENT_LOCAL(Info, *pInfo); + + SERIALISE_CHECK_READ_ERRORS(); + + if(IsReplayingAndReading()) + { + VkCopyAccelerationStructureInfoKHR unwrappedInfo = Info; + unwrappedInfo.src = Unwrap(unwrappedInfo.src); + unwrappedInfo.dst = Unwrap(unwrappedInfo.dst); + + ObjDisp(commandBuffer)->CmdCopyAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); + } + + return true; +} + +void WrappedVulkan::vkCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer, + const VkCopyAccelerationStructureInfoKHR *pInfo) +{ + VkCopyAccelerationStructureInfoKHR unwrappedInfo = *pInfo; + unwrappedInfo.src = Unwrap(unwrappedInfo.src); + unwrappedInfo.dst = Unwrap(unwrappedInfo.dst); + SERIALISE_TIME_CALL( + ObjDisp(commandBuffer)->CmdCopyAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo)); + + if(IsCaptureMode(m_State)) + { + VkResourceRecord *record = GetRecord(commandBuffer); + + CACHE_THREAD_SERIALISER(); + ser.SetActionChunk(); + SCOPED_SERIALISE_CHUNK(VulkanChunk::vkCmdCopyAccelerationStructureKHR); + Serialise_vkCmdCopyAccelerationStructureKHR(ser, commandBuffer, pInfo); + + record->AddChunk(scope.Get(&record->cmdInfo->alloc)); + + GetResourceManager()->MarkResourceFrameReferenced(GetResID(pInfo->src), eFrameRef_Read); + GetResourceManager()->MarkResourceFrameReferenced(GetResID(pInfo->dst), eFrameRef_CompleteWrite); + } +} + +template +bool WrappedVulkan::Serialise_vkCmdCopyAccelerationStructureToMemoryKHR( + SerialiserType &ser, VkCommandBuffer commandBuffer, + const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) +{ + SERIALISE_ELEMENT(commandBuffer); + SERIALISE_ELEMENT_LOCAL(Info, *pInfo); + + SERIALISE_CHECK_READ_ERRORS(); + + if(IsReplayingAndReading()) + { + VkCopyAccelerationStructureToMemoryInfoKHR unwrappedInfo = Info; + unwrappedInfo.src = Unwrap(unwrappedInfo.src); + + ObjDisp(commandBuffer)->CmdCopyAccelerationStructureToMemoryKHR(Unwrap(commandBuffer), &unwrappedInfo); + } + + return true; +} + +void WrappedVulkan::vkCmdCopyAccelerationStructureToMemoryKHR( + VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) +{ + // We will always report ASes as incompatible so this would be an illegal call +} + +template +bool WrappedVulkan::Serialise_vkCmdCopyMemoryToAccelerationStructureKHR( + SerialiserType &ser, VkCommandBuffer commandBuffer, + const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) +{ + SERIALISE_ELEMENT(commandBuffer); + SERIALISE_ELEMENT_LOCAL(Info, *pInfo); + + SERIALISE_CHECK_READ_ERRORS(); + + if(IsReplayingAndReading()) + { + VkCopyMemoryToAccelerationStructureInfoKHR unwrappedInfo = Info; + unwrappedInfo.dst = Unwrap(unwrappedInfo.dst); + + ObjDisp(commandBuffer)->CmdCopyMemoryToAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); + } + + return true; +} + +void WrappedVulkan::vkCmdCopyMemoryToAccelerationStructureKHR( + VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) +{ + VkCopyMemoryToAccelerationStructureInfoKHR unwrappedInfo = *pInfo; + unwrappedInfo.dst = Unwrap(unwrappedInfo.dst); + SERIALISE_TIME_CALL( + ObjDisp(commandBuffer) + ->CmdCopyMemoryToAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo)); + + if(IsCaptureMode(m_State)) + { + VkResourceRecord *record = GetRecord(commandBuffer); + + CACHE_THREAD_SERIALISER(); + ser.SetActionChunk(); + SCOPED_SERIALISE_CHUNK(VulkanChunk::vkCmdCopyMemoryToAccelerationStructureKHR); + Serialise_vkCmdCopyMemoryToAccelerationStructureKHR(ser, commandBuffer, pInfo); + + record->AddChunk(scope.Get(&record->cmdInfo->alloc)); + + GetResourceManager()->MarkResourceFrameReferenced(GetResID(pInfo->dst), eFrameRef_CompleteWrite); + } +} + +void WrappedVulkan::vkCmdWriteAccelerationStructuresPropertiesKHR( + VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, + const VkAccelerationStructureKHR *pAccelerationStructures, VkQueryType queryType, + VkQueryPool queryPool, uint32_t firstQuery) +{ + byte *memory = GetTempMemory(sizeof(VkAccelerationStructureKHR) * accelerationStructureCount); + VkAccelerationStructureKHR *unwrappedASes = (VkAccelerationStructureKHR *)memory; + for(uint32_t i = 0; i < accelerationStructureCount; ++i) + unwrappedASes[i] = Unwrap(pAccelerationStructures[i]); + + ObjDisp(commandBuffer) + ->CmdWriteAccelerationStructuresPropertiesKHR(Unwrap(commandBuffer), + accelerationStructureCount, unwrappedASes, + queryType, Unwrap(queryPool), firstQuery); +} + +VkResult WrappedVulkan::vkWriteAccelerationStructuresPropertiesKHR( + VkDevice device, uint32_t accelerationStructureCount, + const VkAccelerationStructureKHR *pAccelerationStructures, VkQueryType queryType, + size_t dataSize, void *pData, size_t stride) +{ + byte *memory = GetTempMemory(sizeof(VkAccelerationStructureKHR) * accelerationStructureCount); + VkAccelerationStructureKHR *unwrappedASes = (VkAccelerationStructureKHR *)memory; + for(uint32_t i = 0; i < accelerationStructureCount; ++i) + unwrappedASes[i] = Unwrap(pAccelerationStructures[i]); + + return ObjDisp(device)->WriteAccelerationStructuresPropertiesKHR( + Unwrap(device), accelerationStructureCount, unwrappedASes, queryType, dataSize, pData, stride); +} + INSTANTIATE_FUNCTION_SERIALISED(VkResult, vkCreateCommandPool, VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool); @@ -7733,3 +8119,23 @@ INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdBeginRendering, VkCommandBuffer comma const VkRenderingInfo *pRenderingInfo); INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdEndRendering, VkCommandBuffer commandBuffer); + +INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdBuildAccelerationStructuresIndirectKHR, + VkCommandBuffer commandBuffer, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkDeviceAddress *pIndirectDeviceAddresses, + const uint32_t *pIndirectStrides, + const uint32_t *const *ppMaxPrimitiveCounts); +INSTANTIATE_FUNCTION_SERIALISED( + void, vkCmdBuildAccelerationStructuresKHR, VkCommandBuffer commandBuffer, uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR *pInfos, + const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos); +INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdCopyAccelerationStructureKHR, + VkCommandBuffer commandBuffer, + const VkCopyAccelerationStructureInfoKHR *pInfo); +INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdCopyAccelerationStructureToMemoryKHR, + VkCommandBuffer commandBuffer, + const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) +INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdCopyMemoryToAccelerationStructureKHR, + VkCommandBuffer commandBuffer, + const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) diff --git a/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp index 779cf784b6..239516b2fc 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp @@ -1171,3 +1171,43 @@ VkResult WrappedVulkan::vkGetPhysicalDeviceFragmentShadingRatesKHR( ->GetPhysicalDeviceFragmentShadingRatesKHR(Unwrap(physicalDevice), pFragmentShadingRateCount, pFragmentShadingRates); } + +uint32_t WrappedVulkan::vkGetDeferredOperationMaxConcurrencyKHR(VkDevice device, + VkDeferredOperationKHR operation) +{ + return ObjDisp(device)->GetDeferredOperationMaxConcurrencyKHR(Unwrap(device), operation); +} + +VkResult WrappedVulkan::vkGetDeferredOperationResultKHR(VkDevice device, + VkDeferredOperationKHR operation) +{ + return ObjDisp(device)->GetDeferredOperationResultKHR(Unwrap(device), operation); +} + +void WrappedVulkan::vkGetAccelerationStructureBuildSizesKHR( + VkDevice device, VkAccelerationStructureBuildTypeKHR buildType, + const VkAccelerationStructureBuildGeometryInfoKHR *pBuildInfo, + const uint32_t *pMaxPrimitiveCounts, VkAccelerationStructureBuildSizesInfoKHR *pSizeInfo) +{ + VkAccelerationStructureBuildGeometryInfoKHR unwrapped = *pBuildInfo; + unwrapped.srcAccelerationStructure = Unwrap(unwrapped.srcAccelerationStructure); + unwrapped.dstAccelerationStructure = Unwrap(unwrapped.dstAccelerationStructure); + + ObjDisp(device)->GetAccelerationStructureBuildSizesKHR(Unwrap(device), buildType, pBuildInfo, + pMaxPrimitiveCounts, pSizeInfo); +} + +VkDeviceAddress WrappedVulkan::vkGetAccelerationStructureDeviceAddressKHR( + VkDevice device, const VkAccelerationStructureDeviceAddressInfoKHR *pInfo) +{ + VkAccelerationStructureDeviceAddressInfoKHR info = *pInfo; + info.accelerationStructure = Unwrap(info.accelerationStructure); + return ObjDisp(device)->GetAccelerationStructureDeviceAddressKHR(Unwrap(device), &info); +} + +void WrappedVulkan::vkGetDeviceAccelerationStructureCompatibilityKHR( + VkDevice device, const VkAccelerationStructureVersionInfoKHR *pVersionInfo, + VkAccelerationStructureCompatibilityKHR *pCompatibility) +{ + *pCompatibility = VK_ACCELERATION_STRUCTURE_COMPATIBILITY_INCOMPATIBLE_KHR; +} diff --git a/renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp index 32b1555d4c..3573b9b6d0 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp @@ -184,6 +184,7 @@ DESTROY_IMPL(VkCommandPool, DestroyCommandPool) DESTROY_IMPL(VkQueryPool, DestroyQueryPool) DESTROY_IMPL(VkDescriptorUpdateTemplate, DestroyDescriptorUpdateTemplate) DESTROY_IMPL(VkSamplerYcbcrConversion, DestroySamplerYcbcrConversion) +DESTROY_IMPL(VkAccelerationStructureKHR, DestroyAccelerationStructureKHR) #undef DESTROY_IMPL @@ -568,6 +569,13 @@ bool WrappedVulkan::ReleaseResource(WrappedVkRes *res) vt->DestroySamplerYcbcrConversion(Unwrap(dev), real, NULL); break; } + case eResAccelerationStructureKHR: + { + VkAccelerationStructureKHR real = nondisp->real.As(); + GetResourceManager()->ReleaseWrappedResource(VkAccelerationStructureKHR(handle)); + vt->DestroyAccelerationStructureKHR(Unwrap(dev), real, NULL); + break; + } } return true; @@ -2016,6 +2024,9 @@ static ObjData GetObjData(VkObjectType objType, uint64_t object) case VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION: ret.record = GetRecord((VkSamplerYcbcrConversion)object); break; + case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR: + ret.record = GetRecord((VkAccelerationStructureKHR)object); + break; ///////////////////////////// // special cases @@ -2045,14 +2056,13 @@ static ObjData GetObjData(VkObjectType objType, uint64_t object) break; } - // private data slots are not wrapped - case VK_OBJECT_TYPE_PRIVATE_DATA_SLOT: ret.unwrapped = object; break; + // private data slots and deferred host operations are not wrapped + case VK_OBJECT_TYPE_PRIVATE_DATA_SLOT: + case VK_OBJECT_TYPE_DEFERRED_OPERATION_KHR: ret.unwrapped = object; break; // these objects are not supported - case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR: case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV: case VK_OBJECT_TYPE_PERFORMANCE_CONFIGURATION_INTEL: - case VK_OBJECT_TYPE_DEFERRED_OPERATION_KHR: case VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NV: case VK_OBJECT_TYPE_CUDA_MODULE_NV: case VK_OBJECT_TYPE_CUDA_FUNCTION_NV: @@ -2277,6 +2287,9 @@ bool WrappedVulkan::Serialise_vkDebugMarkerSetObjectNameEXT( case eResSamplerConversion: type = VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION_EXT; break; + case eResAccelerationStructureKHR: + type = VK_DEBUG_REPORT_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR_EXT; + break; } if(ObjDisp(m_Device)->DebugMarkerSetObjectNameEXT && @@ -2466,6 +2479,7 @@ bool WrappedVulkan::Serialise_vkSetDebugUtilsObjectNameEXT( case eResSurface: type = VK_OBJECT_TYPE_SURFACE_KHR; break; case eResDescUpdateTemplate: type = VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE; break; case eResSamplerConversion: type = VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION; break; + case eResAccelerationStructureKHR: type = VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR; break; } if(ObjDisp(m_Device)->SetDebugUtilsObjectNameEXT && type != VK_OBJECT_TYPE_UNKNOWN && @@ -2630,6 +2644,26 @@ void WrappedVulkan::vkGetPrivateData(VkDevice device, VkObjectType objectType, u privateDataSlot, pData); } +// deferred host operations are not supported, host operations are always captured non-deferred, +// so these wrapped functions are just pass-throughs +VkResult WrappedVulkan::vkCreateDeferredOperationKHR(VkDevice device, + const VkAllocationCallbacks *pAllocator, + VkDeferredOperationKHR *pDeferredOperation) +{ + return ObjDisp(device)->CreateDeferredOperationKHR(Unwrap(device), pAllocator, pDeferredOperation); +} + +VkResult WrappedVulkan::vkDeferredOperationJoinKHR(VkDevice device, VkDeferredOperationKHR operation) +{ + return ObjDisp(device)->DeferredOperationJoinKHR(Unwrap(device), operation); +} + +void WrappedVulkan::vkDestroyDeferredOperationKHR(VkDevice device, VkDeferredOperationKHR operation, + const VkAllocationCallbacks *pAllocator) +{ + return ObjDisp(device)->DestroyDeferredOperationKHR(Unwrap(device), operation, pAllocator); +} + INSTANTIATE_FUNCTION_SERIALISED(VkResult, vkCreateSampler, VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSampler *pSampler); diff --git a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp index b28a280e14..9783baff42 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp @@ -3123,6 +3123,123 @@ void WrappedVulkan::vkSetDeviceMemoryPriorityEXT(VkDevice device, VkDeviceMemory } } +template +bool WrappedVulkan::Serialise_vkCreateAccelerationStructureKHR( + SerialiserType &ser, VkDevice device, const VkAccelerationStructureCreateInfoKHR *pCreateInfo, + const VkAllocationCallbacks *pAllocator, VkAccelerationStructureKHR *pAccelerationStructure) +{ + SERIALISE_ELEMENT(device); + SERIALISE_ELEMENT_LOCAL(CreateInfo, *pCreateInfo).Important(); + SERIALISE_ELEMENT_OPT(pAllocator); + SERIALISE_ELEMENT_LOCAL(AccelerationStructure, GetResID(*pAccelerationStructure)) + .TypedAs("VkAccelerationStructureKHR"_lit); + + SERIALISE_CHECK_READ_ERRORS(); + + if(IsReplayingAndReading()) + { + VkAccelerationStructureCreateInfoKHR unwrappedInfo = CreateInfo; + unwrappedInfo.buffer = Unwrap(unwrappedInfo.buffer); + + VkAccelerationStructureKHR acc = VK_NULL_HANDLE; + VkResult ret = + ObjDisp(device)->CreateAccelerationStructureKHR(Unwrap(device), &CreateInfo, NULL, &acc); + + if(ret != VK_SUCCESS) + { + SET_ERROR_RESULT(m_FailedReplayResult, ResultCode::APIReplayFailed, + "Error creating acceleration structure, VkResult: %s", ToStr(ret).c_str()); + return false; + } + else + { + ResourceId live; + + if(GetResourceManager()->HasWrapper(ToTypedHandle(acc))) + { + live = GetResourceManager()->GetNonDispWrapper(acc)->id; + + // destroy this instance of the duplicate, as we must have matching create/destroy + // calls and there won't be a wrapped resource hanging around to destroy this one. + ObjDisp(device)->DestroyAccelerationStructureKHR(Unwrap(device), acc, NULL); + + // whenever the new ID is requested, return the old ID, via replacements. + GetResourceManager()->ReplaceResource(AccelerationStructure, + GetResourceManager()->GetOriginalID(live)); + } + else + { + live = GetResourceManager()->WrapResource(Unwrap(device), acc); + GetResourceManager()->AddLiveResource(AccelerationStructure, acc); + + m_CreationInfo.m_AccelerationStructure[live].Init(GetResourceManager(), m_CreationInfo, + &CreateInfo); + } + } + + AddResource(AccelerationStructure, ResourceType::AccelerationStructure, "AccelerationStructure"); + DerivedResource(device, AccelerationStructure); + DerivedResource(CreateInfo.buffer, AccelerationStructure); + } + + return true; +} + +VkResult WrappedVulkan::vkCreateAccelerationStructureKHR( + VkDevice device, const VkAccelerationStructureCreateInfoKHR *pCreateInfo, + const VkAllocationCallbacks *pAllocator, VkAccelerationStructureKHR *pAccelerationStructure) +{ + VkAccelerationStructureCreateInfoKHR unwrappedInfo = *pCreateInfo; + unwrappedInfo.buffer = Unwrap(unwrappedInfo.buffer); + VkResult ret; + SERIALISE_TIME_CALL(ret = ObjDisp(device)->CreateAccelerationStructureKHR( + Unwrap(device), &unwrappedInfo, pAllocator, pAccelerationStructure)); + + if(ret == VK_SUCCESS) + { + ResourceId id = GetResourceManager()->WrapResource(Unwrap(device), *pAccelerationStructure); + + if(IsCaptureMode(m_State)) + { + Chunk *chunk = NULL; + + { + CACHE_THREAD_SERIALISER(); + + SCOPED_SERIALISE_CHUNK(VulkanChunk::vkCreateAccelerationStructureKHR); + Serialise_vkCreateAccelerationStructureKHR(ser, device, pCreateInfo, NULL, + pAccelerationStructure); + + chunk = scope.Get(); + } + + VkResourceRecord *bufferRecord = GetRecord(pCreateInfo->buffer); + + VkResourceRecord *record = GetResourceManager()->AddResourceRecord(*pAccelerationStructure); + record->AddChunk(chunk); + record->AddParent(bufferRecord); + + // store the base resource + record->baseResource = bufferRecord->GetResourceID(); + record->baseResourceMem = bufferRecord->baseResource; + record->dedicated = bufferRecord->dedicated; + record->resInfo = bufferRecord->resInfo; + record->storable = bufferRecord->storable; + record->memOffset = bufferRecord->memOffset + pCreateInfo->offset; + record->memSize = pCreateInfo->size; + } + else + { + GetResourceManager()->AddLiveResource(id, *pAccelerationStructure); + + m_CreationInfo.m_AccelerationStructure[id].Init(GetResourceManager(), m_CreationInfo, + pCreateInfo); + } + } + + return ret; +} + INSTANTIATE_FUNCTION_SERIALISED(VkResult, vkAllocateMemory, VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory); @@ -3162,3 +3279,8 @@ INSTANTIATE_FUNCTION_SERIALISED(VkResult, vkBindImageMemory2, VkDevice device, INSTANTIATE_FUNCTION_SERIALISED(void, vkSetDeviceMemoryPriorityEXT, VkDevice device, VkDeviceMemory memory, float priority); + +INSTANTIATE_FUNCTION_SERIALISED(VkResult, vkCreateAccelerationStructureKHR, VkDevice device, + const VkAccelerationStructureCreateInfoKHR *pCreateInfo, + const VkAllocationCallbacks *pAllocator, + VkAccelerationStructureKHR *pAccelerationStructure); diff --git a/renderdoc/serialise/serialiser.h b/renderdoc/serialise/serialiser.h index 631567691c..5f486bf111 100644 --- a/renderdoc/serialise/serialiser.h +++ b/renderdoc/serialise/serialiser.h @@ -1407,6 +1407,71 @@ class Serialiser SerialiseValue(type, byteSize, (char *&)el); } + template + void SerialiseArrayValue(SDBasic type, rdcarray &el) + { + uint64_t size = (uint64_t)el.size(); + { + m_InternalElement++; + DoSerialise(*this, size); + m_InternalElement--; + } + + if(IsReading()) + { + VerifyArraySize(size); + } + + if(ExportStructure()) + { + SDObject ¤t = *m_StructureStack.back(); + + current.type.basetype = SDBasic::Array; + current.type.byteSize = size; + + current.ReserveChildren((size_t)size); + + if(IsReading()) + el.resize((size_t)size); + + if(m_LazyThreshold > 0 && size > m_LazyThreshold) + { + PushInternal(); + + for(size_t i = 0; i < (size_t)size; i++) + SerialiseDispatch::Do(*this, el[i]); + + PopInternal(); + + current.SetLazyArray(size, el.data(), MakeLazySerialiser()); + } + else + { + for(size_t i = 0; i < (size_t)size; i++) + { + SDObject &obj = *current.AddAndOwnChild(new SDObject("$el"_lit, TypeName())); + m_StructureStack.push_back(&obj); + + // default to struct. This will be overwritten if appropriate + obj.type.basetype = SDBasic::Struct; + obj.type.byteSize = sizeof(U); + + SerialiseDispatch::Do(*this, el[i]); + + m_StructureStack.pop_back(); + } + } + } + else + { + if(IsReading()) + el.resize((size_t)size); + + for(size_t i = 0; i < (size_t)size; i++) + SerialiseDispatch::Do(*this, el[i]); + } + } + // constructors only available by the derived classes for each serialiser type protected: Serialiser(StreamWriter *writer, Ownership own); @@ -1598,6 +1663,7 @@ class StructuredSerialiser : public Serialiser #define BASIC_TYPE_SERIALISE(typeName, member, type, byteSize) \ DECLARE_STRINGISE_TYPE(typeName) \ + DECLARE_STRINGISE_TYPE(rdcarray) \ template \ void DoSerialise(SerialiserType &ser, typeName &el) \ { \ @@ -1672,6 +1738,12 @@ void DoSerialise(SerialiserType &ser, rdcinflexiblestr &el) ser.SerialiseValue(SDBasic::String, 0, el); } +template +void DoSerialise(SerialiserType &ser, rdcarray &el) +{ + ser.SerialiseArrayValue(SDBasic::Array, el); +} + DECLARE_STRINGISE_TYPE(SDObject *); class ScopedChunk; diff --git a/renderdoc/serialise/serialiser_tests.cpp b/renderdoc/serialise/serialiser_tests.cpp index ccadc477fc..ff5caed2d0 100644 --- a/renderdoc/serialise/serialiser_tests.cpp +++ b/renderdoc/serialise/serialiser_tests.cpp @@ -1016,6 +1016,184 @@ TEST_CASE("Read/write container types", "[serialiser][structured]") delete buf; }; +TEST_CASE("Read/write container of container types", "[serialiser][structured]") +{ + StreamWriter *buf = new StreamWriter(StreamWriter::DefaultScratchSize); + + { + WriteSerialiser ser(buf, Ownership::Nothing); + + { + SCOPED_SERIALISE_CHUNK(5); + + rdcarray> v; + + v.push_back({1, 2, 3}); + v.push_back({4, 5}); + v.push_back({6, 7, 8, 9}); + + SERIALISE_ELEMENT(v); + } + + CHECK(buf->GetOffset() <= 128); + + REQUIRE_FALSE(ser.IsErrored()); + } + + { + ReadSerialiser ser(new StreamReader(buf->GetData(), buf->GetOffset()), Ownership::Stream); + + uint32_t chunkID = ser.ReadChunk(); + + CHECK(chunkID == 5); + + rdcarray> v; + + SERIALISE_ELEMENT(v); + + ser.EndChunk(); + + REQUIRE_FALSE(ser.IsErrored()); + + CHECK(ser.GetReader()->AtEnd()); + + REQUIRE(v.size() == 3); + REQUIRE(v[0].size() == 3); + REQUIRE(v[1].size() == 2); + REQUIRE(v[2].size() == 4); + + CHECK(v[0][0] == 1); + CHECK(v[0][1] == 2); + CHECK(v[0][2] == 3); + CHECK(v[1][0] == 4); + CHECK(v[1][1] == 5); + CHECK(v[2][0] == 6); + CHECK(v[2][1] == 7); + CHECK(v[2][2] == 8); + CHECK(v[2][3] == 9); + } + + { + ReadSerialiser ser(new StreamReader(buf->GetData(), buf->GetOffset()), Ownership::Stream); + + ser.ConfigureStructuredExport([](uint32_t) -> rdcstr { return "TestChunk"; }, true, 0, 1.0); + + ser.ReadChunk(); + { + rdcarray> v; + + SERIALISE_ELEMENT(v); + } + ser.EndChunk(); + + REQUIRE_FALSE(ser.IsErrored()); + + CHECK(ser.GetReader()->AtEnd()); + + const SDFile &structData = ser.GetStructuredFile(); + + CHECK(structData.chunks.size() == 1); + CHECK(structData.buffers.size() == 0); + + REQUIRE(structData.chunks[0]); + + const SDChunk &chunk = *structData.chunks[0]; + + CHECK(chunk.NumChildren() == 1); + + for(const SDObject *o : chunk) + REQUIRE(o); + + int childIdx = 0; + + { + const SDObject &o = *chunk.GetChild(childIdx++); + + CHECK(o.name == "v"); + CHECK(o.type.basetype == SDBasic::Array); + CHECK(o.type.byteSize == 3); + CHECK(o.type.flags == SDTypeFlags::NoFlags); + CHECK(o.NumChildren() == 3); + + // v[0] + { + const SDObject *child = o.GetChild(0); + CHECK(child->name == "$el"); + CHECK(child->type.basetype == SDBasic::Array); + CHECK(child->type.byteSize == 3); + + for(size_t i = 0; i < child->NumChildren(); ++i) + { + const SDObject *grandChild = child->GetChild(i); + + CHECK(grandChild->type.basetype == SDBasic::SignedInteger); + CHECK(grandChild->type.byteSize == 4); + } + + CHECK(child->GetChild(0)->data.basic.i == 1); + CHECK(child->GetChild(1)->data.basic.i == 2); + CHECK(child->GetChild(2)->data.basic.i == 3); + } + + // v[1] + { + const SDObject *child = o.GetChild(1); + CHECK(child->name == "$el"); + CHECK(child->type.basetype == SDBasic::Array); + CHECK(child->type.byteSize == 2); + + for(size_t i = 0; i < child->NumChildren(); ++i) + { + const SDObject *grandChild = child->GetChild(i); + + CHECK(grandChild->type.basetype == SDBasic::SignedInteger); + CHECK(grandChild->type.byteSize == 4); + } + + CHECK(child->GetChild(0)->data.basic.i == 4); + CHECK(child->GetChild(1)->data.basic.i == 5); + } + + // v[2] + { + const SDObject *child = o.GetChild(2); + CHECK(child->name == "$el"); + CHECK(child->type.basetype == SDBasic::Array); + CHECK(child->type.byteSize == 4); + + for(size_t i = 0; i < child->NumChildren(); ++i) + { + const SDObject *grandChild = child->GetChild(i); + + CHECK(grandChild->type.basetype == SDBasic::SignedInteger); + CHECK(grandChild->type.byteSize == 4); + } + + CHECK(child->GetChild(0)->data.basic.i == 6); + CHECK(child->GetChild(1)->data.basic.i == 7); + CHECK(child->GetChild(2)->data.basic.i == 8); + CHECK(child->GetChild(3)->data.basic.i == 9); + } + } + + StreamWriter *rewriteBuf = new StreamWriter(StreamWriter::DefaultScratchSize); + + { + WriteSerialiser rewrite(rewriteBuf, Ownership::Nothing); + + rewrite.WriteStructuredFile(structData, NULL); + } + + // must be bitwise identical to the original serialised data. + REQUIRE(rewriteBuf->GetOffset() == buf->GetOffset()); + CHECK_FALSE(memcmp(rewriteBuf->GetData(), buf->GetData(), (size_t)rewriteBuf->GetOffset())); + + delete rewriteBuf; + } + + delete buf; +} + struct struct1 { struct1() : x(0.0f), y(0.0f), width(0.0f), height(0.0f) {}