summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-05-09 15:28:31 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-05-09 15:28:31 +0000
commit4b38583f4d7d95e9a17180380ea7f59847112310 (patch)
treea6036158a97a8111eb9721ccd773bf11e7bed1f8 /Graphics/GraphicsEngineVulkan
parentImplemented ShaderResourceLayoutVk::dbgVerifyBindings() (diff)
downloadDiligentCore-4b38583f4d7d95e9a17180380ea7f59847112310.tar.gz
DiligentCore-4b38583f4d7d95e9a17180380ea7f59847112310.zip
Implemented VK shader resource layout initialization
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/PipelineLayout.h3
-rw-r--r--Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h29
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h3
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h38
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp6
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp17
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp21
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp79
8 files changed, 81 insertions, 115 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineLayout.h b/Graphics/GraphicsEngineVulkan/include/PipelineLayout.h
index 7846c17b..79110519 100644
--- a/Graphics/GraphicsEngineVulkan/include/PipelineLayout.h
+++ b/Graphics/GraphicsEngineVulkan/include/PipelineLayout.h
@@ -53,9 +53,8 @@ public:
void Finalize(const VulkanUtilities::VulkanLogicalDevice& LogicalDevice);
VkPipelineLayout GetVkPipelineLayout()const{return m_LayoutMgr.GetVkPipelineLayout();}
-#if 0
void InitResourceCache(RenderDeviceVkImpl *pDeviceVkImpl, class ShaderResourceCacheVk& ResourceCache, IMemoryAllocator &CacheMemAllocator)const;
-
+#if 0
void InitStaticSampler(SHADER_TYPE ShaderType, const String &TextureName, const D3DShaderResourceAttribs &ShaderResAttribs);
#endif
diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h
index 8e29dd30..062a5340 100644
--- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h
@@ -68,21 +68,26 @@ public:
// bool CommitResources,
// bool TransitionResources)const;
- //const RootSignature& GetRootSignature()const{return m_RootSig;}
-
- //const ShaderResourceLayoutVk& GetShaderResLayout(SHADER_TYPE ShaderType)const;
+ const PipelineLayout& GetPipelineLayout()const{return m_PipelineLayout;}
+ const ShaderResourceLayoutVk& GetShaderResLayout(SHADER_TYPE ShaderType)const
+ {
+ auto ShaderInd = GetShaderTypeIndex(ShaderType);
+ VERIFY_EXPR(m_pShaderResourceLayouts[ShaderInd] != nullptr);
+ return *m_pShaderResourceLayouts[ShaderInd];
+ }
+
//bool dbgContainsShaderResources()const;
- //IMemoryAllocator &GetResourceCacheDataAllocator(){return m_ResourceCacheDataAllocator;}
- //IMemoryAllocator &GetShaderResourceLayoutDataAllocator(Uint32 ActiveShaderInd)
- //{
- // VERIFY_EXPR(ActiveShaderInd < m_NumShaders);
- // auto *pAllocator = m_ResLayoutDataAllocators.GetAllocator(ActiveShaderInd);
- // return pAllocator != nullptr ? *pAllocator : GetRawAllocator();
- //}
+ IMemoryAllocator& GetResourceCacheDataAllocator(){return m_ResourceCacheDataAllocator;}
+ IMemoryAllocator& GetShaderResourceLayoutDataAllocator(Uint32 ActiveShaderInd)
+ {
+ VERIFY_EXPR(ActiveShaderInd < m_NumShaders);
+ auto *pAllocator = m_ResLayoutDataAllocators.GetAllocator(ActiveShaderInd);
+ return pAllocator != nullptr ? *pAllocator : GetRawAllocator();
+ }
- //IShaderVariable *GetDummyShaderVar(){return &m_DummyVar;}
+ IShaderVariable *GetDummyShaderVar(){return &m_DummyVar;}
private:
@@ -124,7 +129,7 @@ private:
// Do not use strong reference to avoid cyclic references
// Default SRB must be defined after allocators
- //std::unique_ptr<class ShaderResourceBindingVkImpl, STDDeleter<ShaderResourceBindingVkImpl, FixedBlockMemoryAllocator> > m_pDefaultShaderResBinding;
+ std::unique_ptr<class ShaderResourceBindingVkImpl, STDDeleter<ShaderResourceBindingVkImpl, FixedBlockMemoryAllocator> > m_pDefaultShaderResBinding;
VulkanUtilities::RenderPassWrapper m_RenderPass;
VulkanUtilities::PipelineWrapper m_Pipeline;
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h
index a669ac5d..5f572c93 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h
@@ -51,7 +51,7 @@ public:
virtual IShaderVariable *GetVariable(SHADER_TYPE ShaderType, const char *Name)override;
-/* ShaderResourceLayoutVk& GetResourceLayout(SHADER_TYPE ResType)
+ ShaderResourceLayoutVk& GetResourceLayout(SHADER_TYPE ResType)
{
auto ShaderInd = GetShaderTypeIndex(ResType);
auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
@@ -76,7 +76,6 @@ private:
Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1};
bool m_bStaticResourcesInitialized = false;
Uint32 m_NumShaders = 0;
-*/
};
}
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h
index 6cca7ba2..1a217684 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h
@@ -120,13 +120,13 @@ public:
ShaderResourceLayoutVk(IObject &Owner, IMemoryAllocator &ResourceLayoutDataAllocator);
// This constructor is used by ShaderResourceBindingVkImpl to clone layout from the reference layout in PipelineStateVkImpl.
- // Root indices and descriptor table offsets must be correct. Resource cache is assigned, but not initialized.
- //ShaderResourceLayoutVk(IObject &Owner,
- // const ShaderResourceLayoutVk& SrcLayout,
- // IMemoryAllocator &ResourceLayoutDataAllocator,
- // const SHADER_VARIABLE_TYPE *AllowedVarTypes,
- // Uint32 NumAllowedTypes,
- // ShaderResourceCacheVk &ResourceCache);
+ // Descriptor sets and bindings must be correct. Resource cache is assigned, but not initialized.
+ ShaderResourceLayoutVk(IObject &Owner,
+ const ShaderResourceLayoutVk& SrcLayout,
+ IMemoryAllocator &ResourceLayoutDataAllocator,
+ const SHADER_VARIABLE_TYPE *AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ ShaderResourceCacheVk &ResourceCache);
ShaderResourceLayoutVk(const ShaderResourceLayoutVk&) = delete;
ShaderResourceLayoutVk(ShaderResourceLayoutVk&&) = delete;
@@ -160,7 +160,7 @@ public:
const Uint16 Binding;
const Uint16 DescriptorSet;
- const Uint32 OffsetFromSetStart;
+ const Uint32 CacheOffset; // Offset from the beginning of the cached descriptor set
const SPIRVShaderResourceAttribs &SpirvAttribs;
ShaderResourceLayoutVk &ParentResLayout;
@@ -168,17 +168,27 @@ public:
const SPIRVShaderResourceAttribs& _SpirvAttribs,
uint32_t _Binding,
uint32_t _DescriptorSet,
- Uint32 _OffsetFromSetStart) :
- Binding(static_cast<decltype(Binding)>(_Binding)),
- DescriptorSet(static_cast<decltype(DescriptorSet)>(_DescriptorSet)),
- OffsetFromSetStart(_OffsetFromSetStart),
- SpirvAttribs(_SpirvAttribs),
- ParentResLayout(_ParentLayout)
+ Uint32 _CacheOffset) :
+ Binding (static_cast<decltype(Binding)>(_Binding)),
+ DescriptorSet (static_cast<decltype(DescriptorSet)>(_DescriptorSet)),
+ CacheOffset (_CacheOffset),
+ SpirvAttribs (_SpirvAttribs),
+ ParentResLayout (_ParentLayout)
{
VERIFY(_Binding <= std::numeric_limits<decltype(Binding)>::max(), "Binding (", _Binding, ") exceeds representable max value", std::numeric_limits<decltype(Binding)>::max() );
VERIFY(_DescriptorSet <= std::numeric_limits<decltype(DescriptorSet)>::max(), "Descriptor set (", _DescriptorSet, ") exceeds representable max value", std::numeric_limits<decltype(DescriptorSet)>::max());
}
+ VkResource(ShaderResourceLayoutVk& _ParentLayout,
+ const VkResource& _SrcRes) :
+ Binding (_SrcRes.Binding),
+ DescriptorSet (_SrcRes.DescriptorSet),
+ CacheOffset (_SrcRes.CacheOffset),
+ SpirvAttribs (_SrcRes.SpirvAttribs),
+ ParentResLayout (_ParentLayout)
+ {
+ }
+
virtual IReferenceCounters* GetReferenceCounters()const override final
{
return ParentResLayout.GetOwner().GetReferenceCounters();
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp
index 8a747f94..6c73a9fd 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp
@@ -553,10 +553,10 @@ void PipelineLayout::Finalize(const VulkanUtilities::VulkanLogicalDevice& Logica
#endif
}
-#if 0
//http://diligentgraphics.com/diligent-engine/architecture/Vk/shader-resource-cache#Initializing-the-Cache-for-Shader-Resource-Binding-Object
void PipelineLayout::InitResourceCache(RenderDeviceVkImpl *pDeviceVkImpl, ShaderResourceCacheVk& ResourceCache, IMemoryAllocator &CacheMemAllocator)const
{
+#if 0
// Get root table size for every root index
// m_RootParams keeps root tables sorted by the array index, not the root index
// Root views are treated as one-descriptor tables
@@ -657,9 +657,11 @@ void PipelineLayout::InitResourceCache(RenderDeviceVkImpl *pDeviceVkImpl, Shader
VERIFY_EXPR(SrvCbvUavTblStartOffset == TotalSrvCbvUavDescriptors);
VERIFY_EXPR(SamplerTblStartOffset == TotalSamplerDescriptors);
- ResourceCache.SetDescriptorHeapSpace(std::move(CbcSrvUavHeapSpace), std::move(SamplerHeapSpace));
+ ResourceCache.SetDescriptorHeapSpace(std::move(CbcSrvUavHeapSpace), std::move(SamplerHeapSpace));'
+#endif
}
+#if 0
const Vk_RESOURCE_STATES Vk_RESOURCE_STATE_SHADER_RESOURCE = Vk_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | Vk_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
__forceinline
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
index c9b90adc..71db4fe1 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
@@ -155,8 +155,8 @@ void PipelineStateVkImpl::CreateRenderPass(const VulkanUtilities::VulkanLogicalD
PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl *pDeviceVk, const PipelineStateDesc &PipelineDesc) :
TPipelineStateBase(pRefCounters, pDeviceVk, PipelineDesc),
m_DummyVar(*this),
- m_ResourceCacheDataAllocator(GetRawAllocator(), PipelineDesc.SRBAllocationGranularity)/*,
- m_pDefaultShaderResBinding(nullptr, STDDeleter<ShaderResourceBindingVkImpl, FixedBlockMemoryAllocator>(pDeviceVk->GetSRBAllocator()) )*/
+ m_ResourceCacheDataAllocator(GetRawAllocator(), PipelineDesc.SRBAllocationGranularity),
+ m_pDefaultShaderResBinding(nullptr, STDDeleter<ShaderResourceBindingVkImpl, FixedBlockMemoryAllocator>(pDeviceVk->GetSRBAllocator()) )
{
const auto &LogicalDevice = pDeviceVk->GetLogicalDevice();
if (PipelineDesc.IsComputePipeline)
@@ -373,10 +373,9 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, Ren
m_ResLayoutDataAllocators.Init(m_NumShaders, PipelineDesc.SRBAllocationGranularity);
auto &SRBAllocator = pDeviceVk->GetSRBAllocator();
-#if 0
// Default shader resource binding must be initialized after resource layouts are parsed!
m_pDefaultShaderResBinding.reset( NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingVkImpl instance", ShaderResourceBindingVkImpl, this)(this, true) );
-
+#if 0
m_ShaderResourceLayoutHash = m_RootSig.GetHash();
#endif
}
@@ -428,12 +427,10 @@ void PipelineStateVkImpl::BindShaderResources(IResourceMapping *pResourceMapping
void PipelineStateVkImpl::CreateShaderResourceBinding(IShaderResourceBinding **ppShaderResourceBinding)
{
-#if 0
auto *pRenderDeviceVk = ValidatedCast<RenderDeviceVkImpl>( GetDevice() );
auto &SRBAllocator = pRenderDeviceVk->GetSRBAllocator();
auto pResBindingVk = NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingVkImpl instance", ShaderResourceBindingVkImpl)(this, false);
pResBindingVk->QueryInterface(IID_ShaderResourceBinding, reinterpret_cast<IObject**>(ppShaderResourceBinding));
-#endif
}
bool PipelineStateVkImpl::IsCompatibleWith(const IPipelineState *pPSO)const
@@ -486,14 +483,8 @@ bool PipelineStateVkImpl::IsCompatibleWith(const IPipelineState *pPSO)const
return true;
}
-#if 0
-const ShaderResourceLayoutVk& PipelineStateVkImpl::GetShaderResLayout(SHADER_TYPE ShaderType)const
-{
- auto ShaderInd = GetShaderTypeIndex(ShaderType);
- VERIFY_EXPR(m_pShaderResourceLayouts[ShaderInd] != nullptr);
- return *m_pShaderResourceLayouts[ShaderInd];
-}
+#if 0
ShaderResourceCacheVk* PipelineStateVkImpl::CommitAndTransitionShaderResources(IShaderResourceBinding *pShaderResourceBinding,
CommandContext &Ctx,
bool CommitResources,
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
index 54098c16..1db2b68f 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
@@ -31,15 +31,14 @@ namespace Diligent
{
ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl( IReferenceCounters *pRefCounters, PipelineStateVkImpl *pPSO, bool IsPSOInternal) :
- TBase( pRefCounters, pPSO, IsPSOInternal )/*,
- m_ShaderResourceCache(ShaderResourceCacheVk::DbgCacheContentType::SRBResources)*/
+ TBase( pRefCounters, pPSO, IsPSOInternal ),
+ m_ShaderResourceCache(ShaderResourceCacheVk::DbgCacheContentType::SRBResources)
{
-#if 0
auto *ppShaders = pPSO->GetShaders();
m_NumShaders = pPSO->GetNumShaders();
auto *pRenderDeviceVkImpl = ValidatedCast<RenderDeviceVkImpl>(pPSO->GetDevice());
- pPSO->GetRootSignature().InitResourceCache(pRenderDeviceVkImpl, m_ShaderResourceCache, pPSO->GetResourceCacheDataAllocator());
+ pPSO->GetPipelineLayout().InitResourceCache(pRenderDeviceVkImpl, m_ShaderResourceCache, pPSO->GetResourceCacheDataAllocator());
auto *pResLayoutRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutVk", m_NumShaders * sizeof(ShaderResourceLayoutVk));
m_pResourceLayouts = reinterpret_cast<ShaderResourceLayoutVk*>(pResLayoutRawMem);
@@ -59,24 +58,20 @@ ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl( IReferenceCounters *pR
m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s);
}
-#endif
}
ShaderResourceBindingVkImpl::~ShaderResourceBindingVkImpl()
{
-#if 0
for(Uint32 l = 0; l < m_NumShaders; ++l)
m_pResourceLayouts[l].~ShaderResourceLayoutVk();
GetRawAllocator().Free(m_pResourceLayouts);
-#endif
}
IMPLEMENT_QUERY_INTERFACE( ShaderResourceBindingVkImpl, IID_ShaderResourceBindingVk, TBase )
void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMapping *pResMapping, Uint32 Flags)
{
-#if 0
for (auto ShaderInd = 0; ShaderInd <= CSInd; ++ShaderInd )
{
if (ShaderFlags & GetShaderTypeFromIndex(ShaderInd))
@@ -88,12 +83,10 @@ void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMap
}
}
}
-#endif
}
IShaderVariable *ShaderResourceBindingVkImpl::GetVariable(SHADER_TYPE ShaderType, const char *Name)
{
-#if 0
auto ShaderInd = GetShaderTypeIndex(ShaderType);
auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
if (ResLayoutInd < 0)
@@ -106,11 +99,8 @@ IShaderVariable *ShaderResourceBindingVkImpl::GetVariable(SHADER_TYPE ShaderType
pVar = ValidatedCast<PipelineStateVkImpl>(GetPipelineState())->GetDummyShaderVar();
return pVar;
-#endif
- return nullptr;
}
-#if 0
#ifdef VERIFY_SHADER_BINDINGS
void ShaderResourceBindingVkImpl::dbgVerifyResourceBindings(const PipelineStateVkImpl *pPSO)
{
@@ -124,9 +114,7 @@ void ShaderResourceBindingVkImpl::dbgVerifyResourceBindings(const PipelineStateV
m_pResourceLayouts[l].dbgVerifyBindings();
}
#endif
-#endif
-#if 0
void ShaderResourceBindingVkImpl::InitializeStaticResources(const PipelineStateVkImpl *pPSO)
{
VERIFY(!StaticResourcesInitialized(), "Static resources have already been initialized");
@@ -142,11 +130,10 @@ void ShaderResourceBindingVkImpl::InitializeStaticResources(const PipelineStateV
pShader->DbgVerifyStaticResourceBindings();
#endif
auto &ConstResLayout = pShader->GetConstResLayout();
- GetResourceLayout(pShader->GetDesc().ShaderType).CopyStaticResourceDesriptorHandles(ConstResLayout);
+ GetResourceLayout(pShader->GetDesc().ShaderType).InitializeStaticResources(ConstResLayout);
}
m_bStaticResourcesInitialized = true;
}
-#endif
}
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
index 8f18d55f..40be5a25 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp
@@ -66,79 +66,52 @@ void ShaderResourceLayoutVk::AllocateMemory(IMemoryAllocator &Allocator)
m_ResourceBuffer.reset(pRawMem);
}
-#if 0
// Clones layout from the reference layout maintained by the pipeline state
-// Root indices and descriptor table offsets must be correct
+// Descriptor sets and bindings must be correct
// Resource cache is not initialized.
ShaderResourceLayoutVk::ShaderResourceLayoutVk(IObject &Owner,
- const ShaderResourceLayoutVk& SrcLayout,
- IMemoryAllocator &ResourceLayoutDataAllocator,
- const SHADER_VARIABLE_TYPE *AllowedVarTypes,
- Uint32 NumAllowedTypes,
- ShaderResourceCacheVk &ResourceCache) :
+ const ShaderResourceLayoutVk& SrcLayout,
+ IMemoryAllocator &ResourceLayoutDataAllocator,
+ const SHADER_VARIABLE_TYPE *AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ ShaderResourceCacheVk &ResourceCache) :
ShaderResourceLayoutVk(Owner, ResourceLayoutDataAllocator)
{
- m_pVkDevice = SrcLayout.m_pVkDevice;
+ m_pLogicalDevice = SrcLayout.m_pLogicalDevice;
m_pResources = SrcLayout.m_pResources;
m_pResourceCache = &ResourceCache;
Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
-
for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1))
{
- if( !IsAllowedType(VarType, AllowedTypeBits))
- continue;
-
- m_NumCbvSrvUav[VarType] = SrcLayout.m_NumCbvSrvUav[VarType];
- m_NumSamplers[VarType] = SrcLayout.m_NumSamplers[VarType];
+ m_NumResources[VarType] = IsAllowedType(VarType, AllowedTypeBits) ? SrcLayout.m_NumResources[VarType] : 0;
}
AllocateMemory(ResourceLayoutDataAllocator);
- Uint32 CurrCbvSrvUav[SHADER_VARIABLE_TYPE_NUM_TYPES] = {0,0,0};
- Uint32 CurrSampler[SHADER_VARIABLE_TYPE_NUM_TYPES] = {0,0,0};
-
+ Uint32 CurrResInd[SHADER_VARIABLE_TYPE_NUM_TYPES] = {};
for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1))
{
if( !IsAllowedType(VarType, AllowedTypeBits))
continue;
- Uint32 NumSrcCbvSrvUav = SrcLayout.m_NumCbvSrvUav[VarType];
- VERIFY_EXPR(NumSrcCbvSrvUav == m_NumCbvSrvUav[VarType]);
- for( Uint32 r=0; r < NumSrcCbvSrvUav; ++r )
+ Uint32 NumResources = SrcLayout.m_NumResources[VarType];
+ VERIFY_EXPR(NumResources == m_NumResources[VarType]);
+ for( Uint32 r=0; r < NumResources; ++r )
{
- const auto &SrcRes = SrcLayout.GetSrvCbvUav(VarType, r);
- Uint32 SamplerId = SRV_CBV_UAV::InvalidSamplerId;
- if (SrcRes.IsValidSampler())
- {
- const auto &SrcSamplerAttribs = SrcLayout.GetSampler(VarType, SrcRes.GetSamplerId());
- VERIFY(!SrcSamplerAttribs.Attribs.IsStaticSampler(), "Only non-static samplers can be assigned space in shader cache");
- VERIFY(SrcSamplerAttribs.Attribs.GetVariableType() == SrcRes.Attribs.GetVariableType(), "Inconsistent texture and sampler variable types" );
- VERIFY(SrcSamplerAttribs.IsValidRootIndex(), "Root index must be valid");
- VERIFY(SrcSamplerAttribs.IsValidOffset(), "Offset must be valid");
- VERIFY_EXPR(SrcSamplerAttribs.Attribs.BindCount == SrcRes.Attribs.BindCount || SrcSamplerAttribs.Attribs.BindCount == 1);
-
- SamplerId = CurrSampler[VarType];
- VERIFY(SamplerId <= SRV_CBV_UAV::MaxSamplerId, "SamplerId exceeds maximum allowed value (", SRV_CBV_UAV::MaxSamplerId, ")");
- VERIFY_EXPR(SamplerId == SrcRes.GetSamplerId());
- ::new (&GetSampler(VarType, CurrSampler[VarType]++)) Sampler( *this, SrcSamplerAttribs );
- }
-
- VERIFY(SrcRes.IsValidRootIndex(), "Root index must be valid");
- VERIFY(SrcRes.IsValidOffset(), "Offset must be valid");
- ::new (&GetSrvCbvUav(VarType, CurrCbvSrvUav[VarType]++)) SRV_CBV_UAV( *this, SrcRes, SamplerId );
+ const auto &SrcRes = SrcLayout.GetResource(VarType, r);
+ ::new (&GetResource(VarType, CurrResInd[VarType]++)) VkResource( *this, SrcRes );
}
}
#ifdef _DEBUG
for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1))
{
- VERIFY_EXPR( CurrCbvSrvUav[VarType] == m_NumCbvSrvUav[VarType] );
- VERIFY_EXPR( CurrSampler[VarType] == m_NumSamplers[VarType] );
+ VERIFY_EXPR(CurrResInd[VarType] == m_NumResources[VarType] );
}
#endif
}
-#endif
+
void ShaderResourceLayoutVk::Initialize(const VulkanUtilities::VulkanLogicalDevice& LogicalDevice,
const std::shared_ptr<const SPIRVShaderResources>& pSrcResources,
@@ -208,11 +181,11 @@ void ShaderResourceLayoutVk::Initialize(const VulkanUtilities::VulkanLogicalDevi
{
Uint32 Binding = 0;
Uint32 DescriptorSet = 0;
- Uint32 OffsetFromSetStart = 0;
+ Uint32 CacheOffset = 0;
if (pPipelineLayout)
{
VERIFY_EXPR(pSPIRV != nullptr);
- pPipelineLayout->AllocateResourceSlot(Attribs, m_pResources->GetShaderType(), DescriptorSet, Binding, OffsetFromSetStart, *pSPIRV);
+ pPipelineLayout->AllocateResourceSlot(Attribs, m_pResources->GetShaderType(), DescriptorSet, Binding, CacheOffset, *pSPIRV);
VERIFY(DescriptorSet <= std::numeric_limits<decltype(VkResource::DescriptorSet)>::max(), "Descriptor set (", DescriptorSet, ") excceeds representable max value");
VERIFY(Binding <= std::numeric_limits<decltype(VkResource::Binding)>::max(), "Binding (", Binding, ") excceeds representable max value");
}
@@ -230,13 +203,13 @@ void ShaderResourceLayoutVk::Initialize(const VulkanUtilities::VulkanLogicalDevi
VERIFY_EXPR(m_pResourceCache != nullptr);
DescriptorSet = Attribs.Type;
- OffsetFromSetStart = StaticResCacheSetSizes[DescriptorSet];
+ CacheOffset = StaticResCacheSetSizes[DescriptorSet];
Binding = CurrResInd[Attribs.VarType];
StaticResCacheSetSizes[DescriptorSet] += Attribs.ArraySize;
}
// Static samplers are never copied, and SamplerId == InvalidSamplerId
- ::new (&GetResource(Attribs.VarType, CurrResInd[Attribs.VarType]++)) VkResource( *this, Attribs, Binding, DescriptorSet, OffsetFromSetStart);
+ ::new (&GetResource(Attribs.VarType, CurrResInd[Attribs.VarType]++)) VkResource( *this, Attribs, Binding, DescriptorSet, CacheOffset);
};
m_pResources->ProcessResources(
@@ -547,7 +520,7 @@ void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject *pObj, Uint3
SpirvAttribs.VarType != SHADER_VARIABLE_TYPE_DYNAMIC && vkDescrSet != VK_NULL_HANDLE,
"Static and mutable variables and only them are expected to have valid descriptor set assigned");
}
- auto &DstRes = DstDescrSet.GetResource(OffsetFromSetStart + ArrayIndex);
+ auto &DstRes = DstDescrSet.GetResource(CacheOffset + ArrayIndex);
if( pObj )
{
@@ -594,9 +567,9 @@ bool ShaderResourceLayoutVk::VkResource::IsBound(Uint32 ArrayIndex)
if( DescriptorSet < pResourceCache->GetNumDescriptorSets() )
{
auto &Set = pResourceCache->GetDescriptorSet(DescriptorSet);
- if(OffsetFromSetStart + ArrayIndex < Set.GetSize())
+ if(CacheOffset + ArrayIndex < Set.GetSize())
{
- auto &CachedRes = Set.GetResource(OffsetFromSetStart + ArrayIndex);
+ auto &CachedRes = Set.GetResource(CacheOffset + ArrayIndex);
return CachedRes.pObject != nullptr;
}
}
@@ -711,12 +684,12 @@ void ShaderResourceLayoutVk::InitializeStaticResources(const ShaderResourceLayou
for(Uint32 ArrInd = 0; ArrInd < DstRes.SpirvAttribs.ArraySize; ++ArrInd)
{
- auto SrcOffset = SrcRes.OffsetFromSetStart + ArrInd;
+ auto SrcOffset = SrcRes.CacheOffset + ArrInd;
IDeviceObject *pObject = SrcLayout.m_pResourceCache->GetDescriptorSet(SrcRes.DescriptorSet).GetResource(SrcOffset).pObject;
if (!pObject)
LOG_ERROR_MESSAGE("No resource assigned to static shader variable \"", SrcRes.SpirvAttribs.GetPrintName(ArrInd), "\" in shader \"", GetShaderName(), "\".");
- auto DstOffset = DstRes.OffsetFromSetStart + ArrInd;
+ auto DstOffset = DstRes.CacheOffset + ArrInd;
IDeviceObject *pCachedResource = m_pResourceCache->GetDescriptorSet(DstRes.DescriptorSet).GetResource(DstOffset).pObject;
if(pCachedResource != pObject)
{
@@ -742,7 +715,7 @@ void ShaderResourceLayoutVk::dbgVerifyBindings()const
for(Uint32 ArrInd = 0; ArrInd < Res.SpirvAttribs.ArraySize; ++ArrInd)
{
auto &CachedDescrSet = m_pResourceCache->GetDescriptorSet(Res.DescriptorSet);
- const auto &CachedRes = CachedDescrSet.GetResource(Res.OffsetFromSetStart + ArrInd);
+ const auto &CachedRes = CachedDescrSet.GetResource(Res.CacheOffset + ArrInd);
if(CachedRes.pObject == nullptr)
{
LOG_ERROR_MESSAGE("No resource is bound to ", GetShaderVariableTypeLiteralName(Res.SpirvAttribs.VarType), " variable \"", Res.SpirvAttribs.GetPrintName(ArrInd), "\" in shader \"", GetShaderName(), "\"");