array-in-complex-expression.html (3957B)
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 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>GLSL array in complex expression test</title> 12 <link rel="stylesheet" href="../../resources/js-test-style.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="fshaderAndShortCircuits" type="x-shader/x-fragment">#version 300 es 21 precision mediump float; 22 23 out vec4 my_FragColor; 24 25 int g = 0; 26 27 int[2] plus() { 28 ++g; 29 return int[2](g, g); 30 } 31 32 bool minus() { 33 --g; 34 return false; 35 } 36 37 void main() { 38 int a[2] = int[2](0, 0); 39 // The function call must not be evaluated, since && short-circuits 40 minus() && (a == plus()); 41 my_FragColor = vec4(0.0, ((g == -1) ? 1.0 : 0.0), 0.0, 1.0); 42 } 43 </script> 44 <script id="fshaderOrShortCircuits" type="x-shader/x-fragment">#version 300 es 45 precision mediump float; 46 47 out vec4 my_FragColor; 48 49 int g = 0; 50 51 int[2] plus() { 52 ++g; 53 return int[2](g, g); 54 } 55 56 bool minus() { 57 --g; 58 return true; 59 } 60 61 void main() { 62 int a[2] = int[2](0, 0); 63 // The function call must not be evaluated, since || short-circuits. 64 minus() || (a == plus()); 65 my_FragColor = vec4(0.0, ((g == -1) ? 1.0 : 0.0), 0.0, 1.0); 66 } 67 </script> 68 <script id="fshaderTernaryOnlyEvaluatesOneOperand" type="x-shader/x-fragment">#version 300 es 69 precision mediump float; 70 71 out vec4 my_FragColor; 72 73 int g = 0; 74 75 int[2] plus() { 76 ++g; 77 return int[2](g, g); 78 } 79 80 void main() { 81 int a[2] = int[2](0, 0); 82 // The function call must not be evaluated, since the condition is true. 83 (g == 0) ? true : (a == plus()); 84 my_FragColor = vec4(0.0, ((g == 0) ? 1.0 : 0.0), 0.0, 1.0); 85 } 86 </script> 87 <script id="fshaderSequenceSideEffectsAffectingComparedArrayContent" type="x-shader/x-fragment">#version 300 es 88 precision mediump float; 89 90 out vec4 my_FragColor; 91 92 int[2] func(int param) { 93 return int[2](param, param); 94 } 95 96 void main() { 97 int a[2]; 98 for (int i = 0; i < 2; ++i) { 99 a[i] = 1; 100 } 101 int j = 0; 102 // Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9). 103 // The function call that returns the array needs to be evaluated after ++j 104 // for the expression to return the correct value (true). 105 bool result = ((++j), (a == func(j))); 106 my_FragColor = vec4(0.0, (result ? 1.0 : 0.0), 0.0, 1.0); 107 } 108 </script> 109 <script type="application/javascript"> 110 "use strict"; 111 description("Arrays in complex expressions should work"); 112 debug(""); 113 debug("This test is targeted to stress syntax tree transformations that might need to be done in shader translation when the platform doesn't natively support arrays as return values."); 114 115 GLSLConformanceTester.runRenderTests([ 116 { 117 fShaderId: 'fshaderAndShortCircuits', 118 fShaderSuccess: true, 119 linkSuccess: true, 120 passMsg: "Expression where an array is returned from a function call inside an operand to && that doesn't get evaluated as result of short-circuiting" 121 }, 122 { 123 fShaderId: 'fshaderOrShortCircuits', 124 fShaderSuccess: true, 125 linkSuccess: true, 126 passMsg: "Expression where an array is returned from a function call inside an operand to || that doesn't get evaluated as result of short-circuiting" 127 }, 128 { 129 fShaderId: 'fshaderTernaryOnlyEvaluatesOneOperand', 130 fShaderSuccess: true, 131 linkSuccess: true, 132 passMsg: "Expression where an array is returned from a function call in an operand of a ternary operator that doesn't get evaluated" 133 }, 134 { 135 fShaderId: 'fshaderSequenceSideEffectsAffectingComparedArrayContent', 136 fShaderSuccess: true, 137 linkSuccess: true, 138 passMsg: 'Expression where first operand of a sequence operator has side effects which affect the second operand that returns an array' 139 } 140 ], 2); 141 </script> 142 </body> 143 </html>