@@ -250,6 +250,52 @@ RefCntAutoPtr<ITextureAtlasSuballocation> ResourceManager::AllocateTextureSpace(
250250 return pAllocation;
251251}
252252
253+ std::vector<IDynamicTextureAtlas*>& ResourceManager::GetAtlasSnapshot ()
254+ {
255+ m_AtlasSnapshot.clear ();
256+
257+ {
258+ std::shared_lock<std::shared_mutex> SharedLock{m_AtlasesMtx};
259+ for (const auto & it : m_Atlases)
260+ {
261+ m_AtlasSnapshot.emplace_back (it.second );
262+ }
263+ }
264+
265+ return m_AtlasSnapshot;
266+ }
267+
268+ std::vector<IVertexPool*>& ResourceManager::GetVertexPoolSnapshot ()
269+ {
270+ m_VertexPoolSnapshot.clear ();
271+
272+ {
273+ std::shared_lock<std::shared_mutex> SharedLock{m_VertexPoolsMtx};
274+ for (const auto & pools_it : m_VertexPools)
275+ {
276+ for (const auto & Pool : pools_it.second )
277+ m_VertexPoolSnapshot.emplace_back (Pool);
278+ }
279+ }
280+
281+ return m_VertexPoolSnapshot;
282+ }
283+
284+ std::vector<IBufferSuballocator*>& ResourceManager::GetIndexAllocatorSnapshot ()
285+ {
286+ m_IndexAllocatorSnapshot.clear ();
287+
288+ {
289+ std::shared_lock<std::shared_mutex> SharedLock{m_IndexAllocatorsMtx};
290+ for (const RefCntAutoPtr<IBufferSuballocator>& pAllocator : m_IndexAllocators)
291+ {
292+ m_IndexAllocatorSnapshot.emplace_back (pAllocator);
293+ }
294+ }
295+
296+ return m_IndexAllocatorSnapshot;
297+ }
298+
253299RefCntAutoPtr<IBufferSuballocator> ResourceManager::CreateIndexBufferAllocator (IRenderDevice* pDevice) const
254300{
255301 RefCntAutoPtr<IBufferSuballocator> pIndexBufferAllocator;
@@ -395,7 +441,7 @@ Uint32 ResourceManager::GetTextureVersion() const
395441 Uint32 Version = 0 ;
396442
397443 std::shared_lock<std::shared_mutex> SharedLock{m_AtlasesMtx};
398- for (auto atlas_it : m_Atlases)
444+ for (const auto & atlas_it : m_Atlases)
399445 Version += atlas_it.second ->GetVersion ();
400446
401447 return Version;
@@ -407,7 +453,7 @@ Uint32 ResourceManager::GetIndexBufferVersion() const
407453 Uint32 Version = 0 ;
408454
409455 std::shared_lock<std::shared_mutex> SharedLock{m_IndexAllocatorsMtx};
410- for (const auto & pAllocator : m_IndexAllocators)
456+ for (const RefCntAutoPtr<IBufferSuballocator> & pAllocator : m_IndexAllocators)
411457 Version += pAllocator ? pAllocator->GetVersion () : 0 ;
412458
413459 return Version;
@@ -441,22 +487,10 @@ IBuffer* ResourceManager::UpdateIndexBuffer(IRenderDevice* pDevice, IDeviceConte
441487
442488void ResourceManager::UpdateIndexBuffers (IRenderDevice* pDevice, IDeviceContext* pContext)
443489{
444- Uint32 Index = 0 ;
445- for (;; ++Index)
446- {
447- IBufferSuballocator* pIndexBufferAllocator = nullptr ;
448- {
449- std::shared_lock<std::shared_mutex> SharedLock{m_IndexAllocatorsMtx};
450- if (Index >= m_IndexAllocators.size ())
451- break ;
452- pIndexBufferAllocator = m_IndexAllocators[Index];
453- }
490+ for (IBufferSuballocator* pAllocator : GetIndexAllocatorSnapshot ())
491+ pAllocator->Update (pDevice, pContext);
454492
455- if (pIndexBufferAllocator != nullptr )
456- {
457- pIndexBufferAllocator->Update (pDevice, pContext);
458- }
459- }
493+ m_IndexAllocatorSnapshot.clear ();
460494}
461495
462496IBuffer* ResourceManager::GetIndexBuffer (Uint32 Index) const
@@ -491,21 +525,10 @@ Uint32 ResourceManager::GetIndexAllocatorIndex(IBufferSuballocator* pAllocator)
491525
492526void ResourceManager::UpdateVertexBuffers (IRenderDevice* pDevice, IDeviceContext* pContext)
493527{
494- m_TmpVertexPoolList.clear ();
495-
496- {
497- std::shared_lock<std::shared_mutex> SharedLock{m_VertexPoolsMtx};
498- for (const auto & pools_it : m_VertexPools)
499- {
500- for (const auto & Pool : pools_it.second )
501- m_TmpVertexPoolList.emplace_back (Pool);
502- }
503- }
504-
505- for (IVertexPool* Pool : m_TmpVertexPoolList)
528+ for (IVertexPool* Pool : GetVertexPoolSnapshot ())
506529 Pool->UpdateAll (pDevice, pContext);
507530
508- m_TmpVertexPoolList .clear ();
531+ m_VertexPoolSnapshot .clear ();
509532}
510533
511534IVertexPool* ResourceManager::GetVertexPool (const VertexLayoutKey& Key, Uint32 Index)
@@ -577,20 +600,10 @@ ITexture* ResourceManager::UpdateTexture(TEXTURE_FORMAT Fmt, IRenderDevice* pDev
577600
578601void ResourceManager::UpdateTextures (IRenderDevice* pDevice, IDeviceContext* pContext)
579602{
580- m_TmpAtlasList.clear ();
581-
582- {
583- std::shared_lock<std::shared_mutex> SharedLock{m_AtlasesMtx};
584- for (auto it : m_Atlases)
585- {
586- m_TmpAtlasList.emplace_back (it.second );
587- }
588- }
589-
590- for (IDynamicTextureAtlas* pAtlas : m_TmpAtlasList)
603+ for (IDynamicTextureAtlas* pAtlas : GetAtlasSnapshot ())
591604 pAtlas->Update (pDevice, pContext);
592605
593- m_TmpAtlasList .clear ();
606+ m_AtlasSnapshot .clear ();
594607}
595608
596609ITexture* ResourceManager::GetTexture (TEXTURE_FORMAT Fmt) const
@@ -675,7 +688,7 @@ DynamicTextureAtlasUsageStats ResourceManager::GetAtlasUsageStats(TEXTURE_FORMAT
675688 }
676689 else
677690 {
678- for (auto it : m_Atlases)
691+ for (const auto & it : m_Atlases)
679692 {
680693 DynamicTextureAtlasUsageStats AtlasStats;
681694 it.second ->GetUsageStats (AtlasStats);
@@ -746,18 +759,7 @@ void ResourceManager::TransitionResourceStates(IRenderDevice* pDevice, IDeviceCo
746759
747760 if (Info.VertexBuffers .NewState != RESOURCE_STATE_UNKNOWN)
748761 {
749- m_TmpVertexPoolList.clear ();
750-
751- {
752- std::shared_lock<std::shared_mutex> SharedLock{m_VertexPoolsMtx};
753- for (const auto & pools_it : m_VertexPools)
754- {
755- for (const auto & pPool : pools_it.second )
756- m_TmpVertexPoolList.emplace_back (pPool);
757- }
758- }
759-
760- for (IVertexPool* pPool : m_TmpVertexPoolList)
762+ for (IVertexPool* pPool : GetVertexPoolSnapshot ())
761763 {
762764 const VertexPoolDesc& Desc = pPool->GetDesc ();
763765 for (Uint32 elem = 0 ; elem < Desc.NumElements ; ++elem)
@@ -772,31 +774,28 @@ void ResourceManager::TransitionResourceStates(IRenderDevice* pDevice, IDeviceCo
772774 }
773775 }
774776
775- m_TmpVertexPoolList .clear ();
777+ m_VertexPoolSnapshot .clear ();
776778 }
777779
778780 if (Info.IndexBuffer .NewState != RESOURCE_STATE_UNKNOWN)
779781 {
780- IBuffer* pIndexBuffer = Info.IndexBuffer .Update ?
781- UpdateIndexBuffer (pDevice, pContext) :
782- GetIndexBuffer ();
783- if (pIndexBuffer != nullptr )
782+ for (IBufferSuballocator* pAllocator : GetIndexAllocatorSnapshot ())
784783 {
785- m_Barriers.emplace_back (pIndexBuffer, Info.IndexBuffer .OldState , Info.IndexBuffer .NewState , Info.IndexBuffer .Flags );
784+ IBuffer* pIndexBuffer = Info.IndexBuffer .Update ?
785+ pAllocator->Update (pDevice, pContext) :
786+ pAllocator->GetBuffer ();
787+ if (pIndexBuffer != nullptr )
788+ {
789+ m_Barriers.emplace_back (pIndexBuffer, Info.IndexBuffer .OldState , Info.IndexBuffer .NewState , Info.IndexBuffer .Flags );
790+ }
786791 }
792+
793+ m_IndexAllocatorSnapshot.clear ();
787794 }
788795
789796 if (Info.TextureAtlases .NewState != RESOURCE_STATE_UNKNOWN)
790797 {
791- m_TmpAtlasList.clear ();
792-
793- {
794- std::shared_lock<std::shared_mutex> SharedLock{m_AtlasesMtx};
795- for (auto it : m_Atlases)
796- m_TmpAtlasList.emplace_back (it.second );
797- }
798-
799- for (IDynamicTextureAtlas* pAtlas : m_TmpAtlasList)
798+ for (IDynamicTextureAtlas* pAtlas : GetAtlasSnapshot ())
800799 {
801800 ITexture* pTexture = Info.TextureAtlases .Update ?
802801 pAtlas->Update (pDevice, pContext) :
@@ -807,7 +806,7 @@ void ResourceManager::TransitionResourceStates(IRenderDevice* pDevice, IDeviceCo
807806 }
808807 }
809808
810- m_TmpAtlasList .clear ();
809+ m_AtlasSnapshot .clear ();
811810 }
812811
813812 if (!m_Barriers.empty ())
0 commit comments