summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/glsl3/unary-minus-operator-in-dynamic-loop.html
blob: f43cc4f3d5e46efb5033812390bcad72d647d070 (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
<!--

/*
** Copyright (c) 2016 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/

-->

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Unary minus operator on int or uint variables in a dynamic loop in vertex shader should work</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>
</head>

<body>
<canvas id="canvas" style="border: none;" width="1024" height="128"></canvas>
<div id="description"></div>
<div id="console"></div>

<script id="shader-vs-int" type="x-shader/x-vertex">#version 300 es
in highp vec4 pos;

uniform int u_one;
uniform int u_two;
uniform int u_three;

out mediump vec4 v_color;
void main() {
  int array[3];
  array[0] = u_one; // array[0] should be 1
  array[1] = -u_two; // array[1] should be -2
  array[2] = u_three; // array[2] should be 3
  int result = 0;
  for (int i = 0; i < u_three; i++) {
    result += array[i];
  }
  v_color = (result == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
  gl_Position = pos;
}
</script>

<script id="shader-vs-uint" type="x-shader/x-vertex">#version 300 es
in highp vec4 pos;

uniform uint u_one;
uniform uint u_two;
uniform uint u_three;

out mediump vec4 v_color;
void main() {
  uint array[3];
  array[0] = u_one; // array[0] should be 1u
  array[1] = -u_two; // array[1] should be -2u
  array[2] = u_three; // array[2] should be 3u
  uint result = 0u;
  for (uint i = 0u; i < u_three; i++) {
    result += array[i];
  }
  v_color = (result == 2u) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
  gl_Position = pos;
}
</script>

<script id="shader-vs-int-multiple-brackets" type="x-shader/x-vertex">#version 300 es
in highp vec4 pos;

uniform int u_one;
uniform int u_two;
uniform int u_three;

out mediump vec4 v_color;
void main() {
  int array[3];
  array[0] = u_one; // array[0] should be 1
  array[1] = -(-(-u_two + 1) + 1); // array[1] should be -2
  array[2] = u_three; // array[2] should be 3
  int result = 0;
  for (int i = 0; i < u_three; i++) {
    result += array[i];
  }
  v_color = (result == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
  gl_Position = pos;
}
</script>

<script id="shader-vs-uint-multiple-brackets" type="x-shader/x-vertex">#version 300 es
in highp vec4 pos;

uniform uint u_one;
uniform uint u_two;
uniform uint u_three;

out mediump vec4 v_color;
void main() {
  uint array[3];
  array[0] = u_one; // array[0] should be 1u
  array[1] = -(-(-u_two + 1u) + 1u); // array[1] should be -2u
  array[2] = u_three; // array[2] should be 3u
  uint result = 0u;
  for (uint i = 0u; i < u_three; i++) {
    result += array[i];
  }
  v_color = (result == 2u) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
  gl_Position = pos;
}
</script>

<script id="shader-vs-int-implicit-unary-minus" type="x-shader/x-vertex">#version 300 es
in highp vec4 pos;

uniform int u_one;
uniform int u_two;
uniform int u_three;

out mediump vec4 v_color;
void main() {
  int array[3];
  array[0] = u_one; // array[0] should be 1
  array[1] = 1 - u_two;
  array[2] = u_three; // array[2] should be 3
  int result = 0;
  array[1] -= 1; // array[1] should be -u_two == -2
  for (int i = 0; i < u_three; i++) {
    result += array[i];
  }
  v_color = (result == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
  gl_Position = pos;
}
</script>

<script id="shader-vs-uint-implicit-unary-minus" type="x-shader/x-vertex">#version 300 es
in highp vec4 pos;

uniform uint u_one;
uniform uint u_two;
uniform uint u_three;

out mediump vec4 v_color;
void main() {
  uint array[3];
  array[0] = u_one; // array[0] should be 1u
  array[1] = 1u - u_two;
  array[2] = u_three; // array[2] should be 3u
  uint result = 0u;
  array[1] -= 1u; // array[1] should be -u_two == -2u
  for (uint i = 0u; i < u_three; i++) {
    result += array[i];
  }
  v_color = (result == 2u) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
  gl_Position = pos;
}
</script>

<script id="shader-fs" type="x-shader/x-fragment">#version 300 es
in mediump vec4 v_color;
out mediump vec4 o_color;

void main() {
  o_color = v_color;
}
</script>

<script>
"use strict";

function test() {
  description();
  debug("This test exposes an Intel driver bug on Windows.");
  debug("");

  var wtu = WebGLTestUtils;
  var gl = wtu.create3DContext("canvas", undefined, 2);
  if (!gl) {
    testFailed("WebGL 2 context does not exist");
    return;
  }

  var testNum = 0;
  var border = 10; // border between test squares for visibility
  var squareSize = 128;
  var expectedColor = [0, 255, 0, 255]; // green

  function subTest_int(message, VertexShader) {
    debug(message);
    var startX = (squareSize + border) * testNum;
    var program = wtu.setupProgram(
      gl, [VertexShader, "shader-fs"], ["pos"], null, true);
    gl.viewport(startX, 0, squareSize, squareSize);

    var one = gl.getUniformLocation(program, "u_one");
    var two = gl.getUniformLocation(program, "u_two");
    var three = gl.getUniformLocation(program, "u_three");
    gl.uniform1i(one, 1);
    gl.uniform1i(two, 2);
    gl.uniform1i(three, 3);

    wtu.drawUnitQuad(gl);
    wtu.checkCanvasRect(
      gl, startX, 0, squareSize, squareSize,
      expectedColor, "square should be green", 1);
    debug("");
    testNum++;
  }

  function subTest_uint(message, VertexShader) {
    debug(message);
    var startX = (squareSize + border) * testNum;
    var program = wtu.setupProgram(
      gl, [VertexShader, "shader-fs"], ["pos"], null, true);
    gl.viewport(startX, 0, squareSize, squareSize);

    var one = gl.getUniformLocation(program, "u_one");
    var two = gl.getUniformLocation(program, "u_two");
    var three = gl.getUniformLocation(program, "u_three");
    gl.uniform1ui(one, 1);
    gl.uniform1ui(two, 2);
    gl.uniform1ui(three, 3);

    wtu.drawUnitQuad(gl);
    wtu.checkCanvasRect(
      gl, startX, 0, squareSize, squareSize,
      expectedColor, "square should be green", 1);
    debug("");
    testNum++;
  }

  if (!gl) {
    testFailed("context does not exist");
  } else {
    wtu.setupUnitQuad(gl);
    subTest_int("Test unary minus operator on int.", "shader-vs-int");
    subTest_uint("Test unary minus operator on unsigned int.", "shader-vs-uint");
    subTest_int("Test unary minus operator on int with multiple brackets.", "shader-vs-int-multiple-brackets");
    subTest_uint("Test unary minus operator on unsigned int with multiple brackets.", "shader-vs-uint-multiple-brackets");
    subTest_int("Test implicit unary minus operator on int.", "shader-vs-int-implicit-unary-minus");
    subTest_uint("Test implicit unary minus operator on unsigned int.", "shader-vs-uint-implicit-unary-minus");
  }
}

test();
var successfullyParsed = true;
finishTest();
</script>
</body>
</html>