Skip to content

Commit 050bee4

Browse files
HnRenderPass: updated skinning transforms when GeomBindXform changes
1 parent b92984e commit 050bee4

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

Hydrogent/interface/HnMesh.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ class HnMesh final : public pxr::HdMesh
112112

113113
struct Skinning
114114
{
115-
const pxr::VtMatrix4fArray* Xforms = nullptr;
116-
size_t XformsHash = 0;
117-
float4x4 GeomBindXform = float4x4::Identity();
115+
const pxr::VtMatrix4fArray* Xforms = nullptr;
116+
size_t XformsHash = 0;
117+
float4x4 GeomBindXform = float4x4::Identity();
118+
size_t GeomBindXformHash = 0;
118119

119120
explicit operator bool() const { return Xforms != nullptr; }
120121
};

Hydrogent/src/HnMesh.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,17 @@ void HnMesh::UpdateSkinningPrimvars(pxr::HdSceneDelegate&
865865
{
866866
pxr::VtValue GeomBindXformVal = SceneDelegate.GetExtComputationInput(CompInput.sourceComputationId, CompInput.name);
867867

868-
SkinningData.GeomBindXform = GeomBindXformVal.IsHolding<pxr::GfMatrix4f>() ?
869-
ToFloat4x4(GeomBindXformVal.UncheckedGet<pxr::GfMatrix4f>()) :
870-
float4x4::Identity();
868+
if (GeomBindXformVal.IsHolding<pxr::GfMatrix4f>())
869+
{
870+
const pxr::GfMatrix4f& GeomBindXform = GeomBindXformVal.UncheckedGet<pxr::GfMatrix4f>();
871+
SkinningData.GeomBindXform = ToFloat4x4(GeomBindXform);
872+
SkinningData.GeomBindXformHash = pxr::TfHash{}(GeomBindXform);
873+
}
874+
else
875+
{
876+
SkinningData.GeomBindXform = float4x4::Identity();
877+
SkinningData.GeomBindXformHash = 0;
878+
}
871879
}
872880
}
873881

Hydrogent/src/HnRenderPass.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ HnRenderPass::EXECUTE_RESULT HnRenderPass::Execute(HnRenderPassState& RPState, c
412412
Uint32 JointsBufferOffset = 0;
413413
Uint32 CurrJointsDataSize = 0;
414414
size_t XformsHash = 0;
415+
size_t GeomBindXformHash = 0;
415416
Uint32 JointCount = 0;
416417

417418
if (AttribsBuffDesc.Usage != USAGE_DYNAMIC)
@@ -460,7 +461,8 @@ HnRenderPass::EXECUTE_RESULT HnRenderPass::Execute(HnRenderPassState& RPState, c
460461
// Reset the hash to force updating the joint transforms for the next draw item.
461462
// NB: we can't reuse the transforms at the existing offset because they may be
462463
// overwritten by the next draw item.
463-
XformsHash = 0;
464+
XformsHash = 0;
465+
GeomBindXformHash = 0;
464466

465467
RenderPendingDrawItems(State);
466468
VERIFY_EXPR(m_PendingDrawItems.empty());
@@ -518,7 +520,7 @@ HnRenderPass::EXECUTE_RESULT HnRenderPass::Execute(HnRenderPassState& RPState, c
518520
if (MultiDrawCount == PrimitiveArraySize)
519521
MultiDrawCount = 0;
520522

521-
if (pSkinningData && pSkinningData->XformsHash != XformsHash)
523+
if (pSkinningData && (pSkinningData->XformsHash != XformsHash || pSkinningData->GeomBindXformHash != GeomBindXformHash))
522524
{
523525
// Restart batch when the joint transforms change
524526
MultiDrawCount = 0;
@@ -598,7 +600,9 @@ HnRenderPass::EXECUTE_RESULT HnRenderPass::Execute(HnRenderPassState& RPState, c
598600

599601
if (pSkinningData)
600602
{
601-
if (pSkinningData->XformsHash != XformsHash)
603+
// NOTE: we currently reupload all joint transforms if geometry bind matrix changes, which is not optimal.
604+
// A better approach would be to move the matrix to PBRPrimitiveAttribs.
605+
if (pSkinningData->XformsHash != XformsHash || pSkinningData->GeomBindXformHash != GeomBindXformHash)
602606
{
603607
VERIFY(CurrJointsDataSize + JointsDataRange <= JointsBuffDesc.Size,
604608
"There must be enough space for the new joint transforms as we flush the pending draw if there is not enough space.");
@@ -623,7 +627,8 @@ HnRenderPass::EXECUTE_RESULT HnRenderPass::Execute(HnRenderPassState& RPState, c
623627
VERIFY_EXPR(JointsDataSize == State.USDRenderer.GetJointsDataSize(JointCount, ListItem.PSOFlags));
624628
CurrJointsDataSize = AlignUp(JointsBufferOffset + JointsDataSize, JointsBufferOffsetAlignment);
625629

626-
XformsHash = pSkinningData->XformsHash;
630+
XformsHash = pSkinningData->XformsHash;
631+
GeomBindXformHash = pSkinningData->GeomBindXformHash;
627632

628633
VERIFY(MultiDrawCount == 0, "The batch must be reset when the joint transforms change.");
629634
}

0 commit comments

Comments
 (0)