Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / glsl3 / switch-case.html
blob4ab422c958f937c4e9fef4725ad8b68aa965dff7
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>GLSL switch/case corner case 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="fshaderDeclarationInsideSwitch" type="x-shader/x-fragment">#version 300 es
22 precision highp float;
23 out vec4 my_FragColor;
25 uniform int u_zero;
27 void main()
29 my_FragColor = vec4(1, 0, 0, 1);
30 switch (u_zero)
32 case 0:
33 ivec2 i;
34 i = ivec2(1, 0);
35 my_FragColor = vec4(0, i[0], 0, 1);
38 </script>
39 <script id="fshaderDeclarationInsideSwitchDefault" type="x-shader/x-fragment">#version 300 es
41 precision highp float;
42 out vec4 my_FragColor;
44 uniform int u_zero;
46 void main()
48 my_FragColor = vec4(1, 0, 0, 1);
49 switch (u_zero)
51 default:
52 ivec2 i;
53 i = ivec2(1, 0);
54 my_FragColor = vec4(0, i[0], 0, 1);
57 </script>
58 <script id="fshaderDeclarationInsideSwitchLiteral" type="x-shader/x-fragment">#version 300 es
60 precision highp float;
61 out vec4 my_FragColor;
63 void main()
65 my_FragColor = vec4(1, 0, 0, 1);
66 switch (0)
68 case 0:
69 ivec2 i;
70 i = ivec2(1, 0);
71 my_FragColor = vec4(0, i[0], 0, 1);
74 </script>
75 <script id="fshaderDeclarationInsideSwitchLiteralDefault" type="x-shader/x-fragment">#version 300 es
77 precision highp float;
78 out vec4 my_FragColor;
80 void main()
82 my_FragColor = vec4(1, 0, 0, 1);
83 switch (0)
85 default:
86 ivec2 i;
87 i = ivec2(1, 0);
88 my_FragColor = vec4(0, i[0], 0, 1);
91 </script>
92 <script id="fshaderDeclarationInsideSwitchScope" type="x-shader/x-fragment">#version 300 es
94 precision highp float;
95 out vec4 my_FragColor;
97 uniform int u_zero;
99 // GLSL ES 3.10 clarifies the scoping rules that are relevant here. In section 4.2.2 it says:
100 // "The statement following a switch (...) forms a nested scope."
101 // There are no other special scoping rules with regards to switch statements.
103 void main()
105 my_FragColor = vec4(1, 0, 0, 1);
106 switch (u_zero)
108 case 0:
109 ivec2 i;
110 i = ivec2(1, 0);
111 default:
112 my_FragColor = vec4(0, i[0], 0, 1);
115 </script>
116 <script id="fshaderFallThroughAll" type="x-shader/x-fragment">#version 300 es
118 precision highp float;
120 out vec4 my_FragColor;
122 uniform int u_zero;
124 void main()
126 int i = 0;
127 // switch should fall through both cases.
128 switch(u_zero)
130 case 0:
131 i += 1;
132 case 1:
133 i += 2;
135 if (i == 3)
137 my_FragColor = vec4(0, 1, 0, 1);
139 else
141 my_FragColor = vec4(1, 0, 0, 1);
144 </script>
145 <script id="fshaderEmptySwitchStatement" type="x-shader/x-fragment">#version 300 es
147 precision highp float;
149 out vec4 my_FragColor;
151 uniform int u_zero;
153 void main()
155 switch(u_zero)
158 my_FragColor = vec4(0, 1, 0, 1);
160 </script>
161 <script id="fshaderLastCaseHasEmptyDeclaration" type="x-shader/x-fragment">#version 300 es
163 precision highp float;
165 out vec4 my_FragColor;
167 uniform int u_zero;
169 void main()
171 // Empty declaration should count as a statement.
172 switch(u_zero)
174 case 0:
175 int;
177 my_FragColor = vec4(0, 1, 0, 1);
179 </script>
180 <script id="fshaderLastCaseHasEmptyBlock" type="x-shader/x-fragment">#version 300 es
182 precision highp float;
184 out vec4 my_FragColor;
186 uniform int u_zero;
188 void main()
190 // Empty block should count as a statement.
191 switch(u_zero)
193 case 0:
196 my_FragColor = vec4(0, 1, 0, 1);
198 </script>
199 <script id="fshaderLastCaseHasConstantStatement" type="x-shader/x-fragment">#version 300 es
201 precision highp float;
203 out vec4 my_FragColor;
205 uniform int u_zero;
207 void main()
209 // Empty statement should count as a statement.
210 switch(u_zero)
212 case 0:
215 my_FragColor = vec4(0, 1, 0, 1);
217 </script>
218 <script id="fshaderLastCaseHasEmptyStatement" type="x-shader/x-fragment">#version 300 es
220 precision highp float;
222 out vec4 my_FragColor;
224 uniform int u_zero;
226 void main()
228 // Empty statement should count as a statement.
229 switch(u_zero)
231 case 0:
234 my_FragColor = vec4(0, 1, 0, 1);
236 </script>
237 <script id="fshaderCaseInsideBlock" type="x-shader/x-fragment">#version 300 es
239 precision highp float;
241 out vec4 my_FragColor;
243 uniform int u_zero;
245 void main()
247 // Case statements must not be nested in blocks.
248 // GLSL ES 3.00 spec is a bit vague on this but GLSL ES 3.10 section 6.2 is clearer.
249 switch(u_zero)
251 case 1:
253 case 0:
254 my_FragColor = vec4(1, 0, 0, 1);
257 my_FragColor = vec4(0, 1, 0, 1);
259 </script>
260 <script type="application/javascript">
261 "use strict";
262 description();
264 // Covers bugs:
265 // http://anglebug.com/2177
266 // http://anglebug.com/2178
267 // http://anglebug.com/2179
269 GLSLConformanceTester.runTests([
271 fShaderId: 'fshaderDeclarationInsideSwitch',
272 fShaderSuccess: true,
273 linkSuccess: true,
274 passMsg: 'Declaration inside switch should work.',
275 render: true
278 fShaderId: 'fshaderDeclarationInsideSwitchDefault',
279 fShaderSuccess: true,
280 linkSuccess: true,
281 passMsg: 'Declaration inside switch default case should work.',
282 render: true
285 fShaderId: 'fshaderDeclarationInsideSwitchLiteral',
286 fShaderSuccess: true,
287 linkSuccess: true,
288 passMsg: 'Declaration inside switch with literal value should work.',
289 render: true
292 fShaderId: 'fshaderDeclarationInsideSwitchLiteralDefault',
293 fShaderSuccess: true,
294 linkSuccess: true,
295 passMsg: 'Declaration inside switch with literal value and default case should work.',
296 render: true
299 fShaderId: 'fshaderDeclarationInsideSwitchScope',
300 fShaderSuccess: true,
301 linkSuccess: true,
302 passMsg: 'Declaration inside switch should be scoped until the end of the switch statement.',
303 render: true
306 fShaderId: 'fshaderFallThroughAll',
307 fShaderSuccess: true,
308 linkSuccess: true,
309 passMsg: 'Falling through all cases in switch/case should work.',
310 render: true
313 fShaderId: 'fshaderEmptySwitchStatement',
314 fShaderSuccess: true,
315 linkSuccess: true,
316 passMsg: 'Empty switch statements are valid.'
319 fShaderId: 'fshaderLastCaseHasEmptyDeclaration',
320 fShaderSuccess: true,
321 linkSuccess: true,
322 passMsg: 'Empty declaration should count as a statement for the purposes of switch statement validation.'
325 fShaderId: 'fshaderLastCaseHasEmptyBlock',
326 fShaderSuccess: true,
327 linkSuccess: true,
328 passMsg: 'Empty block should count as a statement for the purposes of switch statement validation.'
331 fShaderId: 'fshaderLastCaseHasConstantStatement',
332 fShaderSuccess: true,
333 linkSuccess: true,
334 passMsg: 'Constant statement should count as a statement for the purposes of switch statement validation.'
337 fShaderId: 'fshaderLastCaseHasEmptyStatement',
338 fShaderSuccess: true,
339 linkSuccess: true,
340 passMsg: 'Empty statement should count as a statement for the purposes of switch statement validation.'
343 fShaderId: 'fshaderCaseInsideBlock',
344 fShaderSuccess: false,
345 passMsg: 'Case statements must not be nested inside blocks.'
347 ], 2);
348 </script>
349 </body>
350 </html>