Skip to content

Commit

Permalink
HnRenderPass: implemented draw items update
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 19, 2023
1 parent b40888b commit a6cbdcd
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 6 deletions.
14 changes: 14 additions & 0 deletions Hydrogent/include/HnRenderPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ class HnRenderPass final : public pxr::HdRenderPass
// renderTags.empty() implies execute everything.
virtual void _Execute(const pxr::HdRenderPassStateSharedPtr& State,
const pxr::TfTokenVector& Tags) override final;

virtual void _MarkCollectionDirty() override final;

private:
void UpdateDrawItems(const pxr::TfTokenVector& RenderTags);

private:
pxr::HdRenderIndex::HdDrawItemPtrVector m_DrawItems;

unsigned int m_CollectionVersion = ~0u;
unsigned int m_RprimRenderTagVersion = ~0u;
unsigned int m_TaskRenderTagsVersion = ~0u;

pxr::TfTokenVector m_RenderTags;
};

} // namespace USD
Expand Down
11 changes: 11 additions & 0 deletions Hydrogent/include/Tasks/HnRenderRprimsTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include "HnTask.hpp"

#include "pxr/imaging/hd/renderPass.h"

namespace Diligent
{

Expand Down Expand Up @@ -62,6 +64,15 @@ class HnRenderRprimsTask final : public HnTask


virtual void Execute(pxr::HdTaskContext* TaskCtx) override final;

const pxr::TfTokenVector& GetRenderTags() const
{
return m_RenderTags;
}

private:
pxr::TfTokenVector m_RenderTags;
pxr::HdRenderPassSharedPtr m_RenderPass;
};

} // namespace USD
Expand Down
65 changes: 62 additions & 3 deletions Hydrogent/src/HnRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ HnRenderPass::HnRenderPass(pxr::HdRenderIndex* pIndex,
void HnRenderPass::_Execute(pxr::HdRenderPassStateSharedPtr const& State,
pxr::TfTokenVector const& Tags)
{
UpdateDrawItems(Tags);

pxr::HdRenderIndex* pRenderIndex = GetRenderIndex();
HnRenderDelegate* pRenderDelegate = static_cast<HnRenderDelegate*>(pRenderIndex->GetRenderDelegate());

const pxr::HdRprimCollection& Collection = GetRprimCollection();
pxr::HdRenderIndex::HdDrawItemPtrVector DrawItems = pRenderIndex->GetDrawItems(Collection, Tags);
for (const pxr::HdDrawItem* pDrawItem : DrawItems)
for (const pxr::HdDrawItem* pDrawItem : m_DrawItems)
{
if (!pDrawItem->GetVisible())
continue;
Expand All @@ -68,6 +68,65 @@ void HnRenderPass::_Execute(pxr::HdRenderPassStateSharedPtr const& State,
}
}

void HnRenderPass::_MarkCollectionDirty()
{
// Force any cached data based on collection to be refreshed.
m_CollectionVersion = ~0u;
}

void HnRenderPass::UpdateDrawItems(const pxr::TfTokenVector& RenderTags)
{
pxr::HdRenderIndex* pRenderIndex = GetRenderIndex();
HnRenderDelegate* pRenderDelegate = static_cast<HnRenderDelegate*>(pRenderIndex->GetRenderDelegate());

const pxr::HdRprimCollection& Collection = GetRprimCollection();
const pxr::HdChangeTracker& Tracker = pRenderIndex->GetChangeTracker();

const unsigned int CollectionVersion = Tracker.GetCollectionVersion(Collection.GetName());
const unsigned int RprimRenderTagVersion = Tracker.GetRenderTagVersion();
const unsigned int TaskRenderTagsVersion = Tracker.GetTaskRenderTagsVersion();
//const unsigned int MaterialTagsVersion = GetMaterialTagsVersion(pRenderIndex);
//const unsigned int GeomSubsetDrawItemsVersion = GetGeomSubsetDrawItemsVersion(pRenderIndex);

const bool CollectionChanged = (m_CollectionVersion != CollectionVersion);
const bool RprimRenderTagChanged = (m_RprimRenderTagVersion != RprimRenderTagVersion);
//const bool MaterialTagsChanged = (m_MaterialTagsVersion != MaterialTagsVersion);
//const bool GeomSubsetDrawItemsChanged = (m_GeomSubsetDrawItemsVersion != GeomSubsetDrawItemsVersion);

bool TaskRenderTagsChanged = false;
if (m_TaskRenderTagsVersion != TaskRenderTagsVersion)
{
m_TaskRenderTagsVersion = TaskRenderTagsVersion;
if (m_RenderTags != RenderTags)
{
m_RenderTags = RenderTags;
TaskRenderTagsChanged = true;
}
}

if (CollectionChanged ||
RprimRenderTagChanged ||
//MaterialTagsChanged ||
//GeomSubsetDrawItemsChanged ||
TaskRenderTagsChanged)
{
//const HnRenderParam* const RenderParam = static_cast<HnRenderParam*>(pRenderIndex->GetRenderDelegate()->GetRenderParam());
//if (RenderParam->HasMaterialTag(Collection.GetMaterialTag()))
{
m_DrawItems = GetRenderIndex()->GetDrawItems(Collection, RenderTags);
}
//else
//{
// // There is no prim with the desired material tag.
// m_DrawItems.clear()
//}
}

m_CollectionVersion = CollectionVersion;
m_RprimRenderTagVersion = RprimRenderTagVersion;
}


} // namespace USD

} // namespace Diligent
2 changes: 0 additions & 2 deletions Hydrogent/src/HnRendererImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ class SyncTask final : public pxr::HdTask

void Sync(pxr::HdSceneDelegate* delegate, pxr::HdTaskContext* ctx, pxr::HdDirtyBits* dirtyBits) override final
{
m_RenderPass->Sync();

*dirtyBits = pxr::HdChangeTracker::Clean;
}

Expand Down
54 changes: 54 additions & 0 deletions Hydrogent/src/Tasks/HnRenderRprimsTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#include "Tasks/HnRenderRprimsTask.hpp"

#include "pxr/imaging/hd/renderDelegate.h"

#include "DebugUtilities.hpp"

namespace Diligent
{

Expand All @@ -45,6 +49,49 @@ void HnRenderRprimsTask::Sync(pxr::HdSceneDelegate* Delegate,
pxr::HdTaskContext* TaskCtx,
pxr::HdDirtyBits* DirtyBits)
{
VERIFY_EXPR(Delegate != nullptr && TaskCtx != nullptr && DirtyBits != nullptr);

if (*DirtyBits & pxr::HdChangeTracker::DirtyCollection)
{
pxr::VtValue CollectionVal = Delegate->Get(GetId(), pxr::HdTokens->collection);

pxr::HdRprimCollection Collection = CollectionVal.Get<pxr::HdRprimCollection>();

if (Collection.GetName().IsEmpty())
{
m_RenderPass.reset();
}
else
{
if (!m_RenderPass)
{
pxr::HdRenderIndex& Index = Delegate->GetRenderIndex();
pxr::HdRenderDelegate* RenderDelegate = Index.GetRenderDelegate();
m_RenderPass = RenderDelegate->CreateRenderPass(&Index, Collection);
}
else
{
m_RenderPass->SetRprimCollection(Collection);
}
}
}

if (*DirtyBits & pxr::HdChangeTracker::DirtyParams)
{
// TODO
}

if (*DirtyBits & pxr::HdChangeTracker::DirtyRenderTags)
{
m_RenderTags = _GetTaskRenderTags(Delegate);
}

if (m_RenderPass)
{
m_RenderPass->Sync();
}

*DirtyBits = pxr::HdChangeTracker::Clean;
}

void HnRenderRprimsTask::Prepare(pxr::HdTaskContext* TaskCtx,
Expand All @@ -54,6 +101,13 @@ void HnRenderRprimsTask::Prepare(pxr::HdTaskContext* TaskCtx,

void HnRenderRprimsTask::Execute(pxr::HdTaskContext* TaskCtx)
{
// TODO
pxr::HdRenderPassStateSharedPtr RenderPassState;

if (m_RenderPass)
{
m_RenderPass->Execute(RenderPassState, GetRenderTags());
}
}

} // namespace USD
Expand Down
2 changes: 1 addition & 1 deletion Hydrogent/src/Tasks/HnTaskController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void HnTaskController::CreateRenderRprimsTask(const pxr::TfToken& MaterialTag, T

pxr::HdRprimCollection Collection{
pxr::HdTokens->geometry,
pxr::HdReprSelector{pxr::HdReprTokens->smoothHull},
pxr::HdReprSelector{pxr::HdReprTokens->hull},
false, // forcedRepr
MaterialTag,
};
Expand Down

0 comments on commit a6cbdcd

Please sign in to comment.