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"
45 class BuiltinGlFrontFacingCaseInstance : public ShaderRenderCaseInstance
48 BuiltinGlFrontFacingCaseInstance (Context& context);
50 TestStatus iterate (void);
51 virtual void setupDefaultInputs (void);
54 BuiltinGlFrontFacingCaseInstance::BuiltinGlFrontFacingCaseInstance (Context& context)
55 : ShaderRenderCaseInstance (context)
59 TestStatus BuiltinGlFrontFacingCaseInstance::iterate (void)
61 const UVec2 viewportSize = getViewportSize();
62 const int width = viewportSize.x();
63 const int height = viewportSize.y();
64 const RGBA threshold (2, 2, 2, 2);
65 Surface resImage (width, height);
66 Surface refImage (width, height);
67 bool compareOk = false;
68 const deUint16 indices[12] =
77 render(6, 4, indices);
78 copy(resImage.getAccess(), getResultImage().getAccess());
80 for (int y = 0; y < refImage.getHeight(); y++)
82 for (int x = 0; x < refImage.getWidth()/2; x++)
83 refImage.setPixel(x, y, RGBA::green());
85 for (int x = refImage.getWidth()/2; x < refImage.getWidth(); x++)
86 refImage.setPixel(x, y, RGBA::blue());
89 compareOk = pixelThresholdCompare(m_context.getTestContext().getLog(), "Result", "Image comparison result", refImage, resImage, threshold, COMPARE_LOG_RESULT);
92 return TestStatus::pass("Result image matches reference");
94 return TestStatus::fail("Image mismatch");
97 void BuiltinGlFrontFacingCaseInstance::setupDefaultInputs (void)
99 const float vertices[] =
101 -1.0f, -1.0f, 0.0f, 1.0f,
102 0.0f, -1.0f, 0.0f, 1.0f,
103 1.0f, -1.0f, 0.0f, 1.0f,
104 1.0f, 1.0f, 0.0f, 1.0f,
105 0.0f, 1.0f, 0.0f, 1.0f,
106 -1.0f, 1.0f, 0.0f, 1.0f
109 addAttribute(0u, VK_FORMAT_R32G32B32A32_SFLOAT, (deUint32)sizeof(float) * 4, 6, vertices);
112 class BuiltinGlFrontFacingCase : public TestCase
115 BuiltinGlFrontFacingCase (TestContext& testCtx, const string& name, const string& description);
116 virtual ~BuiltinGlFrontFacingCase (void);
118 void initPrograms (SourceCollections& dst) const;
119 TestInstance* createInstance (Context& context) const;
122 BuiltinGlFrontFacingCase (const BuiltinGlFrontFacingCase&); // not allowed!
123 BuiltinGlFrontFacingCase& operator= (const BuiltinGlFrontFacingCase&); // not allowed!
126 BuiltinGlFrontFacingCase::BuiltinGlFrontFacingCase (TestContext& testCtx, const string& name, const string& description)
127 : TestCase(testCtx, name, description)
131 BuiltinGlFrontFacingCase::~BuiltinGlFrontFacingCase (void)
135 void BuiltinGlFrontFacingCase::initPrograms (SourceCollections& dst) const
137 dst.glslSources.add("vert") << glu::VertexSource(
139 "layout(location = 0) in highp vec4 a_position;\n"
142 " gl_Position = a_position;\n"
145 dst.glslSources.add("frag") << glu::FragmentSource(
147 "layout(location = 0) out lowp vec4 o_color;\n"
150 " if (gl_FrontFacing)\n"
151 " o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
153 " o_color = vec4(0.0, 0.0, 1.0, 1.0);\n"
157 TestInstance* BuiltinGlFrontFacingCase::createInstance (Context& context) const
159 return new BuiltinGlFrontFacingCaseInstance(context);
164 TestCaseGroup* createBuiltinVarTests (TestContext& testCtx)
166 de::MovePtr<TestCaseGroup> varyingGroup(new TestCaseGroup(testCtx, "builtin_var", "Shader builtin variable tests."));
168 varyingGroup->addChild(new BuiltinGlFrontFacingCase(testCtx, "gl_frontfacing", "gl_FrontFacing test"));
170 return varyingGroup.release();