1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*
* Copyright 2019-2021 Diligent Graphics LLC
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 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 Diligent::PipelineStateD3D11Impl class
#include "EngineD3D11ImplTraits.hpp"
#include "PipelineStateBase.hpp"
#include "PipelineResourceSignatureD3D11Impl.hpp" // Required by PipelineStateBase
#include "ShaderD3D11Impl.hpp"
namespace Diligent
{
/// Pipeline state object implementation in Direct3D11 backend.
class PipelineStateD3D11Impl final : public PipelineStateBase<EngineD3D11ImplTraits>
{
public:
using TPipelineStateBase = PipelineStateBase<EngineD3D11ImplTraits>;
PipelineStateD3D11Impl(IReferenceCounters* pRefCounters,
class RenderDeviceD3D11Impl* pDeviceD3D11,
const GraphicsPipelineStateCreateInfo& CreateInfo);
PipelineStateD3D11Impl(IReferenceCounters* pRefCounters,
class RenderDeviceD3D11Impl* pDeviceD3D11,
const ComputePipelineStateCreateInfo& CreateInfo);
~PipelineStateD3D11Impl();
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
/// Implementation of IPipelineState::IsCompatibleWith() in Direct3D11 backend.
virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineState* pPSO) const override final;
/// Implementation of IPipelineStateD3D11::GetD3D11BlendState() method.
virtual ID3D11BlendState* DILIGENT_CALL_TYPE GetD3D11BlendState() override final { return m_pd3d11BlendState; }
/// Implementation of IPipelineStateD3D11::GetD3D11RasterizerState() method.
virtual ID3D11RasterizerState* DILIGENT_CALL_TYPE GetD3D11RasterizerState() override final { return m_pd3d11RasterizerState; }
/// Implementation of IPipelineStateD3D11::GetD3D11DepthStencilState() method.
virtual ID3D11DepthStencilState* DILIGENT_CALL_TYPE GetD3D11DepthStencilState() override final { return m_pd3d11DepthStencilState; }
/// Implementation of IPipelineStateD3D11::GetD3D11InputLayout() method.
virtual ID3D11InputLayout* DILIGENT_CALL_TYPE GetD3D11InputLayout() override final { return m_pd3d11InputLayout; }
/// Implementation of IPipelineStateD3D11::GetD3D11VertexShader() method.
virtual ID3D11VertexShader* DILIGENT_CALL_TYPE GetD3D11VertexShader() override final { return GetD3D11Shader<ID3D11VertexShader>(VSInd); }
/// Implementation of IPipelineStateD3D11::GetD3D11PixelShader() method.
virtual ID3D11PixelShader* DILIGENT_CALL_TYPE GetD3D11PixelShader() override final { return GetD3D11Shader<ID3D11PixelShader>(PSInd); }
/// Implementation of IPipelineStateD3D11::GetD3D11GeometryShader() method.
virtual ID3D11GeometryShader* DILIGENT_CALL_TYPE GetD3D11GeometryShader() override final { return GetD3D11Shader<ID3D11GeometryShader>(GSInd); }
/// Implementation of IPipelineStateD3D11::GetD3D11DomainShader() method.
virtual ID3D11DomainShader* DILIGENT_CALL_TYPE GetD3D11DomainShader() override final { return GetD3D11Shader<ID3D11DomainShader>(DSInd); }
/// Implementation of IPipelineStateD3D11::GetD3D11HullShader() method.
virtual ID3D11HullShader* DILIGENT_CALL_TYPE GetD3D11HullShader() override final { return GetD3D11Shader<ID3D11HullShader>(HSInd); }
/// Implementation of IPipelineStateD3D11::GetD3D11ComputeShader() method.
virtual ID3D11ComputeShader* DILIGENT_CALL_TYPE GetD3D11ComputeShader() override final { return GetD3D11Shader<ID3D11ComputeShader>(CSInd); }
Uint32 GetNumShaders() const { return m_NumShaders; }
#ifdef DILIGENT_DEVELOPMENT
void DvpVerifySRBResources(class ShaderResourceBindingD3D11Impl* pSRBs[], const D3D11ShaderResourceCounters BaseBindings[], Uint32 NumSRBs) const;
#endif
private:
template <typename PSOCreateInfoType>
void InitInternalObjects(const PSOCreateInfoType& CreateInfo,
std::vector<CComPtr<ID3DBlob>>& ByteCodes);
void InitResourceLayouts(const PipelineStateCreateInfo& CreateInfo,
const std::vector<ShaderD3D11Impl*>& Shaders,
std::vector<CComPtr<ID3DBlob>>& ByteCodes);
RefCntAutoPtr<PipelineResourceSignatureD3D11Impl> CreateDefaultResourceSignature(
const PipelineStateCreateInfo& CreateInfo,
const std::vector<ShaderD3D11Impl*>& Shaders);
void Destruct();
void ValidateShaderResources(const ShaderD3D11Impl* pShader);
template <typename D3D11ShaderType>
D3D11ShaderType* GetD3D11Shader(Uint32 ShaderInd)
{
auto idx = m_ShaderIndices[ShaderInd];
return idx >= 0 ? static_cast<D3D11ShaderType*>(m_ppd3d11Shaders[idx].p) : nullptr;
}
private:
// ShaderTypeIndex -> index in m_ppd3d11Shaders array
std::array<Int8, D3D11ResourceBindPoints::NumShaderTypes> m_ShaderIndices = {-1, -1, -1, -1, -1, -1};
// The number of shader stages in this pipeline
Uint8 m_NumShaders = 0;
CComPtr<ID3D11BlendState> m_pd3d11BlendState;
CComPtr<ID3D11RasterizerState> m_pd3d11RasterizerState;
CComPtr<ID3D11DepthStencilState> m_pd3d11DepthStencilState;
CComPtr<ID3D11InputLayout> m_pd3d11InputLayout;
using D3D11ShaderAutoPtrType = CComPtr<ID3D11DeviceChild>;
D3D11ShaderAutoPtrType* m_ppd3d11Shaders = nullptr; // Shader array indexed by m_ShaderIndices[]
#ifdef DILIGENT_DEVELOPMENT
// Shader resources for all shaders in all shader stages in the pipeline.
std::vector<std::shared_ptr<const ShaderResourcesD3D11>> m_ShaderResources;
// Shader resource attributions for every resource in m_ShaderResources, in the same order.
std::vector<ResourceAttribution> m_ResourceAttibutions;
#endif
};
} // namespace Diligent
|