1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
4 *
5 * Copyright 2017 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 ShaderFramebufferFetch tests.
22 *//*--------------------------------------------------------------------*/
23
24 #include "es31fNegativeShaderFramebufferFetchTests.hpp"
25 #include "gluContextInfo.hpp"
26 #include "gluShaderProgram.hpp"
27 #include "tcuStringTemplate.hpp"
28
29 namespace deqp
30 {
31
32 using std::map;
33 using std::string;
34
35 namespace gles31
36 {
37 namespace Functional
38 {
39 namespace NegativeTestShared
40 {
41 namespace
42 {
43
44 static const char *vertexShaderSource = "${GLSL_VERSION_STRING}\n"
45 "\n"
46 "void main (void)\n"
47 "{\n"
48 " gl_Position = vec4(0.0);\n"
49 "}\n";
50
51 static const char *fragmentShaderSource = "${GLSL_VERSION_STRING}\n"
52 "layout(location = 0) out mediump vec4 fragColor;\n"
53 "\n"
54 "void main (void)\n"
55 "{\n"
56 " fragColor = vec4(1.0);\n"
57 "}\n";
58
checkExtensionSupport(NegativeTestContext & ctx,const char * extName)59 static void checkExtensionSupport(NegativeTestContext &ctx, const char *extName)
60 {
61 if (!ctx.getContextInfo().isExtensionSupported(extName))
62 throw tcu::NotSupportedError(string(extName) + " not supported");
63 }
64
checkFramebufferFetchSupport(NegativeTestContext & ctx)65 static void checkFramebufferFetchSupport(NegativeTestContext &ctx)
66 {
67 checkExtensionSupport(ctx, "GL_EXT_shader_framebuffer_fetch");
68 }
69
70 enum ProgramError
71 {
72 PROGRAM_ERROR_LINK = 0,
73 PROGRAM_ERROR_COMPILE,
74 PROGRAM_ERROR_COMPILE_OR_LINK,
75 };
76
verifyProgramError(NegativeTestContext & ctx,const glu::ShaderProgram & program,ProgramError error,glu::ShaderType shaderType)77 void verifyProgramError(NegativeTestContext &ctx, const glu::ShaderProgram &program, ProgramError error,
78 glu::ShaderType shaderType)
79 {
80 bool testFailed = false;
81 string message;
82
83 ctx.getLog() << program;
84
85 switch (error)
86 {
87 case PROGRAM_ERROR_LINK:
88 {
89 message = "Program was not expected to link.";
90 testFailed = (program.getProgramInfo().linkOk);
91 break;
92 }
93 case PROGRAM_ERROR_COMPILE:
94 {
95 message = "Program was not expected to compile.";
96 testFailed = program.getShaderInfo(shaderType).compileOk;
97 break;
98 }
99 case PROGRAM_ERROR_COMPILE_OR_LINK:
100 {
101 message = "Program was not expected to compile or link.";
102 testFailed = (program.getProgramInfo().linkOk) && (program.getShaderInfo(shaderType).compileOk);
103 break;
104 }
105 default:
106 {
107 DE_FATAL("Invalid program error type");
108 break;
109 }
110 }
111
112 if (testFailed)
113 {
114 ctx.getLog() << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
115 ctx.fail(message);
116 }
117 }
118
last_frag_data_not_defined(NegativeTestContext & ctx)119 void last_frag_data_not_defined(NegativeTestContext &ctx)
120 {
121 // this tests does not apply to GL4.5
122 if (!glu::isContextTypeES(ctx.getRenderContext().getType()))
123 return;
124
125 checkFramebufferFetchSupport(ctx);
126
127 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
128 map<string, string> args;
129 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) :
130 getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
131
132 const char *const fragShaderSource = "${GLSL_VERSION_STRING}\n"
133 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
134 "layout(location = 0) out mediump vec4 fragColor;\n"
135 "\n"
136 "void main (void)\n"
137 "{\n"
138 " fragColor = gl_LastFragData[0];\n"
139 "}\n";
140
141 glu::ShaderProgram program(ctx.getRenderContext(),
142 glu::ProgramSources()
143 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
144 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
145
146 ctx.beginSection(
147 "A link error is generated if the built-in fragment outputs of ES 2.0 are used in #version 300 es shaders");
148 verifyProgramError(ctx, program, PROGRAM_ERROR_LINK, glu::SHADERTYPE_FRAGMENT);
149 ctx.endSection();
150 }
151
last_frag_data_readonly(NegativeTestContext & ctx)152 void last_frag_data_readonly(NegativeTestContext &ctx)
153 {
154 return; /// TEMP - not sure what to do, this test crashes on es3.1 and gl4.5 context
155
156 checkFramebufferFetchSupport(ctx);
157
158 map<string, string> args;
159 args["GLSL_VERSION_STRING"] = getGLSLVersionDeclaration(glu::GLSL_VERSION_100_ES);
160
161 const char *const fragShaderSource = "${GLSL_VERSION_STRING}\n"
162 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
163 "\n"
164 "void main (void)\n"
165 "{\n"
166 " gl_LastFragData[0] = vec4(1.0);\n"
167 " gl_FragColor = gl_LastFragData[0];\n"
168 "}\n";
169
170 glu::ShaderProgram program(ctx.getRenderContext(),
171 glu::ProgramSources()
172 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
173 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
174
175 ctx.beginSection(
176 "A compile-time or link error is generated if the built-in fragment outputs of ES 2.0 are written to.");
177 verifyProgramError(ctx, program, PROGRAM_ERROR_COMPILE_OR_LINK, glu::SHADERTYPE_FRAGMENT);
178 ctx.endSection();
179 }
180
invalid_inout_version(NegativeTestContext & ctx)181 void invalid_inout_version(NegativeTestContext &ctx)
182 {
183 checkFramebufferFetchSupport(ctx);
184
185 map<string, string> args;
186 args["GLSL_VERSION_STRING"] = getGLSLVersionDeclaration(glu::GLSL_VERSION_100_ES);
187
188 const char *const fragShaderSource = "${GLSL_VERSION_STRING}\n"
189 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
190 "inout highp vec4 fragColor;\n"
191 "\n"
192 "void main (void)\n"
193 "{\n"
194 " highp float product = dot(vec3(0.5), fragColor.rgb);\n"
195 " gl_FragColor = vec4(product);\n"
196 "}\n";
197
198 glu::ShaderProgram program(ctx.getRenderContext(),
199 glu::ProgramSources()
200 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
201 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
202
203 ctx.beginSection("A compile-time or link error is generated if user-defined inout arrays are used in earlier "
204 "versions of GLSL before ES 3.0");
205 verifyProgramError(ctx, program, PROGRAM_ERROR_COMPILE_OR_LINK, glu::SHADERTYPE_FRAGMENT);
206 ctx.endSection();
207 }
208
invalid_redeclaration_inout(NegativeTestContext & ctx)209 void invalid_redeclaration_inout(NegativeTestContext &ctx)
210 {
211 // this case does not apply to GL4.5
212 if (!glu::isContextTypeES(ctx.getRenderContext().getType()))
213 return;
214
215 checkFramebufferFetchSupport(ctx);
216
217 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
218 map<string, string> args;
219 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) :
220 getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
221
222 const char *const fragShaderSource = "${GLSL_VERSION_STRING}\n"
223 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
224 "layout(location = 0) out mediump vec4 fragColor;\n"
225 "inout highp float gl_FragDepth;\n"
226 "\n"
227 "void main (void)\n"
228 "{\n"
229 " gl_FragDepth += 0.5f;\n"
230 " fragColor = vec4(1.0f);\n"
231 "}\n";
232
233 glu::ShaderProgram program(ctx.getRenderContext(),
234 glu::ProgramSources()
235 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
236 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
237
238 ctx.beginSection("A compile-time or link error is generated if re-declaring an existing fragment output such as "
239 "gl_FragDepth as inout");
240 verifyProgramError(ctx, program, PROGRAM_ERROR_COMPILE_OR_LINK, glu::SHADERTYPE_FRAGMENT);
241 ctx.endSection();
242 }
243
invalid_vertex_inout(NegativeTestContext & ctx)244 void invalid_vertex_inout(NegativeTestContext &ctx)
245 {
246 // this case does not apply to GL4.5
247 if (!glu::isContextTypeES(ctx.getRenderContext().getType()))
248 return;
249
250 checkFramebufferFetchSupport(ctx);
251
252 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
253 map<string, string> args;
254 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) :
255 getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
256
257 const char *const vertShaderSource = "${GLSL_VERSION_STRING}\n"
258 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
259 "inout mediump vec4 v_color;\n"
260 "\n"
261 "void main (void)\n"
262 "{\n"
263 "}\n";
264
265 glu::ShaderProgram program(ctx.getRenderContext(),
266 glu::ProgramSources()
267 << glu::VertexSource(tcu::StringTemplate(vertShaderSource).specialize(args))
268 << glu::FragmentSource(tcu::StringTemplate(fragmentShaderSource).specialize(args)));
269
270 ctx.beginSection(
271 "A compile-time error or link error is generated if inout variables are declared in the vertex shader\n");
272 verifyProgramError(ctx, program, PROGRAM_ERROR_COMPILE_OR_LINK, glu::SHADERTYPE_VERTEX);
273 ctx.endSection();
274 }
275
276 } // namespace
277
getNegativeShaderFramebufferFetchTestFunctions(void)278 std::vector<FunctionContainer> getNegativeShaderFramebufferFetchTestFunctions(void)
279 {
280 const FunctionContainer funcs[] = {
281 {last_frag_data_not_defined, "last_frag_data_not_defined",
282 "The built-in gl_LastFragData not defined in #version 300 es shaders"},
283 {last_frag_data_readonly, "last_frag_data_readonly", "Invalid write to readonly builtin in gl_LastFragData"},
284 {invalid_inout_version, "invalid_inout_version",
285 "Invalid use of user-defined inout arrays in versions before GLSL #version 300 es."},
286 {invalid_redeclaration_inout, "invalid_redeclaration_inout",
287 "Existing fragment shader built-ins cannot be redeclared as inout arrays"},
288 {invalid_vertex_inout, "invalid_vertex_inout",
289 "User defined inout arrays are not allowed in the vertex shader"},
290 };
291
292 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
293 }
294
295 } // namespace NegativeTestShared
296 } // namespace Functional
297 } // namespace gles31
298 } // namespace deqp
299