diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-10-04 23:59:33 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-10-04 23:59:33 +0000 |
| commit | 73fd82a29d3175e156754010f5de261d6f561f16 (patch) | |
| tree | f04b71a06b71addb56d2a79885e53d253caa417e /Graphics/GraphicsEngineVulkan | |
| parent | Added KHR extension emulation via NV extension (diff) | |
| download | DiligentCore-73fd82a29d3175e156754010f5de261d6f561f16.tar.gz DiligentCore-73fd82a29d3175e156754010f5de261d6f561f16.zip | |
A few random fixes to ray tracing API and implementation
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
19 files changed, 187 insertions, 157 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/BottomLevelASVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/BottomLevelASVkImpl.hpp index ccf8f574..eb485370 100644 --- a/Graphics/GraphicsEngineVulkan/include/BottomLevelASVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/BottomLevelASVkImpl.hpp @@ -59,7 +59,7 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_BottomLevelASVk, TBottomLevelASBase); private: - VkDeviceAddress m_DeviceAddress; + VkDeviceAddress m_DeviceAddress = 0; VulkanUtilities::AccelStructWrapper m_VulkanBLAS; VulkanUtilities::VulkanMemoryAllocation m_MemoryAllocation; ScratchBufferSizes m_ScratchSize; diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderBindingTableVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderBindingTableVkImpl.hpp index bba64381..92d83160 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderBindingTableVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderBindingTableVkImpl.hpp @@ -96,17 +96,15 @@ private: private: RefCntAutoPtr<BufferVkImpl> m_pBuffer; std::vector<Uint32> m_ShaderRecords; - Uint32 m_MissShadersOffset; - Uint32 m_HitGroupsOffset; - Uint32 m_CallbaleShadersOffset; - Uint32 m_MissShaderCount; - Uint32 m_HitGroupCount; - Uint32 m_CallableShaderCount; - Uint32 m_ShaderGroupHandleSize; - Uint32 m_ShaderGroupBaseAlignment; - -#ifdef DILIGENT_DEBUG -#endif + + Uint32 m_MissShadersOffset = 0; + Uint32 m_HitGroupsOffset = 0; + Uint32 m_CallbaleShadersOffset = 0; + Uint32 m_MissShaderCount = 0; + Uint32 m_HitGroupCount = 0; + Uint32 m_CallableShaderCount = 0; + Uint32 m_ShaderGroupHandleSize = 0; + Uint32 m_ShaderGroupBaseAlignment = 0; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/TopLevelASVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/TopLevelASVkImpl.hpp index 311266e7..11c1ebef 100644 --- a/Graphics/GraphicsEngineVulkan/include/TopLevelASVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/TopLevelASVkImpl.hpp @@ -59,7 +59,7 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_TopLevelASVk, TTopLevelASBase); private: - VkDeviceAddress m_DeviceAddress; + VkDeviceAddress m_DeviceAddress = 0; VulkanUtilities::AccelStructWrapper m_VulkanTLAS; VulkanUtilities::VulkanMemoryAllocation m_MemoryAllocation; ScratchBufferSizes m_ScratchSize; diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.hpp b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.hpp index 04189820..0cd6de63 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.hpp +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.hpp @@ -147,7 +147,7 @@ public: vkCmdDrawMeshTasksNV(m_VkCmdBuffer, TaskCount, FirstTask); #else - UNSUPPORTED("DrawMesh is not supported when vulkan library linked statically"); + UNSUPPORTED("DrawMesh is not supported when vulkan library is linked statically"); #endif } @@ -160,7 +160,7 @@ public: vkCmdDrawMeshTasksIndirectNV(m_VkCmdBuffer, Buffer, Offset, DrawCount, Stride); #else - UNSUPPORTED("DrawMeshIndirect is not supported when vulkan library linked statically"); + UNSUPPORTED("DrawMeshIndirect is not supported when vulkan library is linked statically"); #endif } @@ -577,7 +577,7 @@ public: #if DILIGENT_USE_VOLK vkCmdBuildAccelerationStructureKHR(m_VkCmdBuffer, infoCount, pInfos, ppOffsetInfos); #else - UNSUPPORTED("Ray tracing is not supported when vulkan library linked statically"); + UNSUPPORTED("Ray tracing is not supported when vulkan library is linked statically"); #endif } @@ -586,7 +586,7 @@ public: #if DILIGENT_USE_VOLK vkCmdCopyAccelerationStructureKHR(m_VkCmdBuffer, &Info); #else - UNSUPPORTED("Ray tracing is not supported when vulkan library linked statically"); + UNSUPPORTED("Ray tracing is not supported when vulkan library is linked statically"); #endif } @@ -601,7 +601,7 @@ public: #if DILIGENT_USE_VOLK vkCmdTraceRaysKHR(m_VkCmdBuffer, &RaygenShaderBindingTable, &MissShaderBindingTable, &HitShaderBindingTable, &CallableShaderBindingTable, width, height, depth); #else - UNSUPPORTED("Ray tracing is not supported when vulkan library linked statically"); + UNSUPPORTED("Ray tracing is not supported when vulkan library is linked statically"); #endif } diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanHeaders.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanHeaders.h index 769391cf..4b352cd6 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanHeaders.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanHeaders.h @@ -31,7 +31,7 @@ # define VK_NO_PROTOTYPES #endif -// TODO: remove it when ray tracing will be released +// TODO: remove when ray tracing is released #define VK_ENABLE_BETA_EXTENSIONS #include "vulkan/vulkan.h" diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.hpp b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.hpp index b9bf651c..0adde0d6 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.hpp +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.hpp @@ -44,7 +44,7 @@ public: VkPhysicalDevice8BitStorageFeaturesKHR Storage8Bit = {}; VkPhysicalDeviceShaderFloat16Int8FeaturesKHR ShaderFloat16Int8 = {}; VkPhysicalDeviceRayTracingFeaturesKHR RayTracing = {}; - bool RayTracingNV = false; // indicates that KHR extension emulated by NV extension + bool RayTracingNV = false; // indicates that KHR extension is emulated by NV extension VkPhysicalDeviceBufferDeviceAddressFeaturesKHR BufferDeviceAddress = {}; VkPhysicalDeviceDescriptorIndexingFeaturesEXT DescriptorIndexing = {}; }; diff --git a/Graphics/GraphicsEngineVulkan/interface/BottomLevelASVk.h b/Graphics/GraphicsEngineVulkan/interface/BottomLevelASVk.h index eb0c2da5..345b0f3b 100644 --- a/Graphics/GraphicsEngineVulkan/interface/BottomLevelASVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/BottomLevelASVk.h @@ -49,10 +49,10 @@ static const INTERFACE_ID IID_BottomLevelASVk = /// Exposes Vulkan-specific functionality of a Bottom-level acceleration structure object. DILIGENT_BEGIN_INTERFACE(IBottomLevelASVk, IBottomLevelAS) { - /// Returns a Vulkan BLAS object handle + /// Returns a Vulkan BLAS object handle. VIRTUAL VkAccelerationStructureKHR METHOD(GetVkBLAS)(THIS) CONST PURE; - /// Returns a Vulkan BLAS device address + /// Returns a Vulkan BLAS device address. VIRTUAL VkDeviceAddress METHOD(GetVkDeviceAddress)(THIS) CONST PURE; }; DILIGENT_END_INTERFACE diff --git a/Graphics/GraphicsEngineVulkan/interface/BufferVk.h b/Graphics/GraphicsEngineVulkan/interface/BufferVk.h index 0c95af96..af1f8673 100644 --- a/Graphics/GraphicsEngineVulkan/interface/BufferVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/BufferVk.h @@ -63,7 +63,7 @@ DILIGENT_BEGIN_INTERFACE(IBufferVk, IBuffer) /// returns Vulkan access flags corresponding to the state. If the state is unknown, returns 0. VIRTUAL VkAccessFlags METHOD(GetAccessFlags)(THIS) CONST PURE; - /// Returns a vulkan device address + /// Returns a Vulkan device address. VIRTUAL VkDeviceAddress METHOD(GetVkDeviceAddress)(THIS) CONST PURE; }; DILIGENT_END_INTERFACE diff --git a/Graphics/GraphicsEngineVulkan/interface/ShaderBindingTableVk.h b/Graphics/GraphicsEngineVulkan/interface/ShaderBindingTableVk.h index e3222728..76e0eadd 100644 --- a/Graphics/GraphicsEngineVulkan/interface/ShaderBindingTableVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/ShaderBindingTableVk.h @@ -45,16 +45,19 @@ static const INTERFACE_ID IID_ShaderBindingTableVk = IShaderBindingTableInclusiveMethods; \ IShaderBindingTableVkMethods ShaderBindingTableVk +// clang-format off /// Exposes Vulkan-specific functionality of a Shader binding table object. DILIGENT_BEGIN_INTERFACE(IShaderBindingTableVk, IShaderBindingTable) { /// AZ TODO - VIRTUAL void METHOD(GetVkStridedBufferRegions)(VkStridedBufferRegionKHR & RaygenShaderBindingTable, - VkStridedBufferRegionKHR & MissShaderBindingTable, - VkStridedBufferRegionKHR & HitShaderBindingTable, - VkStridedBufferRegionKHR & CallableShaderBindingTable) PURE; + VIRTUAL void METHOD(GetVkStridedBufferRegions)(THIS_ + VkStridedBufferRegionKHR REF RaygenShaderBindingTable, + VkStridedBufferRegionKHR REF MissShaderBindingTable, + VkStridedBufferRegionKHR REF HitShaderBindingTable, + VkStridedBufferRegionKHR REF CallableShaderBindingTable) PURE; }; DILIGENT_END_INTERFACE +// clang-format on #include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" diff --git a/Graphics/GraphicsEngineVulkan/interface/TopLevelASVk.h b/Graphics/GraphicsEngineVulkan/interface/TopLevelASVk.h index 3d0b8b09..c09f10c0 100644 --- a/Graphics/GraphicsEngineVulkan/interface/TopLevelASVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/TopLevelASVk.h @@ -48,10 +48,10 @@ static const INTERFACE_ID IID_TopLevelASVk = /// Exposes Vulkan-specific functionality of a Top-level acceleration structure object. DILIGENT_BEGIN_INTERFACE(ITopLevelASVk, ITopLevelAS) { - /// Returns a Vulkan TLAS object handle + /// Returns a Vulkan TLAS object handle. VIRTUAL VkAccelerationStructureKHR METHOD(GetVkTLAS)(THIS) CONST PURE; - /// Returns a Vulkan TLAS device address + /// Returns a Vulkan TLAS device address. VIRTUAL VkDeviceAddress METHOD(GetVkDeviceAddress)(THIS) CONST PURE; }; DILIGENT_END_INTERFACE @@ -60,7 +60,8 @@ DILIGENT_END_INTERFACE #if DILIGENT_C_INTERFACE -# define ITopLevelASVk_GetVkTLAS(This) CALL_IFACE_METHOD(TopLevelASVk, GetVkTLAS, This) +# define ITopLevelASVk_GetVkTLAS(This) CALL_IFACE_METHOD(TopLevelASVk, GetVkTLAS, This) +# define ITopLevelASVk_GetVkDeviceAddress(This) CALL_IFACE_METHOD(TopLevelASVk, GetVkDeviceAddress, This) #endif diff --git a/Graphics/GraphicsEngineVulkan/src/BottomLevelASVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/BottomLevelASVkImpl.cpp index 85c74834..6e0bcbb8 100644 --- a/Graphics/GraphicsEngineVulkan/src/BottomLevelASVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/BottomLevelASVkImpl.cpp @@ -36,8 +36,7 @@ BottomLevelASVkImpl::BottomLevelASVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pRenderDeviceVk, const BottomLevelASDesc& Desc, bool bIsDeviceInternal) : - TBottomLevelASBase{pRefCounters, pRenderDeviceVk, Desc, bIsDeviceInternal}, - m_DeviceAddress{0} + TBottomLevelASBase{pRefCounters, pRenderDeviceVk, Desc, bIsDeviceInternal} { const auto& LogicalDevice = pRenderDeviceVk->GetLogicalDevice(); const auto& PhysicalDevice = pRenderDeviceVk->GetPhysicalDevice(); @@ -100,6 +99,10 @@ BottomLevelASVkImpl::BottomLevelASVkImpl(IReferenceCounters* pRefCounters, } VERIFY_EXPR(MaxBoxCount <= Limits.maxPrimitiveCount); } + else + { + UNEXPECTED("Either pTriangles or pBoxes must not be null"); + } m_VulkanBLAS = LogicalDevice.CreateAccelStruct(CreateInfo, m_Desc.Name); diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index d3f87287..ba36ff7c 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -579,9 +579,12 @@ void DeviceContextVkImpl::DrawMesh(const DrawMeshAttribs& Attribs) return; #ifdef DILIGENT_DEBUG - auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); - VERIFY_EXPR(PhysicalDevice.GetExtFeatures().MeshShader.meshShader == VK_TRUE && PhysicalDevice.GetExtFeatures().MeshShader.taskShader == VK_TRUE); - VERIFY_EXPR(Attribs.ThreadGroupCount <= PhysicalDevice.GetExtProperties().MeshShader.maxDrawMeshTasksCount); + { + const auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); + const auto& MeshShaderFeats = PhysicalDevice.GetExtFeatures().MeshShader; + VERIFY_EXPR(MeshShaderFeats.meshShader != VK_FALSE && MeshShaderFeats.taskShader != VK_FALSE); + VERIFY_EXPR(Attribs.ThreadGroupCount <= PhysicalDevice.GetExtProperties().MeshShader.maxDrawMeshTasksCount); + } #endif PrepareForDraw(Attribs.Flags); @@ -596,8 +599,10 @@ void DeviceContextVkImpl::DrawMeshIndirect(const DrawMeshIndirectAttribs& Attrib return; #ifdef DILIGENT_DEBUG - auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); - VERIFY_EXPR(PhysicalDevice.GetExtFeatures().MeshShader.meshShader == VK_TRUE && PhysicalDevice.GetExtFeatures().MeshShader.taskShader == VK_TRUE); + { + const auto& MeshShaderFeats = m_pDevice->GetPhysicalDevice().GetExtFeatures().MeshShader; + VERIFY_EXPR(MeshShaderFeats.meshShader != VK_FALSE && MeshShaderFeats.taskShader != VK_FALSE); + } #endif // We must prepare indirect draw attribs buffer first because state transitions must @@ -2620,8 +2625,10 @@ void DeviceContextVkImpl::BuildBLAS(const BLASBuildAttribs& Attribs) // AZ TODO: transitions #ifdef DILIGENT_DEBUG - auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); - VERIFY_EXPR(PhysicalDevice.GetExtFeatures().RayTracing.rayTracing == VK_TRUE); + { + const auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); + VERIFY_EXPR(PhysicalDevice.GetExtFeatures().RayTracing.rayTracing != VK_FALSE); + } #endif auto* pBLASVk = ValidatedCast<BottomLevelASVkImpl>(Attribs.pBLAS); @@ -2721,6 +2728,10 @@ void DeviceContextVkImpl::BuildBLAS(const BLASBuildAttribs& Attribs) off.primitiveCount = src.BoxCount; } } + else + { + UNEXPECTED("pTriangleData or pBoxData must not be null"); + } VkAccelerationStructureGeometryKHR const* GeometriesPtr = Geometries.data(); VkAccelerationStructureBuildOffsetInfoKHR const* OffsetsPtr = Offsets.data(); @@ -2750,8 +2761,10 @@ void DeviceContextVkImpl::BuildTLAS(const TLASBuildAttribs& Attribs) // AZ TODO: transitions #ifdef DILIGENT_DEBUG - auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); - VERIFY_EXPR(PhysicalDevice.GetExtFeatures().RayTracing.rayTracing == VK_TRUE); + { + const auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); + VERIFY_EXPR(PhysicalDevice.GetExtFeatures().RayTracing.rayTracing != VK_FALSE); + } #endif auto* pTLASVk = ValidatedCast<TopLevelASVkImpl>(Attribs.pTLAS); @@ -2823,8 +2836,10 @@ void DeviceContextVkImpl::CopyBLAS(const CopyBLASAttribs& Attribs) // AZ TODO: transitions #ifdef DILIGENT_DEBUG - auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); - VERIFY_EXPR(PhysicalDevice.GetExtFeatures().RayTracing.rayTracing == VK_TRUE); + { + const auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); + VERIFY_EXPR(PhysicalDevice.GetExtFeatures().RayTracing.rayTracing != VK_FALSE); + } #endif auto* pSrcVk = ValidatedCast<BottomLevelASVkImpl>(Attribs.pSrc); @@ -2875,8 +2890,10 @@ void DeviceContextVkImpl::TraceRays(const TraceRaysAttribs& Attribs) // AZ TODO: transitions #ifdef DILIGENT_DEBUG - auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); - VERIFY_EXPR(PhysicalDevice.GetExtFeatures().RayTracing.rayTracing == VK_TRUE); + { + const auto& PhysicalDevice = m_pDevice->GetPhysicalDevice(); + VERIFY_EXPR(PhysicalDevice.GetExtFeatures().RayTracing.rayTracing == VK_TRUE); + } #endif VkStridedBufferRegionKHR RaygenShaderBindingTable = {}; diff --git a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp index 692b5428..7a7d8a07 100644 --- a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp @@ -273,7 +273,7 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& _E auto RayTracingFeats = DeiceExtFeatures.RayTracing; auto BufferDeviceAddressFeats = DeiceExtFeatures.BufferDeviceAddress; auto DescriptorIndexingFeats = DeiceExtFeatures.DescriptorIndexing; - ENABLE_FEATURE(RayTracingFeats.rayTracing != VK_FALSE || DeiceExtFeatures.RayTracingNV, MeshShaders, "Ray tracing are"); + ENABLE_FEATURE(RayTracingFeats.rayTracing != VK_FALSE || DeiceExtFeatures.RayTracingNV, RayTracing, "Ray tracing is"); #undef FeatureSupport @@ -418,6 +418,10 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& _E *NextExt = &BufferDeviceAddressFeats; NextExt = &BufferDeviceAddressFeats.pNext; } + else + { + UNEXPECTED("Either KHR or NV extension must be enabled"); + } } // make sure that last pNext is null diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp index 32c0cb29..b7d2b1f4 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp @@ -43,7 +43,7 @@ namespace Diligent static VkShaderStageFlagBits ShaderTypeToVkShaderStageFlagBit(SHADER_TYPE ShaderType) { - static_assert(SHADER_TYPE_LAST == 0x2000, "Please update the switch below to handle the new shader type"); + static_assert(SHADER_TYPE_LAST == SHADER_TYPE_CALLABLE, "Please update the switch below to handle the new shader type"); switch (ShaderType) { // clang-format off diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderBindingTableVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderBindingTableVkImpl.cpp index 21b06fb3..36fa5af0 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderBindingTableVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderBindingTableVkImpl.cpp @@ -36,17 +36,11 @@ ShaderBindingTableVkImpl::ShaderBindingTableVkImpl(IReferenceCounters* RenderDeviceVkImpl* pRenderDeviceVk, const ShaderBindingTableDesc& Desc, bool bIsDeviceInternal) : - TShaderBindingTableBase{pRefCounters, pRenderDeviceVk, Desc, bIsDeviceInternal}, - m_MissShadersOffset{0}, - m_HitGroupsOffset{0}, - m_CallbaleShadersOffset{0}, - m_MissShaderCount{0}, - m_HitGroupCount{0}, - m_CallableShaderCount{0} + TShaderBindingTableBase{pRefCounters, pRenderDeviceVk, Desc, bIsDeviceInternal} { ValidateDesc(Desc); - auto& Props = GetDevice()->GetPhysicalDevice().GetExtProperties().RayTracing; + const auto& Props = GetDevice()->GetPhysicalDevice().GetExtProperties().RayTracing; m_ShaderGroupHandleSize = Props.shaderGroupHandleSize; m_ShaderGroupBaseAlignment = Props.shaderGroupBaseAlignment; @@ -58,7 +52,7 @@ ShaderBindingTableVkImpl::~ShaderBindingTableVkImpl() void ShaderBindingTableVkImpl::ValidateDesc(const ShaderBindingTableDesc& Desc) const { - auto& Props = GetDevice()->GetPhysicalDevice().GetExtProperties().RayTracing; + const auto& Props = GetDevice()->GetPhysicalDevice().GetExtProperties().RayTracing; if (Desc.ShaderRecordSize + Props.shaderGroupHandleSize > Props.maxShaderGroupStride) { @@ -87,7 +81,7 @@ void ShaderBindingTableVkImpl::Reset(const ShaderBindingTableDesc& Desc) m_Desc = Desc; // free memory - decltype(m_ShaderRecords) temp; + decltype(m_ShaderRecords) temp{}; std::swap(temp, m_ShaderRecords); m_MissShadersOffset = 0; @@ -152,7 +146,7 @@ void ShaderBindingTableVkImpl::GetVkStridedBufferRegions(VkStridedBufferRegionKH VkStridedBufferRegionKHR& HitShaderBindingTable, VkStridedBufferRegionKHR& CallableShaderBindingTable) { - auto& Props = GetDevice()->GetPhysicalDevice().GetExtProperties().RayTracing; + const auto& Props = GetDevice()->GetPhysicalDevice().GetExtProperties().RayTracing; const VkDeviceSize Stride = m_Desc.ShaderRecordSize + Props.shaderGroupHandleSize; VERIFY_EXPR(Stride <= Props.maxShaderGroupStride); diff --git a/Graphics/GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp index 0fb2f334..76248d41 100644 --- a/Graphics/GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp @@ -36,8 +36,7 @@ TopLevelASVkImpl::TopLevelASVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pRenderDeviceVk, const TopLevelASDesc& Desc, bool bIsDeviceInternal) : - TTopLevelASBase{pRefCounters, pRenderDeviceVk, Desc, bIsDeviceInternal}, - m_DeviceAddress{0} + TTopLevelASBase{pRefCounters, pRenderDeviceVk, Desc, bIsDeviceInternal} { const auto& LogicalDevice = pRenderDeviceVk->GetLogicalDevice(); const auto& PhysicalDevice = pRenderDeviceVk->GetPhysicalDevice(); diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index b797968c..fa03bca6 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -444,7 +444,7 @@ public: TEXTURE_FORMAT operator[](VkFormat VkFmt) const { - if (VkFmt < _countof(m_VkFmtToTexFmtMap)) + if (VkFmt < VK_FORMAT_RANGE_SIZE) { return m_VkFmtToTexFmtMap[VkFmt]; } @@ -456,7 +456,7 @@ public: } private: - TEXTURE_FORMAT m_VkFmtToTexFmtMap[VK_FORMAT_ASTC_12x12_SRGB_BLOCK + 1] = {}; + TEXTURE_FORMAT m_VkFmtToTexFmtMap[VK_FORMAT_RANGE_SIZE] = {}; std::unordered_map<VkFormat, TEXTURE_FORMAT> m_VkFmtToTexFmtMapExt; }; @@ -640,7 +640,7 @@ VkIndexType TypeToVkIndexType(VALUE_TYPE IndexType) case VT_UNDEFINED: return VK_INDEX_TYPE_NONE_KHR; // only for ray tracing case VT_UINT16: return VK_INDEX_TYPE_UINT16; case VT_UINT32: return VK_INDEX_TYPE_UINT32; - // clang-format on + // clang-format on default: UNEXPECTED("Unexpected index type"); return VK_INDEX_TYPE_UINT32; @@ -1167,7 +1167,7 @@ static VkAccessFlags ResourceStateFlagToVkAccessFlags(RESOURCE_STATE StateFlag) //VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT //VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV - static_assert(RESOURCE_STATE_MAX_BIT == 0x40000, "This function must be updated to handle new resource state flag"); + static_assert(RESOURCE_STATE_MAX_BIT == RESOURCE_STATE_RAY_TRACING, "This function must be updated to handle new resource state flag"); VERIFY((StateFlag & (StateFlag - 1)) == 0, "Only single bit must be set"); switch (StateFlag) { @@ -1332,7 +1332,7 @@ VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag, bool IsInsi //VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR = VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, //VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, - static_assert(RESOURCE_STATE_MAX_BIT == 0x40000, "This function must be updated to handle new resource state flag"); + static_assert(RESOURCE_STATE_MAX_BIT == RESOURCE_STATE_RAY_TRACING, "This function must be updated to handle new resource state flag"); VERIFY((StateFlag & (StateFlag - 1)) == 0, "Only single bit must be set"); switch (StateFlag) { @@ -1366,7 +1366,7 @@ VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag, bool IsInsi RESOURCE_STATE VkImageLayoutToResourceState(VkImageLayout Layout) { - static_assert(RESOURCE_STATE_MAX_BIT == 0x40000, "This function must be updated to handle new resource state flag"); + static_assert(RESOURCE_STATE_MAX_BIT == RESOURCE_STATE_RAY_TRACING, "This function must be updated to handle new resource state flag"); switch (Layout) { // clang-format off @@ -1530,7 +1530,8 @@ VkAccessFlags AccessFlagsToVkAccessFlags(ACCESS_FLAGS AccessFlags) VkBuildAccelerationStructureFlagsKHR BuildASFlagsToVkBuildAccelerationStructureFlags(RAYTRACING_BUILD_AS_FLAGS Flags) { - static_assert(RAYTRACING_BUILD_AS_FLAGS_LAST == 0x10, "AZ TODO"); + static_assert(RAYTRACING_BUILD_AS_FLAGS_LAST == RAYTRACING_BUILD_AS_LOW_MEMORY, + "Please update the switch below to handle the new ray tracing build flag"); VkBuildAccelerationStructureFlagsKHR Result = 0; for (Uint32 Bit = 1; Bit <= Flags; Bit <<= 1) @@ -1538,7 +1539,7 @@ VkBuildAccelerationStructureFlagsKHR BuildASFlagsToVkBuildAccelerationStructureF if ((Flags & Bit) != Bit) continue; - switch (RAYTRACING_BUILD_AS_FLAGS(Bit)) + switch (static_cast<RAYTRACING_BUILD_AS_FLAGS>(Bit)) { // clang-format off case RAYTRACING_BUILD_AS_ALLOW_UPDATE: Result |= VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR; break; @@ -1546,8 +1547,8 @@ VkBuildAccelerationStructureFlagsKHR BuildASFlagsToVkBuildAccelerationStructureF case RAYTRACING_BUILD_AS_PREFER_FAST_TRACE: Result |= VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR; break; case RAYTRACING_BUILD_AS_PREFER_FAST_BUILD: Result |= VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_BUILD_BIT_KHR; break; case RAYTRACING_BUILD_AS_LOW_MEMORY: Result |= VK_BUILD_ACCELERATION_STRUCTURE_LOW_MEMORY_BIT_KHR; break; + // clang-format on default: UNEXPECTED("unknown build AS flag"); - // clang-format on } } return Result; @@ -1555,7 +1556,8 @@ VkBuildAccelerationStructureFlagsKHR BuildASFlagsToVkBuildAccelerationStructureF VkGeometryFlagsKHR GeometryFlagsToVkGeometryFlags(RAYTRACING_GEOMETRY_FLAGS Flags) { - static_assert(RAYTRACING_GEOMETRY_FLAGS_LAST == 0x02, "AZ TODO"); + static_assert(RAYTRACING_GEOMETRY_FLAGS_LAST == RAYTRACING_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION, + "Please update the switch below to handle the new ray tracing geometry flag"); VkGeometryFlagsKHR Result = 0; for (Uint32 Bit = 1; Bit <= Flags; Bit <<= 1) @@ -1563,13 +1565,13 @@ VkGeometryFlagsKHR GeometryFlagsToVkGeometryFlags(RAYTRACING_GEOMETRY_FLAGS Flag if ((Flags & Bit) != Bit) continue; - switch (RAYTRACING_GEOMETRY_FLAGS(Bit)) + switch (static_cast<RAYTRACING_GEOMETRY_FLAGS>(Bit)) { // clang-format off case RAYTRACING_GEOMETRY_OPAQUE: Result |= VK_GEOMETRY_OPAQUE_BIT_KHR; break; case RAYTRACING_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION: Result |= VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR; break; + // clang-format on default: UNEXPECTED("unknown geometry flag"); - // clang-format on } } return Result; @@ -1577,7 +1579,8 @@ VkGeometryFlagsKHR GeometryFlagsToVkGeometryFlags(RAYTRACING_GEOMETRY_FLAGS Flag VkGeometryInstanceFlagsKHR InstanceFlagsToVkGeometryInstanceFlags(RAYTRACING_INSTANCE_FLAGS Flags) { - static_assert(RAYTRACING_INSTANCE_FLAGS_LAST == 0x08, "AZ TODO"); + static_assert(RAYTRACING_INSTANCE_FLAGS_LAST == RAYTRACING_INSTANCE_FORCE_NO_OPAQUE, + "Please update the switch below to handle the new ray tracing instance flag"); VkGeometryInstanceFlagsKHR Result = 0; for (Uint32 Bit = 1; Bit <= Flags; Bit <<= 1) @@ -1585,15 +1588,15 @@ VkGeometryInstanceFlagsKHR InstanceFlagsToVkGeometryInstanceFlags(RAYTRACING_INS if ((Flags & Bit) != Bit) continue; - switch (RAYTRACING_INSTANCE_FLAGS(Bit)) + switch (static_cast<RAYTRACING_INSTANCE_FLAGS>(Bit)) { // clang-format off - case RAYTRACING_INSTANCE_TRIANGLE_FACING_CULL_DISABLE: return VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR; - case RAYTRACING_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE: return VK_GEOMETRY_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE_BIT_KHR; - case RAYTRACING_INSTANCE_FORCE_OPAQUE: return VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR; - case RAYTRACING_INSTANCE_FORCE_NO_OPAQUE: return VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR; + case RAYTRACING_INSTANCE_TRIANGLE_FACING_CULL_DISABLE: Result |= VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR; break; + case RAYTRACING_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE: Result |= VK_GEOMETRY_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE_BIT_KHR; break; + case RAYTRACING_INSTANCE_FORCE_OPAQUE: Result |= VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR; break; + case RAYTRACING_INSTANCE_FORCE_NO_OPAQUE: Result |= VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR; break; + // clang-format on default: UNEXPECTED("unknown instance flag"); - // clang-format on } } return Result; @@ -1601,17 +1604,18 @@ VkGeometryInstanceFlagsKHR InstanceFlagsToVkGeometryInstanceFlags(RAYTRACING_INS VkCopyAccelerationStructureModeKHR CopyASModeToVkCopyAccelerationStructureMode(COPY_AS_MODE Mode) { - static_assert(COPY_AS_MODE_LAST == 0, "AZ TODO"); + static_assert(COPY_AS_MODE_LAST == COPY_AS_MODE_CLONE, + "Please update the switch below to handle the new copy AS mode"); switch (Mode) { // clang-format off case COPY_AS_MODE_CLONE: return VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR; - // clang-format on + // clang-format on + default: + UNEXPECTED("unknown AS copy mode"); + return static_cast<VkCopyAccelerationStructureModeKHR>(0); } - - UNEXPECTED("unknown AS copy mode"); - return VkCopyAccelerationStructureModeKHR(0); } } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanPhysicalDevice.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanPhysicalDevice.cpp index 22659277..3e5f28d4 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanPhysicalDevice.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanPhysicalDevice.cpp @@ -143,7 +143,7 @@ VulkanPhysicalDevice::VulkanPhysicalDevice(VkPhysicalDevice vkDevice, RayTracingNV.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PROPERTIES_NV; } - // Additional extension that required for ray tracing. + // Additional extension that is required for ray tracing. if (IsExtensionSupported(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME)) { *NextFeat = &m_ExtFeatures.BufferDeviceAddress; @@ -152,7 +152,7 @@ VulkanPhysicalDevice::VulkanPhysicalDevice(VkPhysicalDevice vkDevice, m_ExtFeatures.BufferDeviceAddress.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR; } - // Additional extension that required for ray tracing. + // Additional extension that is required for ray tracing. if (IsExtensionSupported(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME)) { *NextFeat = &m_ExtFeatures.DescriptorIndexing; diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanRayTracingKHRviaNV.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanRayTracingKHRviaNV.cpp index de16fe6a..f7a6b8f6 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanRayTracingKHRviaNV.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanRayTracingKHRviaNV.cpp @@ -25,44 +25,49 @@ * of the possibility of such damages. */ -#include "VulkanErrors.hpp" -#include "VulkanUtilities/VulkanLogicalDevice.hpp" -// for KHR ray tracing emulation +// KHR ray tracing emulation through NVidia extension. +// Will be deprecated after the release of KHR extension. + #include <mutex> #include <unordered_map> +#include <vector> + +#include "VulkanErrors.hpp" +#include "VulkanUtilities/VulkanLogicalDevice.hpp" namespace VulkanUtilities { -// KHR ray tracing emulation. -// Will be deprecated after the release of KHR extension. #if DILIGENT_USE_VOLK -static_assert(sizeof(VkAccelerationStructureKHR) == sizeof(VkAccelerationStructureNV), "not compatible with NV extension"); -static_assert(sizeof(VkDeviceAddress) == 8, "not compatible with NV extension"); - -static std::mutex g_BufferDeviceAddressGuard; -static std::unordered_map<VkDeviceAddress, VkBuffer> g_DeviceAddressToBuffer; -static std::unordered_map<VkBuffer, VkDeviceAddress> g_BufferToDeviceAddress; -static uint32_t g_BufferDeviceAddressCounter = 0; -static const VkDeviceAddress g_BufferMask = 0xFFFFFFFF00000000ull; - -static PFN_vkCreateBuffer Origin_vkCreateBuffer = nullptr; -static PFN_vkDestroyBuffer Origin_vkDestroyBuffer = nullptr; -static PFN_vkGetBufferDeviceAddressKHR Origin_vkGetBufferDeviceAddressKHR = nullptr; - -static VkResult VKAPI_CALL Wrap_vkCreateBuffer(VkDevice device, - const VkBufferCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkBuffer* pBuffer) +static_assert(sizeof(VkAccelerationStructureKHR) == sizeof(VkAccelerationStructureNV), "KHR is incompatible with NV extension"); +static_assert(sizeof(VkDeviceAddress) == 8, "KHR is incompatible with NV extension"); + +namespace +{ + +std::mutex g_BufferDeviceAddressGuard; +std::unordered_map<VkDeviceAddress, VkBuffer> g_DeviceAddressToBuffer; +std::unordered_map<VkBuffer, VkDeviceAddress> g_BufferToDeviceAddress; +uint32_t g_BufferDeviceAddressCounter = 0; +constexpr VkDeviceAddress g_BufferMask = 0xFFFFFFFF00000000ull; + +PFN_vkCreateBuffer Origin_vkCreateBuffer = nullptr; +PFN_vkDestroyBuffer Origin_vkDestroyBuffer = nullptr; +PFN_vkGetBufferDeviceAddressKHR Origin_vkGetBufferDeviceAddressKHR = nullptr; + +VkResult VKAPI_CALL Wrap_vkCreateBuffer(VkDevice device, + const VkBufferCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkBuffer* pBuffer) { const_cast<VkBufferCreateInfo*>(pCreateInfo)->usage &= ~VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; return Origin_vkCreateBuffer(device, pCreateInfo, pAllocator, pBuffer); } -static void VKAPI_CALL Wrap_vkDestroyBuffer(VkDevice device, - VkBuffer buffer, - const VkAllocationCallbacks* pAllocator) +void VKAPI_CALL Wrap_vkDestroyBuffer(VkDevice device, + VkBuffer buffer, + const VkAllocationCallbacks* pAllocator) { Origin_vkDestroyBuffer(device, buffer, pAllocator); @@ -76,8 +81,8 @@ static void VKAPI_CALL Wrap_vkDestroyBuffer(VkDevice device, } } -static VkDeviceAddress VKAPI_CALL Wrap_vkGetBufferDeviceAddressKHR(VkDevice device, - const VkBufferDeviceAddressInfo* pInfo) +VkDeviceAddress VKAPI_CALL Wrap_vkGetBufferDeviceAddressKHR(VkDevice device, + const VkBufferDeviceAddressInfo* pInfo) { VERIFY_EXPR(pInfo->sType == VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO_KHR); VERIFY_EXPR(pInfo->pNext == nullptr); @@ -90,9 +95,9 @@ static VkDeviceAddress VKAPI_CALL Wrap_vkGetBufferDeviceAddressKHR(VkDevice return iter->second; // create new device address - VkDeviceAddress Addr = VkDeviceAddress(++g_BufferDeviceAddressCounter) << 32; - g_BufferToDeviceAddress.insert_or_assign(pInfo->buffer, Addr); - g_DeviceAddressToBuffer.insert_or_assign(Addr, pInfo->buffer); + VkDeviceAddress Addr = VkDeviceAddress{++g_BufferDeviceAddressCounter} << 32; + g_BufferToDeviceAddress[pInfo->buffer] = Addr; + g_DeviceAddressToBuffer[Addr] = pInfo->buffer; return Addr; } @@ -101,7 +106,7 @@ struct BufferAndOffset VkBuffer Buffer; VkDeviceSize Offset; }; -static BufferAndOffset DeviceAddressToBuffer(VkDeviceAddress Addr) +BufferAndOffset DeviceAddressToBuffer(VkDeviceAddress Addr) { if (Addr == 0) return {VK_NULL_HANDLE, 0}; @@ -118,21 +123,21 @@ static BufferAndOffset DeviceAddressToBuffer(VkDeviceAddress Addr) return {iter->second, Addr & ~g_BufferMask}; } -static BufferAndOffset DeviceAddressToBuffer(const VkDeviceOrHostAddressConstKHR& Addr) +BufferAndOffset DeviceAddressToBuffer(const VkDeviceOrHostAddressConstKHR& Addr) { return DeviceAddressToBuffer(Addr.deviceAddress); } -static BufferAndOffset DeviceAddressToBuffer(const VkDeviceOrHostAddressKHR& Addr) +BufferAndOffset DeviceAddressToBuffer(const VkDeviceOrHostAddressKHR& Addr) { return DeviceAddressToBuffer(Addr.deviceAddress); } -static VkResult VKAPI_CALL Redirect_vkCreateAccelerationStructureKHR(VkDevice device, - const VkAccelerationStructureCreateInfoKHR* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkAccelerationStructureKHR* pAccelerationStructure) +VkResult VKAPI_CALL Redirect_vkCreateAccelerationStructureKHR(VkDevice device, + const VkAccelerationStructureCreateInfoKHR* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkAccelerationStructureKHR* pAccelerationStructure) { VERIFY_EXPR(pCreateInfo->sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR); VERIFY_EXPR(pCreateInfo->pNext == nullptr); @@ -219,9 +224,9 @@ static VkResult VKAPI_CALL Redirect_vkCreateAccelerationStructureKHR(VkDevice return vkCreateAccelerationStructureNV(device, &CreateInfo, pAllocator, reinterpret_cast<VkAccelerationStructureNV*>(pAccelerationStructure)); } -static void VKAPI_CALL Redirect_vkGetAccelerationStructureMemoryRequirementsKHR(VkDevice device, - const VkAccelerationStructureMemoryRequirementsInfoKHR* pInfo, - VkMemoryRequirements2* pMemoryRequirements) +void VKAPI_CALL Redirect_vkGetAccelerationStructureMemoryRequirementsKHR(VkDevice device, + const VkAccelerationStructureMemoryRequirementsInfoKHR* pInfo, + VkMemoryRequirements2* pMemoryRequirements) { VERIFY_EXPR(pInfo->sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_KHR); VERIFY_EXPR(pInfo->pNext == nullptr); @@ -236,16 +241,16 @@ static void VKAPI_CALL Redirect_vkGetAccelerationStructureMemoryRequirementsKHR( return vkGetAccelerationStructureMemoryRequirementsNV(device, &Info, pMemoryRequirements); } -static VkResult VKAPI_CALL Redirect_vkBindAccelerationStructureMemoryKHR(VkDevice device, - uint32_t bindInfoCount, - const VkBindAccelerationStructureMemoryInfoKHR* pBindInfos) +VkResult VKAPI_CALL Redirect_vkBindAccelerationStructureMemoryKHR(VkDevice device, + uint32_t bindInfoCount, + const VkBindAccelerationStructureMemoryInfoKHR* pBindInfos) { VERIFY_EXPR(pBindInfos->sType == VK_STRUCTURE_TYPE_BIND_ACCELERATION_STRUCTURE_MEMORY_INFO_NV); return vkBindAccelerationStructureMemoryNV(device, bindInfoCount, pBindInfos); } -static VkDeviceAddress VKAPI_CALL Redirect_vkGetAccelerationStructureDeviceAddressKHR(VkDevice device, - const VkAccelerationStructureDeviceAddressInfoKHR* pInfo) +VkDeviceAddress VKAPI_CALL Redirect_vkGetAccelerationStructureDeviceAddressKHR(VkDevice device, + const VkAccelerationStructureDeviceAddressInfoKHR* pInfo) { VERIFY_EXPR(pInfo->sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR); VERIFY_EXPR(pInfo->pNext == nullptr); @@ -255,10 +260,10 @@ static VkDeviceAddress VKAPI_CALL Redirect_vkGetAccelerationStructureDeviceAddre return result; } -static void VKAPI_CALL Redirect_vkCmdBuildAccelerationStructureKHR(VkCommandBuffer commandBuffer, - uint32_t infoCount, - const VkAccelerationStructureBuildGeometryInfoKHR* pInfos, - const VkAccelerationStructureBuildOffsetInfoKHR* const* ppOffsetInfos) +void VKAPI_CALL Redirect_vkCmdBuildAccelerationStructureKHR(VkCommandBuffer commandBuffer, + uint32_t infoCount, + const VkAccelerationStructureBuildGeometryInfoKHR* pInfos, + const VkAccelerationStructureBuildOffsetInfoKHR* const* ppOffsetInfos) { std::vector<VkGeometryNV> Geometries; @@ -384,8 +389,8 @@ static void VKAPI_CALL Redirect_vkCmdBuildAccelerationStructureKHR(VkCommandBuff } } -static void VKAPI_CALL Redirect_vkCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer, - const VkCopyAccelerationStructureInfoKHR* pInfo) +void VKAPI_CALL Redirect_vkCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer, + const VkCopyAccelerationStructureInfoKHR* pInfo) { VERIFY_EXPR(pInfo->sType == VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_INFO_KHR); VERIFY_EXPR(pInfo->pNext == nullptr); @@ -393,14 +398,14 @@ static void VKAPI_CALL Redirect_vkCmdCopyAccelerationStructureKHR(VkCommandBuffe vkCmdCopyAccelerationStructureNV(commandBuffer, pInfo->dst, pInfo->src, pInfo->mode); } -static void VKAPI_CALL Redirect_vkCmdTraceRaysKHR(VkCommandBuffer commandBuffer, - const VkStridedBufferRegionKHR* pRaygenShaderBindingTable, - const VkStridedBufferRegionKHR* pMissShaderBindingTable, - const VkStridedBufferRegionKHR* pHitShaderBindingTable, - const VkStridedBufferRegionKHR* pCallableShaderBindingTable, - uint32_t width, - uint32_t height, - uint32_t depth) +void VKAPI_CALL Redirect_vkCmdTraceRaysKHR(VkCommandBuffer commandBuffer, + const VkStridedBufferRegionKHR* pRaygenShaderBindingTable, + const VkStridedBufferRegionKHR* pMissShaderBindingTable, + const VkStridedBufferRegionKHR* pHitShaderBindingTable, + const VkStridedBufferRegionKHR* pCallableShaderBindingTable, + uint32_t width, + uint32_t height, + uint32_t depth) { vkCmdTraceRaysNV(commandBuffer, pRaygenShaderBindingTable->buffer, pRaygenShaderBindingTable->offset, @@ -410,22 +415,22 @@ static void VKAPI_CALL Redirect_vkCmdTraceRaysKHR(VkCommandBuffer width, height, depth); } -static VkResult VKAPI_CALL Redirect_vkGetRayTracingShaderGroupHandlesKHR(VkDevice device, - VkPipeline pipeline, - uint32_t firstGroup, - uint32_t groupCount, - size_t dataSize, - void* pData) +VkResult VKAPI_CALL Redirect_vkGetRayTracingShaderGroupHandlesKHR(VkDevice device, + VkPipeline pipeline, + uint32_t firstGroup, + uint32_t groupCount, + size_t dataSize, + void* pData) { return vkGetRayTracingShaderGroupHandlesNV(device, pipeline, firstGroup, groupCount, dataSize, pData); } -static VkResult VKAPI_CALL Redirect_vkCreateRayTracingPipelinesKHR(VkDevice device, - VkPipelineCache pipelineCache, - uint32_t createInfoCount, - const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipelines) +VkResult VKAPI_CALL Redirect_vkCreateRayTracingPipelinesKHR(VkDevice device, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines) { std::vector<VkRayTracingPipelineCreateInfoNV> Infos; std::vector<VkRayTracingShaderGroupCreateInfoNV> Groups; @@ -488,6 +493,8 @@ static VkResult VKAPI_CALL Redirect_vkCreateRayTracingPipelinesKHR(VkDevice return vkCreateRayTracingPipelinesNV(device, pipelineCache, createInfoCount, Infos.data(), pAllocator, pPipelines); } +} // namespace + void EnableRayTracingKHRviaNV() { vkCreateAccelerationStructureKHR = &Redirect_vkCreateAccelerationStructureKHR; |
