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
makeImageCreateInfo(const VkImageType imageType,const VkExtent3D & extent,const VkFormat format,const VkImageUsageFlags usage,const VkSampleCountFlagBits samples)112 VkImageCreateInfo makeImageCreateInfo (const VkImageType imageType, const VkExtent3D& extent, const VkFormat format, const VkImageUsageFlags usage, const VkSampleCountFlagBits samples)
113 {
114 const VkImageCreateInfo imageInfo =
115 {
116 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
117 DE_NULL, // const void* pNext;
118 (VkImageCreateFlags)0, // VkImageCreateFlags flags;
119 imageType, // VkImageType imageType;
120 format, // VkFormat format;
121 {extent.width, extent.height, 1u}, // VkExtent3D extent;
122 1u, // uint32_t mipLevels;
123 extent.depth, // uint32_t arrayLayers;
124 samples, // VkSampleCountFlagBits samples;
125 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
126 usage, // VkImageUsageFlags usage;
127 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
128 0u, // uint32_t queueFamilyIndexCount;
129 DE_NULL, // const uint32_t* pQueueFamilyIndices;
130 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
131 };
132 return imageInfo;
133 }
134
makeDescriptorSetLayout(const DeviceInterface & vk,const VkDevice device)135 Move<VkDescriptorSetLayout> makeDescriptorSetLayout (const DeviceInterface& vk,
136 const VkDevice device)
137 {
138 const VkDescriptorSetLayoutBinding binding =
139 {
140 0u, //deUint32 binding;
141 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, //VkDescriptorType descriptorType;
142 1u, //deUint32 descriptorCount;
143 vk::VK_SHADER_STAGE_FRAGMENT_BIT, //VkShaderStageFlags stageFlags;
144 DE_NULL //const VkSampler* pImmutableSamplers;
145 };
146
147 const VkDescriptorSetLayoutCreateInfo createInfo =
148 {
149 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, //VkStructureType sType;
150 DE_NULL, //const void* pNext;
151 0u, //VkDescriptorSetLayoutCreateFlags flags;
152 1u, //deUint32 bindingCount;
153 &binding //const VkDescriptorSetLayoutBinding* pBindings;
154 };
155 return vk::createDescriptorSetLayout(vk, device, &createInfo);
156 }
157
158 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)159 Move<VkRenderPass> makeRenderPass (const DeviceInterface& vk,
160 const VkDevice device,
161 const VkFormat colorFormat,
162 const vector<deUint32>& viewMasks,
163 const VkSampleCountFlagBits samples,
164 const VkAttachmentLoadOp colorLoadOp,
165 const VkFormat dsFormat)
166 {
167 const bool dsAttacmentAvailable = (dsFormat != vk::VK_FORMAT_UNDEFINED);
168 const deUint32 subpassCount = static_cast<deUint32>(viewMasks.size());
169 const AttachmentDesc colorAttachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
170 (
171 // || VkStructureType sType;
172 DE_NULL, // || const void* pNext;
173 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
174 colorFormat, // VkFormat format; || VkFormat format;
175 samples, // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
176 colorLoadOp, // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
177 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
178 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
179 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
180 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout; || VkImageLayout initialLayout;
181 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout; || VkImageLayout finalLayout;
182 );
183
184 const AttachmentRef colorAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
185 (
186 // || VkStructureType sType;
187 DE_NULL, // || const void* pNext;
188 0u, // deUint32 attachment; || deUint32 attachment;
189 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout layout; || VkImageLayout layout;
190 0u // || VkImageAspectFlags aspectMask;
191 );
192
193 const AttachmentDesc dsAttachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
194 (
195 // || VkStructureType sType;
196 DE_NULL, // || const void* pNext;
197 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
198 dsFormat, // VkFormat format; || VkFormat format;
199 samples, // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
200 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
201 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
202 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
203 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
204 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout; || VkImageLayout initialLayout;
205 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout; || VkImageLayout finalLayout;
206 );
207
208 const AttachmentRef depthAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
209 (
210 // || VkStructureType sType;
211 DE_NULL, // || const void* pNext;
212 dsAttacmentAvailable ? 1u : VK_ATTACHMENT_UNUSED, // deUint32 attachment; || deUint32 attachment;
213 dsAttacmentAvailable ? // VkImageLayout layout; || VkImageLayout layout;
214 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL :
215 VK_IMAGE_LAYOUT_UNDEFINED,
216 0u // || VkImageAspectFlags aspectMask;
217 );
218
219 const AttachmentDesc attachmentDescriptions[] =
220 {
221 colorAttachmentDescription,
222 dsAttachmentDescription,
223 };
224
225 DE_ASSERT((typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1)) || (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2)));
226
227 vector <SubpassDesc> subpassDescriptions;
228 for (deUint32 subpassNdx = 0; subpassNdx < subpassCount; ++subpassNdx)
229 {
230 const deUint32 viewMask = (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2))
231 ? viewMasks[subpassNdx]
232 : 0u;
233 const SubpassDesc subpassDescription // VkSubpassDescription || VkSubpassDescription2KHR
234 (
235 // || VkStructureType sType;
236 DE_NULL, // || const void* pNext;
237 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags; || VkSubpassDescriptionFlags flags;
238 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint; || VkPipelineBindPoint pipelineBindPoint;
239 viewMask, // || deUint32 viewMask;
240 0u, // deUint32 inputAttachmentCount; || deUint32 inputAttachmentCount;
241 DE_NULL, // const VkAttachmentReference* pInputAttachments; || const VkAttachmentReference2KHR* pInputAttachments;
242 1u, // deUint32 colorAttachmentCount; || deUint32 colorAttachmentCount;
243 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments; || const VkAttachmentReference2KHR* pColorAttachments;
244 DE_NULL, // const VkAttachmentReference* pResolveAttachments; || const VkAttachmentReference2KHR* pResolveAttachments;
245 &depthAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment; || const VkAttachmentReference2KHR* pDepthStencilAttachment;
246 0u, // deUint32 preserveAttachmentCount; || deUint32 preserveAttachmentCount;
247 DE_NULL // const deUint32* pPreserveAttachments; || const deUint32* pPreserveAttachments;
248 );
249
250 subpassDescriptions.push_back(subpassDescription);
251 }
252
253 const VkRenderPassMultiviewCreateInfo renderPassMultiviewInfo =
254 {
255 VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO_KHR, // VkStructureType sType;
256 DE_NULL, // const void* pNext;
257 subpassCount, // uint32_t subpassCount;
258 &viewMasks[0], // const uint32_t* pViewMasks;
259 0u, // uint32_t dependencyCount;
260 DE_NULL, // const int32_t* pViewOffsets;
261 0u, // uint32_t correlationMaskCount;
262 DE_NULL, // const uint32_t* pCorrelationMasks;
263 };
264 const VkRenderPassMultiviewCreateInfo* renderPassMultiviewInfoPtr = (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1))
265 ? &renderPassMultiviewInfo
266 : DE_NULL;
267
268 const VkPipelineStageFlags srcStageMask = dsAttacmentAvailable
269 ? VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
270 : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
271 const VkAccessFlags srcAccessMask = dsAttacmentAvailable
272 ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
273 : VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
274 vector <SubpassDep> subpassDependencies;
275 for(deUint32 subpassNdx = 0u; subpassNdx < subpassCount; ++subpassNdx)
276 {
277 const SubpassDep subpassDependency // VkSubpassDependency || VkSubpassDependency2KHR
278 (
279 // || VkStructureType sType;
280 DE_NULL, // || const void* pNext;
281 subpassNdx, // deUint32 srcSubpass; || deUint32 srcSubpass;
282 (subpassNdx == subpassCount -1u) ? subpassNdx : subpassNdx+1u, // deUint32 dstSubpass; || deUint32 dstSubpass;
283 srcStageMask, // VkPipelineStageFlags srcStageMask; || VkPipelineStageFlags srcStageMask;
284 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, // VkPipelineStageFlags dstStageMask; || VkPipelineStageFlags dstStageMask;
285 srcAccessMask, // VkAccessFlags srcAccessMask; || VkAccessFlags srcAccessMask;
286 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // VkAccessFlags dstAccessMask; || VkAccessFlags dstAccessMask;
287 (subpassNdx == subpassCount - 1u) ? // VkDependencyFlags dependencyFlags; || VkDependencyFlags dependencyFlags;
288 VK_DEPENDENCY_VIEW_LOCAL_BIT | VK_DEPENDENCY_BY_REGION_BIT :// handle subpass self-dependency
289 VK_DEPENDENCY_VIEW_LOCAL_BIT,
290 0 // || deInt32 viewOffset;
291 );
292 subpassDependencies.push_back(subpassDependency);
293 }
294
295 const RenderPassCreateInfo renderPassInfo // VkRenderPassCreateInfo || VkRenderPassCreateInfo2KHR
296 (
297 // VkStructureType sType; || VkStructureType sType;
298 renderPassMultiviewInfoPtr, // const void* pNext; || const void* pNext;
299 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags; || VkRenderPassCreateFlags flags;
300 dsAttacmentAvailable ? 2u : 1u, // deUint32 attachmentCount; || deUint32 attachmentCount;
301 attachmentDescriptions, // const VkAttachmentDescription* pAttachments; || const VkAttachmentDescription2KHR* pAttachments;
302 subpassCount, // deUint32 subpassCount; || deUint32 subpassCount;
303 &subpassDescriptions[0], // const VkSubpassDescription* pSubpasses; || const VkSubpassDescription2KHR* pSubpasses;
304 subpassCount, // deUint32 dependencyCount; || deUint32 dependencyCount;
305 &subpassDependencies[0], // const VkSubpassDependency* pDependencies; || const VkSubpassDependency2KHR* pDependencies;
306 0u, // || deUint32 correlatedViewMaskCount;
307 DE_NULL // || const deUint32* pCorrelatedViewMasks;
308 );
309
310 return renderPassInfo.createRenderPass(vk, device);
311 }
312
313 // Instantiate function for legacy renderpass structures
314 template
315 Move<VkRenderPass> makeRenderPass<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
316 (const DeviceInterface& vk,
317 const VkDevice device,
318 const VkFormat colorFormat,
319 const vector<deUint32>& viewMasks,
320 const VkSampleCountFlagBits samples,
321 const VkAttachmentLoadOp colorLoadOp,
322 const VkFormat dsFormat);
323
324 // Instantiate function for renderpass2 structures
325 template
326 Move<VkRenderPass> makeRenderPass<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
327 (const DeviceInterface& vk,
328 const VkDevice device,
329 const VkFormat colorFormat,
330 const vector<deUint32>& viewMasks,
331 const VkSampleCountFlagBits samples,
332 const VkAttachmentLoadOp colorLoadOp,
333 const VkFormat dsFormat);
334
335
336 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)337 Move<VkRenderPass> makeRenderPassWithDepth (const DeviceInterface& vk, const VkDevice device, const VkFormat colorFormat, const vector<deUint32>& viewMasks, const VkFormat dsFormat)
338 {
339 return makeRenderPass<AttachmentDesc, AttachmentRef, SubpassDesc, SubpassDep, RenderPassCreateInfo>(vk, device, colorFormat, viewMasks, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR, dsFormat);
340 }
341
342 // Instantiate function for legacy renderpass structures
343 template
344 Move<VkRenderPass> makeRenderPassWithDepth<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
345 (const DeviceInterface& vk,
346 const VkDevice device,
347 const VkFormat colorFormat,
348 const vector<deUint32>& viewMasks,
349 const VkFormat dsFormat);
350
351 // Instantiate function for renderpass2 structures
352 template
353 Move<VkRenderPass> makeRenderPassWithDepth<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
354 (const DeviceInterface& vk,
355 const VkDevice device,
356 const VkFormat colorFormat,
357 const vector<deUint32>& viewMasks,
358 const VkFormat dsFormat);
359
360 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)361 Move<VkRenderPass> makeRenderPassWithAttachments (const DeviceInterface& vk,
362 const VkDevice device,
363 const VkFormat colorFormat,
364 const vector<deUint32>& viewMasks,
365 bool useAspects)
366 {
367 const deUint32 subpassCount = static_cast<deUint32>(viewMasks.size());
368
369 const AttachmentDesc colorAttachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
370 (
371 // || VkStructureType sType;
372 DE_NULL, // || const void* pNext;
373 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
374 colorFormat, // VkFormat format; || VkFormat format;
375 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
376 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
377 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
378 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
379 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
380 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout; || VkImageLayout initialLayout;
381 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout; || VkImageLayout finalLayout;
382 );
383
384 const AttachmentDesc inputAttachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
385 (
386 // || VkStructureType sType;
387 DE_NULL, // || const void* pNext;
388 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
389 colorFormat, // VkFormat format; || VkFormat format;
390 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
391 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
392 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
393 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
394 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
395 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout initialLayout; || VkImageLayout initialLayout;
396 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout finalLayout; || VkImageLayout finalLayout;
397 );
398
399 vector<AttachmentDesc> attachments;
400 attachments.push_back(colorAttachmentDescription);
401 attachments.push_back(inputAttachmentDescription);
402
403 const AttachmentRef colorAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
404 (
405 // || VkStructureType sType;
406 DE_NULL, // || const void* pNext;
407 0u, // deUint32 attachment; || deUint32 attachment;
408 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout layout; || VkImageLayout layout;
409 0u // || VkImageAspectFlags aspectMask;
410 );
411
412 const AttachmentRef inputAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
413 (
414 // || VkStructureType sType;
415 DE_NULL, // || const void* pNext;
416 1u, // deUint32 attachment; || deUint32 attachment;
417 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout layout; || VkImageLayout layout;
418 useAspects ? VK_IMAGE_ASPECT_COLOR_BIT : static_cast<VkImageAspectFlagBits>(0u) // || VkImageAspectFlags aspectMask;
419 );
420
421 const AttachmentRef depthAttachmentReference // VkAttachmentReference || VkAttachmentReference2KHR
422 (
423 // || VkStructureType sType;
424 DE_NULL, // || const void* pNext;
425 VK_ATTACHMENT_UNUSED, // deUint32 attachment; || deUint32 attachment;
426 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout layout; || VkImageLayout layout;
427 0u // || VkImageAspectFlags aspectMask;
428 );
429
430 DE_ASSERT((typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1)) || (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2)));
431
432 vector <SubpassDesc> subpassDescriptions;
433 for (deUint32 subpassNdx = 0; subpassNdx < subpassCount; ++subpassNdx)
434 {
435 const deUint32 viewMask = (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2))
436 ? viewMasks[subpassNdx]
437 : 0u;
438 const SubpassDesc subpassDescription // VkSubpassDescription || VkSubpassDescription2KHR
439 (
440 // || VkStructureType sType;
441 DE_NULL, // || const void* pNext;
442 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags; || VkSubpassDescriptionFlags flags;
443 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint; || VkPipelineBindPoint pipelineBindPoint;
444 viewMask, // || deUint32 viewMask;
445 1u, // deUint32 inputAttachmentCount; || deUint32 inputAttachmentCount;
446 &inputAttachmentReference, // const VkAttachmentReference* pInputAttachments; || const VkAttachmentReference2KHR* pInputAttachments;
447 1u, // deUint32 colorAttachmentCount; || deUint32 colorAttachmentCount;
448 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments; || const VkAttachmentReference2KHR* pColorAttachments;
449 DE_NULL, // const VkAttachmentReference* pResolveAttachments; || const VkAttachmentReference2KHR* pResolveAttachments;
450 &depthAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment; || const VkAttachmentReference2KHR* pDepthStencilAttachment;
451 0u, // deUint32 preserveAttachmentCount; || deUint32 preserveAttachmentCount;
452 DE_NULL // const deUint32* pPreserveAttachments; || const deUint32* pPreserveAttachments;
453 );
454 subpassDescriptions.push_back(subpassDescription);
455 }
456
457 const VkRenderPassMultiviewCreateInfo renderPassMultiviewInfo =
458 {
459 VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO_KHR, //VkStructureType sType;
460 DE_NULL, //const void* pNext;
461 subpassCount, //uint32_t subpassCount;
462 &viewMasks[0], //const uint32_t* pViewMasks;
463 0u, //uint32_t dependencyCount;
464 DE_NULL, //const int32_t* pViewOffsets;
465 0u, //uint32_t correlationMaskCount;
466 DE_NULL, //const uint32_t* pCorrelationMasks;
467 };
468 const VkRenderPassMultiviewCreateInfo* renderPassMultiviewInfoPtr = typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1)
469 ? &renderPassMultiviewInfo
470 : DE_NULL;
471
472 vector <SubpassDep> subpassDependencies;
473 for(deUint32 subpassNdx = 0u; subpassNdx < subpassCount; ++subpassNdx)
474 {
475 const SubpassDep subpassDependency // VkSubpassDependency || VkSubpassDependency2KHR
476 (
477 // || VkStructureType sType;
478 DE_NULL, // || const void* pNext;
479 subpassNdx, // deUint32 srcSubpass; || deUint32 srcSubpass;
480 (subpassNdx == subpassCount -1u) ? subpassNdx : subpassNdx+1u, // deUint32 dstSubpass; || deUint32 dstSubpass;
481 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, // VkPipelineStageFlags srcStageMask; || VkPipelineStageFlags srcStageMask;
482 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, // VkPipelineStageFlags dstStageMask; || VkPipelineStageFlags dstStageMask;
483 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags srcAccessMask; || VkAccessFlags srcAccessMask;
484 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // VkAccessFlags dstAccessMask; || VkAccessFlags dstAccessMask;
485 (subpassNdx == subpassCount - 1u) ? // VkDependencyFlags dependencyFlags; || VkDependencyFlags dependencyFlags;
486 VK_DEPENDENCY_VIEW_LOCAL_BIT | VK_DEPENDENCY_BY_REGION_BIT :// handle subpass self-dependency
487 VK_DEPENDENCY_VIEW_LOCAL_BIT,
488 0 // || deInt32 viewOffset;
489 );
490 subpassDependencies.push_back(subpassDependency);
491 }
492
493 const RenderPassCreateInfo renderPassInfo // VkRenderPassCreateInfo || VkRenderPassCreateInfo2KHR
494 (
495 // VkStructureType sType; || VkStructureType sType;
496 renderPassMultiviewInfoPtr, // const void* pNext; || const void* pNext;
497 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags; || VkRenderPassCreateFlags flags;
498 2u, // deUint32 attachmentCount; || deUint32 attachmentCount;
499 &attachments[0], // const VkAttachmentDescription* pAttachments; || const VkAttachmentDescription2KHR* pAttachments;
500 subpassCount, // deUint32 subpassCount; || deUint32 subpassCount;
501 &subpassDescriptions[0], // const VkSubpassDescription* pSubpasses; || const VkSubpassDescription2KHR* pSubpasses;
502 subpassCount, // deUint32 dependencyCount; || deUint32 dependencyCount;
503 &subpassDependencies[0], // const VkSubpassDependency* pDependencies; || const VkSubpassDependency2KHR* pDependencies;
504 0u, // || deUint32 correlatedViewMaskCount;
505 DE_NULL // || const deUint32* pCorrelatedViewMasks;
506 );
507
508 return renderPassInfo.createRenderPass(vk, device);
509 }
510
511 // Instantiate function for legacy renderpass structures
512 template
513 Move<VkRenderPass> makeRenderPassWithAttachments<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
514 (const DeviceInterface& vk,
515 const VkDevice device,
516 const VkFormat colorFormat,
517 const vector<deUint32>& viewMasks,
518 bool useAspects);
519
520 // Instantiate function for renderpass2 structures
521 template
522 Move<VkRenderPass> makeRenderPassWithAttachments<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
523 (const DeviceInterface& vk,
524 const VkDevice device,
525 const VkFormat colorFormat,
526 const vector<deUint32>& viewMasks,
527 bool useAspects);
528
beginSecondaryCommandBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkRenderPass renderPass,const deUint32 subpass,const VkFramebuffer framebuffer)529 void beginSecondaryCommandBuffer (const DeviceInterface& vk,
530 const VkCommandBuffer commandBuffer,
531 const VkRenderPass renderPass,
532 const deUint32 subpass,
533 const VkFramebuffer framebuffer)
534 {
535 const VkCommandBufferInheritanceInfo secCmdBufInheritInfo =
536 {
537 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, //VkStructureType sType;
538 DE_NULL, //const void* pNext;
539 renderPass, //VkRenderPass renderPass;
540 subpass, //deUint32 subpass;
541 framebuffer, //VkFramebuffer framebuffer;
542 VK_FALSE, //VkBool32 occlusionQueryEnable;
543 (VkQueryControlFlags)0u, //VkQueryControlFlags queryFlags;
544 (VkQueryPipelineStatisticFlags)0u, //VkQueryPipelineStatisticFlags pipelineStatistics;
545 };
546
547 const VkCommandBufferBeginInfo info =
548 {
549 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
550 DE_NULL, // const void* pNext;
551 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, // VkCommandBufferUsageFlags flags;
552 &secCmdBufInheritInfo, // const VkCommandBufferInheritanceInfo* pInheritanceInfo;
553 };
554 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
555 }
556
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)557 void imageBarrier (const DeviceInterface& vk,
558 const VkCommandBuffer cmdBuffer,
559 const VkImage image,
560 const VkImageSubresourceRange subresourceRange,
561 const VkImageLayout oldLayout,
562 const VkImageLayout newLayout,
563 const VkAccessFlags srcAccessMask,
564 const VkAccessFlags dstAccessMask,
565 const VkPipelineStageFlags srcStageMask,
566 const VkPipelineStageFlags dstStageMask)
567 {
568 const VkImageMemoryBarrier barrier =
569 {
570 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
571 DE_NULL, // const void* pNext;
572 srcAccessMask, // VkAccessFlags srcAccessMask;
573 dstAccessMask, // VkAccessFlags dstAccessMask;
574 oldLayout, // VkImageLayout oldLayout;
575 newLayout, // VkImageLayout newLayout;
576 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
577 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
578 image, // VkImage image;
579 subresourceRange, // VkImageSubresourceRange subresourceRange;
580 };
581
582 vk.cmdPipelineBarrier(cmdBuffer, srcStageMask, dstStageMask, (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL,
583 0u, (const VkBufferMemoryBarrier*)DE_NULL,
584 1u, &barrier);
585 }
586
587 } // MultiView
588 } // vkt
589