• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2019 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 Imageless Framebuffer Tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktImagelessFramebufferTests.hpp"
25 #include "vktTestGroupUtil.hpp"
26 #include "vktTestCase.hpp"
27 
28 #include "deUniquePtr.hpp"
29 #include "deRandom.hpp"
30 
31 #include "tcuTextureUtil.hpp"
32 #include "tcuVectorUtil.hpp"
33 #include "tcuImageCompare.hpp"
34 #include "tcuRGBA.hpp"
35 
36 #include "vkCmdUtil.hpp"
37 #include "vkImageUtil.hpp"
38 #include "vkObjUtil.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkRefUtil.hpp"
41 #include "vkTypeUtil.hpp"
42 #include "vkBuilderUtil.hpp"
43 
44 #include <iostream>
45 
46 namespace vkt
47 {
48 namespace imageless
49 {
50 
51 namespace
52 {
53 using namespace vk;
54 using de::MovePtr;
55 using de::UniquePtr;
56 using de::SharedPtr;
57 
58 typedef SharedPtr<Unique<VkPipeline> >	SharedPtrVkPipeline;
59 
60 enum TestType
61 {
62 	TEST_TYPE_COLOR = 0,
63 	TEST_TYPE_DEPTH_STENCIL,
64 	TEST_TYPE_COLOR_RESOLVE,
65 	TEST_TYPE_DEPTH_STENCIL_RESOLVE,
66 	TEST_TYPE_MULTISUBPASS,
67 	TEST_TYPE_LAST
68 };
69 
70 enum AspectFlagBits
71 {
72 	ASPECT_NONE				= 0,
73 	ASPECT_COLOR			= (1<<0),
74 	ASPECT_DEPTH			= (1<<1),
75 	ASPECT_STENCIL			= (1<<2),
76 	ASPECT_DEPTH_STENCIL	= ASPECT_DEPTH | ASPECT_STENCIL,
77 };
78 typedef deUint32 AspectFlags;
79 
80 const deUint32	NO_SAMPLE	= static_cast<deUint32>(-1);
81 const deUint32	NO_SUBPASS	= static_cast<deUint32>(-1);
82 
83 struct TestParameters
84 {
85 	TestType	testType;
86 	VkFormat	colorFormat;
87 	VkFormat	dsFormat;
88 };
89 
90 template<typename T>
makeSharedPtr(Move<T> move)91 inline SharedPtr<Unique<T> > makeSharedPtr (Move<T> move)
92 {
93 	return SharedPtr<Unique<T> >(new Unique<T>(move));
94 }
95 
sampleCountBitFromSampleCount(deUint32 count)96 VkSampleCountFlagBits sampleCountBitFromSampleCount (deUint32 count)
97 {
98 	switch (count)
99 	{
100 		case 1:  return VK_SAMPLE_COUNT_1_BIT;
101 		case 2:  return VK_SAMPLE_COUNT_2_BIT;
102 		case 4:  return VK_SAMPLE_COUNT_4_BIT;
103 		case 8:  return VK_SAMPLE_COUNT_8_BIT;
104 		case 16: return VK_SAMPLE_COUNT_16_BIT;
105 		case 32: return VK_SAMPLE_COUNT_32_BIT;
106 		case 64: return VK_SAMPLE_COUNT_64_BIT;
107 
108 		default:
109 			DE_FATAL("Invalid sample count");
110 			return (VkSampleCountFlagBits)0x0;
111 	}
112 }
113 
convertAttachmentReference(const VkAttachmentReference & attachmentReference,const VkImageAspectFlags aspectMask)114 VkAttachmentReference2 convertAttachmentReference (const VkAttachmentReference& attachmentReference, const VkImageAspectFlags aspectMask)
115 {
116 	const VkAttachmentReference2	attachmentReference2	=
117 	{
118 		VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2,		//  VkStructureType		sType;
119 		DE_NULL,										//  const void*			pNext;
120 		attachmentReference.attachment,					//  deUint32			attachment;
121 		attachmentReference.layout,						//  VkImageLayout		layout;
122 		aspectMask										//  VkImageAspectFlags	aspectMask;
123 	};
124 
125 	return attachmentReference2;
126 }
127 
convertAttachmentDescriptions(const std::vector<VkAttachmentDescription> & attachmentDescriptions)128 std::vector<VkAttachmentDescription2> convertAttachmentDescriptions (const std::vector<VkAttachmentDescription>& attachmentDescriptions)
129 {
130 	std::vector<VkAttachmentDescription2>	attachmentDescriptions2;
131 
132 	attachmentDescriptions2.reserve(attachmentDescriptions.size());
133 
134 	for (size_t adNdx = 0; adNdx < attachmentDescriptions.size(); ++adNdx)
135 	{
136 		const VkAttachmentDescription&		attachmentDescription	= attachmentDescriptions[adNdx];
137 		const VkAttachmentDescription2		attachmentDescription2	=
138 		{
139 			VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,		//  VkStructureType					sType;
140 			DE_NULL,										//  const void*						pNext;
141 			attachmentDescription.flags,					//  VkAttachmentDescriptionFlags	flags;
142 			attachmentDescription.format,					//  VkFormat						format;
143 			attachmentDescription.samples,					//  VkSampleCountFlagBits			samples;
144 			attachmentDescription.loadOp,					//  VkAttachmentLoadOp				loadOp;
145 			attachmentDescription.storeOp,					//  VkAttachmentStoreOp				storeOp;
146 			attachmentDescription.stencilLoadOp,			//  VkAttachmentLoadOp				stencilLoadOp;
147 			attachmentDescription.stencilStoreOp,			//  VkAttachmentStoreOp				stencilStoreOp;
148 			attachmentDescription.initialLayout,			//  VkImageLayout					initialLayout;
149 			attachmentDescription.finalLayout,				//  VkImageLayout					finalLayout;
150 		};
151 
152 		attachmentDescriptions2.push_back(attachmentDescription2);
153 	}
154 
155 	return attachmentDescriptions2;
156 }
157 
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkRenderPass renderPass,const VkShaderModule vertexModule,const VkShaderModule fragmendModule,const VkExtent2D renderSize,const AspectFlags depthStencilAspects=ASPECT_NONE,const VkSampleCountFlagBits sampleCountBits=VK_SAMPLE_COUNT_1_BIT,const deUint32 subpass=0)158 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface&		vk,
159 									   const VkDevice				device,
160 									   const VkPipelineLayout		pipelineLayout,
161 									   const VkRenderPass			renderPass,
162 									   const VkShaderModule			vertexModule,
163 									   const VkShaderModule			fragmendModule,
164 									   const VkExtent2D				renderSize,
165 									   const AspectFlags			depthStencilAspects	= ASPECT_NONE,
166 									   const VkSampleCountFlagBits	sampleCountBits		= VK_SAMPLE_COUNT_1_BIT,
167 									   const deUint32				subpass				= 0)
168 {
169 	const bool									useDepth						= (depthStencilAspects & ASPECT_DEPTH) != 0;
170 	const bool									useStencil						= (depthStencilAspects & ASPECT_STENCIL) != 0;
171 	const std::vector<VkViewport>				viewports						(1, makeViewport(renderSize));
172 	const std::vector<VkRect2D>					scissors						(1, makeRect2D(renderSize));
173 	const VkStencilOpState						stencilOpState					=
174 	{
175 		VK_STENCIL_OP_KEEP,					//  VkStencilOp	failOp;
176 		VK_STENCIL_OP_INCREMENT_AND_CLAMP,	//  VkStencilOp	passOp;
177 		VK_STENCIL_OP_KEEP,					//  VkStencilOp	depthFailOp;
178 		VK_COMPARE_OP_ALWAYS,				//  VkCompareOp	compareOp;
179 		~0u,								//  deUint32	compareMask;
180 		~0u,								//  deUint32	writeMask;
181 		0u									//  deUint32	reference;
182 	};
183 	const VkPipelineDepthStencilStateCreateInfo	pipelineDepthStencilStateInfo	=
184 	{
185 		VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,	//  VkStructureType							sType;
186 		DE_NULL,													//  const void*								pNext;
187 		(VkPipelineDepthStencilStateCreateFlags)0,					//  VkPipelineDepthStencilStateCreateFlags	flags;
188 		useDepth ? VK_TRUE : VK_FALSE,								//  VkBool32								depthTestEnable;
189 		useDepth ? VK_TRUE : VK_FALSE,								//  VkBool32								depthWriteEnable;
190 		VK_COMPARE_OP_LESS,											//  VkCompareOp								depthCompareOp;
191 		VK_FALSE,													//  VkBool32								depthBoundsTestEnable;
192 		useStencil ? VK_TRUE : VK_FALSE,							//  VkBool32								stencilTestEnable;
193 		stencilOpState,												//  VkStencilOpState						front;
194 		stencilOpState,												//  VkStencilOpState						back;
195 		0.0f,														//  float									minDepthBounds;
196 		1.0f														//  float									maxDepthBounds;
197 	};
198 	const VkPipelineMultisampleStateCreateInfo	multisampleState				=
199 	{
200 		VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,	//  VkStructureType							sType;
201 		DE_NULL,													//  const void*								pNext;
202 		(VkPipelineMultisampleStateCreateFlags)0u,					//  VkPipelineMultisampleStateCreateFlags	flags;
203 		sampleCountBits,											//  VkSampleCountFlagBits					rasterizationSamples;
204 		VK_FALSE,													//  VkBool32								sampleShadingEnable;
205 		0.0f,														//  float									minSampleShading;
206 		DE_NULL,													//  const VkSampleMask*						pSampleMask;
207 		VK_FALSE,													//  VkBool32								alphaToCoverageEnable;
208 		VK_FALSE,													//  VkBool32								alphaToOneEnable;
209 	};
210 
211 	return makeGraphicsPipeline(vk,									//  const DeviceInterface&							vk
212 								device,								//  const VkDevice									device
213 								pipelineLayout,						//  const VkPipelineLayout							pipelineLayout
214 								vertexModule,						//  const VkShaderModule							vertexShaderModule
215 								DE_NULL,							//  const VkShaderModule							tessellationControlModule
216 								DE_NULL,							//  const VkShaderModule							tessellationEvalModule
217 								DE_NULL,							//  const VkShaderModule							geometryShaderModule
218 								fragmendModule,						//  const VkShaderModule							fragmentShaderModule
219 								renderPass,							//  const VkRenderPass								renderPass
220 								viewports,							//  const std::vector<VkViewport>&					viewports
221 								scissors,							//  const std::vector<VkRect2D>&					scissors
222 								VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,//  const VkPrimitiveTopology						topology
223 								subpass,							//  const deUint32									subpass
224 								0u,									//  const deUint32									patchControlPoints
225 								DE_NULL,							//  const VkPipelineVertexInputStateCreateInfo*		vertexInputStateCreateInfo
226 								DE_NULL,							//  const VkPipelineRasterizationStateCreateInfo*	rasterizationStateCreateInfo
227 								&multisampleState,					//  const VkPipelineMultisampleStateCreateInfo*		multisampleStateCreateInfo
228 								&pipelineDepthStencilStateInfo);	//  const VkPipelineDepthStencilStateCreateInfo*	depthStencilStateCreateInfo
229 }
230 
makeRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const VkFormat depthStencilFormat,const VkSampleCountFlagBits colorSamples,const VkSampleCountFlagBits depthStencilSamples=VK_SAMPLE_COUNT_1_BIT,const VkAttachmentLoadOp loadOperation=VK_ATTACHMENT_LOAD_OP_CLEAR,const VkImageLayout finalLayoutColor=VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,const VkImageLayout finalLayoutDepthStencil=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,const VkImageLayout subpassLayoutColor=VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,const VkImageLayout subpassLayoutDepthStencil=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,const VkAllocationCallbacks * const allocationCallbacks=DE_NULL)231 Move<VkRenderPass> makeRenderPass (const DeviceInterface&				vk,
232 								   const VkDevice						device,
233 								   const VkFormat						colorFormat,
234 								   const VkFormat						depthStencilFormat,
235 								   const VkSampleCountFlagBits			colorSamples,
236 								   const VkSampleCountFlagBits			depthStencilSamples			= VK_SAMPLE_COUNT_1_BIT,
237 								   const VkAttachmentLoadOp				loadOperation				= VK_ATTACHMENT_LOAD_OP_CLEAR,
238 								   const VkImageLayout					finalLayoutColor			= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
239 								   const VkImageLayout					finalLayoutDepthStencil		= VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
240 								   const VkImageLayout					subpassLayoutColor			= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
241 								   const VkImageLayout					subpassLayoutDepthStencil	= VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
242 								   const VkAllocationCallbacks* const	allocationCallbacks			= DE_NULL)
243 {
244 	const bool								hasColor									= colorFormat != VK_FORMAT_UNDEFINED;
245 	const bool								hasDepthStencil								= depthStencilFormat != VK_FORMAT_UNDEFINED;
246 	const bool								hasColorResolve								= hasColor && (colorSamples != VK_SAMPLE_COUNT_1_BIT);
247 	const bool								hasDepthStencilResolve						= hasDepthStencil && (depthStencilSamples != VK_SAMPLE_COUNT_1_BIT);
248 	const VkImageLayout						initialLayoutColor							= loadOperation == VK_ATTACHMENT_LOAD_OP_LOAD ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
249 	const VkImageLayout						initialLayoutDepthStencil					= loadOperation == VK_ATTACHMENT_LOAD_OP_LOAD ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
250 	const VkAttachmentDescription			colorAttachmentDescription					=
251 	{
252 		(VkAttachmentDescriptionFlags)0,		//  VkAttachmentDescriptionFlags	flags;
253 		colorFormat,							//  VkFormat						format;
254 		colorSamples,							//  VkSampleCountFlagBits			samples;
255 		loadOperation,							//  VkAttachmentLoadOp				loadOp;
256 		VK_ATTACHMENT_STORE_OP_STORE,			//  VkAttachmentStoreOp				storeOp;
257 		VK_ATTACHMENT_LOAD_OP_DONT_CARE,		//  VkAttachmentLoadOp				stencilLoadOp;
258 		VK_ATTACHMENT_STORE_OP_DONT_CARE,		//  VkAttachmentStoreOp				stencilStoreOp;
259 		initialLayoutColor,						//  VkImageLayout					initialLayout;
260 		finalLayoutColor						//  VkImageLayout					finalLayout;
261 	};
262 	const VkAttachmentDescription			depthStencilAttachmentDescription			=
263 	{
264 		(VkAttachmentDescriptionFlags)0,		//  VkAttachmentDescriptionFlags	flags;
265 		depthStencilFormat,						//  VkFormat						format;
266 		depthStencilSamples,					//  VkSampleCountFlagBits			samples;
267 		loadOperation,							//  VkAttachmentLoadOp				loadOp;
268 		VK_ATTACHMENT_STORE_OP_STORE,			//  VkAttachmentStoreOp				storeOp;
269 		loadOperation,							//  VkAttachmentLoadOp				stencilLoadOp;
270 		VK_ATTACHMENT_STORE_OP_STORE,			//  VkAttachmentStoreOp				stencilStoreOp;
271 		initialLayoutDepthStencil,				//  VkImageLayout					initialLayout;
272 		finalLayoutDepthStencil					//  VkImageLayout					finalLayout;
273 	};
274 	const VkAttachmentDescription			colorResolveAttachmentDescription			=
275 	{
276 		(VkAttachmentDescriptionFlags)0,		//  VkAttachmentDescriptionFlags	flags;
277 		colorFormat,							//  VkFormat						format;
278 		VK_SAMPLE_COUNT_1_BIT,					//  VkSampleCountFlagBits			samples;
279 		VK_ATTACHMENT_LOAD_OP_LOAD,				//  VkAttachmentLoadOp				loadOp;
280 		VK_ATTACHMENT_STORE_OP_STORE,			//  VkAttachmentStoreOp				storeOp;
281 		VK_ATTACHMENT_LOAD_OP_DONT_CARE,		//  VkAttachmentLoadOp				stencilLoadOp;
282 		VK_ATTACHMENT_STORE_OP_DONT_CARE,		//  VkAttachmentStoreOp				stencilStoreOp;
283 		initialLayoutColor,						//  VkImageLayout					initialLayout;
284 		finalLayoutColor						//  VkImageLayout					finalLayout;
285 	};
286 	const VkAttachmentDescription			depthStencilResolveAttachmentDescription	=
287 	{
288 		(VkAttachmentDescriptionFlags)0,		//  VkAttachmentDescriptionFlags	flags;
289 		depthStencilFormat,						//  VkFormat						format;
290 		VK_SAMPLE_COUNT_1_BIT,					//  VkSampleCountFlagBits			samples;
291 		VK_ATTACHMENT_LOAD_OP_LOAD,				//  VkAttachmentLoadOp				loadOp;
292 		VK_ATTACHMENT_STORE_OP_STORE,			//  VkAttachmentStoreOp				storeOp;
293 		VK_ATTACHMENT_LOAD_OP_LOAD,				//  VkAttachmentLoadOp				stencilLoadOp;
294 		VK_ATTACHMENT_STORE_OP_STORE,			//  VkAttachmentStoreOp				stencilStoreOp;
295 		initialLayoutDepthStencil,				//  VkImageLayout					initialLayout;
296 		finalLayoutDepthStencil					//  VkImageLayout					finalLayout;
297 	};
298 	std::vector<VkAttachmentDescription>	attachmentDescriptions;
299 
300 	if (hasColor)
301 		attachmentDescriptions.push_back(colorAttachmentDescription);
302 	if (hasDepthStencil)
303 		attachmentDescriptions.push_back(depthStencilAttachmentDescription);
304 	if (hasColorResolve)
305 		attachmentDescriptions.push_back(colorResolveAttachmentDescription);
306 	if (hasDepthStencilResolve)
307 		attachmentDescriptions.push_back(depthStencilResolveAttachmentDescription);
308 
309 	deUint32								attachmentCounter								= 0;
310 	const VkAttachmentReference				colorAttachmentRef								=
311 	{
312 		hasColor ? attachmentCounter++ : 0u,				//  deUint32		attachment;
313 		subpassLayoutColor									//  VkImageLayout	layout;
314 	};
315 	const VkAttachmentReference				depthStencilAttachmentRef						=
316 	{
317 		hasDepthStencil ? attachmentCounter++ : 0u,			//  deUint32		attachment;
318 		subpassLayoutDepthStencil							//  VkImageLayout	layout;
319 	};
320 	const VkAttachmentReference				colorResolveAttachmentRef						=
321 	{
322 		hasColorResolve ? attachmentCounter++ : 0u,			//  deUint32		attachment;
323 		subpassLayoutColor									//  VkImageLayout	layout;
324 	};
325 
326 	if (hasDepthStencilResolve)
327 	{
328 		const VkImageAspectFlags							colorAspectMask							= VK_IMAGE_ASPECT_COLOR_BIT;
329 		const VkImageAspectFlags							depthStencilAspectMask					= VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
330 		const VkAttachmentReference2						colorAttachmentRef2						= convertAttachmentReference(colorAttachmentRef, colorAspectMask);
331 		const VkAttachmentReference2						depthStencilAttachmentRef2				= convertAttachmentReference(depthStencilAttachmentRef, depthStencilAspectMask);
332 		const VkAttachmentReference2						colorResolveAttachmentRef2				= convertAttachmentReference(colorResolveAttachmentRef, colorAspectMask);
333 		const VkAttachmentReference2						depthStencilResolveAttachmentRef2		=
334 		{
335 			VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2,				//  VkStructureType		sType;
336 			DE_NULL,												//  const void*			pNext;
337 			hasDepthStencilResolve ? attachmentCounter++ : 0u,		//  deUint32			attachment;
338 			subpassLayoutDepthStencil,								//  VkImageLayout		layout;
339 			depthStencilAspectMask									//  VkImageAspectFlags	aspectMask;
340 		};
341 		const VkSubpassDescriptionDepthStencilResolve		subpassDescriptionDepthStencilResolve	=
342 		{
343 			VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE,		//  VkStructureType						sType;
344 			DE_NULL,															//  const void*							pNext;
345 			VK_RESOLVE_MODE_SAMPLE_ZERO_BIT,									//  VkResolveModeFlagBitsKHR			depthResolveMode;
346 			VK_RESOLVE_MODE_SAMPLE_ZERO_BIT,									//  VkResolveModeFlagBitsKHR			stencilResolveMode;
347 			&depthStencilResolveAttachmentRef2									//  const VkAttachmentReference2KHR*	pDepthStencilResolveAttachment;
348 		};
349 		const VkSubpassDescription2							subpassDescription2						=
350 		{
351 			VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2,					//  VkStructureType						sType;
352 			&subpassDescriptionDepthStencilResolve,						//  const void*							pNext;
353 			(VkSubpassDescriptionFlags)0,								//  VkSubpassDescriptionFlags			flags;
354 			VK_PIPELINE_BIND_POINT_GRAPHICS,							//  VkPipelineBindPoint					pipelineBindPoint;
355 			0u,															//  deUint32							viewMask;
356 			0u,															//  deUint32							inputAttachmentCount;
357 			DE_NULL,													//  const VkAttachmentReference2*		pInputAttachments;
358 			hasColor ? 1u : 0u,											//  deUint32							colorAttachmentCount;
359 			hasColor ? &colorAttachmentRef2 : DE_NULL,					//  const VkAttachmentReference2*		pColorAttachments;
360 			hasColorResolve ? &colorResolveAttachmentRef2 : DE_NULL,	//  const VkAttachmentReference2*		pResolveAttachments;
361 			hasDepthStencil ? &depthStencilAttachmentRef2 : DE_NULL,	//  const VkAttachmentReference2*		pDepthStencilAttachment;
362 			0u,															//  deUint32							preserveAttachmentCount;
363 			DE_NULL														//  const deUint32*						pPreserveAttachments;
364 		};
365 		const std::vector<VkAttachmentDescription2>			attachmentDescriptions2					= convertAttachmentDescriptions(attachmentDescriptions);
366 		const VkRenderPassCreateInfo2						renderPassInfo							=
367 		{
368 			VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2,		//  VkStructureType						sType;
369 			DE_NULL,											//  const void*							pNext;
370 			(VkRenderPassCreateFlags)0,							//  VkRenderPassCreateFlags				flags;
371 			(deUint32)attachmentDescriptions2.size(),			//  deUint32							attachmentCount;
372 			&attachmentDescriptions2[0],						//  const VkAttachmentDescription2*		pAttachments;
373 			1u,													//  deUint32							subpassCount;
374 			&subpassDescription2,								//  const VkSubpassDescription2*		pSubpasses;
375 			0u,													//  deUint32							dependencyCount;
376 			DE_NULL,											//  const VkSubpassDependency2*			pDependencies;
377 			0u,													//  deUint32							correlatedViewMaskCount;
378 			DE_NULL												//  const deUint32*						pCorrelatedViewMasks;
379 		};
380 
381 		return createRenderPass2(vk, device, &renderPassInfo, allocationCallbacks);
382 	}
383 	else
384 	{
385 		const VkSubpassDescription				subpassDescription							=
386 		{
387 			(VkSubpassDescriptionFlags)0,							//  VkSubpassDescriptionFlags		flags;
388 			VK_PIPELINE_BIND_POINT_GRAPHICS,						//  VkPipelineBindPoint				pipelineBindPoint;
389 			0u,														//  deUint32						inputAttachmentCount;
390 			DE_NULL,												//  const VkAttachmentReference*	pInputAttachments;
391 			hasColor ? 1u : 0u,										//  deUint32						colorAttachmentCount;
392 			hasColor ? &colorAttachmentRef : DE_NULL,				//  const VkAttachmentReference*	pColorAttachments;
393 			hasColorResolve ? &colorResolveAttachmentRef : DE_NULL,	//  const VkAttachmentReference*	pResolveAttachments;
394 			hasDepthStencil ? &depthStencilAttachmentRef : DE_NULL,	//  const VkAttachmentReference*	pDepthStencilAttachment;
395 			0u,														//  deUint32						preserveAttachmentCount;
396 			DE_NULL													//  const deUint32*					pPreserveAttachments;
397 		};
398 		const VkRenderPassCreateInfo			renderPassInfo								=
399 		{
400 			VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,	//  VkStructureType					sType;
401 			DE_NULL,									//  const void*						pNext;
402 			(VkRenderPassCreateFlags)0,					//  VkRenderPassCreateFlags			flags;
403 			(deUint32)attachmentDescriptions.size(),	//  deUint32						attachmentCount;
404 			&attachmentDescriptions[0],					//  const VkAttachmentDescription*	pAttachments;
405 			1u,											//  deUint32						subpassCount;
406 			&subpassDescription,						//  const VkSubpassDescription*		pSubpasses;
407 			0u,											//  deUint32						dependencyCount;
408 			DE_NULL										//  const VkSubpassDependency*		pDependencies;
409 		};
410 
411 		return createRenderPass(vk, device, &renderPassInfo, allocationCallbacks);
412 	}
413 }
414 
makeRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat,const VkAllocationCallbacks * const allocationCallbacks)415 Move<VkRenderPass> makeRenderPass (const DeviceInterface&				vk,
416 								   const VkDevice						device,
417 								   const VkFormat						colorFormat,
418 								   const VkAllocationCallbacks* const	allocationCallbacks)
419 {
420 	const VkAttachmentDescription	attachmentDescriptions[]	=
421 	{
422 		{
423 			(VkAttachmentDescriptionFlags)0,			//  VkAttachmentDescriptionFlags	flags;
424 			colorFormat,								//  VkFormat						format;
425 			VK_SAMPLE_COUNT_1_BIT,						//  VkSampleCountFlagBits			samples;
426 			VK_ATTACHMENT_LOAD_OP_CLEAR,				//  VkAttachmentLoadOp				loadOp;
427 			VK_ATTACHMENT_STORE_OP_STORE,				//  VkAttachmentStoreOp				storeOp;
428 			VK_ATTACHMENT_LOAD_OP_DONT_CARE,			//  VkAttachmentLoadOp				stencilLoadOp;
429 			VK_ATTACHMENT_STORE_OP_DONT_CARE,			//  VkAttachmentStoreOp				stencilStoreOp;
430 			VK_IMAGE_LAYOUT_UNDEFINED,					//  VkImageLayout					initialLayout;
431 			VK_IMAGE_LAYOUT_GENERAL						//  VkImageLayout					finalLayout;
432 		},
433 		{
434 			(VkAttachmentDescriptionFlags)0,			//  VkAttachmentDescriptionFlags	flags;
435 			colorFormat,								//  VkFormat						format;
436 			VK_SAMPLE_COUNT_1_BIT,						//  VkSampleCountFlagBits			samples;
437 			VK_ATTACHMENT_LOAD_OP_LOAD,					//  VkAttachmentLoadOp				loadOp;
438 			VK_ATTACHMENT_STORE_OP_STORE,				//  VkAttachmentStoreOp				storeOp;
439 			VK_ATTACHMENT_LOAD_OP_DONT_CARE,			//  VkAttachmentLoadOp				stencilLoadOp;
440 			VK_ATTACHMENT_STORE_OP_DONT_CARE,			//  VkAttachmentStoreOp				stencilStoreOp;
441 			VK_IMAGE_LAYOUT_UNDEFINED,					//  VkImageLayout					initialLayout;
442 			VK_IMAGE_LAYOUT_GENERAL						//  VkImageLayout					finalLayout;
443 		},
444 	};
445 	const VkAttachmentReference		colorAttachmentRef0			=
446 	{
447 		0u,							//  deUint32		attachment;
448 		VK_IMAGE_LAYOUT_GENERAL		//  VkImageLayout	layout;
449 	};
450 	const deUint32					preserveAttachment			= 1u;
451 	const VkAttachmentReference		inputAttachmentRef1			=
452 	{
453 		0u,							//  deUint32		attachment;
454 		VK_IMAGE_LAYOUT_GENERAL		//  VkImageLayout	layout;
455 	};
456 	const VkAttachmentReference		colorAttachmentRef1			=
457 	{
458 		1u,							//  deUint32		attachment;
459 		VK_IMAGE_LAYOUT_GENERAL		//  VkImageLayout	layout;
460 	};
461 	const VkSubpassDescription		subpassDescriptions[]		=
462 	{
463 		{
464 			(VkSubpassDescriptionFlags)0,				//  VkSubpassDescriptionFlags		flags;
465 			VK_PIPELINE_BIND_POINT_GRAPHICS,			//  VkPipelineBindPoint				pipelineBindPoint;
466 			0u,											//  deUint32						inputAttachmentCount;
467 			DE_NULL,									//  const VkAttachmentReference*	pInputAttachments;
468 			1u,											//  deUint32						colorAttachmentCount;
469 			&colorAttachmentRef0,						//  const VkAttachmentReference*	pColorAttachments;
470 			DE_NULL,									//  const VkAttachmentReference*	pResolveAttachments;
471 			DE_NULL,									//  const VkAttachmentReference*	pDepthStencilAttachment;
472 			1u,											//  deUint32						preserveAttachmentCount;
473 			&preserveAttachment							//  const deUint32*					pPreserveAttachments;
474 		},
475 		{
476 			(VkSubpassDescriptionFlags)0,				//  VkSubpassDescriptionFlags		flags;
477 			VK_PIPELINE_BIND_POINT_GRAPHICS,			//  VkPipelineBindPoint				pipelineBindPoint;
478 			1u,											//  deUint32						inputAttachmentCount;
479 			&inputAttachmentRef1,						//  const VkAttachmentReference*	pInputAttachments;
480 			1u,											//  deUint32						colorAttachmentCount;
481 			&colorAttachmentRef1,						//  const VkAttachmentReference*	pColorAttachments;
482 			DE_NULL,									//  const VkAttachmentReference*	pResolveAttachments;
483 			DE_NULL,									//  const VkAttachmentReference*	pDepthStencilAttachment;
484 			0u,											//  deUint32						preserveAttachmentCount;
485 			DE_NULL										//  const deUint32*					pPreserveAttachments;
486 		},
487 	};
488 	const VkSubpassDependency		subpassDependency			=
489 	{
490 		0,												//  deUint32						srcSubpass;
491 		1u,												//  deUint32						dstSubpass;
492 		VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,	//  VkPipelineStageFlags			srcStageMask;
493 		VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,			//  VkPipelineStageFlags			dstStageMask;
494 		VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,			//  VkAccessFlags					srcAccessMask;
495 		VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,			//  VkAccessFlags					dstAccessMask;
496 		VK_DEPENDENCY_VIEW_LOCAL_BIT,					//  VkDependencyFlags				dependencyFlags;
497 	};
498 	const VkRenderPassCreateInfo	renderPassInfo				=
499 	{
500 		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,		//  VkStructureType					sType;
501 		DE_NULL,										//  const void*						pNext;
502 		(VkRenderPassCreateFlags)0,						//  VkRenderPassCreateFlags			flags;
503 		DE_LENGTH_OF_ARRAY(attachmentDescriptions),		//  deUint32						attachmentCount;
504 		&attachmentDescriptions[0],						//  const VkAttachmentDescription*	pAttachments;
505 		DE_LENGTH_OF_ARRAY(subpassDescriptions),		//  deUint32						subpassCount;
506 		&subpassDescriptions[0],						//  const VkSubpassDescription*		pSubpasses;
507 		1u,												//  deUint32						dependencyCount;
508 		&subpassDependency								//  const VkSubpassDependency*		pDependencies;
509 	};
510 
511 	return createRenderPass(vk, device, &renderPassInfo, allocationCallbacks);
512 }
513 
makeImageCreateInfo(const VkFormat format,const VkExtent2D size,const VkImageUsageFlags usage,VkSampleCountFlagBits samples=VK_SAMPLE_COUNT_1_BIT)514 VkImageCreateInfo makeImageCreateInfo (const VkFormat format, const VkExtent2D size, const VkImageUsageFlags usage, VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT)
515 {
516 	const VkExtent3D		extent		= { size.width, size.height, 1u };
517 	const VkImageCreateInfo imageParams =
518 	{
519 		VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,			// VkStructureType			sType;
520 		DE_NULL,										// const void*				pNext;
521 		0u,												// VkImageCreateFlags		flags;
522 		VK_IMAGE_TYPE_2D,								// VkImageType				imageType;
523 		format,											// VkFormat					format;
524 		extent,											// VkExtent3D				extent;
525 		1u,												// deUint32					mipLevels;
526 		1u,												// deUint32					arrayLayers;
527 		samples,										// VkSampleCountFlagBits	samples;
528 		VK_IMAGE_TILING_OPTIMAL,						// VkImageTiling			tiling;
529 		usage,											// VkImageUsageFlags		usage;
530 		VK_SHARING_MODE_EXCLUSIVE,						// VkSharingMode			sharingMode;
531 		0u,												// deUint32					queueFamilyIndexCount;
532 		DE_NULL,										// const deUint32*			pQueueFamilyIndices;
533 		VK_IMAGE_LAYOUT_UNDEFINED,						// VkImageLayout			initialLayout;
534 	};
535 	return imageParams;
536 }
537 
makeFramebufferAttachmentImageInfos(const VkExtent2D & renderSize,const VkFormat * colorFormat,const VkImageUsageFlags colorUsage,const VkFormat * dsFormat,const VkImageUsageFlags dsUsage,const AspectFlags resolveAspects,const deUint32 inputAttachmentCount)538 std::vector<VkFramebufferAttachmentImageInfo> makeFramebufferAttachmentImageInfos (const VkExtent2D&			renderSize,
539 																				   const VkFormat*				colorFormat,
540 																				   const VkImageUsageFlags		colorUsage,
541 																				   const VkFormat*				dsFormat,
542 																				   const VkImageUsageFlags		dsUsage,
543 																				   const AspectFlags			resolveAspects,
544 																				   const deUint32				inputAttachmentCount)
545 {
546 	const bool										colorResolve					= (resolveAspects & ASPECT_COLOR) != 0;
547 	const bool										depthStencilResolve				= (resolveAspects & ASPECT_DEPTH_STENCIL) != 0;
548 	std::vector<VkFramebufferAttachmentImageInfo>	framebufferAttachmentImageInfos;
549 
550 	DE_ASSERT(colorFormat != DE_NULL);
551 	DE_ASSERT(dsFormat != DE_NULL);
552 
553 	if (*colorFormat != VK_FORMAT_UNDEFINED)
554 	{
555 		const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo		=
556 		{
557 			VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO,		//  VkStructureType		sType;
558 			DE_NULL,													//  const void*			pNext;
559 			(VkImageCreateFlags)0u,										//  VkImageCreateFlags	flags;
560 			colorUsage,													//  VkImageUsageFlags	usage;
561 			renderSize.width,											//  deUint32			width;
562 			renderSize.height,											//  deUint32			height;
563 			1u,															//  deUint32			layerCount;
564 			1u,															//  deUint32			viewFormatCount;
565 			colorFormat													//  const VkFormat*		pViewFormats;
566 		};
567 
568 		framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
569 	}
570 
571 	if (*dsFormat != VK_FORMAT_UNDEFINED)
572 	{
573 		const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo		=
574 		{
575 			VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO,		//  VkStructureType		sType;
576 			DE_NULL,													//  const void*			pNext;
577 			(VkImageCreateFlags)0u,										//  VkImageCreateFlags	flags;
578 			dsUsage,													//  VkImageUsageFlags	usage;
579 			renderSize.width,											//  deUint32			width;
580 			renderSize.height,											//  deUint32			height;
581 			1u,															//  deUint32			layerCount;
582 			1u,															//  deUint32			viewFormatCount;
583 			dsFormat													//  const VkFormat*		pViewFormats;
584 		};
585 
586 		framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
587 	}
588 
589 	if (colorResolve)
590 	{
591 		const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo		=
592 		{
593 			VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO,		//  VkStructureType		sType;
594 			DE_NULL,													//  const void*			pNext;
595 			(VkImageCreateFlags)0u,										//  VkImageCreateFlags	flags;
596 			colorUsage,													//  VkImageUsageFlags	usage;
597 			renderSize.width,											//  deUint32			width;
598 			renderSize.height,											//  deUint32			height;
599 			1u,															//  deUint32			layerCount;
600 			1u,															//  deUint32			viewFormatCount;
601 			colorFormat													//  const VkFormat*		pViewFormats;
602 		};
603 
604 		DE_ASSERT(*colorFormat != VK_FORMAT_UNDEFINED);
605 
606 		framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
607 	}
608 
609 	if (depthStencilResolve)
610 	{
611 		const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo		=
612 		{
613 			VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO,		//  VkStructureType		sType;
614 			DE_NULL,													//  const void*			pNext;
615 			(VkImageCreateFlags)0u,										//  VkImageCreateFlags	flags;
616 			dsUsage,													//  VkImageUsageFlags	usage;
617 			renderSize.width,											//  deUint32			width;
618 			renderSize.height,											//  deUint32			height;
619 			1u,															//  deUint32			layerCount;
620 			1u,															//  deUint32			viewFormatCount;
621 			dsFormat													//  const VkFormat*		pViewFormats;
622 		};
623 
624 		DE_ASSERT(*dsFormat != VK_FORMAT_UNDEFINED);
625 
626 		framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
627 	}
628 
629 	for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < inputAttachmentCount; ++inputAttachmentNdx)
630 	{
631 		const VkFramebufferAttachmentImageInfo framebufferAttachmentImageInfo		=
632 		{
633 			VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO,		//  VkStructureType		sType;
634 			DE_NULL,													//  const void*			pNext;
635 			(VkImageCreateFlags)0u,										//  VkImageCreateFlags	flags;
636 			colorUsage | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT,			//  VkImageUsageFlags	usage;
637 			renderSize.width,											//  deUint32			width;
638 			renderSize.height,											//  deUint32			height;
639 			1u,															//  deUint32			layerCount;
640 			1u,															//  deUint32			viewFormatCount;
641 			colorFormat													//  const VkFormat*		pViewFormats;
642 		};
643 
644 		framebufferAttachmentImageInfos.push_back(framebufferAttachmentImageInfo);
645 	}
646 
647 	return framebufferAttachmentImageInfos;
648 }
649 
makeFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const VkExtent2D & renderSize,const VkFormat * colorFormat,const VkImageUsageFlags colorUsage,const VkFormat * dsFormat,const VkImageUsageFlags dsUsage=static_cast<VkImageUsageFlags> (0),const AspectFlags resolveAspects=ASPECT_NONE,const deUint32 inputAttachmentCount=0)650 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface&			vk,
651 									 const VkDevice					device,
652 									 const VkRenderPass				renderPass,
653 									 const VkExtent2D&				renderSize,
654 									 const VkFormat*				colorFormat,
655 									 const VkImageUsageFlags		colorUsage,
656 									 const VkFormat*				dsFormat,
657 									 const VkImageUsageFlags		dsUsage					= static_cast<VkImageUsageFlags>(0),
658 									 const AspectFlags				resolveAspects			= ASPECT_NONE,
659 									 const deUint32					inputAttachmentCount	= 0)
660 {
661 	const std::vector<VkFramebufferAttachmentImageInfo>		framebufferAttachmentImageInfos		= makeFramebufferAttachmentImageInfos(renderSize, colorFormat, colorUsage, dsFormat, dsUsage, resolveAspects, inputAttachmentCount);
662 	const deUint32											attachmentCount						= static_cast<deUint32>(framebufferAttachmentImageInfos.size());
663 	const VkFramebufferAttachmentsCreateInfo				framebufferAttachmentsCreateInfo	=
664 	{
665 		VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO,		//  VkStructureType								sType;
666 		DE_NULL,													//  const void*									pNext;
667 		attachmentCount,											//  deUint32									attachmentImageInfoCount;
668 		&framebufferAttachmentImageInfos[0]							//  const VkFramebufferAttachmentImageInfo*		pAttachmentImageInfos;
669 	};
670 	const VkFramebufferCreateInfo							framebufferInfo	=
671 	{
672 		VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,					//  VkStructureType				sType;
673 		&framebufferAttachmentsCreateInfo,							//  const void*					pNext;
674 		VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT,						//  VkFramebufferCreateFlags	flags;
675 		renderPass,													//  VkRenderPass				renderPass;
676 		attachmentCount,											//  deUint32					attachmentCount;
677 		DE_NULL,													//  const VkImageView*			pAttachments;
678 		renderSize.width,											//  deUint32					width;
679 		renderSize.height,											//  deUint32					height;
680 		1u,															//  deUint32					layers;
681 	};
682 
683 	return createFramebuffer(vk, device, &framebufferInfo);
684 }
685 
makeVerifyFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const VkImageView colorAttachment,const VkExtent2D & renderSize,const deUint32 layers=1u)686 Move<VkFramebuffer> makeVerifyFramebuffer (const DeviceInterface&	vk,
687 										   const VkDevice			device,
688 										   const VkRenderPass		renderPass,
689 										   const VkImageView		colorAttachment,
690 										   const VkExtent2D&		renderSize,
691 										   const deUint32			layers = 1u)
692 {
693 	const VkFramebufferCreateInfo framebufferInfo = {
694 		VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,		//  VkStructureType				sType;
695 		DE_NULL,										//  const void*					pNext;
696 		(VkFramebufferCreateFlags)0,					//  VkFramebufferCreateFlags	flags;
697 		renderPass,										//  VkRenderPass				renderPass;
698 		1u,												//  deUint32					attachmentCount;
699 		&colorAttachment,								//  const VkImageView*			pAttachments;
700 		renderSize.width,								//  deUint32					width;
701 		renderSize.height,								//  deUint32					height;
702 		layers,											//  deUint32					layers;
703 	};
704 
705 	return createFramebuffer(vk, device, &framebufferInfo);
706 }
707 
makeVerifyPipelineLayout(const DeviceInterface & vk,const VkDevice device,const VkDescriptorSetLayout descriptorSetLayout)708 Move<VkPipelineLayout> makeVerifyPipelineLayout (const DeviceInterface&			vk,
709 												 const VkDevice					device,
710 												 const VkDescriptorSetLayout	descriptorSetLayout)
711 {
712 	const VkPushConstantRange			pushConstantRanges			=
713 	{
714 		VK_SHADER_STAGE_FRAGMENT_BIT,					//  VkShaderStageFlags				stageFlags;
715 		0u,												//  deUint32						offset;
716 		sizeof(deUint32)								//  deUint32						size;
717 	};
718 	const VkPipelineLayoutCreateInfo	pipelineLayoutCreateInfo	=
719 	{
720 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,	//  VkStructureType					sType;
721 		DE_NULL,										//  const void*						pNext;
722 		(VkPipelineLayoutCreateFlags)0,					//  VkPipelineLayoutCreateFlags		flags;
723 		1u,												//  deUint32						setLayoutCount;
724 		&descriptorSetLayout,							//  const VkDescriptorSetLayout*	pSetLayouts;
725 		1u,												//  deUint32						pushConstantRangeCount;
726 		&pushConstantRanges,							//  const VkPushConstantRange*		pPushConstantRanges;
727 	};
728 	return createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
729 }
730 
makeVerifyRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat colorFormat)731 Move<VkRenderPass> makeVerifyRenderPass (const DeviceInterface&	vk,
732 										 const VkDevice			device,
733 										 const VkFormat			colorFormat)
734 {
735 	return makeRenderPass(vk, device, colorFormat);
736 }
737 
makeImageMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkImageLayout oldLayout,const VkImageLayout newLayout,const VkImage image,const VkImageSubresourceRange subresourceRange)738 VkImageMemoryBarrier makeImageMemoryBarrier	(const VkAccessFlags			srcAccessMask,
739 											 const VkAccessFlags			dstAccessMask,
740 											 const VkImageLayout			oldLayout,
741 											 const VkImageLayout			newLayout,
742 											 const VkImage					image,
743 											 const VkImageSubresourceRange	subresourceRange)
744 {
745 	const VkImageMemoryBarrier barrier =
746 	{
747 		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,			// VkStructureType			sType;
748 		DE_NULL,										// const void*				pNext;
749 		srcAccessMask,									// VkAccessFlags			outputMask;
750 		dstAccessMask,									// VkAccessFlags			inputMask;
751 		oldLayout,										// VkImageLayout			oldLayout;
752 		newLayout,										// VkImageLayout			newLayout;
753 		VK_QUEUE_FAMILY_IGNORED,						// deUint32					srcQueueFamilyIndex;
754 		VK_QUEUE_FAMILY_IGNORED,						// deUint32					destQueueFamilyIndex;
755 		image,											// VkImage					image;
756 		subresourceRange,								// VkImageSubresourceRange	subresourceRange;
757 	};
758 	return barrier;
759 }
760 
makeBufferMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkBuffer buffer,const VkDeviceSize offset,const VkDeviceSize bufferSizeBytes)761 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags	srcAccessMask,
762 											   const VkAccessFlags	dstAccessMask,
763 											   const VkBuffer		buffer,
764 											   const VkDeviceSize	offset,
765 											   const VkDeviceSize	bufferSizeBytes)
766 {
767 	const VkBufferMemoryBarrier barrier =
768 	{
769 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,	//  VkStructureType	sType;
770 		DE_NULL,									//  const void*		pNext;
771 		srcAccessMask,								//  VkAccessFlags	srcAccessMask;
772 		dstAccessMask,								//  VkAccessFlags	dstAccessMask;
773 		VK_QUEUE_FAMILY_IGNORED,					//  deUint32		srcQueueFamilyIndex;
774 		VK_QUEUE_FAMILY_IGNORED,					//  deUint32		destQueueFamilyIndex;
775 		buffer,										//  VkBuffer		buffer;
776 		offset,										//  VkDeviceSize	offset;
777 		bufferSizeBytes,							//  VkDeviceSize	size;
778 	};
779 	return barrier;
780 }
781 
makeSampler(const DeviceInterface & vk,const VkDevice & device)782 Move<VkSampler> makeSampler (const DeviceInterface& vk, const VkDevice& device)
783 {
784 	const VkSamplerCreateInfo createInfo =
785 	{
786 		VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,		//  VkStructureType			sType;
787 		DE_NULL,									//  const void*				pNext;
788 		0u,											//  VkSamplerCreateFlags	flags;
789 		VK_FILTER_NEAREST,							//  VkFilter				magFilter;
790 		VK_FILTER_NEAREST,							//  VkFilter				minFilter;
791 		VK_SAMPLER_MIPMAP_MODE_LINEAR,				//  VkSamplerMipmapMode		mipmapMode;
792 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,		//  VkSamplerAddressMode	addressModeU;
793 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,		//  VkSamplerAddressMode	addressModeV;
794 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,		//  VkSamplerAddressMode	addressModeW;
795 		0.0f,										//  float					mipLodBias;
796 		VK_FALSE,									//  VkBool32				anisotropyEnable;
797 		1.0f,										//  float					maxAnisotropy;
798 		VK_FALSE,									//  VkBool32				compareEnable;
799 		VK_COMPARE_OP_ALWAYS,						//  VkCompareOp				compareOp;
800 		0.0f,										//  float					minLod;
801 		0.0f,										//  float					maxLod;
802 		VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,	//  VkBorderColor			borderColor;
803 		VK_FALSE									//  VkBool32				unnormalizedCoordinates;
804 	};
805 
806 	return createSampler(vk, device, &createInfo);
807 }
808 
fillBuffer(const DeviceInterface & vk,const VkDevice device,Allocation & bufferAlloc,const void * data,const VkDeviceSize dataSize)809 void fillBuffer (const DeviceInterface& vk, const VkDevice device, Allocation& bufferAlloc, const void* data, const VkDeviceSize dataSize)
810 {
811 	const VkMappedMemoryRange	memRange		=
812 	{
813 		VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,	//  VkStructureType	sType;
814 		DE_NULL,								//  const void*		pNext;
815 		bufferAlloc.getMemory(),				//  VkDeviceMemory	memory;
816 		bufferAlloc.getOffset(),				//  VkDeviceSize	offset;
817 		VK_WHOLE_SIZE							//  VkDeviceSize	size;
818 	};
819 	const deUint32				dataSize32		= static_cast<deUint32>(dataSize);
820 
821 	deMemcpy(bufferAlloc.getHostPtr(), data, dataSize32);
822 	VK_CHECK(vk.flushMappedMemoryRanges(device, 1u, &memRange));
823 }
824 
getFullQuadVertices(void)825 std::vector<float> getFullQuadVertices (void)
826 {
827 	const float					verticesData[]	=
828 	{
829 		-1.0f, -1.0f, 0.0f, 1.0f,
830 		-1.0f, +1.0f, 0.0f, 1.0f,
831 		+1.0f, -1.0f, 0.0f, 1.0f,
832 		-1.0f, +1.0f, 0.0f, 1.0f,
833 		+1.0f, -1.0f, 0.0f, 1.0f,
834 		+1.0f, +1.0f, 0.0f, 1.0f,
835 	};
836 	const std::vector<float>	vertices		(verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
837 
838 	return vertices;
839 }
840 
checkImageFormatProperties(const InstanceInterface & vki,const VkPhysicalDevice & physDevice,const VkFormat format,const VkImageUsageFlags imageUsageFlags,const VkExtent2D & requiredSize2D)841 void checkImageFormatProperties (const InstanceInterface&	vki,
842 								 const VkPhysicalDevice&	physDevice,
843 								 const VkFormat				format,
844 								 const VkImageUsageFlags	imageUsageFlags,
845 								 const VkExtent2D&			requiredSize2D)
846 {
847 	const VkImageType			imageType			= VK_IMAGE_TYPE_2D;
848 	const VkImageTiling			imageTiling			= VK_IMAGE_TILING_OPTIMAL;
849 	const VkImageCreateFlags	imageCreateFlags	= static_cast<VkImageCreateFlags>(0u);
850 	const deUint32				requiredLayers		= 1u;
851 	const VkExtent3D			requiredSize		= makeExtent3D(requiredSize2D.height, requiredSize2D.width, 1u);
852 
853 	VkImageFormatProperties	imageFormatProperties;
854 	VkResult				result;
855 
856 	deMemset(&imageFormatProperties, 0, sizeof(imageFormatProperties));
857 
858 	result = vki.getPhysicalDeviceImageFormatProperties(physDevice, format, imageType, imageTiling, imageUsageFlags, imageCreateFlags, &imageFormatProperties);
859 
860 	if (result									!= VK_SUCCESS			||
861 		imageFormatProperties.maxArrayLayers	<  requiredLayers		||
862 		imageFormatProperties.maxExtent.height	<  requiredSize.height	||
863 		imageFormatProperties.maxExtent.width	<  requiredSize.width	||
864 		imageFormatProperties.maxExtent.depth	<  requiredSize.depth)
865 	{
866 		TCU_THROW(NotSupportedError, "Depth/stencil format is not supported");
867 	}
868 }
869 
getStencilBufferFormat(VkFormat depthStencilImageFormat)870 VkFormat getStencilBufferFormat(VkFormat depthStencilImageFormat)
871 {
872 	const tcu::TextureFormat	tcuFormat	= mapVkFormat(depthStencilImageFormat);
873 	const VkFormat				result		= (tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS) ? VK_FORMAT_S8_UINT : VK_FORMAT_UNDEFINED;
874 
875 	DE_ASSERT(result != VK_FORMAT_UNDEFINED);
876 
877 	return result;
878 }
879 
convertDepthToColor(const tcu::TextureFormat & dataFormat,const int width,const int height,const void * data,const tcu::TextureFormat & targetFormat)880 static MovePtr<tcu::TextureLevel> convertDepthToColor (const tcu::TextureFormat& dataFormat, const int width, const int height, const void* data, const tcu::TextureFormat& targetFormat)
881 {
882 	const tcu::ConstPixelBufferAccess	srcImage	(dataFormat, width, height, 1u, data);
883 	MovePtr<tcu::TextureLevel>			dstImage	(new tcu::TextureLevel(targetFormat, width, height, 1u));
884 	tcu::PixelBufferAccess				dstAccess	(dstImage->getAccess());
885 
886 	for (int y = 0; y < height; y++)
887 	for (int x = 0; x < width; x++)
888 	{
889 		const float		depth	= srcImage.getPixDepth(x, y);
890 		const tcu::Vec4	color	= tcu::Vec4(depth, depth, depth, 1.0f);
891 
892 		dstAccess.setPixel(color, x, y);
893 	}
894 
895 	return dstImage;
896 }
897 
convertStencilToColor(const tcu::TextureFormat & dataFormat,const int width,const int height,const void * data,const tcu::TextureFormat & targetFormat)898 static MovePtr<tcu::TextureLevel> convertStencilToColor (const tcu::TextureFormat& dataFormat, const int width, const int height, const void* data, const tcu::TextureFormat& targetFormat)
899 {
900 	const int							maxValue	(4);
901 	const tcu::ConstPixelBufferAccess	srcImage	(dataFormat, width, height, 1u, data);
902 	MovePtr<tcu::TextureLevel>			dstImage	(new tcu::TextureLevel(targetFormat, width, height, 1u));
903 	tcu::PixelBufferAccess				dstAccess	(dstImage->getAccess());
904 
905 	for (int y = 0; y < height; y++)
906 	for (int x = 0; x < width; x++)
907 	{
908 		const int		stencilInt	= srcImage.getPixStencil(x, y);
909 		const float		stencil		= (stencilInt < maxValue) ? float(stencilInt) / float(maxValue) : 1.0f;
910 		const tcu::Vec4	color		= tcu::Vec4(stencil, stencil, stencil, 1.0f);
911 
912 		dstAccess.setPixel(color, x, y);
913 	}
914 
915 	return dstImage;
916 }
917 
918 class ColorImagelessTestInstance : public TestInstance
919 {
920 public:
921 										ColorImagelessTestInstance			(Context& context, const TestParameters& parameters);
922 protected:
923 	virtual tcu::TestStatus				iterate								(void);
924 
925 	virtual std::vector<float>			getVertices							(void);
926 	void								readOneSampleFromMultisampleImage	(const VkFormat					srcFormat,
927 																			 const Unique<VkImage>&			srcImage,
928 																			 const deUint32					sampleID,
929 																			 const VkFormat					dstFormat,
930 																			 const Unique<VkImage>&			dstImage,
931 																			 const Unique<VkBuffer>&		dstBuffer,
932 																			 const AspectFlags				aspect);
933 	virtual MovePtr<tcu::TextureLevel>	generateReferenceImage				(const tcu::TextureFormat&		textureFormat,
934 																			 const AspectFlags				aspectFlags,
935 																			 const deUint32					sample,
936 																			 const deUint32					subpass);
937 	virtual bool						verifyBuffer						(const UniquePtr<Allocation>&	bufAlloc,
938 																			 const VkFormat					bufferFormat,
939 																			 const std::string&				name,
940 																			 const AspectFlags				aspectFlags,
941 																			 const deUint32					sample		= NO_SAMPLE,
942 																			 const deUint32					subpass		= NO_SUBPASS);
943 	virtual bool						verifyBufferInternal				(const void*					resultData,
944 																			 const tcu::TextureFormat&		textureFormat,
945 																			 const tcu::TextureLevel&		referenceImage,
946 																			 const std::string&				name);
947 
948 	const bool							m_extensions;
949 	const VkExtent2D					m_imageExtent2D;
950 	const TestParameters				m_parameters;
951 	VkImageUsageFlags					m_colorImageUsage;
952 };
953 
ColorImagelessTestInstance(Context & context,const TestParameters & parameters)954 ColorImagelessTestInstance::ColorImagelessTestInstance (Context& context, const TestParameters& parameters)
955 	: TestInstance				(context)
956 	, m_extensions				(context.requireDeviceFunctionality("VK_KHR_imageless_framebuffer"))
957 	, m_imageExtent2D			(makeExtent2D(32u, 32u))
958 	, m_parameters				(parameters)
959 	, m_colorImageUsage			(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT)
960 {
961 	const InstanceInterface&								vki								= m_context.getInstanceInterface();
962 	const VkPhysicalDevice									physDevice						= m_context.getPhysicalDevice();
963 	const VkPhysicalDeviceImagelessFramebufferFeatures&		imagelessFramebufferFeatures	(context.getImagelessFramebufferFeatures());
964 
965 	if (imagelessFramebufferFeatures.imagelessFramebuffer == DE_FALSE)
966 		TCU_THROW(NotSupportedError, "Imageless framebuffer is not supported");
967 
968 	checkImageFormatProperties(vki, physDevice, m_parameters.colorFormat, m_colorImageUsage, m_imageExtent2D);
969 }
970 
readOneSampleFromMultisampleImage(const VkFormat srcFormat,const Unique<VkImage> & srcImage,const deUint32 sampleID,const VkFormat dstFormat,const Unique<VkImage> & dstImage,const Unique<VkBuffer> & dstBuffer,const AspectFlags aspect)971 void ColorImagelessTestInstance::readOneSampleFromMultisampleImage (const VkFormat			srcFormat,
972 																	const Unique<VkImage>&	srcImage,
973 																	const deUint32			sampleID,
974 																	const VkFormat			dstFormat,
975 																	const Unique<VkImage>&	dstImage,
976 																	const Unique<VkBuffer>&	dstBuffer,
977 																	const AspectFlags		aspect)
978 {
979 	const DeviceInterface&				vk					= m_context.getDeviceInterface();
980 	const VkDevice						device				= m_context.getDevice();
981 	const deUint32						queueFamilyIndex	= m_context.getUniversalQueueFamilyIndex();
982 	const VkQueue						queue				= m_context.getUniversalQueue();
983 	Allocator&							allocator			= m_context.getDefaultAllocator();
984 
985 	const tcu::Vec4						clearColor			= tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
986 	const bool							color				= ((aspect & ASPECT_COLOR) != 0);
987 	const bool							depth				= ((aspect & ASPECT_DEPTH) != 0);
988 	const bool							stencil				= ((aspect & ASPECT_STENCIL) != 0);
989 	const VkImageAspectFlags			srcAspect			= color   ? VK_IMAGE_ASPECT_COLOR_BIT
990 															: depth   ? VK_IMAGE_ASPECT_DEPTH_BIT
991 															: VK_IMAGE_ASPECT_STENCIL_BIT;
992 	const VkImageSubresourceRange		srcSubresRange		= makeImageSubresourceRange(srcAspect, 0u, 1u, 0u, 1u);
993 	const Unique<VkImageView>			srcImageView		(makeImageView			(vk, device, *srcImage, VK_IMAGE_VIEW_TYPE_2D, srcFormat, srcSubresRange));
994 
995 	const VkImageAspectFlags			dstAspect			= VK_IMAGE_ASPECT_COLOR_BIT;
996 	const VkImageSubresourceRange		dstSubresRange		= makeImageSubresourceRange(dstAspect, 0u, 1u, 0u, 1u);
997 	const Unique<VkImageView>			dstAttachment		(makeImageView			(vk, device, *dstImage, VK_IMAGE_VIEW_TYPE_2D, dstFormat, dstSubresRange));
998 
999 	const std::string					fragModuleInfix		= color   ? "-color"
1000 															: depth   ? "-depth"
1001 															: stencil ? "-stencil"
1002 															: "";
1003 	const Unique<VkShaderModule>		vertModule			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("demultisample-vert"), 0u));
1004 	const Unique<VkShaderModule>		fragModule			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("demultisample" + fragModuleInfix + "-frag"), 0u));
1005 	const Unique<VkRenderPass>			renderPass			(makeVerifyRenderPass	(vk, device, dstFormat));
1006 	const Unique<VkFramebuffer>			framebuffer			(makeVerifyFramebuffer	(vk, device, *renderPass, *dstAttachment, m_imageExtent2D));
1007 
1008 	const VkDescriptorType				samplerDescType		(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
1009 	const Unique<VkSampler>				sampler				(makeSampler(vk, device));
1010 	const Unique<VkDescriptorSetLayout>	descriptorSetLayout	(DescriptorSetLayoutBuilder()
1011 		.addSingleSamplerBinding(samplerDescType, VK_SHADER_STAGE_FRAGMENT_BIT, &sampler.get())
1012 		.build(vk, device));
1013 	const Unique<VkDescriptorPool>		descriptorPool		(DescriptorPoolBuilder()
1014 		.addType(samplerDescType)
1015 		.build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u));
1016 	const Unique<VkDescriptorSet>		descriptorSet		(makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout));
1017 	const VkDescriptorImageInfo			imageDescriptorInfo	(makeDescriptorImageInfo(DE_NULL, *srcImageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL));
1018 
1019 	DescriptorSetUpdateBuilder()
1020 		.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), samplerDescType, &imageDescriptorInfo)
1021 		.update(vk, device);
1022 
1023 	const Unique<VkPipelineLayout>		pipelineLayout		(makeVerifyPipelineLayout	(vk, device, *descriptorSetLayout));
1024 	const Unique<VkPipeline>			pipeline			(makeGraphicsPipeline		(vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D));
1025 	const Unique<VkCommandPool>			cmdPool				(createCommandPool			(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1026 	const Unique<VkCommandBuffer>		cmdBuffer			(allocateCommandBuffer		(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1027 
1028 	const std::vector<float>			vertexArray			(getFullQuadVertices());
1029 	const deUint32						vertexCount			(static_cast<deUint32>(vertexArray.size() / 4u));
1030 	const VkDeviceSize					vertexArraySize		(vertexArray.size() * sizeof(vertexArray[0]));
1031 	const Unique<VkBuffer>				vertexBuffer		(makeBuffer				(vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1032 	const UniquePtr<Allocation>			vertexBufferAlloc	(bindBuffer				(vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1033 	const VkDeviceSize					vertexBufferOffset	(0u);
1034 
1035 	fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1036 
1037 	beginCommandBuffer(vk, *cmdBuffer);
1038 	{
1039 		if (sampleID == 0)
1040 		{
1041 			if (color)
1042 			{
1043 				const VkImageMemoryBarrier	preCopyBarrier	= makeImageMemoryBarrier	(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
1044 																						 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1045 																						 *srcImage, srcSubresRange);
1046 
1047 				vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1048 			}
1049 			else if (depth)
1050 			{
1051 				const VkImageSubresourceRange	preCopySubresRange	= makeImageSubresourceRange	(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 1u, 0u, 1u);
1052 				const VkImageMemoryBarrier		preCopyBarrier		= makeImageMemoryBarrier	(VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
1053 																								 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1054 																								 *srcImage, preCopySubresRange);
1055 
1056 				vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1057 			}
1058 		}
1059 
1060 		beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor);
1061 		{
1062 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1063 
1064 			vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL);
1065 
1066 			vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1067 
1068 			vk.cmdPushConstants(*cmdBuffer, *pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0u, sizeof(sampleID), &sampleID);
1069 
1070 			vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1071 		}
1072 		endRenderPass(vk, *cmdBuffer);
1073 
1074 		// Image copy
1075 		{
1076 			const VkImageMemoryBarrier	preCopyBarrier	= makeImageMemoryBarrier	(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1077 																					 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1078 																					 *dstImage, dstSubresRange);
1079 			const VkBufferImageCopy		region			= makeBufferImageCopy		(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1080 																					 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1081 			const VkBufferMemoryBarrier	postCopyBarrier	= makeBufferMemoryBarrier	(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *dstBuffer, 0ull, VK_WHOLE_SIZE);
1082 
1083 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1084 			vk.cmdCopyImageToBuffer(*cmdBuffer, *dstImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *dstBuffer, 1u, &region);
1085 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
1086 		}
1087 	}
1088 	endCommandBuffer(vk, *cmdBuffer);
1089 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1090 }
1091 
verifyBufferInternal(const void * resultData,const tcu::TextureFormat & textureFormat,const tcu::TextureLevel & referenceImage,const std::string & name)1092 bool ColorImagelessTestInstance::verifyBufferInternal (const void* resultData, const tcu::TextureFormat& textureFormat, const tcu::TextureLevel& referenceImage, const std::string& name)
1093 {
1094 	const int							dataSize		(m_imageExtent2D.width * m_imageExtent2D.height * textureFormat.getPixelSize());
1095 	const tcu::ConstPixelBufferAccess	referenceAccess	(referenceImage.getAccess());
1096 
1097 	if (deMemCmp(resultData, referenceAccess.getDataPtr(), dataSize) != 0)
1098 	{
1099 		const tcu::ConstPixelBufferAccess	resultImage	(textureFormat, m_imageExtent2D.width, m_imageExtent2D.height, 1u, resultData);
1100 		bool								ok;
1101 
1102 		ok = tcu::intThresholdCompare(m_context.getTestContext().getLog(), name.c_str(), "", referenceAccess, resultImage, tcu::UVec4(1), tcu::COMPARE_LOG_RESULT);
1103 
1104 		return ok;
1105 	}
1106 
1107 	return true;
1108 }
1109 
verifyBuffer(const UniquePtr<Allocation> & bufAlloc,const VkFormat bufferFormat,const std::string & name,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1110 bool ColorImagelessTestInstance::verifyBuffer (const UniquePtr<Allocation>& bufAlloc, const VkFormat bufferFormat, const std::string& name, const AspectFlags aspectFlags, const deUint32 sample, const deUint32 subpass)
1111 {
1112 	invalidateMappedMemoryRange(m_context.getDeviceInterface(), m_context.getDevice(), bufAlloc->getMemory(), bufAlloc->getOffset(), VK_WHOLE_SIZE);
1113 
1114 	const tcu::TextureFormat			bufferTextureFormat		(mapVkFormat(bufferFormat));
1115 	const bool							multisampled			(sample != NO_SAMPLE);
1116 	const bool							depth					((aspectFlags & ASPECT_DEPTH) != 0);
1117 	const bool							stencil					((aspectFlags & ASPECT_STENCIL) != 0);
1118 	const bool							convertRequired			((depth || stencil) && !multisampled);
1119 	const tcu::TextureFormat			convertTextureFormat	(tcu::TextureFormat(tcu::TextureFormat::R, tcu::TextureFormat::UNORM_INT8));
1120 	const tcu::TextureFormat			referenceTextureFormat	(convertRequired ? convertTextureFormat : bufferTextureFormat);
1121 	const MovePtr<tcu::TextureLevel>	referenceImage			(generateReferenceImage(referenceTextureFormat, aspectFlags, sample, subpass));
1122 
1123 	if (!multisampled && depth)
1124 	{
1125 		MovePtr<tcu::TextureLevel>	convertedImage	(convertDepthToColor(bufferTextureFormat, m_imageExtent2D.width, m_imageExtent2D.height, bufAlloc->getHostPtr(), convertTextureFormat));
1126 		tcu::ConstPixelBufferAccess	convertedAccess	(convertedImage->getAccess());
1127 
1128 		return verifyBufferInternal(convertedAccess.getDataPtr(), convertTextureFormat, *referenceImage, name);
1129 	}
1130 	else if (!multisampled && stencil)
1131 	{
1132 		MovePtr<tcu::TextureLevel>	convertedImage	(convertStencilToColor(bufferTextureFormat, m_imageExtent2D.width, m_imageExtent2D.height, bufAlloc->getHostPtr(), convertTextureFormat));
1133 		tcu::ConstPixelBufferAccess	convertedAccess	(convertedImage->getAccess());
1134 
1135 		return verifyBufferInternal(convertedAccess.getDataPtr(), convertTextureFormat, *referenceImage, name);
1136 	}
1137 	else
1138 	{
1139 		const void*	resultData	(bufAlloc->getHostPtr());
1140 
1141 		return verifyBufferInternal(resultData, bufferTextureFormat, *referenceImage, name);
1142 	}
1143 }
1144 
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1145 MovePtr<tcu::TextureLevel> ColorImagelessTestInstance::generateReferenceImage (const tcu::TextureFormat&	textureFormat,
1146 																			   const AspectFlags			aspectFlags,
1147 																			   const deUint32				sample,
1148 																			   const deUint32				subpass)
1149 {
1150 	const int					width			= m_imageExtent2D.width;
1151 	const int					height			= m_imageExtent2D.height;
1152 	const int					componentValue	(static_cast<int>(0.75f * 0x100));
1153 	const tcu::RGBA				colorDrawRGBA	(tcu::RGBA(componentValue, componentValue, componentValue, 0xFF));
1154 	const tcu::Vec4				colorDraw		(colorDrawRGBA.toVec());
1155 	const tcu::Vec4				colorFill		(tcu::RGBA::black().toVec());
1156 	MovePtr<tcu::TextureLevel>	image			(new tcu::TextureLevel(textureFormat, width, height));
1157 	tcu::PixelBufferAccess		access			(image->getAccess());
1158 
1159 	DE_UNREF(aspectFlags);
1160 	DE_ASSERT(aspectFlags == ASPECT_COLOR);
1161 	DE_UNREF(sample);
1162 	DE_ASSERT(sample == NO_SAMPLE);
1163 	DE_UNREF(subpass);
1164 	DE_ASSERT(subpass == NO_SUBPASS);
1165 
1166 	for (int y = 0; y < height; ++y)
1167 	{
1168 		const tcu::Vec4&	validColor	= (y < height / 2) ? colorFill : colorDraw;
1169 
1170 		for (int x = 0; x < width; ++x)
1171 			access.setPixel(validColor, x, y);
1172 	}
1173 
1174 	return image;
1175 }
1176 
getVertices(void)1177 std::vector<float> ColorImagelessTestInstance::getVertices (void)
1178 {
1179 	const float					verticesData[]	=
1180 	{
1181 		-1.0f,  0.0f, 0.0f, 1.0f,
1182 		-1.0f, +1.0f, 0.0f, 1.0f,
1183 		+1.0f,  0.0f, 0.0f, 1.0f,
1184 		-1.0f, +1.0f, 0.0f, 1.0f,
1185 		+1.0f,  0.0f, 0.0f, 1.0f,
1186 		+1.0f, +1.0f, 0.0f, 1.0f,
1187 	};
1188 	const std::vector<float>	vertices		(verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
1189 
1190 	return vertices;
1191 }
1192 
iterate(void)1193 tcu::TestStatus ColorImagelessTestInstance::iterate (void)
1194 {
1195 	const DeviceInterface&			vk					= m_context.getDeviceInterface();
1196 	const VkDevice					device				= m_context.getDevice();
1197 	const deUint32					queueFamilyIndex	= m_context.getUniversalQueueFamilyIndex();
1198 	const VkQueue					queue				= m_context.getUniversalQueue();
1199 	Allocator&						allocator			= m_context.getDefaultAllocator();
1200 
1201 	const tcu::Vec4					clearColor			= tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1202 	const VkFormat					colorFormat			= m_parameters.colorFormat;
1203 	const VkDeviceSize				colorBufferSize		= m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
1204 	const VkImageSubresourceRange	colorSubresRange	= makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1205 
1206 	const Unique<VkImage>			colorImage			(makeImage				(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1207 	const UniquePtr<Allocation>		colorImageAlloc		(bindImage				(vk, device, allocator, *colorImage, MemoryRequirement::Any));
1208 	const Unique<VkImageView>		colorAttachment		(makeImageView			(vk, device, *colorImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1209 	const Unique<VkBuffer>			colorBuffer			(makeBuffer				(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1210 	const UniquePtr<Allocation>		colorBufferAlloc	(bindBuffer				(vk, device, allocator, *colorBuffer, MemoryRequirement::HostVisible));
1211 
1212 	const Unique<VkShaderModule>	vertModule			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("vert"), 0u));
1213 	const Unique<VkShaderModule>	fragModule			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("frag"), 0u));
1214 	const Unique<VkRenderPass>		renderPass			(makeRenderPass			(vk, device, colorFormat, m_parameters.dsFormat));
1215 	const Unique<VkFramebuffer>		framebuffer			(makeFramebuffer		(vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat));
1216 	const Unique<VkPipelineLayout>	pipelineLayout		(makePipelineLayout		(vk, device));
1217 	const Unique<VkPipeline>		pipeline			(makeGraphicsPipeline	(vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D));
1218 	const Unique<VkCommandPool>		cmdPool				(createCommandPool		(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1219 	const Unique<VkCommandBuffer>	cmdBuffer			(allocateCommandBuffer	(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1220 
1221 	const std::vector<float>		vertexArray			(getVertices());
1222 	const deUint32					vertexCount			(static_cast<deUint32>(vertexArray.size() / 4u));
1223 	const VkDeviceSize				vertexArraySize		(vertexArray.size() * sizeof(vertexArray[0]));
1224 	const Unique<VkBuffer>			vertexBuffer		(makeBuffer				(vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1225 	const UniquePtr<Allocation>		vertexBufferAlloc	(bindBuffer				(vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1226 	const VkDeviceSize				vertexBufferOffset	(0u);
1227 
1228 	fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1229 
1230 	beginCommandBuffer(vk, *cmdBuffer);
1231 	{
1232 		const VkRenderPassAttachmentBeginInfo		renderPassAttachmentBeginInfo	=
1233 		{
1234 			VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO,		//  VkStructureType		sType;
1235 			DE_NULL,													//  const void*			pNext;
1236 			1u,															//  deUint32			attachmentCount;
1237 			&*colorAttachment											//  const VkImageView*	pAttachments;
1238 		};
1239 
1240 		beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, &renderPassAttachmentBeginInfo);
1241 		{
1242 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1243 
1244 			vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1245 
1246 			vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1247 		}
1248 		endRenderPass(vk, *cmdBuffer);
1249 
1250 		// Color image copy
1251 		{
1252 			const VkImageMemoryBarrier	preCopyBarrier	= makeImageMemoryBarrier	(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1253 																					 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1254 																					 *colorImage, colorSubresRange);
1255 			const VkBufferImageCopy		region			= makeBufferImageCopy		(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1256 																					 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1257 			const VkBufferMemoryBarrier	postCopyBarrier	= makeBufferMemoryBarrier	(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *colorBuffer, 0ull, VK_WHOLE_SIZE);
1258 
1259 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1260 			vk.cmdCopyImageToBuffer(*cmdBuffer, *colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *colorBuffer, 1u, &region);
1261 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
1262 		}
1263 	}
1264 	endCommandBuffer(vk, *cmdBuffer);
1265 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1266 
1267 	if (verifyBuffer(colorBufferAlloc, colorFormat, "Color", ASPECT_COLOR))
1268 		return tcu::TestStatus::pass("Pass");
1269 	else
1270 		return tcu::TestStatus::fail("Fail");
1271 }
1272 
1273 class DepthImagelessTestInstance : public ColorImagelessTestInstance
1274 {
1275 public:
1276 										DepthImagelessTestInstance	(Context& context, const TestParameters& parameters);
1277 
1278 protected:
1279 	virtual tcu::TestStatus				iterate						(void);
1280 
1281 	virtual std::vector<float>			getVertices					(void);
1282 
1283 	virtual MovePtr<tcu::TextureLevel>	generateReferenceImage		(const tcu::TextureFormat&	textureFormat,
1284 																	 const AspectFlags			aspectFlags,
1285 																	 const deUint32				sample,
1286 																	 const deUint32				subpass);
1287 
1288 	VkImageUsageFlags					m_dsImageUsage;
1289 };
1290 
DepthImagelessTestInstance(Context & context,const TestParameters & parameters)1291 DepthImagelessTestInstance::DepthImagelessTestInstance (Context& context, const TestParameters& parameters)
1292 	: ColorImagelessTestInstance	(context, parameters)
1293 	, m_dsImageUsage				(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT)
1294 {
1295 	const InstanceInterface&	vki			= m_context.getInstanceInterface();
1296 	const VkPhysicalDevice		physDevice	= m_context.getPhysicalDevice();
1297 
1298 	checkImageFormatProperties(vki, physDevice, m_parameters.dsFormat, m_dsImageUsage, m_imageExtent2D);
1299 }
1300 
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1301 MovePtr<tcu::TextureLevel> DepthImagelessTestInstance::generateReferenceImage (const tcu::TextureFormat&	textureFormat,
1302 																			   const AspectFlags			aspectFlags,
1303 																			   const deUint32				sample,
1304 																			   const deUint32				subpass)
1305 {
1306 	const bool					color	= ((aspectFlags & ASPECT_COLOR) != 0);
1307 	const bool					depth	= ((aspectFlags & ASPECT_DEPTH) != 0);
1308 	const bool					stencil	= ((aspectFlags & ASPECT_STENCIL) != 0);
1309 	const int					width	= m_imageExtent2D.width;
1310 	const int					height	= m_imageExtent2D.height;
1311 	MovePtr<tcu::TextureLevel>	image	(new tcu::TextureLevel(textureFormat, width, height));
1312 	tcu::PixelBufferAccess		access	(image->getAccess());
1313 
1314 	DE_ASSERT(dePop32(aspectFlags) == 1);
1315 	DE_UNREF(sample);
1316 	DE_ASSERT(sample == NO_SAMPLE);
1317 	DE_UNREF(subpass);
1318 	DE_ASSERT(subpass == NO_SUBPASS);
1319 
1320 	if (color)
1321 	{
1322 		const int		componentValue	(static_cast<int>(0.75f * 0x100));
1323 		const tcu::RGBA	colorDrawRGBA	(tcu::RGBA(componentValue, componentValue, componentValue, 0xFF));
1324 		const tcu::Vec4	colorDraw		(colorDrawRGBA.toVec());
1325 		const tcu::Vec4	colorDrawTop	(tcu::RGBA::white().toVec());
1326 		const tcu::Vec4	colorFill		(tcu::RGBA::black().toVec());
1327 
1328 		for (int y = 0; y < height; ++y)
1329 		for (int x = 0; x < width; ++x)
1330 		{
1331 			const tcu::Vec4&	validColor	= (y < height / 2) ? colorFill
1332 											: (x < width  / 2) ? colorDraw
1333 											: colorDrawTop;
1334 
1335 			access.setPixel(validColor, x, y);
1336 		}
1337 	}
1338 
1339 	if (depth)
1340 	{
1341 		const int			colorFillValue	(static_cast<int>(1.00f * 0x100));
1342 		const int			colorDrawValue	(static_cast<int>(0.50f * 0x100));
1343 		const int			colorTopValue	(static_cast<int>(0.25f * 0x100));
1344 		const tcu::IVec4	colorFill		(colorFillValue, 0, 0, 0xFF);
1345 		const tcu::IVec4	colorDraw		(colorDrawValue, 0, 0, 0xFF);
1346 		const tcu::IVec4	colorTop		(colorTopValue,  0, 0, 0xFF);
1347 
1348 		for (int y = 0; y < height; ++y)
1349 		for (int x = 0; x < width; ++x)
1350 		{
1351 			const tcu::IVec4&	validColor	= (y < height / 2) ? colorFill
1352 											: (x < width  / 2) ? colorDraw
1353 											: colorTop;
1354 
1355 			access.setPixel(validColor, x, y);
1356 		}
1357 	}
1358 
1359 	if (stencil)
1360 	{
1361 		const int			colorFillValue	(static_cast<int>(0.00f * 0x100));
1362 		const int			colorDrawValue	(static_cast<int>(0.25f * 0x100));
1363 		const int			colorTopValue	(static_cast<int>(0.50f * 0x100));
1364 		const tcu::IVec4	colorFill		(colorFillValue, 0, 0, 0xFF);
1365 		const tcu::IVec4	colorDraw		(colorDrawValue, 0, 0, 0xFF);
1366 		const tcu::IVec4	colorTop		(colorTopValue,  0, 0, 0xFF);
1367 
1368 		for (int y = 0; y < height; ++y)
1369 		for (int x = 0; x < width; ++x)
1370 		{
1371 			const tcu::IVec4&	validColor	= (y < height / 2) ? colorFill
1372 											: (x < width  / 2) ? colorDraw
1373 											: colorTop;
1374 
1375 			access.setPixel(validColor, x, y);
1376 		}
1377 	}
1378 
1379 	return image;
1380 }
1381 
getVertices(void)1382 std::vector<float> DepthImagelessTestInstance::getVertices (void)
1383 {
1384 	const float					verticesData[]	=
1385 	{
1386 		-1.0f,  0.0f, 0.50f, 1.0f,
1387 		-1.0f, +1.0f, 0.50f, 1.0f,
1388 		+1.0f,  0.0f, 0.50f, 1.0f,
1389 		-1.0f, +1.0f, 0.50f, 1.0f,
1390 		+1.0f,  0.0f, 0.50f, 1.0f,
1391 		+1.0f, +1.0f, 0.50f, 1.0f,
1392 
1393 		 0.0f,  0.0f, 0.25f, 1.0f,
1394 		 0.0f, +1.0f, 0.25f, 1.0f,
1395 		+1.0f,  0.0f, 0.25f, 1.0f,
1396 		 0.0f, +1.0f, 0.25f, 1.0f,
1397 		+1.0f,  0.0f, 0.25f, 1.0f,
1398 		+1.0f, +1.0f, 0.25f, 1.0f,
1399 	};
1400 	const std::vector<float>	vertices		(verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
1401 
1402 	return vertices;
1403 }
1404 
iterate(void)1405 tcu::TestStatus DepthImagelessTestInstance::iterate (void)
1406 {
1407 	const DeviceInterface&			vk					= m_context.getDeviceInterface();
1408 	const VkDevice					device				= m_context.getDevice();
1409 	const deUint32					queueFamilyIndex	= m_context.getUniversalQueueFamilyIndex();
1410 	const VkQueue					queue				= m_context.getUniversalQueue();
1411 	Allocator&						allocator			= m_context.getDefaultAllocator();
1412 
1413 	const deUint32					sampleCount			= 1u;
1414 	const VkSampleCountFlagBits		sampleCountFlag		= sampleCountBitFromSampleCount(sampleCount);
1415 	const tcu::Vec4					clearColor			= tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1416 	const VkFormat					colorFormat			= m_parameters.colorFormat;
1417 	const VkDeviceSize				colorBufferSize		= m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
1418 	const VkImageSubresourceRange	colorSubresRange	= makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1419 
1420 	const Unique<VkImage>			colorImage			(makeImage				(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1421 	const UniquePtr<Allocation>		colorImageAlloc		(bindImage				(vk, device, allocator, *colorImage, MemoryRequirement::Any));
1422 	const Unique<VkImageView>		colorAttachment		(makeImageView			(vk, device, *colorImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1423 	const Unique<VkBuffer>			colorBuffer			(makeBuffer				(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1424 	const UniquePtr<Allocation>		colorBufferAlloc	(bindBuffer				(vk, device, allocator, *colorBuffer, MemoryRequirement::HostVisible));
1425 
1426 	const float						clearDepth			= 1.0f;
1427 	const deUint32					clearStencil		= 0u;
1428 	const VkFormat					dsFormat			= m_parameters.dsFormat;
1429 	const deUint32					dsImagePixelSize	= static_cast<deUint32>(tcu::getPixelSize(mapVkFormat(dsFormat)));
1430 	const VkImageAspectFlags		dsAspectFlags		= VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
1431 	const VkImageSubresourceRange	dsSubresRange		= makeImageSubresourceRange(dsAspectFlags, 0u, 1u, 0u, 1u);
1432 
1433 	const VkDeviceSize				depthBufferSize		= m_imageExtent2D.width * m_imageExtent2D.height * dsImagePixelSize;
1434 	const VkFormat					stencilBufferFormat	= getStencilBufferFormat(dsFormat);
1435 	const deUint32					stencilPixelSize	= static_cast<deUint32>(tcu::getPixelSize(mapVkFormat(stencilBufferFormat)));
1436 	const VkDeviceSize				stencilBufferSize	= m_imageExtent2D.width * m_imageExtent2D.height * stencilPixelSize;
1437 
1438 	const Unique<VkImage>			dsImage				(makeImage				(vk, device, makeImageCreateInfo(dsFormat, m_imageExtent2D, m_dsImageUsage)));
1439 	const UniquePtr<Allocation>		dsImageAlloc		(bindImage				(vk, device, allocator, *dsImage, MemoryRequirement::Any));
1440 	const Unique<VkImageView>		dsAttachment		(makeImageView			(vk, device, *dsImage, VK_IMAGE_VIEW_TYPE_2D, dsFormat, dsSubresRange));
1441 	const Unique<VkBuffer>			depthBuffer			(makeBuffer				(vk, device, depthBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1442 	const UniquePtr<Allocation>		depthBufferAlloc	(bindBuffer				(vk, device, allocator, *depthBuffer, MemoryRequirement::HostVisible));
1443 	const Unique<VkBuffer>			stencilBuffer		(makeBuffer				(vk, device, stencilBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1444 	const UniquePtr<Allocation>		stencilBufferAlloc	(bindBuffer				(vk, device, allocator, *stencilBuffer, MemoryRequirement::HostVisible));
1445 
1446 	const Unique<VkShaderModule>	vertModule			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("vert"), 0u));
1447 	const Unique<VkShaderModule>	fragModule			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("frag"), 0u));
1448 	const Unique<VkRenderPass>		renderPass			(makeRenderPass			(vk, device, colorFormat, dsFormat, sampleCountFlag));
1449 	const Unique<VkFramebuffer>		framebuffer			(makeFramebuffer		(vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &dsFormat, m_dsImageUsage));
1450 	const Unique<VkPipelineLayout>	pipelineLayout		(makePipelineLayout		(vk, device));
1451 	const Unique<VkPipeline>		pipeline			(makeGraphicsPipeline	(vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D, ASPECT_DEPTH_STENCIL));
1452 	const Unique<VkCommandPool>		cmdPool				(createCommandPool		(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1453 	const Unique<VkCommandBuffer>	cmdBuffer			(allocateCommandBuffer	(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1454 
1455 	const std::vector<float>		vertexArray			(getVertices());
1456 	const deUint32					vertexCount			(static_cast<deUint32>(vertexArray.size() / 4u));
1457 	const VkDeviceSize				vertexArraySize		(vertexArray.size() * sizeof(vertexArray[0]));
1458 	const Unique<VkBuffer>			vertexBuffer		(makeBuffer				(vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1459 	const UniquePtr<Allocation>		vertexBufferAlloc	(bindBuffer				(vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1460 	const VkDeviceSize				vertexBufferOffset	(0u);
1461 
1462 	fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1463 
1464 	beginCommandBuffer(vk, *cmdBuffer);
1465 	{
1466 		const VkImageView							attachments[]					= { *colorAttachment, *dsAttachment };
1467 		const VkRenderPassAttachmentBeginInfo		renderPassAttachmentBeginInfo	=
1468 		{
1469 			VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO,		//  VkStructureType		sType;
1470 			DE_NULL,													//  const void*			pNext;
1471 			DE_LENGTH_OF_ARRAY(attachments),							//  deUint32			attachmentCount;
1472 			attachments													//  const VkImageView*	pAttachments;
1473 		};
1474 
1475 		beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, clearDepth, clearStencil, &renderPassAttachmentBeginInfo);
1476 		{
1477 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1478 
1479 			vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1480 
1481 			vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1482 		}
1483 		endRenderPass(vk, *cmdBuffer);
1484 
1485 		// Color image copy
1486 		{
1487 			const VkImageMemoryBarrier	preCopyBarrier	= makeImageMemoryBarrier	(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1488 																					 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1489 																					 *colorImage, colorSubresRange);
1490 			const VkBufferImageCopy		region			= makeBufferImageCopy		(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1491 																					 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1492 			const VkBufferMemoryBarrier	postCopyBarrier	= makeBufferMemoryBarrier	(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *colorBuffer, 0ull, VK_WHOLE_SIZE);
1493 
1494 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1495 			vk.cmdCopyImageToBuffer(*cmdBuffer, *colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *colorBuffer, 1u, &region);
1496 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
1497 		}
1498 
1499 		// Depth/Stencil image copy
1500 		{
1501 			const VkImageMemoryBarrier	preCopyBarrier		= makeImageMemoryBarrier(VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1502 																VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *dsImage, dsSubresRange);
1503 			const VkBufferImageCopy		depthCopyRegion		= makeBufferImageCopy(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1504 																				  makeImageSubresourceLayers(VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u));
1505 			const VkBufferImageCopy		stencilCopyRegion	= makeBufferImageCopy(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1506 																				  makeImageSubresourceLayers(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u));
1507 			const VkBufferMemoryBarrier	postCopyBarriers[]	=
1508 			{
1509 				makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *depthBuffer, 0ull, VK_WHOLE_SIZE),
1510 				makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *stencilBuffer, 0ull, VK_WHOLE_SIZE),
1511 			};
1512 
1513 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1514 			vk.cmdCopyImageToBuffer(*cmdBuffer, *dsImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *depthBuffer, 1u, &depthCopyRegion);
1515 			vk.cmdCopyImageToBuffer(*cmdBuffer, *dsImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *stencilBuffer, 1u, &stencilCopyRegion);
1516 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, DE_LENGTH_OF_ARRAY(postCopyBarriers), postCopyBarriers, DE_NULL, 0u);
1517 		}
1518 	}
1519 	endCommandBuffer(vk, *cmdBuffer);
1520 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1521 
1522 	{
1523 		std::string result;
1524 
1525 		if (!verifyBuffer(colorBufferAlloc, colorFormat, "Color", ASPECT_COLOR))
1526 			result += " Color";
1527 
1528 		if (!verifyBuffer(depthBufferAlloc, dsFormat, "Depth", ASPECT_DEPTH))
1529 			result += " Depth";
1530 
1531 		if (!verifyBuffer(stencilBufferAlloc, stencilBufferFormat, "Stencil", ASPECT_STENCIL))
1532 			result += " Stencil";
1533 
1534 		if (result.empty())
1535 			return tcu::TestStatus::pass("Pass");
1536 		else
1537 			return tcu::TestStatus::fail("Following parts of image are incorrect:" + result);
1538 	}
1539 }
1540 
1541 class ColorResolveImagelessTestInstance : public ColorImagelessTestInstance
1542 {
1543 public:
1544 										ColorResolveImagelessTestInstance	(Context& context, const TestParameters& parameters);
1545 protected:
1546 	virtual tcu::TestStatus				iterate								(void);
1547 
1548 	virtual MovePtr<tcu::TextureLevel>	generateReferenceImage				(const tcu::TextureFormat&	textureFormat,
1549 																			 const AspectFlags			aspectFlags,
1550 																			 const deUint32				sample,
1551 																			 const deUint32				subpass);
1552 
1553 	virtual std::vector<float>			getVertices							(void);
1554 };
1555 
ColorResolveImagelessTestInstance(Context & context,const TestParameters & parameters)1556 ColorResolveImagelessTestInstance::ColorResolveImagelessTestInstance (Context& context, const TestParameters& parameters)
1557 	: ColorImagelessTestInstance	(context, parameters)
1558 {
1559 	const InstanceInterface&	vki			= m_context.getInstanceInterface();
1560 	const VkPhysicalDevice		physDevice	= m_context.getPhysicalDevice();
1561 
1562 	// To validate per-sample image image must also be sampled
1563 	m_colorImageUsage |= VK_IMAGE_USAGE_SAMPLED_BIT;
1564 
1565 	checkImageFormatProperties(vki, physDevice, m_parameters.colorFormat, m_colorImageUsage, m_imageExtent2D);
1566 }
1567 
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1568 MovePtr<tcu::TextureLevel> ColorResolveImagelessTestInstance::generateReferenceImage (const tcu::TextureFormat&	textureFormat,
1569 																					  const AspectFlags			aspectFlags,
1570 																					  const deUint32			sample,
1571 																					  const deUint32			subpass)
1572 {
1573 	const int					width			= m_imageExtent2D.width;
1574 	const int					height			= m_imageExtent2D.height;
1575 	MovePtr<tcu::TextureLevel>	image			(new tcu::TextureLevel(textureFormat, width, height));
1576 	tcu::PixelBufferAccess		access			(image->getAccess());
1577 	const int					componentValue	(static_cast<int>(0.75f * 0x100));
1578 	const tcu::RGBA				colorDrawRGBA	(tcu::RGBA(componentValue, componentValue, componentValue, 0xFF));
1579 	const tcu::Vec4				colorDraw		(colorDrawRGBA.toVec());
1580 	const tcu::Vec4				colorFill		(tcu::RGBA::black().toVec());
1581 	const tcu::Vec4				colorEdge0		(colorDraw);
1582 	const tcu::Vec4				colorEdge1		(colorFill);
1583 	const tcu::Vec4				colorEdge2		(colorDraw);
1584 	const tcu::Vec4				colorEdge3		(colorFill);
1585 	const tcu::Vec4				colorEdgeR		((colorDraw.x() + colorFill.x()) / 2, (colorDraw.y() + colorFill.y()) / 2, (colorDraw.z() + colorFill.z()) / 2, colorDraw.w()); // AVERAGE
1586 	const tcu::Vec4&			colorEdge		= sample == 0 ? colorEdge0
1587 												: sample == 1 ? colorEdge1
1588 												: sample == 2 ? colorEdge2
1589 												: sample == 3 ? colorEdge3
1590 												: colorEdgeR;
1591 
1592 	DE_UNREF(aspectFlags);
1593 	DE_ASSERT(dePop32(aspectFlags) == 1);
1594 	DE_ASSERT(aspectFlags == ASPECT_COLOR);
1595 	DE_UNREF(subpass);
1596 	DE_ASSERT(subpass == NO_SUBPASS);
1597 
1598 	for (int y = 0; y < height; ++y)
1599 	for (int x = 0; x < width; ++x)
1600 	{
1601 		const int			mx			= width - 1 - x;
1602 		const tcu::Vec4&	validColor	= (y == mx) ? colorEdge
1603 										: (y >  mx) ? colorFill
1604 										: colorDraw;
1605 
1606 		access.setPixel(validColor, x, y);
1607 	}
1608 
1609 	return image;
1610 }
1611 
getVertices(void)1612 std::vector<float> ColorResolveImagelessTestInstance::getVertices (void)
1613 {
1614 	const float					verticesData[]	=
1615 	{
1616 		-1.0f, -1.0f, 0.0f, 1.0f,
1617 		-1.0f, +1.0f, 0.0f, 1.0f,
1618 		+1.0f, -1.0f, 0.0f, 1.0f,
1619 	};
1620 	const std::vector<float>	vertices		(verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
1621 
1622 	return vertices;
1623 }
1624 
iterate(void)1625 tcu::TestStatus ColorResolveImagelessTestInstance::iterate (void)
1626 {
1627 	const DeviceInterface&			vk						= m_context.getDeviceInterface();
1628 	const VkDevice					device					= m_context.getDevice();
1629 	const deUint32					queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
1630 	const VkQueue					queue					= m_context.getUniversalQueue();
1631 	Allocator&						allocator				= m_context.getDefaultAllocator();
1632 
1633 	const VkSampleCountFlagBits		sampleCount				= VK_SAMPLE_COUNT_4_BIT;
1634 	const tcu::Vec4					clearColor				= tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1635 	const VkFormat					colorFormat				= m_parameters.colorFormat;
1636 	const VkDeviceSize				colorBufferSize			= m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
1637 	const VkImageSubresourceRange	colorSubresRange		= makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1638 
1639 	const Unique<VkImage>			colorImage				(makeImage				(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage, sampleCount)));
1640 	const UniquePtr<Allocation>		colorImageAlloc			(bindImage				(vk, device, allocator, *colorImage, MemoryRequirement::Any));
1641 	const Unique<VkImageView>		colorAttachment			(makeImageView			(vk, device, *colorImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1642 
1643 	const Unique<VkImage>			colorResolveImage		(makeImage				(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1644 	const UniquePtr<Allocation>		colorResolveImageAlloc	(bindImage				(vk, device, allocator, *colorResolveImage, MemoryRequirement::Any));
1645 	const Unique<VkImageView>		colorResolveAttachment	(makeImageView			(vk, device, *colorResolveImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1646 	const Unique<VkBuffer>			colorResolveBuffer		(makeBuffer				(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1647 	const UniquePtr<Allocation>		colorResolveBufferAlloc	(bindBuffer				(vk, device, allocator, *colorResolveBuffer, MemoryRequirement::HostVisible));
1648 
1649 	const Unique<VkShaderModule>	vertModule				(createShaderModule		(vk, device, m_context.getBinaryCollection().get("vert"), 0u));
1650 	const Unique<VkShaderModule>	fragModule				(createShaderModule		(vk, device, m_context.getBinaryCollection().get("frag"), 0u));
1651 	const Unique<VkRenderPass>		renderPass				(makeRenderPass			(vk, device, colorFormat, m_parameters.dsFormat, sampleCount));
1652 	const Unique<VkFramebuffer>		framebuffer				(makeFramebuffer		(vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat, 0u, ASPECT_COLOR));
1653 	const Unique<VkPipelineLayout>	pipelineLayout			(makePipelineLayout		(vk, device));
1654 	const Unique<VkPipeline>		pipeline				(makeGraphicsPipeline	(vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D, ASPECT_NONE, sampleCount));
1655 	const Unique<VkCommandPool>		cmdPool					(createCommandPool		(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1656 	const Unique<VkCommandBuffer>	cmdBuffer				(allocateCommandBuffer	(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1657 
1658 	const std::vector<float>		vertexArray				(getVertices());
1659 	const deUint32					vertexCount				(static_cast<deUint32>(vertexArray.size() / 4u));
1660 	const VkDeviceSize				vertexArraySize			(vertexArray.size() * sizeof(vertexArray[0]));
1661 	const Unique<VkBuffer>			vertexBuffer			(makeBuffer				(vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1662 	const UniquePtr<Allocation>		vertexBufferAlloc		(bindBuffer				(vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1663 	const VkDeviceSize				vertexBufferOffset		(0u);
1664 
1665 	fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1666 
1667 	beginCommandBuffer(vk, *cmdBuffer);
1668 	{
1669 		const VkImageView							attachments[]					= { *colorAttachment, *colorResolveAttachment };
1670 		const VkRenderPassAttachmentBeginInfo		renderPassAttachmentBeginInfo	=
1671 		{
1672 			VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO,		//  VkStructureType		sType;
1673 			DE_NULL,													//  const void*			pNext;
1674 			DE_LENGTH_OF_ARRAY(attachments),							//  deUint32			attachmentCount;
1675 			attachments													//  const VkImageView*	pAttachments;
1676 		};
1677 
1678 		beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, &renderPassAttachmentBeginInfo);
1679 		{
1680 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1681 
1682 			vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1683 
1684 			vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1685 		}
1686 		endRenderPass(vk, *cmdBuffer);
1687 
1688 		// Color image copy
1689 		{
1690 			const VkImageMemoryBarrier	preCopyBarrier	= makeImageMemoryBarrier	(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1691 																					 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1692 																					 *colorResolveImage, colorSubresRange);
1693 			const VkBufferImageCopy		region			= makeBufferImageCopy		(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1694 																					 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1695 			const VkBufferMemoryBarrier	postCopyBarrier	= makeBufferMemoryBarrier	(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *colorResolveBuffer, 0ull, VK_WHOLE_SIZE);
1696 
1697 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1698 			vk.cmdCopyImageToBuffer(*cmdBuffer, *colorResolveImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *colorResolveBuffer, 1u, &region);
1699 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
1700 		}
1701 	}
1702 	endCommandBuffer(vk, *cmdBuffer);
1703 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1704 
1705 	{
1706 		std::string result;
1707 
1708 		if (!verifyBuffer(colorResolveBufferAlloc, colorFormat, "ResolveColor", ASPECT_COLOR))
1709 			result += " ResolveColor";
1710 
1711 		// Parse color aspect of separate samples of multisample image
1712 		for (deUint32 sampleNdx = 0; sampleNdx < sampleCount; ++sampleNdx)
1713 		{
1714 			const std::string				name				("Color" + de::toString(sampleNdx));
1715 			const Unique<VkImage>			imageSample			(makeImage	(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1716 			const UniquePtr<Allocation>		imageSampleAlloc	(bindImage	(vk, device, allocator, *imageSample, MemoryRequirement::Any));
1717 			const Unique<VkBuffer>			imageBuffer			(makeBuffer	(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1718 			const UniquePtr<Allocation>		imageBufferAlloc	(bindBuffer	(vk, device, allocator, *imageBuffer, MemoryRequirement::HostVisible));
1719 
1720 			readOneSampleFromMultisampleImage(colorFormat, colorImage, sampleNdx, colorFormat, imageSample, imageBuffer, ASPECT_COLOR);
1721 
1722 			if (!verifyBuffer(imageBufferAlloc, colorFormat, name, ASPECT_COLOR, sampleNdx))
1723 				result += " " + name;
1724 		}
1725 
1726 
1727 		if (result.empty())
1728 			return tcu::TestStatus::pass("Pass");
1729 		else
1730 			return tcu::TestStatus::fail("Fail");
1731 	}
1732 }
1733 
1734 class DepthResolveImagelessTestInstance : public DepthImagelessTestInstance
1735 {
1736 public:
1737 										DepthResolveImagelessTestInstance	(Context& context, const TestParameters& parameters);
1738 
1739 protected:
1740 	virtual tcu::TestStatus				iterate								(void);
1741 
1742 	virtual MovePtr<tcu::TextureLevel>	generateReferenceImage				(const tcu::TextureFormat&	textureFormat,
1743 																			 const AspectFlags			aspectFlags,
1744 																			 const deUint32				sample,
1745 																			 const deUint32				subpass);
1746 
1747 	virtual std::vector<float>			getVertices							(void);
1748 };
1749 
DepthResolveImagelessTestInstance(Context & context,const TestParameters & parameters)1750 DepthResolveImagelessTestInstance::DepthResolveImagelessTestInstance (Context& context, const TestParameters& parameters)
1751 	: DepthImagelessTestInstance	(context, parameters)
1752 {
1753 	context.requireDeviceFunctionality("VK_KHR_depth_stencil_resolve");
1754 
1755 	const InstanceInterface&							vki					= m_context.getInstanceInterface();
1756 	const VkPhysicalDevice								physDevice			= m_context.getPhysicalDevice();
1757 	VkPhysicalDeviceProperties2							deviceProperties;
1758 	VkPhysicalDeviceDepthStencilResolveProperties		dsResolveProperties;
1759 
1760 	deMemset(&deviceProperties, 0, sizeof(deviceProperties));
1761 	deMemset(&dsResolveProperties, 0, sizeof(dsResolveProperties));
1762 
1763 	deviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
1764 	deviceProperties.pNext = &dsResolveProperties;
1765 
1766 	dsResolveProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES;
1767 	dsResolveProperties.pNext = DE_NULL;
1768 
1769 	vki.getPhysicalDeviceProperties2(physDevice, &deviceProperties);
1770 
1771 	m_colorImageUsage |= VK_IMAGE_USAGE_SAMPLED_BIT;
1772 
1773 	checkImageFormatProperties(vki, physDevice, m_parameters.colorFormat, m_colorImageUsage, m_imageExtent2D);
1774 
1775 	m_dsImageUsage |= VK_IMAGE_USAGE_SAMPLED_BIT;
1776 
1777 	checkImageFormatProperties(vki, physDevice, m_parameters.dsFormat, m_dsImageUsage, m_imageExtent2D);
1778 }
1779 
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)1780 MovePtr<tcu::TextureLevel> DepthResolveImagelessTestInstance::generateReferenceImage (const tcu::TextureFormat&	textureFormat,
1781 																					  const AspectFlags			aspectFlags,
1782 																					  const deUint32			sample,
1783 																					  const deUint32			subpass)
1784 {
1785 	const bool					color	= ((aspectFlags & ASPECT_COLOR) != 0);
1786 	const bool					depth	= ((aspectFlags & ASPECT_DEPTH) != 0);
1787 	const bool					stencil	= ((aspectFlags & ASPECT_STENCIL) != 0);
1788 	const int					width	= m_imageExtent2D.width;
1789 	const int					height	= m_imageExtent2D.height;
1790 	MovePtr<tcu::TextureLevel>	image	(new tcu::TextureLevel(textureFormat, width, height));
1791 	tcu::PixelBufferAccess		access	(image->getAccess());
1792 
1793 	DE_ASSERT(dePop32(aspectFlags) == 1);
1794 	DE_UNREF(subpass);
1795 
1796 	if (color)
1797 	{
1798 		const tcu::Vec4		colorDraw	(tcu::RGBA::blue().toVec());
1799 		const tcu::Vec4		colorFill	(tcu::RGBA::black().toVec());
1800 		const tcu::Vec4		colorEdge0	(colorDraw);
1801 		const tcu::Vec4		colorEdge1	(colorFill);
1802 		const tcu::Vec4		colorEdge2	(colorDraw);
1803 		const tcu::Vec4		colorEdge3	(colorFill);
1804 		const tcu::Vec4		colorEdgeR	((colorDraw.x() + colorFill.x()) / 2, (colorDraw.y() + colorFill.y()) / 2, (colorDraw.z() + colorFill.z()) / 2, colorDraw.w()); // AVERAGE
1805 		const tcu::Vec4&	colorEdge	= sample == 0 ? colorEdge0
1806 										: sample == 1 ? colorEdge1
1807 										: sample == 2 ? colorEdge2
1808 										: sample == 3 ? colorEdge3
1809 										: colorEdgeR;
1810 
1811 		for (int y = 0; y < height; ++y)
1812 		for (int x = 0; x < width; ++x)
1813 		{
1814 			const int			mx			= width - 1 - x;
1815 			const tcu::Vec4&	validColor	= (y == mx) ? colorEdge
1816 											: (y >  mx) ? colorFill
1817 											: colorDraw;
1818 
1819 			access.setPixel(validColor, x, y);
1820 		}
1821 	}
1822 
1823 	if (depth)
1824 	{
1825 		const int			colorFillValue	(static_cast<int>(1.00f * 0x100));
1826 		const int			colorDrawValue	(static_cast<int>(0.00f * 0x100));
1827 		const tcu::IVec4	colorFill		(colorFillValue, colorFillValue, colorFillValue, 0xFF);
1828 		const tcu::IVec4	colorDraw		(colorDrawValue, colorDrawValue, colorDrawValue, 0xFF);
1829 		const tcu::IVec4	colorEdge0		(colorDraw);
1830 		const tcu::IVec4	colorEdge1		(colorFill);
1831 		const tcu::IVec4	colorEdge2		(colorDraw);
1832 		const tcu::IVec4	colorEdge3		(colorFill);
1833 		const tcu::IVec4	colorEdgeR		(colorEdge0); // SAMPLE_ZERO
1834 		const tcu::IVec4&	colorEdge		= sample == 0 ? colorEdge0
1835 											: sample == 1 ? colorEdge1
1836 											: sample == 2 ? colorEdge2
1837 											: sample == 3 ? colorEdge3
1838 											: colorEdgeR;
1839 
1840 		for (int y = 0; y < height; ++y)
1841 		for (int x = 0; x < width; ++x)
1842 		{
1843 			const int			mx			= width - 1 - x;
1844 			const tcu::IVec4&	validColor	= (y == mx) ? colorEdge
1845 											: (y >  mx) ? colorFill
1846 											: colorDraw;
1847 
1848 			access.setPixel(validColor, x, y);
1849 		}
1850 	}
1851 
1852 	if (stencil)
1853 	{
1854 		const int			colorFillValue	((0 * 0x100) / 4);
1855 		const int			colorDrawValue	((1 * 0x100) / 4);
1856 		const tcu::IVec4	colorFill		(colorFillValue, colorFillValue, colorFillValue, 0xFF);
1857 		const tcu::IVec4	colorDraw		(colorDrawValue, colorDrawValue, colorDrawValue, 0xFF);
1858 		const tcu::IVec4	colorEdge0		(colorDraw);
1859 		const tcu::IVec4	colorEdge1		(colorFill);
1860 		const tcu::IVec4	colorEdge2		(colorDraw);
1861 		const tcu::IVec4	colorEdge3		(colorFill);
1862 		const tcu::IVec4	colorEdgeR		(colorEdge0); // SAMPLE_ZERO
1863 		const tcu::IVec4&	colorEdge		= sample == 0 ? colorEdge0
1864 											: sample == 1 ? colorEdge1
1865 											: sample == 2 ? colorEdge2
1866 											: sample == 3 ? colorEdge3
1867 											: colorEdgeR;
1868 
1869 		for (int y = 0; y < height; ++y)
1870 		for (int x = 0; x < width; ++x)
1871 		{
1872 			const int			mx			= width - 1 - x;
1873 			const tcu::IVec4&	validColor	= (y == mx) ? colorEdge
1874 											: (y >  mx) ? colorFill
1875 											: colorDraw;
1876 
1877 			access.setPixel(validColor, x, y);
1878 		}
1879 	}
1880 
1881 	return image;
1882 }
1883 
getVertices(void)1884 std::vector<float> DepthResolveImagelessTestInstance::getVertices (void)
1885 {
1886 	const float					verticesData[]	=
1887 	{
1888 		-1.0f, -1.0f, 0.0f, 1.0f,
1889 		-1.0f, +1.0f, 0.0f, 1.0f,
1890 		+1.0f, -1.0f, 0.0f, 1.0f,
1891 		-1.0f, -1.0f, 0.5f, 1.0f,
1892 		-1.0f, +1.0f, 0.5f, 1.0f,
1893 		+1.0f, -1.0f, 0.5f, 1.0f,
1894 	};
1895 	const std::vector<float>	vertices		(verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
1896 
1897 	return vertices;
1898 }
1899 
iterate(void)1900 tcu::TestStatus DepthResolveImagelessTestInstance::iterate (void)
1901 {
1902 	const DeviceInterface&			vk							= m_context.getDeviceInterface();
1903 	const VkDevice					device						= m_context.getDevice();
1904 	const deUint32					queueFamilyIndex			= m_context.getUniversalQueueFamilyIndex();
1905 	const VkQueue					queue						= m_context.getUniversalQueue();
1906 	Allocator&						allocator					= m_context.getDefaultAllocator();
1907 
1908 	const deUint32					sampleCount					= 4u;
1909 	const VkSampleCountFlagBits		sampleCountFlag				= sampleCountBitFromSampleCount(sampleCount);
1910 	const tcu::Vec4					clearColor					= tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
1911 	const VkFormat					colorFormat					= m_parameters.colorFormat;
1912 	const VkDeviceSize				colorBufferSize				= m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
1913 	const VkImageSubresourceRange	colorSubresRange			= makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1914 
1915 	const Unique<VkImage>			colorImage					(makeImage				(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage, sampleCountFlag)));
1916 	const UniquePtr<Allocation>		colorImageAlloc				(bindImage				(vk, device, allocator, *colorImage, MemoryRequirement::Any));
1917 	const Unique<VkImageView>		colorAttachment				(makeImageView			(vk, device, *colorImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1918 
1919 	const Unique<VkImage>			colorResolveImage			(makeImage				(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
1920 	const UniquePtr<Allocation>		colorResolveImageAlloc		(bindImage				(vk, device, allocator, *colorResolveImage, MemoryRequirement::Any));
1921 	const Unique<VkImageView>		colorResolveAttachment		(makeImageView			(vk, device, *colorResolveImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
1922 	const Unique<VkBuffer>			colorResolveBuffer			(makeBuffer				(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1923 	const UniquePtr<Allocation>		colorResolveBufferAlloc		(bindBuffer				(vk, device, allocator, *colorResolveBuffer, MemoryRequirement::HostVisible));
1924 
1925 	const float						clearDepth					= 1.0f;
1926 	const deUint32					clearStencil				= 0u;
1927 	const VkFormat					dsFormat					= m_parameters.dsFormat;
1928 	const deUint32					dsImagePixelSize			= static_cast<deUint32>(tcu::getPixelSize(mapVkFormat(dsFormat)));
1929 	const VkImageAspectFlags		dsAspectFlags				= VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
1930 	const VkImageSubresourceRange	dsSubresRange				= makeImageSubresourceRange(dsAspectFlags, 0u, 1u, 0u, 1u);
1931 
1932 	const VkDeviceSize				depthBufferSize				= m_imageExtent2D.width * m_imageExtent2D.height * dsImagePixelSize;
1933 	const VkFormat					stencilBufferFormat			= getStencilBufferFormat(dsFormat);
1934 	const deUint32					stencilPixelSize			= static_cast<deUint32>(tcu::getPixelSize(mapVkFormat(stencilBufferFormat)));
1935 	const VkDeviceSize				stencilBufferSize			= m_imageExtent2D.width * m_imageExtent2D.height * stencilPixelSize;
1936 
1937 	const Unique<VkImage>			dsImage						(makeImage				(vk, device, makeImageCreateInfo(dsFormat, m_imageExtent2D, m_dsImageUsage, sampleCountFlag)));
1938 	const UniquePtr<Allocation>		dsImageAlloc				(bindImage				(vk, device, allocator, *dsImage, MemoryRequirement::Any));
1939 	const Unique<VkImageView>		dsAttachment				(makeImageView			(vk, device, *dsImage, VK_IMAGE_VIEW_TYPE_2D, dsFormat, dsSubresRange));
1940 
1941 	const Unique<VkImage>			dsResolveImage				(makeImage				(vk, device, makeImageCreateInfo(dsFormat, m_imageExtent2D, m_dsImageUsage)));
1942 	const UniquePtr<Allocation>		dsResolveImageAlloc			(bindImage				(vk, device, allocator, *dsResolveImage, MemoryRequirement::Any));
1943 	const Unique<VkImageView>		dsResolveAttachment			(makeImageView			(vk, device, *dsResolveImage, VK_IMAGE_VIEW_TYPE_2D, dsFormat, dsSubresRange));
1944 	const Unique<VkBuffer>			depthResolveBuffer			(makeBuffer				(vk, device, depthBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1945 	const UniquePtr<Allocation>		depthResolveBufferAlloc		(bindBuffer				(vk, device, allocator, *depthResolveBuffer, MemoryRequirement::HostVisible));
1946 	const Unique<VkBuffer>			stencilResolveBuffer		(makeBuffer				(vk, device, stencilBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT));
1947 	const UniquePtr<Allocation>		stencilResolveBufferAlloc	(bindBuffer				(vk, device, allocator, *stencilResolveBuffer, MemoryRequirement::HostVisible));
1948 
1949 	const Unique<VkShaderModule>	vertModule					(createShaderModule		(vk, device, m_context.getBinaryCollection().get("vert"), 0u));
1950 	const Unique<VkShaderModule>	fragModule					(createShaderModule		(vk, device, m_context.getBinaryCollection().get("frag"), 0u));
1951 	const Unique<VkRenderPass>		renderPass					(makeRenderPass			(vk, device, colorFormat, m_parameters.dsFormat, sampleCountFlag, sampleCountFlag));
1952 	const Unique<VkFramebuffer>		framebuffer					(makeFramebuffer		(vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat, m_dsImageUsage, ASPECT_COLOR|ASPECT_DEPTH_STENCIL));
1953 	const Unique<VkPipelineLayout>	pipelineLayout				(makePipelineLayout		(vk, device));
1954 	const Unique<VkPipeline>		pipeline					(makeGraphicsPipeline	(vk, device, *pipelineLayout, *renderPass, *vertModule, *fragModule, m_imageExtent2D, ASPECT_DEPTH_STENCIL, sampleCountFlag));
1955 	const Unique<VkCommandPool>		cmdPool						(createCommandPool		(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
1956 	const Unique<VkCommandBuffer>	cmdBuffer					(allocateCommandBuffer	(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1957 
1958 	const std::vector<float>		vertexArray					(getVertices());
1959 	const deUint32					vertexCount					(static_cast<deUint32>(vertexArray.size() / 4u));
1960 	const VkDeviceSize				vertexArraySize				(vertexArray.size() * sizeof(vertexArray[0]));
1961 	const Unique<VkBuffer>			vertexBuffer				(makeBuffer				(vk, device, vertexArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
1962 	const UniquePtr<Allocation>		vertexBufferAlloc			(bindBuffer				(vk, device, allocator, *vertexBuffer, MemoryRequirement::HostVisible));
1963 	const VkDeviceSize				vertexBufferOffset			(0u);
1964 
1965 	fillBuffer(vk, device, *vertexBufferAlloc, &vertexArray[0], vertexArraySize);
1966 
1967 	beginCommandBuffer(vk, *cmdBuffer);
1968 	{
1969 		const VkImageView							attachments[]					= { *colorAttachment, *dsAttachment, *colorResolveAttachment, *dsResolveAttachment };
1970 		const VkRenderPassAttachmentBeginInfo		renderPassAttachmentBeginInfo	=
1971 		{
1972 			VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO,		//  VkStructureType		sType;
1973 			DE_NULL,													//  const void*			pNext;
1974 			DE_LENGTH_OF_ARRAY(attachments),							//  deUint32			attachmentCount;
1975 			attachments													//  const VkImageView*	pAttachments;
1976 		};
1977 
1978 		beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, clearDepth, clearStencil, &renderPassAttachmentBeginInfo);
1979 		{
1980 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1981 
1982 			vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertexBuffer, &vertexBufferOffset);
1983 
1984 			vk.cmdDraw(*cmdBuffer, vertexCount, 1u, 0u, 0u);
1985 		}
1986 		endRenderPass(vk, *cmdBuffer);
1987 
1988 		// Color resolve image copy
1989 		{
1990 			const VkImageMemoryBarrier	preCopyBarrier	= makeImageMemoryBarrier	(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1991 																					 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1992 																					 *colorResolveImage, colorSubresRange);
1993 			const VkBufferImageCopy		region			= makeBufferImageCopy		(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
1994 																					 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
1995 			const VkBufferMemoryBarrier	postCopyBarrier	= makeBufferMemoryBarrier	(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *colorResolveBuffer, 0ull, VK_WHOLE_SIZE);
1996 
1997 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
1998 			vk.cmdCopyImageToBuffer(*cmdBuffer, *colorResolveImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *colorResolveBuffer, 1u, &region);
1999 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
2000 		}
2001 
2002 		// Depth/Stencil resolve image copy
2003 		{
2004 			const VkImageMemoryBarrier	preCopyBarrier		= makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_READ_BIT,
2005 																					 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2006 																					 *dsResolveImage, dsSubresRange);
2007 			const VkBufferImageCopy		depthCopyRegion		= makeBufferImageCopy(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2008 																				  makeImageSubresourceLayers(VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u));
2009 			const VkBufferImageCopy		stencilCopyRegion	= makeBufferImageCopy(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2010 																				  makeImageSubresourceLayers(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u));
2011 			const VkBufferMemoryBarrier	postCopyBarriers[]	=
2012 			{
2013 				makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *depthResolveBuffer, 0ull, VK_WHOLE_SIZE),
2014 				makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *stencilResolveBuffer, 0ull, VK_WHOLE_SIZE),
2015 			};
2016 
2017 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2018 			vk.cmdCopyImageToBuffer(*cmdBuffer, *dsResolveImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *depthResolveBuffer, 1u, &depthCopyRegion);
2019 			vk.cmdCopyImageToBuffer(*cmdBuffer, *dsResolveImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *stencilResolveBuffer, 1u, &stencilCopyRegion);
2020 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, DE_LENGTH_OF_ARRAY(postCopyBarriers), postCopyBarriers, DE_NULL, 0u);
2021 		}
2022 	}
2023 	endCommandBuffer(vk, *cmdBuffer);
2024 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
2025 
2026 	{
2027 		std::string result;
2028 
2029 		if (!verifyBuffer(colorResolveBufferAlloc, colorFormat, "ResolveColor", ASPECT_COLOR))
2030 			result += " ResolveColor";
2031 
2032 		if (!verifyBuffer(depthResolveBufferAlloc, dsFormat, "ResolveDepth", ASPECT_DEPTH))
2033 			result += " ResolveDepth";
2034 
2035 		if (!verifyBuffer(stencilResolveBufferAlloc, stencilBufferFormat, "ResolveStencil", ASPECT_STENCIL))
2036 			result += " ResolveStencil";
2037 
2038 		// Parse color aspect of separate samples of multisample image
2039 		for (deUint32 sampleNdx = 0; sampleNdx < sampleCount; ++sampleNdx)
2040 		{
2041 			const std::string				name				("Color" + de::toString(sampleNdx));
2042 			const Unique<VkImage>			imageSample			(makeImage	(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
2043 			const UniquePtr<Allocation>		imageSampleAlloc	(bindImage	(vk, device, allocator, *imageSample, MemoryRequirement::Any));
2044 			const Unique<VkBuffer>			imageBuffer			(makeBuffer	(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2045 			const UniquePtr<Allocation>		imageBufferAlloc	(bindBuffer	(vk, device, allocator, *imageBuffer, MemoryRequirement::HostVisible));
2046 
2047 			readOneSampleFromMultisampleImage(colorFormat, colorImage, sampleNdx, colorFormat, imageSample, imageBuffer, ASPECT_COLOR);
2048 
2049 			if (!verifyBuffer(imageBufferAlloc, colorFormat, name, ASPECT_COLOR, sampleNdx))
2050 				result += " " + name;
2051 		}
2052 
2053 		// Parse depth aspect of separate samples of multisample image
2054 		for (deUint32 sampleNdx = 0; sampleNdx < sampleCount; ++sampleNdx)
2055 		{
2056 			const std::string				name				("Depth" + de::toString(sampleNdx));
2057 			const Unique<VkImage>			imageSample			(makeImage	(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
2058 			const UniquePtr<Allocation>		imageSampleAlloc	(bindImage	(vk, device, allocator, *imageSample, MemoryRequirement::Any));
2059 			const Unique<VkBuffer>			imageBuffer			(makeBuffer	(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2060 			const UniquePtr<Allocation>		imageBufferAlloc	(bindBuffer	(vk, device, allocator, *imageBuffer, MemoryRequirement::HostVisible));
2061 
2062 			readOneSampleFromMultisampleImage(dsFormat, dsImage, sampleNdx, colorFormat, imageSample, imageBuffer, ASPECT_DEPTH);
2063 
2064 			if (!verifyBuffer(imageBufferAlloc, colorFormat, name, ASPECT_DEPTH, sampleNdx))
2065 				result += " " + name;
2066 		}
2067 
2068 		// Parse stencil aspect of separate samples of multisample image
2069 		for (deUint32 sampleNdx = 0; sampleNdx < sampleCount; ++sampleNdx)
2070 		{
2071 			const std::string				name				("Stencil" + de::toString(sampleNdx));
2072 			const Unique<VkImage>			imageSample			(makeImage	(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage)));
2073 			const UniquePtr<Allocation>		imageSampleAlloc	(bindImage	(vk, device, allocator, *imageSample, MemoryRequirement::Any));
2074 			const Unique<VkBuffer>			imageBuffer			(makeBuffer	(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2075 			const UniquePtr<Allocation>		imageBufferAlloc	(bindBuffer	(vk, device, allocator, *imageBuffer, MemoryRequirement::HostVisible));
2076 
2077 			readOneSampleFromMultisampleImage(dsFormat, dsImage, sampleNdx, colorFormat, imageSample, imageBuffer, ASPECT_STENCIL);
2078 
2079 			if (!verifyBuffer(imageBufferAlloc, colorFormat, name, ASPECT_STENCIL, sampleNdx))
2080 				result += " " + name;
2081 		}
2082 
2083 		if (result.empty())
2084 			return tcu::TestStatus::pass("Pass");
2085 		else
2086 			return tcu::TestStatus::fail("Following parts of image are incorrect:" + result);
2087 	}
2088 }
2089 
2090 class MultisubpassTestInstance : public ColorImagelessTestInstance
2091 {
2092 public:
2093 										MultisubpassTestInstance	(Context& context, const TestParameters& parameters);
2094 
2095 protected:
2096 	virtual tcu::TestStatus				iterate						(void);
2097 
2098 	virtual std::vector<float>			getVertices					(void);
2099 
2100 	virtual MovePtr<tcu::TextureLevel>	generateReferenceImage		(const tcu::TextureFormat&	textureFormat,
2101 																	 const AspectFlags			aspectFlags,
2102 																	 const deUint32				sample,
2103 																	 const deUint32				subpass);
2104 };
2105 
MultisubpassTestInstance(Context & context,const TestParameters & parameters)2106 MultisubpassTestInstance::MultisubpassTestInstance (Context& context, const TestParameters& parameters)
2107 	: ColorImagelessTestInstance	(context, parameters)
2108 {
2109 }
2110 
getVertices(void)2111 std::vector<float> MultisubpassTestInstance::getVertices (void)
2112 {
2113 	const float					verticesData[]	=
2114 	{
2115 		-1.0f,  0.0f, 0.0f, 1.0f,
2116 		-1.0f, +1.0f, 0.0f, 1.0f,
2117 		+1.0f,  0.0f, 0.0f, 1.0f,
2118 		-1.0f, +1.0f, 0.0f, 1.0f,
2119 		+1.0f,  0.0f, 0.0f, 1.0f,
2120 		+1.0f, +1.0f, 0.0f, 1.0f,
2121 	};
2122 	const std::vector<float>	vertices		(verticesData, verticesData + DE_LENGTH_OF_ARRAY(verticesData));
2123 
2124 	return vertices;
2125 }
2126 
generateReferenceImage(const tcu::TextureFormat & textureFormat,const AspectFlags aspectFlags,const deUint32 sample,const deUint32 subpass)2127 MovePtr<tcu::TextureLevel> MultisubpassTestInstance::generateReferenceImage (const tcu::TextureFormat&	textureFormat,
2128 																			 const AspectFlags			aspectFlags,
2129 																			 const deUint32				sample,
2130 																			 const deUint32				subpass)
2131 {
2132 	const int					width			= m_imageExtent2D.width;
2133 	const int					height			= m_imageExtent2D.height;
2134 	const tcu::Vec4				colorDraw0		(0.0f, 0.0f, 1.0f, 1.0f);
2135 	const tcu::Vec4				colorFill0		(tcu::RGBA::black().toVec());
2136 	const tcu::Vec4				colorDraw1		(colorDraw0.x(), 1.0f, colorDraw0.z(), 1.0f);
2137 	const tcu::Vec4				colorFill1		(colorFill0.x(), 1.0f, colorFill0.z(), 1.0f);
2138 	const tcu::Vec4&			colorDraw		((subpass == 0) ? colorDraw0 : colorDraw1);
2139 	const tcu::Vec4&			colorFill		((subpass == 0) ? colorFill0 : colorFill1);
2140 	MovePtr<tcu::TextureLevel>	image			(new tcu::TextureLevel(textureFormat, width, height));
2141 	tcu::PixelBufferAccess		access			(image->getAccess());
2142 
2143 	DE_UNREF(aspectFlags);
2144 	DE_ASSERT(aspectFlags == ASPECT_COLOR);
2145 	DE_UNREF(sample);
2146 	DE_ASSERT(sample == NO_SAMPLE);
2147 	DE_ASSERT(subpass != NO_SUBPASS);
2148 
2149 	for (int y = 0; y < height; ++y)
2150 	{
2151 		const tcu::Vec4&	validColor	= (y < height / 2) ? colorFill : colorDraw;
2152 
2153 		for (int x = 0; x < width; ++x)
2154 			access.setPixel(validColor, x, y);
2155 	}
2156 
2157 	return image;
2158 }
2159 
iterate(void)2160 tcu::TestStatus MultisubpassTestInstance::iterate (void)
2161 {
2162 	const DeviceInterface&				vk					= m_context.getDeviceInterface();
2163 	const VkDevice						device				= m_context.getDevice();
2164 	const deUint32						queueFamilyIndex	= m_context.getUniversalQueueFamilyIndex();
2165 	const VkQueue						queue				= m_context.getUniversalQueue();
2166 	Allocator&							allocator			= m_context.getDefaultAllocator();
2167 
2168 	const tcu::Vec4						clearColor			= tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
2169 	const VkFormat						colorFormat			= m_parameters.colorFormat;
2170 	const VkDeviceSize					colorBufferSize		= m_imageExtent2D.width * m_imageExtent2D.height * tcu::getPixelSize(mapVkFormat(colorFormat));
2171 	const VkImageSubresourceRange		colorSubresRange	= makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
2172 
2173 	const Unique<VkImage>				color0Image			(makeImage				(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)));
2174 	const UniquePtr<Allocation>			color0ImageAlloc	(bindImage				(vk, device, allocator, *color0Image, MemoryRequirement::Any));
2175 	const Unique<VkImageView>			color0Attachment	(makeImageView			(vk, device, *color0Image, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
2176 	const Unique<VkBuffer>				color0Buffer		(makeBuffer				(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2177 	const UniquePtr<Allocation>			color0BufferAlloc	(bindBuffer				(vk, device, allocator, *color0Buffer, MemoryRequirement::HostVisible));
2178 
2179 	const Unique<VkImage>				color1Image			(makeImage				(vk, device, makeImageCreateInfo(colorFormat, m_imageExtent2D, m_colorImageUsage | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)));
2180 	const UniquePtr<Allocation>			color1ImageAlloc	(bindImage				(vk, device, allocator, *color1Image, MemoryRequirement::Any));
2181 	const Unique<VkImageView>			color1Attachment	(makeImageView			(vk, device, *color1Image, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorSubresRange));
2182 	const Unique<VkBuffer>				color1Buffer		(makeBuffer				(vk, device, colorBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT));
2183 	const UniquePtr<Allocation>			color1BufferAlloc	(bindBuffer				(vk, device, allocator, *color1Buffer, MemoryRequirement::HostVisible));
2184 
2185 	const VkDescriptorType				descriptorType		(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT);
2186 	const Unique<VkDescriptorSetLayout>	descriptorSetLayout	(DescriptorSetLayoutBuilder()
2187 		.addSingleBinding(descriptorType, VK_SHADER_STAGE_FRAGMENT_BIT)
2188 		.build(vk, device));
2189 	const Unique<VkDescriptorPool>		descriptorPool		(DescriptorPoolBuilder()
2190 		.addType(descriptorType)
2191 		.build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u));
2192 	const Unique<VkDescriptorSet>		descriptorSet		(makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout));
2193 	const VkDescriptorImageInfo			imageDescriptorInfo	(makeDescriptorImageInfo(DE_NULL, *color0Attachment, VK_IMAGE_LAYOUT_GENERAL));
2194 
2195 	DescriptorSetUpdateBuilder()
2196 		.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), descriptorType, &imageDescriptorInfo)
2197 		.update(vk, device);
2198 
2199 	const Unique<VkRenderPass>			renderPass			(makeRenderPass			(vk, device, colorFormat, DE_NULL));
2200 	const Unique<VkFramebuffer>			framebuffer			(makeFramebuffer		(vk, device, *renderPass, m_imageExtent2D, &colorFormat, m_colorImageUsage, &m_parameters.dsFormat, 0u, ASPECT_NONE, 1u));
2201 	const Unique<VkCommandPool>			cmdPool				(createCommandPool		(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex));
2202 	const Unique<VkCommandBuffer>		cmdBuffer			(allocateCommandBuffer	(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
2203 
2204 	const Unique<VkShaderModule>		vertModule0			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("vert"), 0u));
2205 	const Unique<VkShaderModule>		fragModule0			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("frag"), 0u));
2206 	const Unique<VkPipelineLayout>		pipelineLayout0		(makePipelineLayout		(vk, device));
2207 	const Unique<VkPipeline>			pipeline0			(makeGraphicsPipeline	(vk, device, *pipelineLayout0, *renderPass, *vertModule0, *fragModule0, m_imageExtent2D));
2208 
2209 	const Unique<VkShaderModule>		vertModule1			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("vert1"), 0u));
2210 	const Unique<VkShaderModule>		fragModule1			(createShaderModule		(vk, device, m_context.getBinaryCollection().get("frag1"), 0u));
2211 	const Unique<VkPipelineLayout>		pipelineLayout1		(makePipelineLayout		(vk, device, 1u, &*descriptorSetLayout));
2212 	const Unique<VkPipeline>			pipeline1			(makeGraphicsPipeline	(vk, device, *pipelineLayout1, *renderPass, *vertModule1, *fragModule1, m_imageExtent2D, 0u, VK_SAMPLE_COUNT_1_BIT, 1u));
2213 
2214 	const std::vector<float>			vertex0Array		(getVertices());
2215 	const deUint32						vertex0Count		(static_cast<deUint32>(vertex0Array.size() / 4u));
2216 	const VkDeviceSize					vertex0ArraySize	(vertex0Array.size() * sizeof(vertex0Array[0]));
2217 	const Unique<VkBuffer>				vertex0Buffer		(makeBuffer				(vk, device, vertex0ArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
2218 	const UniquePtr<Allocation>			vertex0BufferAlloc	(bindBuffer				(vk, device, allocator, *vertex0Buffer, MemoryRequirement::HostVisible));
2219 	const VkDeviceSize					vertex0BufferOffset	(0u);
2220 
2221 	const std::vector<float>			vertex1Array		(getFullQuadVertices());
2222 	const deUint32						vertex1Count		(static_cast<deUint32>(vertex1Array.size() / 4u));
2223 	const VkDeviceSize					vertex1ArraySize	(vertex1Array.size() * sizeof(vertex1Array[0]));
2224 	const Unique<VkBuffer>				vertex1Buffer		(makeBuffer				(vk, device, vertex1ArraySize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
2225 	const UniquePtr<Allocation>			vertex1BufferAlloc	(bindBuffer				(vk, device, allocator, *vertex1Buffer, MemoryRequirement::HostVisible));
2226 	const VkDeviceSize					vertex1BufferOffset	(0u);
2227 
2228 	fillBuffer(vk, device, *vertex0BufferAlloc, &vertex0Array[0], vertex0ArraySize);
2229 	fillBuffer(vk, device, *vertex1BufferAlloc, &vertex1Array[0], vertex1ArraySize);
2230 
2231 	beginCommandBuffer(vk, *cmdBuffer);
2232 	{
2233 		const VkImageView							attachments[]					= { *color0Attachment, *color1Attachment };
2234 		const VkRenderPassAttachmentBeginInfo		renderPassAttachmentBeginInfo	=
2235 		{
2236 			VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO,		//  VkStructureType		sType;
2237 			DE_NULL,													//  const void*			pNext;
2238 			DE_LENGTH_OF_ARRAY(attachments),							//  deUint32			attachmentCount;
2239 			&attachments[0]												//  const VkImageView*	pAttachments;
2240 		};
2241 
2242 		beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, makeRect2D(m_imageExtent2D), clearColor, &renderPassAttachmentBeginInfo);
2243 		{
2244 			{
2245 				vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline0);
2246 
2247 				vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertex0Buffer, &vertex0BufferOffset);
2248 
2249 				vk.cmdDraw(*cmdBuffer, vertex0Count, 1u, 0u, 0u);
2250 			}
2251 
2252 			vk.cmdNextSubpass(*cmdBuffer, VK_SUBPASS_CONTENTS_INLINE);
2253 
2254 			{
2255 				vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline1);
2256 
2257 				vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &*vertex1Buffer, &vertex1BufferOffset);
2258 
2259 				vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout1, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL);
2260 
2261 				vk.cmdDraw(*cmdBuffer, vertex1Count, 1u, 0u, 0u);
2262 			}
2263 		}
2264 		endRenderPass(vk, *cmdBuffer);
2265 
2266 		// Subpass0 color image copy
2267 		{
2268 			const VkImageMemoryBarrier	preCopyBarrier	= makeImageMemoryBarrier	(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
2269 																					 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2270 																					 *color0Image, colorSubresRange);
2271 			const VkBufferImageCopy		region			= makeBufferImageCopy		(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2272 																					 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
2273 			const VkBufferMemoryBarrier	postCopyBarrier	= makeBufferMemoryBarrier	(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *color0Buffer, 0ull, VK_WHOLE_SIZE);
2274 
2275 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2276 			vk.cmdCopyImageToBuffer(*cmdBuffer, *color0Image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *color0Buffer, 1u, &region);
2277 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
2278 		}
2279 
2280 		// Subpass1 color image copy
2281 		{
2282 			const VkImageMemoryBarrier	preCopyBarrier	= makeImageMemoryBarrier	(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
2283 																					 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
2284 																					 *color1Image, colorSubresRange);
2285 			const VkBufferImageCopy		region			= makeBufferImageCopy		(makeExtent3D(m_imageExtent2D.width, m_imageExtent2D.height, 1u),
2286 																					 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u));
2287 			const VkBufferMemoryBarrier	postCopyBarrier	= makeBufferMemoryBarrier	(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, *color1Buffer, 0ull, VK_WHOLE_SIZE);
2288 
2289 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preCopyBarrier);
2290 			vk.cmdCopyImageToBuffer(*cmdBuffer, *color1Image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *color1Buffer, 1u, &region);
2291 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &postCopyBarrier, DE_NULL, 0u);
2292 		}
2293 	}
2294 	endCommandBuffer(vk, *cmdBuffer);
2295 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
2296 
2297 	{
2298 		std::string result;
2299 
2300 		if (!verifyBuffer(color0BufferAlloc, colorFormat, "ColorSubpass0", ASPECT_COLOR, NO_SAMPLE, 0u))
2301 			result += " ColorSubpass0";
2302 
2303 		if (!verifyBuffer(color1BufferAlloc, colorFormat, "ColorSubpass1", ASPECT_COLOR, NO_SAMPLE, 1u))
2304 			result += " ColorSubpass1";
2305 
2306 		if (result.empty())
2307 			return tcu::TestStatus::pass("Pass");
2308 		else
2309 			return tcu::TestStatus::fail("Following parts of image are incorrect:" + result);
2310 	}
2311 }
2312 
2313 class BaseTestCase : public TestCase
2314 {
2315 public:
2316 							BaseTestCase	(tcu::TestContext& context, const std::string& name, const std::string& description, const TestParameters& parameters);
2317 	virtual					~BaseTestCase	(void);
2318 
2319 protected:
2320 	virtual void			checkSupport	(Context& context) const;
2321 	virtual void			initPrograms	(SourceCollections& programCollection) const;
2322 	virtual TestInstance*	createInstance	(Context& context) const;
2323 
2324 	const TestParameters	m_parameters;
2325 };
2326 
BaseTestCase(tcu::TestContext & context,const std::string & name,const std::string & description,const TestParameters & parameters)2327 BaseTestCase::BaseTestCase (tcu::TestContext& context, const std::string& name, const std::string& description, const TestParameters& parameters)
2328 	: TestCase		(context, name, description)
2329 	, m_parameters	(parameters)
2330 {
2331 }
2332 
~BaseTestCase()2333 BaseTestCase::~BaseTestCase ()
2334 {
2335 }
2336 
checkSupport(Context & context) const2337 void BaseTestCase::checkSupport (Context& context) const
2338 {
2339 	if (m_parameters.testType == TEST_TYPE_COLOR_RESOLVE || m_parameters.testType == TEST_TYPE_DEPTH_STENCIL_RESOLVE)
2340 	{
2341 		if (!context.getDeviceProperties().limits.standardSampleLocations)
2342 			TCU_THROW(NotSupportedError, "Non-standard sample locations are not supported");
2343 	}
2344 }
2345 
initPrograms(SourceCollections & programCollection) const2346 void BaseTestCase::initPrograms (SourceCollections& programCollection) const
2347 {
2348 	// Vertex shader
2349 	{
2350 		std::ostringstream src;
2351 
2352 		if (m_parameters.testType == TEST_TYPE_COLOR || m_parameters.testType == TEST_TYPE_COLOR_RESOLVE || m_parameters.testType == TEST_TYPE_DEPTH_STENCIL)
2353 		{
2354 			src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2355 				<< "\n"
2356 				<< "layout(location = 0) in highp vec4 a_position;\n"
2357 				<< "layout(location = 0) out highp vec4 a_color;\n"
2358 				<< "\n"
2359 				<< "void main (void)\n"
2360 				<< "{\n"
2361 				<< "    gl_Position = a_position;\n"
2362 				<< "    if (gl_VertexIndex < 6)\n"
2363 				<< "        a_color = vec4(0.75f, 0.75f, 0.75f, 1.0f);\n"
2364 				<< "    else\n"
2365 				<< "        a_color = vec4(1.00f, 1.00f, 1.00f, 1.0f);\n"
2366 				<< "}\n";
2367 		}
2368 
2369 		if (m_parameters.testType == TEST_TYPE_DEPTH_STENCIL_RESOLVE)
2370 		{
2371 			src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2372 				<< "\n"
2373 				<< "layout(location = 0) in highp vec4 a_position;\n"
2374 				<< "layout(location = 0) out highp vec4 a_color;\n"
2375 				<< "\n"
2376 				<< "void main (void)\n"
2377 				<< "{\n"
2378 				<< "    gl_Position = a_position;\n"
2379 				<< "    if (gl_VertexIndex < 3)\n"
2380 				<< "        a_color = vec4(0.00f, 0.00f, 1.00f, 1.0f);\n"
2381 				<< "    else\n"
2382 				<< "        a_color = vec4(0.00f, 1.00f, 0.00f, 1.0f);\n"
2383 				<< "}\n";
2384 		}
2385 
2386 		if (m_parameters.testType == TEST_TYPE_MULTISUBPASS)
2387 		{
2388 			src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2389 				<< "\n"
2390 				<< "layout(location = 0) in highp vec4 a_position;\n"
2391 				<< "layout(location = 0) out highp vec4 a_color;\n"
2392 				<< "\n"
2393 				<< "void main (void)\n"
2394 				<< "{\n"
2395 				<< "    gl_Position = a_position;\n"
2396 				<< "    a_color = vec4(0.0f, 0.0f, 1.0f, 1.0f);\n"
2397 				<< "}\n";
2398 		}
2399 
2400 		programCollection.glslSources.add("vert") << glu::VertexSource(src.str());
2401 	}
2402 
2403 	// Fragment shader
2404 	{
2405 		std::ostringstream src;
2406 
2407 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2408 			<< "\n"
2409 			<< "layout(location = 0) in highp vec4 a_color;\n"
2410 			<< "layout(location = 0) out highp vec4 o_color;\n"
2411 			<< "\n"
2412 			<< "void main (void)\n"
2413 			<< "{\n"
2414 			<< "    o_color = a_color;\n"
2415 			<< "}\n";
2416 
2417 		programCollection.glslSources.add("frag") << glu::FragmentSource(src.str());
2418 	}
2419 
2420 	// Additional shaders
2421 	if (m_parameters.testType == TEST_TYPE_COLOR_RESOLVE || m_parameters.testType == TEST_TYPE_DEPTH_STENCIL_RESOLVE)
2422 	{
2423 		// Vertex shader
2424 		{
2425 			std::ostringstream src;
2426 
2427 			src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2428 				<< "\n"
2429 				<< "layout(location = 0) in highp vec4 a_position;\n"
2430 				<< "\n"
2431 				<< "void main (void)\n"
2432 				<< "{\n"
2433 				<< "    gl_Position = a_position;\n"
2434 				<< "}\n";
2435 
2436 			programCollection.glslSources.add("demultisample-vert") << glu::VertexSource(src.str());
2437 		}
2438 
2439 		// Fragment shader
2440 		{
2441 			// Color
2442 			{
2443 				std::ostringstream src;
2444 
2445 				src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2446 					<< "\n"
2447 					<< "layout(set = 0, binding = 0) uniform sampler2DMS u_ms_image_sampler;\n"
2448 					<< "layout(push_constant) uniform PushConstantsBlock {\n"
2449 					<< "    highp int sampleID;\n"
2450 					<< "} pushConstants;\n"
2451 					<< "layout(location = 0) out highp vec4 o_color;\n"
2452 					<< "\n"
2453 					<< "void main (void)\n"
2454 					<< "{\n"
2455 					<< "    o_color = texelFetch(u_ms_image_sampler, ivec2(gl_FragCoord.xy), pushConstants.sampleID);\n"
2456 					<< "}\n";
2457 
2458 				programCollection.glslSources.add("demultisample-color-frag") << glu::FragmentSource(src.str());
2459 			}
2460 
2461 			// Depth
2462 			{
2463 				std::ostringstream src;
2464 
2465 				// Depth-component textures are treated as one-component floating-point textures.
2466 				src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2467 					<< "\n"
2468 					<< "layout(binding = 0) uniform sampler2DMS u_ms_image_sampler;\n"
2469 					<< "layout(push_constant) uniform PushConstantsBlock {\n"
2470 					<< "    highp int sampleID;\n"
2471 					<< "} pushConstants;\n"
2472 					<< "layout(location = 0) out highp vec4 o_color;\n"
2473 					<< "\n"
2474 					<< "void main (void)\n"
2475 					<< "{\n"
2476 					<< "    vec4 val = texelFetch(u_ms_image_sampler, ivec2(gl_FragCoord.xy), pushConstants.sampleID);\n"
2477 					<< "    o_color = vec4(val.x, val.x, val.x, 1.0);\n"
2478 					<< "}\n";
2479 
2480 				programCollection.glslSources.add("demultisample-depth-frag") << glu::FragmentSource(src.str());
2481 			}
2482 
2483 			// Stencil
2484 			{
2485 				std::ostringstream src;
2486 
2487 				// Stencil-component textures are treated as one-component unsigned integer textures.
2488 				src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2489 					<< "\n"
2490 					<< "layout(binding = 0) uniform usampler2DMS u_ms_image_sampler;\n"
2491 					<< "layout(push_constant) uniform PushConstantsBlock {\n"
2492 					<< "    highp int sampleID;\n"
2493 					<< "} pushConstants;\n"
2494 					<< "layout(location = 0) out highp vec4 o_color;\n"
2495 					<< "\n"
2496 					<< "void main (void)\n"
2497 					<< "{\n"
2498 					<< "    uvec4 uVal = texelFetch(u_ms_image_sampler, ivec2(gl_FragCoord.xy), pushConstants.sampleID);\n"
2499 					<< "    float val = float(uVal.x) / 4.0f;\n"
2500 					<< "    o_color = vec4(val, val, val, 1.0);\n"
2501 					<< "}\n";
2502 
2503 				programCollection.glslSources.add("demultisample-stencil-frag") << glu::FragmentSource(src.str());
2504 			}
2505 		}
2506 	}
2507 
2508 	if (m_parameters.testType == TEST_TYPE_MULTISUBPASS)
2509 	{
2510 		// Vertex shader
2511 		{
2512 			std::ostringstream src;
2513 
2514 			src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2515 				<< "\n"
2516 				<< "layout(location = 0) in highp vec4 a_position;\n"
2517 				<< "\n"
2518 				<< "void main (void)\n"
2519 				<< "{\n"
2520 				<< "    gl_Position = a_position;\n"
2521 				<< "}\n";
2522 
2523 			programCollection.glslSources.add("vert1") << glu::VertexSource(src.str());
2524 		}
2525 
2526 		// Fragment shader
2527 		{
2528 			std::ostringstream src;
2529 
2530 			src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
2531 				<< "\n"
2532 				<< "layout(input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput u_colors;\n"
2533 				<< "layout(location = 0) out highp vec4 o_color;\n"
2534 				<< "\n"
2535 				<< "void main (void)\n"
2536 				<< "{\n"
2537 				<< "    o_color = subpassLoad(u_colors);\n"
2538 				<< "    o_color.g = 1.0f;\n"
2539 				<< "    o_color.a = 1.0f;\n"
2540 				<< "}\n";
2541 
2542 			programCollection.glslSources.add("frag1") << glu::FragmentSource(src.str());
2543 		}
2544 	}
2545 
2546 
2547 	return;
2548 }
2549 
createInstance(Context & context) const2550 TestInstance*	BaseTestCase::createInstance (Context& context) const
2551 {
2552 	if (m_parameters.testType == TEST_TYPE_COLOR)
2553 		return new ColorImagelessTestInstance(context, m_parameters);
2554 
2555 	if (m_parameters.testType == TEST_TYPE_DEPTH_STENCIL)
2556 		return new DepthImagelessTestInstance(context, m_parameters);
2557 
2558 	if (m_parameters.testType == TEST_TYPE_COLOR_RESOLVE)
2559 		return new ColorResolveImagelessTestInstance(context, m_parameters);
2560 
2561 	if (m_parameters.testType == TEST_TYPE_DEPTH_STENCIL_RESOLVE)
2562 		return new DepthResolveImagelessTestInstance(context, m_parameters);
2563 
2564 	if (m_parameters.testType == TEST_TYPE_MULTISUBPASS)
2565 		return new MultisubpassTestInstance(context, m_parameters);
2566 
2567 	TCU_THROW(InternalError, "Unknown test type specified");
2568 }
2569 
imagelessColorTests(tcu::TestContext & testCtx)2570 tcu::TestNode*	imagelessColorTests (tcu::TestContext& testCtx)
2571 {
2572 	TestParameters	parameters	=
2573 	{
2574 		TEST_TYPE_COLOR,					//  TestType	testType;
2575 		VK_FORMAT_R8G8B8A8_UNORM,			//  VkFormat	colorFormat;
2576 		VK_FORMAT_UNDEFINED,				//  VkFormat	dsFormat;
2577 	};
2578 
2579 	return new BaseTestCase(testCtx, "color", "Imageless color attachment test", parameters);
2580 }
2581 
imagelessDepthStencilTests(tcu::TestContext & testCtx)2582 tcu::TestNode*	imagelessDepthStencilTests (tcu::TestContext& testCtx)
2583 {
2584 	TestParameters	parameters	=
2585 	{
2586 		TEST_TYPE_DEPTH_STENCIL,			//  TestType	testType;
2587 		VK_FORMAT_R8G8B8A8_UNORM,			//  VkFormat	colorFormat;
2588 		VK_FORMAT_D24_UNORM_S8_UINT,		//  VkFormat	dsFormat;
2589 	};
2590 
2591 	return new BaseTestCase(testCtx, "depth_stencil", "Imageless depth/stencil attachment test", parameters);
2592 }
2593 
imagelessColorResolveTests(tcu::TestContext & testCtx)2594 tcu::TestNode*	imagelessColorResolveTests (tcu::TestContext& testCtx)
2595 {
2596 	TestParameters	parameters	=
2597 	{
2598 		TEST_TYPE_COLOR_RESOLVE,			//  TestType	testType;
2599 		VK_FORMAT_R8G8B8A8_UNORM,			//  VkFormat	colorFormat;
2600 		VK_FORMAT_UNDEFINED,				//  VkFormat	dsFormat;
2601 	};
2602 
2603 	return new BaseTestCase(testCtx, "color_resolve", "Imageless color attachment resolve test", parameters);
2604 }
2605 
imagelessDepthStencilResolveTests(tcu::TestContext & testCtx)2606 tcu::TestNode*	imagelessDepthStencilResolveTests (tcu::TestContext& testCtx)
2607 {
2608 	TestParameters	parameters	=
2609 	{
2610 		TEST_TYPE_DEPTH_STENCIL_RESOLVE,	//  TestType	testType;
2611 		VK_FORMAT_R8G8B8A8_UNORM,			//  VkFormat	colorFormat;
2612 		VK_FORMAT_D24_UNORM_S8_UINT,		//  VkFormat	dsFormat;
2613 	};
2614 
2615 	return new BaseTestCase(testCtx, "depth_stencil_resolve", "Imageless color and depth/stencil attachment resolve test", parameters);
2616 }
2617 
imagelessMultisubpass(tcu::TestContext & testCtx)2618 tcu::TestNode*	imagelessMultisubpass (tcu::TestContext& testCtx)
2619 {
2620 	TestParameters	parameters	=
2621 	{
2622 		TEST_TYPE_MULTISUBPASS,			//  TestType	testType;
2623 		VK_FORMAT_R8G8B8A8_UNORM,		//  VkFormat	colorFormat;
2624 		VK_FORMAT_UNDEFINED,			//  VkFormat	dsFormat;
2625 	};
2626 
2627 	return new BaseTestCase(testCtx, "multisubpass", "Multi-subpass test", parameters);
2628 }
2629 
2630 }	// anonymous
2631 
createTests(tcu::TestContext & testCtx)2632 tcu::TestCaseGroup* createTests (tcu::TestContext& testCtx)
2633 {
2634 	de::MovePtr<tcu::TestCaseGroup> imagelessFramebufferGroup (new tcu::TestCaseGroup(testCtx, "imageless_framebuffer", "Imageless Framebuffer tests"));
2635 
2636 	imagelessFramebufferGroup->addChild(imagelessColorTests(testCtx));						// Color only test
2637 	imagelessFramebufferGroup->addChild(imagelessDepthStencilTests(testCtx));				// Color and depth/stencil test
2638 	imagelessFramebufferGroup->addChild(imagelessColorResolveTests(testCtx));				// Color and color resolve test
2639 	imagelessFramebufferGroup->addChild(imagelessDepthStencilResolveTests(testCtx));		// Color, depth and depth resolve test (interaction with VK_KHR_depth_stencil_resolve)
2640 	imagelessFramebufferGroup->addChild(imagelessMultisubpass(testCtx));					// Multi-subpass test
2641 
2642 	return imagelessFramebufferGroup.release();
2643 }
2644 
2645 } // imageless
2646 } // vkt
2647