xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/draw/vktDrawCreateInfoUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTDRAWCREATEINFOUTIL_HPP
2 #define _VKTDRAWCREATEINFOUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 The Khronos Group Inc.
8  * Copyright (c) 2015 Intel Corporation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief CreateInfo utilities
25  *//*--------------------------------------------------------------------*/
26 
27 #include "vkDefs.hpp"
28 #include "tcuVector.hpp"
29 #include "deSharedPtr.hpp"
30 #include <vector>
31 
32 namespace vkt
33 {
34 namespace Draw
35 {
36 
37 class ImageSubresourceRange : public vk::VkImageSubresourceRange
38 {
39 public:
40     ImageSubresourceRange(vk::VkImageAspectFlags aspectMask, uint32_t baseMipLevel = 0, uint32_t levelCount = 1,
41                           uint32_t baseArrayLayer = 0, uint32_t layerCount = 1);
42 };
43 
44 class ComponentMapping : public vk::VkComponentMapping
45 {
46 public:
47     ComponentMapping(vk::VkComponentSwizzle r = vk::VK_COMPONENT_SWIZZLE_R,
48                      vk::VkComponentSwizzle g = vk::VK_COMPONENT_SWIZZLE_G,
49                      vk::VkComponentSwizzle b = vk::VK_COMPONENT_SWIZZLE_B,
50                      vk::VkComponentSwizzle a = vk::VK_COMPONENT_SWIZZLE_A);
51 };
52 
53 class ImageViewCreateInfo : public vk::VkImageViewCreateInfo
54 {
55 public:
56     ImageViewCreateInfo(vk::VkImage image, vk::VkImageViewType viewType, vk::VkFormat format,
57                         const vk::VkImageSubresourceRange &subresourceRange,
58                         const vk::VkComponentMapping &components = ComponentMapping(),
59                         vk::VkImageViewCreateFlags flags         = 0);
60 
61     ImageViewCreateInfo(vk::VkImage image, vk::VkImageViewType viewType, vk::VkFormat format,
62                         const vk::VkComponentMapping &components = ComponentMapping(),
63                         vk::VkImageViewCreateFlags flags         = 0);
64 };
65 
66 class BufferViewCreateInfo : public vk::VkBufferViewCreateInfo
67 {
68 public:
69     BufferViewCreateInfo(vk::VkBuffer buffer, vk::VkFormat format, vk::VkDeviceSize offset, vk::VkDeviceSize range);
70 };
71 
72 class BufferCreateInfo : public vk::VkBufferCreateInfo
73 {
74 public:
75     BufferCreateInfo(vk::VkDeviceSize size, vk::VkBufferCreateFlags usage,
76                      vk::VkSharingMode sharingMode = vk::VK_SHARING_MODE_EXCLUSIVE, uint32_t queueFamilyIndexCount = 0,
77                      const uint32_t *pQueueFamilyIndices = DE_NULL, vk::VkBufferCreateFlags flags = 0);
78 
79     BufferCreateInfo(const BufferCreateInfo &other);
80     BufferCreateInfo &operator=(const BufferCreateInfo &other);
81 
82 private:
83     std::vector<uint32_t> m_queueFamilyIndices;
84 };
85 
86 class ImageCreateInfo : public vk::VkImageCreateInfo
87 {
88 public:
89     ImageCreateInfo(vk::VkImageType imageType, vk::VkFormat format, vk::VkExtent3D extent, uint32_t mipLevels,
90                     uint32_t arrayLayers, vk::VkSampleCountFlagBits samples, vk::VkImageTiling tiling,
91                     vk::VkImageUsageFlags usage, vk::VkSharingMode sharingMode = vk::VK_SHARING_MODE_EXCLUSIVE,
92                     uint32_t queueFamilyIndexCount = 0, const uint32_t *pQueueFamilyIndices = DE_NULL,
93                     vk::VkImageCreateFlags flags = 0, vk::VkImageLayout initialLayout = vk::VK_IMAGE_LAYOUT_UNDEFINED);
94 
95 private:
96     ImageCreateInfo(const ImageCreateInfo &other);
97     ImageCreateInfo &operator=(const ImageCreateInfo &other);
98 
99     std::vector<uint32_t> m_queueFamilyIndices;
100 };
101 
102 class FramebufferCreateInfo : public vk::VkFramebufferCreateInfo
103 {
104 public:
105     FramebufferCreateInfo(vk::VkRenderPass renderPass, const std::vector<vk::VkImageView> &attachments, uint32_t width,
106                           uint32_t height, uint32_t layers);
107 };
108 
109 class AttachmentDescription : public vk::VkAttachmentDescription
110 {
111 public:
112     AttachmentDescription(vk::VkFormat format, vk::VkSampleCountFlagBits samples, vk::VkAttachmentLoadOp loadOp,
113                           vk::VkAttachmentStoreOp storeOp, vk::VkAttachmentLoadOp stencilLoadOp,
114                           vk::VkAttachmentStoreOp stencilStoreOp, vk::VkImageLayout initialLayout,
115                           vk::VkImageLayout finalLayout);
116 
117     AttachmentDescription(const vk::VkAttachmentDescription &);
118 };
119 
120 class AttachmentReference : public vk::VkAttachmentReference
121 {
122 public:
123     AttachmentReference(uint32_t attachment, vk::VkImageLayout layout);
124     AttachmentReference(void);
125 };
126 
127 class SubpassDescription : public vk::VkSubpassDescription
128 {
129 public:
130     SubpassDescription(vk::VkPipelineBindPoint pipelineBindPoint, vk::VkSubpassDescriptionFlags flags,
131                        uint32_t inputAttachmentCount, const vk::VkAttachmentReference *inputAttachments,
132                        uint32_t colorAttachmentCount, const vk::VkAttachmentReference *colorAttachments,
133                        const vk::VkAttachmentReference *resolveAttachments,
134                        vk::VkAttachmentReference depthStencilAttachment, uint32_t preserveAttachmentCount,
135                        const uint32_t *preserveAttachments);
136 
137     SubpassDescription(const vk::VkSubpassDescription &other);
138     SubpassDescription(const SubpassDescription &other);
139     SubpassDescription &operator=(const SubpassDescription &other);
140 
141 private:
142     std::vector<vk::VkAttachmentReference> m_inputAttachments;
143     std::vector<vk::VkAttachmentReference> m_colorAttachments;
144     std::vector<vk::VkAttachmentReference> m_resolveAttachments;
145     std::vector<uint32_t> m_preserveAttachments;
146 
147     vk::VkAttachmentReference m_depthStencilAttachment;
148 };
149 
150 class SubpassDependency : public vk::VkSubpassDependency
151 {
152 public:
153     SubpassDependency(uint32_t srcSubpass, uint32_t dstSubpass, vk::VkPipelineStageFlags srcStageMask,
154                       vk::VkPipelineStageFlags dstStageMask, vk::VkAccessFlags srcAccessMask,
155                       vk::VkAccessFlags dstAccessMask, vk::VkDependencyFlags dependencyFlags);
156 
157     SubpassDependency(const vk::VkSubpassDependency &other);
158 };
159 
160 class RenderPassCreateInfo : public vk::VkRenderPassCreateInfo
161 {
162 public:
163     RenderPassCreateInfo(
164         const std::vector<vk::VkAttachmentDescription> &attachments,
165         const std::vector<vk::VkSubpassDescription> &subpasses,
166         const std::vector<vk::VkSubpassDependency> &dependiences = std::vector<vk::VkSubpassDependency>());
167 
168     RenderPassCreateInfo(uint32_t attachmentCount = 0, const vk::VkAttachmentDescription *pAttachments = DE_NULL,
169                          uint32_t subpassCount = 0, const vk::VkSubpassDescription *pSubpasses = DE_NULL,
170                          uint32_t dependencyCount = 0, const vk::VkSubpassDependency *pDependiences = DE_NULL);
171 
172     void addAttachment(vk::VkAttachmentDescription attachment);
173     void addSubpass(vk::VkSubpassDescription subpass);
174     void addDependency(vk::VkSubpassDependency dependency);
175 
176 private:
177     std::vector<AttachmentDescription> m_attachments;
178     std::vector<SubpassDescription> m_subpasses;
179     std::vector<SubpassDependency> m_dependiences;
180 
181     std::vector<vk::VkAttachmentDescription> m_attachmentsStructs;
182     std::vector<vk::VkSubpassDescription> m_subpassesStructs;
183     std::vector<vk::VkSubpassDependency> m_dependiencesStructs;
184 
185     RenderPassCreateInfo(const RenderPassCreateInfo &other);            //Not allowed!
186     RenderPassCreateInfo &operator=(const RenderPassCreateInfo &other); //Not allowed!
187 };
188 
189 class RenderPassBeginInfo : public vk::VkRenderPassBeginInfo
190 {
191 public:
192     RenderPassBeginInfo(vk::VkRenderPass renderPass, vk::VkFramebuffer framebuffer, vk::VkRect2D renderArea,
193                         const std::vector<vk::VkClearValue> &clearValues = std::vector<vk::VkClearValue>());
194 
195 private:
196     std::vector<vk::VkClearValue> m_clearValues;
197 
198     RenderPassBeginInfo(const RenderPassBeginInfo &other);            //Not allowed!
199     RenderPassBeginInfo &operator=(const RenderPassBeginInfo &other); //Not allowed!
200 };
201 
202 class CmdPoolCreateInfo : public vk::VkCommandPoolCreateInfo
203 {
204 public:
205     CmdPoolCreateInfo(uint32_t queueFamilyIndex,
206                       vk::VkCommandPoolCreateFlags flags = vk::VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
207 };
208 
209 class CmdBufferBeginInfo : public vk::VkCommandBufferBeginInfo
210 {
211 public:
212     CmdBufferBeginInfo(vk::VkCommandBufferUsageFlags flags = 0);
213 };
214 
215 class DescriptorPoolSize : public vk::VkDescriptorPoolSize
216 {
217 public:
DescriptorPoolSize(vk::VkDescriptorType _type,uint32_t _descriptorCount)218     DescriptorPoolSize(vk::VkDescriptorType _type, uint32_t _descriptorCount)
219     {
220         type            = _type;
221         descriptorCount = _descriptorCount;
222     }
223 };
224 
225 class DescriptorPoolCreateInfo : public vk::VkDescriptorPoolCreateInfo
226 {
227 public:
228     DescriptorPoolCreateInfo(const std::vector<vk::VkDescriptorPoolSize> &poolSizeCounts,
229                              vk::VkDescriptorPoolCreateFlags flags, uint32_t maxSets);
230 
231     DescriptorPoolCreateInfo &addDescriptors(vk::VkDescriptorType type, uint32_t count);
232 
233 private:
234     std::vector<vk::VkDescriptorPoolSize> m_poolSizeCounts;
235 };
236 
237 class DescriptorSetLayoutCreateInfo : public vk::VkDescriptorSetLayoutCreateInfo
238 {
239 public:
240     DescriptorSetLayoutCreateInfo(uint32_t bindingCount, const vk::VkDescriptorSetLayoutBinding *pBindings);
241 };
242 
243 class PipelineLayoutCreateInfo : public vk::VkPipelineLayoutCreateInfo
244 {
245 public:
246     PipelineLayoutCreateInfo(uint32_t descriptorSetCount, const vk::VkDescriptorSetLayout *pSetLayouts,
247                              uint32_t pushConstantRangeCount                    = 0,
248                              const vk::VkPushConstantRange *pPushConstantRanges = DE_NULL);
249 
250     PipelineLayoutCreateInfo(
251         const std::vector<vk::VkDescriptorSetLayout> &setLayouts = std::vector<vk::VkDescriptorSetLayout>(),
252         uint32_t pushConstantRangeCount = 0, const vk::VkPushConstantRange *pPushConstantRanges = DE_NULL);
253 
254 private:
255     std::vector<vk::VkDescriptorSetLayout> m_setLayouts;
256     std::vector<vk::VkPushConstantRange> m_pushConstantRanges;
257 };
258 
259 class PipelineCreateInfo : public vk::VkGraphicsPipelineCreateInfo
260 {
261 public:
262     class VertexInputState : public vk::VkPipelineVertexInputStateCreateInfo
263     {
264     public:
265         VertexInputState(uint32_t vertexBindingDescriptionCount                                    = 0,
266                          const vk::VkVertexInputBindingDescription *pVertexBindingDescriptions     = NULL,
267                          uint32_t vertexAttributeDescriptionCount                                  = 0,
268                          const vk::VkVertexInputAttributeDescription *pVertexAttributeDescriptions = NULL);
269 
270         VertexInputState &addDivisors(
271             uint32_t vertexBindingDivisorCount                                          = 0,
272             const vk::VkVertexInputBindingDivisorDescriptionEXT *pVertexBindingDivisors = NULL);
273 
274         vk::VkPipelineVertexInputDivisorStateCreateInfoEXT m_divisorState;
275     };
276 
277     class InputAssemblerState : public vk::VkPipelineInputAssemblyStateCreateInfo
278     {
279     public:
280         InputAssemblerState(vk::VkPrimitiveTopology topology, vk::VkBool32 primitiveRestartEnable = false);
281     };
282 
283     class TessellationState : public vk::VkPipelineTessellationStateCreateInfo
284     {
285     public:
286         TessellationState(uint32_t patchControlPoints = 0);
287     };
288 
289     class ViewportState : public vk::VkPipelineViewportStateCreateInfo
290     {
291     public:
292         ViewportState(uint32_t viewportCount, std::vector<vk::VkViewport> viewports = std::vector<vk::VkViewport>(0),
293                       std::vector<vk::VkRect2D> scissors = std::vector<vk::VkRect2D>(0));
294 
295         ViewportState(const ViewportState &other);
296         ViewportState &operator=(const ViewportState &other);
297 
298         std::vector<vk::VkViewport> m_viewports;
299         std::vector<vk::VkRect2D> m_scissors;
300     };
301 
302     class RasterizerState : public vk::VkPipelineRasterizationStateCreateInfo
303     {
304     public:
305         RasterizerState(vk::VkBool32 depthClampEnable = false, vk::VkBool32 rasterizerDiscardEnable = false,
306                         vk::VkPolygonMode polygonMode = vk::VK_POLYGON_MODE_FILL,
307                         vk::VkCullModeFlags cullMode  = vk::VK_CULL_MODE_NONE,
308                         vk::VkFrontFace frontFace = vk::VK_FRONT_FACE_CLOCKWISE, vk::VkBool32 depthBiasEnable = true,
309                         float depthBiasConstantFactor = 0.0f, float depthBiasClamp = 0.0f,
310                         float depthBiasSlopeFactor = 0.0f, float lineWidth = 1.0f);
311     };
312 
313     class MultiSampleState : public vk::VkPipelineMultisampleStateCreateInfo
314     {
315     public:
316         MultiSampleState(vk::VkSampleCountFlagBits rasterizationSamples = vk::VK_SAMPLE_COUNT_1_BIT,
317                          vk::VkBool32 sampleShadingEnable = false, float minSampleShading = 0.0f,
318                          const std::vector<vk::VkSampleMask> &sampleMask = std::vector<vk::VkSampleMask>(1,
319                                                                                                          0xffffffffu),
320                          bool alphaToCoverageEnable = false, bool alphaToOneEnable = false);
321 
322         MultiSampleState(const MultiSampleState &other);
323         MultiSampleState &operator=(const MultiSampleState &other);
324 
325     private:
326         std::vector<vk::VkSampleMask> m_sampleMask;
327     };
328 
329     class ColorBlendState : public vk::VkPipelineColorBlendStateCreateInfo
330     {
331     public:
332         class Attachment : public vk::VkPipelineColorBlendAttachmentState
333         {
334         public:
335             Attachment(vk::VkBool32 blendEnable                 = false,
336                        vk::VkBlendFactor srcColorBlendFactor    = vk::VK_BLEND_FACTOR_SRC_COLOR,
337                        vk::VkBlendFactor dstColorBlendFactor    = vk::VK_BLEND_FACTOR_DST_COLOR,
338                        vk::VkBlendOp colorBlendOp               = vk::VK_BLEND_OP_ADD,
339                        vk::VkBlendFactor srcAlphaBlendFactor    = vk::VK_BLEND_FACTOR_SRC_COLOR,
340                        vk::VkBlendFactor dstAlphaBlendFactor    = vk::VK_BLEND_FACTOR_DST_COLOR,
341                        vk::VkBlendOp alphaBlendOp               = vk::VK_BLEND_OP_ADD,
342                        vk::VkColorComponentFlags colorWriteMask = vk::VK_COLOR_COMPONENT_R_BIT |
343                                                                   vk::VK_COLOR_COMPONENT_G_BIT |
344                                                                   vk::VK_COLOR_COMPONENT_B_BIT |
345                                                                   vk::VK_COLOR_COMPONENT_A_BIT);
346         };
347 
348         ColorBlendState(const std::vector<vk::VkPipelineColorBlendAttachmentState> &attachments,
349                         vk::VkBool32 alphaToCoverageEnable = false, vk::VkLogicOp logicOp = vk::VK_LOGIC_OP_COPY);
350 
351         ColorBlendState(uint32_t attachmentCount, const vk::VkPipelineColorBlendAttachmentState *attachments,
352                         vk::VkBool32 logicOpEnable = false, vk::VkLogicOp logicOp = vk::VK_LOGIC_OP_COPY);
353 
354         ColorBlendState(const vk::VkPipelineColorBlendStateCreateInfo &createInfo);
355         ColorBlendState(const ColorBlendState &createInfo, std::vector<float> blendConstants = std::vector<float>(4));
356 
357     private:
358         std::vector<vk::VkPipelineColorBlendAttachmentState> m_attachments;
359     };
360 
361     class DepthStencilState : public vk::VkPipelineDepthStencilStateCreateInfo
362     {
363     public:
364         class StencilOpState : public vk::VkStencilOpState
365         {
366         public:
367             StencilOpState(vk::VkStencilOp failOp      = vk::VK_STENCIL_OP_REPLACE,
368                            vk::VkStencilOp passOp      = vk::VK_STENCIL_OP_REPLACE,
369                            vk::VkStencilOp depthFailOp = vk::VK_STENCIL_OP_REPLACE,
370                            vk::VkCompareOp compareOp = vk::VK_COMPARE_OP_ALWAYS, uint32_t compareMask = 0xffffffffu,
371                            uint32_t writeMask = 0xffffffffu, uint32_t reference = 0u);
372         };
373 
374         DepthStencilState(vk::VkBool32 depthTestEnable = false, vk::VkBool32 depthWriteEnable = false,
375                           vk::VkCompareOp depthCompareOp     = vk::VK_COMPARE_OP_ALWAYS,
376                           vk::VkBool32 depthBoundsTestEnable = false, vk::VkBool32 stencilTestEnable = false,
377                           StencilOpState front = StencilOpState(), StencilOpState back = StencilOpState(),
378                           float minDepthBounds = 0.0f, float maxDepthBounds = 1.0f);
379     };
380 
381     class PipelineShaderStage : public vk::VkPipelineShaderStageCreateInfo
382     {
383     public:
384         PipelineShaderStage(vk::VkShaderModule shaderModule, const char *pName, vk::VkShaderStageFlagBits stage);
385     };
386 
387     class DynamicState : public vk::VkPipelineDynamicStateCreateInfo
388     {
389     public:
390         DynamicState(const std::vector<vk::VkDynamicState> &dynamicStates = std::vector<vk::VkDynamicState>(0));
391 
392         DynamicState(const DynamicState &other);
393         DynamicState &operator=(const DynamicState &other);
394 
395         std::vector<vk::VkDynamicState> m_dynamicStates;
396     };
397 
398     PipelineCreateInfo(vk::VkPipelineLayout layout, vk::VkRenderPass renderPass, int subpass,
399                        vk::VkPipelineCreateFlags flags);
400 
401     PipelineCreateInfo &addShader(const vk::VkPipelineShaderStageCreateInfo &shader);
402 
403     PipelineCreateInfo &addState(const vk::VkPipelineVertexInputStateCreateInfo &state);
404     PipelineCreateInfo &addState(const vk::VkPipelineInputAssemblyStateCreateInfo &state);
405     PipelineCreateInfo &addState(const vk::VkPipelineColorBlendStateCreateInfo &state);
406     PipelineCreateInfo &addState(const vk::VkPipelineViewportStateCreateInfo &state);
407     PipelineCreateInfo &addState(const vk::VkPipelineDepthStencilStateCreateInfo &state);
408     PipelineCreateInfo &addState(const vk::VkPipelineTessellationStateCreateInfo &state);
409     PipelineCreateInfo &addState(const vk::VkPipelineRasterizationStateCreateInfo &state);
410     PipelineCreateInfo &addState(const vk::VkPipelineMultisampleStateCreateInfo &state);
411     PipelineCreateInfo &addState(const vk::VkPipelineDynamicStateCreateInfo &state);
412 
413 protected:
414     std::vector<vk::VkPipelineShaderStageCreateInfo> m_shaders;
415 
416     vk::VkPipelineVertexInputStateCreateInfo m_vertexInputState;
417     vk::VkPipelineInputAssemblyStateCreateInfo m_inputAssemblyState;
418     std::vector<vk::VkPipelineColorBlendAttachmentState> m_colorBlendStateAttachments;
419     vk::VkPipelineColorBlendStateCreateInfo m_colorBlendState;
420     vk::VkPipelineViewportStateCreateInfo m_viewportState;
421     vk::VkPipelineDepthStencilStateCreateInfo m_dynamicDepthStencilState;
422     vk::VkPipelineTessellationStateCreateInfo m_tessState;
423     vk::VkPipelineRasterizationStateCreateInfo m_rasterState;
424     vk::VkPipelineMultisampleStateCreateInfo m_multisampleState;
425     vk::VkPipelineDynamicStateCreateInfo m_dynamicState;
426 
427     std::vector<vk::VkDynamicState> m_dynamicStates;
428     std::vector<vk::VkViewport> m_viewports;
429     std::vector<vk::VkRect2D> m_scissors;
430     std::vector<vk::VkSampleMask> m_multisampleStateSampleMask;
431 };
432 
433 class SamplerCreateInfo : public vk::VkSamplerCreateInfo
434 {
435 public:
436     SamplerCreateInfo(vk::VkFilter magFilter = vk::VK_FILTER_NEAREST, vk::VkFilter minFilter = vk::VK_FILTER_NEAREST,
437                       vk::VkSamplerMipmapMode mipmapMode = vk::VK_SAMPLER_MIPMAP_MODE_NEAREST,
438                       vk::VkSamplerAddressMode addressU  = vk::VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
439                       vk::VkSamplerAddressMode addressV  = vk::VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
440                       vk::VkSamplerAddressMode addressW  = vk::VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
441                       float mipLodBias = 0.0f, vk::VkBool32 anisotropyEnable = VK_FALSE, float maxAnisotropy = 1.0f,
442                       vk::VkBool32 compareEnable = false, vk::VkCompareOp compareOp = vk::VK_COMPARE_OP_ALWAYS,
443                       float minLod = 0.0f, float maxLod = 16.0f,
444                       vk::VkBorderColor borderColor        = vk::VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
445                       vk::VkBool32 unnormalizedCoordinates = false);
446 };
447 
448 } // namespace Draw
449 } // namespace vkt
450 
451 #endif // _VKTDRAWCREATEINFOUTIL_HPP
452