Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / glsl3 / short-circuiting-in-loop-condition.html
blob802d67aa4a3376c93591aea0beeca9da35f57761
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 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
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>
16 </head>
17 <body>
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;
22 uniform bool u;
23 out vec4 result;
24 int sideEffectCounter;
26 bool foo() {
27 ++sideEffectCounter;
28 return true;
31 void main() {
32 sideEffectCounter = 0;
33 int iterations = 0;
35 while(u && foo()) {
36 ++iterations;
37 if (iterations >= 10) {
38 break;
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);
45 </script>
46 <script id="fshaderForCondition" type="x-shader/x-fragment">#version 300 es
47 precision mediump float;
48 uniform bool u;
49 out vec4 result;
50 int sideEffectCounter;
52 bool foo() {
53 ++sideEffectCounter;
54 return true;
57 void main() {
58 sideEffectCounter = 0;
59 for(int iterations = 0; u && foo();) {
60 ++iterations;
61 if (iterations >= 10) {
62 break;
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);
69 </script>
70 <script id="fshaderFor" type="x-shader/x-fragment">#version 300 es
71 precision mediump float;
72 uniform bool u;
73 out vec4 result;
74 int sideEffectCounter;
76 bool foo() {
77 ++sideEffectCounter;
78 return true;
81 void main() {
82 sideEffectCounter = 0;
83 for(int iterations = 0; true; u && foo()) {
84 ++iterations;
85 if (iterations > 10) {
86 break;
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);
93 </script>
94 <script id="fshaderDoWhile" type="x-shader/x-fragment">#version 300 es
95 precision mediump float;
96 uniform bool u;
97 out vec4 result;
98 int sideEffectCounter;
100 bool foo() {
101 ++sideEffectCounter;
102 return true;
105 void main() {
106 sideEffectCounter = 0;
107 int iterations = 0;
109 do {
110 ++iterations;
111 if (iterations > 10) {
112 break;
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);
119 </script>
120 <script id="fshaderSequence" type="x-shader/x-fragment">#version 300 es
121 precision mediump float;
122 uniform bool u;
123 out vec4 result;
124 int sideEffectCounter;
126 bool foo() {
127 ++sideEffectCounter;
128 return true;
131 void main() {
132 sideEffectCounter = 0;
133 int iterations = 0;
135 while(u, u && foo()) {
136 ++iterations;
137 if (iterations >= 10) {
138 break;
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);
145 </script>
146 <script type="text/javascript">
147 "use strict";
148 description("Test behavior of a short-circuiting operator in a loop using a function call with side effects");
150 var testShaders = [
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'}
158 var testList = [];
160 for (var i = 0; i < testShaders.length; ++i) {
161 testList.push({
162 fShaderId: testShaders[i].fShaderId,
163 fShaderSuccess: true,
164 linkSuccess: true,
165 passMsg: 'Short-circuiting operator with a true condition ' + testShaders[i].description,
166 uniforms: [{name: "u", functionName: "uniform1i", value: 1}]
168 testList.push({
169 fShaderId: testShaders[i].fShaderId,
170 fShaderSuccess: true,
171 linkSuccess: 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);
178 </script>
179 </body>
180 </html>