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