Diligent Engine  v.2.4.g
PipelineStateD3D11Impl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
32 
34 #include "PipelineStateBase.hpp"
35 
36 #include "PipelineResourceSignatureD3D11Impl.hpp" // Required by PipelineStateBase
37 #include "ShaderD3D11Impl.hpp"
38 
39 namespace Diligent
40 {
41 
43 class PipelineStateD3D11Impl final : public PipelineStateBase<EngineD3D11ImplTraits>
44 {
45 public:
47 
49  class RenderDeviceD3D11Impl* pDeviceD3D11,
50  const GraphicsPipelineStateCreateInfo& CreateInfo);
52  class RenderDeviceD3D11Impl* pDeviceD3D11,
53  const ComputePipelineStateCreateInfo& CreateInfo);
55 
56  virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
57 
59  virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineState* pPSO) const override final;
60 
62  virtual ID3D11BlendState* DILIGENT_CALL_TYPE GetD3D11BlendState() override final { return m_pd3d11BlendState; }
63 
65  virtual ID3D11RasterizerState* DILIGENT_CALL_TYPE GetD3D11RasterizerState() override final { return m_pd3d11RasterizerState; }
66 
68  virtual ID3D11DepthStencilState* DILIGENT_CALL_TYPE GetD3D11DepthStencilState() override final { return m_pd3d11DepthStencilState; }
69 
71  virtual ID3D11InputLayout* DILIGENT_CALL_TYPE GetD3D11InputLayout() override final { return m_pd3d11InputLayout; }
72 
74  virtual ID3D11VertexShader* DILIGENT_CALL_TYPE GetD3D11VertexShader() override final { return GetD3D11Shader<ID3D11VertexShader>(VSInd); }
75 
77  virtual ID3D11PixelShader* DILIGENT_CALL_TYPE GetD3D11PixelShader() override final { return GetD3D11Shader<ID3D11PixelShader>(PSInd); }
78 
80  virtual ID3D11GeometryShader* DILIGENT_CALL_TYPE GetD3D11GeometryShader() override final { return GetD3D11Shader<ID3D11GeometryShader>(GSInd); }
81 
83  virtual ID3D11DomainShader* DILIGENT_CALL_TYPE GetD3D11DomainShader() override final { return GetD3D11Shader<ID3D11DomainShader>(DSInd); }
84 
86  virtual ID3D11HullShader* DILIGENT_CALL_TYPE GetD3D11HullShader() override final { return GetD3D11Shader<ID3D11HullShader>(HSInd); }
87 
89  virtual ID3D11ComputeShader* DILIGENT_CALL_TYPE GetD3D11ComputeShader() override final { return GetD3D11Shader<ID3D11ComputeShader>(CSInd); }
90 
91  Uint32 GetNumShaders() const { return m_NumShaders; }
92 
94  {
96  return m_BaseBindings[Index];
97  }
98 
100  {
101  return m_NumPixelUAVs;
102  }
103 
104 #ifdef DILIGENT_DEVELOPMENT
105  using ShaderResourceCacheArrayType = std::array<ShaderResourceCacheD3D11*, MAX_RESOURCE_SIGNATURES>;
106  using BaseBindingsArrayType = std::array<D3D11ShaderResourceCounters, MAX_RESOURCE_SIGNATURES>;
107  void DvpVerifySRBResources(const ShaderResourceCacheArrayType& ResourceCaches,
108  const BaseBindingsArrayType& BaseBindings) const;
109 #endif
110 
111 private:
112  template <typename PSOCreateInfoType>
113  void InitInternalObjects(const PSOCreateInfoType& CreateInfo,
114  CComPtr<ID3DBlob>& pVSByteCode);
115 
116  void InitResourceLayouts(const PipelineStateCreateInfo& CreateInfo,
117  const std::vector<ShaderD3D11Impl*>& Shaders,
118  CComPtr<ID3DBlob>& pVSByteCode);
119 
120  RefCntAutoPtr<PipelineResourceSignatureD3D11Impl> CreateDefaultResourceSignature(
121  const PipelineStateCreateInfo& CreateInfo,
122  const std::vector<ShaderD3D11Impl*>& Shaders);
123 
124  void Destruct();
125 
126  void ValidateShaderResources(const ShaderD3D11Impl* pShader);
127 
128  template <typename D3D11ShaderType>
129  D3D11ShaderType* GetD3D11Shader(Uint32 ShaderInd)
130  {
131  auto idx = m_ShaderIndices[ShaderInd];
132  return idx >= 0 ? static_cast<D3D11ShaderType*>(m_ppd3d11Shaders[idx].p) : nullptr;
133  }
134 
135 private:
136  // ShaderTypeIndex (e.g. VSInd, PSInd, etc.) -> index in m_ppd3d11Shaders array
137  std::array<Int8, D3D11ResourceBindPoints::NumShaderTypes> m_ShaderIndices = {-1, -1, -1, -1, -1, -1};
138 
139  // The number of shader stages in this pipeline
140  Uint8 m_NumShaders = 0;
141 
142  // The total number of pixel shader UAVs used by this pipeline, including render targets
143  Uint8 m_NumPixelUAVs = 0;
144 
145  CComPtr<ID3D11BlendState> m_pd3d11BlendState;
146  CComPtr<ID3D11RasterizerState> m_pd3d11RasterizerState;
147  CComPtr<ID3D11DepthStencilState> m_pd3d11DepthStencilState;
148  CComPtr<ID3D11InputLayout> m_pd3d11InputLayout;
149 
150  using D3D11ShaderAutoPtrType = CComPtr<ID3D11DeviceChild>;
151  D3D11ShaderAutoPtrType* m_ppd3d11Shaders = nullptr; // Shader array indexed by m_ShaderIndices[]
152 
153  D3D11ShaderResourceCounters* m_BaseBindings = nullptr; // [GetResourceSignatureCount()]
154 
155 #ifdef DILIGENT_DEVELOPMENT
156  // Shader resources for all shaders in all shader stages in the pipeline.
157  std::vector<std::shared_ptr<const ShaderResourcesD3D11>> m_ShaderResources;
158 
159  // Shader resource attributions for every resource in m_ShaderResources, in the same order.
160  std::vector<ResourceAttribution> m_ResourceAttibutions;
161 #endif
162 };
163 
164 } // namespace Diligent
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::GraphicsPipelineStateCreateInfo
Graphics pipeline state creation attributes.
Definition: PipelineState.h:397
Diligent::PipelineStateD3D11Impl::GetD3D11DepthStencilState
virtual ID3D11DepthStencilState * GetD3D11DepthStencilState() override final
Implementation of IPipelineStateD3D11::GetD3D11DepthStencilState() method.
Definition: PipelineStateD3D11Impl.hpp:68
ShaderD3D11Impl.hpp
Diligent::PipelineStateD3D11Impl::GetD3D11InputLayout
virtual ID3D11InputLayout * GetD3D11InputLayout() override final
Implementation of IPipelineStateD3D11::GetD3D11InputLayout() method.
Definition: PipelineStateD3D11Impl.hpp:71
PipelineStateBase.hpp
Diligent::IPipelineState
Pipeline state interface.
Definition: PipelineState.h:505
Diligent::IObject
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
Diligent::PipelineStateD3D11Impl::QueryInterface
virtual void QueryInterface(const INTERFACE_ID &IID, IObject **ppInterface) override final
Diligent::PipelineStateD3D11Impl
Pipeline state object implementation in Direct3D11 backend.
Definition: PipelineStateD3D11Impl.hpp:43
Diligent::PipelineStateD3D11Impl::GetD3D11HullShader
virtual ID3D11HullShader * GetD3D11HullShader() override final
Implementation of IPipelineStateD3D11::GetD3D11HullShader() method.
Definition: PipelineStateD3D11Impl.hpp:86
Diligent::INTERFACE_ID
Unique interface identifier.
Definition: InterfaceID.h:37
Diligent::PipelineStateD3D11Impl::~PipelineStateD3D11Impl
~PipelineStateD3D11Impl()
Definition: PipelineStateD3D11Impl.cpp:352
Diligent::D3D11ShaderResourceCounters
std::array< D3D11ResourceRangeCounters, D3D11_RESOURCE_RANGE_COUNT > D3D11ShaderResourceCounters
Resource counters for all shader stages and all resource types.
Definition: PipelineResourceAttribsD3D11.hpp:271
Diligent::PipelineStateCreateInfo
Pipeline state creation attributes.
Definition: PipelineState.h:370
Diligent::PipelineStateD3D11Impl::GetD3D11ComputeShader
virtual ID3D11ComputeShader * GetD3D11ComputeShader() override final
Implementation of IPipelineStateD3D11::GetD3D11ComputeShader() method.
Definition: PipelineStateD3D11Impl.hpp:89
Diligent::RefCntAutoPtr
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Diligent::ComputePipelineStateCreateInfo
Compute pipeline state description.
Definition: PipelineState.h:427
Diligent::PipelineStateD3D11Impl::GetBaseBindings
const D3D11ShaderResourceCounters & GetBaseBindings(Uint32 Index) const
Definition: PipelineStateD3D11Impl.hpp:93
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::PipelineStateD3D11Impl::GetD3D11VertexShader
virtual ID3D11VertexShader * GetD3D11VertexShader() override final
Implementation of IPipelineStateD3D11::GetD3D11VertexShader() method.
Definition: PipelineStateD3D11Impl.hpp:74
Diligent::PipelineStateD3D11Impl::GetD3D11DomainShader
virtual ID3D11DomainShader * GetD3D11DomainShader() override final
Implementation of IPipelineStateD3D11::GetD3D11DomainShader() method.
Definition: PipelineStateD3D11Impl.hpp:83
Diligent::PipelineStateD3D11Impl::GetD3D11GeometryShader
virtual ID3D11GeometryShader * GetD3D11GeometryShader() override final
Implementation of IPipelineStateD3D11::GetD3D11GeometryShader() method.
Definition: PipelineStateD3D11Impl.hpp:80
Diligent::PipelineStateD3D11Impl::IsCompatibleWith
virtual bool IsCompatibleWith(const IPipelineState *pPSO) const override final
Implementation of IPipelineState::IsCompatibleWith() in Direct3D11 backend.
Definition: PipelineStateD3D11Impl.cpp:374
Diligent::PipelineStateD3D11Impl::GetD3D11BlendState
virtual ID3D11BlendState * GetD3D11BlendState() override final
Implementation of IPipelineStateD3D11::GetD3D11BlendState() method.
Definition: PipelineStateD3D11Impl.hpp:62
Diligent::PipelineStateBase< EngineD3D11ImplTraits >::GetResourceSignatureCount
virtual Uint32 GetResourceSignatureCount() const override final
Implementation of IPipelineState::GetResourceSignatureCount().
Definition: PipelineStateBase.hpp:426
Diligent::PipelineStateD3D11Impl::GetD3D11RasterizerState
virtual ID3D11RasterizerState * GetD3D11RasterizerState() override final
Implementation of IPipelineStateD3D11::GetD3D11RasterizerState() method.
Definition: PipelineStateD3D11Impl.hpp:65
Diligent::ShaderD3D11Impl
Shader implementation in Direct3D11 backend.
Definition: ShaderD3D11Impl.hpp:48
EngineD3D11ImplTraits.hpp
Diligent::Uint8
uint8_t Uint8
8-bit unsigned integer
Definition: BasicTypes.h:53
VERIFY_EXPR
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
Diligent::RenderDeviceD3D11Impl
Render device implementation in Direct3D11 backend.
Definition: RenderDeviceD3D11Impl.hpp:40
Diligent::PipelineStateD3D11Impl::PipelineStateD3D11Impl
PipelineStateD3D11Impl(IReferenceCounters *pRefCounters, class RenderDeviceD3D11Impl *pDeviceD3D11, const GraphicsPipelineStateCreateInfo &CreateInfo)
Definition: PipelineStateD3D11Impl.cpp:285
Diligent::PipelineStateBase
Template class implementing base functionality of the pipeline state object.
Definition: PipelineStateBase.hpp:99
Diligent::PipelineStateD3D11Impl::GetD3D11PixelShader
virtual ID3D11PixelShader * GetD3D11PixelShader() override final
Implementation of IPipelineStateD3D11::GetD3D11PixelShader() method.
Definition: PipelineStateD3D11Impl.hpp:77
Diligent::PipelineStateD3D11Impl::GetNumPixleUAVs
Uint8 GetNumPixleUAVs() const
Definition: PipelineStateD3D11Impl.hpp:99
Diligent::PipelineStateD3D11Impl::GetNumShaders
Uint32 GetNumShaders() const
Definition: PipelineStateD3D11Impl.hpp:91
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
PipelineResourceSignatureD3D11Impl.hpp