Go to the documentation of this file.
34 #include <unordered_map>
61 template <
typename ResourceDescType>
69 m_NumDeletedObjects{0},
70 m_DescToObjHashMap(
STD_ALLOCATOR_RAW_MEM(HashMapElem, RawAllocator,
"Allocator for unordered_map<ResourceDescType, RefCntWeakPtr<IDeviceObject> >")),
71 m_RegistryName{RegistryName}
82 VERIFY(m_DescToObjHashMap.empty(),
"DescToObjHashMap is not empty");
106 m_NumDeletedObjects = 0;
126 VERIFY(Elems.first->first == ObjectDesc,
"Incorrect object description");
128 "' with the same description already exists in the registry."
129 "Replacing with the new object named '",
130 ObjectDesc.Name ? ObjectDesc.Name :
"",
"'.");
131 Elems.first->second = pObject;
138 VERIFY(*ppObject ==
nullptr,
"Overwriting reference to existing object may cause memory leaks");
142 auto It = m_DescToObjHashMap.find(Desc);
143 if (It != m_DescToObjHashMap.end())
149 auto pObject = It->second.Lock();
152 *ppObject = pObject.Detach();
158 m_DescToObjHashMap.erase(It);
167 Uint32 NumPurgedObjects = 0;
168 auto It = m_DescToObjHashMap.begin();
169 while (It != m_DescToObjHashMap.end())
181 if (!It->second.IsValid())
183 m_DescToObjHashMap.erase(It);
189 LOG_INFO_MESSAGE(
"Purged ", NumPurgedObjects,
" deleted objects from the ", m_RegistryName,
" registry");
208 typedef std::pair<const ResourceDescType, RefCntWeakPtr<IDeviceObject>> HashMapElem;
209 std::unordered_map<ResourceDescType, RefCntWeakPtr<IDeviceObject>, std::hash<ResourceDescType>, std::equal_to<ResourceDescType>,
STDAllocatorRawMem<HashMapElem>> m_DescToObjHashMap;
212 const String m_RegistryName;
void Find(const ResourceDescType &Desc, IDeviceObject **ppObject)
Finds the object in the registry.
Definition: StateObjectsRegistry.hpp:136
StateObjectsRegistry(IMemoryAllocator &RawAllocator, const Char *RegistryName)
Definition: StateObjectsRegistry.hpp:68
char Char
Definition: BasicTypes.h:64
Implementation of weak pointers.
Definition: RefCntAutoPtr.hpp:40
void ReportDeletedObject()
Increments the number of outstanding deleted objects. When this number reaches DeletedObjectsToPurge,...
Definition: StateObjectsRegistry.hpp:195
~StateObjectsRegistry()
Definition: StateObjectsRegistry.hpp:74
static Type AtomicIncrement(std::atomic< Type > &Val)
Definition: BasicAtomics.hpp:41
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:52
Definition: STDAllocator.hpp:53
#define LOG_INFO_MESSAGE(...)
Definition: Errors.hpp:124
static constexpr int DeletedObjectsToPurge
Number of outstanding deleted objects to purge the registry.
Definition: StateObjectsRegistry.hpp:66
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Template class implementing state object registry.
Definition: StateObjectsRegistry.hpp:62
std::atomic< Long > AtomicLong
Definition: BasicAtomics.hpp:35
static Type AtomicDecrement(std::atomic< Type > &Val)
Definition: BasicAtomics.hpp:48
Base interface for a raw memory allocator.
Definition: MemoryAllocator.h:41
#define LOG_WARNING_MESSAGE(...)
Definition: Errors.hpp:123
void Add(const ResourceDescType &ObjectDesc, IDeviceObject *pObject)
Adds a new object to the registry.
Definition: StateObjectsRegistry.hpp:96
#define STD_ALLOCATOR_RAW_MEM(Type, Allocator, Description)
Definition: STDAllocator.hpp:179
std::basic_string< Char > String
String variable.
Definition: BasicTypes.h:66
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
void Purge()
Purges outstanding deleted objects from the registry.
Definition: StateObjectsRegistry.hpp:165
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37