1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 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 Statistics Query Tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktQueryPoolStatisticsTests.hpp"
25 #include "vktTestCase.hpp"
26 
27 #include "vktDrawImageObjectUtil.hpp"
28 #include "vktDrawBufferObjectUtil.hpp"
29 #include "vktDrawCreateInfoUtil.hpp"
30 #include "vkBuilderUtil.hpp"
31 #include "vkRefUtil.hpp"
32 #include "vkPrograms.hpp"
33 #include "vkTypeUtil.hpp"
34 #include "vkCmdUtil.hpp"
35 #include "vkObjUtil.hpp"
36 
37 #include "deMath.h"
38 
39 #include "tcuTestLog.hpp"
40 #include "tcuResource.hpp"
41 #include "tcuImageCompare.hpp"
42 #include "vkImageUtil.hpp"
43 #include "tcuCommandLine.hpp"
44 #include "tcuRGBA.hpp"
45 #include "tcuStringTemplate.hpp"
46 #include "tcuMaybe.hpp"
47 
48 #include <vector>
49 #include <utility>
50 #include <algorithm>
51 
52 using std::vector;
53 using std::pair;
54 
55 namespace vkt
56 {
57 namespace QueryPool
58 {
59 namespace
60 {
61 
62 using namespace vk;
63 using namespace Draw;
64 
65 //Test parameters
66 enum
67 {
68 	WIDTH	= 64,
69 	HEIGHT	= 64
70 };
71 
72 enum ResetType
73 {
74 	RESET_TYPE_NORMAL = 0,
75 	RESET_TYPE_HOST,
76 	RESET_TYPE_BEFORE_COPY,
77 	RESET_TYPE_LAST
78 };
79 
inputTypeToGLString(const VkPrimitiveTopology & inputType)80 std::string inputTypeToGLString (const VkPrimitiveTopology& inputType)
81 {
82 	switch (inputType)
83 	{
84 		case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
85 			return "points";
86 		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
87 		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
88 			return "lines";
89 		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
90 		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
91 			return "lines_adjacency";
92 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
93 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
94 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
95 			return "triangles";
96 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
97 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
98 			return "triangles_adjacency";
99 		default:
100 			DE_ASSERT(DE_FALSE);
101 			return "error";
102 	}
103 }
104 
outputTypeToGLString(const VkPrimitiveTopology & outputType)105 std::string outputTypeToGLString (const VkPrimitiveTopology& outputType)
106 {
107 	switch (outputType)
108 	{
109 		case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
110 			return "points";
111 		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
112 		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
113 		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
114 		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
115 				return "line_strip";
116 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
117 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
118 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
119 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
120 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
121 			return "triangle_strip";
122 		default:
123 			DE_ASSERT(DE_FALSE);
124 			return "error";
125 	}
126 }
127 
128 using Pair32						= pair<deUint32, deUint32>;
129 using Pair64						= pair<deUint64, deUint64>;
130 using ResultsVector					= vector<deUint64>;
131 using ResultsVectorWithAvailability	= vector<Pair64>;
132 
133 // Get query pool results as a vector. Note results are always converted to
134 // deUint64, but the actual vkGetQueryPoolResults call will use the 64-bits flag
135 // or not depending on your preferences.
GetQueryPoolResultsVector(ResultsVector & output,const DeviceInterface & vk,vk::VkDevice device,vk::VkQueryPool queryPool,deUint32 firstQuery,deUint32 queryCount,VkQueryResultFlags flags)136 vk::VkResult GetQueryPoolResultsVector(
137 	ResultsVector& output, const DeviceInterface& vk, vk::VkDevice device, vk::VkQueryPool queryPool, deUint32 firstQuery, deUint32 queryCount, VkQueryResultFlags flags)
138 {
139 	if (flags & vk::VK_QUERY_RESULT_WITH_AVAILABILITY_BIT)
140 		TCU_THROW(InternalError, "Availability flag passed when expecting results as ResultsVector");
141 
142 	vk::VkResult result;
143 	output.resize(queryCount);
144 
145 	if (flags & vk::VK_QUERY_RESULT_64_BIT)
146 	{
147 		constexpr size_t	stride		= sizeof(ResultsVector::value_type);
148 		const size_t		totalSize	= stride * output.size();
149 		result = vk.getQueryPoolResults(device, queryPool, firstQuery, queryCount, totalSize, output.data(), stride, flags);
150 	}
151 	else
152 	{
153 		using IntermediateVector = vector<deUint32>;
154 
155 		IntermediateVector	intermediate(queryCount);
156 
157 		// Try to preserve existing data if possible.
158 		std::transform(begin(output), end(output), begin(intermediate), [](deUint64 v) { return static_cast<deUint32>(v); });
159 
160 		constexpr size_t	stride		= sizeof(decltype(intermediate)::value_type);
161 		const size_t		totalSize	= stride * intermediate.size();
162 
163 		// Get and copy results.
164 		result = vk.getQueryPoolResults(device, queryPool, firstQuery, queryCount, totalSize, intermediate.data(), stride, flags);
165 		std::copy(begin(intermediate), end(intermediate), begin(output));
166 	}
167 
168 	return result;
169 }
170 
171 // Same as the normal GetQueryPoolResultsVector but returning the availability
172 // bit associated to each query in addition to the query value.
GetQueryPoolResultsVector(ResultsVectorWithAvailability & output,const DeviceInterface & vk,vk::VkDevice device,vk::VkQueryPool queryPool,deUint32 firstQuery,deUint32 queryCount,VkQueryResultFlags flags)173 vk::VkResult GetQueryPoolResultsVector(
174 	ResultsVectorWithAvailability& output, const DeviceInterface& vk, vk::VkDevice device, vk::VkQueryPool queryPool, deUint32 firstQuery, deUint32 queryCount, VkQueryResultFlags flags)
175 {
176 	flags |= vk::VK_QUERY_RESULT_WITH_AVAILABILITY_BIT;
177 
178 	vk::VkResult result;
179 	output.resize(queryCount);
180 
181 	if (flags & vk::VK_QUERY_RESULT_64_BIT)
182 	{
183 		constexpr size_t	stride		= sizeof(ResultsVectorWithAvailability::value_type);
184 		const size_t		totalSize	= stride * output.size();
185 		result = vk.getQueryPoolResults(device, queryPool, firstQuery, queryCount, totalSize, output.data(), stride, flags);
186 	}
187 	else
188 	{
189 		using IntermediateVector = vector<Pair32>;
190 
191 		IntermediateVector	intermediate(queryCount);
192 
193 		// Try to preserve existing output data if possible.
194 		std::transform(begin(output), end(output), begin(intermediate), [](const Pair64& p) { return Pair32{static_cast<deUint32>(p.first), static_cast<deUint32>(p.second)}; });
195 
196 		constexpr size_t	stride		= sizeof(decltype(intermediate)::value_type);
197 		const size_t		totalSize	= stride * intermediate.size();
198 
199 		// Get and copy.
200 		result = vk.getQueryPoolResults(device, queryPool, firstQuery, queryCount, totalSize, intermediate.data(), stride, flags);
201 		std::transform(begin(intermediate), end(intermediate), begin(output), [](const Pair32& p) { return Pair64{p.first, p.second}; });
202 	}
203 
204 	return result;
205 }
206 
207 // Generic parameters structure.
208 struct GenericParameters
209 {
210 	ResetType	resetType;
211 	deBool		query64Bits;
212 
GenericParametersvkt::QueryPool::__anon7c1ba6010111::GenericParameters213 	GenericParameters (ResetType resetType_, deBool query64Bits_)
214 		: resetType{resetType_}, query64Bits{query64Bits_}
215 		{}
216 
querySizeFlagsvkt::QueryPool::__anon7c1ba6010111::GenericParameters217 	VkQueryResultFlags querySizeFlags () const
218 	{
219 		return (query64Bits ? static_cast<VkQueryResultFlags>(vk::VK_QUERY_RESULT_64_BIT) : 0u);
220 	}
221 };
222 
beginSecondaryCommandBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkQueryPipelineStatisticFlags queryFlags,const VkRenderPass renderPass=(VkRenderPass)0u,const VkFramebuffer framebuffer=(VkFramebuffer)0u,const VkCommandBufferUsageFlags bufferUsageFlags=VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)223 void beginSecondaryCommandBuffer (const DeviceInterface&				vk,
224 								  const VkCommandBuffer					commandBuffer,
225 								  const VkQueryPipelineStatisticFlags	queryFlags,
226 								  const VkRenderPass					renderPass = (VkRenderPass)0u,
227 								  const VkFramebuffer					framebuffer = (VkFramebuffer)0u,
228 								  const VkCommandBufferUsageFlags		bufferUsageFlags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)
229 {
230 	const VkCommandBufferInheritanceInfo	secCmdBufInheritInfo	=
231 	{
232 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
233 		DE_NULL,
234 		renderPass,					// renderPass
235 		0u,							// subpass
236 		framebuffer,				// framebuffer
237 		VK_FALSE,					// occlusionQueryEnable
238 		(VkQueryControlFlags)0u,	// queryFlags
239 		queryFlags,					// pipelineStatistics
240 	};
241 
242 	const VkCommandBufferBeginInfo			info					=
243 	{
244 		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,	// VkStructureType							sType;
245 		DE_NULL,										// const void*								pNext;
246 		bufferUsageFlags,								// VkCommandBufferUsageFlags				flags;
247 		&secCmdBufInheritInfo,							// const VkCommandBufferInheritanceInfo*	pInheritanceInfo;
248 	};
249 	VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
250 }
251 
makeQueryPool(const DeviceInterface & vk,const VkDevice device,deUint32 queryCount,VkQueryPipelineStatisticFlags statisticFlags)252 Move<VkQueryPool> makeQueryPool (const DeviceInterface& vk, const VkDevice device, deUint32 queryCount, VkQueryPipelineStatisticFlags statisticFlags )
253 {
254 	const VkQueryPoolCreateInfo queryPoolCreateInfo =
255 	{
256 		VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,	// VkStructureType					sType
257 		DE_NULL,									// const void*						pNext
258 		(VkQueryPoolCreateFlags)0,					// VkQueryPoolCreateFlags			flags
259 		VK_QUERY_TYPE_PIPELINE_STATISTICS ,			// VkQueryType						queryType
260 		queryCount,									// deUint32							entryCount
261 		statisticFlags,								// VkQueryPipelineStatisticFlags	pipelineStatistics
262 	};
263 	return createQueryPool(vk, device, &queryPoolCreateInfo);
264 }
265 
calculatePearsonCorrelation(const std::vector<deUint64> & x,const ResultsVector & y)266 double calculatePearsonCorrelation(const std::vector<deUint64>& x, const ResultsVector& y)
267 {
268 	// This function calculates Pearson correlation coefficient ( https://en.wikipedia.org/wiki/Pearson_correlation_coefficient )
269 	// Two statistical variables are linear ( == fully corellated ) when fabs( Pearson corelation coefficient ) == 1
270 	// Two statistical variables are independent when pearson corelation coefficient == 0
271 	// If fabs( Pearson coefficient ) is > 0.8 then these two variables are almost linear
272 
273 	DE_ASSERT(x.size() == y.size());
274 	DE_ASSERT(x.size() > 1);
275 
276 	// calculate mean values
277 	double xMean = 0.0, yMean = 0.0;
278 	for (deUint32 i = 0; i < x.size(); ++i)
279 	{
280 		xMean += static_cast<double>(x[i]);
281 		yMean += static_cast<double>(y[i]);
282 	}
283 	xMean /= static_cast<double>(x.size());
284 	yMean /= static_cast<double>(x.size());
285 
286 	// calculate standard deviations
287 	double xS = 0.0, yS = 0.0;
288 	for (deUint32 i = 0; i < x.size(); ++i)
289 	{
290 		double xv = static_cast<double>(x[i]) - xMean;
291 		double yv = static_cast<double>(y[i]) - yMean;
292 
293 		xS += xv * xv;
294 		yS += yv * yv;
295 	}
296 	xS = sqrt( xS / static_cast<double>(x.size() - 1) );
297 	yS = sqrt( yS / static_cast<double>(x.size() - 1) );
298 
299 	// calculate Pearson coefficient
300 	double pearson = 0.0;
301 	for (deUint32 i = 0; i < x.size(); ++i)
302 	{
303 		double xv = (static_cast<double>(x[i]) - xMean ) / xS;
304 		double yv = (static_cast<double>(y[i]) - yMean ) / yS;
305 		pearson   += xv * yv;
306 	}
307 
308 	return pearson / static_cast<double>(x.size() - 1);
309 }
310 
calculatePearsonCorrelation(const std::vector<deUint64> & x,const ResultsVectorWithAvailability & ya)311 double calculatePearsonCorrelation(const std::vector<deUint64>& x, const ResultsVectorWithAvailability& ya)
312 {
313 	ResultsVector y;
314 	for (const auto& elt : ya)
315 		y.push_back(elt.first);
316 	return calculatePearsonCorrelation(x, y);
317 }
318 
clearBuffer(const DeviceInterface & vk,const VkDevice device,const de::SharedPtr<Buffer> buffer,const VkDeviceSize bufferSizeBytes)319 void clearBuffer (const DeviceInterface& vk, const VkDevice device, const de::SharedPtr<Buffer> buffer, const VkDeviceSize bufferSizeBytes)
320 {
321 	const std::vector<deUint8>	data			((size_t)bufferSizeBytes, 0u);
322 	const Allocation&			allocation		= buffer->getBoundMemory();
323 	void*						allocationData	= allocation.getHostPtr();
324 	invalidateAlloc(vk, device, allocation);
325 	deMemcpy(allocationData, &data[0], (size_t)bufferSizeBytes);
326 }
327 
328 class StatisticQueryTestInstance : public TestInstance
329 {
330 public:
331 					StatisticQueryTestInstance	(Context& context, deUint32 queryCount);
332 protected:
333 	struct ValueAndAvailability
334 	{
335 		deUint64 value;
336 		deUint64 availability;
337 	};
338 
339 	de::SharedPtr<Buffer> m_resetBuffer;
340 
341 	virtual void			checkExtensions		(deBool hostResetQueryEnabled);
342 	tcu::TestStatus			verifyUnavailable	();
343 };
344 
StatisticQueryTestInstance(Context & context,deUint32 queryCount)345 StatisticQueryTestInstance::StatisticQueryTestInstance (Context& context, deUint32 queryCount)
346 	: TestInstance	(context)
347 	, m_resetBuffer (Buffer::createAndAlloc(context.getDeviceInterface(),
348 											context.getDevice(),
349 											BufferCreateInfo(queryCount * sizeof(ValueAndAvailability), VK_BUFFER_USAGE_TRANSFER_DST_BIT),
350 											context.getDefaultAllocator(),
351 											vk::MemoryRequirement::HostVisible))
352 {
353 }
354 
checkExtensions(deBool hostResetQueryEnabled)355 void StatisticQueryTestInstance::checkExtensions (deBool hostResetQueryEnabled)
356 {
357 	if (!m_context.getDeviceFeatures().pipelineStatisticsQuery)
358 		throw tcu::NotSupportedError("Pipeline statistics queries are not supported");
359 
360 	if (hostResetQueryEnabled == DE_TRUE)
361 	{
362 		// Check VK_EXT_host_query_reset is supported
363 		m_context.requireDeviceFunctionality("VK_EXT_host_query_reset");
364 		if(m_context.getHostQueryResetFeatures().hostQueryReset == VK_FALSE)
365 			throw tcu::NotSupportedError(std::string("Implementation doesn't support resetting queries from the host").c_str());
366 	}
367 }
368 
verifyUnavailable()369 tcu::TestStatus	StatisticQueryTestInstance::verifyUnavailable ()
370 {
371 	struct ValueAndAvailability va;
372 	const vk::Allocation& allocation = m_resetBuffer->getBoundMemory();
373 	const void* allocationData = allocation.getHostPtr();
374 
375 	vk::invalidateAlloc(m_context.getDeviceInterface(), m_context.getDevice(), allocation);
376 	deMemcpy(&va, allocationData, sizeof(va));
377 	return ((va.availability != 0) ? tcu::TestStatus::fail("Availability bit nonzero after resetting query") : tcu::TestStatus::pass("Pass"));
378 }
379 
380 class ComputeInvocationsTestInstance : public StatisticQueryTestInstance
381 {
382 public:
383 	struct ParametersCompute : public GenericParameters
384 	{
ParametersComputevkt::QueryPool::__anon7c1ba6010111::ComputeInvocationsTestInstance::ParametersCompute385 		ParametersCompute (const tcu::UVec3& localSize_, const tcu::UVec3& groupSize_, const std::string& shaderName_, ResetType resetType_, deBool query64Bits_)
386 			: GenericParameters{resetType_, query64Bits_}
387 			, localSize(localSize_)
388 			, groupSize(groupSize_)
389 			, shaderName(shaderName_)
390 			{}
391 
392 		tcu::UVec3	localSize;
393 		tcu::UVec3	groupSize;
394 		std::string	shaderName;
395 	};
396 							ComputeInvocationsTestInstance		(Context& context, const std::vector<ParametersCompute>& parameters);
397 	tcu::TestStatus			iterate								(void);
398 protected:
399 	virtual tcu::TestStatus	executeTest							(const VkCommandPool&			cmdPool,
400 																 const VkPipelineLayout			pipelineLayout,
401 																 const VkDescriptorSet&			descriptorSet,
402 																 const de::SharedPtr<Buffer>	buffer,
403 																 const VkDeviceSize				bufferSizeBytes);
getComputeExecution(const ParametersCompute & parm) const404 	deUint32				getComputeExecution					(const ParametersCompute& parm) const
405 		{
406 			return parm.localSize.x() * parm.localSize.y() *parm.localSize.z() * parm.groupSize.x() * parm.groupSize.y() * parm.groupSize.z();
407 		}
408 	const std::vector<ParametersCompute>&	m_parameters;
409 };
410 
ComputeInvocationsTestInstance(Context & context,const std::vector<ParametersCompute> & parameters)411 ComputeInvocationsTestInstance::ComputeInvocationsTestInstance (Context& context, const std::vector<ParametersCompute>& parameters)
412 	: StatisticQueryTestInstance	(context, 1u)
413 	, m_parameters					(parameters)
414 {
415 }
416 
iterate(void)417 tcu::TestStatus	ComputeInvocationsTestInstance::iterate (void)
418 {
419 	checkExtensions((m_parameters[0].resetType == RESET_TYPE_HOST)? DE_TRUE : DE_FALSE);
420 	const DeviceInterface&				vk						= m_context.getDeviceInterface();
421 	const VkDevice						device					= m_context.getDevice();
422 	deUint32							maxSize					= 0u;
423 
424 	for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
425 		maxSize = deMaxu32(maxSize, getComputeExecution(m_parameters[parametersNdx]));
426 
427 	const VkDeviceSize					bufferSizeBytes			= static_cast<VkDeviceSize>(deAlignSize(static_cast<size_t>(sizeof(deUint32) * maxSize),
428 																								static_cast<size_t>(m_context.getDeviceProperties().limits.nonCoherentAtomSize)));
429 	de::SharedPtr<Buffer>				buffer					= Buffer::createAndAlloc(vk, device, BufferCreateInfo(bufferSizeBytes, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT),
430 																							 m_context.getDefaultAllocator(), MemoryRequirement::HostVisible);
431 
432 	const Unique<VkDescriptorSetLayout>	descriptorSetLayout		(DescriptorSetLayoutBuilder()
433 			.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
434 			.build(vk, device));
435 
436 	const Unique<VkPipelineLayout>		pipelineLayout			(makePipelineLayout(vk, device, *descriptorSetLayout));
437 
438 	const Unique<VkDescriptorPool>		descriptorPool			(DescriptorPoolBuilder()
439 			.addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
440 			.build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u));
441 
442 	const VkDescriptorSetAllocateInfo allocateParams		=
443 	{
444 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,	// VkStructureType				sType;
445 		DE_NULL,										// const void*					pNext;
446 		*descriptorPool,								// VkDescriptorPool				descriptorPool;
447 		1u,												// deUint32						setLayoutCount;
448 		&(*descriptorSetLayout),						// const VkDescriptorSetLayout*	pSetLayouts;
449 	};
450 
451 	const Unique<VkDescriptorSet>		descriptorSet		(allocateDescriptorSet(vk, device, &allocateParams));
452 	const VkDescriptorBufferInfo		descriptorInfo		=
453 	{
454 		buffer->object(),	//VkBuffer		buffer;
455 		0ull,				//VkDeviceSize	offset;
456 		bufferSizeBytes,	//VkDeviceSize	range;
457 	};
458 
459 	DescriptorSetUpdateBuilder()
460 		.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &descriptorInfo)
461 		.update(vk, device);
462 
463 	const CmdPoolCreateInfo			cmdPoolCreateInfo	(m_context.getUniversalQueueFamilyIndex());
464 	const Unique<VkCommandPool>		cmdPool				(createCommandPool(vk, device, &cmdPoolCreateInfo));
465 
466 	return executeTest (*cmdPool, *pipelineLayout, *descriptorSet, buffer, bufferSizeBytes);
467 }
468 
executeTest(const VkCommandPool & cmdPool,const VkPipelineLayout pipelineLayout,const VkDescriptorSet & descriptorSet,const de::SharedPtr<Buffer> buffer,const VkDeviceSize bufferSizeBytes)469 tcu::TestStatus ComputeInvocationsTestInstance::executeTest (const VkCommandPool&			cmdPool,
470 															 const VkPipelineLayout			pipelineLayout,
471 															 const VkDescriptorSet&			descriptorSet,
472 															 const de::SharedPtr<Buffer>	buffer,
473 															 const VkDeviceSize				bufferSizeBytes)
474 {
475 	const DeviceInterface&				vk						= m_context.getDeviceInterface();
476 	const VkDevice						device					= m_context.getDevice();
477 	const VkQueue						queue					= m_context.getUniversalQueue();
478 	const VkBufferMemoryBarrier			computeFinishBarrier	=
479 	{
480 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,					// VkStructureType	sType;
481 		DE_NULL,													// const void*		pNext;
482 		VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,		// VkAccessFlags	srcAccessMask;
483 		VK_ACCESS_HOST_READ_BIT,									// VkAccessFlags	dstAccessMask;
484 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			srcQueueFamilyIndex;
485 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			destQueueFamilyIndex;
486 		buffer->object(),											// VkBuffer			buffer;
487 		0ull,														// VkDeviceSize		offset;
488 		bufferSizeBytes,											// VkDeviceSize		size;
489 	};
490 
491 	for(size_t parametersNdx = 0u; parametersNdx < m_parameters.size(); ++parametersNdx)
492 	{
493 		clearBuffer(vk, device, buffer, bufferSizeBytes);
494 		const Unique<VkShaderModule>			shaderModule				(createShaderModule(vk, device,
495 																			m_context.getBinaryCollection().get(m_parameters[parametersNdx].shaderName), (VkShaderModuleCreateFlags)0u));
496 
497 		const VkPipelineShaderStageCreateInfo	pipelineShaderStageParams	=
498 		{
499 			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType						sType;
500 			DE_NULL,												// const void*							pNext;
501 			(VkPipelineShaderStageCreateFlags)0u,					// VkPipelineShaderStageCreateFlags		flags;
502 			VK_SHADER_STAGE_COMPUTE_BIT,							// VkShaderStageFlagBits				stage;
503 			*shaderModule,											// VkShaderModule						module;
504 			"main",													// const char*							pName;
505 			DE_NULL,												// const VkSpecializationInfo*			pSpecializationInfo;
506 		};
507 
508 		const VkComputePipelineCreateInfo		pipelineCreateInfo			=
509 		{
510 			VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,	// VkStructureType					sType;
511 			DE_NULL,										// const void*						pNext;
512 			(VkPipelineCreateFlags)0u,						// VkPipelineCreateFlags			flags;
513 			pipelineShaderStageParams,						// VkPipelineShaderStageCreateInfo	stage;
514 			pipelineLayout,									// VkPipelineLayout					layout;
515 			DE_NULL,										// VkPipeline						basePipelineHandle;
516 			0,												// deInt32							basePipelineIndex;
517 		};
518 		const Unique<VkPipeline> pipeline(createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo));
519 
520 		const Unique<VkCommandBuffer>	cmdBuffer			(allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
521 		const Unique<VkQueryPool>		queryPool			(makeQueryPool(vk, device, 1u, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT));
522 
523 		beginCommandBuffer(vk, *cmdBuffer);
524 			if (m_parameters[0].resetType != RESET_TYPE_HOST)
525 				vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, 1u);
526 
527 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
528 			vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
529 
530 			vk.cmdBeginQuery(*cmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
531 			vk.cmdDispatch(*cmdBuffer, m_parameters[parametersNdx].groupSize.x(), m_parameters[parametersNdx].groupSize.y(), m_parameters[parametersNdx].groupSize.z());
532 			vk.cmdEndQuery(*cmdBuffer, *queryPool, 0u);
533 
534 			if (m_parameters[0].resetType == RESET_TYPE_BEFORE_COPY)
535 			{
536 				vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, 1u);
537 				vk.cmdCopyQueryPoolResults(*cmdBuffer, *queryPool, 0, 1u, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
538 			}
539 
540 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT,
541 				(VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeFinishBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
542 
543 		endCommandBuffer(vk, *cmdBuffer);
544 
545 		m_context.getTestContext().getLog() << tcu::TestLog::Message << "Compute shader invocations: " << getComputeExecution(m_parameters[parametersNdx]) << tcu::TestLog::EndMessage;
546 
547 		if (m_parameters[0].resetType == RESET_TYPE_HOST)
548 			vk.resetQueryPool(device, *queryPool, 0u, 1u);
549 
550 		// Wait for completion
551 		submitCommandsAndWait(vk, device, queue, *cmdBuffer);
552 
553 		// Validate the results
554 		const Allocation& bufferAllocation = buffer->getBoundMemory();
555 		invalidateAlloc(vk, device, bufferAllocation);
556 
557 		if (m_parameters[0].resetType == RESET_TYPE_NORMAL)
558 		{
559 			ResultsVector data;
560 			VK_CHECK(GetQueryPoolResultsVector(data, vk, device, *queryPool, 0u, 1u, (VK_QUERY_RESULT_WAIT_BIT | m_parameters[0].querySizeFlags())));
561 			if (getComputeExecution(m_parameters[parametersNdx]) != data[0])
562 				return tcu::TestStatus::fail("QueryPoolResults incorrect");
563 		}
564 		else if (m_parameters[0].resetType == RESET_TYPE_HOST)
565 		{
566 			ResultsVectorWithAvailability data;
567 			VK_CHECK(GetQueryPoolResultsVector(data, vk, device, *queryPool, 0u, 1u, (VK_QUERY_RESULT_WAIT_BIT | m_parameters[0].querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT)));
568 			if (getComputeExecution(m_parameters[parametersNdx]) != data[0].first || data[0].second == 0)
569 				return tcu::TestStatus::fail("QueryPoolResults incorrect");
570 
571 			deUint64 temp = data[0].first;
572 
573 			vk.resetQueryPool(device, *queryPool, 0, 1u);
574 			vk::VkResult res = GetQueryPoolResultsVector(data, vk, device, *queryPool, 0u, 1u, (m_parameters[0].querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT));
575 			/* From Vulkan spec:
576 			 *
577 			 * If VK_QUERY_RESULT_WAIT_BIT and VK_QUERY_RESULT_PARTIAL_BIT are both not set then no result values are written to pData
578 			 * for queries that are in the unavailable state at the time of the call, and vkGetQueryPoolResults returns VK_NOT_READY.
579 			 * However, availability state is still written to pData for those queries if VK_QUERY_RESULT_WITH_AVAILABILITY_BIT is set.
580 			 */
581 			if (res != vk::VK_NOT_READY || data[0].first != temp || data[0].second != 0u)
582 				return tcu::TestStatus::fail("QueryPoolResults incorrect reset");
583 		}
584 		else
585 		{
586 			// With RESET_TYPE_BEFORE_COPY, we only need to verify the result after the copy include an availability bit set as zero.
587 			return verifyUnavailable();
588 		}
589 
590 		const deUint32* bufferPtr = static_cast<deUint32*>(bufferAllocation.getHostPtr());
591 		for (deUint32 ndx = 0u; ndx < getComputeExecution(m_parameters[parametersNdx]); ++ndx)
592 		{
593 			if (bufferPtr[ndx] != ndx)
594 				return tcu::TestStatus::fail("Compute shader didn't write data to the buffer");
595 		}
596 	}
597 	return tcu::TestStatus::pass("Pass");
598 }
599 
600 class ComputeInvocationsSecondaryTestInstance : public ComputeInvocationsTestInstance
601 {
602 public:
603 							ComputeInvocationsSecondaryTestInstance	(Context& context, const std::vector<ParametersCompute>& parameters);
604 protected:
605 	tcu::TestStatus			executeTest								(const VkCommandPool&			cmdPool,
606 																	 const VkPipelineLayout			pipelineLayout,
607 																	 const VkDescriptorSet&			descriptorSet,
608 																	 const de::SharedPtr<Buffer>	buffer,
609 																	 const VkDeviceSize				bufferSizeBytes);
610 	virtual tcu::TestStatus	checkResult								(const de::SharedPtr<Buffer>	buffer,
611 																	 const VkQueryPool				queryPool);
612 };
613 
ComputeInvocationsSecondaryTestInstance(Context & context,const std::vector<ParametersCompute> & parameters)614 ComputeInvocationsSecondaryTestInstance::ComputeInvocationsSecondaryTestInstance	(Context& context, const std::vector<ParametersCompute>& parameters)
615 	: ComputeInvocationsTestInstance	(context, parameters)
616 {
617 }
618 
executeTest(const VkCommandPool & cmdPool,const VkPipelineLayout pipelineLayout,const VkDescriptorSet & descriptorSet,const de::SharedPtr<Buffer> buffer,const VkDeviceSize bufferSizeBytes)619 tcu::TestStatus ComputeInvocationsSecondaryTestInstance::executeTest (const VkCommandPool&			cmdPool,
620 																	  const VkPipelineLayout		pipelineLayout,
621 																	  const VkDescriptorSet&		descriptorSet,
622 																	  const de::SharedPtr<Buffer>	buffer,
623 																	  const VkDeviceSize			bufferSizeBytes)
624 {
625 	typedef de::SharedPtr<Unique<VkShaderModule> >	VkShaderModuleSp;
626 	typedef de::SharedPtr<Unique<VkPipeline> >		VkPipelineSp;
627 
628 	const DeviceInterface&					vk							= m_context.getDeviceInterface();
629 	const VkDevice							device						= m_context.getDevice();
630 	const VkQueue							queue						= m_context.getUniversalQueue();
631 
632 	const VkBufferMemoryBarrier				computeShaderWriteBarrier	=
633 	{
634 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,					// VkStructureType	sType;
635 		DE_NULL,													// const void*		pNext;
636 		VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,		// VkAccessFlags	srcAccessMask;
637 		VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,		// VkAccessFlags	dstAccessMask;
638 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			srcQueueFamilyIndex;
639 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			destQueueFamilyIndex;
640 		buffer->object(),											// VkBuffer			buffer;
641 		0ull,														// VkDeviceSize		offset;
642 		bufferSizeBytes,											// VkDeviceSize		size;
643 	};
644 
645 	const VkBufferMemoryBarrier				computeFinishBarrier		=
646 	{
647 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,					// VkStructureType	sType;
648 		DE_NULL,													// const void*		pNext;
649 		VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,		// VkAccessFlags	srcAccessMask;
650 		VK_ACCESS_HOST_READ_BIT,									// VkAccessFlags	dstAccessMask;
651 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			srcQueueFamilyIndex;
652 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			destQueueFamilyIndex;
653 		buffer->object(),											// VkBuffer			buffer;
654 		0ull,														// VkDeviceSize		offset;
655 		bufferSizeBytes,											// VkDeviceSize		size;
656 	};
657 
658 	std::vector<VkShaderModuleSp>			shaderModule;
659 	std::vector<VkPipelineSp>				pipeline;
660 	for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
661 	{
662 		shaderModule.push_back(VkShaderModuleSp(new Unique<VkShaderModule>(createShaderModule(vk, device, m_context.getBinaryCollection().get(m_parameters[parametersNdx].shaderName), (VkShaderModuleCreateFlags)0u))));
663 		const VkPipelineShaderStageCreateInfo	pipelineShaderStageParams	=
664 		{
665 			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType						sType;
666 			DE_NULL,												// const void*							pNext;
667 			0u,														// VkPipelineShaderStageCreateFlags		flags;
668 			VK_SHADER_STAGE_COMPUTE_BIT,							// VkShaderStageFlagBits				stage;
669 			shaderModule.back().get()->get(),						// VkShaderModule						module;
670 			"main",													// const char*							pName;
671 			DE_NULL,												// const VkSpecializationInfo*			pSpecializationInfo;
672 		};
673 
674 		const VkComputePipelineCreateInfo		pipelineCreateInfo			=
675 		{
676 			VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,	// VkStructureType					sType;
677 			DE_NULL,										// const void*						pNext;
678 			0u,												// VkPipelineCreateFlags			flags;
679 			pipelineShaderStageParams,						// VkPipelineShaderStageCreateInfo	stage;
680 			pipelineLayout,									// VkPipelineLayout					layout;
681 			DE_NULL,										// VkPipeline						basePipelineHandle;
682 			0,												// deInt32							basePipelineIndex;
683 		};
684 		pipeline.push_back(VkPipelineSp(new Unique<VkPipeline>(createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo))));
685 	}
686 
687 	const Unique<VkCommandBuffer>				primaryCmdBuffer			(allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
688 	const Unique<VkCommandBuffer>				secondaryCmdBuffer			(allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
689 
690 	const Unique<VkQueryPool>					queryPool					(makeQueryPool(vk, device, 1u, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT));
691 
692 	clearBuffer(vk, device, buffer, bufferSizeBytes);
693 	beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT);
694 		vk.cmdBindDescriptorSets(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
695 		if (m_parameters[0].resetType != RESET_TYPE_HOST)
696 			vk.cmdResetQueryPool(*secondaryCmdBuffer, *queryPool, 0u, 1u);
697 		vk.cmdBeginQuery(*secondaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
698 		for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
699 		{
700 				vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline[parametersNdx].get()->get());
701 				vk.cmdDispatch(*secondaryCmdBuffer, m_parameters[parametersNdx].groupSize.x(), m_parameters[parametersNdx].groupSize.y(), m_parameters[parametersNdx].groupSize.z());
702 
703 				vk.cmdPipelineBarrier(*secondaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
704 					(VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeShaderWriteBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
705 		}
706 		vk.cmdEndQuery(*secondaryCmdBuffer, *queryPool, 0u);
707 
708 		if (m_parameters[0].resetType == RESET_TYPE_BEFORE_COPY)
709 		{
710 			vk.cmdResetQueryPool(*secondaryCmdBuffer, *queryPool, 0u, 1u);
711 			vk.cmdCopyQueryPoolResults(*secondaryCmdBuffer, *queryPool, 0, 1u, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
712 		}
713 
714 	endCommandBuffer(vk, *secondaryCmdBuffer);
715 
716 	beginCommandBuffer(vk, *primaryCmdBuffer);
717 		vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
718 
719 		vk.cmdPipelineBarrier(*primaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT,
720 			(VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeFinishBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
721 
722 	endCommandBuffer(vk, *primaryCmdBuffer);
723 
724 	// Secondary buffer is emitted only once, so it is safe to reset the query pool here.
725 	if (m_parameters[0].resetType == RESET_TYPE_HOST)
726 		vk.resetQueryPool(device, *queryPool, 0u, 1u);
727 
728 	// Wait for completion
729 	submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
730 	return checkResult(buffer, *queryPool);
731 }
732 
checkResult(const de::SharedPtr<Buffer> buffer,const VkQueryPool queryPool)733 tcu::TestStatus ComputeInvocationsSecondaryTestInstance::checkResult (const de::SharedPtr<Buffer> buffer, const VkQueryPool queryPool)
734 {
735 	const DeviceInterface&	vk					= m_context.getDeviceInterface();
736 	const VkDevice			device				= m_context.getDevice();
737 	{
738 		deUint64 expected	= 0u;
739 		for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
740 			expected += getComputeExecution(m_parameters[parametersNdx]);
741 
742 		if (m_parameters[0].resetType == RESET_TYPE_NORMAL)
743 		{
744 			ResultsVector results;
745 			VK_CHECK(GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, 1u, (VK_QUERY_RESULT_WAIT_BIT | m_parameters[0].querySizeFlags())));
746 			if (expected != results[0])
747 				return tcu::TestStatus::fail("QueryPoolResults incorrect");
748 		}
749 		else if (m_parameters[0].resetType == RESET_TYPE_HOST)
750 		{
751 			ResultsVectorWithAvailability results;
752 			VK_CHECK(GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, 1u, (VK_QUERY_RESULT_WAIT_BIT | m_parameters[0].querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT)));
753 			if (expected != results[0].first || results[0].second == 0u)
754 				return tcu::TestStatus::fail("QueryPoolResults incorrect");
755 
756 			deUint64 temp = results[0].first;
757 
758 			vk.resetQueryPool(device, queryPool, 0u, 1u);
759 			vk::VkResult res = GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, 1u, (m_parameters[0].querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT));
760 			/* From Vulkan spec:
761 			 *
762 			 * If VK_QUERY_RESULT_WAIT_BIT and VK_QUERY_RESULT_PARTIAL_BIT are both not set then no result values are written to pData
763 			 * for queries that are in the unavailable state at the time of the call, and vkGetQueryPoolResults returns VK_NOT_READY.
764 			 * However, availability state is still written to pData for those queries if VK_QUERY_RESULT_WITH_AVAILABILITY_BIT is set.
765 			 */
766 			if (res != vk::VK_NOT_READY || results[0].first != temp || results[0].second != 0u)
767 				return tcu::TestStatus::fail("QueryPoolResults incorrect reset");
768 		}
769 		else
770 		{
771 			// With RESET_TYPE_BEFORE_COPY, we only need to verify the result after the copy include an availability bit set as zero.
772 			return verifyUnavailable();
773 		}
774 
775 	}
776 
777 	{
778 		// Validate the results
779 		const Allocation&	bufferAllocation	= buffer->getBoundMemory();
780 		invalidateAlloc(vk, device, bufferAllocation);
781 		const deUint32*		bufferPtr			= static_cast<deUint32*>(bufferAllocation.getHostPtr());
782 		deUint32			minSize				= ~0u;
783 		for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
784 			minSize = deMinu32(minSize, getComputeExecution(m_parameters[parametersNdx]));
785 		for (deUint32 ndx = 0u; ndx < minSize; ++ndx)
786 		{
787 			if (bufferPtr[ndx] != ndx * m_parameters.size())
788 				return tcu::TestStatus::fail("Compute shader didn't write data to the buffer");
789 		}
790 	}
791 	return tcu::TestStatus::pass("Pass");
792 }
793 
794 class ComputeInvocationsSecondaryInheritedTestInstance : public ComputeInvocationsSecondaryTestInstance
795 {
796 public:
797 					ComputeInvocationsSecondaryInheritedTestInstance	(Context& context, const std::vector<ParametersCompute>& parameters);
798 protected:
799 	virtual void	checkExtensions							(deBool hostResetQueryEnabled);
800 
801 	tcu::TestStatus	executeTest								(const VkCommandPool&			cmdPool,
802 															 const VkPipelineLayout			pipelineLayout,
803 															 const VkDescriptorSet&			descriptorSet,
804 															 const de::SharedPtr<Buffer>	buffer,
805 															 const VkDeviceSize				bufferSizeBytes);
806 };
807 
ComputeInvocationsSecondaryInheritedTestInstance(Context & context,const std::vector<ParametersCompute> & parameters)808 ComputeInvocationsSecondaryInheritedTestInstance::ComputeInvocationsSecondaryInheritedTestInstance	(Context& context, const std::vector<ParametersCompute>& parameters)
809 	: ComputeInvocationsSecondaryTestInstance	(context, parameters)
810 {
811 }
812 
checkExtensions(deBool hostResetQueryEnabled)813 void ComputeInvocationsSecondaryInheritedTestInstance::checkExtensions (deBool hostResetQueryEnabled)
814 {
815 	StatisticQueryTestInstance::checkExtensions(hostResetQueryEnabled);
816 	if (!m_context.getDeviceFeatures().inheritedQueries)
817 		throw tcu::NotSupportedError("Inherited queries are not supported");
818 }
819 
executeTest(const VkCommandPool & cmdPool,const VkPipelineLayout pipelineLayout,const VkDescriptorSet & descriptorSet,const de::SharedPtr<Buffer> buffer,const VkDeviceSize bufferSizeBytes)820 tcu::TestStatus ComputeInvocationsSecondaryInheritedTestInstance::executeTest (const VkCommandPool&			cmdPool,
821 																			  const VkPipelineLayout		pipelineLayout,
822 																			  const VkDescriptorSet&		descriptorSet,
823 																			  const de::SharedPtr<Buffer>	buffer,
824 																			  const VkDeviceSize			bufferSizeBytes)
825 {
826 	typedef de::SharedPtr<Unique<VkShaderModule> >	VkShaderModuleSp;
827 	typedef de::SharedPtr<Unique<VkPipeline> >		VkPipelineSp;
828 
829 	const DeviceInterface&						vk								= m_context.getDeviceInterface();
830 	const VkDevice								device							= m_context.getDevice();
831 	const VkQueue								queue							= m_context.getUniversalQueue();
832 
833 	const VkBufferMemoryBarrier					computeShaderWriteBarrier		=
834 	{
835 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,					// VkStructureType	sType;
836 		DE_NULL,													// const void*		pNext;
837 		VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,		// VkAccessFlags	srcAccessMask;
838 		VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,		// VkAccessFlags	dstAccessMask;
839 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			srcQueueFamilyIndex;
840 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			destQueueFamilyIndex;
841 		buffer->object(),											// VkBuffer			buffer;
842 		0ull,														// VkDeviceSize		offset;
843 		bufferSizeBytes,											// VkDeviceSize		size;
844 	};
845 
846 	const VkBufferMemoryBarrier					computeFinishBarrier			=
847 	{
848 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,					// VkStructureType	sType;
849 		DE_NULL,													// const void*		pNext;
850 		VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,		// VkAccessFlags	srcAccessMask;
851 		VK_ACCESS_HOST_READ_BIT,									// VkAccessFlags	dstAccessMask;
852 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			srcQueueFamilyIndex;
853 		VK_QUEUE_FAMILY_IGNORED,									// deUint32			destQueueFamilyIndex;
854 		buffer->object(),											// VkBuffer			buffer;
855 		0ull,														// VkDeviceSize		offset;
856 		bufferSizeBytes,											// VkDeviceSize		size;
857 	};
858 
859 	std::vector<VkShaderModuleSp>				shaderModule;
860 	std::vector<VkPipelineSp>					pipeline;
861 	for(size_t parametersNdx = 0u; parametersNdx < m_parameters.size(); ++parametersNdx)
862 	{
863 		shaderModule.push_back(VkShaderModuleSp(new Unique<VkShaderModule>(createShaderModule(vk, device, m_context.getBinaryCollection().get(m_parameters[parametersNdx].shaderName), (VkShaderModuleCreateFlags)0u))));
864 		const VkPipelineShaderStageCreateInfo	pipelineShaderStageParams		=
865 		{
866 			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType					sType;
867 			DE_NULL,												// const void*						pNext;
868 			0u,														// VkPipelineShaderStageCreateFlags	flags;
869 			VK_SHADER_STAGE_COMPUTE_BIT,							// VkShaderStageFlagBits			stage;
870 			shaderModule.back().get()->get(),						// VkShaderModule					module;
871 			"main",													// const char*						pName;
872 			DE_NULL,												// const VkSpecializationInfo*		pSpecializationInfo;
873 		};
874 
875 		const VkComputePipelineCreateInfo		pipelineCreateInfo				=
876 		{
877 			VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,	// VkStructureType					sType;
878 			DE_NULL,										// const void*						pNext;
879 			0u,												// VkPipelineCreateFlags			flags;
880 			pipelineShaderStageParams,						// VkPipelineShaderStageCreateInfo	stage;
881 			pipelineLayout,									// VkPipelineLayout					layout;
882 			DE_NULL,										// VkPipeline						basePipelineHandle;
883 			0,												// deInt32							basePipelineIndex;
884 		};
885 		pipeline.push_back(VkPipelineSp(new Unique<VkPipeline>(createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo))));
886 	}
887 
888 	const Unique<VkCommandBuffer>				primaryCmdBuffer			(allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
889 	const Unique<VkCommandBuffer>				secondaryCmdBuffer			(allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
890 
891 	const Unique<VkQueryPool>					queryPool					(makeQueryPool(vk, device, 1u, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT));
892 
893 	clearBuffer(vk, device, buffer, bufferSizeBytes);
894 	beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT);
895 		vk.cmdBindDescriptorSets(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
896 		for(size_t parametersNdx = 1; parametersNdx < m_parameters.size(); ++parametersNdx)
897 		{
898 				vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline[parametersNdx].get()->get());
899 				vk.cmdDispatch(*secondaryCmdBuffer, m_parameters[parametersNdx].groupSize.x(), m_parameters[parametersNdx].groupSize.y(), m_parameters[parametersNdx].groupSize.z());
900 
901 				vk.cmdPipelineBarrier(*secondaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
902 					(VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeShaderWriteBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
903 		}
904 	endCommandBuffer(vk, *secondaryCmdBuffer);
905 
906 	beginCommandBuffer(vk, *primaryCmdBuffer);
907 		if (m_parameters[0].resetType != RESET_TYPE_HOST)
908 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
909 		vk.cmdBindDescriptorSets(*primaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
910 		vk.cmdBindPipeline(*primaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline[0].get()->get());
911 
912 		vk.cmdBeginQuery(*primaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
913 		vk.cmdDispatch(*primaryCmdBuffer, m_parameters[0].groupSize.x(), m_parameters[0].groupSize.y(), m_parameters[0].groupSize.z());
914 
915 		vk.cmdPipelineBarrier(*primaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
916 				(VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeShaderWriteBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
917 
918 		vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
919 
920 		vk.cmdPipelineBarrier(*primaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT,
921 			(VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeFinishBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
922 
923 		vk.cmdEndQuery(*primaryCmdBuffer, *queryPool, 0u);
924 
925 		if (m_parameters[0].resetType == RESET_TYPE_BEFORE_COPY)
926 		{
927 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
928 			vk.cmdCopyQueryPoolResults(*primaryCmdBuffer, *queryPool, 0, 1u, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
929 		}
930 
931 	endCommandBuffer(vk, *primaryCmdBuffer);
932 
933 	if (m_parameters[0].resetType == RESET_TYPE_HOST)
934 		vk.resetQueryPool(device, *queryPool, 0u, 1u);
935 
936 	// Wait for completion
937 	submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
938 	return checkResult(buffer, *queryPool);
939 }
940 
941 class GraphicBasicTestInstance : public StatisticQueryTestInstance
942 {
943 public:
944 	struct VertexData
945 	{
VertexDatavkt::QueryPool::__anon7c1ba6010111::GraphicBasicTestInstance::VertexData946 		VertexData (const tcu::Vec4 position_, const tcu::Vec4 color_)
947 			: position	(position_)
948 			, color		(color_)
949 		{}
950 		tcu::Vec4	position;
951 		tcu::Vec4	color;
952 	};
953 
954 	struct ParametersGraphic : public GenericParameters
955 	{
ParametersGraphicvkt::QueryPool::__anon7c1ba6010111::GraphicBasicTestInstance::ParametersGraphic956 		ParametersGraphic (const VkQueryPipelineStatisticFlags queryStatisticFlags_, const VkPrimitiveTopology primitiveTopology_, const ResetType resetType_, const deBool query64Bits_, const deBool vertexOnlyPipe_ = DE_FALSE)
957 			: GenericParameters		{resetType_, query64Bits_}
958 			, queryStatisticFlags	(queryStatisticFlags_)
959 			, primitiveTopology		(primitiveTopology_)
960 			, vertexOnlyPipe		(vertexOnlyPipe_)
961 			{}
962 
963 		VkQueryPipelineStatisticFlags	queryStatisticFlags;
964 		VkPrimitiveTopology				primitiveTopology;
965 		deBool							vertexOnlyPipe;
966 	};
967 											GraphicBasicTestInstance			(vkt::Context&					context,
968 																				 const std::vector<VertexData>&	data,
969 																				 const ParametersGraphic&		parametersGraphic,
970 																				 const std::vector<deUint64>&	drawRepeats );
971 	tcu::TestStatus							iterate								(void);
972 protected:
973 	de::SharedPtr<Buffer>					creatAndFillVertexBuffer			(void);
974 	virtual void							createPipeline						(void) = 0;
975 	void									creatColorAttachmentAndRenderPass	(void);
976 	bool									checkImage							(void);
977 	virtual tcu::TestStatus					executeTest							(void) = 0;
978 	virtual tcu::TestStatus					checkResult							(VkQueryPool queryPool) = 0;
979 	virtual void							draw								(VkCommandBuffer cmdBuffer) = 0;
980 
981 	const VkFormat						m_colorAttachmentFormat;
982 	de::SharedPtr<Image>				m_colorAttachmentImage;
983 	de::SharedPtr<Image>				m_depthImage;
984 	Move<VkImageView>					m_attachmentView;
985 	Move<VkImageView>					m_depthiew;
986 	Move<VkRenderPass>					m_renderPass;
987 	Move<VkFramebuffer>					m_framebuffer;
988 	Move<VkPipeline>					m_pipeline;
989 	Move<VkPipelineLayout>				m_pipelineLayout;
990 	const std::vector<VertexData>&		m_data;
991 	const ParametersGraphic&			m_parametersGraphic;
992 	std::vector<deUint64>				m_drawRepeats;
993 };
994 
GraphicBasicTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)995 GraphicBasicTestInstance::GraphicBasicTestInstance (vkt::Context&					context,
996 													const std::vector<VertexData>&	data,
997 													const ParametersGraphic&		parametersGraphic,
998 													const std::vector<deUint64>&	drawRepeats )
999 	: StatisticQueryTestInstance	(context, static_cast<deUint32>(drawRepeats.size()))
1000 	, m_colorAttachmentFormat		(VK_FORMAT_R8G8B8A8_UNORM)
1001 	, m_data						(data)
1002 	, m_parametersGraphic			(parametersGraphic)
1003 	, m_drawRepeats					(drawRepeats)
1004 {
1005 }
1006 
iterate(void)1007 tcu::TestStatus GraphicBasicTestInstance::iterate (void)
1008 {
1009 	checkExtensions((m_parametersGraphic.resetType == RESET_TYPE_HOST)? DE_TRUE : DE_FALSE);
1010 	creatColorAttachmentAndRenderPass();
1011 	createPipeline();
1012 	return executeTest();
1013 }
1014 
creatAndFillVertexBuffer(void)1015 de::SharedPtr<Buffer> GraphicBasicTestInstance::creatAndFillVertexBuffer (void)
1016 {
1017 	const DeviceInterface&		vk				= m_context.getDeviceInterface();
1018 	const VkDevice				device			= m_context.getDevice();
1019 
1020 	const VkDeviceSize			dataSize		= static_cast<VkDeviceSize>(deAlignSize(static_cast<size_t>( m_data.size() * sizeof(VertexData)),
1021 		static_cast<size_t>(m_context.getDeviceProperties().limits.nonCoherentAtomSize)));
1022 
1023 	de::SharedPtr<Buffer>		vertexBuffer	= Buffer::createAndAlloc(vk, device, BufferCreateInfo(dataSize,
1024 		VK_BUFFER_USAGE_VERTEX_BUFFER_BIT), m_context.getDefaultAllocator(), MemoryRequirement::HostVisible);
1025 
1026 	deUint8*					ptr				= reinterpret_cast<deUint8*>(vertexBuffer->getBoundMemory().getHostPtr());
1027 	deMemcpy(ptr, &m_data[0], static_cast<size_t>( m_data.size() * sizeof(VertexData)));
1028 
1029 	flushMappedMemoryRange(vk, device, vertexBuffer->getBoundMemory().getMemory(), vertexBuffer->getBoundMemory().getOffset(), dataSize);
1030 	return vertexBuffer;
1031 }
1032 
creatColorAttachmentAndRenderPass(void)1033 void GraphicBasicTestInstance::creatColorAttachmentAndRenderPass (void)
1034 {
1035 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1036 	const VkDevice			device	= m_context.getDevice();
1037 
1038 	{
1039 		VkExtent3D					imageExtent				=
1040 		{
1041 			WIDTH,	// width;
1042 			HEIGHT,	// height;
1043 			1u		// depth;
1044 		};
1045 
1046 		const ImageCreateInfo		colorImageCreateInfo	(VK_IMAGE_TYPE_2D, m_colorAttachmentFormat, imageExtent, 1, 1, VK_SAMPLE_COUNT_1_BIT, VK_IMAGE_TILING_OPTIMAL,
1047 															VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
1048 
1049 		m_colorAttachmentImage	= Image::createAndAlloc(vk, device, colorImageCreateInfo, m_context.getDefaultAllocator(), m_context.getUniversalQueueFamilyIndex());
1050 
1051 		const ImageViewCreateInfo	attachmentViewInfo		(m_colorAttachmentImage->object(), VK_IMAGE_VIEW_TYPE_2D, m_colorAttachmentFormat);
1052 		m_attachmentView			= createImageView(vk, device, &attachmentViewInfo);
1053 
1054 		ImageCreateInfo				depthImageCreateInfo	(vk::VK_IMAGE_TYPE_2D, VK_FORMAT_D16_UNORM, imageExtent, 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
1055 															 vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
1056 
1057 		m_depthImage				= Image::createAndAlloc(vk, device, depthImageCreateInfo, m_context.getDefaultAllocator(), m_context.getUniversalQueueFamilyIndex());
1058 
1059 		// Construct a depth  view from depth image
1060 		const ImageViewCreateInfo	depthViewInfo			(m_depthImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_D16_UNORM);
1061 		m_depthiew				= vk::createImageView(vk, device, &depthViewInfo);
1062 	}
1063 
1064 	{
1065 		// Renderpass and Framebuffer
1066 		RenderPassCreateInfo		renderPassCreateInfo;
1067 		renderPassCreateInfo.addAttachment(AttachmentDescription(m_colorAttachmentFormat,						// format
1068 																	VK_SAMPLE_COUNT_1_BIT,						// samples
1069 																	VK_ATTACHMENT_LOAD_OP_CLEAR,				// loadOp
1070 																	VK_ATTACHMENT_STORE_OP_STORE ,				// storeOp
1071 																	VK_ATTACHMENT_LOAD_OP_DONT_CARE,			// stencilLoadOp
1072 																	VK_ATTACHMENT_STORE_OP_STORE ,				// stencilLoadOp
1073 																	VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,	// initialLauout
1074 																	VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));	// finalLayout
1075 
1076 		renderPassCreateInfo.addAttachment(AttachmentDescription(VK_FORMAT_D16_UNORM,										// format
1077 																 vk::VK_SAMPLE_COUNT_1_BIT,									// samples
1078 																 vk::VK_ATTACHMENT_LOAD_OP_CLEAR,							// loadOp
1079 																 vk::VK_ATTACHMENT_STORE_OP_DONT_CARE,						// storeOp
1080 																 vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,						// stencilLoadOp
1081 																 vk::VK_ATTACHMENT_STORE_OP_DONT_CARE,						// stencilLoadOp
1082 																 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,		// initialLauout
1083 																 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));	// finalLayout
1084 
1085 		const VkAttachmentReference	colorAttachmentReference =
1086 		{
1087 			0u,											// attachment
1088 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL	// layout
1089 		};
1090 
1091 		const VkAttachmentReference depthAttachmentReference =
1092 		{
1093 			1u,															// attachment
1094 			vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL		// layout
1095 		};
1096 
1097 		const VkSubpassDescription	subpass =
1098 		{
1099 			(VkSubpassDescriptionFlags) 0,		//VkSubpassDescriptionFlags		flags;
1100 			VK_PIPELINE_BIND_POINT_GRAPHICS,	//VkPipelineBindPoint			pipelineBindPoint;
1101 			0u,									//deUint32						inputAttachmentCount;
1102 			DE_NULL,							//const VkAttachmentReference*	pInputAttachments;
1103 			1u,									//deUint32						colorAttachmentCount;
1104 			&colorAttachmentReference,			//const VkAttachmentReference*	pColorAttachments;
1105 			DE_NULL,							//const VkAttachmentReference*	pResolveAttachments;
1106 			&depthAttachmentReference,			//const VkAttachmentReference*	pDepthStencilAttachment;
1107 			0u,									//deUint32						preserveAttachmentCount;
1108 			DE_NULL,							//const deUint32*				pPreserveAttachments;
1109 		};
1110 
1111 		renderPassCreateInfo.addSubpass(subpass);
1112 		m_renderPass = createRenderPass(vk, device, &renderPassCreateInfo);
1113 
1114 		std::vector<vk::VkImageView> attachments(2);
1115 		attachments[0] = *m_attachmentView;
1116 		attachments[1] = *m_depthiew;
1117 
1118 		FramebufferCreateInfo		framebufferCreateInfo(*m_renderPass, attachments, WIDTH, HEIGHT, 1);
1119 		m_framebuffer = createFramebuffer(vk, device, &framebufferCreateInfo);
1120 	}
1121 }
1122 
checkImage(void)1123 bool GraphicBasicTestInstance::checkImage (void)
1124 {
1125 	if (m_parametersGraphic.vertexOnlyPipe)
1126 		return true;
1127 
1128 	const VkQueue						queue			= m_context.getUniversalQueue();
1129 	const VkOffset3D					zeroOffset		= { 0, 0, 0 };
1130 	const tcu::ConstPixelBufferAccess	renderedFrame	= m_colorAttachmentImage->readSurface(queue, m_context.getDefaultAllocator(),
1131 															VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, VK_IMAGE_ASPECT_COLOR_BIT);
1132 	int									colorNdx		= 0;
1133 	tcu::Texture2D						referenceFrame	(mapVkFormat(m_colorAttachmentFormat), WIDTH, HEIGHT);
1134 	referenceFrame.allocLevel(0);
1135 
1136 	for (int y = 0; y < HEIGHT/2; ++y)
1137 	for (int x = 0; x < WIDTH/2; ++x)
1138 			referenceFrame.getLevel(0).setPixel(m_data[colorNdx].color, x, y);
1139 
1140 	colorNdx += 4;
1141 	for (int y =  HEIGHT/2; y < HEIGHT; ++y)
1142 	for (int x = 0; x < WIDTH/2; ++x)
1143 			referenceFrame.getLevel(0).setPixel(m_data[colorNdx].color, x, y);
1144 
1145 	colorNdx += 4;
1146 	for (int y = 0; y < HEIGHT/2; ++y)
1147 	for (int x =  WIDTH/2; x < WIDTH; ++x)
1148 			referenceFrame.getLevel(0).setPixel(m_data[colorNdx].color, x, y);
1149 
1150 	colorNdx += 4;
1151 	for (int y =  HEIGHT/2; y < HEIGHT; ++y)
1152 	for (int x =  WIDTH/2; x < WIDTH; ++x)
1153 			referenceFrame.getLevel(0).setPixel(m_data[colorNdx].color, x, y);
1154 
1155 	return tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Result", "Image comparison result", referenceFrame.getLevel(0), renderedFrame, tcu::Vec4(0.01f), tcu::COMPARE_LOG_ON_ERROR);
1156 }
1157 
1158 class VertexShaderTestInstance : public GraphicBasicTestInstance
1159 {
1160 public:
1161 							VertexShaderTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
1162 protected:
1163 	virtual void			createPipeline				(void);
1164 	virtual tcu::TestStatus	executeTest					(void);
1165 	virtual tcu::TestStatus	checkResult					(VkQueryPool queryPool);
1166 	void					draw						(VkCommandBuffer cmdBuffer);
1167 };
1168 
VertexShaderTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)1169 VertexShaderTestInstance::VertexShaderTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
1170 	: GraphicBasicTestInstance	(context, data, parametersGraphic, drawRepeats )
1171 {
1172 }
1173 
createPipeline(void)1174 void VertexShaderTestInstance::createPipeline (void)
1175 {
1176 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
1177 	const VkDevice			device	= m_context.getDevice();
1178 
1179 	switch (m_parametersGraphic.primitiveTopology)
1180 	{
1181 		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
1182 		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
1183 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
1184 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
1185 			if (!m_context.getDeviceFeatures().geometryShader)
1186 				throw tcu::NotSupportedError("Geometry shader are not supported");
1187 			break;
1188 		default:
1189 			break;
1190 	}
1191 
1192 	// Pipeline
1193 	Unique<VkShaderModule>	vs(createShaderModule(vk, device, m_context.getBinaryCollection().get("vertex"), 0));
1194 	Move<VkShaderModule>	fs;
1195 
1196 	if (!m_parametersGraphic.vertexOnlyPipe)
1197 		fs = createShaderModule(vk, device, m_context.getBinaryCollection().get("fragment"), 0);
1198 
1199 	const PipelineCreateInfo::ColorBlendState::Attachment attachmentState;
1200 
1201 	const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
1202 	m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
1203 
1204 	const VkVertexInputBindingDescription vertexInputBindingDescription		=
1205 	{
1206 		0,											// binding;
1207 		static_cast<deUint32>(sizeof(VertexData)),	// stride;
1208 		VK_VERTEX_INPUT_RATE_VERTEX				// inputRate
1209 	};
1210 
1211 	const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
1212 	{
1213 		{
1214 			0u,
1215 			0u,
1216 			VK_FORMAT_R32G32B32A32_SFLOAT,
1217 			0u
1218 		},	// VertexElementData::position
1219 		{
1220 			1u,
1221 			0u,
1222 			VK_FORMAT_R32G32B32A32_SFLOAT,
1223 			static_cast<deUint32>(sizeof(tcu::Vec4))
1224 		},	// VertexElementData::color
1225 	};
1226 
1227 	const VkPipelineVertexInputStateCreateInfo vf_info			=
1228 	{																	// sType;
1229 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,		// pNext;
1230 		NULL,															// flags;
1231 		0u,																// vertexBindingDescriptionCount;
1232 		1u,																// pVertexBindingDescriptions;
1233 		&vertexInputBindingDescription,									// vertexAttributeDescriptionCount;
1234 		2u,																// pVertexAttributeDescriptions;
1235 		vertexInputAttributeDescriptions
1236 	};
1237 
1238 	PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, (VkPipelineCreateFlags)0);
1239 	pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", VK_SHADER_STAGE_VERTEX_BIT));
1240 	if (!m_parametersGraphic.vertexOnlyPipe)
1241 		pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", VK_SHADER_STAGE_FRAGMENT_BIT));
1242 	pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
1243 	pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_parametersGraphic.primitiveTopology));
1244 	pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &attachmentState));
1245 
1246 	const VkViewport	viewport	= makeViewport(WIDTH, HEIGHT);
1247 	const VkRect2D		scissor		= makeRect2D(WIDTH, HEIGHT);
1248 	pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1u, std::vector<VkViewport>(1, viewport), std::vector<VkRect2D>(1, scissor)));
1249 	pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
1250 	pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
1251 	pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
1252 	pipelineCreateInfo.addState(vf_info);
1253 	m_pipeline = createGraphicsPipeline(vk, device, DE_NULL, &pipelineCreateInfo);
1254 }
1255 
executeTest(void)1256 tcu::TestStatus VertexShaderTestInstance::executeTest (void)
1257 {
1258 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
1259 	const VkDevice							device					= m_context.getDevice();
1260 	const VkQueue							queue					= m_context.getUniversalQueue();
1261 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
1262 
1263 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
1264 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
1265 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
1266 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
1267 
1268 	const VkDeviceSize						vertexBufferOffset		= 0u;
1269 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
1270 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
1271 
1272 	const Unique<VkCommandBuffer>			cmdBuffer				(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1273 
1274 	beginCommandBuffer(vk, *cmdBuffer);
1275 	{
1276 		std::vector<VkClearValue>	renderPassClearValues	(2);
1277 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1278 
1279 		initialTransitionColor2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1280 									  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
1281 		initialTransitionDepth2DImage(vk, *cmdBuffer, m_depthImage->object(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1282 									  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
1283 
1284 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
1285 			vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, queryCount);
1286 
1287 		beginRenderPass(vk, *cmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0]);
1288 
1289 		for (deUint32 i = 0; i < queryCount; ++i)
1290 		{
1291 			vk.cmdBeginQuery(*cmdBuffer, *queryPool, i, (VkQueryControlFlags)0u);
1292 			vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
1293 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1294 
1295 			for(deUint64 j=0; j<m_drawRepeats[i]; ++j)
1296 				draw(*cmdBuffer);
1297 
1298 			vk.cmdEndQuery(*cmdBuffer, *queryPool, i);
1299 		}
1300 
1301 		endRenderPass(vk, *cmdBuffer);
1302 
1303 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
1304 		{
1305 			vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, queryCount);
1306 			vk.cmdCopyQueryPoolResults(*cmdBuffer, *queryPool, 0, queryCount, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
1307 		}
1308 
1309 		transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
1310 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
1311 	}
1312 	endCommandBuffer(vk, *cmdBuffer);
1313 
1314 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
1315 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
1316 
1317 	// Wait for completion
1318 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1319 	return checkResult (*queryPool);
1320 }
1321 
checkResult(VkQueryPool queryPool)1322 tcu::TestStatus VertexShaderTestInstance::checkResult (VkQueryPool queryPool)
1323 {
1324 	const DeviceInterface&	vk			= m_context.getDeviceInterface();
1325 	const VkDevice			device		= m_context.getDevice();
1326 	deUint64				expectedMin	= 0u;
1327 
1328 	switch(m_parametersGraphic.queryStatisticFlags)
1329 	{
1330 		case VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT:
1331 			expectedMin = 16u;
1332 			break;
1333 		case VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT:
1334 			expectedMin =	m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST					? 15u :
1335 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY			?  8u :
1336 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY		? 14u :
1337 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY		?  6u :
1338 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY	?  8u :
1339 							16u;
1340 			break;
1341 		case VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT:
1342 			expectedMin =	m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST						? 16u :
1343 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST						?  8u :
1344 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP						? 15u :
1345 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST					?  5u :
1346 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP					?  8u :
1347 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN						? 14u :
1348 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY			?  4u :
1349 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY		? 13u :
1350 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY		?  2u :
1351 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY	?  6u :
1352 							0u;
1353 			break;
1354 		case VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT:
1355 			expectedMin =	m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST						?     9u :
1356 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST						?   192u :
1357 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP						?   448u :
1358 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST					?  2016u :
1359 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP					?  4096u :
1360 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN						? 10208u :
1361 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY			?   128u :
1362 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY		?   416u :
1363 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY		?   992u :
1364 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY	?  3072u :
1365 							0u;
1366 			break;
1367 		default:
1368 			DE_FATAL("Unexpected type of statistics query");
1369 			break;
1370 	}
1371 
1372 	const deUint32 queryCount = static_cast<deUint32>(m_drawRepeats.size());
1373 
1374 	if (m_parametersGraphic.resetType == RESET_TYPE_NORMAL)
1375 	{
1376 		ResultsVector results(queryCount, 0u);
1377 		VK_CHECK(GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (VK_QUERY_RESULT_WAIT_BIT | m_parametersGraphic.querySizeFlags())));
1378 		if (results[0] < expectedMin)
1379 			return tcu::TestStatus::fail("QueryPoolResults incorrect");
1380 		if (queryCount > 1)
1381 		{
1382 			double pearson = calculatePearsonCorrelation(m_drawRepeats, results);
1383 			if ( fabs( pearson ) < 0.8 )
1384 				return tcu::TestStatus::fail("QueryPoolResults are nonlinear");
1385 		}
1386 	}
1387 	else if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
1388 	{
1389 		ResultsVectorWithAvailability results(queryCount, pair<deUint64, deUint64>(0u,0u));
1390 		VK_CHECK(GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (VK_QUERY_RESULT_WAIT_BIT | m_parametersGraphic.querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT)));
1391 		if (results[0].first < expectedMin || results[0].second == 0)
1392 			return tcu::TestStatus::fail("QueryPoolResults incorrect");
1393 
1394 		if (queryCount > 1)
1395 		{
1396 			double pearson = calculatePearsonCorrelation(m_drawRepeats, results);
1397 			if ( fabs( pearson ) < 0.8 )
1398 				return tcu::TestStatus::fail("QueryPoolResults are nonlinear");
1399 		}
1400 
1401 		deUint64 temp = results[0].first;
1402 
1403 		vk.resetQueryPool(device, queryPool, 0, queryCount);
1404 		vk::VkResult res = GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (m_parametersGraphic.querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT));
1405 		/* From Vulkan spec:
1406 		 *
1407 		 * If VK_QUERY_RESULT_WAIT_BIT and VK_QUERY_RESULT_PARTIAL_BIT are both not set then no result values are written to pData
1408 		 * for queries that are in the unavailable state at the time of the call, and vkGetQueryPoolResults returns VK_NOT_READY.
1409 		 * However, availability state is still written to pData for those queries if VK_QUERY_RESULT_WITH_AVAILABILITY_BIT is set.
1410 		 */
1411 		if (res != vk::VK_NOT_READY || results[0].first != temp || results[0].second != 0)
1412 			return tcu::TestStatus::fail("QueryPoolResults incorrect reset");
1413 	}
1414 	else
1415 	{
1416 		// With RESET_TYPE_BEFORE_COPY, we only need to verify the result after the copy include an availability bit set as zero.
1417 		return verifyUnavailable();
1418 	}
1419 
1420 	if (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP && !checkImage())
1421 		return tcu::TestStatus::fail("Result image doesn't match expected image.");
1422 
1423 	return tcu::TestStatus::pass("Pass");
1424 }
1425 
draw(VkCommandBuffer cmdBuffer)1426 void VertexShaderTestInstance::draw (VkCommandBuffer cmdBuffer)
1427 {
1428 	const DeviceInterface& vk = m_context.getDeviceInterface();
1429 	switch(m_parametersGraphic.primitiveTopology)
1430 	{
1431 		case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
1432 		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
1433 		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
1434 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
1435 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
1436 		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
1437 		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
1438 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
1439 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
1440 			vk.cmdDraw(cmdBuffer, 16u, 1u, 0u, 0u);
1441 			break;
1442 		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
1443 			vk.cmdDraw(cmdBuffer, 4u, 1u, 0u,  0u);
1444 			vk.cmdDraw(cmdBuffer, 4u, 1u, 4u,  1u);
1445 			vk.cmdDraw(cmdBuffer, 4u, 1u, 8u,  2u);
1446 			vk.cmdDraw(cmdBuffer, 4u, 1u, 12u, 3u);
1447 			break;
1448 		default:
1449 			DE_ASSERT(0);
1450 			break;
1451 	}
1452 }
1453 
1454 class VertexShaderSecondaryTestInstance : public VertexShaderTestInstance
1455 {
1456 public:
1457 							VertexShaderSecondaryTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
1458 protected:
1459 	virtual tcu::TestStatus	executeTest							(void);
1460 };
1461 
VertexShaderSecondaryTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)1462 VertexShaderSecondaryTestInstance::VertexShaderSecondaryTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
1463 	: VertexShaderTestInstance	(context, data, parametersGraphic, drawRepeats)
1464 {
1465 }
1466 
1467 typedef de::SharedPtr<vk::Unique<VkCommandBuffer>> VkCommandBufferSp;
1468 
executeTest(void)1469 tcu::TestStatus VertexShaderSecondaryTestInstance::executeTest (void)
1470 {
1471 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
1472 	const VkDevice							device					= m_context.getDevice();
1473 	const VkQueue							queue					= m_context.getUniversalQueue();
1474 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
1475 
1476 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
1477 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
1478 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
1479 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
1480 
1481 	const VkDeviceSize						vertexBufferOffset		= 0u;
1482 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
1483 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
1484 
1485 	const Unique<VkCommandBuffer>			primaryCmdBuffer		(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1486 	std::vector<VkCommandBufferSp>			secondaryCmdBuffers(queryCount);
1487 
1488 	for (deUint32 i = 0; i < queryCount; ++i)
1489 		secondaryCmdBuffers[i] = VkCommandBufferSp(new vk::Unique<VkCommandBuffer>(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY)));
1490 
1491 	for (deUint32 i = 0; i < queryCount; ++i)
1492 	{
1493 		beginSecondaryCommandBuffer(vk, secondaryCmdBuffers[i]->get(), m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1494 		vk.cmdBeginQuery(secondaryCmdBuffers[i]->get(), *queryPool, i, (VkQueryControlFlags)0u);
1495 		vk.cmdBindPipeline(secondaryCmdBuffers[i]->get(), VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1496 		vk.cmdBindVertexBuffers(secondaryCmdBuffers[i]->get(), 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1497 		for(deUint32 j=0; j<m_drawRepeats[i]; ++j)
1498 			draw(secondaryCmdBuffers[i]->get());
1499 		vk.cmdEndQuery(secondaryCmdBuffers[i]->get(), *queryPool, i);
1500 		endCommandBuffer(vk, secondaryCmdBuffers[i]->get());
1501 	}
1502 
1503 	beginCommandBuffer(vk, *primaryCmdBuffer);
1504 	{
1505 		std::vector<VkClearValue>	renderPassClearValues	(2);
1506 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1507 
1508 		initialTransitionColor2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1509 									  vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
1510 		initialTransitionDepth2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1511 									  vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
1512 
1513 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
1514 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
1515 
1516 		beginRenderPass(vk, *primaryCmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0], VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1517 		for (deUint32 i = 0; i < queryCount; ++i)
1518 			vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &(secondaryCmdBuffers[i]->get()));
1519 		endRenderPass(vk, *primaryCmdBuffer);
1520 
1521 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
1522 		{
1523 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
1524 			vk.cmdCopyQueryPoolResults(*primaryCmdBuffer, *queryPool, 0, queryCount, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
1525 		}
1526 
1527 		transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
1528 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
1529 	}
1530 	endCommandBuffer(vk, *primaryCmdBuffer);
1531 
1532 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
1533 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
1534 
1535 	// Wait for completion
1536 	submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1537 	return checkResult (*queryPool);
1538 }
1539 
1540 class VertexShaderSecondaryInheritedTestInstance : public VertexShaderTestInstance
1541 {
1542 public:
1543 							VertexShaderSecondaryInheritedTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
1544 protected:
1545 	virtual void			checkExtensions						(deBool hostQueryResetEnabled);
1546 	virtual tcu::TestStatus	executeTest							(void);
1547 };
1548 
VertexShaderSecondaryInheritedTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)1549 VertexShaderSecondaryInheritedTestInstance::VertexShaderSecondaryInheritedTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
1550 	: VertexShaderTestInstance	(context, data, parametersGraphic, drawRepeats)
1551 {
1552 }
1553 
checkExtensions(deBool hostQueryResetEnabled)1554 void VertexShaderSecondaryInheritedTestInstance::checkExtensions (deBool hostQueryResetEnabled)
1555 {
1556 	StatisticQueryTestInstance::checkExtensions(hostQueryResetEnabled);
1557 	if (!m_context.getDeviceFeatures().inheritedQueries)
1558 		throw tcu::NotSupportedError("Inherited queries are not supported");
1559 }
1560 
executeTest(void)1561 tcu::TestStatus VertexShaderSecondaryInheritedTestInstance::executeTest (void)
1562 {
1563 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
1564 	const VkDevice							device					= m_context.getDevice();
1565 	const VkQueue							queue					= m_context.getUniversalQueue();
1566 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
1567 
1568 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
1569 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
1570 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
1571 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
1572 
1573 	const VkDeviceSize						vertexBufferOffset		= 0u;
1574 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
1575 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
1576 
1577 	const Unique<VkCommandBuffer>			primaryCmdBuffer		(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1578 	std::vector<VkCommandBufferSp>			secondaryCmdBuffers(queryCount);
1579 
1580 	for (deUint32 i = 0; i < queryCount; ++i)
1581 		secondaryCmdBuffers[i] = VkCommandBufferSp(new vk::Unique<VkCommandBuffer>(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY)));
1582 
1583 	for (deUint32 i = 0; i < queryCount; ++i)
1584 	{
1585 		beginSecondaryCommandBuffer(vk, secondaryCmdBuffers[i]->get(), m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1586 		vk.cmdBindPipeline(secondaryCmdBuffers[i]->get(), VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1587 		vk.cmdBindVertexBuffers(secondaryCmdBuffers[i]->get(), 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1588 		for (deUint32 j = 0; j<m_drawRepeats[i]; ++j)
1589 			draw(secondaryCmdBuffers[i]->get());
1590 		endCommandBuffer(vk, secondaryCmdBuffers[i]->get());
1591 	}
1592 
1593 	beginCommandBuffer(vk, *primaryCmdBuffer);
1594 	{
1595 		std::vector<VkClearValue>	renderPassClearValues	(2);
1596 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1597 
1598 		initialTransitionColor2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1599 									  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
1600 		initialTransitionDepth2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1601 									  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
1602 
1603 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
1604 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
1605 
1606 		for (deUint32 i = 0; i < queryCount; ++i)
1607 		{
1608 			vk.cmdBeginQuery(*primaryCmdBuffer, *queryPool, i, (VkQueryControlFlags)0u);
1609 			beginRenderPass(vk, *primaryCmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0], VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1610 			vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &(secondaryCmdBuffers[i]->get()));
1611 			endRenderPass(vk, *primaryCmdBuffer);
1612 			vk.cmdEndQuery(*primaryCmdBuffer, *queryPool, i);
1613 		}
1614 
1615 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
1616 		{
1617 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
1618 			vk.cmdCopyQueryPoolResults(*primaryCmdBuffer, *queryPool, 0, queryCount, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
1619 		}
1620 
1621 		transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
1622 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
1623 	}
1624 	endCommandBuffer(vk, *primaryCmdBuffer);
1625 
1626 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
1627 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
1628 
1629 	// Wait for completion
1630 	submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1631 	return checkResult (*queryPool);
1632 }
1633 
1634 class GeometryShaderTestInstance : public GraphicBasicTestInstance
1635 {
1636 public:
1637 							GeometryShaderTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
1638 protected:
1639 	virtual void			checkExtensions				(deBool hostQueryResetEnabled);
1640 	virtual void			createPipeline				(void);
1641 	virtual tcu::TestStatus	executeTest					(void);
1642 	tcu::TestStatus			checkResult					(VkQueryPool queryPool);
1643 	void					draw						(VkCommandBuffer cmdBuffer);
1644 };
1645 
GeometryShaderTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)1646 GeometryShaderTestInstance::GeometryShaderTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
1647 	: GraphicBasicTestInstance(context, data, parametersGraphic, drawRepeats)
1648 {
1649 }
1650 
checkExtensions(deBool hostQueryResetEnabled)1651 void GeometryShaderTestInstance::checkExtensions (deBool hostQueryResetEnabled)
1652 {
1653 	StatisticQueryTestInstance::checkExtensions(hostQueryResetEnabled);
1654 	if (!m_context.getDeviceFeatures().geometryShader)
1655 		throw tcu::NotSupportedError("Geometry shader are not supported");
1656 }
1657 
createPipeline(void)1658 void GeometryShaderTestInstance::createPipeline (void)
1659 {
1660 	const DeviceInterface&	vk						= m_context.getDeviceInterface();
1661 	const VkDevice			device					= m_context.getDevice();
1662 	const VkBool32			useGeomPointSize		= m_context.getDeviceFeatures().shaderTessellationAndGeometryPointSize && (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
1663 
1664 	// Pipeline
1665 	Unique<VkShaderModule> vs(createShaderModule(vk, device, m_context.getBinaryCollection().get("vertex"), (VkShaderModuleCreateFlags)0));
1666 	Unique<VkShaderModule> gs(createShaderModule(vk, device, m_context.getBinaryCollection().get(useGeomPointSize ? "geometry_point_size" : "geometry"), (VkShaderModuleCreateFlags)0));
1667 	Unique<VkShaderModule> fs(createShaderModule(vk, device, m_context.getBinaryCollection().get("fragment"), (VkShaderModuleCreateFlags)0));
1668 
1669 	const PipelineCreateInfo::ColorBlendState::Attachment attachmentState;
1670 
1671 	const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
1672 	m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
1673 
1674 	const VkVertexInputBindingDescription vertexInputBindingDescription		=
1675 	{
1676 		0u,											// binding;
1677 		static_cast<deUint32>(sizeof(VertexData)),	// stride;
1678 		VK_VERTEX_INPUT_RATE_VERTEX					// inputRate
1679 	};
1680 
1681 	const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
1682 	{
1683 		{
1684 			0u,
1685 			0u,
1686 			VK_FORMAT_R32G32B32A32_SFLOAT,
1687 			0u
1688 		},	// VertexElementData::position
1689 		{
1690 			1u,
1691 			0u,
1692 			VK_FORMAT_R32G32B32A32_SFLOAT,
1693 			static_cast<deUint32>(sizeof(tcu::Vec4))
1694 		},	// VertexElementData::color
1695 	};
1696 
1697 	const VkPipelineVertexInputStateCreateInfo vf_info			=
1698 	{																	// sType;
1699 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,		// pNext;
1700 		NULL,															// flags;
1701 		0u,																// vertexBindingDescriptionCount;
1702 		1,																// pVertexBindingDescriptions;
1703 		&vertexInputBindingDescription,									// vertexAttributeDescriptionCount;
1704 		2,																// pVertexAttributeDescriptions;
1705 		vertexInputAttributeDescriptions
1706 	};
1707 
1708 	PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, (VkPipelineCreateFlags)0);
1709 	pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", VK_SHADER_STAGE_VERTEX_BIT));
1710 	pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*gs, "main", VK_SHADER_STAGE_GEOMETRY_BIT));
1711 	pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", VK_SHADER_STAGE_FRAGMENT_BIT));
1712 	pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_parametersGraphic.primitiveTopology));
1713 	pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &attachmentState));
1714 
1715 	const VkViewport	viewport	= makeViewport(WIDTH, HEIGHT);
1716 	const VkRect2D		scissor		= makeRect2D(WIDTH, HEIGHT);
1717 
1718 	pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1, std::vector<VkViewport>(1, viewport), std::vector<VkRect2D>(1, scissor)));
1719 
1720 	if (m_context.getDeviceFeatures().depthBounds)
1721 		pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState(true, true, VK_COMPARE_OP_GREATER_OR_EQUAL, true));
1722 	else
1723 		pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
1724 
1725 	pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState(false));
1726 	pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
1727 	pipelineCreateInfo.addState(vf_info);
1728 	m_pipeline = createGraphicsPipeline(vk, device, DE_NULL, &pipelineCreateInfo);
1729 }
1730 
executeTest(void)1731 tcu::TestStatus GeometryShaderTestInstance::executeTest (void)
1732 {
1733 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
1734 	const VkDevice							device					= m_context.getDevice();
1735 	const VkQueue							queue					= m_context.getUniversalQueue();
1736 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
1737 
1738 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
1739 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
1740 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
1741 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
1742 
1743 	const VkDeviceSize						vertexBufferOffset		= 0u;
1744 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
1745 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
1746 
1747 	const Unique<VkCommandBuffer>			cmdBuffer				(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1748 
1749 	beginCommandBuffer(vk, *cmdBuffer);
1750 	{
1751 		std::vector<VkClearValue>	renderPassClearValues	(2);
1752 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1753 
1754 		initialTransitionColor2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1755 									  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
1756 		initialTransitionDepth2DImage(vk, *cmdBuffer, m_depthImage->object(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1757 									  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
1758 
1759 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
1760 			vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, queryCount);
1761 
1762 		beginRenderPass(vk, *cmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0]);
1763 
1764 		for (deUint32 i = 0; i < queryCount; ++i)
1765 		{
1766 			vk.cmdBeginQuery(*cmdBuffer, *queryPool, i, (VkQueryControlFlags)0u);
1767 			vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
1768 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1769 
1770 			for (deUint64 j = 0; j<m_drawRepeats[i]; ++j)
1771 				draw(*cmdBuffer);
1772 
1773 			vk.cmdEndQuery(*cmdBuffer, *queryPool, i);
1774 		}
1775 
1776 		endRenderPass(vk, *cmdBuffer);
1777 
1778 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
1779 		{
1780 			vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, queryCount);
1781 			vk.cmdCopyQueryPoolResults(*cmdBuffer, *queryPool, 0, queryCount, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
1782 		}
1783 
1784 		transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
1785 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
1786 	}
1787 	endCommandBuffer(vk, *cmdBuffer);
1788 
1789 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
1790 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
1791 
1792 	// Wait for completion
1793 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1794 	return checkResult(*queryPool);
1795 }
1796 
checkResult(VkQueryPool queryPool)1797 tcu::TestStatus GeometryShaderTestInstance::checkResult (VkQueryPool queryPool)
1798 {
1799 	const DeviceInterface&	vk			= m_context.getDeviceInterface();
1800 	const VkDevice			device		= m_context.getDevice();
1801 	deUint64				expectedMin	= 0u;
1802 
1803 	switch(m_parametersGraphic.queryStatisticFlags)
1804 	{
1805 		case VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT:
1806 			expectedMin =	m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST						? 16u :
1807 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST						? 8u :
1808 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP						? 15u :
1809 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST					? 4u :
1810 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP					? 4u :
1811 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN						? 14u :
1812 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY			? 4u :
1813 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY		? 13u :
1814 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY		? 2u :
1815 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY	? 6u :
1816 							0u;
1817 			break;
1818 		case VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT:
1819 		case VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT:
1820 		case VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT:
1821 			expectedMin =	m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST						? 112u :
1822 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST						? 32u :
1823 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP						? 60u :
1824 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST					? 8u :
1825 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP					? 8u :
1826 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN						? 28u :
1827 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY			? 16u :
1828 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY		? 52u :
1829 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY		? 4u :
1830 							m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY	? 12u :
1831 							0u;
1832 			break;
1833 		default:
1834 			DE_FATAL("Unexpected type of statistics query");
1835 			break;
1836 	}
1837 
1838 	const deUint32 queryCount = static_cast<deUint32>(m_drawRepeats.size());
1839 
1840 	if (m_parametersGraphic.resetType == RESET_TYPE_NORMAL)
1841 	{
1842 		ResultsVector results(queryCount, 0u);
1843 		VK_CHECK(GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (VK_QUERY_RESULT_WAIT_BIT | m_parametersGraphic.querySizeFlags())));
1844 		if (results[0] < expectedMin)
1845 			return tcu::TestStatus::fail("QueryPoolResults incorrect");
1846 		if (queryCount > 1)
1847 		{
1848 			double pearson = calculatePearsonCorrelation(m_drawRepeats, results);
1849 			if ( fabs( pearson ) < 0.8 )
1850 				return tcu::TestStatus::fail("QueryPoolResults are nonlinear");
1851 		}
1852 	}
1853 	else if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
1854 	{
1855 		ResultsVectorWithAvailability results(queryCount, pair<deUint64, deUint64>(0u, 0u));
1856 		VK_CHECK(GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (VK_QUERY_RESULT_WAIT_BIT | m_parametersGraphic.querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT)));
1857 		if (results[0].first < expectedMin || results[0].second == 0u)
1858 			return tcu::TestStatus::fail("QueryPoolResults incorrect");
1859 
1860 		if (queryCount > 1)
1861 		{
1862 			double pearson = calculatePearsonCorrelation(m_drawRepeats, results);
1863 			if ( fabs( pearson ) < 0.8 )
1864 				return tcu::TestStatus::fail("QueryPoolResults are nonlinear");
1865 		}
1866 
1867 		deUint64 temp = results[0].first;
1868 
1869 		vk.resetQueryPool(device, queryPool, 0, queryCount);
1870 		vk::VkResult res = GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (m_parametersGraphic.querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT));
1871 		/* From Vulkan spec:
1872 		 *
1873 		 * If VK_QUERY_RESULT_WAIT_BIT and VK_QUERY_RESULT_PARTIAL_BIT are both not set then no result values are written to pData
1874 		 * for queries that are in the unavailable state at the time of the call, and vkGetQueryPoolResults returns VK_NOT_READY.
1875 		 * However, availability state is still written to pData for those queries if VK_QUERY_RESULT_WITH_AVAILABILITY_BIT is set.
1876 		 */
1877 		if (res != vk::VK_NOT_READY || results[0].first != temp || results[0].second != 0u)
1878 			return tcu::TestStatus::fail("QueryPoolResults incorrect reset");
1879 	}
1880 	else
1881 	{
1882 		// With RESET_TYPE_BEFORE_COPY, we only need to verify the result after the copy include an availability bit set as zero.
1883 		return verifyUnavailable();
1884 	}
1885 
1886 	if ( (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST || m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ) && !checkImage())
1887 		return tcu::TestStatus::fail("Result image doesn't match expected image.");
1888 
1889 	return tcu::TestStatus::pass("Pass");
1890 }
1891 
draw(VkCommandBuffer cmdBuffer)1892 void GeometryShaderTestInstance::draw (VkCommandBuffer cmdBuffer)
1893 {
1894 	const DeviceInterface&	vk			= m_context.getDeviceInterface();
1895 	if (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ||
1896 		m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
1897 	{
1898 		vk.cmdDraw(cmdBuffer, 3u, 1u,  0u,  1u);
1899 		vk.cmdDraw(cmdBuffer, 3u, 1u,  4u,  1u);
1900 		vk.cmdDraw(cmdBuffer, 3u, 1u,  8u,  2u);
1901 		vk.cmdDraw(cmdBuffer, 3u, 1u, 12u,  3u);
1902 	}
1903 	else
1904 	{
1905 		vk.cmdDraw(cmdBuffer, 16u, 1u, 0u,  0u);
1906 	}
1907 }
1908 
1909 class GeometryShaderSecondaryTestInstance : public GeometryShaderTestInstance
1910 {
1911 public:
1912 							GeometryShaderSecondaryTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
1913 protected:
1914 	virtual tcu::TestStatus	executeTest							(void);
1915 };
1916 
GeometryShaderSecondaryTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)1917 GeometryShaderSecondaryTestInstance::GeometryShaderSecondaryTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
1918 	: GeometryShaderTestInstance	(context, data, parametersGraphic, drawRepeats)
1919 {
1920 }
1921 
executeTest(void)1922 tcu::TestStatus GeometryShaderSecondaryTestInstance::executeTest (void)
1923 {
1924 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
1925 	const VkDevice							device					= m_context.getDevice();
1926 	const VkQueue							queue					= m_context.getUniversalQueue();
1927 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
1928 
1929 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
1930 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
1931 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
1932 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
1933 
1934 	const VkDeviceSize						vertexBufferOffset		= 0;
1935 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
1936 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
1937 
1938 	const Unique<VkCommandBuffer>			primaryCmdBuffer		(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1939 	std::vector<VkCommandBufferSp>			secondaryCmdBuffers(queryCount);
1940 
1941 	for (deUint32 i = 0; i < queryCount; ++i)
1942 		secondaryCmdBuffers[i] = VkCommandBufferSp(new vk::Unique<VkCommandBuffer>(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY)));
1943 
1944 	for (deUint32 i = 0; i < queryCount; ++i)
1945 	{
1946 		beginSecondaryCommandBuffer(vk, secondaryCmdBuffers[i]->get(), m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1947 		vk.cmdBeginQuery(secondaryCmdBuffers[i]->get(), *queryPool, i, (VkQueryControlFlags)0u);
1948 		vk.cmdBindPipeline(secondaryCmdBuffers[i]->get(), VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1949 		vk.cmdBindVertexBuffers(secondaryCmdBuffers[i]->get(), 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1950 		for (deUint32 j = 0; j<m_drawRepeats[i]; ++j)
1951 			draw(secondaryCmdBuffers[i]->get());
1952 		vk.cmdEndQuery(secondaryCmdBuffers[i]->get(), *queryPool, i);
1953 		endCommandBuffer(vk, secondaryCmdBuffers[i]->get());
1954 	}
1955 
1956 	beginCommandBuffer(vk, *primaryCmdBuffer);
1957 	{
1958 		std::vector<VkClearValue>	renderPassClearValues	(2);
1959 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1960 
1961 		initialTransitionColor2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1962 									  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
1963 		initialTransitionDepth2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1964 									  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
1965 
1966 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
1967 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
1968 		beginRenderPass(vk, *primaryCmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0], VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1969 		for (deUint32 i = 0; i < queryCount; ++i)
1970 			vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &(secondaryCmdBuffers[i]->get()));
1971 		endRenderPass(vk, *primaryCmdBuffer);
1972 
1973 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
1974 		{
1975 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
1976 			vk.cmdCopyQueryPoolResults(*primaryCmdBuffer, *queryPool, 0, queryCount, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
1977 		}
1978 
1979 		transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
1980 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
1981 	}
1982 	endCommandBuffer(vk, *primaryCmdBuffer);
1983 
1984 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
1985 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
1986 
1987 	// Wait for completion
1988 	submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1989 	return checkResult(*queryPool);
1990 }
1991 
1992 class GeometryShaderSecondaryInheritedTestInstance : public GeometryShaderTestInstance
1993 {
1994 public:
1995 							GeometryShaderSecondaryInheritedTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
1996 protected:
1997 	virtual void			checkExtensions						(deBool hostQueryResetEnabled);
1998 	virtual tcu::TestStatus	executeTest							(void);
1999 };
2000 
GeometryShaderSecondaryInheritedTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)2001 GeometryShaderSecondaryInheritedTestInstance::GeometryShaderSecondaryInheritedTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
2002 	: GeometryShaderTestInstance	(context, data, parametersGraphic, drawRepeats)
2003 {
2004 }
2005 
checkExtensions(deBool hostQueryResetEnabled)2006 void GeometryShaderSecondaryInheritedTestInstance::checkExtensions (deBool hostQueryResetEnabled)
2007 {
2008 	GeometryShaderTestInstance::checkExtensions(hostQueryResetEnabled);
2009 	if (!m_context.getDeviceFeatures().inheritedQueries)
2010 		throw tcu::NotSupportedError("Inherited queries are not supported");
2011 }
2012 
executeTest(void)2013 tcu::TestStatus GeometryShaderSecondaryInheritedTestInstance::executeTest (void)
2014 {
2015 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
2016 	const VkDevice							device					= m_context.getDevice();
2017 	const VkQueue							queue					= m_context.getUniversalQueue();
2018 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
2019 
2020 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
2021 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
2022 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
2023 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
2024 
2025 	const VkDeviceSize						vertexBufferOffset		= 0u;
2026 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
2027 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
2028 
2029 	const Unique<VkCommandBuffer>			primaryCmdBuffer		(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
2030 	std::vector<VkCommandBufferSp>			secondaryCmdBuffers(queryCount);
2031 
2032 	for (deUint32 i = 0; i < queryCount; ++i)
2033 		secondaryCmdBuffers[i] = VkCommandBufferSp(new vk::Unique<VkCommandBuffer>(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY)));
2034 
2035 	for (deUint32 i = 0; i < queryCount; ++i)
2036 	{
2037 		beginSecondaryCommandBuffer(vk, secondaryCmdBuffers[i]->get(), m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
2038 		vk.cmdBindPipeline(secondaryCmdBuffers[i]->get(), VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2039 		vk.cmdBindVertexBuffers(secondaryCmdBuffers[i]->get(), 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2040 		for (deUint32 j = 0; j<m_drawRepeats[i]; ++j)
2041 			draw(secondaryCmdBuffers[i]->get());
2042 		endCommandBuffer(vk, secondaryCmdBuffers[i]->get());
2043 	}
2044 
2045 	beginCommandBuffer(vk, *primaryCmdBuffer);
2046 	{
2047 		std::vector<VkClearValue>	renderPassClearValues	(2);
2048 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
2049 
2050 		initialTransitionColor2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2051 									  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
2052 		initialTransitionDepth2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2053 									  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
2054 
2055 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
2056 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
2057 
2058 		for (deUint32 i = 0; i < queryCount; ++i)
2059 		{
2060 			vk.cmdBeginQuery(*primaryCmdBuffer, *queryPool, i, (VkQueryControlFlags)0u);
2061 			beginRenderPass(vk, *primaryCmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0], VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
2062 			vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &(secondaryCmdBuffers[i]->get()));
2063 			endRenderPass(vk, *primaryCmdBuffer);
2064 			vk.cmdEndQuery(*primaryCmdBuffer, *queryPool, i);
2065 		}
2066 
2067 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
2068 		{
2069 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
2070 			vk.cmdCopyQueryPoolResults(*primaryCmdBuffer, *queryPool, 0, queryCount, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
2071 		}
2072 
2073 		transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
2074 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
2075 	}
2076 	endCommandBuffer(vk, *primaryCmdBuffer);
2077 
2078 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
2079 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
2080 
2081 	// Wait for completion
2082 	submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
2083 	return checkResult(*queryPool);
2084 }
2085 
2086 class TessellationShaderTestInstance : public GraphicBasicTestInstance
2087 {
2088 public:
2089 							TessellationShaderTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
2090 protected:
2091 	virtual	void			checkExtensions				(deBool hostQueryResetEnabled);
2092 	virtual void			createPipeline				(void);
2093 	virtual tcu::TestStatus	executeTest					(void);
2094 	virtual tcu::TestStatus	checkResult					(VkQueryPool queryPool);
2095 	void					draw						(VkCommandBuffer cmdBuffer);
2096 };
2097 
TessellationShaderTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)2098 TessellationShaderTestInstance::TessellationShaderTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
2099 	: GraphicBasicTestInstance	(context, data, parametersGraphic, drawRepeats)
2100 {
2101 }
2102 
checkExtensions(deBool hostQueryResetEnabled)2103 void TessellationShaderTestInstance::checkExtensions (deBool hostQueryResetEnabled)
2104 {
2105 	StatisticQueryTestInstance::checkExtensions(hostQueryResetEnabled);
2106 	if (!m_context.getDeviceFeatures().tessellationShader)
2107 		throw tcu::NotSupportedError("Tessellation shader are not supported");
2108 }
2109 
2110 
createPipeline(void)2111 void TessellationShaderTestInstance::createPipeline (void)
2112 {
2113 	const DeviceInterface&	vk		= m_context.getDeviceInterface();
2114 	const VkDevice			device	= m_context.getDevice();
2115 
2116 	// Pipeline
2117 	Unique<VkShaderModule> vs(createShaderModule(vk, device, m_context.getBinaryCollection().get("vertex"), (VkShaderModuleCreateFlags)0));
2118 	Unique<VkShaderModule> tc(createShaderModule(vk, device, m_context.getBinaryCollection().get("tessellation_control"), (VkShaderModuleCreateFlags)0));
2119 	Unique<VkShaderModule> te(createShaderModule(vk, device, m_context.getBinaryCollection().get("tessellation_evaluation"), (VkShaderModuleCreateFlags)0));
2120 	Unique<VkShaderModule> fs(createShaderModule(vk, device, m_context.getBinaryCollection().get("fragment"), (VkShaderModuleCreateFlags)0));
2121 
2122 	const PipelineCreateInfo::ColorBlendState::Attachment attachmentState;
2123 
2124 	const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
2125 	m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
2126 
2127 	const VkVertexInputBindingDescription vertexInputBindingDescription		=
2128 	{
2129 		0u,											// binding;
2130 		static_cast<deUint32>(sizeof(VertexData)),	// stride;
2131 		VK_VERTEX_INPUT_RATE_VERTEX					// inputRate
2132 	};
2133 
2134 	const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
2135 	{
2136 		{
2137 			0u,
2138 			0u,
2139 			VK_FORMAT_R32G32B32A32_SFLOAT,
2140 			0u
2141 		},	// VertexElementData::position
2142 		{
2143 			1u,
2144 			0u,
2145 			VK_FORMAT_R32G32B32A32_SFLOAT,
2146 			static_cast<deUint32>(sizeof(tcu::Vec4))
2147 		},	// VertexElementData::color
2148 	};
2149 
2150 	const VkPipelineVertexInputStateCreateInfo vf_info			=
2151 	{																	// sType;
2152 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,		// pNext;
2153 		NULL,															// flags;
2154 		0u,																// vertexBindingDescriptionCount;
2155 		1u,																// pVertexBindingDescriptions;
2156 		&vertexInputBindingDescription,									// vertexAttributeDescriptionCount;
2157 		2u,																// pVertexAttributeDescriptions;
2158 		vertexInputAttributeDescriptions
2159 	};
2160 
2161 	PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, (VkPipelineCreateFlags)0);
2162 	pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", VK_SHADER_STAGE_VERTEX_BIT));
2163 	pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*tc, "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT));
2164 	pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*te, "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT));
2165 	pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", VK_SHADER_STAGE_FRAGMENT_BIT));
2166 	pipelineCreateInfo.addState	(PipelineCreateInfo::TessellationState(4));
2167 	pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(VK_PRIMITIVE_TOPOLOGY_PATCH_LIST));
2168 	pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &attachmentState));
2169 
2170 	const VkViewport	viewport	= makeViewport(WIDTH, HEIGHT);
2171 	const VkRect2D		scissor		= makeRect2D(WIDTH, HEIGHT);
2172 
2173 	pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1, std::vector<VkViewport>(1, viewport), std::vector<VkRect2D>(1, scissor)));
2174 	pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
2175 	pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
2176 	pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
2177 	pipelineCreateInfo.addState(vf_info);
2178 	m_pipeline = createGraphicsPipeline(vk, device, DE_NULL, &pipelineCreateInfo);
2179 }
2180 
executeTest(void)2181 tcu::TestStatus	TessellationShaderTestInstance::executeTest (void)
2182 {
2183 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
2184 	const VkDevice							device					= m_context.getDevice();
2185 	const VkQueue							queue					= m_context.getUniversalQueue();
2186 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
2187 
2188 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
2189 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
2190 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
2191 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
2192 
2193 	const VkDeviceSize						vertexBufferOffset		= 0u;
2194 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
2195 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
2196 
2197 	const Unique<VkCommandBuffer>			cmdBuffer				(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
2198 
2199 	beginCommandBuffer(vk, *cmdBuffer);
2200 	{
2201 		std::vector<VkClearValue>	renderPassClearValues	(2);
2202 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
2203 
2204 		initialTransitionColor2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2205 									  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
2206 		initialTransitionDepth2DImage(vk, *cmdBuffer, m_depthImage->object(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2207 									  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
2208 
2209 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
2210 			vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, queryCount);
2211 
2212 		beginRenderPass(vk, *cmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0]);
2213 
2214 		for (deUint32 i = 0; i < queryCount; ++i)
2215 		{
2216 			vk.cmdBeginQuery(*cmdBuffer, *queryPool, i, (VkQueryControlFlags)0u);
2217 			vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
2218 			vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2219 
2220 			for (deUint64 j = 0; j<m_drawRepeats[i]; ++j)
2221 				draw(*cmdBuffer);
2222 
2223 			vk.cmdEndQuery(*cmdBuffer, *queryPool, i);
2224 		}
2225 
2226 		endRenderPass(vk, *cmdBuffer);
2227 
2228 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
2229 		{
2230 			vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, queryCount);
2231 			vk.cmdCopyQueryPoolResults(*cmdBuffer, *queryPool, 0, queryCount, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
2232 		}
2233 
2234 		transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
2235 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
2236 	}
2237 	endCommandBuffer(vk, *cmdBuffer);
2238 
2239 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
2240 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
2241 
2242 	// Wait for completion
2243 	submitCommandsAndWait(vk, device, queue, *cmdBuffer);
2244 	return checkResult (*queryPool);
2245 }
2246 
checkResult(VkQueryPool queryPool)2247 tcu::TestStatus TessellationShaderTestInstance::checkResult (VkQueryPool queryPool)
2248 {
2249 	const DeviceInterface&	vk			= m_context.getDeviceInterface();
2250 	const VkDevice			device		= m_context.getDevice();
2251 	deUint64				expectedMin	= 0u;
2252 
2253 	switch(m_parametersGraphic.queryStatisticFlags)
2254 	{
2255 		case VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT:
2256 			expectedMin = 4u;
2257 			break;
2258 		case VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT:
2259 			expectedMin = 100u;
2260 			break;
2261 		default:
2262 			DE_FATAL("Unexpected type of statistics query");
2263 			break;
2264 	}
2265 
2266 	const deUint32 queryCount = static_cast<deUint32>(m_drawRepeats.size());
2267 
2268 	if (m_parametersGraphic.resetType == RESET_TYPE_NORMAL)
2269 	{
2270 		ResultsVector results(queryCount, 0u);
2271 		VK_CHECK(GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (VK_QUERY_RESULT_WAIT_BIT | m_parametersGraphic.querySizeFlags())));
2272 		if (results[0] < expectedMin)
2273 			return tcu::TestStatus::fail("QueryPoolResults incorrect");
2274 		if (queryCount > 1)
2275 		{
2276 			double pearson = calculatePearsonCorrelation(m_drawRepeats, results);
2277 			if ( fabs( pearson ) < 0.8 )
2278 				return tcu::TestStatus::fail("QueryPoolResults are nonlinear");
2279 		}
2280 
2281 		if (!checkImage())
2282 			return tcu::TestStatus::fail("Result image doesn't match expected image.");
2283 	}
2284 	else if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
2285 	{
2286 		ResultsVectorWithAvailability results(queryCount, pair<deUint64,deUint64>(0u,0u));
2287 		VK_CHECK(GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (VK_QUERY_RESULT_WAIT_BIT | m_parametersGraphic.querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT)));
2288 		if (results[0].first < expectedMin || results[0].second == 0u)
2289 			return tcu::TestStatus::fail("QueryPoolResults incorrect");
2290 
2291 		if (queryCount > 1)
2292 		{
2293 			double pearson = calculatePearsonCorrelation(m_drawRepeats, results);
2294 			if ( fabs( pearson ) < 0.8 )
2295 				return tcu::TestStatus::fail("QueryPoolResults are nonlinear");
2296 		}
2297 
2298 		deUint64 temp = results[0].first;
2299 
2300 		vk.resetQueryPool(device, queryPool, 0, queryCount);
2301 		vk::VkResult res = GetQueryPoolResultsVector(results, vk, device, queryPool, 0u, queryCount, (m_parametersGraphic.querySizeFlags() | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT));
2302 		/* From Vulkan spec:
2303 		 *
2304 		 * If VK_QUERY_RESULT_WAIT_BIT and VK_QUERY_RESULT_PARTIAL_BIT are both not set then no result values are written to pData
2305 		 * for queries that are in the unavailable state at the time of the call, and vkGetQueryPoolResults returns VK_NOT_READY.
2306 		 * However, availability state is still written to pData for those queries if VK_QUERY_RESULT_WITH_AVAILABILITY_BIT is set.
2307 		 */
2308 		if (res != vk::VK_NOT_READY || results[0].first != temp || results[0].second != 0u)
2309 			return tcu::TestStatus::fail("QueryPoolResults incorrect reset");
2310 	}
2311 	else
2312 	{
2313 		// With RESET_TYPE_BEFORE_COPY, we only need to verify the result after the copy include an availability bit set as zero.
2314 		return verifyUnavailable();
2315 	}
2316 	return tcu::TestStatus::pass("Pass");
2317 }
2318 
draw(VkCommandBuffer cmdBuffer)2319 void TessellationShaderTestInstance::draw (VkCommandBuffer cmdBuffer)
2320 {
2321 	const DeviceInterface& vk = m_context.getDeviceInterface();
2322 	vk.cmdDraw(cmdBuffer, static_cast<deUint32>(m_data.size()), 1u, 0u, 0u);
2323 }
2324 
2325 class TessellationShaderSecondrayTestInstance : public TessellationShaderTestInstance
2326 {
2327 public:
2328 							TessellationShaderSecondrayTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
2329 protected:
2330 	virtual tcu::TestStatus	executeTest								(void);
2331 };
2332 
TessellationShaderSecondrayTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)2333 TessellationShaderSecondrayTestInstance::TessellationShaderSecondrayTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
2334 	: TessellationShaderTestInstance	(context, data, parametersGraphic, drawRepeats)
2335 {
2336 }
2337 
executeTest(void)2338 tcu::TestStatus	TessellationShaderSecondrayTestInstance::executeTest (void)
2339 {
2340 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
2341 	const VkDevice							device					= m_context.getDevice();
2342 	const VkQueue							queue					= m_context.getUniversalQueue();
2343 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
2344 
2345 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
2346 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
2347 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
2348 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
2349 
2350 	const VkDeviceSize						vertexBufferOffset		= 0u;
2351 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
2352 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
2353 
2354 	const Unique<VkCommandBuffer>			primaryCmdBuffer		(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
2355 	std::vector<VkCommandBufferSp>			secondaryCmdBuffers(queryCount);
2356 
2357 	for (deUint32 i = 0; i < queryCount; ++i)
2358 		secondaryCmdBuffers[i] = VkCommandBufferSp(new vk::Unique<VkCommandBuffer>(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY)));
2359 
2360 	for (deUint32 i = 0; i < queryCount; ++i)
2361 	{
2362 		beginSecondaryCommandBuffer(vk, secondaryCmdBuffers[i]->get(), m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
2363 		vk.cmdBeginQuery(secondaryCmdBuffers[i]->get(), *queryPool, i, (VkQueryControlFlags)0u);
2364 		vk.cmdBindPipeline(secondaryCmdBuffers[i]->get(), VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2365 		vk.cmdBindVertexBuffers(secondaryCmdBuffers[i]->get(), 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2366 		for (deUint32 j = 0; j<m_drawRepeats[i]; ++j)
2367 			draw(secondaryCmdBuffers[i]->get());
2368 		vk.cmdEndQuery(secondaryCmdBuffers[i]->get(), *queryPool, i);
2369 		endCommandBuffer(vk, secondaryCmdBuffers[i]->get());
2370 	}
2371 
2372 	beginCommandBuffer(vk, *primaryCmdBuffer);
2373 	{
2374 		std::vector<VkClearValue>	renderPassClearValues	(2);
2375 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
2376 
2377 		initialTransitionColor2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2378 									  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
2379 		initialTransitionDepth2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2380 									  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
2381 
2382 		vk.cmdBindVertexBuffers(*primaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2383 		vk.cmdBindPipeline(*primaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2384 
2385 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
2386 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
2387 
2388 		beginRenderPass(vk, *primaryCmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0], VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
2389 		for (deUint32 i = 0; i < queryCount; ++i)
2390 			vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &(secondaryCmdBuffers[i]->get()));
2391 		endRenderPass(vk, *primaryCmdBuffer);
2392 
2393 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
2394 		{
2395 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
2396 			vk.cmdCopyQueryPoolResults(*primaryCmdBuffer, *queryPool, 0, 1u, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
2397 		}
2398 
2399 		transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
2400 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
2401 	}
2402 	endCommandBuffer(vk, *primaryCmdBuffer);
2403 
2404 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
2405 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
2406 
2407 	// Wait for completion
2408 	submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
2409 	return checkResult (*queryPool);
2410 }
2411 
2412 class TessellationShaderSecondrayInheritedTestInstance : public TessellationShaderTestInstance
2413 {
2414 public:
2415 							TessellationShaderSecondrayInheritedTestInstance	(vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats);
2416 protected:
2417 	virtual void			checkExtensions							(deBool hostQueryResetEnabled);
2418 	virtual tcu::TestStatus	executeTest								(void);
2419 };
2420 
TessellationShaderSecondrayInheritedTestInstance(vkt::Context & context,const std::vector<VertexData> & data,const ParametersGraphic & parametersGraphic,const std::vector<deUint64> & drawRepeats)2421 TessellationShaderSecondrayInheritedTestInstance::TessellationShaderSecondrayInheritedTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic, const std::vector<deUint64>& drawRepeats)
2422 	: TessellationShaderTestInstance	(context, data, parametersGraphic, drawRepeats)
2423 {
2424 }
2425 
checkExtensions(deBool hostQueryResetEnabled)2426 void TessellationShaderSecondrayInheritedTestInstance::checkExtensions (deBool hostQueryResetEnabled)
2427 {
2428 	TessellationShaderTestInstance::checkExtensions(hostQueryResetEnabled);
2429 	if (!m_context.getDeviceFeatures().inheritedQueries)
2430 		throw tcu::NotSupportedError("Inherited queries are not supported");
2431 }
2432 
executeTest(void)2433 tcu::TestStatus	TessellationShaderSecondrayInheritedTestInstance::executeTest (void)
2434 {
2435 	const DeviceInterface&					vk						= m_context.getDeviceInterface();
2436 	const VkDevice							device					= m_context.getDevice();
2437 	const VkQueue							queue					= m_context.getUniversalQueue();
2438 	const deUint32							queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
2439 
2440 	const CmdPoolCreateInfo					cmdPoolCreateInfo		(queueFamilyIndex);
2441 	const Move<VkCommandPool>				cmdPool					= createCommandPool(vk, device, &cmdPoolCreateInfo);
2442 	const deUint32							queryCount				= static_cast<deUint32>(m_drawRepeats.size());
2443 	const Unique<VkQueryPool>				queryPool				(makeQueryPool(vk, device, queryCount, m_parametersGraphic.queryStatisticFlags));
2444 
2445 	const VkDeviceSize						vertexBufferOffset		= 0u;
2446 	const de::SharedPtr<Buffer>				vertexBufferSp			= creatAndFillVertexBuffer();
2447 	const VkBuffer							vertexBuffer			= vertexBufferSp->object();
2448 
2449 	const Unique<VkCommandBuffer>			primaryCmdBuffer		(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
2450 	std::vector<VkCommandBufferSp>			secondaryCmdBuffers(queryCount);
2451 
2452 	for (deUint32 i = 0; i < queryCount; ++i)
2453 		secondaryCmdBuffers[i] = VkCommandBufferSp(new vk::Unique<VkCommandBuffer>(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY)));
2454 
2455 	for (deUint32 i = 0; i < queryCount; ++i)
2456 	{
2457 		beginSecondaryCommandBuffer(vk, secondaryCmdBuffers[i]->get(), m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
2458 		vk.cmdBindPipeline(secondaryCmdBuffers[i]->get(), VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2459 		vk.cmdBindVertexBuffers(secondaryCmdBuffers[i]->get(), 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2460 		for (deUint32 j = 0; j<m_drawRepeats[i]; ++j)
2461 			draw(secondaryCmdBuffers[i]->get());
2462 		endCommandBuffer(vk, secondaryCmdBuffers[i]->get());
2463 	}
2464 
2465 	beginCommandBuffer(vk, *primaryCmdBuffer);
2466 	{
2467 		std::vector<VkClearValue>	renderPassClearValues	(2);
2468 		deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
2469 
2470 		initialTransitionColor2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2471 									  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
2472 		initialTransitionDepth2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2473 									  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
2474 
2475 		if (m_parametersGraphic.resetType != RESET_TYPE_HOST)
2476 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
2477 
2478 		for (deUint32 i = 0; i < queryCount; ++i)
2479 		{
2480 			vk.cmdBeginQuery(*primaryCmdBuffer, *queryPool, i, (VkQueryControlFlags)0u);
2481 			beginRenderPass(vk, *primaryCmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT), (deUint32)renderPassClearValues.size(), &renderPassClearValues[0], VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
2482 			vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &(secondaryCmdBuffers[i]->get()));
2483 			endRenderPass(vk, *primaryCmdBuffer);
2484 			vk.cmdEndQuery(*primaryCmdBuffer, *queryPool, i);
2485 		}
2486 
2487 		if (m_parametersGraphic.resetType == RESET_TYPE_BEFORE_COPY)
2488 		{
2489 			vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, queryCount);
2490 			vk.cmdCopyQueryPoolResults(*primaryCmdBuffer, *queryPool, 0, queryCount, m_resetBuffer->object(), 0u, sizeof(ValueAndAvailability), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
2491 		}
2492 
2493 		transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
2494 						  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
2495 	}
2496 	endCommandBuffer(vk, *primaryCmdBuffer);
2497 
2498 	if (m_parametersGraphic.resetType == RESET_TYPE_HOST)
2499 		vk.resetQueryPool(device, *queryPool, 0u, queryCount);
2500 
2501 	// Wait for completion
2502 	submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
2503 	return checkResult (*queryPool);
2504 }
2505 
2506 template<class Instance>
2507 class QueryPoolStatisticsTest : public TestCase
2508 {
2509 public:
QueryPoolStatisticsTest(tcu::TestContext & context,const std::string & name,const std::string & description,const ResetType resetType,deBool query64Bits)2510 	QueryPoolStatisticsTest (tcu::TestContext &context, const std::string& name, const std::string& description, const ResetType resetType, deBool query64Bits)
2511 		: TestCase			(context, name.c_str(), description.c_str())
2512 	{
2513 		const tcu::UVec3	localSize[]		=
2514 		{
2515 			tcu::UVec3	(2u,			2u,	2u),
2516 			tcu::UVec3	(1u,			1u,	1u),
2517 			tcu::UVec3	(WIDTH/(7u*3u),	7u,	3u),
2518 		};
2519 
2520 		const tcu::UVec3	groupSize[]		=
2521 		{
2522 			tcu::UVec3	(2u,			2u,	2u),
2523 			tcu::UVec3	(WIDTH/(7u*3u),	7u,	3u),
2524 			tcu::UVec3	(1u,			1u,	1u),
2525 		};
2526 
2527 		DE_ASSERT(DE_LENGTH_OF_ARRAY(localSize) == DE_LENGTH_OF_ARRAY(groupSize));
2528 
2529 		for(int shaderNdx = 0; shaderNdx < DE_LENGTH_OF_ARRAY(localSize); ++shaderNdx)
2530 		{
2531 			std::ostringstream	shaderName;
2532 			shaderName<< "compute_" << shaderNdx;
2533 			const ComputeInvocationsTestInstance::ParametersCompute	parameters(
2534 				localSize[shaderNdx],
2535 				groupSize[shaderNdx],
2536 				shaderName.str(),
2537 				resetType,
2538 				query64Bits
2539 			);
2540 			m_parameters.push_back(parameters);
2541 		}
2542 	}
2543 
createInstance(vkt::Context & context) const2544 	vkt::TestInstance* createInstance (vkt::Context& context) const
2545 	{
2546 		return new Instance(context, m_parameters);
2547 	}
2548 
initPrograms(SourceCollections & sourceCollections) const2549 	void initPrograms(SourceCollections& sourceCollections) const
2550 	{
2551 		std::ostringstream	source;
2552 		source	<< "layout(binding = 0) writeonly buffer Output {\n"
2553 				<< "	uint values[];\n"
2554 				<< "} sb_out;\n\n"
2555 				<< "void main (void) {\n"
2556 				<< "	uvec3 indexUvec3 = uvec3 (gl_GlobalInvocationID.x,\n"
2557 				<< "	                          gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x,\n"
2558 				<< "	                          gl_GlobalInvocationID.z * gl_NumWorkGroups.x * gl_NumWorkGroups.y * gl_WorkGroupSize.x * gl_WorkGroupSize.y);\n"
2559 				<< "	uint index = indexUvec3.x + indexUvec3.y + indexUvec3.z;\n"
2560 				<< "	sb_out.values[index] += index;\n"
2561 				<< "}\n";
2562 
2563 		for(size_t shaderNdx = 0; shaderNdx < m_parameters.size(); ++shaderNdx)
2564 		{
2565 			std::ostringstream	src;
2566 			src	<< glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
2567 				<< "layout (local_size_x = " << m_parameters[shaderNdx].localSize.x() << ", local_size_y = " << m_parameters[shaderNdx].localSize.y() << ", local_size_z = " << m_parameters[shaderNdx].localSize.z() << ") in;\n"
2568 				<< source.str();
2569 			sourceCollections.glslSources.add(m_parameters[shaderNdx].shaderName) << glu::ComputeSource(src.str());
2570 		}
2571 	}
2572 private:
2573 	std::vector<ComputeInvocationsTestInstance::ParametersCompute>	m_parameters;
2574 };
2575 
2576 template<class Instance>
2577 class QueryPoolGraphicStatisticsTest : public TestCase
2578 {
2579 public:
QueryPoolGraphicStatisticsTest(tcu::TestContext & context,const std::string & name,const std::string & description,const GraphicBasicTestInstance::ParametersGraphic parametersGraphic,const std::vector<deUint64> & drawRepeats)2580 	QueryPoolGraphicStatisticsTest (tcu::TestContext &context, const std::string& name, const std::string& description, const GraphicBasicTestInstance::ParametersGraphic parametersGraphic, const std::vector<deUint64>& drawRepeats)
2581 		: TestCase				(context, name.c_str(), description.c_str())
2582 		, m_parametersGraphic	(parametersGraphic)
2583 		, m_drawRepeats			( drawRepeats )
2584 	{
2585 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4(-1.0f,-1.0f, 1.0f, 1.0f), tcu::RGBA::red().toVec()));
2586 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4(-1.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::red().toVec()));
2587 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f,-1.0f, 1.0f, 1.0f), tcu::RGBA::red().toVec()));
2588 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::red().toVec()));
2589 
2590 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4(-1.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
2591 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
2592 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
2593 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
2594 
2595 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f,-1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
2596 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
2597 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 1.0f,-1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
2598 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 1.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
2599 
2600 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::gray().toVec()));
2601 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::gray().toVec()));
2602 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 1.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::gray().toVec()));
2603 		m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::gray().toVec()));
2604 	}
2605 
createInstance(vkt::Context & context) const2606 	vkt::TestInstance* createInstance (vkt::Context& context) const
2607 	{
2608 		return new Instance(context, m_data, m_parametersGraphic, m_drawRepeats);
2609 	}
2610 
initPrograms(SourceCollections & sourceCollections) const2611 	void initPrograms(SourceCollections& sourceCollections) const
2612 	{
2613 		{ // Vertex Shader
2614 			std::ostringstream	source;
2615 			source	<< glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
2616 					<< "layout(location = 0) in highp vec4 in_position;\n"
2617 					<< "layout(location = 1) in vec4 in_color;\n"
2618 					<< "layout(location = 0) out vec4 out_color;\n"
2619 					<< "void main (void)\n"
2620 					<< "{\n"
2621 					<< "	gl_PointSize = 1.0;\n"
2622 					<< "	gl_Position = in_position;\n"
2623 					<< "	out_color = in_color;\n"
2624 					<< "}\n";
2625 			sourceCollections.glslSources.add("vertex") << glu::VertexSource(source.str());
2626 		}
2627 
2628 		if (m_parametersGraphic.queryStatisticFlags & (VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT|
2629 									VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT))
2630 		{// Tessellation control & evaluation
2631 			std::ostringstream source_tc;
2632 			source_tc	<< glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
2633 						<< "#extension GL_EXT_tessellation_shader : require\n"
2634 						<< "layout(vertices = 4) out;\n"
2635 						<< "layout(location = 0) in vec4 in_color[];\n"
2636 						<< "layout(location = 0) out vec4 out_color[];\n"
2637 						<< "\n"
2638 						<< "void main (void)\n"
2639 						<< "{\n"
2640 						<< "	if( gl_InvocationID == 0 )\n"
2641 						<< "	{\n"
2642 						<< "		gl_TessLevelInner[0] = 4.0f;\n"
2643 						<< "		gl_TessLevelInner[1] = 4.0f;\n"
2644 						<< "		gl_TessLevelOuter[0] = 4.0f;\n"
2645 						<< "		gl_TessLevelOuter[1] = 4.0f;\n"
2646 						<< "		gl_TessLevelOuter[2] = 4.0f;\n"
2647 						<< "		gl_TessLevelOuter[3] = 4.0f;\n"
2648 						<< "	}\n"
2649 						<< "	out_color[gl_InvocationID] = in_color[gl_InvocationID];\n"
2650 						<< "	gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
2651 						<< "}\n";
2652 			sourceCollections.glslSources.add("tessellation_control") << glu::TessellationControlSource(source_tc.str());
2653 
2654 			std::ostringstream source_te;
2655 			source_te	<< glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
2656 						<< "#extension GL_EXT_tessellation_shader : require\n"
2657 						<< "layout( quads, equal_spacing, ccw ) in;\n"
2658 						<< "layout(location = 0) in vec4 in_color[];\n"
2659 						<< "layout(location = 0) out vec4 out_color;\n"
2660 						<< "void main (void)\n"
2661 						<< "{\n"
2662 						<< "	const float u = gl_TessCoord.x;\n"
2663 						<< "	const float v = gl_TessCoord.y;\n"
2664 						<< "	const float w = gl_TessCoord.z;\n"
2665 						<< "	gl_Position = (1 - u) * (1 - v) * gl_in[0].gl_Position +(1 - u) * v * gl_in[1].gl_Position + u * (1 - v) * gl_in[2].gl_Position + u * v * gl_in[3].gl_Position;\n"
2666 						<< "	out_color = in_color[0];\n"
2667 						<< "}\n";
2668 			sourceCollections.glslSources.add("tessellation_evaluation") << glu::TessellationEvaluationSource(source_te.str());
2669 		}
2670 
2671 		if(m_parametersGraphic.queryStatisticFlags & (VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT | VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT |
2672 									VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT | VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT))
2673 		{ // Geometry Shader
2674 			const bool isTopologyPointSize = m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
2675 			std::ostringstream	source;
2676 			source	<< glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
2677 					<< "layout("<<inputTypeToGLString(m_parametersGraphic.primitiveTopology)<<") in;\n"
2678 					<< "layout("<<outputTypeToGLString (m_parametersGraphic.primitiveTopology)<<", max_vertices = 16) out;\n"
2679 					<< "layout(location = 0) in vec4 in_color[];\n"
2680 					<< "layout(location = 0) out vec4 out_color;\n"
2681 					<< "void main (void)\n"
2682 					<< "{\n"
2683 					<< "	out_color = in_color[0];\n"
2684 					<< (isTopologyPointSize ? "${pointSize}" : "" )
2685 					<< "	gl_Position = gl_in[0].gl_Position;\n"
2686 					<< "	EmitVertex();\n"
2687 					<< "	EndPrimitive();\n"
2688 					<< "\n"
2689 					<< "	out_color = in_color[0];\n"
2690 					<< (isTopologyPointSize ? "${pointSize}" : "")
2691 					<< "	gl_Position = vec4(1.0, 1.0, 1.0, 1.0);\n"
2692 					<< "	EmitVertex();\n"
2693 					<< "	out_color = in_color[0];\n"
2694 					<< (isTopologyPointSize ? "${pointSize}" : "")
2695 					<< "	gl_Position = vec4(-1.0, -1.0, 1.0, 1.0);\n"
2696 					<< "	EmitVertex();\n"
2697 					<< "	EndPrimitive();\n"
2698 					<< "\n";
2699 			if (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ||
2700 				m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
2701 			{
2702 				source	<< "\n"
2703 						<< "	out_color = in_color[0];\n"
2704 						<< "	gl_Position = gl_in[0].gl_Position;\n"
2705 						<< "	EmitVertex();\n"
2706 						<< "	out_color = in_color[0];\n"
2707 						<< "	gl_Position = gl_in[1].gl_Position;\n"
2708 						<< "	EmitVertex();\n"
2709 						<< "	out_color = in_color[0];\n"
2710 						<< "	gl_Position = gl_in[2].gl_Position;\n"
2711 						<< "	EmitVertex();\n"
2712 						<< "	out_color = in_color[0];\n"
2713 						<< "	gl_Position = vec4(gl_in[2].gl_Position.x, gl_in[1].gl_Position.y, 1.0, 1.0);\n"
2714 						<< "	EmitVertex();\n"
2715 						<< "	EndPrimitive();\n";
2716 			}
2717 			else
2718 			{
2719 				source	<< "	out_color = in_color[0];\n"
2720 						<< (isTopologyPointSize ? "${pointSize}" : "")
2721 						<< "	gl_Position = vec4(1.0, 1.0, 1.0, 1.0);\n"
2722 						<< "	EmitVertex();\n"
2723 						<< "	out_color = in_color[0];\n"
2724 						<< (isTopologyPointSize ? "${pointSize}" : "")
2725 						<< "	gl_Position = vec4(1.0, -1.0, 1.0, 1.0);\n"
2726 						<< "	EmitVertex();\n"
2727 						<< "	out_color = in_color[0];\n"
2728 						<< (isTopologyPointSize ? "${pointSize}" : "")
2729 						<< "	gl_Position = vec4(-1.0, 1.0, 1.0, 1.0);\n"
2730 						<< "	EmitVertex();\n"
2731 						<< "	out_color = in_color[0];\n"
2732 						<< (isTopologyPointSize ? "${pointSize}" : "")
2733 						<< "	gl_Position = vec4(-1.0, -1.0, 1.0, 1.0);\n"
2734 						<< "	EmitVertex();\n"
2735 						<< "	EndPrimitive();\n";
2736 			}
2737 			source	<< "}\n";
2738 
2739 			if (isTopologyPointSize)
2740 			{
2741 				// Add geometry shader codes with and without gl_PointSize if the primitive topology is VK_PRIMITIVE_TOPOLOGY_POINT_LIST
2742 
2743 				tcu::StringTemplate sourceTemplate(source.str());
2744 
2745 				std::map<std::string, std::string> pointSize;
2746 				std::map<std::string, std::string> noPointSize;
2747 
2748 				pointSize["pointSize"]		= "	gl_PointSize = gl_in[0].gl_PointSize;\n";
2749 				noPointSize["pointSize"]	= "";
2750 
2751 				sourceCollections.glslSources.add("geometry") << glu::GeometrySource(sourceTemplate.specialize(noPointSize));
2752 				sourceCollections.glslSources.add("geometry_point_size") << glu::GeometrySource(sourceTemplate.specialize(pointSize));
2753 			}
2754 			else
2755 			{
2756 				sourceCollections.glslSources.add("geometry") << glu::GeometrySource(source.str());
2757 			}
2758 		}
2759 
2760 		if (!m_parametersGraphic.vertexOnlyPipe)
2761 		{ // Fragment Shader
2762 			std::ostringstream	source;
2763 			source	<< glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
2764 					<< "layout(location = 0) in vec4 in_color;\n"
2765 					<< "layout(location = 0) out vec4 out_color;\n"
2766 					<< "void main()\n"
2767 					<<"{\n"
2768 					<< "	out_color = in_color;\n"
2769 					<< "}\n";
2770 			sourceCollections.glslSources.add("fragment") << glu::FragmentSource(source.str());
2771 		}
2772 	}
2773 private:
2774 	std::vector<GraphicBasicTestInstance::VertexData>	m_data;
2775 	const GraphicBasicTestInstance::ParametersGraphic	m_parametersGraphic;
2776 	std::vector<deUint64>								m_drawRepeats;
2777 };
2778 } //anonymous
2779 
QueryPoolStatisticsTests(tcu::TestContext & testCtx)2780 QueryPoolStatisticsTests::QueryPoolStatisticsTests (tcu::TestContext &testCtx)
2781 	: TestCaseGroup(testCtx, "statistics_query", "Tests for statistics queries")
2782 {
2783 }
2784 
bitPrefix(deBool query64bits)2785 inline std::string bitPrefix(deBool query64bits)
2786 {
2787 	return (query64bits ? "64bits_" : "32bits_");
2788 }
2789 
init(void)2790 void QueryPoolStatisticsTests::init (void)
2791 {
2792 	std::string topology_name [VK_PRIMITIVE_TOPOLOGY_LAST] =
2793 	{
2794 		"point_list",
2795 		"line_list",
2796 		"line_strip",
2797 		"triangle_list",
2798 		"triangle_strip",
2799 		"triangle_fan",
2800 		"line_list_with_adjacency",
2801 		"line_strip_with_adjacency",
2802 		"triangle_list_with_adjacency",
2803 		"triangle_strip_with_adjacency",
2804 		"patch_list"
2805 	};
2806 
2807 	std::vector<deUint64> sixRepeats								= { 1, 3, 5, 8, 15, 24 };
2808 
2809 	de::MovePtr<TestCaseGroup>	computeShaderInvocationsGroup		(new TestCaseGroup(m_testCtx, "compute_shader_invocations",			"Query pipeline statistic compute shader invocations"));
2810 	de::MovePtr<TestCaseGroup>	inputAssemblyVertices				(new TestCaseGroup(m_testCtx, "input_assembly_vertices",			"Query pipeline statistic input assembly vertices"));
2811 	de::MovePtr<TestCaseGroup>	inputAssemblyPrimitives				(new TestCaseGroup(m_testCtx, "input_assembly_primitives",			"Query pipeline statistic input assembly primitives"));
2812 	de::MovePtr<TestCaseGroup>	vertexShaderInvocations				(new TestCaseGroup(m_testCtx, "vertex_shader_invocations",			"Query pipeline statistic vertex shader invocation"));
2813 	de::MovePtr<TestCaseGroup>	fragmentShaderInvocations			(new TestCaseGroup(m_testCtx, "fragment_shader_invocations",		"Query pipeline statistic fragment shader invocation"));
2814 	de::MovePtr<TestCaseGroup>	geometryShaderInvocations			(new TestCaseGroup(m_testCtx, "geometry_shader_invocations",		"Query pipeline statistic geometry shader invocation"));
2815 	de::MovePtr<TestCaseGroup>	geometryShaderPrimitives			(new TestCaseGroup(m_testCtx, "geometry_shader_primitives",			"Query pipeline statistic geometry shader primitives"));
2816 	de::MovePtr<TestCaseGroup>	clippingInvocations					(new TestCaseGroup(m_testCtx, "clipping_invocations",				"Query pipeline statistic clipping invocations"));
2817 	de::MovePtr<TestCaseGroup>	clippingPrimitives					(new TestCaseGroup(m_testCtx, "clipping_primitives",				"Query pipeline statistic clipping primitives"));
2818 	de::MovePtr<TestCaseGroup>	tesControlPatches					(new TestCaseGroup(m_testCtx, "tes_control_patches",				"Query pipeline statistic tessellation control shader patches"));
2819 	de::MovePtr<TestCaseGroup>	tesEvaluationShaderInvocations		(new TestCaseGroup(m_testCtx, "tes_evaluation_shader_invocations",	"Query pipeline statistic tessellation evaluation shader invocations"));
2820 
2821 	de::MovePtr<TestCaseGroup>	vertexOnlyGroup									(new TestCaseGroup(m_testCtx, "vertex_only",						"Use only vertex shader in a graphics pipeline"));
2822 	de::MovePtr<TestCaseGroup>	inputAssemblyVerticesVertexOnly					(new TestCaseGroup(m_testCtx, "input_assembly_vertices",			"Query pipeline statistic input assembly vertices"));
2823 	de::MovePtr<TestCaseGroup>	inputAssemblyPrimitivesVertexOnly				(new TestCaseGroup(m_testCtx, "input_assembly_primitives",			"Query pipeline statistic input assembly primitives"));
2824 	de::MovePtr<TestCaseGroup>	vertexShaderInvocationsVertexOnly				(new TestCaseGroup(m_testCtx, "vertex_shader_invocations",			"Query pipeline statistic vertex shader invocation"));
2825 
2826 	de::MovePtr<TestCaseGroup>	hostQueryResetGroup								(new TestCaseGroup(m_testCtx, "host_query_reset",					"Check host query reset pipeline statistic compute shader invocations"));
2827 	de::MovePtr<TestCaseGroup>	computeShaderInvocationsGroupHostQueryReset		(new TestCaseGroup(m_testCtx, "compute_shader_invocations",			"Query pipeline statistic compute shader invocations"));
2828 	de::MovePtr<TestCaseGroup>	inputAssemblyVerticesHostQueryReset				(new TestCaseGroup(m_testCtx, "input_assembly_vertices",			"Query pipeline statistic input assembly vertices"));
2829 	de::MovePtr<TestCaseGroup>	inputAssemblyPrimitivesHostQueryReset			(new TestCaseGroup(m_testCtx, "input_assembly_primitives",			"Query pipeline statistic input assembly primitives"));
2830 	de::MovePtr<TestCaseGroup>	vertexShaderInvocationsHostQueryReset			(new TestCaseGroup(m_testCtx, "vertex_shader_invocations",			"Query pipeline statistic vertex shader invocation"));
2831 	de::MovePtr<TestCaseGroup>	fragmentShaderInvocationsHostQueryReset			(new TestCaseGroup(m_testCtx, "fragment_shader_invocations",		"Query pipeline statistic fragment shader invocation"));
2832 	de::MovePtr<TestCaseGroup>	geometryShaderInvocationsHostQueryReset			(new TestCaseGroup(m_testCtx, "geometry_shader_invocations",		"Query pipeline statistic geometry shader invocation"));
2833 	de::MovePtr<TestCaseGroup>	geometryShaderPrimitivesHostQueryReset			(new TestCaseGroup(m_testCtx, "geometry_shader_primitives",			"Query pipeline statistic geometry shader primitives"));
2834 	de::MovePtr<TestCaseGroup>	clippingInvocationsHostQueryReset				(new TestCaseGroup(m_testCtx, "clipping_invocations",				"Query pipeline statistic clipping invocations"));
2835 	de::MovePtr<TestCaseGroup>	clippingPrimitivesHostQueryReset				(new TestCaseGroup(m_testCtx, "clipping_primitives",				"Query pipeline statistic clipping primitives"));
2836 	de::MovePtr<TestCaseGroup>	tesControlPatchesHostQueryReset					(new TestCaseGroup(m_testCtx, "tes_control_patches",				"Query pipeline statistic tessellation control shader patches"));
2837 	de::MovePtr<TestCaseGroup>	tesEvaluationShaderInvocationsHostQueryReset	(new TestCaseGroup(m_testCtx, "tes_evaluation_shader_invocations",	"Query pipeline statistic tessellation evaluation shader invocations"));
2838 
2839 	de::MovePtr<TestCaseGroup>	resetBeforeCopyGroup							(new TestCaseGroup(m_testCtx, "reset_before_copy",					"Check pipeline statistic unavailability when resetting before copying"));
2840 	de::MovePtr<TestCaseGroup>	computeShaderInvocationsGroupResetBeforeCopy	(new TestCaseGroup(m_testCtx, "compute_shader_invocations",			"Query pipeline statistic compute shader invocations"));
2841 	de::MovePtr<TestCaseGroup>	inputAssemblyVerticesResetBeforeCopy			(new TestCaseGroup(m_testCtx, "input_assembly_vertices",			"Query pipeline statistic input assembly vertices"));
2842 	de::MovePtr<TestCaseGroup>	inputAssemblyPrimitivesResetBeforeCopy			(new TestCaseGroup(m_testCtx, "input_assembly_primitives",			"Query pipeline statistic input assembly primitives"));
2843 	de::MovePtr<TestCaseGroup>	vertexShaderInvocationsResetBeforeCopy			(new TestCaseGroup(m_testCtx, "vertex_shader_invocations",			"Query pipeline statistic vertex shader invocation"));
2844 	de::MovePtr<TestCaseGroup>	fragmentShaderInvocationsResetBeforeCopy		(new TestCaseGroup(m_testCtx, "fragment_shader_invocations",		"Query pipeline statistic fragment shader invocation"));
2845 	de::MovePtr<TestCaseGroup>	geometryShaderInvocationsResetBeforeCopy		(new TestCaseGroup(m_testCtx, "geometry_shader_invocations",		"Query pipeline statistic geometry shader invocation"));
2846 	de::MovePtr<TestCaseGroup>	geometryShaderPrimitivesResetBeforeCopy			(new TestCaseGroup(m_testCtx, "geometry_shader_primitives",			"Query pipeline statistic geometry shader primitives"));
2847 	de::MovePtr<TestCaseGroup>	clippingInvocationsResetBeforeCopy				(new TestCaseGroup(m_testCtx, "clipping_invocations",				"Query pipeline statistic clipping invocations"));
2848 	de::MovePtr<TestCaseGroup>	clippingPrimitivesResetBeforeCopy				(new TestCaseGroup(m_testCtx, "clipping_primitives",				"Query pipeline statistic clipping primitives"));
2849 	de::MovePtr<TestCaseGroup>	tesControlPatchesResetBeforeCopy				(new TestCaseGroup(m_testCtx, "tes_control_patches",				"Query pipeline statistic tessellation control shader patches"));
2850 	de::MovePtr<TestCaseGroup>	tesEvaluationShaderInvocationsResetBeforeCopy	(new TestCaseGroup(m_testCtx, "tes_evaluation_shader_invocations",	"Query pipeline statistic tessellation evaluation shader invocations"));
2851 
2852 	for (deUint32 i = 0; i < 2; ++i)
2853 	{
2854 		deBool query64Bits = (i == 1);
2855 		std::string prefix = bitPrefix(query64Bits);
2856 
2857 		computeShaderInvocationsGroup->addChild(new QueryPoolStatisticsTest<ComputeInvocationsTestInstance>						(m_testCtx,	prefix + "primary",				"", RESET_TYPE_NORMAL, query64Bits));
2858 		computeShaderInvocationsGroup->addChild(new QueryPoolStatisticsTest<ComputeInvocationsSecondaryTestInstance>			(m_testCtx,	prefix + "secondary",			"", RESET_TYPE_NORMAL, query64Bits));
2859 		computeShaderInvocationsGroup->addChild(new QueryPoolStatisticsTest<ComputeInvocationsSecondaryInheritedTestInstance>	(m_testCtx,	prefix + "secondary_inherited",	"", RESET_TYPE_NORMAL, query64Bits));
2860 
2861 		computeShaderInvocationsGroupHostQueryReset->addChild(new QueryPoolStatisticsTest<ComputeInvocationsTestInstance>					(m_testCtx,	prefix + "primary",				"", RESET_TYPE_HOST, query64Bits));
2862 		computeShaderInvocationsGroupHostQueryReset->addChild(new QueryPoolStatisticsTest<ComputeInvocationsSecondaryTestInstance>			(m_testCtx,	prefix + "secondary",			"", RESET_TYPE_HOST, query64Bits));
2863 		computeShaderInvocationsGroupHostQueryReset->addChild(new QueryPoolStatisticsTest<ComputeInvocationsSecondaryInheritedTestInstance>	(m_testCtx,	prefix + "secondary_inherited",	"", RESET_TYPE_HOST, query64Bits));
2864 
2865 		computeShaderInvocationsGroupResetBeforeCopy->addChild(new QueryPoolStatisticsTest<ComputeInvocationsTestInstance>					(m_testCtx,	prefix + "primary",				"", RESET_TYPE_BEFORE_COPY, query64Bits));
2866 		computeShaderInvocationsGroupResetBeforeCopy->addChild(new QueryPoolStatisticsTest<ComputeInvocationsSecondaryTestInstance>			(m_testCtx,	prefix + "secondary",			"", RESET_TYPE_BEFORE_COPY, query64Bits));
2867 		computeShaderInvocationsGroupResetBeforeCopy->addChild(new QueryPoolStatisticsTest<ComputeInvocationsSecondaryInheritedTestInstance>(m_testCtx,	prefix + "secondary_inherited",	"", RESET_TYPE_BEFORE_COPY, query64Bits));
2868 
2869 		//VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT
2870 		inputAssemblyVertices->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + "primary",				"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2871 		inputAssemblyVertices->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + "secondary",			"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2872 		inputAssemblyVertices->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + "secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2873 
2874 		inputAssemblyVerticesVertexOnly->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>						(m_testCtx,	prefix + "primary",				"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2875 		inputAssemblyVerticesVertexOnly->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>				(m_testCtx,	prefix + "secondary",			"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2876 		inputAssemblyVerticesVertexOnly->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + "secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2877 
2878 		inputAssemblyVerticesHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + "primary",				"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
2879 		inputAssemblyVerticesHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + "secondary",			"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
2880 		inputAssemblyVerticesHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>(m_testCtx,	prefix + "secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
2881 
2882 		inputAssemblyVerticesResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>						(m_testCtx,	prefix + "primary",				"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2883 		inputAssemblyVerticesResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + "secondary",			"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2884 		inputAssemblyVerticesResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + "secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2885 	}
2886 
2887 	//VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT
2888 	{
2889 		de::MovePtr<TestCaseGroup>	primary				(new TestCaseGroup(m_testCtx, "primary",			""));
2890 		de::MovePtr<TestCaseGroup>	secondary			(new TestCaseGroup(m_testCtx, "secondary",			""));
2891 		de::MovePtr<TestCaseGroup>	secondaryInherited	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2892 
2893 		de::MovePtr<TestCaseGroup>	primaryVertexOnly				(new TestCaseGroup(m_testCtx, "primary",			""));
2894 		de::MovePtr<TestCaseGroup>	secondaryVertexOnly				(new TestCaseGroup(m_testCtx, "secondary",			""));
2895 		de::MovePtr<TestCaseGroup>	secondaryInheritedVertexOnly	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2896 
2897 		de::MovePtr<TestCaseGroup>	primaryHostQueryReset				(new TestCaseGroup(m_testCtx, "primary",			""));
2898 		de::MovePtr<TestCaseGroup>	secondaryHostQueryReset				(new TestCaseGroup(m_testCtx, "secondary",			""));
2899 		de::MovePtr<TestCaseGroup>	secondaryInheritedHostQueryReset	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2900 
2901 		de::MovePtr<TestCaseGroup>	primaryResetBeforeCopy				(new TestCaseGroup(m_testCtx, "primary",			""));
2902 		de::MovePtr<TestCaseGroup>	secondaryResetBeforeCopy			(new TestCaseGroup(m_testCtx, "secondary",			""));
2903 		de::MovePtr<TestCaseGroup>	secondaryInheritedResetBeforeCopy	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2904 
2905 		for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2906 		{
2907 			for (deUint32 i = 0; i < 2; ++i)
2908 			{
2909 				deBool query64Bits = (i == 1);
2910 				std::string prefix = bitPrefix(query64Bits);
2911 
2912 				primary->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2913 				secondary->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2914 				secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2915 
2916 				primaryHostQueryReset->addChild				(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
2917 				secondaryHostQueryReset->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
2918 				secondaryInheritedHostQueryReset->addChild	(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
2919 
2920 				primaryVertexOnly->addChild				(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2921 				secondaryVertexOnly->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2922 				secondaryInheritedVertexOnly->addChild	(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2923 
2924 				primaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2925 				secondaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2926 				secondaryInheritedResetBeforeCopy->addChild	(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2927 			}
2928 		}
2929 
2930 		inputAssemblyPrimitives->addChild(primary.release());
2931 		inputAssemblyPrimitives->addChild(secondary.release());
2932 		inputAssemblyPrimitives->addChild(secondaryInherited.release());
2933 
2934 		inputAssemblyPrimitivesVertexOnly->addChild(primaryVertexOnly.release());
2935 		inputAssemblyPrimitivesVertexOnly->addChild(secondaryVertexOnly.release());
2936 		inputAssemblyPrimitivesVertexOnly->addChild(secondaryInheritedVertexOnly.release());
2937 
2938 		inputAssemblyPrimitivesHostQueryReset->addChild(primaryHostQueryReset.release());
2939 		inputAssemblyPrimitivesHostQueryReset->addChild(secondaryHostQueryReset.release());
2940 		inputAssemblyPrimitivesHostQueryReset->addChild(secondaryInheritedHostQueryReset.release());
2941 
2942 		inputAssemblyPrimitivesResetBeforeCopy->addChild(primaryResetBeforeCopy.release());
2943 		inputAssemblyPrimitivesResetBeforeCopy->addChild(secondaryResetBeforeCopy.release());
2944 		inputAssemblyPrimitivesResetBeforeCopy->addChild(secondaryInheritedResetBeforeCopy.release());
2945 	}
2946 
2947 	//VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT
2948 	{
2949 		de::MovePtr<TestCaseGroup>	primary				(new TestCaseGroup(m_testCtx, "primary",			""));
2950 		de::MovePtr<TestCaseGroup>	secondary			(new TestCaseGroup(m_testCtx, "secondary",			""));
2951 		de::MovePtr<TestCaseGroup>	secondaryInherited	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2952 
2953 		de::MovePtr<TestCaseGroup>	primaryVertexOnly				(new TestCaseGroup(m_testCtx, "primary",			""));
2954 		de::MovePtr<TestCaseGroup>	secondaryVertexOnly				(new TestCaseGroup(m_testCtx, "secondary",			""));
2955 		de::MovePtr<TestCaseGroup>	secondaryInheritedVertexOnly	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2956 
2957 		de::MovePtr<TestCaseGroup>	primaryHostQueryReset				(new TestCaseGroup(m_testCtx, "primary",			""));
2958 		de::MovePtr<TestCaseGroup>	secondaryHostQueryReset				(new TestCaseGroup(m_testCtx, "secondary",			""));
2959 		de::MovePtr<TestCaseGroup>	secondaryInheritedHostQueryReset	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2960 
2961 		de::MovePtr<TestCaseGroup>	primaryResetBeforeCopy				(new TestCaseGroup(m_testCtx, "primary",			""));
2962 		de::MovePtr<TestCaseGroup>	secondaryResetBeforeCopy			(new TestCaseGroup(m_testCtx, "secondary",			""));
2963 		de::MovePtr<TestCaseGroup>	secondaryInheritedResetBeforeCopy	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2964 
2965 		for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2966 		{
2967 			for (deUint32 i = 0; i < 2; ++i)
2968 			{
2969 				deBool query64Bits = (i == 1);
2970 				std::string prefix = bitPrefix(query64Bits);
2971 
2972 				primary->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2973 				secondary->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2974 				secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
2975 
2976 				primaryVertexOnly->addChild				(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2977 				secondaryVertexOnly->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2978 				secondaryInheritedVertexOnly->addChild	(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits, DE_TRUE), sixRepeats));
2979 
2980 				primaryHostQueryReset->addChild				(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
2981 				secondaryHostQueryReset->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
2982 				secondaryInheritedHostQueryReset->addChild	(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
2983 
2984 				primaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2985 				secondaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2986 				secondaryInheritedResetBeforeCopy->addChild	(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
2987 			}
2988 		}
2989 
2990 		vertexShaderInvocations->addChild(primary.release());
2991 		vertexShaderInvocations->addChild(secondary.release());
2992 		vertexShaderInvocations->addChild(secondaryInherited.release());
2993 
2994 		vertexShaderInvocationsVertexOnly->addChild(primaryVertexOnly.release());
2995 		vertexShaderInvocationsVertexOnly->addChild(secondaryVertexOnly.release());
2996 		vertexShaderInvocationsVertexOnly->addChild(secondaryInheritedVertexOnly.release());
2997 
2998 		vertexShaderInvocationsHostQueryReset->addChild(primaryHostQueryReset.release());
2999 		vertexShaderInvocationsHostQueryReset->addChild(secondaryHostQueryReset.release());
3000 		vertexShaderInvocationsHostQueryReset->addChild(secondaryInheritedHostQueryReset.release());
3001 
3002 		vertexShaderInvocationsResetBeforeCopy->addChild(primaryResetBeforeCopy.release());
3003 		vertexShaderInvocationsResetBeforeCopy->addChild(secondaryResetBeforeCopy.release());
3004 		vertexShaderInvocationsResetBeforeCopy->addChild(secondaryInheritedResetBeforeCopy.release());
3005 	}
3006 
3007 	//VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT
3008 	{
3009 		de::MovePtr<TestCaseGroup>	primary				(new TestCaseGroup(m_testCtx, "primary",			""));
3010 		de::MovePtr<TestCaseGroup>	secondary			(new TestCaseGroup(m_testCtx, "secondary",			""));
3011 		de::MovePtr<TestCaseGroup>	secondaryInherited	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3012 
3013 		de::MovePtr<TestCaseGroup>	primaryHostQueryReset				(new TestCaseGroup(m_testCtx, "primary",			""));
3014 		de::MovePtr<TestCaseGroup>	secondaryHostQueryReset				(new TestCaseGroup(m_testCtx, "secondary",			""));
3015 		de::MovePtr<TestCaseGroup>	secondaryInheritedHostQueryReset	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3016 
3017 		de::MovePtr<TestCaseGroup>	primaryResetBeforeCopy				(new TestCaseGroup(m_testCtx, "primary",			""));
3018 		de::MovePtr<TestCaseGroup>	secondaryResetBeforeCopy			(new TestCaseGroup(m_testCtx, "secondary",			""));
3019 		de::MovePtr<TestCaseGroup>	secondaryInheritedResetBeforeCopy	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3020 
3021 		for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
3022 		{
3023 			for (deUint32 i = 0; i < 2; ++i)
3024 			{
3025 				deBool query64Bits = (i == 1);
3026 				std::string prefix = bitPrefix(query64Bits);
3027 
3028 				primary->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3029 				secondary->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3030 				secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3031 
3032 				primaryHostQueryReset->addChild				(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3033 				secondaryHostQueryReset->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3034 				secondaryInheritedHostQueryReset->addChild	(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3035 
3036 				primaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>					(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3037 				secondaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3038 				secondaryInheritedResetBeforeCopy->addChild	(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3039 			}
3040 		}
3041 
3042 		fragmentShaderInvocations->addChild(primary.release());
3043 		fragmentShaderInvocations->addChild(secondary.release());
3044 		fragmentShaderInvocations->addChild(secondaryInherited.release());
3045 
3046 		fragmentShaderInvocationsHostQueryReset->addChild(primaryHostQueryReset.release());
3047 		fragmentShaderInvocationsHostQueryReset->addChild(secondaryHostQueryReset.release());
3048 		fragmentShaderInvocationsHostQueryReset->addChild(secondaryInheritedHostQueryReset.release());
3049 
3050 		fragmentShaderInvocationsResetBeforeCopy->addChild(primaryResetBeforeCopy.release());
3051 		fragmentShaderInvocationsResetBeforeCopy->addChild(secondaryResetBeforeCopy.release());
3052 		fragmentShaderInvocationsResetBeforeCopy->addChild(secondaryInheritedResetBeforeCopy.release());
3053 	}
3054 
3055 	//VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT
3056 	{
3057 		de::MovePtr<TestCaseGroup>	primary				(new TestCaseGroup(m_testCtx, "primary",			""));
3058 		de::MovePtr<TestCaseGroup>	secondary			(new TestCaseGroup(m_testCtx, "secondary",			""));
3059 		de::MovePtr<TestCaseGroup>	secondaryInherited	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3060 
3061 		de::MovePtr<TestCaseGroup>	primaryHostQueryReset				(new TestCaseGroup(m_testCtx, "primary",			""));
3062 		de::MovePtr<TestCaseGroup>	secondaryHostQueryReset				(new TestCaseGroup(m_testCtx, "secondary",			""));
3063 		de::MovePtr<TestCaseGroup>	secondaryInheritedHostQueryReset	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3064 
3065 		de::MovePtr<TestCaseGroup>	primaryResetBeforeCopy				(new TestCaseGroup(m_testCtx, "primary",			""));
3066 		de::MovePtr<TestCaseGroup>	secondaryResetBeforeCopy			(new TestCaseGroup(m_testCtx, "secondary",			""));
3067 		de::MovePtr<TestCaseGroup>	secondaryInheritedResetBeforeCopy	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3068 
3069 		for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
3070 		{
3071 			for (deUint32 i = 0; i < 2; ++i)
3072 			{
3073 				deBool query64Bits = (i == 1);
3074 				std::string prefix = bitPrefix(query64Bits);
3075 
3076 				primary->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3077 				secondary->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3078 				secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3079 
3080 				primaryHostQueryReset->addChild				(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3081 				secondaryHostQueryReset->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3082 				secondaryInheritedHostQueryReset->addChild	(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3083 
3084 				primaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3085 				secondaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3086 				secondaryInheritedResetBeforeCopy->addChild	(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3087 			}
3088 		}
3089 
3090 		geometryShaderInvocations->addChild(primary.release());
3091 		geometryShaderInvocations->addChild(secondary.release());
3092 		geometryShaderInvocations->addChild(secondaryInherited.release());
3093 
3094 		geometryShaderInvocationsHostQueryReset->addChild(primaryHostQueryReset.release());
3095 		geometryShaderInvocationsHostQueryReset->addChild(secondaryHostQueryReset.release());
3096 		geometryShaderInvocationsHostQueryReset->addChild(secondaryInheritedHostQueryReset.release());
3097 
3098 		geometryShaderInvocationsResetBeforeCopy->addChild(primaryResetBeforeCopy.release());
3099 		geometryShaderInvocationsResetBeforeCopy->addChild(secondaryResetBeforeCopy.release());
3100 		geometryShaderInvocationsResetBeforeCopy->addChild(secondaryInheritedResetBeforeCopy.release());
3101 	}
3102 
3103 	//VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT
3104 	{
3105 		de::MovePtr<TestCaseGroup>	primary				(new TestCaseGroup(m_testCtx, "primary",			""));
3106 		de::MovePtr<TestCaseGroup>	secondary			(new TestCaseGroup(m_testCtx, "secondary",			""));
3107 		de::MovePtr<TestCaseGroup>	secondaryInherited	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3108 
3109 		de::MovePtr<TestCaseGroup>	primaryHostQueryReset				(new TestCaseGroup(m_testCtx, "primary",			""));
3110 		de::MovePtr<TestCaseGroup>	secondaryHostQueryReset				(new TestCaseGroup(m_testCtx, "secondary",			""));
3111 		de::MovePtr<TestCaseGroup>	secondaryInheritedHostQueryReset	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3112 
3113 		de::MovePtr<TestCaseGroup>	primaryResetBeforeCopy				(new TestCaseGroup(m_testCtx, "primary",			""));
3114 		de::MovePtr<TestCaseGroup>	secondaryResetBeforeCopy			(new TestCaseGroup(m_testCtx, "secondary",			""));
3115 		de::MovePtr<TestCaseGroup>	secondaryInheritedResetBeforeCopy	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3116 
3117 		for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
3118 		{
3119 			for (deUint32 i = 0; i < 2; ++i)
3120 			{
3121 				deBool query64Bits = (i == 1);
3122 				std::string prefix = bitPrefix(query64Bits);
3123 
3124 				primary->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3125 				secondary->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3126 				secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3127 
3128 				primaryHostQueryReset->addChild				(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3129 				secondaryHostQueryReset->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3130 				secondaryInheritedHostQueryReset->addChild	(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3131 
3132 				primaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3133 				secondaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3134 				secondaryInheritedResetBeforeCopy->addChild	(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3135 			}
3136 		}
3137 
3138 		geometryShaderPrimitives->addChild(primary.release());
3139 		geometryShaderPrimitives->addChild(secondary.release());
3140 		geometryShaderPrimitives->addChild(secondaryInherited.release());
3141 
3142 		geometryShaderPrimitivesHostQueryReset->addChild(primaryHostQueryReset.release());
3143 		geometryShaderPrimitivesHostQueryReset->addChild(secondaryHostQueryReset.release());
3144 		geometryShaderPrimitivesHostQueryReset->addChild(secondaryInheritedHostQueryReset.release());
3145 
3146 		geometryShaderPrimitivesResetBeforeCopy->addChild(primaryResetBeforeCopy.release());
3147 		geometryShaderPrimitivesResetBeforeCopy->addChild(secondaryResetBeforeCopy.release());
3148 		geometryShaderPrimitivesResetBeforeCopy->addChild(secondaryInheritedResetBeforeCopy.release());
3149 	}
3150 
3151 	//VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT
3152 	{
3153 		de::MovePtr<TestCaseGroup>	primary				(new TestCaseGroup(m_testCtx, "primary",			""));
3154 		de::MovePtr<TestCaseGroup>	secondary			(new TestCaseGroup(m_testCtx, "secondary",			""));
3155 		de::MovePtr<TestCaseGroup>	secondaryInherited	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3156 
3157 		de::MovePtr<TestCaseGroup>	primaryHostQueryReset				(new TestCaseGroup(m_testCtx, "primary",			""));
3158 		de::MovePtr<TestCaseGroup>	secondaryHostQueryReset				(new TestCaseGroup(m_testCtx, "secondary",			""));
3159 		de::MovePtr<TestCaseGroup>	secondaryInheritedHostQueryReset	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3160 
3161 		de::MovePtr<TestCaseGroup>	primaryResetBeforeCopy				(new TestCaseGroup(m_testCtx, "primary",			""));
3162 		de::MovePtr<TestCaseGroup>	secondaryResetBeforeCopy			(new TestCaseGroup(m_testCtx, "secondary",			""));
3163 		de::MovePtr<TestCaseGroup>	secondaryInheritedResetBeforeCopy	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3164 
3165 		for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
3166 		{
3167 			for (deUint32 i = 0; i < 2; ++i)
3168 			{
3169 				deBool query64Bits = (i == 1);
3170 				std::string prefix = bitPrefix(query64Bits);
3171 
3172 				primary->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3173 				secondary->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3174 				secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3175 
3176 				primaryHostQueryReset->addChild				(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3177 				secondaryHostQueryReset->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3178 				secondaryInheritedHostQueryReset->addChild	(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3179 
3180 				primaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3181 				secondaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3182 				secondaryInheritedResetBeforeCopy->addChild	(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3183 			}
3184 		}
3185 
3186 		clippingInvocations->addChild(primary.release());
3187 		clippingInvocations->addChild(secondary.release());
3188 		clippingInvocations->addChild(secondaryInherited.release());
3189 
3190 		clippingInvocationsHostQueryReset->addChild(primaryHostQueryReset.release());
3191 		clippingInvocationsHostQueryReset->addChild(secondaryHostQueryReset.release());
3192 		clippingInvocationsHostQueryReset->addChild(secondaryInheritedHostQueryReset.release());
3193 
3194 		clippingInvocationsResetBeforeCopy->addChild(primaryResetBeforeCopy.release());
3195 		clippingInvocationsResetBeforeCopy->addChild(secondaryResetBeforeCopy.release());
3196 		clippingInvocationsResetBeforeCopy->addChild(secondaryInheritedResetBeforeCopy.release());
3197 	}
3198 
3199 	//VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT
3200 	{
3201 		de::MovePtr<TestCaseGroup>	primary				(new TestCaseGroup(m_testCtx, "primary",			""));
3202 		de::MovePtr<TestCaseGroup>	secondary			(new TestCaseGroup(m_testCtx, "secondary",			""));
3203 		de::MovePtr<TestCaseGroup>	secondaryInherited	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3204 
3205 		de::MovePtr<TestCaseGroup>	primaryHostQueryReset				(new TestCaseGroup(m_testCtx, "primary",			""));
3206 		de::MovePtr<TestCaseGroup>	secondaryHostQueryReset				(new TestCaseGroup(m_testCtx, "secondary",			""));
3207 		de::MovePtr<TestCaseGroup>	secondaryInheritedHostQueryReset	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3208 
3209 		de::MovePtr<TestCaseGroup>	primaryResetBeforeCopy				(new TestCaseGroup(m_testCtx, "primary",			""));
3210 		de::MovePtr<TestCaseGroup>	secondaryResetBeforeCopy				(new TestCaseGroup(m_testCtx, "secondary",			""));
3211 		de::MovePtr<TestCaseGroup>	secondaryInheritedResetBeforeCopy	(new TestCaseGroup(m_testCtx, "secondary_inherited",""));
3212 
3213 		for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
3214 		{
3215 			for (deUint32 i = 0; i < 2; ++i)
3216 			{
3217 				deBool query64Bits = (i == 1);
3218 				std::string prefix = bitPrefix(query64Bits);
3219 
3220 				primary->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3221 				secondary->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3222 				secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3223 
3224 				primaryHostQueryReset->addChild				(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3225 				secondaryHostQueryReset->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3226 				secondaryInheritedHostQueryReset->addChild	(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_HOST, query64Bits), sixRepeats));
3227 
3228 				primaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>						(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3229 				secondaryResetBeforeCopy->addChild			(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>			(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3230 				secondaryInheritedResetBeforeCopy->addChild	(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>	(m_testCtx,	prefix + topology_name[topologyNdx],	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3231 			}
3232 		}
3233 
3234 		clippingPrimitives->addChild(primary.release());
3235 		clippingPrimitives->addChild(secondary.release());
3236 		clippingPrimitives->addChild(secondaryInherited.release());
3237 
3238 		clippingPrimitivesHostQueryReset->addChild(primaryHostQueryReset.release());
3239 		clippingPrimitivesHostQueryReset->addChild(secondaryHostQueryReset.release());
3240 		clippingPrimitivesHostQueryReset->addChild(secondaryInheritedHostQueryReset.release());
3241 
3242 		clippingPrimitivesResetBeforeCopy->addChild(primaryResetBeforeCopy.release());
3243 		clippingPrimitivesResetBeforeCopy->addChild(secondaryResetBeforeCopy.release());
3244 		clippingPrimitivesResetBeforeCopy->addChild(secondaryInheritedResetBeforeCopy.release());
3245 	}
3246 
3247 	//VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT
3248 	for (deUint32 i = 0; i < 2; ++i)
3249 	{
3250 		deBool query64Bits = (i == 1);
3251 		std::string prefix = bitPrefix(query64Bits);
3252 
3253 		tesControlPatches->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderTestInstance>					(m_testCtx,	prefix + "tes_control_patches",						"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3254 		tesControlPatches->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayTestInstance>			(m_testCtx,	prefix + "tes_control_patches_secondary",			"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3255 		tesControlPatches->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayInheritedTestInstance>(m_testCtx,	prefix + "tes_control_patches_secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3256 
3257 		tesControlPatchesHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderTestInstance>					(m_testCtx,	prefix + "tes_control_patches",						"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
3258 		tesControlPatchesHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayTestInstance>			(m_testCtx,	prefix + "tes_control_patches_secondary",			"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
3259 		tesControlPatchesHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayInheritedTestInstance>	(m_testCtx,	prefix + "tes_control_patches_secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
3260 
3261 		tesControlPatchesResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderTestInstance>					(m_testCtx,	prefix + "tes_control_patches",						"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3262 		tesControlPatchesResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayTestInstance>			(m_testCtx,	prefix + "tes_control_patches_secondary",			"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3263 		tesControlPatchesResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayInheritedTestInstance>	(m_testCtx,	prefix + "tes_control_patches_secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3264 
3265 		//VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT
3266 		tesEvaluationShaderInvocations->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderTestInstance>					 (m_testCtx,	prefix + "tes_evaluation_shader_invocations",						"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3267 		tesEvaluationShaderInvocations->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayTestInstance>		 (m_testCtx,	prefix + "tes_evaluation_shader_invocations_secondary",				"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3268 		tesEvaluationShaderInvocations->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayInheritedTestInstance>(m_testCtx,	prefix + "tes_evaluation_shader_invocations_secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_NORMAL, query64Bits), sixRepeats));
3269 
3270 		tesEvaluationShaderInvocationsHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderTestInstance>					(m_testCtx,	prefix + "tes_evaluation_shader_invocations",						"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
3271 		tesEvaluationShaderInvocationsHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayTestInstance>			(m_testCtx,	prefix + "tes_evaluation_shader_invocations_secondary",				"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
3272 		tesEvaluationShaderInvocationsHostQueryReset->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayInheritedTestInstance>	(m_testCtx,	prefix + "tes_evaluation_shader_invocations_secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_HOST, query64Bits), sixRepeats));
3273 
3274 		tesEvaluationShaderInvocationsResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderTestInstance>					(m_testCtx,	prefix + "tes_evaluation_shader_invocations",						"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3275 		tesEvaluationShaderInvocationsResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayTestInstance>			(m_testCtx,	prefix + "tes_evaluation_shader_invocations_secondary",				"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3276 		tesEvaluationShaderInvocationsResetBeforeCopy->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayInheritedTestInstance>(m_testCtx,	prefix + "tes_evaluation_shader_invocations_secondary_inherited",	"",	GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, RESET_TYPE_BEFORE_COPY, query64Bits), sixRepeats));
3277 	}
3278 
3279 	addChild(computeShaderInvocationsGroup.release());
3280 	addChild(inputAssemblyVertices.release());
3281 	addChild(inputAssemblyPrimitives.release());
3282 	addChild(vertexShaderInvocations.release());
3283 	addChild(fragmentShaderInvocations.release());
3284 	addChild(geometryShaderInvocations.release());
3285 	addChild(geometryShaderPrimitives.release());
3286 	addChild(clippingInvocations.release());
3287 	addChild(clippingPrimitives.release());
3288 	addChild(tesControlPatches.release());
3289 	addChild(tesEvaluationShaderInvocations.release());
3290 
3291 	vertexOnlyGroup->addChild(inputAssemblyVerticesVertexOnly.release());
3292 	vertexOnlyGroup->addChild(inputAssemblyPrimitivesVertexOnly.release());
3293 	vertexOnlyGroup->addChild(vertexShaderInvocationsVertexOnly.release());
3294 	addChild(vertexOnlyGroup.release());
3295 
3296 	hostQueryResetGroup->addChild(computeShaderInvocationsGroupHostQueryReset.release());
3297 	hostQueryResetGroup->addChild(inputAssemblyVerticesHostQueryReset.release());
3298 	hostQueryResetGroup->addChild(inputAssemblyPrimitivesHostQueryReset.release());
3299 	hostQueryResetGroup->addChild(vertexShaderInvocationsHostQueryReset.release());
3300 	hostQueryResetGroup->addChild(fragmentShaderInvocationsHostQueryReset.release());
3301 	hostQueryResetGroup->addChild(geometryShaderInvocationsHostQueryReset.release());
3302 	hostQueryResetGroup->addChild(geometryShaderPrimitivesHostQueryReset.release());
3303 	hostQueryResetGroup->addChild(clippingInvocationsHostQueryReset.release());
3304 	hostQueryResetGroup->addChild(clippingPrimitivesHostQueryReset.release());
3305 	hostQueryResetGroup->addChild(tesControlPatchesHostQueryReset.release());
3306 	hostQueryResetGroup->addChild(tesEvaluationShaderInvocationsHostQueryReset.release());
3307 	addChild(hostQueryResetGroup.release());
3308 
3309 	resetBeforeCopyGroup->addChild(computeShaderInvocationsGroupResetBeforeCopy.release());
3310 	resetBeforeCopyGroup->addChild(inputAssemblyVerticesResetBeforeCopy.release());
3311 	resetBeforeCopyGroup->addChild(inputAssemblyPrimitivesResetBeforeCopy.release());
3312 	resetBeforeCopyGroup->addChild(vertexShaderInvocationsResetBeforeCopy.release());
3313 	resetBeforeCopyGroup->addChild(fragmentShaderInvocationsResetBeforeCopy.release());
3314 	resetBeforeCopyGroup->addChild(geometryShaderInvocationsResetBeforeCopy.release());
3315 	resetBeforeCopyGroup->addChild(geometryShaderPrimitivesResetBeforeCopy.release());
3316 	resetBeforeCopyGroup->addChild(clippingInvocationsResetBeforeCopy.release());
3317 	resetBeforeCopyGroup->addChild(clippingPrimitivesResetBeforeCopy.release());
3318 	resetBeforeCopyGroup->addChild(tesControlPatchesResetBeforeCopy.release());
3319 	resetBeforeCopyGroup->addChild(tesEvaluationShaderInvocationsResetBeforeCopy.release());
3320 	addChild(resetBeforeCopyGroup.release());
3321 }
3322 
3323 } //QueryPool
3324 } //vkt
3325