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 Compute tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es31fNegativeComputeTests.hpp"
25 #include "gluContextInfo.hpp"
26 #include "gluShaderProgram.hpp"
27 #include "glwDefs.hpp"
28 #include "glwEnums.hpp"
29 #include "tcuStringTemplate.hpp"
41 namespace NegativeTestShared
49 static const char* const vertexShaderSource = "${GLSL_VERSION_STRING}\n"
53 " gl_Position = vec4(0.0);\n"
56 static const char* const fragmentShaderSource = "${GLSL_VERSION_STRING}\n"
57 "precision mediump float;\n"
58 "layout(location = 0) out mediump vec4 fragColor;\n"
62 " fragColor = vec4(1.0);\n"
65 static const char* const computeShaderSource = "${GLSL_VERSION_STRING}\n"
66 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
71 static const char* const invalidComputeShaderSource = "${GLSL_VERSION_STRING}\n"
72 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
75 " highp uint var = -1;\n" // error
78 int getResourceLimit (NegativeTestContext& ctx, GLenum resource)
81 ctx.glGetIntegerv(resource, &limit);
86 void verifyLinkError (NegativeTestContext& ctx, const glu::ShaderProgram& program)
88 bool testFailed = false;
90 tcu::TestLog& log = ctx.getLog();
93 testFailed = program.getProgramInfo().linkOk;
97 const char* const message("Program was not expected to link.");
98 log << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
103 void verifyCompileError (NegativeTestContext& ctx, const glu::ShaderProgram& program, glu::ShaderType shaderType)
105 bool testFailed = false;
107 tcu::TestLog& log = ctx.getLog();
110 testFailed = program.getShaderInfo(shaderType).compileOk;
114 const char* const message("Program was not expected to compile.");
115 log << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
120 string generateComputeShader (NegativeTestContext& ctx, const string& shaderDeclarations, const string& shaderBody)
122 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
123 const char* const shaderVersion = isES32
124 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES)
125 : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
127 std::ostringstream compShaderSource;
129 compShaderSource << shaderVersion << "\n"
130 << "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
131 << shaderDeclarations << "\n"
132 << "void main (void)\n"
137 return compShaderSource.str();
140 string genBuiltInSource (glu::ShaderType shaderType)
142 std::ostringstream source;
143 source << "${GLSL_VERSION_STRING}\n";
147 case glu::SHADERTYPE_VERTEX:
148 case glu::SHADERTYPE_FRAGMENT:
151 case glu::SHADERTYPE_COMPUTE:
152 source << "layout (local_size_x = 1) in;\n";
155 case glu::SHADERTYPE_GEOMETRY:
156 source << "layout(points) in;\n"
157 << "layout(line_strip, max_vertices = 3) out;\n";
160 case glu::SHADERTYPE_TESSELLATION_CONTROL:
161 source << "${GLSL_TESS_EXTENSION_STRING}\n"
162 << "layout(vertices = 10) out;\n";
165 case glu::SHADERTYPE_TESSELLATION_EVALUATION:
166 source << "${GLSL_TESS_EXTENSION_STRING}\n"
167 << "layout(triangles) in;\n";
171 DE_FATAL("Unknown shader type");
176 << "void main(void)\n"
178 << "${COMPUTE_BUILT_IN_CONSTANTS_STRING}"
184 void exceed_uniform_block_limit (NegativeTestContext& ctx)
186 std::ostringstream shaderDecl;
187 std::ostringstream shaderBody;
189 shaderDecl << "layout(std140, binding = 0) uniform Block\n"
191 << " highp vec4 val;\n"
192 << "} block[" << getResourceLimit(ctx, GL_MAX_COMPUTE_UNIFORM_BLOCKS) + 1 << "];\n";
194 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
195 << glu::ComputeSource(generateComputeShader(ctx, shaderDecl.str(), shaderBody.str())));
197 ctx.beginSection("Link error is generated if a compute shader exceeds GL_MAX_COMPUTE_UNIFORM_BLOCKS.");
198 verifyLinkError(ctx, program);
202 void exceed_shader_storage_block_limit (NegativeTestContext& ctx)
204 std::ostringstream shaderDecl;
205 std::ostringstream shaderBody;
207 shaderDecl << "layout(std140, binding = 0) buffer Block\n"
209 << " highp vec4 val;\n"
210 << "} block[" << getResourceLimit(ctx, GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS) + 1 << "];\n";
212 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
213 << glu::ComputeSource(generateComputeShader(ctx, shaderDecl.str(), shaderBody.str())));
215 ctx.beginSection("Link error is generated if compute shader exceeds GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS.");
216 verifyLinkError(ctx, program);
220 void exceed_texture_image_units_limit (NegativeTestContext& ctx)
222 const int limit = getResourceLimit(ctx, GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS) + 1;
223 std::ostringstream shaderDecl;
224 std::ostringstream shaderBody;
226 shaderDecl << "layout(binding = 0) "
227 << "uniform highp sampler2D u_sampler[" << limit + 1 << "];\n"
229 << "layout(binding = 0) buffer Output {\n"
230 << " vec4 values[ " << limit + 1 << " ];\n"
233 for (int i = 0; i < limit + 1; ++i)
234 shaderBody << " sb_out.values[" << i << "] = texture(u_sampler[" << i << "], vec2(1.0f));\n";
236 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
237 << glu::ComputeSource(generateComputeShader(ctx, shaderDecl.str(), shaderBody.str())));
239 tcu::TestLog& log = ctx.getLog();
240 log << tcu::TestLog::Message << "Possible link error is generated if compute shader exceeds GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS." << tcu::TestLog::EndMessage;
243 if (program.getProgramInfo().linkOk)
245 log << tcu::TestLog::Message << "Quality Warning: program was not expected to link." << tcu::TestLog::EndMessage;
246 ctx.glUseProgram(program.getProgram());
247 ctx.expectError(GL_NO_ERROR);
249 ctx.beginSection("GL_INVALID_OPERATION error is generated if the sum of the number of active samplers for each active program exceeds the maximum number of texture image units allowed");
250 ctx.glDispatchCompute(1, 1, 1);
251 ctx.expectError(GL_INVALID_VALUE);
256 void exceed_image_uniforms_limit (NegativeTestContext& ctx)
258 const int limit = getResourceLimit(ctx, GL_MAX_COMPUTE_IMAGE_UNIFORMS);
259 std::ostringstream shaderDecl;
260 std::ostringstream shaderBody;
262 shaderDecl << "layout(rgba8, binding = 0) "
263 << "uniform readonly highp image2D u_image[" << limit + 1 << "];\n"
265 << "layout(binding = 0) buffer Output {\n"
266 << " float values[" << limit + 1 << "];\n"
269 for (int i = 0; i < limit + 1; ++i)
270 shaderBody << " sb_out.values[" << i << "]" << " = imageLoad(u_image[" << i << "], ivec2(gl_GlobalInvocationID.xy)).x;\n";
272 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
273 << glu::ComputeSource(generateComputeShader(ctx, shaderDecl.str(), shaderBody.str())));
275 ctx.beginSection("Link error is generated if compute shader exceeds GL_MAX_COMPUTE_IMAGE_UNIFORMS.");
276 verifyLinkError(ctx, program);
280 void exceed_shared_memory_size_limit (NegativeTestContext& ctx)
282 const int limit = getResourceLimit(ctx, GL_MAX_COMPUTE_SHARED_MEMORY_SIZE);
283 const long numberOfElements = limit / sizeof(GLuint);
284 std::ostringstream shaderDecl;
285 std::ostringstream shaderBody;
287 shaderDecl << "shared uint values[" << numberOfElements + 1 << "];\n"
289 << "layout(binding = 0) buffer Output {\n"
293 shaderBody << " sb_out.values = values[" << numberOfElements << "];\n";
295 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
296 << glu::ComputeSource(generateComputeShader(ctx, shaderDecl.str(), shaderBody.str())));
298 ctx.beginSection("Link error is generated if compute shader exceeds GL_MAX_COMPUTE_SHARED_MEMORY_SIZE.");
299 verifyLinkError(ctx, program);
303 void exceed_uniform_components_limit (NegativeTestContext& ctx)
305 const int limit = getResourceLimit(ctx, GL_MAX_COMPUTE_UNIFORM_COMPONENTS);
306 std::ostringstream shaderDecl;
307 std::ostringstream shaderBody;
309 shaderDecl << "uniform highp uint u_value[" << limit + 1 << "];\n"
311 << "layout(binding = 0) buffer Output {\n"
312 << " uint values[2];\n"
315 shaderBody << " sb_out.values[0] = u_value[" << limit << "];\n";
316 shaderBody << " sb_out.values[1] = u_value[0];\n";
318 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
319 << glu::ComputeSource(generateComputeShader(ctx, shaderDecl.str(), shaderBody.str())));
321 ctx.beginSection("Link error is generated if compute shader exceeds GL_MAX_COMPUTE_UNIFORM_COMPONENTS.");
322 verifyLinkError(ctx, program);
326 void exceed_atomic_counter_buffer_limit (NegativeTestContext& ctx)
328 const int limit = getResourceLimit(ctx, GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS);
329 std::ostringstream shaderDecl;
330 std::ostringstream shaderBody;
332 for (int i = 0; i < limit + 1; ++i)
334 shaderDecl << "layout(binding = " << i << ") "
335 << "uniform atomic_uint u_atomic" << i << ";\n";
338 shaderBody << " uint oldVal = atomicCounterIncrement(u_atomic" << i << ");\n";
340 shaderBody << " oldVal = atomicCounterIncrement(u_atomic" << i << ");\n";
343 shaderBody << " sb_out.value = oldVal;\n";
346 << "layout(binding = 0) buffer Output {\n"
350 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
351 << glu::ComputeSource(generateComputeShader(ctx, shaderDecl.str(), shaderBody.str())));
353 ctx.beginSection("Link error is generated if compute shader exceeds GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS.");
354 verifyLinkError(ctx, program);
358 void exceed_atomic_counters_limit (NegativeTestContext& ctx)
360 std::ostringstream shaderDecl;
361 std::ostringstream shaderBody;
363 shaderDecl << "layout(binding = 0, offset = 0) uniform atomic_uint u_atomic0;\n"
364 << "layout(binding = " << sizeof(GLuint) * getResourceLimit(ctx, GL_MAX_COMPUTE_ATOMIC_COUNTERS) << ", offset = 0) uniform atomic_uint u_atomic1;\n"
366 << "layout(binding = 0) buffer Output {\n"
370 shaderBody << " uint oldVal = 0u;\n"
371 << " oldVal = atomicCounterIncrement(u_atomic0);\n"
372 << " oldVal = atomicCounterIncrement(u_atomic1);\n"
373 << " sb_out.value = oldVal;\n";
375 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources()
376 << glu::ComputeSource(generateComputeShader(ctx, shaderDecl.str(), shaderBody.str())));
378 ctx.beginSection("Link error is generated if compute shader exceeds GL_MAX_COMPUTE_ATOMIC_COUNTERS.");
379 verifyLinkError(ctx, program);
383 void program_not_active (NegativeTestContext& ctx)
385 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
386 map<string, string> args;
387 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
389 const glu::VertexSource vertSource(tcu::StringTemplate(vertexShaderSource).specialize(args));
390 const glu::FragmentSource fragSource(tcu::StringTemplate(fragmentShaderSource).specialize(args));
392 glu::ProgramPipeline pipeline(ctx.getRenderContext());
394 glu::ShaderProgram vertProgram (ctx.getRenderContext(), glu::ProgramSources() << glu::ProgramSeparable(true) << vertSource);
395 glu::ShaderProgram fragProgram (ctx.getRenderContext(), glu::ProgramSources() << glu::ProgramSeparable(true) << fragSource);
397 tcu::TestLog& log = ctx.getLog();
398 log << vertProgram << fragProgram;
400 if (!vertProgram.isOk() || !fragProgram.isOk())
401 TCU_THROW(InternalError, "failed to build program");
403 ctx.glBindProgramPipeline(pipeline.getPipeline());
404 ctx.expectError(GL_NO_ERROR);
406 ctx.beginSection("Program not set at all");
408 ctx.beginSection("GL_INVALID_OPERATION is generated by glDispatchCompute if there is no active program for the compute shader stage.");
409 ctx.glDispatchCompute(1, 1, 1);
410 ctx.expectError(GL_INVALID_OPERATION);
413 ctx.beginSection("GL_INVALID_OPERATION is generated by glDispatchComputeIndirect if there is no active program for the compute shader stage.");
414 GLintptr indirect = 0;
415 ctx.glDispatchComputeIndirect(indirect);
416 ctx.expectError(GL_INVALID_OPERATION);
421 ctx.beginSection("Program contains graphic pipeline stages");
423 ctx.glUseProgramStages(pipeline.getPipeline(), GL_VERTEX_SHADER_BIT, vertProgram.getProgram());
424 ctx.glUseProgramStages(pipeline.getPipeline(), GL_FRAGMENT_SHADER_BIT, fragProgram.getProgram());
425 ctx.expectError(GL_NO_ERROR);
427 ctx.beginSection("GL_INVALID_OPERATION is generated by glDispatchCompute if there is no active program for the compute shader stage.");
428 ctx.glDispatchCompute(1, 1, 1);
429 ctx.expectError(GL_INVALID_OPERATION);
432 ctx.beginSection("GL_INVALID_OPERATION is generated by glDispatchComputeIndirect if there is no active program for the compute shader stage.");
433 GLintptr indirect = 0;
434 ctx.glDispatchComputeIndirect(indirect);
435 ctx.expectError(GL_INVALID_OPERATION);
440 ctx.glBindProgramPipeline(0);
441 ctx.expectError(GL_NO_ERROR);
444 void invalid_program_query (NegativeTestContext& ctx)
446 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
447 map<string, string> args;
448 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
450 GLint data[3] = { 0, 0, 0 };
452 ctx.beginSection("Compute shader that does not link");
454 const glu::ComputeSource compSource(tcu::StringTemplate(invalidComputeShaderSource).specialize(args));
455 glu::ShaderProgram invalidComputeProgram (ctx.getRenderContext(), glu::ProgramSources() << compSource);
457 tcu::TestLog& log = ctx.getLog();
458 log << invalidComputeProgram;
460 if (invalidComputeProgram.isOk())
461 TCU_THROW(InternalError, "program should not of built");
463 ctx.beginSection("GL_INVALID_OPERATION is generated if GL_COMPUTE_WORK_GROUP_SIZE is queried for a program which has not been linked properly.");
464 ctx.glGetProgramiv(invalidComputeProgram.getProgram(), GL_COMPUTE_WORK_GROUP_SIZE, &data[0]);
465 ctx.expectError(GL_INVALID_OPERATION);
472 ctx.beginSection("Compute shader not present");
474 const glu::VertexSource vertSource(tcu::StringTemplate(vertexShaderSource).specialize(args));
475 const glu::FragmentSource fragSource(tcu::StringTemplate(fragmentShaderSource).specialize(args));
476 glu::ShaderProgram graphicsPipelineProgram (ctx.getRenderContext(), glu::ProgramSources() << vertSource << fragSource);
478 tcu::TestLog& log = ctx.getLog();
479 log << graphicsPipelineProgram;
481 if (!graphicsPipelineProgram.isOk())
482 TCU_THROW(InternalError, "failed to build program");
484 ctx.beginSection("GL_INVALID_OPERATION is generated if GL_COMPUTE_WORK_GROUP_SIZE is queried for a program which has not been linked properly.");
485 ctx.glGetProgramiv(graphicsPipelineProgram.getProgram(), GL_COMPUTE_WORK_GROUP_SIZE, &data[0]);
486 ctx.expectError(GL_INVALID_OPERATION);
494 void invalid_dispatch_compute_indirect (NegativeTestContext& ctx)
496 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
497 map<string, string> args;
498 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
500 const glu::ComputeSource compSource(tcu::StringTemplate(computeShaderSource).specialize(args));
501 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources() << compSource);
503 tcu::TestLog& log = ctx.getLog();
507 TCU_THROW(InternalError, "failed to build program");
509 ctx.glUseProgram(program.getProgram());
510 ctx.expectError(GL_NO_ERROR);
521 ctx.glGenBuffers(1, &buffer);
522 ctx.glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0);
523 ctx.expectError(GL_NO_ERROR);
525 ctx.beginSection("GL_INVALID_OPERATION is generated by glDispatchComputeIndirect if zero is bound to GL_DISPATCH_INDIRECT_BUFFER.");
526 GLintptr indirect = 0;
527 ctx.glDispatchComputeIndirect(indirect);
528 ctx.expectError(GL_INVALID_OPERATION);
531 ctx.glDeleteBuffers(1, &buffer);
536 ctx.glGenBuffers(1, &buffer);
537 ctx.expectError(GL_NO_ERROR);
539 ctx.glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, buffer);
540 ctx.expectError(GL_NO_ERROR);
542 ctx.glBufferData(GL_DISPATCH_INDIRECT_BUFFER, sizeof(data), &data, GL_STATIC_DRAW);
543 ctx.expectError(GL_NO_ERROR);
545 ctx.beginSection("GL_INVALID_OPERATION is generated by glDispatchComputeIndirect if data is sourced beyond the end of the buffer object.");
546 GLintptr indirect = 1 << 10;
547 ctx.glDispatchComputeIndirect(indirect);
548 ctx.expectError(GL_INVALID_OPERATION);
551 ctx.glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0);
552 ctx.glDeleteBuffers(1, &buffer);
556 ctx.beginSection("GL_INVALID_VALUE is generated by glDispatchComputeIndirect if the value of indirect is less than zero.");
557 GLintptr indirect = -1;
558 ctx.glDispatchComputeIndirect(indirect);
559 ctx.expectError(GL_INVALID_VALUE);
565 ctx.glGenBuffers(1, &buffer);
566 ctx.expectError(GL_NO_ERROR);
568 ctx.glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, buffer);
569 ctx.expectError(GL_NO_ERROR);
571 ctx.glBufferData(GL_DISPATCH_INDIRECT_BUFFER, sizeof(data), &data, GL_STATIC_DRAW);
572 ctx.expectError(GL_NO_ERROR);
574 ctx.beginSection("GL_INVALID_VALUE is generated by glDispatchComputeIndirect if indirect is not a multiple of the size, in basic machine units, of uint.");
575 GLintptr indirect = sizeof(data) + 1;
576 ctx.glDispatchComputeIndirect(indirect);
577 ctx.expectError(GL_INVALID_VALUE);
580 ctx.glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0);
581 ctx.glDeleteBuffers(1, &buffer);
585 void invalid_maximum_work_group_counts (NegativeTestContext& ctx)
587 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
588 map<string, string> args;
589 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
591 const glu::ComputeSource compSource(tcu::StringTemplate(computeShaderSource).specialize(args));
592 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources() << compSource);
594 tcu::TestLog& log = ctx.getLog();
598 TCU_THROW(InternalError, "failed to build program");
600 ctx.glUseProgram(program.getProgram());
601 ctx.expectError(GL_NO_ERROR);
603 GLint workGroupCountX;
604 ctx.glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, (GLuint)0, &workGroupCountX);
605 ctx.expectError(GL_NO_ERROR);
607 ctx.beginSection("GL_INVALID_VALUE is generated by glDispatchCompute if <numGroupsX> array is larger than the maximum work group count for the x dimension.");
608 ctx.glDispatchCompute(workGroupCountX+1, 1, 1);
609 ctx.expectError(GL_INVALID_VALUE);
612 GLint workGroupCountY;
613 ctx.glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, (GLuint)1, &workGroupCountY);
614 ctx.expectError(GL_NO_ERROR);
616 ctx.beginSection("GL_INVALID_VALUE is generated by glDispatchCompute if <numGroupsY> array is larger than the maximum work group count for the y dimension.");
617 ctx.glDispatchCompute(1, workGroupCountY+1, 1);
618 ctx.expectError(GL_INVALID_VALUE);
621 GLint workGroupCountZ;
622 ctx.glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, (GLuint)2, &workGroupCountZ);
623 ctx.expectError(GL_NO_ERROR);
625 ctx.beginSection("GL_INVALID_VALUE is generated by glDispatchCompute if <numGroupsZ> array is larger than the maximum work group count for the z dimension.");
626 ctx.glDispatchCompute(1, 1, workGroupCountZ+1);
627 ctx.expectError(GL_INVALID_VALUE);
631 void invalid_maximum_work_group_sizes (NegativeTestContext& ctx)
633 GLint maxWorkGroupSizeX;
634 ctx.glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, (GLuint)0, &maxWorkGroupSizeX);
635 ctx.expectError(GL_NO_ERROR);
637 GLint maxWorkGroupSizeY;
638 ctx.glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, (GLuint)1, &maxWorkGroupSizeY);
639 ctx.expectError(GL_NO_ERROR);
641 GLint maxWorkGroupSizeZ;
642 ctx.glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, (GLuint)2, &maxWorkGroupSizeZ);
643 ctx.expectError(GL_NO_ERROR);
645 GLint maxWorkGroupInvocations;
646 ctx.glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, &maxWorkGroupInvocations);
647 ctx.expectError(GL_NO_ERROR);
649 DE_ASSERT((maxWorkGroupSizeX * maxWorkGroupSizeY * maxWorkGroupSizeZ) > maxWorkGroupInvocations );
651 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
652 const char* const shaderVersion = isES32
653 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES)
654 : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
661 } localWorkGroupSizeCases[] =
663 { maxWorkGroupSizeX+1, 1, 1 },
664 { 1, maxWorkGroupSizeY+1, 1 },
665 { 1, 1, maxWorkGroupSizeZ+1 },
666 { maxWorkGroupSizeX, maxWorkGroupSizeY, maxWorkGroupSizeZ },
669 for (int testCase = 0; testCase < DE_LENGTH_OF_ARRAY(localWorkGroupSizeCases); ++testCase)
671 std::ostringstream compShaderSource;
673 compShaderSource << shaderVersion << "\n"
674 << "layout(local_size_x = " << localWorkGroupSizeCases[testCase].x << ", local_size_y = " << localWorkGroupSizeCases[testCase].y << ", local_size_z = " << localWorkGroupSizeCases[testCase].z << ") in;\n"
675 << "void main (void)\n"
679 const glu::ComputeSource compSource(compShaderSource.str());
680 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources() << compSource);
682 if (testCase == DE_LENGTH_OF_ARRAY(localWorkGroupSizeCases)-1)
684 bool testFailed = false;
685 ctx.beginSection("A compile time or link error is generated if the maximum number of invocations in a single local work group (product of the three dimensions) is greater than GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS.");
687 ctx.getLog() << program;
688 testFailed = (program.getProgramInfo().linkOk) && (program.getShaderInfo(glu::SHADERTYPE_COMPUTE).compileOk);
692 const char* const message("Program was not expected to compile or link.");
693 ctx.getLog() << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
699 ctx.beginSection("A compile time error is generated if the fixed local group size of the shader in any dimension is greater than the maximum supported.");
700 verifyCompileError(ctx, program, glu::SHADERTYPE_COMPUTE);
707 void invalid_layout_qualifiers (NegativeTestContext& ctx)
709 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
710 const char* const shaderVersion = isES32
711 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES)
712 : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
715 std::ostringstream compShaderSource;
716 compShaderSource << shaderVersion << "\n"
717 << "void main (void)\n"
721 const glu::ComputeSource compSource(compShaderSource.str());
722 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources() << compSource);
724 ctx.beginSection("A link error is generated if the compute shader program does not contain an input layout qualifier specifying a fixed local group size.");
725 verifyLinkError(ctx, program);
730 std::ostringstream compShaderSource;
731 compShaderSource << shaderVersion << "\n"
732 << "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
733 << "layout(local_size_x = 2, local_size_y = 2, local_size_z = 2) in;\n"
734 << "void main (void)\n"
738 const glu::ComputeSource compSource(compShaderSource.str());
739 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources() << compSource);
741 ctx.beginSection("A compile-time error is generated if a local work group size qualifier is declared more than once in the same shader.");
742 verifyCompileError(ctx, program, glu::SHADERTYPE_COMPUTE);
747 std::ostringstream compShaderSource;
748 compShaderSource << shaderVersion << "\n"
749 << "out mediump vec4 fragColor;\n"
751 << "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
752 << "void main (void)\n"
756 const glu::ComputeSource compSource(compShaderSource.str());
757 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources() << compSource);
759 ctx.beginSection("A compile-time error is generated if a user defined output variable is declared in a compute shader.");
760 verifyCompileError(ctx, program, glu::SHADERTYPE_COMPUTE);
765 std::ostringstream compShaderSource;
766 compShaderSource << shaderVersion << "\n"
767 << "uvec3 gl_NumWorkGroups;\n"
768 << "uvec3 gl_WorkGroupSize;\n"
769 << "uvec3 gl_WorkGroupID;\n"
770 << "uvec3 gl_LocalInvocationID;\n"
771 << "uvec3 gl_GlobalInvocationID;\n"
772 << "uvec3 gl_LocalInvocationIndex;\n"
774 << "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
775 << "void main (void)\n"
779 const glu::ComputeSource compSource(compShaderSource.str());
780 glu::ShaderProgram program(ctx.getRenderContext(), glu::ProgramSources() << compSource);
782 ctx.beginSection("A compile time or link error is generated if compute shader built-in variables are redeclared.");
783 bool testFailed = false;
785 tcu::TestLog& log = ctx.getLog();
788 testFailed = (program.getProgramInfo().linkOk) && (program.getShaderInfo(glu::SHADERTYPE_COMPUTE).compileOk);
792 const char* const message("Program was not expected to compile or link.");
793 log << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
801 void invalid_write_built_in_constants (NegativeTestContext& ctx)
803 if ((!ctx.isExtensionSupported("GL_EXT_tessellation_shader") && !ctx.isExtensionSupported("GL_OES_tessellation_shader")) ||
804 (!ctx.isExtensionSupported("GL_EXT_geometry_shader") && !ctx.isExtensionSupported("GL_OES_geometry_shader")))
806 TCU_THROW(NotSupportedError, "tessellation and geometry shader extensions not supported");
809 const bool isES32 = glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
810 map<string, string> args;
812 args["GLSL_VERSION_STRING"] = isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
813 args["GLSL_TESS_EXTENSION_STRING"] = isES32 ? "" : "#extension GL_EXT_tessellation_shader : require";
814 args["COMPUTE_BUILT_IN_CONSTANTS_STRING"] = " gl_MaxComputeWorkGroupCount = ivec3(65535, 65535, 65535);\n"
815 " gl_MaxComputeWorkGroupCount = ivec3(1024, 1024, 64);\n"
816 " gl_MaxComputeWorkGroupSize = ivec3(512);\n"
817 " gl_MaxComputeUniformComponents = 512;\n"
818 " gl_MaxComputeTextureImageUnits = 16;\n"
819 " gl_MaxComputeImageUniforms = 8;\n"
820 " gl_MaxComputeAtomicCounters = 8;\n"
821 " gl_MaxComputeAtomicCounterBuffers = 1;\n";
823 const glu::VertexSource vertSource (tcu::StringTemplate(genBuiltInSource(glu::SHADERTYPE_VERTEX)).specialize(args));
824 const glu::FragmentSource fragSource (tcu::StringTemplate(genBuiltInSource(glu::SHADERTYPE_FRAGMENT)).specialize(args));
825 const glu::TessellationControlSource tessCtrlSource (tcu::StringTemplate(genBuiltInSource(glu::SHADERTYPE_TESSELLATION_CONTROL)).specialize(args));
826 const glu::TessellationEvaluationSource tessEvalSource (tcu::StringTemplate(genBuiltInSource(glu::SHADERTYPE_TESSELLATION_EVALUATION)).specialize(args));
827 const glu::GeometrySource geometrySource (tcu::StringTemplate(genBuiltInSource(glu::SHADERTYPE_GEOMETRY)).specialize(args));
828 const glu::ComputeSource computeSource (tcu::StringTemplate(genBuiltInSource(glu::SHADERTYPE_COMPUTE)).specialize(args));
830 glu::ShaderProgram vertProgram (ctx.getRenderContext(), glu::ProgramSources() << glu::ProgramSeparable(true) << vertSource);
831 glu::ShaderProgram fragProgram (ctx.getRenderContext(), glu::ProgramSources() << glu::ProgramSeparable(true) << fragSource);
832 glu::ShaderProgram tessCtrlProgram (ctx.getRenderContext(), glu::ProgramSources() << glu::ProgramSeparable(true) << tessCtrlSource);
833 glu::ShaderProgram tessEvalProgram (ctx.getRenderContext(), glu::ProgramSources() << glu::ProgramSeparable(true) << tessEvalSource);
834 glu::ShaderProgram geometryProgram (ctx.getRenderContext(), glu::ProgramSources() << glu::ProgramSeparable(true) << geometrySource);
835 glu::ShaderProgram computeProgram (ctx.getRenderContext(), glu::ProgramSources() << glu::ProgramSeparable(true) << computeSource);
837 ctx.beginSection("A compile time is generated if compute built-in constants provided in all shaders are written to.");
838 verifyCompileError(ctx, vertProgram, glu::SHADERTYPE_VERTEX);
839 verifyCompileError(ctx, fragProgram, glu::SHADERTYPE_FRAGMENT);
840 verifyCompileError(ctx, tessCtrlProgram, glu::SHADERTYPE_TESSELLATION_CONTROL);
841 verifyCompileError(ctx, tessEvalProgram, glu::SHADERTYPE_TESSELLATION_EVALUATION);
842 verifyCompileError(ctx, geometryProgram, glu::SHADERTYPE_GEOMETRY);
843 verifyCompileError(ctx, computeProgram, glu::SHADERTYPE_COMPUTE);
849 std::vector<FunctionContainer> getNegativeComputeTestFunctions (void)
851 const FunctionContainer funcs[] =
853 { program_not_active, "program_not_active", "Use dispatch commands with no active program" },
854 { invalid_program_query, "invalid_program_query", "Querying GL_COMPUTE_WORK_GROUP_SIZE with glGetProgramiv() on invalid programs" },
855 { invalid_dispatch_compute_indirect, "invalid_dispatch_compute_indirect", "Invalid glDispatchComputeIndirect usage" },
856 { invalid_maximum_work_group_counts, "invalid_maximum_work_group_counts", "Maximum workgroup counts for dispatch commands" },
857 { invalid_maximum_work_group_sizes, "invalid_maximum_work_group_sizes", "Maximum local workgroup sizes declared in compute shaders" },
858 { invalid_layout_qualifiers, "invalid_layout_qualifiers", "Invalid layout qualifiers in compute shaders" },
859 { invalid_write_built_in_constants, "invalid_write_built_in_constants", "Invalid writes to built-in compute shader constants" },
860 { exceed_uniform_block_limit, "exceed_uniform_block_limit", "Link error when shader exceeds GL_MAX_COMPUTE_UNIFORM_BLOCKS" },
861 { exceed_shader_storage_block_limit, "exceed_shader_storage_block_limit", "Link error when shader exceeds GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS" },
862 { exceed_texture_image_units_limit, "exceed_texture_image_units_limit", "Link error when shader exceeds GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS" },
863 { exceed_image_uniforms_limit, "exceed_image_uniforms_limit", "Link error when shader exceeds GL_MAX_COMPUTE_IMAGE_UNIFORMS" },
864 { exceed_shared_memory_size_limit, "exceed_shared_memory_size_limit", "Link error when shader exceeds GL_MAX_COMPUTE_SHARED_MEMORY_SIZE" },
865 { exceed_uniform_components_limit, "exceed_uniform_components_limit", "Link error when shader exceeds GL_MAX_COMPUTE_UNIFORM_COMPONENTS" },
866 { exceed_atomic_counter_buffer_limit, "exceed_atomic_counter_buffer_limit", "Link error when shader exceeds GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS" },
867 { exceed_atomic_counters_limit, "exceed_atomic_counters_limit", "Link error when shader exceeds GL_MAX_COMPUTE_ATOMIC_COUNTERS" },
870 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
873 } // NegativeTestShared