• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 			VK_DEPENDENCY_VIEW_LOCAL_BIT_KHR,								//  VkDependencyFlags				dependencyFlags;			||	VkDependencyFlags					dependencyFlags;
288 			0																//																||	deInt32								viewOffset;
289 		);
290 		subpassDependencies.push_back(subpassDependency);
291 	}
292 
293 	const RenderPassCreateInfo					renderPassInfo				//  VkRenderPassCreateInfo										||  VkRenderPassCreateInfo2KHR
294 	(
295 																			//  VkStructureType					sType;						||  VkStructureType						sType;
296 		renderPassMultiviewInfoPtr,											//  const void*						pNext;						||  const void*							pNext;
297 		(VkRenderPassCreateFlags)0,											//  VkRenderPassCreateFlags			flags;						||  VkRenderPassCreateFlags				flags;
298 		dsAttacmentAvailable ? 2u : 1u,										//  deUint32						attachmentCount;			||  deUint32							attachmentCount;
299 		attachmentDescriptions,												//  const VkAttachmentDescription*	pAttachments;				||  const VkAttachmentDescription2KHR*	pAttachments;
300 		subpassCount,														//  deUint32						subpassCount;				||  deUint32							subpassCount;
301 		&subpassDescriptions[0],											//  const VkSubpassDescription*		pSubpasses;					||  const VkSubpassDescription2KHR*		pSubpasses;
302 		subpassCount,														//  deUint32						dependencyCount;			||  deUint32							dependencyCount;
303 		&subpassDependencies[0],											//  const VkSubpassDependency*		pDependencies;				||  const VkSubpassDependency2KHR*		pDependencies;
304 		0u,																	//																||  deUint32							correlatedViewMaskCount;
305 		DE_NULL																//																||  const deUint32*						pCorrelatedViewMasks;
306 	);
307 
308 	return renderPassInfo.createRenderPass(vk, device);
309 }
310 
311 // Instantiate function for legacy renderpass structures
312 template
313 Move<VkRenderPass> makeRenderPass<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
314 								  (const DeviceInterface&		vk,
315 								   const VkDevice				device,
316 								   const VkFormat				colorFormat,
317 								   const vector<deUint32>&		viewMasks,
318 								   const VkSampleCountFlagBits	samples,
319 								   const VkAttachmentLoadOp		colorLoadOp,
320 								   const VkFormat				dsFormat);
321 
322 // Instantiate function for renderpass2 structures
323 template
324 Move<VkRenderPass> makeRenderPass<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
325 								  (const DeviceInterface&		vk,
326 								   const VkDevice				device,
327 								   const VkFormat				colorFormat,
328 								   const vector<deUint32>&		viewMasks,
329 								   const VkSampleCountFlagBits	samples,
330 								   const VkAttachmentLoadOp		colorLoadOp,
331 								   const VkFormat				dsFormat);
332 
333 
334 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)335 Move<VkRenderPass> makeRenderPassWithDepth (const DeviceInterface& vk, const VkDevice device, const VkFormat colorFormat, const vector<deUint32>& viewMasks, const VkFormat dsFormat)
336 {
337 	return makeRenderPass<AttachmentDesc, AttachmentRef, SubpassDesc, SubpassDep, RenderPassCreateInfo>(vk, device, colorFormat, viewMasks, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR, dsFormat);
338 }
339 
340 // Instantiate function for legacy renderpass structures
341 template
342 Move<VkRenderPass> makeRenderPassWithDepth<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
343 										   (const DeviceInterface&		vk,
344 											const VkDevice				device,
345 											const VkFormat				colorFormat,
346 											const vector<deUint32>&		viewMasks,
347 											const VkFormat				dsFormat);
348 
349 // Instantiate function for renderpass2 structures
350 template
351 Move<VkRenderPass> makeRenderPassWithDepth<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
352 										   (const DeviceInterface&		vk,
353 											const VkDevice				device,
354 											const VkFormat				colorFormat,
355 											const vector<deUint32>&		viewMasks,
356 											const VkFormat				dsFormat);
357 
358 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)359 Move<VkRenderPass> makeRenderPassWithAttachments (const DeviceInterface&	vk,
360 												  const VkDevice			device,
361 												  const VkFormat			colorFormat,
362 												  const vector<deUint32>&	viewMasks,
363 												  bool						useAspects)
364 {
365 	const deUint32								subpassCount				= static_cast<deUint32>(viewMasks.size());
366 
367 	const AttachmentDesc						colorAttachmentDescription	//  VkAttachmentDescription										||  VkAttachmentDescription2KHR
368 	(
369 																			//																||  VkStructureType						sType;
370 		DE_NULL,															//																||  const void*							pNext;
371 		(VkAttachmentDescriptionFlags)0,									//  VkAttachmentDescriptionFlags	flags;						||  VkAttachmentDescriptionFlags		flags;
372 		colorFormat,														//  VkFormat						format;						||  VkFormat							format;
373 		VK_SAMPLE_COUNT_1_BIT,												//  VkSampleCountFlagBits			samples;					||  VkSampleCountFlagBits				samples;
374 		VK_ATTACHMENT_LOAD_OP_CLEAR,										//  VkAttachmentLoadOp				loadOp;						||  VkAttachmentLoadOp					loadOp;
375 		VK_ATTACHMENT_STORE_OP_STORE,										//  VkAttachmentStoreOp				storeOp;					||  VkAttachmentStoreOp					storeOp;
376 		VK_ATTACHMENT_LOAD_OP_DONT_CARE,									//  VkAttachmentLoadOp				stencilLoadOp;				||  VkAttachmentLoadOp					stencilLoadOp;
377 		VK_ATTACHMENT_STORE_OP_DONT_CARE,									//  VkAttachmentStoreOp				stencilStoreOp;				||  VkAttachmentStoreOp					stencilStoreOp;
378 		VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,							//  VkImageLayout					initialLayout;				||  VkImageLayout						initialLayout;
379 		VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL							//  VkImageLayout					finalLayout;				||  VkImageLayout						finalLayout;
380 	);
381 
382 	const AttachmentDesc						inputAttachmentDescription	//  VkAttachmentDescription										||  VkAttachmentDescription2KHR
383 	(
384 																			//																||  VkStructureType						sType;
385 		DE_NULL,															//																||  const void*							pNext;
386 		(VkAttachmentDescriptionFlags)0,									//  VkAttachmentDescriptionFlags	flags;						||  VkAttachmentDescriptionFlags		flags;
387 		colorFormat,														//  VkFormat						format;						||  VkFormat							format;
388 		VK_SAMPLE_COUNT_1_BIT,												//  VkSampleCountFlagBits			samples;					||  VkSampleCountFlagBits				samples;
389 		VK_ATTACHMENT_LOAD_OP_LOAD,											//  VkAttachmentLoadOp				loadOp;						||  VkAttachmentLoadOp					loadOp;
390 		VK_ATTACHMENT_STORE_OP_STORE,										//  VkAttachmentStoreOp				storeOp;					||  VkAttachmentStoreOp					storeOp;
391 		VK_ATTACHMENT_LOAD_OP_DONT_CARE,									//  VkAttachmentLoadOp				stencilLoadOp;				||  VkAttachmentLoadOp					stencilLoadOp;
392 		VK_ATTACHMENT_STORE_OP_DONT_CARE,									//  VkAttachmentStoreOp				stencilStoreOp;				||  VkAttachmentStoreOp					stencilStoreOp;
393 		VK_IMAGE_LAYOUT_GENERAL,											//  VkImageLayout					initialLayout;				||  VkImageLayout						initialLayout;
394 		VK_IMAGE_LAYOUT_GENERAL												//  VkImageLayout					finalLayout;				||  VkImageLayout						finalLayout;
395 	);
396 
397 	vector<AttachmentDesc>						attachments;
398 	attachments.push_back(colorAttachmentDescription);
399 	attachments.push_back(inputAttachmentDescription);
400 
401 	const AttachmentRef							colorAttachmentReference	//  VkAttachmentReference										||  VkAttachmentReference2KHR
402 	(
403 																			//																||  VkStructureType						sType;
404 		DE_NULL,															//																||  const void*							pNext;
405 		0u,																	//  deUint32						attachment;					||  deUint32							attachment;
406 		VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,							//  VkImageLayout					layout;						||  VkImageLayout						layout;
407 		0u																	//																||  VkImageAspectFlags					aspectMask;
408 	);
409 
410 	const AttachmentRef							inputAttachmentReference	//  VkAttachmentReference										||  VkAttachmentReference2KHR
411 	(
412 																			//																||  VkStructureType						sType;
413 		DE_NULL,															//																||  const void*							pNext;
414 		1u,																	//  deUint32						attachment;					||  deUint32							attachment;
415 		VK_IMAGE_LAYOUT_GENERAL,											//  VkImageLayout					layout;						||  VkImageLayout						layout;
416 		useAspects ? VK_IMAGE_ASPECT_COLOR_BIT : static_cast<VkImageAspectFlagBits>(0u)							//																||  VkImageAspectFlags					aspectMask;
417 	);
418 
419 	const AttachmentRef							depthAttachmentReference	//  VkAttachmentReference										||  VkAttachmentReference2KHR
420 	(
421 																			//																||  VkStructureType						sType;
422 		DE_NULL,															//																||  const void*							pNext;
423 		VK_ATTACHMENT_UNUSED,												//  deUint32						attachment;					||  deUint32							attachment;
424 		VK_IMAGE_LAYOUT_UNDEFINED,											//  VkImageLayout					layout;						||  VkImageLayout						layout;
425 		0u																	//																||  VkImageAspectFlags					aspectMask;
426 	);
427 
428 	DE_ASSERT((typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1)) || (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2)));
429 
430 	vector <SubpassDesc>						subpassDescriptions;
431 	for (deUint32 subpassNdx = 0; subpassNdx < subpassCount; ++subpassNdx)
432 	{
433 		const deUint32							viewMask					= (typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo2))
434 																			? viewMasks[subpassNdx]
435 																			: 0u;
436 		const SubpassDesc						subpassDescription			//  VkSubpassDescription										||  VkSubpassDescription2KHR
437 		(
438 																			//																||  VkStructureType						sType;
439 			DE_NULL,														//																||  const void*							pNext;
440 			(VkSubpassDescriptionFlags)0,									// VkSubpassDescriptionFlags		flags;						||  VkSubpassDescriptionFlags			flags;
441 			VK_PIPELINE_BIND_POINT_GRAPHICS,								// VkPipelineBindPoint				pipelineBindPoint;			||  VkPipelineBindPoint					pipelineBindPoint;
442 			viewMask,														//																||  deUint32							viewMask;
443 			1u,																// deUint32							inputAttachmentCount;		||  deUint32							inputAttachmentCount;
444 			&inputAttachmentReference,										// const VkAttachmentReference*		pInputAttachments;			||  const VkAttachmentReference2KHR*	pInputAttachments;
445 			1u,																// deUint32							colorAttachmentCount;		||  deUint32							colorAttachmentCount;
446 			&colorAttachmentReference,										// const VkAttachmentReference*		pColorAttachments;			||  const VkAttachmentReference2KHR*	pColorAttachments;
447 			DE_NULL,														// const VkAttachmentReference*		pResolveAttachments;		||  const VkAttachmentReference2KHR*	pResolveAttachments;
448 			&depthAttachmentReference,										// const VkAttachmentReference*		pDepthStencilAttachment;	||  const VkAttachmentReference2KHR*	pDepthStencilAttachment;
449 			0u,																// deUint32							preserveAttachmentCount;	||  deUint32							preserveAttachmentCount;
450 			DE_NULL															// const deUint32*					pPreserveAttachments;		||  const deUint32*						pPreserveAttachments;
451 		);
452 		subpassDescriptions.push_back(subpassDescription);
453 	}
454 
455 	const VkRenderPassMultiviewCreateInfo		renderPassMultiviewInfo		=
456 	{
457 		VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO_KHR,	//VkStructureType	sType;
458 		DE_NULL,													//const void*		pNext;
459 		subpassCount,												//uint32_t			subpassCount;
460 		&viewMasks[0],												//const uint32_t*	pViewMasks;
461 		0u,															//uint32_t			dependencyCount;
462 		DE_NULL,													//const int32_t*	pViewOffsets;
463 		0u,															//uint32_t			correlationMaskCount;
464 		DE_NULL,													//const uint32_t*	pCorrelationMasks;
465 	};
466 	const VkRenderPassMultiviewCreateInfo*		renderPassMultiviewInfoPtr	= typeid(RenderPassCreateInfo) == typeid(RenderPassCreateInfo1)
467 																			? &renderPassMultiviewInfo
468 																			: DE_NULL;
469 
470 	vector <SubpassDep>							subpassDependencies;
471 	for(deUint32 subpassNdx = 0u; subpassNdx < subpassCount; ++subpassNdx)
472 	{
473 		const SubpassDep						subpassDependency			//  VkSubpassDependency											||  VkSubpassDependency2KHR
474 		(
475 																			//																||	VkStructureType						sType;
476 			DE_NULL,														//																||	const void*							pNext;
477 			subpassNdx,														//  deUint32						srcSubpass;					||	deUint32							srcSubpass;
478 			(subpassNdx == subpassCount -1u) ? subpassNdx : subpassNdx+1u,	//  deUint32						dstSubpass;					||	deUint32							dstSubpass;
479 			VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,					//  VkPipelineStageFlags			srcStageMask;				||	VkPipelineStageFlags				srcStageMask;
480 			VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,							//  VkPipelineStageFlags			dstStageMask;				||	VkPipelineStageFlags				dstStageMask;
481 			VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,							//  VkAccessFlags					srcAccessMask;				||	VkAccessFlags						srcAccessMask;
482 			VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,							//  VkAccessFlags					dstAccessMask;				||	VkAccessFlags						dstAccessMask;
483 			VK_DEPENDENCY_VIEW_LOCAL_BIT_KHR,								//  VkDependencyFlags				dependencyFlags;			||	VkDependencyFlags					dependencyFlags;
484 			0																//																||	deInt32								viewOffset;
485 		);
486 		subpassDependencies.push_back(subpassDependency);
487 	}
488 
489 	const RenderPassCreateInfo					renderPassInfo				//  VkRenderPassCreateInfo										||  VkRenderPassCreateInfo2KHR
490 	(
491 																			//  VkStructureType					sType;						||  VkStructureType						sType;
492 		renderPassMultiviewInfoPtr,											//  const void*						pNext;						||  const void*							pNext;
493 		(VkRenderPassCreateFlags)0,											//  VkRenderPassCreateFlags			flags;						||  VkRenderPassCreateFlags				flags;
494 		2u,																	//  deUint32						attachmentCount;			||  deUint32							attachmentCount;
495 		&attachments[0],													//  const VkAttachmentDescription*	pAttachments;				||  const VkAttachmentDescription2KHR*	pAttachments;
496 		subpassCount,														//  deUint32						subpassCount;				||  deUint32							subpassCount;
497 		&subpassDescriptions[0],											//  const VkSubpassDescription*		pSubpasses;					||  const VkSubpassDescription2KHR*		pSubpasses;
498 		subpassCount,														//  deUint32						dependencyCount;			||  deUint32							dependencyCount;
499 		&subpassDependencies[0],											//  const VkSubpassDependency*		pDependencies;				||  const VkSubpassDependency2KHR*		pDependencies;
500 		0u,																	//																||  deUint32							correlatedViewMaskCount;
501 		DE_NULL																//																||  const deUint32*						pCorrelatedViewMasks;
502 	);
503 
504 	return renderPassInfo.createRenderPass(vk, device);
505 }
506 
507 // Instantiate function for legacy renderpass structures
508 template
509 Move<VkRenderPass> makeRenderPassWithAttachments<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>
510 												 (const DeviceInterface&	vk,
511 												  const VkDevice			device,
512 												  const VkFormat			colorFormat,
513 												  const vector<deUint32>&	viewMasks,
514 												  bool						useAspects);
515 
516 // Instantiate function for renderpass2 structures
517 template
518 Move<VkRenderPass> makeRenderPassWithAttachments<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>
519 												 (const DeviceInterface&	vk,
520 												  const VkDevice			device,
521 												  const VkFormat			colorFormat,
522 												  const vector<deUint32>&	viewMasks,
523 												  bool						useAspects);
524 
beginSecondaryCommandBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkRenderPass renderPass,const deUint32 subpass,const VkFramebuffer framebuffer)525 void beginSecondaryCommandBuffer (const DeviceInterface&				vk,
526 								   const VkCommandBuffer				commandBuffer,
527 								   const VkRenderPass					renderPass,
528 								   const deUint32						subpass,
529 								   const VkFramebuffer					framebuffer)
530 {
531 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
532 	{
533 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,	//VkStructureType				sType;
534 		DE_NULL,											//const void*					pNext;
535 		renderPass,											//VkRenderPass					renderPass;
536 		subpass,											//deUint32						subpass;
537 		framebuffer,										//VkFramebuffer					framebuffer;
538 		VK_FALSE,											//VkBool32						occlusionQueryEnable;
539 		(VkQueryControlFlags)0u,							//VkQueryControlFlags			queryFlags;
540 		(VkQueryPipelineStatisticFlags)0u,					//VkQueryPipelineStatisticFlags	pipelineStatistics;
541 	};
542 
543 	const VkCommandBufferBeginInfo			info					=
544 	{
545 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,		// VkStructureType							sType;
546 		DE_NULL,											// const void*								pNext;
547 		VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT,	// VkCommandBufferUsageFlags				flags;
548 		&secCmdBufInheritInfo,							// const VkCommandBufferInheritanceInfo*	pInheritanceInfo;
549 	};
550 	VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
551 }
552 
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)553 void imageBarrier (const DeviceInterface&			vk,
554 				   const VkCommandBuffer			cmdBuffer,
555 				   const VkImage					image,
556 				   const VkImageSubresourceRange	subresourceRange,
557 				   const VkImageLayout				oldLayout,
558 				   const VkImageLayout				newLayout,
559 				   const VkAccessFlags				srcAccessMask,
560 				   const VkAccessFlags				dstAccessMask,
561 				   const VkPipelineStageFlags		srcStageMask,
562 				   const VkPipelineStageFlags		dstStageMask)
563 {
564 	const VkImageMemoryBarrier		barrier				=
565 	{
566 		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,	// VkStructureType			sType;
567 		DE_NULL,								// const void*				pNext;
568 		srcAccessMask,							// VkAccessFlags			srcAccessMask;
569 		dstAccessMask,							// VkAccessFlags			dstAccessMask;
570 		oldLayout,								// VkImageLayout			oldLayout;
571 		newLayout,								// VkImageLayout			newLayout;
572 		VK_QUEUE_FAMILY_IGNORED,				// deUint32					srcQueueFamilyIndex;
573 		VK_QUEUE_FAMILY_IGNORED,				// deUint32					dstQueueFamilyIndex;
574 		image,									// VkImage					image;
575 		subresourceRange,						// VkImageSubresourceRange	subresourceRange;
576 	};
577 
578 	vk.cmdPipelineBarrier(cmdBuffer, srcStageMask, dstStageMask, (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL,
579 		0u, (const VkBufferMemoryBarrier*)DE_NULL,
580 		1u, &barrier);
581 }
582 
583 } // MultiView
584 } // vkt
585