Skip to content

Commit c308f4e

Browse files
HnMaterial: improved logic to detect if SRB needs to be recreated
1 parent 649e2e8 commit c308f4e

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

Hydrogent/include/HnTextureRegistry.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,13 @@ class HnTextureRegistry final : public std::enable_shared_from_this<HnTextureReg
160160

161161
/// Returns the texture registry storage version.
162162
///
163-
/// \remarks The storage version is incremented every time a new texture is created
164-
/// or dynamic texture atlas version changes.
163+
/// \remarks The storage version is incremented every time a new texture is created.
165164
///
166165
/// The storage version is not incremented when the texture data is updated.
167166
Uint32 GetStorageVersion() const;
168167

168+
Uint32 GetAtlasVersion() const;
169+
169170
/// Returns the texture registry data version.
170171
///
171172
/// \remarks The data version is incremented every time a texture is loaded or updated.

Hydrogent/src/HnMaterial.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,20 @@ bool HnMaterial::UpdateSRB(HnRenderDelegate& RenderDelegate)
975975
RefCntAutoPtr<HnMaterialSRBCache> SRBCache{RenderDelegate.GetMaterialSRBCache(), IID_HnMaterialSRBCache};
976976
VERIFY_EXPR(SRBCache);
977977

978-
const Uint32 ResourceCacheVersion = TexRegistry.GetStorageVersion() + SRBCache->GetMaterialAttribsBufferVersion();
978+
const HN_MATERIAL_TEXTURES_BINDING_MODE BindingMode = static_cast<const HnRenderParam*>(RenderDelegate.GetRenderParam())->GetTextureBindingMode();
979+
980+
Uint32 ResourceCacheVersion = SRBCache->GetMaterialAttribsBufferVersion();
981+
if (BindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_ATLAS)
982+
{
983+
// Need to recreate SRBs if the atlas texture has changed
984+
ResourceCacheVersion += TexRegistry.GetAtlasVersion();
985+
}
986+
else if (BindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_DYNAMIC)
987+
{
988+
// Need to recreate the SRB if any new texture is created
989+
ResourceCacheVersion += TexRegistry.GetStorageVersion();
990+
}
991+
979992
if (m_ResourceCacheVersion != ResourceCacheVersion)
980993
{
981994
m_SRB.Release();
@@ -1022,7 +1035,6 @@ bool HnMaterial::UpdateSRB(HnRenderDelegate& RenderDelegate)
10221035

10231036
HnMaterialSRBCache::ResourceKey SRBKey{m_ResourceCacheVersion};
10241037

1025-
const HN_MATERIAL_TEXTURES_BINDING_MODE BindingMode = static_cast<const HnRenderParam*>(RenderDelegate.GetRenderParam())->GetTextureBindingMode();
10261038
if (BindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_LEGACY ||
10271039
BindingMode == HN_MATERIAL_TEXTURES_BINDING_MODE_ATLAS)
10281040
{

Hydrogent/src/HnRenderDelegate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,8 @@ void HnRenderDelegate::CommitResources(pxr::HdChangeTracker* tracker)
738738
}
739739

740740
{
741-
// Tex storage version is incremented every time a new texture is created or texture atlas version changes.
742-
const Uint32 TexStorageVersion = m_TextureRegistry->GetStorageVersion();
741+
// Tex storage version is incremented every time a new texture is created.
742+
const Uint32 TexStorageVersion = m_TextureRegistry->GetStorageVersion() + m_TextureRegistry->GetAtlasVersion();
743743
if (m_MaterialResourcesVersion != m_RenderParam->GetAttribVersion(HnRenderParam::GlobalAttrib::Material) + TexStorageVersion)
744744
{
745745
std::lock_guard<std::mutex> Guard{m_MaterialsMtx};

Hydrogent/src/HnTextureRegistry.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,12 @@ HnTextureRegistry::TextureHandleSharedPtr HnTextureRegistry::Allocate(const HnTe
416416

417417
Uint32 HnTextureRegistry::GetStorageVersion() const
418418
{
419-
Uint32 Version = m_StorageVersion.load();
420-
if (m_pResourceManager != nullptr)
421-
Version += m_pResourceManager->GetTextureVersion();
422-
return Version;
419+
return m_StorageVersion.load();
420+
}
421+
422+
Uint32 HnTextureRegistry::GetAtlasVersion() const
423+
{
424+
return m_pResourceManager != nullptr ? m_pResourceManager->GetTextureVersion() : 0;
423425
}
424426

425427
Uint32 HnTextureRegistry::GetDataVersion() const

0 commit comments

Comments
 (0)