1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Copyright (c) 2016 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Shader builtin variable tests.
24 *//*--------------------------------------------------------------------*/
26 #include "vktShaderRenderBuiltinVarTests.hpp"
27 #include "vktShaderRender.hpp"
28 #include "gluShaderUtil.hpp"
29 #include "tcuImageCompare.hpp"
30 #include "tcuStringTemplate.hpp"
31 #include "tcuTextureUtil.hpp"
34 #include "deRandom.hpp"
50 class BuiltinGlFrontFacingCaseInstance : public ShaderRenderCaseInstance
53 BuiltinGlFrontFacingCaseInstance (Context& context);
55 TestStatus iterate (void);
56 virtual void setupDefaultInputs (void);
59 BuiltinGlFrontFacingCaseInstance::BuiltinGlFrontFacingCaseInstance (Context& context)
60 : ShaderRenderCaseInstance (context)
64 TestStatus BuiltinGlFrontFacingCaseInstance::iterate (void)
66 const UVec2 viewportSize = getViewportSize();
67 const int width = viewportSize.x();
68 const int height = viewportSize.y();
69 const RGBA threshold (2, 2, 2, 2);
70 Surface resImage (width, height);
71 Surface refImage (width, height);
72 bool compareOk = false;
73 const deUint16 indices[12] =
82 render(6, 4, indices);
83 copy(resImage.getAccess(), getResultImage().getAccess());
85 for (int y = 0; y < refImage.getHeight(); y++)
87 for (int x = 0; x < refImage.getWidth()/2; x++)
88 refImage.setPixel(x, y, RGBA::green());
90 for (int x = refImage.getWidth()/2; x < refImage.getWidth(); x++)
91 refImage.setPixel(x, y, RGBA::blue());
94 compareOk = pixelThresholdCompare(m_context.getTestContext().getLog(), "Result", "Image comparison result", refImage, resImage, threshold, COMPARE_LOG_RESULT);
97 return TestStatus::pass("Result image matches reference");
99 return TestStatus::fail("Image mismatch");
102 void BuiltinGlFrontFacingCaseInstance::setupDefaultInputs (void)
104 const float vertices[] =
106 -1.0f, -1.0f, 0.0f, 1.0f,
107 0.0f, -1.0f, 0.0f, 1.0f,
108 1.0f, -1.0f, 0.0f, 1.0f,
109 1.0f, 1.0f, 0.0f, 1.0f,
110 0.0f, 1.0f, 0.0f, 1.0f,
111 -1.0f, 1.0f, 0.0f, 1.0f
114 addAttribute(0u, VK_FORMAT_R32G32B32A32_SFLOAT, deUint32(sizeof(float) * 4), 6, vertices);
117 class BuiltinGlFrontFacingCase : public TestCase
120 BuiltinGlFrontFacingCase (TestContext& testCtx, const string& name, const string& description);
121 virtual ~BuiltinGlFrontFacingCase (void);
123 void initPrograms (SourceCollections& dst) const;
124 TestInstance* createInstance (Context& context) const;
127 BuiltinGlFrontFacingCase (const BuiltinGlFrontFacingCase&); // not allowed!
128 BuiltinGlFrontFacingCase& operator= (const BuiltinGlFrontFacingCase&); // not allowed!
131 BuiltinGlFrontFacingCase::BuiltinGlFrontFacingCase (TestContext& testCtx, const string& name, const string& description)
132 : TestCase(testCtx, name, description)
136 BuiltinGlFrontFacingCase::~BuiltinGlFrontFacingCase (void)
140 void BuiltinGlFrontFacingCase::initPrograms (SourceCollections& dst) const
142 dst.glslSources.add("vert") << glu::VertexSource(
144 "layout(location = 0) in highp vec4 a_position;\n"
147 " gl_Position = a_position;\n"
150 dst.glslSources.add("frag") << glu::FragmentSource(
152 "layout(location = 0) out lowp vec4 o_color;\n"
155 " if (gl_FrontFacing)\n"
156 " o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
158 " o_color = vec4(0.0, 0.0, 1.0, 1.0);\n"
162 TestInstance* BuiltinGlFrontFacingCase::createInstance (Context& context) const
164 return new BuiltinGlFrontFacingCaseInstance(context);
167 class BuiltinGlFragCoordXYZCaseInstance : public ShaderRenderCaseInstance
170 BuiltinGlFragCoordXYZCaseInstance (Context& context);
172 TestStatus iterate (void);
173 virtual void setupDefaultInputs (void);
176 BuiltinGlFragCoordXYZCaseInstance::BuiltinGlFragCoordXYZCaseInstance (Context& context)
177 : ShaderRenderCaseInstance (context)
181 TestStatus BuiltinGlFragCoordXYZCaseInstance::iterate (void)
183 const UVec2 viewportSize = getViewportSize();
184 const int width = viewportSize.x();
185 const int height = viewportSize.y();
186 const tcu::Vec3 scale (1.f / float(width), 1.f / float(height), 1.0f);
187 const tcu::RGBA threshold (2, 2, 2, 2);
188 Surface resImage (width, height);
189 Surface refImage (width, height);
190 bool compareOk = false;
191 const deUint16 indices[6] =
198 addUniform(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, scale);
200 render(4, 2, indices);
201 copy(resImage.getAccess(), getResultImage().getAccess());
204 for (int y = 0; y < refImage.getHeight(); y++)
206 for (int x = 0; x < refImage.getWidth(); x++)
208 const float xf = (float(x)+.5f) / float(refImage.getWidth());
209 const float yf = (float(refImage.getHeight()-y-1)+.5f) / float(refImage.getHeight());
210 const float z = (xf + yf) / 2.0f;
211 const Vec3 fragCoord (float(x)+.5f, float(y)+.5f, z);
212 const Vec3 scaledFC = fragCoord*scale;
213 const Vec4 color (scaledFC.x(), scaledFC.y(), scaledFC.z(), 1.0f);
215 refImage.setPixel(x, y, RGBA(color));
219 compareOk = pixelThresholdCompare(m_context.getTestContext().getLog(), "Result", "Image comparison result", refImage, resImage, threshold, COMPARE_LOG_RESULT);
222 return TestStatus::pass("Result image matches reference");
224 return TestStatus::fail("Image mismatch");
227 void BuiltinGlFragCoordXYZCaseInstance::setupDefaultInputs (void)
229 const float vertices[] =
231 -1.0f, 1.0f, 0.0f, 1.0f,
232 -1.0f, -1.0f, 0.5f, 1.0f,
233 1.0f, 1.0f, 0.5f, 1.0f,
234 1.0f, -1.0f, 1.0f, 1.0f,
237 addAttribute(0u, VK_FORMAT_R32G32B32A32_SFLOAT, deUint32(sizeof(float) * 4), 4, vertices);
240 class BuiltinGlFragCoordXYZCase : public TestCase
243 BuiltinGlFragCoordXYZCase (TestContext& testCtx, const string& name, const string& description);
244 virtual ~BuiltinGlFragCoordXYZCase (void);
246 void initPrograms (SourceCollections& dst) const;
247 TestInstance* createInstance (Context& context) const;
250 BuiltinGlFragCoordXYZCase (const BuiltinGlFragCoordXYZCase&); // not allowed!
251 BuiltinGlFragCoordXYZCase& operator= (const BuiltinGlFragCoordXYZCase&); // not allowed!
254 BuiltinGlFragCoordXYZCase::BuiltinGlFragCoordXYZCase (TestContext& testCtx, const string& name, const string& description)
255 : TestCase(testCtx, name, description)
259 BuiltinGlFragCoordXYZCase::~BuiltinGlFragCoordXYZCase (void)
263 void BuiltinGlFragCoordXYZCase::initPrograms (SourceCollections& dst) const
265 dst.glslSources.add("vert") << glu::VertexSource(
267 "layout(location = 0) in highp vec4 a_position;\n"
270 " gl_Position = a_position;\n"
273 dst.glslSources.add("frag") << glu::FragmentSource(
275 "layout(set=0, binding=0) uniform Scale { highp vec3 u_scale; };\n"
276 "layout(location = 0) out highp vec4 o_color;\n"
279 " o_color = vec4(gl_FragCoord.xyz * u_scale, 1.0);\n"
283 TestInstance* BuiltinGlFragCoordXYZCase::createInstance (Context& context) const
285 return new BuiltinGlFragCoordXYZCaseInstance(context);
288 inline float projectedTriInterpolate (const Vec3& s, const Vec3& w, float nx, float ny)
290 return (s[0]*(1.0f-nx-ny)/w[0] + s[1]*ny/w[1] + s[2]*nx/w[2]) / ((1.0f-nx-ny)/w[0] + ny/w[1] + nx/w[2]);
293 class BuiltinGlFragCoordWCaseInstance : public ShaderRenderCaseInstance
296 BuiltinGlFragCoordWCaseInstance (Context& context);
298 TestStatus iterate (void);
299 virtual void setupDefaultInputs (void);
307 BuiltinGlFragCoordWCaseInstance::BuiltinGlFragCoordWCaseInstance (Context& context)
308 : ShaderRenderCaseInstance (context)
309 , m_w (1.7f, 2.0f, 1.2f, 1.0f)
313 TestStatus BuiltinGlFragCoordWCaseInstance::iterate (void)
315 const UVec2 viewportSize = getViewportSize();
316 const int width = viewportSize.x();
317 const int height = viewportSize.y();
318 const tcu::RGBA threshold (2, 2, 2, 2);
319 Surface resImage (width, height);
320 Surface refImage (width, height);
321 bool compareOk = false;
322 const deUint16 indices[6] =
329 render(4, 2, indices);
330 copy(resImage.getAccess(), getResultImage().getAccess());
333 for (int y = 0; y < refImage.getHeight(); y++)
335 for (int x = 0; x < refImage.getWidth(); x++)
337 const float xf = (float(x)+.5f) / float(refImage.getWidth());
338 const float yf = (float(refImage.getHeight()-y-1)+.5f) / float(refImage.getHeight());
339 const float oow = ((xf + yf) < 1.0f)
340 ? projectedTriInterpolate(Vec3(m_w[0], m_w[1], m_w[2]), Vec3(m_w[0], m_w[1], m_w[2]), xf, yf)
341 : projectedTriInterpolate(Vec3(m_w[3], m_w[2], m_w[1]), Vec3(m_w[3], m_w[2], m_w[1]), 1.0f-xf, 1.0f-yf);
342 const Vec4 color (0.0f, oow - 1.0f, 0.0f, 1.0f);
344 refImage.setPixel(x, y, RGBA(color));
348 compareOk = pixelThresholdCompare(m_context.getTestContext().getLog(), "Result", "Image comparison result", refImage, resImage, threshold, COMPARE_LOG_RESULT);
351 return TestStatus::pass("Result image matches reference");
353 return TestStatus::fail("Image mismatch");
356 void BuiltinGlFragCoordWCaseInstance::setupDefaultInputs (void)
358 const float vertices[] =
360 -m_w[0], m_w[0], 0.0f, m_w[0],
361 -m_w[1], -m_w[1], 0.0f, m_w[1],
362 m_w[2], m_w[2], 0.0f, m_w[2],
363 m_w[3], -m_w[3], 0.0f, m_w[3]
366 addAttribute(0u, VK_FORMAT_R32G32B32A32_SFLOAT, deUint32(sizeof(float) * 4), 4, vertices);
369 class BuiltinGlFragCoordWCase : public TestCase
372 BuiltinGlFragCoordWCase (TestContext& testCtx, const string& name, const string& description);
373 virtual ~BuiltinGlFragCoordWCase (void);
375 void initPrograms (SourceCollections& dst) const;
376 TestInstance* createInstance (Context& context) const;
379 BuiltinGlFragCoordWCase (const BuiltinGlFragCoordWCase&); // not allowed!
380 BuiltinGlFragCoordWCase& operator= (const BuiltinGlFragCoordWCase&); // not allowed!
383 BuiltinGlFragCoordWCase::BuiltinGlFragCoordWCase (TestContext& testCtx, const string& name, const string& description)
384 : TestCase(testCtx, name, description)
388 BuiltinGlFragCoordWCase::~BuiltinGlFragCoordWCase (void)
392 void BuiltinGlFragCoordWCase::initPrograms (SourceCollections& dst) const
394 dst.glslSources.add("vert") << glu::VertexSource(
396 "layout(location = 0) in highp vec4 a_position;\n"
399 " gl_Position = a_position;\n"
402 dst.glslSources.add("frag") << glu::FragmentSource(
404 "layout(location = 0) out highp vec4 o_color;\n"
407 " o_color = vec4(0.0, 1.0 / gl_FragCoord.w - 1.0, 0.0, 1.0);\n"
411 TestInstance* BuiltinGlFragCoordWCase::createInstance (Context& context) const
413 return new BuiltinGlFragCoordWCaseInstance(context);
416 class BuiltinGlPointCoordCaseInstance : public ShaderRenderCaseInstance
419 BuiltinGlPointCoordCaseInstance (Context& context);
421 TestStatus iterate (void);
422 virtual void setupDefaultInputs (void);
425 BuiltinGlPointCoordCaseInstance::BuiltinGlPointCoordCaseInstance (Context& context)
426 : ShaderRenderCaseInstance (context)
430 TestStatus BuiltinGlPointCoordCaseInstance::iterate (void)
432 const UVec2 viewportSize = getViewportSize();
433 const int width = viewportSize.x();
434 const int height = viewportSize.y();
435 const float threshold = 0.02f;
436 const int numPoints = 16;
437 vector<Vec3> coords (numPoints);
438 de::Random rnd (0x145fa);
439 Surface resImage (width, height);
440 Surface refImage (width, height);
441 bool compareOk = false;
442 VkPhysicalDeviceLimits limits = m_context.getDeviceProperties().limits;
444 // Compute coordinates.
446 for (vector<Vec3>::iterator coord = coords.begin(); coord != coords.end(); ++coord)
448 coord->x() = rnd.getFloat(-0.9f, 0.9f);
449 coord->y() = rnd.getFloat(-0.9f, 0.9f);
450 coord->z() = limits.pointSizeRange[0] + float(rnd.getInt(0, int((limits.pointSizeRange[1] - limits.pointSizeRange[0]) / limits.pointSizeGranularity))) * limits.pointSizeGranularity;
455 addAttribute(0u, VK_FORMAT_R32G32B32_SFLOAT, deUint32(sizeof(Vec3)), numPoints, &coords[0]);
456 render(numPoints, 0, DE_NULL, VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
457 copy(resImage.getAccess(), getResultImage().getAccess());
460 clear(refImage.getAccess(), m_clearColor);
461 for (vector<Vec3>::const_iterator pointIter = coords.begin(); pointIter != coords.end(); ++pointIter)
463 const int x0 = deRoundFloatToInt32(float(width) *(pointIter->x()*0.5f + 0.5f) - pointIter->z()*0.5f);
464 const int y0 = deRoundFloatToInt32(float(height)*(pointIter->y()*0.5f + 0.5f) - pointIter->z()*0.5f);
465 const int x1 = deRoundFloatToInt32(float(width) *(pointIter->x()*0.5f + 0.5f) + pointIter->z()*0.5f);
466 const int y1 = deRoundFloatToInt32(float(height)*(pointIter->y()*0.5f + 0.5f) + pointIter->z()*0.5f);
470 for (int yo = 0; yo < h; yo++)
472 for (int xo = 0; xo < w; xo++)
474 const float xf = (float(xo)+0.5f) / float(w);
475 const float yf = (float(yo)+0.5f) / float(h);
476 const Vec4 color (xf, yf, 0.0f, 1.0f);
477 const int dx = x0+xo;
478 const int dy = y0+yo;
480 if (de::inBounds(dx, 0, refImage.getWidth()) && de::inBounds(dy, 0, refImage.getHeight()))
481 refImage.setPixel(dx, dy, RGBA(color));
486 compareOk = fuzzyCompare(m_context.getTestContext().getLog(), "Result", "Image comparison result", refImage, resImage, threshold, COMPARE_LOG_RESULT);
489 return TestStatus::pass("Result image matches reference");
491 return TestStatus::fail("Image mismatch");
494 void BuiltinGlPointCoordCaseInstance::setupDefaultInputs (void)
498 class BuiltinGlPointCoordCase : public TestCase
501 BuiltinGlPointCoordCase (TestContext& testCtx, const string& name, const string& description);
502 virtual ~BuiltinGlPointCoordCase (void);
504 void initPrograms (SourceCollections& dst) const;
505 TestInstance* createInstance (Context& context) const;
508 BuiltinGlPointCoordCase (const BuiltinGlPointCoordCase&); // not allowed!
509 BuiltinGlPointCoordCase& operator= (const BuiltinGlPointCoordCase&); // not allowed!
512 BuiltinGlPointCoordCase::BuiltinGlPointCoordCase (TestContext& testCtx, const string& name, const string& description)
513 : TestCase(testCtx, name, description)
517 BuiltinGlPointCoordCase::~BuiltinGlPointCoordCase (void)
521 void BuiltinGlPointCoordCase::initPrograms (SourceCollections& dst) const
523 dst.glslSources.add("vert") << glu::VertexSource(
525 "layout(location = 0) in highp vec3 a_position;\n"
528 " gl_Position = vec4(a_position.xy, 0.0, 1.0);\n"
529 " gl_PointSize = a_position.z;\n"
532 dst.glslSources.add("frag") << glu::FragmentSource(
534 "layout(location = 0) out lowp vec4 o_color;\n"
537 " o_color = vec4(gl_PointCoord, 0.0, 1.0);\n"
541 TestInstance* BuiltinGlPointCoordCase::createInstance (Context& context) const
543 return new BuiltinGlPointCoordCaseInstance(context);
546 enum ShaderInputTypeBits
548 SHADER_INPUT_BUILTIN_BIT = 0x01,
549 SHADER_INPUT_VARYING_BIT = 0x02,
550 SHADER_INPUT_CONSTANT_BIT = 0x04
553 typedef deUint16 ShaderInputTypes;
555 string shaderInputTypeToString (ShaderInputTypes type)
557 string typeString = "input";
562 if (type & SHADER_INPUT_BUILTIN_BIT)
563 typeString += "_builtin";
565 if (type & SHADER_INPUT_VARYING_BIT)
566 typeString += "_varying";
568 if (type & SHADER_INPUT_CONSTANT_BIT)
569 typeString += "_constant";
574 class BuiltinInputVariationsCaseInstance : public ShaderRenderCaseInstance
577 BuiltinInputVariationsCaseInstance (Context& context, const ShaderInputTypes shaderInputTypes);
579 TestStatus iterate (void);
580 virtual void setupDefaultInputs (void);
581 virtual void updatePushConstants (vk::VkCommandBuffer commandBuffer, vk::VkPipelineLayout pipelineLayout);
584 const ShaderInputTypes m_shaderInputTypes;
585 const Vec4 m_constantColor;
588 BuiltinInputVariationsCaseInstance::BuiltinInputVariationsCaseInstance (Context& context, const ShaderInputTypes shaderInputTypes)
589 : ShaderRenderCaseInstance (context)
590 , m_shaderInputTypes (shaderInputTypes)
591 , m_constantColor (0.1f, 0.05f, 0.2f, 0.0f)
595 TestStatus BuiltinInputVariationsCaseInstance::iterate (void)
597 const UVec2 viewportSize = getViewportSize();
598 const int width = viewportSize.x();
599 const int height = viewportSize.y();
600 const tcu::RGBA threshold (2, 2, 2, 2);
601 Surface resImage (width, height);
602 Surface refImage (width, height);
603 bool compareOk = false;
604 const VkPushConstantRange pcRanges =
606 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlags stageFlags;
607 0u, // deUint32 offset;
608 sizeof(Vec4) // deUint32 size;
610 const deUint16 indices[12] =
620 if (m_shaderInputTypes & SHADER_INPUT_CONSTANT_BIT)
621 setPushConstantRanges(1, &pcRanges);
623 render(6, 4, indices);
624 copy(resImage.getAccess(), getResultImage().getAccess());
627 for (int y = 0; y < refImage.getHeight(); y++)
629 for (int x = 0; x < refImage.getWidth(); x++)
631 Vec4 color (0.1f, 0.2f, 0.3f, 1.0f);
633 if (((m_shaderInputTypes & SHADER_INPUT_BUILTIN_BIT) && (x < refImage.getWidth() / 2)) ||
634 !(m_shaderInputTypes & SHADER_INPUT_BUILTIN_BIT))
636 if (m_shaderInputTypes & SHADER_INPUT_VARYING_BIT)
638 const float xf = (float(x)+.5f) / float(refImage.getWidth());
639 color += Vec4(0.6f * (1 - xf), 0.6f * xf, 0.0f, 0.0f);
642 color += Vec4(0.3f, 0.2f, 0.1f, 0.0f);
645 if (m_shaderInputTypes & SHADER_INPUT_CONSTANT_BIT)
646 color += m_constantColor;
648 refImage.setPixel(x, y, RGBA(color));
652 compareOk = pixelThresholdCompare(m_context.getTestContext().getLog(), "Result", "Image comparison result", refImage, resImage, threshold, COMPARE_LOG_RESULT);
655 return TestStatus::pass("Result image matches reference");
657 return TestStatus::fail("Image mismatch");
660 void BuiltinInputVariationsCaseInstance::setupDefaultInputs (void)
662 const float vertices[] =
664 -1.0f, -1.0f, 0.0f, 1.0f,
665 0.0f, -1.0f, 0.0f, 1.0f,
666 1.0f, -1.0f, 0.0f, 1.0f,
667 1.0f, 1.0f, 0.0f, 1.0f,
668 0.0f, 1.0f, 0.0f, 1.0f,
669 -1.0f, 1.0f, 0.0f, 1.0f
672 addAttribute(0u, VK_FORMAT_R32G32B32A32_SFLOAT, deUint32(sizeof(float) * 4), 6, vertices);
674 if (m_shaderInputTypes & SHADER_INPUT_VARYING_BIT)
676 const float colors[] =
678 0.6f, 0.0f, 0.0f, 1.0f,
679 0.3f, 0.3f, 0.0f, 1.0f,
680 0.0f, 0.6f, 0.0f, 1.0f,
681 0.0f, 0.6f, 0.0f, 1.0f,
682 0.3f, 0.3f, 0.0f, 1.0f,
683 0.6f, 0.0f, 0.0f, 1.0f
685 addAttribute(1u, VK_FORMAT_R32G32B32A32_SFLOAT, deUint32(sizeof(float) * 4), 6, colors);
689 void BuiltinInputVariationsCaseInstance::updatePushConstants (vk::VkCommandBuffer commandBuffer, vk::VkPipelineLayout pipelineLayout)
691 if (m_shaderInputTypes & SHADER_INPUT_CONSTANT_BIT)
693 const DeviceInterface& vk = m_context.getDeviceInterface();
694 vk.cmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(Vec4), &m_constantColor);
698 class BuiltinInputVariationsCase : public TestCase
701 BuiltinInputVariationsCase (TestContext& testCtx, const string& name, const string& description, const ShaderInputTypes shaderInputTypes);
702 virtual ~BuiltinInputVariationsCase (void);
704 void initPrograms (SourceCollections& dst) const;
705 TestInstance* createInstance (Context& context) const;
708 BuiltinInputVariationsCase (const BuiltinInputVariationsCase&); // not allowed!
709 BuiltinInputVariationsCase& operator= (const BuiltinInputVariationsCase&); // not allowed!
710 const ShaderInputTypes m_shaderInputTypes;
713 BuiltinInputVariationsCase::BuiltinInputVariationsCase (TestContext& testCtx, const string& name, const string& description, ShaderInputTypes shaderInputTypes)
714 : TestCase (testCtx, name, description)
715 , m_shaderInputTypes (shaderInputTypes)
719 BuiltinInputVariationsCase::~BuiltinInputVariationsCase (void)
723 void BuiltinInputVariationsCase::initPrograms (SourceCollections& dst) const
725 map<string, string> vertexParams;
726 map<string, string> fragmentParams;
727 const tcu::StringTemplate vertexCodeTemplate (
729 "layout(location = 0) in highp vec4 a_position;\n"
730 "out gl_PerVertex {\n"
731 " vec4 gl_Position;\n"
736 " gl_Position = a_position;\n"
740 const tcu::StringTemplate fragmentCodeTemplate (
744 "layout(location = 0) out highp vec4 o_color;\n"
747 " o_color = vec4(0.1, 0.2, 0.3, 1.0);\n"
753 vertexParams["VARYING_DECL"] =
754 m_shaderInputTypes & SHADER_INPUT_VARYING_BIT ? "layout(location = 1) in highp vec4 a_color;\n"
755 "layout(location = 0) out highp vec4 v_color;\n"
758 vertexParams["VARYING_USAGE"] =
759 m_shaderInputTypes & SHADER_INPUT_VARYING_BIT ? "v_color = a_color;\n"
762 fragmentParams["VARYING_DECL"] =
763 m_shaderInputTypes & SHADER_INPUT_VARYING_BIT ? "layout(location = 0) in highp vec4 a_color;\n"
766 fragmentParams["CONSTANT_DECL"] =
767 m_shaderInputTypes & SHADER_INPUT_CONSTANT_BIT ? "layout(push_constant) uniform PCBlock {\n"
772 fragmentParams["BUILTIN_USAGE"] =
773 m_shaderInputTypes & SHADER_INPUT_BUILTIN_BIT ? "if (gl_FrontFacing)\n"
776 fragmentParams["VARYING_USAGE"] =
777 m_shaderInputTypes & SHADER_INPUT_VARYING_BIT ? "o_color += vec4(a_color.xyz, 0.0);\n"
778 : "o_color += vec4(0.3, 0.2, 0.1, 0.0);\n";
781 fragmentParams["CONSTANT_USAGE"] =
782 m_shaderInputTypes & SHADER_INPUT_CONSTANT_BIT ? "o_color += pc.color;\n"
785 dst.glslSources.add("vert") << glu::VertexSource(vertexCodeTemplate.specialize(vertexParams));
786 dst.glslSources.add("frag") << glu::FragmentSource(fragmentCodeTemplate.specialize(fragmentParams));
789 TestInstance* BuiltinInputVariationsCase::createInstance (Context& context) const
791 return new BuiltinInputVariationsCaseInstance(context, m_shaderInputTypes);
796 TestCaseGroup* createBuiltinVarTests (TestContext& testCtx)
798 de::MovePtr<TestCaseGroup> builtinGroup (new TestCaseGroup(testCtx, "builtin_var", "Shader builtin variable tests."));
799 de::MovePtr<TestCaseGroup> simpleGroup (new TestCaseGroup(testCtx, "simple", "Simple cases."));
800 de::MovePtr<TestCaseGroup> inputVariationsGroup (new TestCaseGroup(testCtx, "input_variations", "Input type variation tests."));
802 simpleGroup->addChild(new BuiltinGlFrontFacingCase(testCtx, "frontfacing", "FrontFacing test"));
803 simpleGroup->addChild(new BuiltinGlFragCoordXYZCase(testCtx, "fragcoord_xyz", "FragCoord xyz test"));
804 simpleGroup->addChild(new BuiltinGlFragCoordWCase(testCtx, "fragcoord_w", "FragCoord w test"));
805 simpleGroup->addChild(new BuiltinGlPointCoordCase(testCtx, "pointcoord", "PointCoord test"));
807 builtinGroup->addChild(simpleGroup.release());
809 for (deUint16 shaderType = 0; shaderType <= (SHADER_INPUT_BUILTIN_BIT | SHADER_INPUT_VARYING_BIT | SHADER_INPUT_CONSTANT_BIT); ++shaderType)
811 inputVariationsGroup->addChild(new BuiltinInputVariationsCase(testCtx, shaderInputTypeToString(shaderType), "Input variation test", shaderType));
814 builtinGroup->addChild(inputVariationsGroup.release());
815 return builtinGroup.release();