xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/draw/vktDrawCreateInfoUtil.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Intel Corporation
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief CreateInfo utilities
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vktDrawCreateInfoUtil.hpp"
26 
27 #include "vkImageUtil.hpp"
28 
29 namespace vkt
30 {
31 namespace Draw
32 {
33 
ImageSubresourceRange(vk::VkImageAspectFlags _aspectMask,uint32_t _baseMipLevel,uint32_t _levelCount,uint32_t _baseArrayLayer,uint32_t _layerCount)34 ImageSubresourceRange::ImageSubresourceRange(vk::VkImageAspectFlags _aspectMask, uint32_t _baseMipLevel,
35                                              uint32_t _levelCount, uint32_t _baseArrayLayer, uint32_t _layerCount)
36 {
37     aspectMask     = _aspectMask;
38     baseMipLevel   = _baseMipLevel;
39     levelCount     = _levelCount;
40     baseArrayLayer = _baseArrayLayer;
41     layerCount     = _layerCount;
42 }
43 
ComponentMapping(vk::VkComponentSwizzle _r,vk::VkComponentSwizzle _g,vk::VkComponentSwizzle _b,vk::VkComponentSwizzle _a)44 ComponentMapping::ComponentMapping(vk::VkComponentSwizzle _r, vk::VkComponentSwizzle _g, vk::VkComponentSwizzle _b,
45                                    vk::VkComponentSwizzle _a)
46 {
47     r = _r;
48     g = _g;
49     b = _b;
50     a = _a;
51 }
52 
ImageViewCreateInfo(vk::VkImage _image,vk::VkImageViewType _viewType,vk::VkFormat _format,const vk::VkImageSubresourceRange & _subresourceRange,const vk::VkComponentMapping & _components,vk::VkImageViewCreateFlags _flags)53 ImageViewCreateInfo::ImageViewCreateInfo(vk::VkImage _image, vk::VkImageViewType _viewType, vk::VkFormat _format,
54                                          const vk::VkImageSubresourceRange &_subresourceRange,
55                                          const vk::VkComponentMapping &_components, vk::VkImageViewCreateFlags _flags)
56 {
57     sType            = vk::VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
58     pNext            = DE_NULL;
59     flags            = 0u;
60     image            = _image;
61     viewType         = _viewType;
62     format           = _format;
63     components.r     = _components.r;
64     components.g     = _components.g;
65     components.b     = _components.b;
66     components.a     = _components.a;
67     subresourceRange = _subresourceRange;
68     flags            = _flags;
69 }
70 
ImageViewCreateInfo(vk::VkImage _image,vk::VkImageViewType _viewType,vk::VkFormat _format,const vk::VkComponentMapping & _components,vk::VkImageViewCreateFlags _flags)71 ImageViewCreateInfo::ImageViewCreateInfo(vk::VkImage _image, vk::VkImageViewType _viewType, vk::VkFormat _format,
72                                          const vk::VkComponentMapping &_components, vk::VkImageViewCreateFlags _flags)
73 {
74     sType        = vk::VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
75     pNext        = DE_NULL;
76     flags        = 0u;
77     image        = _image;
78     viewType     = _viewType;
79     format       = _format;
80     components.r = _components.r;
81     components.g = _components.g;
82     components.b = _components.b;
83     components.a = _components.a;
84 
85     vk::VkImageAspectFlags aspectFlags;
86     const tcu::TextureFormat tcuFormat = vk::mapVkFormat(_format);
87 
88     switch (tcuFormat.order)
89     {
90     case tcu::TextureFormat::D:
91         aspectFlags = vk::VK_IMAGE_ASPECT_DEPTH_BIT;
92         break;
93     case tcu::TextureFormat::S:
94         aspectFlags = vk::VK_IMAGE_ASPECT_STENCIL_BIT;
95         break;
96     case tcu::TextureFormat::DS:
97         aspectFlags = vk::VK_IMAGE_ASPECT_STENCIL_BIT | vk::VK_IMAGE_ASPECT_DEPTH_BIT;
98         break;
99     default:
100         aspectFlags = vk::VK_IMAGE_ASPECT_COLOR_BIT;
101         break;
102     }
103 
104     subresourceRange = ImageSubresourceRange(aspectFlags);
105     flags            = _flags;
106 }
107 
BufferViewCreateInfo(vk::VkBuffer _buffer,vk::VkFormat _format,vk::VkDeviceSize _offset,vk::VkDeviceSize _range)108 BufferViewCreateInfo::BufferViewCreateInfo(vk::VkBuffer _buffer, vk::VkFormat _format, vk::VkDeviceSize _offset,
109                                            vk::VkDeviceSize _range)
110 {
111     sType = vk::VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
112     pNext = DE_NULL;
113 
114     flags  = 0;
115     buffer = _buffer;
116     format = _format;
117     offset = _offset;
118     range  = _range;
119 }
120 
BufferCreateInfo(vk::VkDeviceSize _size,vk::VkBufferUsageFlags _usage,vk::VkSharingMode _sharingMode,uint32_t _queueFamilyIndexCount,const uint32_t * _pQueueFamilyIndices,vk::VkBufferCreateFlags _flags)121 BufferCreateInfo::BufferCreateInfo(vk::VkDeviceSize _size, vk::VkBufferUsageFlags _usage,
122                                    vk::VkSharingMode _sharingMode, uint32_t _queueFamilyIndexCount,
123                                    const uint32_t *_pQueueFamilyIndices, vk::VkBufferCreateFlags _flags)
124 {
125     sType                 = vk::VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
126     pNext                 = DE_NULL;
127     size                  = _size;
128     usage                 = _usage;
129     flags                 = _flags;
130     sharingMode           = _sharingMode;
131     queueFamilyIndexCount = _queueFamilyIndexCount;
132 
133     if (_queueFamilyIndexCount)
134     {
135         m_queueFamilyIndices =
136             std::vector<uint32_t>(_pQueueFamilyIndices, _pQueueFamilyIndices + _queueFamilyIndexCount);
137         pQueueFamilyIndices = &m_queueFamilyIndices[0];
138     }
139     else
140     {
141         pQueueFamilyIndices = _pQueueFamilyIndices;
142     }
143 }
144 
BufferCreateInfo(const BufferCreateInfo & other)145 BufferCreateInfo::BufferCreateInfo(const BufferCreateInfo &other)
146 {
147     sType                 = other.sType;
148     pNext                 = other.pNext;
149     size                  = other.size;
150     usage                 = other.usage;
151     flags                 = other.flags;
152     sharingMode           = other.sharingMode;
153     queueFamilyIndexCount = other.queueFamilyIndexCount;
154 
155     m_queueFamilyIndices = other.m_queueFamilyIndices;
156     DE_ASSERT(m_queueFamilyIndices.size() == queueFamilyIndexCount);
157 
158     if (m_queueFamilyIndices.size())
159     {
160         pQueueFamilyIndices = &m_queueFamilyIndices[0];
161     }
162     else
163     {
164         pQueueFamilyIndices = DE_NULL;
165     }
166 }
167 
operator =(const BufferCreateInfo & other)168 BufferCreateInfo &BufferCreateInfo::operator=(const BufferCreateInfo &other)
169 {
170     sType                 = other.sType;
171     pNext                 = other.pNext;
172     size                  = other.size;
173     usage                 = other.usage;
174     flags                 = other.flags;
175     sharingMode           = other.sharingMode;
176     queueFamilyIndexCount = other.queueFamilyIndexCount;
177 
178     m_queueFamilyIndices = other.m_queueFamilyIndices;
179 
180     DE_ASSERT(m_queueFamilyIndices.size() == queueFamilyIndexCount);
181 
182     if (m_queueFamilyIndices.size())
183     {
184         pQueueFamilyIndices = &m_queueFamilyIndices[0];
185     }
186     else
187     {
188         pQueueFamilyIndices = DE_NULL;
189     }
190 
191     return *this;
192 }
193 
ImageCreateInfo(vk::VkImageType _imageType,vk::VkFormat _format,vk::VkExtent3D _extent,uint32_t _mipLevels,uint32_t _arrayLayers,vk::VkSampleCountFlagBits _samples,vk::VkImageTiling _tiling,vk::VkImageUsageFlags _usage,vk::VkSharingMode _sharingMode,uint32_t _queueFamilyIndexCount,const uint32_t * _pQueueFamilyIndices,vk::VkImageCreateFlags _flags,vk::VkImageLayout _initialLayout)194 ImageCreateInfo::ImageCreateInfo(vk::VkImageType _imageType, vk::VkFormat _format, vk::VkExtent3D _extent,
195                                  uint32_t _mipLevels, uint32_t _arrayLayers, vk::VkSampleCountFlagBits _samples,
196                                  vk::VkImageTiling _tiling, vk::VkImageUsageFlags _usage,
197                                  vk::VkSharingMode _sharingMode, uint32_t _queueFamilyIndexCount,
198                                  const uint32_t *_pQueueFamilyIndices, vk::VkImageCreateFlags _flags,
199                                  vk::VkImageLayout _initialLayout)
200 {
201     if (_queueFamilyIndexCount)
202     {
203         m_queueFamilyIndices =
204             std::vector<uint32_t>(_pQueueFamilyIndices, _pQueueFamilyIndices + _queueFamilyIndexCount);
205     }
206 
207     sType                 = vk::VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
208     pNext                 = DE_NULL;
209     flags                 = _flags;
210     imageType             = _imageType;
211     format                = _format;
212     extent                = _extent;
213     mipLevels             = _mipLevels;
214     arrayLayers           = _arrayLayers;
215     samples               = _samples;
216     tiling                = _tiling;
217     usage                 = _usage;
218     sharingMode           = _sharingMode;
219     queueFamilyIndexCount = _queueFamilyIndexCount;
220 
221     if (m_queueFamilyIndices.size())
222     {
223         pQueueFamilyIndices = &m_queueFamilyIndices[0];
224     }
225     else
226     {
227         pQueueFamilyIndices = DE_NULL;
228     }
229     initialLayout = _initialLayout;
230 }
231 
FramebufferCreateInfo(vk::VkRenderPass _renderPass,const std::vector<vk::VkImageView> & atachments,uint32_t _width,uint32_t _height,uint32_t _layers)232 FramebufferCreateInfo::FramebufferCreateInfo(vk::VkRenderPass _renderPass,
233                                              const std::vector<vk::VkImageView> &atachments, uint32_t _width,
234                                              uint32_t _height, uint32_t _layers)
235 {
236     sType = vk::VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
237     pNext = DE_NULL;
238     flags = 0u;
239 
240     renderPass      = _renderPass;
241     attachmentCount = static_cast<uint32_t>(atachments.size());
242 
243     if (attachmentCount)
244     {
245         pAttachments = const_cast<vk::VkImageView *>(&atachments[0]);
246     }
247 
248     width  = _width;
249     height = _height;
250     layers = _layers;
251 }
252 
RenderPassCreateInfo(const std::vector<vk::VkAttachmentDescription> & attachments,const std::vector<vk::VkSubpassDescription> & subpasses,const std::vector<vk::VkSubpassDependency> & dependiences)253 RenderPassCreateInfo::RenderPassCreateInfo(const std::vector<vk::VkAttachmentDescription> &attachments,
254                                            const std::vector<vk::VkSubpassDescription> &subpasses,
255                                            const std::vector<vk::VkSubpassDependency> &dependiences)
256 
257     : m_attachments(attachments.begin(), attachments.end())
258     , m_subpasses(subpasses.begin(), subpasses.end())
259     , m_dependiences(dependiences.begin(), dependiences.end())
260     , m_attachmentsStructs(m_attachments.begin(), m_attachments.end())
261     , m_subpassesStructs(m_subpasses.begin(), m_subpasses.end())
262     , m_dependiencesStructs(m_dependiences.begin(), m_dependiences.end())
263 {
264     sType = vk::VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
265     pNext = DE_NULL;
266     flags = 0;
267 
268     attachmentCount = static_cast<uint32_t>(m_attachments.size());
269     pAttachments    = &m_attachmentsStructs[0];
270     subpassCount    = static_cast<uint32_t>(m_subpasses.size());
271     pSubpasses      = &m_subpassesStructs[0];
272     dependencyCount = static_cast<uint32_t>(m_dependiences.size());
273     pDependencies   = &m_dependiencesStructs[0];
274 }
275 
RenderPassCreateInfo(uint32_t _attachmentCount,const vk::VkAttachmentDescription * _pAttachments,uint32_t _subpassCount,const vk::VkSubpassDescription * _pSubpasses,uint32_t _dependencyCount,const vk::VkSubpassDependency * _pDependiences)276 RenderPassCreateInfo::RenderPassCreateInfo(uint32_t _attachmentCount, const vk::VkAttachmentDescription *_pAttachments,
277                                            uint32_t _subpassCount, const vk::VkSubpassDescription *_pSubpasses,
278                                            uint32_t _dependencyCount, const vk::VkSubpassDependency *_pDependiences)
279 {
280 
281     m_attachments  = std::vector<AttachmentDescription>(_pAttachments, _pAttachments + _attachmentCount);
282     m_subpasses    = std::vector<SubpassDescription>(_pSubpasses, _pSubpasses + _subpassCount);
283     m_dependiences = std::vector<SubpassDependency>(_pDependiences, _pDependiences + _dependencyCount);
284 
285     m_attachmentsStructs  = std::vector<vk::VkAttachmentDescription>(m_attachments.begin(), m_attachments.end());
286     m_subpassesStructs    = std::vector<vk::VkSubpassDescription>(m_subpasses.begin(), m_subpasses.end());
287     m_dependiencesStructs = std::vector<vk::VkSubpassDependency>(m_dependiences.begin(), m_dependiences.end());
288 
289     sType = vk::VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
290     pNext = DE_NULL;
291     flags = 0;
292 
293     attachmentCount = static_cast<uint32_t>(m_attachments.size());
294 
295     if (attachmentCount)
296     {
297         pAttachments = &m_attachmentsStructs[0];
298     }
299     else
300     {
301         pAttachments = DE_NULL;
302     }
303 
304     subpassCount = static_cast<uint32_t>(m_subpasses.size());
305 
306     if (subpassCount)
307     {
308         pSubpasses = &m_subpassesStructs[0];
309     }
310     else
311     {
312         pSubpasses = DE_NULL;
313     }
314 
315     dependencyCount = static_cast<uint32_t>(m_dependiences.size());
316 
317     if (dependencyCount)
318     {
319         pDependencies = &m_dependiencesStructs[0];
320     }
321     else
322     {
323         pDependencies = DE_NULL;
324     }
325 }
326 
addAttachment(vk::VkAttachmentDescription attachment)327 void RenderPassCreateInfo::addAttachment(vk::VkAttachmentDescription attachment)
328 {
329 
330     m_attachments.push_back(attachment);
331     m_attachmentsStructs = std::vector<vk::VkAttachmentDescription>(m_attachments.begin(), m_attachments.end());
332     attachmentCount      = static_cast<uint32_t>(m_attachments.size());
333     pAttachments         = &m_attachmentsStructs[0];
334 }
335 
addSubpass(vk::VkSubpassDescription subpass)336 void RenderPassCreateInfo::addSubpass(vk::VkSubpassDescription subpass)
337 {
338 
339     m_subpasses.push_back(subpass);
340     m_subpassesStructs = std::vector<vk::VkSubpassDescription>(m_subpasses.begin(), m_subpasses.end());
341     subpassCount       = static_cast<uint32_t>(m_subpasses.size());
342     pSubpasses         = &m_subpassesStructs[0];
343 }
344 
addDependency(vk::VkSubpassDependency dependency)345 void RenderPassCreateInfo::addDependency(vk::VkSubpassDependency dependency)
346 {
347 
348     m_dependiences.push_back(dependency);
349     m_dependiencesStructs = std::vector<vk::VkSubpassDependency>(m_dependiences.begin(), m_dependiences.end());
350 
351     dependencyCount = static_cast<uint32_t>(m_dependiences.size());
352     pDependencies   = &m_dependiencesStructs[0];
353 }
354 
RenderPassBeginInfo(vk::VkRenderPass _renderPass,vk::VkFramebuffer _framebuffer,vk::VkRect2D _renderArea,const std::vector<vk::VkClearValue> & _clearValues)355 RenderPassBeginInfo::RenderPassBeginInfo(vk::VkRenderPass _renderPass, vk::VkFramebuffer _framebuffer,
356                                          vk::VkRect2D _renderArea, const std::vector<vk::VkClearValue> &_clearValues)
357 {
358 
359     m_clearValues = _clearValues;
360 
361     sType           = vk::VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
362     pNext           = DE_NULL;
363     renderPass      = _renderPass;
364     framebuffer     = _framebuffer;
365     renderArea      = _renderArea;
366     clearValueCount = static_cast<uint32_t>(m_clearValues.size());
367     pClearValues    = m_clearValues.size() ? &m_clearValues[0] : DE_NULL;
368 }
369 
CmdPoolCreateInfo(uint32_t _queueFamilyIndex,unsigned int _flags)370 CmdPoolCreateInfo::CmdPoolCreateInfo(uint32_t _queueFamilyIndex, unsigned int _flags)
371 {
372     sType = vk::VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
373     pNext = DE_NULL;
374 
375     queueFamilyIndex = _queueFamilyIndex;
376     flags            = _flags;
377 }
378 
AttachmentDescription(vk::VkFormat _format,vk::VkSampleCountFlagBits _samples,vk::VkAttachmentLoadOp _loadOp,vk::VkAttachmentStoreOp _storeOp,vk::VkAttachmentLoadOp _stencilLoadOp,vk::VkAttachmentStoreOp _stencilStoreOp,vk::VkImageLayout _initialLayout,vk::VkImageLayout _finalLayout)379 AttachmentDescription::AttachmentDescription(vk::VkFormat _format, vk::VkSampleCountFlagBits _samples,
380                                              vk::VkAttachmentLoadOp _loadOp, vk::VkAttachmentStoreOp _storeOp,
381                                              vk::VkAttachmentLoadOp _stencilLoadOp,
382                                              vk::VkAttachmentStoreOp _stencilStoreOp, vk::VkImageLayout _initialLayout,
383                                              vk::VkImageLayout _finalLayout)
384 {
385     flags          = 0;
386     format         = _format;
387     samples        = _samples;
388     loadOp         = _loadOp;
389     storeOp        = _storeOp;
390     stencilLoadOp  = _stencilLoadOp;
391     stencilStoreOp = _stencilStoreOp;
392     initialLayout  = _initialLayout;
393     finalLayout    = _finalLayout;
394 }
395 
AttachmentDescription(const vk::VkAttachmentDescription & rhs)396 AttachmentDescription::AttachmentDescription(const vk::VkAttachmentDescription &rhs)
397 {
398     flags          = rhs.flags;
399     format         = rhs.format;
400     samples        = rhs.samples;
401     loadOp         = rhs.loadOp;
402     storeOp        = rhs.storeOp;
403     stencilLoadOp  = rhs.stencilLoadOp;
404     stencilStoreOp = rhs.stencilStoreOp;
405     initialLayout  = rhs.initialLayout;
406     finalLayout    = rhs.finalLayout;
407 }
408 
AttachmentReference(uint32_t _attachment,vk::VkImageLayout _layout)409 AttachmentReference::AttachmentReference(uint32_t _attachment, vk::VkImageLayout _layout)
410 {
411     attachment = _attachment;
412     layout     = _layout;
413 }
414 
AttachmentReference(void)415 AttachmentReference::AttachmentReference(void)
416 {
417     attachment = VK_ATTACHMENT_UNUSED;
418     layout     = vk::VK_IMAGE_LAYOUT_UNDEFINED;
419 }
420 
SubpassDescription(vk::VkPipelineBindPoint _pipelineBindPoint,vk::VkSubpassDescriptionFlags _flags,uint32_t _inputAttachmentCount,const vk::VkAttachmentReference * _inputAttachments,uint32_t _colorAttachmentCount,const vk::VkAttachmentReference * _colorAttachments,const vk::VkAttachmentReference * _resolveAttachments,vk::VkAttachmentReference depthStencilAttachment,uint32_t _preserveAttachmentCount,const uint32_t * _preserveAttachments)421 SubpassDescription::SubpassDescription(vk::VkPipelineBindPoint _pipelineBindPoint, vk::VkSubpassDescriptionFlags _flags,
422                                        uint32_t _inputAttachmentCount,
423                                        const vk::VkAttachmentReference *_inputAttachments,
424                                        uint32_t _colorAttachmentCount,
425                                        const vk::VkAttachmentReference *_colorAttachments,
426                                        const vk::VkAttachmentReference *_resolveAttachments,
427                                        vk::VkAttachmentReference depthStencilAttachment,
428                                        uint32_t _preserveAttachmentCount, const uint32_t *_preserveAttachments)
429 {
430     m_inputAttachments =
431         std::vector<vk::VkAttachmentReference>(_inputAttachments, _inputAttachments + _inputAttachmentCount);
432     m_colorAttachments =
433         std::vector<vk::VkAttachmentReference>(_colorAttachments, _colorAttachments + _colorAttachmentCount);
434 
435     if (_resolveAttachments)
436         m_resolveAttachments =
437             std::vector<vk::VkAttachmentReference>(_resolveAttachments, _resolveAttachments + _colorAttachmentCount);
438 
439     m_preserveAttachments =
440         std::vector<uint32_t>(_preserveAttachments, _preserveAttachments + _preserveAttachmentCount);
441 
442     m_depthStencilAttachment = depthStencilAttachment;
443 
444     flags                   = _flags;
445     pipelineBindPoint       = _pipelineBindPoint;
446     inputAttachmentCount    = _inputAttachmentCount;
447     pInputAttachments       = DE_NULL;
448     colorAttachmentCount    = _colorAttachmentCount;
449     pColorAttachments       = DE_NULL;
450     pResolveAttachments     = DE_NULL;
451     pDepthStencilAttachment = &m_depthStencilAttachment;
452     pPreserveAttachments    = DE_NULL;
453     preserveAttachmentCount = _preserveAttachmentCount;
454 
455     if (!m_inputAttachments.empty())
456         pInputAttachments = &m_inputAttachments[0];
457 
458     if (!m_colorAttachments.empty())
459         pColorAttachments = &m_colorAttachments[0];
460 
461     if (!m_resolveAttachments.empty())
462         pResolveAttachments = &m_resolveAttachments[0];
463 
464     if (!m_preserveAttachments.empty())
465         pPreserveAttachments = &m_preserveAttachments[0];
466 }
467 
SubpassDescription(const vk::VkSubpassDescription & rhs)468 SubpassDescription::SubpassDescription(const vk::VkSubpassDescription &rhs)
469 {
470     *static_cast<vk::VkSubpassDescription *>(this) = rhs;
471 
472     m_inputAttachments =
473         std::vector<vk::VkAttachmentReference>(rhs.pInputAttachments, rhs.pInputAttachments + rhs.inputAttachmentCount);
474 
475     m_colorAttachments =
476         std::vector<vk::VkAttachmentReference>(rhs.pColorAttachments, rhs.pColorAttachments + rhs.colorAttachmentCount);
477 
478     if (rhs.pResolveAttachments)
479         m_resolveAttachments = std::vector<vk::VkAttachmentReference>(
480             rhs.pResolveAttachments, rhs.pResolveAttachments + rhs.colorAttachmentCount);
481 
482     m_preserveAttachments =
483         std::vector<uint32_t>(rhs.pPreserveAttachments, rhs.pPreserveAttachments + rhs.preserveAttachmentCount);
484 
485     if (rhs.pDepthStencilAttachment)
486         m_depthStencilAttachment = *rhs.pDepthStencilAttachment;
487 
488     if (!m_inputAttachments.empty())
489         pInputAttachments = &m_inputAttachments[0];
490 
491     if (!m_colorAttachments.empty())
492         pColorAttachments = &m_colorAttachments[0];
493 
494     if (!m_resolveAttachments.empty())
495         pResolveAttachments = &m_resolveAttachments[0];
496 
497     pDepthStencilAttachment = &m_depthStencilAttachment;
498 
499     if (!m_preserveAttachments.empty())
500         pPreserveAttachments = &m_preserveAttachments[0];
501 }
502 
SubpassDescription(const SubpassDescription & rhs)503 SubpassDescription::SubpassDescription(const SubpassDescription &rhs)
504 {
505     *this = rhs;
506 }
507 
operator =(const SubpassDescription & rhs)508 SubpassDescription &SubpassDescription::operator=(const SubpassDescription &rhs)
509 {
510     *static_cast<vk::VkSubpassDescription *>(this) = rhs;
511 
512     m_inputAttachments       = rhs.m_inputAttachments;
513     m_colorAttachments       = rhs.m_colorAttachments;
514     m_resolveAttachments     = rhs.m_resolveAttachments;
515     m_preserveAttachments    = rhs.m_preserveAttachments;
516     m_depthStencilAttachment = rhs.m_depthStencilAttachment;
517 
518     if (!m_inputAttachments.empty())
519         pInputAttachments = &m_inputAttachments[0];
520 
521     if (!m_colorAttachments.empty())
522         pColorAttachments = &m_colorAttachments[0];
523 
524     if (!m_resolveAttachments.empty())
525         pResolveAttachments = &m_resolveAttachments[0];
526 
527     pDepthStencilAttachment = &m_depthStencilAttachment;
528 
529     if (!m_preserveAttachments.empty())
530         pPreserveAttachments = &m_preserveAttachments[0];
531 
532     return *this;
533 }
534 
SubpassDependency(uint32_t _srcSubpass,uint32_t _dstSubpass,vk::VkPipelineStageFlags _srcStageMask,vk::VkPipelineStageFlags _dstStageMask,vk::VkAccessFlags _srcAccessMask,vk::VkAccessFlags _dstAccessMask,vk::VkDependencyFlags _dependencyFlags)535 SubpassDependency::SubpassDependency(uint32_t _srcSubpass, uint32_t _dstSubpass, vk::VkPipelineStageFlags _srcStageMask,
536                                      vk::VkPipelineStageFlags _dstStageMask, vk::VkAccessFlags _srcAccessMask,
537                                      vk::VkAccessFlags _dstAccessMask, vk::VkDependencyFlags _dependencyFlags)
538 {
539     srcSubpass      = _srcSubpass;
540     dstSubpass      = _dstSubpass;
541     srcStageMask    = _srcStageMask;
542     dstStageMask    = _dstStageMask;
543     srcAccessMask   = _srcAccessMask;
544     dstAccessMask   = _dstAccessMask;
545     dependencyFlags = _dependencyFlags;
546 }
547 
SubpassDependency(const vk::VkSubpassDependency & rhs)548 SubpassDependency::SubpassDependency(const vk::VkSubpassDependency &rhs)
549 {
550     srcSubpass      = rhs.srcSubpass;
551     dstSubpass      = rhs.dstSubpass;
552     srcStageMask    = rhs.srcStageMask;
553     dstStageMask    = rhs.dstStageMask;
554     srcAccessMask   = rhs.srcAccessMask;
555     dstAccessMask   = rhs.dstAccessMask;
556     dependencyFlags = rhs.dependencyFlags;
557 }
558 
CmdBufferBeginInfo(vk::VkCommandBufferUsageFlags _flags)559 CmdBufferBeginInfo::CmdBufferBeginInfo(vk::VkCommandBufferUsageFlags _flags)
560 {
561     sType            = vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
562     pNext            = DE_NULL;
563     flags            = _flags;
564     pInheritanceInfo = DE_NULL;
565 }
566 
DescriptorPoolCreateInfo(const std::vector<vk::VkDescriptorPoolSize> & poolSizeCounts,vk::VkDescriptorPoolCreateFlags _flags,uint32_t _maxSets)567 DescriptorPoolCreateInfo::DescriptorPoolCreateInfo(const std::vector<vk::VkDescriptorPoolSize> &poolSizeCounts,
568                                                    vk::VkDescriptorPoolCreateFlags _flags, uint32_t _maxSets)
569     : m_poolSizeCounts(poolSizeCounts)
570 {
571     sType         = vk::VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
572     pNext         = DE_NULL;
573     flags         = _flags;
574     maxSets       = _maxSets;
575     poolSizeCount = static_cast<uint32_t>(m_poolSizeCounts.size());
576     pPoolSizes    = &m_poolSizeCounts[0];
577 }
578 
addDescriptors(vk::VkDescriptorType type,uint32_t count)579 DescriptorPoolCreateInfo &DescriptorPoolCreateInfo::addDescriptors(vk::VkDescriptorType type, uint32_t count)
580 {
581     vk::VkDescriptorPoolSize descriptorTypeCount = {type, count};
582     m_poolSizeCounts.push_back(descriptorTypeCount);
583 
584     poolSizeCount = static_cast<uint32_t>(m_poolSizeCounts.size());
585     pPoolSizes    = &m_poolSizeCounts[0];
586 
587     return *this;
588 }
589 
DescriptorSetLayoutCreateInfo(uint32_t _bindingCount,const vk::VkDescriptorSetLayoutBinding * _pBindings)590 DescriptorSetLayoutCreateInfo::DescriptorSetLayoutCreateInfo(uint32_t _bindingCount,
591                                                              const vk::VkDescriptorSetLayoutBinding *_pBindings)
592 {
593     sType        = vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
594     pNext        = DE_NULL;
595     flags        = 0;
596     bindingCount = _bindingCount;
597     pBindings    = _pBindings;
598 }
599 
PipelineLayoutCreateInfo(uint32_t _descriptorSetCount,const vk::VkDescriptorSetLayout * _pSetLayouts,uint32_t _pushConstantRangeCount,const vk::VkPushConstantRange * _pPushConstantRanges)600 PipelineLayoutCreateInfo::PipelineLayoutCreateInfo(uint32_t _descriptorSetCount,
601                                                    const vk::VkDescriptorSetLayout *_pSetLayouts,
602                                                    uint32_t _pushConstantRangeCount,
603                                                    const vk::VkPushConstantRange *_pPushConstantRanges)
604     : m_pushConstantRanges(_pPushConstantRanges, _pPushConstantRanges + _pushConstantRangeCount)
605 {
606     for (unsigned int i = 0; i < _descriptorSetCount; i++)
607     {
608         m_setLayouts.push_back(_pSetLayouts[i]);
609     }
610 
611     sType                  = vk::VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
612     pNext                  = DE_NULL;
613     flags                  = 0;
614     setLayoutCount         = static_cast<uint32_t>(m_setLayouts.size());
615     pSetLayouts            = setLayoutCount > 0 ? &m_setLayouts[0] : DE_NULL;
616     pushConstantRangeCount = static_cast<uint32_t>(m_pushConstantRanges.size());
617 
618     if (m_pushConstantRanges.size())
619     {
620         pPushConstantRanges = &m_pushConstantRanges[0];
621     }
622     else
623     {
624         pPushConstantRanges = DE_NULL;
625     }
626 }
627 
PipelineLayoutCreateInfo(const std::vector<vk::VkDescriptorSetLayout> & setLayouts,uint32_t _pushConstantRangeCount,const vk::VkPushConstantRange * _pPushConstantRanges)628 PipelineLayoutCreateInfo::PipelineLayoutCreateInfo(const std::vector<vk::VkDescriptorSetLayout> &setLayouts,
629                                                    uint32_t _pushConstantRangeCount,
630                                                    const vk::VkPushConstantRange *_pPushConstantRanges)
631     : m_setLayouts(setLayouts)
632     , m_pushConstantRanges(_pPushConstantRanges, _pPushConstantRanges + _pushConstantRangeCount)
633 {
634     sType = vk::VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
635     pNext = DE_NULL;
636 
637     flags          = 0;
638     setLayoutCount = static_cast<uint32_t>(m_setLayouts.size());
639 
640     if (setLayoutCount)
641     {
642         pSetLayouts = &m_setLayouts[0];
643     }
644     else
645     {
646         pSetLayouts = DE_NULL;
647     }
648 
649     pushConstantRangeCount = static_cast<uint32_t>(m_pushConstantRanges.size());
650     if (pushConstantRangeCount)
651     {
652         pPushConstantRanges = &m_pushConstantRanges[0];
653     }
654     else
655     {
656         pPushConstantRanges = DE_NULL;
657     }
658 }
659 
PipelineShaderStage(vk::VkShaderModule _module,const char * _pName,vk::VkShaderStageFlagBits _stage)660 PipelineCreateInfo::PipelineShaderStage::PipelineShaderStage(vk::VkShaderModule _module, const char *_pName,
661                                                              vk::VkShaderStageFlagBits _stage)
662 {
663     sType               = vk::VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
664     pNext               = DE_NULL;
665     flags               = 0u;
666     stage               = _stage;
667     module              = _module;
668     pName               = _pName;
669     pSpecializationInfo = DE_NULL;
670 }
671 
VertexInputState(uint32_t _vertexBindingDescriptionCount,const vk::VkVertexInputBindingDescription * _pVertexBindingDescriptions,uint32_t _vertexAttributeDescriptionCount,const vk::VkVertexInputAttributeDescription * _pVertexAttributeDescriptions)672 PipelineCreateInfo::VertexInputState::VertexInputState(
673     uint32_t _vertexBindingDescriptionCount, const vk::VkVertexInputBindingDescription *_pVertexBindingDescriptions,
674     uint32_t _vertexAttributeDescriptionCount,
675     const vk::VkVertexInputAttributeDescription *_pVertexAttributeDescriptions)
676 {
677     sType                           = vk::VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
678     pNext                           = DE_NULL;
679     flags                           = 0u;
680     vertexBindingDescriptionCount   = _vertexBindingDescriptionCount;
681     pVertexBindingDescriptions      = _pVertexBindingDescriptions;
682     vertexAttributeDescriptionCount = _vertexAttributeDescriptionCount;
683     pVertexAttributeDescriptions    = _pVertexAttributeDescriptions;
684 }
685 
addDivisors(uint32_t _vertexBindingDivisorCount,const vk::VkVertexInputBindingDivisorDescriptionEXT * _pVertexBindingDivisors)686 PipelineCreateInfo::VertexInputState &PipelineCreateInfo::VertexInputState::addDivisors(
687     uint32_t _vertexBindingDivisorCount, const vk::VkVertexInputBindingDivisorDescriptionEXT *_pVertexBindingDivisors)
688 {
689     m_divisorState.sType = vk::VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT;
690     m_divisorState.vertexBindingDivisorCount = _vertexBindingDivisorCount;
691     m_divisorState.pVertexBindingDivisors    = _pVertexBindingDivisors;
692 
693     // Link it into the chainadd
694     m_divisorState.pNext = this->pNext;
695     pNext                = &m_divisorState;
696 
697     return *this;
698 }
699 
InputAssemblerState(vk::VkPrimitiveTopology _topology,vk::VkBool32 _primitiveRestartEnable)700 PipelineCreateInfo::InputAssemblerState::InputAssemblerState(vk::VkPrimitiveTopology _topology,
701                                                              vk::VkBool32 _primitiveRestartEnable)
702 {
703     sType                  = vk::VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
704     pNext                  = DE_NULL;
705     flags                  = 0u;
706     topology               = _topology;
707     primitiveRestartEnable = _primitiveRestartEnable;
708 }
709 
TessellationState(uint32_t _patchControlPoints)710 PipelineCreateInfo::TessellationState::TessellationState(uint32_t _patchControlPoints)
711 {
712     sType              = vk::VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
713     pNext              = DE_NULL;
714     flags              = 0;
715     patchControlPoints = _patchControlPoints;
716 }
717 
ViewportState(uint32_t _viewportCount,std::vector<vk::VkViewport> _viewports,std::vector<vk::VkRect2D> _scissors)718 PipelineCreateInfo::ViewportState::ViewportState(uint32_t _viewportCount, std::vector<vk::VkViewport> _viewports,
719                                                  std::vector<vk::VkRect2D> _scissors)
720 {
721     sType         = vk::VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
722     pNext         = DE_NULL;
723     flags         = 0u;
724     viewportCount = _viewportCount;
725     scissorCount  = _viewportCount;
726 
727     if (!_viewports.size())
728     {
729         m_viewports.resize(viewportCount);
730         deMemset(&m_viewports[0], 0, sizeof(m_viewports[0]) * m_viewports.size());
731     }
732     else
733     {
734         m_viewports = _viewports;
735     }
736 
737     if (!_scissors.size())
738     {
739         m_scissors.resize(scissorCount);
740         deMemset(&m_scissors[0], 0, sizeof(m_scissors[0]) * m_scissors.size());
741     }
742     else
743     {
744         m_scissors = _scissors;
745     }
746 
747     pViewports = &m_viewports[0];
748     pScissors  = &m_scissors[0];
749 }
750 
ViewportState(const ViewportState & other)751 PipelineCreateInfo::ViewportState::ViewportState(const ViewportState &other)
752 {
753     sType         = other.sType;
754     pNext         = other.pNext;
755     flags         = other.flags;
756     viewportCount = other.viewportCount;
757     scissorCount  = other.scissorCount;
758 
759     m_viewports = std::vector<vk::VkViewport>(other.pViewports, other.pViewports + viewportCount);
760     m_scissors  = std::vector<vk::VkRect2D>(other.pScissors, other.pScissors + scissorCount);
761 
762     pViewports = &m_viewports[0];
763     pScissors  = &m_scissors[0];
764 }
765 
operator =(const ViewportState & other)766 PipelineCreateInfo::ViewportState &PipelineCreateInfo::ViewportState::operator=(const ViewportState &other)
767 {
768     sType         = other.sType;
769     pNext         = other.pNext;
770     flags         = other.flags;
771     viewportCount = other.viewportCount;
772     scissorCount  = other.scissorCount;
773 
774     m_viewports = std::vector<vk::VkViewport>(other.pViewports, other.pViewports + scissorCount);
775     m_scissors  = std::vector<vk::VkRect2D>(other.pScissors, other.pScissors + scissorCount);
776 
777     pViewports = &m_viewports[0];
778     pScissors  = &m_scissors[0];
779     return *this;
780 }
781 
RasterizerState(vk::VkBool32 _depthClampEnable,vk::VkBool32 _rasterizerDiscardEnable,vk::VkPolygonMode _polygonMode,vk::VkCullModeFlags _cullMode,vk::VkFrontFace _frontFace,vk::VkBool32 _depthBiasEnable,float _depthBiasConstantFactor,float _depthBiasClamp,float _depthBiasSlopeFactor,float _lineWidth)782 PipelineCreateInfo::RasterizerState::RasterizerState(vk::VkBool32 _depthClampEnable,
783                                                      vk::VkBool32 _rasterizerDiscardEnable,
784                                                      vk::VkPolygonMode _polygonMode, vk::VkCullModeFlags _cullMode,
785                                                      vk::VkFrontFace _frontFace, vk::VkBool32 _depthBiasEnable,
786                                                      float _depthBiasConstantFactor, float _depthBiasClamp,
787                                                      float _depthBiasSlopeFactor, float _lineWidth)
788 {
789     sType                   = vk::VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
790     pNext                   = DE_NULL;
791     flags                   = 0u;
792     depthClampEnable        = _depthClampEnable;
793     rasterizerDiscardEnable = _rasterizerDiscardEnable;
794     polygonMode             = _polygonMode;
795     cullMode                = _cullMode;
796     frontFace               = _frontFace;
797 
798     depthBiasEnable         = _depthBiasEnable;
799     depthBiasConstantFactor = _depthBiasConstantFactor;
800     depthBiasClamp          = _depthBiasClamp;
801     depthBiasSlopeFactor    = _depthBiasSlopeFactor;
802     lineWidth               = _lineWidth;
803 }
804 
MultiSampleState(vk::VkSampleCountFlagBits _rasterizationSamples,vk::VkBool32 _sampleShadingEnable,float _minSampleShading,const std::vector<vk::VkSampleMask> & _sampleMask,bool _alphaToCoverageEnable,bool _alphaToOneEnable)805 PipelineCreateInfo::MultiSampleState::MultiSampleState(vk::VkSampleCountFlagBits _rasterizationSamples,
806                                                        vk::VkBool32 _sampleShadingEnable, float _minSampleShading,
807                                                        const std::vector<vk::VkSampleMask> &_sampleMask,
808                                                        bool _alphaToCoverageEnable, bool _alphaToOneEnable)
809     : m_sampleMask(_sampleMask)
810 {
811     sType                 = vk::VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
812     pNext                 = DE_NULL;
813     flags                 = 0u;
814     rasterizationSamples  = _rasterizationSamples;
815     sampleShadingEnable   = _sampleShadingEnable;
816     minSampleShading      = _minSampleShading;
817     pSampleMask           = &m_sampleMask[0];
818     alphaToCoverageEnable = _alphaToCoverageEnable;
819     alphaToOneEnable      = _alphaToOneEnable;
820 }
821 
MultiSampleState(const MultiSampleState & other)822 PipelineCreateInfo::MultiSampleState::MultiSampleState(const MultiSampleState &other)
823 {
824     sType                = other.sType;
825     pNext                = other.pNext;
826     flags                = other.flags;
827     rasterizationSamples = other.rasterizationSamples;
828     sampleShadingEnable  = other.sampleShadingEnable;
829     minSampleShading     = other.minSampleShading;
830 
831     const size_t sampleMaskArrayLen =
832         (sizeof(vk::VkSampleMask) * 8 + other.rasterizationSamples) / (sizeof(vk::VkSampleMask) * 8);
833 
834     m_sampleMask = std::vector<vk::VkSampleMask>(other.pSampleMask, other.pSampleMask + sampleMaskArrayLen);
835     pSampleMask  = &m_sampleMask[0];
836 }
837 
operator =(const MultiSampleState & other)838 PipelineCreateInfo::MultiSampleState &PipelineCreateInfo::MultiSampleState::operator=(const MultiSampleState &other)
839 {
840     sType                = other.sType;
841     pNext                = other.pNext;
842     flags                = other.flags;
843     rasterizationSamples = other.rasterizationSamples;
844     sampleShadingEnable  = other.sampleShadingEnable;
845     minSampleShading     = other.minSampleShading;
846 
847     const size_t sampleMaskArrayLen =
848         (sizeof(vk::VkSampleMask) * 8 + other.rasterizationSamples) / (sizeof(vk::VkSampleMask) * 8);
849 
850     m_sampleMask = std::vector<vk::VkSampleMask>(other.pSampleMask, other.pSampleMask + sampleMaskArrayLen);
851     pSampleMask  = &m_sampleMask[0];
852 
853     return *this;
854 }
855 
ColorBlendState(const std::vector<vk::VkPipelineColorBlendAttachmentState> & _attachments,vk::VkBool32 _logicOpEnable,vk::VkLogicOp _logicOp)856 PipelineCreateInfo::ColorBlendState::ColorBlendState(
857     const std::vector<vk::VkPipelineColorBlendAttachmentState> &_attachments, vk::VkBool32 _logicOpEnable,
858     vk::VkLogicOp _logicOp)
859     : m_attachments(_attachments)
860 {
861     sType           = vk::VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
862     pNext           = DE_NULL;
863     flags           = 0u;
864     logicOpEnable   = _logicOpEnable;
865     logicOp         = _logicOp;
866     attachmentCount = static_cast<uint32_t>(m_attachments.size());
867     pAttachments    = &m_attachments[0];
868     deMemset(blendConstants, 0, sizeof(blendConstants));
869 }
870 
ColorBlendState(uint32_t _attachmentCount,const vk::VkPipelineColorBlendAttachmentState * _attachments,vk::VkBool32 _logicOpEnable,vk::VkLogicOp _logicOp)871 PipelineCreateInfo::ColorBlendState::ColorBlendState(uint32_t _attachmentCount,
872                                                      const vk::VkPipelineColorBlendAttachmentState *_attachments,
873                                                      vk::VkBool32 _logicOpEnable, vk::VkLogicOp _logicOp)
874     : m_attachments(_attachments, _attachments + _attachmentCount)
875 {
876     sType           = vk::VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
877     pNext           = DE_NULL;
878     flags           = 0;
879     logicOpEnable   = _logicOpEnable;
880     logicOp         = _logicOp;
881     attachmentCount = static_cast<uint32_t>(m_attachments.size());
882     pAttachments    = &m_attachments[0];
883     deMemset(blendConstants, 0, sizeof(blendConstants));
884 }
885 
ColorBlendState(const vk::VkPipelineColorBlendStateCreateInfo & createInfo)886 PipelineCreateInfo::ColorBlendState::ColorBlendState(const vk::VkPipelineColorBlendStateCreateInfo &createInfo)
887     : m_attachments(createInfo.pAttachments, createInfo.pAttachments + createInfo.attachmentCount)
888 {
889     sType           = createInfo.sType;
890     pNext           = createInfo.pNext;
891     flags           = createInfo.flags;
892     logicOpEnable   = createInfo.logicOpEnable;
893     logicOp         = createInfo.logicOp;
894     attachmentCount = static_cast<uint32_t>(m_attachments.size());
895     pAttachments    = &m_attachments[0];
896     deMemset(blendConstants, 0, sizeof(blendConstants));
897 }
898 
ColorBlendState(const ColorBlendState & createInfo,std::vector<float> _blendConstants)899 PipelineCreateInfo::ColorBlendState::ColorBlendState(const ColorBlendState &createInfo,
900                                                      std::vector<float> _blendConstants)
901     : m_attachments(createInfo.pAttachments, createInfo.pAttachments + createInfo.attachmentCount)
902 {
903     sType           = createInfo.sType;
904     pNext           = createInfo.pNext;
905     flags           = createInfo.flags;
906     logicOpEnable   = createInfo.logicOpEnable;
907     logicOp         = createInfo.logicOp;
908     attachmentCount = static_cast<uint32_t>(m_attachments.size());
909     pAttachments    = &m_attachments[0];
910     deMemcpy(blendConstants, &_blendConstants[0], 4 * sizeof(float));
911 }
912 
Attachment(vk::VkBool32 _blendEnable,vk::VkBlendFactor _srcColorBlendFactor,vk::VkBlendFactor _dstColorBlendFactor,vk::VkBlendOp _colorBlendOp,vk::VkBlendFactor _srcAlphaBlendFactor,vk::VkBlendFactor _dstAlphaBlendFactor,vk::VkBlendOp _alphaBlendOp,vk::VkColorComponentFlags _colorWriteMask)913 PipelineCreateInfo::ColorBlendState::Attachment::Attachment(
914     vk::VkBool32 _blendEnable, vk::VkBlendFactor _srcColorBlendFactor, vk::VkBlendFactor _dstColorBlendFactor,
915     vk::VkBlendOp _colorBlendOp, vk::VkBlendFactor _srcAlphaBlendFactor, vk::VkBlendFactor _dstAlphaBlendFactor,
916     vk::VkBlendOp _alphaBlendOp, vk::VkColorComponentFlags _colorWriteMask)
917 {
918     blendEnable         = _blendEnable;
919     srcColorBlendFactor = _srcColorBlendFactor;
920     dstColorBlendFactor = _dstColorBlendFactor;
921     colorBlendOp        = _colorBlendOp;
922     srcAlphaBlendFactor = _srcAlphaBlendFactor;
923     dstAlphaBlendFactor = _dstAlphaBlendFactor;
924     alphaBlendOp        = _alphaBlendOp;
925     colorWriteMask      = _colorWriteMask;
926 }
927 
StencilOpState(vk::VkStencilOp _failOp,vk::VkStencilOp _passOp,vk::VkStencilOp _depthFailOp,vk::VkCompareOp _compareOp,uint32_t _compareMask,uint32_t _writeMask,uint32_t _reference)928 PipelineCreateInfo::DepthStencilState::StencilOpState::StencilOpState(vk::VkStencilOp _failOp, vk::VkStencilOp _passOp,
929                                                                       vk::VkStencilOp _depthFailOp,
930                                                                       vk::VkCompareOp _compareOp, uint32_t _compareMask,
931                                                                       uint32_t _writeMask, uint32_t _reference)
932 {
933     failOp      = _failOp;
934     passOp      = _passOp;
935     depthFailOp = _depthFailOp;
936     compareOp   = _compareOp;
937 
938     compareMask = _compareMask;
939     writeMask   = _writeMask;
940     reference   = _reference;
941 }
942 
DepthStencilState(vk::VkBool32 _depthTestEnable,vk::VkBool32 _depthWriteEnable,vk::VkCompareOp _depthCompareOp,vk::VkBool32 _depthBoundsTestEnable,vk::VkBool32 _stencilTestEnable,StencilOpState _front,StencilOpState _back,float _minDepthBounds,float _maxDepthBounds)943 PipelineCreateInfo::DepthStencilState::DepthStencilState(vk::VkBool32 _depthTestEnable, vk::VkBool32 _depthWriteEnable,
944                                                          vk::VkCompareOp _depthCompareOp,
945                                                          vk::VkBool32 _depthBoundsTestEnable,
946                                                          vk::VkBool32 _stencilTestEnable, StencilOpState _front,
947                                                          StencilOpState _back, float _minDepthBounds,
948                                                          float _maxDepthBounds)
949 {
950     sType                 = vk::VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
951     pNext                 = DE_NULL;
952     flags                 = 0u;
953     depthTestEnable       = _depthTestEnable;
954     depthWriteEnable      = _depthWriteEnable;
955     depthCompareOp        = _depthCompareOp;
956     depthBoundsTestEnable = _depthBoundsTestEnable;
957     stencilTestEnable     = _stencilTestEnable;
958     front                 = _front;
959     back                  = _back;
960 
961     minDepthBounds = _minDepthBounds;
962     maxDepthBounds = _maxDepthBounds;
963 }
964 
DynamicState(const std::vector<vk::VkDynamicState> & _dynamicStates)965 PipelineCreateInfo::DynamicState::DynamicState(const std::vector<vk::VkDynamicState> &_dynamicStates)
966 {
967     sType = vk::VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
968     pNext = DE_NULL;
969     flags = 0;
970 
971     if (!_dynamicStates.size())
972     {
973         const vk::VkDynamicState dynamicState[] = {
974             vk::VK_DYNAMIC_STATE_VIEWPORT,
975             vk::VK_DYNAMIC_STATE_SCISSOR,
976             vk::VK_DYNAMIC_STATE_LINE_WIDTH,
977             vk::VK_DYNAMIC_STATE_DEPTH_BIAS,
978             vk::VK_DYNAMIC_STATE_BLEND_CONSTANTS,
979             vk::VK_DYNAMIC_STATE_DEPTH_BOUNDS,
980             vk::VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
981             vk::VK_DYNAMIC_STATE_STENCIL_WRITE_MASK,
982             vk::VK_DYNAMIC_STATE_STENCIL_REFERENCE,
983         };
984 
985         for (size_t i = 0; i < DE_LENGTH_OF_ARRAY(dynamicState); ++i)
986         {
987             m_dynamicStates.push_back(dynamicState[i]);
988         }
989     }
990     else
991         m_dynamicStates = _dynamicStates;
992 
993     dynamicStateCount = static_cast<uint32_t>(m_dynamicStates.size());
994     pDynamicStates    = &m_dynamicStates[0];
995 }
996 
DynamicState(const DynamicState & other)997 PipelineCreateInfo::DynamicState::DynamicState(const DynamicState &other)
998 {
999     sType = other.sType;
1000     pNext = other.pNext;
1001 
1002     flags             = other.flags;
1003     dynamicStateCount = other.dynamicStateCount;
1004     m_dynamicStates   = std::vector<vk::VkDynamicState>(other.pDynamicStates, other.pDynamicStates + dynamicStateCount);
1005     pDynamicStates    = &m_dynamicStates[0];
1006 }
1007 
operator =(const DynamicState & other)1008 PipelineCreateInfo::DynamicState &PipelineCreateInfo::DynamicState::operator=(const DynamicState &other)
1009 {
1010     sType = other.sType;
1011     pNext = other.pNext;
1012 
1013     flags             = other.flags;
1014     dynamicStateCount = other.dynamicStateCount;
1015     m_dynamicStates   = std::vector<vk::VkDynamicState>(other.pDynamicStates, other.pDynamicStates + dynamicStateCount);
1016     pDynamicStates    = &m_dynamicStates[0];
1017 
1018     return *this;
1019 }
1020 
PipelineCreateInfo(vk::VkPipelineLayout _layout,vk::VkRenderPass _renderPass,int _subpass,vk::VkPipelineCreateFlags _flags)1021 PipelineCreateInfo::PipelineCreateInfo(vk::VkPipelineLayout _layout, vk::VkRenderPass _renderPass, int _subpass,
1022                                        vk::VkPipelineCreateFlags _flags)
1023 {
1024     deMemset(static_cast<vk::VkGraphicsPipelineCreateInfo *>(this), 0, sizeof(vk::VkGraphicsPipelineCreateInfo));
1025 
1026     sType              = vk::VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
1027     pNext              = DE_NULL;
1028     flags              = _flags;
1029     renderPass         = _renderPass;
1030     subpass            = _subpass;
1031     layout             = _layout;
1032     basePipelineHandle = DE_NULL;
1033     basePipelineIndex  = 0;
1034     pDynamicState      = DE_NULL;
1035 }
1036 
addShader(const vk::VkPipelineShaderStageCreateInfo & shader)1037 PipelineCreateInfo &PipelineCreateInfo::addShader(const vk::VkPipelineShaderStageCreateInfo &shader)
1038 {
1039     m_shaders.push_back(shader);
1040 
1041     stageCount = static_cast<uint32_t>(m_shaders.size());
1042     pStages    = &m_shaders[0];
1043 
1044     return *this;
1045 }
1046 
addState(const vk::VkPipelineVertexInputStateCreateInfo & state)1047 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineVertexInputStateCreateInfo &state)
1048 {
1049     m_vertexInputState = state;
1050     pVertexInputState  = &m_vertexInputState;
1051 
1052     return *this;
1053 }
1054 
addState(const vk::VkPipelineInputAssemblyStateCreateInfo & state)1055 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineInputAssemblyStateCreateInfo &state)
1056 {
1057     m_inputAssemblyState = state;
1058     pInputAssemblyState  = &m_inputAssemblyState;
1059 
1060     return *this;
1061 }
1062 
addState(const vk::VkPipelineColorBlendStateCreateInfo & state)1063 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineColorBlendStateCreateInfo &state)
1064 {
1065     m_colorBlendStateAttachments = std::vector<vk::VkPipelineColorBlendAttachmentState>(
1066         state.pAttachments, state.pAttachments + state.attachmentCount);
1067     m_colorBlendState              = state;
1068     m_colorBlendState.pAttachments = &m_colorBlendStateAttachments[0];
1069     pColorBlendState               = &m_colorBlendState;
1070 
1071     return *this;
1072 }
1073 
addState(const vk::VkPipelineViewportStateCreateInfo & state)1074 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineViewportStateCreateInfo &state)
1075 {
1076     m_viewports                = std::vector<vk::VkViewport>(state.pViewports, state.pViewports + state.viewportCount);
1077     m_scissors                 = std::vector<vk::VkRect2D>(state.pScissors, state.pScissors + state.scissorCount);
1078     m_viewportState            = state;
1079     m_viewportState.pViewports = &m_viewports[0];
1080     m_viewportState.pScissors  = &m_scissors[0];
1081     pViewportState             = &m_viewportState;
1082 
1083     return *this;
1084 }
1085 
addState(const vk::VkPipelineDepthStencilStateCreateInfo & state)1086 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineDepthStencilStateCreateInfo &state)
1087 {
1088     m_dynamicDepthStencilState = state;
1089     pDepthStencilState         = &m_dynamicDepthStencilState;
1090     return *this;
1091 }
1092 
addState(const vk::VkPipelineTessellationStateCreateInfo & state)1093 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineTessellationStateCreateInfo &state)
1094 {
1095     m_tessState        = state;
1096     pTessellationState = &m_tessState;
1097 
1098     return *this;
1099 }
1100 
addState(const vk::VkPipelineRasterizationStateCreateInfo & state)1101 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineRasterizationStateCreateInfo &state)
1102 {
1103     m_rasterState       = state;
1104     pRasterizationState = &m_rasterState;
1105 
1106     return *this;
1107 }
1108 
addState(const vk::VkPipelineMultisampleStateCreateInfo & state)1109 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineMultisampleStateCreateInfo &state)
1110 {
1111 
1112     const size_t sampleMaskArrayLen =
1113         (sizeof(vk::VkSampleMask) * 8 + state.rasterizationSamples) / (sizeof(vk::VkSampleMask) * 8);
1114     m_multisampleState = state;
1115     if (state.pSampleMask != DE_NULL)
1116     {
1117         m_multisampleStateSampleMask =
1118             std::vector<vk::VkSampleMask>(state.pSampleMask, state.pSampleMask + sampleMaskArrayLen);
1119         m_multisampleState.pSampleMask = &m_multisampleStateSampleMask[0];
1120     }
1121     pMultisampleState = &m_multisampleState;
1122 
1123     return *this;
1124 }
addState(const vk::VkPipelineDynamicStateCreateInfo & state)1125 PipelineCreateInfo &PipelineCreateInfo::addState(const vk::VkPipelineDynamicStateCreateInfo &state)
1126 {
1127     m_dynamicStates =
1128         std::vector<vk::VkDynamicState>(state.pDynamicStates, state.pDynamicStates + state.dynamicStateCount);
1129     m_dynamicState                = state;
1130     m_dynamicState.pDynamicStates = &m_dynamicStates[0];
1131     pDynamicState                 = &m_dynamicState;
1132 
1133     return *this;
1134 }
1135 
SamplerCreateInfo(vk::VkFilter _magFilter,vk::VkFilter _minFilter,vk::VkSamplerMipmapMode _mipmapMode,vk::VkSamplerAddressMode _addressModeU,vk::VkSamplerAddressMode _addressModeV,vk::VkSamplerAddressMode _addressModeW,float _mipLodBias,vk::VkBool32 _anisotropyEnable,float _maxAnisotropy,vk::VkBool32 _compareEnable,vk::VkCompareOp _compareOp,float _minLod,float _maxLod,vk::VkBorderColor _borderColor,vk::VkBool32 _unnormalizedCoordinates)1136 SamplerCreateInfo::SamplerCreateInfo(vk::VkFilter _magFilter, vk::VkFilter _minFilter,
1137                                      vk::VkSamplerMipmapMode _mipmapMode, vk::VkSamplerAddressMode _addressModeU,
1138                                      vk::VkSamplerAddressMode _addressModeV, vk::VkSamplerAddressMode _addressModeW,
1139                                      float _mipLodBias, vk::VkBool32 _anisotropyEnable, float _maxAnisotropy,
1140                                      vk::VkBool32 _compareEnable, vk::VkCompareOp _compareOp, float _minLod,
1141                                      float _maxLod, vk::VkBorderColor _borderColor,
1142                                      vk::VkBool32 _unnormalizedCoordinates)
1143 {
1144     sType                   = vk::VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1145     pNext                   = DE_NULL;
1146     flags                   = 0u;
1147     magFilter               = _magFilter;
1148     minFilter               = _minFilter;
1149     mipmapMode              = _mipmapMode;
1150     addressModeU            = _addressModeU;
1151     addressModeV            = _addressModeV;
1152     addressModeW            = _addressModeW;
1153     mipLodBias              = _mipLodBias;
1154     anisotropyEnable        = _anisotropyEnable;
1155     maxAnisotropy           = _maxAnisotropy;
1156     compareEnable           = _compareEnable;
1157     compareOp               = _compareOp;
1158     minLod                  = _minLod;
1159     maxLod                  = _maxLod;
1160     borderColor             = _borderColor;
1161     unnormalizedCoordinates = _unnormalizedCoordinates;
1162 }
1163 } // namespace Draw
1164 } // namespace vkt
1165