summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/glsl3/vector-dynamic-indexing.html
blob: 5bf60578ad419909af011e01ec0a5d9c4b94c5f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GLSL dynamic vector and matrix indexing test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/glsl-conformance-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="fshaderIndexMatrixTwice" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

void main() {
    mat2 m = mat2(0.0, 0.0, 0.0, 1.0);
    float f = m[u_zero + 1][u_zero + 1];
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexWithValueFromIndexingExpression" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

void main() {
    ivec2 i = ivec2(0, 2);
    vec4 v = vec4(0.0, 0.2, 1.0, 0.4);
    float f = v[i[u_zero + 1]];
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexLValue" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

void main() {
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    v[u_zero + 1] = 5.0;
    vec4 expected = vec4(1.0, 5.0, 3.0, 4.0);
    float f = 1.0 - distance(v, expected);
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexLValueWithValueFromIndexingExpression" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

void main() {
    ivec2 i = ivec2(0, 2);
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    v[i[u_zero + 1]] = 5.0;
    vec4 expected = vec4(1.0, 2.0, 5.0, 4.0);
    float f = 1.0 - distance(v, expected);
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexBuiltInFunctionCallOutParameter" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

void main() {
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    modf(5.5, v[u_zero + 3]);
    vec4 expected = vec4(1.0, 2.0, 3.0, 5.0);
    float f = 1.0 - distance(v, expected);
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexUserDefinedFunctionCallOutParameter" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

void foo(out float f) {
    modf(5.5, f);
}

void main() {
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    foo(v[u_zero + 3]);
    vec4 expected = vec4(1.0, 2.0, 3.0, 5.0);
    float f = 1.0 - distance(v, expected);
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexUserDefinedFunctionCallInOutParameter" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

void foo(inout float f) {
    float g = f + 2.5;
    modf(g, f);
}

void main() {
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    foo(v[u_zero + 2]);
    vec4 expected = vec4(1.0, 2.0, 5.0, 4.0);
    float f = 1.0 - distance(v, expected);
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexWithSideEffects" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

int sideEffectCounter = 0;

int funcWithSideEffects() {
    sideEffectCounter++;
    return 2;
}

void main() {
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    v[funcWithSideEffects()] = 5.0;
    vec4 expected = vec4(1.0, 2.0, 5.0, 4.0);
    float f = 1.0 - distance(v, expected);
    if (sideEffectCounter != 1) {
        f = 0.0;
    }
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexInOutWithSideEffects" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

int sideEffectCounter = 0;

int funcWithSideEffects() {
    sideEffectCounter++;
    return 2;
}

void main() {
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    v[funcWithSideEffects()]++;
    vec4 expected = vec4(1.0, 2.0, 4.0, 4.0);
    float f = 1.0 - distance(v, expected);
    if (sideEffectCounter != 1) {
        f = 0.0;
    }
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexUserDefinedFunctionCallInOutParameterWithIndexWithSideEffects" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

int sideEffectCounter = 0;

void foo(inout float f) {
    float g = f + 2.5;
    modf(g, f);
}

int funcWithSideEffects() {
    sideEffectCounter++;
    return 2;
}

void main() {
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    foo(v[funcWithSideEffects()]);
    vec4 expected = vec4(1.0, 2.0, 5.0, 4.0);
    float f = 1.0 - distance(v, expected);
    if (sideEffectCounter != 1) {
        f = 0.0;
    }
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexLValueWithUint" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform uint u_zero;

void main() {
    vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
    v[u_zero] = 5.0;
    vec4 expected = vec4(5.0, 2.0, 3.0, 4.0);
    float f = 1.0 - distance(v, expected);
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script id="fshaderIndexUniform" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform vec4 u_zeroVec;
uniform uint u_zero;

void main() {
    // This test is just to catch a crash bug that occurred in ANGLE's workaround.
    // Rendering result is not meaningful.
    float f = u_zeroVec[u_zero];
    my_FragColor = vec4(f, 1.0, 0.0, 1.0);
}
</script>
<script id="fshaderSequenceDynamicIndexingVectorLvalue" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;
uniform int u_zero;

int sideEffectCounter = 0;
float func() {
    ++sideEffectCounter;
    return -1.0;
}

void main() {
    vec4 v = vec4(0.0, 2.0, 4.0, 6.0);
    float f = (func(), (++v[u_zero + sideEffectCounter]));
    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);
}
</script>
<script id="fshaderIndexMatrixTwiceInLValue" type="x-shader/x-fragment">#version 300 es
precision mediump float;

out vec4 my_FragColor;

uniform int u_zero;

void main() {
    mat2 m = mat2(0.0, 0.0, 0.0, 0.0);
    m[u_zero + 1][u_zero + 1] = float(u_zero + 1);
    float f = m[1][1];
    my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);
}
</script>
<script type="application/javascript">
"use strict";
description("Dynamic indexing of vectors and matrices should work.");

debug("Dynamic indexing of vectors and matrices requires complex workarounds on HLSL backends. Try to test possible bugs those workarounds might have.");

GLSLConformanceTester.runRenderTests([
{
  fShaderId: 'fshaderIndexMatrixTwice',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index matrix and then index the resulting vector in the same expression'
},
{
  fShaderId: 'fshaderIndexWithValueFromIndexingExpression',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index a vector with an index that is the result of indexing'
},
{
  fShaderId: 'fshaderIndexLValue',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index on the left-hand side of assignment'
},
{
  fShaderId: 'fshaderIndexLValueWithValueFromIndexingExpression',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index on the left-hand side of assignment with an index that is the result of indexing'
},
{
  fShaderId: 'fshaderIndexBuiltInFunctionCallOutParameter',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index the out parameter passed to built-in modf'
},
{
  fShaderId: 'fshaderIndexUserDefinedFunctionCallOutParameter',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index an out parameter passed to an user-defined function'
},
{
  fShaderId: 'fshaderIndexUserDefinedFunctionCallInOutParameter',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index an inout parameter passed to an user-defined function'
},
{
  fShaderId: 'fshaderIndexWithSideEffects',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Use expression with side effects as an index of an l-value'
},
{
  fShaderId: 'fshaderIndexInOutWithSideEffects',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Use expression with side effects as an index of an l-value that is both read and written'
},
{
  fShaderId: 'fshaderIndexUserDefinedFunctionCallInOutParameterWithIndexWithSideEffects',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index an inout parameter passed to an user-defined function with an index with side effects'
},
{
  fShaderId: 'fshaderIndexLValueWithUint',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index on the left-hand side of assignment with an uint'
},
{
  fShaderId: 'fshaderIndexUniform',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index a uniform with a uniform'
},
{
  fShaderId: 'fshaderSequenceDynamicIndexingVectorLvalue',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Sequence operator with dynamic indexing of a vector as an l-value inside'
},
{
  fShaderId: 'fshaderIndexMatrixTwiceInLValue',
  fShaderSuccess: true,
  linkSuccess: true,
  passMsg: 'Index matrix and then index the resulting vector in the same expression inside an l-value'
}
], 2);
</script>
</body>
</html>