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