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