From d9a2cd67d1e59a4703ed3edc1610bb270516dd78 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 5 Oct 2024 11:27:53 -0700 Subject: [PATCH] HnGeometryPool: added option to disallow pool allocation reuse to support GL --- Hydrogent/interface/HnGeometryPool.hpp | 3 ++- Hydrogent/src/HnGeometryPool.cpp | 16 ++++++++++------ Hydrogent/src/HnMesh.cpp | 5 ++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Hydrogent/interface/HnGeometryPool.hpp b/Hydrogent/interface/HnGeometryPool.hpp index 83f9beb4..a8c718f8 100644 --- a/Hydrogent/interface/HnGeometryPool.hpp +++ b/Hydrogent/interface/HnGeometryPool.hpp @@ -85,7 +85,8 @@ class HnGeometryPool final void AllocateVertices(const std::string& Name, const BufferSourcesMapType& Sources, - std::shared_ptr& Handle); + std::shared_ptr& Handle, + bool DisallowPoolAllocationReuse); void AllocateIndices(const std::string& Name, pxr::VtValue Indices, diff --git a/Hydrogent/src/HnGeometryPool.cpp b/Hydrogent/src/HnGeometryPool.cpp index 0f83549a..72d4894a 100644 --- a/Hydrogent/src/HnGeometryPool.cpp +++ b/Hydrogent/src/HnGeometryPool.cpp @@ -118,6 +118,7 @@ class HnGeometryPool::VertexData final : public GeometryPoolData const BufferSourcesMapType& Sources, const VertexStreamHashesType& Hashes, GLTF::ResourceManager* pResMgr, + bool DisallowPoolAllocationReuse, std::shared_ptr ExistingData) : m_Name{std::move(Name)}, m_NumVertices{!Sources.empty() ? static_cast(Sources.begin()->second->GetNumElements()) : 0}, @@ -194,7 +195,7 @@ class HnGeometryPool::VertexData final : public GeometryPoolData // If there is existing data, we will check if it is not used by other // handles in the Update() method and hence its buffers can be reused. - if (!ExistingData) + if (!ExistingData || DisallowPoolAllocationReuse) { InitPoolAllocation(); } @@ -226,7 +227,7 @@ class HnGeometryPool::VertexData final : public GeometryPoolData } std::shared_ptr& ExistingData = m_StagingData->ExistingData; - if (ExistingData) + if (ExistingData && !m_PoolAllocation) { if (ExistingData->GetUseCount() == 0) { @@ -456,8 +457,8 @@ class HnGeometryPool::VertexData final : public GeometryPoolData std::shared_ptr ExistingData; - StagingData(GLTF::ResourceManager* pResMgr) : - pResMgr{pResMgr} + StagingData(GLTF::ResourceManager* _pResMgr) : + pResMgr{_pResMgr} {} }; std::unique_ptr m_StagingData; @@ -813,7 +814,8 @@ class HnGeometryPool::IndexHandleImpl final : public HnGeometryPool::IndexHandle void HnGeometryPool::AllocateVertices(const std::string& Name, const BufferSourcesMapType& Sources, - std::shared_ptr& Handle) + std::shared_ptr& Handle, + bool DisallowPoolAllocationReuse) { if (Sources.empty()) { @@ -845,7 +847,9 @@ void HnGeometryPool::AllocateVertices(const std::string& Name, [&]() { // This code is executed only if the data is not found in the cache, and the data is created only once. - std::shared_ptr Data = std::make_shared(Name, Sources, Hashes, m_UseVertexPool ? &m_ResMgr : nullptr, ExistingData); + std::shared_ptr Data = std::make_shared(Name, Sources, Hashes, + m_UseVertexPool ? &m_ResMgr : nullptr, + DisallowPoolAllocationReuse, ExistingData); { std::lock_guard Guard{m_PendingVertexDataMtx}; diff --git a/Hydrogent/src/HnMesh.cpp b/Hydrogent/src/HnMesh.cpp index 2c98fc2c..a160e96f 100644 --- a/Hydrogent/src/HnMesh.cpp +++ b/Hydrogent/src/HnMesh.cpp @@ -393,7 +393,10 @@ void HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate, if (!StagingVerts.Sources.empty()) { HnGeometryPool& GeometryPool = RenderDelegate->GetGeometryPool(); - GeometryPool.AllocateVertices(Id.GetString(), StagingVerts.Sources, m_VertexHandle); + // When native start vertex is not supported, start vertex needs to be baked into the index data, and + // we need to know the start vertex now, so we have to disallow pool allocation reuse (with pool allocation reuse + // enabled, the allocation initialization is delayed until the GeometryPool.Commit() is called later). + GeometryPool.AllocateVertices(Id.GetString(), StagingVerts.Sources, m_VertexHandle, /*DisallowPoolAllocationReuse = */ !UseNativeStartVertex); if (!UseNativeStartVertex) {