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