1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2016 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Negative Precise Tests
22 *//*--------------------------------------------------------------------*/
24 #include "es31fNegativePreciseTests.hpp"
26 #include "gluShaderProgram.hpp"
27 #include "glwEnums.hpp"
35 namespace NegativeTestShared
42 TEST_PRECISE_AS_VARIABLE_NAME = 0,
43 TEST_PRECISE_AS_FUNCTION_NAME,
44 TEST_PRECISE_AS_ARGUMENT_NAME,
45 TEST_PRECISE_AS_MACRO_NAME,
46 TEST_PRECISE_MACRO_AND_VARIABLE,
47 TEST_PRECISE_MACRO_AND_FUNCTION,
48 TEST_PRECISE_MACRO_AND_ARGUMENT,
53 static const glu::ShaderType s_shaderTypes[] =
55 glu::SHADERTYPE_VERTEX,
56 glu::SHADERTYPE_FRAGMENT,
57 glu::SHADERTYPE_GEOMETRY,
58 glu::SHADERTYPE_COMPUTE,
59 glu::SHADERTYPE_TESSELLATION_CONTROL,
60 glu::SHADERTYPE_TESSELLATION_EVALUATION
63 std::string generateShaderSource (NegativeTestContext& ctx, glu::ShaderType shaderType, TestPrecise test)
65 const bool supportsES32 = contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
66 const glu::GLSLVersion version = supportsES32 ? glu::GLSL_VERSION_320_ES : glu::GLSL_VERSION_310_ES;
67 std::ostringstream source;
69 source << glu::getGLSLVersionDeclaration(version) << "\n"
70 << (supportsES32 ? "" : "#extension GL_EXT_gpu_shader5 : enable\n");
74 case TEST_PRECISE_AS_MACRO_NAME: source << "#define precise 0\n"; break;
76 case TEST_PRECISE_MACRO_AND_VARIABLE:
77 case TEST_PRECISE_MACRO_AND_FUNCTION:
78 case TEST_PRECISE_MACRO_AND_ARGUMENT: source << "#define precise aName\n"; break;
85 case glu::SHADERTYPE_GEOMETRY:
86 source << (supportsES32 ? "" : "#extension GL_EXT_geometry_shader : enable\n")
87 << "layout(max_vertices = 5) out;\n";
90 case glu::SHADERTYPE_TESSELLATION_CONTROL:
91 source << (supportsES32 ? "" : "#extension GL_EXT_tessellation_shader : enable\n")
92 << "layout(vertices = 3) out;\n";
95 case glu::SHADERTYPE_TESSELLATION_EVALUATION:
96 source << (supportsES32 ? "" : "#extension GL_EXT_tessellation_shader : enable\n")
97 << "layout(triangles, equal_spacing, cw) in;\n";
106 case TEST_PRECISE_AS_FUNCTION_NAME:
107 case TEST_PRECISE_MACRO_AND_FUNCTION:
109 << "void precise()\n"
114 case TEST_PRECISE_AS_ARGUMENT_NAME:
115 case TEST_PRECISE_MACRO_AND_ARGUMENT:
117 << "void example(int precise)\n"
126 source << "void main()\n"
131 case TEST_PRECISE_AS_VARIABLE_NAME:
132 case TEST_PRECISE_MACRO_AND_VARIABLE: source << " int precise = 1;\n"; break;
133 case TEST_PRECISE_AS_MACRO_NAME: source << " int number = precise;\n"; break;
143 void generateAndVerifyShader (NegativeTestContext& ctx, glu::ShaderType shaderType, TestPrecise test)
145 glu::Shader shader (ctx.getRenderContext(), shaderType);
146 std::string shaderSource = generateShaderSource(ctx, shaderType, test);
147 const char* const source = shaderSource.c_str();
148 const int length = (int) shaderSource.size();
150 shader.setSources(1, &source, &length);
153 ctx.getLog() << shader;
155 if (shader.getCompileStatus())
156 ctx.fail("Shader was not expected to compile.");
159 void precise_as_variable_name (NegativeTestContext& ctx)
161 TCU_CHECK_AND_THROW(NotSupportedError,
162 ctx.isExtensionSupported("GL_EXT_gpu_shader5") || contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)),
163 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher.");
165 ctx.beginSection("Test that precise cannot be used as a variable name.");
166 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx)
168 if (ctx.isShaderSupported(s_shaderTypes[ndx]))
169 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_VARIABLE_NAME);
174 void precise_as_function_name (NegativeTestContext& ctx)
176 TCU_CHECK_AND_THROW(NotSupportedError,
177 ctx.isExtensionSupported("GL_EXT_gpu_shader5") || contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)),
178 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher.");
180 ctx.beginSection("Test that precise cannot be used as a function name.");
181 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx)
183 if (ctx.isShaderSupported(s_shaderTypes[ndx]))
184 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_FUNCTION_NAME);
189 void precise_as_function_argument (NegativeTestContext& ctx)
191 TCU_CHECK_AND_THROW(NotSupportedError,
192 ctx.isExtensionSupported("GL_EXT_gpu_shader5") || contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)),
193 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher.");
195 ctx.beginSection("Test that precise cannot be used as a argument name.");
196 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx)
198 if (ctx.isShaderSupported(s_shaderTypes[ndx]))
199 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_ARGUMENT_NAME);
206 std::vector<FunctionContainer> getNegativePreciseTestFunctions (void)
208 const FunctionContainer funcs[] =
210 {precise_as_variable_name, "precise_as_variable_name", "Test precise keyword as variable name." },
211 {precise_as_function_name, "precise_as_function_name", "Test precise keyword as function name." },
212 {precise_as_function_argument, "precise_as_function_argument", "Test precise keyword as argument name." },
215 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
218 } // NegativeTestShared