Diligent Engine  v.2.4.g
PipelineStateGLImpl.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 
30 #include <vector>
31 
32 #include "EngineGLImplTraits.hpp"
33 #include "PipelineStateBase.hpp"
34 
35 #include "PipelineResourceSignatureGLImpl.hpp" // Requiured by PipelineStateBase
36 #include "ShaderGLImpl.hpp"
37 
38 #include "GLObjectWrapper.hpp"
39 #include "GLContext.hpp"
40 
41 namespace Diligent
42 {
43 
45 class PipelineStateGLImpl final : public PipelineStateBase<EngineGLImplTraits>
46 {
47 public:
49 
51  RenderDeviceGLImpl* pDeviceGL,
52  const GraphicsPipelineStateCreateInfo& CreateInfo,
53  bool IsDeviceInternal = false);
55  RenderDeviceGLImpl* pDeviceGL,
56  const ComputePipelineStateCreateInfo& CreateInfo,
57  bool IsDeviceInternal = false);
59 
61  virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override;
62 
63  void CommitProgram(GLContextState& State);
64 
66  const TBindings& GetBaseBindings(Uint32 Index) const
67  {
69  return m_BaseBindings[Index];
70  }
71 
72 #ifdef DILIGENT_DEVELOPMENT
73  using ShaderResourceCacheArrayType = std::array<ShaderResourceCacheGL*, MAX_RESOURCE_SIGNATURES>;
74  using BaseBindingsArrayType = std::array<TBindings, MAX_RESOURCE_SIGNATURES>;
75  void DvpVerifySRBResources(const ShaderResourceCacheArrayType& ResourceCaches,
76  const BaseBindingsArrayType& BaseBindings) const;
77 #endif
78 
79 private:
80  using TShaderStages = std::vector<ShaderGLImpl*>;
81 
83 
84  template <typename PSOCreateInfoType>
85  void InitInternalObjects(const PSOCreateInfoType& CreateInfo, const TShaderStages& ShaderStages);
86 
87  void InitResourceLayout(const PipelineStateCreateInfo& CreateInfo,
88  const TShaderStages& ShaderStages,
89  SHADER_TYPE ActiveStages);
90 
92  const PipelineStateCreateInfo& CreateInfo,
93  const TShaderStages& ShaderStages,
94  SHADER_TYPE ActiveStages);
95 
96  void Destruct();
97 
98  SHADER_TYPE GetShaderStageType(Uint32 Index) const;
99  Uint32 GetNumShaderStages() const { return m_NumPrograms; }
100 
101  void ValidateShaderResources(std::shared_ptr<const ShaderResourcesGL> pShaderResources, const char* ShaderName, SHADER_TYPE ShaderStages);
102 
103 private:
104  // Linked GL programs for every shader stage. Every pipeline needs to have its own programs
105  // because resource bindings assigned by PipelineResourceSignatureGLImpl::ApplyBindings depend on other
106  // shader stages.
107  using GLProgramObj = GLObjectWrappers::GLProgramObj;
108  GLProgramObj* m_GLPrograms = nullptr; // [m_NumPrograms]
109 
110  ThreadingTools::LockFlag m_ProgPipelineLockFlag;
111 
112  std::vector<std::pair<GLContext::NativeGLContextType, GLObjectWrappers::GLPipelineObj>> m_GLProgPipelines;
113 
114  Uint8 m_NumPrograms = 0;
115  bool m_IsProgramPipelineSupported = false;
116  SHADER_TYPE* m_ShaderTypes = nullptr; // [m_NumPrograms]
117 
118  TBindings* m_BaseBindings = nullptr; // [m_SignatureCount]
119 
120 #ifdef DILIGENT_DEVELOPMENT
121  // Shader resources for all shaders in all shader stages in the pipeline.
122  std::vector<std::shared_ptr<const ShaderResourcesGL>> m_ShaderResources;
123  std::vector<String> m_ShaderNames;
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 __forceinline SHADER_TYPE GetShaderStageType(const ShaderGLImpl* pShader)
131 {
132  return pShader->GetDesc().ShaderType;
133 }
134 
135 } // 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::GLContext::NativeGLContextType
EGLContext NativeGLContextType
Definition: GLContextAndroid.hpp:39
Diligent::ShaderGLImpl
Shader object implementation in OpenGL backend.
Definition: ShaderGLImpl.hpp:39
Diligent::GraphicsPipelineStateCreateInfo
Graphics pipeline state creation attributes.
Definition: PipelineState.h:397
PipelineStateBase.hpp
Diligent::SHADER_TYPE
SHADER_TYPE
Describes the shader type.
Definition: GraphicsTypes.h:65
ThreadingTools::LockFlag
Definition: LockHelper.hpp:36
Diligent::IObject
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
Diligent::DeviceObjectBase::GetDesc
virtual const ObjectDescType & GetDesc() const override final
Definition: DeviceObjectBase.hpp:140
PipelineResourceSignatureGLImpl.hpp
Diligent::PipelineStateGLImpl::CommitProgram
void CommitProgram(GLContextState &State)
Definition: PipelineStateGLImpl.cpp:415
Diligent::INTERFACE_ID
Unique interface identifier.
Definition: InterfaceID.h:37
Diligent::GetShaderStageType
__forceinline SHADER_TYPE GetShaderStageType(const ShaderD3D11Impl *pShader)
Definition: PipelineStateD3D11Impl.cpp:43
Diligent::PipelineStateGLImpl::QueryInterface
virtual void QueryInterface(const INTERFACE_ID &IID, IObject **ppInterface) override
Queries the specific interface, see IObject::QueryInterface() for details.
Diligent::ShaderDesc::ShaderType
SHADER_TYPE ShaderType
Shader type. See Diligent::SHADER_TYPE.
Definition: Shader.h:113
Diligent::PipelineStateGLImpl::GetBaseBindings
const TBindings & GetBaseBindings(Uint32 Index) const
Definition: PipelineStateGLImpl.hpp:66
Diligent::PipelineStateGLImpl::~PipelineStateGLImpl
~PipelineStateGLImpl()
Definition: PipelineStateGLImpl.cpp:382
Diligent::PipelineStateCreateInfo
Pipeline state creation attributes.
Definition: PipelineState.h:370
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::PipelineStateGLImpl
Pipeline state object implementation in OpenGL backend.
Definition: PipelineStateGLImpl.hpp:45
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
GLObjectWrappers::GLProgramObj
GLObjWrapper< GLProgramObjCreateReleaseHelper > GLProgramObj
Definition: GLObjectWrapper.hpp:167
Diligent::RenderDeviceGLImpl
Render device implementation in OpenGL backend.
Definition: RenderDeviceGLImpl.hpp:45
Diligent::PipelineResourceSignatureGLImpl::TBindings
std::array< Uint16, BINDING_RANGE_COUNT > TBindings
Definition: PipelineResourceSignatureGLImpl.hpp:82
Diligent::PipelineStateBase< EngineGLImplTraits >::GetResourceSignatureCount
virtual Uint32 GetResourceSignatureCount() const override final
Implementation of IPipelineState::GetResourceSignatureCount().
Definition: PipelineStateBase.hpp:426
EngineGLImplTraits.hpp
GLContext.hpp
Diligent::PipelineStateGLImpl::PipelineStateGLImpl
PipelineStateGLImpl(IReferenceCounters *pRefCounters, RenderDeviceGLImpl *pDeviceGL, const GraphicsPipelineStateCreateInfo &CreateInfo, bool IsDeviceInternal=false)
Definition: PipelineStateGLImpl.cpp:311
Diligent::PipelineStateGLImpl::TBindings
PipelineResourceSignatureGLImpl::TBindings TBindings
Definition: PipelineStateGLImpl.hpp:65
GLObjectWrappers::GLObjWrapper
Definition: GLObjectWrapper.hpp:36
Diligent::Uint8
uint8_t Uint8
8-bit unsigned integer
Definition: BasicTypes.h:53
VERIFY_EXPR
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
Diligent::GLContextState
Definition: GLContextState.hpp:39
Diligent::PipelineStateBase
Template class implementing base functionality of the pipeline state object.
Definition: PipelineStateBase.hpp:99
ShaderGLImpl.hpp
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
GLObjectWrapper.hpp