shaders-with-constant-expression-loop-conditions.html (3792B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 <!DOCTYPE html> 7 <html> 8 <head> 9 <meta charset="utf-8"> 10 <title>WebGL GLSL Conformance Tests</title> 11 <link rel="stylesheet" href="../../../resources/js-test-style.css" /> 12 <link rel="stylesheet" href="../../../resources/glsl-feature-tests.css" /> 13 <script src="../../../js/js-test-pre.js"></script> 14 <script src="../../../js/webgl-test-utils.js"></script> 15 <script src="../../../js/glsl-conformance-test.js"></script> 16 </head> 17 <body> 18 <div id="description"></div> 19 <div id="console"></div> 20 <script id="vertexShaderLiteralLoopCondition" type="text/something-not-javascript"> 21 attribute vec4 a_position; 22 void main() 23 { 24 for (int i = 0; i < 5 + 5; i++) { } 25 gl_Position = a_position; 26 } 27 </script> 28 <script id="fragmentShaderLiteralLoopCondition" type="text/something-not-javascript"> 29 void main() 30 { 31 for (int i = 0; i < 5 + 5; i++) { } 32 gl_FragColor = vec4(1.0); 33 } 34 </script> 35 <script id="vertexShaderConstVarLoopCondition" type="text/something-not-javascript"> 36 attribute vec4 a_position; 37 void main() 38 { 39 // Explicitly constant variables can be part of a constant expression 40 const int constVar = 5; 41 for (int i = 0; i < 5 + constVar; i++) { } 42 gl_Position = a_position; 43 } 44 </script> 45 <script id="fragmentShaderConstVarLoopCondition" type="text/something-not-javascript"> 46 void main() 47 { 48 // Explicitly constant variables can be part of a constant expression 49 const int constVar = 5; 50 for (int i = 0; i < constVar + 5; i++) { } 51 gl_FragColor = vec4(1.0); 52 } 53 </script> 54 <script id="vertexShaderNonConstVarLoopCondition" type="text/something-not-javascript"> 55 attribute vec4 a_position; 56 void main() 57 { 58 // Despite assigning a constant and not modifying it, nonConstVar is not semantically a constant expression 59 int nonConstVar = 10; 60 for (int i = 0; i < nonConstVar; i++) { } 61 gl_Position = a_position; 62 } 63 </script> 64 <script id="fragmentShaderNonConstVarLoopCondition" type="text/something-not-javascript"> 65 void main() 66 { 67 // Despite assigning a constant and not modifying it, nonConstVar is not semantically a constant expression 68 int nonConstVar = 10; 69 for (int i = 0; i < nonConstVar; i++) { } 70 gl_FragColor = vec4(1.0); 71 } 72 </script> 73 <script> 74 "use strict"; 75 var wtu = WebGLTestUtils; 76 77 var tests = []; 78 tests.push({ 79 vShaderSource: wtu.getScript("vertexShaderLiteralLoopCondition"), 80 vShaderSuccess: true, 81 fShaderSource: wtu.getScript("fragmentShaderLiteralLoopCondition"), 82 fShaderSuccess: true, 83 linkSuccess: true, 84 passMsg: "Shaders with literals in the loop condition should compile and link.", 85 }); 86 tests.push({ 87 vShaderSource: wtu.getScript("vertexShaderConstVarLoopCondition"), 88 vShaderSuccess: true, 89 fShaderSource: wtu.getScript("fragmentShaderConstVarLoopCondition"), 90 fShaderSuccess: true, 91 linkSuccess: true, 92 passMsg: "Shaders with constant variables in the loop condition should compile and link.", 93 }); 94 tests.push({ 95 vShaderSource: wtu.getScript("vertexShaderNonConstVarLoopCondition"), 96 vShaderSuccess: false, 97 fShaderSource: wtu.getScript("fragmentShaderLiteralLoopCondition"), 98 fShaderSuccess: true, 99 linkSuccess: false, 100 passMsg: "Vertex shader with non-const variable in the loop condition should fail.", 101 }); 102 tests.push({ 103 vShaderSource: wtu.getScript("vertexShaderLiteralLoopCondition"), 104 vShaderSuccess: true, 105 fShaderSource: wtu.getScript("fragmentShaderNonConstVarLoopCondition"), 106 fShaderSuccess: false, 107 linkSuccess: false, 108 passMsg: "Fragment shader with non-const variable in the loop condition should fail.", 109 }); 110 111 GLSLConformanceTester.runTests(tests); 112 var successfullyParsed = true; 113 </script> 114 </body> 115 </html>