Merge vk-gl-cts/vulkan-cts-1.2.4 into vk-gl-cts/vulkan-cts-1.2.5
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / renderpass / vktRenderPassTestsUtil.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2018 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief RenderPass test utils
22  *//*--------------------------------------------------------------------*/
23
24 #include "vktRenderPassTestsUtil.hpp"
25 #include "tcuTestCase.hpp"
26 #include "vkMemUtil.hpp"
27 #include "vkRefUtil.hpp"
28
29 #include <vector>
30
31 using namespace vk;
32
33 namespace vkt
34 {
35 namespace renderpass
36 {
37
38 AttachmentDescription1::AttachmentDescription1 (const void*                                             pNext_,
39                                                                                                 VkAttachmentDescriptionFlags    flags_,
40                                                                                                 VkFormat                                                format_,
41                                                                                                 VkSampleCountFlagBits                   samples_,
42                                                                                                 VkAttachmentLoadOp                              loadOp_,
43                                                                                                 VkAttachmentStoreOp                             storeOp_,
44                                                                                                 VkAttachmentLoadOp                              stencilLoadOp_,
45                                                                                                 VkAttachmentStoreOp                             stencilStoreOp_,
46                                                                                                 VkImageLayout                                   initialLayout_,
47                                                                                                 VkImageLayout                                   finalLayout_)
48 {
49         DE_ASSERT(pNext_ == DE_NULL);
50
51         // No sType field in this struct
52         DE_UNREF(pNext_);
53         flags                   = flags_;
54         format                  = format_;
55         samples                 = samples_;
56         loadOp                  = loadOp_;
57         storeOp                 = storeOp_;
58         stencilLoadOp   = stencilLoadOp_;
59         stencilStoreOp  = stencilStoreOp_;
60         initialLayout   = initialLayout_;
61         finalLayout             = finalLayout_;
62 }
63
64 AttachmentDescription2::AttachmentDescription2 (const void*                                             pNext_,
65                                                                                                 VkAttachmentDescriptionFlags    flags_,
66                                                                                                 VkFormat                                                format_,
67                                                                                                 VkSampleCountFlagBits                   samples_,
68                                                                                                 VkAttachmentLoadOp                              loadOp_,
69                                                                                                 VkAttachmentStoreOp                             storeOp_,
70                                                                                                 VkAttachmentLoadOp                              stencilLoadOp_,
71                                                                                                 VkAttachmentStoreOp                             stencilStoreOp_,
72                                                                                                 VkImageLayout                                   initialLayout_,
73                                                                                                 VkImageLayout                                   finalLayout_)
74 {
75         sType                   = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2;
76         pNext                   = pNext_;
77         flags                   = flags_;
78         format                  = format_;
79         samples                 = samples_;
80         loadOp                  = loadOp_;
81         storeOp                 = storeOp_;
82         stencilLoadOp   = stencilLoadOp_;
83         stencilStoreOp  = stencilStoreOp_;
84         initialLayout   = initialLayout_;
85         finalLayout             = finalLayout_;
86 }
87
88 AttachmentReference1::AttachmentReference1 (const void*                 pNext_,
89                                                                                         deUint32                        attachment_,
90                                                                                         VkImageLayout           layout_,
91                                                                                         VkImageAspectFlags      aspectMask_)
92 {
93         DE_ASSERT(pNext_ == DE_NULL);
94
95         // No sType field in this struct
96         DE_UNREF        (pNext_);
97         attachment      = attachment_;
98         layout          = layout_;
99         DE_UNREF        (aspectMask_);
100 }
101
102 AttachmentReference2::AttachmentReference2 (const void*                 pNext_,
103                                                                                         deUint32                        attachment_,
104                                                                                         VkImageLayout           layout_,
105                                                                                         VkImageAspectFlags      aspectMask_)
106 {
107         sType           = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2;
108         pNext           = pNext_;
109         attachment      = attachment_;
110         layout          = layout_;
111         aspectMask      = aspectMask_;
112 }
113
114 SubpassDescription1::SubpassDescription1 (const void*                                           pNext_,
115                                                                                   VkSubpassDescriptionFlags                     flags_,
116                                                                                   VkPipelineBindPoint                           pipelineBindPoint_,
117                                                                                   deUint32                                                      viewMask_,
118                                                                                   deUint32                                                      inputAttachmentCount_,
119                                                                                   const VkAttachmentReference*          pInputAttachments_,
120                                                                                   deUint32                                                      colorAttachmentCount_,
121                                                                                   const VkAttachmentReference*          pColorAttachments_,
122                                                                                   const VkAttachmentReference*          pResolveAttachments_,
123                                                                                   const VkAttachmentReference*          pDepthStencilAttachment_,
124                                                                                   deUint32                                                      preserveAttachmentCount_,
125                                                                                   const deUint32*                                       pPreserveAttachments_)
126 {
127         DE_ASSERT(pNext_ == DE_NULL);
128         DE_ASSERT(viewMask_ == 0);
129
130         // No sType field in this struct
131         DE_UNREF                                (pNext_);
132         flags                                   = flags_;
133         pipelineBindPoint               = pipelineBindPoint_;
134         DE_UNREF                                (viewMask_);
135         inputAttachmentCount    = inputAttachmentCount_;
136         pInputAttachments               = pInputAttachments_;
137         colorAttachmentCount    = colorAttachmentCount_;
138         pColorAttachments               = pColorAttachments_;
139         pResolveAttachments             = pResolveAttachments_;
140         pDepthStencilAttachment = pDepthStencilAttachment_;
141         preserveAttachmentCount = preserveAttachmentCount_;
142         pPreserveAttachments    = pPreserveAttachments_;
143 }
144
145 SubpassDescription2::SubpassDescription2 (const void*                                           pNext_,
146                                                                                   VkSubpassDescriptionFlags                     flags_,
147                                                                                   VkPipelineBindPoint                           pipelineBindPoint_,
148                                                                                   deUint32                                                      viewMask_,
149                                                                                   deUint32                                                      inputAttachmentCount_,
150                                                                                   const VkAttachmentReference2*         pInputAttachments_,
151                                                                                   deUint32                                                      colorAttachmentCount_,
152                                                                                   const VkAttachmentReference2*         pColorAttachments_,
153                                                                                   const VkAttachmentReference2*         pResolveAttachments_,
154                                                                                   const VkAttachmentReference2*         pDepthStencilAttachment_,
155                                                                                   deUint32                                                      preserveAttachmentCount_,
156                                                                                   const deUint32*                                       pPreserveAttachments_)
157 {
158         sType                                   = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2;
159         pNext                                   = pNext_;
160         flags                                   = flags_;
161         pipelineBindPoint               = pipelineBindPoint_;
162         viewMask                                = viewMask_;
163         inputAttachmentCount    = inputAttachmentCount_;
164         pInputAttachments               = pInputAttachments_;
165         colorAttachmentCount    = colorAttachmentCount_;
166         pColorAttachments               = pColorAttachments_;
167         pResolveAttachments             = pResolveAttachments_;
168         pDepthStencilAttachment = pDepthStencilAttachment_;
169         preserveAttachmentCount = preserveAttachmentCount_;
170         pPreserveAttachments    = pPreserveAttachments_;
171 }
172
173 SubpassDependency1::SubpassDependency1 (const void*                             pNext_,
174                                                                                 deUint32                                srcSubpass_,
175                                                                                 deUint32                                dstSubpass_,
176                                                                                 VkPipelineStageFlags    srcStageMask_,
177                                                                                 VkPipelineStageFlags    dstStageMask_,
178                                                                                 VkAccessFlags                   srcAccessMask_,
179                                                                                 VkAccessFlags                   dstAccessMask_,
180                                                                                 VkDependencyFlags               dependencyFlags_,
181                                                                                 deInt32                                 viewOffset_)
182 {
183         DE_ASSERT(pNext_ == DE_NULL);
184         DE_ASSERT(viewOffset_ == 0);
185
186         // No sType field in this struct
187         DE_UNREF                (pNext_);
188         srcSubpass              = srcSubpass_;
189         dstSubpass              = dstSubpass_;
190         srcStageMask    = srcStageMask_;
191         dstStageMask    = dstStageMask_;
192         srcAccessMask   = srcAccessMask_;
193         dstAccessMask   = dstAccessMask_;
194         dependencyFlags = dependencyFlags_;
195         DE_UNREF                (viewOffset_);
196 }
197
198 SubpassDependency2::SubpassDependency2 (const void*                             pNext_,
199                                                                                 deUint32                                srcSubpass_,
200                                                                                 deUint32                                dstSubpass_,
201                                                                                 VkPipelineStageFlags    srcStageMask_,
202                                                                                 VkPipelineStageFlags    dstStageMask_,
203                                                                                 VkAccessFlags                   srcAccessMask_,
204                                                                                 VkAccessFlags                   dstAccessMask_,
205                                                                                 VkDependencyFlags               dependencyFlags_,
206                                                                                 deInt32                                 viewOffset_)
207 {
208         sType                   = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2;
209         pNext                   = pNext_;
210         srcSubpass              = srcSubpass_;
211         dstSubpass              = dstSubpass_;
212         srcStageMask    = srcStageMask_;
213         dstStageMask    = dstStageMask_;
214         srcAccessMask   = srcAccessMask_;
215         dstAccessMask   = dstAccessMask_;
216         dependencyFlags = dependencyFlags_;
217         viewOffset              = viewOffset_;
218 }
219
220 RenderPassCreateInfo1::RenderPassCreateInfo1 (const void*                                               pNext_,
221                                                                                           VkRenderPassCreateFlags                       flags_,
222                                                                                           deUint32                                                      attachmentCount_,
223                                                                                           const VkAttachmentDescription*        pAttachments_,
224                                                                                           deUint32                                                      subpassCount_,
225                                                                                           const VkSubpassDescription*           pSubpasses_,
226                                                                                           deUint32                                                      dependencyCount_,
227                                                                                           const VkSubpassDependency*            pDependencies_,
228                                                                                           deUint32                                                      correlatedViewMaskCount_,
229                                                                                           const deUint32*                                       pCorrelatedViewMasks_)
230 {
231         DE_ASSERT(correlatedViewMaskCount_ == 0);
232         DE_ASSERT(pCorrelatedViewMasks_ == DE_NULL);
233
234         sType                                   = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
235         pNext                                   = pNext_;
236         flags                                   = flags_;
237         attachmentCount                 = attachmentCount_;
238         pAttachments                    = pAttachments_;
239         subpassCount                    = subpassCount_;
240         pSubpasses                              = pSubpasses_;
241         dependencyCount                 = dependencyCount_;
242         pDependencies                   = pDependencies_;
243         DE_UNREF                                (correlatedViewMaskCount_);
244         DE_UNREF                                (pCorrelatedViewMasks_);
245 }
246
247 Move<VkRenderPass>      RenderPassCreateInfo1::createRenderPass (const DeviceInterface& vk, VkDevice device) const
248 {
249         return vk::createRenderPass(vk, device, this);
250 }
251
252 RenderPassCreateInfo2::RenderPassCreateInfo2 (const void*                                                       pNext_,
253                                                                                           VkRenderPassCreateFlags                               flags_,
254                                                                                           deUint32                                                              attachmentCount_,
255                                                                                           const VkAttachmentDescription2*               pAttachments_,
256                                                                                           deUint32                                                              subpassCount_,
257                                                                                           const VkSubpassDescription2*                  pSubpasses_,
258                                                                                           deUint32                                                              dependencyCount_,
259                                                                                           const VkSubpassDependency2*                   pDependencies_,
260                                                                                           deUint32                                                              correlatedViewMaskCount_,
261                                                                                           const deUint32*                                               pCorrelatedViewMasks_)
262 {
263         sType                                   = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2;
264         pNext                                   = pNext_;
265         flags                                   = flags_;
266         attachmentCount                 = attachmentCount_;
267         pAttachments                    = pAttachments_;
268         subpassCount                    = subpassCount_;
269         pSubpasses                              = pSubpasses_;
270         dependencyCount                 = dependencyCount_;
271         pDependencies                   = pDependencies_;
272         correlatedViewMaskCount = correlatedViewMaskCount_;
273         pCorrelatedViewMasks    = pCorrelatedViewMasks_;
274 }
275
276 Move<VkRenderPass>      RenderPassCreateInfo2::createRenderPass (const DeviceInterface& vk, VkDevice device) const
277 {
278         return vk::createRenderPass2(vk, device, this);
279 }
280
281 SubpassBeginInfo1::SubpassBeginInfo1 (const void*               pNext_,
282                                                                           VkSubpassContents     contents_)
283         : contents      (contents_)
284 {
285         DE_ASSERT(pNext_ == DE_NULL);
286
287         DE_UNREF(pNext_);
288 }
289
290 SubpassBeginInfo2::SubpassBeginInfo2 (const void*               pNext_,
291                                                                           VkSubpassContents     contents_)
292 {
293         sType           = VK_STRUCTURE_TYPE_SUBPASS_BEGIN_INFO;
294         pNext           = pNext_;
295         contents        = contents_;
296 }
297
298 SubpassEndInfo1::SubpassEndInfo1 (const void*   pNext_)
299 {
300         DE_ASSERT(pNext_ == DE_NULL);
301
302         DE_UNREF(pNext_);
303 }
304
305 SubpassEndInfo2::SubpassEndInfo2 (const void*   pNext_)
306 {
307         sType   = VK_STRUCTURE_TYPE_SUBPASS_END_INFO;
308         pNext   = pNext_;
309 }
310
311 void RenderpassSubpass1::cmdBeginRenderPass (const DeviceInterface&                     vk,
312                                                                                          VkCommandBuffer                                cmdBuffer,
313                                                                                          const VkRenderPassBeginInfo*   pRenderPassBegin,
314                                                                                          const SubpassBeginInfo*                pSubpassBeginInfo)
315 {
316         DE_ASSERT(pSubpassBeginInfo != DE_NULL);
317
318         vk.cmdBeginRenderPass(cmdBuffer, pRenderPassBegin, pSubpassBeginInfo->contents);
319 }
320
321 void RenderpassSubpass1::cmdNextSubpass (const DeviceInterface&         vk,
322                                                                                  VkCommandBuffer                        cmdBuffer,
323                                                                                  const SubpassBeginInfo*        pSubpassBeginInfo,
324                                                                                  const SubpassEndInfo*          pSubpassEndInfo)
325 {
326         DE_UNREF(pSubpassEndInfo);
327         DE_ASSERT(pSubpassBeginInfo != DE_NULL);
328
329         vk.cmdNextSubpass(cmdBuffer, pSubpassBeginInfo->contents);
330 }
331
332 void RenderpassSubpass1::cmdEndRenderPass (const DeviceInterface&       vk,
333                                                                                    VkCommandBuffer                      cmdBuffer,
334                                                                                    const SubpassEndInfo*        pSubpassEndInfo)
335 {
336         DE_UNREF(pSubpassEndInfo);
337
338         vk.cmdEndRenderPass(cmdBuffer);
339 }
340
341 void RenderpassSubpass2::cmdBeginRenderPass (const DeviceInterface&                     vk,
342                                                                                          VkCommandBuffer                                cmdBuffer,
343                                                                                          const VkRenderPassBeginInfo*   pRenderPassBegin,
344                                                                                          const SubpassBeginInfo*                pSubpassBeginInfo)
345 {
346         vk.cmdBeginRenderPass2(cmdBuffer, pRenderPassBegin, pSubpassBeginInfo);
347 }
348
349 void RenderpassSubpass2::cmdNextSubpass (const DeviceInterface&         vk,
350                                                                                  VkCommandBuffer                        cmdBuffer,
351                                                                                  const SubpassBeginInfo*        pSubpassBeginInfo,
352                                                                                  const SubpassEndInfo*          pSubpassEndInfo)
353 {
354         DE_ASSERT(pSubpassBeginInfo != DE_NULL);
355         DE_ASSERT(pSubpassEndInfo != DE_NULL);
356
357         vk.cmdNextSubpass2(cmdBuffer, pSubpassBeginInfo, pSubpassEndInfo);
358 }
359
360 void RenderpassSubpass2::cmdEndRenderPass (const DeviceInterface&       vk,
361                                                                                    VkCommandBuffer                      cmdBuffer,
362                                                                                    const SubpassEndInfo*        pSubpassEndInfo)
363 {
364         DE_ASSERT(pSubpassEndInfo != DE_NULL);
365
366         vk.cmdEndRenderPass2(cmdBuffer, pSubpassEndInfo);
367 }
368
369 // For internal to RP/RP2 conversions
370
371 AttachmentReference::AttachmentReference (deUint32                              attachment,
372                                                                                   VkImageLayout                 layout,
373                                                                                   VkImageAspectFlags    aspectMask)
374
375         :m_attachment   (attachment)
376         ,m_layout               (layout)
377         ,m_aspectMask   (aspectMask)
378 {
379 }
380
381 deUint32 AttachmentReference::getAttachment (void) const
382 {
383         return m_attachment;
384 }
385
386 VkImageLayout AttachmentReference::getImageLayout (void) const
387 {
388         return m_layout;
389 }
390
391 VkImageAspectFlags AttachmentReference::getAspectMask (void) const
392 {
393         return m_aspectMask;
394 }
395
396 void AttachmentReference::setImageLayout (VkImageLayout layout)
397 {
398         m_layout = layout;
399 }
400
401 Subpass::Subpass (VkPipelineBindPoint                                           pipelineBindPoint,
402                                   VkSubpassDescriptionFlags                                     flags,
403                                   const std::vector<AttachmentReference>&       inputAttachments,
404                                   const std::vector<AttachmentReference>&       colorAttachments,
405                                   const std::vector<AttachmentReference>&       resolveAttachments,
406                                   AttachmentReference                                           depthStencilAttachment,
407                                   const std::vector<deUint32>&                          preserveAttachments,
408                                   bool                                                                          omitBlendState)
409
410         :m_pipelineBindPoint            (pipelineBindPoint)
411         ,m_flags                                        (flags)
412         ,m_inputAttachments                     (inputAttachments)
413         ,m_colorAttachments                     (colorAttachments)
414         ,m_resolveAttachments           (resolveAttachments)
415         ,m_depthStencilAttachment       (depthStencilAttachment)
416         ,m_preserveAttachments          (preserveAttachments)
417         ,m_omitBlendState                       (omitBlendState)
418 {
419 }
420
421 VkPipelineBindPoint Subpass::getPipelineBindPoint (void) const
422 {
423         return m_pipelineBindPoint;
424 }
425
426 VkSubpassDescriptionFlags Subpass::getFlags (void) const
427 {
428         return m_flags;
429 }
430
431 const std::vector<AttachmentReference>& Subpass::getInputAttachments (void) const
432 {
433         return m_inputAttachments;
434 }
435
436 const std::vector<AttachmentReference>& Subpass::getColorAttachments (void) const
437 {
438         return m_colorAttachments;
439 }
440
441 const std::vector<AttachmentReference>& Subpass::getResolveAttachments (void) const
442 {
443         return m_resolveAttachments;
444 }
445
446 const AttachmentReference& Subpass::getDepthStencilAttachment (void) const
447 {
448         return m_depthStencilAttachment;
449 }
450
451 const std::vector<deUint32>& Subpass::getPreserveAttachments (void) const
452 {
453         return m_preserveAttachments;
454 }
455
456 bool Subpass::getOmitBlendState (void) const
457 {
458         return m_omitBlendState;
459 }
460
461 SubpassDependency::SubpassDependency (deUint32                          srcPass,
462                                                                           deUint32                              dstPass,
463
464                                                                           VkPipelineStageFlags  srcStageMask,
465                                                                           VkPipelineStageFlags  dstStageMask,
466
467                                                                           VkAccessFlags                 srcAccessMask,
468                                                                           VkAccessFlags                 dstAccessMask,
469
470                                                                           VkDependencyFlags             flags)
471
472         : m_srcPass                     (srcPass)
473         , m_dstPass                     (dstPass)
474
475         , m_srcStageMask        (srcStageMask)
476         , m_dstStageMask        (dstStageMask)
477
478         , m_srcAccessMask       (srcAccessMask)
479         , m_dstAccessMask       (dstAccessMask)
480         , m_flags                       (flags)
481 {
482 }
483
484 deUint32 SubpassDependency::getSrcPass (void) const
485 {
486         return m_srcPass;
487 }
488
489 deUint32 SubpassDependency::getDstPass (void) const
490 {
491         return m_dstPass;
492 }
493
494 VkPipelineStageFlags SubpassDependency::getSrcStageMask (void) const
495 {
496         return m_srcStageMask;
497 }
498
499 VkPipelineStageFlags SubpassDependency::getDstStageMask (void) const
500 {
501         return m_dstStageMask;
502 }
503
504 VkAccessFlags SubpassDependency::getSrcAccessMask (void) const
505 {
506         return m_srcAccessMask;
507 }
508
509 VkAccessFlags SubpassDependency::getDstAccessMask (void) const
510 {
511         return m_dstAccessMask;
512 }
513
514 VkDependencyFlags SubpassDependency::getFlags (void) const
515 {
516         return m_flags;
517 }
518
519 Attachment::Attachment (VkFormat                                format,
520                                                 VkSampleCountFlagBits   samples,
521
522                                                 VkAttachmentLoadOp              loadOp,
523                                                 VkAttachmentStoreOp             storeOp,
524
525                                                 VkAttachmentLoadOp              stencilLoadOp,
526                                                 VkAttachmentStoreOp             stencilStoreOp,
527
528                                                 VkImageLayout                   initialLayout,
529                                                 VkImageLayout                   finalLayout)
530
531         : m_format                      (format)
532         , m_samples                     (samples)
533         , m_loadOp                      (loadOp)
534         , m_storeOp                     (storeOp)
535         , m_stencilLoadOp       (stencilLoadOp)
536         , m_stencilStoreOp      (stencilStoreOp)
537         , m_initialLayout       (initialLayout)
538         , m_finalLayout         (finalLayout)
539 {
540 }
541
542 VkFormat Attachment::getFormat (void) const
543 {
544         return m_format;
545 }
546
547 VkSampleCountFlagBits Attachment::getSamples (void) const
548 {
549         return m_samples;
550 }
551
552 VkAttachmentLoadOp Attachment::getLoadOp (void) const
553 {
554         return m_loadOp;
555 }
556
557 VkAttachmentStoreOp Attachment::getStoreOp (void) const
558 {
559         return m_storeOp;
560 }
561
562 VkAttachmentLoadOp Attachment::getStencilLoadOp (void) const
563 {
564         return m_stencilLoadOp;
565 }
566
567 VkAttachmentStoreOp Attachment::getStencilStoreOp (void) const
568 {
569         return m_stencilStoreOp;
570 }
571
572 VkImageLayout Attachment::getInitialLayout (void) const
573 {
574         return m_initialLayout;
575 }
576
577 VkImageLayout Attachment::getFinalLayout (void) const
578 {
579         return m_finalLayout;
580 }
581
582 RenderPass::RenderPass (const std::vector<Attachment>&                                          attachments,
583                                                 const std::vector<Subpass>&                                                     subpasses,
584                                                 const std::vector<SubpassDependency>&                           dependencies,
585                                                 const std::vector<VkInputAttachmentAspectReference>     inputAspects)
586
587         : m_attachments         (attachments)
588         , m_subpasses           (subpasses)
589         , m_dependencies        (dependencies)
590         , m_inputAspects        (inputAspects)
591 {
592 }
593
594 const std::vector<Attachment>& RenderPass::getAttachments (void) const
595 {
596         return m_attachments;
597 }
598
599 const std::vector<Subpass>& RenderPass::getSubpasses (void) const
600 {
601         return m_subpasses;
602 }
603
604 const std::vector<SubpassDependency>& RenderPass::getDependencies (void) const
605 {
606         return m_dependencies;
607 }
608
609 const std::vector<VkInputAttachmentAspectReference>& RenderPass::getInputAspects (void) const
610 {
611         return m_inputAspects;
612 }
613
614 template <typename AttachmentDesc>
615 AttachmentDesc createAttachmentDescription (const Attachment& attachment)
616 {
617         const AttachmentDesc attachmentDescription      //  VkAttachmentDescription                                                     ||  VkAttachmentDescription2
618         (
619                                                                                                 //                                                                                                      ||  VkStructureType                                     sType;
620                 DE_NULL,                                                                //                                                                                                      ||  const void*                                         pNext;
621                 0u,                                                                             //  VkAttachmentDescriptionFlags        flags;                  ||  VkAttachmentDescriptionFlags        flags;
622                 attachment.getFormat(),                                 //  VkFormat                                            format;                 ||  VkFormat                                            format;
623                 attachment.getSamples(),                                //  VkSampleCountFlagBits                       samples;                ||  VkSampleCountFlagBits                       samples;
624                 attachment.getLoadOp(),                                 //  VkAttachmentLoadOp                          loadOp;                 ||  VkAttachmentLoadOp                          loadOp;
625                 attachment.getStoreOp(),                                //  VkAttachmentStoreOp                         storeOp;                ||  VkAttachmentStoreOp                         storeOp;
626                 attachment.getStencilLoadOp(),                  //  VkAttachmentLoadOp                          stencilLoadOp;  ||  VkAttachmentLoadOp                          stencilLoadOp;
627                 attachment.getStencilStoreOp(),                 //  VkAttachmentStoreOp                         stencilStoreOp; ||  VkAttachmentStoreOp                         stencilStoreOp;
628                 attachment.getInitialLayout(),                  //  VkImageLayout                                       initialLayout;  ||  VkImageLayout                                       initialLayout;
629                 attachment.getFinalLayout()                             //  VkImageLayout                                       finalLayout;    ||  VkImageLayout                                       finalLayout;
630         );
631
632         return attachmentDescription;
633 }
634
635 template <typename AttachmentRef>
636 AttachmentRef createAttachmentReference (const AttachmentReference& referenceInfo)
637 {
638         const AttachmentRef     reference               //  VkAttachmentReference                               ||  VkAttachmentReference2
639         (
640                                                                                 //                                                                              ||  VkStructureType                             sType;
641                 DE_NULL,                                                //                                                                              ||  const void*                                 pNext;
642                 referenceInfo.getAttachment(),  //  deUint32                            attachment;     ||  deUint32                                    attachment;
643                 referenceInfo.getImageLayout(), //  VkImageLayout                       layout;         ||  VkImageLayout                               layout;
644                 referenceInfo.getAspectMask()   //                                                                              ||  VkImageAspectFlags                  aspectMask;
645         );
646
647         return reference;
648 }
649
650 template <typename SubpassDesc, typename AttachmentRef>
651 SubpassDesc createSubpassDescription (const Subpass&                            subpass,
652                                                                           std::vector<AttachmentRef>*   attachmentReferenceLists,
653                                                                           std::vector<deUint32>*                preserveAttachmentReferences)
654 {
655         std::vector<AttachmentRef>&     inputAttachmentReferences                       = attachmentReferenceLists[0];
656         std::vector<AttachmentRef>&     colorAttachmentReferences                       = attachmentReferenceLists[1];
657         std::vector<AttachmentRef>&     resolveAttachmentReferences                     = attachmentReferenceLists[2];
658         std::vector<AttachmentRef>&     depthStencilAttachmentReferences        = attachmentReferenceLists[3];
659
660         for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
661                 colorAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getColorAttachments()[attachmentNdx]));
662
663         for (size_t attachmentNdx = 0; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
664                 inputAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getInputAttachments()[attachmentNdx]));
665
666         for (size_t attachmentNdx = 0; attachmentNdx < subpass.getResolveAttachments().size(); attachmentNdx++)
667                 resolveAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getResolveAttachments()[attachmentNdx]));
668
669         depthStencilAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getDepthStencilAttachment()));
670
671         for (size_t attachmentNdx = 0; attachmentNdx < subpass.getPreserveAttachments().size(); attachmentNdx++)
672                 preserveAttachmentReferences->push_back(subpass.getPreserveAttachments()[attachmentNdx]);
673
674         DE_ASSERT(resolveAttachmentReferences.empty() || colorAttachmentReferences.size() == resolveAttachmentReferences.size());
675
676         {
677                 const SubpassDesc subpassDescription                                                                                                            //  VkSubpassDescription                                                                                ||  VkSubpassDescription2
678                 (
679                                                                                                                                                                                                         //                                                                                                                              ||  VkStructureType                                             sType;
680                         DE_NULL,                                                                                                                                                                //                                                                                                                              ||  const void*                                                 pNext;
681                         subpass.getFlags(),                                                                                                                                             //  VkSubpassDescriptionFlags           flags;                                          ||  VkSubpassDescriptionFlags                   flags;
682                         subpass.getPipelineBindPoint(),                                                                                                                 //  VkPipelineBindPoint                         pipelineBindPoint;                      ||  VkPipelineBindPoint                                 pipelineBindPoint;
683                         0u,                                                                                                                                                                             //                                                                                                                              ||  deUint32                                                    viewMask;
684                         (deUint32)inputAttachmentReferences.size(),                                                                                             //  deUint32                                            inputAttachmentCount;           ||  deUint32                                                    inputAttachmentCount;
685                         inputAttachmentReferences.empty() ? DE_NULL : &inputAttachmentReferences[0],                    //  const VkAttachmentReference*        pInputAttachments;                      ||  const VkAttachmentReference2*               pInputAttachments;
686                         (deUint32)colorAttachmentReferences.size(),                                                                                             //  deUint32                                            colorAttachmentCount;           ||  deUint32                                                    colorAttachmentCount;
687                         colorAttachmentReferences.empty() ? DE_NULL :  &colorAttachmentReferences[0],                   //  const VkAttachmentReference*        pColorAttachments;                      ||  const VkAttachmentReference2*               pColorAttachments;
688                         resolveAttachmentReferences.empty() ? DE_NULL : &resolveAttachmentReferences[0],                //  const VkAttachmentReference*        pResolveAttachments;            ||  const VkAttachmentReference2*               pResolveAttachments;
689                         &depthStencilAttachmentReferences[0],                                                                                                   //  const VkAttachmentReference*        pDepthStencilAttachment;        ||  const VkAttachmentReference2*               pDepthStencilAttachment;
690                         (deUint32)preserveAttachmentReferences->size(),                                                                                 //  deUint32                                            preserveAttachmentCount;        ||  deUint32                                                    preserveAttachmentCount;
691                         preserveAttachmentReferences->empty() ? DE_NULL : &(*preserveAttachmentReferences)[0]   //  const deUint32*                                     pPreserveAttachments;           ||  const deUint32*                                             pPreserveAttachments;
692                 );
693
694                 return subpassDescription;
695         }
696 }
697
698 VkMemoryBarrier2KHR createMemoryBarrierFromSubpassDependency(const SubpassDependency& dependencyInfo)
699 {
700         return
701         {
702                 VK_STRUCTURE_TYPE_MEMORY_BARRIER_2_KHR,                                                                                         // VkStructureType                              sType
703                 DE_NULL,                                                                                                                                                        // const void*                                  pNext
704                 static_cast<VkPipelineStageFlags2KHR>   (dependencyInfo.getSrcStageMask()),                     // VkPipelineStageFlags2KHR             srcStageMask
705                 static_cast<VkAccessFlags2KHR>                  (dependencyInfo.getSrcAccessMask()),            // VkAccessFlags2KHR                    srcAccessMask
706                 static_cast<VkPipelineStageFlags2KHR>   (dependencyInfo.getDstStageMask()),                     // VkPipelineStageFlags2KHR             dstStageMask
707                 static_cast<VkAccessFlags2KHR>                  (dependencyInfo.getDstAccessMask())                     // VkAccessFlags2KHR                    dstAccessMask
708         };
709 }
710
711 template <typename SubpassDep>
712 SubpassDep createSubpassDependency (const SubpassDependency& dependencyInfo, VkMemoryBarrier2KHR* memoryBarrierPtr = DE_NULL)
713 {
714         VkPipelineStageFlags    srcStageMask    = dependencyInfo.getSrcStageMask();
715         VkPipelineStageFlags    dstStageMask    = dependencyInfo.getDstStageMask();
716         VkAccessFlags                   srcAccessMask   = dependencyInfo.getSrcAccessMask();
717         VkAccessFlags                   dstAccessMask   = dependencyInfo.getDstAccessMask();
718
719         // If an instance of VkMemoryBarrier2KHR is included in the pNext chain, srcStageMask,
720         // dstStageMask, srcAccessMask and dstAccessMask parameters are ignored. The synchronization
721         // and access scopes instead are defined by the parameters of VkMemoryBarrier2KHR.
722         if (memoryBarrierPtr)
723         {
724                 srcStageMask    = 0;
725                 dstStageMask    = 0;
726                 srcAccessMask   = 0;
727                 dstAccessMask   = 0;
728         }
729
730         return                                                                  //  VkSubpassDependency                                         ||  VkSubpassDependency2
731         {
732                 memoryBarrierPtr,                                       //                                                                                      ||      const void*                                     pNext
733                 dependencyInfo.getSrcPass(),            //  deUint32                            srcSubpass              ||      deUint32                                        srcSubpass
734                 dependencyInfo.getDstPass(),            //  deUint32                            dstSubpass              ||      deUint32                                        dstSubpass
735                 srcStageMask,                                           //  VkPipelineStageFlags        srcStageMask    ||      VkPipelineStageFlags            srcStageMask
736                 dstStageMask,                                           //  VkPipelineStageFlags        dstStageMask    ||      VkPipelineStageFlags            dstStageMask
737                 srcAccessMask,                                          //  VkAccessFlags                       srcAccessMask   ||      VkAccessFlags                           srcAccessMask
738                 dstAccessMask,                                          //  VkAccessFlags                       dstAccessMask   ||      VkAccessFlags                           dstAccessMask
739                 dependencyInfo.getFlags(),                      //  VkDependencyFlags           dependencyFlags ||      VkDependencyFlags                       dependencyFlags
740                 0u                                                                      //      deInt32                                 viewOffset              ||      deInt32                                         viewOffset
741         };
742 }
743
744 de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo> createRenderPassInputAttachmentAspectCreateInfo (const RenderPass& renderPassInfo)
745 {
746         de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo> result (DE_NULL);
747
748         if (!renderPassInfo.getInputAspects().empty())
749         {
750                 const VkRenderPassInputAttachmentAspectCreateInfo       inputAspectCreateInfo   =
751                 {
752                         VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO,
753                         DE_NULL,
754
755                         (deUint32)renderPassInfo.getInputAspects().size(),
756                         renderPassInfo.getInputAspects().data(),
757                 };
758
759                 result = de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo>(new VkRenderPassInputAttachmentAspectCreateInfo(inputAspectCreateInfo));
760         }
761
762         return result;
763 }
764
765 template<typename AttachmentDesc, typename AttachmentRef, typename SubpassDesc, typename SubpassDep, typename RenderPassCreateInfo>
766 Move<VkRenderPass> createRenderPass (const DeviceInterface&     vk,
767                                                                          VkDevice                               device,
768                                                                          const RenderPass&              renderPassInfo,
769                                                                          SynchronizationType    synchronizationType)
770 {
771         const size_t                                                                                            perSubpassAttachmentReferenceLists = 4;
772         std::vector<AttachmentDesc>                                                                     attachments;
773         std::vector<SubpassDesc>                                                                        subpasses;
774         std::vector<SubpassDep>                                                                         dependencies;
775         std::vector<VkMemoryBarrier2KHR>                                                        memoryBarriers;
776         std::vector<std::vector<AttachmentRef> >                                        attachmentReferenceLists(renderPassInfo.getSubpasses().size() * perSubpassAttachmentReferenceLists);
777         std::vector<std::vector<deUint32> >                                                     preserveAttachments(renderPassInfo.getSubpasses().size());
778         de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo>        inputAspectCreateInfo(createRenderPassInputAttachmentAspectCreateInfo(renderPassInfo));
779
780         for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
781                 attachments.push_back(createAttachmentDescription<AttachmentDesc>(renderPassInfo.getAttachments()[attachmentNdx]));
782
783         for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
784                 subpasses.push_back(createSubpassDescription<SubpassDesc>(renderPassInfo.getSubpasses()[subpassNdx], &(attachmentReferenceLists[subpassNdx * perSubpassAttachmentReferenceLists]), &preserveAttachments[subpassNdx]));
785
786         if (synchronizationType == SYNCHRONIZATION_TYPE_SYNCHRONIZATION2)
787         {
788                 // reserve space to avoid reallocation in vector that will invalidate pointers
789                 memoryBarriers.reserve(renderPassInfo.getDependencies().size());
790                 for (const auto& dependency : renderPassInfo.getDependencies())
791                 {
792                         memoryBarriers.push_back(createMemoryBarrierFromSubpassDependency(dependency));
793                         dependencies.push_back(createSubpassDependency<SubpassDep>(dependency, &memoryBarriers.back()));
794                 }
795         }
796         else
797         {
798                 for (const auto& dependency : renderPassInfo.getDependencies())
799                         dependencies.push_back(createSubpassDependency<SubpassDep>(dependency));
800         }
801
802         const RenderPassCreateInfo      renderPassCreator                               //  VkRenderPassCreateInfo                                                              ||  VkRenderPassCreateInfo2
803         (
804                                                                                                                                 //  VkStructureType                                     sType;                          ||  VkStructureType                                             sType;
805                 inputAspectCreateInfo.get(),                                                    //  const void*                                         pNext;                          ||  const void*                                                 pNext;
806                 (VkRenderPassCreateFlags)0u,                                                    //  VkRenderPassCreateFlags                     flags;                          ||  VkRenderPassCreateFlags                             flags;
807                 (deUint32)attachments.size(),                                                   //  deUint32                                            attachmentCount;        ||  deUint32                                                    attachmentCount;
808                 (attachments.empty() ? DE_NULL : &attachments[0]),              //  const VkAttachmentDescription*      pAttachments;           ||  const VkAttachmentDescription2*             pAttachments;
809                 (deUint32)subpasses.size(),                                                             //  deUint32                                            subpassCount;           ||  deUint32                                                    subpassCount;
810                 (subpasses.empty() ? DE_NULL : &subpasses[0]),                  //  const VkSubpassDescription*         pSubpasses;                     ||  const VkSubpassDescription2*                pSubpasses;
811                 (deUint32)dependencies.size(),                                                  //  deUint32                                            dependencyCount;        ||  deUint32                                                    dependencyCount;
812                 (dependencies.empty() ? DE_NULL : &dependencies[0]),    //  const VkSubpassDependency*          pDependencies;          ||  const VkSubpassDependency2*                 pDependencies;
813                 0u,                                                                                                             //                                                                                                              ||  deUint32                                                    correlatedViewMaskCount;
814                 DE_NULL                                                                                                 //                                                                                                              ||  const deUint32*                                             pCorrelatedViewMasks;
815         );
816
817         return renderPassCreator.createRenderPass(vk, device);
818 }
819
820 Move<VkRenderPass> createRenderPass (const DeviceInterface&     vk,
821                                                                          VkDevice                               device,
822                                                                          const RenderPass&              renderPassInfo,
823                                                                          RenderPassType                 renderPassType,
824                                                                          SynchronizationType    synchronizationType)
825 {
826         switch (renderPassType)
827         {
828                 case RENDERPASS_TYPE_LEGACY:
829                         return createRenderPass<AttachmentDescription1,
830                                                                         AttachmentReference1,
831                                                                         SubpassDescription1,
832                                                                         SubpassDependency1,
833                                                                         RenderPassCreateInfo1>(vk, device, renderPassInfo, SYNCHRONIZATION_TYPE_LEGACY);
834                 case RENDERPASS_TYPE_RENDERPASS2:
835                         return createRenderPass<AttachmentDescription2,
836                                                                         AttachmentReference2,
837                                                                         SubpassDescription2,
838                                                                         SubpassDependency2,
839                                                                         RenderPassCreateInfo2>(vk, device, renderPassInfo, synchronizationType);
840                 default:
841                         TCU_THROW(InternalError, "Impossible");
842         }
843 }
844
845 } // renderpass
846
847 } // vkt