1 #ifndef _VKPIPELINECONSTRUCTIONUTIL_HPP
2 #define _VKPIPELINECONSTRUCTIONUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2021 The Khronos Group Inc.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Wrapper that can construct monolithic pipeline or use
24 VK_EXT_graphics_pipeline_library for pipeline construction.
25 *//*--------------------------------------------------------------------*/
29 #include "tcuDefs.hpp"
30 #include "deSharedPtr.hpp"
37 enum PipelineConstructionType
39 PIPELINE_CONSTRUCTION_TYPE_MONOLITHIC = 0, // Construct legacy - monolithic pipeline
40 PIPELINE_CONSTRUCTION_TYPE_LINK_TIME_OPTIMIZED_LIBRARY, // Use VK_EXT_graphics_pipeline_library and construc pipeline out of 4 pipeline parts
41 PIPELINE_CONSTRUCTION_TYPE_FAST_LINKED_LIBRARY // Same as PIPELINE_CONSTRUCTION_TYPE_OPTIMISED_LIBRARY but with fast linking
44 void checkPipelineLibraryRequirements (const InstanceInterface& vki,
45 VkPhysicalDevice physicalDevice,
46 PipelineConstructionType pipelineConstructionType);
48 // This exception may be raised in one of the intermediate steps when using shader module IDs instead of normal module objects.
49 class PipelineCompileRequiredError : public std::runtime_error
52 PipelineCompileRequiredError (const std::string& msg)
53 : std::runtime_error(msg)
57 // Class that can build monolithic pipeline or fully separated pipeline libraries
58 // depending on PipelineType specified in the constructor.
59 // Rarely needed configuration was extracted to setDefault*/disable* functions while common
60 // state setup is provided as arguments of four setup* functions - one for each state group.
61 class GraphicsPipelineWrapper
64 GraphicsPipelineWrapper (const DeviceInterface& vk,
66 const PipelineConstructionType pipelineConstructionType,
67 const VkPipelineCreateFlags flags = 0u);
69 GraphicsPipelineWrapper (GraphicsPipelineWrapper&&) noexcept;
71 ~GraphicsPipelineWrapper (void) = default;
74 // By default pipelineLayout used for monotlithic pipeline is taken from layout specified
75 // in setupPreRasterizationShaderState but when there are also descriptor sets needed for fragment
76 // shader bindings then separate pipeline layout for monolithic pipeline must be provided
77 GraphicsPipelineWrapper& setMonolithicPipelineLayout (const VkPipelineLayout layout);
80 // By default dynamic state has to be specified before specifying other CreateInfo structures
81 GraphicsPipelineWrapper& setDynamicState (const VkPipelineDynamicStateCreateInfo* dynamicState);
83 // Specify topology that is used by default InputAssemblyState in vertex input state. This needs to be
84 // specified only when there is no custom InputAssemblyState provided in setupVertexInputStete and when
85 // topology is diferent then VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST which is used by default.
86 GraphicsPipelineWrapper& setDefaultTopology (const VkPrimitiveTopology topology);
88 // Specify patch control points that is used by default TessellationState in pre-rasterization shader state.
89 // This can to be specified only when there is no custom TessellationState provided in
90 // setupPreRasterizationShaderState and when patchControlPoints is diferent then 3 which is used by default.
91 GraphicsPipelineWrapper& setDefaultPatchControlPoints (const deUint32 patchControlPoints);
93 // Enable discarding of primitives that is used by default RasterizationState in pre-rasterization shader state.
94 // This can be specified only when there is no custom RasterizationState provided in setupPreRasterizationShaderState.
95 GraphicsPipelineWrapper& setDefaultRasterizerDiscardEnable (const deBool rasterizerDiscardEnable = DE_TRUE);
97 // When some states are not provided then default structures can be used. This behaviour can be turned on by one of below methods.
98 // Some tests require those states to be NULL so we can't assume using default versions.
99 GraphicsPipelineWrapper& setDefaultRasterizationState (void);
100 GraphicsPipelineWrapper& setDefaultDepthStencilState (void);
101 GraphicsPipelineWrapper& setDefaultColorBlendState (void);
102 GraphicsPipelineWrapper& setDefaultMultisampleState (void);
104 // Pre-rasterization shader state uses provieded viewports and scissors to create ViewportState. By default
105 // number of viewports and scissors is same as number of items in vector but when vectors are empty then by
106 // default count of viewports/scissors is set to 1. This can be changed by below functions.
107 GraphicsPipelineWrapper& setDefaultViewportsCount (deUint32 viewportCount = 0u);
108 GraphicsPipelineWrapper& setDefaultScissorsCount (deUint32 scissorCount = 0u);
110 // Pre-rasterization shader state uses default ViewportState, this method extends it with VkPipelineViewportDepthClipControlCreateInfoEXT.
111 GraphicsPipelineWrapper& setDepthClipControl (const VkPipelineViewportDepthClipControlCreateInfoEXT* depthClipControlCreateInfo);
113 // Pre-rasterization shader state uses provieded viewports and scissors to create ViewportState. When disableViewportState
114 // is used then ViewportState won't be constructed and NULL will be used.
115 GraphicsPipelineWrapper& disableViewportState (void);
118 // Setup vertex input state. When VertexInputState or InputAssemblyState are not provided then default structures will be used.
119 GraphicsPipelineWrapper& setupVertexInputStete (const VkPipelineVertexInputStateCreateInfo* vertexInputState = DE_NULL,
120 const VkPipelineInputAssemblyStateCreateInfo* inputAssemblyState = DE_NULL,
121 const VkPipelineCache partPipelineCache = DE_NULL,
122 VkPipelineCreationFeedbackCreateInfoEXT* partCreationFeedback = DE_NULL);
124 // Setup pre-rasterization shader state.
125 GraphicsPipelineWrapper& setupPreRasterizationShaderState (const std::vector<VkViewport>& viewports,
126 const std::vector<VkRect2D>& scissors,
127 const VkPipelineLayout layout,
128 const VkRenderPass renderPass,
129 const deUint32 subpass,
130 const VkShaderModule vertexShaderModule,
131 const VkPipelineRasterizationStateCreateInfo* rasterizationState = DE_NULL,
132 const VkShaderModule tessellationControlShaderModule = DE_NULL,
133 const VkShaderModule tessellationEvalShaderModule = DE_NULL,
134 const VkShaderModule geometryShaderModule = DE_NULL,
135 const VkSpecializationInfo* specializationInfo = DE_NULL,
136 VkPipelineRenderingCreateInfoKHR* rendering = DE_NULL,
137 const VkPipelineCache partPipelineCache = DE_NULL,
138 VkPipelineCreationFeedbackCreateInfoEXT* partCreationFeedback = DE_NULL);
140 GraphicsPipelineWrapper& setupPreRasterizationShaderState2 (const std::vector<VkViewport>& viewports,
141 const std::vector<VkRect2D>& scissors,
142 const VkPipelineLayout layout,
143 const VkRenderPass renderPass,
144 const deUint32 subpass,
145 const VkShaderModule vertexShaderModule,
146 const VkPipelineRasterizationStateCreateInfo* rasterizationState = nullptr,
147 const VkShaderModule tessellationControlShaderModulnullptre = DE_NULL,
148 const VkShaderModule tessellationEvalShaderModule = DE_NULL,
149 const VkShaderModule geometryShaderModule = DE_NULL,
150 const VkSpecializationInfo* vertSpecializationInfo = nullptr,
151 const VkSpecializationInfo* tescSpecializationInfo = nullptr,
152 const VkSpecializationInfo* teseSpecializationInfo = nullptr,
153 const VkSpecializationInfo* geomSpecializationInfo = nullptr,
154 VkPipelineRenderingCreateInfoKHR* rendering = nullptr,
155 const VkPipelineCache partPipelineCache = DE_NULL,
156 VkPipelineCreationFeedbackCreateInfoEXT* partCreationFeedback = nullptr);
158 // Note: VkPipelineShaderStageModuleIdentifierCreateInfoEXT::pIdentifier will not be copied. They need to continue to exist outside this wrapper.
159 GraphicsPipelineWrapper& setupPreRasterizationShaderState3 (const std::vector<VkViewport>& viewports,
160 const std::vector<VkRect2D>& scissors,
161 const VkPipelineLayout layout,
162 const VkRenderPass renderPass,
163 const deUint32 subpass,
164 const VkShaderModule vertexShaderModule,
165 const VkPipelineShaderStageModuleIdentifierCreateInfoEXT* vertShaderModuleId = nullptr,
166 const VkPipelineRasterizationStateCreateInfo* rasterizationState = nullptr,
167 const VkShaderModule tessellationControlShaderModule = DE_NULL,
168 const VkPipelineShaderStageModuleIdentifierCreateInfoEXT* tescShaderModuleId = nullptr,
169 const VkShaderModule tessellationEvalShaderModule = DE_NULL,
170 const VkPipelineShaderStageModuleIdentifierCreateInfoEXT* teseShaderModuleId = nullptr,
171 const VkShaderModule geometryShaderModule = DE_NULL,
172 const VkPipelineShaderStageModuleIdentifierCreateInfoEXT* geomShaderModuleId = nullptr,
173 const VkSpecializationInfo* vertSpecializationInfo = nullptr,
174 const VkSpecializationInfo* tescSpecializationInfo = nullptr,
175 const VkSpecializationInfo* teseSpecializationInfo = nullptr,
176 const VkSpecializationInfo* geomSpecializationInfo = nullptr,
177 VkPipelineRenderingCreateInfoKHR* rendering = nullptr,
178 const VkPipelineCache partPipelineCache = DE_NULL,
179 VkPipelineCreationFeedbackCreateInfoEXT* partCreationFeedback = nullptr);
181 // Setup fragment shader state.
182 GraphicsPipelineWrapper& setupFragmentShaderState (const VkPipelineLayout layout,
183 const VkRenderPass renderPass,
184 const deUint32 subpass,
185 const VkShaderModule fragmentShaderModule,
186 const VkPipelineDepthStencilStateCreateInfo* depthStencilState = DE_NULL,
187 const VkPipelineMultisampleStateCreateInfo* multisampleState = DE_NULL,
188 VkPipelineFragmentShadingRateStateCreateInfoKHR* fragmentShadingRateState = DE_NULL,
189 const VkSpecializationInfo* specializationInfo = DE_NULL,
190 const VkPipelineCache partPipelineCache = DE_NULL,
191 VkPipelineCreationFeedbackCreateInfoEXT* partCreationFeedback = DE_NULL);
193 // Note: VkPipelineShaderStageModuleIdentifierCreateInfoEXT::pIdentifier will not be copied. They need to continue to exist outside this wrapper.
194 GraphicsPipelineWrapper& setupFragmentShaderState2 (const VkPipelineLayout layout,
195 const VkRenderPass renderPass,
196 const deUint32 subpass,
197 const VkShaderModule fragmentShaderModule,
198 const VkPipelineShaderStageModuleIdentifierCreateInfoEXT* fragmentShaderModuleId = nullptr,
199 const VkPipelineDepthStencilStateCreateInfo* depthStencilState = nullptr,
200 const VkPipelineMultisampleStateCreateInfo* multisampleState = nullptr,
201 VkPipelineFragmentShadingRateStateCreateInfoKHR* fragmentShadingRateState = nullptr,
202 const VkSpecializationInfo* specializationInfo = nullptr,
203 const VkPipelineCache partPipelineCache = DE_NULL,
204 VkPipelineCreationFeedbackCreateInfoEXT* partCreationFeedback = nullptr);
206 // Setup fragment output state.
207 GraphicsPipelineWrapper& setupFragmentOutputState (const VkRenderPass renderPass,
208 const deUint32 subpass = 0u,
209 const VkPipelineColorBlendStateCreateInfo* colorBlendState = DE_NULL,
210 const VkPipelineMultisampleStateCreateInfo* multisampleState = DE_NULL,
211 const VkPipelineCache partPipelineCache = DE_NULL,
212 VkPipelineCreationFeedbackCreateInfoEXT* partCreationFeedback = DE_NULL);
214 // Build pipeline object out of provided state.
215 void buildPipeline (const VkPipelineCache pipelineCache = DE_NULL,
216 const VkPipeline basePipelineHandle = DE_NULL,
217 const deInt32 basePipelineIndex = 0,
218 VkPipelineCreationFeedbackCreateInfoEXT* creationFeedback = DE_NULL);
220 // Returns true when pipeline was build using buildPipeline method.
221 deBool wasBuild (void) const;
223 // Get compleate pipeline. GraphicsPipelineWrapper preserves ovnership and will desroy pipeline in its destructor.
224 vk::VkPipeline getPipeline (void) const;
226 // Destroy compleate pipeline - pipeline parts are not destroyed.
227 void destroyPipeline (void);
231 // No default constructor - use parametrized constructor or emplace_back in case of vectors.
232 GraphicsPipelineWrapper() = default;
238 // Store partial pipelines when non monolithic construction was used.
239 Move<VkPipeline> m_pipelineParts[4];
241 // Store monolithic pipeline or linked pipeline libraries.
242 Move<VkPipeline> m_pipelineFinal;
244 // Store internal data that is needed only for pipeline construction.
245 de::SharedPtr<InternalData> m_internalData;
250 #endif // _VKPIPELINECONSTRUCTIONUTIL_HPP