Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / glsl3 / vector-dynamic-indexing.html
blob5bf60578ad419909af011e01ec0a5d9c4b94c5f0
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 dynamic vector and matrix indexing 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="fshaderIndexMatrixTwice" type="x-shader/x-fragment">#version 300 es
21 precision mediump float;
23 out vec4 my_FragColor;
25 uniform int u_zero;
27 void main() {
28 mat2 m = mat2(0.0, 0.0, 0.0, 1.0);
29 float f = m[u_zero + 1][u_zero + 1];
30 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
32 </script>
33 <script id="fshaderIndexWithValueFromIndexingExpression" type="x-shader/x-fragment">#version 300 es
34 precision mediump float;
36 out vec4 my_FragColor;
38 uniform int u_zero;
40 void main() {
41 ivec2 i = ivec2(0, 2);
42 vec4 v = vec4(0.0, 0.2, 1.0, 0.4);
43 float f = v[i[u_zero + 1]];
44 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
46 </script>
47 <script id="fshaderIndexLValue" type="x-shader/x-fragment">#version 300 es
48 precision mediump float;
50 out vec4 my_FragColor;
52 uniform int u_zero;
54 void main() {
55 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
56 v[u_zero + 1] = 5.0;
57 vec4 expected = vec4(1.0, 5.0, 3.0, 4.0);
58 float f = 1.0 - distance(v, expected);
59 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
61 </script>
62 <script id="fshaderIndexLValueWithValueFromIndexingExpression" type="x-shader/x-fragment">#version 300 es
63 precision mediump float;
65 out vec4 my_FragColor;
67 uniform int u_zero;
69 void main() {
70 ivec2 i = ivec2(0, 2);
71 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
72 v[i[u_zero + 1]] = 5.0;
73 vec4 expected = vec4(1.0, 2.0, 5.0, 4.0);
74 float f = 1.0 - distance(v, expected);
75 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
77 </script>
78 <script id="fshaderIndexBuiltInFunctionCallOutParameter" type="x-shader/x-fragment">#version 300 es
79 precision mediump float;
81 out vec4 my_FragColor;
83 uniform int u_zero;
85 void main() {
86 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
87 modf(5.5, v[u_zero + 3]);
88 vec4 expected = vec4(1.0, 2.0, 3.0, 5.0);
89 float f = 1.0 - distance(v, expected);
90 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
92 </script>
93 <script id="fshaderIndexUserDefinedFunctionCallOutParameter" type="x-shader/x-fragment">#version 300 es
94 precision mediump float;
96 out vec4 my_FragColor;
98 uniform int u_zero;
100 void foo(out float f) {
101 modf(5.5, f);
104 void main() {
105 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
106 foo(v[u_zero + 3]);
107 vec4 expected = vec4(1.0, 2.0, 3.0, 5.0);
108 float f = 1.0 - distance(v, expected);
109 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
111 </script>
112 <script id="fshaderIndexUserDefinedFunctionCallInOutParameter" type="x-shader/x-fragment">#version 300 es
113 precision mediump float;
115 out vec4 my_FragColor;
117 uniform int u_zero;
119 void foo(inout float f) {
120 float g = f + 2.5;
121 modf(g, f);
124 void main() {
125 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
126 foo(v[u_zero + 2]);
127 vec4 expected = vec4(1.0, 2.0, 5.0, 4.0);
128 float f = 1.0 - distance(v, expected);
129 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
131 </script>
132 <script id="fshaderIndexWithSideEffects" type="x-shader/x-fragment">#version 300 es
133 precision mediump float;
135 out vec4 my_FragColor;
137 uniform int u_zero;
139 int sideEffectCounter = 0;
141 int funcWithSideEffects() {
142 sideEffectCounter++;
143 return 2;
146 void main() {
147 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
148 v[funcWithSideEffects()] = 5.0;
149 vec4 expected = vec4(1.0, 2.0, 5.0, 4.0);
150 float f = 1.0 - distance(v, expected);
151 if (sideEffectCounter != 1) {
152 f = 0.0;
154 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
156 </script>
157 <script id="fshaderIndexInOutWithSideEffects" type="x-shader/x-fragment">#version 300 es
158 precision mediump float;
160 out vec4 my_FragColor;
162 uniform int u_zero;
164 int sideEffectCounter = 0;
166 int funcWithSideEffects() {
167 sideEffectCounter++;
168 return 2;
171 void main() {
172 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
173 v[funcWithSideEffects()]++;
174 vec4 expected = vec4(1.0, 2.0, 4.0, 4.0);
175 float f = 1.0 - distance(v, expected);
176 if (sideEffectCounter != 1) {
177 f = 0.0;
179 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
181 </script>
182 <script id="fshaderIndexUserDefinedFunctionCallInOutParameterWithIndexWithSideEffects" type="x-shader/x-fragment">#version 300 es
183 precision mediump float;
185 out vec4 my_FragColor;
187 uniform int u_zero;
189 int sideEffectCounter = 0;
191 void foo(inout float f) {
192 float g = f + 2.5;
193 modf(g, f);
196 int funcWithSideEffects() {
197 sideEffectCounter++;
198 return 2;
201 void main() {
202 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
203 foo(v[funcWithSideEffects()]);
204 vec4 expected = vec4(1.0, 2.0, 5.0, 4.0);
205 float f = 1.0 - distance(v, expected);
206 if (sideEffectCounter != 1) {
207 f = 0.0;
209 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
211 </script>
212 <script id="fshaderIndexLValueWithUint" type="x-shader/x-fragment">#version 300 es
213 precision mediump float;
215 out vec4 my_FragColor;
217 uniform uint u_zero;
219 void main() {
220 vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
221 v[u_zero] = 5.0;
222 vec4 expected = vec4(5.0, 2.0, 3.0, 4.0);
223 float f = 1.0 - distance(v, expected);
224 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
226 </script>
227 <script id="fshaderIndexUniform" type="x-shader/x-fragment">#version 300 es
228 precision mediump float;
230 out vec4 my_FragColor;
232 uniform vec4 u_zeroVec;
233 uniform uint u_zero;
235 void main() {
236 // This test is just to catch a crash bug that occurred in ANGLE's workaround.
237 // Rendering result is not meaningful.
238 float f = u_zeroVec[u_zero];
239 my_FragColor = vec4(f, 1.0, 0.0, 1.0);
241 </script>
242 <script id="fshaderSequenceDynamicIndexingVectorLvalue" type="x-shader/x-fragment">#version 300 es
243 precision mediump float;
245 out vec4 my_FragColor;
246 uniform int u_zero;
248 int sideEffectCounter = 0;
249 float func() {
250 ++sideEffectCounter;
251 return -1.0;
254 void main() {
255 vec4 v = vec4(0.0, 2.0, 4.0, 6.0);
256 float f = (func(), (++v[u_zero + sideEffectCounter]));
257 my_FragColor = (abs(f - 3.0) < 0.01 && abs(v[1] - 3.0) < 0.01 && sideEffectCounter == 1) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
259 </script>
260 <script id="fshaderIndexMatrixTwiceInLValue" type="x-shader/x-fragment">#version 300 es
261 precision mediump float;
263 out vec4 my_FragColor;
265 uniform int u_zero;
267 void main() {
268 mat2 m = mat2(0.0, 0.0, 0.0, 0.0);
269 m[u_zero + 1][u_zero + 1] = float(u_zero + 1);
270 float f = m[1][1];
271 my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
273 </script>
274 <script type="application/javascript">
275 "use strict";
276 description("Dynamic indexing of vectors and matrices should work.");
278 debug("Dynamic indexing of vectors and matrices requires complex workarounds on HLSL backends. Try to test possible bugs those workarounds might have.");
280 GLSLConformanceTester.runRenderTests([
282 fShaderId: 'fshaderIndexMatrixTwice',
283 fShaderSuccess: true,
284 linkSuccess: true,
285 passMsg: 'Index matrix and then index the resulting vector in the same expression'
288 fShaderId: 'fshaderIndexWithValueFromIndexingExpression',
289 fShaderSuccess: true,
290 linkSuccess: true,
291 passMsg: 'Index a vector with an index that is the result of indexing'
294 fShaderId: 'fshaderIndexLValue',
295 fShaderSuccess: true,
296 linkSuccess: true,
297 passMsg: 'Index on the left-hand side of assignment'
300 fShaderId: 'fshaderIndexLValueWithValueFromIndexingExpression',
301 fShaderSuccess: true,
302 linkSuccess: true,
303 passMsg: 'Index on the left-hand side of assignment with an index that is the result of indexing'
306 fShaderId: 'fshaderIndexBuiltInFunctionCallOutParameter',
307 fShaderSuccess: true,
308 linkSuccess: true,
309 passMsg: 'Index the out parameter passed to built-in modf'
312 fShaderId: 'fshaderIndexUserDefinedFunctionCallOutParameter',
313 fShaderSuccess: true,
314 linkSuccess: true,
315 passMsg: 'Index an out parameter passed to an user-defined function'
318 fShaderId: 'fshaderIndexUserDefinedFunctionCallInOutParameter',
319 fShaderSuccess: true,
320 linkSuccess: true,
321 passMsg: 'Index an inout parameter passed to an user-defined function'
324 fShaderId: 'fshaderIndexWithSideEffects',
325 fShaderSuccess: true,
326 linkSuccess: true,
327 passMsg: 'Use expression with side effects as an index of an l-value'
330 fShaderId: 'fshaderIndexInOutWithSideEffects',
331 fShaderSuccess: true,
332 linkSuccess: true,
333 passMsg: 'Use expression with side effects as an index of an l-value that is both read and written'
336 fShaderId: 'fshaderIndexUserDefinedFunctionCallInOutParameterWithIndexWithSideEffects',
337 fShaderSuccess: true,
338 linkSuccess: true,
339 passMsg: 'Index an inout parameter passed to an user-defined function with an index with side effects'
342 fShaderId: 'fshaderIndexLValueWithUint',
343 fShaderSuccess: true,
344 linkSuccess: true,
345 passMsg: 'Index on the left-hand side of assignment with an uint'
348 fShaderId: 'fshaderIndexUniform',
349 fShaderSuccess: true,
350 linkSuccess: true,
351 passMsg: 'Index a uniform with a uniform'
354 fShaderId: 'fshaderSequenceDynamicIndexingVectorLvalue',
355 fShaderSuccess: true,
356 linkSuccess: true,
357 passMsg: 'Sequence operator with dynamic indexing of a vector as an l-value inside'
360 fShaderId: 'fshaderIndexMatrixTwiceInLValue',
361 fShaderSuccess: true,
362 linkSuccess: true,
363 passMsg: 'Index matrix and then index the resulting vector in the same expression inside an l-value'
365 ], 2);
366 </script>
367 </body>
368 </html>