1 /*------------------------------------------------------------------------- 2 * drawElements Quality Program OpenGL ES 3.1 Module 3 * ------------------------------------------------- 4 * 5 * Copyright 2016 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 Precise Tests 22 *//*--------------------------------------------------------------------*/ 23 24 #include "es31fNegativePreciseTests.hpp" 25 26 #include "gluShaderProgram.hpp" 27 #include "glwEnums.hpp" 28 29 namespace deqp 30 { 31 namespace gles31 32 { 33 namespace Functional 34 { 35 namespace NegativeTestShared 36 { 37 namespace 38 { 39 40 enum TestPrecise 41 { 42 TEST_PRECISE_AS_VARIABLE_NAME = 0, 43 TEST_PRECISE_AS_FUNCTION_NAME, 44 TEST_PRECISE_AS_ARGUMENT_NAME, 45 TEST_PRECISE_AS_MACRO_NAME, 46 TEST_PRECISE_MACRO_AND_VARIABLE, 47 TEST_PRECISE_MACRO_AND_FUNCTION, 48 TEST_PRECISE_MACRO_AND_ARGUMENT, 49 50 TEST_PRECISE_LAST 51 }; 52 53 static const glu::ShaderType s_shaderTypes[] = 54 { 55 glu::SHADERTYPE_VERTEX, 56 glu::SHADERTYPE_FRAGMENT, 57 glu::SHADERTYPE_GEOMETRY, 58 glu::SHADERTYPE_COMPUTE, 59 glu::SHADERTYPE_TESSELLATION_CONTROL, 60 glu::SHADERTYPE_TESSELLATION_EVALUATION 61 }; 62 63 std::string generateShaderSource (NegativeTestContext& ctx, glu::ShaderType shaderType, TestPrecise test) 64 { 65 const bool supportsES32 = contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)); 66 const glu::GLSLVersion version = supportsES32 ? glu::GLSL_VERSION_320_ES : glu::GLSL_VERSION_310_ES; 67 std::ostringstream source; 68 69 source << glu::getGLSLVersionDeclaration(version) << "\n" 70 << (supportsES32 ? "" : "#extension GL_EXT_gpu_shader5 : enable\n"); 71 72 switch (test) 73 { 74 case TEST_PRECISE_AS_MACRO_NAME: source << "#define precise 0\n"; break; 75 76 case TEST_PRECISE_MACRO_AND_VARIABLE: 77 case TEST_PRECISE_MACRO_AND_FUNCTION: 78 case TEST_PRECISE_MACRO_AND_ARGUMENT: source << "#define precise aName\n"; break; 79 default: 80 break; 81 } 82 83 switch (shaderType) 84 { 85 case glu::SHADERTYPE_GEOMETRY: 86 source << (supportsES32 ? "" : "#extension GL_EXT_geometry_shader : enable\n") 87 << "layout(max_vertices = 5) out;\n"; 88 break; 89 90 case glu::SHADERTYPE_TESSELLATION_CONTROL: 91 source << (supportsES32 ? "" : "#extension GL_EXT_tessellation_shader : enable\n") 92 << "layout(vertices = 3) out;\n"; 93 break; 94 95 case glu::SHADERTYPE_TESSELLATION_EVALUATION: 96 source << (supportsES32 ? "" : "#extension GL_EXT_tessellation_shader : enable\n") 97 << "layout(triangles, equal_spacing, cw) in;\n"; 98 break; 99 100 default: 101 break; 102 } 103 104 switch (test) 105 { 106 case TEST_PRECISE_AS_FUNCTION_NAME: 107 case TEST_PRECISE_MACRO_AND_FUNCTION: 108 source << "\n" 109 << "void precise()\n" 110 << "{\n" 111 << "}\n"; 112 break; 113 114 case TEST_PRECISE_AS_ARGUMENT_NAME: 115 case TEST_PRECISE_MACRO_AND_ARGUMENT: 116 source << "\n" 117 << "void example(int precise)\n" 118 << "{\n" 119 << "}\n"; 120 break; 121 122 default: 123 break; 124 } 125 126 source << "void main()\n" 127 << "{\n"; 128 129 switch (test) 130 { 131 case TEST_PRECISE_AS_VARIABLE_NAME: 132 case TEST_PRECISE_MACRO_AND_VARIABLE: source << " int precise = 1;\n"; break; 133 case TEST_PRECISE_AS_MACRO_NAME: source << " int number = precise;\n"; break; 134 default: 135 break; 136 } 137 138 source << "}\n"; 139 140 return source.str(); 141 } 142 143 void generateAndVerifyShader (NegativeTestContext& ctx, glu::ShaderType shaderType, TestPrecise test) 144 { 145 glu::Shader shader (ctx.getRenderContext(), shaderType); 146 std::string shaderSource = generateShaderSource(ctx, shaderType, test); 147 const char* const source = shaderSource.c_str(); 148 const int length = (int) shaderSource.size(); 149 150 shader.setSources(1, &source, &length); 151 shader.compile(); 152 153 ctx.getLog() << shader; 154 155 if (shader.getCompileStatus()) 156 ctx.fail("Shader was not expected to compile."); 157 } 158 159 void precise_as_variable_name (NegativeTestContext& ctx) 160 { 161 TCU_CHECK_AND_THROW(NotSupportedError, 162 ctx.isExtensionSupported("GL_EXT_gpu_shader5") || contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)), 163 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher."); 164 165 ctx.beginSection("Test that precise cannot be used as a variable name."); 166 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx) 167 { 168 if (ctx.isShaderSupported(s_shaderTypes[ndx])) 169 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_VARIABLE_NAME); 170 } 171 ctx.endSection(); 172 } 173 174 void precise_as_function_name (NegativeTestContext& ctx) 175 { 176 TCU_CHECK_AND_THROW(NotSupportedError, 177 ctx.isExtensionSupported("GL_EXT_gpu_shader5") || contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)), 178 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher."); 179 180 ctx.beginSection("Test that precise cannot be used as a function name."); 181 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx) 182 { 183 if (ctx.isShaderSupported(s_shaderTypes[ndx])) 184 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_FUNCTION_NAME); 185 } 186 ctx.endSection(); 187 } 188 189 void precise_as_function_argument (NegativeTestContext& ctx) 190 { 191 TCU_CHECK_AND_THROW(NotSupportedError, 192 ctx.isExtensionSupported("GL_EXT_gpu_shader5") || contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)), 193 "This test requires support for the extension GL_EXT_gpu_shader5 or context version 3.2 or higher."); 194 195 ctx.beginSection("Test that precise cannot be used as a argument name."); 196 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaderTypes); ++ndx) 197 { 198 if (ctx.isShaderSupported(s_shaderTypes[ndx])) 199 generateAndVerifyShader(ctx, s_shaderTypes[ndx], TEST_PRECISE_AS_ARGUMENT_NAME); 200 } 201 ctx.endSection(); 202 } 203 204 } // anonymous 205 206 std::vector<FunctionContainer> getNegativePreciseTestFunctions (void) 207 { 208 const FunctionContainer funcs[] = 209 { 210 {precise_as_variable_name, "precise_as_variable_name", "Test precise keyword as variable name." }, 211 {precise_as_function_name, "precise_as_function_name", "Test precise keyword as function name." }, 212 {precise_as_function_argument, "precise_as_function_argument", "Test precise keyword as argument name." }, 213 }; 214 215 return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs)); 216 } 217 218 } // NegativeTestShared 219 } // Functional 220 } // gles31 221 } // deqp 222