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.
10 <meta charset=
"utf-8">
11 <title>WebGL Loops and side-effects 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>
17 <div id=
"description"></div>
18 <canvas id=
"canvas" style=
"width: 50px; height: 50px;"> </canvas>
19 <div id=
"console"></div>
21 <!-- Variations on counter functions that used to give incorrect result on OSX 10.9 -->
22 <script id=
"counter0" type=
"x-shader/x-shader">
39 <script id=
"counter1" type=
"x-shader/x-shader">
51 <script id=
"counter2" type=
"x-shader/x-shader">
68 <script id=
"counter3" type=
"x-shader/x-shader">
84 <script id=
"counter4" type=
"x-shader/x-shader">
87 bool bar = s0 || (i++ <
3);
97 <script id=
"counter5" type=
"x-shader/x-shader">
100 if (!(s0 || (i++ <
3))) {
108 <script id=
"counter6" type=
"x-shader/x-shader">
110 while(s0 || (i++ <
3)) {
117 <script id=
"counter7" type=
"x-shader/x-shader">
125 description("This test checks for bugs related to loops and side-effects.");
129 var wtu
= WebGLTestUtils
;
130 var canvas
= document
.getElementById("canvas");
131 var gl
= wtu
.create3DContext(canvas
, null, 2);
134 testFailed("WebGL context does not exist");
136 testPassed("WebGL context exists");
138 for (var i
= 0; i
< 8; i
++) {
139 tryCounter(document
.getElementById("counter" + i
).text
);
144 function evaluateCounter(source
) {
145 var jsSource
= "(function(n, i) {" +
146 source
.split("bool").join("var") +
149 return eval(jsSource
);
152 function makeFSSource(source
) {
154 "#version 300 es\n" +
155 "precision highp float;\n" +
156 "in float vertexCounter;\n" +
157 "uniform int uVertZero;\n" +
158 "uniform int uReference;\n" +
159 "out vec4 fragColor;\n" +
160 "int counter(int n, int i) {\n" +
164 " fragColor = vec4(0.0, 0.0, 0.0, 1.0);\n" +
165 " fragColor.r = float(counter(uVertZero, uVertZero) == uReference);\n" +
166 " fragColor.g = float(int(vertexCounter) == uReference);\n" +
171 function makeVSSource(source
) {
173 "#version 300 es\n" +
174 "out float vertexCounter;\n" +
175 "uniform int uFragZero;\n" +
176 "in vec4 vPosition;\n" +
177 "int counter(int n, int i) {\n" +
181 " gl_Position = vPosition;\n" +
182 " vertexCounter = float(counter(uFragZero, uFragZero));\n" +
187 function tryCounter(source
) {
188 canvas
.width
= 50; canvas
.height
= 50;
189 gl
.viewport(0, 0, canvas
.width
, canvas
.height
);
190 wtu
.setupUnitQuad(gl
, 0, 1);
192 var program
= wtu
.setupProgram(gl
, [makeVSSource(source
), makeFSSource(source
)], ['vPosition'], [0], true);
194 gl
.uniform1i(gl
.getUniformLocation(program
, "uVertZero"), 0);
195 gl
.uniform1i(gl
.getUniformLocation(program
, "uFragZero"), 0);
197 var reference
= evaluateCounter(source
);
198 gl
.uniform1i(gl
.getUniformLocation(program
, "uReference"), reference
);
200 gl
.useProgram(program
);
201 wtu
.clearAndDrawUnitQuad(gl
, [0, 0, 0, 0]);
202 wtu
.checkCanvas(gl
, [255, 255, 0, 255]);
206 var successfullyParsed
= true;
208 <script src=
"../../js/js-test-post.js"></script>