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