diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-05-26 21:38:05 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-05-26 21:38:05 +0000 |
| commit | 0a7d205555beed14a75688333544944f631b0fe3 (patch) | |
| tree | 4462331af35f4a861f7d3ecbf04c7d172c092772 /Graphics/GraphicsEngineVulkan | |
| parent | Updated comments to ShaderResourceLayoutVk plus some other minor updates (diff) | |
| download | DiligentCore-0a7d205555beed14a75688333544944f631b0fe3.tar.gz DiligentCore-0a7d205555beed14a75688333544944f631b0fe3.zip | |
Updated comments to ShaderVariableManagerVk
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
3 files changed, 55 insertions, 54 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h index 5ba41839..81aa5ed9 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h @@ -44,7 +44,7 @@ // * Every VkResource structure holds a reference to SPIRVShaderResourceAttribs structure from SPIRVShaderResources. // * ShaderResourceLayoutVk keeps a shared pointer to SPIRVShaderResources instance. // * Every ShaderVariableVkImpl variable managed by ShaderVariableManagerVk keeps a reference to corresponding VkResource. -// +// // // ______________________ ________________________________________________________________________ // | | unique_ptr | | | | | | | | @@ -52,19 +52,19 @@ // |______________________| |________|_________|__________|__________|_______|_________|_____________| // A A A // | | | -// |shared_ptr Ref Ref +// |shared_ptr Ref Ref // ________|__________________ ________\____________________|_____________________________________________ // | | unique_ptr | | | | | // | ShaderResourceLayoutVk |--------------->| VkResource[0] | VkResource[1] | ... | VkResource[s+m+d-1] | // |___________________________| |___________________|_________________|_______________|_____________________| -// A A -// | | -// Ref Ref -// | \ -// __________________________ _________|_____________________\__________________________________________ -// | | | | | | +// A A +// / | +// Ref Ref +// / | +// __________________________ __________________/___________________________|___________________________ +// | | | | | | // | ShaderVariableManagerVk |---------------->| ShaderVariableVkImpl[0] | ShaderVariableVkImpl[1] | ... | -// |__________________________| |___________________________|____________________________|_________________| +// |__________________________| |___________________________|____________________________|_________________| // // // @@ -75,14 +75,14 @@ // | | unique_ptr | | | | | // | ShaderResourceLayoutVk |--------------->| VkResource[0] | VkResource[1] | ... | VkResource[s+m+d-1] | // |___________________________| |___________________|_________________|_______________|_____________________| -// | | -// | | -// | (DescriptorSet, CacheOffset) / (DescriptorSet, CacheOffset) -// \ / -// __________________________ ________V_______________________________________________________V_______ -// | | | | -// | ShaderResourceCacheVk |---------------->| Resources | -// |__________________________| |________________________________________________________________________| +// | | +// | | +// | (DescriptorSet, CacheOffset) / (DescriptorSet, CacheOffset) +// \ / +// __________________________ ________V_______________________________________________________V_______ +// | | | | +// | ShaderResourceCacheVk |---------------->| Resources | +// |__________________________| |________________________________________________________________________| // // // diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h index 13fef274..fff164d4 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h @@ -23,13 +23,41 @@ #pragma once +/// \file +/// Declaration of Diligent::ShaderVariableManagerVk and Diligent::ShaderVariableVkImpl classes + +// +// * ShaderVariableManagerVk keeps list of variables of a specific type. +// * Every ShaderVariableVkImpl references VkResource from ShaderResourceLayoutVk +// * ShaderVariableManagerVk keeps pointer to ShaderResourceCacheVk +// * ShaderVariableManagerVk is used by ShaderVkImpl to manage static resources and by +// ShaderResourceBindingVkImpl to manage mutable and dynamic resources +// +// __________________________ __________________________________________________________________________ +// | | | | | | +// ----| ShaderVariableManagerVk |---------------->| ShaderVariableVkImpl[0] | ShaderVariableVkImpl[1] | ... | +// | |__________________________| |___________________________|____________________________|_________________| +// | | \ | +// | | Ref Ref +// | | \ | +// | ___________V_______________ ______________________V_______________________V____________________________ +// | | | unique_ptr | | | | | +// | | ShaderResourceLayoutVk |--------------->| VkResource[0] | VkResource[1] | ... | VkResource[s+m+d-1] | +// | |___________________________| |___________________|_________________|_______________|_____________________| +// | | | +// | | | +// | | (DescriptorSet, CacheOffset) / (DescriptorSet, CacheOffset) +// | \ / +// | __________________________ ________V_______________________________________________________V_______ +// | | | | | +// --->| ShaderResourceCacheVk |---------------->| Resources | +// |__________________________| |________________________________________________________________________| +// +// + #include <memory> #include <unordered_map> -// Set this define to 1 to use unordered_map to store shader variables. -// Note that sizeof(m_VariableHash)==128 (release mode, MS compiler, x64). -#define USE_VARIABLE_HASH_MAP 0 - #include "ShaderResourceLayoutVk.h" namespace Diligent @@ -37,6 +65,7 @@ namespace Diligent class ShaderVariableVkImpl; +// sizeof(ShaderVariableManagerVk) == 40 (x64, msvc, Release) class ShaderVariableManagerVk { public: @@ -59,20 +88,16 @@ public: private: friend ShaderVariableVkImpl; -#if USE_VARIABLE_HASH_MAP - void InitVariablesHashMap(); - - // Hash map to look up shader variables by name. - // Note that sizeof(m_VariableHash)==128 (release mode, MS compiler, x64). - typedef std::pair<HashMapStringKey, IShaderVariable*> VariableHashElemType; - std::unordered_map<HashMapStringKey, IShaderVariable*, std::hash<HashMapStringKey>, std::equal_to<HashMapStringKey>, STDAllocatorRawMem<VariableHashElemType> > m_VariableHash; -#endif - IObject& m_Owner; const ShaderResourceLayoutVk* m_pResourceLayout= nullptr; ShaderResourceCacheVk* m_pResourceCache = nullptr; + + // Memory is allocated through the allocator provided by the pipeline state. If allocation granularity > 1, fixed block + // memory allocator is used. This ensures that all resources from different shader resource bindings reside in + // continuous memory. If allocation granularity == 1, raw allocator is used. ShaderVariableVkImpl* m_pVariables = nullptr; Uint32 m_NumVariables = 0; + #ifdef _DEBUG IMemoryAllocator* m_pDbgAllocator = nullptr; #endif diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp index 6f6f7d9e..c08ad725 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp @@ -71,10 +71,6 @@ void ShaderVariableManagerVk::Initialize(const ShaderResourceLayoutVk& SrcLayout } } VERIFY_EXPR(VarInd == m_NumVariables); - -#if USE_VARIABLE_HASH_MAP - InitVariablesHashMap(); -#endif } ShaderVariableManagerVk::~ShaderVariableManagerVk() @@ -95,12 +91,6 @@ void ShaderVariableManagerVk::Destroy(IMemoryAllocator &Allocator) ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(const Char* Name) { ShaderVariableVkImpl* pVar = nullptr; -#if USE_VARIABLE_HASH_MAP - // Name will be implicitly converted to HashMapStringKey without making a copy - auto it = m_VariableHash.find(Name); - if (it != m_VariableHash.end()) - pVar = it->second; -#else for (Uint32 v = 0; v < m_NumVariables; ++v) { auto &Var = m_pVariables[v]; @@ -111,7 +101,6 @@ ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(const Char* Name) break; } } -#endif if (pVar == nullptr) { @@ -160,17 +149,4 @@ void ShaderVariableManagerVk::BindResources( IResourceMapping* pResourceMapping, } } -#if USE_VARIABLE_HASH_MAP -void ShaderVariableManagerVk::InitVariablesHashMap() -{ - Uint32 TotalResources = GetTotalResourceCount(); - for (Uint32 r = 0; r < TotalResources; ++r) - { - auto &Res = GetResource(r); - /* HashMapStringKey will make a copy of the string*/ - m_VariableHash.insert(std::make_pair(Diligent::HashMapStringKey(Res.Name), &Res)); - } -} -#endif - } |
