diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-11-06 05:21:44 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-11-06 05:21:44 +0000 |
| commit | b91d3ed49a11b62fee1c54c61ed941ac9d1fabe6 (patch) | |
| tree | 636b35d76378cc0fa3fd8aec4e2e102126526e93 /Graphics/GraphicsEngine | |
| parent | Fixed gcc error plus few minor updates (diff) | |
| download | DiligentCore-b91d3ed49a11b62fee1c54c61ed941ac9d1fabe6.tar.gz DiligentCore-b91d3ed49a11b62fee1c54c61ed941ac9d1fabe6.zip | |
Updated TopLevelASBase
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/BottomLevelASBase.hpp | 4 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/TopLevelASBase.hpp | 66 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/src/BottomLevelASBase.cpp | 2 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/src/TopLevelASBase.cpp (renamed from Graphics/GraphicsEngine/include/pch.h) | 56 |
5 files changed, 64 insertions, 65 deletions
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 <class BaseInterface, class RenderDeviceImplType> 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 <class BaseInterface, class BottomLevelASType, class RenderDeviceImplType> @@ -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/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/include/pch.h b/Graphics/GraphicsEngine/src/TopLevelASBase.cpp index 74889e44..5ccc51c4 100644 --- a/Graphics/GraphicsEngine/include/pch.h +++ b/Graphics/GraphicsEngine/src/TopLevelASBase.cpp @@ -25,21 +25,41 @@ * of the possibility of such damages. */ -/// \file -/// Precomputed header - -#pragma once - -#include <vector> -#include <list> -#include <set> -#include <map> -#include <unordered_map> -#include <memory> -#include <algorithm> -#include "GraphicsTypes.h" -#include "RefCntAutoPtr.hpp" -#include "Errors.hpp" -#include "DebugUtilities.hpp" -#include "RenderDeviceBase.hpp" -#include "DeviceContextBase.hpp"
\ No newline at end of file +#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 |
