diff --git a/Hydrogent/include/HnGeometryPool.hpp b/Hydrogent/include/HnGeometryPool.hpp index a8c718f8..c058dadf 100644 --- a/Hydrogent/include/HnGeometryPool.hpp +++ b/Hydrogent/include/HnGeometryPool.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "pxr/pxr.h" #include "pxr/base/tf/token.h" @@ -93,6 +94,9 @@ class HnGeometryPool final Uint32 StartVertex, std::shared_ptr& Handle); + Int64 GetPendingVertexDataSize() const { return m_PendingVertexDataSize; } + Int64 GetPendingIndexDataSize() const { return m_PendingIndexDataSize; } + private: RefCntAutoPtr m_pDevice; GLTF::ResourceManager& m_ResMgr; @@ -107,9 +111,11 @@ class HnGeometryPool final std::mutex m_PendingVertexDataMtx; std::vector> m_PendingVertexData; + std::atomic m_PendingVertexDataSize{0}; std::mutex m_PendingIndexDataMtx; std::vector> m_PendingIndexData; + std::atomic m_PendingIndexDataSize{0}; ObjectsRegistry> m_VertexCache; ObjectsRegistry> m_IndexCache; diff --git a/Hydrogent/src/HnGeometryPool.cpp b/Hydrogent/src/HnGeometryPool.cpp index cb05f593..18b6c615 100644 --- a/Hydrogent/src/HnGeometryPool.cpp +++ b/Hydrogent/src/HnGeometryPool.cpp @@ -56,6 +56,8 @@ HnGeometryPool::HnGeometryPool(IRenderDevice* pDevice, HnGeometryPool::~HnGeometryPool() { + VERIFY((m_PendingVertexData.empty() && m_PendingVertexDataSize >= 0) || m_PendingVertexDataSize == 0, "Pending vertex data size must be 0 when there are no pending data"); + VERIFY((m_PendingIndexData.empty() && m_PendingIndexDataSize >= 0) || m_PendingIndexDataSize == 0, "Pending index data size must be 0 when there are no pending data"); } class GeometryPoolData @@ -411,6 +413,17 @@ class HnGeometryPool::VertexData final : public GeometryPoolData return Hashes; } + size_t GetTotalSize() const + { + size_t TotalSize = 0; + for (const auto& stream_it : m_Streams) + { + const VertexStream& Stream = stream_it.second; + TotalSize += m_NumVertices * Stream.ElementSize; + } + return TotalSize; + } + private: void InitPoolAllocation() { @@ -691,6 +704,11 @@ class HnGeometryPool::IndexData final : public GeometryPoolData CommitPendingUses(); } + size_t GetSize() const + { + return m_NumIndices * sizeof(Uint32); + } + private: void InitPoolAllocation() { @@ -869,6 +887,8 @@ void HnGeometryPool::AllocateVertices(const std::string& Name, m_UseVertexPool ? &m_ResMgr : nullptr, DisallowPoolAllocationReuse, ExistingData); + m_PendingVertexDataSize.fetch_add(static_cast(Data->GetTotalSize())); + { std::lock_guard Guard{m_PendingVertexDataMtx}; m_PendingVertexData.emplace_back(Data); @@ -914,6 +934,8 @@ void HnGeometryPool::AllocateIndices(const std::string& std::shared_ptr Data = std::make_shared(Name, std::move(Indices), StartVertex, m_UseIndexPool ? &m_ResMgr : nullptr, ExistingData); + m_PendingIndexDataSize.fetch_add(static_cast(Data->GetSize())); + { std::lock_guard Guard{m_PendingIndexDataMtx}; m_PendingIndexData.emplace_back(Data); @@ -940,6 +962,8 @@ void HnGeometryPool::Commit(IDeviceContext* pContext) for (auto& Data : m_PendingVertexData) { Data->Initialize(m_pDevice, pContext); + m_PendingVertexDataSize.fetch_add(-static_cast(Data->GetTotalSize())); + VERIFY_EXPR(m_PendingVertexDataSize >= 0); } m_PendingVertexData.clear(); } @@ -949,6 +973,8 @@ void HnGeometryPool::Commit(IDeviceContext* pContext) for (auto& Data : m_PendingIndexData) { Data->Initialize(m_pDevice, pContext); + m_PendingIndexDataSize.fetch_add(-static_cast(Data->GetSize())); + VERIFY_EXPR(m_PendingIndexDataSize >= 0); } m_PendingIndexData.clear(); }