summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-02-24 03:39:00 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:10 +0000
commit8813773d1df679d1a747a91e6be7afcdaa5b42c7 (patch)
tree9371c6756d6265dcce359535447eb8a4c8a148d9 /Graphics/GraphicsEngineD3D12
parentImproved paramter packing for CommitRootTables and CommitRootViews methods of... (diff)
downloadDiligentCore-8813773d1df679d1a747a91e6be7afcdaa5b42c7.tar.gz
DiligentCore-8813773d1df679d1a747a91e6be7afcdaa5b42c7.zip
Reworked ShaderResourceBindingVkImpl and ShaderResourceBindingD3D12Impl: moved common functionality to ShaderResourceBindingBase
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp15
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp86
4 files changed, 20 insertions, 85 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp
index a5740af3..9a4b8f9d 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp
@@ -73,7 +73,7 @@ public:
ResourceDesc = m_pShaderResources->GetHLSLShaderResourceDesc(Index);
}
- ID3DBlob* GetShaderByteCode() { return m_pShaderByteCode; }
+ ID3DBlob* GetShaderByteCode() const { return m_pShaderByteCode; }
const Char* GetEntryPoint() const { return m_EntryPoint.c_str(); }
const std::shared_ptr<const ShaderResourcesD3D12>& GetShaderResources() const { return m_pShaderResources; }
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
index 69d97431..9a570c54 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp
@@ -41,15 +41,14 @@ namespace Diligent
{
/// Implementation of the Diligent::IShaderResourceBindingD3D12 interface
-// sizeof(ShaderResourceBindingD3D12Impl) == 152 (x64, msvc, Release)
+// sizeof(ShaderResourceBindingD3D12Impl) == 104 (x64, msvc, Release)
class ShaderResourceBindingD3D12Impl final : public ShaderResourceBindingBase<IShaderResourceBindingD3D12, PipelineResourceSignatureD3D12Impl>
{
public:
using TBase = ShaderResourceBindingBase<IShaderResourceBindingD3D12, PipelineResourceSignatureD3D12Impl>;
ShaderResourceBindingD3D12Impl(IReferenceCounters* pRefCounters,
- PipelineResourceSignatureD3D12Impl* pPRS,
- bool IsDeviceInternal);
+ PipelineResourceSignatureD3D12Impl* pPRS);
~ShaderResourceBindingD3D12Impl();
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_ShaderResourceBindingD3D12, TBase)
@@ -62,17 +61,10 @@ public:
virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final;
- virtual void DILIGENT_CALL_TYPE InitializeStaticResources(const IPipelineState* pPipelineState) override final;
-
virtual void DILIGENT_CALL_TYPE InitializeStaticResourcesWithSignature(const IPipelineResourceSignature* pResourceSignature) override final;
ShaderResourceCacheD3D12& GetResourceCache() { return m_ShaderResourceCache; }
- bool StaticResourcesInitialized() const
- {
- return m_bStaticResourcesInitialized;
- }
-
private:
void Destruct();
@@ -83,9 +75,6 @@ private:
// indexed by the shader type pipeline index (returned by GetShaderTypePipelineIndex)
std::array<Int8, MAX_SHADERS_IN_PIPELINE> m_ShaderVarIndex = {-1, -1, -1, -1, -1, -1};
static_assert(MAX_SHADERS_IN_PIPELINE == 6, "Please update the initializer list above");
-
- bool m_bStaticResourcesInitialized = false;
- const Uint8 m_NumShaders = 0;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
index a60f193a..3438b4b3 100644
--- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
@@ -391,7 +391,7 @@ void PipelineResourceSignatureD3D12Impl::CreateShaderResourceBinding(IShaderReso
bool InitStaticResources)
{
auto& SRBAllocator = m_pDevice->GetSRBAllocator();
- auto* pResBindingD3D12 = NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingD3D12Impl instance", ShaderResourceBindingD3D12Impl)(this, false);
+ auto* pResBindingD3D12 = NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingD3D12Impl instance", ShaderResourceBindingD3D12Impl)(this);
if (InitStaticResources)
pResBindingD3D12->InitializeStaticResources(nullptr);
pResBindingD3D12->QueryInterface(IID_ShaderResourceBinding, reinterpret_cast<IObject**>(ppShaderResourceBinding));
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
index ff976294..e13e6175 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
@@ -34,28 +34,27 @@ namespace Diligent
{
ShaderResourceBindingD3D12Impl::ShaderResourceBindingD3D12Impl(IReferenceCounters* pRefCounters,
- PipelineResourceSignatureD3D12Impl* pPRS,
- bool IsDeviceInternal) :
+ PipelineResourceSignatureD3D12Impl* pPRS) :
// clang-format off
TBase
{
pRefCounters,
- pPRS,
- IsDeviceInternal
+ pPRS
},
- m_ShaderResourceCache{ShaderResourceCacheD3D12::CacheContentType::SRB},
- m_NumShaders {static_cast<decltype(m_NumShaders)>(pPRS->GetNumActiveShaderStages())}
+ m_ShaderResourceCache{ShaderResourceCacheD3D12::CacheContentType::SRB}
// clang-format on
{
try
{
m_ShaderVarIndex.fill(-1);
+ const auto NumShaders = GetNumShaders();
+
FixedLinearAllocator MemPool{GetRawAllocator()};
- MemPool.AddSpace<ShaderVariableManagerD3D12>(m_NumShaders);
+ MemPool.AddSpace<ShaderVariableManagerD3D12>(NumShaders);
MemPool.Reserve();
// Constructor of ShaderVariableManagerD3D12 is noexcept, so we can safely construct all managers.
- m_pShaderVarMgrs = MemPool.ConstructArray<ShaderVariableManagerD3D12>(m_NumShaders, std::ref(*this), std::ref(m_ShaderResourceCache));
+ m_pShaderVarMgrs = MemPool.ConstructArray<ShaderVariableManagerD3D12>(NumShaders, std::ref(*this), std::ref(m_ShaderResourceCache));
// The memory is now owned by ShaderResourceBindingD3D12Impl and will be freed by Destruct().
auto* Ptr = MemPool.ReleaseOwnership();
@@ -69,24 +68,24 @@ ShaderResourceBindingD3D12Impl::ShaderResourceBindingD3D12Impl(IReferenceCounter
auto& ResourceCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(0);
pPRS->InitSRBResourceCache(m_ShaderResourceCache, ResourceCacheDataAllocator, pPRS->GetDesc().Name);
- for (Uint32 s = 0; s < m_NumShaders; ++s)
+ for (Uint32 s = 0; s < NumShaders; ++s)
{
const auto ShaderType = pPRS->GetActiveShaderStageType(s);
const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPRS->GetPipelineType());
+ const auto MgrInd = m_ActiveShaderStageIndex[ShaderInd];
+ VERIFY_EXPR(MgrInd >= 0 && MgrInd < static_cast<int>(NumShaders));
auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
// It is important that initialization is separated from construction because it provides exception safety.
constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC};
- m_pShaderVarMgrs[s].Initialize(
+ m_pShaderVarMgrs[MgrInd].Initialize(
*pPRS,
VarDataAllocator,
AllowedVarTypes,
_countof(AllowedVarTypes),
ShaderType //
);
-
- m_ShaderVarIndex[ShaderInd] = static_cast<Int8>(s);
}
}
catch (...)
@@ -107,7 +106,7 @@ void ShaderResourceBindingD3D12Impl::Destruct()
if (m_pShaderVarMgrs != nullptr)
{
auto& SRBMemAllocator = GetSignature()->GetSRBMemoryAllocator();
- for (Uint32 s = 0; s < m_NumShaders; ++s)
+ for (Uint32 s = 0; s < GetNumShaders(); ++s)
{
auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
m_pShaderVarMgrs[s].Destroy(VarDataAllocator);
@@ -119,75 +118,22 @@ void ShaderResourceBindingD3D12Impl::Destruct()
void ShaderResourceBindingD3D12Impl::BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)
{
- const auto PipelineType = GetPipelineType();
- for (Int32 ShaderInd = 0; ShaderInd < static_cast<Int32>(m_ShaderVarIndex.size()); ++ShaderInd)
- {
- auto VarMngrInd = m_ShaderVarIndex[ShaderInd];
- if (VarMngrInd >= 0)
- {
- // ShaderInd is the shader type pipeline index here
- const auto ShaderType = GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType);
- if (ShaderFlags & ShaderType)
- {
- m_pShaderVarMgrs[VarMngrInd].BindResources(pResMapping, Flags);
- }
- }
- }
+ BindResourcesImpl(ShaderFlags, pResMapping, Flags, m_pShaderVarMgrs);
}
IShaderResourceVariable* ShaderResourceBindingD3D12Impl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name)
{
- auto VarMngrInd = GetVariableByNameHelper(ShaderType, Name, m_ShaderVarIndex);
- if (VarMngrInd < 0)
- return nullptr;
-
- VERIFY_EXPR(static_cast<Uint32>(VarMngrInd) < Uint32{m_NumShaders});
- return m_pShaderVarMgrs[VarMngrInd].GetVariable(Name);
+ return GetVariableByNameImpl(ShaderType, Name, m_pShaderVarMgrs);
}
Uint32 ShaderResourceBindingD3D12Impl::GetVariableCount(SHADER_TYPE ShaderType) const
{
- auto VarMngrInd = GetVariableCountHelper(ShaderType, m_ShaderVarIndex);
- if (VarMngrInd < 0)
- return 0;
-
- VERIFY_EXPR(static_cast<Uint32>(VarMngrInd) < Uint32{m_NumShaders});
- return m_pShaderVarMgrs[VarMngrInd].GetVariableCount();
+ return GetVariableCountImpl(ShaderType, m_pShaderVarMgrs);
}
IShaderResourceVariable* ShaderResourceBindingD3D12Impl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)
{
- auto VarMngrInd = GetVariableByIndexHelper(ShaderType, Index, m_ShaderVarIndex);
- if (VarMngrInd < 0)
- return nullptr;
-
- VERIFY_EXPR(static_cast<Uint32>(VarMngrInd) < Uint32{m_NumShaders});
- return m_pShaderVarMgrs[VarMngrInd].GetVariable(Index);
-}
-
-void ShaderResourceBindingD3D12Impl::InitializeStaticResources(const IPipelineState* pPipelineState)
-{
- if (StaticResourcesInitialized())
- {
- LOG_WARNING_MESSAGE("Static resources have already been initialized in this shader resource binding object. The operation will be ignored.");
- return;
- }
-
- if (pPipelineState == nullptr)
- {
- InitializeStaticResourcesWithSignature(nullptr);
- }
- else
- {
- auto* pSign = pPipelineState->GetResourceSignature(GetBindingIndex());
- if (pSign == nullptr)
- {
- LOG_ERROR_MESSAGE("Shader resource binding is not compatible with pipeline state.");
- return;
- }
-
- InitializeStaticResourcesWithSignature(pSign);
- }
+ return GetVariableByIndexImpl(ShaderType, Index, m_pShaderVarMgrs);
}
void ShaderResourceBindingD3D12Impl::InitializeStaticResourcesWithSignature(const IPipelineResourceSignature* pResourceSignature)