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 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>
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;
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);
33 <script id=
"fshaderIndexWithValueFromIndexingExpression" type=
"x-shader/x-fragment">#version
300 es
34 precision mediump float;
36 out vec4 my_FragColor;
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);
47 <script id=
"fshaderIndexLValue" type=
"x-shader/x-fragment">#version
300 es
48 precision mediump float;
50 out vec4 my_FragColor;
55 vec4 v = vec4(
1.0,
2.0,
3.0,
4.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);
62 <script id=
"fshaderIndexLValueWithValueFromIndexingExpression" type=
"x-shader/x-fragment">#version
300 es
63 precision mediump float;
65 out vec4 my_FragColor;
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);
78 <script id=
"fshaderIndexBuiltInFunctionCallOutParameter" type=
"x-shader/x-fragment">#version
300 es
79 precision mediump float;
81 out vec4 my_FragColor;
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);
93 <script id=
"fshaderIndexUserDefinedFunctionCallOutParameter" type=
"x-shader/x-fragment">#version
300 es
94 precision mediump float;
96 out vec4 my_FragColor;
100 void foo(out float f) {
105 vec4 v = vec4(
1.0,
2.0,
3.0,
4.0);
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);
112 <script id=
"fshaderIndexUserDefinedFunctionCallInOutParameter" type=
"x-shader/x-fragment">#version
300 es
113 precision mediump float;
115 out vec4 my_FragColor;
119 void foo(inout float f) {
125 vec4 v = vec4(
1.0,
2.0,
3.0,
4.0);
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);
132 <script id=
"fshaderIndexWithSideEffects" type=
"x-shader/x-fragment">#version
300 es
133 precision mediump float;
135 out vec4 my_FragColor;
139 int sideEffectCounter =
0;
141 int funcWithSideEffects() {
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) {
154 my_FragColor = vec4(
1.0 - f, f,
0.0,
1.0);
157 <script id=
"fshaderIndexInOutWithSideEffects" type=
"x-shader/x-fragment">#version
300 es
158 precision mediump float;
160 out vec4 my_FragColor;
164 int sideEffectCounter =
0;
166 int funcWithSideEffects() {
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) {
179 my_FragColor = vec4(
1.0 - f, f,
0.0,
1.0);
182 <script id=
"fshaderIndexUserDefinedFunctionCallInOutParameterWithIndexWithSideEffects" type=
"x-shader/x-fragment">#version
300 es
183 precision mediump float;
185 out vec4 my_FragColor;
189 int sideEffectCounter =
0;
191 void foo(inout float f) {
196 int funcWithSideEffects() {
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) {
209 my_FragColor = vec4(
1.0 - f, f,
0.0,
1.0);
212 <script id=
"fshaderIndexLValueWithUint" type=
"x-shader/x-fragment">#version
300 es
213 precision mediump float;
215 out vec4 my_FragColor;
220 vec4 v = vec4(
1.0,
2.0,
3.0,
4.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);
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;
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);
242 <script id=
"fshaderSequenceDynamicIndexingVectorLvalue" type=
"x-shader/x-fragment">#version
300 es
243 precision mediump float;
245 out vec4 my_FragColor;
248 int sideEffectCounter =
0;
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);
260 <script id=
"fshaderIndexMatrixTwiceInLValue" type=
"x-shader/x-fragment">#version
300 es
261 precision mediump float;
263 out vec4 my_FragColor;
268 mat2 m = mat2(
0.0,
0.0,
0.0,
0.0);
269 m[u_zero +
1][u_zero +
1] = float(u_zero +
1);
271 my_FragColor = vec4(
1.0 - f, f,
0.0,
1.0);
274 <script type=
"application/javascript">
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,
285 passMsg: 'Index matrix and then index the resulting vector in the same expression'
288 fShaderId: 'fshaderIndexWithValueFromIndexingExpression',
289 fShaderSuccess: true,
291 passMsg: 'Index a vector with an index that is the result of indexing'
294 fShaderId: 'fshaderIndexLValue',
295 fShaderSuccess: true,
297 passMsg: 'Index on the left-hand side of assignment'
300 fShaderId: 'fshaderIndexLValueWithValueFromIndexingExpression',
301 fShaderSuccess: 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,
309 passMsg: 'Index the out parameter passed to built-in modf'
312 fShaderId: 'fshaderIndexUserDefinedFunctionCallOutParameter',
313 fShaderSuccess: true,
315 passMsg: 'Index an out parameter passed to an user-defined function'
318 fShaderId: 'fshaderIndexUserDefinedFunctionCallInOutParameter',
319 fShaderSuccess: true,
321 passMsg: 'Index an inout parameter passed to an user-defined function'
324 fShaderId: 'fshaderIndexWithSideEffects',
325 fShaderSuccess: true,
327 passMsg: 'Use expression with side effects as an index of an l-value'
330 fShaderId: 'fshaderIndexInOutWithSideEffects',
331 fShaderSuccess: 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,
339 passMsg: 'Index an inout parameter passed to an user-defined function with an index with side effects'
342 fShaderId: 'fshaderIndexLValueWithUint',
343 fShaderSuccess: true,
345 passMsg: 'Index on the left-hand side of assignment with an uint'
348 fShaderId: 'fshaderIndexUniform',
349 fShaderSuccess: true,
351 passMsg: 'Index a uniform with a uniform'
354 fShaderId: 'fshaderSequenceDynamicIndexingVectorLvalue',
355 fShaderSuccess: true,
357 passMsg: 'Sequence operator with dynamic indexing of a vector as an l-value inside'
360 fShaderId: 'fshaderIndexMatrixTwiceInLValue',
361 fShaderSuccess: true,
363 passMsg: 'Index matrix and then index the resulting vector in the same expression inside an l-value'