Merge pull request #2554 from aws-lumberyard-dev/Atom/IndexedDataVector
Promote IndexedDataVector to public Feature/Utils header
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AtomCore/std/containers/array_view.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
|
||||
namespace AZ::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<typename DataType, typename IndexType = uint16_t>
|
||||
class IndexedDataVector
|
||||
{
|
||||
public:
|
||||
IndexedDataVector();
|
||||
explicit IndexedDataVector(size_t initialReservedSize);
|
||||
~IndexedDataVector() = default;
|
||||
|
||||
static constexpr IndexType NoFreeSlot = std::numeric_limits<IndexType>::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<DataType>& GetDataVector();
|
||||
const AZStd::vector<DataType>& GetDataVector() const;
|
||||
|
||||
AZStd::vector<IndexType>& GetIndexVector();
|
||||
const AZStd::vector<IndexType>& GetIndexVector() const;
|
||||
|
||||
IndexType GetRawIndex(IndexType index) const;
|
||||
|
||||
private:
|
||||
constexpr static size_t InitialReservedSize = 128;
|
||||
|
||||
// Stores data indices and an embedded free list
|
||||
AZStd::vector<IndexType> m_indices;
|
||||
// Stores the indirection index
|
||||
AZStd::vector<IndexType> m_dataToIndices;
|
||||
AZStd::vector<DataType> m_data;
|
||||
};
|
||||
} // namespace AZ::Render
|
||||
|
||||
#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<typename DataType, typename IndexType>
|
||||
inline IndexedDataVector<DataType, IndexType>::IndexedDataVector()
|
||||
: IndexedDataVector(InitialReservedSize)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline IndexedDataVector<DataType, IndexType>::IndexedDataVector(size_t initialReservedSize)
|
||||
{
|
||||
m_dataToIndices.reserve(initialReservedSize);
|
||||
m_indices.reserve(initialReservedSize);
|
||||
m_data.reserve(initialReservedSize);
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline void IndexedDataVector<DataType, IndexType>::Clear()
|
||||
{
|
||||
m_dataToIndices.clear();
|
||||
m_indices.clear();
|
||||
m_data.clear();
|
||||
|
||||
m_firstFreeSlot = NoFreeSlot;
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline IndexType IndexedDataVector<DataType, IndexType>::GetFreeSlotIndex()
|
||||
{
|
||||
IndexType freeSlotIndex = static_cast<IndexType>(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<IndexType>(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<typename DataType, typename IndexType>
|
||||
inline void IndexedDataVector<DataType, IndexType>::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<typename DataType, typename IndexType>
|
||||
inline DataType& IndexedDataVector<DataType, IndexType>::GetData(IndexType index)
|
||||
{
|
||||
return m_data.at(m_indices.at(index));
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline const DataType& IndexedDataVector<DataType, IndexType>::GetData(IndexType index) const
|
||||
{
|
||||
return m_data.at(m_indices.at(index));
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline size_t IndexedDataVector<DataType, IndexType>::GetDataCount() const
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline AZStd::vector<DataType>& IndexedDataVector<DataType, IndexType>::GetDataVector()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline const AZStd::vector<DataType>& IndexedDataVector<DataType, IndexType>::GetDataVector() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline AZStd::vector<IndexType>& IndexedDataVector<DataType, IndexType>::GetIndexVector()
|
||||
{
|
||||
return m_dataToIndices;
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline const AZStd::vector<IndexType>& IndexedDataVector<DataType, IndexType>::GetIndexVector() const
|
||||
{
|
||||
return m_dataToIndices;
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
IndexType IndexedDataVector<DataType, IndexType>::GetRawIndex(IndexType index) const
|
||||
{
|
||||
return m_indices.at(index);
|
||||
}
|
||||
} // namespace AZ::Render
|
||||
@@ -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
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <Atom/Feature/CoreLights/CapsuleLightFeatureProcessorInterface.h>
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
#include <Atom/Feature/CoreLights/PhotometricValue.h>
|
||||
|
||||
namespace AZ
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <CoreLights/EsmShadowmapsPass.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
#include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
|
||||
#include <Atom/RPI.Public/AuxGeom/AuxGeomFeatureProcessorInterface.h>
|
||||
#include <Atom/RPI.Public/Buffer/Buffer.h>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <Atom/Feature/CoreLights/DiskLightFeatureProcessorInterface.h>
|
||||
#include <Atom/Feature/CoreLights/PhotometricValue.h>
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
#include <Shadows/ProjectedShadowFeatureProcessor.h>
|
||||
|
||||
namespace AZ
|
||||
|
||||
@@ -1,55 +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
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AtomCore/std/containers/array_view.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
template <typename DataType, typename IndexType = uint16_t>
|
||||
class IndexedDataVector
|
||||
{
|
||||
public:
|
||||
IndexedDataVector();
|
||||
~IndexedDataVector() = default;
|
||||
|
||||
static constexpr IndexType NoFreeSlot = std::numeric_limits<IndexType>::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<DataType>& GetDataVector();
|
||||
const AZStd::vector<DataType>& GetDataVector() const;
|
||||
|
||||
IndexType GetRawIndex(IndexType index) const;
|
||||
|
||||
private:
|
||||
|
||||
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
|
||||
AZStd::vector<IndexType> m_indices;
|
||||
// stores the index of index vector for respective light
|
||||
AZStd::vector<IndexType> m_dataToIndices;
|
||||
// stores light data
|
||||
AZStd::vector<DataType> m_data;
|
||||
};
|
||||
|
||||
#include "IndexedDataVector.inl"
|
||||
}
|
||||
}
|
||||
@@ -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<typename DataType, typename IndexType>
|
||||
inline IndexedDataVector<DataType,IndexType>::IndexedDataVector()
|
||||
{
|
||||
m_dataToIndices.reserve(InitialReservedCount);
|
||||
m_indices.reserve(InitialReservedCount);
|
||||
m_data.reserve(InitialReservedCount);
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline void IndexedDataVector<DataType, IndexType>::Clear()
|
||||
{
|
||||
m_dataToIndices.clear();
|
||||
m_indices.clear();
|
||||
m_data.clear();
|
||||
|
||||
m_firstFreeSlot = NoFreeSlot;
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline IndexType IndexedDataVector<DataType, IndexType>::GetFreeSlotIndex()
|
||||
{
|
||||
IndexType freeSlotIndex = static_cast<IndexType>(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<IndexType>(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<typename DataType, typename IndexType>
|
||||
inline void IndexedDataVector<DataType, IndexType>::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<typename DataType, typename IndexType>
|
||||
inline DataType& IndexedDataVector<DataType, IndexType>::GetData(IndexType index)
|
||||
{
|
||||
return m_data.at(m_indices.at(index));
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline const DataType& IndexedDataVector<DataType, IndexType>::GetData(IndexType index) const
|
||||
{
|
||||
return m_data.at(m_indices.at(index));
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline size_t IndexedDataVector<DataType, IndexType>::GetDataCount() const
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline AZStd::vector<DataType>& IndexedDataVector<DataType, IndexType>::GetDataVector()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
template<typename DataType, typename IndexType>
|
||||
inline const AZStd::vector<DataType>& IndexedDataVector<DataType, IndexType>::GetDataVector() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
template <typename DataType, typename IndexType>
|
||||
IndexType IndexedDataVector<DataType, IndexType>::GetRawIndex(IndexType index) const
|
||||
{
|
||||
return m_indices.at(index);
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <Atom/Feature/CoreLights/PhotometricValue.h>
|
||||
#include <Atom/Feature/CoreLights/PointLightFeatureProcessorInterface.h>
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
#include <Shadows/ProjectedShadowFeatureProcessor.h>
|
||||
|
||||
namespace AZ
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <Atom/Feature/CoreLights/QuadLightFeatureProcessorInterface.h>
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <Atom/Feature/CoreLights/PhotometricValue.h>
|
||||
#include <Atom/Feature/CoreLights/SimplePointLightFeatureProcessorInterface.h>
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <Atom/Feature/CoreLights/PhotometricValue.h>
|
||||
#include <Atom/Feature/CoreLights/SimpleSpotLightFeatureProcessorInterface.h>
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
#include <Atom/Feature/Decals/DecalFeatureProcessorInterface.h>
|
||||
#include <Atom/RPI.Reflect/Image/ImageAsset.h>
|
||||
#include <Atom/RPI.Public/Image/StreamingImage.h>
|
||||
@@ -16,7 +17,6 @@
|
||||
#include <Atom/Feature/Utils/IndexableList.h>
|
||||
#include <Decals/DecalTextureArray.h>
|
||||
#include <Decals/AsyncLoadTracker.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
#include <Atom/Feature/Shadows/ProjectedShadowFeatureProcessorInterface.h>
|
||||
#include <Atom/Feature/Utils/GpuBufferHandler.h>
|
||||
#include <Atom/Feature/Utils/IndexedDataVector.h>
|
||||
#include <Atom/Feature/Utils/MultiSparseVector.h>
|
||||
#include <CoreLights/EsmShadowmapsPass.h>
|
||||
#include <CoreLights/ProjectedShadowmapsPass.h>
|
||||
#include <CoreLights/IndexedDataVector.h>
|
||||
|
||||
namespace AZ::Render
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user