Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 8 | |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 9 | #include "libANGLE/Context.h" |
| 10 | #include "libANGLE/Program.h" |
Jamie Madill | 1048e43 | 2016-07-23 18:51:28 -0400 | [diff] [blame] | 11 | #include "test_utils/gl_raii.h" |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 12 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 13 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 14 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 15 | namespace |
| 16 | { |
| 17 | |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 18 | class GLSLTest : public ANGLETest |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 19 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 20 | protected: |
| 21 | GLSLTest() |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 22 | { |
| 23 | setWindowWidth(128); |
| 24 | setWindowHeight(128); |
| 25 | setConfigRedBits(8); |
| 26 | setConfigGreenBits(8); |
| 27 | setConfigBlueBits(8); |
| 28 | setConfigAlphaBits(8); |
| 29 | } |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 30 | |
| 31 | virtual void SetUp() |
| 32 | { |
| 33 | ANGLETest::SetUp(); |
| 34 | |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 35 | mSimpleVSSource = SHADER_SOURCE |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 36 | ( |
| 37 | attribute vec4 inputAttribute; |
| 38 | void main() |
| 39 | { |
| 40 | gl_Position = inputAttribute; |
| 41 | } |
| 42 | ); |
| 43 | } |
| 44 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 45 | std::string GenerateVaryingType(GLint vectorSize) |
| 46 | { |
| 47 | char varyingType[10]; |
| 48 | |
| 49 | if (vectorSize == 1) |
| 50 | { |
| 51 | sprintf(varyingType, "float"); |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | sprintf(varyingType, "vec%d", vectorSize); |
| 56 | } |
| 57 | |
| 58 | return std::string(varyingType); |
| 59 | } |
| 60 | |
| 61 | std::string GenerateVectorVaryingDeclaration(GLint vectorSize, GLint arraySize, GLint id) |
| 62 | { |
| 63 | char buff[100]; |
| 64 | |
| 65 | if (arraySize == 1) |
| 66 | { |
| 67 | sprintf(buff, "varying %s v%d;\n", GenerateVaryingType(vectorSize).c_str(), id); |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | sprintf(buff, "varying %s v%d[%d];\n", GenerateVaryingType(vectorSize).c_str(), id, arraySize); |
| 72 | } |
| 73 | |
| 74 | return std::string(buff); |
| 75 | } |
| 76 | |
| 77 | std::string GenerateVectorVaryingSettingCode(GLint vectorSize, GLint arraySize, GLint id) |
| 78 | { |
| 79 | std::string returnString; |
| 80 | char buff[100]; |
| 81 | |
| 82 | if (arraySize == 1) |
| 83 | { |
| 84 | sprintf(buff, "\t v%d = %s(1.0);\n", id, GenerateVaryingType(vectorSize).c_str()); |
| 85 | returnString += buff; |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | for (int i = 0; i < arraySize; i++) |
| 90 | { |
| 91 | sprintf(buff, "\t v%d[%d] = %s(1.0);\n", id, i, GenerateVaryingType(vectorSize).c_str()); |
| 92 | returnString += buff; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return returnString; |
| 97 | } |
| 98 | |
| 99 | std::string GenerateVectorVaryingUseCode(GLint arraySize, GLint id) |
| 100 | { |
| 101 | if (arraySize == 1) |
| 102 | { |
| 103 | char buff[100]; |
| 104 | sprintf(buff, "v%d + ", id); |
| 105 | return std::string(buff); |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | std::string returnString; |
| 110 | for (int i = 0; i < arraySize; i++) |
| 111 | { |
| 112 | char buff[100]; |
| 113 | sprintf(buff, "v%d[%d] + ", id, i); |
| 114 | returnString += buff; |
| 115 | } |
| 116 | return returnString; |
| 117 | } |
| 118 | } |
| 119 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 120 | void GenerateGLSLWithVaryings(GLint floatCount, GLint floatArrayCount, GLint vec2Count, GLint vec2ArrayCount, GLint vec3Count, GLint vec3ArrayCount, |
| 121 | GLint vec4Count, GLint vec4ArrayCount, bool useFragCoord, bool usePointCoord, bool usePointSize, |
| 122 | std::string* fragmentShader, std::string* vertexShader) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 123 | { |
| 124 | // Generate a string declaring the varyings, to share between the fragment shader and the vertex shader. |
| 125 | std::string varyingDeclaration; |
| 126 | |
| 127 | unsigned int varyingCount = 0; |
| 128 | |
| 129 | for (GLint i = 0; i < floatCount; i++) |
| 130 | { |
| 131 | varyingDeclaration += GenerateVectorVaryingDeclaration(1, 1, varyingCount); |
| 132 | varyingCount += 1; |
| 133 | } |
| 134 | |
| 135 | for (GLint i = 0; i < floatArrayCount; i++) |
| 136 | { |
| 137 | varyingDeclaration += GenerateVectorVaryingDeclaration(1, 2, varyingCount); |
| 138 | varyingCount += 1; |
| 139 | } |
| 140 | |
| 141 | for (GLint i = 0; i < vec2Count; i++) |
| 142 | { |
| 143 | varyingDeclaration += GenerateVectorVaryingDeclaration(2, 1, varyingCount); |
| 144 | varyingCount += 1; |
| 145 | } |
| 146 | |
| 147 | for (GLint i = 0; i < vec2ArrayCount; i++) |
| 148 | { |
| 149 | varyingDeclaration += GenerateVectorVaryingDeclaration(2, 2, varyingCount); |
| 150 | varyingCount += 1; |
| 151 | } |
| 152 | |
| 153 | for (GLint i = 0; i < vec3Count; i++) |
| 154 | { |
| 155 | varyingDeclaration += GenerateVectorVaryingDeclaration(3, 1, varyingCount); |
| 156 | varyingCount += 1; |
| 157 | } |
| 158 | |
| 159 | for (GLint i = 0; i < vec3ArrayCount; i++) |
| 160 | { |
| 161 | varyingDeclaration += GenerateVectorVaryingDeclaration(3, 2, varyingCount); |
| 162 | varyingCount += 1; |
| 163 | } |
| 164 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 165 | for (GLint i = 0; i < vec4Count; i++) |
| 166 | { |
| 167 | varyingDeclaration += GenerateVectorVaryingDeclaration(4, 1, varyingCount); |
| 168 | varyingCount += 1; |
| 169 | } |
| 170 | |
| 171 | for (GLint i = 0; i < vec4ArrayCount; i++) |
| 172 | { |
| 173 | varyingDeclaration += GenerateVectorVaryingDeclaration(4, 2, varyingCount); |
| 174 | varyingCount += 1; |
| 175 | } |
| 176 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 177 | // Generate the vertex shader |
| 178 | vertexShader->clear(); |
| 179 | vertexShader->append(varyingDeclaration); |
| 180 | vertexShader->append("\nvoid main()\n{\n"); |
| 181 | |
| 182 | unsigned int currentVSVarying = 0; |
| 183 | |
| 184 | for (GLint i = 0; i < floatCount; i++) |
| 185 | { |
| 186 | vertexShader->append(GenerateVectorVaryingSettingCode(1, 1, currentVSVarying)); |
| 187 | currentVSVarying += 1; |
| 188 | } |
| 189 | |
| 190 | for (GLint i = 0; i < floatArrayCount; i++) |
| 191 | { |
| 192 | vertexShader->append(GenerateVectorVaryingSettingCode(1, 2, currentVSVarying)); |
| 193 | currentVSVarying += 1; |
| 194 | } |
| 195 | |
| 196 | for (GLint i = 0; i < vec2Count; i++) |
| 197 | { |
| 198 | vertexShader->append(GenerateVectorVaryingSettingCode(2, 1, currentVSVarying)); |
| 199 | currentVSVarying += 1; |
| 200 | } |
| 201 | |
| 202 | for (GLint i = 0; i < vec2ArrayCount; i++) |
| 203 | { |
| 204 | vertexShader->append(GenerateVectorVaryingSettingCode(2, 2, currentVSVarying)); |
| 205 | currentVSVarying += 1; |
| 206 | } |
| 207 | |
| 208 | for (GLint i = 0; i < vec3Count; i++) |
| 209 | { |
| 210 | vertexShader->append(GenerateVectorVaryingSettingCode(3, 1, currentVSVarying)); |
| 211 | currentVSVarying += 1; |
| 212 | } |
| 213 | |
| 214 | for (GLint i = 0; i < vec3ArrayCount; i++) |
| 215 | { |
| 216 | vertexShader->append(GenerateVectorVaryingSettingCode(3, 2, currentVSVarying)); |
| 217 | currentVSVarying += 1; |
| 218 | } |
| 219 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 220 | for (GLint i = 0; i < vec4Count; i++) |
| 221 | { |
| 222 | vertexShader->append(GenerateVectorVaryingSettingCode(4, 1, currentVSVarying)); |
| 223 | currentVSVarying += 1; |
| 224 | } |
| 225 | |
| 226 | for (GLint i = 0; i < vec4ArrayCount; i++) |
| 227 | { |
| 228 | vertexShader->append(GenerateVectorVaryingSettingCode(4, 2, currentVSVarying)); |
| 229 | currentVSVarying += 1; |
| 230 | } |
| 231 | |
| 232 | if (usePointSize) |
| 233 | { |
| 234 | vertexShader->append("gl_PointSize = 1.0;\n"); |
| 235 | } |
| 236 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 237 | vertexShader->append("}\n"); |
| 238 | |
| 239 | // Generate the fragment shader |
| 240 | fragmentShader->clear(); |
| 241 | fragmentShader->append("precision highp float;\n"); |
| 242 | fragmentShader->append(varyingDeclaration); |
| 243 | fragmentShader->append("\nvoid main() \n{ \n\tvec4 retColor = vec4(0,0,0,0);\n"); |
| 244 | |
| 245 | unsigned int currentFSVarying = 0; |
| 246 | |
| 247 | // Make use of the float varyings |
| 248 | fragmentShader->append("\tretColor += vec4("); |
| 249 | |
| 250 | for (GLint i = 0; i < floatCount; i++) |
| 251 | { |
| 252 | fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying)); |
| 253 | currentFSVarying += 1; |
| 254 | } |
| 255 | |
| 256 | for (GLint i = 0; i < floatArrayCount; i++) |
| 257 | { |
| 258 | fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying)); |
| 259 | currentFSVarying += 1; |
| 260 | } |
| 261 | |
| 262 | fragmentShader->append("0.0, 0.0, 0.0, 0.0);\n"); |
| 263 | |
| 264 | // Make use of the vec2 varyings |
| 265 | fragmentShader->append("\tretColor += vec4("); |
| 266 | |
| 267 | for (GLint i = 0; i < vec2Count; i++) |
| 268 | { |
| 269 | fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying)); |
| 270 | currentFSVarying += 1; |
| 271 | } |
| 272 | |
| 273 | for (GLint i = 0; i < vec2ArrayCount; i++) |
| 274 | { |
| 275 | fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying)); |
| 276 | currentFSVarying += 1; |
| 277 | } |
| 278 | |
| 279 | fragmentShader->append("vec2(0.0, 0.0), 0.0, 0.0);\n"); |
| 280 | |
| 281 | // Make use of the vec3 varyings |
| 282 | fragmentShader->append("\tretColor += vec4("); |
| 283 | |
| 284 | for (GLint i = 0; i < vec3Count; i++) |
| 285 | { |
| 286 | fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying)); |
| 287 | currentFSVarying += 1; |
| 288 | } |
| 289 | |
| 290 | for (GLint i = 0; i < vec3ArrayCount; i++) |
| 291 | { |
| 292 | fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying)); |
| 293 | currentFSVarying += 1; |
| 294 | } |
| 295 | |
| 296 | fragmentShader->append("vec3(0.0, 0.0, 0.0), 0.0);\n"); |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 297 | |
| 298 | // Make use of the vec4 varyings |
| 299 | fragmentShader->append("\tretColor += "); |
| 300 | |
| 301 | for (GLint i = 0; i < vec4Count; i++) |
| 302 | { |
| 303 | fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying)); |
| 304 | currentFSVarying += 1; |
| 305 | } |
| 306 | |
| 307 | for (GLint i = 0; i < vec4ArrayCount; i++) |
| 308 | { |
| 309 | fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying)); |
| 310 | currentFSVarying += 1; |
| 311 | } |
| 312 | |
| 313 | fragmentShader->append("vec4(0.0, 0.0, 0.0, 0.0);\n"); |
| 314 | |
| 315 | // Set gl_FragColor, and use special variables if requested |
| 316 | fragmentShader->append("\tgl_FragColor = retColor"); |
| 317 | |
| 318 | if (useFragCoord) |
| 319 | { |
| 320 | fragmentShader->append(" + gl_FragCoord"); |
| 321 | } |
| 322 | |
| 323 | if (usePointCoord) |
| 324 | { |
| 325 | fragmentShader->append(" + vec4(gl_PointCoord, 0.0, 0.0)"); |
| 326 | } |
| 327 | |
| 328 | fragmentShader->append(";\n}"); |
| 329 | } |
| 330 | |
| 331 | void VaryingTestBase(GLint floatCount, GLint floatArrayCount, GLint vec2Count, GLint vec2ArrayCount, GLint vec3Count, GLint vec3ArrayCount, |
| 332 | GLint vec4Count, GLint vec4ArrayCount, bool useFragCoord, bool usePointCoord, bool usePointSize, bool expectSuccess) |
| 333 | { |
| 334 | std::string fragmentShaderSource; |
| 335 | std::string vertexShaderSource; |
| 336 | |
| 337 | GenerateGLSLWithVaryings(floatCount, floatArrayCount, vec2Count, vec2ArrayCount, vec3Count, vec3ArrayCount, |
| 338 | vec4Count, vec4ArrayCount, useFragCoord, usePointCoord, usePointSize, |
| 339 | &fragmentShaderSource, &vertexShaderSource); |
| 340 | |
| 341 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 342 | |
| 343 | if (expectSuccess) |
| 344 | { |
| 345 | EXPECT_NE(0u, program); |
| 346 | } |
| 347 | else |
| 348 | { |
| 349 | EXPECT_EQ(0u, program); |
| 350 | } |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 353 | void CompileGLSLWithUniformsAndSamplers(GLint vertexUniformCount, |
| 354 | GLint fragmentUniformCount, |
| 355 | GLint vertexSamplersCount, |
| 356 | GLint fragmentSamplersCount, |
| 357 | bool expectSuccess) |
| 358 | { |
| 359 | std::stringstream vertexShader; |
| 360 | std::stringstream fragmentShader; |
| 361 | |
| 362 | // Generate the vertex shader |
| 363 | vertexShader << "precision mediump float;\n"; |
| 364 | |
| 365 | for (int i = 0; i < vertexUniformCount; i++) |
| 366 | { |
| 367 | vertexShader << "uniform vec4 v" << i << ";\n"; |
| 368 | } |
| 369 | |
| 370 | for (int i = 0; i < vertexSamplersCount; i++) |
| 371 | { |
| 372 | vertexShader << "uniform sampler2D s" << i << ";\n"; |
| 373 | } |
| 374 | |
| 375 | vertexShader << "void main()\n{\n"; |
| 376 | |
| 377 | for (int i = 0; i < vertexUniformCount; i++) |
| 378 | { |
| 379 | vertexShader << " gl_Position += v" << i << ";\n"; |
| 380 | } |
| 381 | |
| 382 | for (int i = 0; i < vertexSamplersCount; i++) |
| 383 | { |
| 384 | vertexShader << " gl_Position += texture2D(s" << i << ", vec2(0.0, 0.0));\n"; |
| 385 | } |
| 386 | |
| 387 | if (vertexUniformCount == 0 && vertexSamplersCount == 0) |
| 388 | { |
| 389 | vertexShader << " gl_Position = vec4(0.0);\n"; |
| 390 | } |
| 391 | |
| 392 | vertexShader << "}\n"; |
| 393 | |
| 394 | // Generate the fragment shader |
| 395 | fragmentShader << "precision mediump float;\n"; |
| 396 | |
| 397 | for (int i = 0; i < fragmentUniformCount; i++) |
| 398 | { |
| 399 | fragmentShader << "uniform vec4 v" << i << ";\n"; |
| 400 | } |
| 401 | |
| 402 | for (int i = 0; i < fragmentSamplersCount; i++) |
| 403 | { |
| 404 | fragmentShader << "uniform sampler2D s" << i << ";\n"; |
| 405 | } |
| 406 | |
| 407 | fragmentShader << "void main()\n{\n"; |
| 408 | |
| 409 | for (int i = 0; i < fragmentUniformCount; i++) |
| 410 | { |
| 411 | fragmentShader << " gl_FragColor += v" << i << ";\n"; |
| 412 | } |
| 413 | |
| 414 | for (int i = 0; i < fragmentSamplersCount; i++) |
| 415 | { |
| 416 | fragmentShader << " gl_FragColor += texture2D(s" << i << ", vec2(0.0, 0.0));\n"; |
| 417 | } |
| 418 | |
| 419 | if (fragmentUniformCount == 0 && fragmentSamplersCount == 0) |
| 420 | { |
| 421 | fragmentShader << " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"; |
| 422 | } |
| 423 | |
| 424 | fragmentShader << "}\n"; |
| 425 | |
| 426 | GLuint program = CompileProgram(vertexShader.str(), fragmentShader.str()); |
| 427 | |
| 428 | if (expectSuccess) |
| 429 | { |
| 430 | EXPECT_NE(0u, program); |
| 431 | } |
| 432 | else |
| 433 | { |
| 434 | EXPECT_EQ(0u, program); |
| 435 | } |
| 436 | } |
| 437 | |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 438 | std::string mSimpleVSSource; |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 439 | }; |
| 440 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 441 | class GLSLTest_ES3 : public GLSLTest |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 442 | { |
Olli Etuaho | e1d199b | 2016-07-19 17:14:27 +0300 | [diff] [blame] | 443 | void SetUp() override |
| 444 | { |
| 445 | ANGLETest::SetUp(); |
| 446 | |
| 447 | mSimpleVSSource = |
| 448 | "#version 300 es\n" |
| 449 | "in vec4 inputAttribute;" |
| 450 | "void main()" |
| 451 | "{" |
| 452 | " gl_Position = inputAttribute;" |
| 453 | "}"; |
| 454 | } |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 455 | }; |
| 456 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 457 | TEST_P(GLSLTest, NamelessScopedStructs) |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 458 | { |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 459 | const std::string fragmentShaderSource = SHADER_SOURCE |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 460 | ( |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 461 | precision mediump float; |
| 462 | |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 463 | void main() |
| 464 | { |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 465 | struct |
| 466 | { |
| 467 | float q; |
| 468 | } b; |
| 469 | |
| 470 | gl_FragColor = vec4(1, 0, 0, 1); |
| 471 | gl_FragColor.a += b.q; |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 472 | } |
| 473 | ); |
| 474 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 475 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 476 | EXPECT_NE(0u, program); |
| 477 | } |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 478 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 479 | TEST_P(GLSLTest, ScopedStructsOrderBug) |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 480 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 481 | // TODO(geofflang): Find out why this doesn't compile on Apple OpenGL drivers |
| 482 | // (http://anglebug.com/1292) |
Geoff Lang | 5103f4c | 2016-01-26 11:40:18 -0500 | [diff] [blame] | 483 | // TODO(geofflang): Find out why this doesn't compile on AMD OpenGL drivers |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 484 | // (http://anglebug.com/1291) |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 485 | if (IsDesktopOpenGL() && (IsOSX() || !IsNVIDIA())) |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 486 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 487 | std::cout << "Test disabled on this OpenGL configuration." << std::endl; |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 488 | return; |
| 489 | } |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 490 | |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 491 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 492 | ( |
| 493 | precision mediump float; |
| 494 | |
| 495 | struct T |
| 496 | { |
| 497 | float f; |
| 498 | }; |
| 499 | |
| 500 | void main() |
| 501 | { |
| 502 | T a; |
| 503 | |
| 504 | struct T |
| 505 | { |
| 506 | float q; |
| 507 | }; |
| 508 | |
| 509 | T b; |
| 510 | |
| 511 | gl_FragColor = vec4(1, 0, 0, 1); |
| 512 | gl_FragColor.a += a.f; |
| 513 | gl_FragColor.a += b.q; |
| 514 | } |
| 515 | ); |
| 516 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 517 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 518 | EXPECT_NE(0u, program); |
| 519 | } |
| 520 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 521 | TEST_P(GLSLTest, ScopedStructsBug) |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 522 | { |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 523 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 524 | ( |
| 525 | precision mediump float; |
| 526 | |
| 527 | struct T_0 |
| 528 | { |
| 529 | float f; |
| 530 | }; |
| 531 | |
| 532 | void main() |
| 533 | { |
| 534 | gl_FragColor = vec4(1, 0, 0, 1); |
| 535 | |
| 536 | struct T |
| 537 | { |
| 538 | vec2 v; |
| 539 | }; |
| 540 | |
| 541 | T_0 a; |
| 542 | T b; |
| 543 | |
| 544 | gl_FragColor.a += a.f; |
| 545 | gl_FragColor.a += b.v.x; |
| 546 | } |
| 547 | ); |
| 548 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 549 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 550 | EXPECT_NE(0u, program); |
| 551 | } |
| 552 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 553 | TEST_P(GLSLTest, DxPositionBug) |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 554 | { |
| 555 | const std::string &vertexShaderSource = SHADER_SOURCE |
| 556 | ( |
| 557 | attribute vec4 inputAttribute; |
| 558 | varying float dx_Position; |
| 559 | void main() |
| 560 | { |
| 561 | gl_Position = vec4(inputAttribute); |
| 562 | dx_Position = 0.0; |
| 563 | } |
| 564 | ); |
| 565 | |
| 566 | const std::string &fragmentShaderSource = SHADER_SOURCE |
| 567 | ( |
| 568 | precision mediump float; |
| 569 | |
| 570 | varying float dx_Position; |
| 571 | |
| 572 | void main() |
| 573 | { |
| 574 | gl_FragColor = vec4(dx_Position, 0, 0, 1); |
| 575 | } |
| 576 | ); |
| 577 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 578 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 579 | EXPECT_NE(0u, program); |
| 580 | } |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 581 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 582 | TEST_P(GLSLTest, ElseIfRewriting) |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 583 | { |
| 584 | const std::string &vertexShaderSource = |
| 585 | "attribute vec4 a_position;\n" |
| 586 | "varying float v;\n" |
| 587 | "void main() {\n" |
| 588 | " gl_Position = a_position;\n" |
| 589 | " v = 1.0;\n" |
| 590 | " if (a_position.x <= 0.5) {\n" |
| 591 | " v = 0.0;\n" |
| 592 | " } else if (a_position.x >= 0.5) {\n" |
| 593 | " v = 2.0;\n" |
| 594 | " }\n" |
| 595 | "}\n"; |
| 596 | |
| 597 | const std::string &fragmentShaderSource = |
| 598 | "precision highp float;\n" |
| 599 | "varying float v;\n" |
| 600 | "void main() {\n" |
| 601 | " vec4 color = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 602 | " if (v >= 1.0) color = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 603 | " if (v >= 2.0) color = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 604 | " gl_FragColor = color;\n" |
| 605 | "}\n"; |
| 606 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 607 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 608 | ASSERT_NE(0u, program); |
| 609 | |
| 610 | drawQuad(program, "a_position", 0.5f); |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 611 | |
| 612 | EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255); |
| 613 | EXPECT_PIXEL_EQ(getWindowWidth()-1, 0, 0, 255, 0, 255); |
| 614 | } |
| 615 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 616 | TEST_P(GLSLTest, TwoElseIfRewriting) |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 617 | { |
| 618 | const std::string &vertexShaderSource = |
| 619 | "attribute vec4 a_position;\n" |
| 620 | "varying float v;\n" |
| 621 | "void main() {\n" |
| 622 | " gl_Position = a_position;\n" |
Jamie Madill | 778d527 | 2014-08-04 13:13:25 -0400 | [diff] [blame] | 623 | " if (a_position.x == 0.0) {\n" |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 624 | " v = 1.0;\n" |
| 625 | " } else if (a_position.x > 0.5) {\n" |
| 626 | " v = 0.0;\n" |
| 627 | " } else if (a_position.x > 0.75) {\n" |
| 628 | " v = 0.5;\n" |
| 629 | " }\n" |
| 630 | "}\n"; |
| 631 | |
| 632 | const std::string &fragmentShaderSource = |
| 633 | "precision highp float;\n" |
| 634 | "varying float v;\n" |
| 635 | "void main() {\n" |
| 636 | " gl_FragColor = vec4(v, 0.0, 0.0, 1.0);\n" |
| 637 | "}\n"; |
| 638 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 639 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 640 | EXPECT_NE(0u, program); |
| 641 | } |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 642 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 643 | TEST_P(GLSLTest, FrontFacingAndVarying) |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 644 | { |
Geoff Lang | dd323e9 | 2015-06-09 15:16:31 -0400 | [diff] [blame] | 645 | EGLPlatformParameters platform = GetParam().eglParameters; |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 646 | |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 647 | const std::string vertexShaderSource = SHADER_SOURCE |
| 648 | ( |
| 649 | attribute vec4 a_position; |
| 650 | varying float v_varying; |
| 651 | void main() |
| 652 | { |
| 653 | v_varying = a_position.x; |
| 654 | gl_Position = a_position; |
| 655 | } |
| 656 | ); |
| 657 | |
| 658 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 659 | ( |
| 660 | precision mediump float; |
| 661 | varying float v_varying; |
| 662 | void main() |
| 663 | { |
| 664 | vec4 c; |
| 665 | |
| 666 | if (gl_FrontFacing) |
| 667 | { |
| 668 | c = vec4(v_varying, 0, 0, 1.0); |
| 669 | } |
| 670 | else |
| 671 | { |
| 672 | c = vec4(0, v_varying, 0, 1.0); |
| 673 | } |
| 674 | gl_FragColor = c; |
| 675 | } |
| 676 | ); |
| 677 | |
| 678 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Austin Kinross | 02df796 | 2015-07-01 10:03:42 -0700 | [diff] [blame] | 679 | |
| 680 | // Compilation should fail on D3D11 feature level 9_3, since gl_FrontFacing isn't supported. |
| 681 | if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE) |
| 682 | { |
| 683 | if (platform.majorVersion == 9 && platform.minorVersion == 3) |
| 684 | { |
| 685 | EXPECT_EQ(0u, program); |
| 686 | return; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | // Otherwise, compilation should succeed |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 691 | EXPECT_NE(0u, program); |
| 692 | } |
| 693 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 694 | // Verify that linking shaders declaring different shading language versions fails. |
| 695 | TEST_P(GLSLTest_ES3, VersionMismatch) |
| 696 | { |
| 697 | const std::string fragmentShaderSource100 = |
| 698 | "precision mediump float;\n" |
| 699 | "varying float v_varying;\n" |
| 700 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 701 | |
| 702 | const std::string vertexShaderSource100 = |
| 703 | "attribute vec4 a_position;\n" |
| 704 | "varying float v_varying;\n" |
| 705 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 706 | |
| 707 | const std::string fragmentShaderSource300 = |
| 708 | "#version 300 es\n" |
| 709 | "precision mediump float;\n" |
| 710 | "in float v_varying;\n" |
| 711 | "out vec4 my_FragColor;\n" |
| 712 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 713 | |
| 714 | const std::string vertexShaderSource300 = |
| 715 | "#version 300 es\n" |
| 716 | "in vec4 a_position;\n" |
| 717 | "out float v_varying;\n" |
| 718 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 719 | |
| 720 | GLuint program = CompileProgram(vertexShaderSource300, fragmentShaderSource100); |
| 721 | EXPECT_EQ(0u, program); |
| 722 | |
| 723 | program = CompileProgram(vertexShaderSource100, fragmentShaderSource300); |
| 724 | EXPECT_EQ(0u, program); |
| 725 | } |
| 726 | |
| 727 | // Verify that declaring varying as invariant only in vertex shader fails in ESSL 1.00. |
| 728 | TEST_P(GLSLTest, InvariantVaryingOut) |
| 729 | { |
| 730 | const std::string fragmentShaderSource = |
| 731 | "precision mediump float;\n" |
| 732 | "varying float v_varying;\n" |
| 733 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 734 | |
| 735 | const std::string vertexShaderSource = |
| 736 | "attribute vec4 a_position;\n" |
| 737 | "invariant varying float v_varying;\n" |
| 738 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 739 | |
| 740 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 741 | EXPECT_EQ(0u, program); |
| 742 | } |
| 743 | |
| 744 | // Verify that declaring varying as invariant only in vertex shader succeeds in ESSL 3.00. |
| 745 | TEST_P(GLSLTest_ES3, InvariantVaryingOut) |
| 746 | { |
| 747 | // TODO: ESSL 3.00 -> GLSL 1.20 translation should add "invariant" in fragment shader |
| 748 | // for varyings which are invariant in vertex shader (http://anglebug.com/1293) |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 749 | if (IsDesktopOpenGL()) |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 750 | { |
| 751 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | const std::string fragmentShaderSource = |
| 756 | "#version 300 es\n" |
| 757 | "precision mediump float;\n" |
| 758 | "in float v_varying;\n" |
| 759 | "out vec4 my_FragColor;\n" |
| 760 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 761 | |
| 762 | const std::string vertexShaderSource = |
| 763 | "#version 300 es\n" |
| 764 | "in vec4 a_position;\n" |
| 765 | "invariant out float v_varying;\n" |
| 766 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 767 | |
| 768 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 769 | EXPECT_NE(0u, program); |
| 770 | } |
| 771 | |
| 772 | // Verify that declaring varying as invariant only in fragment shader fails in ESSL 1.00. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 773 | TEST_P(GLSLTest, InvariantVaryingIn) |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 774 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 775 | const std::string fragmentShaderSource = |
| 776 | "precision mediump float;\n" |
| 777 | "invariant varying float v_varying;\n" |
| 778 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 779 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 780 | const std::string vertexShaderSource = |
| 781 | "attribute vec4 a_position;\n" |
| 782 | "varying float v_varying;\n" |
| 783 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 784 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 785 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 786 | EXPECT_EQ(0u, program); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 787 | } |
| 788 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 789 | // Verify that declaring varying as invariant only in fragment shader fails in ESSL 3.00. |
| 790 | TEST_P(GLSLTest_ES3, InvariantVaryingIn) |
| 791 | { |
| 792 | const std::string fragmentShaderSource = |
| 793 | "#version 300 es\n" |
| 794 | "precision mediump float;\n" |
| 795 | "invariant in float v_varying;\n" |
| 796 | "out vec4 my_FragColor;\n" |
| 797 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 798 | |
| 799 | const std::string vertexShaderSource = |
| 800 | "#version 300 es\n" |
| 801 | "in vec4 a_position;\n" |
| 802 | "out float v_varying;\n" |
| 803 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 804 | |
| 805 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 806 | EXPECT_EQ(0u, program); |
| 807 | } |
| 808 | |
| 809 | // Verify that declaring varying as invariant in both shaders succeeds in ESSL 1.00. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 810 | TEST_P(GLSLTest, InvariantVaryingBoth) |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 811 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 812 | const std::string fragmentShaderSource = |
| 813 | "precision mediump float;\n" |
| 814 | "invariant varying float v_varying;\n" |
| 815 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 816 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 817 | const std::string vertexShaderSource = |
| 818 | "attribute vec4 a_position;\n" |
| 819 | "invariant varying float v_varying;\n" |
| 820 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 821 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 822 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 823 | EXPECT_NE(0u, program); |
| 824 | } |
| 825 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 826 | // Verify that declaring varying as invariant in both shaders fails in ESSL 3.00. |
| 827 | TEST_P(GLSLTest_ES3, InvariantVaryingBoth) |
| 828 | { |
| 829 | const std::string fragmentShaderSource = |
| 830 | "#version 300 es\n" |
| 831 | "precision mediump float;\n" |
| 832 | "invariant in float v_varying;\n" |
| 833 | "out vec4 my_FragColor;\n" |
| 834 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 835 | |
| 836 | const std::string vertexShaderSource = |
| 837 | "#version 300 es\n" |
| 838 | "in vec4 a_position;\n" |
| 839 | "invariant out float v_varying;\n" |
| 840 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 841 | |
| 842 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 843 | EXPECT_EQ(0u, program); |
| 844 | } |
| 845 | |
| 846 | // Verify that declaring gl_Position as invariant succeeds in ESSL 1.00. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 847 | TEST_P(GLSLTest, InvariantGLPosition) |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 848 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 849 | const std::string fragmentShaderSource = |
| 850 | "precision mediump float;\n" |
| 851 | "varying float v_varying;\n" |
| 852 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 853 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 854 | const std::string vertexShaderSource = |
| 855 | "attribute vec4 a_position;\n" |
| 856 | "invariant gl_Position;\n" |
| 857 | "varying float v_varying;\n" |
| 858 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 859 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 860 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 861 | EXPECT_NE(0u, program); |
| 862 | } |
| 863 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 864 | // Verify that declaring gl_Position as invariant succeeds in ESSL 3.00. |
| 865 | TEST_P(GLSLTest_ES3, InvariantGLPosition) |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 866 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 867 | const std::string fragmentShaderSource = |
| 868 | "#version 300 es\n" |
| 869 | "precision mediump float;\n" |
| 870 | "in float v_varying;\n" |
| 871 | "out vec4 my_FragColor;\n" |
| 872 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 873 | |
| 874 | const std::string vertexShaderSource = |
| 875 | "#version 300 es\n" |
| 876 | "in vec4 a_position;\n" |
| 877 | "invariant gl_Position;\n" |
| 878 | "out float v_varying;\n" |
| 879 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 880 | |
| 881 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 882 | EXPECT_NE(0u, program); |
| 883 | } |
| 884 | |
| 885 | // Verify that using invariant(all) in both shaders succeeds in ESSL 1.00. |
| 886 | TEST_P(GLSLTest, InvariantAllBoth) |
| 887 | { |
| 888 | // TODO: ESSL 1.00 -> GLSL 1.20 translation should add "invariant" in fragment shader |
| 889 | // for varyings which are invariant in vertex shader individually, |
| 890 | // and remove invariant(all) from fragment shader (http://anglebug.com/1293) |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 891 | if (IsDesktopOpenGL()) |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 892 | { |
| 893 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 894 | return; |
| 895 | } |
| 896 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 897 | const std::string fragmentShaderSource = |
| 898 | "#pragma STDGL invariant(all)\n" |
| 899 | "precision mediump float;\n" |
| 900 | "varying float v_varying;\n" |
| 901 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 902 | |
| 903 | const std::string vertexShaderSource = |
| 904 | "#pragma STDGL invariant(all)\n" |
| 905 | "attribute vec4 a_position;\n" |
| 906 | "varying float v_varying;\n" |
| 907 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 908 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 909 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 910 | EXPECT_NE(0u, program); |
| 911 | } |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 912 | |
Geoff Lang | 156d719 | 2016-07-21 16:11:00 -0400 | [diff] [blame] | 913 | // Verify that functions without return statements still compile |
| 914 | TEST_P(GLSLTest, MissingReturnFloat) |
| 915 | { |
| 916 | const std::string vertexShaderSource = |
| 917 | "varying float v_varying;\n" |
| 918 | "float f() { if (v_varying > 0.0) return 1.0; }\n" |
| 919 | "void main() { gl_Position = vec4(f(), 0, 0, 1); }\n"; |
| 920 | |
| 921 | const std::string fragmentShaderSource = |
| 922 | "precision mediump float;\n" |
| 923 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 924 | |
| 925 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 926 | EXPECT_NE(0u, program); |
| 927 | } |
| 928 | |
| 929 | // Verify that functions without return statements still compile |
| 930 | TEST_P(GLSLTest, MissingReturnVec2) |
| 931 | { |
| 932 | const std::string vertexShaderSource = |
| 933 | "varying float v_varying;\n" |
| 934 | "vec2 f() { if (v_varying > 0.0) return vec2(1.0, 1.0); }\n" |
| 935 | "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; |
| 936 | |
| 937 | const std::string fragmentShaderSource = |
| 938 | "precision mediump float;\n" |
| 939 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 940 | |
| 941 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 942 | EXPECT_NE(0u, program); |
| 943 | } |
| 944 | |
| 945 | // Verify that functions without return statements still compile |
| 946 | TEST_P(GLSLTest, MissingReturnVec3) |
| 947 | { |
| 948 | const std::string vertexShaderSource = |
| 949 | "varying float v_varying;\n" |
| 950 | "vec3 f() { if (v_varying > 0.0) return vec3(1.0, 1.0, 1.0); }\n" |
| 951 | "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; |
| 952 | |
| 953 | const std::string fragmentShaderSource = |
| 954 | "precision mediump float;\n" |
| 955 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 956 | |
| 957 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 958 | EXPECT_NE(0u, program); |
| 959 | } |
| 960 | |
| 961 | // Verify that functions without return statements still compile |
| 962 | TEST_P(GLSLTest, MissingReturnVec4) |
| 963 | { |
| 964 | const std::string vertexShaderSource = |
| 965 | "varying float v_varying;\n" |
| 966 | "vec4 f() { if (v_varying > 0.0) return vec4(1.0, 1.0, 1.0, 1.0); }\n" |
| 967 | "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; |
| 968 | |
| 969 | const std::string fragmentShaderSource = |
| 970 | "precision mediump float;\n" |
| 971 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 972 | |
| 973 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 974 | EXPECT_NE(0u, program); |
| 975 | } |
| 976 | |
| 977 | // Verify that functions without return statements still compile |
| 978 | TEST_P(GLSLTest, MissingReturnIVec4) |
| 979 | { |
| 980 | const std::string vertexShaderSource = |
| 981 | "varying float v_varying;\n" |
| 982 | "ivec4 f() { if (v_varying > 0.0) return ivec4(1, 1, 1, 1); }\n" |
| 983 | "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; |
| 984 | |
| 985 | const std::string fragmentShaderSource = |
| 986 | "precision mediump float;\n" |
| 987 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 988 | |
| 989 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 990 | EXPECT_NE(0u, program); |
| 991 | } |
| 992 | |
| 993 | // Verify that functions without return statements still compile |
| 994 | TEST_P(GLSLTest, MissingReturnMat4) |
| 995 | { |
| 996 | const std::string vertexShaderSource = |
| 997 | "varying float v_varying;\n" |
| 998 | "mat4 f() { if (v_varying > 0.0) return mat4(1.0); }\n" |
| 999 | "void main() { gl_Position = vec4(f()[0][0], 0, 0, 1); }\n"; |
| 1000 | |
| 1001 | const std::string fragmentShaderSource = |
| 1002 | "precision mediump float;\n" |
| 1003 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1004 | |
| 1005 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1006 | EXPECT_NE(0u, program); |
| 1007 | } |
| 1008 | |
| 1009 | // Verify that functions without return statements still compile |
| 1010 | TEST_P(GLSLTest, MissingReturnStruct) |
| 1011 | { |
| 1012 | const std::string vertexShaderSource = |
| 1013 | "varying float v_varying;\n" |
| 1014 | "struct s { float a; int b; vec2 c; };\n" |
| 1015 | "s f() { if (v_varying > 0.0) return s(1.0, 1, vec2(1.0, 1.0)); }\n" |
| 1016 | "void main() { gl_Position = vec4(f().a, 0, 0, 1); }\n"; |
| 1017 | |
| 1018 | const std::string fragmentShaderSource = |
| 1019 | "precision mediump float;\n" |
| 1020 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1021 | |
| 1022 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1023 | EXPECT_NE(0u, program); |
| 1024 | } |
| 1025 | |
| 1026 | // Verify that functions without return statements still compile |
| 1027 | TEST_P(GLSLTest_ES3, MissingReturnArray) |
| 1028 | { |
| 1029 | const std::string vertexShaderSource = |
| 1030 | "#version 300 es\n" |
| 1031 | "in float v_varying;\n" |
| 1032 | "vec2[2] f() { if (v_varying > 0.0) { return vec2[2](vec2(1.0, 1.0), vec2(1.0, 1.0)); } }\n" |
| 1033 | "void main() { gl_Position = vec4(f()[0].x, 0, 0, 1); }\n"; |
| 1034 | |
| 1035 | const std::string fragmentShaderSource = |
| 1036 | "#version 300 es\n" |
| 1037 | "precision mediump float;\n" |
| 1038 | "out vec4 my_FragColor;\n" |
| 1039 | "void main() { my_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1040 | |
| 1041 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1042 | EXPECT_NE(0u, program); |
| 1043 | } |
| 1044 | |
| 1045 | // Verify that functions without return statements still compile |
| 1046 | TEST_P(GLSLTest_ES3, MissingReturnArrayOfStructs) |
| 1047 | { |
| 1048 | const std::string vertexShaderSource = |
| 1049 | "#version 300 es\n" |
| 1050 | "in float v_varying;\n" |
| 1051 | "struct s { float a; int b; vec2 c; };\n" |
| 1052 | "s[2] f() { if (v_varying > 0.0) { return s[2](s(1.0, 1, vec2(1.0, 1.0)), s(1.0, 1, " |
| 1053 | "vec2(1.0, 1.0))); } }\n" |
| 1054 | "void main() { gl_Position = vec4(f()[0].a, 0, 0, 1); }\n"; |
| 1055 | |
| 1056 | const std::string fragmentShaderSource = |
| 1057 | "#version 300 es\n" |
| 1058 | "precision mediump float;\n" |
| 1059 | "out vec4 my_FragColor;\n" |
| 1060 | "void main() { my_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1061 | |
| 1062 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1063 | EXPECT_NE(0u, program); |
| 1064 | } |
| 1065 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 1066 | // Verify that using invariant(all) in both shaders fails in ESSL 3.00. |
| 1067 | TEST_P(GLSLTest_ES3, InvariantAllBoth) |
| 1068 | { |
| 1069 | const std::string fragmentShaderSource = |
| 1070 | "#version 300 es\n" |
| 1071 | "#pragma STDGL invariant(all)\n" |
| 1072 | "precision mediump float;\n" |
| 1073 | "in float v_varying;\n" |
| 1074 | "out vec4 my_FragColor;\n" |
| 1075 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1076 | |
| 1077 | const std::string vertexShaderSource = |
| 1078 | "#version 300 es\n" |
| 1079 | "#pragma STDGL invariant(all)\n" |
| 1080 | "in vec4 a_position;\n" |
| 1081 | "out float v_varying;\n" |
| 1082 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1083 | |
| 1084 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1085 | EXPECT_EQ(0u, program); |
| 1086 | } |
| 1087 | |
| 1088 | // Verify that using invariant(all) only in fragment shader fails in ESSL 1.00. |
| 1089 | TEST_P(GLSLTest, InvariantAllIn) |
| 1090 | { |
| 1091 | const std::string fragmentShaderSource = |
| 1092 | "#pragma STDGL invariant(all)\n" |
| 1093 | "precision mediump float;\n" |
| 1094 | "varying float v_varying;\n" |
| 1095 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1096 | |
| 1097 | const std::string vertexShaderSource = |
| 1098 | "attribute vec4 a_position;\n" |
| 1099 | "varying float v_varying;\n" |
| 1100 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1101 | |
| 1102 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1103 | EXPECT_EQ(0u, program); |
| 1104 | } |
| 1105 | |
| 1106 | // Verify that using invariant(all) only in fragment shader fails in ESSL 3.00. |
| 1107 | TEST_P(GLSLTest_ES3, InvariantAllIn) |
| 1108 | { |
| 1109 | const std::string fragmentShaderSource = |
| 1110 | "#version 300 es\n" |
| 1111 | "#pragma STDGL invariant(all)\n" |
| 1112 | "precision mediump float;\n" |
| 1113 | "in float v_varying;\n" |
| 1114 | "out vec4 my_FragColor;\n" |
| 1115 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1116 | |
| 1117 | const std::string vertexShaderSource = |
| 1118 | "#version 300 es\n" |
| 1119 | "in vec4 a_position;\n" |
| 1120 | "out float v_varying;\n" |
| 1121 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1122 | |
| 1123 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1124 | EXPECT_EQ(0u, program); |
| 1125 | } |
| 1126 | |
| 1127 | // Verify that using invariant(all) only in vertex shader fails in ESSL 1.00. |
| 1128 | TEST_P(GLSLTest, InvariantAllOut) |
| 1129 | { |
| 1130 | const std::string fragmentShaderSource = |
| 1131 | "precision mediump float;\n" |
| 1132 | "varying float v_varying;\n" |
| 1133 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1134 | |
| 1135 | const std::string vertexShaderSource = |
| 1136 | "#pragma STDGL invariant(all)\n" |
| 1137 | "attribute vec4 a_position;\n" |
| 1138 | "varying float v_varying;\n" |
| 1139 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1140 | |
| 1141 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1142 | EXPECT_EQ(0u, program); |
| 1143 | } |
| 1144 | |
| 1145 | // Verify that using invariant(all) only in vertex shader succeeds in ESSL 3.00. |
| 1146 | TEST_P(GLSLTest_ES3, InvariantAllOut) |
| 1147 | { |
| 1148 | // TODO: ESSL 3.00 -> GLSL 1.20 translation should add "invariant" in fragment shader |
| 1149 | // for varyings which are invariant in vertex shader, |
| 1150 | // because of invariant(all) being used in vertex shader (http://anglebug.com/1293) |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 1151 | if (IsDesktopOpenGL()) |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 1152 | { |
| 1153 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1154 | return; |
| 1155 | } |
| 1156 | |
| 1157 | const std::string fragmentShaderSource = |
| 1158 | "#version 300 es\n" |
| 1159 | "precision mediump float;\n" |
| 1160 | "in float v_varying;\n" |
| 1161 | "out vec4 my_FragColor;\n" |
| 1162 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1163 | |
| 1164 | const std::string vertexShaderSource = |
| 1165 | "#version 300 es\n" |
| 1166 | "#pragma STDGL invariant(all)\n" |
| 1167 | "in vec4 a_position;\n" |
| 1168 | "out float v_varying;\n" |
| 1169 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1170 | |
| 1171 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1172 | EXPECT_NE(0u, program); |
| 1173 | } |
| 1174 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1175 | TEST_P(GLSLTest, MaxVaryingVec4) |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1176 | { |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1177 | #if defined(__APPLE__) |
| 1178 | // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers |
| 1179 | // (http://anglebug.com/1291) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1180 | if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1181 | { |
| 1182 | std::cout << "Test disabled on Apple AMD OpenGL." << std::endl; |
| 1183 | return; |
| 1184 | } |
| 1185 | #endif |
| 1186 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1187 | GLint maxVaryings = 0; |
| 1188 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1189 | |
| 1190 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, false, false, true); |
| 1191 | } |
| 1192 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1193 | TEST_P(GLSLTest, MaxMinusTwoVaryingVec4PlusTwoSpecialVariables) |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1194 | { |
| 1195 | GLint maxVaryings = 0; |
| 1196 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1197 | |
| 1198 | // Generate shader code that uses gl_FragCoord and gl_PointCoord, two special fragment shader variables. |
| 1199 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings - 2, 0, true, true, false, true); |
| 1200 | } |
| 1201 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1202 | TEST_P(GLSLTest, MaxMinusTwoVaryingVec4PlusThreeSpecialVariables) |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1203 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1204 | // TODO(geofflang): Figure out why this fails on OpenGL AMD (http://anglebug.com/1291) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1205 | if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1206 | { |
| 1207 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1208 | return; |
| 1209 | } |
| 1210 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1211 | GLint maxVaryings = 0; |
| 1212 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1213 | |
| 1214 | // Generate shader code that uses gl_FragCoord, gl_PointCoord and gl_PointSize. |
| 1215 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings - 2, 0, true, true, true, true); |
| 1216 | } |
| 1217 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1218 | // Disabled because drivers are allowed to successfully compile shaders that have more than the |
| 1219 | // maximum number of varyings. (http://anglebug.com/1296) |
| 1220 | TEST_P(GLSLTest, DISABLED_MaxVaryingVec4PlusFragCoord) |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1221 | { |
| 1222 | GLint maxVaryings = 0; |
| 1223 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1224 | |
| 1225 | // Generate shader code that uses gl_FragCoord, a special fragment shader variables. |
| 1226 | // This test should fail, since we are really using (maxVaryings + 1) varyings. |
| 1227 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, true, false, false, false); |
| 1228 | } |
| 1229 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1230 | // Disabled because drivers are allowed to successfully compile shaders that have more than the |
| 1231 | // maximum number of varyings. (http://anglebug.com/1296) |
| 1232 | TEST_P(GLSLTest, DISABLED_MaxVaryingVec4PlusPointCoord) |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1233 | { |
| 1234 | GLint maxVaryings = 0; |
| 1235 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1236 | |
| 1237 | // Generate shader code that uses gl_FragCoord, a special fragment shader variables. |
| 1238 | // This test should fail, since we are really using (maxVaryings + 1) varyings. |
| 1239 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, true, false, false); |
| 1240 | } |
| 1241 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1242 | TEST_P(GLSLTest, MaxVaryingVec3) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1243 | { |
| 1244 | GLint maxVaryings = 0; |
| 1245 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1246 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1247 | VaryingTestBase(0, 0, 0, 0, maxVaryings, 0, 0, 0, false, false, false, true); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1250 | TEST_P(GLSLTest, MaxVaryingVec3Array) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1251 | { |
| 1252 | GLint maxVaryings = 0; |
| 1253 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1254 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1255 | VaryingTestBase(0, 0, 0, 0, 0, maxVaryings / 2, 0, 0, false, false, false, true); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Jamie Madill | bee59e0 | 2014-10-02 10:44:18 -0400 | [diff] [blame] | 1258 | // Disabled because of a failure in D3D9 |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1259 | TEST_P(GLSLTest, MaxVaryingVec3AndOneFloat) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1260 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1261 | if (IsD3D9()) |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1262 | { |
| 1263 | std::cout << "Test disabled on D3D9." << std::endl; |
| 1264 | return; |
| 1265 | } |
| 1266 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1267 | GLint maxVaryings = 0; |
| 1268 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1269 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1270 | VaryingTestBase(1, 0, 0, 0, maxVaryings, 0, 0, 0, false, false, false, true); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Jamie Madill | bee59e0 | 2014-10-02 10:44:18 -0400 | [diff] [blame] | 1273 | // Disabled because of a failure in D3D9 |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1274 | TEST_P(GLSLTest, MaxVaryingVec3ArrayAndOneFloatArray) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1275 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1276 | if (IsD3D9()) |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1277 | { |
| 1278 | std::cout << "Test disabled on D3D9." << std::endl; |
| 1279 | return; |
| 1280 | } |
| 1281 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1282 | GLint maxVaryings = 0; |
| 1283 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1284 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1285 | VaryingTestBase(0, 1, 0, 0, 0, maxVaryings / 2, 0, 0, false, false, false, true); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Jamie Madill | bee59e0 | 2014-10-02 10:44:18 -0400 | [diff] [blame] | 1288 | // Disabled because of a failure in D3D9 |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1289 | TEST_P(GLSLTest, TwiceMaxVaryingVec2) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1290 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1291 | if (IsD3D9()) |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1292 | { |
| 1293 | std::cout << "Test disabled on D3D9." << std::endl; |
| 1294 | return; |
| 1295 | } |
| 1296 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1297 | if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1298 | { |
| 1299 | // TODO(geofflang): Figure out why this fails on NVIDIA's GLES driver |
| 1300 | std::cout << "Test disabled on OpenGL ES." << std::endl; |
| 1301 | return; |
| 1302 | } |
| 1303 | |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1304 | #if defined(__APPLE__) |
| 1305 | // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers |
| 1306 | // (http://anglebug.com/1291) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1307 | if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1308 | { |
| 1309 | std::cout << "Test disabled on Apple AMD OpenGL." << std::endl; |
| 1310 | return; |
| 1311 | } |
| 1312 | #endif |
| 1313 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1314 | GLint maxVaryings = 0; |
| 1315 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1316 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1317 | VaryingTestBase(0, 0, 2 * maxVaryings, 0, 0, 0, 0, 0, false, false, false, true); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Jamie Madill | bee59e0 | 2014-10-02 10:44:18 -0400 | [diff] [blame] | 1320 | // Disabled because of a failure in D3D9 |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1321 | TEST_P(GLSLTest, MaxVaryingVec2Arrays) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1322 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1323 | if (IsD3DSM3()) |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1324 | { |
| 1325 | std::cout << "Test disabled on SM3." << std::endl; |
| 1326 | return; |
| 1327 | } |
| 1328 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1329 | if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1330 | { |
| 1331 | // TODO(geofflang): Figure out why this fails on NVIDIA's GLES driver |
| 1332 | std::cout << "Test disabled on OpenGL ES." << std::endl; |
| 1333 | return; |
| 1334 | } |
| 1335 | |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1336 | #if defined(__APPLE__) |
| 1337 | // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers |
| 1338 | // (http://anglebug.com/1291) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1339 | if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1340 | { |
| 1341 | std::cout << "Test disabled on Apple AMD OpenGL." << std::endl; |
| 1342 | return; |
| 1343 | } |
| 1344 | #endif |
| 1345 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1346 | GLint maxVaryings = 0; |
| 1347 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1348 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1349 | VaryingTestBase(0, 0, 0, maxVaryings, 0, 0, 0, 0, false, false, false, true); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1352 | // Disabled because drivers are allowed to successfully compile shaders that have more than the |
| 1353 | // maximum number of varyings. (http://anglebug.com/1296) |
| 1354 | TEST_P(GLSLTest, DISABLED_MaxPlusOneVaryingVec3) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1355 | { |
| 1356 | GLint maxVaryings = 0; |
| 1357 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1358 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1359 | VaryingTestBase(0, 0, 0, 0, maxVaryings + 1, 0, 0, 0, false, false, false, false); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1362 | // Disabled because drivers are allowed to successfully compile shaders that have more than the |
| 1363 | // maximum number of varyings. (http://anglebug.com/1296) |
| 1364 | TEST_P(GLSLTest, DISABLED_MaxPlusOneVaryingVec3Array) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1365 | { |
| 1366 | GLint maxVaryings = 0; |
| 1367 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1368 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1369 | VaryingTestBase(0, 0, 0, 0, 0, maxVaryings / 2 + 1, 0, 0, false, false, false, false); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1372 | // Disabled because drivers are allowed to successfully compile shaders that have more than the |
| 1373 | // maximum number of varyings. (http://anglebug.com/1296) |
| 1374 | TEST_P(GLSLTest, DISABLED_MaxVaryingVec3AndOneVec2) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1375 | { |
| 1376 | GLint maxVaryings = 0; |
| 1377 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1378 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1379 | VaryingTestBase(0, 0, 1, 0, maxVaryings, 0, 0, 0, false, false, false, false); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1382 | // Disabled because drivers are allowed to successfully compile shaders that have more than the |
| 1383 | // maximum number of varyings. (http://anglebug.com/1296) |
| 1384 | TEST_P(GLSLTest, DISABLED_MaxPlusOneVaryingVec2) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1385 | { |
| 1386 | GLint maxVaryings = 0; |
| 1387 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1388 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1389 | VaryingTestBase(0, 0, 2 * maxVaryings + 1, 0, 0, 0, 0, 0, false, false, false, false); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1392 | // Disabled because drivers are allowed to successfully compile shaders that have more than the |
| 1393 | // maximum number of varyings. (http://anglebug.com/1296) |
| 1394 | TEST_P(GLSLTest, DISABLED_MaxVaryingVec3ArrayAndMaxPlusOneFloatArray) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1395 | { |
| 1396 | GLint maxVaryings = 0; |
| 1397 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1398 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1399 | VaryingTestBase(0, maxVaryings / 2 + 1, 0, 0, 0, 0, 0, maxVaryings / 2, false, false, false, false); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1400 | } |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1401 | |
| 1402 | // Verify shader source with a fixed length that is less than the null-terminated length will compile. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1403 | TEST_P(GLSLTest, FixedShaderLength) |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1404 | { |
| 1405 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1406 | |
| 1407 | const std::string appendGarbage = "abcasdfasdfasdfasdfasdf"; |
| 1408 | const std::string source = "void main() { gl_FragColor = vec4(0, 0, 0, 0); }" + appendGarbage; |
| 1409 | const char *sourceArray[1] = { source.c_str() }; |
Corentin Wallez | 973402f | 2015-05-11 13:42:22 -0400 | [diff] [blame] | 1410 | GLint lengths[1] = { static_cast<GLint>(source.length() - appendGarbage.length()) }; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1411 | glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths); |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1412 | glCompileShader(shader); |
| 1413 | |
| 1414 | GLint compileResult; |
| 1415 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1416 | EXPECT_NE(compileResult, 0); |
| 1417 | } |
| 1418 | |
| 1419 | // Verify that a negative shader source length is treated as a null-terminated length. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1420 | TEST_P(GLSLTest, NegativeShaderLength) |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1421 | { |
| 1422 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1423 | |
| 1424 | const char *sourceArray[1] = { "void main() { gl_FragColor = vec4(0, 0, 0, 0); }" }; |
| 1425 | GLint lengths[1] = { -10 }; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1426 | glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths); |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1427 | glCompileShader(shader); |
| 1428 | |
| 1429 | GLint compileResult; |
| 1430 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1431 | EXPECT_NE(compileResult, 0); |
| 1432 | } |
| 1433 | |
Corentin Wallez | 9a9c048 | 2016-04-12 10:36:25 -0400 | [diff] [blame] | 1434 | // Check that having an invalid char after the "." doesn't cause an assert. |
| 1435 | TEST_P(GLSLTest, InvalidFieldFirstChar) |
| 1436 | { |
| 1437 | GLuint shader = glCreateShader(GL_VERTEX_SHADER); |
| 1438 | const char *source = "void main() {vec4 x; x.}"; |
| 1439 | glShaderSource(shader, 1, &source, 0); |
| 1440 | glCompileShader(shader); |
| 1441 | |
| 1442 | GLint compileResult; |
| 1443 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1444 | EXPECT_EQ(0, compileResult); |
| 1445 | } |
| 1446 | |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1447 | // Verify that a length array with mixed positive and negative values compiles. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1448 | TEST_P(GLSLTest, MixedShaderLengths) |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1449 | { |
| 1450 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1451 | |
| 1452 | const char *sourceArray[] = |
| 1453 | { |
| 1454 | "void main()", |
| 1455 | "{", |
| 1456 | " gl_FragColor = vec4(0, 0, 0, 0);", |
| 1457 | "}", |
| 1458 | }; |
| 1459 | GLint lengths[] = |
| 1460 | { |
| 1461 | -10, |
| 1462 | 1, |
Corentin Wallez | 973402f | 2015-05-11 13:42:22 -0400 | [diff] [blame] | 1463 | static_cast<GLint>(strlen(sourceArray[2])), |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1464 | -1, |
| 1465 | }; |
| 1466 | ASSERT_EQ(ArraySize(sourceArray), ArraySize(lengths)); |
| 1467 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1468 | glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths); |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1469 | glCompileShader(shader); |
| 1470 | |
| 1471 | GLint compileResult; |
| 1472 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1473 | EXPECT_NE(compileResult, 0); |
| 1474 | } |
| 1475 | |
| 1476 | // Verify that zero-length shader source does not affect shader compilation. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1477 | TEST_P(GLSLTest, ZeroShaderLength) |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1478 | { |
| 1479 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1480 | |
| 1481 | const char *sourceArray[] = |
| 1482 | { |
| 1483 | "adfasdf", |
| 1484 | "34534", |
| 1485 | "void main() { gl_FragColor = vec4(0, 0, 0, 0); }", |
| 1486 | "", |
| 1487 | "asdfasdfsdsdf", |
| 1488 | }; |
| 1489 | GLint lengths[] = |
| 1490 | { |
| 1491 | 0, |
| 1492 | 0, |
| 1493 | -1, |
| 1494 | 0, |
| 1495 | 0, |
| 1496 | }; |
| 1497 | ASSERT_EQ(ArraySize(sourceArray), ArraySize(lengths)); |
| 1498 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1499 | glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths); |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1500 | glCompileShader(shader); |
| 1501 | |
| 1502 | GLint compileResult; |
| 1503 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1504 | EXPECT_NE(compileResult, 0); |
| 1505 | } |
Jamie Madill | 21c1e45 | 2014-12-29 11:33:41 -0500 | [diff] [blame] | 1506 | |
| 1507 | // Tests that bad index expressions don't crash ANGLE's translator. |
| 1508 | // https://code.google.com/p/angleproject/issues/detail?id=857 |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1509 | TEST_P(GLSLTest, BadIndexBug) |
Jamie Madill | 21c1e45 | 2014-12-29 11:33:41 -0500 | [diff] [blame] | 1510 | { |
| 1511 | const std::string &fragmentShaderSourceVec = |
| 1512 | "precision mediump float;\n" |
| 1513 | "uniform vec4 uniformVec;\n" |
| 1514 | "void main()\n" |
| 1515 | "{\n" |
| 1516 | " gl_FragColor = vec4(uniformVec[int()]);\n" |
| 1517 | "}"; |
| 1518 | |
| 1519 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceVec); |
| 1520 | EXPECT_EQ(0u, shader); |
| 1521 | |
| 1522 | if (shader != 0) |
| 1523 | { |
| 1524 | glDeleteShader(shader); |
| 1525 | } |
| 1526 | |
| 1527 | const std::string &fragmentShaderSourceMat = |
| 1528 | "precision mediump float;\n" |
| 1529 | "uniform mat4 uniformMat;\n" |
| 1530 | "void main()\n" |
| 1531 | "{\n" |
| 1532 | " gl_FragColor = vec4(uniformMat[int()]);\n" |
| 1533 | "}"; |
| 1534 | |
| 1535 | shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceMat); |
| 1536 | EXPECT_EQ(0u, shader); |
| 1537 | |
| 1538 | if (shader != 0) |
| 1539 | { |
| 1540 | glDeleteShader(shader); |
| 1541 | } |
| 1542 | |
| 1543 | const std::string &fragmentShaderSourceArray = |
| 1544 | "precision mediump float;\n" |
| 1545 | "uniform vec4 uniformArray;\n" |
| 1546 | "void main()\n" |
| 1547 | "{\n" |
| 1548 | " gl_FragColor = vec4(uniformArray[int()]);\n" |
| 1549 | "}"; |
| 1550 | |
| 1551 | shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceArray); |
| 1552 | EXPECT_EQ(0u, shader); |
| 1553 | |
| 1554 | if (shader != 0) |
| 1555 | { |
| 1556 | glDeleteShader(shader); |
| 1557 | } |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1558 | } |
| 1559 | |
Jamie Madill | 2e295e2 | 2015-04-29 10:41:33 -0400 | [diff] [blame] | 1560 | // Test that structs defined in uniforms are translated correctly. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1561 | TEST_P(GLSLTest, StructSpecifiersUniforms) |
Jamie Madill | 2e295e2 | 2015-04-29 10:41:33 -0400 | [diff] [blame] | 1562 | { |
| 1563 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 1564 | ( |
| 1565 | precision mediump float; |
| 1566 | |
| 1567 | uniform struct S { float field;} s; |
| 1568 | |
| 1569 | void main() |
| 1570 | { |
| 1571 | gl_FragColor = vec4(1, 0, 0, 1); |
| 1572 | gl_FragColor.a += s.field; |
| 1573 | } |
| 1574 | ); |
| 1575 | |
| 1576 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 1577 | EXPECT_NE(0u, program); |
| 1578 | } |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1579 | |
| 1580 | // Test that gl_DepthRange is not stored as a uniform location. Since uniforms |
| 1581 | // beginning with "gl_" are filtered out by our validation logic, we must |
| 1582 | // bypass the validation to test the behaviour of the implementation. |
| 1583 | // (note this test is still Impl-independent) |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1584 | TEST_P(GLSLTest, DepthRangeUniforms) |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1585 | { |
| 1586 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 1587 | ( |
| 1588 | precision mediump float; |
| 1589 | |
| 1590 | void main() |
| 1591 | { |
| 1592 | gl_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff, 1); |
| 1593 | } |
| 1594 | ); |
| 1595 | |
| 1596 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 1597 | EXPECT_NE(0u, program); |
| 1598 | |
| 1599 | // dive into the ANGLE internals, so we can bypass validation. |
| 1600 | gl::Context *context = reinterpret_cast<gl::Context *>(getEGLWindow()->getContext()); |
| 1601 | gl::Program *glProgram = context->getProgram(program); |
| 1602 | GLint nearIndex = glProgram->getUniformLocation("gl_DepthRange.near"); |
| 1603 | EXPECT_EQ(-1, nearIndex); |
| 1604 | |
| 1605 | // Test drawing does not throw an exception. |
| 1606 | drawQuad(program, "inputAttribute", 0.5f); |
| 1607 | |
| 1608 | EXPECT_GL_NO_ERROR(); |
| 1609 | |
| 1610 | glDeleteProgram(program); |
| 1611 | } |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1612 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1613 | std::string GenerateSmallPowShader(double base, double exponent) |
| 1614 | { |
| 1615 | std::stringstream stream; |
| 1616 | |
| 1617 | stream.precision(8); |
| 1618 | |
| 1619 | double result = pow(base, exponent); |
| 1620 | |
| 1621 | stream << "precision highp float;\n" |
| 1622 | << "float fun(float arg)\n" |
| 1623 | << "{\n" |
| 1624 | << " return pow(arg, " << std::fixed << exponent << ");\n" |
| 1625 | << "}\n" |
| 1626 | << "\n" |
| 1627 | << "void main()\n" |
| 1628 | << "{\n" |
| 1629 | << " const float a = " << std::scientific << base << ";\n" |
| 1630 | << " float b = fun(a);\n" |
| 1631 | << " if (abs(" << result << " - b) < " << std::abs(result * 0.001) << ")\n" |
| 1632 | << " {\n" |
| 1633 | << " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 1634 | << " }\n" |
| 1635 | << " else\n" |
| 1636 | << " {\n" |
| 1637 | << " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1638 | << " }\n" |
| 1639 | << "}\n"; |
| 1640 | |
| 1641 | return stream.str(); |
| 1642 | } |
| 1643 | |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1644 | // Covers the WebGL test 'glsl/bugs/pow-of-small-constant-in-user-defined-function' |
Jamie Madill | 1048e43 | 2016-07-23 18:51:28 -0400 | [diff] [blame] | 1645 | // See http://anglebug.com/851 |
| 1646 | TEST_P(GLSLTest, PowOfSmallConstant) |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1647 | { |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1648 | std::vector<double> bads; |
| 1649 | for (int eps = -1; eps <= 1; ++eps) |
| 1650 | { |
| 1651 | for (int i = -4; i <= 5; ++i) |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1652 | { |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1653 | if (i >= -1 && i <= 1) |
| 1654 | continue; |
| 1655 | const double epsilon = 1.0e-8; |
| 1656 | double bad = static_cast<double>(i) + static_cast<double>(eps) * epsilon; |
| 1657 | bads.push_back(bad); |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1658 | } |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1659 | } |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1660 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1661 | for (double bad : bads) |
| 1662 | { |
| 1663 | const std::string &fragmentShaderSource = GenerateSmallPowShader(1.0e-6, bad); |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1664 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1665 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1666 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1667 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 1668 | |
| 1669 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1670 | EXPECT_GL_NO_ERROR(); |
| 1671 | } |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1672 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1673 | |
Cooper Partin | a5ef8d8 | 2015-08-19 14:52:21 -0700 | [diff] [blame] | 1674 | // Test that fragment shaders which contain non-constant loop indexers and compiled for FL9_3 and |
| 1675 | // below |
| 1676 | // fail with a specific error message. |
| 1677 | // Additionally test that the same fragment shader compiles successfully with feature levels greater |
| 1678 | // than FL9_3. |
| 1679 | TEST_P(GLSLTest, LoopIndexingValidation) |
| 1680 | { |
| 1681 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 1682 | ( |
| 1683 | precision mediump float; |
| 1684 | |
| 1685 | uniform float loopMax; |
| 1686 | |
| 1687 | void main() |
| 1688 | { |
| 1689 | gl_FragColor = vec4(1, 0, 0, 1); |
| 1690 | for (float l = 0.0; l < loopMax; l++) |
| 1691 | { |
| 1692 | if (loopMax > 3.0) |
| 1693 | { |
| 1694 | gl_FragColor.a += 0.1; |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | ); |
| 1699 | |
| 1700 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1701 | |
| 1702 | const char *sourceArray[1] = {fragmentShaderSource.c_str()}; |
| 1703 | glShaderSource(shader, 1, sourceArray, nullptr); |
| 1704 | glCompileShader(shader); |
| 1705 | |
| 1706 | GLint compileResult; |
| 1707 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1708 | |
| 1709 | // If the test is configured to run limited to Feature Level 9_3, then it is |
| 1710 | // assumed that shader compilation will fail with an expected error message containing |
| 1711 | // "Loop index cannot be compared with non-constant expression" |
Olli Etuaho | 814a54d | 2015-08-27 16:23:09 +0300 | [diff] [blame] | 1712 | if ((GetParam() == ES2_D3D11_FL9_3() || GetParam() == ES2_D3D9())) |
Cooper Partin | a5ef8d8 | 2015-08-19 14:52:21 -0700 | [diff] [blame] | 1713 | { |
| 1714 | if (compileResult != 0) |
| 1715 | { |
| 1716 | FAIL() << "Shader compilation succeeded, expected failure"; |
| 1717 | } |
| 1718 | else |
| 1719 | { |
| 1720 | GLint infoLogLength; |
| 1721 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 1722 | |
| 1723 | std::string infoLog; |
| 1724 | infoLog.resize(infoLogLength); |
| 1725 | glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]); |
| 1726 | |
| 1727 | if (infoLog.find("Loop index cannot be compared with non-constant expression") == |
| 1728 | std::string::npos) |
| 1729 | { |
| 1730 | FAIL() << "Shader compilation failed with unexpected error message"; |
| 1731 | } |
| 1732 | } |
| 1733 | } |
| 1734 | else |
| 1735 | { |
| 1736 | EXPECT_NE(0, compileResult); |
| 1737 | } |
| 1738 | |
| 1739 | if (shader != 0) |
| 1740 | { |
| 1741 | glDeleteShader(shader); |
| 1742 | } |
| 1743 | } |
| 1744 | |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1745 | // Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS |
| 1746 | // can actually be used. |
| 1747 | TEST_P(GLSLTest, VerifyMaxVertexUniformVectors) |
| 1748 | { |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1749 | int maxUniforms = 10000; |
| 1750 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms); |
| 1751 | EXPECT_GL_NO_ERROR(); |
| 1752 | std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl; |
| 1753 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1754 | CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, 0, 0, true); |
| 1755 | } |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1756 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1757 | // Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS |
| 1758 | // can actually be used along with the maximum number of texture samplers. |
| 1759 | TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsWithSamplers) |
| 1760 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1761 | if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE || |
| 1762 | GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1763 | { |
| 1764 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1765 | return; |
| 1766 | } |
| 1767 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1768 | int maxUniforms = 10000; |
| 1769 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms); |
| 1770 | EXPECT_GL_NO_ERROR(); |
| 1771 | std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl; |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1772 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1773 | int maxTextureImageUnits = 0; |
| 1774 | glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1775 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1776 | CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, maxTextureImageUnits, 0, true); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | // Tests that the maximum uniforms count + 1 from querying GL_MAX_VERTEX_UNIFORM_VECTORS |
| 1780 | // fails shader compilation. |
| 1781 | TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsExceeded) |
| 1782 | { |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1783 | int maxUniforms = 10000; |
| 1784 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms); |
| 1785 | EXPECT_GL_NO_ERROR(); |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1786 | std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS + 1 = " << maxUniforms + 1 << std::endl; |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1787 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1788 | CompileGLSLWithUniformsAndSamplers(maxUniforms + 1, 0, 0, 0, false); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | // Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS |
| 1792 | // can actually be used. |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1793 | TEST_P(GLSLTest, VerifyMaxFragmentUniformVectors) |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1794 | { |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1795 | int maxUniforms = 10000; |
| 1796 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms); |
| 1797 | EXPECT_GL_NO_ERROR(); |
| 1798 | std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS = " << maxUniforms << std::endl; |
| 1799 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1800 | CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, 0, true); |
| 1801 | } |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1802 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1803 | // Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS |
| 1804 | // can actually be used along with the maximum number of texture samplers. |
| 1805 | TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsWithSamplers) |
| 1806 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1807 | if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE || |
| 1808 | GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1809 | { |
| 1810 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1811 | return; |
| 1812 | } |
| 1813 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1814 | int maxUniforms = 10000; |
| 1815 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms); |
| 1816 | EXPECT_GL_NO_ERROR(); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1817 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1818 | int maxTextureImageUnits = 0; |
| 1819 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1820 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1821 | CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, maxTextureImageUnits, true); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | // Tests that the maximum uniforms count + 1 from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS |
| 1825 | // fails shader compilation. |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1826 | TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsExceeded) |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1827 | { |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1828 | int maxUniforms = 10000; |
| 1829 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms); |
| 1830 | EXPECT_GL_NO_ERROR(); |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1831 | std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS + 1 = " << maxUniforms + 1 |
| 1832 | << std::endl; |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1833 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1834 | CompileGLSLWithUniformsAndSamplers(0, maxUniforms + 1, 0, 0, false); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 1837 | // Test that two constructors which have vec4 and mat2 parameters get disambiguated (issue in |
| 1838 | // HLSL). |
| 1839 | TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x2) |
| 1840 | { |
| 1841 | const std::string fragmentShaderSource = |
| 1842 | "#version 300 es\n" |
| 1843 | "precision highp float;\n" |
| 1844 | "out vec4 my_FragColor;\n" |
| 1845 | "void main()\n" |
| 1846 | "{\n" |
| 1847 | " my_FragColor = vec4(0.0);\n" |
| 1848 | "}"; |
| 1849 | |
| 1850 | const std::string vertexShaderSource = |
| 1851 | "#version 300 es\n" |
| 1852 | "precision highp float;\n" |
| 1853 | "in vec4 a_vec;\n" |
| 1854 | "in mat2 a_mat;\n" |
| 1855 | "void main()\n" |
| 1856 | "{\n" |
| 1857 | " gl_Position = vec4(a_vec) + vec4(a_mat);\n" |
| 1858 | "}"; |
| 1859 | |
| 1860 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1861 | EXPECT_NE(0u, program); |
| 1862 | } |
| 1863 | |
| 1864 | // Test that two constructors which have mat2x3 and mat3x2 parameters get disambiguated. |
| 1865 | // This was suspected to be an issue in HLSL, but HLSL seems to be able to natively choose between |
| 1866 | // the function signatures in this case. |
| 1867 | TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x3) |
| 1868 | { |
| 1869 | const std::string fragmentShaderSource = |
| 1870 | "#version 300 es\n" |
| 1871 | "precision highp float;\n" |
| 1872 | "out vec4 my_FragColor;\n" |
| 1873 | "void main()\n" |
| 1874 | "{\n" |
| 1875 | " my_FragColor = vec4(0.0);\n" |
| 1876 | "}"; |
| 1877 | |
| 1878 | const std::string vertexShaderSource = |
| 1879 | "#version 300 es\n" |
| 1880 | "precision highp float;\n" |
| 1881 | "in mat3x2 a_matA;\n" |
| 1882 | "in mat2x3 a_matB;\n" |
| 1883 | "void main()\n" |
| 1884 | "{\n" |
| 1885 | " gl_Position = vec4(a_matA) + vec4(a_matB);\n" |
| 1886 | "}"; |
| 1887 | |
| 1888 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1889 | EXPECT_NE(0u, program); |
| 1890 | } |
| 1891 | |
| 1892 | // Test that two functions which have vec4 and mat2 parameters get disambiguated (issue in HLSL). |
| 1893 | TEST_P(GLSLTest_ES3, AmbiguousFunctionCall2x2) |
| 1894 | { |
| 1895 | const std::string fragmentShaderSource = |
| 1896 | "#version 300 es\n" |
| 1897 | "precision highp float;\n" |
| 1898 | "out vec4 my_FragColor;\n" |
| 1899 | "void main()\n" |
| 1900 | "{\n" |
| 1901 | " my_FragColor = vec4(0.0);\n" |
| 1902 | "}"; |
| 1903 | |
| 1904 | const std::string vertexShaderSource = |
| 1905 | "#version 300 es\n" |
| 1906 | "precision highp float;\n" |
| 1907 | "in vec4 a_vec;\n" |
| 1908 | "in mat2 a_mat;\n" |
| 1909 | "vec4 foo(vec4 a)\n" |
| 1910 | "{\n" |
| 1911 | " return a;\n" |
| 1912 | "}\n" |
| 1913 | "vec4 foo(mat2 a)\n" |
| 1914 | "{\n" |
| 1915 | " return vec4(a[0][0]);\n" |
| 1916 | "}\n" |
| 1917 | "void main()\n" |
| 1918 | "{\n" |
| 1919 | " gl_Position = foo(a_vec) + foo(a_mat);\n" |
| 1920 | "}"; |
| 1921 | |
| 1922 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1923 | EXPECT_NE(0u, program); |
| 1924 | } |
| 1925 | |
| 1926 | // Test that an user-defined function with a large number of float4 parameters doesn't fail due to |
| 1927 | // the function name being too long. |
| 1928 | TEST_P(GLSLTest_ES3, LargeNumberOfFloat4Parameters) |
| 1929 | { |
| 1930 | const std::string fragmentShaderSource = |
| 1931 | "#version 300 es\n" |
| 1932 | "precision highp float;\n" |
| 1933 | "out vec4 my_FragColor;\n" |
| 1934 | "void main()\n" |
| 1935 | "{\n" |
| 1936 | " my_FragColor = vec4(0.0);\n" |
| 1937 | "}"; |
| 1938 | |
| 1939 | std::stringstream vertexShaderStream; |
| 1940 | const unsigned int paramCount = 1024u; |
| 1941 | |
| 1942 | vertexShaderStream << "#version 300 es\n" |
| 1943 | "precision highp float;\n" |
| 1944 | "in vec4 a_vec;\n" |
| 1945 | "vec4 lotsOfVec4Parameters("; |
| 1946 | for (unsigned int i = 0; i < paramCount; ++i) |
| 1947 | { |
| 1948 | vertexShaderStream << "vec4 a" << i << ", "; |
| 1949 | } |
| 1950 | vertexShaderStream << "vec4 aLast)\n" |
| 1951 | "{\n" |
| 1952 | " return "; |
| 1953 | for (unsigned int i = 0; i < paramCount; ++i) |
| 1954 | { |
| 1955 | vertexShaderStream << "a" << i << " + "; |
| 1956 | } |
| 1957 | vertexShaderStream << "aLast;\n" |
| 1958 | "}\n" |
| 1959 | "void main()\n" |
| 1960 | "{\n" |
| 1961 | " gl_Position = lotsOfVec4Parameters("; |
| 1962 | for (unsigned int i = 0; i < paramCount; ++i) |
| 1963 | { |
| 1964 | vertexShaderStream << "a_vec, "; |
| 1965 | } |
| 1966 | vertexShaderStream << "a_vec);\n" |
| 1967 | "}"; |
| 1968 | |
| 1969 | GLuint program = CompileProgram(vertexShaderStream.str(), fragmentShaderSource); |
| 1970 | EXPECT_NE(0u, program); |
| 1971 | } |
| 1972 | |
Olli Etuaho | d4f4c11 | 2016-04-15 15:11:24 +0300 | [diff] [blame] | 1973 | // This test was written specifically to stress DeferGlobalInitializers AST transformation. |
| 1974 | // Test a shader where a global constant array is initialized with an expression containing array |
| 1975 | // indexing. This initializer is tricky to constant fold, so if it's not constant folded it needs to |
| 1976 | // be handled in a way that doesn't generate statements in the global scope in HLSL output. |
| 1977 | // Also includes multiple array initializers in one declaration, where only the second one has |
| 1978 | // array indexing. This makes sure that the qualifier for the declaration is set correctly if |
| 1979 | // transformations are applied to the declaration also in the case of ESSL output. |
| 1980 | TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing) |
| 1981 | { |
Yuly Novikov | 41db224 | 2016-06-25 00:14:28 -0400 | [diff] [blame] | 1982 | // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1428 is fixed |
| 1983 | if (IsAndroid() && IsAdreno() && IsOpenGLES()) |
| 1984 | { |
| 1985 | std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl; |
| 1986 | return; |
| 1987 | } |
| 1988 | |
Olli Etuaho | d4f4c11 | 2016-04-15 15:11:24 +0300 | [diff] [blame] | 1989 | const std::string vertexShaderSource = |
| 1990 | "#version 300 es\n" |
| 1991 | "precision highp float;\n" |
| 1992 | "in vec4 a_vec;\n" |
| 1993 | "void main()\n" |
| 1994 | "{\n" |
| 1995 | " gl_Position = vec4(a_vec);\n" |
| 1996 | "}"; |
| 1997 | |
| 1998 | const std::string fragmentShaderSource = |
| 1999 | "#version 300 es\n" |
| 2000 | "precision highp float;\n" |
| 2001 | "out vec4 my_FragColor;\n" |
| 2002 | "const highp float f[2] = float[2](0.1, 0.2);\n" |
| 2003 | "const highp float[2] g = float[2](0.3, 0.4), h = float[2](0.5, f[1]);\n" |
| 2004 | "void main()\n" |
| 2005 | "{\n" |
| 2006 | " my_FragColor = vec4(h[1]);\n" |
| 2007 | "}"; |
| 2008 | |
| 2009 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 2010 | EXPECT_NE(0u, program); |
| 2011 | } |
| 2012 | |
Corentin Wallez | 419bfc9 | 2016-06-28 10:54:45 -0700 | [diff] [blame] | 2013 | // Test that index-constant sampler array indexing is supported. |
| 2014 | TEST_P(GLSLTest, IndexConstantSamplerArrayIndexing) |
| 2015 | { |
| 2016 | if (IsD3D11_FL93()) { |
| 2017 | std::cout << "Test skipped on D3D11 FL 9.3." << std::endl; |
| 2018 | return; |
| 2019 | } |
| 2020 | |
| 2021 | const std::string vertexShaderSource = |
| 2022 | "attribute vec4 vPosition;\n" |
| 2023 | "void main()\n" |
| 2024 | "{\n" |
| 2025 | " gl_Position = vPosition;\n" |
| 2026 | "}"; |
| 2027 | |
| 2028 | const std::string fragmentShaderSource = |
| 2029 | "precision mediump float;\n" |
| 2030 | "uniform sampler2D uni[2];\n" |
| 2031 | "\n" |
| 2032 | "float zero(int x)\n" |
| 2033 | "{\n" |
| 2034 | " return float(x) - float(x);\n" |
| 2035 | "}\n" |
| 2036 | "\n" |
| 2037 | "void main()\n" |
| 2038 | "{\n" |
| 2039 | " vec4 c = vec4(0,0,0,0);\n" |
| 2040 | " for (int ii = 1; ii < 3; ++ii) {\n" |
| 2041 | " if (c.x > 255.0) {\n" |
| 2042 | " c.x = 255.0 + zero(ii);\n" |
| 2043 | " break;\n" |
| 2044 | " }\n" |
| 2045 | // Index the sampler array with a predictable loop index (index-constant) as opposed to |
| 2046 | // a true constant. This is valid in OpenGL ES but isn't in many Desktop OpenGL versions, |
| 2047 | // without an extension. |
| 2048 | " c += texture2D(uni[ii - 1], vec2(0.5, 0.5));\n" |
| 2049 | " }\n" |
| 2050 | " gl_FragColor = c;\n" |
| 2051 | "}"; |
| 2052 | |
| 2053 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 2054 | EXPECT_NE(0u, program); |
| 2055 | } |
| 2056 | |
Corentin Wallez | b00dcee | 2016-07-11 17:42:58 -0400 | [diff] [blame] | 2057 | // Test that the #pragma directive is supported and doesn't trigger a compilation failure on the |
| 2058 | // native driver. The only pragma that gets passed to the OpenGL driver is "invariant" but we don't |
| 2059 | // want to test its behavior, so don't use any varyings. |
| 2060 | TEST_P(GLSLTest, PragmaDirective) |
| 2061 | { |
| 2062 | const std::string vertexShaderSource = |
| 2063 | "#pragma STDGL invariant(all)\n" |
| 2064 | "void main()\n" |
| 2065 | "{\n" |
| 2066 | " gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2067 | "}\n"; |
| 2068 | |
| 2069 | const std::string fragmentShaderSource = |
| 2070 | "precision mediump float;\n" |
| 2071 | "void main()\n" |
| 2072 | "{\n" |
| 2073 | " gl_FragColor = vec4(1.0);\n" |
| 2074 | "}\n"; |
| 2075 | |
| 2076 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 2077 | EXPECT_NE(0u, program); |
| 2078 | } |
| 2079 | |
Olli Etuaho | e1d199b | 2016-07-19 17:14:27 +0300 | [diff] [blame] | 2080 | // Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9). |
| 2081 | // The function call that returns the array needs to be evaluated after ++j for the expression to |
| 2082 | // return the correct value (true). |
| 2083 | TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderArray) |
| 2084 | { |
| 2085 | const std::string &fragmentShaderSource = |
| 2086 | "#version 300 es\n" |
| 2087 | "precision mediump float;\n" |
| 2088 | "out vec4 my_FragColor; \n" |
| 2089 | "int[2] func(int param) {\n" |
| 2090 | " return int[2](param, param);\n" |
| 2091 | "}\n" |
| 2092 | "void main() {\n" |
| 2093 | " int a[2]; \n" |
| 2094 | " for (int i = 0; i < 2; ++i) {\n" |
| 2095 | " a[i] = 1;\n" |
| 2096 | " }\n" |
| 2097 | " int j = 0; \n" |
| 2098 | " bool result = ((++j), (a == func(j)));\n" |
| 2099 | " my_FragColor = vec4(0.0, (result ? 1.0 : 0.0), 0.0, 1.0);\n" |
| 2100 | "}\n"; |
| 2101 | |
| 2102 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 2103 | ASSERT_NE(0u, program); |
| 2104 | |
| 2105 | drawQuad(program, "inputAttribute", 0.5f); |
| 2106 | |
| 2107 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2108 | } |
| 2109 | |
| 2110 | // Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9). |
| 2111 | // The short-circuiting expression needs to be evaluated after ++j for the expression to return the |
| 2112 | // correct value (true). |
| 2113 | TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderShortCircuit) |
| 2114 | { |
| 2115 | const std::string &fragmentShaderSource = |
| 2116 | "#version 300 es\n" |
| 2117 | "precision mediump float;\n" |
| 2118 | "out vec4 my_FragColor; \n" |
| 2119 | "void main() {\n" |
| 2120 | " int j = 0; \n" |
| 2121 | " bool result = ((++j), (j == 1 ? true : (++j == 3)));\n" |
| 2122 | " my_FragColor = vec4(0.0, ((result && j == 1) ? 1.0 : 0.0), 0.0, 1.0);\n" |
| 2123 | "}\n"; |
| 2124 | |
| 2125 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 2126 | ASSERT_NE(0u, program); |
| 2127 | |
| 2128 | drawQuad(program, "inputAttribute", 0.5f); |
| 2129 | |
| 2130 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2131 | } |
| 2132 | |
Jamie Madill | 666f65a | 2016-08-26 01:34:37 +0000 | [diff] [blame] | 2133 | // Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9). |
| 2134 | // Indexing the vector needs to be evaluated after func() for the right result. |
| 2135 | TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderDynamicVectorIndexingInLValue) |
| 2136 | { |
| 2137 | const std::string &fragmentShaderSource = |
| 2138 | "#version 300 es\n" |
| 2139 | "precision mediump float;\n" |
| 2140 | "out vec4 my_FragColor;\n" |
| 2141 | "uniform int u_zero;\n" |
| 2142 | "int sideEffectCount = 0;\n" |
| 2143 | "float func() {\n" |
| 2144 | " ++sideEffectCount;\n" |
| 2145 | " return -1.0;\n" |
| 2146 | "}\n" |
| 2147 | "void main() {\n" |
| 2148 | " vec4 v = vec4(0.0, 2.0, 4.0, 6.0); \n" |
| 2149 | " float f = (func(), (++v[u_zero + sideEffectCount]));\n" |
| 2150 | " bool green = abs(f - 3.0) < 0.01 && abs(v[1] - 3.0) < 0.01 && sideEffectCount == 1;\n" |
| 2151 | " my_FragColor = vec4(0.0, (green ? 1.0 : 0.0), 0.0, 1.0);\n" |
| 2152 | "}\n"; |
| 2153 | |
| 2154 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 2155 | ASSERT_NE(0u, program); |
| 2156 | |
| 2157 | drawQuad(program, "inputAttribute", 0.5f); |
| 2158 | |
| 2159 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2160 | } |
| 2161 | |
Jamie Madill | c9bde92 | 2016-07-24 17:58:50 -0400 | [diff] [blame] | 2162 | // Test that using gl_PointCoord with GL_TRIANGLES doesn't produce a link error. |
| 2163 | // From WebGL test conformance/rendering/point-specific-shader-variables.html |
| 2164 | // See http://anglebug.com/1380 |
| 2165 | TEST_P(GLSLTest, RenderTrisWithPointCoord) |
| 2166 | { |
| 2167 | const std::string &vert = |
| 2168 | "attribute vec2 aPosition;\n" |
| 2169 | "void main()\n" |
| 2170 | "{\n" |
| 2171 | " gl_Position = vec4(aPosition, 0, 1);\n" |
| 2172 | " gl_PointSize = 1.0;\n" |
| 2173 | "}"; |
| 2174 | const std::string &frag = |
| 2175 | "void main()\n" |
| 2176 | "{\n" |
| 2177 | " gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);\n" |
| 2178 | " gl_FragColor = vec4(0, 1, 0, 1);\n" |
| 2179 | "}"; |
| 2180 | |
| 2181 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2182 | drawQuad(prog.get(), "aPosition", 0.5f); |
| 2183 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2184 | } |
| 2185 | |
Jamie Madill | 5655b84 | 2016-08-02 11:00:07 -0400 | [diff] [blame] | 2186 | // Convers a bug with the integer pow statement workaround. |
| 2187 | TEST_P(GLSLTest, NestedPowStatements) |
| 2188 | { |
| 2189 | const std::string &vert = |
| 2190 | "attribute vec2 position;\n" |
| 2191 | "void main()\n" |
| 2192 | "{\n" |
| 2193 | " gl_Position = vec4(position, 0, 1);\n" |
| 2194 | "}"; |
| 2195 | const std::string &frag = |
| 2196 | "precision mediump float;\n" |
| 2197 | "float func(float v)\n" |
| 2198 | "{\n" |
| 2199 | " float f1 = pow(v, 2.0);\n" |
| 2200 | " return pow(f1 + v, 2.0);\n" |
| 2201 | "}\n" |
| 2202 | "void main()\n" |
| 2203 | "{\n" |
| 2204 | " float v = func(2.0);\n" |
| 2205 | " gl_FragColor = abs(v - 36.0) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" |
| 2206 | "}"; |
| 2207 | |
| 2208 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2209 | drawQuad(prog.get(), "position", 0.5f); |
| 2210 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2211 | } |
| 2212 | |
Olli Etuaho | ab48164 | 2016-08-26 12:09:10 +0300 | [diff] [blame^] | 2213 | // Test a nested sequence operator with a ternary operator inside. The ternary operator is |
| 2214 | // intended to be such that it gets converted to an if statement on the HLSL backend. |
| 2215 | TEST_P(GLSLTest, NestedSequenceOperatorWithTernaryInside) |
| 2216 | { |
| 2217 | const std::string &vert = |
| 2218 | "attribute vec2 position;\n" |
| 2219 | "void main()\n" |
| 2220 | "{\n" |
| 2221 | " gl_Position = vec4(position, 0, 1);\n" |
| 2222 | "}"; |
| 2223 | |
| 2224 | // Note that the uniform keep_flop_positive doesn't need to be set - the test expects it to have |
| 2225 | // its default value false. |
| 2226 | const std::string &frag = |
| 2227 | "precision mediump float;\n" |
| 2228 | "uniform bool keep_flop_positive;\n" |
| 2229 | "float flop;\n" |
| 2230 | "void main() {\n" |
| 2231 | " flop = -1.0,\n" |
| 2232 | " (flop *= -1.0,\n" |
| 2233 | " keep_flop_positive ? 0.0 : flop *= -1.0),\n" |
| 2234 | " gl_FragColor = vec4(0, -flop, 0, 1);\n" |
| 2235 | "}"; |
| 2236 | |
| 2237 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2238 | drawQuad(prog.get(), "position", 0.5f); |
| 2239 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2240 | } |
| 2241 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 2242 | } // anonymous namespace |
| 2243 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 2244 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 2245 | ANGLE_INSTANTIATE_TEST(GLSLTest, |
| 2246 | ES2_D3D9(), |
| 2247 | ES2_D3D11(), |
| 2248 | ES2_D3D11_FL9_3(), |
| 2249 | ES2_OPENGL(), |
| 2250 | ES3_OPENGL(), |
| 2251 | ES2_OPENGLES(), |
| 2252 | ES3_OPENGLES()); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 2253 | |
| 2254 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 2255 | ANGLE_INSTANTIATE_TEST(GLSLTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |