summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
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/GraphicsEngineD3D12
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/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/RootSignature.hpp5
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp8
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp1
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp30
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RootSignature.cpp9
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp47
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp3
8 files changed, 43 insertions, 62 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp
index b4d2fce9..c248a7b1 100644
--- a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp
@@ -129,7 +129,7 @@ private:
ShaderResourceCacheD3D12* m_pStaticResourceCaches = nullptr;
ShaderVariableManagerD3D12* m_pStaticVarManagers = nullptr;
// Resource layout index in m_ResourceLayouts[] array for every shader stage
- std::array<Int8, NUM_SHADER_TYPES> m_ResourceLayoutIndex;
+ std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_ResourceLayoutIndex;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/include/RootSignature.hpp b/Graphics/GraphicsEngineD3D12/include/RootSignature.hpp
index c62c8198..9a70e486 100644
--- a/Graphics/GraphicsEngineD3D12/include/RootSignature.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/RootSignature.hpp
@@ -318,6 +318,7 @@ public:
const D3DShaderResourceAttribs& ShaderResAttribs);
void AllocateResourceSlot(SHADER_TYPE ShaderType,
+ PIPELINE_TYPE PipelineType,
const D3DShaderResourceAttribs& ShaderResAttribs,
SHADER_RESOURCE_VARIABLE_TYPE VariableType,
D3D12_DESCRIPTOR_RANGE_TYPE RangeType,
@@ -474,9 +475,9 @@ private:
// in m_RootParams (NOT the Root Index!), for every variable type
// (static, mutable, dynamic) and every shader type,
// or -1, if the table is not yet assigned to the combination
- std::array<Uint8, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES * NUM_SHADER_TYPES> m_SrvCbvUavRootTablesMap;
+ std::array<Uint8, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES * MAX_SHADERS_IN_PIPELINE> m_SrvCbvUavRootTablesMap;
// This array contains the same data for Sampler root table
- std::array<Uint8, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES * NUM_SHADER_TYPES> m_SamplerRootTablesMap;
+ std::array<Uint8, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES * MAX_SHADERS_IN_PIPELINE> m_SamplerRootTablesMap;
RootParamsManager m_RootParams;
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
index 7c83ddbf..6906796f 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
@@ -33,7 +33,6 @@
#include "ShaderResourceBindingD3D12.h"
#include "RenderDeviceD3D12.h"
#include "ShaderResourceBindingBase.hpp"
-#include "ShaderBase.hpp"
#include "ShaderResourceCacheD3D12.hpp"
#include "ShaderResourceLayoutD3D12.hpp"
#include "ShaderVariableD3D12.hpp"
@@ -80,9 +79,10 @@ private:
ShaderResourceCacheD3D12 m_ShaderResourceCache;
ShaderVariableManagerD3D12* m_pShaderVarMgrs = nullptr;
// Resource layout index in m_ResourceLayouts[] array for every shader stage
- std::array<Int8, NUM_SHADER_TYPES> m_ResourceLayoutIndex;
- bool m_bStaticResourcesInitialized = false;
- const Uint8 m_NumShaders = 0;
+ std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_ResourceLayoutIndex;
+
+ bool m_bStaticResourcesInitialized = false;
+ const Uint8 m_NumShaders = 0;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp
index 19c8afb7..e043cf4a 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp
@@ -119,6 +119,7 @@ public:
// no shader resource cache is provided
ShaderResourceLayoutD3D12(IObject& Owner,
ID3D12Device* pd3d12Device,
+ PIPELINE_TYPE PipelineType,
const PipelineResourceLayoutDesc& ResourceLayout,
std::shared_ptr<const ShaderResourcesD3D12> pSrcResources,
IMemoryAllocator& LayoutDataAllocator,
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
index ecb18672..bc23c7da 100644
--- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
@@ -104,6 +104,8 @@ PipelineStateD3D12Impl::PipelineStateD3D12Impl(IReferenceCounters* pR
TPipelineStateBase{pRefCounters, pDeviceD3D12, CreateInfo.PSODesc},
m_SRBMemAllocator{GetRawAllocator()}
{
+ m_ResourceLayoutIndex.fill(-1);
+
auto pd3d12Device = pDeviceD3D12->GetD3D12Device();
const auto& ResourceLayout = m_Desc.ResourceLayout;
m_RootSig.AllocateStaticSamplers(ResourceLayout);
@@ -141,7 +143,7 @@ PipelineStateD3D12Impl::PipelineStateD3D12Impl(IReferenceCounters* pR
{
auto* pShaderD3D12 = GetShader<ShaderD3D12Impl>(s);
auto ShaderType = pShaderD3D12->GetDesc().ShaderType;
- auto ShaderInd = GetShaderTypeIndex(ShaderType);
+ auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, m_Desc.PipelineType);
m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s);
@@ -150,6 +152,7 @@ PipelineStateD3D12Impl::PipelineStateD3D12Impl(IReferenceCounters* pR
{
*this,
pDeviceD3D12->GetD3D12Device(),
+ m_Desc.PipelineType,
ResourceLayout,
pShaderD3D12->GetShaderResources(),
GetRawAllocator(),
@@ -167,6 +170,7 @@ PipelineStateD3D12Impl::PipelineStateD3D12Impl(IReferenceCounters* pR
{
*this,
pDeviceD3D12->GetD3D12Device(),
+ m_Desc.PipelineType,
ResourceLayout,
pShaderD3D12->GetShaderResources(),
GetRawAllocator(),
@@ -613,29 +617,23 @@ void PipelineStateD3D12Impl::BindStaticResources(Uint32 ShaderFlags, IResourceMa
Uint32 PipelineStateD3D12Impl::GetStaticVariableCount(SHADER_TYPE ShaderType) const
{
- const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
- if (LayoutInd < 0)
- return 0;
-
- return m_pStaticVarManagers[LayoutInd].GetVariableCount();
+ const auto LayoutInd = GetStaticVariableCountHelper(ShaderType, m_ResourceLayoutIndex);
+ VERIFY_EXPR(LayoutInd < 0 || static_cast<Uint32>(LayoutInd) <= m_NumShaders);
+ return LayoutInd >= 0 ? m_pStaticVarManagers[LayoutInd].GetVariableCount() : 0;
}
IShaderResourceVariable* PipelineStateD3D12Impl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name)
{
- const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
- if (LayoutInd < 0)
- return nullptr;
-
- return m_pStaticVarManagers[LayoutInd].GetVariable(Name);
+ const auto LayoutInd = GetStaticVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex);
+ VERIFY_EXPR(LayoutInd < 0 || static_cast<Uint32>(LayoutInd) <= m_NumShaders);
+ return LayoutInd >= 0 ? m_pStaticVarManagers[LayoutInd].GetVariable(Name) : nullptr;
}
IShaderResourceVariable* PipelineStateD3D12Impl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
{
- const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
- if (LayoutInd < 0)
- return nullptr;
-
- return m_pStaticVarManagers[LayoutInd].GetVariable(Index);
+ const auto LayoutInd = GetStaticVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex);
+ VERIFY_EXPR(LayoutInd < 0 || static_cast<Uint32>(LayoutInd) <= m_NumShaders);
+ return LayoutInd >= 0 ? m_pStaticVarManagers[LayoutInd].GetVariable(Index) : nullptr;
}
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
index 6ec0497f..43fc21ac 100644
--- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
@@ -312,6 +312,7 @@ void RootSignature::InitStaticSampler(SHADER_TYPE ShaderType
// http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Shader-Resource-Layouts-and-Root-Signature-in-a-Pipeline-State-Object
void RootSignature::AllocateResourceSlot(SHADER_TYPE ShaderType,
+ PIPELINE_TYPE PipelineType,
const D3DShaderResourceAttribs& ShaderResAttribs,
SHADER_RESOURCE_VARIABLE_TYPE VariableType,
D3D12_DESCRIPTOR_RANGE_TYPE RangeType,
@@ -319,8 +320,7 @@ void RootSignature::AllocateResourceSlot(SHADER_TYPE ShaderT
Uint32& OffsetFromTableStart // Output parameter
)
{
- auto ShaderInd = GetShaderTypeIndex(ShaderType);
- auto ShaderVisibility = GetShaderVisibility(ShaderType);
+ const auto ShaderVisibility = GetShaderVisibility(ShaderType);
if (RangeType == D3D12_DESCRIPTOR_RANGE_TYPE_CBV && ShaderResAttribs.BindCount == 1)
{
// Allocate single CBV directly in the root signature
@@ -334,9 +334,10 @@ void RootSignature::AllocateResourceSlot(SHADER_TYPE ShaderT
}
else
{
+ const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
// Use the same table for static and mutable resources. Treat both as static
- auto RootTableType = (VariableType == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) ? SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC : SHADER_RESOURCE_VARIABLE_TYPE_STATIC;
- auto TableIndKey = ShaderInd * SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + RootTableType;
+ const auto RootTableType = (VariableType == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) ? SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC : SHADER_RESOURCE_VARIABLE_TYPE_STATIC;
+ const auto TableIndKey = ShaderInd * SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + RootTableType;
// Get the table array index (this is not the root index!)
auto& RootTableArrayInd = ((RangeType == D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER) ? m_SamplerRootTablesMap : m_SrvCbvUavRootTablesMap)[TableIndKey];
if (RootTableArrayInd == InvalidRootTableIndex)
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
index 94d65cda..9f71e9c0 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
@@ -61,7 +61,7 @@ ShaderResourceBindingD3D12Impl::ShaderResourceBindingD3D12Impl(IReferenceCounter
{
auto* pShader = ppShaders[s];
auto ShaderType = pShader->GetDesc().ShaderType;
- auto ShaderInd = GetShaderTypeIndex(ShaderType);
+ auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPSO->GetDesc().PipelineType);
auto& VarDataAllocator = pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s);
@@ -101,13 +101,15 @@ IMPLEMENT_QUERY_INTERFACE(ShaderResourceBindingD3D12Impl, IID_ShaderResourceBind
void ShaderResourceBindingD3D12Impl::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);
}
}
@@ -116,43 +118,20 @@ void ShaderResourceBindingD3D12Impl::BindResources(Uint32 ShaderFlags, IResource
IShaderResourceVariable* ShaderResourceBindingD3D12Impl::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 ShaderResourceBindingD3D12Impl::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* ShaderResourceBindingD3D12Impl::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;
}
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp
index 66f6c1d7..6c313882 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp
@@ -114,6 +114,7 @@ void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator&
// http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-cache#Initializing-Shader-Resource-Layouts-in-a-Pipeline-State
ShaderResourceLayoutD3D12::ShaderResourceLayoutD3D12(IObject& Owner,
ID3D12Device* pd3d12Device,
+ PIPELINE_TYPE PipelineType,
const PipelineResourceLayoutDesc& ResourceLayout,
std::shared_ptr<const ShaderResourcesD3D12> pSrcResources,
IMemoryAllocator& LayoutDataAllocator,
@@ -211,7 +212,7 @@ ShaderResourceLayoutD3D12::ShaderResourceLayoutD3D12(IObject&
if (pRootSig)
{
- pRootSig->AllocateResourceSlot(m_pResources->GetShaderType(), Attribs, VarType, DescriptorRangeType, RootIndex, Offset);
+ pRootSig->AllocateResourceSlot(m_pResources->GetShaderType(), PipelineType, Attribs, VarType, DescriptorRangeType, RootIndex, Offset);
VERIFY(RootIndex <= D3D12Resource::MaxRootIndex, "Root index excceeds allowed limit");
}
else