Skip to content

Commit

Permalink
HnGeometryPool: reworked space reserving
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Jan 18, 2025
1 parent a952254 commit f9c6e6a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
27 changes: 25 additions & 2 deletions Hydrogent/include/HnGeometryPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,31 @@ class HnGeometryPool final
Int64 GetPendingVertexDataSize() const { return m_PendingVertexDataSize.load(); }
Int64 GetPendingIndexDataSize() const { return m_PendingIndexDataSize.load(); }

Int64 ReserveDataSize(Uint64 Size);
void ReleaseReservedDataSize(Uint64 Size);
class ReservedSpace
{
public:
ReservedSpace(ReservedSpace&& Other) noexcept;

ReservedSpace& operator=(const ReservedSpace&) = delete;
ReservedSpace& operator=(ReservedSpace&&) = delete;

~ReservedSpace();

Uint64 GetTotalPendingSize() const { return m_TotalPendingSize; }

private:
ReservedSpace(HnGeometryPool& Pool, Uint64 Size, Uint64 TotalPendingSize) noexcept;

private:
friend class HnGeometryPool;
HnGeometryPool& m_Pool;
Uint64 m_Size = 0;
Uint64 m_TotalPendingSize = 0;
};
ReservedSpace ReserveSpace(Uint64 Size);

private:
void ReleaseReservedSpace(Uint64 Size);

private:
RefCntAutoPtr<IRenderDevice> m_pDevice;
Expand Down
34 changes: 31 additions & 3 deletions Hydrogent/src/HnGeometryPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,15 +1017,43 @@ void HnGeometryPool::Commit(IDeviceContext* pContext)
}
}

Int64 HnGeometryPool::ReserveDataSize(Uint64 Size)
HnGeometryPool::ReservedSpace::ReservedSpace(HnGeometryPool& Pool,
Uint64 Size,
Uint64 TotalPendingSize) noexcept :
m_Pool{Pool},
m_Size{Size},
m_TotalPendingSize{TotalPendingSize}
{
return GetPendingVertexDataSize() +
}

HnGeometryPool::ReservedSpace::ReservedSpace(ReservedSpace&& Other) noexcept :
m_Pool{Other.m_Pool},
m_Size{Other.m_Size},
m_TotalPendingSize{Other.m_TotalPendingSize}
{
Other.m_Size = 0;
Other.m_TotalPendingSize = 0;
}

HnGeometryPool::ReservedSpace::~ReservedSpace()
{
if (m_Size != 0)
{
m_Pool.ReleaseReservedSpace(m_Size);
}
}

HnGeometryPool::ReservedSpace HnGeometryPool::ReserveSpace(Uint64 Size)
{
const Int64 TotalPendingSize =
GetPendingVertexDataSize() +
GetPendingIndexDataSize() +
m_ReservedDataSize.fetch_add(static_cast<Int64>(Size)) +
static_cast<Int64>(Size);
return {*this, Size, static_cast<Uint64>(TotalPendingSize)};
}

void HnGeometryPool::ReleaseReservedDataSize(Uint64 Size)
void HnGeometryPool::ReleaseReservedSpace(Uint64 Size)
{
VERIFY_EXPR(m_ReservedDataSize.load() >= static_cast<Int64>(Size));
m_ReservedDataSize.fetch_add(-static_cast<Int64>(Size));
Expand Down
26 changes: 3 additions & 23 deletions Hydrogent/src/HnMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,30 +412,10 @@ bool HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
ExpectedGeometryDataSize += MeshUtils.GetTotalIndexCount(IndexCountFlags) * sizeof(Uint32);
}

class GeometryPoolReservedDataGuard
HnGeometryPool::ReservedSpace ReservedSpace = GeometryPool.ReserveSpace(ExpectedGeometryDataSize);
if (GeometryLoadBudget > 0 && ReservedSpace.GetTotalPendingSize() > GeometryLoadBudget)
{
public:
GeometryPoolReservedDataGuard(HnGeometryPool& Pool, Uint64 Size) :
m_Pool{Pool},
m_Size{Size},
m_TotalSize{static_cast<Uint64>(Pool.ReserveDataSize(Size))}
{
}
~GeometryPoolReservedDataGuard()
{
m_Pool.ReleaseReservedDataSize(m_Size);
}
Uint64 GetTotalSize() const { return m_TotalSize; }

private:
HnGeometryPool& m_Pool;
const Uint64 m_Size;
const Uint64 m_TotalSize;
};
GeometryPoolReservedDataGuard ReservedDataGuard{GeometryPool, ExpectedGeometryDataSize};
if (GeometryLoadBudget > 0 && ReservedDataGuard.GetTotalSize() > GeometryLoadBudget)
{
if (ReservedDataGuard.GetTotalSize() == ExpectedGeometryDataSize)
if (ReservedSpace.GetTotalPendingSize() == ExpectedGeometryDataSize)
{
LOG_WARNING_MESSAGE("Syncing rprim ", Id, " requires ", ExpectedGeometryDataSize,
" bytes of geometry data, which exceeds the budget ", GeometryLoadBudget, ".");
Expand Down

0 comments on commit f9c6e6a

Please sign in to comment.