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