Skip to content

Commit

Permalink
Hydrogent: minor changes + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 13, 2023
1 parent e1e992e commit 3d129f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
2 changes: 0 additions & 2 deletions Hydrogent/interface/HnRenderPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ namespace Diligent
namespace USD
{

class HnMesh;
class HnMaterial;
class HnDrawItem;
class HnRenderPassState;

Expand Down
47 changes: 17 additions & 30 deletions Hydrogent/src/HnRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ HnRenderPass::HnRenderPass(pxr::HdRenderIndex* pIndex,
struct HnRenderPass::RenderState
{
IDeviceContext* const pCtx;
IBuffer* const pPrimitiveAttribsCB;

const Uint32 PrimitiveAttribsAlignedOffset;

Expand All @@ -82,7 +81,7 @@ void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& RPState,
if (m_DrawItems.empty())
return;

// Render pass state is initialized by the setup rendering task, and
// Render pass state is initialized by HnBeginFrameTask, and
// passed from the render Rprims task.
if (!RPState)
{
Expand All @@ -96,20 +95,15 @@ void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& RPState,
pxr::HdRenderIndex* pRenderIndex = GetRenderIndex();
HnRenderDelegate* pRenderDelegate = static_cast<HnRenderDelegate*>(pRenderIndex->GetRenderDelegate());

auto USDRenderer = pRenderDelegate->GetUSDRenderer();
if (!USDRenderer)
{
UNEXPECTED("USD renderer is not initialized");
return;
}

RenderState State{
pRenderDelegate->GetDeviceContext(),
pRenderDelegate->GetPrimitiveAttribsCB(),
pRenderDelegate->GetPrimitiveAttribsAlignedOffset(),
};

const auto& Desc = State.pPrimitiveAttribsCB->GetDesc();
IBuffer* const pPrimitiveAttribsCB = pRenderDelegate->GetPrimitiveAttribsCB();
VERIFY_EXPR(pPrimitiveAttribsCB != nullptr);

const auto& Desc = pPrimitiveAttribsCB->GetDesc();
const auto MaxDrawItemsInBuffer = Desc.Size / State.PrimitiveAttribsAlignedOffset;
const auto NumDrawItems = m_DrawItems.size();

Expand All @@ -121,22 +115,13 @@ void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& RPState,
if (!DrawItem.IsValid() || !DrawItem.GetHdDrawItem().GetVisible())
continue;

if (m_PendingDrawItems.size() == MaxDrawItemsInBuffer)
{
// The buffer is full, render the items and start filling the buffer from the beginning.
State.pCtx->UnmapBuffer(State.pPrimitiveAttribsCB, MAP_WRITE);
pCurrPrimitive = nullptr;
RenderPendingDrawItems(State);
VERIFY_EXPR(m_PendingDrawItems.empty());
}

if (pCurrPrimitive == nullptr)
{
State.pCtx->MapBuffer(State.pPrimitiveAttribsCB, MAP_WRITE, MAP_FLAG_DISCARD, reinterpret_cast<PVoid&>(pCurrPrimitive));
State.pCtx->MapBuffer(pPrimitiveAttribsCB, MAP_WRITE, MAP_FLAG_DISCARD, reinterpret_cast<PVoid&>(pCurrPrimitive));
if (pCurrPrimitive == nullptr)
{
UNEXPECTED("Failed to map the primitive attributes buffer");
return;
break;
}
}

Expand Down Expand Up @@ -165,14 +150,18 @@ void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& RPState,

pCurrPrimitive = reinterpret_cast<HLSL::PBRPrimitiveAttribs*>(reinterpret_cast<Uint8*>(pCurrPrimitive) + State.PrimitiveAttribsAlignedOffset);
m_PendingDrawItems.push_back(&DrawItem);
}

if (pCurrPrimitive != nullptr)
{
// Render the remaining items.
State.pCtx->UnmapBuffer(State.pPrimitiveAttribsCB, MAP_WRITE);
RenderPendingDrawItems(State);
if (m_PendingDrawItems.size() == MaxDrawItemsInBuffer || DrawItemIdx == NumDrawItems - 1)
{
// Either the buffer is full or this is the last item. Render the pending items and start
// filling the buffer from the beginning.
State.pCtx->UnmapBuffer(pPrimitiveAttribsCB, MAP_WRITE);
pCurrPrimitive = nullptr;
RenderPendingDrawItems(State);
VERIFY_EXPR(m_PendingDrawItems.empty());
}
}
VERIFY_EXPR(pCurrPrimitive == nullptr);
}

void HnRenderPass::_MarkCollectionDirty()
Expand Down Expand Up @@ -279,7 +268,6 @@ void HnRenderPass::UpdateDrawItemsGPUResources(const HnRenderPassState& RPState)

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

auto USDRenderer = pRenderDelegate->GetUSDRenderer();

Expand Down Expand Up @@ -420,7 +408,6 @@ void HnRenderPass::UpdateDrawItemsGPUResources(const HnRenderPassState& RPState)
}

VERIFY_EXPR(pPSO != nullptr);

DrawItem.SetPSO(pPSO);
}

Expand Down
4 changes: 2 additions & 2 deletions Hydrogent/src/Tasks/HnRenderRprimsTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ void HnRenderRprimsTask::Execute(pxr::HdTaskContext* TaskCtx)
{
if (m_RenderPass)
{
// Render pass state is initialized by the setup rendering task.
// Render pass state is initialized by HnBeginFrameTask.
// It is shared between all instances of the render rprims task.
std::shared_ptr<HnRenderPassState> RenderPassState = GetRenderPassState(TaskCtx);
VERIFY(RenderPassState, "Render pass state is null. This likely indicates that setup rendering task has not been created or executed.");
VERIFY(RenderPassState, "Render pass state is null. This likely indicates that HnBeginFrameTask was not been created or executed.");
m_RenderPass->Execute(RenderPassState, GetRenderTags());
}
}
Expand Down

0 comments on commit 3d129f8

Please sign in to comment.