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>Short circuit in loop condition 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>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
20 <script id=
"fshaderWhile" type=
"x-shader/x-fragment">#version
300 es
21 precision mediump float;
24 int sideEffectCounter;
32 sideEffectCounter =
0;
37 if (iterations
>=
10) {
42 bool success = (u && sideEffectCounter ==
10) || (!u && sideEffectCounter ==
0);
43 result = success ? vec4(
0,
1.0,
0,
1.0) : vec4(
0,
1.0,
0,
0);
46 <script id=
"fshaderForCondition" type=
"x-shader/x-fragment">#version
300 es
47 precision mediump float;
50 int sideEffectCounter;
58 sideEffectCounter =
0;
59 for(int iterations =
0; u && foo();) {
61 if (iterations
>=
10) {
66 bool success = (u && sideEffectCounter ==
10) || (!u && sideEffectCounter ==
0);
67 result = success ? vec4(
0,
1.0,
0,
1.0) : vec4(
0,
1.0,
0,
0);
70 <script id=
"fshaderFor" type=
"x-shader/x-fragment">#version
300 es
71 precision mediump float;
74 int sideEffectCounter;
82 sideEffectCounter =
0;
83 for(int iterations =
0; true; u && foo()) {
85 if (iterations
> 10) {
90 bool success = (u && sideEffectCounter ==
10) || (!u && sideEffectCounter ==
0);
91 result = success ? vec4(
0,
1.0,
0,
1.0) : vec4(
0,
1.0,
0,
0);
94 <script id=
"fshaderDoWhile" type=
"x-shader/x-fragment">#version
300 es
95 precision mediump float;
98 int sideEffectCounter;
106 sideEffectCounter =
0;
111 if (iterations
> 10) {
114 } while (u && foo());
116 bool success = (u && sideEffectCounter ==
10) || (!u && sideEffectCounter ==
0);
117 result = success ? vec4(
0,
1.0,
0,
1.0) : vec4(
0,
1.0,
0,
0);
120 <script id=
"fshaderSequence" type=
"x-shader/x-fragment">#version
300 es
121 precision mediump float;
124 int sideEffectCounter;
132 sideEffectCounter =
0;
135 while(u, u && foo()) {
137 if (iterations
>=
10) {
142 bool success = (u && sideEffectCounter ==
10) || (!u && sideEffectCounter ==
0);
143 result = success ? vec4(
0,
1.0,
0,
1.0) : vec4(
0,
1.0,
0,
0);
146 <script type=
"text/javascript">
148 description("Test behavior of a short-circuiting operator in a loop using a function call with side effects");
151 {fShaderId
: 'fshaderWhile', description
: 'in while loop condition'},
152 {fShaderId
: 'fshaderForCondition', description
: 'in for loop condition'},
153 {fShaderId
: 'fshaderFor', description
: 'in for loop expression'},
154 {fShaderId
: 'fshaderDoWhile', description
: 'in do-while loop condition'},
155 {fShaderId
: 'fshaderSequence', description
: 'inside a sequence in while loop condition'}
160 for (var i
= 0; i
< testShaders
.length
; ++i
) {
162 fShaderId
: testShaders
[i
].fShaderId
,
163 fShaderSuccess
: true,
165 passMsg
: 'Short-circuiting operator with a true condition ' + testShaders
[i
].description
,
166 uniforms
: [{name
: "u", functionName
: "uniform1i", value
: 1}]
169 fShaderId
: testShaders
[i
].fShaderId
,
170 fShaderSuccess
: true,
172 passMsg
: 'Short-circuiting operator with a false condition ' + testShaders
[i
].description
,
173 uniforms
: [{name
: "u", functionName
: "uniform1i", value
: 0}]
177 GLSLConformanceTester
.runRenderTests(testList
, 2);