summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-03-07 02:58:56 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-03-07 02:58:56 +0000
commitbc9fc76496034a50faf3d7fe7be868d5d62f6663 (patch)
treee9438fe09533409c57c9c63b2f69a895e2cf8615 /Graphics/GraphicsEngineD3D12
parentMerge pull request #67 from StarshipVendingMachine/android-vulkan (diff)
parentMinor comment updates (diff)
downloadDiligentCore-bc9fc76496034a50faf3d7fe7be868d5d62f6663.tar.gz
DiligentCore-bc9fc76496034a50faf3d7fe7be868d5d62f6663.zip
Merged var_type_refactor into master
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/CMakeLists.txt4
-rw-r--r--Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h14
-rw-r--r--Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h33
-rw-r--r--Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h20
-rw-r--r--Graphics/GraphicsEngineD3D12/include/RootSignature.h87
-rw-r--r--Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h35
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h10
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h111
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h56
-rw-r--r--Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h (renamed from Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h)24
-rw-r--r--Graphics/GraphicsEngineD3D12/readme.md2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp20
-rw-r--r--Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp (renamed from Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp)96
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp135
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp36
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RootSignature.cpp82
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp29
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp32
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp330
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp43
28 files changed, 668 insertions, 547 deletions
diff --git a/Graphics/GraphicsEngineD3D12/CMakeLists.txt b/Graphics/GraphicsEngineD3D12/CMakeLists.txt
index d9505bd0..a5fac952 100644
--- a/Graphics/GraphicsEngineD3D12/CMakeLists.txt
+++ b/Graphics/GraphicsEngineD3D12/CMakeLists.txt
@@ -40,10 +40,10 @@ set(INTERFACE
interface/BufferViewD3D12.h
interface/CommandQueueD3D12.h
interface/DeviceContextD3D12.h
+ interface/EngineFactoryD3D12.h
interface/FenceD3D12.h
interface/PipelineStateD3D12.h
interface/RenderDeviceD3D12.h
- interface/RenderDeviceFactoryD3D12.h
interface/SamplerD3D12.h
interface/ShaderD3D12.h
interface/ShaderResourceBindingD3D12.h
@@ -64,11 +64,11 @@ set(SRC
src/DescriptorHeap.cpp
src/DeviceContextD3D12Impl.cpp
src/D3D12DynamicHeap.cpp
+ src/EngineFactoryD3D12.cpp
src/FenceD3D12Impl.cpp
src/GenerateMips.cpp
src/PipelineStateD3D12Impl.cpp
src/RenderDeviceD3D12Impl.cpp
- src/RenderDeviceFactoryD3D12.cpp
src/RootSignature.cpp
src/SamplerD3D12Impl.cpp
src/ShaderD3D12Impl.cpp
diff --git a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h
index 708a65ea..0bdd87ac 100644
--- a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h
@@ -58,7 +58,7 @@ public:
ID3D12Resource* pd3d12Buffer);
~BufferD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
#ifdef DEVELOPMENT
void DvpVerifyDynamicAllocation(class DeviceContextD3D12Impl* pCtx)const;
diff --git a/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h
index cf8b403c..0d375eb3 100644
--- a/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h
@@ -49,7 +49,7 @@ public:
DescriptorHeapAllocation&& HandleAlloc,
bool bIsDefaultView);
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle()override final{return m_DescriptorHandle.GetCpuHandle();}
diff --git a/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h
index 31f248bb..4089663c 100644
--- a/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h
@@ -42,7 +42,7 @@ public:
CommandQueueD3D12Impl(IReferenceCounters *pRefCounters, ID3D12CommandQueue *pd3d12NativeCmdQueue, ID3D12Fence *pd3d12Fence);
~CommandQueueD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
// Returns the fence value that will be signaled next time
virtual Uint64 GetNextFenceValue()override final { return m_NextFenceValue; }
diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
index dfdfa760..d22784dd 100644
--- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
@@ -52,15 +52,15 @@ class DeviceContextD3D12Impl final : public DeviceContextNextGenBase< DeviceCont
public:
using TDeviceContextBase = DeviceContextNextGenBase< DeviceContextBase<IDeviceContextD3D12, DeviceContextD3D12ImplTraits> >;
- DeviceContextD3D12Impl(IReferenceCounters* pRefCounters,
- class RenderDeviceD3D12Impl* pDevice,
- bool bIsDeferred,
- const EngineD3D12Attribs& Attribs,
- Uint32 ContextId,
- Uint32 CommandQueueId);
+ DeviceContextD3D12Impl(IReferenceCounters* pRefCounters,
+ class RenderDeviceD3D12Impl* pDevice,
+ bool bIsDeferred,
+ const EngineD3D12CreateInfo& EngineCI,
+ Uint32 ContextId,
+ Uint32 CommandQueueId);
~DeviceContextD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual void SetPipelineState(IPipelineState* pPipelineState)override final;
diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h
index 43b2c12d..fa51b6d0 100644
--- a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h
@@ -33,6 +33,7 @@
#include "ShaderResourceLayoutD3D12.h"
#include "SRBMemoryAllocator.h"
#include "RenderDeviceD3D12Impl.h"
+#include "ShaderVariableD3D12.h"
namespace Diligent
{
@@ -47,14 +48,22 @@ public:
PipelineStateD3D12Impl( IReferenceCounters *pRefCounters, RenderDeviceD3D12Impl *pDeviceD3D12, const PipelineStateDesc &PipelineDesc );
~PipelineStateD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
- virtual ID3D12PipelineState *GetD3D12PipelineState()const override final{return m_pd3d12PSO;}
-
+ virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags)override final;
+
+ virtual Uint32 GetStaticVariableCount(SHADER_TYPE ShaderType) const override final;
+
+ virtual IShaderResourceVariable* GetStaticShaderVariable(SHADER_TYPE ShaderType, const Char* Name) override final;
+
+ virtual IShaderResourceVariable* GetStaticShaderVariable(SHADER_TYPE ShaderType, Uint32 Index) override final;
+
virtual void CreateShaderResourceBinding( IShaderResourceBinding **ppShaderResourceBinding, bool InitStaticResources )override final;
virtual bool IsCompatibleWith(const IPipelineState *pPSO)const override final;
+ virtual ID3D12PipelineState *GetD3D12PipelineState()const override final{return m_pd3d12PSO;}
+
virtual ID3D12RootSignature *GetD3D12RootSignature()const override final{return m_RootSig.GetD3D12RootSignature(); }
ShaderResourceCacheD3D12* CommitAndTransitionShaderResources(IShaderResourceBinding* pShaderResourceBinding,
@@ -70,7 +79,19 @@ public:
VERIFY_EXPR(ShaderInd < m_NumShaders);
return m_pShaderResourceLayouts[ShaderInd];
}
+
+ const ShaderResourceLayoutD3D12& GetStaticShaderResLayout(Uint32 ShaderInd)const
+ {
+ VERIFY_EXPR(ShaderInd < m_NumShaders);
+ return m_pShaderResourceLayouts[m_NumShaders + ShaderInd];
+ }
+ ShaderResourceCacheD3D12& GetStaticShaderResCache(Uint32 ShaderInd)const
+ {
+ VERIFY_EXPR(ShaderInd < m_NumShaders);
+ return m_pStaticResourceCaches[ShaderInd];
+ }
+
bool dbgContainsShaderResources()const;
SRBMemoryAllocator& GetSRBMemoryAllocator()
@@ -87,7 +108,11 @@ private:
// Must be defined before default SRB
SRBMemoryAllocator m_SRBMemAllocator;
- ShaderResourceLayoutD3D12* m_pShaderResourceLayouts;
+ ShaderResourceLayoutD3D12* m_pShaderResourceLayouts = nullptr;
+ ShaderResourceCacheD3D12* m_pStaticResourceCaches = nullptr;
+ ShaderVariableManagerD3D12* m_pStaticVarManagers = nullptr;
+ // Resource layout index in m_ResourceLayouts[] array for every shader stage
+ Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1};
};
}
diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h
index 7f53cb26..376e32d1 100644
--- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h
@@ -45,22 +45,22 @@ class RenderDeviceD3D12Impl final : public RenderDeviceNextGenBase< RenderDevice
public:
using TRenderDeviceBase = RenderDeviceNextGenBase< RenderDeviceD3DBase<IRenderDeviceD3D12>, ICommandQueueD3D12 >;
- RenderDeviceD3D12Impl( IReferenceCounters* pRefCounters,
- IMemoryAllocator& RawMemAllocator,
- const EngineD3D12Attribs& CreationAttribs,
- ID3D12Device* pD3D12Device,
- size_t CommandQueueCount,
- ICommandQueueD3D12** ppCmdQueues,
- Uint32 NumDeferredContexts );
+ RenderDeviceD3D12Impl( IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ const EngineD3D12CreateInfo& EngineCI,
+ ID3D12Device* pD3D12Device,
+ size_t CommandQueueCount,
+ ICommandQueueD3D12** ppCmdQueues,
+ Uint32 NumDeferredContexts );
~RenderDeviceD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState )override final;
virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer **ppBuffer)override final;
- virtual void CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader **ppShader)override final;
+ virtual void CreateShader(const ShaderCreateInfo& ShaderCreateInfo, IShader **ppShader)override final;
virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture **ppTexture)override final;
@@ -108,7 +108,7 @@ private:
CComPtr<ID3D12Device> m_pd3d12Device;
- EngineD3D12Attribs m_EngineAttribs;
+ EngineD3D12CreateInfo m_EngineAttribs;
CPUDescriptorHeap m_CPUDescriptorHeaps[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES];
GPUDescriptorHeap m_GPUDescriptorHeaps[2]; // D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV == 0
diff --git a/Graphics/GraphicsEngineD3D12/include/RootSignature.h b/Graphics/GraphicsEngineD3D12/include/RootSignature.h
index fbf17f4d..1d312399 100644
--- a/Graphics/GraphicsEngineD3D12/include/RootSignature.h
+++ b/Graphics/GraphicsEngineD3D12/include/RootSignature.h
@@ -40,12 +40,12 @@ class RootParameter
{
public:
- RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType,
- Uint32 RootIndex,
- UINT Register,
- UINT RegisterSpace,
- D3D12_SHADER_VISIBILITY Visibility,
- SHADER_VARIABLE_TYPE VarType)noexcept :
+ RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType,
+ Uint32 RootIndex,
+ UINT Register,
+ UINT RegisterSpace,
+ D3D12_SHADER_VISIBILITY Visibility,
+ SHADER_RESOURCE_VARIABLE_TYPE VarType)noexcept :
m_RootIndex (RootIndex),
m_ShaderVarType(VarType)
{
@@ -56,13 +56,13 @@ public:
m_RootParam.Descriptor.RegisterSpace = RegisterSpace;
}
- RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType,
- Uint32 RootIndex,
- UINT Register,
- UINT RegisterSpace,
- UINT NumDwords,
- D3D12_SHADER_VISIBILITY Visibility,
- SHADER_VARIABLE_TYPE VarType)noexcept :
+ RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType,
+ Uint32 RootIndex,
+ UINT Register,
+ UINT RegisterSpace,
+ UINT NumDwords,
+ D3D12_SHADER_VISIBILITY Visibility,
+ SHADER_RESOURCE_VARIABLE_TYPE VarType)noexcept :
m_RootIndex (RootIndex),
m_ShaderVarType(VarType)
{
@@ -74,12 +74,12 @@ public:
m_RootParam.Constants.RegisterSpace = RegisterSpace;
}
- RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType,
- Uint32 RootIndex,
- UINT NumRanges,
- D3D12_DESCRIPTOR_RANGE* pRanges,
- D3D12_SHADER_VISIBILITY Visibility,
- SHADER_VARIABLE_TYPE VarType)noexcept :
+ RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType,
+ Uint32 RootIndex,
+ UINT NumRanges,
+ D3D12_DESCRIPTOR_RANGE* pRanges,
+ D3D12_SHADER_VISIBILITY Visibility,
+ SHADER_RESOURCE_VARIABLE_TYPE VarType)noexcept :
m_RootIndex (RootIndex),
m_ShaderVarType(VarType)
{
@@ -158,7 +158,7 @@ public:
m_DescriptorTableSize = std::max(m_DescriptorTableSize, OffsetFromTableStart + Count);
}
- SHADER_VARIABLE_TYPE GetShaderVariableType()const{ return m_ShaderVarType; }
+ SHADER_RESOURCE_VARIABLE_TYPE GetShaderVariableType()const{ return m_ShaderVarType; }
Uint32 GetDescriptorTableSize()const
{
VERIFY(m_RootParam.ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, "Incorrect parameter table: descriptor table is expected");
@@ -274,10 +274,10 @@ public:
private:
- SHADER_VARIABLE_TYPE m_ShaderVarType = static_cast<SHADER_VARIABLE_TYPE>(-1);
- D3D12_ROOT_PARAMETER m_RootParam = {};
- Uint32 m_DescriptorTableSize = 0;
- Uint32 m_RootIndex = static_cast<Uint32>(-1);
+ SHADER_RESOURCE_VARIABLE_TYPE m_ShaderVarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(-1);
+ D3D12_ROOT_PARAMETER m_RootParam = {};
+ Uint32 m_DescriptorTableSize = 0;
+ Uint32 m_RootIndex = static_cast<Uint32>(-1);
};
@@ -288,9 +288,9 @@ class RootSignature
public:
RootSignature();
- void AllocateStaticSamplers(IShader* const *ppShaders, Uint32 NumShaders);
+ void AllocateStaticSamplers(const PipelineResourceLayoutDesc& ResourceLayout);
- void Finalize(ID3D12Device *pd3d12Device);
+ void Finalize(ID3D12Device* pd3d12Device);
ID3D12RootSignature* GetD3D12RootSignature()const{return m_pd3d12RootSignature;}
@@ -305,6 +305,7 @@ public:
void AllocateResourceSlot(SHADER_TYPE ShaderType,
const D3DShaderResourceAttribs& ShaderResAttribs,
+ SHADER_RESOURCE_VARIABLE_TYPE VariableType,
D3D12_DESCRIPTOR_RANGE_TYPE RangeType,
Uint32& RootIndex,
Uint32& OffsetFromTableStart);
@@ -330,15 +331,15 @@ public:
bool IsCompute,
class DeviceContextD3D12Impl* pCtx)const;
- Uint32 GetTotalSrvCbvUavSlots(SHADER_VARIABLE_TYPE VarType)const
+ Uint32 GetTotalSrvCbvUavSlots(SHADER_RESOURCE_VARIABLE_TYPE VarType)const
{
return m_TotalSrvCbvUavSlots[VarType];
}
- Uint32 GetTotalSamplerSlots(SHADER_VARIABLE_TYPE VarType)const
+ Uint32 GetTotalSamplerSlots(SHADER_RESOURCE_VARIABLE_TYPE VarType)const
{
return m_TotalSamplerSlots[VarType];
}
- Uint32 GetTotalRootViews(SHADER_VARIABLE_TYPE VarType)const
+ Uint32 GetTotalRootViews(SHADER_RESOURCE_VARIABLE_TYPE VarType)const
{
return m_TotalRootViews[VarType];
}
@@ -359,9 +360,9 @@ private:
std::vector<Uint32, STDAllocatorRawMem<Uint32> > GetCacheTableSizes()const;
- std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> m_TotalSrvCbvUavSlots = {};
- std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> m_TotalSamplerSlots = {};
- std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> m_TotalRootViews = {};
+ std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> m_TotalSrvCbvUavSlots = {};
+ std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> m_TotalSamplerSlots = {};
+ std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> m_TotalRootViews = {};
CComPtr<ID3D12RootSignature> m_pd3d12RootSignature;
@@ -402,16 +403,16 @@ private:
return m_pRootViews[ViewInd];
}
- void AddRootView(D3D12_ROOT_PARAMETER_TYPE ParameterType,
- Uint32 RootIndex,
- UINT Register,
- D3D12_SHADER_VISIBILITY Visibility,
- SHADER_VARIABLE_TYPE VarType);
+ void AddRootView(D3D12_ROOT_PARAMETER_TYPE ParameterType,
+ Uint32 RootIndex,
+ UINT Register,
+ D3D12_SHADER_VISIBILITY Visibility,
+ SHADER_RESOURCE_VARIABLE_TYPE VarType);
- void AddRootTable(Uint32 RootIndex,
- D3D12_SHADER_VISIBILITY Visibility,
- SHADER_VARIABLE_TYPE VarType,
- Uint32 NumRangesInNewTable = 1);
+ void AddRootTable(Uint32 RootIndex,
+ D3D12_SHADER_VISIBILITY Visibility,
+ SHADER_RESOURCE_VARIABLE_TYPE VarType,
+ Uint32 NumRangesInNewTable = 1);
void AddDescriptorRanges(Uint32 RootTableInd, Uint32 NumExtraRanges = 1);
@@ -446,9 +447,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_VARIABLE_TYPE_NUM_TYPES * 6> m_SrvCbvUavRootTablesMap;
+ std::array<Uint8, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES * 6> m_SrvCbvUavRootTablesMap;
// This array contains the same data for Sampler root table
- std::array<Uint8, SHADER_VARIABLE_TYPE_NUM_TYPES * 6> m_SamplerRootTablesMap;
+ std::array<Uint8, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES * 6> m_SamplerRootTablesMap;
RootParamsManager m_RootParams;
diff --git a/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h
index c34e2417..2cc34633 100644
--- a/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h
@@ -47,7 +47,7 @@ public:
const SamplerDesc& SamplerDesc);
~SamplerD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle()override{ return m_Descriptor.GetCpuHandle(); }
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h
index 8f80e54b..9227287e 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h
@@ -45,49 +45,30 @@ class ShaderD3D12Impl final : public ShaderBase<IShaderD3D12, RenderDeviceD3D12I
public:
using TShaderBase = ShaderBase<IShaderD3D12, RenderDeviceD3D12Impl>;
- ShaderD3D12Impl(IReferenceCounters* pRefCounters,
- RenderDeviceD3D12Impl* pRenderDeviceD3D12,
- const ShaderCreationAttribs& ShaderCreationAttribs);
+ ShaderD3D12Impl(IReferenceCounters* pRefCounters,
+ RenderDeviceD3D12Impl* pRenderDeviceD3D12,
+ const ShaderCreateInfo& ShaderCI);
~ShaderD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
- virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override final
+ virtual Uint32 GetResourceCount()const override final
{
- m_StaticVarsMgr.BindResources(pResourceMapping, Flags);
- }
-
- virtual IShaderVariable* GetShaderVariable(const Char* Name)override final
- {
- return m_StaticVarsMgr.GetVariable(Name);
+ return m_pShaderResources->GetTotalResources();
}
- virtual Uint32 GetVariableCount() const override final
+ virtual ShaderResourceDesc GetResource(Uint32 Index)const override final
{
- return m_StaticVarsMgr.GetVariableCount();
- }
-
- virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final
- {
- return m_StaticVarsMgr.GetVariable(Index);
+ return m_pShaderResources->GetShaderResourceDesc(Index);
}
ID3DBlob* GetShaderByteCode(){return m_pShaderByteCode;}
const std::shared_ptr<const ShaderResourcesD3D12>& GetShaderResources()const { return m_pShaderResources; }
- const ShaderResourceLayoutD3D12& GetStaticResLayout()const { return m_StaticResLayout; }
- const ShaderResourceCacheD3D12& GetStaticResCache() const { return m_StaticResCache; }
-
-#ifdef DEVELOPMENT
- bool DvpVerifyStaticResourceBindings()const;
-#endif
private:
// ShaderResources class instance must be referenced through the shared pointer, because
// it is referenced by ShaderResourceLayoutD3D12 class instances
std::shared_ptr<const ShaderResourcesD3D12> m_pShaderResources;
- ShaderResourceLayoutD3D12 m_StaticResLayout;
- ShaderResourceCacheD3D12 m_StaticResCache;
- ShaderVariableManagerD3D12 m_StaticVarsMgr;
};
}
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h
index 4f2cdef5..18f03df1 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h
@@ -49,15 +49,15 @@ public:
bool IsPSOInternal);
~ShaderResourceBindingD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject** ppInterface )override;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)override;
- virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, const char* Name)override;
+ virtual IShaderResourceVariable* GetVariable(SHADER_TYPE ShaderType, const char* Name)override;
virtual Uint32 GetVariableCount(SHADER_TYPE ShaderType) const override final;
- virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, Uint32 Index)override final;
+ virtual IShaderResourceVariable* GetVariable(SHADER_TYPE ShaderType, Uint32 Index)override final;
virtual void InitializeStaticResources(const IPipelineState* pPipelineState)override final;
@@ -74,9 +74,9 @@ private:
ShaderResourceCacheD3D12 m_ShaderResourceCache;
ShaderVariableManagerD3D12* m_pShaderVarMgrs = nullptr;
// Resource layout index in m_ResourceLayouts[] array for every shader stage
- Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1};
+ Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1};
bool m_bStaticResourcesInitialized = false;
- const Uint8 m_NumShaders = 0;
+ const Uint8 m_NumShaders = 0;
};
}
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h
index e734cf5c..35ddfbc7 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h
@@ -37,14 +37,14 @@
// | SRV/CBV/UAV - STATIC | SRV/CBV/UAV - MUTABLE | SRV/CBV/UAV - DYNAMIC | Samplers - STATIC | Samplers - MUTABLE | Samplers - DYNAMIC ||
// | | | |
//
-// s == NumCbvSrvUav[SHADER_VARIABLE_TYPE_STATIC]
-// m == NumCbvSrvUav[SHADER_VARIABLE_TYPE_MUTABLE]
-// d == NumCbvSrvUav[SHADER_VARIABLE_TYPE_DYNAMIC]
+// s == NumCbvSrvUav[SHADER_RESOURCE_VARIABLE_TYPE_STATIC]
+// m == NumCbvSrvUav[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE]
+// d == NumCbvSrvUav[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC]
// smd = s+m+d
//
-// s' == NumSamplers[SHADER_VARIABLE_TYPE_STATIC]
-// m' == NumSamplers[SHADER_VARIABLE_TYPE_MUTABLE]
-// d' == NumSamplers[SHADER_VARIABLE_TYPE_DYNAMIC]
+// s' == NumSamplers[SHADER_RESOURCE_VARIABLE_TYPE_STATIC]
+// m' == NumSamplers[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE]
+// d' == NumSamplers[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC]
//
// Every D3D12Resource structure holds a reference to D3DShaderResourceAttribs structure from ShaderResourcesD3D12.
// ShaderResourceLayoutD3D12 holds shared pointer to ShaderResourcesD3D12 instance. Note that ShaderResourcesD3D12::SamplerId
@@ -86,14 +86,13 @@
// ** These resource layouts are used as reference layouts for shader resource binding objects
// ** All variable types are preserved
// ** Root indices and descriptor table offsets are assigned during the initialization
-// * Every shader object (ShaderD3D12Impl) contains shader resource layout that facilitates management of static shader resources
+// * Every pipeline state object also contains shader resource layout that facilitates management of static shader resources
// ** The resource layout defines artificial layout where root index matches the resource type (CBV/SRV/UAV/SAM)
// ** Only static variables are referenced
//
// * Every shader resource binding object (ShaderResourceBindingD3D12Impl) encompasses shader variable
// manager (ShaderVariableManagerD3D12) for every active shader stage in the parent pipeline state that
// handles mutable and dynamic resources
-// * Every shader object (ShaderD3D12Impl) constains shader variable manager that handles static resources
#include <array>
@@ -109,7 +108,21 @@ namespace Diligent
class ShaderResourceLayoutD3D12 final
{
public:
- ShaderResourceLayoutD3D12(IObject& Owner);
+
+ // There are two modes a layout can be constructed:
+ // - initialize static resource layout and initialize shader resource cache to hold static resources
+ // - initialize reference layouts that address all types of resources (static, mutable, dynamic).
+ // Root indices and descriptor table offsets are assigned during the initialization;
+ // no shader resource cache is provided
+ ShaderResourceLayoutD3D12(IObject& Owner,
+ ID3D12Device* pd3d12Device,
+ const PipelineResourceLayoutDesc& ResourceLayout,
+ std::shared_ptr<const ShaderResourcesD3D12> pSrcResources,
+ IMemoryAllocator& LayoutDataAllocator,
+ const SHADER_RESOURCE_VARIABLE_TYPE* const VarTypes,
+ Uint32 NumAllowedTypes,
+ ShaderResourceCacheD3D12* pResourceCache,
+ class RootSignature* pRootSig);
ShaderResourceLayoutD3D12 (const ShaderResourceLayoutD3D12&) = delete;
ShaderResourceLayoutD3D12 (ShaderResourceLayoutD3D12&&) = delete;
@@ -118,20 +131,6 @@ public:
~ShaderResourceLayoutD3D12();
- // The method is called by
- // - ShaderD3D12Impl class instance to initialize static resource layout and initialize shader resource cache
- // to hold static resources
- // - PipelineStateD3D12Impl class instance to reference all types of resources (static, mutable, dynamic).
- // Root indices and descriptor table offsets are assigned during the initialization;
- // no shader resource cache is provided
- void Initialize(ID3D12Device* pd3d12Device,
- std::shared_ptr<const ShaderResourcesD3D12> pSrcResources,
- IMemoryAllocator& LayoutDataAllocator,
- const SHADER_VARIABLE_TYPE* VarTypes,
- Uint32 NumAllowedTypes,
- ShaderResourceCacheD3D12* pResourceCache,
- class RootSignature* pRootSig);
-
// sizeof(D3D12Resource) == 24 (x64)
struct D3D12Resource final
{
@@ -141,7 +140,8 @@ public:
D3D12Resource& operator = ( D3D12Resource&&) = delete;
static constexpr const Uint32 ResourceTypeBits = 3;
- static constexpr const Uint32 RootIndexBits = 16 - ResourceTypeBits;
+ static constexpr const Uint32 VariableTypeBits = 2;
+ static constexpr const Uint32 RootIndexBits = 16 - ResourceTypeBits - VariableTypeBits;
static constexpr const Uint32 InvalidRootIndex = (1 << RootIndexBits) - 1;
static constexpr const Uint32 MaxRootIndex = InvalidRootIndex - 1;
@@ -150,24 +150,29 @@ public:
static constexpr const Uint32 MaxSamplerId = InvalidSamplerId-1;
static constexpr const Uint32 InvalidOffset = static_cast<Uint32>(-1);
+ static_assert( SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES < (1 << VariableTypeBits), "2 bits is not enough to store SHADER_RESOURCE_VARIABLE_TYPE");
static_assert( static_cast<int>(CachedResourceType::NumTypes) < (1 << ResourceTypeBits), "3 bits is not enough to store CachedResourceType");
- const ShaderResourceLayoutD3D12& ParentResLayout;
- const D3DShaderResourceAttribs& Attribs;
- const Uint32 OffsetFromTableStart;
- const Uint16 ResourceType : ResourceTypeBits; // | 0 1 2 |
- const Uint16 RootIndex : RootIndexBits; // | 3 4 5 ... 15 |
- const Uint16 SamplerId;
+/* 0 */ const ShaderResourceLayoutD3D12& ParentResLayout;
+/* 8 */ const D3DShaderResourceAttribs& Attribs;
+/*16 */ const Uint32 OffsetFromTableStart;
+/*20.0*/ const Uint16 ResourceType : ResourceTypeBits; // | 0 1 2 |
+/*20.3*/ const Uint16 VariableType : VariableTypeBits; // | 3 4 |
+/*20.5*/ const Uint16 RootIndex : RootIndexBits; // | 5 6 7 ... 15 |
+/*22 */ const Uint16 SamplerId;
+/*24 */ // End of data
D3D12Resource(const ShaderResourceLayoutD3D12& _ParentLayout,
- const D3DShaderResourceAttribs& _Attribs,
- CachedResourceType _ResType,
+ const D3DShaderResourceAttribs& _Attribs,
+ SHADER_RESOURCE_VARIABLE_TYPE _VariableType,
+ CachedResourceType _ResType,
Uint32 _RootIndex,
Uint32 _OffsetFromTableStart,
Uint32 _SamplerId)noexcept :
ParentResLayout (_ParentLayout),
Attribs (_Attribs),
ResourceType (static_cast<Uint16>(_ResType)),
+ VariableType (static_cast<Uint16>(_VariableType)),
RootIndex (static_cast<Uint16>(_RootIndex)),
SamplerId (static_cast<Uint16>(_SamplerId)),
OffsetFromTableStart( _OffsetFromTableStart )
@@ -175,6 +180,7 @@ public:
VERIFY(IsValidOffset(), "Offset must be valid");
VERIFY(IsValidRootIndex(), "Root index must be valid");
VERIFY(_RootIndex <= MaxRootIndex, "Root index (", _RootIndex, ") exceeds max allowed value (", MaxRootIndex, ")" );
+ VERIFY(_VariableType < (1 << VariableTypeBits), "Variable type is out of representable range");
VERIFY(_SamplerId == InvalidSamplerId || _SamplerId <= MaxSamplerId, "Sampler id (", _SamplerId, ") exceeds max allowed value (", MaxSamplerId, ")" );
VERIFY(_SamplerId == InvalidSamplerId || GetResType() == CachedResourceType::TexSRV, "A sampler can only be assigned to a Texture SRV");
}
@@ -191,6 +197,7 @@ public:
bool IsValidOffset() const { return OffsetFromTableStart != InvalidOffset; }
CachedResourceType GetResType() const { return static_cast<CachedResourceType>( ResourceType ); }
+ SHADER_RESOURCE_VARIABLE_TYPE GetVariableType() const { return static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VariableType); }
private:
void CacheCB(IDeviceObject* pBuffer,
@@ -224,46 +231,52 @@ public:
IObject& GetOwner(){return m_Owner;}
- Uint32 GetCbvSrvUavCount(SHADER_VARIABLE_TYPE VarType)const
+ Uint32 GetCbvSrvUavCount(SHADER_RESOURCE_VARIABLE_TYPE VarType)const
{
return m_CbvSrvUavOffsets[VarType + 1] - m_CbvSrvUavOffsets[VarType];
}
- Uint32 GetSamplerCount(SHADER_VARIABLE_TYPE VarType)const
+ Uint32 GetSamplerCount(SHADER_RESOURCE_VARIABLE_TYPE VarType)const
{
return m_SamplersOffsets[VarType + 1] - m_SamplersOffsets[VarType];
}
- const D3D12Resource& GetSrvCbvUav(SHADER_VARIABLE_TYPE VarType, Uint32 r)const
+ const D3D12Resource& GetSrvCbvUav(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 r)const
{
VERIFY_EXPR( r < GetCbvSrvUavCount(VarType) );
return GetResource(GetSrvCbvUavOffset(VarType,r));
}
- const D3D12Resource& GetSampler(SHADER_VARIABLE_TYPE VarType, Uint32 s)const
+ const D3D12Resource& GetSampler(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 s)const
{
VERIFY_EXPR( s < GetSamplerCount(VarType) );
return GetResource(GetSamplerOffset(VarType,s));
}
const bool IsUsingSeparateSamplers() const {return !m_pResources->IsUsingCombinedTextureSamplers();}
+
+ SHADER_TYPE GetShaderType() const {return m_pResources->GetShaderType();}
private:
const D3D12Resource& GetAssignedSampler(const D3D12Resource& TexSrv)const;
D3D12Resource& GetAssignedSampler(const D3D12Resource& TexSrv);
- const Char* GetShaderName()const;
+ const Char* GetShaderName()const
+ {
+ return m_pResources->GetShaderName();
+ }
+
Uint32 GetTotalSrvCbvUavCount()const
{
VERIFY_EXPR(m_CbvSrvUavOffsets[0] == 0);
- return m_CbvSrvUavOffsets[SHADER_VARIABLE_TYPE_NUM_TYPES];
+ return m_CbvSrvUavOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES];
}
Uint32 GetTotalSamplerCount()const
{
- return m_SamplersOffsets[SHADER_VARIABLE_TYPE_NUM_TYPES] - m_SamplersOffsets[0];
+ return m_SamplersOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES] - m_SamplersOffsets[0];
}
Uint32 GetTotalResourceCount()const
{
- return m_SamplersOffsets[SHADER_VARIABLE_TYPE_NUM_TYPES];
+ return m_SamplersOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES];
}
D3D12Resource& GetResource(Uint32 r)
@@ -279,25 +292,25 @@ private:
return Resource[r];
}
- Uint32 GetSrvCbvUavOffset(SHADER_VARIABLE_TYPE VarType, Uint32 r)const
+ Uint32 GetSrvCbvUavOffset(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 r)const
{
Uint32 Offset = m_CbvSrvUavOffsets[VarType] + r;
VERIFY_EXPR( Offset < m_CbvSrvUavOffsets[VarType+1] );
return Offset;
}
- D3D12Resource& GetSrvCbvUav(SHADER_VARIABLE_TYPE VarType, Uint32 r)
+ D3D12Resource& GetSrvCbvUav(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 r)
{
VERIFY_EXPR( r < GetCbvSrvUavCount(VarType) );
return GetResource(GetSrvCbvUavOffset(VarType,r));
}
- Uint32 GetSamplerOffset(SHADER_VARIABLE_TYPE VarType, Uint32 s)const
+ Uint32 GetSamplerOffset(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 s)const
{
auto Offset = m_SamplersOffsets[VarType] + s;
VERIFY_EXPR( Offset < m_SamplersOffsets[VarType+1] );
return Offset;
}
- D3D12Resource& GetSampler(SHADER_VARIABLE_TYPE VarType, Uint32 s)
+ D3D12Resource& GetSampler(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 s)
{
VERIFY_EXPR( s < GetSamplerCount(VarType) );
return GetResource(GetSamplerOffset(VarType,s));
@@ -309,15 +322,15 @@ private:
}
void AllocateMemory(IMemoryAllocator& Allocator,
- const std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount,
- const std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES>& SamplerCount);
+ const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount,
+ const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& SamplerCount);
std::unique_ptr<void, STDDeleterRawMem<void> > m_ResourceBuffer;
- std::array<Uint16, SHADER_VARIABLE_TYPE_NUM_TYPES + 1> m_CbvSrvUavOffsets = {};
- std::array<Uint16, SHADER_VARIABLE_TYPE_NUM_TYPES + 1> m_SamplersOffsets = {};
+ std::array<Uint16, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + 1> m_CbvSrvUavOffsets = {};
+ std::array<Uint16, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + 1> m_SamplersOffsets = {};
- CComPtr<ID3D12Device> m_pd3d12Device;
IObject& m_Owner;
+ CComPtr<ID3D12Device> m_pd3d12Device;
// We must use shared_ptr to reference ShaderResources instance, because
// there may be multiple objects referencing the same set of resources
std::shared_ptr<const ShaderResourcesD3D12> m_pResources;
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h
index 0c1127d2..240493cc 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h
@@ -30,7 +30,7 @@
// * ShaderVariableManagerD3D12 keeps list of variables of specific types
// * Every ShaderVariableD3D12Impl references D3D12Resource from ShaderResourceLayoutD3D12
// * ShaderVariableManagerD3D12 keeps pointer to ShaderResourceCacheD3D12
-// * ShaderVariableManagerD3D12 is used by ShaderD3D12Impl to manage static resources and by
+// * ShaderVariableManagerD3D12 is used by PipelineStateD3D12Impl to manage static resources and by
// ShaderResourceBindingD3D12Impl to manage mutable and dynamic resources
//
// _____________________________ ________________________________________________________________________________
@@ -66,20 +66,18 @@ namespace Diligent
class ShaderVariableD3D12Impl;
-// sizeof(ShaderVariableManagerD3D12) == 40 (x64, msvc, Release)
+// sizeof(ShaderVariableManagerD3D12) == 32 (x64, msvc, Release)
class ShaderVariableManagerD3D12
{
public:
- ShaderVariableManagerD3D12(IObject &Owner) :
- m_Owner(Owner)
- {}
+ ShaderVariableManagerD3D12(IObject& Owner,
+ const ShaderResourceLayoutD3D12& Layout,
+ IMemoryAllocator& Allocator,
+ const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ ShaderResourceCacheD3D12& ResourceCache);
~ShaderVariableManagerD3D12();
- void Initialize(const ShaderResourceLayoutD3D12& Layout,
- IMemoryAllocator& Allocator,
- const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- ShaderResourceCacheD3D12& ResourceCache);
void Destroy(IMemoryAllocator& Allocator);
ShaderVariableD3D12Impl* GetVariable(const Char* Name);
@@ -87,10 +85,10 @@ public:
void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags);
- static size_t GetRequiredMemorySize(const ShaderResourceLayoutD3D12& Layout,
- const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- Uint32& NumVariables);
+ static size_t GetRequiredMemorySize(const ShaderResourceLayoutD3D12& Layout,
+ const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ Uint32& NumVariables);
Uint32 GetVariableCount()const { return m_NumVariables; }
@@ -99,13 +97,13 @@ private:
Uint32 GetVariableIndex(const ShaderVariableD3D12Impl& Variable);
- IObject& m_Owner;
- // Variable mgr is owned by either Shader object (in which case m_pResourceLayout points to
- // static resource layout owned by the same shader object), or by SRB object (in which case
- // m_pResourceLayout points to corresponding layout in pipeline state). Since SRB keeps strong
- // reference to PSO, the layout is guaranteed be alive while SRB is alive
- const ShaderResourceLayoutD3D12* m_pResourceLayout= nullptr;
- ShaderResourceCacheD3D12* m_pResourceCache = nullptr;
+ IObject& m_Owner;
+
+ // Variable mgr is owned by either Pipeline state object (in which case m_ResourceCache references
+ // static resource cache owned by the same PSO object), or by SRB object (in which case
+ // m_ResourceCache references the cache in the SRB). Thus the cache and the resource layout
+ // (which the variables reference) are guaranteed to be alive while the manager is alive.
+ ShaderResourceCacheD3D12& m_ResourceCache;
// 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
@@ -114,12 +112,12 @@ private:
Uint32 m_NumVariables = 0;
#ifdef _DEBUG
- IMemoryAllocator* m_pDbgAllocator = nullptr;
+ IMemoryAllocator& m_DbgAllocator;
#endif
};
// sizeof(ShaderVariableD3D12Impl) == 24 (x64)
-class ShaderVariableD3D12Impl final : public IShaderVariable
+class ShaderVariableD3D12Impl final : public IShaderResourceVariable
{
public:
ShaderVariableD3D12Impl(ShaderVariableManagerD3D12& ParentManager,
@@ -154,29 +152,27 @@ public:
return;
*ppInterface = nullptr;
- if (IID == IID_ShaderVariable || IID == IID_Unknown)
+ if (IID == IID_ShaderResourceVariable || IID == IID_Unknown)
{
*ppInterface = this;
(*ppInterface)->AddRef();
}
}
- virtual SHADER_VARIABLE_TYPE GetType()const override final
+ virtual SHADER_RESOURCE_VARIABLE_TYPE GetType()const override final
{
- return m_Resource.Attribs.GetVariableType();
+ return m_Resource.GetVariableType();
}
virtual void Set(IDeviceObject *pObject)override final
{
- VERIFY_EXPR(m_ParentManager.m_pResourceCache != nullptr);
- m_Resource.BindResource(pObject, 0, *m_ParentManager.m_pResourceCache);
+ m_Resource.BindResource(pObject, 0, m_ParentManager.m_ResourceCache);
}
virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final
{
- VERIFY_EXPR(m_ParentManager.m_pResourceCache != nullptr);
for (Uint32 Elem = 0; Elem < NumElements; ++Elem)
- m_Resource.BindResource(ppObjects[Elem], FirstElement + Elem, *m_ParentManager.m_pResourceCache);
+ m_Resource.BindResource(ppObjects[Elem], FirstElement + Elem, m_ParentManager.m_ResourceCache);
}
virtual Uint32 GetArraySize()const override final
diff --git a/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h
index 50d80511..61d8cfb8 100644
--- a/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h
@@ -49,7 +49,7 @@ public:
void* pNativeWndHandle);
~SwapChainD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual void Present(Uint32 SyncInterval)override final;
virtual void Resize( Uint32 NewWidth, Uint32 NewHeight )override final;
diff --git a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h
index b205f843..92e3333e 100644
--- a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h
@@ -60,7 +60,7 @@ public:
ID3D12Resource* pTexture);
~TextureD3D12Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual ID3D12Resource* GetD3D12Texture(){ return GetD3D12Resource(); }
diff --git a/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h
index 5f68724d..41c17980 100644
--- a/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h
@@ -49,7 +49,7 @@ public:
DescriptorHeapAllocation&& HandleAlloc,
bool bIsDefaultView);
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle()override{return m_Descriptor.GetCpuHandle();}
diff --git a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h b/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h
index 80e6f580..7ac6e9e0 100644
--- a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h
+++ b/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h
@@ -42,18 +42,18 @@ namespace Diligent
class IEngineFactoryD3D12
{
public:
- virtual void CreateDeviceAndContextsD3D12( const EngineD3D12Attribs& CreationAttribs,
- IRenderDevice** ppDevice,
- IDeviceContext** ppContexts,
- Uint32 NumDeferredContexts) = 0;
-
- virtual void AttachToD3D12Device(void* pd3d12NativeDevice,
- size_t CommandQueueCount,
- class ICommandQueueD3D12** ppCommandQueues,
- const EngineD3D12Attribs& EngineAttribs,
- IRenderDevice** ppDevice,
- IDeviceContext** ppContexts,
- Uint32 NumDeferredContexts) = 0;
+ virtual void CreateDeviceAndContextsD3D12(const EngineD3D12CreateInfo& EngineCI,
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppContexts,
+ Uint32 NumDeferredContexts) = 0;
+
+ virtual void AttachToD3D12Device(void* pd3d12NativeDevice,
+ size_t CommandQueueCount,
+ class ICommandQueueD3D12** ppCommandQueues,
+ const EngineD3D12CreateInfo& EngineCI,
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppContexts,
+ Uint32 NumDeferredContexts) = 0;
virtual void CreateSwapChainD3D12( IRenderDevice* pDevice,
IDeviceContext* pImmediateContext,
diff --git a/Graphics/GraphicsEngineD3D12/readme.md b/Graphics/GraphicsEngineD3D12/readme.md
index 3827a4f0..85ad141b 100644
--- a/Graphics/GraphicsEngineD3D12/readme.md
+++ b/Graphics/GraphicsEngineD3D12/readme.md
@@ -8,7 +8,7 @@ Implementation of Direct3D12 back-end
The following code snippet shows how to initialize Diligent Engine in D3D12 mode.
```cpp
-#include "RenderDeviceFactoryD3D12.h"
+#include "EngineFactoryD3D12.h"
using namespace Diligent;
// ...
diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
index 7e8eeeed..a1d9db3f 100644
--- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
@@ -51,39 +51,39 @@ namespace Diligent
return ss.str();
}
- DeviceContextD3D12Impl::DeviceContextD3D12Impl( IReferenceCounters* pRefCounters,
- RenderDeviceD3D12Impl* pDeviceD3D12Impl,
- bool bIsDeferred,
- const EngineD3D12Attribs& Attribs,
- Uint32 ContextId,
- Uint32 CommandQueueId) :
+ DeviceContextD3D12Impl::DeviceContextD3D12Impl(IReferenceCounters* pRefCounters,
+ RenderDeviceD3D12Impl* pDeviceD3D12Impl,
+ bool bIsDeferred,
+ const EngineD3D12CreateInfo& EngineCI,
+ Uint32 ContextId,
+ Uint32 CommandQueueId) :
TDeviceContextBase
{
pRefCounters,
pDeviceD3D12Impl,
ContextId,
CommandQueueId,
- bIsDeferred ? std::numeric_limits<decltype(m_NumCommandsToFlush)>::max() : Attribs.NumCommandsToFlushCmdList,
+ bIsDeferred ? std::numeric_limits<decltype(m_NumCommandsToFlush)>::max() : EngineCI.NumCommandsToFlushCmdList,
bIsDeferred
},
m_DynamicHeap
{
pDeviceD3D12Impl->GetDynamicMemoryManager(),
GetContextObjectName("Dynamic heap", bIsDeferred, ContextId),
- Attribs.DynamicHeapPageSize
+ EngineCI.DynamicHeapPageSize
},
m_DynamicGPUDescriptorAllocator
{
{
GetRawAllocator(),
pDeviceD3D12Impl->GetGPUDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
- Attribs.DynamicDescriptorAllocationChunkSize[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV],
+ EngineCI.DynamicDescriptorAllocationChunkSize[D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV],
GetContextObjectName("CBV_SRV_UAV dynamic descriptor allocator", bIsDeferred, ContextId)
},
{
GetRawAllocator(),
pDeviceD3D12Impl->GetGPUDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER),
- Attribs.DynamicDescriptorAllocationChunkSize[D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER],
+ EngineCI.DynamicDescriptorAllocationChunkSize[D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER],
GetContextObjectName("SAMPLER dynamic descriptor allocator", bIsDeferred, ContextId)
}
},
diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
index 3096ea9e..18a69020 100644
--- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
@@ -26,7 +26,7 @@
#include "pch.h"
#include <array>
-#include "RenderDeviceFactoryD3D12.h"
+#include "EngineFactoryD3D12.h"
#include "RenderDeviceD3D12Impl.h"
#include "DeviceContextD3D12Impl.h"
#include "SwapChainD3D12Impl.h"
@@ -51,18 +51,18 @@ public:
return &TheFactory;
}
- void CreateDeviceAndContextsD3D12( const EngineD3D12Attribs& CreationAttribs,
- IRenderDevice** ppDevice,
- IDeviceContext** ppContexts,
- Uint32 NumDeferredContexts)override final;
+ void CreateDeviceAndContextsD3D12(const EngineD3D12CreateInfo& EngineCI,
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppContexts,
+ Uint32 NumDeferredContexts)override final;
- void AttachToD3D12Device(void* pd3d12NativeDevice,
- size_t CommandQueueCount,
- ICommandQueueD3D12** ppCommandQueues,
- const EngineD3D12Attribs& EngineAttribs,
- IRenderDevice** ppDevice,
- IDeviceContext** ppContexts,
- Uint32 NumDeferredContexts)override final;
+ void AttachToD3D12Device(void* pd3d12NativeDevice,
+ size_t CommandQueueCount,
+ ICommandQueueD3D12** ppCommandQueues,
+ const EngineD3D12CreateInfo& EngineCI,
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppContexts,
+ Uint32 NumDeferredContexts)override final;
void CreateSwapChainD3D12( IRenderDevice* pDevice,
IDeviceContext* pImmediateContext,
@@ -101,7 +101,7 @@ void GetHardwareAdapter(IDXGIFactory2* pFactory, IDXGIAdapter1** ppAdapter)
/// Creates render device and device contexts for Direct3D12-based engine implementation
-/// \param [in] CreationAttribs - Engine creation attributes.
+/// \param [in] EngineCI - Engine creation attributes.
/// \param [out] ppDevice - Address of the memory location where pointer to
/// the created device will be written
/// \param [out] ppContexts - Address of the memory location where pointers to
@@ -112,13 +112,13 @@ void GetHardwareAdapter(IDXGIFactory2* pFactory, IDXGIAdapter1** ppAdapter)
/// of deferred contexts is requested, pointers to the
/// contexts are written to ppContexts array starting
/// at position 1
-void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12( const EngineD3D12Attribs& CreationAttribs,
- IRenderDevice** ppDevice,
- IDeviceContext** ppContexts,
- Uint32 NumDeferredContexts)
+void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12(const EngineD3D12CreateInfo& EngineCI,
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppContexts,
+ Uint32 NumDeferredContexts)
{
- if (CreationAttribs.DebugMessageCallback != nullptr)
- SetDebugMessageCallback(CreationAttribs.DebugMessageCallback);
+ if (EngineCI.DebugMessageCallback != nullptr)
+ SetDebugMessageCallback(EngineCI.DebugMessageCallback);
VERIFY( ppDevice && ppContexts, "Null pointer provided" );
if( !ppDevice || !ppContexts )
@@ -126,7 +126,7 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12( const EngineD3D12Attr
for(Uint32 Type=D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; Type < D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++Type)
{
- auto CPUHeapAllocSize = CreationAttribs.CPUDescriptorHeapAllocationSize[Type];
+ auto CPUHeapAllocSize = EngineCI.CPUDescriptorHeapAllocationSize[Type];
Uint32 MaxSize = 1 << 20;
if( CPUHeapAllocSize > 1 << 20 )
{
@@ -164,7 +164,7 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12( const EngineD3D12Attr
CHECK_D3D_RESULT_THROW(hr, "Failed to create DXGI factory");
CComPtr<IDXGIAdapter1> hardwareAdapter;
- if(CreationAttribs.AdapterId == EngineD3D12Attribs::DefaultAdapterId)
+ if(EngineCI.AdapterId == EngineD3D12CreateInfo::DefaultAdapterId)
{
GetHardwareAdapter(factory, &hardwareAdapter);
if(hardwareAdapter == nullptr)
@@ -173,11 +173,11 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12( const EngineD3D12Attr
else
{
auto Adapters = FindCompatibleAdapters();
- if(CreationAttribs.AdapterId < Adapters.size())
- hardwareAdapter = Adapters[CreationAttribs.AdapterId];
+ if(EngineCI.AdapterId < Adapters.size())
+ hardwareAdapter = Adapters[EngineCI.AdapterId];
else
{
- LOG_ERROR_AND_THROW(CreationAttribs.AdapterId, " is not a valid hardware adapter id. Total number of compatible adapters available on this system: ", Adapters.size());
+ LOG_ERROR_AND_THROW(EngineCI.AdapterId, " is not a valid hardware adapter id. Total number of compatible adapters available on this system: ", Adapters.size());
}
}
@@ -263,7 +263,7 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12( const EngineD3D12Attr
}
std::array<ICommandQueueD3D12*, 1> CmdQueues = {pCmdQueueD3D12};
- AttachToD3D12Device(d3d12Device, CmdQueues.size(), CmdQueues.data(), CreationAttribs, ppDevice, ppContexts, NumDeferredContexts);
+ AttachToD3D12Device(d3d12Device, CmdQueues.size(), CmdQueues.data(), EngineCI, ppDevice, ppContexts, NumDeferredContexts);
}
@@ -272,7 +272,7 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12( const EngineD3D12Attr
/// \param [in] pd3d12NativeDevice - pointer to native D3D12 device
/// \param [in] CommandQueueCount - Number of command queues
/// \param [in] ppCommandQueues - pointer to the array of command queues
-/// \param [in] EngineAttribs - Engine creation attributes.
+/// \param [in] EngineCI - Engine creation attributes.
/// \param [out] ppDevice - Address of the memory location where pointer to
/// the created device will be written
/// \param [out] ppContexts - Address of the memory location where pointers to
@@ -283,16 +283,16 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12( const EngineD3D12Attr
/// of deferred contexts is requested, pointers to the
/// contexts are written to ppContexts array starting
/// at position 1
-void EngineFactoryD3D12Impl::AttachToD3D12Device(void* pd3d12NativeDevice,
- size_t CommandQueueCount,
- ICommandQueueD3D12** ppCommandQueues,
- const EngineD3D12Attribs& EngineAttribs,
- IRenderDevice** ppDevice,
- IDeviceContext** ppContexts,
- Uint32 NumDeferredContexts)
+void EngineFactoryD3D12Impl::AttachToD3D12Device(void* pd3d12NativeDevice,
+ size_t CommandQueueCount,
+ ICommandQueueD3D12** ppCommandQueues,
+ const EngineD3D12CreateInfo& EngineCI,
+ IRenderDevice** ppDevice,
+ IDeviceContext** ppContexts,
+ Uint32 NumDeferredContexts)
{
- if (EngineAttribs.DebugMessageCallback != nullptr)
- SetDebugMessageCallback(EngineAttribs.DebugMessageCallback);
+ if (EngineCI.DebugMessageCallback != nullptr)
+ SetDebugMessageCallback(EngineCI.DebugMessageCallback);
VERIFY( pd3d12NativeDevice && ppCommandQueues && ppDevice && ppContexts, "Null pointer provided" );
if( !pd3d12NativeDevice || !ppCommandQueues || !ppDevice || !ppContexts )
@@ -303,13 +303,13 @@ void EngineFactoryD3D12Impl::AttachToD3D12Device(void* pd3d1
try
{
- SetRawAllocator(EngineAttribs.pRawMemAllocator);
+ SetRawAllocator(EngineCI.pRawMemAllocator);
auto &RawMemAllocator = GetRawAllocator();
auto d3d12Device = reinterpret_cast<ID3D12Device*>(pd3d12NativeDevice);
- RenderDeviceD3D12Impl *pRenderDeviceD3D12( NEW_RC_OBJ(RawMemAllocator, "RenderDeviceD3D12Impl instance", RenderDeviceD3D12Impl)(RawMemAllocator, EngineAttribs, d3d12Device, CommandQueueCount, ppCommandQueues, NumDeferredContexts ) );
+ RenderDeviceD3D12Impl *pRenderDeviceD3D12( NEW_RC_OBJ(RawMemAllocator, "RenderDeviceD3D12Impl instance", RenderDeviceD3D12Impl)(RawMemAllocator, EngineCI, d3d12Device, CommandQueueCount, ppCommandQueues, NumDeferredContexts ) );
pRenderDeviceD3D12->QueryInterface(IID_RenderDevice, reinterpret_cast<IObject**>(ppDevice) );
- RefCntAutoPtr<DeviceContextD3D12Impl> pImmediateCtxD3D12( NEW_RC_OBJ(RawMemAllocator, "DeviceContextD3D12Impl instance", DeviceContextD3D12Impl)(pRenderDeviceD3D12, false, EngineAttribs, 0, 0) );
+ RefCntAutoPtr<DeviceContextD3D12Impl> pImmediateCtxD3D12( NEW_RC_OBJ(RawMemAllocator, "DeviceContextD3D12Impl instance", DeviceContextD3D12Impl)(pRenderDeviceD3D12, false, EngineCI, 0, 0) );
// We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceD3D12 will
// keep a weak reference to the context
pImmediateCtxD3D12->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppContexts) );
@@ -317,7 +317,7 @@ void EngineFactoryD3D12Impl::AttachToD3D12Device(void* pd3d1
for (Uint32 DeferredCtx = 0; DeferredCtx < NumDeferredContexts; ++DeferredCtx)
{
- RefCntAutoPtr<DeviceContextD3D12Impl> pDeferredCtxD3D12( NEW_RC_OBJ(RawMemAllocator, "DeviceContextD3D12Impl instance", DeviceContextD3D12Impl)(pRenderDeviceD3D12, true, EngineAttribs, 1+DeferredCtx, 0) );
+ RefCntAutoPtr<DeviceContextD3D12Impl> pDeferredCtxD3D12( NEW_RC_OBJ(RawMemAllocator, "DeviceContextD3D12Impl instance", DeviceContextD3D12Impl)(pRenderDeviceD3D12, true, EngineCI, 1+DeferredCtx, 0) );
// We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceD3D12 will
// keep a weak reference to the context
pDeferredCtxD3D12->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppContexts + 1 + DeferredCtx) );
@@ -358,12 +358,12 @@ void EngineFactoryD3D12Impl::AttachToD3D12Device(void* pd3d1
///
/// \param [out] ppSwapChain - Address of the memory location where pointer to the new
/// swap chain will be written
-void EngineFactoryD3D12Impl::CreateSwapChainD3D12( IRenderDevice* pDevice,
- IDeviceContext* pImmediateContext,
- const SwapChainDesc& SCDesc,
- const FullScreenModeDesc& FSDesc,
- void* pNativeWndHandle,
- ISwapChain** ppSwapChain )
+void EngineFactoryD3D12Impl::CreateSwapChainD3D12(IRenderDevice* pDevice,
+ IDeviceContext* pImmediateContext,
+ const SwapChainDesc& SCDesc,
+ const FullScreenModeDesc& FSDesc,
+ void* pNativeWndHandle,
+ ISwapChain** ppSwapChain )
{
VERIFY( ppSwapChain, "Null pointer provided" );
if( !ppSwapChain )
@@ -390,7 +390,7 @@ void EngineFactoryD3D12Impl::CreateSwapChainD3D12( IRenderDevice* pDe
{
if (auto pDeferredCtx = pDeviceD3D12->GetDeferredContext(ctx))
{
- auto *pDeferredCtxD3D12 = pDeferredCtx.RawPtr<DeviceContextD3D12Impl>();
+ auto* pDeferredCtxD3D12 = pDeferredCtx.RawPtr<DeviceContextD3D12Impl>();
pDeferredCtxD3D12->SetSwapChain(pSwapChainD3D12);
// We cannot bind default render target here because
// there is no guarantee that deferred context will be used
@@ -399,7 +399,7 @@ void EngineFactoryD3D12Impl::CreateSwapChainD3D12( IRenderDevice* pDe
}
}
}
- catch( const std::runtime_error & )
+ catch( const std::runtime_error& )
{
if( *ppSwapChain )
{
@@ -422,7 +422,7 @@ void EngineFactoryD3D12Impl::CreateSwapChainD3D12( IRenderDevice* pDe
/// x86 | GraphicsEngineD3D12_32d.dll | GraphicsEngineD3D12_32r.dll
/// x64 | GraphicsEngineD3D12_64d.dll | GraphicsEngineD3D12_64r.dll
///
-void LoadGraphicsEngineD3D12(GetEngineFactoryD3D12Type &GetFactoryFunc)
+void LoadGraphicsEngineD3D12(GetEngineFactoryD3D12Type& GetFactoryFunc)
{
// This function is only required because DoxyGen refuses to generate documentation for a static function when SHOW_FILES==NO
#error This function must never be compiled;
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
index 8d5f1ba4..46530860 100644
--- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp
@@ -67,17 +67,87 @@ PipelineStateD3D12Impl :: PipelineStateD3D12Impl(IReferenceCounters* pRefCo
m_SRBMemAllocator(GetRawAllocator())
{
auto pd3d12Device = pDeviceD3D12->GetD3D12Device();
-
- m_RootSig.AllocateStaticSamplers( GetShaders(), GetNumShaders() );
+ const auto& ResourceLayout = m_Desc.ResourceLayout;
+ m_RootSig.AllocateStaticSamplers(ResourceLayout);
+
+ {
+ auto& ShaderResLayoutAllocator = GetRawAllocator();
+ auto* pShaderResLayoutRawMem = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutD3D12", sizeof(ShaderResourceLayoutD3D12) * m_NumShaders * 2);
+ m_pShaderResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D12*>(pShaderResLayoutRawMem);
+ }
+
+ {
+ auto& ShaderResCacheAllocator = GetRawAllocator();
+ auto* pShaderResCacheRawMem = ALLOCATE(ShaderResCacheAllocator, "Raw memory for ShaderResourceCacheD3D12", sizeof(ShaderResourceCacheD3D12) * m_NumShaders);
+ m_pStaticResourceCaches = reinterpret_cast<ShaderResourceCacheD3D12*>(pShaderResCacheRawMem);
+ }
+
+ {
+ auto& ShaderVarMgrAllocator = GetRawAllocator();
+ auto* pStaticVarsMgrRawMem = ALLOCATE(ShaderVarMgrAllocator, "Raw memory for ShaderVariableManagerD3D12", sizeof(ShaderVariableManagerD3D12) * m_NumShaders);
+ m_pStaticVarManagers = reinterpret_cast<ShaderVariableManagerD3D12*>(pStaticVarsMgrRawMem);
+ }
+
+#ifdef DEVELOPMENT
+ {
+ const ShaderResources* pResources[MaxShadersInPipeline] = {};
+ for (Uint32 s = 0; s < m_NumShaders; ++s)
+ {
+ const auto* pShader = GetShader<const ShaderD3D12Impl>(s);
+ pResources[s] = &(*pShader->GetShaderResources());
+ }
+ ShaderResources::DvpVerifyResourceLayout(ResourceLayout, pResources, m_NumShaders);
+ }
+#endif
- auto& ShaderResLayoutAllocator = GetRawAllocator();
- auto* pShaderResLayoutRawMem = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutD3D12", sizeof(ShaderResourceLayoutD3D12) * m_NumShaders);
- m_pShaderResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D12*>(pShaderResLayoutRawMem);
for (Uint32 s=0; s < m_NumShaders; ++s)
{
auto* pShaderD3D12 = GetShader<ShaderD3D12Impl>(s);
- new (m_pShaderResourceLayouts+s) ShaderResourceLayoutD3D12(*this);
- m_pShaderResourceLayouts[s].Initialize(pDeviceD3D12->GetD3D12Device(), pShaderD3D12->GetShaderResources(), GetRawAllocator(), nullptr, 0, nullptr, &m_RootSig);
+ auto ShaderType = pShaderD3D12->GetDesc().ShaderType;
+ auto ShaderInd = GetShaderTypeIndex(ShaderType);
+ m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s);
+
+ new (m_pShaderResourceLayouts+s)
+ ShaderResourceLayoutD3D12
+ {
+ *this,
+ pDeviceD3D12->GetD3D12Device(),
+ ResourceLayout,
+ pShaderD3D12->GetShaderResources(),
+ GetRawAllocator(),
+ nullptr,
+ 0,
+ nullptr,
+ &m_RootSig
+ };
+
+ new (m_pStaticResourceCaches+s) ShaderResourceCacheD3D12{ShaderResourceCacheD3D12::DbgCacheContentType::StaticShaderResources};
+
+ const SHADER_RESOURCE_VARIABLE_TYPE StaticVarType[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC};
+ new (m_pShaderResourceLayouts + m_NumShaders + s)
+ ShaderResourceLayoutD3D12
+ {
+ *this,
+ pDeviceD3D12->GetD3D12Device(),
+ ResourceLayout,
+ pShaderD3D12->GetShaderResources(),
+ GetRawAllocator(),
+ StaticVarType,
+ _countof(StaticVarType),
+ m_pStaticResourceCaches+s,
+ nullptr
+ };
+
+ new (m_pStaticVarManagers+s)
+ ShaderVariableManagerD3D12
+ {
+ *this,
+ GetStaticShaderResLayout(s),
+ GetRawAllocator(),
+ nullptr,
+ 0,
+ GetStaticShaderResCache(s)
+ };
}
m_RootSig.Finalize(pd3d12Device);
@@ -204,7 +274,7 @@ PipelineStateD3D12Impl :: PipelineStateD3D12Impl(IReferenceCounters* pRefCo
std::array<size_t, MaxShadersInPipeline> ShaderVarMgrDataSizes = {};
for (Uint32 s = 0; s < m_NumShaders; ++s)
{
- std::array<SHADER_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC };
+ std::array<SHADER_RESOURCE_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC };
Uint32 NumVariablesUnused = 0;
ShaderVarMgrDataSizes[s] = ShaderVariableManagerD3D12::GetRequiredMemorySize(m_pShaderResourceLayouts[s], AllowedVarTypes.data(), static_cast<Uint32>(AllowedVarTypes.size()), NumVariablesUnused);
}
@@ -221,8 +291,14 @@ PipelineStateD3D12Impl::~PipelineStateD3D12Impl()
auto& ShaderResLayoutAllocator = GetRawAllocator();
for(Uint32 s = 0; s < m_NumShaders; ++s)
{
+ m_pStaticVarManagers[s].Destroy(GetRawAllocator());
+ m_pStaticVarManagers[s].~ShaderVariableManagerD3D12();
+ m_pStaticResourceCaches [s].~ShaderResourceCacheD3D12();
m_pShaderResourceLayouts[s].~ShaderResourceLayoutD3D12();
+ m_pShaderResourceLayouts[m_NumShaders+s].~ShaderResourceLayoutD3D12();
}
+ ShaderResLayoutAllocator.Free(m_pStaticVarManagers);
+ ShaderResLayoutAllocator.Free(m_pStaticResourceCaches);
ShaderResLayoutAllocator.Free(m_pShaderResourceLayouts);
// D3D12 object can only be destroyed when it is no longer used by the GPU
@@ -324,8 +400,8 @@ ShaderResourceCacheD3D12* PipelineStateD3D12Impl::CommitAndTransitionShaderResou
}
- if( (m_RootSig.GetTotalSrvCbvUavSlots(SHADER_VARIABLE_TYPE_STATIC) != 0 ||
- m_RootSig.GetTotalRootViews(SHADER_VARIABLE_TYPE_STATIC) != 0) && !pResBindingD3D12Impl->StaticResourcesInitialized() )
+ if( (m_RootSig.GetTotalSrvCbvUavSlots(SHADER_RESOURCE_VARIABLE_TYPE_STATIC) != 0 ||
+ m_RootSig.GetTotalRootViews(SHADER_RESOURCE_VARIABLE_TYPE_STATIC) != 0) && !pResBindingD3D12Impl->StaticResourcesInitialized() )
{
LOG_ERROR_MESSAGE("Static resources have not been initialized in the shader resource binding object being committed for PSO '", m_Desc.Name,"'. Please call IShaderResourceBinding::InitializeStaticResources().");
}
@@ -357,7 +433,7 @@ ShaderResourceCacheD3D12* PipelineStateD3D12Impl::CommitAndTransitionShaderResou
bool PipelineStateD3D12Impl::dbgContainsShaderResources()const
{
- for(auto VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1))
+ for(auto VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1))
{
if (m_RootSig.GetTotalSrvCbvUavSlots(VarType) != 0 ||
m_RootSig.GetTotalRootViews (VarType) != 0)
@@ -366,4 +442,41 @@ bool PipelineStateD3D12Impl::dbgContainsShaderResources()const
return false;
}
+void PipelineStateD3D12Impl::BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags)
+{
+ for (Uint32 s=0; s < m_NumShaders; ++s)
+ {
+ auto ShaderType = GetStaticShaderResLayout(s).GetShaderType();
+ if ((ShaderFlags & ShaderType) != 0)
+ m_pStaticVarManagers[s].BindResources(pResourceMapping, Flags);
+ }
+}
+
+Uint32 PipelineStateD3D12Impl::GetStaticVariableCount(SHADER_TYPE ShaderType) const
+{
+ const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
+ if (LayoutInd < 0)
+ return 0;
+
+ return m_pStaticVarManagers[LayoutInd].GetVariableCount();
+}
+
+IShaderResourceVariable* PipelineStateD3D12Impl::GetStaticShaderVariable(SHADER_TYPE ShaderType, const Char* Name)
+{
+ const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
+ if (LayoutInd < 0)
+ return nullptr;
+
+ return m_pStaticVarManagers[LayoutInd].GetVariable(Name);
+}
+
+IShaderResourceVariable* PipelineStateD3D12Impl::GetStaticShaderVariable(SHADER_TYPE ShaderType, Uint32 Index)
+{
+ const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)];
+ if (LayoutInd < 0)
+ return nullptr;
+
+ return m_pStaticVarManagers[LayoutInd].GetVariable(Index);
+}
+
}
diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
index 202b729a..54396583 100644
--- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
@@ -37,13 +37,13 @@
namespace Diligent
{
-RenderDeviceD3D12Impl :: RenderDeviceD3D12Impl(IReferenceCounters* pRefCounters,
- IMemoryAllocator& RawMemAllocator,
- const EngineD3D12Attribs& CreationAttribs,
- ID3D12Device* pd3d12Device,
- size_t CommandQueueCount,
- ICommandQueueD3D12** ppCmdQueues,
- Uint32 NumDeferredContexts) :
+RenderDeviceD3D12Impl :: RenderDeviceD3D12Impl(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ const EngineD3D12CreateInfo& EngineCI,
+ ID3D12Device* pd3d12Device,
+ size_t CommandQueueCount,
+ ICommandQueueD3D12** ppCmdQueues,
+ Uint32 NumDeferredContexts) :
TRenderDeviceBase
{
pRefCounters,
@@ -62,22 +62,22 @@ RenderDeviceD3D12Impl :: RenderDeviceD3D12Impl(IReferenceCounters* pRef
sizeof(FenceD3D12Impl)
},
m_pd3d12Device (pd3d12Device),
- m_EngineAttribs (CreationAttribs),
+ m_EngineAttribs (EngineCI),
m_CmdListManager(*this),
m_CPUDescriptorHeaps
{
- {RawMemAllocator, *this, CreationAttribs.CPUDescriptorHeapAllocationSize[0], D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE},
- {RawMemAllocator, *this, CreationAttribs.CPUDescriptorHeapAllocationSize[1], D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, D3D12_DESCRIPTOR_HEAP_FLAG_NONE},
- {RawMemAllocator, *this, CreationAttribs.CPUDescriptorHeapAllocationSize[2], D3D12_DESCRIPTOR_HEAP_TYPE_RTV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE},
- {RawMemAllocator, *this, CreationAttribs.CPUDescriptorHeapAllocationSize[3], D3D12_DESCRIPTOR_HEAP_TYPE_DSV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE}
+ {RawMemAllocator, *this, EngineCI.CPUDescriptorHeapAllocationSize[0], D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE},
+ {RawMemAllocator, *this, EngineCI.CPUDescriptorHeapAllocationSize[1], D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, D3D12_DESCRIPTOR_HEAP_FLAG_NONE},
+ {RawMemAllocator, *this, EngineCI.CPUDescriptorHeapAllocationSize[2], D3D12_DESCRIPTOR_HEAP_TYPE_RTV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE},
+ {RawMemAllocator, *this, EngineCI.CPUDescriptorHeapAllocationSize[3], D3D12_DESCRIPTOR_HEAP_TYPE_DSV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE}
},
m_GPUDescriptorHeaps
{
- {RawMemAllocator, *this, CreationAttribs.GPUDescriptorHeapSize[0], CreationAttribs.GPUDescriptorHeapDynamicSize[0], D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE},
- {RawMemAllocator, *this, CreationAttribs.GPUDescriptorHeapSize[1], CreationAttribs.GPUDescriptorHeapDynamicSize[1], D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}
+ {RawMemAllocator, *this, EngineCI.GPUDescriptorHeapSize[0], EngineCI.GPUDescriptorHeapDynamicSize[0], D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE},
+ {RawMemAllocator, *this, EngineCI.GPUDescriptorHeapSize[1], EngineCI.GPUDescriptorHeapDynamicSize[1], D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}
},
m_ContextPool(STD_ALLOCATOR_RAW_MEM(PooledCommandContext, GetRawAllocator(), "Allocator for vector<PooledCommandContext>")),
- m_DynamicMemoryManager(GetRawAllocator(), *this, CreationAttribs.NumDynamicHeapPagesToReserve, CreationAttribs.DynamicHeapPageSize),
+ m_DynamicMemoryManager(GetRawAllocator(), *this, EngineCI.NumDynamicHeapPagesToReserve, EngineCI.DynamicHeapPageSize),
m_MipsGenerator(pd3d12Device)
{
m_DeviceCaps.DevType = DeviceType::D3D12;
@@ -318,12 +318,12 @@ void RenderDeviceD3D12Impl :: CreateBuffer(const BufferDesc& BuffDesc, const Buf
}
-void RenderDeviceD3D12Impl :: CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader** ppShader)
+void RenderDeviceD3D12Impl :: CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader)
{
- CreateDeviceObject( "shader", ShaderCreationAttribs.Desc, ppShader,
+ CreateDeviceObject( "shader", ShaderCI.Desc, ppShader,
[&]()
{
- ShaderD3D12Impl *pShaderD3D12( NEW_RC_OBJ(m_ShaderObjAllocator, "ShaderD3D12Impl instance", ShaderD3D12Impl)(this, ShaderCreationAttribs ) );
+ ShaderD3D12Impl *pShaderD3D12( NEW_RC_OBJ(m_ShaderObjAllocator, "ShaderD3D12Impl instance", ShaderD3D12Impl)(this, ShaderCI ) );
pShaderD3D12->QueryInterface( IID_Shader, reinterpret_cast<IObject**>(ppShader) );
OnCreateDeviceObject( pShaderD3D12 );
diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
index 82bf20dd..b5809eb5 100644
--- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
@@ -100,17 +100,17 @@ void RootSignature::RootParamsManager::AddRootView(D3D12_ROOT_PARAMETER_TYPE Par
Uint32 RootIndex,
UINT Register,
D3D12_SHADER_VISIBILITY Visibility,
- SHADER_VARIABLE_TYPE VarType)
+ SHADER_RESOURCE_VARIABLE_TYPE VarType)
{
auto *pRangePtr = Extend(0, 1, 0);
VERIFY_EXPR((char*)pRangePtr == (char*)m_pMemory.get() + GetRequiredMemorySize(0, 0, 0));
new(m_pRootViews + m_NumRootViews-1) RootParameter(ParameterType, RootIndex, Register, 0u, Visibility, VarType);
}
-void RootSignature::RootParamsManager::AddRootTable(Uint32 RootIndex,
- D3D12_SHADER_VISIBILITY Visibility,
- SHADER_VARIABLE_TYPE VarType,
- Uint32 NumRangesInNewTable)
+void RootSignature::RootParamsManager::AddRootTable(Uint32 RootIndex,
+ D3D12_SHADER_VISIBILITY Visibility,
+ SHADER_RESOURCE_VARIABLE_TYPE VarType,
+ Uint32 NumRangesInNewTable)
{
auto *pRangePtr = Extend(1, 0, NumRangesInNewTable);
VERIFY_EXPR( (char*)(pRangePtr + NumRangesInNewTable) == (char*)m_pMemory.get() + GetRequiredMemorySize(0, 0, 0));
@@ -267,8 +267,8 @@ void RootSignature::InitStaticSampler(SHADER_TYPE ShaderType
StreqSuff(SamplerName, StSmplr.SamplerDesc.SamplerOrTextureName, SamplerSuffix))
{
StSmplr.ShaderRegister = SamplerAttribs.BindPoint;
- StSmplr.ArraySize = SamplerAttribs.BindCount;
- StSmplr.RegisterSpace = 0;
+ StSmplr.ArraySize = SamplerAttribs.BindCount;
+ StSmplr.RegisterSpace = 0;
SamplerFound = true;
break;
}
@@ -283,6 +283,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,
const D3DShaderResourceAttribs& ShaderResAttribs,
+ SHADER_RESOURCE_VARIABLE_TYPE VariableType,
D3D12_DESCRIPTOR_RANGE_TYPE RangeType,
Uint32& RootIndex, // Output parameter
Uint32& OffsetFromTableStart // Output parameter
@@ -299,13 +300,13 @@ void RootSignature::AllocateResourceSlot(SHADER_TYPE ShaderT
OffsetFromTableStart = 0;
// Add new root view to existing root parameters
- m_RootParams.AddRootView(D3D12_ROOT_PARAMETER_TYPE_CBV, RootIndex, ShaderResAttribs.BindPoint, ShaderVisibility, ShaderResAttribs.GetVariableType());
+ m_RootParams.AddRootView(D3D12_ROOT_PARAMETER_TYPE_CBV, RootIndex, ShaderResAttribs.BindPoint, ShaderVisibility, VariableType);
}
else
{
// Use the same table for static and mutable resources. Treat both as static
- auto RootTableType = (ShaderResAttribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) ? SHADER_VARIABLE_TYPE_DYNAMIC : SHADER_VARIABLE_TYPE_STATIC;
- auto TableIndKey = ShaderInd * SHADER_VARIABLE_TYPE_NUM_TYPES + RootTableType;
+ 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;
// 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)
@@ -397,37 +398,36 @@ void RootSignature::dbgVerifyRootParameters()const
}
VERIFY(dbgTotalSrvCbvUavSlots ==
- m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_STATIC] +
- m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_MUTABLE] +
- m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC], "Unexpected number of SRV CBV UAV resource slots");
+ m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] +
+ m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] +
+ m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC], "Unexpected number of SRV CBV UAV resource slots");
VERIFY(dbgTotalSamplerSlots ==
- m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_STATIC] +
- m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_MUTABLE] +
- m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_DYNAMIC], "Unexpected number of sampler slots");
+ m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] +
+ m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] +
+ m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC], "Unexpected number of sampler slots");
VERIFY(dbgTotalRootViews ==
- m_TotalRootViews[SHADER_VARIABLE_TYPE_STATIC] +
- m_TotalRootViews[SHADER_VARIABLE_TYPE_MUTABLE] +
- m_TotalRootViews[SHADER_VARIABLE_TYPE_DYNAMIC], "Unexpected number of root views");
+ m_TotalRootViews[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] +
+ m_TotalRootViews[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] +
+ m_TotalRootViews[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC], "Unexpected number of root views");
}
#endif
-void RootSignature::AllocateStaticSamplers(IShader* const* ppShaders, Uint32 NumShaders)
+void RootSignature::AllocateStaticSamplers(const PipelineResourceLayoutDesc& ResourceLayout)
{
- Uint32 TotalSamplers = 0;
- for(Uint32 s=0;s < NumShaders; ++s)
- TotalSamplers += ppShaders[s]->GetDesc().NumStaticSamplers;
- if (TotalSamplers > 0)
+ if (ResourceLayout.NumStaticSamplers > 0)
{
- m_StaticSamplers.reserve(TotalSamplers);
- for(Uint32 sh=0;sh < NumShaders; ++sh)
+ m_StaticSamplers.reserve(ResourceLayout.NumStaticSamplers);
+ for(Uint32 sam=0; sam < ResourceLayout.NumStaticSamplers; ++sam)
{
- const auto& Desc = ppShaders[sh]->GetDesc();
- for(Uint32 sam=0; sam < Desc.NumStaticSamplers; ++sam)
+ const auto& StSamDesc = ResourceLayout.StaticSamplers[sam];
+ Uint32 ShaderStages = StSamDesc.ShaderStages;
+ while (ShaderStages != 0)
{
- m_StaticSamplers.emplace_back(Desc.StaticSamplers[sam], GetShaderVisibility(Desc.ShaderType));
+ auto Stage = ShaderStages & ~(ShaderStages-1);
+ m_StaticSamplers.emplace_back(StSamDesc, GetShaderVisibility(static_cast<SHADER_TYPE>(Stage)));
+ ShaderStages &= ~Stage;
}
}
- VERIFY_EXPR(m_StaticSamplers.size() == TotalSamplers);
}
}
@@ -530,7 +530,7 @@ void RootSignature::Finalize(ID3D12Device* pd3d12Device)
hr = pd3d12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), __uuidof(m_pd3d12RootSignature), reinterpret_cast<void**>( static_cast<ID3D12RootSignature**>(&m_pd3d12RootSignature)));
CHECK_D3D_RESULT_THROW(hr, "Failed to create root signature");
- bool bHasDynamicDescriptors = m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC] != 0 || m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_DYNAMIC] != 0;
+ bool bHasDynamicDescriptors = m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] != 0 || m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] != 0;
if(bHasDynamicDescriptors)
{
CommitDescriptorHandles = &RootSignature::CommitDescriptorHandlesInternal_SMD<false>;
@@ -581,11 +581,11 @@ void RootSignature::InitResourceCache(RenderDeviceD3D12Impl* pDeviceD3D12Impl
// Allocate space in GPU-visible descriptor heap for static and mutable variables only
Uint32 TotalSrvCbvUavDescriptors =
- m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_STATIC] +
- m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_MUTABLE];
+ m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] +
+ m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE];
Uint32 TotalSamplerDescriptors =
- m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_STATIC] +
- m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_MUTABLE];
+ m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] +
+ m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE];
DescriptorHeapAllocation CbcSrvUavHeapSpace, SamplerHeapSpace;
if(TotalSrvCbvUavDescriptors)
@@ -624,7 +624,7 @@ void RootSignature::InitResourceCache(RenderDeviceD3D12Impl* pDeviceD3D12Impl
#endif
// Space for dynamic variables is allocated at every draw call
- if( RootParam.GetShaderVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC )
+ if( RootParam.GetShaderVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC )
{
if( HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV )
{
@@ -886,8 +886,8 @@ void RootSignature::CommitDescriptorHandlesInternal_SMD(RenderDeviceD3D12Impl*
{
auto *pd3d12Device = pRenderDeviceD3D12->GetD3D12Device();
- Uint32 NumDynamicCbvSrvUavDescriptors = m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC];
- Uint32 NumDynamicSamplerDescriptors = m_TotalSamplerSlots [SHADER_VARIABLE_TYPE_DYNAMIC];
+ Uint32 NumDynamicCbvSrvUavDescriptors = m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC];
+ Uint32 NumDynamicSamplerDescriptors = m_TotalSamplerSlots [SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC];
VERIFY_EXPR(NumDynamicCbvSrvUavDescriptors > 0 || NumDynamicSamplerDescriptors > 0);
DescriptorHeapAllocation DynamicCbvSrvUavDescriptors, DynamicSamplerDescriptors;
@@ -920,7 +920,7 @@ void RootSignature::CommitDescriptorHandlesInternal_SMD(RenderDeviceD3D12Impl*
[&](Uint32 RootInd, const RootParameter& RootTable, const D3D12_ROOT_PARAMETER& D3D12Param, bool IsResourceTable, D3D12_DESCRIPTOR_HEAP_TYPE dbgHeapType)
{
D3D12_GPU_DESCRIPTOR_HANDLE RootTableGPUDescriptorHandle;
- bool IsDynamicTable = RootTable.GetShaderVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC;
+ bool IsDynamicTable = RootTable.GetShaderVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC;
if (IsDynamicTable)
{
if( IsResourceTable )
@@ -1008,7 +1008,7 @@ void RootSignature::CommitDescriptorHandlesInternal_SM(RenderDeviceD3D12Impl*
bool IsCompute,
bool ValidateStates)const
{
- VERIFY_EXPR(m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC] == 0 && m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_DYNAMIC] == 0);
+ VERIFY_EXPR(m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] == 0 && m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] == 0);
CommandContext::ShaderDescriptorHeaps Heaps(ResourceCache.GetSrvCbvUavDescriptorHeap(), ResourceCache.GetSamplerDescriptorHeap());
if(Heaps)
@@ -1017,7 +1017,7 @@ void RootSignature::CommitDescriptorHandlesInternal_SM(RenderDeviceD3D12Impl*
m_RootParams.ProcessRootTables(
[&](Uint32 RootInd, const RootParameter& RootTable, const D3D12_ROOT_PARAMETER& D3D12Param, bool IsResourceTable, D3D12_DESCRIPTOR_HEAP_TYPE dbgHeapType )
{
- VERIFY(RootTable.GetShaderVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC, "Unexpected dynamic resource");
+ VERIFY(RootTable.GetShaderVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC, "Unexpected dynamic resource");
D3D12_GPU_DESCRIPTOR_HANDLE RootTableGPUDescriptorHandle = IsResourceTable ?
ResourceCache.GetShaderVisibleTableGPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV>(RootInd) :
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
index bdaf41b0..ba069332 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
@@ -32,40 +32,23 @@
namespace Diligent
{
-ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters,
- RenderDeviceD3D12Impl* pRenderDeviceD3D12,
- const ShaderCreationAttribs& ShaderCreationAttribs) :
- TShaderBase(pRefCounters, pRenderDeviceD3D12, ShaderCreationAttribs.Desc),
- ShaderD3DBase(ShaderCreationAttribs),
- m_StaticResLayout(*this),
- m_StaticResCache(ShaderResourceCacheD3D12::DbgCacheContentType::StaticShaderResources),
- m_StaticVarsMgr(*this)
+ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters,
+ RenderDeviceD3D12Impl* pRenderDeviceD3D12,
+ const ShaderCreateInfo& ShaderCI) :
+ TShaderBase(pRefCounters, pRenderDeviceD3D12, ShaderCI.Desc),
+ ShaderD3DBase(ShaderCI)
{
// Load shader resources
auto& Allocator = GetRawAllocator();
auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(ShaderResourcesD3D12));
- auto* pResources = new (pRawMem) ShaderResourcesD3D12(m_pShaderByteCode, m_Desc, ShaderCreationAttribs.UseCombinedTextureSamplers ? ShaderCreationAttribs.CombinedSamplerSuffix : nullptr);
+ auto* pResources = new (pRawMem) ShaderResourcesD3D12(m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr);
m_pShaderResources.reset(pResources, STDDeleterRawMem<ShaderResourcesD3D12>(Allocator));
-
- // Clone only static resources that will be set directly in the shader
- // http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Special-Resource-Layout-for-Managing-Static-Shader-Resources
- SHADER_VARIABLE_TYPE VarTypes[] = {SHADER_VARIABLE_TYPE_STATIC};
- m_StaticResLayout.Initialize(pRenderDeviceD3D12->GetD3D12Device(), m_pShaderResources, GetRawAllocator(), VarTypes, _countof(VarTypes), &m_StaticResCache, nullptr);
- m_StaticVarsMgr.Initialize(m_StaticResLayout, GetRawAllocator(), nullptr, 0, m_StaticResCache);
}
ShaderD3D12Impl::~ShaderD3D12Impl()
{
- m_StaticVarsMgr.Destroy(GetRawAllocator());
}
IMPLEMENT_QUERY_INTERFACE( ShaderD3D12Impl, IID_ShaderD3D12, TShaderBase )
-#ifdef DEVELOPMENT
-bool ShaderD3D12Impl::DvpVerifyStaticResourceBindings()const
-{
- return m_StaticResLayout.dvpVerifyBindings(m_StaticResCache);
-}
-#endif
-
}
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
index c8fbaeca..644eb1ff 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp
@@ -52,15 +52,22 @@ ShaderResourceBindingD3D12Impl::ShaderResourceBindingD3D12Impl(IReferenceCounter
auto ShaderType = pShader->GetDesc().ShaderType;
auto ShaderInd = GetShaderTypeIndex(ShaderType);
- // Create shader variable manager in place
- new (m_pShaderVarMgrs + s) ShaderVariableManagerD3D12(*this);
-
auto& VarDataAllocator = pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s);
// http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Resource-Layouts-in-a-Shader-Resource-Binding-Object
- std::array<SHADER_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC };
+ const SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = { SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC };
const auto& SrcLayout = pPSO->GetShaderResLayout(s);
- m_pShaderVarMgrs[s].Initialize(SrcLayout, VarDataAllocator, AllowedVarTypes.data(), static_cast<Uint32>(AllowedVarTypes.size()), m_ShaderResourceCache);
+ // Create shader variable manager in place
+ new (m_pShaderVarMgrs + s)
+ ShaderVariableManagerD3D12
+ {
+ *this,
+ SrcLayout,
+ VarDataAllocator,
+ AllowedVarTypes,
+ _countof(AllowedVarTypes),
+ m_ShaderResourceCache
+ };
m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s);
}
@@ -96,7 +103,7 @@ void ShaderResourceBindingD3D12Impl::BindResources(Uint32 ShaderFlags, IResource
}
}
-IShaderVariable *ShaderResourceBindingD3D12Impl::GetVariable(SHADER_TYPE ShaderType, const char *Name)
+IShaderResourceVariable *ShaderResourceBindingD3D12Impl::GetVariable(SHADER_TYPE ShaderType, const char *Name)
{
auto ShaderInd = GetShaderTypeIndex(ShaderType);
auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
@@ -121,7 +128,7 @@ Uint32 ShaderResourceBindingD3D12Impl::GetVariableCount(SHADER_TYPE ShaderType)
return m_pShaderVarMgrs[ResLayoutInd].GetVariableCount();
}
-IShaderVariable* ShaderResourceBindingD3D12Impl::GetVariable(SHADER_TYPE ShaderType, Uint32 Index)
+IShaderResourceVariable* ShaderResourceBindingD3D12Impl::GetVariable(SHADER_TYPE ShaderType, Uint32 Index)
{
auto ShaderInd = GetShaderTypeIndex(ShaderType);
auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
@@ -173,23 +180,22 @@ void ShaderResourceBindingD3D12Impl::InitializeStaticResources(const IPipelineSt
auto* pPSO12 = ValidatedCast<const PipelineStateD3D12Impl>(pPSO);
auto NumShaders = pPSO12->GetNumShaders();
- auto ppShaders = pPSO12->GetShaders();
// Copy static resources
for (Uint32 s = 0; s < NumShaders; ++s)
{
- auto* pShader = ValidatedCast<ShaderD3D12Impl>( ppShaders[s] );
+ const auto& ShaderResLayout = pPSO12->GetShaderResLayout(s);
+ auto& StaticResLayout = pPSO12->GetStaticShaderResLayout(s);
+ auto& StaticResCache = pPSO12->GetStaticShaderResCache(s);
#ifdef DEVELOPMENT
- if (!pShader->DvpVerifyStaticResourceBindings())
+ if (!StaticResLayout.dvpVerifyBindings(StaticResCache))
{
+ auto* pShader = pPSO12->GetShader<ShaderD3D12Impl>(s);
LOG_ERROR_MESSAGE("Static resources in SRB of PSO '", pPSO12->GetDesc().Name, "' will not be successfully initialized "
"because not all static resource bindings in shader '", pShader->GetDesc().Name, "' are valid. "
"Please make sure you bind all static resources to the shader before calling InitializeStaticResources() "
"directly or indirectly by passing InitStaticResources=true to CreateShaderResourceBinding() method.");
}
#endif
- const auto& ShaderResLayout = pPSO12->GetShaderResLayout(s);
- auto& StaticResLayout = pShader->GetStaticResLayout();
- auto& StaticResCache = pShader->GetStaticResCache();
StaticResLayout.CopyStaticResourceDesriptorHandles(StaticResCache, ShaderResLayout, m_ShaderResourceCache);
}
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp
index eada5310..393c1c3b 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp
@@ -33,15 +33,11 @@
#include "ShaderD3D12Impl.h"
#include "RootSignature.h"
#include "PipelineStateD3D12Impl.h"
+#include "ShaderResourceVariableBase.h"
namespace Diligent
{
-ShaderResourceLayoutD3D12::ShaderResourceLayoutD3D12(IObject& Owner) :
- m_Owner(Owner)
-{
-}
-
ShaderResourceLayoutD3D12::~ShaderResourceLayoutD3D12()
{
for(Uint32 r=0; r < GetTotalResourceCount(); ++r)
@@ -78,20 +74,21 @@ D3D12_DESCRIPTOR_RANGE_TYPE GetDescriptorRangeType(CachedResourceType ResType)
return ResTypeToDescrRangeTypeMap[ResType];
}
-void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& Allocator,
- const std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount,
- const std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES>& SamplerCount)
+
+void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& Allocator,
+ const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount,
+ const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& SamplerCount)
{
m_CbvSrvUavOffsets[0] = 0;
- for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1))
+ for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1))
{
VERIFY(m_CbvSrvUavOffsets[VarType] + CbvSrvUavCount[VarType] <= std::numeric_limits<Uint16>::max(), "Offset is not representable in 16 bits" );
m_CbvSrvUavOffsets[VarType+1] = static_cast<Uint16>(m_CbvSrvUavOffsets[VarType] + CbvSrvUavCount[VarType]);
VERIFY_EXPR(GetCbvSrvUavCount(VarType) == CbvSrvUavCount[VarType]);
}
- m_SamplersOffsets[0] = m_CbvSrvUavOffsets[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))
+ m_SamplersOffsets[0] = m_CbvSrvUavOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES];
+ for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1))
{
VERIFY(m_SamplersOffsets[VarType] + SamplerCount[VarType] <= std::numeric_limits<Uint16>::max(), "Offset is not representable in 16 bits" );
m_SamplersOffsets[VarType+1] = static_cast<Uint16>(m_SamplersOffsets[VarType] + SamplerCount[VarType]);
@@ -102,94 +99,106 @@ void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator&
if(MemSize == 0)
return;
- auto *pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader resource layout resources", MemSize);
+ auto* pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader resource layout resources", MemSize);
m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void> >(pRawMem, Allocator);
}
// http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Shader-Resource-Layouts-and-Root-Signature-in-a-Pipeline-State-Object
// http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-cache#Initializing-Shader-Resource-Layouts-in-a-Pipeline-State
-void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* pd3d12Device,
- std::shared_ptr<const ShaderResourcesD3D12> pSrcResources,
- IMemoryAllocator& LayoutDataAllocator,
- const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- ShaderResourceCacheD3D12* pResourceCache,
- RootSignature* pRootSig)
+ShaderResourceLayoutD3D12::ShaderResourceLayoutD3D12(IObject& Owner,
+ ID3D12Device* pd3d12Device,
+ const PipelineResourceLayoutDesc& ResourceLayout,
+ std::shared_ptr<const ShaderResourcesD3D12> pSrcResources,
+ IMemoryAllocator& LayoutDataAllocator,
+ const SHADER_RESOURCE_VARIABLE_TYPE* const AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ ShaderResourceCacheD3D12* pResourceCache,
+ RootSignature* pRootSig) :
+ m_Owner (Owner),
+ m_pd3d12Device (pd3d12Device),
+ m_pResources (std::move(pSrcResources))
{
- m_pResources = std::move(pSrcResources);
- m_pd3d12Device = pd3d12Device;
-
VERIFY_EXPR( (pResourceCache != nullptr) ^ (pRootSig != nullptr) );
- Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
+ const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
- std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> CbvSrvUavCount = {};
- std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> SamplerCount = {};
+ std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CbvSrvUavCount = {};
+ std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> SamplerCount = {};
// Count number of resources to allocate all needed memory
m_pResources->ProcessResources(
- AllowedVarTypes, NumAllowedTypes,
-
[&](const D3DShaderResourceAttribs& CB, Uint32)
{
- VERIFY_EXPR(CB.IsAllowedType(AllowedTypeBits));
- ++CbvSrvUavCount[CB.GetVariableType()];
+ auto VarType = m_pResources->FindVariableType(CB, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ ++CbvSrvUavCount[VarType];
},
[&](const D3DShaderResourceAttribs& Sam, Uint32)
{
- VERIFY_EXPR(Sam.IsAllowedType(AllowedTypeBits));
- if (!Sam.IsStaticSampler())
+ auto VarType = m_pResources->FindVariableType(Sam, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
{
- ++SamplerCount[Sam.GetVariableType()];
+ auto StaticSamplerInd = m_pResources->FindStaticSampler(Sam, ResourceLayout);
+ // Skip static samplers
+ if (StaticSamplerInd < 0)
+ ++SamplerCount[VarType];
}
},
[&](const D3DShaderResourceAttribs& TexSRV, Uint32)
{
- VERIFY_EXPR(TexSRV.IsAllowedType(AllowedTypeBits));
- auto VarType = TexSRV.GetVariableType();
- ++CbvSrvUavCount[VarType];
- if(TexSRV.ValidSamplerAssigned())
+ auto VarType = m_pResources->FindVariableType(TexSRV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
{
- auto SamplerId = TexSRV.GetSamplerId();
- const auto& SamplerAttribs = m_pResources->GetSampler(SamplerId);
- DEV_CHECK_ERR(SamplerAttribs.GetVariableType() == TexSRV.GetVariableType(),
- "The type (", GetShaderVariableTypeLiteralName(TexSRV.GetVariableType()),") of texture SRV variable '", TexSRV.Name,
- "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SamplerAttribs.GetVariableType()),
- ") of the sampler '", SamplerAttribs.Name, "' that is assigned to it");
+ ++CbvSrvUavCount[VarType];
+ if (TexSRV.IsCombinedWithSampler())
+ {
+ const auto& SamplerAttribs = m_pResources->GetCombinedSampler(TexSRV);
+ auto SamplerVarType = m_pResources->FindVariableType(SamplerAttribs, ResourceLayout);
+ DEV_CHECK_ERR(SamplerVarType == VarType,
+ "The type (", GetShaderVariableTypeLiteralName(VarType),") of texture SRV variable '", TexSRV.Name,
+ "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SamplerVarType),
+ ") of the sampler '", SamplerAttribs.Name, "' that is assigned to it"); (void)SamplerVarType;
+ }
}
},
[&](const D3DShaderResourceAttribs& TexUAV, Uint32)
{
- VERIFY_EXPR(TexUAV.IsAllowedType(AllowedTypeBits));
- ++CbvSrvUavCount[TexUAV.GetVariableType()];
+ auto VarType = m_pResources->FindVariableType(TexUAV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ ++CbvSrvUavCount[VarType];
},
[&](const D3DShaderResourceAttribs& BufSRV, Uint32)
{
- VERIFY_EXPR(BufSRV.IsAllowedType(AllowedTypeBits));
- ++CbvSrvUavCount[BufSRV.GetVariableType()];
+ auto VarType = m_pResources->FindVariableType(BufSRV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ ++CbvSrvUavCount[VarType];
},
[&](const D3DShaderResourceAttribs& BufUAV, Uint32)
{
- VERIFY_EXPR(BufUAV.IsAllowedType(AllowedTypeBits));
- ++CbvSrvUavCount[BufUAV.GetVariableType()];
+ auto VarType = m_pResources->FindVariableType(BufUAV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ ++CbvSrvUavCount[VarType];
}
);
AllocateMemory(LayoutDataAllocator, CbvSrvUavCount, SamplerCount);
- std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> CurrCbvSrvUav = {};
- std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> CurrSampler = {};
+ std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CurrCbvSrvUav = {};
+ std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CurrSampler = {};
Uint32 StaticResCacheTblSizes[4] = {0, 0, 0, 0};
- auto AddResource = [&](const D3DShaderResourceAttribs& Attribs, CachedResourceType ResType, Uint32 SamplerId = D3D12Resource::InvalidSamplerId)
+ auto AddResource = [&](const D3DShaderResourceAttribs& Attribs,
+ CachedResourceType ResType,
+ SHADER_RESOURCE_VARIABLE_TYPE VarType,
+ Uint32 SamplerId = D3D12Resource::InvalidSamplerId)
{
Uint32 RootIndex = D3D12Resource::InvalidRootIndex;
Uint32 Offset = D3D12Resource::InvalidOffset;
D3D12_DESCRIPTOR_RANGE_TYPE DescriptorRangeType = GetDescriptorRangeType(ResType);
if (pRootSig)
{
- pRootSig->AllocateResourceSlot(m_pResources->GetShaderType(), Attribs, DescriptorRangeType, RootIndex, Offset );
+ pRootSig->AllocateResourceSlot(m_pResources->GetShaderType(), Attribs, VarType, DescriptorRangeType, RootIndex, Offset );
VERIFY(RootIndex <= D3D12Resource::MaxRootIndex, "Root index excceeds allowed limit");
}
else
@@ -214,92 +223,114 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device*
VERIFY(Offset != D3D12Resource::InvalidOffset, "Offset must be valid");
// Static samplers are never copied, and SamplerId == InvalidSamplerId
- auto VarType = Attribs.GetVariableType();
auto& NewResource = (ResType == CachedResourceType::Sampler) ?
GetSampler (VarType, CurrSampler [VarType]++) :
GetSrvCbvUav(VarType, CurrCbvSrvUav[VarType]++);
- ::new (&NewResource) D3D12Resource(*this, Attribs, ResType, RootIndex, Offset, SamplerId);
+ ::new (&NewResource) D3D12Resource(*this, Attribs, VarType, ResType, RootIndex, Offset, SamplerId);
};
m_pResources->ProcessResources(
- AllowedVarTypes, NumAllowedTypes,
-
[&](const D3DShaderResourceAttribs& CB, Uint32)
{
- VERIFY_EXPR( CB.IsAllowedType(AllowedTypeBits) );
- AddResource(CB, CachedResourceType::CBV);
+ auto VarType = m_pResources->FindVariableType(CB, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ AddResource(CB, CachedResourceType::CBV, VarType);
},
[&](const D3DShaderResourceAttribs& Sam, Uint32)
{
- VERIFY_EXPR( Sam.IsAllowedType(AllowedTypeBits) );
- if (Sam.IsStaticSampler())
- {
- if (pRootSig != nullptr)
- pRootSig->InitStaticSampler(m_pResources->GetShaderType(), Sam.Name, m_pResources->GetCombinedSamplerSuffix(), Sam);
- }
- else
+ auto VarType = m_pResources->FindVariableType(Sam, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
{
- AddResource(Sam, CachedResourceType::Sampler);
+ auto StaticSamplerInd = m_pResources->FindStaticSampler(Sam, ResourceLayout);
+ if (StaticSamplerInd >= 0)
+ {
+ if (pRootSig != nullptr)
+ pRootSig->InitStaticSampler(m_pResources->GetShaderType(), Sam.Name, m_pResources->GetCombinedSamplerSuffix(), Sam);
+ }
+ else
+ {
+ AddResource(Sam, CachedResourceType::Sampler, VarType);
+ }
}
},
[&](const D3DShaderResourceAttribs& TexSRV, Uint32)
{
- VERIFY_EXPR(TexSRV.IsAllowedType(AllowedTypeBits) );
- static_assert(SHADER_VARIABLE_TYPE_NUM_TYPES == 3, "Unexpected number of shader variable types");
- VERIFY(CurrSampler[SHADER_VARIABLE_TYPE_STATIC] + CurrSampler[SHADER_VARIABLE_TYPE_MUTABLE] + CurrSampler[SHADER_VARIABLE_TYPE_DYNAMIC] == GetTotalSamplerCount(), "All samplers must be initialized before texture SRVs");
-
- Uint32 SamplerId = D3D12Resource::InvalidSamplerId;
- if (TexSRV.ValidSamplerAssigned())
+ auto VarType = m_pResources->FindVariableType(TexSRV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
{
- const auto& SamplerAttribs = m_pResources->GetSampler(TexSRV.GetSamplerId());
- DEV_CHECK_ERR(SamplerAttribs.GetVariableType() == TexSRV.GetVariableType(),
- "The type (", GetShaderVariableTypeLiteralName(TexSRV.GetVariableType()),") of texture SRV variable '", TexSRV.Name,
- "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SamplerAttribs.GetVariableType()),
- ") of the sampler '", SamplerAttribs.Name, "' that is assigned to it");
-
- if (SamplerAttribs.IsStaticSampler())
- {
- // Static samplers are never copied, and SamplerId == InvalidSamplerId
- }
- else
+ static_assert(SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES == 3, "Unexpected number of shader variable types");
+ VERIFY(CurrSampler[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] + CurrSampler[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] + CurrSampler[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] == GetTotalSamplerCount(), "All samplers must be initialized before texture SRVs");
+
+ Uint32 SamplerId = D3D12Resource::InvalidSamplerId;
+ if (TexSRV.IsCombinedWithSampler())
{
- auto SamplerCount = GetTotalSamplerCount();
- for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId)
+ const auto& SamplerAttribs = m_pResources->GetCombinedSampler(TexSRV);
+ auto SamplerVarType = m_pResources->FindVariableType(SamplerAttribs, ResourceLayout);
+ DEV_CHECK_ERR(SamplerVarType == VarType,
+ "The type (", GetShaderVariableTypeLiteralName(VarType),") of texture SRV variable '", TexSRV.Name,
+ "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SamplerVarType),
+ ") of the sampler '", SamplerAttribs.Name, "' that is assigned to it");
+
+ auto StaticSamplerInd = m_pResources->FindStaticSampler(SamplerAttribs, ResourceLayout);
+ if (StaticSamplerInd >= 0)
{
- const auto& Sampler = GetSampler(SamplerId);
- if (strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0)
- break;
+ // Static samplers are never copied, and SamplerId == InvalidSamplerId
+#ifdef _DEBUG
+ auto SamplerCount = GetTotalSamplerCount();
+ for (Uint32 s = 0; s < SamplerCount; ++s)
+ {
+ const auto& Sampler = GetSampler(s);
+ if (strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0)
+ LOG_ERROR("Static sampler '", Sampler.Attribs.Name, "' was found among resources. This seems to be a bug");
+ }
+#endif
}
- if (SamplerId == SamplerCount)
+ else
{
- LOG_ERROR("Unable to find sampler '", SamplerAttribs.Name, "' assigned to texture SRV '", TexSRV.Name, "' in the list of already created resources. This seems to be a bug.");
- SamplerId = D3D12Resource::InvalidSamplerId;
+ auto SamplerCount = GetTotalSamplerCount();
+ bool SamplerFound = false;
+ for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId)
+ {
+ const auto& Sampler = GetSampler(SamplerId);
+ SamplerFound = strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0;
+ if (SamplerFound)
+ break;
+ }
+
+ if (!SamplerFound)
+ {
+ LOG_ERROR("Unable to find sampler '", SamplerAttribs.Name, "' assigned to texture SRV '", TexSRV.Name, "' in the list of already created resources. This seems to be a bug.");
+ SamplerId = D3D12Resource::InvalidSamplerId;
+ }
+ VERIFY(SamplerId <= D3D12Resource::MaxSamplerId, "Sampler index excceeds allowed limit");
}
- VERIFY(SamplerId <= D3D12Resource::MaxSamplerId, "Sampler index excceeds allowed limit");
}
+ AddResource(TexSRV, CachedResourceType::TexSRV, VarType, SamplerId);
}
- AddResource(TexSRV, CachedResourceType::TexSRV, SamplerId);
},
[&](const D3DShaderResourceAttribs& TexUAV, Uint32)
{
- VERIFY_EXPR( TexUAV.IsAllowedType(AllowedTypeBits) );
- AddResource(TexUAV, CachedResourceType::TexUAV);
+ auto VarType = m_pResources->FindVariableType(TexUAV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ AddResource(TexUAV, CachedResourceType::TexUAV, VarType);
},
[&](const D3DShaderResourceAttribs& BufSRV, Uint32)
{
- VERIFY_EXPR( BufSRV.IsAllowedType(AllowedTypeBits) );
- AddResource(BufSRV, CachedResourceType::BufSRV);
+ auto VarType = m_pResources->FindVariableType(BufSRV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ AddResource(BufSRV, CachedResourceType::BufSRV, VarType);
},
[&](const D3DShaderResourceAttribs& BufUAV, Uint32)
{
- VERIFY_EXPR( BufUAV.IsAllowedType(AllowedTypeBits) );
- AddResource(BufUAV, CachedResourceType::BufUAV);
+ auto VarType = m_pResources->FindVariableType(BufUAV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ AddResource(BufUAV, CachedResourceType::BufUAV, VarType);
}
);
#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))
+ for(SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1))
{
VERIFY( CurrCbvSrvUav[VarType] == CbvSrvUavCount[VarType], "Not all Srv/Cbv/Uavs are initialized, which result in a crash when dtor is called" );
VERIFY( CurrSampler[VarType] == SamplerCount [VarType], "Not all Samplers are initialized, which result in a crash when dtor is called" );
@@ -326,7 +357,7 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device*
#define LOG_RESOURCE_BINDING_ERROR(ResType, pResource, VarName, ShaderName, ...)\
{ \
- const auto &ResName = pResource->GetDesc().Name; \
+ const auto& ResName = pResource->GetDesc().Name; \
LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " '", ResName, "' to variable '", VarName, \
"' in shader '", ShaderName, "'. ", __VA_ARGS__ ); \
}
@@ -347,11 +378,11 @@ void ShaderResourceLayoutD3D12::D3D12Resource::CacheCB(IDeviceObject*
{
if (pBuffD3D12->GetDesc().BindFlags & BIND_UNIFORM_BUFFER)
{
- if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr)
+ if (GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr)
{
if (DstRes.pObject != pBuffD3D12)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetVariableType());
LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayInd), "' in shader '", ParentResLayout.GetShaderName(), "'. Attempting to bind another constant buffer is an error and will be ignored. Use another shader resource binding instance or label the variable as dynamic." );
}
@@ -429,19 +460,21 @@ void ShaderResourceLayoutD3D12::D3D12Resource::CacheResourceView(IDeviceObject*
auto ViewType = ViewDesc.ViewType;
if (ViewType != dbgExpectedViewType)
{
- const auto *ExpectedViewTypeName = GetViewTypeLiteralName( dbgExpectedViewType );
- const auto *ActualViewTypeName = GetViewTypeLiteralName( ViewType );
+ const auto* ExpectedViewTypeName = GetViewTypeLiteralName( dbgExpectedViewType );
+ const auto* ActualViewTypeName = GetViewTypeLiteralName( ViewType );
LOG_RESOURCE_BINDING_ERROR(ResourceViewTraits<TResourceViewType>::Name, pViewD3D12, Attribs.GetPrintName(ArrayIndex), ParentResLayout.GetShaderName(),
"Incorrect view type: ", ExpectedViewTypeName, " is expected, ", ActualViewTypeName, " provided." );
return;
}
#endif
- if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr)
+ if (GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr)
{
if (DstRes.pObject != pViewD3D12)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
- LOG_ERROR_MESSAGE( "Non-null resource is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and will be ignored. Use another shader resource binding instance or label the variable as dynamic." );
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetVariableType());
+ LOG_ERROR_MESSAGE( "Non-null resource is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '",
+ ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and will be "
+ "ignored. Use another shader resource binding instance or label the variable as dynamic." );
}
// Do not update resource if one is already bound unless it is dynamic. This may be
@@ -484,11 +517,11 @@ void ShaderResourceLayoutD3D12::D3D12Resource::CacheSampler(IDeviceObject*
RefCntAutoPtr<ISamplerD3D12> pSamplerD3D12(pSampler, IID_SamplerD3D12);
if (pSamplerD3D12)
{
- if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstSam.pObject != nullptr)
+ if (GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC && DstSam.pObject != nullptr)
{
if (DstSam.pObject != pSampler)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetVariableType());
LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler is an error and will be ignored. Use another shader resource binding instance or label the variable as dynamic." );
}
@@ -525,7 +558,7 @@ const ShaderResourceLayoutD3D12::D3D12Resource& ShaderResourceLayoutD3D12::GetAs
VERIFY(TexSrv.GetResType() == CachedResourceType::TexSRV, "Unexpected resource type: texture SRV is expected");
VERIFY(TexSrv.ValidSamplerAssigned(), "Texture SRV has no associated sampler");
const auto& SamInfo = GetSampler(TexSrv.SamplerId);
- VERIFY(SamInfo.Attribs.GetVariableType() == TexSrv.Attribs.GetVariableType(), "Inconsistent texture and sampler variable types");
+ VERIFY(SamInfo.GetVariableType() == TexSrv.GetVariableType(), "Inconsistent texture and sampler variable types");
VERIFY(StreqSuff(SamInfo.Attribs.Name, TexSrv.Attribs.Name, m_pResources->GetCombinedSamplerSuffix()), "Sampler name '", SamInfo.Attribs.Name, "' does not match texture name '", TexSrv.Attribs.Name, '\'');
return SamInfo;
}
@@ -563,7 +596,7 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject*
}
else
{
- if(Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC)
+ if(GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call");
else
VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space");
@@ -587,10 +620,10 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject*
case CachedResourceType::TexSRV:
CacheResourceView<ITextureViewD3D12>(pObj, DstRes, ArrayIndex, ShdrVisibleHeapCPUDescriptorHandle, TEXTURE_VIEW_SHADER_RESOURCE, [&](ITextureViewD3D12* pTexView)
{
- if(ValidSamplerAssigned())
+ if (ValidSamplerAssigned())
{
auto& Sam = ParentResLayout.GetAssignedSampler(*this);
- VERIFY( !Sam.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" );
+ //VERIFY( !Sam.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" );
VERIFY_EXPR(Attribs.BindCount == Sam.Attribs.BindCount || Sam.Attribs.BindCount == 1);
auto SamplerArrInd = Sam.Attribs.BindCount > 1 ? ArrayIndex : 0;
auto ShdrVisibleSamplerHeapCPUDescriptorHandle = ResourceCache.GetShaderVisibleTableCPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER>(Sam.RootIndex, Sam.OffsetFromTableStart + SamplerArrInd);
@@ -603,7 +636,7 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject*
}
else if (ResourceCache.DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::SRBResources)
{
- if(Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC)
+ if(GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
VERIFY(ShdrVisibleSamplerHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call");
else
VERIFY(ShdrVisibleSamplerHeapCPUDescriptorHandle.ptr != 0 || pTexView == nullptr, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space");
@@ -649,7 +682,7 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject*
}
else
{
- if (DstRes.pObject != nullptr && Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (DstRes.pObject != nullptr && GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
LOG_ERROR_MESSAGE( "Shader variable '", Attribs.Name, "' in shader '", ParentResLayout.GetShaderName(), "' is not dynamic but is being reset to null. This is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic if you need to bind another resource." );
DstRes = ShaderResourceCacheD3D12::Resource{};
@@ -659,7 +692,7 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject*
D3D12_CPU_DESCRIPTOR_HANDLE NullHandle = {0};
auto SamplerArrInd = Sam.Attribs.BindCount > 1 ? ArrayIndex : 0;
auto& DstSam = ResourceCache.GetRootTable(Sam.RootIndex).GetResource(Sam.OffsetFromTableStart + SamplerArrInd, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, ParentResLayout.m_pResources->GetShaderType());
- if (DstSam.pObject != nullptr && Sam.Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (DstSam.pObject != nullptr && Sam.GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
LOG_ERROR_MESSAGE( "Sampler variable '", Sam.Attribs.Name, "' in shader '", ParentResLayout.GetShaderName(), "' is not dynamic but is being reset to null. This is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic if you need to bind another sampler." );
DstSam = ShaderResourceCacheD3D12::Resource{};
}
@@ -699,13 +732,13 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR
// Samplers at root index D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER
// Every resource is stored at offset that equals resource bind point
- auto CbvSrvUavCount = DstLayout.GetCbvSrvUavCount(SHADER_VARIABLE_TYPE_STATIC);
- VERIFY(GetCbvSrvUavCount(SHADER_VARIABLE_TYPE_STATIC) == CbvSrvUavCount, "Number of static resources in the source cache (", GetCbvSrvUavCount(SHADER_VARIABLE_TYPE_STATIC), ") is not consistent with the number of static resources in destination cache (", CbvSrvUavCount, ")" );
+ auto CbvSrvUavCount = DstLayout.GetCbvSrvUavCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
+ VERIFY(GetCbvSrvUavCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC) == CbvSrvUavCount, "Number of static resources in the source cache (", GetCbvSrvUavCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC), ") is not consistent with the number of static resources in destination cache (", CbvSrvUavCount, ")" );
for(Uint32 r=0; r < CbvSrvUavCount; ++r)
{
// Get resource attributes
- const auto& res = DstLayout.GetSrvCbvUav(SHADER_VARIABLE_TYPE_STATIC, r);
+ const auto& res = DstLayout.GetSrvCbvUav(SHADER_RESOURCE_VARIABLE_TYPE_STATIC, r);
auto RangeType = GetDescriptorRangeType(res.GetResType());
for(Uint32 ArrInd = 0; ArrInd < res.Attribs.BindCount; ++ArrInd)
{
@@ -716,7 +749,7 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR
// D3D12_DESCRIPTOR_RANGE_TYPE_CBV = 2
const auto& SrcRes = SrcCache.GetRootTable(RangeType).GetResource(BindPoint, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, m_pResources->GetShaderType());
if( !SrcRes.pObject )
- LOG_ERROR_MESSAGE( "No resource assigned to static shader variable '", res.Attribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'." );
+ LOG_ERROR_MESSAGE( "No resource is assigned to static shader variable '", res.Attribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'." );
// Destination resource is at the root index and offset defined by the resource layout
auto& DstRes = DstCache.GetRootTable(res.RootIndex).GetResource(res.OffsetFromTableStart + ArrInd, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, m_pResources->GetShaderType());
@@ -748,18 +781,18 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR
{
const auto& SamInfo = DstLayout.GetAssignedSampler(res);
- VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache");
+ //VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache");
VERIFY(SamInfo.Attribs.IsValidBindPoint(), "Sampler bind point must be valid");
VERIFY_EXPR(SamInfo.Attribs.BindCount == res.Attribs.BindCount || SamInfo.Attribs.BindCount == 1);
}
}
- auto SamplerCount = DstLayout.GetSamplerCount(SHADER_VARIABLE_TYPE_STATIC);
- VERIFY(GetSamplerCount(SHADER_VARIABLE_TYPE_STATIC) == SamplerCount, "Number of static-type samplers in the source cache (", GetSamplerCount(SHADER_VARIABLE_TYPE_STATIC), ") is not consistent with the number of static-type samplers in destination cache (", SamplerCount, ")" );
+ auto SamplerCount = DstLayout.GetSamplerCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
+ VERIFY(GetSamplerCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC) == SamplerCount, "Number of static-type samplers in the source cache (", GetSamplerCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC), ") is not consistent with the number of static-type samplers in destination cache (", SamplerCount, ")" );
for(Uint32 s=0; s < SamplerCount; ++s)
{
- const auto& SamInfo = DstLayout.GetSampler(SHADER_VARIABLE_TYPE_STATIC, s);
+ const auto& SamInfo = DstLayout.GetSampler(SHADER_RESOURCE_VARIABLE_TYPE_STATIC, s);
for(Uint32 ArrInd = 0; ArrInd < SamInfo.Attribs.BindCount; ++ArrInd)
{
auto BindPoint = SamInfo.Attribs.BindPoint + ArrInd;
@@ -768,7 +801,7 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR
const auto& SrcSampler = SrcCache.GetRootTable(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER).GetResource(BindPoint, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, m_pResources->GetShaderType());
if( !SrcSampler.pObject )
LOG_ERROR_MESSAGE( "No sampler assigned to static shader variable '", SamInfo.Attribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'." );
- auto &DstSampler = DstCache.GetRootTable(SamInfo.RootIndex).GetResource(SamInfo.OffsetFromTableStart + ArrInd, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, m_pResources->GetShaderType());
+ auto& DstSampler = DstCache.GetRootTable(SamInfo.RootIndex).GetResource(SamInfo.OffsetFromTableStart + ArrInd, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, m_pResources->GetShaderType());
if(DstSampler.pObject != SrcSampler.pObject)
{
@@ -800,12 +833,12 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR
bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12& ResourceCache)const
{
bool BindingsOK = true;
- for (SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1))
+ for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1))
{
for (Uint32 r=0; r < GetCbvSrvUavCount(VarType); ++r)
{
const auto& res = GetSrvCbvUav(VarType, r);
- VERIFY(res.Attribs.GetVariableType() == VarType, "Unexpected variable type");
+ VERIFY(res.GetVariableType() == VarType, "Unexpected variable type");
for (Uint32 ArrInd = 0; ArrInd < res.Attribs.BindCount; ++ArrInd)
{
@@ -819,7 +852,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12
// Dynamic buffers do not have CPU descriptor handle as they do not keep D3D12 buffer, and space is allocated from the GPU ring buffer
CachedRes.CPUDescriptorHandle.ptr == 0 && !(CachedRes.Type==CachedResourceType::CBV && CachedRes.pObject.RawPtr<const BufferD3D12Impl>()->GetDesc().Usage == USAGE_DYNAMIC) )
{
- LOG_ERROR_MESSAGE( "No resource is bound to ", GetShaderVariableTypeLiteralName(res.Attribs.GetVariableType()), " variable '", res.Attribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'" );
+ LOG_ERROR_MESSAGE( "No resource is bound to ", GetShaderVariableTypeLiteralName(res.GetVariableType()), " variable '", res.Attribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'" );
BindingsOK = false;
}
@@ -857,7 +890,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12
}
else
{
- if (res.Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (res.GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call");
else
VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space");
@@ -875,7 +908,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12
{
VERIFY(res.GetResType() == CachedResourceType::TexSRV, "Sampler can only be assigned to a texture SRV" );
const auto& SamInfo = GetAssignedSampler(res);
- VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" );
+ //VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" );
VERIFY(SamInfo.Attribs.IsValidBindPoint(), "Sampler bind point must be valid");
for (Uint32 ArrInd = 0; ArrInd < SamInfo.Attribs.BindCount; ++ArrInd)
@@ -900,7 +933,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12
}
else if (ResourceCache.DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::SRBResources)
{
- if (SamInfo.Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (SamInfo.GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call");
else
VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space");
@@ -918,7 +951,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12
for (Uint32 s=0; s < GetSamplerCount(VarType); ++s)
{
const auto& sam = GetSampler(VarType, s);
- VERIFY(sam.Attribs.GetVariableType() == VarType, "Unexpected sampler variable type");
+ VERIFY(sam.GetVariableType() == VarType, "Unexpected sampler variable type");
for (Uint32 ArrInd = 0; ArrInd < sam.Attribs.BindCount; ++ArrInd)
{
@@ -940,35 +973,4 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12
}
#endif
-const Char* ShaderResourceLayoutD3D12::GetShaderName()const
-{
- RefCntAutoPtr<IShader> pShader(&m_Owner, IID_Shader);
- if (pShader)
- {
- return pShader->GetDesc().Name;
- }
- else
- {
- RefCntAutoPtr<IPipelineState> pPSO(&m_Owner, IID_PipelineState);
- if(pPSO)
- {
- auto* pPSOD3D12 = pPSO.RawPtr<PipelineStateD3D12Impl>();
- auto* ppShaders = pPSOD3D12->GetShaders();
- auto NumShaders = pPSOD3D12->GetNumShaders();
- for (Uint32 s = 0; s < NumShaders; ++s)
- {
- const auto& ShaderDesc = ppShaders[s]->GetDesc();
- if(ShaderDesc.ShaderType == m_pResources->GetShaderType())
- return ShaderDesc.Name;
- }
- UNEXPECTED("Shader not found");
- }
- else
- {
- UNEXPECTED("Shader resource layout owner is expected to be a shader or a pipeline state");
- }
- }
- return "";
-}
-
}
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
index efb6602a..2504d198 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
@@ -48,7 +48,7 @@ ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode, const Shad
Initialize<D3D12_SHADER_DESC, D3D12_SHADER_INPUT_BIND_DESC, ID3D12ShaderReflection>(
pShaderBytecode,
NewResourceHandler{},
- ShdrDesc,
+ ShdrDesc.Name,
CombinedSamplerSuffix
);
}
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
index 35bd4d81..de8e9855 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
@@ -24,18 +24,19 @@
#include "pch.h"
#include "ShaderVariableD3D12.h"
+#include "ShaderResourceVariableBase.h"
namespace Diligent
{
-size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const ShaderResourceLayoutD3D12& Layout,
- const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- Uint32& NumVariables)
+size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const ShaderResourceLayoutD3D12& Layout,
+ const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ Uint32& NumVariables)
{
NumVariables = 0;
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))
+ for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1))
{
if (IsAllowedType(VarType, AllowedTypeBits))
{
@@ -49,18 +50,19 @@ size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const ShaderResourceLay
}
// Creates shader variable for every resource from SrcLayout whose type is one AllowedVarTypes
-void ShaderVariableManagerD3D12::Initialize(const ShaderResourceLayoutD3D12& SrcLayout,
- IMemoryAllocator& Allocator,
- const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- ShaderResourceCacheD3D12& ResourceCache)
-{
- m_pResourceLayout = &SrcLayout;
- m_pResourceCache = &ResourceCache;
+ShaderVariableManagerD3D12::ShaderVariableManagerD3D12(IObject& Owner,
+ const ShaderResourceLayoutD3D12& SrcLayout,
+ IMemoryAllocator& Allocator,
+ const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ ShaderResourceCacheD3D12& ResourceCache) :
+ m_Owner (Owner),
+ m_ResourceCache (ResourceCache)
#ifdef _DEBUG
- m_pDbgAllocator = &Allocator;
+ , m_DbgAllocator (Allocator)
#endif
+{
const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
VERIFY_EXPR(m_NumVariables == 0);
auto MemSize = GetRequiredMemorySize(SrcLayout, AllowedVarTypes, NumAllowedTypes, m_NumVariables);
@@ -72,7 +74,7 @@ void ShaderVariableManagerD3D12::Initialize(const ShaderResourceLayoutD3D12& Src
m_pVariables = reinterpret_cast<ShaderVariableD3D12Impl*>(pRawMem);
Uint32 VarInd = 0;
- for (SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1))
+ for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1))
{
if (!IsAllowedType(VarType, AllowedTypeBits))
continue;
@@ -106,7 +108,7 @@ ShaderVariableManagerD3D12::~ShaderVariableManagerD3D12()
void ShaderVariableManagerD3D12::Destroy(IMemoryAllocator &Allocator)
{
- VERIFY(m_pDbgAllocator == &Allocator, "Incosistent alloctor");
+ VERIFY(&m_DbgAllocator == &Allocator, "Incosistent alloctor");
if(m_pVariables != nullptr)
{
@@ -166,7 +168,6 @@ Uint32 ShaderVariableManagerD3D12::GetVariableIndex(const ShaderVariableD3D12Imp
void ShaderVariableManagerD3D12::BindResources( IResourceMapping* pResourceMapping, Uint32 Flags)
{
- VERIFY_EXPR(m_pResourceCache != nullptr);
DEV_CHECK_ERR(pResourceMapping != nullptr, "Failed to bind resources: resource mapping is null");
if ( (Flags & BIND_SHADER_RESOURCES_UPDATE_ALL) == 0 )
@@ -177,12 +178,12 @@ void ShaderVariableManagerD3D12::BindResources( IResourceMapping* pResourceMappi
auto &Var = m_pVariables[v];
const auto& Res = Var.m_Resource;
- if ( (Flags & (1 << Res.Attribs.GetVariableType())) == 0 )
+ if ( (Flags & (1 << Res.GetVariableType())) == 0 )
continue;
for (Uint32 ArrInd = 0; ArrInd < Res.Attribs.BindCount; ++ArrInd)
{
- if( (Flags & BIND_SHADER_RESOURCES_KEEP_EXISTING) && Res.IsBound(ArrInd, *m_pResourceCache) )
+ if( (Flags & BIND_SHADER_RESOURCES_KEEP_EXISTING) && Res.IsBound(ArrInd, m_ResourceCache) )
continue;
RefCntAutoPtr<IDeviceObject> pObj;
@@ -191,11 +192,11 @@ void ShaderVariableManagerD3D12::BindResources( IResourceMapping* pResourceMappi
if ( pObj )
{
// Call non-virtual function
- Res.BindResource(pObj, ArrInd, *m_pResourceCache);
+ Res.BindResource(pObj, ArrInd, m_ResourceCache);
}
else
{
- if( (Flags & BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED) && !Res.IsBound(ArrInd, *m_pResourceCache) )
+ if( (Flags & BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED) && !Res.IsBound(ArrInd, m_ResourceCache) )
LOG_ERROR_MESSAGE( "Unable to bind resource to shader variable '", Res.Attribs.GetPrintName(ArrInd), "': resource is not found in the resource mapping" );
}
}