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::string;
33 using std::map;
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, glu::ShaderType shaderType)
78 {
79 bool testFailed = false;
80 string message;
81
82 ctx.getLog() << program;
83
84 switch (error)
85 {
86 case PROGRAM_ERROR_LINK:
87 {
88 message = "Program was not expected to link.";
89 testFailed = (program.getProgramInfo().linkOk);
90 break;
91 }
92 case PROGRAM_ERROR_COMPILE:
93 {
94 message = "Program was not expected to compile.";
95 testFailed = program.getShaderInfo(shaderType).compileOk;
96 break;
97 }
98 case PROGRAM_ERROR_COMPILE_OR_LINK:
99 {
100 message = "Program was not expected to compile or link.";
101 testFailed = (program.getProgramInfo().linkOk) && (program.getShaderInfo(shaderType).compileOk);
102 break;
103 }
104 default:
105 {
106 DE_FATAL("Invalid program error type");
107 break;
108 }
109 }
110
111 if (testFailed)
112 {
113 ctx.getLog() << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
114 ctx.fail(message);
115 }
116 }
117
last_frag_data_not_defined(NegativeTestContext & ctx)118 void last_frag_data_not_defined (NegativeTestContext& ctx)
119 {
120 checkFramebufferFetchSupport(ctx);
121
122 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
123 map<string, string> args;
124 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
125
126 const char* const fragShaderSource = "${GLSL_VERSION_STRING}\n"
127 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
128 "layout(location = 0) out mediump vec4 fragColor;\n"
129 "\n"
130 "void main (void)\n"
131 "{\n"
132 " fragColor = gl_LastFragData[0];\n"
133 "}\n";
134
135 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
136 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
137 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
138
139 ctx.beginSection("A link error is generated if the built-in fragment outputs of ES 2.0 are used in #version 300 es shaders");
140 verifyProgramError(ctx, program, PROGRAM_ERROR_LINK, glu::SHADERTYPE_FRAGMENT);
141 ctx.endSection();
142 }
143
last_frag_data_readonly(NegativeTestContext & ctx)144 void last_frag_data_readonly (NegativeTestContext& ctx)
145 {
146 checkFramebufferFetchSupport(ctx);
147
148 map<string, string> args;
149 args["GLSL_VERSION_STRING"] = getGLSLVersionDeclaration(glu::GLSL_VERSION_100_ES);
150
151 const char* const fragShaderSource = "${GLSL_VERSION_STRING}\n"
152 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
153 "\n"
154 "void main (void)\n"
155 "{\n"
156 " gl_LastFragData[0] = vec4(1.0);\n"
157 " gl_FragColor = gl_LastFragData[0];\n"
158 "}\n";
159
160 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
161 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
162 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
163
164 ctx.beginSection("A compile-time or link error is generated if the built-in fragment outputs of ES 2.0 are written to.");
165 verifyProgramError(ctx, program, PROGRAM_ERROR_COMPILE_OR_LINK, glu::SHADERTYPE_FRAGMENT);
166 ctx.endSection();
167 }
168
invalid_inout_version(NegativeTestContext & ctx)169 void invalid_inout_version (NegativeTestContext& ctx)
170 {
171 checkFramebufferFetchSupport(ctx);
172
173 map<string, string> args;
174 args["GLSL_VERSION_STRING"] = getGLSLVersionDeclaration(glu::GLSL_VERSION_100_ES);
175
176 const char* const fragShaderSource = "${GLSL_VERSION_STRING}\n"
177 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
178 "inout highp vec4 fragColor;\n"
179 "\n"
180 "void main (void)\n"
181 "{\n"
182 " highp float product = dot(vec3(0.5), fragColor.rgb);\n"
183 " gl_FragColor = vec4(product);\n"
184 "}\n";
185
186 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
187 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
188 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
189
190 ctx.beginSection("A compile-time or link error is generated if user-defined inout arrays are used in earlier versions of GLSL before ES 3.0");
191 verifyProgramError(ctx, program, PROGRAM_ERROR_COMPILE_OR_LINK, glu::SHADERTYPE_FRAGMENT);
192 ctx.endSection();
193 }
194
invalid_redeclaration_inout(NegativeTestContext & ctx)195 void invalid_redeclaration_inout (NegativeTestContext& ctx)
196 {
197 checkFramebufferFetchSupport(ctx);
198
199 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
200 map<string, string> args;
201 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
202
203 const char* const fragShaderSource = "${GLSL_VERSION_STRING}\n"
204 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
205 "layout(location = 0) out mediump vec4 fragColor;\n"
206 "inout highp float gl_FragDepth;\n"
207 "\n"
208 "void main (void)\n"
209 "{\n"
210 " gl_FragDepth += 0.5f;\n"
211 " fragColor = vec4(1.0f);\n"
212 "}\n";
213
214 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
215 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
216 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
217
218 ctx.beginSection("A compile-time or link error is generated if re-declaring an existing fragment output such as gl_FragDepth as inout");
219 verifyProgramError(ctx, program, PROGRAM_ERROR_COMPILE_OR_LINK, glu::SHADERTYPE_FRAGMENT);
220 ctx.endSection();
221 }
222
invalid_vertex_inout(NegativeTestContext & ctx)223 void invalid_vertex_inout (NegativeTestContext& ctx)
224 {
225 checkFramebufferFetchSupport(ctx);
226
227 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
228 map<string, string> args;
229 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
230
231 const char* const vertShaderSource = "${GLSL_VERSION_STRING}\n"
232 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
233 "inout mediump vec4 v_color;\n"
234 "\n"
235 "void main (void)\n"
236 "{\n"
237 "}\n";
238
239 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
240 << glu::VertexSource(tcu::StringTemplate(vertShaderSource).specialize(args))
241 << glu::FragmentSource(tcu::StringTemplate(fragmentShaderSource).specialize(args)));
242
243 ctx.beginSection("A compile-time error or link error is generated if inout variables are declared in the vertex shader\n");
244 verifyProgramError(ctx, program, PROGRAM_ERROR_COMPILE_OR_LINK, glu::SHADERTYPE_VERTEX);
245 ctx.endSection();
246 }
247
248 } // anonymous
249
getNegativeShaderFramebufferFetchTestFunctions(void)250 std::vector<FunctionContainer> getNegativeShaderFramebufferFetchTestFunctions (void)
251 {
252 const FunctionContainer funcs[] =
253 {
254 { last_frag_data_not_defined, "last_frag_data_not_defined", "The built-in gl_LastFragData not defined in #version 300 es shaders" },
255 { last_frag_data_readonly, "last_frag_data_readonly", "Invalid write to readonly builtin in gl_LastFragData" },
256 { invalid_inout_version, "invalid_inout_version", "Invalid use of user-defined inout arrays in versions before GLSL #version 300 es." },
257 { invalid_redeclaration_inout, "invalid_redeclaration_inout", "Existing fragment shader built-ins cannot be redeclared as inout arrays" },
258 { invalid_vertex_inout, "invalid_vertex_inout", "User defined inout arrays are not allowed in the vertex shader" },
259 };
260
261 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
262 }
263
264 } // NegativeTestShared
265 } // Functional
266 } // gles31
267 } // deqp
268