From 649e2e8b57b474945320f8ac8d2774ed7fd8ce63 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 24 Nov 2024 17:59:42 -0800 Subject: [PATCH] HnMaterial: slightly reworked ApplyMaterialAttribsBufferOffset method --- Hydrogent/interface/HnMaterial.hpp | 13 ++++++------- Hydrogent/src/HnRenderPass.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Hydrogent/interface/HnMaterial.hpp b/Hydrogent/interface/HnMaterial.hpp index f12c058c..b6923d26 100644 --- a/Hydrogent/interface/HnMaterial.hpp +++ b/Hydrogent/interface/HnMaterial.hpp @@ -91,11 +91,15 @@ class HnMaterial final : public pxr::HdMaterial m_PrimitiveAttribsVar->SetBufferOffset(PrimitiveAttribsOffset); return m_SRB; } - void ApplyMaterialAttribsBufferOffset() const + void ApplyMaterialAttribsBufferOffset(Uint32& CurrentOffset) const { VERIFY_EXPR(m_MaterialAttribsVar != nullptr); VERIFY_EXPR(m_PBRMaterialAttribsBufferOffset != ~0u); - m_MaterialAttribsVar->SetBufferOffset(m_PBRMaterialAttribsBufferOffset); + if (CurrentOffset != m_PBRMaterialAttribsBufferOffset) + { + m_MaterialAttribsVar->SetBufferOffset(m_PBRMaterialAttribsBufferOffset); + CurrentOffset = m_PBRMaterialAttribsBufferOffset; + } } void SetJointsBufferOffset(Uint32 Offset) const { @@ -137,11 +141,6 @@ class HnMaterial final : public pxr::HdMaterial Uint32 GetPBRPrimitiveAttribsBufferRange() const { return m_PBRPrimitiveAttribsBufferRange; } Uint32 GetPBRMaterialAttribsSize() const { return m_PBRMaterialAttribsSize; } - Uint32 GetPBRMaterialAttribsBufferOffset() const - { - VERIFY_EXPR(m_PBRMaterialAttribsBufferOffset != ~0u); - return m_PBRMaterialAttribsBufferOffset; - } private: HnMaterial(pxr::SdfPath const& id); diff --git a/Hydrogent/src/HnRenderPass.cpp b/Hydrogent/src/HnRenderPass.cpp index 5ed3e31b..e00d896c 100644 --- a/Hydrogent/src/HnRenderPass.cpp +++ b/Hydrogent/src/HnRenderPass.cpp @@ -153,11 +153,11 @@ struct HnRenderPass::RenderState return; } - if (pNewSRB != this->pMaterialSRB || this->MaterialBufferOffset != Material.GetPBRMaterialAttribsBufferOffset()) + if (pNewSRB != this->pMaterialSRB) { - Material.ApplyMaterialAttribsBufferOffset(); - this->MaterialBufferOffset = Material.GetPBRMaterialAttribsBufferOffset(); + this->MaterialBufferOffset = ~0u; } + Material.ApplyMaterialAttribsBufferOffset(this->MaterialBufferOffset); if (pNewSRB == this->pMaterialSRB) return; @@ -226,7 +226,7 @@ struct HnRenderPass::RenderState IBuffer* pIndexBuffer = nullptr; - Uint32 MaterialBufferOffset = 0; + Uint32 MaterialBufferOffset = ~0u; Uint32 NumVertexBuffers = 0; std::array ppVertexBuffers = {};