• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2021 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 Dynamic Rendering Tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "deRandom.hpp"
25 #include "deUniquePtr.hpp"
26 
27 #include "tcuImageCompare.hpp"
28 #include "tcuRGBA.hpp"
29 #include "tcuTestLog.hpp"
30 #include "tcuTextureUtil.hpp"
31 #include "tcuVectorUtil.hpp"
32 
33 #include "vkBarrierUtil.hpp"
34 #include "vkBuilderUtil.hpp"
35 #include "vkCmdUtil.hpp"
36 #include "vktDrawBufferObjectUtil.hpp"
37 #include "vktDynamicRenderingTests.hpp"
38 #include "vkImageUtil.hpp"
39 #include "vkObjUtil.hpp"
40 #include "vkQueryUtil.hpp"
41 #include "vkRefUtil.hpp"
42 #include "vktTestGroupUtil.hpp"
43 #include "vktTestCase.hpp"
44 #include "vkTypeUtil.hpp"
45 
46 #include <iostream>
47 
48 namespace vkt
49 {
50 namespace renderpass
51 {
52 namespace
53 {
54 
55 using namespace vk;
56 using namespace Draw;
57 
58 using de::MovePtr;
59 using de::UniquePtr;
60 using de::SharedPtr;
61 
62 using tcu::UVec2;
63 using tcu::Vec4;
64 using tcu::IVec4;
65 using tcu::UVec4;
66 
67 constexpr auto		VK_NULL_HANDLE				= DE_NULL;
68  // maxColorAttachments is guaranteed to be at least 4.
69 constexpr deUint32	COLOR_ATTACHMENTS_NUMBER	= 4;
70 
71 constexpr deUint32	TEST_ATTACHMENT_LOAD_OP_LAST = 3;
72 
73 enum TestType
74 {
75 	// Draw two triangles in a single primary command buffer, beginning and ending the render pass instance.
76 	TEST_TYPE_SINGLE_CMDBUF = 0,
77 	// Draw two triangles in a single primary command buffer, but across two render pass instances, with the second RESUMING the first.
78 	TEST_TYPE_SINGLE_CMDBUF_RESUMING,
79 	// Draw two triangles in two primary command buffers, across two render pass instances, with the second RESUMING the first.
80 	TEST_TYPE_TWO_CMDBUF_RESUMING,
81 	// Draw two triangles in two secondary command buffers, across two render pass instances,
82 	//with the second RESUMING the first, both recorded to the same primary command buffer.
83 	TEST_TYPE_SECONDARY_CMDBUF_RESUMING,
84 	// Draw two triangles in two secondary command buffers, across two render pass instances,
85 	// with the second RESUMING the first, executed in the two primary command buffers.
86 	TEST_TYPE_SECONDARY_CMDBUF_TWO_PRIMARY_RESUMING,
87 	// Using CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw two triangles in one secondary command buffer,
88 	// and execute it inside a single render pass instance in one primary command buffer.
89 	TEST_TYPE_CONTENTS_SECONDARY_COMMAND_BUFFER,
90 	// Using CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw two triangles in two secondary command buffers,
91 	// and execute them inside a single render pass instance in one primary command buffer.
92 	TEST_TYPE_CONTENTS_2_SECONDARY_COMMAND_BUFFER,
93 	// Using CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw two triangles in two secondary command buffers,
94 	// and execute them inside two render pass instances, with the second RESUMING the first, both recorded in the same primary command buffer.
95 	TEST_TYPE_CONTENTS_2_SECONDARY_COMMAND_BUFFER_RESUMING,
96 	// Using CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw two triangles in two secondary command buffers,
97 	// and execute them inside two render pass instances, with the second RESUMING the first, recorded into two primary command buffers.
98 	TEST_TYPE_CONTENTS_2_SECONDARY_2_PRIMARY_COMDBUF_RESUMING,
99 	// In one primary command buffer, record two render pass instances, with the second resuming the first.In the first,
100 	// draw one triangle directly in the primary command buffer.For the second, use CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR,
101 	// draw the second triangle in a secondary command buffer, and execute it in that second render pass instance.
102 	TEST_TYPE_CONTENTS_PRIMARY_SECONDARY_COMDBUF_RESUMING,
103 	// In one primary command buffer, record two render pass instances, with the second resuming the first.In the first,
104 	// use CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw the first triangle in a secondary command buffer,
105 	// and execute it in that first render pass instance.In the second, draw one triangle directly in the primary command buffer.
106 	TEST_TYPE_CONTENTS_SECONDARY_PRIMARY_COMDBUF_RESUMING,
107 	// In two primary command buffers, record two render pass instances(one in each), with the second resuming the first.In the first,
108 	// draw one triangle directly in the primary command buffer.For the second, use CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR,
109 	// draw the second triangle in a secondary command buffer, and execute it in that second render pass instance.
110 	TEST_TYPE_CONTENTS_2_PRIMARY_SECONDARY_COMDBUF_RESUMING,
111 	// In two primary command buffers, record two render pass instances(one in each), with the second resuming the first.In the first,
112 	// use CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw the first triangle in a secondary command buffer, and execute it in that first
113 	// render pass instance.In the second, draw one triangle directly in the primary command buffer.
114 	TEST_TYPE_CONTENTS_SECONDARY_2_PRIMARY_COMDBUF_RESUMING,
115 	TEST_TYPE_LAST
116 };
117 
118 enum TestAttachmentType
119 {
120 	TEST_ATTACHMENT_SINGLE_COLOR = 0,
121 	TEST_ATTACHMENT_DEPTH_ATTACHMENT,
122 	TEST_ATTACHMENT_STENCIL_ATTACHMENT,
123 	TEST_ATTACHMENT_MULTIPLE_COLOR,
124 	TEST_ATTACHMENT_ALL,
125 	TEST_ATTACHMENT_LAST
126 };
127 
128 enum TestAttachmentStoreOp
129 {
130 	TEST_ATTACHMENT_STORE_OP_STORE     = VK_ATTACHMENT_STORE_OP_STORE,
131 	TEST_ATTACHMENT_STORE_OP_DONT_CARE =VK_ATTACHMENT_STORE_OP_DONT_CARE,
132 	TEST_ATTACHMENT_STORE_OP_LAST
133 };
134 
135 struct TestParameters
136 {
137 	TestType		testType;
138 	const Vec4		clearColor;
139 	const VkFormat	imageFormat;
140 	const UVec2		renderSize;
141 };
142 
143 struct ImagesLayout
144 {
145 	VkImageLayout	oldColors[COLOR_ATTACHMENTS_NUMBER];
146 	VkImageLayout	oldStencil;
147 	VkImageLayout	oldDepth;
148 };
149 
150 struct ImagesFormat
151 {
152 	VkFormat	colors[COLOR_ATTACHMENTS_NUMBER];
153 	VkFormat	depth;
154 	VkFormat	stencil;
155 };
156 
157 struct ClearAttachmentData
158 {
159 	std::vector<VkClearAttachment>	colorDepthClear1;
160 	std::vector<VkClearAttachment>	colorDepthClear2;
161 	VkClearAttachment				stencilClear1;
162 	VkClearAttachment				stencilClear2;
163 	VkClearRect						rectColorDepth1;
164 	VkClearRect						rectColorDepth2;
165 	VkClearRect						rectStencil1;
166 	VkClearRect						rectStencil2;
167 
ClearAttachmentDatavkt::renderpass::__anon5aa28def0111::ClearAttachmentData168 	ClearAttachmentData	(const deUint32	colorAtchCount,
169 						const VkFormat	depth,
170 						const VkFormat	stencil)
171 	{
172 		if (colorAtchCount != 0)
173 		{
174 			for (deUint32 atchNdx = 0; atchNdx < colorAtchCount; ++atchNdx)
175 			{
176 				const VkClearAttachment green =
177 				{
178 					VK_IMAGE_ASPECT_COLOR_BIT,
179 					atchNdx,
180 					makeClearValueColorF32(0.0f, 1.0f, static_cast<float>(atchNdx) * 0.15f, 1.0f)
181 				};
182 				colorDepthClear1.push_back(green);
183 
184 				const VkClearAttachment yellow =
185 				{
186 					VK_IMAGE_ASPECT_COLOR_BIT,
187 					atchNdx,
188 					makeClearValueColorF32(1.0f, 1.0f, static_cast<float>(atchNdx) * 0.15f, 1.0f)
189 				};
190 				colorDepthClear2.push_back(yellow);
191 			}
192 		}
193 
194 		if (depth != VK_FORMAT_UNDEFINED)
195 		{
196 			const VkClearAttachment zero =
197 			{
198 				VK_IMAGE_ASPECT_DEPTH_BIT,
199 				0,
200 				makeClearValueDepthStencil(0.0f, 0)
201 			};
202 			colorDepthClear1.push_back(zero);
203 
204 			const VkClearAttachment one =
205 			{
206 				VK_IMAGE_ASPECT_DEPTH_BIT,
207 				0,
208 				makeClearValueDepthStencil(0.2f, 0)
209 			};
210 			colorDepthClear2.push_back(one);
211 		}
212 
213 		if (stencil != VK_FORMAT_UNDEFINED)
214 		{
215 			stencilClear1 =
216 			{
217 				VK_IMAGE_ASPECT_STENCIL_BIT,
218 				0,
219 				makeClearValueDepthStencil(0.0f, 1)
220 			};
221 
222 			stencilClear2 =
223 			{
224 				VK_IMAGE_ASPECT_STENCIL_BIT,
225 				0,
226 				makeClearValueDepthStencil(0.0f, 2)
227 			};
228 
229 			rectStencil1 =
230 			{
231 				makeRect2D(0, 0, 32, 16),
232 				0u,
233 				1u,
234 			};
235 
236 			rectStencil2 =
237 			{
238 				makeRect2D(0, 16, 32, 16),
239 				0u,
240 				1u,
241 			};
242 		}
243 
244 		rectColorDepth1 =
245 		{
246 			makeRect2D(0, 0, 16, 32),
247 			0u,
248 			1u,
249 		};
250 
251 		rectColorDepth2 =
252 		{
253 			makeRect2D(16, 0, 16, 32),
254 			0u,
255 			1u,
256 		};
257 	}
258 };
259 
260 template<typename T>
sizeInBytes(const std::vector<T> & vec)261 inline VkDeviceSize sizeInBytes (const std::vector<T>& vec)
262 {
263 	return vec.size() * sizeof(vec[0]);
264 }
265 
makeImageCreateInfo(const VkFormat format,const UVec2 & size,VkImageUsageFlags usage)266 VkImageCreateInfo makeImageCreateInfo (const VkFormat		format,
267 									   const UVec2&			size,
268 									   VkImageUsageFlags	usage)
269 {
270 	const VkImageCreateInfo imageParams =
271 	{
272 		VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,	// VkStructureType			sType;
273 		DE_NULL,								// const void*				pNext;
274 		(VkImageCreateFlags)0,					// VkImageCreateFlags		flags;
275 		VK_IMAGE_TYPE_2D,						// VkImageType				imageType;
276 		format,									// VkFormat					format;
277 		makeExtent3D(size.x(), size.y(), 1),	// VkExtent3D				extent;
278 		1u,										// deUint32					mipLevels;
279 		1u,										// deUint32					arrayLayers;
280 		VK_SAMPLE_COUNT_1_BIT,					// VkSampleCountFlagBits	samples;
281 		VK_IMAGE_TILING_OPTIMAL,				// VkImageTiling			tiling;
282 		usage,									// VkImageUsageFlags		usage;
283 		VK_SHARING_MODE_EXCLUSIVE,				// VkSharingMode			sharingMode;
284 		0u,										// deUint32					queueFamilyIndexCount;
285 		DE_NULL,								// const deUint32*			pQueueFamilyIndices;
286 		VK_IMAGE_LAYOUT_UNDEFINED,				// VkImageLayout			initialLayout;
287 	};
288 	return imageParams;
289 }
290 
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule vertexModule,const VkShaderModule fragmentModule,const UVec2 renderSize,const deUint32 colorAttachmentCount,const VkFormat * pColorAttachmentFormats,const VkFormat depthStencilAttachmentFormat)291 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface&	vk,
292 									   const VkDevice			device,
293 									   const VkPipelineLayout	pipelineLayout,
294 									   const VkShaderModule		vertexModule,
295 									   const VkShaderModule		fragmentModule,
296 									   const UVec2				renderSize,
297 									   const deUint32			colorAttachmentCount,
298 									   const VkFormat*			pColorAttachmentFormats,
299 									   const VkFormat			depthStencilAttachmentFormat)
300 {
301 	const VkVertexInputBindingDescription vertexInputBindingDescription =
302 	{
303 		0u,								// uint32_t				binding;
304 		sizeof(Vec4),					// uint32_t				stride;
305 		VK_VERTEX_INPUT_RATE_VERTEX,	// VkVertexInputRate	inputRate;
306 	};
307 
308 	const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
309 	{
310 		{
311 			0u,								// uint32_t			location;
312 			0u,								// uint32_t			binding;
313 			VK_FORMAT_R32G32B32A32_SFLOAT,	// VkFormat			format;
314 			0u,								// uint32_t			offset;
315 		},
316 	};
317 
318 	const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo =
319 	{
320 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,		// VkStructureType								sType;
321 		DE_NULL,														// const void*									pNext;
322 		(VkPipelineVertexInputStateCreateFlags)0,						// VkPipelineVertexInputStateCreateFlags		flags;
323 		1u,																// uint32_t										vertexBindingDescriptionCount;
324 		&vertexInputBindingDescription,									// const VkVertexInputBindingDescription*		pVertexBindingDescriptions;
325 		DE_LENGTH_OF_ARRAY(vertexInputAttributeDescriptions),			// uint32_t										vertexAttributeDescriptionCount;
326 		vertexInputAttributeDescriptions,								// const VkVertexInputAttributeDescription*		pVertexAttributeDescriptions;
327 	};
328 
329 	const VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateInfo =
330 	{
331 		VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,	// VkStructureType								sType;
332 		DE_NULL,														// const void*									pNext;
333 		(VkPipelineInputAssemblyStateCreateFlags)0,						// VkPipelineInputAssemblyStateCreateFlags		flags;
334 		VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,							// VkPrimitiveTopology							topology;
335 		VK_FALSE,														// VkBool32										primitiveRestartEnable;
336 	};
337 
338 	VkViewport		viewport = makeViewport(0.0f, 0.0f, static_cast<float>(renderSize.x()), static_cast<float>(renderSize.y()), 0.0f, 1.0f);
339 	const VkRect2D	rectScissorRenderSize = { { 0, 0 }, { renderSize.x(), renderSize.y() } };
340 
341 	const VkPipelineViewportStateCreateInfo pipelineViewportStateInfo =
342 	{
343 		VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,	// VkStructureType								sType;
344 		DE_NULL,												// const void*									pNext;
345 		(VkPipelineViewportStateCreateFlags)0,					// VkPipelineViewportStateCreateFlags			flags;
346 		1u,														// uint32_t										viewportCount;
347 		&viewport,												// const VkViewport*							pViewports;
348 		1u,														// uint32_t										scissorCount;
349 		&rectScissorRenderSize,									// const VkRect2D*								pScissors;
350 	};
351 
352 	const VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateInfo =
353 	{
354 		VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,	// VkStructureType								sType;
355 		DE_NULL,													// const void*									pNext;
356 		(VkPipelineRasterizationStateCreateFlags)0,					// VkPipelineRasterizationStateCreateFlags		flags;
357 		VK_FALSE,													// VkBool32										depthClampEnable;
358 		VK_FALSE,													// VkBool32										rasterizerDiscardEnable;
359 		VK_POLYGON_MODE_FILL,										// VkPolygonMode								polygonMode;
360 		VK_CULL_MODE_NONE,											// VkCullModeFlags								cullMode;
361 		VK_FRONT_FACE_COUNTER_CLOCKWISE,							// VkFrontFace									frontFace;
362 		VK_FALSE,													// VkBool32										depthBiasEnable;
363 		0.0f,														// float										depthBiasConstantFactor;
364 		0.0f,														// float										depthBiasClamp;
365 		0.0f,														// float										depthBiasSlopeFactor;
366 		1.0f,														// float										lineWidth;
367 	};
368 
369 	const VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateInfo =
370 	{
371 		VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,	// VkStructureType								sType;
372 		DE_NULL,													// const void*									pNext;
373 		(VkPipelineMultisampleStateCreateFlags)0,					// VkPipelineMultisampleStateCreateFlags		flags;
374 		VK_SAMPLE_COUNT_1_BIT,										// VkSampleCountFlagBits						rasterizationSamples;
375 		VK_FALSE,													// VkBool32										sampleShadingEnable;
376 		0.0f,														// float										minSampleShading;
377 		DE_NULL,													// const VkSampleMask*							pSampleMask;
378 		VK_FALSE,													// VkBool32										alphaToCoverageEnable;
379 		VK_FALSE													// VkBool32										alphaToOneEnable;
380 	};
381 
382 	const VkStencilOpState stencilOp = makeStencilOpState(
383 		VK_STENCIL_OP_ZERO,					// stencil fail
384 		VK_STENCIL_OP_INCREMENT_AND_CLAMP,	// depth & stencil pass
385 		VK_STENCIL_OP_INCREMENT_AND_CLAMP,	// depth only fail
386 		VK_COMPARE_OP_NOT_EQUAL,			// compare op
387 		240u,								// compare mask
388 		255u,								// write mask
389 		255u);								// reference
390 
391 	VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateInfo =
392 	{
393 		VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,		// VkStructureType								sType;
394 		DE_NULL,														// const void*									pNext;
395 		(VkPipelineDepthStencilStateCreateFlags)0,						// VkPipelineDepthStencilStateCreateFlags		flags;
396 		VK_TRUE,														// VkBool32										depthTestEnable;
397 		VK_TRUE,														// VkBool32										depthWriteEnable;
398 		VK_COMPARE_OP_ALWAYS,											// VkCompareOp									depthCompareOp;
399 		VK_FALSE,														// VkBool32										depthBoundsTestEnable;
400 		VK_TRUE,														// VkBool32										stencilTestEnable;
401 		stencilOp,														// VkStencilOpState								front;
402 		stencilOp,														// VkStencilOpState								back;
403 		0.0f,															// float										minDepthBounds;
404 		1.0f,															// float										maxDepthBounds;
405 	};
406 
407 	const VkColorComponentFlags					colorComponentsAll = VK_COLOR_COMPONENT_R_BIT |
408 																	 VK_COLOR_COMPONENT_G_BIT |
409 																	 VK_COLOR_COMPONENT_B_BIT |
410 																	 VK_COLOR_COMPONENT_A_BIT;
411 
412 	std::vector<VkPipelineColorBlendAttachmentState>	colorBlendAttachmentState;
413 
414 	for (deUint32 ndx = 0 ; ndx < colorAttachmentCount; ++ndx)
415 	{
416 		const VkPipelineColorBlendAttachmentState	pipelineColorBlendAttachmentState =
417 		{
418 			VK_FALSE,				// VkBool32					blendEnable;
419 			VK_BLEND_FACTOR_ONE,	// VkBlendFactor			srcColorBlendFactor;
420 			VK_BLEND_FACTOR_ZERO,	// VkBlendFactor			dstColorBlendFactor;
421 			VK_BLEND_OP_ADD,		// VkBlendOp				colorBlendOp;
422 			VK_BLEND_FACTOR_ONE,	// VkBlendFactor			srcAlphaBlendFactor;
423 			VK_BLEND_FACTOR_ZERO,	// VkBlendFactor			dstAlphaBlendFactor;
424 			VK_BLEND_OP_ADD,		// VkBlendOp				alphaBlendOp;
425 			colorComponentsAll,		// VkColorComponentFlags	colorWriteMask;
426 		};
427 
428 		colorBlendAttachmentState.push_back(pipelineColorBlendAttachmentState);
429 	}
430 
431 	const VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateInfo =
432 	{
433 		VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,	// VkStructureType								sType;
434 		DE_NULL,													// const void*									pNext;
435 		(VkPipelineColorBlendStateCreateFlags)0,					// VkPipelineColorBlendStateCreateFlags			flags;
436 		VK_FALSE,													// VkBool32										logicOpEnable;
437 		VK_LOGIC_OP_COPY,											// VkLogicOp									logicOp;
438 		colorAttachmentCount,										// deUint32										attachmentCount;
439 		colorBlendAttachmentState.data(),							// const VkPipelineColorBlendAttachmentState*	pAttachments;
440 		{ 0.0f, 0.0f, 0.0f, 0.0f },									// float										blendConstants[4];
441 	};
442 
443 	const VkPipelineShaderStageCreateInfo pShaderStages[] =
444 	{
445 		{
446 			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType								sType;
447 			DE_NULL,												// const void*									pNext;
448 			(VkPipelineShaderStageCreateFlags)0,					// VkPipelineShaderStageCreateFlags				flags;
449 			VK_SHADER_STAGE_VERTEX_BIT,								// VkShaderStageFlagBits						stage;
450 			vertexModule,											// VkShaderModule								module;
451 			"main",													// const char*									pName;
452 			DE_NULL,												// const VkSpecializationInfo*					pSpecializationInfo;
453 		},
454 		{
455 			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType								sType;
456 			DE_NULL,												// const void*									pNext;
457 			(VkPipelineShaderStageCreateFlags)0,					// VkPipelineShaderStageCreateFlags				flags;
458 			VK_SHADER_STAGE_FRAGMENT_BIT,							// VkShaderStageFlagBits						stage;
459 			fragmentModule,											// VkShaderModule								module;
460 			"main",													// const char*									pName;
461 			DE_NULL,												// const VkSpecializationInfo*					pSpecializationInfo;
462 		},
463 	};
464 
465 	const VkPipelineRenderingCreateInfoKHR renderingCreateInfo
466 	{
467 		VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR,			// VkStructureType	sType;
468 		DE_NULL,														// const void*		pNext;
469 		0u,																// deUint32			viewMask;
470 		colorAttachmentCount,											// deUint32			colorAttachmentCount;
471 		pColorAttachmentFormats,										// const VkFormat*	pColorAttachmentFormats;
472 		depthStencilAttachmentFormat,									// VkFormat			depthAttachmentFormat;
473 		depthStencilAttachmentFormat,									// VkFormat			stencilAttachmentFormat;
474 	};
475 
476 	const VkGraphicsPipelineCreateInfo graphicsPipelineInfo =
477 	{
478 		VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,	// VkStructureType									sType;
479 		&renderingCreateInfo,								// const void*										pNext;
480 		(VkPipelineCreateFlags)0,							// VkPipelineCreateFlags							flags;
481 		2u,													// deUint32											stageCount;
482 		pShaderStages,										// const VkPipelineShaderStageCreateInfo*			pStages;
483 		&vertexInputStateInfo,								// const VkPipelineVertexInputStateCreateInfo*		pVertexInputState;
484 		&pipelineInputAssemblyStateInfo,					// const VkPipelineInputAssemblyStateCreateInfo*	pInputAssemblyState;
485 		DE_NULL,											// const VkPipelineTessellationStateCreateInfo*		pTessellationState;
486 		&pipelineViewportStateInfo,							// const VkPipelineViewportStateCreateInfo*			pViewportState;
487 		&pipelineRasterizationStateInfo,					// const VkPipelineRasterizationStateCreateInfo*	pRasterizationState;
488 		&pipelineMultisampleStateInfo,						// const VkPipelineMultisampleStateCreateInfo*		pMultisampleState;
489 		&pipelineDepthStencilStateInfo,						// const VkPipelineDepthStencilStateCreateInfo*		pDepthStencilState;
490 		&pipelineColorBlendStateInfo,						// const VkPipelineColorBlendStateCreateInfo*		pColorBlendState;
491 		DE_NULL,											// const VkPipelineDynamicStateCreateInfo*			pDynamicState;
492 		pipelineLayout,										// VkPipelineLayout									layout;
493 		VK_NULL_HANDLE,										// VkRenderPass										renderPass;
494 		0u,													// deUint32											subpass;
495 		DE_NULL,											// VkPipeline										basePipelineHandle;
496 		0,													// deInt32											basePipelineIndex;
497 	};
498 
499 	return createGraphicsPipeline(vk, device, DE_NULL, &graphicsPipelineInfo);
500 }
501 
getSupportedStencilFormat(const InstanceInterface & vki,VkPhysicalDevice physDev)502 VkFormat getSupportedStencilFormat (const InstanceInterface&	vki,
503 									VkPhysicalDevice			physDev)
504 {
505 	const VkFormat				formatList[] = { VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT };
506 	const VkFormatFeatureFlags	requirements = (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT |
507 												VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
508 
509 	for (int i = 0; i < DE_LENGTH_OF_ARRAY(formatList); ++i)
510 	{
511 		const auto properties = getPhysicalDeviceFormatProperties(vki, physDev, formatList[i]);
512 		if ((properties.optimalTilingFeatures & requirements) == requirements)
513 			return formatList[i];
514 	}
515 
516 	return VK_FORMAT_UNDEFINED;
517 }
518 
getDepthTextureFormat(const VkFormat depthStencilFormat)519 tcu::TextureFormat getDepthTextureFormat (const VkFormat	depthStencilFormat)
520 {
521 	return	((depthStencilFormat == VK_FORMAT_D24_UNORM_S8_UINT) ?
522 			tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNSIGNED_INT_24_8_REV) :
523 			tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT));
524 }
525 
generateColroImage(const tcu::TextureFormat format,const UVec2 & renderSize,const int attachmentNdx)526 tcu::TextureLevel generateColroImage (const tcu::TextureFormat	format,
527 									  const UVec2&				renderSize,
528 									  const int					attachmentNdx)
529 {
530 	tcu::TextureLevel	image		(format, renderSize.x(), renderSize.y());
531 	const float			atchNdx		= static_cast<float>(attachmentNdx);
532 	const Vec4			greenColor	= Vec4(0.0f, 1.0f, atchNdx * 0.15f, 1.0f);
533 	const Vec4			yellowColor	= Vec4(1.0f, 1.0f, atchNdx * 0.15f, 1.0f);
534 
535 	for (deUint32 y = 0; y < renderSize.y(); ++y)
536 	{
537 		for (deUint32 x = 0; x < renderSize.x() / 2u; ++x)
538 		{
539 			image.getAccess().setPixel(greenColor, x, y);
540 		}
541 		for (deUint32 x = renderSize.x() / 2u; x < renderSize.x(); ++x)
542 		{
543 			image.getAccess().setPixel(yellowColor, x, y);
544 		}
545 	}
546 
547 	return image;
548 }
549 
generateDepthImage(const tcu::TextureFormat format,const UVec2 & renderSize)550 tcu::TextureLevel generateDepthImage (const tcu::TextureFormat	format,
551 									  const UVec2&				renderSize)
552 {
553 	tcu::TextureLevel	image	(format, renderSize.x(), renderSize.y());
554 	const float			value1	= 0.0f;
555 	const float			value2	= 0.2f;
556 
557 	for (deUint32 y = 0; y < renderSize.y(); ++y)
558 	{
559 		for (deUint32 x = 0; x < renderSize.x() / 2u; ++x)
560 		{
561 			image.getAccess().setPixDepth(value1, x, y);
562 		}
563 		for (deUint32 x = renderSize.x() / 2u; x < renderSize.x(); ++x)
564 		{
565 			image.getAccess().setPixDepth(value2, x, y);
566 		}
567 	}
568 
569 	return image;
570 }
571 
generateStencilImage(const tcu::TextureFormat format,const UVec2 & renderSize)572 tcu::TextureLevel generateStencilImage (const tcu::TextureFormat	format,
573 										const UVec2&				renderSize)
574 {
575 	tcu::TextureLevel	image	(format, renderSize.x(), renderSize.y());
576 	const IVec4			value1	= IVec4(1,0,0,0);
577 	const IVec4			value2	= IVec4(2,0,0,0);
578 
579 	for (deUint32 x = 0; x < renderSize.x(); ++x)
580 	{
581 		for (deUint32 y = 0; y < renderSize.y() / 2u; ++y)
582 		{
583 			image.getAccess().setPixel(value1, x, y);
584 		}
585 		for (deUint32 y = renderSize.y() / 2u; y < renderSize.y(); ++y)
586 		{
587 			image.getAccess().setPixel(value2, x, y);
588 		}
589 	}
590 
591 	return image;
592 }
593 
submitCommandsAndWait(const DeviceInterface & vk,const VkDevice device,const VkQueue queue,const VkCommandBuffer commandBuffer,const VkCommandBuffer commandBuffer2)594 void submitCommandsAndWait (const DeviceInterface&	vk,
595 							const VkDevice			device,
596 							const VkQueue			queue,
597 							const VkCommandBuffer	commandBuffer,
598 							const VkCommandBuffer	commandBuffer2)
599 {
600 	const Unique<VkFence>	fence(createFence(vk, device));
601 	const VkCommandBuffer	cmdBuffers[2] = { commandBuffer, commandBuffer2 };
602 
603 	const VkSubmitInfo		submitInfo =
604 	{
605 		VK_STRUCTURE_TYPE_SUBMIT_INFO,	// VkStructureType				sType;
606 		DE_NULL,						// const void*					pNext;
607 		0u,								// deUint32						waitSemaphoreCount;
608 		DE_NULL,						// const VkSemaphore*			pWaitSemaphores;
609 		DE_NULL,						// const VkPipelineStageFlags*	pWaitDstStageMask;
610 		2u,								// deUint32						commandBufferCount;
611 		cmdBuffers,						// const VkCommandBuffer*		pCommandBuffers;
612 		0u,								// deUint32						signalSemaphoreCount;
613 		nullptr,						// const VkSemaphore*			pSignalSemaphores;
614 	};
615 
616 	VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
617 	VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
618 }
619 
beginSecondaryCmdBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,VkRenderingFlagsKHR renderingFlags,const deUint32 colorAttachmentCount,const ImagesFormat & imagesFormat)620 void beginSecondaryCmdBuffer (const DeviceInterface&	vk,
621 							  const VkCommandBuffer		commandBuffer,
622 							  VkRenderingFlagsKHR		renderingFlags,
623 							  const deUint32			colorAttachmentCount,
624 							  const ImagesFormat&		imagesFormat)
625 {
626 	const VkFormat depthStencilFormat = (imagesFormat.depth != VK_FORMAT_UNDEFINED) ?
627 		imagesFormat.depth : imagesFormat.stencil;
628 	const VkCommandBufferInheritanceRenderingInfoKHR inheritanceRenderingInfo
629 	{
630 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_RENDERING_INFO_KHR,	// VkStructureType			sType;
631 		DE_NULL,															// const void*				pNext;
632 		renderingFlags,														// VkRenderingFlagsKHR		flags;
633 		0u,																	// uint32_t					viewMask;
634 		colorAttachmentCount,												// uint32_t					colorAttachmentCount;
635 		(colorAttachmentCount > 0) ? imagesFormat.colors : DE_NULL,			// const VkFormat*			pColorAttachmentFormats;
636 		depthStencilFormat,													// VkFormat					depthAttachmentFormat;
637 		depthStencilFormat,													// VkFormat					stencilAttachmentFormat;
638 		VK_SAMPLE_COUNT_1_BIT,												// VkSampleCountFlagBits	rasterizationSamples;
639 	};
640 
641 	const VkCommandBufferInheritanceInfo	bufferInheritanceInfo =
642 	{
643 		vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,	// VkStructureType					sType;
644 		&inheritanceRenderingInfo,								// const void*						pNext;
645 		VK_NULL_HANDLE,											// VkRenderPass						renderPass;
646 		0u,														// deUint32							subpass;
647 		VK_NULL_HANDLE,											// VkFramebuffer					framebuffer;
648 		VK_FALSE,												// VkBool32							occlusionQueryEnable;
649 		(vk::VkQueryControlFlags)0u,							// VkQueryControlFlags				queryFlags;
650 		(vk::VkQueryPipelineStatisticFlags)0u					// VkQueryPipelineStatisticFlags	pipelineStatistics;
651 	};
652 
653 	const VkCommandBufferBeginInfo commandBufBeginParams =
654 	{
655 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,		// VkStructureType				sType;
656 		DE_NULL,											// const void*					pNext;
657 		VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
658 		VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT,	// VkCommandBufferUsageFlags	flags;
659 		&bufferInheritanceInfo
660 	};
661 	VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
662 }
663 
beginSecondaryCmdBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer)664 void beginSecondaryCmdBuffer(const DeviceInterface&	vk,
665 							const VkCommandBuffer	commandBuffer)
666 {
667 	const VkCommandBufferInheritanceInfo	bufferInheritanceInfo =
668 	{
669 		vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,	// VkStructureType					sType;
670 		DE_NULL,												// const void*						pNext;
671 		VK_NULL_HANDLE,											// VkRenderPass						renderPass;
672 		0u,														// deUint32							subpass;
673 		VK_NULL_HANDLE,											// VkFramebuffer					framebuffer;
674 		VK_FALSE,												// VkBool32							occlusionQueryEnable;
675 		(vk::VkQueryControlFlags)0u,							// VkQueryControlFlags				queryFlags;
676 		(vk::VkQueryPipelineStatisticFlags)0u					// VkQueryPipelineStatisticFlags	pipelineStatistics;
677 	};
678 
679 	const VkCommandBufferBeginInfo commandBufBeginParams =
680 	{
681 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,		// VkStructureType				sType;
682 		DE_NULL,											// const void*					pNext;
683 		VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,		// VkCommandBufferUsageFlags	flags;
684 		&bufferInheritanceInfo
685 	};
686 	VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
687 }
688 
689 class DynamicRenderingTestInstance : public TestInstance
690 {
691 public:
692 									DynamicRenderingTestInstance	(Context&							context,
693 																	 const TestParameters&				parameters);
694 protected:
695 	virtual tcu::TestStatus			iterate							(void);
696 	void							initialize						(void);
697 	void							createCmdBuffer					(void);
698 	virtual void					rendering						(const VkPipeline					pipeline,
699 																	 const std::vector<VkImageView>&	attachmentBindInfos,
700 																	 const deUint32						colorAtchCount,
701 																	 ImagesLayout&						imagesLayout,
702 																	 const ImagesFormat&				imagesFormat);
703 	void							preBarier						(const deUint32						colorAtchCount,
704 																	 ImagesLayout&						imagesLayout,
705 																	 const ImagesFormat&				imagesFormat);
706 	void							beginRenderingKHR				(VkCommandBuffer					cmdBuffer,
707 																	 const std::vector<VkImageView>&	attachmentBindInfos,
708 																	 const VkRenderingFlagsKHR			flags,
709 																	 const deUint32						colorAtchCount,
710 																	 const ImagesFormat&				imagesFormat,
711 																	 const VkAttachmentLoadOp			loadOp,
712 																	 const VkAttachmentStoreOp			storeOp);
713 	void							copyImgToBuff					(VkCommandBuffer					commandBuffer,
714 																	const deUint32						colorAtchCount,
715 																	 ImagesLayout&						imagesLayout,
716 																	 const ImagesFormat&				imagesFormat);
717 	void							verifyResults					(const deUint32						colorAtchCount,
718 																	 const ImagesFormat&				imagesFormat);
719 
720 	const TestParameters			m_parameters;
721 	VkFormat						m_formatStencilDepthImage;
722 	Move<VkImage>					m_imageColor[COLOR_ATTACHMENTS_NUMBER];
723 	Move<VkImage>					m_imageStencilDepth;
724 	Move<VkImageView>				m_colorAttachmentView[COLOR_ATTACHMENTS_NUMBER];
725 	Move<VkImageView>				m_stencilDepthAttachmentView;
726 	MovePtr<Allocation>				m_imageColorAlloc[COLOR_ATTACHMENTS_NUMBER];
727 	MovePtr<Allocation>				m_imageStencilDepthAlloc;
728 	SharedPtr<Buffer>				m_imageBuffer[COLOR_ATTACHMENTS_NUMBER];
729 	SharedPtr<Buffer>				m_imageDepthBuffer;
730 	SharedPtr<Buffer>				m_imageStencilBuffer;
731 
732 	Move<VkShaderModule>			m_vertexModule;
733 	Move<VkShaderModule>			m_fragmentModule;
734 	SharedPtr<Buffer>				m_vertexBuffer;
735 	Move<VkPipelineLayout>			m_pipelineLayout;
736 
737 	Move<VkCommandPool>				m_cmdPool;
738 	Move<VkCommandBuffer>			m_cmdBuffer;
739 
740 	std::vector<tcu::TextureLevel>	m_referenceImages;
741 };
742 
DynamicRenderingTestInstance(Context & context,const TestParameters & parameters)743 DynamicRenderingTestInstance::DynamicRenderingTestInstance (Context&				context,
744 															const TestParameters&	parameters)
745 	: TestInstance	(context)
746 	, m_parameters	(parameters)
747 {
748 	const VkPhysicalDeviceDynamicRenderingFeaturesKHR&		dynamicRenderingFeatures	(context.getDynamicRenderingFeatures());
749 
750 	if (dynamicRenderingFeatures.dynamicRendering == DE_FALSE)
751 		TCU_FAIL("dynamicRendering is not supported");
752 
753 	initialize();
754 	createCmdBuffer();
755 }
756 
iterate(void)757 tcu::TestStatus DynamicRenderingTestInstance::iterate (void)
758 {
759 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
760 	const VkDevice			device	= m_context.getDevice();
761 
762 	ImagesLayout imagesLayout
763 	{
764 		{
765 			VK_IMAGE_LAYOUT_UNDEFINED,
766 			VK_IMAGE_LAYOUT_UNDEFINED,
767 			VK_IMAGE_LAYOUT_UNDEFINED,
768 			VK_IMAGE_LAYOUT_UNDEFINED
769 		},								// oldColors
770 		VK_IMAGE_LAYOUT_UNDEFINED,		// oldLStencil
771 		VK_IMAGE_LAYOUT_UNDEFINED,		// oldDepth
772 	};
773 
774 	for (int attachmentTest = 0; attachmentTest < TEST_ATTACHMENT_LAST; ++attachmentTest)
775 	{
776 		std::vector<VkImageView>	attachmentBindInfos;
777 
778 		ImagesFormat imagesFormat
779 		{
780 			{
781 				m_parameters.imageFormat,
782 				m_parameters.imageFormat,
783 				m_parameters.imageFormat,
784 				m_parameters.imageFormat,
785 			},								// colors
786 			m_formatStencilDepthImage,		// depth
787 			m_formatStencilDepthImage,		// stencil
788 		};
789 
790 		deUint32	colorAtchCount		= 0u;
791 
792 		switch(attachmentTest)
793 		{
794 			case TEST_ATTACHMENT_SINGLE_COLOR:
795 			{
796 				attachmentBindInfos.push_back(*m_colorAttachmentView[0]);
797 				imagesFormat.depth		= VK_FORMAT_UNDEFINED;
798 				imagesFormat.stencil	= VK_FORMAT_UNDEFINED;
799 				colorAtchCount			= 1u;
800 				break;
801 			}
802 			case TEST_ATTACHMENT_DEPTH_ATTACHMENT:
803 			{
804 				attachmentBindInfos.push_back(*m_stencilDepthAttachmentView);
805 				imagesFormat.colors[0]	= VK_FORMAT_UNDEFINED;
806 				imagesFormat.stencil	= VK_FORMAT_UNDEFINED;
807 				break;
808 			}
809 			case TEST_ATTACHMENT_STENCIL_ATTACHMENT:
810 			{
811 				attachmentBindInfos.push_back(*m_stencilDepthAttachmentView);
812 				imagesFormat.colors[0]	= VK_FORMAT_UNDEFINED;
813 				imagesFormat.depth		= VK_FORMAT_UNDEFINED;
814 				break;
815 			}
816 			case TEST_ATTACHMENT_MULTIPLE_COLOR:
817 			{
818 				for(deUint32 ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ndx++)
819 					attachmentBindInfos.push_back(*m_colorAttachmentView[ndx]);
820 
821 				colorAtchCount			= COLOR_ATTACHMENTS_NUMBER;
822 				imagesFormat.depth		= VK_FORMAT_UNDEFINED;
823 				imagesFormat.stencil	= VK_FORMAT_UNDEFINED;
824 				break;
825 			}
826 			case TEST_ATTACHMENT_ALL:
827 			{
828 				for (deUint32 ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ndx++)
829 					attachmentBindInfos.push_back(*m_colorAttachmentView[ndx]);
830 
831 				attachmentBindInfos.push_back(*m_stencilDepthAttachmentView);
832 				attachmentBindInfos.push_back(*m_stencilDepthAttachmentView);
833 
834 				colorAtchCount = COLOR_ATTACHMENTS_NUMBER;
835 				break;
836 			}
837 			default:
838 				DE_FATAL("Impossible");
839 		};
840 		Move<VkPipeline>	pipeline	= makeGraphicsPipeline(vk, device, *m_pipelineLayout,
841 															  *m_vertexModule, *m_fragmentModule,
842 															   m_parameters.renderSize, colorAtchCount, imagesFormat.colors,
843 															   ((imagesFormat.depth == VK_FORMAT_UNDEFINED) ? imagesFormat.stencil : imagesFormat.depth));
844 
845 		rendering(*pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat);
846 	}
847 	return tcu::TestStatus::pass("Pass");
848 }
849 
initialize(void)850 void DynamicRenderingTestInstance::initialize (void)
851 {
852 	const InstanceInterface&	vki			= m_context.getInstanceInterface();
853 	const DeviceInterface&		vk			= m_context.getDeviceInterface();
854 	const VkPhysicalDevice		physDevice	= m_context.getPhysicalDevice();
855 	const VkDevice				device		= m_context.getDevice();
856 	Allocator&					allocator	= m_context.getDefaultAllocator();
857 
858 	// Vertices.
859 	{
860 		std::vector<Vec4>	vertices;
861 
862 		// Draw a quad covering the whole renderarea
863 		vertices.push_back(Vec4(-1.0f,  1.0f, 0.0f, 1.0f));
864 		vertices.push_back(Vec4(-1.0f, -1.0f, 0.0f, 1.0f));
865 		vertices.push_back(Vec4( 0.0f,  1.0f, 0.0f, 1.0f));
866 		vertices.push_back(Vec4( 0.0f, -1.0f, 0.0f, 1.0f));
867 
868 		vertices.push_back(Vec4(1.0f, -1.0f, 0.2f, 1.0f));
869 		vertices.push_back(Vec4(0.0f, -1.0f, 0.2f, 1.0f));
870 		vertices.push_back(Vec4(1.0f,  1.0f, 0.2f, 1.0f));
871 		vertices.push_back(Vec4(0.0f,  1.0f, 0.2f, 1.0f));
872 
873 		vertices.push_back(Vec4(-1.0f, 1.0f, 0.0f, 1.0f));
874 		vertices.push_back(Vec4(-1.0f, 0.0f, 0.0f, 1.0f));
875 		vertices.push_back(Vec4( 1.0f, 1.0f, 0.0f, 1.0f));
876 		vertices.push_back(Vec4( 1.0f, 0.0f, 0.0f, 1.0f));
877 
878 		const VkDeviceSize			bufferSize	= sizeInBytes(vertices);
879 		const VkBufferCreateInfo	bufferInfo	= makeBufferCreateInfo(bufferSize,
880 																	   VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
881 
882 		m_vertexBuffer	= Buffer::createAndAlloc(vk, device,
883 												 bufferInfo,
884 												 allocator,
885 												 MemoryRequirement::HostVisible);
886 		deMemcpy(m_vertexBuffer->getBoundMemory().getHostPtr(), vertices.data(), static_cast<std::size_t>(bufferSize));
887 		flushAlloc(vk, device, m_vertexBuffer->getBoundMemory());
888 	}
889 
890 	// Images color attachment.
891 	{
892 		const VkImageUsageFlags			imageUsage			= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
893 															  VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
894 		const VkDeviceSize				imageBufferSize		= m_parameters.renderSize.x() *
895 															  m_parameters.renderSize.y() *
896 															  tcu::getPixelSize(mapVkFormat(m_parameters.imageFormat));
897 		const VkImageSubresourceRange	imageSubresource	= makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
898 		const VkImageCreateInfo			imageInfo			= makeImageCreateInfo(m_parameters.imageFormat,
899 																				  m_parameters.renderSize, imageUsage);
900 		const VkBufferCreateInfo		bufferInfo			= makeBufferCreateInfo(imageBufferSize,
901 																				   VK_BUFFER_USAGE_TRANSFER_DST_BIT);
902 
903 		for(deUint32 ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ++ndx)
904 		{
905 			m_imageColor[ndx]			= makeImage(vk, device, imageInfo);
906 			m_imageColorAlloc[ndx]		= bindImage(vk, device, allocator, *m_imageColor[ndx], MemoryRequirement::Any);
907 			m_imageBuffer[ndx]			= Buffer::createAndAlloc(vk, device, bufferInfo,
908 																 allocator, MemoryRequirement::HostVisible);
909 			m_colorAttachmentView[ndx]	= makeImageView(vk, device, *m_imageColor[ndx],
910 														VK_IMAGE_VIEW_TYPE_2D, m_parameters.imageFormat, imageSubresource);
911 
912 			const Allocation alloc = m_imageBuffer[ndx]->getBoundMemory();
913 			deMemset(alloc.getHostPtr(), 0, static_cast<std::size_t>(imageBufferSize));
914 			flushAlloc(vk, device, alloc);
915 		}
916 	}
917 
918 	//Image stencil and depth attachment.
919 	{
920 		m_formatStencilDepthImage = getSupportedStencilFormat(vki, physDevice);
921 
922 		const VkImageAspectFlags		imageDepthStencilAspec	= VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
923 		const VkImageSubresourceRange	imageStencilSubresource	= makeImageSubresourceRange(imageDepthStencilAspec, 0u, 1u, 0u, 1u);
924 		const VkDeviceSize				imageBufferStencilSize	= m_parameters.renderSize.x() *
925 																  m_parameters.renderSize.y() *
926 																  tcu::getPixelSize(mapVkFormat(VK_FORMAT_S8_UINT));
927 		const VkDeviceSize				imageBufferDepthlSize	= m_parameters.renderSize.x() *
928 																  m_parameters.renderSize.y() *
929 																  tcu::getPixelSize(getDepthTextureFormat(m_formatStencilDepthImage));
930 
931 		const VkImageUsageFlags			imageStenciDepthlUsage	= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
932 																  VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
933 		const VkImageCreateInfo			imageInfo				= makeImageCreateInfo(m_formatStencilDepthImage,
934 																					  m_parameters.renderSize, imageStenciDepthlUsage);
935 		const VkBufferCreateInfo		bufferStencilInfo		= makeBufferCreateInfo(imageBufferStencilSize,
936 																					   VK_BUFFER_USAGE_TRANSFER_DST_BIT);
937 		const VkBufferCreateInfo		bufferDepthlInfo		= makeBufferCreateInfo(imageBufferDepthlSize,
938 																					   VK_BUFFER_USAGE_TRANSFER_DST_BIT);
939 
940 		m_imageStencilDepth				= makeImage(vk, device, imageInfo);
941 		m_imageStencilDepthAlloc		= bindImage(vk, device, allocator, *m_imageStencilDepth, MemoryRequirement::Any);
942 
943 		m_imageStencilBuffer			= Buffer::createAndAlloc(vk, device, bufferStencilInfo,
944 																 allocator, MemoryRequirement::HostVisible);
945 		m_imageDepthBuffer				= Buffer::createAndAlloc(vk, device, bufferDepthlInfo,
946 																 allocator, MemoryRequirement::HostVisible);
947 		m_stencilDepthAttachmentView	= makeImageView(vk, device, *m_imageStencilDepth,
948 														VK_IMAGE_VIEW_TYPE_2D, m_formatStencilDepthImage, imageStencilSubresource);
949 
950 		const Allocation alloc = m_imageStencilBuffer->getBoundMemory();
951 		deMemset(alloc.getHostPtr(), 0, static_cast<std::size_t>(imageBufferStencilSize));
952 		flushAlloc(vk, device, alloc);
953 
954 		const Allocation allocDepth = m_imageDepthBuffer->getBoundMemory();
955 		deMemset(allocDepth.getHostPtr(), 0, static_cast<std::size_t>(imageBufferDepthlSize));
956 		flushAlloc(vk, device, allocDepth);
957 	}
958 
959 	m_pipelineLayout		= makePipelineLayout(vk, device);
960 	m_vertexModule			= createShaderModule(vk, device, m_context.getBinaryCollection().get("vert"), 0u);
961 	m_fragmentModule		= createShaderModule(vk, device, m_context.getBinaryCollection().get("frag"), 0u);
962 
963 	for (deUint32 ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ++ndx)
964 	{
965 		m_referenceImages.push_back(generateColroImage(mapVkFormat(m_parameters.imageFormat),
966 			m_parameters.renderSize, ndx));
967 	}
968 
969 	m_referenceImages.push_back(generateDepthImage(getDepthTextureFormat(m_formatStencilDepthImage),
970 		m_parameters.renderSize));
971 
972 	m_referenceImages.push_back(generateStencilImage(mapVkFormat(VK_FORMAT_S8_UINT),
973 		m_parameters.renderSize));
974 }
975 
createCmdBuffer(void)976 void DynamicRenderingTestInstance::createCmdBuffer (void)
977 {
978 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
979 	const VkDevice			device	= m_context.getDevice();
980 
981 	m_cmdPool	= createCommandPool(vk, device,
982 									VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
983 									m_context.getUniversalQueueFamilyIndex());
984 	m_cmdBuffer	= allocateCommandBuffer(vk, device, *m_cmdPool,
985 										VK_COMMAND_BUFFER_LEVEL_PRIMARY);
986 }
987 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)988 void DynamicRenderingTestInstance::rendering (const VkPipeline					pipeline,
989 											  const std::vector<VkImageView>&	attachmentBindInfos,
990 											  const deUint32					colorAtchCount,
991 											  ImagesLayout&						imagesLayout,
992 											  const ImagesFormat&				imagesFormat)
993 {
994 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
995 	const VkDevice			device	= m_context.getDevice();
996 	const VkQueue			queue	= m_context.getUniversalQueue();
997 
998 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
999 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1000 	{
1001 
1002 		beginCommandBuffer(vk, *m_cmdBuffer);
1003 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
1004 
1005 		beginRenderingKHR(*m_cmdBuffer,
1006 						  attachmentBindInfos,
1007 						  0,
1008 						  colorAtchCount,
1009 						  imagesFormat,
1010 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1011 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1012 
1013 		vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1014 
1015 		{
1016 			const VkBuffer vertexBuffer = m_vertexBuffer->object();
1017 			const VkDeviceSize vertexBufferOffset = 0ull;
1018 			vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1019 		}
1020 
1021 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
1022 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
1023 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 4u, 0u);
1024 
1025 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
1026 
1027 		copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1028 
1029 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1030 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1031 
1032 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1033 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1034 		{
1035 			verifyResults(colorAtchCount, imagesFormat);
1036 
1037 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1038 
1039 			beginCommandBuffer(vk, *m_cmdBuffer);
1040 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
1041 
1042 			beginRenderingKHR(*m_cmdBuffer,
1043 							  attachmentBindInfos,
1044 							  0,
1045 							  colorAtchCount,
1046 							  imagesFormat,
1047 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1048 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1049 
1050 			if (clearData.colorDepthClear1.size() != 0)
1051 			{
1052 				vk.cmdClearAttachments(*m_cmdBuffer,
1053 										static_cast<deUint32>(clearData.colorDepthClear1.size()),
1054 										clearData.colorDepthClear1.data(),
1055 										1, &clearData.rectColorDepth1);
1056 			}
1057 
1058 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1059 				vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1060 
1061 			if (clearData.colorDepthClear2.size() != 0)
1062 			{
1063 				vk.cmdClearAttachments(*m_cmdBuffer,
1064 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
1065 										clearData.colorDepthClear2.data(),
1066 										1, &clearData.rectColorDepth2);
1067 			}
1068 
1069 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1070 				vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1071 
1072 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
1073 
1074 			copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1075 
1076 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1077 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1078 
1079 			verifyResults(colorAtchCount, imagesFormat);
1080 		}
1081 	}
1082 }
1083 
preBarier(const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1084 void DynamicRenderingTestInstance::preBarier (const deUint32		colorAtchCount,
1085 											  ImagesLayout&			imagesLayout,
1086 											  const ImagesFormat&	imagesFormat)
1087 {
1088 	const DeviceInterface&	vk = m_context.getDeviceInterface();
1089 
1090 	std::vector<VkImageMemoryBarrier> barriers;
1091 
1092 	for (deUint32 ndx = 0; ndx < colorAtchCount; ++ndx)
1093 	{
1094 		const VkImageSubresourceRange	subresource = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1095 		const VkImageMemoryBarrier		barrier = makeImageMemoryBarrier(VK_ACCESS_NONE_KHR,
1096 																		 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1097 																		 imagesLayout.oldColors[ndx],
1098 																		 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1099 																		 *m_imageColor[ndx],
1100 																		 subresource);
1101 		barriers.push_back(barrier);
1102 		imagesLayout.oldColors[ndx] = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1103 	}
1104 
1105 	if (imagesFormat.depth != VK_FORMAT_UNDEFINED)
1106 	{
1107 		const VkImageSubresourceRange	subresource = makeImageSubresourceRange(VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 1u, 0u, 1u);
1108 		const VkImageMemoryBarrier		barrier = makeImageMemoryBarrier(VK_ACCESS_NONE_KHR,
1109 																		 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
1110 																		 imagesLayout.oldDepth,
1111 																		 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1112 																		 *m_imageStencilDepth,
1113 																		 subresource);
1114 		imagesLayout.oldDepth = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
1115 		barriers.push_back(barrier);
1116 	}
1117 
1118 	if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1119 	{
1120 		const VkImageSubresourceRange	subresource = makeImageSubresourceRange(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 1u, 0u, 1u);
1121 		const VkImageMemoryBarrier		barrier = makeImageMemoryBarrier(VK_ACCESS_NONE_KHR,
1122 																		 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
1123 																		 imagesLayout.oldStencil,
1124 																		 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1125 																		 *m_imageStencilDepth,
1126 																		 subresource);
1127 		imagesLayout.oldStencil = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
1128 		barriers.push_back(barrier);
1129 	}
1130 
1131 	cmdPipelineImageMemoryBarrier(vk,
1132 								  *m_cmdBuffer,
1133 								  VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
1134 								  VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
1135 								  VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
1136 								  barriers.data(),
1137 								  barriers.size());
1138 }
1139 
beginRenderingKHR(VkCommandBuffer cmdBuffer,const std::vector<VkImageView> & attachmentBindInfos,const VkRenderingFlagsKHR flags,const deUint32 colorAtchCount,const ImagesFormat & imagesFormat,const VkAttachmentLoadOp loadOp,const VkAttachmentStoreOp storeOp)1140 void DynamicRenderingTestInstance::beginRenderingKHR (VkCommandBuffer					cmdBuffer,
1141 													  const std::vector<VkImageView>&	attachmentBindInfos,
1142 													  const VkRenderingFlagsKHR			flags,
1143 													  const deUint32					colorAtchCount,
1144 													  const ImagesFormat&				imagesFormat,
1145 													  const VkAttachmentLoadOp			loadOp,
1146 													  const VkAttachmentStoreOp			storeOp)
1147 {
1148 	const DeviceInterface&	vk			= m_context.getDeviceInterface();
1149 	const VkClearValue		clearValue	= makeClearValueColor(m_parameters.clearColor);
1150 	const VkRect2D			renderArea	=
1151 	{
1152 		makeOffset2D(0, 0),
1153 		makeExtent2D(m_parameters.renderSize.x(), m_parameters.renderSize.y()),
1154 	};
1155 
1156 	std::vector<VkRenderingAttachmentInfoKHR>	attachments;
1157 
1158 	for (deUint32 ndx = 0; ndx < colorAtchCount; ++ndx)
1159 	{
1160 		const VkRenderingAttachmentInfoKHR renderingAtachInfo =
1161 		{
1162 			VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR,	// VkStructureType			sType;
1163 			DE_NULL,											// const void*				pNext;
1164 			attachmentBindInfos[ndx],							// VkImageView				imageView;
1165 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,			// VkImageLayout			imageLayout;
1166 			VK_RESOLVE_MODE_NONE,								// VkResolveModeFlagBits	resolveMode;
1167 			VK_NULL_HANDLE,										// VkImageView				resolveImageView;
1168 			VK_IMAGE_LAYOUT_UNDEFINED,							// VkImageLayout			resolveImageLayout;
1169 			loadOp,												// VkAttachmentLoadOp		loadOp;
1170 			storeOp,											// VkAttachmentStoreOp		storeOp;
1171 			clearValue,											// VkClearValue				clearValue;
1172 		};
1173 
1174 		attachments.push_back(renderingAtachInfo);
1175 	}
1176 
1177 	if (imagesFormat.depth != VK_FORMAT_UNDEFINED)
1178 	{
1179 		const VkRenderingAttachmentInfoKHR renderingAtachInfo =
1180 		{
1181 			VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR,	// VkStructureType			sType;
1182 			DE_NULL,											// const void*				pNext;
1183 			attachmentBindInfos[colorAtchCount],				// VkImageView				imageView;
1184 			VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,	// VkImageLayout			imageLayout;
1185 			VK_RESOLVE_MODE_NONE,								// VkResolveModeFlagBits	resolveMode;
1186 			VK_NULL_HANDLE,										// VkImageView				resolveImageView;
1187 			VK_IMAGE_LAYOUT_UNDEFINED,							// VkImageLayout			resolveImageLayout;
1188 			loadOp,												// VkAttachmentLoadOp		loadOp;
1189 			storeOp,											// VkAttachmentStoreOp		storeOp;
1190 			clearValue,											// VkClearValue				clearValue;
1191 		};
1192 
1193 		attachments.push_back(renderingAtachInfo);
1194 	}
1195 
1196 	const deUint32 stencilNdx = colorAtchCount + ((imagesFormat.depth != VK_FORMAT_UNDEFINED) ? 1 : 0);
1197 
1198 	if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1199 	{
1200 		const VkRenderingAttachmentInfoKHR renderingAtachInfo =
1201 		{
1202 			VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR,	// VkStructureType			sType;
1203 			DE_NULL,											// const void*				pNext;
1204 			attachmentBindInfos[stencilNdx],					// VkImageView				imageView;
1205 			VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,	// VkImageLayout			imageLayout;
1206 			VK_RESOLVE_MODE_NONE,								// VkResolveModeFlagBits	resolveMode;
1207 			VK_NULL_HANDLE,										// VkImageView				resolveImageView;
1208 			VK_IMAGE_LAYOUT_UNDEFINED,							// VkImageLayout			resolveImageLayout;
1209 			loadOp,												// VkAttachmentLoadOp		loadOp;
1210 			storeOp,											// VkAttachmentStoreOp		storeOp;
1211 			clearValue,											// VkClearValue				clearValue;
1212 		};
1213 
1214 		attachments.push_back(renderingAtachInfo);
1215 	}
1216 
1217 	const VkRenderingInfoKHR renderingInfo =
1218 	{
1219 		VK_STRUCTURE_TYPE_RENDERING_INFO_KHR,					// VkStructureType						sType;
1220 		DE_NULL,												// const void*							pNext;
1221 		flags,													// VkRenderingFlagsKHR					flags;
1222 		renderArea,												// VkRect2D								renderArea;
1223 		1u,														// deUint32								layerCount;
1224 		0u,														// deUint32								viewMask;
1225 		colorAtchCount,											// deUint32								colorAttachmentCount;
1226 		((colorAtchCount != 0) ? attachments.data() : DE_NULL),	// const VkRenderingAttachmentInfoKHR*	pColorAttachments;
1227 		((imagesFormat.depth != VK_FORMAT_UNDEFINED) ?
1228 			&attachments[colorAtchCount] :
1229 			DE_NULL),											// const VkRenderingAttachmentInfoKHR*	pDepthAttachment;
1230 		((imagesFormat.stencil != VK_FORMAT_UNDEFINED) ?
1231 			&attachments[stencilNdx] :
1232 			DE_NULL),											// const VkRenderingAttachmentInfoKHR*	pStencilAttachment;
1233 	};
1234 
1235 	vk.cmdBeginRenderingKHR(cmdBuffer, &renderingInfo);
1236 }
1237 
copyImgToBuff(VkCommandBuffer commandBuffer,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1238 void DynamicRenderingTestInstance::copyImgToBuff (VkCommandBuffer		commandBuffer,
1239 												  const deUint32		colorAtchCount,
1240 												  ImagesLayout&			imagesLayout,
1241 												  const ImagesFormat&	imagesFormat)
1242 {
1243 	const DeviceInterface&	vk = m_context.getDeviceInterface();
1244 
1245 	if (imagesFormat.colors[0] != VK_FORMAT_UNDEFINED)
1246 	{
1247 		for (deUint32 ndx = 0; ndx < colorAtchCount; ndx++)
1248 		{
1249 			vk::copyImageToBuffer(vk, commandBuffer, *m_imageColor[ndx], m_imageBuffer[ndx]->object(),
1250 								  tcu::IVec2(m_parameters.renderSize.x(), m_parameters.renderSize.y()),
1251 								  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, imagesLayout.oldColors[ndx], 1u,
1252 								  VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT);
1253 			imagesLayout.oldColors[ndx] = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
1254 		}
1255 	}
1256 	if (imagesFormat.depth != VK_FORMAT_UNDEFINED)
1257 	{
1258 		copyImageToBuffer(vk, commandBuffer, *m_imageStencilDepth, m_imageDepthBuffer->object(),
1259 						  tcu::IVec2(m_parameters.renderSize.x(), m_parameters.renderSize.y()),
1260 						  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, imagesLayout.oldDepth,
1261 						  1u, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_ASPECT_DEPTH_BIT);
1262 		imagesLayout.oldDepth = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
1263 	}
1264 	if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1265 	{
1266 		copyImageToBuffer(vk, commandBuffer, *m_imageStencilDepth, m_imageStencilBuffer->object(),
1267 						  tcu::IVec2(m_parameters.renderSize.x(), m_parameters.renderSize.y()),
1268 						  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, imagesLayout.oldStencil,
1269 						  1u, VK_IMAGE_ASPECT_STENCIL_BIT, VK_IMAGE_ASPECT_STENCIL_BIT);
1270 		imagesLayout.oldStencil = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
1271 	}
1272 }
1273 
verifyResults(const deUint32 colorAtchCount,const ImagesFormat & imagesFormat)1274 void	DynamicRenderingTestInstance::verifyResults (const deUint32			colorAtchCount,
1275 													 const ImagesFormat&	imagesFormat)
1276 {
1277 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1278 	const VkDevice			device	= m_context.getDevice();
1279 	tcu::TestLog&			log		= m_context.getTestContext().getLog();
1280 
1281 	if (imagesFormat.colors[0] != VK_FORMAT_UNDEFINED)
1282 	{
1283 		for (deUint32 ndx = 0; ndx < colorAtchCount; ndx++)
1284 		{
1285 			const Allocation allocColor = m_imageBuffer[ndx]->getBoundMemory();
1286 			invalidateAlloc(vk, device, allocColor);
1287 			const tcu::ConstPixelBufferAccess	resultColorImage(mapVkFormat(m_parameters.imageFormat), m_parameters.renderSize.x(), m_parameters.renderSize.y(), 1u, allocColor.getHostPtr());
1288 
1289 			if (!tcu::floatThresholdCompare(log, "Compare Color Image", "Result comparison",
1290 				m_referenceImages[ndx].getAccess(), resultColorImage,
1291 				Vec4(0.02f), tcu::COMPARE_LOG_ON_ERROR))
1292 			{
1293 				TCU_FAIL("Rendered color image is not correct");
1294 			}
1295 		}
1296 	}
1297 
1298 	if (imagesFormat.depth != VK_FORMAT_UNDEFINED)
1299 	{
1300 		const Allocation			allocDepth = m_imageDepthBuffer->getBoundMemory();
1301 		invalidateAlloc(vk, device, allocDepth);
1302 
1303 		const tcu::ConstPixelBufferAccess	resultDepthImage(getDepthTextureFormat(m_formatStencilDepthImage),
1304 															 m_parameters.renderSize.x(),
1305 															 m_parameters.renderSize.y(),
1306 															 1u, allocDepth.getHostPtr());
1307 		if (m_formatStencilDepthImage == VK_FORMAT_D24_UNORM_S8_UINT)
1308 		{
1309 			de::MovePtr<tcu::TextureLevel>	result(new tcu::TextureLevel(mapVkFormat(m_formatStencilDepthImage),
1310 														m_parameters.renderSize.x(), m_parameters.renderSize.y(), 1u));
1311 			tcu::copy(tcu::getEffectiveDepthStencilAccess(result->getAccess(), tcu::Sampler::MODE_DEPTH), resultDepthImage);
1312 
1313 			const tcu::ConstPixelBufferAccess	depthResult		= tcu::getEffectiveDepthStencilAccess(result->getAccess(), tcu::Sampler::MODE_DEPTH);
1314 			const tcu::ConstPixelBufferAccess	expectedResult	= tcu::getEffectiveDepthStencilAccess(m_referenceImages[COLOR_ATTACHMENTS_NUMBER].getAccess(), tcu::Sampler::MODE_DEPTH);
1315 
1316 			if (!tcu::intThresholdCompare(log, "Compare Depth Image", "Result comparison",
1317 				expectedResult, depthResult,UVec4(0, 0, 0, 0), tcu::COMPARE_LOG_ON_ERROR))
1318 			{
1319 				TCU_FAIL("Rendered depth image is not correct");
1320 			}
1321 		}
1322 		else
1323 		{
1324 			if (!tcu::floatThresholdCompare(log, "Compare Depth Image", "Result comparison",
1325 				m_referenceImages[COLOR_ATTACHMENTS_NUMBER].getAccess(), resultDepthImage,
1326 				Vec4(0.02f), tcu::COMPARE_LOG_ON_ERROR))
1327 			{
1328 				TCU_FAIL("Rendered depth image is not correct");
1329 			}
1330 		}
1331 	}
1332 
1333 	if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1334 	{
1335 		const Allocation allocStencil = m_imageStencilBuffer->getBoundMemory();
1336 		invalidateAlloc(vk, device, allocStencil);
1337 		const tcu::ConstPixelBufferAccess	resultStencilImage(mapVkFormat(VK_FORMAT_S8_UINT),
1338 															   m_parameters.renderSize.x(),
1339 															   m_parameters.renderSize.y(),
1340 															   1u, allocStencil.getHostPtr());
1341 
1342 		if (!tcu::intThresholdCompare(log, "Compare Stencil Image", "Result comparison",
1343 			m_referenceImages[COLOR_ATTACHMENTS_NUMBER + 1].getAccess(), resultStencilImage,
1344 			UVec4(0, 0, 0, 0), tcu::COMPARE_LOG_ON_ERROR))
1345 		{
1346 			TCU_FAIL("Rendered stencil image is not correct");
1347 		}
1348 	}
1349 }
1350 
1351 class SingleCmdBufferResuming : public DynamicRenderingTestInstance
1352 {
1353 public:
1354 			SingleCmdBufferResuming	(Context&							context,
1355 									 const TestParameters&				parameters);
1356 protected:
1357 	void	rendering				(const VkPipeline					pipeline,
1358 									 const std::vector<VkImageView>&	attachmentBindInfos,
1359 									 const deUint32						colorAtchCount,
1360 									 ImagesLayout&						imagesLayout,
1361 									 const ImagesFormat&				imagesFormat) override;
1362 };
1363 
SingleCmdBufferResuming(Context & context,const TestParameters & parameters)1364 SingleCmdBufferResuming::SingleCmdBufferResuming (Context&				context,
1365 													const TestParameters&	parameters)
1366 	: DynamicRenderingTestInstance(context, parameters)
1367 {
1368 }
1369 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1370 void	SingleCmdBufferResuming::rendering (const VkPipeline				pipeline,
1371 											const std::vector<VkImageView>&	attachmentBindInfos,
1372 											const deUint32					colorAtchCount,
1373 											ImagesLayout&					imagesLayout,
1374 											const ImagesFormat&				imagesFormat)
1375 {
1376 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1377 	const VkDevice			device	= m_context.getDevice();
1378 	const VkQueue			queue	= m_context.getUniversalQueue();
1379 
1380 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
1381 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1382 	{
1383 		beginCommandBuffer(vk, *m_cmdBuffer);
1384 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
1385 
1386 		beginRenderingKHR(*m_cmdBuffer,
1387 						  attachmentBindInfos,
1388 						  VK_RENDERING_SUSPENDING_BIT_KHR,
1389 						  colorAtchCount,
1390 						  imagesFormat,
1391 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1392 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1393 
1394 		vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1395 
1396 		{
1397 			const VkBuffer vertexBuffer = m_vertexBuffer->object();
1398 			const VkDeviceSize vertexBufferOffset = 0ull;
1399 			vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1400 		}
1401 
1402 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
1403 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
1404 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
1405 
1406 		beginRenderingKHR(*m_cmdBuffer,
1407 						  attachmentBindInfos,
1408 						  VK_RENDERING_RESUMING_BIT_KHR,
1409 						  colorAtchCount,
1410 						  imagesFormat,
1411 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1412 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1413 
1414 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 4u, 0u);
1415 
1416 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
1417 
1418 		copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1419 
1420 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1421 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1422 
1423 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1424 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1425 		{
1426 			verifyResults(colorAtchCount, imagesFormat);
1427 
1428 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1429 
1430 			beginCommandBuffer(vk, *m_cmdBuffer);
1431 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
1432 
1433 			beginRenderingKHR(*m_cmdBuffer,
1434 							  attachmentBindInfos,
1435 							  VK_RENDERING_SUSPENDING_BIT_KHR,
1436 							  colorAtchCount,
1437 							  imagesFormat,
1438 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1439 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1440 
1441 			if (clearData.colorDepthClear1.size() != 0)
1442 			{
1443 				vk.cmdClearAttachments(*m_cmdBuffer,
1444 										static_cast<deUint32>(clearData.colorDepthClear1.size()),
1445 										clearData.colorDepthClear1.data(),
1446 										1, &clearData.rectColorDepth1);
1447 			}
1448 
1449 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1450 				vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1451 
1452 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
1453 
1454 			beginRenderingKHR(*m_cmdBuffer,
1455 							  attachmentBindInfos,
1456 							  VK_RENDERING_RESUMING_BIT_KHR,
1457 							  colorAtchCount,
1458 							  imagesFormat,
1459 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1460 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1461 
1462 			if (clearData.colorDepthClear2.size() != 0)
1463 			{
1464 				vk.cmdClearAttachments(*m_cmdBuffer,
1465 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
1466 										clearData.colorDepthClear2.data(),
1467 										1, &clearData.rectColorDepth2);
1468 			}
1469 
1470 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1471 				vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1472 
1473 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
1474 
1475 			copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1476 
1477 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1478 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1479 
1480 			verifyResults(colorAtchCount, imagesFormat);
1481 		}
1482 	}
1483 }
1484 
1485 class TwoPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
1486 {
1487 public:
1488 			TwoPrimaryCmdBufferResuming	(Context&							context,
1489 										 const TestParameters&				parameters);
1490 protected:
1491 	void	rendering					(const VkPipeline					pipeline,
1492 										 const std::vector<VkImageView>&	attachmentBindInfos,
1493 										 const deUint32						colorAtchCount,
1494 										 ImagesLayout&						imagesLayout,
1495 										 const ImagesFormat&				imagesFormat) override;
1496 
1497 	Move<VkCommandBuffer>	m_cmdBuffer2;
1498 };
1499 
TwoPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)1500 TwoPrimaryCmdBufferResuming::TwoPrimaryCmdBufferResuming (Context&				context,
1501 														  const TestParameters&	parameters)
1502 	: DynamicRenderingTestInstance(context, parameters)
1503 {
1504 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1505 	const VkDevice			device	= m_context.getDevice();
1506 
1507 	m_cmdBuffer2 = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
1508 }
1509 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1510 void	TwoPrimaryCmdBufferResuming::rendering (const VkPipeline				pipeline,
1511 												const std::vector<VkImageView>&	attachmentBindInfos,
1512 												const deUint32					colorAtchCount,
1513 												ImagesLayout&					imagesLayout,
1514 												const ImagesFormat&				imagesFormat)
1515 {
1516 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1517 	const VkDevice			device	= m_context.getDevice();
1518 	const VkQueue			queue	= m_context.getUniversalQueue();
1519 
1520 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
1521 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1522 	{
1523 		// First Primary CommandBuffer
1524 		beginCommandBuffer(vk, *m_cmdBuffer);
1525 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
1526 
1527 		beginRenderingKHR(*m_cmdBuffer,
1528 						  attachmentBindInfos,
1529 						  VK_RENDERING_SUSPENDING_BIT_KHR,
1530 						  colorAtchCount,
1531 						  imagesFormat,
1532 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1533 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1534 
1535 		vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1536 
1537 		{
1538 			const VkBuffer vertexBuffer = m_vertexBuffer->object();
1539 			const VkDeviceSize vertexBufferOffset = 0ull;
1540 			vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1541 		}
1542 
1543 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
1544 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
1545 
1546 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
1547 
1548 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1549 
1550 		// Second Primary CommandBuffer
1551 		beginCommandBuffer(vk, *m_cmdBuffer2);
1552 
1553 		beginRenderingKHR(*m_cmdBuffer2,
1554 						  attachmentBindInfos,
1555 						  VK_RENDERING_RESUMING_BIT_KHR,
1556 						  colorAtchCount,
1557 						  imagesFormat,
1558 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1559 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1560 
1561 		vk.cmdBindPipeline(*m_cmdBuffer2, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1562 
1563 		{
1564 			const VkBuffer vertexBuffer = m_vertexBuffer->object();
1565 			const VkDeviceSize vertexBufferOffset = 0ull;
1566 			vk.cmdBindVertexBuffers(*m_cmdBuffer2, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1567 		}
1568 
1569 		vk.cmdDraw(*m_cmdBuffer2, 4u, 1u, 4u, 0u);
1570 
1571 		vk.cmdEndRenderingKHR(*m_cmdBuffer2);
1572 
1573 		copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
1574 
1575 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
1576 
1577 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
1578 
1579 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1580 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1581 		{
1582 			verifyResults(colorAtchCount, imagesFormat);
1583 
1584 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1585 
1586 			// First Primary CommandBuffer
1587 			beginCommandBuffer(vk, *m_cmdBuffer);
1588 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
1589 
1590 			beginRenderingKHR(*m_cmdBuffer,
1591 							  attachmentBindInfos,
1592 							  VK_RENDERING_SUSPENDING_BIT_KHR,
1593 							  colorAtchCount,
1594 							  imagesFormat,
1595 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1596 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1597 
1598 			if (clearData.colorDepthClear1.size() != 0)
1599 			{
1600 				vk.cmdClearAttachments(*m_cmdBuffer,
1601 										static_cast<deUint32>(clearData.colorDepthClear1.size()),
1602 										clearData.colorDepthClear1.data(),
1603 										1, &clearData.rectColorDepth1);
1604 			}
1605 
1606 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1607 				vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1608 
1609 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
1610 
1611 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1612 
1613 			// Second Primary CommandBuffer
1614 			beginCommandBuffer(vk, *m_cmdBuffer2);
1615 
1616 			beginRenderingKHR(*m_cmdBuffer2,
1617 							  attachmentBindInfos,
1618 							  VK_RENDERING_RESUMING_BIT_KHR,
1619 							  colorAtchCount,
1620 							  imagesFormat,
1621 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1622 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1623 
1624 			if (clearData.colorDepthClear2.size() != 0)
1625 			{
1626 				vk.cmdClearAttachments(*m_cmdBuffer2,
1627 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
1628 										clearData.colorDepthClear2.data(),
1629 										1, &clearData.rectColorDepth2);
1630 			}
1631 
1632 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1633 				vk.cmdClearAttachments(*m_cmdBuffer2, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1634 
1635 			vk.cmdEndRenderingKHR(*m_cmdBuffer2);
1636 
1637 			copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
1638 
1639 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
1640 
1641 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
1642 
1643 			verifyResults(colorAtchCount, imagesFormat);
1644 		}
1645 	}
1646 }
1647 
1648 class TwoSecondaryCmdBufferResuming : public DynamicRenderingTestInstance
1649 {
1650 public:
1651 			TwoSecondaryCmdBufferResuming	(Context&							context,
1652 											 const TestParameters&				parameters);
1653 protected:
1654 	void	rendering						(const VkPipeline					pipeline,
1655 											 const std::vector<VkImageView>&	attachmentBindInfos,
1656 											 const deUint32						colorAtchCount,
1657 											 ImagesLayout&						imagesLayout,
1658 											 const ImagesFormat&				imagesFormat) override;
1659 
1660 	Move<VkCommandBuffer>	m_secCmdBuffers[2];
1661 };
1662 
TwoSecondaryCmdBufferResuming(Context & context,const TestParameters & parameters)1663 TwoSecondaryCmdBufferResuming::TwoSecondaryCmdBufferResuming (Context&				context,
1664 															  const TestParameters&	parameters)
1665 	: DynamicRenderingTestInstance(context, parameters)
1666 {
1667 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1668 	const VkDevice			device	= m_context.getDevice();
1669 
1670 	m_secCmdBuffers[0] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1671 	m_secCmdBuffers[1] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1672 }
1673 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1674 void	TwoSecondaryCmdBufferResuming::rendering (const VkPipeline					pipeline,
1675 												  const std::vector<VkImageView>&	attachmentBindInfos,
1676 												  const deUint32					colorAtchCount,
1677 												  ImagesLayout&						imagesLayout,
1678 												  const ImagesFormat&				imagesFormat)
1679 {
1680 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1681 	const VkDevice			device	= m_context.getDevice();
1682 	const VkQueue			queue	= m_context.getUniversalQueue();
1683 
1684 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
1685 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1686 	{
1687 		VkCommandBuffer		secCmdBuffers[2]	= {
1688 													*(m_secCmdBuffers[0]),
1689 													*(m_secCmdBuffers[1])
1690 												  };
1691 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
1692 		const VkDeviceSize	vertexBufferOffset	= 0ull;
1693 
1694 		// secCmdBuffersFirst
1695 		beginSecondaryCmdBuffer(vk, secCmdBuffers[0]);
1696 
1697 		beginRenderingKHR(secCmdBuffers[0],
1698 						  attachmentBindInfos,
1699 						  VK_RENDERING_SUSPENDING_BIT_KHR,
1700 						  colorAtchCount,
1701 						  imagesFormat,
1702 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1703 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1704 
1705 		vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1706 		vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1707 
1708 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
1709 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
1710 
1711 		vk.cmdEndRenderingKHR(secCmdBuffers[0]);
1712 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1713 
1714 		// secCmdBuffersSecond
1715 		beginSecondaryCmdBuffer(vk, secCmdBuffers[1]);
1716 
1717 		beginRenderingKHR(secCmdBuffers[1],
1718 						  attachmentBindInfos,
1719 						  VK_RENDERING_RESUMING_BIT_KHR,
1720 						  colorAtchCount,
1721 						  imagesFormat,
1722 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1723 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1724 
1725 		vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1726 		vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1727 
1728 		vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
1729 
1730 		vk.cmdEndRenderingKHR(secCmdBuffers[1]);
1731 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1732 
1733 		// Primary commandBuffer
1734 		beginCommandBuffer(vk, *m_cmdBuffer);
1735 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
1736 
1737 		vk.cmdExecuteCommands(*m_cmdBuffer, 2u, secCmdBuffers);
1738 
1739 		copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1740 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1741 
1742 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1743 
1744 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1745 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1746 		{
1747 			verifyResults(colorAtchCount, imagesFormat);
1748 
1749 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1750 
1751 		// secCmdBuffersFirst
1752 			beginSecondaryCmdBuffer(vk, secCmdBuffers[0]);
1753 
1754 			beginRenderingKHR(secCmdBuffers[0],
1755 							  attachmentBindInfos,
1756 							  VK_RENDERING_SUSPENDING_BIT_KHR,
1757 							  colorAtchCount,
1758 							  imagesFormat,
1759 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1760 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1761 
1762 			if (clearData.colorDepthClear1.size() != 0)
1763 			{
1764 				vk.cmdClearAttachments(secCmdBuffers[0],
1765 									   static_cast<deUint32>(clearData.colorDepthClear1.size()),
1766 									   clearData.colorDepthClear1.data(),
1767 									   1, &clearData.rectColorDepth1);
1768 			}
1769 
1770 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1771 				vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1772 
1773 			vk.cmdEndRenderingKHR(secCmdBuffers[0]);
1774 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1775 
1776 			// secCmdBuffersSecond
1777 			beginSecondaryCmdBuffer(vk, secCmdBuffers[1]);
1778 
1779 			beginRenderingKHR(secCmdBuffers[1],
1780 							  attachmentBindInfos,
1781 							  VK_RENDERING_RESUMING_BIT_KHR,
1782 							  colorAtchCount,
1783 							  imagesFormat,
1784 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1785 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1786 
1787 			if (clearData.colorDepthClear2.size() != 0)
1788 			{
1789 				vk.cmdClearAttachments(secCmdBuffers[1],
1790 									   static_cast<deUint32>(clearData.colorDepthClear2.size()),
1791 									   clearData.colorDepthClear2.data(),
1792 									   1, &clearData.rectColorDepth2);
1793 			}
1794 
1795 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1796 				vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1797 
1798 			vk.cmdEndRenderingKHR(secCmdBuffers[1]);
1799 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1800 
1801 			// Primary commandBuffer
1802 			beginCommandBuffer(vk, *m_cmdBuffer);
1803 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
1804 
1805 			vk.cmdExecuteCommands(*m_cmdBuffer, 2u, secCmdBuffers);
1806 
1807 			copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1808 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1809 
1810 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1811 
1812 			verifyResults(colorAtchCount, imagesFormat);
1813 		}
1814 	}
1815 }
1816 
1817 class TwoSecondaryTwoPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
1818 {
1819 public:
1820 			TwoSecondaryTwoPrimaryCmdBufferResuming	(Context&							context,
1821 													 const TestParameters&				parameters);
1822 protected:
1823 	void	rendering								(const VkPipeline					pipeline,
1824 													 const std::vector<VkImageView>&	attachmentBindInfos,
1825 													 const deUint32						colorAtchCount,
1826 													 ImagesLayout&						imagesLayout,
1827 													 const ImagesFormat&				imagesFormat) override;
1828 
1829 	Move<VkCommandBuffer>	m_cmdBuffer2;
1830 	Move<VkCommandBuffer>	m_secCmdBuffers[2];
1831 };
1832 
TwoSecondaryTwoPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)1833 TwoSecondaryTwoPrimaryCmdBufferResuming::TwoSecondaryTwoPrimaryCmdBufferResuming (Context&				context,
1834 																				  const TestParameters&	parameters)
1835 	: DynamicRenderingTestInstance(context, parameters)
1836 {
1837 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1838 	const VkDevice			device	= m_context.getDevice();
1839 
1840 	m_cmdBuffer2		= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
1841 	m_secCmdBuffers[0]	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1842 	m_secCmdBuffers[1]	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1843 }
1844 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1845 void	TwoSecondaryTwoPrimaryCmdBufferResuming::rendering (const VkPipeline				pipeline,
1846 															const std::vector<VkImageView>&	attachmentBindInfos,
1847 															const deUint32					colorAtchCount,
1848 															ImagesLayout&					imagesLayout,
1849 															const ImagesFormat&				imagesFormat)
1850 {
1851 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1852 	const VkDevice			device	= m_context.getDevice();
1853 	const VkQueue			queue	= m_context.getUniversalQueue();
1854 
1855 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
1856 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1857 	{
1858 		VkCommandBuffer		secCmdBuffers[2]	= {
1859 													*(m_secCmdBuffers[0]),
1860 													*(m_secCmdBuffers[1])
1861 												  };
1862 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
1863 		const VkDeviceSize	vertexBufferOffset	= 0ull;
1864 
1865 		// secCmdBuffersFirst
1866 		beginSecondaryCmdBuffer(vk, secCmdBuffers[0]);
1867 
1868 		beginRenderingKHR(secCmdBuffers[0],
1869 						  attachmentBindInfos,
1870 						  VK_RENDERING_SUSPENDING_BIT_KHR,
1871 						  colorAtchCount,
1872 						  imagesFormat,
1873 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1874 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1875 
1876 		vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1877 		vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1878 
1879 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
1880 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
1881 
1882 		vk.cmdEndRenderingKHR(secCmdBuffers[0]);
1883 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1884 
1885 
1886 		// secCmdBuffersSecond
1887 		beginSecondaryCmdBuffer(vk, secCmdBuffers[1]);
1888 
1889 		beginRenderingKHR(secCmdBuffers[1],
1890 						  attachmentBindInfos,
1891 						  VK_RENDERING_RESUMING_BIT_KHR,
1892 						  colorAtchCount,
1893 						  imagesFormat,
1894 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1895 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1896 
1897 		vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1898 		vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1899 
1900 		vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
1901 
1902 		vk.cmdEndRenderingKHR(secCmdBuffers[1]);
1903 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1904 
1905 		// Primary commandBuffer
1906 		beginCommandBuffer(vk, *m_cmdBuffer);
1907 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
1908 
1909 		vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
1910 
1911 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1912 
1913 		// Primary commandBuffer2
1914 		beginCommandBuffer(vk, *m_cmdBuffer2);
1915 
1916 		vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &secCmdBuffers[1]);
1917 
1918 		copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
1919 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
1920 
1921 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
1922 
1923 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1924 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1925 		{
1926 			verifyResults(colorAtchCount, imagesFormat);
1927 
1928 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1929 
1930 			// secCmdBuffersFirst
1931 			beginSecondaryCmdBuffer(vk, secCmdBuffers[0]);
1932 
1933 			beginRenderingKHR(secCmdBuffers[0],
1934 							  attachmentBindInfos,
1935 							  VK_RENDERING_SUSPENDING_BIT_KHR,
1936 							  colorAtchCount,
1937 							  imagesFormat,
1938 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1939 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1940 
1941 			if (clearData.colorDepthClear1.size() != 0)
1942 			{
1943 				vk.cmdClearAttachments(secCmdBuffers[0],
1944 									   static_cast<deUint32>(clearData.colorDepthClear1.size()),
1945 									   clearData.colorDepthClear1.data(),
1946 									   1, &clearData.rectColorDepth1);
1947 			}
1948 
1949 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1950 				vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1951 
1952 			vk.cmdEndRenderingKHR(secCmdBuffers[0]);
1953 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1954 
1955 			// secCmdBuffersSecond
1956 			beginSecondaryCmdBuffer(vk, secCmdBuffers[1]);
1957 
1958 			beginRenderingKHR(secCmdBuffers[1],
1959 							  attachmentBindInfos,
1960 							  VK_RENDERING_RESUMING_BIT_KHR,
1961 							  colorAtchCount,
1962 							  imagesFormat,
1963 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1964 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1965 
1966 			if (clearData.colorDepthClear2.size() != 0)
1967 			{
1968 				vk.cmdClearAttachments(secCmdBuffers[1],
1969 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
1970 										clearData.colorDepthClear2.data(),
1971 										1, &clearData.rectColorDepth2);
1972 			}
1973 
1974 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1975 				vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1976 
1977 			vk.cmdEndRenderingKHR(secCmdBuffers[1]);
1978 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1979 
1980 			// Primary commandBuffer
1981 			beginCommandBuffer(vk, *m_cmdBuffer);
1982 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
1983 
1984 			vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
1985 
1986 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1987 
1988 			// Primary commandBuffer2
1989 			beginCommandBuffer(vk, *m_cmdBuffer2);
1990 
1991 			vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &secCmdBuffers[1]);
1992 
1993 			copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
1994 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
1995 
1996 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
1997 
1998 			verifyResults(colorAtchCount, imagesFormat);
1999 		}
2000 	}
2001 }
2002 
2003 class ContentsSecondaryCmdBuffer : public DynamicRenderingTestInstance
2004 {
2005 public:
2006 			ContentsSecondaryCmdBuffer	(Context&							context,
2007 										 const TestParameters&				parameters);
2008 protected:
2009 	void	rendering					(const VkPipeline					pipeline,
2010 										 const std::vector<VkImageView>&	attachmentBindInfos,
2011 										 const deUint32						colorAtchCount,
2012 										 ImagesLayout&						imagesLayout,
2013 										 const ImagesFormat&				imagesFormat) override;
2014 
2015 	Move<VkCommandBuffer>	m_secCmdBuffers;
2016 };
2017 
ContentsSecondaryCmdBuffer(Context & context,const TestParameters & parameters)2018 ContentsSecondaryCmdBuffer::ContentsSecondaryCmdBuffer (Context&				context,
2019 														const TestParameters&	parameters)
2020 	: DynamicRenderingTestInstance(context, parameters)
2021 {
2022 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2023 	const VkDevice			device	= m_context.getDevice();
2024 
2025 	m_secCmdBuffers	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2026 }
2027 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2028 void	ContentsSecondaryCmdBuffer::rendering (const VkPipeline					pipeline,
2029 											   const std::vector<VkImageView>&	attachmentBindInfos,
2030 											   const deUint32					colorAtchCount,
2031 											   ImagesLayout&					imagesLayout,
2032 											   const ImagesFormat&				imagesFormat)
2033 {
2034 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2035 	const VkDevice			device	= m_context.getDevice();
2036 	const VkQueue			queue	= m_context.getUniversalQueue();
2037 
2038 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
2039 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2040 	{
2041 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
2042 		const VkDeviceSize	vertexBufferOffset	= 0ull;
2043 
2044 		// secCmdBuffers
2045 		beginSecondaryCmdBuffer(vk, *m_secCmdBuffers, (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
2046 
2047 		vk.cmdBindPipeline(*m_secCmdBuffers, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2048 		vk.cmdBindVertexBuffers(*m_secCmdBuffers, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2049 
2050 		vk.cmdDraw(*m_secCmdBuffers, 4u, 1u, 8u, 0u);
2051 		vk.cmdDraw(*m_secCmdBuffers, 4u, 1u, 0u, 0u);
2052 		vk.cmdDraw(*m_secCmdBuffers, 4u, 1u, 4u, 0u);
2053 
2054 		VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffers));
2055 
2056 		// Primary commandBuffer
2057 		beginCommandBuffer(vk, *m_cmdBuffer);
2058 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
2059 
2060 		beginRenderingKHR(*m_cmdBuffer,
2061 						  attachmentBindInfos,
2062 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR,
2063 						  colorAtchCount,
2064 						  imagesFormat,
2065 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2066 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2067 
2068 		vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffers));
2069 
2070 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2071 
2072 		copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2073 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2074 
2075 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2076 
2077 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2078 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2079 		{
2080 			verifyResults(colorAtchCount, imagesFormat);
2081 
2082 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2083 
2084 			// secCmdBuffers
2085 			beginSecondaryCmdBuffer(vk, *m_secCmdBuffers, (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
2086 
2087 			if (clearData.colorDepthClear1.size() != 0)
2088 			{
2089 				vk.cmdClearAttachments(*m_secCmdBuffers,
2090 									   static_cast<deUint32>(clearData.colorDepthClear1.size()),
2091 									   clearData.colorDepthClear1.data(),
2092 									   1, &clearData.rectColorDepth1);
2093 			}
2094 
2095 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2096 				vk.cmdClearAttachments(*m_secCmdBuffers, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2097 
2098 			if (clearData.colorDepthClear2.size() != 0)
2099 			{
2100 				vk.cmdClearAttachments(*m_secCmdBuffers,
2101 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
2102 										clearData.colorDepthClear2.data(),
2103 										1, &clearData.rectColorDepth2);
2104 			}
2105 
2106 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2107 				vk.cmdClearAttachments(*m_secCmdBuffers, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2108 
2109 			VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffers));
2110 
2111 			// Primary commandBuffer
2112 			beginCommandBuffer(vk, *m_cmdBuffer);
2113 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
2114 
2115 			beginRenderingKHR(*m_cmdBuffer,
2116 							  attachmentBindInfos,
2117 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR,
2118 							  colorAtchCount,
2119 							  imagesFormat,
2120 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2121 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2122 
2123 			vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffers));
2124 
2125 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2126 
2127 			copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2128 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2129 
2130 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2131 
2132 			verifyResults(colorAtchCount, imagesFormat);
2133 		}
2134 	}
2135 }
2136 
2137 class ContentsTwoSecondaryCmdBuffer : public DynamicRenderingTestInstance
2138 {
2139 public:
2140 			ContentsTwoSecondaryCmdBuffer		(Context&							context,
2141 												 const TestParameters&				parameters);
2142 protected:
2143 	void	rendering							(const VkPipeline					pipeline,
2144 												 const std::vector<VkImageView>&	attachmentBindInfos,
2145 												 const deUint32						colorAtchCount,
2146 												 ImagesLayout&						imagesLayout,
2147 												 const ImagesFormat&				imagesFormat) override;
2148 
2149 	Move<VkCommandBuffer>	m_secCmdBuffers[2];
2150 };
2151 
ContentsTwoSecondaryCmdBuffer(Context & context,const TestParameters & parameters)2152 ContentsTwoSecondaryCmdBuffer::ContentsTwoSecondaryCmdBuffer (Context&				context,
2153 															  const TestParameters&	parameters)
2154 	: DynamicRenderingTestInstance(context, parameters)
2155 {
2156 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2157 	const VkDevice			device	= m_context.getDevice();
2158 
2159 	m_secCmdBuffers[0] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2160 	m_secCmdBuffers[1] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2161 }
2162 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2163 void	ContentsTwoSecondaryCmdBuffer::rendering (const VkPipeline					pipeline,
2164 												  const std::vector<VkImageView>&	attachmentBindInfos,
2165 												  const deUint32					colorAtchCount,
2166 												  ImagesLayout&						imagesLayout,
2167 												  const ImagesFormat&				imagesFormat)
2168 {
2169 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2170 	const VkDevice			device	= m_context.getDevice();
2171 	const VkQueue			queue	= m_context.getUniversalQueue();
2172 
2173 	VkCommandBuffer		secCmdBuffers[2] = {
2174 												*(m_secCmdBuffers[0]),
2175 												*(m_secCmdBuffers[1])
2176 											};
2177 
2178 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
2179 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2180 	{
2181 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
2182 		const VkDeviceSize	vertexBufferOffset	= 0ull;
2183 
2184 		// secCmdBuffers
2185 		beginSecondaryCmdBuffer(vk, secCmdBuffers[0], (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
2186 
2187 		vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2188 		vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2189 
2190 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
2191 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
2192 
2193 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2194 
2195 		// secCmdBuffers2
2196 		beginSecondaryCmdBuffer(vk, secCmdBuffers[1], (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
2197 
2198 		vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2199 		vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2200 
2201 		vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
2202 
2203 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2204 
2205 		// Primary commandBuffer
2206 		beginCommandBuffer(vk, *m_cmdBuffer);
2207 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
2208 
2209 		beginRenderingKHR(*m_cmdBuffer,
2210 						  attachmentBindInfos,
2211 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR,
2212 						  colorAtchCount,
2213 						  imagesFormat,
2214 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2215 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2216 
2217 		vk.cmdExecuteCommands(*m_cmdBuffer, 2u, secCmdBuffers);
2218 
2219 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2220 
2221 		copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2222 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2223 
2224 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2225 
2226 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2227 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2228 		{
2229 			verifyResults(colorAtchCount, imagesFormat);
2230 
2231 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2232 
2233 			// secCmdBuffers
2234 			beginSecondaryCmdBuffer(vk, secCmdBuffers[0], (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
2235 
2236 			if (clearData.colorDepthClear1.size() != 0)
2237 			{
2238 				vk.cmdClearAttachments(secCmdBuffers[0],
2239 									   static_cast<deUint32>(clearData.colorDepthClear1.size()),
2240 									   clearData.colorDepthClear1.data(),
2241 									   1, &clearData.rectColorDepth1);
2242 			}
2243 
2244 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2245 				vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2246 
2247 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2248 
2249 			// secCmdBuffers2
2250 			beginSecondaryCmdBuffer(vk, secCmdBuffers[1], (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
2251 
2252 			if (clearData.colorDepthClear2.size() != 0)
2253 			{
2254 				vk.cmdClearAttachments(secCmdBuffers[1],
2255 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
2256 										clearData.colorDepthClear2.data(),
2257 										1, &clearData.rectColorDepth2);
2258 			}
2259 
2260 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2261 				vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2262 
2263 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2264 
2265 			// Primary commandBuffer
2266 			beginCommandBuffer(vk, *m_cmdBuffer);
2267 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
2268 
2269 			beginRenderingKHR(*m_cmdBuffer,
2270 							  attachmentBindInfos,
2271 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR,
2272 							  colorAtchCount,
2273 							  imagesFormat,
2274 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2275 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2276 
2277 			vk.cmdExecuteCommands(*m_cmdBuffer, 2u, secCmdBuffers);
2278 
2279 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2280 
2281 			copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2282 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2283 
2284 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2285 
2286 			verifyResults(colorAtchCount, imagesFormat);
2287 		}
2288 	}
2289 }
2290 
2291 class ContentsTwoSecondaryCmdBufferResuming : public DynamicRenderingTestInstance
2292 {
2293 public:
2294 			ContentsTwoSecondaryCmdBufferResuming	(Context&							context,
2295 													 const TestParameters&				parameters);
2296 protected:
2297 	void	rendering								(const VkPipeline					pipeline,
2298 													 const std::vector<VkImageView>&	attachmentBindInfos,
2299 													 const deUint32						colorAtchCount,
2300 													 ImagesLayout&						imagesLayout,
2301 													 const ImagesFormat&				imagesFormat) override;
2302 
2303 	Move<VkCommandBuffer>	m_secCmdBuffers[2];
2304 };
2305 
ContentsTwoSecondaryCmdBufferResuming(Context & context,const TestParameters & parameters)2306 ContentsTwoSecondaryCmdBufferResuming::ContentsTwoSecondaryCmdBufferResuming (Context&				context,
2307 																			  const TestParameters&	parameters)
2308 	: DynamicRenderingTestInstance(context, parameters)
2309 {
2310 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2311 	const VkDevice			device	= m_context.getDevice();
2312 
2313 	m_secCmdBuffers[0] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2314 	m_secCmdBuffers[1] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2315 }
2316 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2317 void	ContentsTwoSecondaryCmdBufferResuming::rendering (const VkPipeline					pipeline,
2318 														  const std::vector<VkImageView>&	attachmentBindInfos,
2319 														  const deUint32					colorAtchCount,
2320 														  ImagesLayout&						imagesLayout,
2321 														  const ImagesFormat&				imagesFormat)
2322 {
2323 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2324 	const VkDevice			device	= m_context.getDevice();
2325 	const VkQueue			queue	= m_context.getUniversalQueue();
2326 
2327 	VkCommandBuffer		secCmdBuffers[2] = {
2328 												*(m_secCmdBuffers[0]),
2329 												*(m_secCmdBuffers[1])
2330 											};
2331 
2332 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
2333 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2334 	{
2335 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
2336 		const VkDeviceSize	vertexBufferOffset	= 0ull;
2337 
2338 		// secCmdBuffers
2339 		beginSecondaryCmdBuffer(vk, secCmdBuffers[0], VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
2340 
2341 		vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2342 		vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2343 
2344 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
2345 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
2346 
2347 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2348 
2349 		// secCmdBuffers2
2350 		beginSecondaryCmdBuffer(vk, secCmdBuffers[1], VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2351 
2352 		vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2353 		vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2354 
2355 		vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
2356 
2357 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2358 
2359 		// Primary commandBuffer
2360 		beginCommandBuffer(vk, *m_cmdBuffer);
2361 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
2362 
2363 		beginRenderingKHR(*m_cmdBuffer,
2364 						  attachmentBindInfos,
2365 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2366 						  VK_RENDERING_SUSPENDING_BIT_KHR,
2367 						  colorAtchCount,
2368 						  imagesFormat,
2369 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2370 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2371 
2372 		vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
2373 
2374 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2375 
2376 		beginRenderingKHR(*m_cmdBuffer,
2377 						  attachmentBindInfos,
2378 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2379 						  VK_RENDERING_RESUMING_BIT_KHR,
2380 						  colorAtchCount,
2381 						  imagesFormat,
2382 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2383 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2384 
2385 		vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[1]);
2386 
2387 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2388 
2389 		copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2390 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2391 
2392 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2393 
2394 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2395 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2396 		{
2397 			verifyResults(colorAtchCount, imagesFormat);
2398 
2399 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2400 
2401 			// secCmdBuffers
2402 			beginSecondaryCmdBuffer(vk, secCmdBuffers[0], VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
2403 
2404 			if (clearData.colorDepthClear1.size() != 0)
2405 			{
2406 				vk.cmdClearAttachments(secCmdBuffers[0],
2407 									   static_cast<deUint32>(clearData.colorDepthClear1.size()),
2408 									   clearData.colorDepthClear1.data(),
2409 									   1, &clearData.rectColorDepth1);
2410 			}
2411 
2412 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2413 				vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2414 
2415 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2416 
2417 			// secCmdBuffers2
2418 			beginSecondaryCmdBuffer(vk, secCmdBuffers[1], VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2419 
2420 			if (clearData.colorDepthClear2.size() != 0)
2421 			{
2422 				vk.cmdClearAttachments(secCmdBuffers[1],
2423 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
2424 										clearData.colorDepthClear2.data(),
2425 										1, &clearData.rectColorDepth2);
2426 			}
2427 
2428 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2429 				vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2430 
2431 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2432 
2433 			// Primary commandBuffer
2434 			beginCommandBuffer(vk, *m_cmdBuffer);
2435 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
2436 
2437 			beginRenderingKHR(*m_cmdBuffer,
2438 							  attachmentBindInfos,
2439 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2440 							  VK_RENDERING_SUSPENDING_BIT_KHR,
2441 							  colorAtchCount,
2442 							  imagesFormat,
2443 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2444 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2445 
2446 			vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
2447 
2448 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2449 
2450 			beginRenderingKHR(*m_cmdBuffer,
2451 							  attachmentBindInfos,
2452 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2453 							  VK_RENDERING_RESUMING_BIT_KHR,
2454 							  colorAtchCount,
2455 							  imagesFormat,
2456 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2457 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2458 
2459 			vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[1]);
2460 
2461 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2462 
2463 			copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2464 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2465 
2466 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2467 
2468 			verifyResults(colorAtchCount, imagesFormat);
2469 		}
2470 	}
2471 }
2472 
2473 class ContentsTwoSecondaryTwoPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
2474 {
2475 public:
2476 			ContentsTwoSecondaryTwoPrimaryCmdBufferResuming	(Context&							context,
2477 															 const TestParameters&				parameters);
2478 protected:
2479 	void	rendering										(const VkPipeline					pipeline,
2480 															 const std::vector<VkImageView>&	attachmentBindInfos,
2481 															 const deUint32						colorAtchCount,
2482 															 ImagesLayout&						imagesLayout,
2483 															 const ImagesFormat&				imagesFormat) override;
2484 
2485 	Move<VkCommandBuffer>	m_cmdBuffer2;
2486 	Move<VkCommandBuffer>	m_secCmdBuffers[2];
2487 };
2488 
ContentsTwoSecondaryTwoPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)2489 ContentsTwoSecondaryTwoPrimaryCmdBufferResuming::ContentsTwoSecondaryTwoPrimaryCmdBufferResuming	(Context&				context,
2490 																									 const TestParameters&	parameters)
2491 	: DynamicRenderingTestInstance(context, parameters)
2492 {
2493 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2494 	const VkDevice			device	= m_context.getDevice();
2495 
2496 	m_cmdBuffer2		= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2497 	m_secCmdBuffers[0]	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2498 	m_secCmdBuffers[1]	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2499 }
2500 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2501 void	ContentsTwoSecondaryTwoPrimaryCmdBufferResuming::rendering (const VkPipeline				pipeline,
2502 																	const std::vector<VkImageView>&	attachmentBindInfos,
2503 																	const deUint32					colorAtchCount,
2504 																	ImagesLayout&					imagesLayout,
2505 																	const ImagesFormat&				imagesFormat)
2506 {
2507 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2508 	const VkDevice			device	= m_context.getDevice();
2509 	const VkQueue			queue	= m_context.getUniversalQueue();
2510 
2511 	VkCommandBuffer		secCmdBuffers[2] = {
2512 												*(m_secCmdBuffers[0]),
2513 												*(m_secCmdBuffers[1])
2514 											};
2515 
2516 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
2517 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2518 	{
2519 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
2520 		const VkDeviceSize	vertexBufferOffset	= 0ull;
2521 
2522 		// secCmdBuffers
2523 		beginSecondaryCmdBuffer(vk, secCmdBuffers[0], VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
2524 
2525 		vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2526 		vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2527 
2528 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
2529 		vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
2530 
2531 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2532 
2533 		// secCmdBuffers2
2534 		beginSecondaryCmdBuffer(vk, secCmdBuffers[1], VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2535 
2536 		vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2537 		vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2538 
2539 		vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
2540 
2541 		VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2542 
2543 		// Primary commandBuffer
2544 		beginCommandBuffer(vk, *m_cmdBuffer);
2545 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
2546 
2547 		beginRenderingKHR(*m_cmdBuffer,
2548 						  attachmentBindInfos,
2549 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2550 						  VK_RENDERING_SUSPENDING_BIT_KHR,
2551 						  colorAtchCount,
2552 						  imagesFormat,
2553 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2554 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2555 
2556 		vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
2557 
2558 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2559 
2560 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2561 
2562 		// Primary commandBuffer2
2563 		beginCommandBuffer(vk, *m_cmdBuffer2);
2564 
2565 		beginRenderingKHR(*m_cmdBuffer2,
2566 						  attachmentBindInfos,
2567 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2568 						  VK_RENDERING_RESUMING_BIT_KHR,
2569 						  colorAtchCount,
2570 						  imagesFormat,
2571 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2572 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2573 
2574 		vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &secCmdBuffers[1]);
2575 
2576 		vk.cmdEndRenderingKHR(*m_cmdBuffer2);
2577 
2578 		copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
2579 
2580 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
2581 
2582 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
2583 
2584 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2585 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2586 		{
2587 			verifyResults(colorAtchCount, imagesFormat);
2588 
2589 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2590 
2591 			// secCmdBuffers
2592 			beginSecondaryCmdBuffer(vk, secCmdBuffers[0], VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
2593 
2594 			if (clearData.colorDepthClear1.size() != 0)
2595 			{
2596 				vk.cmdClearAttachments(secCmdBuffers[0],
2597 										static_cast<deUint32>(clearData.colorDepthClear1.size()),
2598 										clearData.colorDepthClear1.data(),
2599 										1, &clearData.rectColorDepth1);
2600 			}
2601 
2602 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2603 				vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2604 
2605 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2606 
2607 			// secCmdBuffers2
2608 			beginSecondaryCmdBuffer(vk, secCmdBuffers[1], VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2609 
2610 			if (clearData.colorDepthClear2.size() != 0)
2611 			{
2612 				vk.cmdClearAttachments(secCmdBuffers[1],
2613 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
2614 										clearData.colorDepthClear2.data(),
2615 										1, &clearData.rectColorDepth2);
2616 			}
2617 
2618 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2619 				vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2620 
2621 			VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2622 
2623 			// Primary commandBuffer
2624 			beginCommandBuffer(vk, *m_cmdBuffer);
2625 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
2626 
2627 			beginRenderingKHR(*m_cmdBuffer,
2628 							  attachmentBindInfos,
2629 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2630 							  VK_RENDERING_SUSPENDING_BIT_KHR,
2631 							  colorAtchCount,
2632 							  imagesFormat,
2633 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2634 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2635 
2636 			vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
2637 
2638 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2639 
2640 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2641 
2642 			// Primary commandBuffer2
2643 			beginCommandBuffer(vk, *m_cmdBuffer2);
2644 
2645 			beginRenderingKHR(*m_cmdBuffer2,
2646 							  attachmentBindInfos,
2647 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2648 							  VK_RENDERING_RESUMING_BIT_KHR,
2649 							  colorAtchCount,
2650 							  imagesFormat,
2651 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2652 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2653 
2654 			vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &secCmdBuffers[1]);
2655 
2656 			vk.cmdEndRenderingKHR(*m_cmdBuffer2);
2657 
2658 			copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
2659 
2660 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
2661 
2662 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
2663 
2664 			verifyResults(colorAtchCount, imagesFormat);
2665 		}
2666 	}
2667 }
2668 
2669 class ContentsPrimarySecondaryCmdBufferResuming : public DynamicRenderingTestInstance
2670 {
2671 public:
2672 			ContentsPrimarySecondaryCmdBufferResuming	(Context&							context,
2673 														 const TestParameters&				parameters);
2674 protected:
2675 	void	rendering									(const VkPipeline					pipeline,
2676 														 const std::vector<VkImageView>&	attachmentBindInfos,
2677 														 const deUint32						colorAtchCount,
2678 														 ImagesLayout&						imagesLayout,
2679 														 const ImagesFormat&				imagesFormat) override;
2680 
2681 	Move<VkCommandBuffer>	m_secCmdBuffer;
2682 };
2683 
ContentsPrimarySecondaryCmdBufferResuming(Context & context,const TestParameters & parameters)2684 ContentsPrimarySecondaryCmdBufferResuming::ContentsPrimarySecondaryCmdBufferResuming (Context&				context,
2685 																					  const TestParameters&	parameters)
2686 	: DynamicRenderingTestInstance(context, parameters)
2687 {
2688 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2689 	const VkDevice			device	= m_context.getDevice();
2690 
2691 	m_secCmdBuffer	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2692 }
2693 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2694 void	ContentsPrimarySecondaryCmdBufferResuming::rendering (const VkPipeline					pipeline,
2695 															  const std::vector<VkImageView>&	attachmentBindInfos,
2696 															  const deUint32					colorAtchCount,
2697 															  ImagesLayout&						imagesLayout,
2698 															  const ImagesFormat&				imagesFormat)
2699 {
2700 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2701 	const VkDevice			device	= m_context.getDevice();
2702 	const VkQueue			queue	= m_context.getUniversalQueue();
2703 
2704 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
2705 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2706 	{
2707 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
2708 		const VkDeviceSize	vertexBufferOffset	= 0ull;
2709 
2710 		// secCmdBuffer
2711 		beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2712 
2713 		vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2714 		vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2715 
2716 		vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 4u, 0u);
2717 
2718 		VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2719 
2720 		// Primary commandBuffer
2721 		beginCommandBuffer(vk, *m_cmdBuffer);
2722 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
2723 
2724 		beginRenderingKHR(*m_cmdBuffer,
2725 						  attachmentBindInfos,
2726 						  VK_RENDERING_SUSPENDING_BIT_KHR,
2727 						  colorAtchCount,
2728 						  imagesFormat,
2729 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2730 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2731 
2732 		vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2733 		vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2734 
2735 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
2736 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
2737 
2738 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2739 
2740 		beginRenderingKHR(*m_cmdBuffer,
2741 						  attachmentBindInfos,
2742 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2743 						  VK_RENDERING_RESUMING_BIT_KHR,
2744 						  colorAtchCount,
2745 						  imagesFormat,
2746 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2747 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2748 
2749 		vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2750 
2751 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2752 
2753 		copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2754 
2755 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2756 
2757 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2758 
2759 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2760 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2761 		{
2762 			verifyResults(colorAtchCount, imagesFormat);
2763 
2764 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2765 
2766 			// secCmdBuffer
2767 			beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2768 
2769 			if (clearData.colorDepthClear1.size() != 0)
2770 			{
2771 				vk.cmdClearAttachments(*m_secCmdBuffer,
2772 										static_cast<deUint32>(clearData.colorDepthClear1.size()),
2773 										clearData.colorDepthClear1.data(),
2774 										1, &clearData.rectColorDepth1);
2775 			}
2776 
2777 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2778 				vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2779 
2780 			VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2781 
2782 			// Primary commandBuffer
2783 			beginCommandBuffer(vk, *m_cmdBuffer);
2784 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
2785 
2786 			beginRenderingKHR(*m_cmdBuffer,
2787 							  attachmentBindInfos,
2788 							  VK_RENDERING_SUSPENDING_BIT_KHR,
2789 							  colorAtchCount,
2790 							  imagesFormat,
2791 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2792 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2793 
2794 			if (clearData.colorDepthClear2.size() != 0)
2795 			{
2796 				vk.cmdClearAttachments(*m_cmdBuffer,
2797 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
2798 										clearData.colorDepthClear2.data(),
2799 										1, &clearData.rectColorDepth2);
2800 			}
2801 
2802 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2803 				vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2804 
2805 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2806 
2807 			beginRenderingKHR(*m_cmdBuffer,
2808 							  attachmentBindInfos,
2809 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2810 							  VK_RENDERING_RESUMING_BIT_KHR,
2811 							  colorAtchCount,
2812 							  imagesFormat,
2813 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2814 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2815 
2816 			vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2817 
2818 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2819 
2820 			copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2821 
2822 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2823 
2824 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2825 
2826 			verifyResults(colorAtchCount, imagesFormat);
2827 		}
2828 	}
2829 }
2830 
2831 class ContentsSecondaryPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
2832 {
2833 public:
2834 			ContentsSecondaryPrimaryCmdBufferResuming	(Context&							context,
2835 														 const TestParameters&				parameters);
2836 protected:
2837 	void	rendering									(const VkPipeline					pipeline,
2838 														 const std::vector<VkImageView>&	attachmentBindInfos,
2839 														 const deUint32						colorAtchCount,
2840 														 ImagesLayout&						imagesLayout,
2841 														 const ImagesFormat&				imagesFormat) override;
2842 
2843 	Move<VkCommandBuffer>	m_secCmdBuffer;
2844 };
2845 
ContentsSecondaryPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)2846 ContentsSecondaryPrimaryCmdBufferResuming::ContentsSecondaryPrimaryCmdBufferResuming (Context&				context,
2847 																					  const TestParameters&	parameters)
2848 	: DynamicRenderingTestInstance(context, parameters)
2849 {
2850 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2851 	const VkDevice			device	= m_context.getDevice();
2852 
2853 	m_secCmdBuffer	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2854 }
2855 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2856 void	ContentsSecondaryPrimaryCmdBufferResuming::rendering (const VkPipeline					pipeline,
2857 															  const std::vector<VkImageView>&	attachmentBindInfos,
2858 															  const deUint32					colorAtchCount,
2859 															  ImagesLayout&						imagesLayout,
2860 															  const ImagesFormat&				imagesFormat)
2861 {
2862 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2863 	const VkDevice			device	= m_context.getDevice();
2864 	const VkQueue			queue	= m_context.getUniversalQueue();
2865 
2866 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
2867 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2868 	{
2869 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
2870 		const VkDeviceSize	vertexBufferOffset	= 0ull;
2871 
2872 		// secCmdBuffer
2873 		beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
2874 
2875 		vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2876 		vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2877 
2878 		vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 8u, 0u);
2879 		vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 0u, 0u);
2880 
2881 		VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2882 
2883 		// Primary commandBuffer
2884 		beginCommandBuffer(vk, *m_cmdBuffer);
2885 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
2886 
2887 		beginRenderingKHR(*m_cmdBuffer,
2888 						  attachmentBindInfos,
2889 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2890 						  VK_RENDERING_SUSPENDING_BIT_KHR,
2891 						  colorAtchCount,
2892 						  imagesFormat,
2893 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2894 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2895 
2896 		vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2897 
2898 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2899 
2900 		beginRenderingKHR(*m_cmdBuffer,
2901 						  attachmentBindInfos,
2902 						  VK_RENDERING_RESUMING_BIT_KHR,
2903 						  colorAtchCount,
2904 						  imagesFormat,
2905 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2906 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2907 
2908 		vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2909 		vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2910 
2911 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 4u, 0u);
2912 
2913 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
2914 
2915 		copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2916 
2917 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2918 
2919 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2920 
2921 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2922 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2923 		{
2924 			verifyResults(colorAtchCount, imagesFormat);
2925 
2926 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2927 
2928 			// secCmdBuffer
2929 			beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
2930 
2931 			if (clearData.colorDepthClear1.size() != 0)
2932 			{
2933 				vk.cmdClearAttachments(*m_secCmdBuffer,
2934 										static_cast<deUint32>(clearData.colorDepthClear1.size()),
2935 										clearData.colorDepthClear1.data(),
2936 										1, &clearData.rectColorDepth1);
2937 			}
2938 
2939 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2940 				vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2941 
2942 			VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2943 
2944 			// Primary commandBuffer
2945 			beginCommandBuffer(vk, *m_cmdBuffer);
2946 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
2947 
2948 			beginRenderingKHR(*m_cmdBuffer,
2949 							  attachmentBindInfos,
2950 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2951 							  VK_RENDERING_SUSPENDING_BIT_KHR,
2952 							  colorAtchCount,
2953 							  imagesFormat,
2954 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2955 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2956 
2957 			vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2958 
2959 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2960 
2961 			beginRenderingKHR(*m_cmdBuffer,
2962 							  attachmentBindInfos,
2963 							  VK_RENDERING_RESUMING_BIT_KHR,
2964 							  colorAtchCount,
2965 							  imagesFormat,
2966 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2967 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2968 
2969 			if (clearData.colorDepthClear2.size() != 0)
2970 			{
2971 				vk.cmdClearAttachments(*m_cmdBuffer,
2972 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
2973 										clearData.colorDepthClear2.data(),
2974 										1, &clearData.rectColorDepth2);
2975 			}
2976 
2977 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2978 				vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2979 
2980 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
2981 
2982 			copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2983 
2984 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2985 
2986 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2987 
2988 			verifyResults(colorAtchCount, imagesFormat);
2989 		}
2990 	}
2991 }
2992 
2993 class ContentsTwoPrimarySecondaryCmdBufferResuming : public DynamicRenderingTestInstance
2994 {
2995 public:
2996 			ContentsTwoPrimarySecondaryCmdBufferResuming	(Context&							context,
2997 															 const TestParameters&				parameters);
2998 protected:
2999 	void	rendering										(const VkPipeline					pipeline,
3000 															 const std::vector<VkImageView>&	attachmentBindInfos,
3001 															 const deUint32						colorAtchCount,
3002 															 ImagesLayout&						imagesLayout,
3003 															 const ImagesFormat&				imagesFormat) override;
3004 
3005 	Move<VkCommandBuffer>	m_cmdBuffer2;
3006 	Move<VkCommandBuffer>	m_secCmdBuffer;
3007 };
3008 
ContentsTwoPrimarySecondaryCmdBufferResuming(Context & context,const TestParameters & parameters)3009 ContentsTwoPrimarySecondaryCmdBufferResuming::ContentsTwoPrimarySecondaryCmdBufferResuming (Context&				context,
3010 																							const TestParameters&	parameters)
3011 	: DynamicRenderingTestInstance(context, parameters)
3012 {
3013 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
3014 	const VkDevice			device	= m_context.getDevice();
3015 
3016 	m_cmdBuffer2	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
3017 	m_secCmdBuffer	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
3018 }
3019 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)3020 void	ContentsTwoPrimarySecondaryCmdBufferResuming::rendering (const VkPipeline					pipeline,
3021 																 const std::vector<VkImageView>&	attachmentBindInfos,
3022 																 const deUint32						colorAtchCount,
3023 																 ImagesLayout&						imagesLayout,
3024 																 const ImagesFormat&				imagesFormat)
3025 {
3026 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
3027 	const VkDevice			device	= m_context.getDevice();
3028 	const VkQueue			queue	= m_context.getUniversalQueue();
3029 
3030 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
3031 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
3032 	{
3033 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
3034 		const VkDeviceSize	vertexBufferOffset	= 0ull;
3035 
3036 		// secCmdBuffer
3037 		beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
3038 
3039 		vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3040 		vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
3041 
3042 		vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 4u, 0u);
3043 
3044 		VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
3045 
3046 		// Primary commandBuffer
3047 		beginCommandBuffer(vk, *m_cmdBuffer);
3048 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
3049 
3050 		beginRenderingKHR(*m_cmdBuffer,
3051 						  attachmentBindInfos,
3052 						  VK_RENDERING_SUSPENDING_BIT_KHR,
3053 						  colorAtchCount,
3054 						  imagesFormat,
3055 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3056 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3057 
3058 		vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3059 		vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
3060 
3061 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
3062 		vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
3063 
3064 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
3065 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3066 
3067 		// Primary commandBuffer2
3068 		beginCommandBuffer(vk, *m_cmdBuffer2);
3069 
3070 		beginRenderingKHR(*m_cmdBuffer2,
3071 						  attachmentBindInfos,
3072 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
3073 						  VK_RENDERING_RESUMING_BIT_KHR,
3074 						  colorAtchCount,
3075 						  imagesFormat,
3076 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3077 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3078 
3079 		vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &(*m_secCmdBuffer));
3080 
3081 		vk.cmdEndRenderingKHR(*m_cmdBuffer2);
3082 
3083 		copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
3084 
3085 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
3086 
3087 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
3088 
3089 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
3090 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
3091 		{
3092 			verifyResults(colorAtchCount, imagesFormat);
3093 
3094 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
3095 
3096 			// secCmdBuffer
3097 			beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
3098 
3099 			if (clearData.colorDepthClear1.size() != 0)
3100 			{
3101 				vk.cmdClearAttachments(*m_secCmdBuffer,
3102 										static_cast<deUint32>(clearData.colorDepthClear1.size()),
3103 										clearData.colorDepthClear1.data(),
3104 										1, &clearData.rectColorDepth1);
3105 			}
3106 
3107 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
3108 				vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
3109 
3110 			VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
3111 
3112 			// Primary commandBuffer
3113 			beginCommandBuffer(vk, *m_cmdBuffer);
3114 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
3115 
3116 			beginRenderingKHR(*m_cmdBuffer,
3117 							  attachmentBindInfos,
3118 							  VK_RENDERING_SUSPENDING_BIT_KHR,
3119 							  colorAtchCount,
3120 							  imagesFormat,
3121 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3122 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3123 
3124 			if (clearData.colorDepthClear2.size() != 0)
3125 			{
3126 				vk.cmdClearAttachments(*m_cmdBuffer,
3127 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
3128 										clearData.colorDepthClear2.data(),
3129 										1, &clearData.rectColorDepth2);
3130 			}
3131 
3132 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
3133 				vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
3134 
3135 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
3136 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3137 
3138 			// Primary commandBuffer2
3139 			beginCommandBuffer(vk, *m_cmdBuffer2);
3140 
3141 			beginRenderingKHR(*m_cmdBuffer2,
3142 							  attachmentBindInfos,
3143 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
3144 							  VK_RENDERING_RESUMING_BIT_KHR,
3145 							  colorAtchCount,
3146 							  imagesFormat,
3147 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3148 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3149 
3150 			vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &(*m_secCmdBuffer));
3151 
3152 			vk.cmdEndRenderingKHR(*m_cmdBuffer2);
3153 
3154 			copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
3155 
3156 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
3157 
3158 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
3159 
3160 			verifyResults(colorAtchCount, imagesFormat);
3161 		}
3162 	}
3163 }
3164 
3165 class ContentsSecondaryTwoPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
3166 {
3167 public:
3168 			ContentsSecondaryTwoPrimaryCmdBufferResuming	(Context&							context,
3169 															 const TestParameters&				parameters);
3170 protected:
3171 	void	rendering										(const VkPipeline					pipeline,
3172 															 const std::vector<VkImageView>&	attachmentBindInfos,
3173 															 const deUint32						colorAtchCount,
3174 															 ImagesLayout&						imagesLayout,
3175 															 const ImagesFormat&				imagesFormat) override;
3176 
3177 	Move<VkCommandBuffer>	m_cmdBuffer2;
3178 	Move<VkCommandBuffer>	m_secCmdBuffer;
3179 };
3180 
ContentsSecondaryTwoPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)3181 ContentsSecondaryTwoPrimaryCmdBufferResuming::ContentsSecondaryTwoPrimaryCmdBufferResuming (Context&				context,
3182 																							const TestParameters&	parameters)
3183 	: DynamicRenderingTestInstance(context, parameters)
3184 {
3185 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
3186 	const VkDevice			device	= m_context.getDevice();
3187 
3188 	m_cmdBuffer2	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
3189 	m_secCmdBuffer	= allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
3190 }
3191 
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const deUint32 colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)3192 void	ContentsSecondaryTwoPrimaryCmdBufferResuming::rendering (const VkPipeline					pipeline,
3193 																 const std::vector<VkImageView>&	attachmentBindInfos,
3194 																 const deUint32						colorAtchCount,
3195 																 ImagesLayout&						imagesLayout,
3196 																 const ImagesFormat&				imagesFormat)
3197 {
3198 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
3199 	const VkDevice			device	= m_context.getDevice();
3200 	const VkQueue			queue	= m_context.getUniversalQueue();
3201 
3202 	for (deUint32 attachmentLoadOp  = 0; attachmentLoadOp  < TEST_ATTACHMENT_LOAD_OP_LAST;  ++attachmentLoadOp)
3203 	for (deUint32 attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
3204 	{
3205 		const VkBuffer		vertexBuffer		= m_vertexBuffer->object();
3206 		const VkDeviceSize	vertexBufferOffset	= 0ull;
3207 
3208 		// secCmdBuffer
3209 		beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
3210 
3211 		vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3212 		vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
3213 
3214 		vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 8u, 0u);
3215 		vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 0u, 0u);
3216 
3217 		VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
3218 
3219 		// Primary commandBuffer
3220 		beginCommandBuffer(vk, *m_cmdBuffer);
3221 		preBarier(colorAtchCount, imagesLayout, imagesFormat);
3222 
3223 		beginRenderingKHR(*m_cmdBuffer,
3224 						  attachmentBindInfos,
3225 						  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
3226 						  VK_RENDERING_SUSPENDING_BIT_KHR,
3227 						  colorAtchCount,
3228 						  imagesFormat,
3229 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3230 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3231 
3232 		vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
3233 
3234 		vk.cmdEndRenderingKHR(*m_cmdBuffer);
3235 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3236 
3237 		// Primary commandBuffer2
3238 		beginCommandBuffer(vk, *m_cmdBuffer2);
3239 
3240 		beginRenderingKHR(*m_cmdBuffer2,
3241 						  attachmentBindInfos,
3242 						  VK_RENDERING_RESUMING_BIT_KHR,
3243 						  colorAtchCount,
3244 						  imagesFormat,
3245 						  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3246 						  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3247 
3248 		vk.cmdBindPipeline(*m_cmdBuffer2, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3249 		vk.cmdBindVertexBuffers(*m_cmdBuffer2, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
3250 
3251 		vk.cmdDraw(*m_cmdBuffer2, 4u, 1u, 4u, 0u);
3252 
3253 		vk.cmdEndRenderingKHR(*m_cmdBuffer2);
3254 
3255 		copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
3256 
3257 		VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
3258 
3259 		submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
3260 
3261 		if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp)   == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
3262 			(static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
3263 		{
3264 			verifyResults(colorAtchCount, imagesFormat);
3265 
3266 			const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
3267 
3268 			// secCmdBuffer
3269 			beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
3270 
3271 			if (clearData.colorDepthClear1.size() != 0)
3272 			{
3273 				vk.cmdClearAttachments(*m_secCmdBuffer,
3274 										static_cast<deUint32>(clearData.colorDepthClear1.size()),
3275 										clearData.colorDepthClear1.data(),
3276 										1, &clearData.rectColorDepth1);
3277 			}
3278 
3279 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
3280 				vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
3281 
3282 			VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
3283 
3284 			// Primary commandBuffer
3285 			beginCommandBuffer(vk, *m_cmdBuffer);
3286 			preBarier(colorAtchCount, imagesLayout, imagesFormat);
3287 
3288 			beginRenderingKHR(*m_cmdBuffer,
3289 							  attachmentBindInfos,
3290 							  VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
3291 							  VK_RENDERING_SUSPENDING_BIT_KHR,
3292 							  colorAtchCount,
3293 							  imagesFormat,
3294 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3295 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3296 
3297 			vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
3298 
3299 			vk.cmdEndRenderingKHR(*m_cmdBuffer);
3300 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3301 
3302 			// Primary commandBuffer2
3303 			beginCommandBuffer(vk, *m_cmdBuffer2);
3304 
3305 			beginRenderingKHR(*m_cmdBuffer2,
3306 							  attachmentBindInfos,
3307 							  VK_RENDERING_RESUMING_BIT_KHR,
3308 							  colorAtchCount,
3309 							  imagesFormat,
3310 							  static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3311 							  static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3312 
3313 			if (clearData.colorDepthClear2.size() != 0)
3314 			{
3315 				vk.cmdClearAttachments(*m_cmdBuffer2,
3316 										static_cast<deUint32>(clearData.colorDepthClear2.size()),
3317 										clearData.colorDepthClear2.data(),
3318 										1, &clearData.rectColorDepth2);
3319 			}
3320 
3321 			if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
3322 				vk.cmdClearAttachments(*m_cmdBuffer2, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
3323 
3324 			vk.cmdEndRenderingKHR(*m_cmdBuffer2);
3325 
3326 			copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
3327 
3328 			VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
3329 
3330 			submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
3331 
3332 			verifyResults(colorAtchCount, imagesFormat);
3333 		}
3334 	}
3335 }
3336 
3337 class BaseTestCase : public TestCase
3338 {
3339 public:
3340 							BaseTestCase	(tcu::TestContext&		context,
3341 											 const std::string&		name,
3342 											 const std::string&		description,
3343 											 const TestParameters&	parameters);
3344 	virtual					~BaseTestCase	(void);
3345 
3346 protected:
3347 	virtual void			checkSupport	(Context&				context) const;
3348 	virtual void			initPrograms	(SourceCollections&		programCollection) const;
3349 	virtual TestInstance*	createInstance	(Context&				context) const;
3350 
3351 	const TestParameters	m_parameters;
3352 };
3353 
BaseTestCase(tcu::TestContext & context,const std::string & name,const std::string & description,const TestParameters & parameters)3354 BaseTestCase::BaseTestCase (tcu::TestContext&		context,
3355 							const std::string&		name,
3356 							const std::string&		description,
3357 							const TestParameters&	parameters)
3358 	: TestCase		(context, name, description)
3359 	, m_parameters	(parameters)
3360 {
3361 }
3362 
~BaseTestCase()3363 BaseTestCase::~BaseTestCase ()
3364 {
3365 }
3366 
checkSupport(Context & context) const3367 void BaseTestCase::checkSupport (Context& context) const
3368 {
3369 	if(!context.requireDeviceFunctionality("VK_KHR_dynamic_rendering"))
3370 		TCU_THROW(NotSupportedError, "VK_KHR_dynamic_rendering not supported");
3371 }
3372 
initPrograms(SourceCollections & programCollection) const3373 void BaseTestCase::initPrograms (SourceCollections& programCollection) const
3374 {
3375 	// Vertex
3376 	{
3377 		std::ostringstream src;
3378 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
3379 			<< "\n"
3380 			<< "layout(location = 0) in highp vec4 position;\n"
3381 			<< "layout(location = 0) out highp vec4 vsColor;\n"
3382 			<< "\n"
3383 			<< "out gl_PerVertex {\n"
3384 			<< "   vec4 gl_Position;\n"
3385 			<< "};\n"
3386 			<< "\n"
3387 			<< "void main (void)\n"
3388 			<< "{\n"
3389 			<< "    gl_Position = position;\n"
3390 			<< "    vsColor     = vec4(gl_Position.z * 5.0f, 1.0f, 0.0f, 1.0f);\n"
3391 			<< "}\n";
3392 		programCollection.glslSources.add("vert") << glu::VertexSource(src.str());
3393 	}
3394 
3395 	// Fragment multi color attachment
3396 	{
3397 		std::ostringstream src;
3398 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
3399 			<< "\n"
3400 			<< "layout(location = 0) in highp vec4 vsColor;\n";
3401 
3402 			for (deUint32 ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ++ndx)
3403 				src << "layout(location = " << ndx << ") out highp vec4 fsColor" << ndx << ";\n";
3404 
3405 		src << "\n"
3406 			<< "void main (void)\n"
3407 			<< "{\n"
3408 			<< "    vec4 color   = vsColor;\n";
3409 		for (deUint32 ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ++ndx)
3410 		{
3411 			src << "    color.z      = 0.15f * " << ndx << ".0f;\n"
3412 				<< "    fsColor" << ndx << "     = color;\n";
3413 		}
3414 		src << "}\n";
3415 		programCollection.glslSources.add("frag") << glu::FragmentSource(src.str());
3416 	}
3417 }
3418 
createInstance(Context & context) const3419 TestInstance*	BaseTestCase::createInstance (Context& context) const
3420 {
3421 	switch(m_parameters.testType)
3422 	{
3423 		case TEST_TYPE_SINGLE_CMDBUF:
3424 		{
3425 			return new DynamicRenderingTestInstance(context, m_parameters);
3426 		}
3427 		case TEST_TYPE_SINGLE_CMDBUF_RESUMING:
3428 		{
3429 			return new SingleCmdBufferResuming(context, m_parameters);
3430 		}
3431 		case TEST_TYPE_TWO_CMDBUF_RESUMING:
3432 		{
3433 			return new TwoPrimaryCmdBufferResuming(context, m_parameters);
3434 		}
3435 		case TEST_TYPE_SECONDARY_CMDBUF_RESUMING:
3436 		{
3437 			return new TwoSecondaryCmdBufferResuming(context, m_parameters);
3438 		}
3439 		case TEST_TYPE_SECONDARY_CMDBUF_TWO_PRIMARY_RESUMING:
3440 		{
3441 			return new TwoSecondaryTwoPrimaryCmdBufferResuming(context, m_parameters);
3442 		}
3443 		case TEST_TYPE_CONTENTS_SECONDARY_COMMAND_BUFFER:
3444 		{
3445 			return new ContentsSecondaryCmdBuffer(context, m_parameters);
3446 		}
3447 		case TEST_TYPE_CONTENTS_2_SECONDARY_COMMAND_BUFFER:
3448 		{
3449 			return new ContentsTwoSecondaryCmdBuffer(context, m_parameters);
3450 		}
3451 		case TEST_TYPE_CONTENTS_2_SECONDARY_COMMAND_BUFFER_RESUMING:
3452 		{
3453 			return new ContentsTwoSecondaryCmdBufferResuming(context, m_parameters);
3454 		}
3455 		case TEST_TYPE_CONTENTS_2_SECONDARY_2_PRIMARY_COMDBUF_RESUMING:
3456 		{
3457 			return new ContentsTwoSecondaryTwoPrimaryCmdBufferResuming(context, m_parameters);
3458 		}
3459 		case TEST_TYPE_CONTENTS_PRIMARY_SECONDARY_COMDBUF_RESUMING:
3460 		{
3461 			return new ContentsPrimarySecondaryCmdBufferResuming(context, m_parameters);
3462 		}
3463 		case TEST_TYPE_CONTENTS_SECONDARY_PRIMARY_COMDBUF_RESUMING:
3464 		{
3465 			return new ContentsSecondaryPrimaryCmdBufferResuming(context, m_parameters);
3466 		}
3467 		case TEST_TYPE_CONTENTS_2_PRIMARY_SECONDARY_COMDBUF_RESUMING:
3468 		{
3469 			return new ContentsTwoPrimarySecondaryCmdBufferResuming(context, m_parameters);
3470 		}
3471 		case TEST_TYPE_CONTENTS_SECONDARY_2_PRIMARY_COMDBUF_RESUMING:
3472 		{
3473 			return new ContentsSecondaryTwoPrimaryCmdBufferResuming(context, m_parameters);
3474 		}
3475 		default:
3476 			DE_FATAL("Impossible");
3477 	}
3478 	return nullptr;
3479 }
3480 
dynamicRenderingTests(tcu::TestContext & testCtx,const TestParameters & parameters)3481 tcu::TestNode* dynamicRenderingTests (tcu::TestContext& testCtx, const TestParameters& parameters)
3482 {
3483 	const std::string testName[TEST_TYPE_LAST] =
3484 	{
3485 		"single_cmdbuffer",
3486 		"single_cmdbuffer_resuming",
3487 		"2_cmdbuffers_resuming",
3488 		"2_secondary_cmdbuffers_resuming",
3489 		"2_secondary_2_primary_cmdbuffers_resuming",
3490 		"contents_secondary_cmdbuffers",
3491 		"contents_2_secondary_cmdbuffers",
3492 		"contents_2_secondary_cmdbuffers_resuming",
3493 		"contents_2_secondary_2_primary_cmdbuffers_resuming",
3494 		"contents_primary_secondary_cmdbuffers_resuming",
3495 		"contents_secondary_primary_cmdbuffers_resuming",
3496 		"contents_2_primary_secondary_cmdbuffers_resuming",
3497 		"contents_secondary_2_primary_cmdbuffers_resuming",
3498 	};
3499 
3500 	return new BaseTestCase(testCtx, testName[parameters.testType], "Dynamic Rendering tests", parameters);
3501 }
3502 
3503 }	// anonymous
3504 
createDynamicRenderingBasicTests(tcu::TestContext & testCtx)3505 tcu::TestCaseGroup* createDynamicRenderingBasicTests(tcu::TestContext& testCtx)
3506 {
3507 	de::MovePtr<tcu::TestCaseGroup> dynamicRenderingGroup (new tcu::TestCaseGroup(testCtx, "basic", "Basic dynamic rendering tests"));
3508 
3509 	for (int testType = 0; testType < TEST_TYPE_LAST; ++testType)
3510 	{
3511 		const TestParameters	parameters =
3512 		{
3513 			static_cast<TestType>(testType),	// TestType			testType;
3514 			Vec4(0.0f, 0.0f, 0.0f, 1.0f),		// const Vec4		clearColor;
3515 			VK_FORMAT_R8G8B8A8_UNORM,			// const VkFormat	imageFormat;
3516 			(UVec2(32, 32))						// const UVec2		renderSize;
3517 		};
3518 
3519 		dynamicRenderingGroup->addChild(dynamicRenderingTests(testCtx, parameters));
3520 	}
3521 
3522 	return dynamicRenderingGroup.release();
3523 }
3524 
3525 } // renderpass
3526 } // vkt
3527