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