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>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>
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;
29 my_FragColor = vec4(
1,
0,
0,
1);
35 my_FragColor = vec4(
0, i[
0],
0,
1);
39 <script id=
"fshaderDeclarationInsideSwitchDefault" type=
"x-shader/x-fragment">#version
300 es
41 precision highp float;
42 out vec4 my_FragColor;
48 my_FragColor = vec4(
1,
0,
0,
1);
54 my_FragColor = vec4(
0, i[
0],
0,
1);
58 <script id=
"fshaderDeclarationInsideSwitchLiteral" type=
"x-shader/x-fragment">#version
300 es
60 precision highp float;
61 out vec4 my_FragColor;
65 my_FragColor = vec4(
1,
0,
0,
1);
71 my_FragColor = vec4(
0, i[
0],
0,
1);
75 <script id=
"fshaderDeclarationInsideSwitchLiteralDefault" type=
"x-shader/x-fragment">#version
300 es
77 precision highp float;
78 out vec4 my_FragColor;
82 my_FragColor = vec4(
1,
0,
0,
1);
88 my_FragColor = vec4(
0, i[
0],
0,
1);
92 <script id=
"fshaderDeclarationInsideSwitchScope" type=
"x-shader/x-fragment">#version
300 es
94 precision highp float;
95 out vec4 my_FragColor;
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.
105 my_FragColor = vec4(
1,
0,
0,
1);
112 my_FragColor = vec4(
0, i[
0],
0,
1);
116 <script id=
"fshaderFallThroughAll" type=
"x-shader/x-fragment">#version
300 es
118 precision highp float;
120 out vec4 my_FragColor;
127 // switch should fall through both cases.
137 my_FragColor = vec4(
0,
1,
0,
1);
141 my_FragColor = vec4(
1,
0,
0,
1);
145 <script id=
"fshaderEmptySwitchStatement" type=
"x-shader/x-fragment">#version
300 es
147 precision highp float;
149 out vec4 my_FragColor;
158 my_FragColor = vec4(
0,
1,
0,
1);
161 <script id=
"fshaderLastCaseHasEmptyDeclaration" type=
"x-shader/x-fragment">#version
300 es
163 precision highp float;
165 out vec4 my_FragColor;
171 // Empty declaration should count as a statement.
177 my_FragColor = vec4(
0,
1,
0,
1);
180 <script id=
"fshaderLastCaseHasEmptyBlock" type=
"x-shader/x-fragment">#version
300 es
182 precision highp float;
184 out vec4 my_FragColor;
190 // Empty block should count as a statement.
196 my_FragColor = vec4(
0,
1,
0,
1);
199 <script id=
"fshaderLastCaseHasConstantStatement" type=
"x-shader/x-fragment">#version
300 es
201 precision highp float;
203 out vec4 my_FragColor;
209 // Empty statement should count as a statement.
215 my_FragColor = vec4(
0,
1,
0,
1);
218 <script id=
"fshaderLastCaseHasEmptyStatement" type=
"x-shader/x-fragment">#version
300 es
220 precision highp float;
222 out vec4 my_FragColor;
228 // Empty statement should count as a statement.
234 my_FragColor = vec4(
0,
1,
0,
1);
237 <script id=
"fshaderCaseInsideBlock" type=
"x-shader/x-fragment">#version
300 es
239 precision highp float;
241 out vec4 my_FragColor;
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.
254 my_FragColor = vec4(
1,
0,
0,
1);
257 my_FragColor = vec4(
0,
1,
0,
1);
260 <script type=
"application/javascript">
265 // http://anglebug.com/
2177
266 // http://anglebug.com/
2178
267 // http://anglebug.com/
2179
269 GLSLConformanceTester.runTests([
271 fShaderId: 'fshaderDeclarationInsideSwitch',
272 fShaderSuccess: true,
274 passMsg: 'Declaration inside switch should work.',
278 fShaderId: 'fshaderDeclarationInsideSwitchDefault',
279 fShaderSuccess: true,
281 passMsg: 'Declaration inside switch default case should work.',
285 fShaderId: 'fshaderDeclarationInsideSwitchLiteral',
286 fShaderSuccess: true,
288 passMsg: 'Declaration inside switch with literal value should work.',
292 fShaderId: 'fshaderDeclarationInsideSwitchLiteralDefault',
293 fShaderSuccess: true,
295 passMsg: 'Declaration inside switch with literal value and default case should work.',
299 fShaderId: 'fshaderDeclarationInsideSwitchScope',
300 fShaderSuccess: true,
302 passMsg: 'Declaration inside switch should be scoped until the end of the switch statement.',
306 fShaderId: 'fshaderFallThroughAll',
307 fShaderSuccess: true,
309 passMsg: 'Falling through all cases in switch/case should work.',
313 fShaderId: 'fshaderEmptySwitchStatement',
314 fShaderSuccess: true,
316 passMsg: 'Empty switch statements are valid.'
319 fShaderId: 'fshaderLastCaseHasEmptyDeclaration',
320 fShaderSuccess: true,
322 passMsg: 'Empty declaration should count as a statement for the purposes of switch statement validation.'
325 fShaderId: 'fshaderLastCaseHasEmptyBlock',
326 fShaderSuccess: true,
328 passMsg: 'Empty block should count as a statement for the purposes of switch statement validation.'
331 fShaderId: 'fshaderLastCaseHasConstantStatement',
332 fShaderSuccess: true,
334 passMsg: 'Constant statement should count as a statement for the purposes of switch statement validation.'
337 fShaderId: 'fshaderLastCaseHasEmptyStatement',
338 fShaderSuccess: 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.'