From bb782e83b46d41fd8a64b7ce4a62aa598913d7c9 Mon Sep 17 00:00:00 2001 From: Jeremy Ong Date: Wed, 28 Jul 2021 09:33:28 -0600 Subject: [PATCH 1/4] Promote IndexedDataVector to public Feature/Utils header Signed-off-by: Jeremy Ong --- .../Atom/Feature/Utils}/IndexedDataVector.h | 0 .../Atom/Feature/Utils}/IndexedDataVector.inl | 0 .../Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp | 2 +- .../Code/Source/CoreLights/CapsuleLightFeatureProcessor.h | 2 +- .../Code/Source/CoreLights/DirectionalLightFeatureProcessor.h | 2 +- .../Common/Code/Source/CoreLights/DiskLightFeatureProcessor.h | 2 +- .../Code/Source/CoreLights/PointLightFeatureProcessor.h | 2 +- .../Common/Code/Source/CoreLights/QuadLightFeatureProcessor.h | 2 +- .../Code/Source/CoreLights/SimplePointLightFeatureProcessor.h | 2 +- .../Code/Source/CoreLights/SimpleSpotLightFeatureProcessor.h | 2 +- .../Code/Source/Decals/DecalTextureArrayFeatureProcessor.h | 2 +- .../Code/Source/Shadows/ProjectedShadowFeatureProcessor.h | 2 +- Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake | 4 ++-- 13 files changed, 12 insertions(+), 12 deletions(-) rename Gems/Atom/Feature/Common/Code/{Source/CoreLights => Include/Atom/Feature/Utils}/IndexedDataVector.h (100%) rename Gems/Atom/Feature/Common/Code/{Source/CoreLights => Include/Atom/Feature/Utils}/IndexedDataVector.inl (100%) diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/IndexedDataVector.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h similarity index 100% rename from Gems/Atom/Feature/Common/Code/Source/CoreLights/IndexedDataVector.h rename to Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/IndexedDataVector.inl b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl similarity index 100% rename from Gems/Atom/Feature/Common/Code/Source/CoreLights/IndexedDataVector.inl rename to Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl diff --git a/Gems/Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp b/Gems/Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp index 6ad0099686..1500079b00 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/CommonSystemComponent.cpp @@ -284,7 +284,7 @@ namespace AZ passSystem->AddPassCreator(Name("ReflectionScreenSpaceCompositePass"), &Render::ReflectionScreenSpaceCompositePass::Create); passSystem->AddPassCreator(Name("ReflectionCopyFrameBufferPass"), &Render::ReflectionCopyFrameBufferPass::Create); - // Add RayTracing pas + // Add RayTracing pass passSystem->AddPassCreator(Name("RayTracingPass"), &Render::RayTracingPass::Create); // setup handler for load pass template mappings diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/CapsuleLightFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/CoreLights/CapsuleLightFeatureProcessor.h index a85831e290..6749acfcf5 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CoreLights/CapsuleLightFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/CoreLights/CapsuleLightFeatureProcessor.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include namespace AZ diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/DirectionalLightFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/CoreLights/DirectionalLightFeatureProcessor.h index a312b31dda..4c486c4540 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CoreLights/DirectionalLightFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/CoreLights/DirectionalLightFeatureProcessor.h @@ -9,9 +9,9 @@ #pragma once #include -#include #include +#include #include #include #include diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/DiskLightFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/CoreLights/DiskLightFeatureProcessor.h index 2e97ae1ded..36837a67fb 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CoreLights/DiskLightFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/CoreLights/DiskLightFeatureProcessor.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include namespace AZ diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/PointLightFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/CoreLights/PointLightFeatureProcessor.h index b7b644da9e..3c231c1fb0 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CoreLights/PointLightFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/CoreLights/PointLightFeatureProcessor.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include namespace AZ diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/QuadLightFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/CoreLights/QuadLightFeatureProcessor.h index 567d309dff..17d6aab304 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CoreLights/QuadLightFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/CoreLights/QuadLightFeatureProcessor.h @@ -10,7 +10,7 @@ #include #include -#include +#include namespace AZ { diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/SimplePointLightFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/CoreLights/SimplePointLightFeatureProcessor.h index 3d36bb1978..bd9160b171 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CoreLights/SimplePointLightFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/CoreLights/SimplePointLightFeatureProcessor.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include namespace AZ { diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/SimpleSpotLightFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/CoreLights/SimpleSpotLightFeatureProcessor.h index 1d72c3e6cc..bc132be77c 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CoreLights/SimpleSpotLightFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/CoreLights/SimpleSpotLightFeatureProcessor.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include namespace AZ { diff --git a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h index 649928d26d..57c5c69e0d 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/Decals/DecalTextureArrayFeatureProcessor.h @@ -9,6 +9,7 @@ #pragma once #include +#include #include #include #include @@ -16,7 +17,6 @@ #include #include #include -#include namespace AZ { diff --git a/Gems/Atom/Feature/Common/Code/Source/Shadows/ProjectedShadowFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Source/Shadows/ProjectedShadowFeatureProcessor.h index 3dbf88addb..8beed800b6 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Shadows/ProjectedShadowFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Source/Shadows/ProjectedShadowFeatureProcessor.h @@ -10,10 +10,10 @@ #include #include +#include #include #include #include -#include namespace AZ::Render { diff --git a/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake b/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake index 401fac8c0c..40188109ca 100644 --- a/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake +++ b/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake @@ -37,6 +37,8 @@ set(FILES Include/Atom/Feature/TransformService/TransformServiceFeatureProcessor.h Include/Atom/Feature/Utils/FrameCaptureBus.h Include/Atom/Feature/Utils/GpuBufferHandler.h + Include/Atom/Feature/Utils/IndexedDataVector.h + Include/Atom/Feature/Utils/IndexedDataVector.inl Include/Atom/Feature/Utils/MultiIndexedDataVector.h Include/Atom/Feature/Utils/MultiSparseVector.h Include/Atom/Feature/Utils/ProfilingCaptureBus.h @@ -77,8 +79,6 @@ set(FILES Source/CoreLights/DiskLightFeatureProcessor.cpp Source/CoreLights/EsmShadowmapsPass.h Source/CoreLights/EsmShadowmapsPass.cpp - Source/CoreLights/IndexedDataVector.h - Source/CoreLights/IndexedDataVector.inl Source/CoreLights/LtcCommon.h Source/CoreLights/LtcCommon.cpp Source/CoreLights/PointLightFeatureProcessor.h From e1ce742f14f096e9a2e9d0a7af68cca9068f8628 Mon Sep 17 00:00:00 2001 From: Jeremy Ong Date: Wed, 28 Jul 2021 12:30:06 -0600 Subject: [PATCH 2/4] Generalize comments pertaining to light data and consolidate inline header Signed-off-by: Jeremy Ong --- .../Atom/Feature/Utils/IndexedDataVector.h | 128 ++++++++++++++++-- .../Atom/Feature/Utils/IndexedDataVector.inl | 113 ---------------- .../Code/atom_feature_common_files.cmake | 1 - 3 files changed, 120 insertions(+), 122 deletions(-) delete mode 100644 Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h index f2a372aca9..a73ba2f16b 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h @@ -15,11 +15,15 @@ namespace AZ { namespace Render { + // Growable vector that leverages indirection to support erasure of elements while maintaining + // resident data in a densely packed region of memory. Useful as a backing store for growable + // buffers intended to be uploaded to the GPU for example. template class IndexedDataVector { public: IndexedDataVector(); + explicit IndexedDataVector(size_t initialReservedSize); ~IndexedDataVector() = default; static constexpr IndexType NoFreeSlot = std::numeric_limits::max(); @@ -39,17 +43,125 @@ namespace AZ IndexType GetRawIndex(IndexType index) const; private: + constexpr static size_t InitialReservedSize = 128; - static constexpr size_t InitialReservedCount = 128; - - // stores the index of data vector for respective light, it also include a linked list to flag the free slots + // Stores data indices and an embedded free list AZStd::vector m_indices; - // stores the index of index vector for respective light + // Stores the indirection index AZStd::vector m_dataToIndices; - // stores light data AZStd::vector m_data; }; -#include "IndexedDataVector.inl" - } -} + template + inline IndexedDataVector::IndexedDataVector() + : IndexedDataVector(InitialReservedSize) + { + } + + template + inline IndexedDataVector::IndexedDataVector(size_t initialReservedSize) + { + m_dataToIndices.reserve(initialReservedSize); + m_indices.reserve(initialReservedSize); + m_data.reserve(initialReservedSize); + } + + template + inline void IndexedDataVector::Clear() + { + m_dataToIndices.clear(); + m_indices.clear(); + m_data.clear(); + + m_firstFreeSlot = NoFreeSlot; + } + + template + inline IndexType IndexedDataVector::GetFreeSlotIndex() + { + IndexType freeSlotIndex = static_cast(m_indices.size()); + + if (freeSlotIndex == NoFreeSlot) + { + // the vector is full + return NoFreeSlot; + } + + if (m_firstFreeSlot == NoFreeSlot) + { + // If there's no free slot, add on to the end. + m_indices.push_back(freeSlotIndex); + } + else + { + // Fill the free slot. m_indices uses it's empty slots to store a linked list (via indices) to other empty slots. + freeSlotIndex = m_firstFreeSlot; + m_firstFreeSlot = m_indices.at(m_firstFreeSlot); + m_indices.at(freeSlotIndex) = static_cast(m_data.size()); + } + + // The data itself is always packed and m_indices points at it, so push a new entry to the back. + m_data.push_back(DataType()); + m_dataToIndices.push_back(freeSlotIndex); + + return freeSlotIndex; + } + + template + inline void IndexedDataVector::RemoveIndex(IndexType index) + { + IndexType dataIndex = m_indices.at(index); + + // Copy the back light on top of this one. + m_data.at(dataIndex) = m_data.back(); + m_dataToIndices.at(dataIndex) = m_dataToIndices.back(); + + // Update the index of the moved light + m_indices.at(m_dataToIndices.at(dataIndex)) = dataIndex; + + // Pop the back + m_data.pop_back(); + m_dataToIndices.pop_back(); + + // Use free slot to link to next free slot + m_indices.at(index) = m_firstFreeSlot; + m_firstFreeSlot = index; + } + + template + inline DataType& IndexedDataVector::GetData(IndexType index) + { + return m_data.at(m_indices.at(index)); + } + + template + inline const DataType& IndexedDataVector::GetData(IndexType index) const + { + return m_data.at(m_indices.at(index)); + } + + template + inline size_t IndexedDataVector::GetDataCount() const + { + return m_data.size(); + } + + template + inline AZStd::vector& IndexedDataVector::GetDataVector() + { + return m_data; + } + + template + inline const AZStd::vector& IndexedDataVector::GetDataVector() const + { + return m_data; + } + + template + IndexType IndexedDataVector::GetRawIndex(IndexType index) const + { + return m_indices.at(index); + } + } // namespace Render +} // namespace AZ diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl deleted file mode 100644 index da10e5a503..0000000000 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -template -inline IndexedDataVector::IndexedDataVector() -{ - m_dataToIndices.reserve(InitialReservedCount); - m_indices.reserve(InitialReservedCount); - m_data.reserve(InitialReservedCount); -} - -template -inline void IndexedDataVector::Clear() -{ - m_dataToIndices.clear(); - m_indices.clear(); - m_data.clear(); - - m_firstFreeSlot = NoFreeSlot; -} - -template -inline IndexType IndexedDataVector::GetFreeSlotIndex() -{ - IndexType freeSlotIndex = static_cast(m_indices.size()); - - if (freeSlotIndex == NoFreeSlot) - { - // the vector is full - return NoFreeSlot; - } - - if (m_firstFreeSlot == NoFreeSlot) - { - // If there's no free slot, add on to the end. - m_indices.push_back(freeSlotIndex); - } - else - { - // Fill the free slot. m_indices uses it's empty slots to store a linked list (via indices) to other empty slots. - freeSlotIndex = m_firstFreeSlot; - m_firstFreeSlot = m_indices.at(m_firstFreeSlot); - m_indices.at(freeSlotIndex) = static_cast(m_data.size()); - } - - // The data itself is always packed and m_indices points at it, so push a new entry to the back. - m_data.push_back(DataType()); - m_dataToIndices.push_back(freeSlotIndex); - - return freeSlotIndex; -} - -template -inline void IndexedDataVector::RemoveIndex(IndexType index) -{ - IndexType dataIndex = m_indices.at(index); - - // Copy the back light on top of this one. - m_data.at(dataIndex) = m_data.back(); - m_dataToIndices.at(dataIndex) = m_dataToIndices.back(); - - // Update the index of the moved light - m_indices.at(m_dataToIndices.at(dataIndex)) = dataIndex; - - // Pop the back - m_data.pop_back(); - m_dataToIndices.pop_back(); - - // Use free slot to link to next free slot - m_indices.at(index) = m_firstFreeSlot; - m_firstFreeSlot = index; -} - -template -inline DataType& IndexedDataVector::GetData(IndexType index) -{ - return m_data.at(m_indices.at(index)); -} - -template -inline const DataType& IndexedDataVector::GetData(IndexType index) const -{ - return m_data.at(m_indices.at(index)); -} - -template -inline size_t IndexedDataVector::GetDataCount() const -{ - return m_data.size(); -} - -template -inline AZStd::vector& IndexedDataVector::GetDataVector() -{ - return m_data; -} - -template -inline const AZStd::vector& IndexedDataVector::GetDataVector() const -{ - return m_data; -} - -template -IndexType IndexedDataVector::GetRawIndex(IndexType index) const -{ - return m_indices.at(index); -} diff --git a/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake b/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake index 40188109ca..e4a914ac34 100644 --- a/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake +++ b/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake @@ -38,7 +38,6 @@ set(FILES Include/Atom/Feature/Utils/FrameCaptureBus.h Include/Atom/Feature/Utils/GpuBufferHandler.h Include/Atom/Feature/Utils/IndexedDataVector.h - Include/Atom/Feature/Utils/IndexedDataVector.inl Include/Atom/Feature/Utils/MultiIndexedDataVector.h Include/Atom/Feature/Utils/MultiSparseVector.h Include/Atom/Feature/Utils/ProfilingCaptureBus.h From 78760245c5a96d81881ccc2b800c2a58390a3a5c Mon Sep 17 00:00:00 2001 From: Jeremy Ong Date: Wed, 28 Jul 2021 15:26:41 -0600 Subject: [PATCH 3/4] Remove one level of indentation Signed-off-by: Jeremy Ong --- .../Atom/Feature/Utils/IndexedDataVector.h | 267 +++++++++--------- 1 file changed, 132 insertions(+), 135 deletions(-) diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h index a73ba2f16b..9231813d36 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h @@ -8,160 +8,157 @@ #pragma once -#include #include +#include -namespace AZ +namespace AZ::Render { - namespace Render + // Growable vector that leverages indirection to support erasure of elements while maintaining + // resident data in a densely packed region of memory. Useful as a backing store for growable + // buffers intended to be uploaded to the GPU for example. + template + class IndexedDataVector { - // Growable vector that leverages indirection to support erasure of elements while maintaining - // resident data in a densely packed region of memory. Useful as a backing store for growable - // buffers intended to be uploaded to the GPU for example. - template - class IndexedDataVector - { - public: - IndexedDataVector(); - explicit IndexedDataVector(size_t initialReservedSize); - ~IndexedDataVector() = default; - - static constexpr IndexType NoFreeSlot = std::numeric_limits::max(); - IndexType m_firstFreeSlot = NoFreeSlot; - - void Clear(); - IndexType GetFreeSlotIndex(); - void RemoveIndex(IndexType index); - - DataType& GetData(IndexType index); - const DataType& GetData(IndexType index) const; - size_t GetDataCount() const; - - AZStd::vector& GetDataVector(); - const AZStd::vector& GetDataVector() const; - - IndexType GetRawIndex(IndexType index) const; - - private: - constexpr static size_t InitialReservedSize = 128; - - // Stores data indices and an embedded free list - AZStd::vector m_indices; - // Stores the indirection index - AZStd::vector m_dataToIndices; - AZStd::vector m_data; - }; - - template - inline IndexedDataVector::IndexedDataVector() - : IndexedDataVector(InitialReservedSize) + public: + IndexedDataVector(); + explicit IndexedDataVector(size_t initialReservedSize); + ~IndexedDataVector() = default; + + static constexpr IndexType NoFreeSlot = std::numeric_limits::max(); + IndexType m_firstFreeSlot = NoFreeSlot; + + void Clear(); + IndexType GetFreeSlotIndex(); + void RemoveIndex(IndexType index); + + DataType& GetData(IndexType index); + const DataType& GetData(IndexType index) const; + size_t GetDataCount() const; + + AZStd::vector& GetDataVector(); + const AZStd::vector& GetDataVector() const; + + IndexType GetRawIndex(IndexType index) const; + + private: + constexpr static size_t InitialReservedSize = 128; + + // Stores data indices and an embedded free list + AZStd::vector m_indices; + // Stores the indirection index + AZStd::vector m_dataToIndices; + AZStd::vector m_data; + }; + + template + inline IndexedDataVector::IndexedDataVector() + : IndexedDataVector(InitialReservedSize) + { + } + + template + inline IndexedDataVector::IndexedDataVector(size_t initialReservedSize) + { + m_dataToIndices.reserve(initialReservedSize); + m_indices.reserve(initialReservedSize); + m_data.reserve(initialReservedSize); + } + + template + inline void IndexedDataVector::Clear() + { + m_dataToIndices.clear(); + m_indices.clear(); + m_data.clear(); + + m_firstFreeSlot = NoFreeSlot; + } + + template + inline IndexType IndexedDataVector::GetFreeSlotIndex() + { + IndexType freeSlotIndex = static_cast(m_indices.size()); + + if (freeSlotIndex == NoFreeSlot) { + // the vector is full + return NoFreeSlot; } - template - inline IndexedDataVector::IndexedDataVector(size_t initialReservedSize) + if (m_firstFreeSlot == NoFreeSlot) { - m_dataToIndices.reserve(initialReservedSize); - m_indices.reserve(initialReservedSize); - m_data.reserve(initialReservedSize); + // If there's no free slot, add on to the end. + m_indices.push_back(freeSlotIndex); + } + else + { + // Fill the free slot. m_indices uses it's empty slots to store a linked list (via indices) to other empty slots. + freeSlotIndex = m_firstFreeSlot; + m_firstFreeSlot = m_indices.at(m_firstFreeSlot); + m_indices.at(freeSlotIndex) = static_cast(m_data.size()); } - template - inline void IndexedDataVector::Clear() - { - m_dataToIndices.clear(); - m_indices.clear(); - m_data.clear(); + // The data itself is always packed and m_indices points at it, so push a new entry to the back. + m_data.push_back(DataType()); + m_dataToIndices.push_back(freeSlotIndex); - m_firstFreeSlot = NoFreeSlot; - } + return freeSlotIndex; + } - template - inline IndexType IndexedDataVector::GetFreeSlotIndex() - { - IndexType freeSlotIndex = static_cast(m_indices.size()); + template + inline void IndexedDataVector::RemoveIndex(IndexType index) + { + IndexType dataIndex = m_indices.at(index); - if (freeSlotIndex == NoFreeSlot) - { - // the vector is full - return NoFreeSlot; - } + // Copy the back light on top of this one. + m_data.at(dataIndex) = m_data.back(); + m_dataToIndices.at(dataIndex) = m_dataToIndices.back(); - if (m_firstFreeSlot == NoFreeSlot) - { - // If there's no free slot, add on to the end. - m_indices.push_back(freeSlotIndex); - } - else - { - // Fill the free slot. m_indices uses it's empty slots to store a linked list (via indices) to other empty slots. - freeSlotIndex = m_firstFreeSlot; - m_firstFreeSlot = m_indices.at(m_firstFreeSlot); - m_indices.at(freeSlotIndex) = static_cast(m_data.size()); - } + // Update the index of the moved light + m_indices.at(m_dataToIndices.at(dataIndex)) = dataIndex; - // The data itself is always packed and m_indices points at it, so push a new entry to the back. - m_data.push_back(DataType()); - m_dataToIndices.push_back(freeSlotIndex); + // Pop the back + m_data.pop_back(); + m_dataToIndices.pop_back(); - return freeSlotIndex; - } + // Use free slot to link to next free slot + m_indices.at(index) = m_firstFreeSlot; + m_firstFreeSlot = index; + } - template - inline void IndexedDataVector::RemoveIndex(IndexType index) - { - IndexType dataIndex = m_indices.at(index); + template + inline DataType& IndexedDataVector::GetData(IndexType index) + { + return m_data.at(m_indices.at(index)); + } - // Copy the back light on top of this one. - m_data.at(dataIndex) = m_data.back(); - m_dataToIndices.at(dataIndex) = m_dataToIndices.back(); + template + inline const DataType& IndexedDataVector::GetData(IndexType index) const + { + return m_data.at(m_indices.at(index)); + } - // Update the index of the moved light - m_indices.at(m_dataToIndices.at(dataIndex)) = dataIndex; + template + inline size_t IndexedDataVector::GetDataCount() const + { + return m_data.size(); + } - // Pop the back - m_data.pop_back(); - m_dataToIndices.pop_back(); + template + inline AZStd::vector& IndexedDataVector::GetDataVector() + { + return m_data; + } - // Use free slot to link to next free slot - m_indices.at(index) = m_firstFreeSlot; - m_firstFreeSlot = index; - } + template + inline const AZStd::vector& IndexedDataVector::GetDataVector() const + { + return m_data; + } - template - inline DataType& IndexedDataVector::GetData(IndexType index) - { - return m_data.at(m_indices.at(index)); - } - - template - inline const DataType& IndexedDataVector::GetData(IndexType index) const - { - return m_data.at(m_indices.at(index)); - } - - template - inline size_t IndexedDataVector::GetDataCount() const - { - return m_data.size(); - } - - template - inline AZStd::vector& IndexedDataVector::GetDataVector() - { - return m_data; - } - - template - inline const AZStd::vector& IndexedDataVector::GetDataVector() const - { - return m_data; - } - - template - IndexType IndexedDataVector::GetRawIndex(IndexType index) const - { - return m_indices.at(index); - } - } // namespace Render -} // namespace AZ + template + IndexType IndexedDataVector::GetRawIndex(IndexType index) const + { + return m_indices.at(index); + } +} // namespace AZ::Render From 68a7a21e62f31633b3ab0f7b0c7f0476188549f4 Mon Sep 17 00:00:00 2001 From: Jeremy Ong Date: Sat, 31 Jul 2021 00:25:53 -0600 Subject: [PATCH 4/4] Reintroduce .h and .inl split Signed-off-by: Jeremy Ong --- .../Atom/Feature/Utils/IndexedDataVector.h | 117 +-------------- .../Atom/Feature/Utils/IndexedDataVector.inl | 134 ++++++++++++++++++ .../Code/atom_feature_common_files.cmake | 1 + 3 files changed, 140 insertions(+), 112 deletions(-) create mode 100644 Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h index 9231813d36..37835bd6a8 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.h @@ -38,6 +38,9 @@ namespace AZ::Render AZStd::vector& GetDataVector(); const AZStd::vector& GetDataVector() const; + AZStd::vector& GetIndexVector(); + const AZStd::vector& GetIndexVector() const; + IndexType GetRawIndex(IndexType index) const; private: @@ -49,116 +52,6 @@ namespace AZ::Render AZStd::vector m_dataToIndices; AZStd::vector m_data; }; - - template - inline IndexedDataVector::IndexedDataVector() - : IndexedDataVector(InitialReservedSize) - { - } - - template - inline IndexedDataVector::IndexedDataVector(size_t initialReservedSize) - { - m_dataToIndices.reserve(initialReservedSize); - m_indices.reserve(initialReservedSize); - m_data.reserve(initialReservedSize); - } - - template - inline void IndexedDataVector::Clear() - { - m_dataToIndices.clear(); - m_indices.clear(); - m_data.clear(); - - m_firstFreeSlot = NoFreeSlot; - } - - template - inline IndexType IndexedDataVector::GetFreeSlotIndex() - { - IndexType freeSlotIndex = static_cast(m_indices.size()); - - if (freeSlotIndex == NoFreeSlot) - { - // the vector is full - return NoFreeSlot; - } - - if (m_firstFreeSlot == NoFreeSlot) - { - // If there's no free slot, add on to the end. - m_indices.push_back(freeSlotIndex); - } - else - { - // Fill the free slot. m_indices uses it's empty slots to store a linked list (via indices) to other empty slots. - freeSlotIndex = m_firstFreeSlot; - m_firstFreeSlot = m_indices.at(m_firstFreeSlot); - m_indices.at(freeSlotIndex) = static_cast(m_data.size()); - } - - // The data itself is always packed and m_indices points at it, so push a new entry to the back. - m_data.push_back(DataType()); - m_dataToIndices.push_back(freeSlotIndex); - - return freeSlotIndex; - } - - template - inline void IndexedDataVector::RemoveIndex(IndexType index) - { - IndexType dataIndex = m_indices.at(index); - - // Copy the back light on top of this one. - m_data.at(dataIndex) = m_data.back(); - m_dataToIndices.at(dataIndex) = m_dataToIndices.back(); - - // Update the index of the moved light - m_indices.at(m_dataToIndices.at(dataIndex)) = dataIndex; - - // Pop the back - m_data.pop_back(); - m_dataToIndices.pop_back(); - - // Use free slot to link to next free slot - m_indices.at(index) = m_firstFreeSlot; - m_firstFreeSlot = index; - } - - template - inline DataType& IndexedDataVector::GetData(IndexType index) - { - return m_data.at(m_indices.at(index)); - } - - template - inline const DataType& IndexedDataVector::GetData(IndexType index) const - { - return m_data.at(m_indices.at(index)); - } - - template - inline size_t IndexedDataVector::GetDataCount() const - { - return m_data.size(); - } - - template - inline AZStd::vector& IndexedDataVector::GetDataVector() - { - return m_data; - } - - template - inline const AZStd::vector& IndexedDataVector::GetDataVector() const - { - return m_data; - } - - template - IndexType IndexedDataVector::GetRawIndex(IndexType index) const - { - return m_indices.at(index); - } } // namespace AZ::Render + +#include diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl new file mode 100644 index 0000000000..076caad7f4 --- /dev/null +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/IndexedDataVector.inl @@ -0,0 +1,134 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +namespace AZ::Render +{ + template + inline IndexedDataVector::IndexedDataVector() + : IndexedDataVector(InitialReservedSize) + { + } + + template + inline IndexedDataVector::IndexedDataVector(size_t initialReservedSize) + { + m_dataToIndices.reserve(initialReservedSize); + m_indices.reserve(initialReservedSize); + m_data.reserve(initialReservedSize); + } + + template + inline void IndexedDataVector::Clear() + { + m_dataToIndices.clear(); + m_indices.clear(); + m_data.clear(); + + m_firstFreeSlot = NoFreeSlot; + } + + template + inline IndexType IndexedDataVector::GetFreeSlotIndex() + { + IndexType freeSlotIndex = static_cast(m_indices.size()); + + if (freeSlotIndex == NoFreeSlot) + { + // the vector is full + return NoFreeSlot; + } + + if (m_firstFreeSlot == NoFreeSlot) + { + // If there's no free slot, add on to the end. + m_indices.push_back(freeSlotIndex); + } + else + { + // Fill the free slot. m_indices uses it's empty slots to store a linked list (via indices) to other empty slots. + freeSlotIndex = m_firstFreeSlot; + m_firstFreeSlot = m_indices.at(m_firstFreeSlot); + m_indices.at(freeSlotIndex) = static_cast(m_data.size()); + } + + // The data itself is always packed and m_indices points at it, so push a new entry to the back. + m_data.push_back(DataType()); + m_dataToIndices.push_back(freeSlotIndex); + + return freeSlotIndex; + } + + template + inline void IndexedDataVector::RemoveIndex(IndexType index) + { + IndexType dataIndex = m_indices.at(index); + + // Copy the back light on top of this one. + m_data.at(dataIndex) = m_data.back(); + m_dataToIndices.at(dataIndex) = m_dataToIndices.back(); + + // Update the index of the moved light + m_indices.at(m_dataToIndices.at(dataIndex)) = dataIndex; + + // Pop the back + m_data.pop_back(); + m_dataToIndices.pop_back(); + + // Use free slot to link to next free slot + m_indices.at(index) = m_firstFreeSlot; + m_firstFreeSlot = index; + } + + template + inline DataType& IndexedDataVector::GetData(IndexType index) + { + return m_data.at(m_indices.at(index)); + } + + template + inline const DataType& IndexedDataVector::GetData(IndexType index) const + { + return m_data.at(m_indices.at(index)); + } + + template + inline size_t IndexedDataVector::GetDataCount() const + { + return m_data.size(); + } + + template + inline AZStd::vector& IndexedDataVector::GetDataVector() + { + return m_data; + } + + template + inline const AZStd::vector& IndexedDataVector::GetDataVector() const + { + return m_data; + } + + template + inline AZStd::vector& IndexedDataVector::GetIndexVector() + { + return m_dataToIndices; + } + + template + inline const AZStd::vector& IndexedDataVector::GetIndexVector() const + { + return m_dataToIndices; + } + + template + IndexType IndexedDataVector::GetRawIndex(IndexType index) const + { + return m_indices.at(index); + } +} // namespace AZ::Render diff --git a/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake b/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake index e4a914ac34..40188109ca 100644 --- a/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake +++ b/Gems/Atom/Feature/Common/Code/atom_feature_common_files.cmake @@ -38,6 +38,7 @@ set(FILES Include/Atom/Feature/Utils/FrameCaptureBus.h Include/Atom/Feature/Utils/GpuBufferHandler.h Include/Atom/Feature/Utils/IndexedDataVector.h + Include/Atom/Feature/Utils/IndexedDataVector.inl Include/Atom/Feature/Utils/MultiIndexedDataVector.h Include/Atom/Feature/Utils/MultiSparseVector.h Include/Atom/Feature/Utils/ProfilingCaptureBus.h