From b91d3ed49a11b62fee1c54c61ed941ac9d1fabe6 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 5 Nov 2020 21:21:44 -0800 Subject: Updated TopLevelASBase --- Graphics/GraphicsEngine/CMakeLists.txt | 1 + .../GraphicsEngine/include/BottomLevelASBase.hpp | 4 +- Graphics/GraphicsEngine/include/TopLevelASBase.hpp | 66 ++++++++-------------- Graphics/GraphicsEngine/include/pch.h | 45 --------------- Graphics/GraphicsEngine/src/BottomLevelASBase.cpp | 2 +- Graphics/GraphicsEngine/src/TopLevelASBase.cpp | 65 +++++++++++++++++++++ 6 files changed, 91 insertions(+), 92 deletions(-) delete mode 100644 Graphics/GraphicsEngine/include/pch.h create mode 100644 Graphics/GraphicsEngine/src/TopLevelASBase.cpp (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/CMakeLists.txt b/Graphics/GraphicsEngine/CMakeLists.txt index a5597f77..bf504c37 100644 --- a/Graphics/GraphicsEngine/CMakeLists.txt +++ b/Graphics/GraphicsEngine/CMakeLists.txt @@ -76,6 +76,7 @@ set(SOURCE src/ResourceMappingBase.cpp src/RenderPassBase.cpp src/TextureBase.cpp + src/TopLevelASBase.cpp ) add_library(Diligent-GraphicsEngine STATIC ${SOURCE} ${INTERFACE} ${INCLUDE}) diff --git a/Graphics/GraphicsEngine/include/BottomLevelASBase.hpp b/Graphics/GraphicsEngine/include/BottomLevelASBase.hpp index ddb5dd22..2f4a26d0 100644 --- a/Graphics/GraphicsEngine/include/BottomLevelASBase.hpp +++ b/Graphics/GraphicsEngine/include/BottomLevelASBase.hpp @@ -54,8 +54,8 @@ void CopyBottomLevelASDesc(const BottomLevelASDesc& /// Template class implementing base functionality for a bottom-level acceleration structure object. -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IBottomLevelASD3D12 or Diligent::IBottomLevelASVk). +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::IBottomLevelASD3D12 or Diligent::IBottomLevelASVk). /// \tparam RenderDeviceImplType - type of the render device implementation /// (Diligent::RenderDeviceD3D12Impl or Diligent::RenderDeviceVkImpl) template diff --git a/Graphics/GraphicsEngine/include/TopLevelASBase.hpp b/Graphics/GraphicsEngine/include/TopLevelASBase.hpp index 47cf50dd..392f1130 100644 --- a/Graphics/GraphicsEngine/include/TopLevelASBase.hpp +++ b/Graphics/GraphicsEngine/include/TopLevelASBase.hpp @@ -41,10 +41,13 @@ namespace Diligent { +/// Validates top-level AS description and throws an exception in case of an error. +void ValidateTopLevelASDesc(const TopLevelASDesc& Desc) noexcept(false); + /// Template class implementing base functionality for a top-level acceleration structure object. -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ITopLevelASD3D12 or Diligent::ITopLevelASVk). +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::ITopLevelASD3D12 or Diligent::ITopLevelASVk). /// \tparam RenderDeviceImplType - type of the render device implementation /// (Diligent::RenderDeviceD3D12Impl or Diligent::RenderDeviceVkImpl) template @@ -64,25 +67,28 @@ public: bool bIsDeviceInternal = false) : TDeviceObjectBase{pRefCounters, pDevice, Desc, bIsDeviceInternal} { - ValidateTopLevelASDesc(Desc); + ValidateTopLevelASDesc(this->m_Desc); } ~TopLevelASBase() { } + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_TopLevelAS, TDeviceObjectBase) + void SetInstanceData(const TLASBuildInstanceData* pInstances, Uint32 InstanceCount, Uint32 HitShadersPerInstance) noexcept { try { - this->m_Instances.clear(); - this->m_StringPool.Release(); + ClearInstanceData(); + this->m_HitShadersPerInstance = HitShadersPerInstance; size_t StringPoolSize = 0; for (Uint32 i = 0; i < InstanceCount; ++i) { - StringPoolSize += strlen(pInstances[i].InstanceName) + 1; + VERIFY_EXPR(pInstances[i].InstanceName != nullptr); + StringPoolSize += StringPool::GetRequiredReserveSize(pInstances[i].InstanceName); } this->m_StringPool.Reserve(StringPoolSize, GetRawAllocator()); @@ -112,7 +118,7 @@ public: case SHADER_BINDING_MODE_PER_GEOMETRY: InstanceOffset += (BLASDesc.TriangleCount + BLASDesc.BoxCount) * HitShadersPerInstance; break; case SHADER_BINDING_MODE_PER_INSTANCE: InstanceOffset += HitShadersPerInstance; break; case SHADER_BINDING_USER_DEFINED: UNEXPECTED("TLAS_INSTANCE_OFFSET_AUTO is not compatible with SHADER_BINDING_USER_DEFINED"); break; - default: UNEXPECTED("unknown ray tracing shader binding mode"); + default: UNEXPECTED("Unknown ray tracing shader binding mode"); // clang-format on } } @@ -126,14 +132,14 @@ public: } catch (...) { - this->m_Instances.clear(); + ClearInstanceData(); } } void CopyInstancceData(const TopLevelASBase& Src) noexcept { - this->m_Instances.clear(); - this->m_StringPool.Release(); + ClearInstanceData(); + this->m_StringPool.Reserve(Src.m_StringPool.GetReservedSize(), GetRawAllocator()); this->m_HitShadersPerInstance = Src.m_HitShadersPerInstance; this->m_Desc.BindingMode = Src.m_Desc.BindingMode; @@ -202,8 +208,8 @@ public: result = false; } - // validate instances - for (auto& NameAndInst : m_Instances) + // Validate instances + for (const auto& NameAndInst : m_Instances) { const InstanceDesc& Inst = NameAndInst.second; const BottomLevelASDesc& Desc = Inst.pBLAS->GetDesc(); @@ -231,41 +237,13 @@ public: } #endif -protected: - static void ValidateTopLevelASDesc(const TopLevelASDesc& Desc) +private: + void ClearInstanceData() { -#define LOG_TLAS_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Description of Top-level AS '", (Desc.Name ? Desc.Name : ""), "' is invalid: ", ##__VA_ARGS__) - - if (Desc.CompactedSize > 0) - { - if (Desc.MaxInstanceCount != 0) - { - LOG_TLAS_ERROR_AND_THROW("If CompactedSize is specified then MaxInstanceCount must be zero"); - } - - if (Desc.Flags != RAYTRACING_BUILD_AS_NONE) - { - LOG_TLAS_ERROR_AND_THROW("If CompactedSize is specified then Flags must be RAYTRACING_BUILD_AS_NONE"); - } - } - else - { - if (Desc.MaxInstanceCount == 0) - { - LOG_TLAS_ERROR_AND_THROW("MaxInstanceCount must not be zero"); - } - - if ((Desc.Flags & RAYTRACING_BUILD_AS_PREFER_FAST_TRACE) && (Desc.Flags & RAYTRACING_BUILD_AS_PREFER_FAST_BUILD)) - { - LOG_TLAS_ERROR_AND_THROW("can not set both flags RAYTRACING_BUILD_AS_PREFER_FAST_TRACE and RAYTRACING_BUILD_AS_PREFER_FAST_BUILD"); - } - } - -#undef LOG_TLAS_ERROR_AND_THROW + this->m_Instances.clear(); + this->m_StringPool.Release(); } - IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_TopLevelAS, TDeviceObjectBase) - protected: RESOURCE_STATE m_State = RESOURCE_STATE_UNKNOWN; Uint32 m_HitShadersPerInstance = 0; diff --git a/Graphics/GraphicsEngine/include/pch.h b/Graphics/GraphicsEngine/include/pch.h deleted file mode 100644 index 74889e44..00000000 --- a/Graphics/GraphicsEngine/include/pch.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019-2020 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -/// \file -/// Precomputed header - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include "GraphicsTypes.h" -#include "RefCntAutoPtr.hpp" -#include "Errors.hpp" -#include "DebugUtilities.hpp" -#include "RenderDeviceBase.hpp" -#include "DeviceContextBase.hpp" \ No newline at end of file diff --git a/Graphics/GraphicsEngine/src/BottomLevelASBase.cpp b/Graphics/GraphicsEngine/src/BottomLevelASBase.cpp index 092161b7..46d82244 100644 --- a/Graphics/GraphicsEngine/src/BottomLevelASBase.cpp +++ b/Graphics/GraphicsEngine/src/BottomLevelASBase.cpp @@ -53,7 +53,7 @@ void ValidateBottomLevelASDesc(const BottomLevelASDesc& Desc) noexcept(false) if (Desc.pTriangles == nullptr && Desc.TriangleCount > 0) LOG_BLAS_ERROR_AND_THROW("pTriangles is null, but TriangleCount is not 0"); - if ((Desc.Flags & RAYTRACING_BUILD_AS_PREFER_FAST_TRACE) && (Desc.Flags & RAYTRACING_BUILD_AS_PREFER_FAST_BUILD)) + if ((Desc.Flags & RAYTRACING_BUILD_AS_PREFER_FAST_TRACE) != 0 && (Desc.Flags & RAYTRACING_BUILD_AS_PREFER_FAST_BUILD) != 0) LOG_BLAS_ERROR_AND_THROW("RAYTRACING_BUILD_AS_PREFER_FAST_TRACE and RAYTRACING_BUILD_AS_PREFER_FAST_BUILD flags are mutually exclusive"); for (Uint32 i = 0; i < Desc.TriangleCount; ++i) diff --git a/Graphics/GraphicsEngine/src/TopLevelASBase.cpp b/Graphics/GraphicsEngine/src/TopLevelASBase.cpp new file mode 100644 index 00000000..5ccc51c4 --- /dev/null +++ b/Graphics/GraphicsEngine/src/TopLevelASBase.cpp @@ -0,0 +1,65 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "TopLevelASBase.hpp" + +namespace Diligent +{ + +void ValidateTopLevelASDesc(const TopLevelASDesc& Desc) noexcept(false) +{ +#define LOG_TLAS_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Description of a top-level AS '", (Desc.Name ? Desc.Name : ""), "' is invalid: ", ##__VA_ARGS__) + + if (Desc.CompactedSize > 0) + { + if (Desc.MaxInstanceCount != 0) + { + LOG_TLAS_ERROR_AND_THROW("If non-zero CompactedSize is specified, MaxInstanceCount must be zero"); + } + + if (Desc.Flags != RAYTRACING_BUILD_AS_NONE) + { + LOG_TLAS_ERROR_AND_THROW("If non-zero CompactedSize is specified, Flags must be RAYTRACING_BUILD_AS_NONE"); + } + } + else + { + if (Desc.MaxInstanceCount == 0) + { + LOG_TLAS_ERROR_AND_THROW("MaxInstanceCount must not be zero"); + } + + if ((Desc.Flags & RAYTRACING_BUILD_AS_PREFER_FAST_TRACE) != 0 && (Desc.Flags & RAYTRACING_BUILD_AS_PREFER_FAST_BUILD) != 0) + { + LOG_TLAS_ERROR_AND_THROW("RAYTRACING_BUILD_AS_PREFER_FAST_TRACE and RAYTRACING_BUILD_AS_PREFER_FAST_BUILD flags are mutually exclusive"); + } + } + +#undef LOG_TLAS_ERROR_AND_THROW +} + +} // namespace Diligent -- cgit v1.2.3