Diligent Engine  v.2.4.g
PipelineStateD3D12Impl.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 
33 #include <vector>
34 
36 #include "PipelineStateBase.hpp"
37 #include "PipelineResourceSignatureD3D12Impl.hpp" // Requiured by PipelineStateBase
38 #include "RootSignature.hpp"
39 
40 namespace Diligent
41 {
42 
43 class ShaderResourcesD3D12;
44 
46 class PipelineStateD3D12Impl final : public PipelineStateBase<EngineD3D12ImplTraits>
47 {
48 public:
50 
55 
57 
58 
59  virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineState* pPSO) const override final;
60 
62  virtual ID3D12PipelineState* DILIGENT_CALL_TYPE GetD3D12PipelineState() const override final { return static_cast<ID3D12PipelineState*>(m_pd3d12PSO.p); }
63 
65  virtual ID3D12StateObject* DILIGENT_CALL_TYPE GetD3D12StateObject() const override final { return static_cast<ID3D12StateObject*>(m_pd3d12PSO.p); }
66 
68  virtual ID3D12RootSignature* DILIGENT_CALL_TYPE GetD3D12RootSignature() const override final { return m_RootSig->GetD3D12RootSignature(); }
69 
70  const RootSignatureD3D12& GetRootSignature() const { return *m_RootSig; }
71 
72 #ifdef DILIGENT_DEVELOPMENT
73  using ShaderResourceCacheArrayType = std::array<ShaderResourceCacheD3D12*, MAX_RESOURCE_SIGNATURES>;
74  void DvpVerifySRBResources(const ShaderResourceCacheArrayType& ResourceCaches) const;
75 #endif
76 
77 private:
78  struct ShaderStageInfo
79  {
80  ShaderStageInfo() {}
81  ShaderStageInfo(ShaderD3D12Impl* _pShader);
82 
83  void Append(ShaderD3D12Impl* pShader);
84  size_t Count() const;
85 
87  std::vector<ShaderD3D12Impl*> Shaders;
88  std::vector<CComPtr<ID3DBlob>> ByteCodes;
89 
90  friend SHADER_TYPE GetShaderStageType(const ShaderStageInfo& Stage) { return Stage.Type; }
91  };
92  using TShaderStages = std::vector<ShaderStageInfo>;
93 
94  template <typename PSOCreateInfoType>
95  void InitInternalObjects(const PSOCreateInfoType& CreateInfo,
96  TShaderStages& ShaderStages,
97  LocalRootSignatureD3D12* pLocalRootSig = nullptr);
98 
99  void InitRootSignature(const PipelineStateCreateInfo& CreateInfo,
100  TShaderStages& ShaderStages,
101  LocalRootSignatureD3D12* pLocalRootSig);
102 
103  static RefCntAutoPtr<PipelineResourceSignatureD3D12Impl> CreateDefaultResourceSignature(
104  RenderDeviceD3D12Impl* pDevice,
105  const PipelineStateCreateInfo& CreateInfo,
106  TShaderStages& ShaderStages,
107  LocalRootSignatureD3D12* pLocalRootSig);
108 
109  void Destruct();
110 
111  void ValidateShaderResources(const ShaderD3D12Impl* pShader, const LocalRootSignatureD3D12* pLocalRootSig);
112 
113 private:
114  CComPtr<ID3D12DeviceChild> m_pd3d12PSO;
115  RefCntAutoPtr<RootSignatureD3D12> m_RootSig;
116 
117  // NB: Pipeline resource signatures used to create the PSO may NOT be the same as
118  // pipeline resource signatures in m_RootSig, because the latter may be used from the
119  // cache. While the two signatures may be compatible, they resource names may not be identical.
120 
121 #ifdef DILIGENT_DEVELOPMENT
122  // Shader resources for all shaders in all shader stages in the pipeline.
123  std::vector<std::shared_ptr<const ShaderResourcesD3D12>> m_ShaderResources;
124 
125  // Shader resource attributions for every resource in m_ShaderResources, in the same order.
126  std::vector<ResourceAttribution> m_ResourceAttibutions;
127 #endif
128 };
129 
130 } // namespace Diligent
Diligent::PipelineStateD3D12Impl::GetD3D12RootSignature
virtual ID3D12RootSignature * GetD3D12RootSignature() const override final
Implementation of IPipelineStateD3D12::GetD3D12RootSignature().
Definition: PipelineStateD3D12Impl.hpp:68
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::RayTracingPipelineStateCreateInfo
Ray tracing pipeline state description.
Definition: PipelineState.h:443
PipelineStateBase.hpp
Diligent::SHADER_TYPE
SHADER_TYPE
Describes the shader type.
Definition: GraphicsTypes.h:65
Diligent::IPipelineState
Pipeline state interface.
Definition: PipelineState.h:505
Diligent::RootSignatureD3D12
Implementation of the Diligent::RootSignature class.
Definition: RootSignature.hpp:67
Diligent::PipelineStateD3D12Impl::~PipelineStateD3D12Impl
~PipelineStateD3D12Impl()
Definition: PipelineStateD3D12Impl.cpp:983
Diligent::PipelineStateD3D12Impl::IsCompatibleWith
virtual bool IsCompatibleWith(const IPipelineState *pPSO) const override final
Implementation of IPipelineState::IsCompatibleWith() in Direct3D12 backend.
Definition: PipelineStateD3D12Impl.cpp:1001
Diligent::GetShaderStageType
__forceinline SHADER_TYPE GetShaderStageType(const ShaderD3D11Impl *pShader)
Definition: PipelineStateD3D11Impl.cpp:43
Diligent::RenderDeviceD3D12Impl
Render device implementation in Direct3D12 backend.
Definition: RenderDeviceD3D12Impl.hpp:70
Diligent::PipelineStateD3D12Impl::GetRootSignature
const RootSignatureD3D12 & GetRootSignature() const
Definition: PipelineStateD3D12Impl.hpp:70
IMPLEMENT_QUERY_INTERFACE_IN_PLACE
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName)
Definition: ObjectBase.hpp:59
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Type
const D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type
Definition: PipelineStateD3D12Impl.cpp:69
Diligent::ComputePipelineStateCreateInfo
Compute pipeline state description.
Definition: PipelineState.h:427
EFileAccessMode::Append
@ Append
Diligent::PipelineStateD3D12Impl::GetD3D12StateObject
virtual ID3D12StateObject * GetD3D12StateObject() const override final
Implementation of IPipelineStateD3D12::GetD3D12StateObject().
Definition: PipelineStateD3D12Impl.hpp:65
Diligent::SHADER_TYPE_UNKNOWN
@ SHADER_TYPE_UNKNOWN
Unknown shader type.
Definition: GraphicsTypes.h:67
RootSignature.hpp
EngineD3D12ImplTraits.hpp
Diligent::PipelineStateCreateInfo
struct PipelineStateCreateInfo PipelineStateCreateInfo
Definition: PipelineState.h:393
Diligent::PipelineStateD3D12Impl::PipelineStateD3D12Impl
PipelineStateD3D12Impl(IReferenceCounters *pRefCounters, RenderDeviceD3D12Impl *pDeviceD3D12, const GraphicsPipelineStateCreateInfo &CreateInfo)
Definition: PipelineStateD3D12Impl.cpp:691
Diligent::PipelineStateD3D12Impl::GetD3D12PipelineState
virtual ID3D12PipelineState * GetD3D12PipelineState() const override final
Implementation of IPipelineStateD3D12::GetD3D12PipelineState().
Definition: PipelineStateD3D12Impl.hpp:62
Diligent::PipelineStateBase
Template class implementing base functionality of the pipeline state object.
Definition: PipelineStateBase.hpp:99
Diligent::PipelineStateD3D12Impl
Pipeline state object implementation in Direct3D12 backend.
Definition: PipelineStateD3D12Impl.hpp:46
PipelineResourceSignatureD3D12Impl.hpp
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37