summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-09-18 05:00:26 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-09-18 05:00:26 +0000
commitce496ba73a61fe88db3d5c233dd920c2689d9e9b (patch)
tree107347e11c1a5a26199d1f8eb59bcec99763e703 /Graphics/GraphicsEngineVulkan
parentMerge branch 'mesh_shader_fix' of https://github.com/azhirnov/DiligentCore in... (diff)
downloadDiligentCore-ce496ba73a61fe88db3d5c233dd920c2689d9e9b.tar.gz
DiligentCore-ce496ba73a61fe88db3d5c233dd920c2689d9e9b.zip
Refactored internal shader resouce variable indexing
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp7
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp7
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp8
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp44
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp2
5 files changed, 25 insertions, 43 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp
index 5f00317e..43ae0456 100644
--- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp
@@ -155,9 +155,10 @@ private:
VulkanUtilities::PipelineWrapper m_Pipeline;
PipelineLayout m_PipelineLayout;
- std::array<Int8, 8> m_ResourceLayoutIndex = {};
- bool m_HasStaticResources = false;
- bool m_HasNonStaticResources = false;
+ std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_ResourceLayoutIndex = {};
+
+ bool m_HasStaticResources = false;
+ bool m_HasNonStaticResources = false;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
index d93a72ac..b3cbe742 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp
@@ -78,9 +78,10 @@ private:
ShaderVariableManagerVk* m_pShaderVarMgrs = nullptr;
// Shader variable manager index in m_pShaderVarMgrs[] array for every shader stage
- std::array<Int8, NUM_SHADER_TYPES> m_ResourceLayoutIndex;
- bool m_bStaticResourcesInitialized = false;
- Uint8 m_NumShaders = 0;
+ std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_ResourceLayoutIndex;
+
+ bool m_bStaticResourcesInitialized = false;
+ Uint8 m_NumShaders = 0;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
index c5b70426..0f824d41 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
@@ -177,7 +177,7 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun
ShaderSPIRVs[s] = pShaderVk->GetSPIRV();
const auto ShaderType = pShaderVk->GetDesc().ShaderType;
- const auto ShaderTypeInd = GetShaderTypeIndex(ShaderType);
+ const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_Desc.PipelineType);
m_ResourceLayoutIndex[ShaderTypeInd] = static_cast<Int8>(s);
auto* pStaticResLayout = new (m_ShaderResourceLayouts + m_NumShaders + s) ShaderResourceLayoutVk(LogicalDevice);
@@ -679,7 +679,7 @@ void PipelineStateVkImpl::BindStaticResources(Uint32 ShaderFlags, IResourceMappi
Uint32 PipelineStateVkImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const
{
- const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
+ const auto LayoutInd = GetStaticVariableCountHelper(ShaderType, m_ResourceLayoutIndex);
if (LayoutInd < 0)
return 0;
@@ -689,7 +689,7 @@ Uint32 PipelineStateVkImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const
IShaderResourceVariable* PipelineStateVkImpl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name)
{
- const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
+ const auto LayoutInd = GetStaticVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex);
if (LayoutInd < 0)
return nullptr;
@@ -699,7 +699,7 @@ IShaderResourceVariable* PipelineStateVkImpl::GetStaticVariableByName(SHADER_TYP
IShaderResourceVariable* PipelineStateVkImpl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
{
- const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
+ const auto LayoutInd = GetStaticVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex);
if (LayoutInd < 0)
return nullptr;
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
index b978c592..efbdc006 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
@@ -64,7 +64,7 @@ ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl(IReferenceCounters* pR
{
auto* pShader = ppShaders[s];
auto ShaderType = pShader->GetDesc().ShaderType;
- auto ShaderInd = GetShaderTypeIndex(ShaderType);
+ auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPSO->GetDesc().PipelineType);
m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s);
@@ -102,12 +102,13 @@ IMPLEMENT_QUERY_INTERFACE(ShaderResourceBindingVkImpl, IID_ShaderResourceBinding
void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)
{
- for (auto ShaderInd = 0; ShaderInd <= CSInd; ++ShaderInd)
+ const auto PipelineType = m_pPSO->GetDesc().PipelineType;
+ for (Int32 ShaderInd = 0; ShaderInd < static_cast<Int32>(m_ResourceLayoutIndex.size()); ++ShaderInd)
{
- if (ShaderFlags & GetShaderTypeFromIndex(ShaderInd))
+ auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
+ if (ResLayoutInd >= 0)
{
- auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
- if (ResLayoutInd >= 0)
+ if (ShaderFlags & GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType))
{
m_pShaderVarMgrs[ResLayoutInd].BindResources(pResMapping, Flags);
}
@@ -117,41 +118,20 @@ void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMap
IShaderResourceVariable* ShaderResourceBindingVkImpl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name)
{
- auto ShaderInd = GetShaderTypeIndex(ShaderType);
- auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
- if (ResLayoutInd < 0)
- {
- LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", GetShaderTypeLiteralName(ShaderType),
- " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'.");
- return nullptr;
- }
- return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name);
+ auto ResLayoutInd = GetVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex);
+ return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name) : nullptr;
}
Uint32 ShaderResourceBindingVkImpl::GetVariableCount(SHADER_TYPE ShaderType) const
{
- auto ShaderInd = GetShaderTypeIndex(ShaderType);
- auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
- if (ResLayoutInd < 0)
- {
- LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", GetShaderTypeLiteralName(ShaderType),
- " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'.");
- return 0;
- }
- return m_pShaderVarMgrs[ResLayoutInd].GetVariableCount();
+ auto ResLayoutInd = GetVariableCountHelper(ShaderType, m_ResourceLayoutIndex);
+ return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariableCount() : 0;
}
IShaderResourceVariable* ShaderResourceBindingVkImpl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
{
- auto ShaderInd = GetShaderTypeIndex(ShaderType);
- auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
- if (ResLayoutInd < 0)
- {
- LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", GetShaderTypeLiteralName(ShaderType),
- " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'.");
- return nullptr;
- }
- return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Index);
+ auto ResLayoutInd = GetVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex);
+ return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariable(Index) : 0;
}
void ShaderResourceBindingVkImpl::InitializeStaticResources(const IPipelineState* pPipelineState)
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
index 5e27beb2..718cc39a 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
@@ -115,7 +115,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters,
if (m_SPIRV.empty())
{
- LOG_ERROR_AND_THROW("Failed to compile shader \"", CreationAttribs.Desc.Name, "\"");
+ LOG_ERROR_AND_THROW("Failed to compile shader '", CreationAttribs.Desc.Name, '\'');
}
}
else if (CreationAttribs.ByteCode != nullptr)