1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2017 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 Vulkan Multi View Render Util
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktMultiViewRenderUtil.hpp"
25 #include "vktMultiViewRenderPassUtil.hpp"
26
27 #include "vktTestCase.hpp"
28 #include "vkBuilderUtil.hpp"
29 #include "vkRefUtil.hpp"
30 #include "vkQueryUtil.hpp"
31 #include "vkTypeUtil.hpp"
32 #include "vkPrograms.hpp"
33 #include "vkPlatform.hpp"
34 #include "vkMemUtil.hpp"
35 #include "vkImageUtil.hpp"
36
37 #include "tcuTestLog.hpp"
38 #include "tcuResource.hpp"
39 #include "tcuImageCompare.hpp"
40 #include "tcuCommandLine.hpp"
41 #include "tcuTextureUtil.hpp"
42 #include "tcuRGBA.hpp"
43
44 namespace vkt
45 {
46 namespace MultiView
47 {
48 using namespace vk;
49 using de::MovePtr;
50 using de::UniquePtr;
51 using std::vector;
52
getAspectFlags(tcu::TextureFormat format)53 VkImageAspectFlags getAspectFlags (tcu::TextureFormat format)
54 {
55 VkImageAspectFlags aspectFlag = 0;
56 aspectFlag |= (tcu::hasDepthComponent(format.order)? VK_IMAGE_ASPECT_DEPTH_BIT : 0);
57 aspectFlag |= (tcu::hasStencilComponent(format.order)? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
58
59 if (!aspectFlag)
60 aspectFlag = VK_IMAGE_ASPECT_COLOR_BIT;
61
62 return aspectFlag;
63 }
64
getStencilBufferFormat(const vk::VkFormat depthStencilImageFormat)65 VkFormat getStencilBufferFormat (const vk::VkFormat depthStencilImageFormat)
66 {
67 const tcu::TextureFormat tcuFormat = mapVkFormat(depthStencilImageFormat);
68 const VkFormat result = (tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS) ? VK_FORMAT_S8_UINT : VK_FORMAT_UNDEFINED;
69
70 DE_ASSERT(result != VK_FORMAT_UNDEFINED);
71
72 return result;
73 }
74
getDepthBufferFormat(const vk::VkFormat depthStencilImageFormat)75 VkFormat getDepthBufferFormat (const vk::VkFormat depthStencilImageFormat)
76 {
77 VkFormat result = VK_FORMAT_UNDEFINED;
78
79 switch (depthStencilImageFormat)
80 {
81 case VK_FORMAT_D16_UNORM:
82 case VK_FORMAT_D16_UNORM_S8_UINT:
83 {
84 result = VK_FORMAT_D16_UNORM;
85
86 break;
87 }
88
89 case VK_FORMAT_D32_SFLOAT:
90 case VK_FORMAT_D32_SFLOAT_S8_UINT:
91 {
92 result = VK_FORMAT_D32_SFLOAT;
93 break;
94 }
95
96 case VK_FORMAT_X8_D24_UNORM_PACK32:
97 case VK_FORMAT_D24_UNORM_S8_UINT:
98 {
99 result = VK_FORMAT_D24_UNORM_S8_UINT;
100 break;
101 }
102
103 default:
104 result = VK_FORMAT_UNDEFINED;
105 }
106
107 DE_ASSERT(result != VK_FORMAT_UNDEFINED);
108
109 return result;
110 }
111
makeBufferCreateInfo(const VkDeviceSize bufferSize,const VkBufferUsageFlags usage)112 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize, const VkBufferUsageFlags usage)
113 {
114 const VkBufferCreateInfo bufferCreateInfo =
115 {
116 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
117 DE_NULL, // const void* pNext;
118 (VkBufferCreateFlags)0, // VkBufferCreateFlags flags;
119 bufferSize, // VkDeviceSize size;
120 usage, // VkBufferUsageFlags usage;
121 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
122 0u, // deUint32 queueFamilyIndexCount;
123 DE_NULL, // const deUint32* pQueueFamilyIndices;
124 };
125 return bufferCreateInfo;
126 }
127
makeImageCreateInfo(const VkImageType imageType,const VkExtent3D & extent,const VkFormat format,const VkImageUsageFlags usage,const VkSampleCountFlagBits samples)128 VkImageCreateInfo makeImageCreateInfo (const VkImageType imageType, const VkExtent3D& extent, const VkFormat format, const VkImageUsageFlags usage, const VkSampleCountFlagBits samples)
129 {
130 const VkImageCreateInfo imageInfo =
131 {
132 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
133 DE_NULL, // const void* pNext;
134 (VkImageCreateFlags)0, // VkImageCreateFlags flags;
135 imageType, // VkImageType imageType;
136 format, // VkFormat format;
137 {extent.width, extent.height, 1u}, // VkExtent3D extent;
138 1u, // uint32_t mipLevels;
139 extent.depth, // uint32_t arrayLayers;
140 samples, // VkSampleCountFlagBits samples;
141 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
142 usage, // VkImageUsageFlags usage;
143 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
144 0u, // uint32_t queueFamilyIndexCount;
145 DE_NULL, // const uint32_t* pQueueFamilyIndices;
146 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
147 };
148 return imageInfo;
149 }
150
makeImageView(const DeviceInterface & vk,const VkDevice device,const VkImage image,const VkImageViewType viewType,const VkFormat format,const VkImageSubresourceRange subresourceRange)151 Move<VkImageView> makeImageView (const DeviceInterface& vk,
152 const VkDevice device,
153 const VkImage image,
154 const VkImageViewType viewType,
155 const VkFormat format,
156 const VkImageSubresourceRange subresourceRange)
157 {
158 const VkImageViewCreateInfo imageViewParams =
159 {
160 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
161 DE_NULL, // const void* pNext;
162 (VkImageViewCreateFlags)0, // VkImageViewCreateFlags flags;
163 image, // VkImage image;
164 viewType, // VkImageViewType viewType;
165 format, // VkFormat format;
166 makeComponentMappingRGBA(), // VkComponentMapping components;
167 subresourceRange, // VkImageSubresourceRange subresourceRange;
168 };
169 return createImageView(vk, device, &imageViewParams);
170 }
171
makeFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const vector<VkImageView> & attachments,const deUint32 width,const deUint32 height,const deUint32 layers)172 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface& vk,
173 const VkDevice device,
174 const VkRenderPass renderPass,
175 const vector<VkImageView>& attachments,
176 const deUint32 width,
177 const deUint32 height,
178 const deUint32 layers)
179 {
180 const VkFramebufferCreateInfo framebufferInfo =
181 {
182 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
183 DE_NULL, // const void* pNext;
184 (VkFramebufferCreateFlags)0, // VkFramebufferCreateFlags flags;
185 renderPass, // VkRenderPass renderPass;
186 static_cast<deUint32>(attachments.size()), // uint32_t attachmentCount;
187 &attachments[0], // const VkImageView* pAttachments;
188 width, // uint32_t width;
189 height, // uint32_t height;
190 layers, // uint32_t layers;
191 };
192 return createFramebuffer(vk, device, &framebufferInfo);
193 }
194
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const VkDescriptorSetLayout * pSetLayouts)195 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
196 const VkDevice device,
197 const VkDescriptorSetLayout* pSetLayouts)
198 {
199 const VkPipelineLayoutCreateInfo info =
200 {
201 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
202 DE_NULL, // const void* pNext;
203 (VkPipelineLayoutCreateFlags)0, // VkPipelineLayoutCreateFlags flags;
204 (DE_NULL == pSetLayouts)? 0u : 1u, // deUint32 setLayoutCount;
205 pSetLayouts, // const VkDescriptorSetLayout* pSetLayouts;
206 0u, // deUint32 pushConstantRangeCount;
207 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
208 };
209 return createPipelineLayout(vk, device, &info);
210 }
211
makeDescriptorSetLayout(const DeviceInterface & vk,const VkDevice device)212 Move<VkDescriptorSetLayout> makeDescriptorSetLayout (const DeviceInterface& vk,
213 const VkDevice device)
214 {
215 const VkDescriptorSetLayoutBinding binding =
216 {
217 0u, //deUint32 binding;
218 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, //VkDescriptorType descriptorType;
219 1u, //deUint32 descriptorCount;
220 vk::VK_SHADER_STAGE_FRAGMENT_BIT, //VkShaderStageFlags stageFlags;
221 DE_NULL //const VkSampler* pImmutableSamplers;
222 };
223
224 const VkDescriptorSetLayoutCreateInfo createInfo =
225 {
226 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, //VkStructureType sType;
227 DE_NULL, //const void* pNext;
228 0u, //VkDescriptorSetLayoutCreateFlags flags;
229 1u, //deUint32 bindingCount;
230 &binding //const VkDescriptorSetLayoutBinding* pBindings;
231 };
232 return vk::createDescriptorSetLayout(vk, device, &createInfo);
233 }
234
235 template<typename AttachmentDesc, typename AttachmentRef, typename SubpassDesc, typename SubpassDep, typename RenderPassCreateInfo>
makeRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const vector<deUint32> & viewMasks,const VkSampleCountFlagBits samples,const VkAttachmentLoadOp colorLoadOp,const VkFormat dsFormat)236 Move<VkRenderPass> makeRenderPass (const DeviceInterface& vk,
237 const VkDevice device,
238 const VkFormat colorFormat,
239 const vector<deUint32>& viewMasks,
240 const VkSampleCountFlagBits samples,
241 const VkAttachmentLoadOp colorLoadOp,
242 const VkFormat dsFormat)
243 {
244 const bool dsAttacmentAvailable = (dsFormat != vk::VK_FORMAT_UNDEFINED);
245 const deUint32 subpassCount = static_cast<deUint32>(viewMasks.size());
246 const AttachmentDesc colorAttachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
247 (
248 // || VkStructureType sType;
249 DE_NULL, // || const void* pNext;
250 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
251 colorFormat, // VkFormat format; || VkFormat format;
252 samples, // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
253 colorLoadOp, // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
254 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
255 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
256 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
257 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout; || VkImageLayout initialLayout;
258 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout; || VkImageLayout finalLayout;
259 );
260
261 const AttachmentRef colorAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
262 (
263 // || VkStructureType sType;
264 DE_NULL, // || const void* pNext;
265 0u, // deUint32 attachment; || deUint32 attachment;
266 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout layout; || VkImageLayout layout;
267 0u // || VkImageAspectFlags aspectMask;
268 );
269
270 const AttachmentDesc dsAttachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
271 (
272 // || VkStructureType sType;
273 DE_NULL, // || const void* pNext;
274 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
275 dsFormat, // VkFormat format; || VkFormat format;
276 samples, // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
277 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
278 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
279 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
280 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
281 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout; || VkImageLayout initialLayout;
282 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout; || VkImageLayout finalLayout;
283 );
284
285 const AttachmentRef depthAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
286 (
287 // || VkStructureType sType;
288 DE_NULL, // || const void* pNext;
289 dsAttacmentAvailable ? 1u : VK_ATTACHMENT_UNUSED, // deUint32 attachment; || deUint32 attachment;
290 dsAttacmentAvailable ? // VkImageLayout layout; || VkImageLayout layout;
291 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL :
292 VK_IMAGE_LAYOUT_UNDEFINED,
293 0u // || VkImageAspectFlags aspectMask;
294 );
295
296 const AttachmentDesc attachmentDescriptions[] =
297 {
298 colorAttachmentDescription,
299 dsAttachmentDescription,
300 };
301
302 DE_ASSERT((typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1)) || (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2)));
303
304 vector <SubpassDesc> subpassDescriptions;
305 for (deUint32 subpassNdx = 0; subpassNdx < subpassCount; ++subpassNdx)
306 {
307 const deUint32 viewMask = (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2))
308 ? viewMasks[subpassNdx]
309 : 0u;
310 const SubpassDesc subpassDescription // VkSubpassDescription || VkSubpassDescription2KHR
311 (
312 // || VkStructureType sType;
313 DE_NULL, // || const void* pNext;
314 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags; || VkSubpassDescriptionFlags flags;
315 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint; || VkPipelineBindPoint pipelineBindPoint;
316 viewMask, // || deUint32 viewMask;
317 0u, // deUint32 inputAttachmentCount; || deUint32 inputAttachmentCount;
318 DE_NULL, // const VkAttachmentReference* pInputAttachments; || const VkAttachmentReference2KHR* pInputAttachments;
319 1u, // deUint32 colorAttachmentCount; || deUint32 colorAttachmentCount;
320 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments; || const VkAttachmentReference2KHR* pColorAttachments;
321 DE_NULL, // const VkAttachmentReference* pResolveAttachments; || const VkAttachmentReference2KHR* pResolveAttachments;
322 &depthAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment; || const VkAttachmentReference2KHR* pDepthStencilAttachment;
323 0u, // deUint32 preserveAttachmentCount; || deUint32 preserveAttachmentCount;
324 DE_NULL // const deUint32* pPreserveAttachments; || const deUint32* pPreserveAttachments;
325 );
326
327 subpassDescriptions.push_back(subpassDescription);
328 }
329
330 const VkRenderPassMultiviewCreateInfo renderPassMultiviewInfo =
331 {
332 VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO_KHR, // VkStructureType sType;
333 DE_NULL, // const void* pNext;
334 subpassCount, // uint32_t subpassCount;
335 &viewMasks[0], // const uint32_t* pViewMasks;
336 0u, // uint32_t dependencyCount;
337 DE_NULL, // const int32_t* pViewOffsets;
338 0u, // uint32_t correlationMaskCount;
339 DE_NULL, // const uint32_t* pCorrelationMasks;
340 };
341 const VkRenderPassMultiviewCreateInfo* renderPassMultiviewInfoPtr = (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1))
342 ? &renderPassMultiviewInfo
343 : DE_NULL;
344
345 const VkPipelineStageFlags srcStageMask = dsAttacmentAvailable
346 ? VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
347 : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
348 const VkAccessFlags srcAccessMask = dsAttacmentAvailable
349 ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
350 : VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
351 vector <SubpassDep> subpassDependencies;
352 for(deUint32 subpassNdx = 0u; subpassNdx < subpassCount; ++subpassNdx)
353 {
354 const SubpassDep subpassDependency // VkSubpassDependency || VkSubpassDependency2KHR
355 (
356 // || VkStructureType sType;
357 DE_NULL, // || const void* pNext;
358 subpassNdx, // deUint32 srcSubpass; || deUint32 srcSubpass;
359 (subpassNdx == subpassCount -1u) ? subpassNdx : subpassNdx+1u, // deUint32 dstSubpass; || deUint32 dstSubpass;
360 srcStageMask, // VkPipelineStageFlags srcStageMask; || VkPipelineStageFlags srcStageMask;
361 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, // VkPipelineStageFlags dstStageMask; || VkPipelineStageFlags dstStageMask;
362 srcAccessMask, // VkAccessFlags srcAccessMask; || VkAccessFlags srcAccessMask;
363 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // VkAccessFlags dstAccessMask; || VkAccessFlags dstAccessMask;
364 VK_DEPENDENCY_VIEW_LOCAL_BIT_KHR, // VkDependencyFlags dependencyFlags; || VkDependencyFlags dependencyFlags;
365 0 // || deInt32 viewOffset;
366 );
367 subpassDependencies.push_back(subpassDependency);
368 }
369
370 const RenderPassCreateInfo renderPassInfo // VkRenderPassCreateInfo || VkRenderPassCreateInfo2KHR
371 (
372 // VkStructureType sType; || VkStructureType sType;
373 renderPassMultiviewInfoPtr, // const void* pNext; || const void* pNext;
374 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags; || VkRenderPassCreateFlags flags;
375 dsAttacmentAvailable ? 2u : 1u, // deUint32 attachmentCount; || deUint32 attachmentCount;
376 attachmentDescriptions, // const VkAttachmentDescription* pAttachments; || const VkAttachmentDescription2KHR* pAttachments;
377 subpassCount, // deUint32 subpassCount; || deUint32 subpassCount;
378 &subpassDescriptions[0], // const VkSubpassDescription* pSubpasses; || const VkSubpassDescription2KHR* pSubpasses;
379 subpassCount, // deUint32 dependencyCount; || deUint32 dependencyCount;
380 &subpassDependencies[0], // const VkSubpassDependency* pDependencies; || const VkSubpassDependency2KHR* pDependencies;
381 0u, // || deUint32 correlatedViewMaskCount;
382 DE_NULL // || const deUint32* pCorrelatedViewMasks;
383 );
384
385 return renderPassInfo.createRenderPass(vk, device);
386 }
387
388 // Instantiate function for legacy renderpass structures
389 template
390 Move<VkRenderPass> makeRenderPass<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
391 (const DeviceInterface& vk,
392 const VkDevice device,
393 const VkFormat colorFormat,
394 const vector<deUint32>& viewMasks,
395 const VkSampleCountFlagBits samples,
396 const VkAttachmentLoadOp colorLoadOp,
397 const VkFormat dsFormat);
398
399 // Instantiate function for renderpass2 structures
400 template
401 Move<VkRenderPass> makeRenderPass<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
402 (const DeviceInterface& vk,
403 const VkDevice device,
404 const VkFormat colorFormat,
405 const vector<deUint32>& viewMasks,
406 const VkSampleCountFlagBits samples,
407 const VkAttachmentLoadOp colorLoadOp,
408 const VkFormat dsFormat);
409
410
411 template<typename AttachmentDesc, typename AttachmentRef, typename SubpassDesc, typename SubpassDep, typename RenderPassCreateInfo>
makeRenderPassWithDepth(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const vector<deUint32> & viewMasks,const VkFormat dsFormat)412 Move<VkRenderPass> makeRenderPassWithDepth (const DeviceInterface& vk, const VkDevice device, const VkFormat colorFormat, const vector<deUint32>& viewMasks, const VkFormat dsFormat)
413 {
414 return makeRenderPass<AttachmentDesc, AttachmentRef, SubpassDesc, SubpassDep, RenderPassCreateInfo>(vk, device, colorFormat, viewMasks, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR, dsFormat);
415 }
416
417 // Instantiate function for legacy renderpass structures
418 template
419 Move<VkRenderPass> makeRenderPassWithDepth<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
420 (const DeviceInterface& vk,
421 const VkDevice device,
422 const VkFormat colorFormat,
423 const vector<deUint32>& viewMasks,
424 const VkFormat dsFormat);
425
426 // Instantiate function for renderpass2 structures
427 template
428 Move<VkRenderPass> makeRenderPassWithDepth<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
429 (const DeviceInterface& vk,
430 const VkDevice device,
431 const VkFormat colorFormat,
432 const vector<deUint32>& viewMasks,
433 const VkFormat dsFormat);
434
435 template<typename AttachmentDesc, typename AttachmentRef, typename SubpassDesc, typename SubpassDep, typename RenderPassCreateInfo>
makeRenderPassWithAttachments(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const vector<deUint32> & viewMasks,bool useAspects)436 Move<VkRenderPass> makeRenderPassWithAttachments (const DeviceInterface& vk,
437 const VkDevice device,
438 const VkFormat colorFormat,
439 const vector<deUint32>& viewMasks,
440 bool useAspects)
441 {
442 const deUint32 subpassCount = static_cast<deUint32>(viewMasks.size());
443
444 const AttachmentDesc colorAttachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
445 (
446 // || VkStructureType sType;
447 DE_NULL, // || const void* pNext;
448 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
449 colorFormat, // VkFormat format; || VkFormat format;
450 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
451 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
452 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
453 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
454 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
455 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout; || VkImageLayout initialLayout;
456 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout; || VkImageLayout finalLayout;
457 );
458
459 const AttachmentDesc inputAttachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
460 (
461 // || VkStructureType sType;
462 DE_NULL, // || const void* pNext;
463 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
464 colorFormat, // VkFormat format; || VkFormat format;
465 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
466 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
467 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
468 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
469 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
470 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout initialLayout; || VkImageLayout initialLayout;
471 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout finalLayout; || VkImageLayout finalLayout;
472 );
473
474 vector<AttachmentDesc> attachments;
475 attachments.push_back(colorAttachmentDescription);
476 attachments.push_back(inputAttachmentDescription);
477
478 const AttachmentRef colorAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
479 (
480 // || VkStructureType sType;
481 DE_NULL, // || const void* pNext;
482 0u, // deUint32 attachment; || deUint32 attachment;
483 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout layout; || VkImageLayout layout;
484 0u // || VkImageAspectFlags aspectMask;
485 );
486
487 const AttachmentRef inputAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
488 (
489 // || VkStructureType sType;
490 DE_NULL, // || const void* pNext;
491 1u, // deUint32 attachment; || deUint32 attachment;
492 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout layout; || VkImageLayout layout;
493 useAspects ? VK_IMAGE_ASPECT_COLOR_BIT : static_cast<VkImageAspectFlagBits>(0u) // || VkImageAspectFlags aspectMask;
494 );
495
496 const AttachmentRef depthAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
497 (
498 // || VkStructureType sType;
499 DE_NULL, // || const void* pNext;
500 VK_ATTACHMENT_UNUSED, // deUint32 attachment; || deUint32 attachment;
501 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout layout; || VkImageLayout layout;
502 0u // || VkImageAspectFlags aspectMask;
503 );
504
505 DE_ASSERT((typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1)) || (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2)));
506
507 vector <SubpassDesc> subpassDescriptions;
508 for (deUint32 subpassNdx = 0; subpassNdx < subpassCount; ++subpassNdx)
509 {
510 const deUint32 viewMask = (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2))
511 ? viewMasks[subpassNdx]
512 : 0u;
513 const SubpassDesc subpassDescription // VkSubpassDescription || VkSubpassDescription2KHR
514 (
515 // || VkStructureType sType;
516 DE_NULL, // || const void* pNext;
517 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags; || VkSubpassDescriptionFlags flags;
518 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint; || VkPipelineBindPoint pipelineBindPoint;
519 viewMask, // || deUint32 viewMask;
520 1u, // deUint32 inputAttachmentCount; || deUint32 inputAttachmentCount;
521 &inputAttachmentReference, // const VkAttachmentReference* pInputAttachments; || const VkAttachmentReference2KHR* pInputAttachments;
522 1u, // deUint32 colorAttachmentCount; || deUint32 colorAttachmentCount;
523 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments; || const VkAttachmentReference2KHR* pColorAttachments;
524 DE_NULL, // const VkAttachmentReference* pResolveAttachments; || const VkAttachmentReference2KHR* pResolveAttachments;
525 &depthAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment; || const VkAttachmentReference2KHR* pDepthStencilAttachment;
526 0u, // deUint32 preserveAttachmentCount; || deUint32 preserveAttachmentCount;
527 DE_NULL // const deUint32* pPreserveAttachments; || const deUint32* pPreserveAttachments;
528 );
529 subpassDescriptions.push_back(subpassDescription);
530 }
531
532 const VkRenderPassMultiviewCreateInfo renderPassMultiviewInfo =
533 {
534 VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO_KHR, //VkStructureType sType;
535 DE_NULL, //const void* pNext;
536 subpassCount, //uint32_t subpassCount;
537 &viewMasks[0], //const uint32_t* pViewMasks;
538 0u, //uint32_t dependencyCount;
539 DE_NULL, //const int32_t* pViewOffsets;
540 0u, //uint32_t correlationMaskCount;
541 DE_NULL, //const uint32_t* pCorrelationMasks;
542 };
543 const VkRenderPassMultiviewCreateInfo* renderPassMultiviewInfoPtr = typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1)
544 ? &renderPassMultiviewInfo
545 : DE_NULL;
546
547 vector <SubpassDep> subpassDependencies;
548 for(deUint32 subpassNdx = 0u; subpassNdx < subpassCount; ++subpassNdx)
549 {
550 const SubpassDep subpassDependency // VkSubpassDependency || VkSubpassDependency2KHR
551 (
552 // || VkStructureType sType;
553 DE_NULL, // || const void* pNext;
554 subpassNdx, // deUint32 srcSubpass; || deUint32 srcSubpass;
555 (subpassNdx == subpassCount -1u) ? subpassNdx : subpassNdx+1u, // deUint32 dstSubpass; || deUint32 dstSubpass;
556 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, // VkPipelineStageFlags srcStageMask; || VkPipelineStageFlags srcStageMask;
557 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, // VkPipelineStageFlags dstStageMask; || VkPipelineStageFlags dstStageMask;
558 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags srcAccessMask; || VkAccessFlags srcAccessMask;
559 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // VkAccessFlags dstAccessMask; || VkAccessFlags dstAccessMask;
560 VK_DEPENDENCY_VIEW_LOCAL_BIT_KHR, // VkDependencyFlags dependencyFlags; || VkDependencyFlags dependencyFlags;
561 0 // || deInt32 viewOffset;
562 );
563 subpassDependencies.push_back(subpassDependency);
564 }
565
566 const RenderPassCreateInfo renderPassInfo // VkRenderPassCreateInfo || VkRenderPassCreateInfo2KHR
567 (
568 // VkStructureType sType; || VkStructureType sType;
569 renderPassMultiviewInfoPtr, // const void* pNext; || const void* pNext;
570 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags; || VkRenderPassCreateFlags flags;
571 2u, // deUint32 attachmentCount; || deUint32 attachmentCount;
572 &attachments[0], // const VkAttachmentDescription* pAttachments; || const VkAttachmentDescription2KHR* pAttachments;
573 subpassCount, // deUint32 subpassCount; || deUint32 subpassCount;
574 &subpassDescriptions[0], // const VkSubpassDescription* pSubpasses; || const VkSubpassDescription2KHR* pSubpasses;
575 subpassCount, // deUint32 dependencyCount; || deUint32 dependencyCount;
576 &subpassDependencies[0], // const VkSubpassDependency* pDependencies; || const VkSubpassDependency2KHR* pDependencies;
577 0u, // || deUint32 correlatedViewMaskCount;
578 DE_NULL // || const deUint32* pCorrelatedViewMasks;
579 );
580
581 return renderPassInfo.createRenderPass(vk, device);
582 }
583
584 // Instantiate function for legacy renderpass structures
585 template
586 Move<VkRenderPass> makeRenderPassWithAttachments<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
587 (const DeviceInterface& vk,
588 const VkDevice device,
589 const VkFormat colorFormat,
590 const vector<deUint32>& viewMasks,
591 bool useAspects);
592
593 // Instantiate function for renderpass2 structures
594 template
595 Move<VkRenderPass> makeRenderPassWithAttachments<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
596 (const DeviceInterface& vk,
597 const VkDevice device,
598 const VkFormat colorFormat,
599 const vector<deUint32>& viewMasks,
600 bool useAspects);
601
beginSecondaryCommandBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkRenderPass renderPass,const deUint32 subpass,const VkFramebuffer framebuffer)602 void beginSecondaryCommandBuffer (const DeviceInterface& vk,
603 const VkCommandBuffer commandBuffer,
604 const VkRenderPass renderPass,
605 const deUint32 subpass,
606 const VkFramebuffer framebuffer)
607 {
608 const VkCommandBufferInheritanceInfo secCmdBufInheritInfo =
609 {
610 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, //VkStructureType sType;
611 DE_NULL, //const void* pNext;
612 renderPass, //VkRenderPass renderPass;
613 subpass, //deUint32 subpass;
614 framebuffer, //VkFramebuffer framebuffer;
615 VK_FALSE, //VkBool32 occlusionQueryEnable;
616 (VkQueryControlFlags)0u, //VkQueryControlFlags queryFlags;
617 (VkQueryPipelineStatisticFlags)0u, //VkQueryPipelineStatisticFlags pipelineStatistics;
618 };
619
620 const VkCommandBufferBeginInfo info =
621 {
622 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
623 DE_NULL, // const void* pNext;
624 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, // VkCommandBufferUsageFlags flags;
625 &secCmdBufInheritInfo, // const VkCommandBufferInheritanceInfo* pInheritanceInfo;
626 };
627 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
628 }
629
imageBarrier(const DeviceInterface & vk,const VkCommandBuffer cmdBuffer,const VkImage image,const VkImageSubresourceRange subresourceRange,const VkImageLayout oldLayout,const VkImageLayout newLayout,const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkPipelineStageFlags srcStageMask,const VkPipelineStageFlags dstStageMask)630 void imageBarrier (const DeviceInterface& vk,
631 const VkCommandBuffer cmdBuffer,
632 const VkImage image,
633 const VkImageSubresourceRange subresourceRange,
634 const VkImageLayout oldLayout,
635 const VkImageLayout newLayout,
636 const VkAccessFlags srcAccessMask,
637 const VkAccessFlags dstAccessMask,
638 const VkPipelineStageFlags srcStageMask,
639 const VkPipelineStageFlags dstStageMask)
640 {
641 const VkImageMemoryBarrier barrier =
642 {
643 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
644 DE_NULL, // const void* pNext;
645 srcAccessMask, // VkAccessFlags srcAccessMask;
646 dstAccessMask, // VkAccessFlags dstAccessMask;
647 oldLayout, // VkImageLayout oldLayout;
648 newLayout, // VkImageLayout newLayout;
649 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
650 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
651 image, // VkImage image;
652 subresourceRange, // VkImageSubresourceRange subresourceRange;
653 };
654
655 vk.cmdPipelineBarrier(cmdBuffer, srcStageMask, dstStageMask, (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL,
656 0u, (const VkBufferMemoryBarrier*)DE_NULL,
657 1u, &barrier);
658 }
659
660 } // MultiView
661 } // vkt
662