summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-11-06 09:30:57 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-11-06 09:30:57 +0000
commit212c9d56ecea034ba637164a54847b24bcc82fbd (patch)
tree6a02089d7d322734b9ae9ced4da0288f0af681b9 /Graphics/GraphicsEngine
parentUpdated ShaderBindingTableBase (diff)
downloadDiligentCore-212c9d56ecea034ba637164a54847b24bcc82fbd.tar.gz
DiligentCore-212c9d56ecea034ba637164a54847b24bcc82fbd.zip
Updated ResourceMappingImpl
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/ResourceMappingImpl.hpp102
-rw-r--r--Graphics/GraphicsEngine/src/ResourceMappingBase.cpp13
2 files changed, 48 insertions, 67 deletions
diff --git a/Graphics/GraphicsEngine/include/ResourceMappingImpl.hpp b/Graphics/GraphicsEngine/include/ResourceMappingImpl.hpp
index b64c8804..ad70ae9d 100644
--- a/Graphics/GraphicsEngine/include/ResourceMappingImpl.hpp
+++ b/Graphics/GraphicsEngine/include/ResourceMappingImpl.hpp
@@ -40,60 +40,7 @@
namespace Diligent
{
-struct ResMappingHashKey
-{
- ResMappingHashKey(const Char* Str, bool bMakeCopy, Uint32 ArrInd) :
- StrKey{Str, bMakeCopy},
- ArrayIndex{ArrInd}
- {
- }
-
- ResMappingHashKey(ResMappingHashKey&& rhs) :
- StrKey{std::move(rhs.StrKey)},
- ArrayIndex{rhs.ArrayIndex}
- {}
-
- bool operator==(const ResMappingHashKey& RHS) const
- {
- return StrKey == RHS.StrKey && ArrayIndex == RHS.ArrayIndex;
- }
-
- size_t GetHash() const
- {
- if (Hash == 0)
- {
- Hash = ComputeHash(StrKey.GetHash(), ArrayIndex);
- }
-
- return Hash;
- }
-
- // clang-format off
- ResMappingHashKey ( const ResMappingHashKey& ) = delete;
- ResMappingHashKey& operator = ( const ResMappingHashKey& ) = delete;
- ResMappingHashKey& operator = ( ResMappingHashKey&& ) = delete;
- // clang-format on
- HashMapStringKey StrKey;
- Uint32 ArrayIndex;
- mutable size_t Hash = 0;
-};
-} // namespace Diligent
-
-namespace std
-{
-template <>
-struct hash<Diligent::ResMappingHashKey>
-{
- size_t operator()(const Diligent::ResMappingHashKey& Key) const
- {
- return Key.GetHash();
- }
-};
-} // namespace std
-
-namespace Diligent
-{
class FixedBlockMemoryAllocator;
/// Implementation of the resource mapping
@@ -105,13 +52,13 @@ public:
/// \param pRefCounters - reference counters object that controls the lifetime of this resource mapping
/// \param RawMemAllocator - raw memory allocator that is used by the m_HashTable member
ResourceMappingImpl(IReferenceCounters* pRefCounters, IMemoryAllocator& RawMemAllocator) :
- TObjectBase(pRefCounters),
- m_HashTable(STD_ALLOCATOR_RAW_MEM(HashTableElem, RawMemAllocator, "Allocator for unordered_map< ResMappingHashKey, RefCntAutoPtr<IDeviceObject> >"))
+ TObjectBase{pRefCounters},
+ m_HashTable{STD_ALLOCATOR_RAW_MEM(HashTableElem, RawMemAllocator, "Allocator for unordered_map<ResMappingHashKey, RefCntAutoPtr<IDeviceObject>>")}
{}
~ResourceMappingImpl();
- virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
+ IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_ResourceMapping, TObjectBase)
/// Implementation of IResourceMapping::AddResource()
virtual void DILIGENT_CALL_TYPE AddResource(const Char* Name,
@@ -137,10 +84,47 @@ public:
virtual size_t DILIGENT_CALL_TYPE GetSize() override final;
private:
+ struct ResMappingHashKey : public HashMapStringKey
+ {
+ using TBase = HashMapStringKey;
+
+ ResMappingHashKey(const Char* Str, bool bMakeCopy, Uint32 ArrInd) :
+ HashMapStringKey{Str, bMakeCopy},
+ ArrayIndex{ArrInd}
+ {
+ Ownership_Hash = (ComputeHash(GetHash(), ArrInd) & HashMask) | (Ownership_Hash & StrOwnershipMask);
+ }
+
+ ResMappingHashKey(ResMappingHashKey&& rhs) :
+ HashMapStringKey{std::move(rhs)},
+ ArrayIndex{rhs.ArrayIndex}
+ {}
+
+ // clang-format off
+ ResMappingHashKey ( const ResMappingHashKey& ) = delete;
+ ResMappingHashKey& operator = ( const ResMappingHashKey& ) = delete;
+ ResMappingHashKey& operator = ( ResMappingHashKey&& ) = delete;
+ // clang-format on
+
+ bool operator==(const ResMappingHashKey& RHS) const
+ {
+ return static_cast<const TBase&>(*this) == static_cast<const TBase&>(RHS) && ArrayIndex == RHS.ArrayIndex;
+ }
+
+ const Uint32 ArrayIndex;
+ };
+
ThreadingTools::LockHelper Lock();
- ThreadingTools::LockFlag m_LockFlag;
- typedef std::pair<const ResMappingHashKey, RefCntAutoPtr<IDeviceObject>> HashTableElem;
- std::unordered_map<ResMappingHashKey, RefCntAutoPtr<IDeviceObject>, std::hash<ResMappingHashKey>, std::equal_to<ResMappingHashKey>, STDAllocatorRawMem<HashTableElem>> m_HashTable;
+ ThreadingTools::LockFlag m_LockFlag;
+
+ using HashTableElem = std::pair<const ResMappingHashKey, RefCntAutoPtr<IDeviceObject>>;
+ std::unordered_map<ResMappingHashKey,
+ RefCntAutoPtr<IDeviceObject>,
+ ResMappingHashKey::Hasher,
+ std::equal_to<ResMappingHashKey>,
+ STDAllocatorRawMem<HashTableElem>>
+ m_HashTable;
};
+
} // namespace Diligent
diff --git a/Graphics/GraphicsEngine/src/ResourceMappingBase.cpp b/Graphics/GraphicsEngine/src/ResourceMappingBase.cpp
index 5ab951b4..859dcf88 100644
--- a/Graphics/GraphicsEngine/src/ResourceMappingBase.cpp
+++ b/Graphics/GraphicsEngine/src/ResourceMappingBase.cpp
@@ -30,12 +30,11 @@
namespace Diligent
{
+
ResourceMappingImpl::~ResourceMappingImpl()
{
}
-IMPLEMENT_QUERY_INTERFACE(ResourceMappingImpl, IID_ResourceMapping, TObjectBase)
-
ThreadingTools::LockHelper ResourceMappingImpl::Lock()
{
return ThreadingTools::LockHelper(m_LockFlag);
@@ -52,10 +51,7 @@ void ResourceMappingImpl::AddResourceArray(const Char* Name, Uint32 StartIndex,
auto* pObject = ppObjects[Elem];
// Try to construct new element in place
- auto Elems =
- m_HashTable.emplace(
- std::make_pair(Diligent::ResMappingHashKey(Name, true, StartIndex + Elem), // Make a copy of the source string
- Diligent::RefCntAutoPtr<IDeviceObject>(pObject)));
+ auto Elems = m_HashTable.emplace(ResMappingHashKey{Name, true /*Make copy*/, StartIndex + Elem}, pObject);
// If there is already element with the same name, replace it
if (!Elems.second && Elems.first->second != pObject)
{
@@ -85,7 +81,7 @@ void ResourceMappingImpl::RemoveResourceByName(const Char* Name, Uint32 ArrayInd
auto LockHelper = Lock();
// Remove object with the given name
// Name will be implicitly converted to HashMapStringKey without making a copy
- m_HashTable.erase(ResMappingHashKey(Name, false, ArrayIndex));
+ m_HashTable.erase(ResMappingHashKey{Name, false, ArrayIndex});
}
void ResourceMappingImpl::GetResource(const Char* Name, IDeviceObject** ppResource, Uint32 ArrayIndex)
@@ -105,7 +101,7 @@ void ResourceMappingImpl::GetResource(const Char* Name, IDeviceObject** ppResour
// Find an object with the requested name
// Name will be implicitly converted to HashMapStringKey without making a copy
- auto It = m_HashTable.find(ResMappingHashKey(Name, false, ArrayIndex));
+ auto It = m_HashTable.find(ResMappingHashKey{Name, false, ArrayIndex});
if (It != m_HashTable.end())
{
*ppResource = It->second.RawPtr();
@@ -118,4 +114,5 @@ size_t ResourceMappingImpl::GetSize()
{
return m_HashTable.size();
}
+
} // namespace Diligent