1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2017 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 ShaderFramebufferFetch tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es31fNegativeShaderFramebufferFetchTests.hpp"
25 #include "gluContextInfo.hpp"
26 #include "gluShaderProgram.hpp"
27 #include "tcuStringTemplate.hpp"
39 namespace NegativeTestShared
44 static const char* vertexShaderSource = "${GLSL_VERSION_STRING}\n"
48 " gl_Position = vec4(0.0);\n"
51 static const char* fragmentShaderSource = "${GLSL_VERSION_STRING}\n"
52 "layout(location = 0) out mediump vec4 fragColor;\n"
56 " fragColor = vec4(1.0);\n"
59 static void checkExtensionSupport (NegativeTestContext& ctx, const char* extName)
61 if (!ctx.getContextInfo().isExtensionSupported(extName))
62 throw tcu::NotSupportedError(string(extName) + " not supported");
65 static void checkFramebufferFetchSupport (NegativeTestContext& ctx)
67 checkExtensionSupport(ctx, "GL_EXT_shader_framebuffer_fetch");
72 PROGRAM_ERROR_LINK = 0,
73 PROGRAM_ERROR_COMPILE,
74 PROGRAM_ERROR_COMPILE_OR_LINK,
77 void verifyProgramError (NegativeTestContext& ctx, const glu::ShaderProgram& program, ProgramError error, glu::ShaderType shaderType)
79 bool testFailed = false;
82 ctx.getLog() << program;
86 case PROGRAM_ERROR_LINK:
88 message = "Program was not expected to link.";
89 testFailed = (program.getProgramInfo().linkOk);
92 case PROGRAM_ERROR_COMPILE:
94 message = "Program was not expected to compile.";
95 testFailed = program.getShaderInfo(shaderType).compileOk;
98 case PROGRAM_ERROR_COMPILE_OR_LINK:
100 message = "Program was not expected to compile or link.";
101 testFailed = (program.getProgramInfo().linkOk) && (program.getShaderInfo(shaderType).compileOk);
106 DE_FATAL("Invalid program error type");
113 ctx.getLog() << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
118 void last_frag_data_not_defined (NegativeTestContext& ctx)
120 checkFramebufferFetchSupport(ctx);
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);
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"
132 " fragColor = gl_LastFragData[0];\n"
135 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
136 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
137 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
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);
144 void last_frag_data_readonly (NegativeTestContext& ctx)
146 checkFramebufferFetchSupport(ctx);
148 map<string, string> args;
149 args["GLSL_VERSION_STRING"] = getGLSLVersionDeclaration(glu::GLSL_VERSION_100_ES);
151 const char* const fragShaderSource = "${GLSL_VERSION_STRING}\n"
152 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
156 " gl_LastFragData[0] = vec4(1.0);\n"
157 " gl_FragColor = gl_LastFragData[0];\n"
160 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
161 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
162 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
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);
169 void invalid_inout_version (NegativeTestContext& ctx)
171 checkFramebufferFetchSupport(ctx);
173 map<string, string> args;
174 args["GLSL_VERSION_STRING"] = getGLSLVersionDeclaration(glu::GLSL_VERSION_100_ES);
176 const char* const fragShaderSource = "${GLSL_VERSION_STRING}\n"
177 "#extension GL_EXT_shader_framebuffer_fetch : require\n"
178 "inout highp vec4 fragColor;\n"
182 " highp float product = dot(vec3(0.5), fragColor.rgb);\n"
183 " gl_FragColor = vec4(product);\n"
186 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
187 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
188 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
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);
195 void invalid_redeclaration_inout (NegativeTestContext& ctx)
197 checkFramebufferFetchSupport(ctx);
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);
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"
210 " gl_FragDepth += 0.5f;\n"
211 " fragColor = vec4(1.0f);\n"
214 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
215 << glu::VertexSource(tcu::StringTemplate(vertexShaderSource).specialize(args))
216 << glu::FragmentSource(tcu::StringTemplate(fragShaderSource).specialize(args)));
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);
223 void invalid_vertex_inout (NegativeTestContext& ctx)
225 checkFramebufferFetchSupport(ctx);
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);
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"
239 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
240 << glu::VertexSource(tcu::StringTemplate(vertShaderSource).specialize(args))
241 << glu::FragmentSource(tcu::StringTemplate(fragmentShaderSource).specialize(args)));
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);
250 std::vector<FunctionContainer> getNegativeShaderFramebufferFetchTestFunctions (void)
252 const FunctionContainer funcs[] =
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" },
261 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
264 } // NegativeTestShared