Skip to content

Commit

Permalink
HnMesh: moved geometry budget check to UpdateRepr()
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Jan 16, 2025
1 parent 05af0b7 commit 09c9b02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Hydrogent/interface/HnMesh.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 Diligent Graphics LLC
* Copyright 2023-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -154,7 +154,7 @@ class HnMesh final : public pxr::HdMesh
struct StagingIndexData;
struct StagingVertexData;

void UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
bool UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
pxr::HdRenderParam* RenderParam,
pxr::HdDirtyBits& DirtyBits,
const pxr::TfToken& ReprToken);
Expand Down
33 changes: 15 additions & 18 deletions Hydrogent/src/HnMesh.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 Diligent Graphics LLC
* Copyright 2023-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -198,17 +198,7 @@ void HnMesh::Sync(pxr::HdSceneDelegate* Delegate,
}
bool UpdateCullMode = pxr::HdChangeTracker::IsTransformDirty(*DirtyBits, Id) || m_CullMode == CULL_MODE_UNDEFINED;


HnRenderDelegate* RenderDelegate = static_cast<HnRenderDelegate*>(Delegate->GetRenderIndex().GetRenderDelegate());
HnGeometryPool& GeometryPool = RenderDelegate->GetGeometryPool();
const Int64 PendingGeometrySize = GeometryPool.GetPendingVertexDataSize() + GeometryPool.GetPendingIndexDataSize();
const Uint64 GeometryLoadBudget = static_cast<HnRenderParam*>(RenderParam)->GetConfig().GeometryLoadBudget;
bool ReprUpdated = false;
if (GeometryLoadBudget == 0 || static_cast<Uint64>(PendingGeometrySize) < GeometryLoadBudget)
{
UpdateRepr(*Delegate, RenderParam, *DirtyBits, ReprToken);
ReprUpdated = true;
}
const bool ReprUpdated = UpdateRepr(*Delegate, RenderParam, *DirtyBits, ReprToken);

if (UpdateMaterials)
{
Expand Down Expand Up @@ -332,16 +322,24 @@ struct HnMesh::StagingVertexData
std::map<pxr::TfToken, std::shared_ptr<pxr::HdBufferSource>> Sources;
};

void HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
bool HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
pxr::HdRenderParam* RenderParam,
pxr::HdDirtyBits& DirtyBits,
const pxr::TfToken& ReprToken)
{
const pxr::HdReprSharedPtr& CurrRepr = _GetRepr(ReprToken);
if (!CurrRepr)
return;
return true;

HnRenderDelegate* RenderDelegate = static_cast<HnRenderDelegate*>(SceneDelegate.GetRenderIndex().GetRenderDelegate());
HnRenderDelegate* RenderDelegate = static_cast<HnRenderDelegate*>(SceneDelegate.GetRenderIndex().GetRenderDelegate());
HnGeometryPool& GeometryPool = RenderDelegate->GetGeometryPool();
const Int64 PendingGeometrySize = GeometryPool.GetPendingVertexDataSize() + GeometryPool.GetPendingIndexDataSize();
const Uint64 GeometryLoadBudget = static_cast<HnRenderParam*>(RenderParam)->GetConfig().GeometryLoadBudget;
if (GeometryLoadBudget > 0 && static_cast<Uint64>(PendingGeometrySize) > GeometryLoadBudget)
{
// Pending geometry size exceeds the budget, skip updating the repr
return false;
}

const pxr::SdfPath& Id = GetId();

Expand Down Expand Up @@ -407,7 +405,6 @@ void HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
Uint32 BakedStartVertex = (!UseNativeStartVertex && m_VertexHandle) ? m_VertexHandle->GetStartVertex() : 0;
if (!StagingVerts.Sources.empty())
{
HnGeometryPool& GeometryPool = RenderDelegate->GetGeometryPool();
// 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).
Expand All @@ -432,8 +429,6 @@ void HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
StagingIndexData StagingInds;
UpdateIndexData(StagingInds, StagingVerts.Points, RenderDelegate->AllowPrimitiveRestart());

HnGeometryPool& GeometryPool = RenderDelegate->GetGeometryPool();

GeometryPool.AllocateIndices(Id.GetString() + " - faces", pxr::VtValue::Take(StagingInds.FaceIndices), BakedStartVertex, m_IndexData.Faces);
GeometryPool.AllocateIndices(Id.GetString() + " - edges", pxr::VtValue::Take(StagingInds.EdgeIndices), BakedStartVertex, m_IndexData.Edges);
GeometryPool.AllocateIndices(Id.GetString() + " - points", pxr::VtValue::Take(StagingInds.PointIndices), BakedStartVertex, m_IndexData.Points);
Expand Down Expand Up @@ -483,6 +478,8 @@ void HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
}

DirtyBits &= ~pxr::HdChangeTracker::NewRepr;

return true;
}

void HnMesh::UpdateDrawItemsForGeometrySubsets(pxr::HdSceneDelegate& SceneDelegate,
Expand Down

0 comments on commit 09c9b02

Please sign in to comment.