1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2015 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 Atomic Counter Tests
22 *//*--------------------------------------------------------------------*/
24 #include "es31fNegativeAtomicCounterTests.hpp"
26 #include "deUniquePtr.hpp"
28 #include "glwEnums.hpp"
29 #include "gluShaderProgram.hpp"
31 #include "tcuTestLog.hpp"
39 namespace NegativeTestShared
46 TESTCASE_LAYOUT_LARGE_BINDING = 0,
47 TESTCASE_LAYOUT_MEDIUMP_PRECISION,
48 TESTCASE_LAYOUT_LOWP_PRECISION,
49 TESTCASE_LAYOUT_BINDING_OFFSET_OVERLAP,
50 TESTCASE_LAYOUT_BINDING_OMITTED,
53 TESTCASE_BODY_DECLARE,
58 static const glu::ShaderType s_shaders[] =
60 glu::SHADERTYPE_VERTEX,
61 glu::SHADERTYPE_FRAGMENT,
62 glu::SHADERTYPE_GEOMETRY,
63 glu::SHADERTYPE_TESSELLATION_CONTROL,
64 glu::SHADERTYPE_TESSELLATION_EVALUATION,
65 glu::SHADERTYPE_COMPUTE
68 std::string genShaderSource (NegativeTestContext& ctx, TestCase test, glu::ShaderType type)
70 DE_ASSERT(test < TESTCASE_LAST && type < glu::SHADERTYPE_LAST);
72 glw::GLint maxBuffers = -1;
73 std::ostringstream shader;
75 ctx.glGetIntegerv(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &maxBuffers);
77 shader << getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES) << "\n";
81 case glu::SHADERTYPE_GEOMETRY:
82 shader << "#extension GL_EXT_geometry_shader : enable\n";
83 shader << "layout(max_vertices = 3) out;\n";
86 case glu::SHADERTYPE_TESSELLATION_CONTROL:
87 case glu::SHADERTYPE_TESSELLATION_EVALUATION:
88 shader << "#extension GL_EXT_tessellation_shader : enable\n";
97 case TESTCASE_LAYOUT_LARGE_BINDING:
98 shader << "layout (binding = " << maxBuffers << ", offset = 0) uniform atomic_uint counter0;\n";
101 case TESTCASE_LAYOUT_MEDIUMP_PRECISION:
102 shader << "layout (binding = 1, offset = 0) " << glu::getPrecisionName(glu::PRECISION_MEDIUMP) << " uniform atomic_uint counter0;\n";
105 case TESTCASE_LAYOUT_LOWP_PRECISION:
106 shader << "layout (binding = 1, offset = 0) " << glu::getPrecisionName(glu::PRECISION_LOWP) << " uniform atomic_uint counter0;\n";
109 case TESTCASE_LAYOUT_BINDING_OFFSET_OVERLAP:
110 shader << "layout (binding = 1, offset = 0) uniform atomic_uint counter0;\n"
111 << "layout (binding = 1, offset = 2) uniform atomic_uint counter1;\n";
114 case TESTCASE_LAYOUT_BINDING_OMITTED:
115 shader << "layout (offset = 0) uniform atomic_uint counter0;\n";
118 case TESTCASE_STRUCT:
122 << " atomic_uint counter;\n"
126 case TESTCASE_BODY_WRITE:
127 shader << "layout (binding = 1) uniform atomic_uint counter;\n";
134 shader << "void main (void)\n"
139 case TESTCASE_BODY_WRITE:
140 shader << "counter = 1;\n";
143 case TESTCASE_BODY_DECLARE:
144 shader << "atomic_uint counter;\n";
156 void iterateShaders (NegativeTestContext& ctx, TestCase testCase)
158 tcu::TestLog& log = ctx.getLog();
159 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaders); ndx++)
161 if (ctx.isShaderSupported(s_shaders[ndx]))
163 ctx.beginSection(std::string("Verify shader: ") + glu::getShaderTypeName(s_shaders[ndx]));
164 const glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources() << glu::ShaderSource(s_shaders[ndx], genShaderSource(ctx, testCase, s_shaders[ndx])));
165 if (program.getShaderInfo(s_shaders[ndx]).compileOk)
168 log << tcu::TestLog::Message << "Expected program to fail, but compilation passed." << tcu::TestLog::EndMessage;
169 ctx.fail("Shader was not expected to compile.");
176 void atomic_max_counter_bindings (NegativeTestContext& ctx)
178 ctx.beginSection("It is a compile-time error to bind an atomic counter with a binding value greater than or equal to gl_MaxAtomicCounterBindings.");
179 iterateShaders(ctx, TESTCASE_LAYOUT_LARGE_BINDING);
183 void atomic_precision (NegativeTestContext& ctx)
185 ctx.beginSection("It is an error to declare an atomic type with a lowp or mediump precision.");
186 iterateShaders(ctx, TESTCASE_LAYOUT_MEDIUMP_PRECISION);
187 iterateShaders(ctx, TESTCASE_LAYOUT_LOWP_PRECISION);
191 void atomic_binding_offset_overlap (NegativeTestContext& ctx)
193 ctx.beginSection("Atomic counters may not have overlapping offsets in the same binding.");
194 iterateShaders(ctx, TESTCASE_LAYOUT_BINDING_OFFSET_OVERLAP);
198 void atomic_binding_omitted (NegativeTestContext& ctx)
200 ctx.beginSection("Atomic counters must specify a binding point");
201 iterateShaders(ctx, TESTCASE_LAYOUT_BINDING_OMITTED);
205 void atomic_struct (NegativeTestContext& ctx)
207 ctx.beginSection("Structures may not have an atomic_uint variable.");
208 iterateShaders(ctx, TESTCASE_STRUCT);
212 void atomic_body_write (NegativeTestContext& ctx)
214 ctx.beginSection("An atomic_uint variable cannot be directly written to.");
215 iterateShaders(ctx, TESTCASE_BODY_WRITE);
219 void atomic_body_declare (NegativeTestContext& ctx)
221 ctx.beginSection("An atomic_uint variable cannot be declared in local scope");
222 iterateShaders(ctx, TESTCASE_BODY_DECLARE);
228 std::vector<FunctionContainer> getNegativeAtomicCounterTestFunctions ()
230 const FunctionContainer funcs[] =
232 {atomic_max_counter_bindings, "atomic_max_counter_bindings", "Invalid atomic counter buffer binding." },
233 {atomic_precision, "atomic_precision", "Invalid precision qualifier." },
234 {atomic_binding_offset_overlap, "atomic_binding_offset_overlap", "Invalid offset." },
235 {atomic_binding_omitted, "atomic_binding_omitted", "Binding not specified." },
236 {atomic_struct, "atomic_struct", "Invalid atomic_uint usage in struct." },
237 {atomic_body_write, "atomic_body_write", "Invalid write access to atomic_uint." },
238 {atomic_body_declare, "atomic_body_declare", "Invalid precision qualifier." },
241 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
244 } // NegativeTestShared