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.
11 <meta charset=
"utf-8">
12 <title>Unary minus operator on int or uint variables in a dynamic loop in vertex shader should work
</title>
13 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
14 <script src=
"../../js/js-test-pre.js"></script>
15 <script src=
"../../js/webgl-test-utils.js"></script>
19 <canvas id=
"canvas" style=
"border: none;" width=
"1024" height=
"128"></canvas>
20 <div id=
"description"></div>
21 <div id=
"console"></div>
23 <script id=
"shader-vs-int" type=
"x-shader/x-vertex">#version
300 es
30 out mediump vec4 v_color;
33 array[
0] = u_one; // array[
0] should be
1
34 array[
1] = -u_two; // array[
1] should be -
2
35 array[
2] = u_three; // array[
2] should be
3
37 for (int i =
0; i < u_three; i++) {
40 v_color = (result ==
2) ? vec4(
0,
1,
0,
1) : vec4(
1,
0,
0,
1);
45 <script id=
"shader-vs-uint" type=
"x-shader/x-vertex">#version
300 es
52 out mediump vec4 v_color;
55 array[
0] = u_one; // array[
0] should be
1u
56 array[
1] = -u_two; // array[
1] should be -
2u
57 array[
2] = u_three; // array[
2] should be
3u
59 for (uint i =
0u; i < u_three; i++) {
62 v_color = (result ==
2u) ? vec4(
0,
1,
0,
1) : vec4(
1,
0,
0,
1);
67 <script id=
"shader-vs-int-multiple-brackets" type=
"x-shader/x-vertex">#version
300 es
74 out mediump vec4 v_color;
77 array[
0] = u_one; // array[
0] should be
1
78 array[
1] = -(-(-u_two +
1) +
1); // array[
1] should be -
2
79 array[
2] = u_three; // array[
2] should be
3
81 for (int i =
0; i < u_three; i++) {
84 v_color = (result ==
2) ? vec4(
0,
1,
0,
1) : vec4(
1,
0,
0,
1);
89 <script id=
"shader-vs-uint-multiple-brackets" type=
"x-shader/x-vertex">#version
300 es
96 out mediump vec4 v_color;
99 array[
0] = u_one; // array[
0] should be
1u
100 array[
1] = -(-(-u_two +
1u) +
1u); // array[
1] should be -
2u
101 array[
2] = u_three; // array[
2] should be
3u
103 for (uint i =
0u; i < u_three; i++) {
106 v_color = (result ==
2u) ? vec4(
0,
1,
0,
1) : vec4(
1,
0,
0,
1);
111 <script id=
"shader-vs-int-implicit-unary-minus" type=
"x-shader/x-vertex">#version
300 es
118 out mediump vec4 v_color;
121 array[
0] = u_one; // array[
0] should be
1
122 array[
1] =
1 - u_two;
123 array[
2] = u_three; // array[
2] should be
3
125 array[
1] -=
1; // array[
1] should be -u_two == -
2
126 for (int i =
0; i < u_three; i++) {
129 v_color = (result ==
2) ? vec4(
0,
1,
0,
1) : vec4(
1,
0,
0,
1);
134 <script id=
"shader-vs-uint-implicit-unary-minus" type=
"x-shader/x-vertex">#version
300 es
139 uniform uint u_three;
141 out mediump vec4 v_color;
144 array[
0] = u_one; // array[
0] should be
1u
145 array[
1] =
1u - u_two;
146 array[
2] = u_three; // array[
2] should be
3u
148 array[
1] -=
1u; // array[
1] should be -u_two == -
2u
149 for (uint i =
0u; i < u_three; i++) {
152 v_color = (result ==
2u) ? vec4(
0,
1,
0,
1) : vec4(
1,
0,
0,
1);
157 <script id=
"shader-fs" type=
"x-shader/x-fragment">#version
300 es
158 in mediump vec4 v_color;
159 out mediump vec4 o_color;
171 debug("This test exposes an Intel driver bug on Windows.");
174 var wtu
= WebGLTestUtils
;
175 var gl
= wtu
.create3DContext("canvas", undefined, 2);
177 testFailed("WebGL 2 context does not exist");
182 var border
= 10; // border between test squares for visibility
183 var squareSize
= 128;
184 var expectedColor
= [0, 255, 0, 255]; // green
186 function subTest_int(message
, VertexShader
) {
188 var startX
= (squareSize
+ border
) * testNum
;
189 var program
= wtu
.setupProgram(
190 gl
, [VertexShader
, "shader-fs"], ["pos"], null, true);
191 gl
.viewport(startX
, 0, squareSize
, squareSize
);
193 var one
= gl
.getUniformLocation(program
, "u_one");
194 var two
= gl
.getUniformLocation(program
, "u_two");
195 var three
= gl
.getUniformLocation(program
, "u_three");
196 gl
.uniform1i(one
, 1);
197 gl
.uniform1i(two
, 2);
198 gl
.uniform1i(three
, 3);
200 wtu
.drawUnitQuad(gl
);
202 gl
, startX
, 0, squareSize
, squareSize
,
203 expectedColor
, "square should be green", 1);
208 function subTest_uint(message
, VertexShader
) {
210 var startX
= (squareSize
+ border
) * testNum
;
211 var program
= wtu
.setupProgram(
212 gl
, [VertexShader
, "shader-fs"], ["pos"], null, true);
213 gl
.viewport(startX
, 0, squareSize
, squareSize
);
215 var one
= gl
.getUniformLocation(program
, "u_one");
216 var two
= gl
.getUniformLocation(program
, "u_two");
217 var three
= gl
.getUniformLocation(program
, "u_three");
218 gl
.uniform1ui(one
, 1);
219 gl
.uniform1ui(two
, 2);
220 gl
.uniform1ui(three
, 3);
222 wtu
.drawUnitQuad(gl
);
224 gl
, startX
, 0, squareSize
, squareSize
,
225 expectedColor
, "square should be green", 1);
231 testFailed("context does not exist");
233 wtu
.setupUnitQuad(gl
);
234 subTest_int("Test unary minus operator on int.", "shader-vs-int");
235 subTest_uint("Test unary minus operator on unsigned int.", "shader-vs-uint");
236 subTest_int("Test unary minus operator on int with multiple brackets.", "shader-vs-int-multiple-brackets");
237 subTest_uint("Test unary minus operator on unsigned int with multiple brackets.", "shader-vs-uint-multiple-brackets");
238 subTest_int("Test implicit unary minus operator on int.", "shader-vs-int-implicit-unary-minus");
239 subTest_uint("Test implicit unary minus operator on unsigned int.", "shader-vs-uint-implicit-unary-minus");
244 var successfullyParsed
= true;