Diligent Engine  v.2.4.g
PipelineStateVkImpl.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 <array>
34 #include <memory>
35 
36 #include "EngineVkImplTraits.hpp"
37 #include "PipelineStateBase.hpp"
38 #include "PipelineResourceSignatureVkImpl.hpp" // Required by PipelineStateBase
39 
42 #include "SRBMemoryAllocator.hpp"
43 #include "PipelineLayoutVk.hpp"
46 
47 namespace Diligent
48 {
49 
51 class PipelineStateVkImpl final : public PipelineStateBase<EngineVkImplTraits>
52 {
53 public:
55 
60 
62 
63 
64  virtual IRenderPassVk* DILIGENT_CALL_TYPE GetRenderPass() const override final { return GetRenderPassPtr().RawPtr<IRenderPassVk>(); }
65 
67  virtual VkPipeline DILIGENT_CALL_TYPE GetVkPipeline() const override final { return m_Pipeline; }
68 
69  const PipelineLayoutVk& GetPipelineLayout() const { return m_PipelineLayout; }
70 
71  static RenderPassDesc GetImplicitRenderPassDesc(Uint32 NumRenderTargets,
72  const TEXTURE_FORMAT RTVFormats[],
73  TEXTURE_FORMAT DSVFormat,
74  Uint8 SampleCount,
75  std::array<RenderPassAttachmentDesc, MAX_RENDER_TARGETS + 1>& Attachments,
76  std::array<AttachmentReference, MAX_RENDER_TARGETS + 1>& AttachmentReferences,
78 
79 
80 
82  {
84  ShaderStageInfo(const ShaderVkImpl* pShader);
85 
86  void Append(const ShaderVkImpl* pShader);
87  size_t Count() const;
88 
89  // Shader stage type. All shaders in the stage must have the same type.
91 
92  std::vector<const ShaderVkImpl*> Shaders;
93  std::vector<std::vector<uint32_t>> SPIRVs;
94 
95  friend SHADER_TYPE GetShaderStageType(const ShaderStageInfo& Stage) { return Stage.Type; }
96  };
97  using TShaderStages = std::vector<ShaderStageInfo>;
98 
99 #ifdef DILIGENT_DEVELOPMENT
100  // Performs validation of SRB resource parameters that are not possible to validate
101  // when resource is bound.
102  using ShaderResourceCacheArrayType = std::array<ShaderResourceCacheVk*, MAX_RESOURCE_SIGNATURES>;
103  void DvpVerifySRBResources(const ShaderResourceCacheArrayType& ResourceCaches) const;
104 
105  void DvpValidateResourceLimits() const;
106 #endif
107 
108 private:
109  template <typename PSOCreateInfoType>
110  TShaderStages InitInternalObjects(const PSOCreateInfoType& CreateInfo,
111  std::vector<VkPipelineShaderStageCreateInfo>& vkShaderStages,
112  std::vector<VulkanUtilities::ShaderModuleWrapper>& ShaderModules);
113 
114  void InitPipelineLayout(const PipelineStateCreateInfo& CreateInfo,
115  TShaderStages& ShaderStages);
116 
117  RefCntAutoPtr<PipelineResourceSignatureVkImpl> CreateDefaultSignature(
118  const PipelineStateCreateInfo& CreateInfo,
119  const TShaderStages& ShaderStages);
120 
121  void Destruct();
122 
124  PipelineLayoutVk m_PipelineLayout;
125 
126 #ifdef DILIGENT_DEVELOPMENT
127  // Shader resources for all shaders in all shader stages
128  std::vector<std::shared_ptr<const SPIRVShaderResources>> m_ShaderResources;
129  // Resource attributions for every resource in m_ShaderResources, in the same order
130  std::vector<ResourceAttribution> m_ResourceAttibutions;
131 #endif
132 };
133 
134 } // namespace Diligent
Diligent::PipelineStateVkImpl::ShaderStageInfo::GetShaderStageType
friend SHADER_TYPE GetShaderStageType(const ShaderStageInfo &Stage)
Definition: PipelineStateVkImpl.hpp:95
Diligent::PipelineStateVkImpl::ShaderStageInfo::ShaderStageInfo
ShaderStageInfo()
Definition: PipelineStateVkImpl.hpp:83
ShaderVariableManagerVk.hpp
PipelineLayoutVk.hpp
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::RenderDeviceVkImpl
Render device implementation in Vulkan backend.
Definition: RenderDeviceVkImpl.hpp:58
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::ShaderVkImpl
Shader object object implementation in Vulkan backend.
Definition: ShaderVkImpl.hpp:41
Diligent::PipelineStateVkImpl::PipelineStateVkImpl
PipelineStateVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl *pDeviceVk, const GraphicsPipelineStateCreateInfo &CreateInfo)
Definition: PipelineStateVkImpl.cpp:994
Diligent::PipelineStateVkImpl
Pipeline state object implementation in Vulkan backend.
Definition: PipelineStateVkImpl.hpp:51
Diligent::RenderPassDesc
Render pass description.
Definition: RenderPass.h:341
Diligent::PipelineStateVkImpl::GetPipelineLayout
const PipelineLayoutVk & GetPipelineLayout() const
Definition: PipelineStateVkImpl.hpp:69
Diligent::PipelineStateBase< EngineVkImplTraits >::GetRenderPassPtr
RefCntAutoPtr< IRenderPass > const & GetRenderPassPtr() const
Definition: PipelineStateBase.hpp:276
PipelineResourceSignatureVkImpl.hpp
Diligent::PipelineStateVkImpl::ShaderStageInfo::Append
void Append(const ShaderVkImpl *pShader)
Definition: PipelineStateVkImpl.cpp:628
Diligent::PipelineStateVkImpl::ShaderStageInfo
Definition: PipelineStateVkImpl.hpp:81
SRBMemoryAllocator.hpp
Diligent::PipelineStateVkImpl::GetImplicitRenderPassDesc
static RenderPassDesc GetImplicitRenderPassDesc(Uint32 NumRenderTargets, const TEXTURE_FORMAT RTVFormats[], TEXTURE_FORMAT DSVFormat, Uint8 SampleCount, std::array< RenderPassAttachmentDesc, MAX_RENDER_TARGETS+1 > &Attachments, std::array< AttachmentReference, MAX_RENDER_TARGETS+1 > &AttachmentReferences, SubpassDesc &SubpassDesc)
Definition: PipelineStateVkImpl.cpp:657
Diligent::PipelineStateVkImpl::ShaderStageInfo::Count
size_t Count() const
Definition: PipelineStateVkImpl.cpp:650
IMPLEMENT_QUERY_INTERFACE_IN_PLACE
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName)
Definition: ObjectBase.hpp:59
Diligent::PipelineStateCreateInfo
Pipeline state creation attributes.
Definition: PipelineState.h:370
Diligent::SubpassDesc
Render pass subpass decription.
Definition: RenderPass.h:186
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::PipelineLayoutVk
Implementation of the Diligent::PipelineLayoutVk class.
Definition: PipelineLayoutVk.hpp:44
Diligent::PipelineStateVkImpl::~PipelineStateVkImpl
~PipelineStateVkImpl()
Definition: PipelineStateVkImpl.cpp:1062
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::SHADER_TYPE_UNKNOWN
@ SHADER_TYPE_UNKNOWN
Unknown shader type.
Definition: GraphicsTypes.h:67
Diligent::PipelineStateVkImpl::TShaderStages
std::vector< ShaderStageInfo > TShaderStages
Definition: PipelineStateVkImpl.hpp:97
Diligent::PipelineStateVkImpl::GetRenderPass
virtual IRenderPassVk * GetRenderPass() const override final
Implementation of IPipelineStateVk::GetRenderPass().
Definition: PipelineStateVkImpl.hpp:64
Diligent::TEXTURE_FORMAT
TEXTURE_FORMAT
Texture formats.
Definition: GraphicsTypes.h:328
VulkanCommandBuffer.hpp
Diligent::PipelineStateVkImpl::GetVkPipeline
virtual VkPipeline GetVkPipeline() const override final
Implementation of IPipelineStateVk::GetVkPipeline().
Definition: PipelineStateVkImpl.hpp:67
Diligent::Uint8
uint8_t Uint8
8-bit unsigned integer
Definition: BasicTypes.h:53
Diligent::PipelineStateVkImpl::ShaderStageInfo::Type
SHADER_TYPE Type
Definition: PipelineStateVkImpl.hpp:90
Diligent::IRenderPassVk
Exposes Vulkan-specific functionality of a RenderPass object.
Definition: RenderPassVk.h:49
VulkanObjectWrappers.hpp
EngineVkImplTraits.hpp
Diligent::PipelineStateBase
Template class implementing base functionality of the pipeline state object.
Definition: PipelineStateBase.hpp:99
VulkanUtilities::PipelineWrapper
DEFINE_VULKAN_OBJECT_WRAPPER(Pipeline) PipelineWrapper
Definition: VulkanLogicalDevice.hpp:76
Diligent::PipelineStateVkImpl::ShaderStageInfo::Shaders
std::vector< const ShaderVkImpl * > Shaders
Definition: PipelineStateVkImpl.hpp:92
Diligent::PipelineStateVkImpl::ShaderStageInfo::SPIRVs
std::vector< std::vector< uint32_t > > SPIRVs
Definition: PipelineStateVkImpl.hpp:93
FixedBlockMemoryAllocator.hpp
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37