Skip to content

Commit

Permalink
HnGeometryPool: added option to disallow pool allocation reuse to sup…
Browse files Browse the repository at this point in the history
…port GL
  • Loading branch information
TheMostDiligent committed Oct 5, 2024
1 parent 35c02d0 commit d9a2cd6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Hydrogent/interface/HnGeometryPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class HnGeometryPool final

void AllocateVertices(const std::string& Name,
const BufferSourcesMapType& Sources,
std::shared_ptr<VertexHandle>& Handle);
std::shared_ptr<VertexHandle>& Handle,
bool DisallowPoolAllocationReuse);

void AllocateIndices(const std::string& Name,
pxr::VtValue Indices,
Expand Down
16 changes: 10 additions & 6 deletions Hydrogent/src/HnGeometryPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class HnGeometryPool::VertexData final : public GeometryPoolData
const BufferSourcesMapType& Sources,
const VertexStreamHashesType& Hashes,
GLTF::ResourceManager* pResMgr,
bool DisallowPoolAllocationReuse,
std::shared_ptr<VertexData> ExistingData) :
m_Name{std::move(Name)},
m_NumVertices{!Sources.empty() ? static_cast<Uint32>(Sources.begin()->second->GetNumElements()) : 0},
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -226,7 +227,7 @@ class HnGeometryPool::VertexData final : public GeometryPoolData
}

std::shared_ptr<VertexData>& ExistingData = m_StagingData->ExistingData;
if (ExistingData)
if (ExistingData && !m_PoolAllocation)
{
if (ExistingData->GetUseCount() == 0)
{
Expand Down Expand Up @@ -456,8 +457,8 @@ class HnGeometryPool::VertexData final : public GeometryPoolData

std::shared_ptr<VertexData> ExistingData;

StagingData(GLTF::ResourceManager* pResMgr) :
pResMgr{pResMgr}
StagingData(GLTF::ResourceManager* _pResMgr) :
pResMgr{_pResMgr}
{}
};
std::unique_ptr<StagingData> m_StagingData;
Expand Down Expand Up @@ -813,7 +814,8 @@ class HnGeometryPool::IndexHandleImpl final : public HnGeometryPool::IndexHandle

void HnGeometryPool::AllocateVertices(const std::string& Name,
const BufferSourcesMapType& Sources,
std::shared_ptr<VertexHandle>& Handle)
std::shared_ptr<VertexHandle>& Handle,
bool DisallowPoolAllocationReuse)
{
if (Sources.empty())
{
Expand Down Expand Up @@ -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<VertexData> Data = std::make_shared<VertexData>(Name, Sources, Hashes, m_UseVertexPool ? &m_ResMgr : nullptr, ExistingData);
std::shared_ptr<VertexData> Data = std::make_shared<VertexData>(Name, Sources, Hashes,
m_UseVertexPool ? &m_ResMgr : nullptr,
DisallowPoolAllocationReuse, ExistingData);

{
std::lock_guard<std::mutex> Guard{m_PendingVertexDataMtx};
Expand Down
5 changes: 4 additions & 1 deletion Hydrogent/src/HnMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit d9a2cd6

Please sign in to comment.