• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2014 The Android Open Source Project
6  * Copyright (c) 2016 The Khronos Group Inc.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Tessellation Miscellaneous Draw Tests
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vktTessellationMiscDrawTests.hpp"
26 #include "vktTestCaseUtil.hpp"
27 #include "vktTessellationUtil.hpp"
28 
29 #include "tcuTestLog.hpp"
30 #include "tcuImageIO.hpp"
31 #include "tcuTexture.hpp"
32 #include "tcuImageCompare.hpp"
33 
34 #include "vkDefs.hpp"
35 #include "vkBarrierUtil.hpp"
36 #include "vkQueryUtil.hpp"
37 #include "vkBuilderUtil.hpp"
38 #include "vkImageUtil.hpp"
39 #include "vkTypeUtil.hpp"
40 #include "vkStrUtil.hpp"
41 #include "vkCmdUtil.hpp"
42 #include "vkObjUtil.hpp"
43 
44 #include "deUniquePtr.hpp"
45 #include "deStringUtil.hpp"
46 
47 #include <string>
48 #include <vector>
49 
50 namespace vkt
51 {
52 namespace tessellation
53 {
54 
55 using namespace vk;
56 
57 namespace
58 {
59 
60 struct CaseDefinition
61 {
62 	TessPrimitiveType	primitiveType;
63 	SpacingMode			spacingMode;
64 	std::string			referenceImagePathPrefix;	//!< without case suffix and extension (e.g. "_1.png")
65 };
66 
makeCaseDefinition(const TessPrimitiveType primitiveType,const SpacingMode spacingMode,const std::string & referenceImagePathPrefix)67 inline CaseDefinition makeCaseDefinition (const TessPrimitiveType	primitiveType,
68 										  const SpacingMode			spacingMode,
69 										  const std::string&		referenceImagePathPrefix)
70 {
71 	CaseDefinition caseDef;
72 	caseDef.primitiveType = primitiveType;
73 	caseDef.spacingMode = spacingMode;
74 	caseDef.referenceImagePathPrefix = referenceImagePathPrefix;
75 	return caseDef;
76 }
77 
genTessLevelCases(const SpacingMode spacingMode)78 std::vector<TessLevels> genTessLevelCases (const SpacingMode spacingMode)
79 {
80 	static const TessLevels tessLevelCases[] =
81 	{
82 		{ { 9.0f,	9.0f	},	{ 9.0f,		9.0f,	9.0f,	9.0f	} },
83 		{ { 8.0f,	11.0f	},	{ 13.0f,	15.0f,	18.0f,	21.0f	} },
84 		{ { 17.0f,	14.0f	},	{ 3.0f,		6.0f,	9.0f,	12.0f	} },
85 	};
86 
87 	std::vector<TessLevels> resultTessLevels(DE_LENGTH_OF_ARRAY(tessLevelCases));
88 
89 	for (int tessLevelCaseNdx = 0; tessLevelCaseNdx < DE_LENGTH_OF_ARRAY(tessLevelCases); ++tessLevelCaseNdx)
90 	{
91 		TessLevels& tessLevels = resultTessLevels[tessLevelCaseNdx];
92 
93 		for (int i = 0; i < 2; ++i)
94 			tessLevels.inner[i] = static_cast<float>(getClampedRoundedTessLevel(spacingMode, tessLevelCases[tessLevelCaseNdx].inner[i]));
95 
96 		for (int i = 0; i < 4; ++i)
97 			tessLevels.outer[i] = static_cast<float>(getClampedRoundedTessLevel(spacingMode, tessLevelCases[tessLevelCaseNdx].outer[i]));
98 	}
99 
100 	return resultTessLevels;
101 }
102 
genVertexPositions(const TessPrimitiveType primitiveType)103 std::vector<tcu::Vec2> genVertexPositions (const TessPrimitiveType primitiveType)
104 {
105 	std::vector<tcu::Vec2> positions;
106 	positions.reserve(4);
107 
108 	if (primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
109 	{
110 		positions.push_back(tcu::Vec2( 0.8f,    0.6f));
111 		positions.push_back(tcu::Vec2( 0.0f, -0.786f));
112 		positions.push_back(tcu::Vec2(-0.8f,    0.6f));
113 	}
114 	else if (primitiveType == TESSPRIMITIVETYPE_QUADS || primitiveType == TESSPRIMITIVETYPE_ISOLINES)
115 	{
116 		positions.push_back(tcu::Vec2(-0.8f, -0.8f));
117 		positions.push_back(tcu::Vec2( 0.8f, -0.8f));
118 		positions.push_back(tcu::Vec2(-0.8f,  0.8f));
119 		positions.push_back(tcu::Vec2( 0.8f,  0.8f));
120 	}
121 	else
122 		DE_ASSERT(false);
123 
124 	return positions;
125 }
126 
127 //! Common test function used by all test cases.
runTest(Context & context,const CaseDefinition caseDef)128 tcu::TestStatus runTest (Context& context, const CaseDefinition caseDef)
129 {
130 	requireFeatures(context.getInstanceInterface(), context.getPhysicalDevice(), FEATURE_TESSELLATION_SHADER);
131 
132 	const DeviceInterface&	vk					= context.getDeviceInterface();
133 	const VkDevice			device				= context.getDevice();
134 	const VkQueue			queue				= context.getUniversalQueue();
135 	const deUint32			queueFamilyIndex	= context.getUniversalQueueFamilyIndex();
136 	Allocator&				allocator			= context.getDefaultAllocator();
137 
138 	const std::vector<TessLevels> tessLevelCases = genTessLevelCases(caseDef.spacingMode);
139 	const std::vector<tcu::Vec2>  vertexData	 = genVertexPositions(caseDef.primitiveType);
140 	const deUint32				  inPatchSize	 = (caseDef.primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? 3 : 4);
141 
142 	// Vertex input: positions
143 
144 	const VkFormat	   vertexFormat		   = VK_FORMAT_R32G32_SFLOAT;
145 	const deUint32	   vertexStride		   = tcu::getPixelSize(mapVkFormat(vertexFormat));
146 	const VkDeviceSize vertexDataSizeBytes = sizeInBytes(vertexData);
147 
148 	const Buffer vertexBuffer(vk, device, allocator,
149 		makeBufferCreateInfo(vertexDataSizeBytes, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT), MemoryRequirement::HostVisible);
150 
151 	DE_ASSERT(inPatchSize == vertexData.size());
152 	DE_ASSERT(sizeof(vertexData[0]) == vertexStride);
153 
154 	{
155 		const Allocation& alloc = vertexBuffer.getAllocation();
156 
157 		deMemcpy(alloc.getHostPtr(), &vertexData[0], static_cast<std::size_t>(vertexDataSizeBytes));
158 		flushAlloc(vk, device, alloc);
159 		// No barrier needed, flushed memory is automatically visible
160 	}
161 
162 	// Color attachment
163 
164 	const tcu::IVec2			  renderSize				 = tcu::IVec2(256, 256);
165 	const VkFormat				  colorFormat				 = VK_FORMAT_R8G8B8A8_UNORM;
166 	const VkImageSubresourceRange colorImageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
167 	const Image					  colorAttachmentImage		 (vk, device, allocator,
168 															 makeImageCreateInfo(renderSize, colorFormat, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 1u),
169 															 MemoryRequirement::Any);
170 
171 	// Color output buffer: image will be copied here for verification
172 
173 	const VkDeviceSize colorBufferSizeBytes = renderSize.x()*renderSize.y() * tcu::getPixelSize(mapVkFormat(colorFormat));
174 	const Buffer	   colorBuffer			(vk, device, allocator, makeBufferCreateInfo(colorBufferSizeBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT), MemoryRequirement::HostVisible);
175 
176 	// Input buffer: tessellation levels. Data is filled in later.
177 
178 	const Buffer tessLevelsBuffer(vk, device, allocator,
179 		makeBufferCreateInfo(sizeof(TessLevels), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT), MemoryRequirement::HostVisible);
180 
181 	// Descriptors
182 
183 	const Unique<VkDescriptorSetLayout> descriptorSetLayout(DescriptorSetLayoutBuilder()
184 		.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)
185 		.build(vk, device));
186 
187 	const Unique<VkDescriptorPool> descriptorPool(DescriptorPoolBuilder()
188 		.addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
189 		.build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u));
190 
191 	const Unique<VkDescriptorSet> descriptorSet(makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout));
192 
193 	const VkDescriptorBufferInfo tessLevelsBufferInfo = makeDescriptorBufferInfo(tessLevelsBuffer.get(), 0ull, sizeof(TessLevels));
194 
195 	DescriptorSetUpdateBuilder()
196 		.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &tessLevelsBufferInfo)
197 		.update(vk, device);
198 
199 	// Pipeline
200 
201 	const Unique<VkImageView>		colorAttachmentView	(makeImageView(vk, device, *colorAttachmentImage, VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorImageSubresourceRange));
202 	const Unique<VkRenderPass>		renderPass			(makeRenderPass(vk, device, colorFormat));
203 	const Unique<VkFramebuffer>		framebuffer			(makeFramebuffer(vk, device, *renderPass, *colorAttachmentView, renderSize.x(), renderSize.y()));
204 	const Unique<VkPipelineLayout>	pipelineLayout		(makePipelineLayout(vk, device, *descriptorSetLayout));
205 	const Unique<VkCommandPool>		cmdPool				(makeCommandPool(vk, device, queueFamilyIndex));
206 	const Unique<VkCommandBuffer>	cmdBuffer			(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
207 
208 	const Unique<VkPipeline> pipeline(GraphicsPipelineBuilder()
209 		.setRenderSize				  (renderSize)
210 		.setVertexInputSingleAttribute(vertexFormat, vertexStride)
211 		.setPatchControlPoints		  (inPatchSize)
212 		.setShader					  (vk, device, VK_SHADER_STAGE_VERTEX_BIT,					context.getBinaryCollection().get("vert"), DE_NULL)
213 		.setShader					  (vk, device, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,	context.getBinaryCollection().get("tesc"), DE_NULL)
214 		.setShader					  (vk, device, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, context.getBinaryCollection().get("tese"), DE_NULL)
215 		.setShader					  (vk, device, VK_SHADER_STAGE_FRAGMENT_BIT,				context.getBinaryCollection().get("frag"), DE_NULL)
216 		.build						  (vk, device, *pipelineLayout, *renderPass));
217 
218 	// Draw commands
219 
220 	deUint32 numPassedCases = 0;
221 
222 	for (deUint32 tessLevelCaseNdx = 0; tessLevelCaseNdx < tessLevelCases.size(); ++tessLevelCaseNdx)
223 	{
224 		context.getTestContext().getLog()
225 			<< tcu::TestLog::Message
226 			<< "Tessellation levels: " << getTessellationLevelsString(tessLevelCases[tessLevelCaseNdx], caseDef.primitiveType)
227 			<< tcu::TestLog::EndMessage;
228 
229 		// Upload tessellation levels data to the input buffer
230 		{
231 			const Allocation& alloc				= tessLevelsBuffer.getAllocation();
232 			TessLevels* const bufferTessLevels	= static_cast<TessLevels*>(alloc.getHostPtr());
233 
234 			*bufferTessLevels = tessLevelCases[tessLevelCaseNdx];
235 			flushAlloc(vk, device, alloc);
236 		}
237 
238 		// Reset the command buffer and begin recording.
239 		beginCommandBuffer(vk, *cmdBuffer);
240 
241 		// Change color attachment image layout
242 		{
243 			// State is slightly different on the first iteration.
244 			const VkImageLayout currentLayout = (tessLevelCaseNdx == 0 ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
245 			const VkAccessFlags srcFlags	  = (tessLevelCaseNdx == 0 ? (VkAccessFlags)0 : (VkAccessFlags)VK_ACCESS_TRANSFER_READ_BIT);
246 
247 			const VkImageMemoryBarrier colorAttachmentLayoutBarrier = makeImageMemoryBarrier(
248 				srcFlags, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
249 				currentLayout, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
250 				*colorAttachmentImage, colorImageSubresourceRange);
251 
252 			vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0u,
253 				0u, DE_NULL, 0u, DE_NULL, 1u, &colorAttachmentLayoutBarrier);
254 		}
255 
256 		// Begin render pass
257 		{
258 			const VkRect2D	renderArea	= makeRect2D(renderSize);
259 			const tcu::Vec4	clearColor	(0.0f, 0.0f, 0.0f, 1.0f);
260 
261 			beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, renderArea, clearColor);
262 		}
263 
264 		vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
265 		vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL);
266 		{
267 			const VkDeviceSize vertexBufferOffset = 0ull;
268 			vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &vertexBuffer.get(), &vertexBufferOffset);
269 		}
270 
271 		// Process enough vertices to make a patch.
272 		vk.cmdDraw(*cmdBuffer, inPatchSize, 1u, 0u, 0u);
273 		endRenderPass(vk, *cmdBuffer);
274 
275 		// Copy render result to a host-visible buffer
276 		copyImageToBuffer(vk, *cmdBuffer, *colorAttachmentImage, *colorBuffer, renderSize);
277 
278 		endCommandBuffer(vk, *cmdBuffer);
279 		submitCommandsAndWait(vk, device, queue, *cmdBuffer);
280 
281 		{
282 			const Allocation&	colorBufferAlloc	= colorBuffer.getAllocation();
283 
284 			invalidateAlloc(vk, device, colorBufferAlloc);
285 
286 			// Verify case result
287 			const tcu::ConstPixelBufferAccess resultImageAccess(mapVkFormat(colorFormat), renderSize.x(), renderSize.y(), 1, colorBufferAlloc.getHostPtr());
288 
289 			// Load reference image
290 			const std::string	referenceImagePath	= caseDef.referenceImagePathPrefix + "_" + de::toString(tessLevelCaseNdx) + ".png";
291 
292 			tcu::TextureLevel	referenceImage;
293 			tcu::ImageIO::loadPNG(referenceImage, context.getTestContext().getArchive(), referenceImagePath.c_str());
294 
295 			if (tcu::fuzzyCompare(context.getTestContext().getLog(), "ImageComparison", "Image Comparison",
296 								  referenceImage.getAccess(), resultImageAccess, 0.002f, tcu::COMPARE_LOG_RESULT))
297 				++numPassedCases;
298 		}
299 	} // tessLevelCaseNdx
300 
301 	return (numPassedCases == tessLevelCases.size() ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Failure"));
302 }
303 
getTessLevelsSSBODeclaration(void)304 inline const char* getTessLevelsSSBODeclaration (void)
305 {
306 	return	"layout(set = 0, binding = 0, std430) readonly restrict buffer TessLevels {\n"
307 			"    float inner0;\n"
308 			"    float inner1;\n"
309 			"    float outer0;\n"
310 			"    float outer1;\n"
311 			"    float outer2;\n"
312 			"    float outer3;\n"
313 			"} sb_levels;\n";
314 }
315 
316 //! Add vertex, fragment, and tessellation control shaders.
initCommonPrograms(vk::SourceCollections & programCollection,const CaseDefinition caseDef)317 void initCommonPrograms (vk::SourceCollections& programCollection, const CaseDefinition caseDef)
318 {
319 	DE_ASSERT(!programCollection.glslSources.contains("vert"));
320 	DE_ASSERT(!programCollection.glslSources.contains("tesc"));
321 	DE_ASSERT(!programCollection.glslSources.contains("frag"));
322 
323 	// Vertex shader
324 	{
325 		std::ostringstream src;
326 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES) << "\n"
327 			<< "\n"
328 			<< "layout(location = 0) in  highp vec2 in_v_position;\n"
329 			<< "layout(location = 0) out highp vec2 in_tc_position;\n"
330 			<< "\n"
331 			<< "void main (void)\n"
332 			<< "{\n"
333 			<< "    in_tc_position = in_v_position;\n"
334 			<< "}\n";
335 
336 		programCollection.glslSources.add("vert") << glu::VertexSource(src.str());
337 	}
338 
339 	// Tessellation control shader
340 	{
341 		const int numVertices = (caseDef.primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? 3 : 4);
342 
343 		std::ostringstream src;
344 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES) << "\n"
345 			<< "#extension GL_EXT_tessellation_shader : require\n"
346 			<< "\n"
347 			<< "layout(vertices = " << numVertices << ") out;\n"
348 			<< "\n"
349 			<< getTessLevelsSSBODeclaration()
350 			<< "\n"
351 			<< "layout(location = 0) in  highp vec2 in_tc_position[];\n"
352 			<< "layout(location = 0) out highp vec2 in_te_position[];\n"
353 			<< "\n"
354 			<< "void main (void)\n"
355 			<< "{\n"
356 			<< "    in_te_position[gl_InvocationID] = in_tc_position[gl_InvocationID];\n"
357 			<< "\n"
358 			<< "    gl_TessLevelInner[0] = sb_levels.inner0;\n"
359 			<< "    gl_TessLevelInner[1] = sb_levels.inner1;\n"
360 			<< "\n"
361 			<< "    gl_TessLevelOuter[0] = sb_levels.outer0;\n"
362 			<< "    gl_TessLevelOuter[1] = sb_levels.outer1;\n"
363 			<< "    gl_TessLevelOuter[2] = sb_levels.outer2;\n"
364 			<< "    gl_TessLevelOuter[3] = sb_levels.outer3;\n"
365 			<< "}\n";
366 
367 		programCollection.glslSources.add("tesc") << glu::TessellationControlSource(src.str());
368 	}
369 
370 	// Fragment shader
371 	{
372 		std::ostringstream src;
373 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES) << "\n"
374 			<< "\n"
375 			<< "layout(location = 0) in  highp   vec4 in_f_color;\n"
376 			<< "layout(location = 0) out mediump vec4 o_color;\n"
377 			<< "\n"
378 			<< "void main (void)\n"
379 			<< "{\n"
380 			<< "    o_color = in_f_color;\n"
381 			<< "}\n";
382 
383 		programCollection.glslSources.add("frag") << glu::FragmentSource(src.str());
384 	}
385 }
386 
initProgramsFillCoverCase(vk::SourceCollections & programCollection,const CaseDefinition caseDef)387 void initProgramsFillCoverCase (vk::SourceCollections& programCollection, const CaseDefinition caseDef)
388 {
389 	DE_ASSERT(caseDef.primitiveType == TESSPRIMITIVETYPE_TRIANGLES || caseDef.primitiveType == TESSPRIMITIVETYPE_QUADS);
390 
391 	initCommonPrograms(programCollection, caseDef);
392 
393 	// Tessellation evaluation shader
394 	{
395 		std::ostringstream src;
396 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES) << "\n"
397 			<< "#extension GL_EXT_tessellation_shader : require\n"
398 			<< "\n"
399 			<< "layout(" << getTessPrimitiveTypeShaderName(caseDef.primitiveType) << ", "
400 						 << getSpacingModeShaderName(caseDef.spacingMode) << ") in;\n"
401 			<< "\n"
402 			<< "layout(location = 0) in  highp vec2 in_te_position[];\n"
403 			<< "layout(location = 0) out highp vec4 in_f_color;\n"
404 			<< "\n"
405 			<< "void main (void)\n"
406 			<< "{\n"
407 			<<	(caseDef.primitiveType == TESSPRIMITIVETYPE_TRIANGLES ?
408 					"    highp float d = 3.0 * min(gl_TessCoord.x, min(gl_TessCoord.y, gl_TessCoord.z));\n"
409 					"    highp vec2 corner0 = in_te_position[0];\n"
410 					"    highp vec2 corner1 = in_te_position[1];\n"
411 					"    highp vec2 corner2 = in_te_position[2];\n"
412 					"    highp vec2 pos =  corner0*gl_TessCoord.x + corner1*gl_TessCoord.y + corner2*gl_TessCoord.z;\n"
413 					"    highp vec2 fromCenter = pos - (corner0 + corner1 + corner2) / 3.0;\n"
414 					"    highp float f = (1.0 - length(fromCenter)) * (1.5 - d);\n"
415 					"    pos += 0.75 * f * fromCenter / (length(fromCenter) + 0.3);\n"
416 					"    gl_Position = vec4(pos, 0.0, 1.0);\n"
417 				: caseDef.primitiveType == TESSPRIMITIVETYPE_QUADS ?
418 					"    highp vec2 corner0 = in_te_position[0];\n"
419 					"    highp vec2 corner1 = in_te_position[1];\n"
420 					"    highp vec2 corner2 = in_te_position[2];\n"
421 					"    highp vec2 corner3 = in_te_position[3];\n"
422 					"    highp vec2 pos = (1.0-gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner0\n"
423 					"                   + (    gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner1\n"
424 					"                   + (1.0-gl_TessCoord.x)*(    gl_TessCoord.y)*corner2\n"
425 					"                   + (    gl_TessCoord.x)*(    gl_TessCoord.y)*corner3;\n"
426 					"    highp float d = 2.0 * min(abs(gl_TessCoord.x-0.5), abs(gl_TessCoord.y-0.5));\n"
427 					"    highp vec2 fromCenter = pos - (corner0 + corner1 + corner2 + corner3) / 4.0;\n"
428 					"    highp float f = (1.0 - length(fromCenter)) * sqrt(1.7 - d);\n"
429 					"    pos += 0.75 * f * fromCenter / (length(fromCenter) + 0.3);\n"
430 					"    gl_Position = vec4(pos, 0.0, 1.0);\n"
431 				: "")
432 			<< "    in_f_color = vec4(1.0);\n"
433 			<< "}\n";
434 
435 		programCollection.glslSources.add("tese") << glu::TessellationEvaluationSource(src.str());
436 	}
437 }
438 
initProgramsFillNonOverlapCase(vk::SourceCollections & programCollection,const CaseDefinition caseDef)439 void initProgramsFillNonOverlapCase (vk::SourceCollections& programCollection, const CaseDefinition caseDef)
440 {
441 	DE_ASSERT(caseDef.primitiveType == TESSPRIMITIVETYPE_TRIANGLES || caseDef.primitiveType == TESSPRIMITIVETYPE_QUADS);
442 
443 	initCommonPrograms(programCollection, caseDef);
444 
445 	// Tessellation evaluation shader
446 	{
447 		std::ostringstream src;
448 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES) << "\n"
449 			<< "#extension GL_EXT_tessellation_shader : require\n"
450 			<< "\n"
451 			<< "layout(" << getTessPrimitiveTypeShaderName(caseDef.primitiveType) << ", "
452 						 << getSpacingModeShaderName(caseDef.spacingMode) << ") in;\n"
453 			<< "\n"
454 			<< getTessLevelsSSBODeclaration()
455 			<< "\n"
456 			<< "layout(location = 0) in  highp vec2 in_te_position[];\n"
457 			<< "layout(location = 0) out highp vec4 in_f_color;\n"
458 			<< "\n"
459 			<< "void main (void)\n"
460 			<< "{\n"
461 			<<	(caseDef.primitiveType == TESSPRIMITIVETYPE_TRIANGLES ?
462 					"    highp vec2 corner0 = in_te_position[0];\n"
463 					"    highp vec2 corner1 = in_te_position[1];\n"
464 					"    highp vec2 corner2 = in_te_position[2];\n"
465 					"    highp vec2 pos =  corner0*gl_TessCoord.x + corner1*gl_TessCoord.y + corner2*gl_TessCoord.z;\n"
466 					"    gl_Position = vec4(pos, 0.0, 1.0);\n"
467 					"    highp int numConcentricTriangles = int(round(sb_levels.inner0)) / 2 + 1;\n"
468 					"    highp float d = 3.0 * min(gl_TessCoord.x, min(gl_TessCoord.y, gl_TessCoord.z));\n"
469 					"    highp int phase = int(d*float(numConcentricTriangles)) % 3;\n"
470 					"    in_f_color = phase == 0 ? vec4(1.0, 0.0, 0.0, 1.0)\n"
471 					"               : phase == 1 ? vec4(0.0, 1.0, 0.0, 1.0)\n"
472 					"               :              vec4(0.0, 0.0, 1.0, 1.0);\n"
473 				: caseDef.primitiveType == TESSPRIMITIVETYPE_QUADS ?
474 					"    highp vec2 corner0 = in_te_position[0];\n"
475 					"    highp vec2 corner1 = in_te_position[1];\n"
476 					"    highp vec2 corner2 = in_te_position[2];\n"
477 					"    highp vec2 corner3 = in_te_position[3];\n"
478 					"    highp vec2 pos = (1.0-gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner0\n"
479 					"                   + (    gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner1\n"
480 					"                   + (1.0-gl_TessCoord.x)*(    gl_TessCoord.y)*corner2\n"
481 					"                   + (    gl_TessCoord.x)*(    gl_TessCoord.y)*corner3;\n"
482 					"    gl_Position = vec4(pos, 0.0, 1.0);\n"
483 					"    highp int phaseX = int(round((0.5 - abs(gl_TessCoord.x-0.5)) * sb_levels.inner0));\n"
484 					"    highp int phaseY = int(round((0.5 - abs(gl_TessCoord.y-0.5)) * sb_levels.inner1));\n"
485 					"    highp int phase = min(phaseX, phaseY) % 3;\n"
486 					"    in_f_color = phase == 0 ? vec4(1.0, 0.0, 0.0, 1.0)\n"
487 					"               : phase == 1 ? vec4(0.0, 1.0, 0.0, 1.0)\n"
488 					"               :              vec4(0.0, 0.0, 1.0, 1.0);\n"
489 					: "")
490 			<< "}\n";
491 
492 		programCollection.glslSources.add("tese") << glu::TessellationEvaluationSource(src.str());
493 	}
494 }
495 
initProgramsIsolinesCase(vk::SourceCollections & programCollection,const CaseDefinition caseDef)496 void initProgramsIsolinesCase (vk::SourceCollections& programCollection, const CaseDefinition caseDef)
497 {
498 	DE_ASSERT(caseDef.primitiveType == TESSPRIMITIVETYPE_ISOLINES);
499 
500 	initCommonPrograms(programCollection, caseDef);
501 
502 	// Tessellation evaluation shader
503 	{
504 		std::ostringstream src;
505 		src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES) << "\n"
506 			<< "#extension GL_EXT_tessellation_shader : require\n"
507 			<< "\n"
508 			<< "layout(" << getTessPrimitiveTypeShaderName(caseDef.primitiveType) << ", "
509 						 << getSpacingModeShaderName(caseDef.spacingMode) << ") in;\n"
510 			<< "\n"
511 			<< getTessLevelsSSBODeclaration()
512 			<< "\n"
513 			<< "layout(location = 0) in  highp vec2 in_te_position[];\n"
514 			<< "layout(location = 0) out highp vec4 in_f_color;\n"
515 			<< "\n"
516 			<< "void main (void)\n"
517 			<< "{\n"
518 			<< "    highp vec2 corner0 = in_te_position[0];\n"
519 			<< "    highp vec2 corner1 = in_te_position[1];\n"
520 			<< "    highp vec2 corner2 = in_te_position[2];\n"
521 			<< "    highp vec2 corner3 = in_te_position[3];\n"
522 			<< "    highp vec2 pos = (1.0-gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner0\n"
523 			<< "                   + (    gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner1\n"
524 			<< "                   + (1.0-gl_TessCoord.x)*(    gl_TessCoord.y)*corner2\n"
525 			<< "                   + (    gl_TessCoord.x)*(    gl_TessCoord.y)*corner3;\n"
526 			<< "    pos.y += 0.15*sin(gl_TessCoord.x*10.0);\n"
527 			<< "    gl_Position = vec4(pos, 0.0, 1.0);\n"
528 			<< "    highp int phaseX = int(round(gl_TessCoord.x*sb_levels.outer1));\n"
529 			<< "    highp int phaseY = int(round(gl_TessCoord.y*sb_levels.outer0));\n"
530 			<< "    highp int phase = (phaseX + phaseY) % 3;\n"
531 			<< "    in_f_color = phase == 0 ? vec4(1.0, 0.0, 0.0, 1.0)\n"
532 			<< "               : phase == 1 ? vec4(0.0, 1.0, 0.0, 1.0)\n"
533 			<< "               :              vec4(0.0, 0.0, 1.0, 1.0);\n"
534 			<< "}\n";
535 
536 		programCollection.glslSources.add("tese") << glu::TessellationEvaluationSource(src.str());
537 	}
538 }
539 
getReferenceImagePathPrefix(const std::string & caseName)540 inline std::string getReferenceImagePathPrefix (const std::string& caseName)
541 {
542 	return "vulkan/data/tessellation/" + caseName + "_ref";
543 }
544 
545 } // anonymous
546 
547 //! These tests correspond to dEQP-GLES31.functional.tessellation.misc_draw.*
createMiscDrawTests(tcu::TestContext & testCtx)548 tcu::TestCaseGroup* createMiscDrawTests (tcu::TestContext& testCtx)
549 {
550 	de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "misc_draw", "Miscellaneous draw-result-verifying cases"));
551 
552 	static const TessPrimitiveType primitivesNoIsolines[] =
553 	{
554 		TESSPRIMITIVETYPE_TRIANGLES,
555 		TESSPRIMITIVETYPE_QUADS,
556 	};
557 
558 	// Triangle fill case
559 	for (int primitiveTypeNdx = 0; primitiveTypeNdx < DE_LENGTH_OF_ARRAY(primitivesNoIsolines); ++primitiveTypeNdx)
560 	for (int spacingModeNdx = 0; spacingModeNdx < SPACINGMODE_LAST; ++spacingModeNdx)
561 	{
562 		const TessPrimitiveType primitiveType = primitivesNoIsolines[primitiveTypeNdx];
563 		const SpacingMode		spacingMode	  = static_cast<SpacingMode>(spacingModeNdx);
564 		const std::string		caseName	  = std::string() + "fill_cover_" + getTessPrimitiveTypeShaderName(primitiveType) + "_" + getSpacingModeShaderName(spacingMode);
565 
566 		addFunctionCaseWithPrograms(group.get(), caseName, "Check that there are no obvious gaps in the triangle-filled area of a tessellated shape",
567 									initProgramsFillCoverCase, runTest, makeCaseDefinition(primitiveType, spacingMode, getReferenceImagePathPrefix(caseName)));
568 	}
569 
570 	// Triangle non-overlap case
571 	for (int primitiveTypeNdx = 0; primitiveTypeNdx < DE_LENGTH_OF_ARRAY(primitivesNoIsolines); ++primitiveTypeNdx)
572 	for (int spacingModeNdx = 0; spacingModeNdx < SPACINGMODE_LAST; ++spacingModeNdx)
573 	{
574 		const TessPrimitiveType primitiveType = primitivesNoIsolines[primitiveTypeNdx];
575 		const SpacingMode		spacingMode	  = static_cast<SpacingMode>(spacingModeNdx);
576 		const std::string		caseName	  = std::string() + "fill_overlap_" + getTessPrimitiveTypeShaderName(primitiveType) + "_" + getSpacingModeShaderName(spacingMode);
577 
578 		addFunctionCaseWithPrograms(group.get(), caseName, "Check that there are no obvious triangle overlaps in the triangle-filled area of a tessellated shape",
579 									initProgramsFillNonOverlapCase, runTest, makeCaseDefinition(primitiveType, spacingMode, getReferenceImagePathPrefix(caseName)));
580 	}
581 
582 	// Isolines
583 	for (int spacingModeNdx = 0; spacingModeNdx < SPACINGMODE_LAST; ++spacingModeNdx)
584 	{
585 		const SpacingMode spacingMode = static_cast<SpacingMode>(spacingModeNdx);
586 		const std::string caseName    = std::string() + "isolines_" + getSpacingModeShaderName(spacingMode);
587 
588 		addFunctionCaseWithPrograms(group.get(), caseName, "Basic isolines render test", checkSupportCase,
589 									initProgramsIsolinesCase, runTest, makeCaseDefinition(TESSPRIMITIVETYPE_ISOLINES, spacingMode, getReferenceImagePathPrefix(caseName)));
590 	}
591 
592 	return group.release();
593 }
594 
595 } // tessellation
596 } // vkt
597