From 5b22be322244bc4368bffd4c34ba2516d638282e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 3 Mar 2019 21:56:38 -0800 Subject: Cleaned up QueryInterface declaration in D3D12 backend --- Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h | 4 ++-- Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') 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..438014e3 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h @@ -60,7 +60,7 @@ public: 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..35cd4e7e 100644 --- a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h @@ -47,7 +47,7 @@ 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;} diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h index 7f53cb26..f9e4d3aa 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h @@ -54,13 +54,13 @@ public: 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; 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/ShaderResourceBindingD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h index 4f2cdef5..aed47701 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h @@ -49,7 +49,7 @@ 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; 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();} -- cgit v1.2.3 From 2f468cbac64474c16a87c2fd6f8c8bb06f3f7d0f Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 3 Mar 2019 22:41:15 -0800 Subject: Updated ShaderResourceLayoutD3D12 and few other objects in D3D12 backend to comply with the new API --- .../GraphicsEngineD3D12/include/RootSignature.h | 82 +++--- .../GraphicsEngineD3D12/include/ShaderD3D12Impl.h | 37 +-- .../include/ShaderResourceBindingD3D12Impl.h | 4 +- .../include/ShaderResourceLayoutD3D12.h | 87 +++--- .../include/ShaderVariableD3D12.h | 28 +- .../src/PipelineStateD3D12Impl.cpp | 8 +- Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 54 ++-- .../GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp | 29 +- .../src/ShaderResourceBindingD3D12Impl.cpp | 6 +- .../src/ShaderResourceLayoutD3D12.cpp | 301 +++++++++++---------- .../src/ShaderResourcesD3D12.cpp | 2 +- .../src/ShaderVariableD3D12.cpp | 25 +- 12 files changed, 317 insertions(+), 346 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/RootSignature.h b/Graphics/GraphicsEngineD3D12/include/RootSignature.h index fbf17f4d..ebe2083e 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(-1); - D3D12_ROOT_PARAMETER m_RootParam = {}; - Uint32 m_DescriptorTableSize = 0; - Uint32 m_RootIndex = static_cast(-1); + SHADER_RESOURCE_VARIABLE_TYPE m_ShaderVarType = static_cast(-1); + D3D12_ROOT_PARAMETER m_RootParam = {}; + Uint32 m_DescriptorTableSize = 0; + Uint32 m_RootIndex = static_cast(-1); }; @@ -330,15 +330,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 +359,9 @@ private: std::vector > GetCacheTableSizes()const; - std::array m_TotalSrvCbvUavSlots = {}; - std::array m_TotalSamplerSlots = {}; - std::array m_TotalRootViews = {}; + std::array m_TotalSrvCbvUavSlots = {}; + std::array m_TotalSamplerSlots = {}; + std::array m_TotalRootViews = {}; CComPtr m_pd3d12RootSignature; @@ -402,16 +402,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 +446,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 m_SrvCbvUavRootTablesMap; + std::array m_SrvCbvUavRootTablesMap; // This array contains the same data for Sampler root table - std::array m_SamplerRootTablesMap; + std::array m_SamplerRootTablesMap; RootParamsManager m_RootParams; diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h index 8f80e54b..674beafb 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h @@ -45,49 +45,20 @@ class ShaderD3D12Impl final : public ShaderBase; - 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 BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override final - { - m_StaticVarsMgr.BindResources(pResourceMapping, Flags); - } - - virtual IShaderVariable* GetShaderVariable(const Char* Name)override final - { - return m_StaticVarsMgr.GetVariable(Name); - } - - virtual Uint32 GetVariableCount() const override final - { - return m_StaticVarsMgr.GetVariableCount(); - } - - virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final - { - return m_StaticVarsMgr.GetVariable(Index); - } + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; ID3DBlob* GetShaderByteCode(){return m_pShaderByteCode;} const std::shared_ptr& 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 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 aed47701..b45514da 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h @@ -53,11 +53,11 @@ public: 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; diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h index e734cf5c..2ae5c927 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 @@ -118,16 +117,16 @@ 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). + // The method is called to + // - 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 void Initialize(ID3D12Device* pd3d12Device, + const PipelineResourceLayoutDesc& ResourceLayout, std::shared_ptr pSrcResources, IMemoryAllocator& LayoutDataAllocator, - const SHADER_VARIABLE_TYPE* VarTypes, + const SHADER_RESOURCE_VARIABLE_TYPE* const VarTypes, Uint32 NumAllowedTypes, ShaderResourceCacheD3D12* pResourceCache, class RootSignature* pRootSig); @@ -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(-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(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(_ResType)), + VariableType (static_cast(_VariableType)), RootIndex (static_cast(_RootIndex)), SamplerId (static_cast(_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( ResourceType ); } + SHADER_RESOURCE_VARIABLE_TYPE GetVariableType() const { return static_cast(VariableType); } private: void CacheCB(IDeviceObject* pBuffer, @@ -224,21 +231,21 @@ 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)); @@ -250,20 +257,24 @@ 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 +290,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,12 +320,12 @@ private: } void AllocateMemory(IMemoryAllocator& Allocator, - const std::array& CbvSrvUavCount, - const std::array& SamplerCount); + const std::array& CbvSrvUavCount, + const std::array& SamplerCount); std::unique_ptr > m_ResourceBuffer; - std::array m_CbvSrvUavOffsets = {}; - std::array m_SamplersOffsets = {}; + std::array m_CbvSrvUavOffsets = {}; + std::array m_SamplersOffsets = {}; CComPtr m_pd3d12Device; IObject& m_Owner; diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h index 0c1127d2..0b6d2762 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 // // _____________________________ ________________________________________________________________________________ @@ -75,11 +75,11 @@ public: {} ~ShaderVariableManagerD3D12(); - void Initialize(const ShaderResourceLayoutD3D12& Layout, - IMemoryAllocator& Allocator, - const SHADER_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - ShaderResourceCacheD3D12& ResourceCache); + void Initialize(const ShaderResourceLayoutD3D12& Layout, + IMemoryAllocator& Allocator, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + ShaderResourceCacheD3D12& ResourceCache); void Destroy(IMemoryAllocator& Allocator); ShaderVariableD3D12Impl* GetVariable(const Char* Name); @@ -87,10 +87,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; } @@ -119,7 +119,7 @@ private: }; // sizeof(ShaderVariableD3D12Impl) == 24 (x64) -class ShaderVariableD3D12Impl final : public IShaderVariable +class ShaderVariableD3D12Impl final : public IShaderResourceVariable { public: ShaderVariableD3D12Impl(ShaderVariableManagerD3D12& ParentManager, @@ -154,16 +154,16 @@ 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 diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index 8d5f1ba4..82c3f587 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -204,7 +204,7 @@ PipelineStateD3D12Impl :: PipelineStateD3D12Impl(IReferenceCounters* pRefCo std::array ShaderVarMgrDataSizes = {}; for (Uint32 s = 0; s < m_NumShaders; ++s) { - std::array AllowedVarTypes = { SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC }; + std::array 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(AllowedVarTypes.size()), NumVariablesUnused); } @@ -324,8 +324,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 +357,7 @@ ShaderResourceCacheD3D12* PipelineStateD3D12Impl::CommitAndTransitionShaderResou bool PipelineStateD3D12Impl::dbgContainsShaderResources()const { - for(auto VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType+1)) + for(auto VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType+1)) { if (m_RootSig.GetTotalSrvCbvUavSlots(VarType) != 0 || m_RootSig.GetTotalRootViews (VarType) != 0) diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 82bf20dd..64da64c9 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)); @@ -304,8 +304,8 @@ void RootSignature::AllocateResourceSlot(SHADER_TYPE ShaderT 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 = (ShaderResAttribs.GetVariableType() == 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,17 +397,17 @@ 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 @@ -530,7 +530,7 @@ void RootSignature::Finalize(ID3D12Device* pd3d12Device) hr = pd3d12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), __uuidof(m_pd3d12RootSignature), reinterpret_cast( static_cast(&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; @@ -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(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(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..b8d46dbb 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp @@ -58,7 +58,7 @@ ShaderResourceBindingD3D12Impl::ShaderResourceBindingD3D12Impl(IReferenceCounter 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 AllowedVarTypes = { SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC }; + std::array 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(AllowedVarTypes.size()), m_ShaderResourceCache); @@ -96,7 +96,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 +121,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]; diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index eada5310..ca133acc 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -33,6 +33,7 @@ #include "ShaderD3D12Impl.h" #include "RootSignature.h" #include "PipelineStateD3D12Impl.h" +#include "ShaderResourceVariableBase.h" namespace Diligent { @@ -78,20 +79,21 @@ D3D12_DESCRIPTOR_RANGE_TYPE GetDescriptorRangeType(CachedResourceType ResType) return ResTypeToDescrRangeTypeMap[ResType]; } -void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& Allocator, - const std::array& CbvSrvUavCount, - const std::array& SamplerCount) + +void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& Allocator, + const std::array& CbvSrvUavCount, + const std::array& SamplerCount) { m_CbvSrvUavOffsets[0] = 0; - for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType+1)) + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType+1)) { VERIFY(m_CbvSrvUavOffsets[VarType] + CbvSrvUavCount[VarType] <= std::numeric_limits::max(), "Offset is not representable in 16 bits" ); m_CbvSrvUavOffsets[VarType+1] = static_cast(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(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(VarType+1)) { VERIFY(m_SamplersOffsets[VarType] + SamplerCount[VarType] <= std::numeric_limits::max(), "Offset is not representable in 16 bits" ); m_SamplersOffsets[VarType+1] = static_cast(m_SamplersOffsets[VarType] + SamplerCount[VarType]); @@ -102,7 +104,7 @@ 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 >(pRawMem, Allocator); } @@ -110,9 +112,10 @@ void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& // 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, + const PipelineResourceLayoutDesc& ResourceLayout, std::shared_ptr pSrcResources, IMemoryAllocator& LayoutDataAllocator, - const SHADER_VARIABLE_TYPE* AllowedVarTypes, + const SHADER_RESOURCE_VARIABLE_TYPE* const AllowedVarTypes, Uint32 NumAllowedTypes, ShaderResourceCacheD3D12* pResourceCache, RootSignature* pRootSig) @@ -122,67 +125,78 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* VERIFY_EXPR( (pResourceCache != nullptr) ^ (pRootSig != nullptr) ); - Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - std::array CbvSrvUavCount = {}; - std::array SamplerCount = {}; + std::array CbvSrvUavCount = {}; + std::array 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.ValidSamplerAssigned()) + { + auto SamplerId = TexSRV.GetSamplerId(); + const auto& SamplerAttribs = m_pResources->GetSampler(SamplerId); + 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 CurrCbvSrvUav = {}; - std::array CurrSampler = {}; + std::array CurrCbvSrvUav = {}; + std::array 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; @@ -214,92 +228,112 @@ 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()) + auto VarType = m_pResources->FindVariableType(Sam, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) { - if (pRootSig != nullptr) - pRootSig->InitStaticSampler(m_pResources->GetShaderType(), Sam.Name, m_pResources->GetCombinedSamplerSuffix(), Sam); - } - else - { - 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.ValidSamplerAssigned()) { - auto SamplerCount = GetTotalSamplerCount(); - for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId) + const auto& SamplerAttribs = m_pResources->GetSampler(TexSRV.GetSamplerId()); + 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 (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId) + { + const auto& Sampler = GetSampler(SamplerId); + 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(); + for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId) + { + const auto& Sampler = GetSampler(SamplerId); + if (strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0) + break; + } + + if (SamplerId == SamplerCount) + { + 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(VarType+1)) + for(SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(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 +360,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 +381,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 +463,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::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 +520,11 @@ void ShaderResourceLayoutD3D12::D3D12Resource::CacheSampler(IDeviceObject* RefCntAutoPtr 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 +561,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 +599,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 +623,10 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject* case CachedResourceType::TexSRV: CacheResourceView(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(Sam.RootIndex, Sam.OffsetFromTableStart + SamplerArrInd); @@ -603,7 +639,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 +685,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 +695,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 +735,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) { @@ -748,18 +784,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 +804,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 +836,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(VarType+1)) + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(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 +855,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()->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 +893,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 +911,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 +936,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 +954,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 +976,4 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12 } #endif -const Char* ShaderResourceLayoutD3D12::GetShaderName()const -{ - RefCntAutoPtr pShader(&m_Owner, IID_Shader); - if (pShader) - { - return pShader->GetDesc().Name; - } - else - { - RefCntAutoPtr pPSO(&m_Owner, IID_PipelineState); - if(pPSO) - { - auto* pPSOD3D12 = pPSO.RawPtr(); - 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( pShaderBytecode, NewResourceHandler{}, - ShdrDesc, + ShdrDesc.Name, CombinedSamplerSuffix ); } diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp index 35bd4d81..877a270d 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(VarType+1)) + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType+1)) { if (IsAllowedType(VarType, AllowedTypeBits)) { @@ -49,11 +50,11 @@ 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) +void ShaderVariableManagerD3D12::Initialize(const ShaderResourceLayoutD3D12& SrcLayout, + IMemoryAllocator& Allocator, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + ShaderResourceCacheD3D12& ResourceCache) { m_pResourceLayout = &SrcLayout; m_pResourceCache = &ResourceCache; @@ -72,7 +73,7 @@ void ShaderVariableManagerD3D12::Initialize(const ShaderResourceLayoutD3D12& Src m_pVariables = reinterpret_cast(pRawMem); Uint32 VarInd = 0; - for (SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType+1)) + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType+1)) { if (!IsAllowedType(VarType, AllowedTypeBits)) continue; @@ -177,7 +178,7 @@ 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) -- cgit v1.2.3 From c72191a465edd01905181aa47cc57e47fcc29b9e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 4 Mar 2019 19:17:32 -0800 Subject: Completed D3D12 back-end refactor to comply with the new API --- .../include/PipelineStateD3D12Impl.h | 31 ++++- .../GraphicsEngineD3D12/include/RootSignature.h | 5 +- .../GraphicsEngineD3D12/include/ShaderD3D12Impl.h | 10 ++ .../include/ShaderResourceBindingD3D12Impl.h | 4 +- .../include/ShaderResourceLayoutD3D12.h | 32 +++--- .../include/ShaderVariableD3D12.h | 33 +++--- .../src/PipelineStateD3D12Impl.cpp | 125 +++++++++++++++++++-- .../src/RenderDeviceD3D12Impl.cpp | 6 +- Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 30 ++--- .../src/ShaderResourceBindingD3D12Impl.cpp | 28 +++-- .../src/ShaderResourceLayoutD3D12.cpp | 49 ++++---- .../src/ShaderVariableD3D12.cpp | 29 ++--- 12 files changed, 265 insertions(+), 117 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h index 35cd4e7e..64dfdc2b 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 { @@ -49,12 +50,20 @@ public: virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; - virtual ID3D12PipelineState *GetD3D12PipelineState()const override final{return m_pd3d12PSO;} - + virtual void BindStaticResources(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/RootSignature.h b/Graphics/GraphicsEngineD3D12/include/RootSignature.h index ebe2083e..1d312399 100644 --- a/Graphics/GraphicsEngineD3D12/include/RootSignature.h +++ b/Graphics/GraphicsEngineD3D12/include/RootSignature.h @@ -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); diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h index 674beafb..9227287e 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h @@ -52,6 +52,16 @@ public: virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + virtual Uint32 GetResourceCount()const override final + { + return m_pShaderResources->GetTotalResources(); + } + + virtual ShaderResourceDesc GetResource(Uint32 Index)const override final + { + return m_pShaderResources->GetShaderResourceDesc(Index); + } + ID3DBlob* GetShaderByteCode(){return m_pShaderByteCode;} const std::shared_ptr& GetShaderResources()const { return m_pShaderResources; } diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h index b45514da..18f03df1 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h @@ -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 2ae5c927..26ed260e 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h @@ -108,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 pSrcResources, + IMemoryAllocator& LayoutDataAllocator, + const SHADER_RESOURCE_VARIABLE_TYPE* const VarTypes, + Uint32 NumAllowedTypes, + ShaderResourceCacheD3D12* pResourceCache, + class RootSignature* pRootSig); ShaderResourceLayoutD3D12 (const ShaderResourceLayoutD3D12&) = delete; ShaderResourceLayoutD3D12 (ShaderResourceLayoutD3D12&&) = delete; @@ -117,20 +131,6 @@ public: ~ShaderResourceLayoutD3D12(); - // The method is called to - // - 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 - void Initialize(ID3D12Device* pd3d12Device, - const PipelineResourceLayoutDesc& ResourceLayout, - std::shared_ptr pSrcResources, - IMemoryAllocator& LayoutDataAllocator, - const SHADER_RESOURCE_VARIABLE_TYPE* const VarTypes, - Uint32 NumAllowedTypes, - ShaderResourceCacheD3D12* pResourceCache, - class RootSignature* pRootSig); - // sizeof(D3D12Resource) == 24 (x64) struct D3D12Resource final { @@ -327,8 +327,8 @@ private: std::array m_CbvSrvUavOffsets = {}; std::array m_SamplersOffsets = {}; - CComPtr m_pd3d12Device; IObject& m_Owner; + CComPtr 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 m_pResources; diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h index 0b6d2762..85dc30c7 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h @@ -70,16 +70,14 @@ class ShaderVariableD3D12Impl; 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_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - ShaderResourceCacheD3D12& ResourceCache); void Destroy(IMemoryAllocator& Allocator); ShaderVariableD3D12Impl* GetVariable(const Char* Name); @@ -99,13 +97,14 @@ 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 + IObject& m_Owner; + + // Variable mgr is owned by either PSO object (in which case m_pResourceLayout points to + // static resource layout owned by the same PSO 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; + const ShaderResourceLayoutD3D12& m_ResourceLayout; + 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,7 +113,7 @@ private: Uint32 m_NumVariables = 0; #ifdef _DEBUG - IMemoryAllocator* m_pDbgAllocator = nullptr; + IMemoryAllocator& m_DbgAllocator; #endif }; @@ -168,15 +167,13 @@ public: 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/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index 82c3f587..91835158 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(pShaderResLayoutRawMem); + } + + { + auto& ShaderResCacheAllocator = GetRawAllocator(); + auto* pShaderResCacheRawMem = ALLOCATE(ShaderResCacheAllocator, "Raw memory for ShaderResourceCacheD3D12", sizeof(ShaderResourceCacheD3D12) * m_NumShaders); + m_pStaticResourceCaches = reinterpret_cast(pShaderResCacheRawMem); + } + + { + auto& ShaderVarMgrAllocator = GetRawAllocator(); + auto* pStaticVarsMgrRawMem = ALLOCATE(ShaderVarMgrAllocator, "Raw memory for ShaderVariableManagerD3D12", sizeof(ShaderVariableManagerD3D12) * m_NumShaders); + m_pStaticVarManagers = reinterpret_cast(pStaticVarsMgrRawMem); + } + +#ifdef DEVELOPMENT + { + const ShaderResources* pResources[MaxShadersInPipeline] = {}; + for (Uint32 s = 0; s < m_NumShaders; ++s) + { + const auto* pShader = GetShader(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(pShaderResLayoutRawMem); for (Uint32 s=0; s < m_NumShaders; ++s) { auto* pShaderD3D12 = GetShader(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(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); @@ -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 @@ -366,4 +442,39 @@ bool PipelineStateD3D12Impl::dbgContainsShaderResources()const return false; } +void PipelineStateD3D12Impl::BindStaticResources(IResourceMapping* pResourceMapping, Uint32 Flags) +{ + for (Uint32 s=0; s < m_NumShaders; ++s) + { + 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..4640daad 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -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(ppShader) ); OnCreateDeviceObject( pShaderD3D12 ); diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 64da64c9..b5809eb5 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -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,12 +300,12 @@ 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_RESOURCE_VARIABLE_TYPE_DYNAMIC) ? SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC : SHADER_RESOURCE_VARIABLE_TYPE_STATIC; + auto RootTableType = (VariableType == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) ? SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC : SHADER_RESOURCE_VARIABLE_TYPE_STATIC; auto TableIndKey = ShaderInd * SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + RootTableType; // Get the table array index (this is not the root index!) auto& RootTableArrayInd = (( RangeType == D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER ) ? m_SamplerRootTablesMap : m_SrvCbvUavRootTablesMap)[ TableIndKey ]; @@ -411,23 +412,22 @@ void RootSignature::dbgVerifyRootParameters()const } #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(Stage))); + ShaderStages &= ~Stage; } } - VERIFY_EXPR(m_StaticSamplers.size() == TotalSamplers); } } diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp index b8d46dbb..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 AllowedVarTypes = { SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_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(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(s); } @@ -173,23 +180,22 @@ void ShaderResourceBindingD3D12Impl::InitializeStaticResources(const IPipelineSt auto* pPSO12 = ValidatedCast(pPSO); auto NumShaders = pPSO12->GetNumShaders(); - auto ppShaders = pPSO12->GetShaders(); // Copy static resources for (Uint32 s = 0; s < NumShaders; ++s) { - auto* pShader = ValidatedCast( 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(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 ca133acc..de7458b6 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -38,11 +38,6 @@ namespace Diligent { -ShaderResourceLayoutD3D12::ShaderResourceLayoutD3D12(IObject& Owner) : - m_Owner(Owner) -{ -} - ShaderResourceLayoutD3D12::~ShaderResourceLayoutD3D12() { for(Uint32 r=0; r < GetTotalResourceCount(); ++r) @@ -111,18 +106,19 @@ void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& // 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, - const PipelineResourceLayoutDesc& ResourceLayout, - std::shared_ptr pSrcResources, - IMemoryAllocator& LayoutDataAllocator, - const SHADER_RESOURCE_VARIABLE_TYPE* const AllowedVarTypes, - Uint32 NumAllowedTypes, - ShaderResourceCacheD3D12* pResourceCache, - RootSignature* pRootSig) +ShaderResourceLayoutD3D12::ShaderResourceLayoutD3D12(IObject& Owner, + ID3D12Device* pd3d12Device, + const PipelineResourceLayoutDesc& ResourceLayout, + std::shared_ptr 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) ); const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); @@ -155,10 +151,9 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* if (IsAllowedType(VarType, AllowedTypeBits)) { ++CbvSrvUavCount[VarType]; - if (TexSRV.ValidSamplerAssigned()) + if (TexSRV.IsCombinedWithSampler()) { - auto SamplerId = TexSRV.GetSamplerId(); - const auto& SamplerAttribs = m_pResources->GetSampler(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, @@ -203,7 +198,7 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* 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 @@ -268,9 +263,9 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* 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.ValidSamplerAssigned()) + if (TexSRV.IsCombinedWithSampler()) { - const auto& SamplerAttribs = m_pResources->GetSampler(TexSRV.GetSamplerId()); + 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, @@ -283,9 +278,9 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* // Static samplers are never copied, and SamplerId == InvalidSamplerId #ifdef _DEBUG auto SamplerCount = GetTotalSamplerCount(); - for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId) + for (Uint32 s = 0; s < SamplerCount; ++s) { - const auto& Sampler = GetSampler(SamplerId); + 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"); } @@ -294,14 +289,16 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* else { auto SamplerCount = GetTotalSamplerCount(); + bool SamplerFound = false; for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId) { const auto& Sampler = GetSampler(SamplerId); - if (strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0) + SamplerFound = strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0; + if (SamplerFound) break; } - if (SamplerId == SamplerCount) + 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; diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp index 877a270d..3c14c461 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp @@ -50,18 +50,20 @@ 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_RESOURCE_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_ResourceLayout (SrcLayout), + 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); @@ -107,7 +109,7 @@ ShaderVariableManagerD3D12::~ShaderVariableManagerD3D12() void ShaderVariableManagerD3D12::Destroy(IMemoryAllocator &Allocator) { - VERIFY(m_pDbgAllocator == &Allocator, "Incosistent alloctor"); + VERIFY(&m_DbgAllocator == &Allocator, "Incosistent alloctor"); if(m_pVariables != nullptr) { @@ -167,7 +169,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 ) @@ -183,7 +184,7 @@ void ShaderVariableManagerD3D12::BindResources( IResourceMapping* pResourceMappi 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 pObj; @@ -192,11 +193,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" ); } } -- cgit v1.2.3 From f551f6353eaf4efe9b7f26d48822b96ebb0706a0 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 4 Mar 2019 22:38:04 -0800 Subject: Updated D3D11, D3D12, and Vk EngineFactory headers & structures --- Graphics/GraphicsEngineD3D12/CMakeLists.txt | 4 +- .../include/DeviceContextD3D12Impl.h | 12 +- .../include/RenderDeviceD3D12Impl.h | 16 +- .../interface/EngineFactoryD3D12.h | 133 +++++++ .../interface/RenderDeviceFactoryD3D12.h | 133 ------- Graphics/GraphicsEngineD3D12/readme.md | 2 +- .../src/DeviceContextD3D12Impl.cpp | 20 +- .../GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp | 438 +++++++++++++++++++++ .../src/RenderDeviceD3D12Impl.cpp | 30 +- .../src/RenderDeviceFactoryD3D12.cpp | 438 --------------------- .../src/ShaderResourceLayoutD3D12.cpp | 2 +- 11 files changed, 614 insertions(+), 614 deletions(-) create mode 100644 Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h delete mode 100644 Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h create mode 100644 Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp delete mode 100644 Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp (limited to 'Graphics/GraphicsEngineD3D12') 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/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h index 438014e3..d22784dd 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h @@ -52,12 +52,12 @@ class DeviceContextD3D12Impl final : public DeviceContextNextGenBase< DeviceCont public: using TDeviceContextBase = DeviceContextNextGenBase< DeviceContextBase >; - 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 INTERFACE_ID& IID, IObject** ppInterface)override final; diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h index f9e4d3aa..376e32d1 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h @@ -45,13 +45,13 @@ class RenderDeviceD3D12Impl final : public RenderDeviceNextGenBase< RenderDevice public: using TRenderDeviceBase = RenderDeviceNextGenBase< RenderDeviceD3DBase, 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 INTERFACE_ID& IID, IObject** ppInterface)override final; @@ -108,7 +108,7 @@ private: CComPtr 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/interface/EngineFactoryD3D12.h b/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h new file mode 100644 index 00000000..7ac6e9e0 --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h @@ -0,0 +1,133 @@ +/* Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of functions that initialize Direct3D12-based engine implementation + +#include + +#include "../../GraphicsEngine/interface/RenderDevice.h" +#include "../../GraphicsEngine/interface/DeviceContext.h" +#include "../../GraphicsEngine/interface/SwapChain.h" + +#if PLATFORM_UNIVERSAL_WINDOWS && defined(ENGINE_DLL) +# include "../../../Common/interface/StringTools.h" +#endif + +namespace Diligent +{ + +class IEngineFactoryD3D12 +{ +public: + 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, + const SwapChainDesc& SwapChainDesc, + const FullScreenModeDesc& FSDesc, + void* pNativeWndHandle, + ISwapChain** ppSwapChain ) = 0; + + virtual void EnumerateHardwareAdapters(Uint32& NumAdapters, + HardwareAdapterAttribs* Adapters) = 0; + + virtual void EnumerateDisplayModes(Uint32 AdapterId, + Uint32 OutputId, + TEXTURE_FORMAT Format, + Uint32& NumDisplayModes, + DisplayModeAttribs* DisplayModes) = 0; + +}; + + +#if ENGINE_DLL + + typedef IEngineFactoryD3D12* (*GetEngineFactoryD3D12Type)(); + + static bool LoadGraphicsEngineD3D12(GetEngineFactoryD3D12Type &GetFactoryFunc) + { + GetFactoryFunc = nullptr; + std::string LibName = "GraphicsEngineD3D12_"; + +#if _WIN64 + LibName += "64"; +#else + LibName += "32"; +#endif + +#ifdef _DEBUG + LibName += "d"; +#else + LibName += "r"; +#endif + + LibName += ".dll"; +#if PLATFORM_WIN32 + auto hModule = LoadLibraryA(LibName.c_str()); +#elif PLATFORM_UNIVERSAL_WINDOWS + auto hModule = LoadPackagedLibrary(WidenString(LibName).c_str(), 0); +#else +# error Unexpected platform +#endif + + if( hModule == NULL ) + { + std::stringstream ss; + ss << "Failed to load " << LibName << " library.\n"; + OutputDebugStringA(ss.str().c_str()); + return false; + } + + GetFactoryFunc = reinterpret_cast( GetProcAddress(hModule, "GetEngineFactoryD3D12") ); + if( GetFactoryFunc == NULL ) + { + std::stringstream ss; + ss << "Failed to load GetEngineFactoryD3D12() from " << LibName << " library.\n"; + OutputDebugStringA(ss.str().c_str()); + FreeLibrary( hModule ); + return false; + } + + return true; + } +#else + + IEngineFactoryD3D12* GetEngineFactoryD3D12(); + +#endif + +} diff --git a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h b/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h deleted file mode 100644 index 80e6f580..00000000 --- a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h +++ /dev/null @@ -1,133 +0,0 @@ -/* Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Declaration of functions that initialize Direct3D12-based engine implementation - -#include - -#include "../../GraphicsEngine/interface/RenderDevice.h" -#include "../../GraphicsEngine/interface/DeviceContext.h" -#include "../../GraphicsEngine/interface/SwapChain.h" - -#if PLATFORM_UNIVERSAL_WINDOWS && defined(ENGINE_DLL) -# include "../../../Common/interface/StringTools.h" -#endif - -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 CreateSwapChainD3D12( IRenderDevice* pDevice, - IDeviceContext* pImmediateContext, - const SwapChainDesc& SwapChainDesc, - const FullScreenModeDesc& FSDesc, - void* pNativeWndHandle, - ISwapChain** ppSwapChain ) = 0; - - virtual void EnumerateHardwareAdapters(Uint32& NumAdapters, - HardwareAdapterAttribs* Adapters) = 0; - - virtual void EnumerateDisplayModes(Uint32 AdapterId, - Uint32 OutputId, - TEXTURE_FORMAT Format, - Uint32& NumDisplayModes, - DisplayModeAttribs* DisplayModes) = 0; - -}; - - -#if ENGINE_DLL - - typedef IEngineFactoryD3D12* (*GetEngineFactoryD3D12Type)(); - - static bool LoadGraphicsEngineD3D12(GetEngineFactoryD3D12Type &GetFactoryFunc) - { - GetFactoryFunc = nullptr; - std::string LibName = "GraphicsEngineD3D12_"; - -#if _WIN64 - LibName += "64"; -#else - LibName += "32"; -#endif - -#ifdef _DEBUG - LibName += "d"; -#else - LibName += "r"; -#endif - - LibName += ".dll"; -#if PLATFORM_WIN32 - auto hModule = LoadLibraryA(LibName.c_str()); -#elif PLATFORM_UNIVERSAL_WINDOWS - auto hModule = LoadPackagedLibrary(WidenString(LibName).c_str(), 0); -#else -# error Unexpected platform -#endif - - if( hModule == NULL ) - { - std::stringstream ss; - ss << "Failed to load " << LibName << " library.\n"; - OutputDebugStringA(ss.str().c_str()); - return false; - } - - GetFactoryFunc = reinterpret_cast( GetProcAddress(hModule, "GetEngineFactoryD3D12") ); - if( GetFactoryFunc == NULL ) - { - std::stringstream ss; - ss << "Failed to load GetEngineFactoryD3D12() from " << LibName << " library.\n"; - OutputDebugStringA(ss.str().c_str()); - FreeLibrary( hModule ); - return false; - } - - return true; - } -#else - - IEngineFactoryD3D12* GetEngineFactoryD3D12(); - -#endif - -} 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::max() : Attribs.NumCommandsToFlushCmdList, + bIsDeferred ? std::numeric_limits::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/EngineFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp new file mode 100644 index 00000000..18a69020 --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp @@ -0,0 +1,438 @@ +/* Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +/// \file +/// Routines that initialize D3D12-based engine implementation + +#include "pch.h" +#include +#include "EngineFactoryD3D12.h" +#include "RenderDeviceD3D12Impl.h" +#include "DeviceContextD3D12Impl.h" +#include "SwapChainD3D12Impl.h" +#include "D3D12TypeConversions.h" +#include "EngineFactoryD3DBase.h" +#include "StringTools.h" +#include "EngineMemory.h" +#include "CommandQueueD3D12Impl.h" +#include +#include + +namespace Diligent +{ + +/// Engine factory for D3D12 implementation +class EngineFactoryD3D12Impl : public EngineFactoryD3DBase +{ +public: + static EngineFactoryD3D12Impl* GetInstance() + { + static EngineFactoryD3D12Impl TheFactory; + return &TheFactory; + } + + void CreateDeviceAndContextsD3D12(const EngineD3D12CreateInfo& EngineCI, + 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, + const SwapChainDesc& SwapChainDesc, + const FullScreenModeDesc& FSDesc, + void* pNativeWndHandle, + ISwapChain** ppSwapChain )override final; +}; + +void GetHardwareAdapter(IDXGIFactory2* pFactory, IDXGIAdapter1** ppAdapter) +{ + CComPtr adapter; + *ppAdapter = nullptr; + + for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &adapter); ++adapterIndex) + { + DXGI_ADAPTER_DESC1 desc; + adapter->GetDesc1(&desc); + + if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) + { + // Skip software devices + continue; + } + + // Check to see if the adapter supports Direct3D 12, but don't create the + // actual device yet. + if (SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr))) + { + break; + } + } + + *ppAdapter = adapter.Detach(); +} + +/// Creates render device and device contexts for Direct3D12-based engine implementation + +/// \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 +/// the contexts will be written. The new immediate +/// context goes at position 0. If NumDeferredContexts > 0, +/// pointers to the deferred contexts are written afterwards. +/// \param [in] NumDeferredContexts - Number of deferred contexts. If non-zero number +/// of deferred contexts is requested, pointers to the +/// contexts are written to ppContexts array starting +/// at position 1 +void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12(const EngineD3D12CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts, + Uint32 NumDeferredContexts) +{ + if (EngineCI.DebugMessageCallback != nullptr) + SetDebugMessageCallback(EngineCI.DebugMessageCallback); + + VERIFY( ppDevice && ppContexts, "Null pointer provided" ); + if( !ppDevice || !ppContexts ) + return; + + for(Uint32 Type=D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; Type < D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++Type) + { + auto CPUHeapAllocSize = EngineCI.CPUDescriptorHeapAllocationSize[Type]; + Uint32 MaxSize = 1 << 20; + if( CPUHeapAllocSize > 1 << 20 ) + { + LOG_ERROR( "CPU Heap allocation size is too large (", CPUHeapAllocSize, "). Max allowed size is ", MaxSize ); + return; + } + + if( (CPUHeapAllocSize % 16) != 0 ) + { + LOG_ERROR( "CPU Heap allocation size (", CPUHeapAllocSize, ") is expected to be multiple of 16" ); + return; + } + } + + *ppDevice = nullptr; + memset(ppContexts, 0, sizeof(*ppContexts) * (1+NumDeferredContexts)); + + RefCntAutoPtr pCmdQueueD3D12; + CComPtr d3d12Device; + try + { +#if defined(_DEBUG) + // Enable the D3D12 debug layer. + { + CComPtr debugController; + if (SUCCEEDED(D3D12GetDebugInterface(__uuidof(debugController), reinterpret_cast(static_cast(&debugController)) ))) + { + debugController->EnableDebugLayer(); + } + } +#endif + + CComPtr factory; + HRESULT hr = CreateDXGIFactory1(__uuidof(factory), reinterpret_cast(static_cast(&factory)) ); + CHECK_D3D_RESULT_THROW(hr, "Failed to create DXGI factory"); + + CComPtr hardwareAdapter; + if(EngineCI.AdapterId == EngineD3D12CreateInfo::DefaultAdapterId) + { + GetHardwareAdapter(factory, &hardwareAdapter); + if(hardwareAdapter == nullptr) + LOG_ERROR_AND_THROW("No suitable hardware adapter found"); + } + else + { + auto Adapters = FindCompatibleAdapters(); + if(EngineCI.AdapterId < Adapters.size()) + hardwareAdapter = Adapters[EngineCI.AdapterId]; + else + { + LOG_ERROR_AND_THROW(EngineCI.AdapterId, " is not a valid hardware adapter id. Total number of compatible adapters available on this system: ", Adapters.size()); + } + } + + { + DXGI_ADAPTER_DESC1 desc; + hardwareAdapter->GetDesc1(&desc); + LOG_INFO_MESSAGE("D3D12-capabale hardware found: ", NarrowString(desc.Description), " (", desc.DedicatedVideoMemory >> 20, " MB)"); + } + + hr = D3D12CreateDevice(hardwareAdapter, D3D_FEATURE_LEVEL_11_0, __uuidof(d3d12Device), reinterpret_cast(static_cast(&d3d12Device)) ); + if( FAILED(hr)) + { + LOG_WARNING_MESSAGE("Failed to create hardware device. Attempting to create WARP device"); + + CComPtr warpAdapter; + hr = factory->EnumWarpAdapter( __uuidof(warpAdapter), reinterpret_cast(static_cast(&warpAdapter)) ); + CHECK_D3D_RESULT_THROW(hr, "Failed to enum warp adapter"); + + hr = D3D12CreateDevice( warpAdapter, D3D_FEATURE_LEVEL_11_0, __uuidof(d3d12Device), reinterpret_cast(static_cast(&d3d12Device)) ); + CHECK_D3D_RESULT_THROW(hr, "Failed to crate warp device"); + } + +#if _DEBUG + { + CComPtr pInfoQueue; + hr = d3d12Device->QueryInterface(__uuidof(pInfoQueue), reinterpret_cast(static_cast(&pInfoQueue))); + if( SUCCEEDED(hr) ) + { + // Suppress whole categories of messages + //D3D12_MESSAGE_CATEGORY Categories[] = {}; + + // Suppress messages based on their severity level + D3D12_MESSAGE_SEVERITY Severities[] = + { + D3D12_MESSAGE_SEVERITY_INFO + }; + + // Suppress individual messages by their ID + //D3D12_MESSAGE_ID DenyIds[] = {}; + + D3D12_INFO_QUEUE_FILTER NewFilter = {}; + //NewFilter.DenyList.NumCategories = _countof(Categories); + //NewFilter.DenyList.pCategoryList = Categories; + NewFilter.DenyList.NumSeverities = _countof(Severities); + NewFilter.DenyList.pSeverityList = Severities; + //NewFilter.DenyList.NumIDs = _countof(DenyIds); + //NewFilter.DenyList.pIDList = DenyIds; + + hr = pInfoQueue->PushStorageFilter(&NewFilter); + VERIFY(SUCCEEDED(hr), "Failed to push storage filter"); + } + } +#endif + +#ifndef RELEASE + // Prevent the GPU from overclocking or underclocking to get consistent timings + //d3d12Device->SetStablePowerState(TRUE); +#endif + + // Describe and create the command queue. + D3D12_COMMAND_QUEUE_DESC queueDesc = {}; + queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; + queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; + + CComPtr pd3d12CmdQueue; + hr = d3d12Device->CreateCommandQueue(&queueDesc, __uuidof(pd3d12CmdQueue), reinterpret_cast(static_cast(&pd3d12CmdQueue))); + CHECK_D3D_RESULT_THROW(hr, "Failed to create command queue"); + hr = pd3d12CmdQueue->SetName(L"Main Command Queue"); + VERIFY_EXPR(SUCCEEDED(hr)); + + CComPtr pd3d12Fence; + hr = d3d12Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(pd3d12Fence), reinterpret_cast(static_cast(&pd3d12Fence))); + CHECK_D3D_RESULT_THROW(hr, "Failed to create main command queue fence"); + d3d12Device->SetName(L"Main Command Queue fence"); + + auto &RawMemAllocator = GetRawAllocator(); + pCmdQueueD3D12 = NEW_RC_OBJ(RawMemAllocator, "CommandQueueD3D12 instance", CommandQueueD3D12Impl)(pd3d12CmdQueue, pd3d12Fence); + } + catch( const std::runtime_error & ) + { + LOG_ERROR( "Failed to initialize D3D12 resources" ); + return; + } + + std::array CmdQueues = {pCmdQueueD3D12}; + AttachToD3D12Device(d3d12Device, CmdQueues.size(), CmdQueues.data(), EngineCI, ppDevice, ppContexts, NumDeferredContexts); +} + + +/// Attaches to existing D3D12 device + +/// \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] 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 +/// the contexts will be written. Pointer to the immediate +/// context goes at position 0. If NumDeferredContexts > 0, +/// pointers to the deferred contexts go afterwards. +/// \param [in] NumDeferredContexts - Number of deferred contexts. If non-zero number +/// 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 EngineD3D12CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts, + Uint32 NumDeferredContexts) +{ + if (EngineCI.DebugMessageCallback != nullptr) + SetDebugMessageCallback(EngineCI.DebugMessageCallback); + + VERIFY( pd3d12NativeDevice && ppCommandQueues && ppDevice && ppContexts, "Null pointer provided" ); + if( !pd3d12NativeDevice || !ppCommandQueues || !ppDevice || !ppContexts ) + return; + + *ppDevice = nullptr; + memset(ppContexts, 0, sizeof(*ppContexts) * (1+NumDeferredContexts)); + + try + { + SetRawAllocator(EngineCI.pRawMemAllocator); + auto &RawMemAllocator = GetRawAllocator(); + auto d3d12Device = reinterpret_cast(pd3d12NativeDevice); + RenderDeviceD3D12Impl *pRenderDeviceD3D12( NEW_RC_OBJ(RawMemAllocator, "RenderDeviceD3D12Impl instance", RenderDeviceD3D12Impl)(RawMemAllocator, EngineCI, d3d12Device, CommandQueueCount, ppCommandQueues, NumDeferredContexts ) ); + pRenderDeviceD3D12->QueryInterface(IID_RenderDevice, reinterpret_cast(ppDevice) ); + + RefCntAutoPtr 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(ppContexts) ); + pRenderDeviceD3D12->SetImmediateContext(pImmediateCtxD3D12); + + for (Uint32 DeferredCtx = 0; DeferredCtx < NumDeferredContexts; ++DeferredCtx) + { + RefCntAutoPtr 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(ppContexts + 1 + DeferredCtx) ); + pRenderDeviceD3D12->SetDeferredContext(DeferredCtx, pDeferredCtxD3D12); + } + } + catch( const std::runtime_error & ) + { + if( *ppDevice ) + { + (*ppDevice)->Release(); + *ppDevice = nullptr; + } + for(Uint32 ctx=0; ctx < 1 + NumDeferredContexts; ++ctx) + { + if( ppContexts[ctx] != nullptr ) + { + ppContexts[ctx]->Release(); + ppContexts[ctx] = nullptr; + } + } + + LOG_ERROR( "Failed to create device and contexts" ); + } +} + +/// Creates a swap chain for Direct3D12-based engine implementation + +/// \param [in] pDevice - Pointer to the render device +/// \param [in] pImmediateContext - Pointer to the immediate device context +/// \param [in] SCDesc - Swap chain description +/// \param [in] FSDesc - Fullscreen mode description +/// \param [in] pNativeWndHandle - Platform-specific native handle of the window +/// the swap chain will be associated with: +/// * On Win32 platform, this should be window handle (HWND) +/// * On Universal Windows Platform, this should be reference to the +/// core window (Windows::UI::Core::CoreWindow) +/// +/// \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 ) +{ + VERIFY( ppSwapChain, "Null pointer provided" ); + if( !ppSwapChain ) + return; + + *ppSwapChain = nullptr; + + try + { + auto *pDeviceD3D12 = ValidatedCast( pDevice ); + auto *pDeviceContextD3D12 = ValidatedCast(pImmediateContext); + auto &RawMemAllocator = GetRawAllocator(); + auto *pSwapChainD3D12 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D12Impl instance", SwapChainD3D12Impl)(SCDesc, FSDesc, pDeviceD3D12, pDeviceContextD3D12, pNativeWndHandle); + pSwapChainD3D12->QueryInterface( IID_SwapChain, reinterpret_cast(ppSwapChain) ); + + pDeviceContextD3D12->SetSwapChain(pSwapChainD3D12); + // Bind default render target + pDeviceContextD3D12->SetRenderTargets( 0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); + // Set default viewport + pDeviceContextD3D12->SetViewports( 1, nullptr, 0, 0 ); + + auto NumDeferredCtx = pDeviceD3D12->GetNumDeferredContexts(); + for (size_t ctx = 0; ctx < NumDeferredCtx; ++ctx) + { + if (auto pDeferredCtx = pDeviceD3D12->GetDeferredContext(ctx)) + { + auto* pDeferredCtxD3D12 = pDeferredCtx.RawPtr(); + pDeferredCtxD3D12->SetSwapChain(pSwapChainD3D12); + // We cannot bind default render target here because + // there is no guarantee that deferred context will be used + // in this frame. It is an error to bind + // RTV of an inactive buffer in the swap chain + } + } + } + catch( const std::runtime_error& ) + { + if( *ppSwapChain ) + { + (*ppSwapChain)->Release(); + *ppSwapChain = nullptr; + } + + LOG_ERROR( "Failed to create the swap chain" ); + } +} + + +#ifdef DOXYGEN +/// Loads Direct3D12-based engine implementation and exports factory functions +/// \param [out] GetFactoryFunc - Pointer to the function that returns factory for D3D12 engine implementation. +/// See EngineFactoryD3D12Impl. +/// \remarks Depending on the configuration and platform, the function loads different dll: +/// Platform\\Configuration | Debug | Release +/// --------------------------|-------------------------------|---------------------------- +/// x86 | GraphicsEngineD3D12_32d.dll | GraphicsEngineD3D12_32r.dll +/// x64 | GraphicsEngineD3D12_64d.dll | GraphicsEngineD3D12_64r.dll +/// +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; +} +#endif + + +IEngineFactoryD3D12* GetEngineFactoryD3D12() +{ + return EngineFactoryD3D12Impl::GetInstance(); +} + +} diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index 4640daad..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")), - m_DynamicMemoryManager(GetRawAllocator(), *this, CreationAttribs.NumDynamicHeapPagesToReserve, CreationAttribs.DynamicHeapPageSize), + m_DynamicMemoryManager(GetRawAllocator(), *this, EngineCI.NumDynamicHeapPagesToReserve, EngineCI.DynamicHeapPageSize), m_MipsGenerator(pd3d12Device) { m_DeviceCaps.DevType = DeviceType::D3D12; diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp deleted file mode 100644 index 3096ea9e..00000000 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp +++ /dev/null @@ -1,438 +0,0 @@ -/* Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -/// \file -/// Routines that initialize D3D12-based engine implementation - -#include "pch.h" -#include -#include "RenderDeviceFactoryD3D12.h" -#include "RenderDeviceD3D12Impl.h" -#include "DeviceContextD3D12Impl.h" -#include "SwapChainD3D12Impl.h" -#include "D3D12TypeConversions.h" -#include "EngineFactoryD3DBase.h" -#include "StringTools.h" -#include "EngineMemory.h" -#include "CommandQueueD3D12Impl.h" -#include -#include - -namespace Diligent -{ - -/// Engine factory for D3D12 implementation -class EngineFactoryD3D12Impl : public EngineFactoryD3DBase -{ -public: - static EngineFactoryD3D12Impl* GetInstance() - { - static EngineFactoryD3D12Impl TheFactory; - return &TheFactory; - } - - void CreateDeviceAndContextsD3D12( const EngineD3D12Attribs& CreationAttribs, - 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 CreateSwapChainD3D12( IRenderDevice* pDevice, - IDeviceContext* pImmediateContext, - const SwapChainDesc& SwapChainDesc, - const FullScreenModeDesc& FSDesc, - void* pNativeWndHandle, - ISwapChain** ppSwapChain )override final; -}; - -void GetHardwareAdapter(IDXGIFactory2* pFactory, IDXGIAdapter1** ppAdapter) -{ - CComPtr adapter; - *ppAdapter = nullptr; - - for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &adapter); ++adapterIndex) - { - DXGI_ADAPTER_DESC1 desc; - adapter->GetDesc1(&desc); - - if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) - { - // Skip software devices - continue; - } - - // Check to see if the adapter supports Direct3D 12, but don't create the - // actual device yet. - if (SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr))) - { - break; - } - } - - *ppAdapter = adapter.Detach(); -} - -/// Creates render device and device contexts for Direct3D12-based engine implementation - -/// \param [in] CreationAttribs - 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 -/// the contexts will be written. The new immediate -/// context goes at position 0. If NumDeferredContexts > 0, -/// pointers to the deferred contexts are written afterwards. -/// \param [in] NumDeferredContexts - Number of deferred contexts. If non-zero number -/// 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) -{ - if (CreationAttribs.DebugMessageCallback != nullptr) - SetDebugMessageCallback(CreationAttribs.DebugMessageCallback); - - VERIFY( ppDevice && ppContexts, "Null pointer provided" ); - if( !ppDevice || !ppContexts ) - return; - - for(Uint32 Type=D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; Type < D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; ++Type) - { - auto CPUHeapAllocSize = CreationAttribs.CPUDescriptorHeapAllocationSize[Type]; - Uint32 MaxSize = 1 << 20; - if( CPUHeapAllocSize > 1 << 20 ) - { - LOG_ERROR( "CPU Heap allocation size is too large (", CPUHeapAllocSize, "). Max allowed size is ", MaxSize ); - return; - } - - if( (CPUHeapAllocSize % 16) != 0 ) - { - LOG_ERROR( "CPU Heap allocation size (", CPUHeapAllocSize, ") is expected to be multiple of 16" ); - return; - } - } - - *ppDevice = nullptr; - memset(ppContexts, 0, sizeof(*ppContexts) * (1+NumDeferredContexts)); - - RefCntAutoPtr pCmdQueueD3D12; - CComPtr d3d12Device; - try - { -#if defined(_DEBUG) - // Enable the D3D12 debug layer. - { - CComPtr debugController; - if (SUCCEEDED(D3D12GetDebugInterface(__uuidof(debugController), reinterpret_cast(static_cast(&debugController)) ))) - { - debugController->EnableDebugLayer(); - } - } -#endif - - CComPtr factory; - HRESULT hr = CreateDXGIFactory1(__uuidof(factory), reinterpret_cast(static_cast(&factory)) ); - CHECK_D3D_RESULT_THROW(hr, "Failed to create DXGI factory"); - - CComPtr hardwareAdapter; - if(CreationAttribs.AdapterId == EngineD3D12Attribs::DefaultAdapterId) - { - GetHardwareAdapter(factory, &hardwareAdapter); - if(hardwareAdapter == nullptr) - LOG_ERROR_AND_THROW("No suitable hardware adapter found"); - } - else - { - auto Adapters = FindCompatibleAdapters(); - if(CreationAttribs.AdapterId < Adapters.size()) - hardwareAdapter = Adapters[CreationAttribs.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()); - } - } - - { - DXGI_ADAPTER_DESC1 desc; - hardwareAdapter->GetDesc1(&desc); - LOG_INFO_MESSAGE("D3D12-capabale hardware found: ", NarrowString(desc.Description), " (", desc.DedicatedVideoMemory >> 20, " MB)"); - } - - hr = D3D12CreateDevice(hardwareAdapter, D3D_FEATURE_LEVEL_11_0, __uuidof(d3d12Device), reinterpret_cast(static_cast(&d3d12Device)) ); - if( FAILED(hr)) - { - LOG_WARNING_MESSAGE("Failed to create hardware device. Attempting to create WARP device"); - - CComPtr warpAdapter; - hr = factory->EnumWarpAdapter( __uuidof(warpAdapter), reinterpret_cast(static_cast(&warpAdapter)) ); - CHECK_D3D_RESULT_THROW(hr, "Failed to enum warp adapter"); - - hr = D3D12CreateDevice( warpAdapter, D3D_FEATURE_LEVEL_11_0, __uuidof(d3d12Device), reinterpret_cast(static_cast(&d3d12Device)) ); - CHECK_D3D_RESULT_THROW(hr, "Failed to crate warp device"); - } - -#if _DEBUG - { - CComPtr pInfoQueue; - hr = d3d12Device->QueryInterface(__uuidof(pInfoQueue), reinterpret_cast(static_cast(&pInfoQueue))); - if( SUCCEEDED(hr) ) - { - // Suppress whole categories of messages - //D3D12_MESSAGE_CATEGORY Categories[] = {}; - - // Suppress messages based on their severity level - D3D12_MESSAGE_SEVERITY Severities[] = - { - D3D12_MESSAGE_SEVERITY_INFO - }; - - // Suppress individual messages by their ID - //D3D12_MESSAGE_ID DenyIds[] = {}; - - D3D12_INFO_QUEUE_FILTER NewFilter = {}; - //NewFilter.DenyList.NumCategories = _countof(Categories); - //NewFilter.DenyList.pCategoryList = Categories; - NewFilter.DenyList.NumSeverities = _countof(Severities); - NewFilter.DenyList.pSeverityList = Severities; - //NewFilter.DenyList.NumIDs = _countof(DenyIds); - //NewFilter.DenyList.pIDList = DenyIds; - - hr = pInfoQueue->PushStorageFilter(&NewFilter); - VERIFY(SUCCEEDED(hr), "Failed to push storage filter"); - } - } -#endif - -#ifndef RELEASE - // Prevent the GPU from overclocking or underclocking to get consistent timings - //d3d12Device->SetStablePowerState(TRUE); -#endif - - // Describe and create the command queue. - D3D12_COMMAND_QUEUE_DESC queueDesc = {}; - queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; - queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; - - CComPtr pd3d12CmdQueue; - hr = d3d12Device->CreateCommandQueue(&queueDesc, __uuidof(pd3d12CmdQueue), reinterpret_cast(static_cast(&pd3d12CmdQueue))); - CHECK_D3D_RESULT_THROW(hr, "Failed to create command queue"); - hr = pd3d12CmdQueue->SetName(L"Main Command Queue"); - VERIFY_EXPR(SUCCEEDED(hr)); - - CComPtr pd3d12Fence; - hr = d3d12Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(pd3d12Fence), reinterpret_cast(static_cast(&pd3d12Fence))); - CHECK_D3D_RESULT_THROW(hr, "Failed to create main command queue fence"); - d3d12Device->SetName(L"Main Command Queue fence"); - - auto &RawMemAllocator = GetRawAllocator(); - pCmdQueueD3D12 = NEW_RC_OBJ(RawMemAllocator, "CommandQueueD3D12 instance", CommandQueueD3D12Impl)(pd3d12CmdQueue, pd3d12Fence); - } - catch( const std::runtime_error & ) - { - LOG_ERROR( "Failed to initialize D3D12 resources" ); - return; - } - - std::array CmdQueues = {pCmdQueueD3D12}; - AttachToD3D12Device(d3d12Device, CmdQueues.size(), CmdQueues.data(), CreationAttribs, ppDevice, ppContexts, NumDeferredContexts); -} - - -/// Attaches to existing D3D12 device - -/// \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 [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 -/// the contexts will be written. Pointer to the immediate -/// context goes at position 0. If NumDeferredContexts > 0, -/// pointers to the deferred contexts go afterwards. -/// \param [in] NumDeferredContexts - Number of deferred contexts. If non-zero number -/// 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) -{ - if (EngineAttribs.DebugMessageCallback != nullptr) - SetDebugMessageCallback(EngineAttribs.DebugMessageCallback); - - VERIFY( pd3d12NativeDevice && ppCommandQueues && ppDevice && ppContexts, "Null pointer provided" ); - if( !pd3d12NativeDevice || !ppCommandQueues || !ppDevice || !ppContexts ) - return; - - *ppDevice = nullptr; - memset(ppContexts, 0, sizeof(*ppContexts) * (1+NumDeferredContexts)); - - try - { - SetRawAllocator(EngineAttribs.pRawMemAllocator); - auto &RawMemAllocator = GetRawAllocator(); - auto d3d12Device = reinterpret_cast(pd3d12NativeDevice); - RenderDeviceD3D12Impl *pRenderDeviceD3D12( NEW_RC_OBJ(RawMemAllocator, "RenderDeviceD3D12Impl instance", RenderDeviceD3D12Impl)(RawMemAllocator, EngineAttribs, d3d12Device, CommandQueueCount, ppCommandQueues, NumDeferredContexts ) ); - pRenderDeviceD3D12->QueryInterface(IID_RenderDevice, reinterpret_cast(ppDevice) ); - - RefCntAutoPtr pImmediateCtxD3D12( NEW_RC_OBJ(RawMemAllocator, "DeviceContextD3D12Impl instance", DeviceContextD3D12Impl)(pRenderDeviceD3D12, false, EngineAttribs, 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(ppContexts) ); - pRenderDeviceD3D12->SetImmediateContext(pImmediateCtxD3D12); - - for (Uint32 DeferredCtx = 0; DeferredCtx < NumDeferredContexts; ++DeferredCtx) - { - RefCntAutoPtr pDeferredCtxD3D12( NEW_RC_OBJ(RawMemAllocator, "DeviceContextD3D12Impl instance", DeviceContextD3D12Impl)(pRenderDeviceD3D12, true, EngineAttribs, 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(ppContexts + 1 + DeferredCtx) ); - pRenderDeviceD3D12->SetDeferredContext(DeferredCtx, pDeferredCtxD3D12); - } - } - catch( const std::runtime_error & ) - { - if( *ppDevice ) - { - (*ppDevice)->Release(); - *ppDevice = nullptr; - } - for(Uint32 ctx=0; ctx < 1 + NumDeferredContexts; ++ctx) - { - if( ppContexts[ctx] != nullptr ) - { - ppContexts[ctx]->Release(); - ppContexts[ctx] = nullptr; - } - } - - LOG_ERROR( "Failed to create device and contexts" ); - } -} - -/// Creates a swap chain for Direct3D12-based engine implementation - -/// \param [in] pDevice - Pointer to the render device -/// \param [in] pImmediateContext - Pointer to the immediate device context -/// \param [in] SCDesc - Swap chain description -/// \param [in] FSDesc - Fullscreen mode description -/// \param [in] pNativeWndHandle - Platform-specific native handle of the window -/// the swap chain will be associated with: -/// * On Win32 platform, this should be window handle (HWND) -/// * On Universal Windows Platform, this should be reference to the -/// core window (Windows::UI::Core::CoreWindow) -/// -/// \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 ) -{ - VERIFY( ppSwapChain, "Null pointer provided" ); - if( !ppSwapChain ) - return; - - *ppSwapChain = nullptr; - - try - { - auto *pDeviceD3D12 = ValidatedCast( pDevice ); - auto *pDeviceContextD3D12 = ValidatedCast(pImmediateContext); - auto &RawMemAllocator = GetRawAllocator(); - auto *pSwapChainD3D12 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D12Impl instance", SwapChainD3D12Impl)(SCDesc, FSDesc, pDeviceD3D12, pDeviceContextD3D12, pNativeWndHandle); - pSwapChainD3D12->QueryInterface( IID_SwapChain, reinterpret_cast(ppSwapChain) ); - - pDeviceContextD3D12->SetSwapChain(pSwapChainD3D12); - // Bind default render target - pDeviceContextD3D12->SetRenderTargets( 0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION ); - // Set default viewport - pDeviceContextD3D12->SetViewports( 1, nullptr, 0, 0 ); - - auto NumDeferredCtx = pDeviceD3D12->GetNumDeferredContexts(); - for (size_t ctx = 0; ctx < NumDeferredCtx; ++ctx) - { - if (auto pDeferredCtx = pDeviceD3D12->GetDeferredContext(ctx)) - { - auto *pDeferredCtxD3D12 = pDeferredCtx.RawPtr(); - pDeferredCtxD3D12->SetSwapChain(pSwapChainD3D12); - // We cannot bind default render target here because - // there is no guarantee that deferred context will be used - // in this frame. It is an error to bind - // RTV of an inactive buffer in the swap chain - } - } - } - catch( const std::runtime_error & ) - { - if( *ppSwapChain ) - { - (*ppSwapChain)->Release(); - *ppSwapChain = nullptr; - } - - LOG_ERROR( "Failed to create the swap chain" ); - } -} - - -#ifdef DOXYGEN -/// Loads Direct3D12-based engine implementation and exports factory functions -/// \param [out] GetFactoryFunc - Pointer to the function that returns factory for D3D12 engine implementation. -/// See EngineFactoryD3D12Impl. -/// \remarks Depending on the configuration and platform, the function loads different dll: -/// Platform\\Configuration | Debug | Release -/// --------------------------|-------------------------------|---------------------------- -/// x86 | GraphicsEngineD3D12_32d.dll | GraphicsEngineD3D12_32r.dll -/// x64 | GraphicsEngineD3D12_64d.dll | GraphicsEngineD3D12_64r.dll -/// -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; -} -#endif - - -IEngineFactoryD3D12* GetEngineFactoryD3D12() -{ - return EngineFactoryD3D12Impl::GetInstance(); -} - -} diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index de7458b6..393c1c3b 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -749,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()); -- cgit v1.2.3 From bdbca67b0e03baec3b9dd803e803d267210e892b Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 4 Mar 2019 23:19:07 -0800 Subject: Added ShaderFlags parameter to IPipelineState::BindStaticResources --- Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h | 2 ++ Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h index 64dfdc2b..fa51b6d0 100644 --- a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h @@ -50,7 +50,7 @@ public: virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; - virtual void BindStaticResources(IResourceMapping* pResourceMapping, Uint32 Flags)override final; + virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags)override final; virtual Uint32 GetStaticVariableCount(SHADER_TYPE ShaderType) const override final; diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h index 26ed260e..35ddfbc7 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h @@ -252,6 +252,8 @@ public: } const bool IsUsingSeparateSamplers() const {return !m_pResources->IsUsingCombinedTextureSamplers();} + + SHADER_TYPE GetShaderType() const {return m_pResources->GetShaderType();} private: const D3D12Resource& GetAssignedSampler(const D3D12Resource& TexSrv)const; diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index 91835158..46530860 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -442,11 +442,13 @@ bool PipelineStateD3D12Impl::dbgContainsShaderResources()const return false; } -void PipelineStateD3D12Impl::BindStaticResources(IResourceMapping* pResourceMapping, Uint32 Flags) +void PipelineStateD3D12Impl::BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) { for (Uint32 s=0; s < m_NumShaders; ++s) { - m_pStaticVarManagers[s].BindResources(pResourceMapping, Flags); + auto ShaderType = GetStaticShaderResLayout(s).GetShaderType(); + if ((ShaderFlags & ShaderType) != 0) + m_pStaticVarManagers[s].BindResources(pResourceMapping, Flags); } } -- cgit v1.2.3 From 76a1a90ee26e3f2e78fab018bbbfc43ddc85d849 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 6 Mar 2019 10:03:57 -0800 Subject: Removed unused m_ResourceLayout member from ShaderVariableManagerVk and ShaderVariableManagerD3D12 plus a bunch of minor updates to fix clang warnings --- Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h | 10 ++++------ Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp | 7 +++---- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h index 85dc30c7..8b9f8fb8 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h @@ -66,7 +66,7 @@ namespace Diligent class ShaderVariableD3D12Impl; -// sizeof(ShaderVariableManagerD3D12) == 40 (x64, msvc, Release) +// sizeof(ShaderVariableManagerD3D12) == 32 (x64, msvc, Release) class ShaderVariableManagerD3D12 { public: @@ -99,11 +99,9 @@ private: IObject& m_Owner; - // Variable mgr is owned by either PSO object (in which case m_pResourceLayout points to - // static resource layout owned by the same PSO 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_ResourceLayout; + // 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 is guaranteed to be alive. ShaderResourceCacheD3D12& m_ResourceCache; // Memory is allocated through the allocator provided by the pipeline state. If allocation granularity > 1, fixed block diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp index 3c14c461..de8e9855 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp @@ -56,11 +56,10 @@ ShaderVariableManagerD3D12::ShaderVariableManagerD3D12(IObject& const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes, ShaderResourceCacheD3D12& ResourceCache) : - m_Owner (Owner), - m_ResourceLayout (SrcLayout), - m_ResourceCache (ResourceCache) + m_Owner (Owner), + m_ResourceCache (ResourceCache) #ifdef _DEBUG - , m_DbgAllocator(Allocator) + , m_DbgAllocator (Allocator) #endif { -- cgit v1.2.3 From 5026a05381f82bbcdc2ff804363c96a3c1b9fa67 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 6 Mar 2019 10:17:37 -0800 Subject: Minor comment updates --- Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h index 8b9f8fb8..240493cc 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h @@ -101,7 +101,8 @@ private: // 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 is guaranteed to be alive. + // 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 -- cgit v1.2.3