1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
4 *
5 * Copyright 2016 The Android Open Source Project
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 *//*!
20 * \file
21 * \brief Negative Precise Tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "es31fNegativePreciseTests.hpp"
25
26 #include "gluShaderProgram.hpp"
27 #include "glwEnums.hpp"
28
29 namespace deqp
30 {
31 namespace gles31
32 {
33 namespace Functional
34 {
35 namespace NegativeTestShared
36 {
37 namespace
38 {
39
40 enum TestPrecise
41 {
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,
49
50 TEST_PRECISE_LAST
51 };
52
53 static const glu::ShaderType s_shaderTypes[] =
54 {
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
61 };
62
generateShaderSource(NegativeTestContext & ctx,glu::ShaderType shaderType,TestPrecise test)63 std::string generateShaderSource (NegativeTestContext& ctx, glu::ShaderType shaderType, TestPrecise test)
64 {
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;
68
69 source << glu::getGLSLVersionDeclaration(version) << "\n"
70 << (supportsES32 ? "" : "#extension GL_EXT_gpu_shader5 : enable\n");
71
72 switch (test)
73 {
74 case TEST_PRECISE_AS_MACRO_NAME: source << "#define precise 0\n"; break;
75
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;
79 default:
80 break;
81 }
82
83 switch (shaderType)
84 {
85 case glu::SHADERTYPE_GEOMETRY:
86 source << (supportsES32 ? "" : "#extension GL_EXT_geometry_shader : enable\n")
87 << "layout(max_vertices = 5) out;\n";
88 break;
89
90 case glu::SHADERTYPE_TESSELLATION_CONTROL:
91 source << (supportsES32 ? "" : "#extension GL_EXT_tessellation_shader : enable\n")
92 << "layout(vertices = 3) out;\n";
93 break;
94
95 case glu::SHADERTYPE_TESSELLATION_EVALUATION:
96 source << (supportsES32 ? "" : "#extension GL_EXT_tessellation_shader : enable\n")
97 << "layout(triangles, equal_spacing, cw) in;\n";
98 break;
99
100 default:
101 break;
102 }
103
104 switch (test)
105 {
106 case TEST_PRECISE_AS_FUNCTION_NAME:
107 case TEST_PRECISE_MACRO_AND_FUNCTION:
108 source << "\n"
109 << "void precise()\n"
110 << "{\n"
111 << "}\n";
112 break;
113
114 case TEST_PRECISE_AS_ARGUMENT_NAME:
115 case TEST_PRECISE_MACRO_AND_ARGUMENT:
116 source << "\n"
117 << "void example(int precise)\n"
118 << "{\n"
119 << "}\n";
120 break;
121
122 default:
123 break;
124 }
125
126 source << "void main()\n"
127 << "{\n";
128
129 switch (test)
130 {
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;
134 default:
135 break;
136 }
137
138 source << "}\n";
139
140 return source.str();
141 }
142
generateAndVerifyShader(NegativeTestContext & ctx,glu::ShaderType shaderType,TestPrecise test)143 void generateAndVerifyShader (NegativeTestContext& ctx, glu::ShaderType shaderType, TestPrecise test)
144 {
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();
149
150 shader.setSources(1, &source, &length);
151 shader.compile();
152
153 ctx.getLog() << shader;
154
155 if (shader.getCompileStatus())
156 ctx.fail("Shader was not expected to compile.");
157 }
158
checkSupport(NegativeTestContext & ctx)159 static bool checkSupport(NegativeTestContext& ctx)
160 {
161 return ctx.isExtensionSupported("GL_EXT_gpu_shader5") ||
162 contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)) ||
163 contextSupports(ctx.getRenderContext().getType(), glu::ApiType::core(4, 5));
164 }
165
precise_as_variable_name(NegativeTestContext & ctx)166 void precise_as_variable_name (NegativeTestContext& ctx)
167 {
168 TCU_CHECK_AND_THROW(NotSupportedError, checkSupport(ctx),
169 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher.");
170
171 ctx.beginSection("Test that precise cannot be used as a variable name.");
172 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx)
173 {
174 if (ctx.isShaderSupported(s_shaderTypes[ndx]))
175 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_VARIABLE_NAME);
176 }
177 ctx.endSection();
178 }
179
precise_as_function_name(NegativeTestContext & ctx)180 void precise_as_function_name (NegativeTestContext& ctx)
181 {
182 TCU_CHECK_AND_THROW(NotSupportedError, checkSupport(ctx),
183 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher.");
184
185 ctx.beginSection("Test that precise cannot be used as a function name.");
186 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx)
187 {
188 if (ctx.isShaderSupported(s_shaderTypes[ndx]))
189 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_FUNCTION_NAME);
190 }
191 ctx.endSection();
192 }
193
precise_as_function_argument(NegativeTestContext & ctx)194 void precise_as_function_argument (NegativeTestContext& ctx)
195 {
196 TCU_CHECK_AND_THROW(NotSupportedError, checkSupport(ctx),
197 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher.");
198
199 ctx.beginSection("Test that precise cannot be used as a argument name.");
200 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx)
201 {
202 if (ctx.isShaderSupported(s_shaderTypes[ndx]))
203 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_ARGUMENT_NAME);
204 }
205 ctx.endSection();
206 }
207
208 } // anonymous
209
getNegativePreciseTestFunctions(void)210 std::vector<FunctionContainer> getNegativePreciseTestFunctions (void)
211 {
212 const FunctionContainer funcs[] =
213 {
214 {precise_as_variable_name, "precise_as_variable_name", "Test precise keyword as variable name." },
215 {precise_as_function_name, "precise_as_function_name", "Test precise keyword as function name." },
216 {precise_as_function_argument, "precise_as_function_argument", "Test precise keyword as argument name." },
217 };
218
219 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
220 }
221
222 } // NegativeTestShared
223 } // Functional
224 } // gles31
225 } // deqp
226