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 | 1048e43 | 2016-07-23 18:51:28 -0400 | [diff] [blame] | 9 | #include "test_utils/gl_raii.h" |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 10 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 11 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 12 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 13 | namespace |
| 14 | { |
| 15 | |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 16 | class GLSLTest : public ANGLETest |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 17 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 18 | protected: |
| 19 | GLSLTest() |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 20 | { |
| 21 | setWindowWidth(128); |
| 22 | setWindowHeight(128); |
| 23 | setConfigRedBits(8); |
| 24 | setConfigGreenBits(8); |
| 25 | setConfigBlueBits(8); |
| 26 | setConfigAlphaBits(8); |
| 27 | } |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 28 | |
| 29 | virtual void SetUp() |
| 30 | { |
| 31 | ANGLETest::SetUp(); |
| 32 | |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 33 | mSimpleVSSource = |
| 34 | R"(attribute vec4 inputAttribute; |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 35 | void main() |
| 36 | { |
| 37 | gl_Position = inputAttribute; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 38 | })"; |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 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 | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 437 | class GLSLTestNoValidation : public GLSLTest |
| 438 | { |
| 439 | public: |
| 440 | GLSLTestNoValidation() { setNoErrorEnabled(true); } |
| 441 | }; |
| 442 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 443 | class GLSLTest_ES3 : public GLSLTest |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 444 | { |
Olli Etuaho | e1d199b | 2016-07-19 17:14:27 +0300 | [diff] [blame] | 445 | void SetUp() override |
| 446 | { |
| 447 | ANGLETest::SetUp(); |
| 448 | |
| 449 | mSimpleVSSource = |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 450 | R"(#version 300 es |
| 451 | in vec4 inputAttribute; |
| 452 | void main() |
| 453 | { |
| 454 | gl_Position = inputAttribute; |
| 455 | })"; |
Olli Etuaho | e1d199b | 2016-07-19 17:14:27 +0300 | [diff] [blame] | 456 | } |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 457 | }; |
| 458 | |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 459 | class GLSLTest_ES31 : public GLSLTest |
| 460 | { |
| 461 | void SetUp() override |
| 462 | { |
| 463 | ANGLETest::SetUp(); |
| 464 | |
| 465 | mSimpleVSSource = |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 466 | R"(#version 310 es |
| 467 | in vec4 inputAttribute; |
| 468 | void main() |
| 469 | { |
| 470 | gl_Position = inputAttribute; |
| 471 | })"; |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 472 | } |
| 473 | }; |
| 474 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 475 | TEST_P(GLSLTest, NamelessScopedStructs) |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 476 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 477 | const std::string fragmentShaderSource = |
| 478 | R"(precision mediump float; |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 479 | void main() |
| 480 | { |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 481 | struct |
| 482 | { |
| 483 | float q; |
| 484 | } b; |
| 485 | |
| 486 | gl_FragColor = vec4(1, 0, 0, 1); |
| 487 | gl_FragColor.a += b.q; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 488 | })"; |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 489 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 490 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 491 | EXPECT_NE(0u, program); |
| 492 | } |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 493 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 494 | TEST_P(GLSLTest, ScopedStructsOrderBug) |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 495 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 496 | // TODO(geofflang): Find out why this doesn't compile on Apple OpenGL drivers |
| 497 | // (http://anglebug.com/1292) |
Geoff Lang | 5103f4c | 2016-01-26 11:40:18 -0500 | [diff] [blame] | 498 | // 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] | 499 | // (http://anglebug.com/1291) |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 500 | if (IsDesktopOpenGL() && (IsOSX() || !IsNVIDIA())) |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 501 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 502 | std::cout << "Test disabled on this OpenGL configuration." << std::endl; |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 503 | return; |
| 504 | } |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 505 | |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 506 | const std::string fragmentShaderSource = |
| 507 | R"(precision mediump float; |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 508 | |
| 509 | struct T |
| 510 | { |
| 511 | float f; |
| 512 | }; |
| 513 | |
| 514 | void main() |
| 515 | { |
| 516 | T a; |
| 517 | |
| 518 | struct T |
| 519 | { |
| 520 | float q; |
| 521 | }; |
| 522 | |
| 523 | T b; |
| 524 | |
| 525 | gl_FragColor = vec4(1, 0, 0, 1); |
| 526 | gl_FragColor.a += a.f; |
| 527 | gl_FragColor.a += b.q; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 528 | })"; |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 529 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 530 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 531 | EXPECT_NE(0u, program); |
| 532 | } |
| 533 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 534 | TEST_P(GLSLTest, ScopedStructsBug) |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 535 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 536 | const std::string fragmentShaderSource = |
| 537 | R"(precision mediump float; |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 538 | |
| 539 | struct T_0 |
| 540 | { |
| 541 | float f; |
| 542 | }; |
| 543 | |
| 544 | void main() |
| 545 | { |
| 546 | gl_FragColor = vec4(1, 0, 0, 1); |
| 547 | |
| 548 | struct T |
| 549 | { |
| 550 | vec2 v; |
| 551 | }; |
| 552 | |
| 553 | T_0 a; |
| 554 | T b; |
| 555 | |
| 556 | gl_FragColor.a += a.f; |
| 557 | gl_FragColor.a += b.v.x; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 558 | })"; |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 559 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 560 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 561 | EXPECT_NE(0u, program); |
| 562 | } |
| 563 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 564 | TEST_P(GLSLTest, DxPositionBug) |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 565 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 566 | const std::string &vertexShaderSource = |
| 567 | R"(attribute vec4 inputAttribute; |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 568 | varying float dx_Position; |
| 569 | void main() |
| 570 | { |
| 571 | gl_Position = vec4(inputAttribute); |
| 572 | dx_Position = 0.0; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 573 | })"; |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 574 | |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 575 | const std::string &fragmentShaderSource = |
| 576 | R"(precision mediump float; |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 577 | |
| 578 | varying float dx_Position; |
| 579 | |
| 580 | void main() |
| 581 | { |
| 582 | gl_FragColor = vec4(dx_Position, 0, 0, 1); |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 583 | })"; |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 584 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 585 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 96509e4 | 2014-05-29 14:33:27 -0400 | [diff] [blame] | 586 | EXPECT_NE(0u, program); |
| 587 | } |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 588 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 589 | TEST_P(GLSLTest, ElseIfRewriting) |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 590 | { |
| 591 | const std::string &vertexShaderSource = |
| 592 | "attribute vec4 a_position;\n" |
| 593 | "varying float v;\n" |
| 594 | "void main() {\n" |
| 595 | " gl_Position = a_position;\n" |
| 596 | " v = 1.0;\n" |
| 597 | " if (a_position.x <= 0.5) {\n" |
| 598 | " v = 0.0;\n" |
| 599 | " } else if (a_position.x >= 0.5) {\n" |
| 600 | " v = 2.0;\n" |
| 601 | " }\n" |
| 602 | "}\n"; |
| 603 | |
| 604 | const std::string &fragmentShaderSource = |
| 605 | "precision highp float;\n" |
| 606 | "varying float v;\n" |
| 607 | "void main() {\n" |
| 608 | " vec4 color = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 609 | " if (v >= 1.0) color = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 610 | " if (v >= 2.0) color = vec4(0.0, 0.0, 1.0, 1.0);\n" |
| 611 | " gl_FragColor = color;\n" |
| 612 | "}\n"; |
| 613 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 614 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 615 | ASSERT_NE(0u, program); |
| 616 | |
| 617 | drawQuad(program, "a_position", 0.5f); |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 618 | |
| 619 | EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255); |
| 620 | EXPECT_PIXEL_EQ(getWindowWidth()-1, 0, 0, 255, 0, 255); |
| 621 | } |
| 622 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 623 | TEST_P(GLSLTest, TwoElseIfRewriting) |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 624 | { |
| 625 | const std::string &vertexShaderSource = |
| 626 | "attribute vec4 a_position;\n" |
| 627 | "varying float v;\n" |
| 628 | "void main() {\n" |
| 629 | " gl_Position = a_position;\n" |
Jamie Madill | 778d527 | 2014-08-04 13:13:25 -0400 | [diff] [blame] | 630 | " if (a_position.x == 0.0) {\n" |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 631 | " v = 1.0;\n" |
| 632 | " } else if (a_position.x > 0.5) {\n" |
| 633 | " v = 0.0;\n" |
| 634 | " } else if (a_position.x > 0.75) {\n" |
| 635 | " v = 0.5;\n" |
| 636 | " }\n" |
| 637 | "}\n"; |
| 638 | |
| 639 | const std::string &fragmentShaderSource = |
| 640 | "precision highp float;\n" |
| 641 | "varying float v;\n" |
| 642 | "void main() {\n" |
| 643 | " gl_FragColor = vec4(v, 0.0, 0.0, 1.0);\n" |
| 644 | "}\n"; |
| 645 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 646 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 4836d22 | 2014-07-24 06:55:51 -0400 | [diff] [blame] | 647 | EXPECT_NE(0u, program); |
| 648 | } |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 649 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 650 | TEST_P(GLSLTest, FrontFacingAndVarying) |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 651 | { |
Geoff Lang | dd323e9 | 2015-06-09 15:16:31 -0400 | [diff] [blame] | 652 | EGLPlatformParameters platform = GetParam().eglParameters; |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 653 | |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 654 | const std::string vertexShaderSource = |
| 655 | R"(attribute vec4 a_position; |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 656 | varying float v_varying; |
| 657 | void main() |
| 658 | { |
| 659 | v_varying = a_position.x; |
| 660 | gl_Position = a_position; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 661 | })"; |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 662 | |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 663 | const std::string fragmentShaderSource = |
| 664 | R"(precision mediump float; |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 665 | varying float v_varying; |
| 666 | void main() |
| 667 | { |
| 668 | vec4 c; |
| 669 | |
| 670 | if (gl_FrontFacing) |
| 671 | { |
| 672 | c = vec4(v_varying, 0, 0, 1.0); |
| 673 | } |
| 674 | else |
| 675 | { |
| 676 | c = vec4(0, v_varying, 0, 1.0); |
| 677 | } |
| 678 | gl_FragColor = c; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 679 | })"; |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 680 | |
| 681 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Austin Kinross | 02df796 | 2015-07-01 10:03:42 -0700 | [diff] [blame] | 682 | |
| 683 | // Compilation should fail on D3D11 feature level 9_3, since gl_FrontFacing isn't supported. |
| 684 | if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE) |
| 685 | { |
| 686 | if (platform.majorVersion == 9 && platform.minorVersion == 3) |
| 687 | { |
| 688 | EXPECT_EQ(0u, program); |
| 689 | return; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | // Otherwise, compilation should succeed |
Jamie Madill | e6256f8 | 2014-09-17 10:31:15 -0400 | [diff] [blame] | 694 | EXPECT_NE(0u, program); |
| 695 | } |
| 696 | |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 697 | // Test that we can release the shader compiler and still compile things properly. |
| 698 | TEST_P(GLSLTest, ReleaseCompilerThenCompile) |
| 699 | { |
| 700 | const std::string &simpleVS = |
| 701 | "attribute vec4 position; void main() { gl_Position = position; }"; |
| 702 | const std::string &simpleFS = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }"; |
| 703 | |
| 704 | // Draw with the first program. |
| 705 | ANGLE_GL_PROGRAM(program1, simpleVS, simpleFS); |
| 706 | drawQuad(program1, "position", 0.5f); |
| 707 | ASSERT_GL_NO_ERROR(); |
| 708 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 709 | |
| 710 | // Clear and release shader compiler. |
| 711 | glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 712 | glClear(GL_COLOR_BUFFER_BIT); |
| 713 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 714 | glReleaseShaderCompiler(); |
| 715 | ASSERT_GL_NO_ERROR(); |
| 716 | |
| 717 | // Draw with a second program. |
| 718 | ANGLE_GL_PROGRAM(program2, simpleVS, simpleFS); |
| 719 | drawQuad(program2, "position", 0.5f); |
| 720 | ASSERT_GL_NO_ERROR(); |
| 721 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 722 | } |
| 723 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 724 | // Verify that linking shaders declaring different shading language versions fails. |
| 725 | TEST_P(GLSLTest_ES3, VersionMismatch) |
| 726 | { |
| 727 | const std::string fragmentShaderSource100 = |
| 728 | "precision mediump float;\n" |
| 729 | "varying float v_varying;\n" |
| 730 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 731 | |
| 732 | const std::string vertexShaderSource100 = |
| 733 | "attribute vec4 a_position;\n" |
| 734 | "varying float v_varying;\n" |
| 735 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 736 | |
| 737 | const std::string fragmentShaderSource300 = |
| 738 | "#version 300 es\n" |
| 739 | "precision mediump float;\n" |
| 740 | "in float v_varying;\n" |
| 741 | "out vec4 my_FragColor;\n" |
| 742 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 743 | |
| 744 | const std::string vertexShaderSource300 = |
| 745 | "#version 300 es\n" |
| 746 | "in vec4 a_position;\n" |
| 747 | "out float v_varying;\n" |
| 748 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 749 | |
| 750 | GLuint program = CompileProgram(vertexShaderSource300, fragmentShaderSource100); |
| 751 | EXPECT_EQ(0u, program); |
| 752 | |
| 753 | program = CompileProgram(vertexShaderSource100, fragmentShaderSource300); |
| 754 | EXPECT_EQ(0u, program); |
| 755 | } |
| 756 | |
| 757 | // Verify that declaring varying as invariant only in vertex shader fails in ESSL 1.00. |
| 758 | TEST_P(GLSLTest, InvariantVaryingOut) |
| 759 | { |
| 760 | const std::string fragmentShaderSource = |
| 761 | "precision mediump float;\n" |
| 762 | "varying float v_varying;\n" |
| 763 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 764 | |
| 765 | const std::string vertexShaderSource = |
| 766 | "attribute vec4 a_position;\n" |
| 767 | "invariant varying float v_varying;\n" |
| 768 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 769 | |
| 770 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 771 | EXPECT_EQ(0u, program); |
| 772 | } |
| 773 | |
| 774 | // Verify that declaring varying as invariant only in vertex shader succeeds in ESSL 3.00. |
| 775 | TEST_P(GLSLTest_ES3, InvariantVaryingOut) |
| 776 | { |
| 777 | // TODO: ESSL 3.00 -> GLSL 1.20 translation should add "invariant" in fragment shader |
| 778 | // for varyings which are invariant in vertex shader (http://anglebug.com/1293) |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 779 | if (IsDesktopOpenGL()) |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 780 | { |
| 781 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 782 | return; |
| 783 | } |
| 784 | |
| 785 | const std::string fragmentShaderSource = |
| 786 | "#version 300 es\n" |
| 787 | "precision mediump float;\n" |
| 788 | "in float v_varying;\n" |
| 789 | "out vec4 my_FragColor;\n" |
| 790 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 791 | |
| 792 | const std::string vertexShaderSource = |
| 793 | "#version 300 es\n" |
| 794 | "in vec4 a_position;\n" |
| 795 | "invariant out float v_varying;\n" |
| 796 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 797 | |
| 798 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 799 | EXPECT_NE(0u, program); |
| 800 | } |
| 801 | |
| 802 | // 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] | 803 | TEST_P(GLSLTest, InvariantVaryingIn) |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 804 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 805 | const std::string fragmentShaderSource = |
| 806 | "precision mediump float;\n" |
| 807 | "invariant varying float v_varying;\n" |
| 808 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 809 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 810 | const std::string vertexShaderSource = |
| 811 | "attribute vec4 a_position;\n" |
| 812 | "varying float v_varying;\n" |
| 813 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 814 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 815 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 816 | EXPECT_EQ(0u, program); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 817 | } |
| 818 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 819 | // Verify that declaring varying as invariant only in fragment shader fails in ESSL 3.00. |
| 820 | TEST_P(GLSLTest_ES3, InvariantVaryingIn) |
| 821 | { |
| 822 | const std::string fragmentShaderSource = |
| 823 | "#version 300 es\n" |
| 824 | "precision mediump float;\n" |
| 825 | "invariant in float v_varying;\n" |
| 826 | "out vec4 my_FragColor;\n" |
| 827 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 828 | |
| 829 | const std::string vertexShaderSource = |
| 830 | "#version 300 es\n" |
| 831 | "in vec4 a_position;\n" |
| 832 | "out float v_varying;\n" |
| 833 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 834 | |
| 835 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 836 | EXPECT_EQ(0u, program); |
| 837 | } |
| 838 | |
| 839 | // 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] | 840 | TEST_P(GLSLTest, InvariantVaryingBoth) |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 841 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 842 | const std::string fragmentShaderSource = |
| 843 | "precision mediump float;\n" |
| 844 | "invariant varying float v_varying;\n" |
| 845 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 846 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 847 | const std::string vertexShaderSource = |
| 848 | "attribute vec4 a_position;\n" |
| 849 | "invariant varying float v_varying;\n" |
| 850 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 851 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 852 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 853 | EXPECT_NE(0u, program); |
| 854 | } |
| 855 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 856 | // Verify that declaring varying as invariant in both shaders fails in ESSL 3.00. |
| 857 | TEST_P(GLSLTest_ES3, InvariantVaryingBoth) |
| 858 | { |
| 859 | const std::string fragmentShaderSource = |
| 860 | "#version 300 es\n" |
| 861 | "precision mediump float;\n" |
| 862 | "invariant in float v_varying;\n" |
| 863 | "out vec4 my_FragColor;\n" |
| 864 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 865 | |
| 866 | const std::string vertexShaderSource = |
| 867 | "#version 300 es\n" |
| 868 | "in vec4 a_position;\n" |
| 869 | "invariant out float v_varying;\n" |
| 870 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 871 | |
| 872 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 873 | EXPECT_EQ(0u, program); |
| 874 | } |
| 875 | |
| 876 | // Verify that declaring gl_Position as invariant succeeds in ESSL 1.00. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 877 | TEST_P(GLSLTest, InvariantGLPosition) |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 878 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 879 | const std::string fragmentShaderSource = |
| 880 | "precision mediump float;\n" |
| 881 | "varying float v_varying;\n" |
| 882 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 883 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 884 | const std::string vertexShaderSource = |
| 885 | "attribute vec4 a_position;\n" |
| 886 | "invariant gl_Position;\n" |
| 887 | "varying float v_varying;\n" |
| 888 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 889 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 890 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 891 | EXPECT_NE(0u, program); |
| 892 | } |
| 893 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 894 | // Verify that declaring gl_Position as invariant succeeds in ESSL 3.00. |
| 895 | TEST_P(GLSLTest_ES3, InvariantGLPosition) |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 896 | { |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 897 | const std::string fragmentShaderSource = |
| 898 | "#version 300 es\n" |
| 899 | "precision mediump float;\n" |
| 900 | "in float v_varying;\n" |
| 901 | "out vec4 my_FragColor;\n" |
| 902 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 903 | |
| 904 | const std::string vertexShaderSource = |
| 905 | "#version 300 es\n" |
| 906 | "in vec4 a_position;\n" |
| 907 | "invariant gl_Position;\n" |
| 908 | "out float v_varying;\n" |
| 909 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 910 | |
| 911 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 912 | EXPECT_NE(0u, program); |
| 913 | } |
| 914 | |
| 915 | // Verify that using invariant(all) in both shaders succeeds in ESSL 1.00. |
| 916 | TEST_P(GLSLTest, InvariantAllBoth) |
| 917 | { |
| 918 | // TODO: ESSL 1.00 -> GLSL 1.20 translation should add "invariant" in fragment shader |
| 919 | // for varyings which are invariant in vertex shader individually, |
| 920 | // and remove invariant(all) from fragment shader (http://anglebug.com/1293) |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 921 | if (IsDesktopOpenGL()) |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 922 | { |
| 923 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 924 | return; |
| 925 | } |
| 926 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 927 | const std::string fragmentShaderSource = |
| 928 | "#pragma STDGL invariant(all)\n" |
| 929 | "precision mediump float;\n" |
| 930 | "varying float v_varying;\n" |
| 931 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 932 | |
| 933 | const std::string vertexShaderSource = |
| 934 | "#pragma STDGL invariant(all)\n" |
| 935 | "attribute vec4 a_position;\n" |
| 936 | "varying float v_varying;\n" |
| 937 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 938 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 939 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 940 | EXPECT_NE(0u, program); |
| 941 | } |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 942 | |
Geoff Lang | 156d719 | 2016-07-21 16:11:00 -0400 | [diff] [blame] | 943 | // Verify that functions without return statements still compile |
| 944 | TEST_P(GLSLTest, MissingReturnFloat) |
| 945 | { |
| 946 | const std::string vertexShaderSource = |
| 947 | "varying float v_varying;\n" |
| 948 | "float f() { if (v_varying > 0.0) return 1.0; }\n" |
| 949 | "void main() { gl_Position = vec4(f(), 0, 0, 1); }\n"; |
| 950 | |
| 951 | const std::string fragmentShaderSource = |
| 952 | "precision mediump float;\n" |
| 953 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 954 | |
| 955 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 956 | EXPECT_NE(0u, program); |
| 957 | } |
| 958 | |
| 959 | // Verify that functions without return statements still compile |
| 960 | TEST_P(GLSLTest, MissingReturnVec2) |
| 961 | { |
| 962 | const std::string vertexShaderSource = |
| 963 | "varying float v_varying;\n" |
| 964 | "vec2 f() { if (v_varying > 0.0) return vec2(1.0, 1.0); }\n" |
| 965 | "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; |
| 966 | |
| 967 | const std::string fragmentShaderSource = |
| 968 | "precision mediump float;\n" |
| 969 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 970 | |
| 971 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 972 | EXPECT_NE(0u, program); |
| 973 | } |
| 974 | |
| 975 | // Verify that functions without return statements still compile |
| 976 | TEST_P(GLSLTest, MissingReturnVec3) |
| 977 | { |
| 978 | const std::string vertexShaderSource = |
| 979 | "varying float v_varying;\n" |
| 980 | "vec3 f() { if (v_varying > 0.0) return vec3(1.0, 1.0, 1.0); }\n" |
| 981 | "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; |
| 982 | |
| 983 | const std::string fragmentShaderSource = |
| 984 | "precision mediump float;\n" |
| 985 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 986 | |
| 987 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 988 | EXPECT_NE(0u, program); |
| 989 | } |
| 990 | |
| 991 | // Verify that functions without return statements still compile |
| 992 | TEST_P(GLSLTest, MissingReturnVec4) |
| 993 | { |
| 994 | const std::string vertexShaderSource = |
| 995 | "varying float v_varying;\n" |
| 996 | "vec4 f() { if (v_varying > 0.0) return vec4(1.0, 1.0, 1.0, 1.0); }\n" |
| 997 | "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; |
| 998 | |
| 999 | const std::string fragmentShaderSource = |
| 1000 | "precision mediump float;\n" |
| 1001 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1002 | |
| 1003 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1004 | EXPECT_NE(0u, program); |
| 1005 | } |
| 1006 | |
| 1007 | // Verify that functions without return statements still compile |
| 1008 | TEST_P(GLSLTest, MissingReturnIVec4) |
| 1009 | { |
| 1010 | const std::string vertexShaderSource = |
| 1011 | "varying float v_varying;\n" |
| 1012 | "ivec4 f() { if (v_varying > 0.0) return ivec4(1, 1, 1, 1); }\n" |
| 1013 | "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; |
| 1014 | |
| 1015 | const std::string fragmentShaderSource = |
| 1016 | "precision mediump float;\n" |
| 1017 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1018 | |
| 1019 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1020 | EXPECT_NE(0u, program); |
| 1021 | } |
| 1022 | |
| 1023 | // Verify that functions without return statements still compile |
| 1024 | TEST_P(GLSLTest, MissingReturnMat4) |
| 1025 | { |
| 1026 | const std::string vertexShaderSource = |
| 1027 | "varying float v_varying;\n" |
| 1028 | "mat4 f() { if (v_varying > 0.0) return mat4(1.0); }\n" |
| 1029 | "void main() { gl_Position = vec4(f()[0][0], 0, 0, 1); }\n"; |
| 1030 | |
| 1031 | const std::string fragmentShaderSource = |
| 1032 | "precision mediump float;\n" |
| 1033 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1034 | |
| 1035 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1036 | EXPECT_NE(0u, program); |
| 1037 | } |
| 1038 | |
| 1039 | // Verify that functions without return statements still compile |
| 1040 | TEST_P(GLSLTest, MissingReturnStruct) |
| 1041 | { |
| 1042 | const std::string vertexShaderSource = |
| 1043 | "varying float v_varying;\n" |
| 1044 | "struct s { float a; int b; vec2 c; };\n" |
| 1045 | "s f() { if (v_varying > 0.0) return s(1.0, 1, vec2(1.0, 1.0)); }\n" |
| 1046 | "void main() { gl_Position = vec4(f().a, 0, 0, 1); }\n"; |
| 1047 | |
| 1048 | const std::string fragmentShaderSource = |
| 1049 | "precision mediump float;\n" |
| 1050 | "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1051 | |
| 1052 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1053 | EXPECT_NE(0u, program); |
| 1054 | } |
| 1055 | |
| 1056 | // Verify that functions without return statements still compile |
| 1057 | TEST_P(GLSLTest_ES3, MissingReturnArray) |
| 1058 | { |
| 1059 | const std::string vertexShaderSource = |
| 1060 | "#version 300 es\n" |
| 1061 | "in float v_varying;\n" |
| 1062 | "vec2[2] f() { if (v_varying > 0.0) { return vec2[2](vec2(1.0, 1.0), vec2(1.0, 1.0)); } }\n" |
| 1063 | "void main() { gl_Position = vec4(f()[0].x, 0, 0, 1); }\n"; |
| 1064 | |
| 1065 | const std::string fragmentShaderSource = |
| 1066 | "#version 300 es\n" |
| 1067 | "precision mediump float;\n" |
| 1068 | "out vec4 my_FragColor;\n" |
| 1069 | "void main() { my_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1070 | |
| 1071 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1072 | EXPECT_NE(0u, program); |
| 1073 | } |
| 1074 | |
| 1075 | // Verify that functions without return statements still compile |
| 1076 | TEST_P(GLSLTest_ES3, MissingReturnArrayOfStructs) |
| 1077 | { |
| 1078 | const std::string vertexShaderSource = |
| 1079 | "#version 300 es\n" |
| 1080 | "in float v_varying;\n" |
| 1081 | "struct s { float a; int b; vec2 c; };\n" |
| 1082 | "s[2] f() { if (v_varying > 0.0) { return s[2](s(1.0, 1, vec2(1.0, 1.0)), s(1.0, 1, " |
| 1083 | "vec2(1.0, 1.0))); } }\n" |
| 1084 | "void main() { gl_Position = vec4(f()[0].a, 0, 0, 1); }\n"; |
| 1085 | |
| 1086 | const std::string fragmentShaderSource = |
| 1087 | "#version 300 es\n" |
| 1088 | "precision mediump float;\n" |
| 1089 | "out vec4 my_FragColor;\n" |
| 1090 | "void main() { my_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1091 | |
| 1092 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1093 | EXPECT_NE(0u, program); |
| 1094 | } |
| 1095 | |
Corentin Wallez | 509e456 | 2016-08-25 14:55:44 -0400 | [diff] [blame] | 1096 | // Verify that functions without return statements still compile |
| 1097 | TEST_P(GLSLTest_ES3, MissingReturnStructOfArrays) |
| 1098 | { |
Olli Etuaho | df7d13e | 2017-05-30 13:53:45 +0300 | [diff] [blame] | 1099 | // TODO(cwallez) remove the suppression once NVIDIA drivers are updated across trybots, drivers |
| 1100 | // since late 2016 should have the fix. Last check on 2017-05-30 revealed that the Windows |
| 1101 | // Server 2008 bots still had the old, failing drivers. |
Corentin Wallez | 509e456 | 2016-08-25 14:55:44 -0400 | [diff] [blame] | 1102 | if (IsNVIDIA() && IsOpenGLES()) |
| 1103 | { |
| 1104 | std::cout << "Test skipped on NVIDIA OpenGL ES because it disallows returning " |
| 1105 | "structure of arrays" |
| 1106 | << std::endl; |
| 1107 | return; |
| 1108 | } |
| 1109 | |
| 1110 | const std::string vertexShaderSource = |
| 1111 | "#version 300 es\n" |
| 1112 | "in float v_varying;\n" |
| 1113 | "struct s { float a[2]; int b[2]; vec2 c[2]; };\n" |
| 1114 | "s f() { if (v_varying > 0.0) { return s(float[2](1.0, 1.0), int[2](1, 1)," |
| 1115 | "vec2[2](vec2(1.0, 1.0), vec2(1.0, 1.0))); } }\n" |
| 1116 | "void main() { gl_Position = vec4(f().a[0], 0, 0, 1); }\n"; |
| 1117 | |
| 1118 | const std::string fragmentShaderSource = |
| 1119 | "#version 300 es\n" |
| 1120 | "precision mediump float;\n" |
| 1121 | "out vec4 my_FragColor;\n" |
| 1122 | "void main() { my_FragColor = vec4(0, 0, 0, 1); }\n"; |
| 1123 | |
| 1124 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1125 | EXPECT_NE(0u, program); |
| 1126 | } |
| 1127 | |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 1128 | // Verify that using invariant(all) in both shaders fails in ESSL 3.00. |
| 1129 | TEST_P(GLSLTest_ES3, InvariantAllBoth) |
| 1130 | { |
| 1131 | const std::string fragmentShaderSource = |
| 1132 | "#version 300 es\n" |
| 1133 | "#pragma STDGL invariant(all)\n" |
| 1134 | "precision mediump float;\n" |
| 1135 | "in float v_varying;\n" |
| 1136 | "out vec4 my_FragColor;\n" |
| 1137 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1138 | |
| 1139 | const std::string vertexShaderSource = |
| 1140 | "#version 300 es\n" |
| 1141 | "#pragma STDGL invariant(all)\n" |
| 1142 | "in vec4 a_position;\n" |
| 1143 | "out float v_varying;\n" |
| 1144 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1145 | |
| 1146 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1147 | EXPECT_EQ(0u, program); |
| 1148 | } |
| 1149 | |
| 1150 | // Verify that using invariant(all) only in fragment shader fails in ESSL 1.00. |
| 1151 | TEST_P(GLSLTest, InvariantAllIn) |
| 1152 | { |
| 1153 | const std::string fragmentShaderSource = |
| 1154 | "#pragma STDGL invariant(all)\n" |
| 1155 | "precision mediump float;\n" |
| 1156 | "varying float v_varying;\n" |
| 1157 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1158 | |
| 1159 | const std::string vertexShaderSource = |
| 1160 | "attribute vec4 a_position;\n" |
| 1161 | "varying float v_varying;\n" |
| 1162 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1163 | |
| 1164 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1165 | EXPECT_EQ(0u, program); |
| 1166 | } |
| 1167 | |
| 1168 | // Verify that using invariant(all) only in fragment shader fails in ESSL 3.00. |
| 1169 | TEST_P(GLSLTest_ES3, InvariantAllIn) |
| 1170 | { |
| 1171 | const std::string fragmentShaderSource = |
| 1172 | "#version 300 es\n" |
| 1173 | "#pragma STDGL invariant(all)\n" |
| 1174 | "precision mediump float;\n" |
| 1175 | "in float v_varying;\n" |
| 1176 | "out vec4 my_FragColor;\n" |
| 1177 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1178 | |
| 1179 | const std::string vertexShaderSource = |
| 1180 | "#version 300 es\n" |
| 1181 | "in vec4 a_position;\n" |
| 1182 | "out float v_varying;\n" |
| 1183 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1184 | |
| 1185 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1186 | EXPECT_EQ(0u, program); |
| 1187 | } |
| 1188 | |
| 1189 | // Verify that using invariant(all) only in vertex shader fails in ESSL 1.00. |
| 1190 | TEST_P(GLSLTest, InvariantAllOut) |
| 1191 | { |
| 1192 | const std::string fragmentShaderSource = |
| 1193 | "precision mediump float;\n" |
| 1194 | "varying float v_varying;\n" |
| 1195 | "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1196 | |
| 1197 | const std::string vertexShaderSource = |
| 1198 | "#pragma STDGL invariant(all)\n" |
| 1199 | "attribute vec4 a_position;\n" |
| 1200 | "varying float v_varying;\n" |
| 1201 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1202 | |
| 1203 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1204 | EXPECT_EQ(0u, program); |
| 1205 | } |
| 1206 | |
| 1207 | // Verify that using invariant(all) only in vertex shader succeeds in ESSL 3.00. |
| 1208 | TEST_P(GLSLTest_ES3, InvariantAllOut) |
| 1209 | { |
| 1210 | // TODO: ESSL 3.00 -> GLSL 1.20 translation should add "invariant" in fragment shader |
| 1211 | // for varyings which are invariant in vertex shader, |
| 1212 | // 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] | 1213 | if (IsDesktopOpenGL()) |
Yuly Novikov | a1f6dc9 | 2016-06-15 23:27:04 -0400 | [diff] [blame] | 1214 | { |
| 1215 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1216 | return; |
| 1217 | } |
| 1218 | |
| 1219 | const std::string fragmentShaderSource = |
| 1220 | "#version 300 es\n" |
| 1221 | "precision mediump float;\n" |
| 1222 | "in float v_varying;\n" |
| 1223 | "out vec4 my_FragColor;\n" |
| 1224 | "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; |
| 1225 | |
| 1226 | const std::string vertexShaderSource = |
| 1227 | "#version 300 es\n" |
| 1228 | "#pragma STDGL invariant(all)\n" |
| 1229 | "in vec4 a_position;\n" |
| 1230 | "out float v_varying;\n" |
| 1231 | "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; |
| 1232 | |
| 1233 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1234 | EXPECT_NE(0u, program); |
| 1235 | } |
| 1236 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1237 | TEST_P(GLSLTest, MaxVaryingVec4) |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1238 | { |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1239 | #if defined(__APPLE__) |
| 1240 | // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers |
| 1241 | // (http://anglebug.com/1291) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1242 | if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1243 | { |
| 1244 | std::cout << "Test disabled on Apple AMD OpenGL." << std::endl; |
| 1245 | return; |
| 1246 | } |
| 1247 | #endif |
| 1248 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1249 | GLint maxVaryings = 0; |
| 1250 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1251 | |
| 1252 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, false, false, true); |
| 1253 | } |
| 1254 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1255 | TEST_P(GLSLTest, MaxMinusTwoVaryingVec4PlusTwoSpecialVariables) |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1256 | { |
| 1257 | GLint maxVaryings = 0; |
| 1258 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1259 | |
| 1260 | // Generate shader code that uses gl_FragCoord and gl_PointCoord, two special fragment shader variables. |
| 1261 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings - 2, 0, true, true, false, true); |
| 1262 | } |
| 1263 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1264 | TEST_P(GLSLTest, MaxMinusTwoVaryingVec4PlusThreeSpecialVariables) |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1265 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1266 | // 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] | 1267 | if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1268 | { |
| 1269 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1270 | return; |
| 1271 | } |
| 1272 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1273 | GLint maxVaryings = 0; |
| 1274 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1275 | |
| 1276 | // Generate shader code that uses gl_FragCoord, gl_PointCoord and gl_PointSize. |
| 1277 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings - 2, 0, true, true, true, true); |
| 1278 | } |
| 1279 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1280 | TEST_P(GLSLTest, MaxVaryingVec3) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1281 | { |
| 1282 | GLint maxVaryings = 0; |
| 1283 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1284 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1285 | VaryingTestBase(0, 0, 0, 0, maxVaryings, 0, 0, 0, false, false, false, true); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1288 | TEST_P(GLSLTest, MaxVaryingVec3Array) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1289 | { |
| 1290 | GLint maxVaryings = 0; |
| 1291 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1292 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1293 | 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] | 1294 | } |
| 1295 | |
Jamie Madill | bee59e0 | 2014-10-02 10:44:18 -0400 | [diff] [blame] | 1296 | // Disabled because of a failure in D3D9 |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1297 | TEST_P(GLSLTest, MaxVaryingVec3AndOneFloat) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1298 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1299 | if (IsD3D9()) |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1300 | { |
| 1301 | std::cout << "Test disabled on D3D9." << std::endl; |
| 1302 | return; |
| 1303 | } |
| 1304 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1305 | GLint maxVaryings = 0; |
| 1306 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1307 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1308 | 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] | 1309 | } |
| 1310 | |
Jamie Madill | bee59e0 | 2014-10-02 10:44:18 -0400 | [diff] [blame] | 1311 | // Disabled because of a failure in D3D9 |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1312 | TEST_P(GLSLTest, MaxVaryingVec3ArrayAndOneFloatArray) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1313 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1314 | if (IsD3D9()) |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1315 | { |
| 1316 | std::cout << "Test disabled on D3D9." << std::endl; |
| 1317 | return; |
| 1318 | } |
| 1319 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1320 | GLint maxVaryings = 0; |
| 1321 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1322 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1323 | 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] | 1324 | } |
| 1325 | |
Jamie Madill | bee59e0 | 2014-10-02 10:44:18 -0400 | [diff] [blame] | 1326 | // Disabled because of a failure in D3D9 |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1327 | TEST_P(GLSLTest, TwiceMaxVaryingVec2) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1328 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1329 | if (IsD3D9()) |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1330 | { |
| 1331 | std::cout << "Test disabled on D3D9." << std::endl; |
| 1332 | return; |
| 1333 | } |
| 1334 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1335 | if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1336 | { |
| 1337 | // TODO(geofflang): Figure out why this fails on NVIDIA's GLES driver |
| 1338 | std::cout << "Test disabled on OpenGL ES." << std::endl; |
| 1339 | return; |
| 1340 | } |
| 1341 | |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1342 | #if defined(__APPLE__) |
| 1343 | // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers |
| 1344 | // (http://anglebug.com/1291) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1345 | if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1346 | { |
| 1347 | std::cout << "Test disabled on Apple AMD OpenGL." << std::endl; |
| 1348 | return; |
| 1349 | } |
| 1350 | #endif |
| 1351 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1352 | GLint maxVaryings = 0; |
| 1353 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1354 | |
Austin Kinross | 8b695ee | 2015-03-12 13:12:20 -0700 | [diff] [blame] | 1355 | 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] | 1356 | } |
| 1357 | |
Jamie Madill | bee59e0 | 2014-10-02 10:44:18 -0400 | [diff] [blame] | 1358 | // Disabled because of a failure in D3D9 |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1359 | TEST_P(GLSLTest, MaxVaryingVec2Arrays) |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1360 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1361 | if (IsD3DSM3()) |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 1362 | { |
| 1363 | std::cout << "Test disabled on SM3." << std::endl; |
| 1364 | return; |
| 1365 | } |
| 1366 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1367 | if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1368 | { |
| 1369 | // TODO(geofflang): Figure out why this fails on NVIDIA's GLES driver |
| 1370 | std::cout << "Test disabled on OpenGL ES." << std::endl; |
| 1371 | return; |
| 1372 | } |
| 1373 | |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1374 | #if defined(__APPLE__) |
| 1375 | // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers |
| 1376 | // (http://anglebug.com/1291) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 1377 | if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | 69accbd | 2016-01-25 16:22:32 -0500 | [diff] [blame] | 1378 | { |
| 1379 | std::cout << "Test disabled on Apple AMD OpenGL." << std::endl; |
| 1380 | return; |
| 1381 | } |
| 1382 | #endif |
| 1383 | |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1384 | GLint maxVaryings = 0; |
| 1385 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 1386 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 1387 | // Special case: because arrays of mat2 are packed as small grids of two rows by two columns, |
| 1388 | // we should be aware that when we're packing into an odd number of varying registers the |
| 1389 | // last row will be empty and can not fit the final vec2 arrary. |
| 1390 | GLint maxVec2Arrays = (maxVaryings >> 1) << 1; |
| 1391 | |
| 1392 | VaryingTestBase(0, 0, 0, maxVec2Arrays, 0, 0, 0, 0, false, false, false, true); |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1395 | // 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] | 1396 | TEST_P(GLSLTest, FixedShaderLength) |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1397 | { |
| 1398 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1399 | |
| 1400 | const std::string appendGarbage = "abcasdfasdfasdfasdfasdf"; |
| 1401 | const std::string source = "void main() { gl_FragColor = vec4(0, 0, 0, 0); }" + appendGarbage; |
| 1402 | const char *sourceArray[1] = { source.c_str() }; |
Corentin Wallez | 973402f | 2015-05-11 13:42:22 -0400 | [diff] [blame] | 1403 | GLint lengths[1] = { static_cast<GLint>(source.length() - appendGarbage.length()) }; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1404 | glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths); |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1405 | glCompileShader(shader); |
| 1406 | |
| 1407 | GLint compileResult; |
| 1408 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1409 | EXPECT_NE(compileResult, 0); |
| 1410 | } |
| 1411 | |
| 1412 | // 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] | 1413 | TEST_P(GLSLTest, NegativeShaderLength) |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1414 | { |
| 1415 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1416 | |
| 1417 | const char *sourceArray[1] = { "void main() { gl_FragColor = vec4(0, 0, 0, 0); }" }; |
| 1418 | GLint lengths[1] = { -10 }; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1419 | glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths); |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1420 | glCompileShader(shader); |
| 1421 | |
| 1422 | GLint compileResult; |
| 1423 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1424 | EXPECT_NE(compileResult, 0); |
| 1425 | } |
| 1426 | |
Corentin Wallez | 9a9c048 | 2016-04-12 10:36:25 -0400 | [diff] [blame] | 1427 | // Check that having an invalid char after the "." doesn't cause an assert. |
| 1428 | TEST_P(GLSLTest, InvalidFieldFirstChar) |
| 1429 | { |
| 1430 | GLuint shader = glCreateShader(GL_VERTEX_SHADER); |
| 1431 | const char *source = "void main() {vec4 x; x.}"; |
| 1432 | glShaderSource(shader, 1, &source, 0); |
| 1433 | glCompileShader(shader); |
| 1434 | |
| 1435 | GLint compileResult; |
| 1436 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1437 | EXPECT_EQ(0, compileResult); |
| 1438 | } |
| 1439 | |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1440 | // Verify that a length array with mixed positive and negative values compiles. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1441 | TEST_P(GLSLTest, MixedShaderLengths) |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1442 | { |
| 1443 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1444 | |
| 1445 | const char *sourceArray[] = |
| 1446 | { |
| 1447 | "void main()", |
| 1448 | "{", |
| 1449 | " gl_FragColor = vec4(0, 0, 0, 0);", |
| 1450 | "}", |
| 1451 | }; |
| 1452 | GLint lengths[] = |
| 1453 | { |
| 1454 | -10, |
| 1455 | 1, |
Corentin Wallez | 973402f | 2015-05-11 13:42:22 -0400 | [diff] [blame] | 1456 | static_cast<GLint>(strlen(sourceArray[2])), |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1457 | -1, |
| 1458 | }; |
| 1459 | ASSERT_EQ(ArraySize(sourceArray), ArraySize(lengths)); |
| 1460 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1461 | glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths); |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1462 | glCompileShader(shader); |
| 1463 | |
| 1464 | GLint compileResult; |
| 1465 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1466 | EXPECT_NE(compileResult, 0); |
| 1467 | } |
| 1468 | |
| 1469 | // Verify that zero-length shader source does not affect shader compilation. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1470 | TEST_P(GLSLTest, ZeroShaderLength) |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1471 | { |
| 1472 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1473 | |
| 1474 | const char *sourceArray[] = |
| 1475 | { |
| 1476 | "adfasdf", |
| 1477 | "34534", |
| 1478 | "void main() { gl_FragColor = vec4(0, 0, 0, 0); }", |
| 1479 | "", |
| 1480 | "asdfasdfsdsdf", |
| 1481 | }; |
| 1482 | GLint lengths[] = |
| 1483 | { |
| 1484 | 0, |
| 1485 | 0, |
| 1486 | -1, |
| 1487 | 0, |
| 1488 | 0, |
| 1489 | }; |
| 1490 | ASSERT_EQ(ArraySize(sourceArray), ArraySize(lengths)); |
| 1491 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1492 | glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths); |
Geoff Lang | f60fab6 | 2014-11-24 11:21:20 -0500 | [diff] [blame] | 1493 | glCompileShader(shader); |
| 1494 | |
| 1495 | GLint compileResult; |
| 1496 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1497 | EXPECT_NE(compileResult, 0); |
| 1498 | } |
Jamie Madill | 21c1e45 | 2014-12-29 11:33:41 -0500 | [diff] [blame] | 1499 | |
| 1500 | // Tests that bad index expressions don't crash ANGLE's translator. |
| 1501 | // https://code.google.com/p/angleproject/issues/detail?id=857 |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1502 | TEST_P(GLSLTest, BadIndexBug) |
Jamie Madill | 21c1e45 | 2014-12-29 11:33:41 -0500 | [diff] [blame] | 1503 | { |
| 1504 | const std::string &fragmentShaderSourceVec = |
| 1505 | "precision mediump float;\n" |
| 1506 | "uniform vec4 uniformVec;\n" |
| 1507 | "void main()\n" |
| 1508 | "{\n" |
| 1509 | " gl_FragColor = vec4(uniformVec[int()]);\n" |
| 1510 | "}"; |
| 1511 | |
| 1512 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceVec); |
| 1513 | EXPECT_EQ(0u, shader); |
| 1514 | |
| 1515 | if (shader != 0) |
| 1516 | { |
| 1517 | glDeleteShader(shader); |
| 1518 | } |
| 1519 | |
| 1520 | const std::string &fragmentShaderSourceMat = |
| 1521 | "precision mediump float;\n" |
| 1522 | "uniform mat4 uniformMat;\n" |
| 1523 | "void main()\n" |
| 1524 | "{\n" |
| 1525 | " gl_FragColor = vec4(uniformMat[int()]);\n" |
| 1526 | "}"; |
| 1527 | |
| 1528 | shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceMat); |
| 1529 | EXPECT_EQ(0u, shader); |
| 1530 | |
| 1531 | if (shader != 0) |
| 1532 | { |
| 1533 | glDeleteShader(shader); |
| 1534 | } |
| 1535 | |
| 1536 | const std::string &fragmentShaderSourceArray = |
| 1537 | "precision mediump float;\n" |
| 1538 | "uniform vec4 uniformArray;\n" |
| 1539 | "void main()\n" |
| 1540 | "{\n" |
| 1541 | " gl_FragColor = vec4(uniformArray[int()]);\n" |
| 1542 | "}"; |
| 1543 | |
| 1544 | shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceArray); |
| 1545 | EXPECT_EQ(0u, shader); |
| 1546 | |
| 1547 | if (shader != 0) |
| 1548 | { |
| 1549 | glDeleteShader(shader); |
| 1550 | } |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1551 | } |
| 1552 | |
Jamie Madill | 2e295e2 | 2015-04-29 10:41:33 -0400 | [diff] [blame] | 1553 | // Test that structs defined in uniforms are translated correctly. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1554 | TEST_P(GLSLTest, StructSpecifiersUniforms) |
Jamie Madill | 2e295e2 | 2015-04-29 10:41:33 -0400 | [diff] [blame] | 1555 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 1556 | const std::string fragmentShaderSource = |
| 1557 | R"(precision mediump float; |
Jamie Madill | 2e295e2 | 2015-04-29 10:41:33 -0400 | [diff] [blame] | 1558 | |
| 1559 | uniform struct S { float field;} s; |
| 1560 | |
| 1561 | void main() |
| 1562 | { |
| 1563 | gl_FragColor = vec4(1, 0, 0, 1); |
| 1564 | gl_FragColor.a += s.field; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 1565 | })"; |
Jamie Madill | 2e295e2 | 2015-04-29 10:41:33 -0400 | [diff] [blame] | 1566 | |
| 1567 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 1568 | EXPECT_NE(0u, program); |
| 1569 | } |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1570 | |
| 1571 | // Test that gl_DepthRange is not stored as a uniform location. Since uniforms |
| 1572 | // beginning with "gl_" are filtered out by our validation logic, we must |
| 1573 | // bypass the validation to test the behaviour of the implementation. |
| 1574 | // (note this test is still Impl-independent) |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 1575 | TEST_P(GLSLTestNoValidation, DepthRangeUniforms) |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1576 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 1577 | const std::string fragmentShaderSource = |
| 1578 | R"(precision mediump float; |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1579 | |
| 1580 | void main() |
| 1581 | { |
| 1582 | gl_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff, 1); |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 1583 | })"; |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1584 | |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 1585 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1586 | |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 1587 | // We need to bypass validation for this call. |
| 1588 | GLint nearIndex = glGetUniformLocation(program.get(), "gl_DepthRange.near"); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1589 | EXPECT_EQ(-1, nearIndex); |
| 1590 | |
| 1591 | // Test drawing does not throw an exception. |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 1592 | drawQuad(program.get(), "inputAttribute", 0.5f); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1593 | |
| 1594 | EXPECT_GL_NO_ERROR(); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1595 | } |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1596 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1597 | std::string GenerateSmallPowShader(double base, double exponent) |
| 1598 | { |
| 1599 | std::stringstream stream; |
| 1600 | |
| 1601 | stream.precision(8); |
| 1602 | |
| 1603 | double result = pow(base, exponent); |
| 1604 | |
| 1605 | stream << "precision highp float;\n" |
| 1606 | << "float fun(float arg)\n" |
| 1607 | << "{\n" |
| 1608 | << " return pow(arg, " << std::fixed << exponent << ");\n" |
| 1609 | << "}\n" |
| 1610 | << "\n" |
| 1611 | << "void main()\n" |
| 1612 | << "{\n" |
| 1613 | << " const float a = " << std::scientific << base << ";\n" |
| 1614 | << " float b = fun(a);\n" |
| 1615 | << " if (abs(" << result << " - b) < " << std::abs(result * 0.001) << ")\n" |
| 1616 | << " {\n" |
| 1617 | << " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 1618 | << " }\n" |
| 1619 | << " else\n" |
| 1620 | << " {\n" |
| 1621 | << " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1622 | << " }\n" |
| 1623 | << "}\n"; |
| 1624 | |
| 1625 | return stream.str(); |
| 1626 | } |
| 1627 | |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1628 | // Covers the WebGL test 'glsl/bugs/pow-of-small-constant-in-user-defined-function' |
Jamie Madill | 1048e43 | 2016-07-23 18:51:28 -0400 | [diff] [blame] | 1629 | // See http://anglebug.com/851 |
| 1630 | TEST_P(GLSLTest, PowOfSmallConstant) |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1631 | { |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1632 | std::vector<double> bads; |
| 1633 | for (int eps = -1; eps <= 1; ++eps) |
| 1634 | { |
| 1635 | for (int i = -4; i <= 5; ++i) |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1636 | { |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1637 | if (i >= -1 && i <= 1) |
| 1638 | continue; |
| 1639 | const double epsilon = 1.0e-8; |
| 1640 | double bad = static_cast<double>(i) + static_cast<double>(eps) * epsilon; |
| 1641 | bads.push_back(bad); |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1642 | } |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1643 | } |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1644 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1645 | for (double bad : bads) |
| 1646 | { |
| 1647 | const std::string &fragmentShaderSource = GenerateSmallPowShader(1.0e-6, bad); |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1648 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1649 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShaderSource); |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1650 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 1651 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 1652 | |
| 1653 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1654 | EXPECT_GL_NO_ERROR(); |
| 1655 | } |
Jamie Madill | 4052dfc | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 1656 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1657 | |
Cooper Partin | a5ef8d8 | 2015-08-19 14:52:21 -0700 | [diff] [blame] | 1658 | // Test that fragment shaders which contain non-constant loop indexers and compiled for FL9_3 and |
| 1659 | // below |
| 1660 | // fail with a specific error message. |
| 1661 | // Additionally test that the same fragment shader compiles successfully with feature levels greater |
| 1662 | // than FL9_3. |
| 1663 | TEST_P(GLSLTest, LoopIndexingValidation) |
| 1664 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 1665 | const std::string fragmentShaderSource = |
| 1666 | R"(precision mediump float; |
Cooper Partin | a5ef8d8 | 2015-08-19 14:52:21 -0700 | [diff] [blame] | 1667 | |
| 1668 | uniform float loopMax; |
| 1669 | |
| 1670 | void main() |
| 1671 | { |
| 1672 | gl_FragColor = vec4(1, 0, 0, 1); |
| 1673 | for (float l = 0.0; l < loopMax; l++) |
| 1674 | { |
| 1675 | if (loopMax > 3.0) |
| 1676 | { |
| 1677 | gl_FragColor.a += 0.1; |
| 1678 | } |
| 1679 | } |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 1680 | })"; |
Cooper Partin | a5ef8d8 | 2015-08-19 14:52:21 -0700 | [diff] [blame] | 1681 | |
| 1682 | GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); |
| 1683 | |
| 1684 | const char *sourceArray[1] = {fragmentShaderSource.c_str()}; |
| 1685 | glShaderSource(shader, 1, sourceArray, nullptr); |
| 1686 | glCompileShader(shader); |
| 1687 | |
| 1688 | GLint compileResult; |
| 1689 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); |
| 1690 | |
| 1691 | // If the test is configured to run limited to Feature Level 9_3, then it is |
| 1692 | // assumed that shader compilation will fail with an expected error message containing |
| 1693 | // "Loop index cannot be compared with non-constant expression" |
Olli Etuaho | 814a54d | 2015-08-27 16:23:09 +0300 | [diff] [blame] | 1694 | if ((GetParam() == ES2_D3D11_FL9_3() || GetParam() == ES2_D3D9())) |
Cooper Partin | a5ef8d8 | 2015-08-19 14:52:21 -0700 | [diff] [blame] | 1695 | { |
| 1696 | if (compileResult != 0) |
| 1697 | { |
| 1698 | FAIL() << "Shader compilation succeeded, expected failure"; |
| 1699 | } |
| 1700 | else |
| 1701 | { |
| 1702 | GLint infoLogLength; |
| 1703 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 1704 | |
| 1705 | std::string infoLog; |
| 1706 | infoLog.resize(infoLogLength); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1707 | glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), nullptr, &infoLog[0]); |
Cooper Partin | a5ef8d8 | 2015-08-19 14:52:21 -0700 | [diff] [blame] | 1708 | |
| 1709 | if (infoLog.find("Loop index cannot be compared with non-constant expression") == |
| 1710 | std::string::npos) |
| 1711 | { |
| 1712 | FAIL() << "Shader compilation failed with unexpected error message"; |
| 1713 | } |
| 1714 | } |
| 1715 | } |
| 1716 | else |
| 1717 | { |
| 1718 | EXPECT_NE(0, compileResult); |
| 1719 | } |
| 1720 | |
| 1721 | if (shader != 0) |
| 1722 | { |
| 1723 | glDeleteShader(shader); |
| 1724 | } |
| 1725 | } |
| 1726 | |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1727 | // Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS |
| 1728 | // can actually be used. |
| 1729 | TEST_P(GLSLTest, VerifyMaxVertexUniformVectors) |
| 1730 | { |
Zhenyao Mo | 1a25672 | 2017-01-12 11:52:57 -0800 | [diff] [blame] | 1731 | if (IsLinux() && IsIntel()) |
| 1732 | { |
| 1733 | std::cout << "Test timed out on Linux Intel. See crbug.com/680631." << std::endl; |
| 1734 | return; |
| 1735 | } |
| 1736 | |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1737 | int maxUniforms = 10000; |
| 1738 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms); |
| 1739 | EXPECT_GL_NO_ERROR(); |
| 1740 | std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl; |
| 1741 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1742 | CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, 0, 0, true); |
| 1743 | } |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1744 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1745 | // Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS |
| 1746 | // can actually be used along with the maximum number of texture samplers. |
| 1747 | TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsWithSamplers) |
| 1748 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1749 | if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE || |
| 1750 | GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1751 | { |
| 1752 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1753 | return; |
| 1754 | } |
| 1755 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1756 | int maxUniforms = 10000; |
| 1757 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms); |
| 1758 | EXPECT_GL_NO_ERROR(); |
| 1759 | std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl; |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1760 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1761 | int maxTextureImageUnits = 0; |
| 1762 | glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1763 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1764 | CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, maxTextureImageUnits, 0, true); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | // Tests that the maximum uniforms count + 1 from querying GL_MAX_VERTEX_UNIFORM_VECTORS |
| 1768 | // fails shader compilation. |
| 1769 | TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsExceeded) |
| 1770 | { |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1771 | int maxUniforms = 10000; |
| 1772 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms); |
| 1773 | EXPECT_GL_NO_ERROR(); |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1774 | 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] | 1775 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1776 | CompileGLSLWithUniformsAndSamplers(maxUniforms + 1, 0, 0, 0, false); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | // Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS |
| 1780 | // can actually be used. |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1781 | TEST_P(GLSLTest, VerifyMaxFragmentUniformVectors) |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1782 | { |
Zhenyao Mo | 1a25672 | 2017-01-12 11:52:57 -0800 | [diff] [blame] | 1783 | if (IsLinux() && IsIntel()) |
| 1784 | { |
| 1785 | std::cout << "Test timed out on Linux Intel. See crbug.com/680631." << std::endl; |
| 1786 | return; |
| 1787 | } |
| 1788 | |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1789 | int maxUniforms = 10000; |
| 1790 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms); |
| 1791 | EXPECT_GL_NO_ERROR(); |
| 1792 | std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS = " << maxUniforms << std::endl; |
| 1793 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1794 | CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, 0, true); |
| 1795 | } |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1796 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1797 | // Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS |
| 1798 | // can actually be used along with the maximum number of texture samplers. |
| 1799 | TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsWithSamplers) |
| 1800 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1801 | if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE || |
| 1802 | GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 1803 | { |
| 1804 | std::cout << "Test disabled on OpenGL." << std::endl; |
| 1805 | return; |
| 1806 | } |
| 1807 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1808 | int maxUniforms = 10000; |
| 1809 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms); |
| 1810 | EXPECT_GL_NO_ERROR(); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1811 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1812 | int maxTextureImageUnits = 0; |
| 1813 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1814 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1815 | CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, maxTextureImageUnits, true); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | // Tests that the maximum uniforms count + 1 from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS |
| 1819 | // fails shader compilation. |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1820 | TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsExceeded) |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1821 | { |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1822 | int maxUniforms = 10000; |
| 1823 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms); |
| 1824 | EXPECT_GL_NO_ERROR(); |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1825 | std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS + 1 = " << maxUniforms + 1 |
| 1826 | << std::endl; |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1827 | |
Austin Kinross | 7a3e8e2 | 2015-10-08 15:50:06 -0700 | [diff] [blame] | 1828 | CompileGLSLWithUniformsAndSamplers(0, maxUniforms + 1, 0, 0, false); |
Cooper Partin | 69f9b2c | 2015-08-20 13:25:41 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
Geoff Lang | ba992ab | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 1831 | // Test compiling shaders using the GL_EXT_shader_texture_lod extension |
| 1832 | TEST_P(GLSLTest, TextureLOD) |
| 1833 | { |
| 1834 | if (!extensionEnabled("GL_EXT_shader_texture_lod")) |
| 1835 | { |
| 1836 | std::cout << "Test skipped due to missing GL_EXT_shader_texture_lod." << std::endl; |
| 1837 | return; |
| 1838 | } |
| 1839 | |
| 1840 | const std::string source = |
| 1841 | "#extension GL_EXT_shader_texture_lod : require\n" |
| 1842 | "uniform sampler2D u_texture;\n" |
| 1843 | "void main() {\n" |
| 1844 | " gl_FragColor = texture2DGradEXT(u_texture, vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, " |
| 1845 | "0.0));\n" |
| 1846 | "}\n"; |
| 1847 | |
| 1848 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); |
| 1849 | ASSERT_NE(0u, shader); |
| 1850 | glDeleteShader(shader); |
| 1851 | } |
| 1852 | |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 1853 | // Test that two constructors which have vec4 and mat2 parameters get disambiguated (issue in |
| 1854 | // HLSL). |
| 1855 | TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x2) |
| 1856 | { |
| 1857 | const std::string fragmentShaderSource = |
| 1858 | "#version 300 es\n" |
| 1859 | "precision highp float;\n" |
| 1860 | "out vec4 my_FragColor;\n" |
| 1861 | "void main()\n" |
| 1862 | "{\n" |
| 1863 | " my_FragColor = vec4(0.0);\n" |
| 1864 | "}"; |
| 1865 | |
| 1866 | const std::string vertexShaderSource = |
| 1867 | "#version 300 es\n" |
| 1868 | "precision highp float;\n" |
| 1869 | "in vec4 a_vec;\n" |
| 1870 | "in mat2 a_mat;\n" |
| 1871 | "void main()\n" |
| 1872 | "{\n" |
| 1873 | " gl_Position = vec4(a_vec) + vec4(a_mat);\n" |
| 1874 | "}"; |
| 1875 | |
| 1876 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1877 | EXPECT_NE(0u, program); |
| 1878 | } |
| 1879 | |
| 1880 | // Test that two constructors which have mat2x3 and mat3x2 parameters get disambiguated. |
| 1881 | // This was suspected to be an issue in HLSL, but HLSL seems to be able to natively choose between |
| 1882 | // the function signatures in this case. |
| 1883 | TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x3) |
| 1884 | { |
| 1885 | const std::string fragmentShaderSource = |
| 1886 | "#version 300 es\n" |
| 1887 | "precision highp float;\n" |
| 1888 | "out vec4 my_FragColor;\n" |
| 1889 | "void main()\n" |
| 1890 | "{\n" |
| 1891 | " my_FragColor = vec4(0.0);\n" |
| 1892 | "}"; |
| 1893 | |
| 1894 | const std::string vertexShaderSource = |
| 1895 | "#version 300 es\n" |
| 1896 | "precision highp float;\n" |
| 1897 | "in mat3x2 a_matA;\n" |
| 1898 | "in mat2x3 a_matB;\n" |
| 1899 | "void main()\n" |
| 1900 | "{\n" |
| 1901 | " gl_Position = vec4(a_matA) + vec4(a_matB);\n" |
| 1902 | "}"; |
| 1903 | |
| 1904 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1905 | EXPECT_NE(0u, program); |
| 1906 | } |
| 1907 | |
| 1908 | // Test that two functions which have vec4 and mat2 parameters get disambiguated (issue in HLSL). |
| 1909 | TEST_P(GLSLTest_ES3, AmbiguousFunctionCall2x2) |
| 1910 | { |
| 1911 | const std::string fragmentShaderSource = |
| 1912 | "#version 300 es\n" |
| 1913 | "precision highp float;\n" |
| 1914 | "out vec4 my_FragColor;\n" |
| 1915 | "void main()\n" |
| 1916 | "{\n" |
| 1917 | " my_FragColor = vec4(0.0);\n" |
| 1918 | "}"; |
| 1919 | |
| 1920 | const std::string vertexShaderSource = |
| 1921 | "#version 300 es\n" |
| 1922 | "precision highp float;\n" |
| 1923 | "in vec4 a_vec;\n" |
| 1924 | "in mat2 a_mat;\n" |
| 1925 | "vec4 foo(vec4 a)\n" |
| 1926 | "{\n" |
| 1927 | " return a;\n" |
| 1928 | "}\n" |
| 1929 | "vec4 foo(mat2 a)\n" |
| 1930 | "{\n" |
| 1931 | " return vec4(a[0][0]);\n" |
| 1932 | "}\n" |
| 1933 | "void main()\n" |
| 1934 | "{\n" |
| 1935 | " gl_Position = foo(a_vec) + foo(a_mat);\n" |
| 1936 | "}"; |
| 1937 | |
| 1938 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 1939 | EXPECT_NE(0u, program); |
| 1940 | } |
| 1941 | |
| 1942 | // Test that an user-defined function with a large number of float4 parameters doesn't fail due to |
| 1943 | // the function name being too long. |
| 1944 | TEST_P(GLSLTest_ES3, LargeNumberOfFloat4Parameters) |
| 1945 | { |
| 1946 | const std::string fragmentShaderSource = |
| 1947 | "#version 300 es\n" |
| 1948 | "precision highp float;\n" |
| 1949 | "out vec4 my_FragColor;\n" |
| 1950 | "void main()\n" |
| 1951 | "{\n" |
| 1952 | " my_FragColor = vec4(0.0);\n" |
| 1953 | "}"; |
| 1954 | |
| 1955 | std::stringstream vertexShaderStream; |
| 1956 | const unsigned int paramCount = 1024u; |
| 1957 | |
| 1958 | vertexShaderStream << "#version 300 es\n" |
| 1959 | "precision highp float;\n" |
| 1960 | "in vec4 a_vec;\n" |
| 1961 | "vec4 lotsOfVec4Parameters("; |
| 1962 | for (unsigned int i = 0; i < paramCount; ++i) |
| 1963 | { |
| 1964 | vertexShaderStream << "vec4 a" << i << ", "; |
| 1965 | } |
| 1966 | vertexShaderStream << "vec4 aLast)\n" |
| 1967 | "{\n" |
| 1968 | " return "; |
| 1969 | for (unsigned int i = 0; i < paramCount; ++i) |
| 1970 | { |
| 1971 | vertexShaderStream << "a" << i << " + "; |
| 1972 | } |
| 1973 | vertexShaderStream << "aLast;\n" |
| 1974 | "}\n" |
| 1975 | "void main()\n" |
| 1976 | "{\n" |
| 1977 | " gl_Position = lotsOfVec4Parameters("; |
| 1978 | for (unsigned int i = 0; i < paramCount; ++i) |
| 1979 | { |
| 1980 | vertexShaderStream << "a_vec, "; |
| 1981 | } |
| 1982 | vertexShaderStream << "a_vec);\n" |
| 1983 | "}"; |
| 1984 | |
| 1985 | GLuint program = CompileProgram(vertexShaderStream.str(), fragmentShaderSource); |
| 1986 | EXPECT_NE(0u, program); |
| 1987 | } |
| 1988 | |
Olli Etuaho | d4f4c11 | 2016-04-15 15:11:24 +0300 | [diff] [blame] | 1989 | // This test was written specifically to stress DeferGlobalInitializers AST transformation. |
| 1990 | // Test a shader where a global constant array is initialized with an expression containing array |
| 1991 | // indexing. This initializer is tricky to constant fold, so if it's not constant folded it needs to |
| 1992 | // be handled in a way that doesn't generate statements in the global scope in HLSL output. |
| 1993 | // Also includes multiple array initializers in one declaration, where only the second one has |
| 1994 | // array indexing. This makes sure that the qualifier for the declaration is set correctly if |
| 1995 | // transformations are applied to the declaration also in the case of ESSL output. |
| 1996 | TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing) |
| 1997 | { |
Yuly Novikov | 41db224 | 2016-06-25 00:14:28 -0400 | [diff] [blame] | 1998 | // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1428 is fixed |
| 1999 | if (IsAndroid() && IsAdreno() && IsOpenGLES()) |
| 2000 | { |
| 2001 | std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl; |
| 2002 | return; |
| 2003 | } |
| 2004 | |
Olli Etuaho | d4f4c11 | 2016-04-15 15:11:24 +0300 | [diff] [blame] | 2005 | const std::string vertexShaderSource = |
| 2006 | "#version 300 es\n" |
| 2007 | "precision highp float;\n" |
| 2008 | "in vec4 a_vec;\n" |
| 2009 | "void main()\n" |
| 2010 | "{\n" |
| 2011 | " gl_Position = vec4(a_vec);\n" |
| 2012 | "}"; |
| 2013 | |
| 2014 | const std::string fragmentShaderSource = |
| 2015 | "#version 300 es\n" |
| 2016 | "precision highp float;\n" |
| 2017 | "out vec4 my_FragColor;\n" |
| 2018 | "const highp float f[2] = float[2](0.1, 0.2);\n" |
| 2019 | "const highp float[2] g = float[2](0.3, 0.4), h = float[2](0.5, f[1]);\n" |
| 2020 | "void main()\n" |
| 2021 | "{\n" |
| 2022 | " my_FragColor = vec4(h[1]);\n" |
| 2023 | "}"; |
| 2024 | |
| 2025 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 2026 | EXPECT_NE(0u, program); |
| 2027 | } |
| 2028 | |
Corentin Wallez | 419bfc9 | 2016-06-28 10:54:45 -0700 | [diff] [blame] | 2029 | // Test that index-constant sampler array indexing is supported. |
| 2030 | TEST_P(GLSLTest, IndexConstantSamplerArrayIndexing) |
| 2031 | { |
| 2032 | if (IsD3D11_FL93()) { |
| 2033 | std::cout << "Test skipped on D3D11 FL 9.3." << std::endl; |
| 2034 | return; |
| 2035 | } |
| 2036 | |
| 2037 | const std::string vertexShaderSource = |
| 2038 | "attribute vec4 vPosition;\n" |
| 2039 | "void main()\n" |
| 2040 | "{\n" |
| 2041 | " gl_Position = vPosition;\n" |
| 2042 | "}"; |
| 2043 | |
| 2044 | const std::string fragmentShaderSource = |
| 2045 | "precision mediump float;\n" |
| 2046 | "uniform sampler2D uni[2];\n" |
| 2047 | "\n" |
| 2048 | "float zero(int x)\n" |
| 2049 | "{\n" |
| 2050 | " return float(x) - float(x);\n" |
| 2051 | "}\n" |
| 2052 | "\n" |
| 2053 | "void main()\n" |
| 2054 | "{\n" |
| 2055 | " vec4 c = vec4(0,0,0,0);\n" |
| 2056 | " for (int ii = 1; ii < 3; ++ii) {\n" |
| 2057 | " if (c.x > 255.0) {\n" |
| 2058 | " c.x = 255.0 + zero(ii);\n" |
| 2059 | " break;\n" |
| 2060 | " }\n" |
| 2061 | // Index the sampler array with a predictable loop index (index-constant) as opposed to |
| 2062 | // a true constant. This is valid in OpenGL ES but isn't in many Desktop OpenGL versions, |
| 2063 | // without an extension. |
| 2064 | " c += texture2D(uni[ii - 1], vec2(0.5, 0.5));\n" |
| 2065 | " }\n" |
| 2066 | " gl_FragColor = c;\n" |
| 2067 | "}"; |
| 2068 | |
| 2069 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 2070 | EXPECT_NE(0u, program); |
| 2071 | } |
| 2072 | |
Corentin Wallez | b00dcee | 2016-07-11 17:42:58 -0400 | [diff] [blame] | 2073 | // Test that the #pragma directive is supported and doesn't trigger a compilation failure on the |
| 2074 | // native driver. The only pragma that gets passed to the OpenGL driver is "invariant" but we don't |
| 2075 | // want to test its behavior, so don't use any varyings. |
| 2076 | TEST_P(GLSLTest, PragmaDirective) |
| 2077 | { |
| 2078 | const std::string vertexShaderSource = |
| 2079 | "#pragma STDGL invariant(all)\n" |
| 2080 | "void main()\n" |
| 2081 | "{\n" |
| 2082 | " gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2083 | "}\n"; |
| 2084 | |
| 2085 | const std::string fragmentShaderSource = |
| 2086 | "precision mediump float;\n" |
| 2087 | "void main()\n" |
| 2088 | "{\n" |
| 2089 | " gl_FragColor = vec4(1.0);\n" |
| 2090 | "}\n"; |
| 2091 | |
| 2092 | GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 2093 | EXPECT_NE(0u, program); |
| 2094 | } |
| 2095 | |
Olli Etuaho | e1d199b | 2016-07-19 17:14:27 +0300 | [diff] [blame] | 2096 | // Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9). |
| 2097 | // The function call that returns the array needs to be evaluated after ++j for the expression to |
| 2098 | // return the correct value (true). |
| 2099 | TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderArray) |
| 2100 | { |
| 2101 | const std::string &fragmentShaderSource = |
| 2102 | "#version 300 es\n" |
| 2103 | "precision mediump float;\n" |
| 2104 | "out vec4 my_FragColor; \n" |
| 2105 | "int[2] func(int param) {\n" |
| 2106 | " return int[2](param, param);\n" |
| 2107 | "}\n" |
| 2108 | "void main() {\n" |
| 2109 | " int a[2]; \n" |
| 2110 | " for (int i = 0; i < 2; ++i) {\n" |
| 2111 | " a[i] = 1;\n" |
| 2112 | " }\n" |
| 2113 | " int j = 0; \n" |
| 2114 | " bool result = ((++j), (a == func(j)));\n" |
| 2115 | " my_FragColor = vec4(0.0, (result ? 1.0 : 0.0), 0.0, 1.0);\n" |
| 2116 | "}\n"; |
| 2117 | |
| 2118 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 2119 | ASSERT_NE(0u, program); |
| 2120 | |
| 2121 | drawQuad(program, "inputAttribute", 0.5f); |
| 2122 | |
| 2123 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2124 | } |
| 2125 | |
| 2126 | // Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9). |
| 2127 | // The short-circuiting expression needs to be evaluated after ++j for the expression to return the |
| 2128 | // correct value (true). |
| 2129 | TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderShortCircuit) |
| 2130 | { |
| 2131 | const std::string &fragmentShaderSource = |
| 2132 | "#version 300 es\n" |
| 2133 | "precision mediump float;\n" |
| 2134 | "out vec4 my_FragColor; \n" |
| 2135 | "void main() {\n" |
| 2136 | " int j = 0; \n" |
| 2137 | " bool result = ((++j), (j == 1 ? true : (++j == 3)));\n" |
| 2138 | " my_FragColor = vec4(0.0, ((result && j == 1) ? 1.0 : 0.0), 0.0, 1.0);\n" |
| 2139 | "}\n"; |
| 2140 | |
| 2141 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 2142 | ASSERT_NE(0u, program); |
| 2143 | |
| 2144 | drawQuad(program, "inputAttribute", 0.5f); |
| 2145 | |
| 2146 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2147 | } |
| 2148 | |
Jamie Madill | 666f65a | 2016-08-26 01:34:37 +0000 | [diff] [blame] | 2149 | // Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9). |
| 2150 | // Indexing the vector needs to be evaluated after func() for the right result. |
| 2151 | TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderDynamicVectorIndexingInLValue) |
| 2152 | { |
| 2153 | const std::string &fragmentShaderSource = |
| 2154 | "#version 300 es\n" |
| 2155 | "precision mediump float;\n" |
| 2156 | "out vec4 my_FragColor;\n" |
| 2157 | "uniform int u_zero;\n" |
| 2158 | "int sideEffectCount = 0;\n" |
| 2159 | "float func() {\n" |
| 2160 | " ++sideEffectCount;\n" |
| 2161 | " return -1.0;\n" |
| 2162 | "}\n" |
| 2163 | "void main() {\n" |
| 2164 | " vec4 v = vec4(0.0, 2.0, 4.0, 6.0); \n" |
| 2165 | " float f = (func(), (++v[u_zero + sideEffectCount]));\n" |
| 2166 | " bool green = abs(f - 3.0) < 0.01 && abs(v[1] - 3.0) < 0.01 && sideEffectCount == 1;\n" |
| 2167 | " my_FragColor = vec4(0.0, (green ? 1.0 : 0.0), 0.0, 1.0);\n" |
| 2168 | "}\n"; |
| 2169 | |
| 2170 | GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource); |
| 2171 | ASSERT_NE(0u, program); |
| 2172 | |
| 2173 | drawQuad(program, "inputAttribute", 0.5f); |
| 2174 | |
| 2175 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2176 | } |
| 2177 | |
Jamie Madill | c9bde92 | 2016-07-24 17:58:50 -0400 | [diff] [blame] | 2178 | // Test that using gl_PointCoord with GL_TRIANGLES doesn't produce a link error. |
| 2179 | // From WebGL test conformance/rendering/point-specific-shader-variables.html |
| 2180 | // See http://anglebug.com/1380 |
| 2181 | TEST_P(GLSLTest, RenderTrisWithPointCoord) |
| 2182 | { |
| 2183 | const std::string &vert = |
| 2184 | "attribute vec2 aPosition;\n" |
| 2185 | "void main()\n" |
| 2186 | "{\n" |
| 2187 | " gl_Position = vec4(aPosition, 0, 1);\n" |
| 2188 | " gl_PointSize = 1.0;\n" |
| 2189 | "}"; |
| 2190 | const std::string &frag = |
| 2191 | "void main()\n" |
| 2192 | "{\n" |
| 2193 | " gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);\n" |
| 2194 | " gl_FragColor = vec4(0, 1, 0, 1);\n" |
| 2195 | "}"; |
| 2196 | |
| 2197 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2198 | drawQuad(prog.get(), "aPosition", 0.5f); |
| 2199 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2200 | } |
| 2201 | |
Jamie Madill | 5655b84 | 2016-08-02 11:00:07 -0400 | [diff] [blame] | 2202 | // Convers a bug with the integer pow statement workaround. |
| 2203 | TEST_P(GLSLTest, NestedPowStatements) |
| 2204 | { |
| 2205 | const std::string &vert = |
| 2206 | "attribute vec2 position;\n" |
| 2207 | "void main()\n" |
| 2208 | "{\n" |
| 2209 | " gl_Position = vec4(position, 0, 1);\n" |
| 2210 | "}"; |
| 2211 | const std::string &frag = |
| 2212 | "precision mediump float;\n" |
| 2213 | "float func(float v)\n" |
| 2214 | "{\n" |
| 2215 | " float f1 = pow(v, 2.0);\n" |
| 2216 | " return pow(f1 + v, 2.0);\n" |
| 2217 | "}\n" |
| 2218 | "void main()\n" |
| 2219 | "{\n" |
| 2220 | " float v = func(2.0);\n" |
| 2221 | " gl_FragColor = abs(v - 36.0) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" |
| 2222 | "}"; |
| 2223 | |
| 2224 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2225 | drawQuad(prog.get(), "position", 0.5f); |
| 2226 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2227 | } |
| 2228 | |
Qiankun Miao | f52fe93 | 2016-12-07 13:39:15 +0800 | [diff] [blame] | 2229 | // Test that -float calculation is correct. |
| 2230 | TEST_P(GLSLTest_ES3, UnaryMinusOperatorFloat) |
| 2231 | { |
Qiankun Miao | f52fe93 | 2016-12-07 13:39:15 +0800 | [diff] [blame] | 2232 | const std::string &vert = |
| 2233 | "#version 300 es\n" |
| 2234 | "in highp vec4 position;\n" |
| 2235 | "void main() {\n" |
| 2236 | " gl_Position = position;\n" |
| 2237 | "}\n"; |
| 2238 | const std::string &frag = |
| 2239 | "#version 300 es\n" |
| 2240 | "out highp vec4 o_color;\n" |
| 2241 | "void main() {\n" |
| 2242 | " highp float f = -1.0;\n" |
| 2243 | " // atan(tan(0.5), -f) should be 0.5.\n" |
| 2244 | " highp float v = atan(tan(0.5), -f);\n" |
| 2245 | " o_color = abs(v - 0.5) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" |
| 2246 | "}\n"; |
| 2247 | |
| 2248 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2249 | drawQuad(prog.get(), "position", 0.5f); |
| 2250 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2251 | } |
| 2252 | |
Olli Etuaho | da9fb09 | 2016-12-09 17:32:29 +0000 | [diff] [blame] | 2253 | // Test that atan(vec2, vec2) calculation is correct. |
| 2254 | TEST_P(GLSLTest_ES3, AtanVec2) |
| 2255 | { |
| 2256 | const std::string &vert = |
| 2257 | "#version 300 es\n" |
| 2258 | "in highp vec4 position;\n" |
| 2259 | "void main() {\n" |
| 2260 | " gl_Position = position;\n" |
| 2261 | "}\n"; |
| 2262 | const std::string &frag = |
| 2263 | "#version 300 es\n" |
| 2264 | "out highp vec4 o_color;\n" |
| 2265 | "void main() {\n" |
| 2266 | " highp float f = 1.0;\n" |
| 2267 | " // atan(tan(0.5), f) should be 0.5.\n" |
| 2268 | " highp vec2 v = atan(vec2(tan(0.5)), vec2(f));\n" |
| 2269 | " o_color = (abs(v[0] - 0.5) < 0.001 && abs(v[1] - 0.5) < 0.001) ? vec4(0, 1, 0, 1) : " |
| 2270 | "vec4(1, 0, 0, 1);\n" |
| 2271 | "}\n"; |
| 2272 | |
| 2273 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2274 | drawQuad(prog.get(), "position", 0.5f); |
| 2275 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2276 | } |
| 2277 | |
Jiawei-Shao | e292e90 | 2016-09-07 10:49:01 +0800 | [diff] [blame] | 2278 | // Convers a bug with the unary minus operator on signed integer workaround. |
| 2279 | TEST_P(GLSLTest_ES3, UnaryMinusOperatorSignedInt) |
| 2280 | { |
| 2281 | const std::string &vert = |
| 2282 | "#version 300 es\n" |
| 2283 | "in highp vec4 position;\n" |
| 2284 | "out mediump vec4 v_color;\n" |
| 2285 | "uniform int ui_one;\n" |
| 2286 | "uniform int ui_two;\n" |
| 2287 | "uniform int ui_three;\n" |
| 2288 | "void main() {\n" |
| 2289 | " int s[3];\n" |
| 2290 | " s[0] = ui_one;\n" |
| 2291 | " s[1] = -(-(-ui_two + 1) + 1);\n" // s[1] = -ui_two |
| 2292 | " s[2] = ui_three;\n" |
| 2293 | " int result = 0;\n" |
| 2294 | " for (int i = 0; i < ui_three; i++) {\n" |
| 2295 | " result += s[i];\n" |
| 2296 | " }\n" |
| 2297 | " v_color = (result == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" |
| 2298 | " gl_Position = position;\n" |
| 2299 | "}\n"; |
| 2300 | const std::string &frag = |
| 2301 | "#version 300 es\n" |
| 2302 | "in mediump vec4 v_color;\n" |
| 2303 | "layout(location=0) out mediump vec4 o_color;\n" |
| 2304 | "void main() {\n" |
| 2305 | " o_color = v_color;\n" |
| 2306 | "}\n"; |
| 2307 | |
| 2308 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2309 | |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 2310 | GLint oneIndex = glGetUniformLocation(prog.get(), "ui_one"); |
Jiawei-Shao | e292e90 | 2016-09-07 10:49:01 +0800 | [diff] [blame] | 2311 | ASSERT_NE(-1, oneIndex); |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 2312 | GLint twoIndex = glGetUniformLocation(prog.get(), "ui_two"); |
Jiawei-Shao | e292e90 | 2016-09-07 10:49:01 +0800 | [diff] [blame] | 2313 | ASSERT_NE(-1, twoIndex); |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 2314 | GLint threeIndex = glGetUniformLocation(prog.get(), "ui_three"); |
Jiawei-Shao | e292e90 | 2016-09-07 10:49:01 +0800 | [diff] [blame] | 2315 | ASSERT_NE(-1, threeIndex); |
| 2316 | glUseProgram(prog.get()); |
| 2317 | glUniform1i(oneIndex, 1); |
| 2318 | glUniform1i(twoIndex, 2); |
| 2319 | glUniform1i(threeIndex, 3); |
| 2320 | |
| 2321 | drawQuad(prog.get(), "position", 0.5f); |
| 2322 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2323 | } |
| 2324 | |
| 2325 | // Convers a bug with the unary minus operator on unsigned integer workaround. |
| 2326 | TEST_P(GLSLTest_ES3, UnaryMinusOperatorUnsignedInt) |
| 2327 | { |
| 2328 | const std::string &vert = |
| 2329 | "#version 300 es\n" |
| 2330 | "in highp vec4 position;\n" |
| 2331 | "out mediump vec4 v_color;\n" |
| 2332 | "uniform uint ui_one;\n" |
| 2333 | "uniform uint ui_two;\n" |
| 2334 | "uniform uint ui_three;\n" |
| 2335 | "void main() {\n" |
| 2336 | " uint s[3];\n" |
| 2337 | " s[0] = ui_one;\n" |
| 2338 | " s[1] = -(-(-ui_two + 1u) + 1u);\n" // s[1] = -ui_two |
| 2339 | " s[2] = ui_three;\n" |
| 2340 | " uint result = 0u;\n" |
| 2341 | " for (uint i = 0u; i < ui_three; i++) {\n" |
| 2342 | " result += s[i];\n" |
| 2343 | " }\n" |
| 2344 | " v_color = (result == 2u) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" |
| 2345 | " gl_Position = position;\n" |
| 2346 | "}\n"; |
| 2347 | const std::string &frag = |
| 2348 | "#version 300 es\n" |
| 2349 | "in mediump vec4 v_color;\n" |
| 2350 | "layout(location=0) out mediump vec4 o_color;\n" |
| 2351 | "void main() {\n" |
| 2352 | " o_color = v_color;\n" |
| 2353 | "}\n"; |
| 2354 | |
| 2355 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2356 | |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 2357 | GLint oneIndex = glGetUniformLocation(prog.get(), "ui_one"); |
Jiawei-Shao | e292e90 | 2016-09-07 10:49:01 +0800 | [diff] [blame] | 2358 | ASSERT_NE(-1, oneIndex); |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 2359 | GLint twoIndex = glGetUniformLocation(prog.get(), "ui_two"); |
Jiawei-Shao | e292e90 | 2016-09-07 10:49:01 +0800 | [diff] [blame] | 2360 | ASSERT_NE(-1, twoIndex); |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 2361 | GLint threeIndex = glGetUniformLocation(prog.get(), "ui_three"); |
Jiawei-Shao | e292e90 | 2016-09-07 10:49:01 +0800 | [diff] [blame] | 2362 | ASSERT_NE(-1, threeIndex); |
| 2363 | glUseProgram(prog.get()); |
| 2364 | glUniform1ui(oneIndex, 1u); |
| 2365 | glUniform1ui(twoIndex, 2u); |
| 2366 | glUniform1ui(threeIndex, 3u); |
| 2367 | |
| 2368 | drawQuad(prog.get(), "position", 0.5f); |
| 2369 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2370 | } |
| 2371 | |
Olli Etuaho | ab48164 | 2016-08-26 12:09:10 +0300 | [diff] [blame] | 2372 | // Test a nested sequence operator with a ternary operator inside. The ternary operator is |
| 2373 | // intended to be such that it gets converted to an if statement on the HLSL backend. |
| 2374 | TEST_P(GLSLTest, NestedSequenceOperatorWithTernaryInside) |
| 2375 | { |
| 2376 | const std::string &vert = |
| 2377 | "attribute vec2 position;\n" |
| 2378 | "void main()\n" |
| 2379 | "{\n" |
| 2380 | " gl_Position = vec4(position, 0, 1);\n" |
| 2381 | "}"; |
| 2382 | |
| 2383 | // Note that the uniform keep_flop_positive doesn't need to be set - the test expects it to have |
| 2384 | // its default value false. |
| 2385 | const std::string &frag = |
| 2386 | "precision mediump float;\n" |
| 2387 | "uniform bool keep_flop_positive;\n" |
| 2388 | "float flop;\n" |
| 2389 | "void main() {\n" |
| 2390 | " flop = -1.0,\n" |
| 2391 | " (flop *= -1.0,\n" |
| 2392 | " keep_flop_positive ? 0.0 : flop *= -1.0),\n" |
| 2393 | " gl_FragColor = vec4(0, -flop, 0, 1);\n" |
| 2394 | "}"; |
| 2395 | |
| 2396 | ANGLE_GL_PROGRAM(prog, vert, frag); |
| 2397 | drawQuad(prog.get(), "position", 0.5f); |
| 2398 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2399 | } |
| 2400 | |
Geoff Lang | 28a97ee | 2016-09-22 13:01:26 -0400 | [diff] [blame] | 2401 | // Test that using a sampler2D and samplerExternalOES in the same shader works (anglebug.com/1534) |
| 2402 | TEST_P(GLSLTest, ExternalAnd2DSampler) |
| 2403 | { |
| 2404 | if (!extensionEnabled("GL_OES_EGL_image_external")) |
| 2405 | { |
| 2406 | std::cout << "Test skipped because GL_OES_EGL_image_external is not available." |
| 2407 | << std::endl; |
| 2408 | return; |
| 2409 | } |
| 2410 | |
| 2411 | const std::string fragmentShader = |
| 2412 | "precision mediump float;\n" |
| 2413 | "uniform samplerExternalOES tex0;\n" |
| 2414 | "uniform sampler2D tex1;\n" |
| 2415 | "void main(void)\n" |
| 2416 | "{\n" |
| 2417 | " vec2 uv = vec2(0.0, 0.0);" |
| 2418 | " gl_FragColor = texture2D(tex0, uv) + texture2D(tex1, uv);\n" |
| 2419 | "}\n"; |
| 2420 | |
| 2421 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2422 | } |
| 2423 | |
Olli Etuaho | 56a2f95 | 2016-12-08 12:16:27 +0000 | [diff] [blame] | 2424 | // Test that literal infinity can be written out from the shader translator. |
| 2425 | // A similar test can't be made for NaNs, since ESSL 3.00.6 requirements for NaNs are very loose. |
| 2426 | TEST_P(GLSLTest_ES3, LiteralInfinityOutput) |
| 2427 | { |
| 2428 | const std::string &fragmentShader = |
| 2429 | "#version 300 es\n" |
| 2430 | "precision highp float;\n" |
| 2431 | "out vec4 out_color;\n" |
| 2432 | "uniform float u;\n" |
| 2433 | "void main()\n" |
| 2434 | "{\n" |
| 2435 | " float infVar = 1.0e40 - u;\n" |
| 2436 | " bool correct = isinf(infVar) && infVar > 0.0;\n" |
| 2437 | " out_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2438 | "}\n"; |
| 2439 | |
| 2440 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2441 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 2442 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2443 | } |
| 2444 | |
| 2445 | // Test that literal negative infinity can be written out from the shader translator. |
| 2446 | // A similar test can't be made for NaNs, since ESSL 3.00.6 requirements for NaNs are very loose. |
| 2447 | TEST_P(GLSLTest_ES3, LiteralNegativeInfinityOutput) |
| 2448 | { |
| 2449 | const std::string &fragmentShader = |
| 2450 | "#version 300 es\n" |
| 2451 | "precision highp float;\n" |
| 2452 | "out vec4 out_color;\n" |
| 2453 | "uniform float u;\n" |
| 2454 | "void main()\n" |
| 2455 | "{\n" |
| 2456 | " float infVar = -1.0e40 + u;\n" |
| 2457 | " bool correct = isinf(infVar) && infVar < 0.0;\n" |
| 2458 | " out_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2459 | "}\n"; |
| 2460 | |
| 2461 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2462 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 2463 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2464 | } |
| 2465 | |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 2466 | // The following MultipleDeclaration* tests are testing TranslatorHLSL specific simplification |
| 2467 | // passes. Because the interaction of multiple passes must be tested, it is difficult to write |
| 2468 | // a unittest for them. Instead we add the tests as end2end so will in particular test |
| 2469 | // TranslatorHLSL when run on Windows. |
| 2470 | |
| 2471 | // Test that passes splitting multiple declarations and comma operators are correctly ordered. |
| 2472 | TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperator) |
| 2473 | { |
| 2474 | const std::string &fragmentShader = |
| 2475 | "#version 300 es\n" |
| 2476 | "precision mediump float;\n" |
| 2477 | "out vec4 color;\n" |
| 2478 | "void main(void)\n" |
| 2479 | "{\n" |
| 2480 | " float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : 0.0), 1.0);\n" |
| 2481 | " color = vec4(b);\n" |
| 2482 | "}\n"; |
| 2483 | |
| 2484 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2485 | } |
| 2486 | |
| 2487 | // Test that passes splitting multiple declarations and comma operators and for loops are |
| 2488 | // correctly ordered. |
| 2489 | TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperatorInForLoop) |
| 2490 | { |
| 2491 | const std::string &fragmentShader = |
| 2492 | "#version 300 es\n" |
| 2493 | "precision mediump float;\n" |
| 2494 | "out vec4 color;\n" |
| 2495 | "void main(void)\n" |
| 2496 | "{\n" |
| 2497 | " for(float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : 0.0), 1.0); a < 10.0; a++)\n" |
| 2498 | " {\n" |
| 2499 | " b += 1.0;\n" |
| 2500 | " color = vec4(b);\n" |
| 2501 | " }\n" |
| 2502 | "}\n"; |
| 2503 | |
| 2504 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2505 | } |
| 2506 | |
| 2507 | // Test that splitting multiple declaration in for loops works with no loop condition |
| 2508 | TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyCondition) |
| 2509 | { |
| 2510 | const std::string &fragmentShader = |
| 2511 | "#version 300 es\n" |
| 2512 | "precision mediump float;\n" |
| 2513 | "out vec4 color;\n" |
| 2514 | "void main(void)\n" |
| 2515 | "{\n" |
| 2516 | " for(float a = 0.0, b = 1.0;; a++)\n" |
| 2517 | " {\n" |
| 2518 | " b += 1.0;\n" |
| 2519 | " if (a > 10.0) {break;}\n" |
| 2520 | " color = vec4(b);\n" |
| 2521 | " }\n" |
| 2522 | "}\n"; |
| 2523 | |
| 2524 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2525 | } |
| 2526 | |
| 2527 | // Test that splitting multiple declaration in for loops works with no loop expression |
| 2528 | TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyExpression) |
| 2529 | { |
| 2530 | const std::string &fragmentShader = |
| 2531 | "#version 300 es\n" |
| 2532 | "precision mediump float;\n" |
| 2533 | "out vec4 color;\n" |
| 2534 | "void main(void)\n" |
| 2535 | "{\n" |
| 2536 | " for(float a = 0.0, b = 1.0; a < 10.0;)\n" |
| 2537 | " {\n" |
| 2538 | " b += 1.0;\n" |
| 2539 | " a += 1.0;\n" |
| 2540 | " color = vec4(b);\n" |
| 2541 | " }\n" |
| 2542 | "}\n"; |
| 2543 | |
| 2544 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2545 | } |
| 2546 | |
Olli Etuaho | 8f6eb2a | 2017-01-12 17:04:58 +0000 | [diff] [blame] | 2547 | // Test that dynamic indexing of a matrix inside a dynamic indexing of a vector in an l-value works |
| 2548 | // correctly. |
| 2549 | TEST_P(GLSLTest_ES3, NestedDynamicIndexingInLValue) |
| 2550 | { |
| 2551 | const std::string &fragmentShader = |
| 2552 | "#version 300 es\n" |
| 2553 | "precision mediump float;\n" |
| 2554 | "out vec4 my_FragColor;\n" |
| 2555 | "uniform int u_zero;\n" |
| 2556 | "void main() {\n" |
| 2557 | " mat2 m = mat2(0.0, 0.0, 0.0, 0.0);\n" |
| 2558 | " m[u_zero + 1][u_zero + 1] = float(u_zero + 1);\n" |
| 2559 | " float f = m[1][1];\n" |
| 2560 | " my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);\n" |
| 2561 | "}\n"; |
| 2562 | |
| 2563 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2564 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 2565 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2566 | } |
| 2567 | |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 2568 | class WebGLGLSLTest : public GLSLTest |
| 2569 | { |
| 2570 | protected: |
| 2571 | WebGLGLSLTest() { setWebGLCompatibilityEnabled(true); } |
| 2572 | }; |
| 2573 | |
| 2574 | TEST_P(WebGLGLSLTest, MaxVaryingVec4PlusFragCoord) |
| 2575 | { |
| 2576 | GLint maxVaryings = 0; |
| 2577 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 2578 | |
| 2579 | // Generate shader code that uses gl_FragCoord, a special fragment shader variables. |
| 2580 | // This test should fail, since we are really using (maxVaryings + 1) varyings. |
| 2581 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, true, false, false, false); |
| 2582 | } |
| 2583 | |
| 2584 | TEST_P(WebGLGLSLTest, MaxVaryingVec4PlusPointCoord) |
| 2585 | { |
| 2586 | GLint maxVaryings = 0; |
| 2587 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 2588 | |
| 2589 | // Generate shader code that uses gl_FragCoord, a special fragment shader variables. |
| 2590 | // This test should fail, since we are really using (maxVaryings + 1) varyings. |
| 2591 | VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, true, false, false); |
| 2592 | } |
| 2593 | |
| 2594 | TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec3) |
| 2595 | { |
| 2596 | GLint maxVaryings = 0; |
| 2597 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 2598 | |
| 2599 | VaryingTestBase(0, 0, 0, 0, maxVaryings + 1, 0, 0, 0, false, false, false, false); |
| 2600 | } |
| 2601 | |
| 2602 | TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec3Array) |
| 2603 | { |
| 2604 | GLint maxVaryings = 0; |
| 2605 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 2606 | |
| 2607 | VaryingTestBase(0, 0, 0, 0, 0, maxVaryings / 2 + 1, 0, 0, false, false, false, false); |
| 2608 | } |
| 2609 | |
| 2610 | TEST_P(WebGLGLSLTest, MaxVaryingVec3AndOneVec2) |
| 2611 | { |
| 2612 | GLint maxVaryings = 0; |
| 2613 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 2614 | |
| 2615 | VaryingTestBase(0, 0, 1, 0, maxVaryings, 0, 0, 0, false, false, false, false); |
| 2616 | } |
| 2617 | |
| 2618 | TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec2) |
| 2619 | { |
| 2620 | GLint maxVaryings = 0; |
| 2621 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 2622 | |
| 2623 | VaryingTestBase(0, 0, 2 * maxVaryings + 1, 0, 0, 0, 0, 0, false, false, false, false); |
| 2624 | } |
| 2625 | |
| 2626 | TEST_P(WebGLGLSLTest, MaxVaryingVec3ArrayAndMaxPlusOneFloatArray) |
| 2627 | { |
| 2628 | GLint maxVaryings = 0; |
| 2629 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings); |
| 2630 | |
| 2631 | VaryingTestBase(0, maxVaryings / 2 + 1, 0, 0, 0, 0, 0, maxVaryings / 2, false, false, false, |
| 2632 | false); |
| 2633 | } |
| 2634 | |
Jamie Madill | 6c9503e | 2016-08-16 14:06:32 -0400 | [diff] [blame] | 2635 | } // anonymous namespace |
| 2636 | |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 2637 | // Test that FindLSB and FindMSB return correct values in their corner cases. |
| 2638 | TEST_P(GLSLTest_ES31, FindMSBAndFindLSBCornerCases) |
| 2639 | { |
Olli Etuaho | 61bd9fe | 2017-01-27 14:20:34 -0800 | [diff] [blame] | 2640 | // Suspecting AMD driver bug - failure seen on bots running on AMD R5 230. |
| 2641 | if (IsAMD() && IsOpenGL() && IsLinux()) |
| 2642 | { |
| 2643 | std::cout << "Test skipped on AMD OpenGL Linux" << std::endl; |
| 2644 | return; |
| 2645 | } |
| 2646 | |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 2647 | const std::string &fragmentShader = |
| 2648 | "#version 310 es\n" |
| 2649 | "precision mediump float;\n" |
| 2650 | "out vec4 my_FragColor;\n" |
| 2651 | "uniform int u_zero;\n" |
| 2652 | "void main() {\n" |
| 2653 | " if (findLSB(u_zero) == -1 && findMSB(u_zero) == -1 && findMSB(u_zero - 1) == -1)\n" |
| 2654 | " {\n" |
| 2655 | " my_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 2656 | " }\n" |
| 2657 | " else\n" |
| 2658 | " {\n" |
| 2659 | " my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 2660 | " }\n" |
| 2661 | "}\n"; |
| 2662 | |
| 2663 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2664 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 2665 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2666 | } |
| 2667 | |
Olli Etuaho | c9da71f | 2017-03-06 16:28:54 +0000 | [diff] [blame] | 2668 | // Test that writing into a swizzled vector that is dynamically indexed succeeds. |
| 2669 | TEST_P(GLSLTest_ES3, WriteIntoDynamicIndexingOfSwizzledVector) |
| 2670 | { |
Corentin Wallez | 6445ddf | 2017-03-08 19:00:32 -0500 | [diff] [blame] | 2671 | if (IsOpenGL()) |
Olli Etuaho | c9da71f | 2017-03-06 16:28:54 +0000 | [diff] [blame] | 2672 | { |
| 2673 | // http://anglebug.com/1924 |
Corentin Wallez | 6445ddf | 2017-03-08 19:00:32 -0500 | [diff] [blame] | 2674 | std::cout << "Test skipped on all OpenGL configurations because it has incorrect results" |
| 2675 | << std::endl; |
Olli Etuaho | c9da71f | 2017-03-06 16:28:54 +0000 | [diff] [blame] | 2676 | return; |
| 2677 | } |
| 2678 | |
| 2679 | // The shader first assigns v.x to v.z (1.0) |
| 2680 | // Then v.y to v.y (2.0) |
| 2681 | // Then v.z to v.x (1.0) |
| 2682 | const std::string &fragmentShader = |
| 2683 | "#version 300 es\n" |
| 2684 | "precision highp float;\n" |
| 2685 | "out vec4 my_FragColor;\n" |
| 2686 | "void main() {\n" |
| 2687 | " vec3 v = vec3(1.0, 2.0, 3.0);\n" |
| 2688 | " for (int i = 0; i < 3; i++) {\n" |
| 2689 | " v.zyx[i] = v[i];\n" |
| 2690 | " }\n" |
| 2691 | " my_FragColor = distance(v, vec3(1.0, 2.0, 1.0)) < 0.01 ? vec4(0, 1, 0, 1) : vec4(1, " |
| 2692 | "0, 0, 1);\n" |
| 2693 | "}\n"; |
| 2694 | |
| 2695 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2696 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 2697 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2698 | } |
| 2699 | |
Jamie Madill | 8aeeed6 | 2017-03-15 18:09:26 -0400 | [diff] [blame] | 2700 | // This test covers a bug (and associated workaround) with nested sampling operations in the HLSL |
| 2701 | // compiler DLL. |
| 2702 | TEST_P(GLSLTest_ES3, NestedSamplingOperation) |
| 2703 | { |
| 2704 | // This seems to be bugged on some version of Android. Might not affect the newest versions. |
| 2705 | // TODO(jmadill): Lift suppression when Chromium bots are upgraded. |
| 2706 | if (IsAndroid() && IsOpenGLES()) |
| 2707 | { |
| 2708 | std::cout << "Test skipped on Android because of bug with Nexus 5X." << std::endl; |
| 2709 | return; |
| 2710 | } |
| 2711 | |
| 2712 | const std::string &vertexShader = |
| 2713 | "#version 300 es\n" |
| 2714 | "out vec2 texCoord;\n" |
| 2715 | "in vec2 position;\n" |
| 2716 | "void main()\n" |
| 2717 | "{\n" |
| 2718 | " gl_Position = vec4(position, 0, 1);\n" |
| 2719 | " texCoord = position * 0.5 + vec2(0.5);\n" |
| 2720 | "}\n"; |
| 2721 | |
| 2722 | const std::string &simpleFragmentShader = |
| 2723 | "#version 300 es\n" |
| 2724 | "in mediump vec2 texCoord;\n" |
| 2725 | "out mediump vec4 fragColor;\n" |
| 2726 | "void main()\n" |
| 2727 | "{\n" |
| 2728 | " fragColor = vec4(texCoord, 0, 1);\n" |
| 2729 | "}\n"; |
| 2730 | |
| 2731 | const std::string &nestedFragmentShader = |
| 2732 | "#version 300 es\n" |
| 2733 | "uniform mediump sampler2D samplerA;\n" |
| 2734 | "uniform mediump sampler2D samplerB;\n" |
| 2735 | "in mediump vec2 texCoord;\n" |
| 2736 | "out mediump vec4 fragColor;\n" |
| 2737 | "void main ()\n" |
| 2738 | "{\n" |
| 2739 | " fragColor = texture(samplerB, texture(samplerA, texCoord).xy);\n" |
| 2740 | "}\n"; |
| 2741 | |
| 2742 | ANGLE_GL_PROGRAM(initProg, vertexShader, simpleFragmentShader); |
| 2743 | ANGLE_GL_PROGRAM(nestedProg, vertexShader, nestedFragmentShader); |
| 2744 | |
| 2745 | // Initialize a first texture with default texCoord data. |
| 2746 | GLTexture texA; |
| 2747 | glActiveTexture(GL_TEXTURE0); |
| 2748 | glBindTexture(GL_TEXTURE_2D, texA); |
| 2749 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 2750 | GL_UNSIGNED_BYTE, nullptr); |
| 2751 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2752 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2753 | |
| 2754 | GLFramebuffer fbo; |
| 2755 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 2756 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0); |
| 2757 | |
| 2758 | drawQuad(initProg, "position", 0.5f); |
| 2759 | ASSERT_GL_NO_ERROR(); |
| 2760 | |
| 2761 | // Initialize a second texture with a simple color pattern. |
| 2762 | GLTexture texB; |
| 2763 | glActiveTexture(GL_TEXTURE1); |
| 2764 | glBindTexture(GL_TEXTURE_2D, texB); |
| 2765 | |
| 2766 | std::array<GLColor, 4> simpleColors = { |
| 2767 | {GLColor::red, GLColor::green, GLColor::blue, GLColor::yellow}}; |
| 2768 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2769 | simpleColors.data()); |
| 2770 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2771 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2772 | |
| 2773 | // Draw with the nested program, using the first texture to index the second. |
| 2774 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2775 | glUseProgram(nestedProg); |
| 2776 | GLint samplerALoc = glGetUniformLocation(nestedProg, "samplerA"); |
| 2777 | ASSERT_NE(-1, samplerALoc); |
| 2778 | glUniform1i(samplerALoc, 0); |
| 2779 | GLint samplerBLoc = glGetUniformLocation(nestedProg, "samplerB"); |
| 2780 | ASSERT_NE(-1, samplerBLoc); |
| 2781 | glUniform1i(samplerBLoc, 1); |
| 2782 | |
| 2783 | drawQuad(nestedProg, "position", 0.5f); |
| 2784 | ASSERT_GL_NO_ERROR(); |
| 2785 | |
| 2786 | // Compute four texel centers. |
| 2787 | Vector2 windowSize(getWindowWidth(), getWindowHeight()); |
| 2788 | Vector2 quarterWindowSize = windowSize / 4; |
| 2789 | Vector2 ul = quarterWindowSize; |
| 2790 | Vector2 ur(windowSize.x() - quarterWindowSize.x(), quarterWindowSize.y()); |
| 2791 | Vector2 ll(quarterWindowSize.x(), windowSize.y() - quarterWindowSize.y()); |
| 2792 | Vector2 lr = windowSize - quarterWindowSize; |
| 2793 | |
| 2794 | EXPECT_PIXEL_COLOR_EQ_VEC2(ul, simpleColors[0]); |
| 2795 | EXPECT_PIXEL_COLOR_EQ_VEC2(ur, simpleColors[1]); |
| 2796 | EXPECT_PIXEL_COLOR_EQ_VEC2(ll, simpleColors[2]); |
| 2797 | EXPECT_PIXEL_COLOR_EQ_VEC2(lr, simpleColors[3]); |
| 2798 | } |
| 2799 | |
Olli Etuaho | 8162926 | 2017-04-19 11:56:01 +0300 | [diff] [blame] | 2800 | // Tests that using a constant declaration as the only statement in a for loop without curly braces |
| 2801 | // doesn't crash. |
| 2802 | TEST_P(GLSLTest, ConstantStatementInForLoop) |
| 2803 | { |
| 2804 | const std::string &vertexShader = |
| 2805 | "void main()\n" |
| 2806 | "{\n" |
| 2807 | " for (int i = 0; i < 10; ++i)\n" |
| 2808 | " const int b = 0;\n" |
| 2809 | "}\n"; |
| 2810 | |
| 2811 | GLuint shader = CompileShader(GL_VERTEX_SHADER, vertexShader); |
| 2812 | EXPECT_NE(0u, shader); |
| 2813 | glDeleteShader(shader); |
| 2814 | } |
| 2815 | |
| 2816 | // Tests that using a constant declaration as a loop init expression doesn't crash. Note that this |
| 2817 | // test doesn't work on D3D9 due to looping limitations, so it is only run on ES3. |
| 2818 | TEST_P(GLSLTest_ES3, ConstantStatementAsLoopInit) |
| 2819 | { |
| 2820 | const std::string &vertexShader = |
| 2821 | "void main()\n" |
| 2822 | "{\n" |
| 2823 | " for (const int i = 0; i < 0;) {}\n" |
| 2824 | "}\n"; |
| 2825 | |
| 2826 | GLuint shader = CompileShader(GL_VERTEX_SHADER, vertexShader); |
| 2827 | EXPECT_NE(0u, shader); |
| 2828 | glDeleteShader(shader); |
| 2829 | } |
| 2830 | |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 2831 | // Test that uninitialized local variables are initialized to 0. |
| 2832 | TEST_P(GLSLTest_ES3, InitUninitializedLocals) |
| 2833 | { |
| 2834 | if (IsAndroid() && IsOpenGLES()) |
| 2835 | { |
| 2836 | // http://anglebug.com/2046 |
| 2837 | std::cout |
| 2838 | << "Test skipped on Android GLES because local variable initialization is disabled." |
| 2839 | << std::endl; |
| 2840 | return; |
| 2841 | } |
| 2842 | |
| 2843 | if (IsOSX() && IsOpenGL()) |
| 2844 | { |
| 2845 | // http://anglebug.com/2041 |
| 2846 | std::cout << "Test skipped on Mac OpenGL because local variable initialization is disabled." |
| 2847 | << std::endl; |
| 2848 | return; |
| 2849 | } |
| 2850 | |
| 2851 | const std::string &fragmentShader = |
| 2852 | "#version 300 es\n" |
| 2853 | "precision mediump float;\n" |
| 2854 | "out vec4 my_FragColor;\n" |
| 2855 | "int result = 0;\n" |
| 2856 | "void main()\n" |
| 2857 | "{\n" |
| 2858 | " int u;\n" |
| 2859 | " result += u;\n" |
| 2860 | " int k = 0;\n" |
| 2861 | " for (int i[2], j = i[0] + 1; k < 2; ++k)\n" |
| 2862 | " {\n" |
| 2863 | " result += j;\n" |
| 2864 | " }\n" |
| 2865 | " if (result == 2)\n" |
| 2866 | " {\n" |
| 2867 | " my_FragColor = vec4(0, 1, 0, 1);\n" |
| 2868 | " }\n" |
| 2869 | " else\n" |
| 2870 | " {\n" |
| 2871 | " my_FragColor = vec4(1, 0, 0, 1);\n" |
| 2872 | " }\n" |
| 2873 | "}\n"; |
| 2874 | |
| 2875 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2876 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 2877 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2878 | } |
| 2879 | |
| 2880 | // Test that uninitialized structs containing arrays of structs are initialized to 0. This |
| 2881 | // specifically tests with two different struct variables declared in the same block. |
| 2882 | TEST_P(GLSLTest, InitUninitializedStructContainingArrays) |
| 2883 | { |
| 2884 | if (IsAndroid() && IsOpenGLES()) |
| 2885 | { |
| 2886 | // http://anglebug.com/2046 |
| 2887 | std::cout |
| 2888 | << "Test skipped on Android GLES because local variable initialization is disabled." |
| 2889 | << std::endl; |
| 2890 | return; |
| 2891 | } |
| 2892 | |
| 2893 | if (IsOSX() && IsOpenGL()) |
| 2894 | { |
| 2895 | // http://anglebug.com/2041 |
| 2896 | std::cout << "Test skipped on Mac OpenGL because local variable initialization is disabled." |
| 2897 | << std::endl; |
| 2898 | return; |
| 2899 | } |
| 2900 | |
| 2901 | const std::string &fragmentShader = |
| 2902 | "precision mediump float;\n" |
| 2903 | "struct T\n" |
| 2904 | "{\n" |
| 2905 | " int a[2];\n" |
| 2906 | "};\n" |
| 2907 | "struct S\n" |
| 2908 | "{\n" |
| 2909 | " T t[2];\n" |
| 2910 | "};\n" |
| 2911 | "void main()\n" |
| 2912 | "{\n" |
| 2913 | " S s;\n" |
| 2914 | " S s2;\n" |
| 2915 | " if (s.t[1].a[1] == 0 && s2.t[1].a[1] == 0)\n" |
| 2916 | " {\n" |
| 2917 | " gl_FragColor = vec4(0, 1, 0, 1);\n" |
| 2918 | " }\n" |
| 2919 | " else\n" |
| 2920 | " {\n" |
| 2921 | " gl_FragColor = vec4(1, 0, 0, 1);\n" |
| 2922 | " }\n" |
| 2923 | "}\n"; |
| 2924 | |
| 2925 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 2926 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 2927 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2928 | } |
| 2929 | |
Geoff Lang | bb1e750 | 2017-06-05 16:40:09 -0400 | [diff] [blame] | 2930 | // Verify that two shaders with the same uniform name and members but different structure names will |
| 2931 | // not link. |
| 2932 | TEST_P(GLSLTest, StructureNameMatchingTest) |
| 2933 | { |
| 2934 | const char *vsSource = |
| 2935 | "// Structures must have the same name, sequence of type names, and\n" |
| 2936 | "// type definitions, and field names to be considered the same type.\n" |
| 2937 | "// GLSL 1.017 4.2.4\n" |
| 2938 | "precision mediump float;\n" |
| 2939 | "struct info {\n" |
| 2940 | " vec4 pos;\n" |
| 2941 | " vec4 color;\n" |
| 2942 | "};\n" |
| 2943 | "\n" |
| 2944 | "uniform info uni;\n" |
| 2945 | "void main()\n" |
| 2946 | "{\n" |
| 2947 | " gl_Position = uni.pos;\n" |
| 2948 | "}\n"; |
| 2949 | |
| 2950 | GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); |
| 2951 | ASSERT_NE(0u, vs); |
| 2952 | glDeleteShader(vs); |
| 2953 | |
| 2954 | const char *fsSource = |
| 2955 | "// Structures must have the same name, sequence of type names, and\n" |
| 2956 | "// type definitions, and field names to be considered the same type.\n" |
| 2957 | "// GLSL 1.017 4.2.4\n" |
| 2958 | "precision mediump float;\n" |
| 2959 | "struct info1 {\n" |
| 2960 | " vec4 pos;\n" |
| 2961 | " vec4 color;\n" |
| 2962 | "};\n" |
| 2963 | "\n" |
| 2964 | "uniform info1 uni;\n" |
| 2965 | "void main()\n" |
| 2966 | "{\n" |
| 2967 | " gl_FragColor = uni.color;\n" |
| 2968 | "}\n"; |
| 2969 | |
| 2970 | GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); |
| 2971 | ASSERT_NE(0u, fs); |
| 2972 | glDeleteShader(fs); |
| 2973 | |
| 2974 | GLuint program = CompileProgram(vsSource, fsSource); |
| 2975 | EXPECT_EQ(0u, program); |
| 2976 | } |
| 2977 | |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 2978 | // Test that an uninitialized nameless struct inside a for loop init statement works. |
| 2979 | TEST_P(GLSLTest_ES3, UninitializedNamelessStructInForInitStatement) |
| 2980 | { |
| 2981 | if (IsAndroid() && IsOpenGLES()) |
| 2982 | { |
| 2983 | // http://anglebug.com/2046 |
| 2984 | std::cout |
| 2985 | << "Test skipped on Android GLES because local variable initialization is disabled." |
| 2986 | << std::endl; |
| 2987 | return; |
| 2988 | } |
| 2989 | |
| 2990 | if (IsOSX() && IsOpenGL()) |
| 2991 | { |
| 2992 | // http://anglebug.com/2041 |
| 2993 | std::cout << "Test skipped on Mac OpenGL because local variable initialization is disabled." |
| 2994 | << std::endl; |
| 2995 | return; |
| 2996 | } |
| 2997 | |
| 2998 | const std::string &fragmentShader = |
| 2999 | "#version 300 es\n" |
| 3000 | "precision highp float;\n" |
| 3001 | "out vec4 my_FragColor;\n" |
| 3002 | "void main()\n" |
| 3003 | "{\n" |
| 3004 | " my_FragColor = vec4(1, 0, 0, 1);\n" |
| 3005 | " for (struct { float q; } b; b.q < 2.0; b.q++) {\n" |
| 3006 | " my_FragColor = vec4(0, 1, 0, 1);\n" |
| 3007 | " }\n" |
| 3008 | "}\n"; |
| 3009 | |
| 3010 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3011 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 3012 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3013 | } |
| 3014 | |
Olli Etuaho | 0ffc441 | 2017-05-19 14:18:55 +0300 | [diff] [blame] | 3015 | // Test that uninitialized global variables are initialized to 0. |
| 3016 | TEST_P(WebGLGLSLTest, InitUninitializedGlobals) |
| 3017 | { |
| 3018 | const std::string &fragmentShader = |
| 3019 | "precision mediump float;\n" |
| 3020 | "int result;\n" |
| 3021 | "int i[2], j = i[0] + 1;\n" |
| 3022 | "void main()\n" |
| 3023 | "{\n" |
| 3024 | " result += j;\n" |
| 3025 | " if (result == 1)\n" |
| 3026 | " {\n" |
| 3027 | " gl_FragColor = vec4(0, 1, 0, 1);\n" |
| 3028 | " }\n" |
| 3029 | " else\n" |
| 3030 | " {\n" |
| 3031 | " gl_FragColor = vec4(1, 0, 0, 1);\n" |
| 3032 | " }\n" |
| 3033 | "}\n"; |
| 3034 | |
| 3035 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3036 | drawQuad(program.get(), "inputAttribute", 0.5f, 1.0f, true); |
| 3037 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3038 | } |
| 3039 | |
| 3040 | // Test that an uninitialized nameless struct in the global scope works. |
| 3041 | TEST_P(WebGLGLSLTest, UninitializedNamelessStructInGlobalScope) |
| 3042 | { |
| 3043 | const std::string &fragmentShader = |
| 3044 | "precision mediump float;\n" |
| 3045 | "struct { float q; } b;\n" |
| 3046 | "void main()\n" |
| 3047 | "{\n" |
| 3048 | " gl_FragColor = vec4(1, 0, 0, 1);\n" |
| 3049 | " if (b.q == 0.0)\n" |
| 3050 | " {\n" |
| 3051 | " gl_FragColor = vec4(0, 1, 0, 1);\n" |
| 3052 | " }\n" |
| 3053 | "}\n"; |
| 3054 | |
| 3055 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3056 | drawQuad(program.get(), "inputAttribute", 0.5f, 1.0f, true); |
| 3057 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3058 | } |
| 3059 | |
Olli Etuaho | 914b79a | 2017-06-19 16:03:19 +0300 | [diff] [blame] | 3060 | // Test that a loop condition that has an initializer declares a variable. |
| 3061 | TEST_P(GLSLTest_ES3, ConditionInitializerDeclaresVariable) |
| 3062 | { |
| 3063 | const std::string &fragmentShader = |
| 3064 | "#version 300 es\n" |
| 3065 | "precision highp float;\n" |
| 3066 | "out vec4 my_FragColor;\n" |
| 3067 | "void main()\n" |
| 3068 | "{\n" |
| 3069 | " float i = 0.0;\n" |
| 3070 | " while (bool foo = (i < 1.5))\n" |
| 3071 | " {\n" |
| 3072 | " if (!foo)\n" |
| 3073 | " {\n" |
| 3074 | " ++i;\n" |
| 3075 | " }\n" |
| 3076 | " if (i > 3.5)\n" |
| 3077 | " {\n" |
| 3078 | " break;\n" |
| 3079 | " }\n" |
| 3080 | " ++i;\n" |
| 3081 | " }\n" |
| 3082 | " my_FragColor = vec4(i * 0.5 - 1.0, i * 0.5, 0.0, 1.0);\n" |
| 3083 | "}\n"; |
| 3084 | |
| 3085 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3086 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 3087 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3088 | } |
| 3089 | |
Olli Etuaho | ff526f1 | 2017-06-30 12:26:54 +0300 | [diff] [blame] | 3090 | // Test that a variable hides a user-defined function with the same name after its initializer. |
| 3091 | // GLSL ES 1.00.17 section 4.2.2: "A variable declaration is visible immediately following the |
| 3092 | // initializer if present, otherwise immediately following the identifier" |
| 3093 | TEST_P(GLSLTest, VariableHidesUserDefinedFunctionAfterInitializer) |
| 3094 | { |
| 3095 | const std::string &fragmentShader = |
| 3096 | "precision mediump float;\n" |
| 3097 | "uniform vec4 u;\n" |
| 3098 | "vec4 foo()\n" |
| 3099 | "{\n" |
| 3100 | " return u;\n" |
| 3101 | "}\n" |
| 3102 | "void main()\n" |
| 3103 | "{\n" |
| 3104 | " vec4 foo = foo();\n" |
| 3105 | " gl_FragColor = foo + vec4(0, 1, 0, 1);\n" |
| 3106 | "}\n"; |
| 3107 | |
| 3108 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3109 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 3110 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3111 | } |
| 3112 | |
Olli Etuaho | 088031e | 2017-07-03 15:59:33 +0300 | [diff] [blame] | 3113 | // Test that structs with identical members are not ambiguous as function arguments. |
| 3114 | TEST_P(GLSLTest, StructsWithSameMembersDisambiguatedByName) |
| 3115 | { |
| 3116 | const std::string &fragmentShader = |
| 3117 | "precision mediump float;\n" |
| 3118 | "uniform float u_zero;\n" |
| 3119 | "struct S { float foo; };\n" |
| 3120 | "struct S2 { float foo; };\n" |
| 3121 | "float get(S s) { return s.foo + u_zero; }\n" |
| 3122 | "float get(S2 s2) { return 0.25 + s2.foo + u_zero; }\n" |
| 3123 | "void main()\n" |
| 3124 | "{\n" |
| 3125 | " S s;\n" |
| 3126 | " s.foo = 0.5;\n" |
| 3127 | " S2 s2;\n" |
| 3128 | " s2.foo = 0.25;\n" |
| 3129 | " gl_FragColor = vec4(0.0, get(s) + get(s2), 0.0, 1.0);\n" |
| 3130 | "}\n"; |
| 3131 | |
| 3132 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3133 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 3134 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3135 | } |
| 3136 | |
Olli Etuaho | 06a06f5 | 2017-07-12 12:22:15 +0300 | [diff] [blame] | 3137 | // Test that a varying struct that's not statically used in the fragment shader works. |
| 3138 | // GLSL ES 3.00.6 section 4.3.10. |
| 3139 | TEST_P(GLSLTest_ES3, VaryingStructNotStaticallyUsedInFragmentShader) |
| 3140 | { |
| 3141 | const std::string &vertexShader = |
| 3142 | "#version 300 es\n" |
| 3143 | "struct S {\n" |
| 3144 | " vec4 field;\n" |
| 3145 | "};\n" |
| 3146 | "out S varStruct;\n" |
| 3147 | "void main()\n" |
| 3148 | "{\n" |
| 3149 | " gl_Position = vec4(1.0);\n" |
| 3150 | " varStruct.field = vec4(0.0, 0.5, 0.0, 0.0);\n" |
| 3151 | "}\n"; |
| 3152 | |
| 3153 | const std::string &fragmentShader = |
| 3154 | "#version 300 es\n" |
| 3155 | "precision mediump float;\n" |
| 3156 | "struct S {\n" |
| 3157 | " vec4 field;\n" |
| 3158 | "};\n" |
| 3159 | "in S varStruct;\n" |
| 3160 | "out vec4 col;\n" |
| 3161 | "void main()\n" |
| 3162 | "{\n" |
| 3163 | " col = vec4(1.0);\n" |
| 3164 | "}\n"; |
| 3165 | |
| 3166 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 3167 | } |
| 3168 | |
| 3169 | // Test that a varying struct that's not declared in the fragment shader links successfully. |
| 3170 | // GLSL ES 3.00.6 section 4.3.10. |
| 3171 | TEST_P(GLSLTest_ES3, VaryingStructNotDeclaredInFragmentShader) |
| 3172 | { |
| 3173 | const std::string &vertexShader = |
| 3174 | "#version 300 es\n" |
| 3175 | "struct S {\n" |
| 3176 | " vec4 field;\n" |
| 3177 | "};\n" |
| 3178 | "out S varStruct;\n" |
| 3179 | "void main()\n" |
| 3180 | "{\n" |
| 3181 | " gl_Position = vec4(1.0);\n" |
| 3182 | " varStruct.field = vec4(0.0, 0.5, 0.0, 0.0);\n" |
| 3183 | "}\n"; |
| 3184 | |
| 3185 | const std::string &fragmentShader = |
| 3186 | "#version 300 es\n" |
| 3187 | "precision mediump float;\n" |
| 3188 | "out vec4 col;\n" |
| 3189 | "void main()\n" |
| 3190 | "{\n" |
| 3191 | " col = vec4(1.0);\n" |
| 3192 | "}\n"; |
| 3193 | |
| 3194 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 3195 | } |
| 3196 | |
| 3197 | // Test that a varying struct that gets used in the fragment shader works. |
| 3198 | TEST_P(GLSLTest_ES3, VaryingStructUsedInFragmentShader) |
| 3199 | { |
| 3200 | const std::string &vertexShader = |
| 3201 | "#version 300 es\n" |
| 3202 | "in vec4 inputAttribute;\n" |
| 3203 | "struct S {\n" |
| 3204 | " vec4 field;\n" |
| 3205 | "};\n" |
| 3206 | "out S varStruct;\n" |
| 3207 | "void main()\n" |
| 3208 | "{\n" |
| 3209 | " gl_Position = inputAttribute;\n" |
| 3210 | " varStruct.field = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| 3211 | "}\n"; |
| 3212 | |
| 3213 | const std::string &fragmentShader = |
| 3214 | "#version 300 es\n" |
| 3215 | "precision mediump float;\n" |
| 3216 | "out vec4 col;\n" |
| 3217 | "struct S {\n" |
| 3218 | " vec4 field;\n" |
| 3219 | "};\n" |
| 3220 | "in S varStruct;\n" |
| 3221 | "void main()\n" |
| 3222 | "{\n" |
| 3223 | " col = varStruct.field;\n" |
| 3224 | "}\n"; |
| 3225 | |
| 3226 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 3227 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 3228 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3229 | } |
| 3230 | |
Olli Etuaho | 3860b6c | 2017-07-19 16:17:24 +0300 | [diff] [blame] | 3231 | // This test covers passing an array of structs containing samplers as a function argument. |
| 3232 | TEST_P(GLSLTest, ArrayOfStructsWithSamplersAsFunctionArg) |
| 3233 | { |
| 3234 | if (IsAndroid() && IsAdreno() && IsOpenGLES()) |
| 3235 | { |
| 3236 | // Shader failed to compile on Android. http://anglebug.com/2114 |
| 3237 | std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl; |
| 3238 | return; |
| 3239 | } |
| 3240 | |
| 3241 | const std::string &vertexShader = |
| 3242 | "attribute vec2 position;\n" |
| 3243 | "void main()\n" |
| 3244 | "{\n" |
| 3245 | " gl_Position = vec4(position, 0, 1);\n" |
| 3246 | "}\n"; |
| 3247 | |
| 3248 | const std::string &fragmentShader = |
| 3249 | "precision mediump float;\n" |
| 3250 | "struct S\n" |
| 3251 | "{\n" |
| 3252 | " sampler2D samplerMember; \n" |
| 3253 | "};\n" |
| 3254 | "uniform S uStructs[2];\n" |
| 3255 | "uniform vec2 uTexCoord;\n" |
| 3256 | "\n" |
| 3257 | "vec4 foo(S[2] structs)\n" |
| 3258 | "{\n" |
| 3259 | " return texture2D(structs[0].samplerMember, uTexCoord);\n" |
| 3260 | "}\n" |
| 3261 | "void main()\n" |
| 3262 | "{\n" |
| 3263 | " gl_FragColor = foo(uStructs);\n" |
| 3264 | "}\n"; |
| 3265 | |
| 3266 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 3267 | |
| 3268 | // Initialize the texture with green. |
| 3269 | GLTexture tex; |
| 3270 | glActiveTexture(GL_TEXTURE0); |
| 3271 | glBindTexture(GL_TEXTURE_2D, tex); |
| 3272 | GLubyte texData[] = {0u, 255u, 0u, 255u}; |
| 3273 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 3274 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 3275 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3276 | ASSERT_GL_NO_ERROR(); |
| 3277 | |
| 3278 | // Draw |
| 3279 | glUseProgram(program); |
| 3280 | GLint samplerMemberLoc = glGetUniformLocation(program, "uStructs[0].samplerMember"); |
| 3281 | ASSERT_NE(-1, samplerMemberLoc); |
| 3282 | glUniform1i(samplerMemberLoc, 0); |
| 3283 | GLint texCoordLoc = glGetUniformLocation(program, "uTexCoord"); |
| 3284 | ASSERT_NE(-1, texCoordLoc); |
| 3285 | glUniform2f(texCoordLoc, 0.5f, 0.5f); |
| 3286 | |
| 3287 | drawQuad(program, "position", 0.5f); |
| 3288 | ASSERT_GL_NO_ERROR(); |
| 3289 | |
| 3290 | EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green); |
| 3291 | } |
| 3292 | |
Olli Etuaho | 28839f0 | 2017-08-15 11:38:16 +0300 | [diff] [blame] | 3293 | // This test covers passing a struct containing an array of samplers as a function argument. |
| 3294 | TEST_P(GLSLTest, StructWithSamplerArrayAsFunctionArg) |
| 3295 | { |
| 3296 | if (IsAndroid() && IsAdreno() && IsOpenGLES()) |
| 3297 | { |
| 3298 | // Shader failed to compile on Android. http://anglebug.com/2114 |
| 3299 | std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl; |
| 3300 | return; |
| 3301 | } |
| 3302 | |
| 3303 | const std::string &vertexShader = |
| 3304 | "attribute vec2 position;\n" |
| 3305 | "void main()\n" |
| 3306 | "{\n" |
| 3307 | " gl_Position = vec4(position, 0, 1);\n" |
| 3308 | "}\n"; |
| 3309 | |
| 3310 | const std::string &fragmentShader = |
| 3311 | "precision mediump float;\n" |
| 3312 | "struct S\n" |
| 3313 | "{\n" |
| 3314 | " sampler2D samplerMembers[2];\n" |
| 3315 | "};\n" |
| 3316 | "uniform S uStruct;\n" |
| 3317 | "uniform vec2 uTexCoord;\n" |
| 3318 | "\n" |
| 3319 | "vec4 foo(S str)\n" |
| 3320 | "{\n" |
| 3321 | " return texture2D(str.samplerMembers[0], uTexCoord);\n" |
| 3322 | "}\n" |
| 3323 | "void main()\n" |
| 3324 | "{\n" |
| 3325 | " gl_FragColor = foo(uStruct);\n" |
| 3326 | "}\n"; |
| 3327 | |
| 3328 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 3329 | |
| 3330 | // Initialize the texture with green. |
| 3331 | GLTexture tex; |
| 3332 | glActiveTexture(GL_TEXTURE0); |
| 3333 | glBindTexture(GL_TEXTURE_2D, tex); |
| 3334 | GLubyte texData[] = {0u, 255u, 0u, 255u}; |
| 3335 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 3336 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 3337 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3338 | ASSERT_GL_NO_ERROR(); |
| 3339 | |
| 3340 | // Draw |
| 3341 | glUseProgram(program); |
| 3342 | GLint samplerMemberLoc = glGetUniformLocation(program, "uStruct.samplerMembers[0]"); |
| 3343 | ASSERT_NE(-1, samplerMemberLoc); |
| 3344 | glUniform1i(samplerMemberLoc, 0); |
| 3345 | GLint texCoordLoc = glGetUniformLocation(program, "uTexCoord"); |
| 3346 | ASSERT_NE(-1, texCoordLoc); |
| 3347 | glUniform2f(texCoordLoc, 0.5f, 0.5f); |
| 3348 | |
| 3349 | drawQuad(program, "position", 0.5f); |
| 3350 | ASSERT_GL_NO_ERROR(); |
| 3351 | |
| 3352 | EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green); |
| 3353 | } |
| 3354 | |
Olli Etuaho | a16a84f | 2017-09-12 13:49:18 +0300 | [diff] [blame] | 3355 | // Test that a global variable declared after main() works. This is a regression test for an issue |
| 3356 | // in global variable initialization. |
| 3357 | TEST_P(WebGLGLSLTest, GlobalVariableDeclaredAfterMain) |
| 3358 | { |
| 3359 | const std::string &fragmentShader = |
| 3360 | "precision mediump float;\n" |
| 3361 | "int getFoo();\n" |
| 3362 | "uniform int u_zero;\n" |
| 3363 | "void main()\n" |
| 3364 | "{\n" |
| 3365 | " gl_FragColor = vec4(1, 0, 0, 1);\n" |
| 3366 | " if (getFoo() == 0)\n" |
| 3367 | " {\n" |
| 3368 | " gl_FragColor = vec4(0, 1, 0, 1);\n" |
| 3369 | " }\n" |
| 3370 | "}\n" |
| 3371 | "int foo;\n" |
| 3372 | "int getFoo()\n" |
| 3373 | "{\n" |
| 3374 | " foo = u_zero;\n" |
| 3375 | " return foo;\n" |
| 3376 | "}\n"; |
| 3377 | |
| 3378 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3379 | drawQuad(program.get(), "inputAttribute", 0.5f, 1.0f, true); |
| 3380 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3381 | } |
| 3382 | |
Olli Etuaho | bb5a7e2 | 2017-08-30 13:03:12 +0300 | [diff] [blame] | 3383 | // Test calling array length() with a "this" expression having side effects inside a loop condition. |
| 3384 | // The spec says that sequence operator operands need to run in sequence. |
| 3385 | TEST_P(GLSLTest_ES3, ArrayLengthOnExpressionWithSideEffectsInLoopCondition) |
| 3386 | { |
| 3387 | // "a" gets doubled three times in the below program. |
| 3388 | const std::string &fragmentShader = |
| 3389 | R"(#version 300 es |
| 3390 | precision highp float; |
| 3391 | out vec4 my_FragColor; |
| 3392 | uniform int u_zero; |
| 3393 | int a; |
| 3394 | int[2] doubleA() |
| 3395 | { |
| 3396 | a *= 2; |
| 3397 | return int[2](a, a); |
| 3398 | } |
| 3399 | void main() |
| 3400 | { |
| 3401 | a = u_zero + 1; |
| 3402 | for (int i = 0; i < doubleA().length(); ++i) |
| 3403 | {} |
| 3404 | if (a == 8) |
| 3405 | { |
| 3406 | my_FragColor = vec4(0, 1, 0, 1); |
| 3407 | } |
| 3408 | else |
| 3409 | { |
| 3410 | my_FragColor = vec4(1, 0, 0, 1); |
| 3411 | } |
| 3412 | })"; |
| 3413 | |
| 3414 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3415 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 3416 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3417 | } |
| 3418 | |
| 3419 | // Test calling array length() with a "this" expression having side effects that interact with side |
| 3420 | // effects of another operand of the same sequence operator. The spec says that sequence operator |
| 3421 | // operands need to run in order from left to right (ESSL 3.00.6 section 5.9). |
| 3422 | TEST_P(GLSLTest_ES3, ArrayLengthOnExpressionWithSideEffectsInSequence) |
| 3423 | { |
| 3424 | const std::string &fragmentShader = |
| 3425 | R"(#version 300 es |
| 3426 | precision highp float; |
| 3427 | out vec4 my_FragColor; |
| 3428 | uniform int u_zero; |
| 3429 | int a; |
| 3430 | int[3] doubleA() |
| 3431 | { |
| 3432 | a *= 2; |
| 3433 | return int[3](a, a, a); |
| 3434 | } |
| 3435 | void main() |
| 3436 | { |
| 3437 | a = u_zero; |
| 3438 | int b = (a++, doubleA().length()); |
| 3439 | if (b == 3 && a == 2) |
| 3440 | { |
| 3441 | my_FragColor = vec4(0, 1, 0, 1); |
| 3442 | } |
| 3443 | else |
| 3444 | { |
| 3445 | my_FragColor = vec4(1, 0, 0, 1); |
| 3446 | } |
| 3447 | })"; |
| 3448 | |
| 3449 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3450 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 3451 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3452 | } |
| 3453 | |
| 3454 | // Test calling array length() with a "this" expression that also contains a call of array length(). |
| 3455 | // Both "this" expressions also have side effects. |
| 3456 | TEST_P(GLSLTest_ES3, NestedArrayLengthMethodsWithSideEffects) |
| 3457 | { |
| 3458 | const std::string &fragmentShader = |
| 3459 | R"(#version 300 es |
| 3460 | precision highp float; |
| 3461 | out vec4 my_FragColor; |
| 3462 | uniform int u_zero; |
| 3463 | int a; |
| 3464 | int[3] multiplyA(int multiplier) |
| 3465 | { |
| 3466 | a *= multiplier; |
| 3467 | return int[3](a, a, a); |
| 3468 | } |
| 3469 | void main() |
| 3470 | { |
| 3471 | a = u_zero + 1; |
| 3472 | int b = multiplyA(multiplyA(2).length()).length(); |
| 3473 | if (b == 3 && a == 6) |
| 3474 | { |
| 3475 | my_FragColor = vec4(0, 1, 0, 1); |
| 3476 | } |
| 3477 | else |
| 3478 | { |
| 3479 | my_FragColor = vec4(1, 0, 0, 1); |
| 3480 | } |
| 3481 | })"; |
| 3482 | |
| 3483 | ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader); |
| 3484 | drawQuad(program.get(), "inputAttribute", 0.5f); |
| 3485 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3486 | } |
| 3487 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 3488 | // 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] | 3489 | ANGLE_INSTANTIATE_TEST(GLSLTest, |
| 3490 | ES2_D3D9(), |
| 3491 | ES2_D3D11(), |
| 3492 | ES2_D3D11_FL9_3(), |
| 3493 | ES2_OPENGL(), |
| 3494 | ES3_OPENGL(), |
| 3495 | ES2_OPENGLES(), |
| 3496 | ES3_OPENGLES()); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 3497 | |
| 3498 | // 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] | 3499 | ANGLE_INSTANTIATE_TEST(GLSLTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 3500 | |
| 3501 | ANGLE_INSTANTIATE_TEST(WebGLGLSLTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES()); |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 3502 | |
| 3503 | ANGLE_INSTANTIATE_TEST(GLSLTest_ES31, ES31_D3D11(), ES31_OPENGL(), ES31_OPENGLES()); |