1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2016 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 Shader Directive Tests
22 *//*--------------------------------------------------------------------*/
24 #include "es31fNegativeShaderDirectiveTests.hpp"
26 #include "gluShaderProgram.hpp"
34 namespace NegativeTestShared
41 EXPECT_RESULT_PASS = 0,
47 void verifyProgram(NegativeTestContext& ctx, glu::ProgramSources sources, ExpectResult expect)
49 DE_ASSERT(expect >= EXPECT_RESULT_PASS && expect < EXPECT_RESULT_LAST);
51 tcu::TestLog& log = ctx.getLog();
52 const glu::ShaderProgram program (ctx.getRenderContext(), sources);
53 bool testFailed = false;
58 if (expect == EXPECT_RESULT_PASS)
60 testFailed = !program.getProgramInfo().linkOk;
61 message = "Program did not link.";
65 testFailed = program.getProgramInfo().linkOk;
66 message = "Program was not expected to link.";
71 log << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
76 void verifyShader(NegativeTestContext& ctx, glu::ShaderType shaderType, std::string shaderSource, ExpectResult expect)
78 DE_ASSERT(expect >= EXPECT_RESULT_PASS && expect < EXPECT_RESULT_LAST);
80 tcu::TestLog& log = ctx.getLog();
81 bool testFailed = false;
82 const char* const source = shaderSource.c_str();
83 const int length = (int) shaderSource.size();
84 glu::Shader shader (ctx.getRenderContext(), shaderType);
87 shader.setSources(1, &source, &length);
92 if (expect == EXPECT_RESULT_PASS)
94 testFailed = !shader.getCompileStatus();
95 message = "Shader did not compile.";
99 testFailed = shader.getCompileStatus();
100 message = "Shader was not expected to compile.";
105 log << tcu::TestLog::Message << message << tcu::TestLog::EndMessage;
110 void primitive_bounding_box (NegativeTestContext& ctx)
112 if (ctx.isShaderSupported(glu::SHADERTYPE_TESSELLATION_CONTROL))
114 ctx.beginSection("GL_EXT_primitive_bounding_box features require enabling the extension in 310 es shaders.");
115 std::ostringstream source;
116 source << "#version 310 es\n"
119 " gl_BoundingBoxEXT[0] = vec4(0.0, 0.0, 0.0, 0.0);\n"
120 " gl_BoundingBoxEXT[1] = vec4(1.0, 1.0, 1.0, 1.0);\n"
122 verifyShader(ctx, glu::SHADERTYPE_TESSELLATION_CONTROL, source.str(), EXPECT_RESULT_FAIL);
126 if (contextSupports(ctx.getRenderContext().getType() , glu::ApiType::es(3, 2)))
128 ctx.beginSection("gl_BoundingBox does not require the OES/EXT suffix in a 320 es shader.");
130 const std::string source = "#version 320 es\n"
131 "layout(vertices = 3) out;\n"
134 " gl_BoundingBox[0] = vec4(0.0, 0.0, 0.0, 0.0);\n"
135 " gl_BoundingBox[1] = vec4(0.0, 0.0, 0.0, 0.0);\n"
137 verifyShader(ctx, glu::SHADERTYPE_TESSELLATION_CONTROL, source, EXPECT_RESULT_PASS);
141 ctx.beginSection("Invalid index used when assigning to gl_BoundingBox in 320 es shader.");
143 const std::string source = "#version 320 es\n"
144 "layout(vertices = 3) out;\n"
147 " gl_BoundingBox[0] = vec4(0.0, 0.0, 0.0, 0.0);\n"
148 " gl_BoundingBox[2] = vec4(0.0, 0.0, 0.0, 0.0);\n"
150 verifyShader(ctx, glu::SHADERTYPE_TESSELLATION_CONTROL, source, EXPECT_RESULT_FAIL);
154 ctx.beginSection("Invalid type assignment to per-patch output array in 320 es shader.");
156 const std::string source = "#version 320 es\n"
157 "layout(vertices = 3) out;\n"
160 " gl_BoundingBox[0] = ivec4(0, 0, 0, 0);\n"
161 " gl_BoundingBox[1] = ivec4(0, 0, 0, 0);\n"
163 verifyShader(ctx, glu::SHADERTYPE_TESSELLATION_CONTROL, source, EXPECT_RESULT_FAIL);
169 void blend_equation_advanced (NegativeTestContext& ctx)
171 static const char* const s_qualifiers[] =
173 "blend_support_multiply",
174 "blend_support_screen",
175 "blend_support_overlay",
176 "blend_support_darken",
177 "blend_support_lighten",
178 "blend_support_colordodge",
179 "blend_support_colorburn",
180 "blend_support_hardlight",
181 "blend_support_softlight",
182 "blend_support_difference",
183 "blend_support_exclusion",
184 "blend_support_hsl_hue",
185 "blend_support_hsl_saturation",
186 "blend_support_hsl_color",
187 "blend_support_hsl_luminosity",
190 ctx.beginSection("GL_KHR_blend_equation_advanced features require enabling the extension in 310 es shaders.");
191 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_qualifiers); ++ndx)
193 std::ostringstream source;
194 source << "#version 310 es\n"
195 "layout(" << s_qualifiers[ndx] << ") out;\n"
199 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
204 void sample_variables (NegativeTestContext& ctx)
206 TCU_CHECK_AND_THROW(NotSupportedError, contextSupports(ctx.getRenderContext().getType() , glu::ApiType::es(3, 2)), "Test requires a context version 3.2 or higher.");
208 static const char* const s_tests[] =
210 "int sampleId = gl_SampleID;",
211 "vec2 samplePos = gl_SamplePosition;",
212 "int sampleMaskIn0 = gl_SampleMaskIn[0];",
213 "int sampleMask0 = gl_SampleMask[0];",
214 "int numSamples = gl_NumSamples;",
217 ctx.beginSection("GL_OES_sample_variables features require enabling the extension in 310 es shaders.");
218 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_tests); ++ndx)
220 std::ostringstream source;
221 source << "#version 310 es\n"
222 "precision mediump float;\n"
225 " " << s_tests[ndx] << "\n"
227 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
232 void shader_image_atomic (NegativeTestContext& ctx)
234 static const char* const s_tests[] =
236 "imageAtomicAdd(u_image, ivec2(1, 1), 1u);",
237 "imageAtomicMin(u_image, ivec2(1, 1), 1u);",
238 "imageAtomicMax(u_image, ivec2(1, 1), 1u);",
239 "imageAtomicAnd(u_image, ivec2(1, 1), 1u);",
240 "imageAtomicOr(u_image, ivec2(1, 1), 1u);",
241 "imageAtomicXor(u_image, ivec2(1, 1), 1u);",
242 "imageAtomicExchange(u_image, ivec2(1, 1), 1u);",
243 "imageAtomicCompSwap(u_image, ivec2(1, 1), 1u, 1u);",
246 ctx.beginSection("GL_OES_shader_image_atomic features require enabling the extension in 310 es shaders.");
247 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_tests); ++ndx)
249 std::ostringstream source;
250 source << "#version 310 es\n"
251 "layout(binding=0, r32ui) coherent uniform highp uimage2D u_image;\n"
252 "precision mediump float;\n"
255 " " << s_tests[ndx] << "\n"
257 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
262 void shader_multisample_interpolation (NegativeTestContext& ctx)
264 static const char* const s_sampleTests[] =
266 "sample in highp float v_var;",
267 "sample out highp float v_var;"
270 static const char* const s_interpolateAtTests[] =
272 "interpolateAtCentroid(interpolant);",
273 "interpolateAtSample(interpolant, 1);",
274 "interpolateAtOffset(interpolant, vec2(1.0, 0.0));"
277 ctx.beginSection("GL_OES_shader_multisample_interpolation features require enabling the extension in 310 es shaders.");
278 ctx.beginSection("Test sample in/out qualifiers.");
279 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_sampleTests); ++ndx)
281 std::ostringstream source;
282 source << "#version 310 es\n"
283 " " << s_sampleTests[ndx] << "\n"
284 "precision mediump float;\n"
288 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
292 ctx.beginSection("Test interpolateAt* functions.");
293 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_sampleTests); ++ndx)
295 std::ostringstream source;
296 source << "#version 310 es\n"
297 "in mediump float interpolant;\n"
298 "precision mediump float;\n"
301 " " << s_interpolateAtTests[ndx] << "\n"
303 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
309 void texture_storage_multisample_2d_array (NegativeTestContext& ctx)
311 static const char* const s_samplerTypeTests[] =
313 "uniform mediump sampler2DMSArray u_sampler;",
314 "uniform mediump isampler2DMSArray u_sampler;",
315 "uniform mediump usampler2DMSArray u_sampler;",
318 ctx.beginSection("GL_OES_texture_storage_multisample_2d_array features require enabling the extension in 310 es shaders.");
319 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_samplerTypeTests); ++ndx)
321 std::ostringstream source;
322 source << "#version 310 es\n"
323 " " << s_samplerTypeTests[ndx] << "\n"
324 "precision mediump float;\n"
328 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
333 void geometry_shader (NegativeTestContext& ctx)
335 if (ctx.isShaderSupported(glu::SHADERTYPE_GEOMETRY))
337 const std::string simpleVtxFrag = "#version 310 es\n"
341 const std::string geometry = "#version 310 es\n"
342 "layout(points, invocations = 1) in;\n"
343 "layout(points, max_vertices = 3) out;\n"
344 "precision mediump float;\n"
350 ctx.beginSection("GL_EXT_geometry_shader features require enabling the extension in 310 es shaders.");
351 verifyProgram(ctx, glu::ProgramSources() << glu::VertexSource(simpleVtxFrag) << glu::GeometrySource(geometry) << glu::FragmentSource(simpleVtxFrag), EXPECT_RESULT_FAIL);
356 void gpu_shader_5 (NegativeTestContext& ctx)
358 ctx.beginSection("GL_EXT_gpu_shader5 features require enabling the extension in 310 es shaders.");
359 ctx.beginSection("Testing the precise qualifier.");
361 std::ostringstream source;
362 source << "#version 310 es\n"
367 " precise int middle = low + ((high - low) / 2);\n"
369 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
373 ctx.beginSection("Testing fused multiply-add.");
375 std::ostringstream source;
376 source << "#version 310 es\n"
377 "in mediump float v_var;"
380 " float fmaResult = fma(v_var, v_var, v_var);"
382 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
386 ctx.beginSection("Testing textureGatherOffsets.");
388 std::ostringstream source;
389 source << "#version 310 es\n"
390 "uniform mediump sampler2D u_tex;\n"
393 " highp vec2 coords = vec2(0.0, 1.0);\n"
394 " const ivec2 offsets[4] = ivec2[](ivec2(0,0), ivec2(1, 0), ivec2(0, 1), ivec2(1, 1));\n"
395 " textureGatherOffsets(u_tex, coords, offsets);\n"
397 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
404 void shader_io_blocks (NegativeTestContext& ctx)
406 ctx.beginSection("GL_EXT_shader_io_blocks features require enabling the extension in 310 es shaders.");
408 std::ostringstream source;
409 source << "#version 310 es\n"
417 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
422 void tessellation_shader (NegativeTestContext& ctx)
424 if (ctx.isShaderSupported(glu::SHADERTYPE_TESSELLATION_CONTROL))
426 const std::string simpleVtxFrag = "#version 310 es\n"
430 const std::string tessControl = "#version 310 es\n"
431 "layout(vertices = 3) out;\n"
435 const std::string tessEvaluation = "#version 310 es\n"
436 "layout(triangles, equal_spacing, cw) in;\n"
440 ctx.beginSection("GL_EXT_tessellation_shader features require enabling the extension in 310 es shaders.");
441 glu::ProgramSources sources;
442 sources << glu::VertexSource(simpleVtxFrag)
443 << glu::TessellationControlSource(tessControl)
444 << glu::TessellationEvaluationSource(tessEvaluation)
445 << glu::FragmentSource(simpleVtxFrag);
446 verifyProgram(ctx, sources, EXPECT_RESULT_FAIL);
451 void texture_buffer (NegativeTestContext& ctx)
453 static const char* const s_samplerBufferTypes[] =
455 "uniform mediump samplerBuffer",
456 "uniform mediump isamplerBuffer",
457 "uniform mediump usamplerBuffer",
458 "layout(rgba32f) uniform mediump writeonly imageBuffer",
459 "layout(rgba32i) uniform mediump writeonly iimageBuffer",
460 "layout(rgba32ui) uniform mediump writeonly uimageBuffer"
463 ctx.beginSection("GL_EXT_texture_buffer features require enabling the extension in 310 es shaders.");
464 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_samplerBufferTypes); ++ndx)
466 std::ostringstream source;
467 source << "#version 310 es\n"
468 "" << s_samplerBufferTypes[ndx] << " u_buffer;\n"
472 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
478 void texture_cube_map_array (NegativeTestContext& ctx)
480 static const char* const s_samplerCubeArrayTypes[] =
482 "uniform mediump samplerCubeArray",
483 "uniform mediump isamplerCubeArray",
484 "uniform mediump usamplerCubeArray",
485 "uniform mediump samplerCubeArrayShadow",
486 "layout(rgba32f) uniform mediump writeonly imageCubeArray",
487 "layout(rgba32i) uniform mediump writeonly iimageCubeArray",
488 "layout(rgba32ui) uniform mediump writeonly uimageCubeArray"
491 ctx.beginSection("GL_EXT_texture_cube_map_array features require enabling the extension in 310 es shaders.");
492 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_samplerCubeArrayTypes); ++ndx)
494 std::ostringstream source;
495 source << "#version 310 es\n"
496 "" << s_samplerCubeArrayTypes[ndx] << " u_cube;\n"
500 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, source.str(), EXPECT_RESULT_FAIL);
505 void executeAccessingBoundingBoxType (NegativeTestContext& ctx, const std::string builtInTypeName, glu::GLSLVersion glslVersion)
507 std::ostringstream sourceStream;
509 std::string extensionPrim;
510 std::string extensionTess;
512 if (glslVersion == glu::GLSL_VERSION_310_ES)
514 version = "#version 310 es\n";
515 extensionPrim = "#extension GL_EXT_primitive_bounding_box : require\n";
516 extensionTess = "#extension GL_EXT_tessellation_shader : require\n";
518 else if (glslVersion >= glu::GLSL_VERSION_320_ES)
520 version = "#version 320 es\n";
526 DE_FATAL("error: context below 3.1 and not supported");
529 ctx.beginSection("cannot access built-in type " + builtInTypeName + "[]" + " in vertex shader");
530 sourceStream << version
534 << " " + builtInTypeName + "[0] = vec4(1.0, 1.0, 1.0, 1.0);\n"
535 << " gl_Position = " + builtInTypeName + "[0];\n"
537 verifyShader(ctx, glu::SHADERTYPE_VERTEX, sourceStream.str(), EXPECT_RESULT_FAIL);
540 sourceStream.str(std::string());
542 if (ctx.isShaderSupported(glu::SHADERTYPE_TESSELLATION_EVALUATION))
544 ctx.beginSection("cannot access built-in type " + builtInTypeName + "[]" + " in tessellation evaluation shader");
545 sourceStream << version
548 << "layout (triangles, equal_spacing, ccw) in;\n"
551 << " " + builtInTypeName + "[0] = vec4(1.0, 1.0, 1.0, 1.0);\n"
552 << " gl_Position = ( gl_TessCoord.x * " + builtInTypeName + "[0] +\n"
553 << " gl_TessCoord.y * " + builtInTypeName + "[0] +\n"
554 << " gl_TessCoord.z * " + builtInTypeName + "[0]);\n"
556 verifyShader(ctx, glu::SHADERTYPE_TESSELLATION_EVALUATION, sourceStream.str(), EXPECT_RESULT_FAIL);
559 sourceStream.str(std::string());
562 if (ctx.isShaderSupported(glu::SHADERTYPE_GEOMETRY))
564 ctx.beginSection("cannot access built-in type " + builtInTypeName + "[]" + " in geometry shader");
565 sourceStream << version
567 << "layout (triangles) in;\n"
568 << "layout (triangle_strip, max_vertices = 3) out;\n"
571 << " " + builtInTypeName + "[0] = vec4(1.0, 1.0, 1.0, 1.0);\n"
572 << " for (int idx = 0; idx < 3; idx++)\n"
574 << " gl_Position = gl_in[idx].gl_Position * " + builtInTypeName + "[0];\n"
575 << " EmitVertex();\n"
577 << " EndPrimitive();\n"
579 verifyShader(ctx, glu::SHADERTYPE_GEOMETRY, sourceStream.str(), EXPECT_RESULT_FAIL);
582 sourceStream.str(std::string());
585 ctx.beginSection("cannot access built-in type " + builtInTypeName + "[]" + " in fragment shader");
586 sourceStream << version
588 << "layout (location = 0) out mediump vec4 fs_colour;\n"
591 << " " + builtInTypeName + "[0] = vec4(1.0, 1.0, 1.0, 1.0);\n"
592 << " fs_colour = " + builtInTypeName + "[0];\n"
594 verifyShader(ctx, glu::SHADERTYPE_FRAGMENT, sourceStream.str(), EXPECT_RESULT_FAIL);
598 void accessing_bounding_box_type (NegativeTestContext& ctx)
600 // Extension requirements and name differences depending on the context
601 if ((ctx.getRenderContext().getType().getMajorVersion() == 3) && (ctx.getRenderContext().getType().getMinorVersion() == 1))
603 executeAccessingBoundingBoxType(ctx, "gl_BoundingBoxEXT", glu::GLSL_VERSION_310_ES);
607 executeAccessingBoundingBoxType(ctx, "gl_BoundingBox", glu::GLSL_VERSION_320_ES);
614 std::vector<FunctionContainer> getNegativeShaderDirectiveTestFunctions (void)
616 const FunctionContainer funcs[] =
618 {primitive_bounding_box, "primitive_bounding_box", "GL_EXT_primitive_bounding_box required in 310 es shaders to use AEP features. Version 320 es shaders do not require suffixes." },
619 {blend_equation_advanced, "blend_equation_advanced", "GL_KHR_blend_equation_advanced is required in 310 es shaders to use AEP features" },
620 {sample_variables, "sample_variables", "GL_OES_sample_variables is required in 310 es shaders to use AEP features" },
621 {shader_image_atomic, "shader_image_atomic", "GL_OES_shader_image_atomic is required in 310 es shaders to use AEP features" },
622 {shader_multisample_interpolation, "shader_multisample_interpolation", "GL_OES_shader_multisample_interpolation is required in 310 es shaders to use AEP features" },
623 {texture_storage_multisample_2d_array, "texture_storage_multisample_2d_array", "GL_OES_texture_storage_multisample_2d_array is required in 310 es shaders to use AEP features" },
624 {geometry_shader, "geometry_shader", "GL_EXT_geometry_shader is required in 310 es shaders to use AEP features" },
625 {gpu_shader_5, "gpu_shader_5", "GL_EXT_gpu_shader5 is required in 310 es shaders to use AEP features" },
626 {shader_io_blocks, "shader_io_blocks", "GL_EXT_shader_io_blocks is required in 310 es shaders to use AEP features" },
627 {tessellation_shader, "tessellation_shader", "GL_EXT_tessellation_shader is required in 310 es shaders to use AEP features" },
628 {texture_buffer, "texture_buffer", "GL_EXT_texture_buffer is required in 310 es shaders to use AEP features" },
629 {texture_cube_map_array, "texture_cube_map_array", "GL_EXT_texture_cube_map_array is required in 310 es shaders to use AEP features" },
630 {accessing_bounding_box_type, "accessing_bounding_box_type", "Should not be able to access gl_BoundingBoxEXT[] and gl_BoundingBox[] in shaders other than tess control and evaluation" },
633 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
636 } // NegativeTestShared