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>Conditional discard in loop issue
</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=
"output" style=
"border: none;" width=
"256" height=
"256"></canvas>
20 <div id=
"description"></div>
21 <div id=
"console"></div>
23 <script id=
"shader-vs" type=
"x-shader/x-vertex">
25 attribute vec4 a_position;
26 attribute vec2 a_tex_coords;
29 varying vec2 v_tex_coords;
32 v_tex_coords = a_tex_coords;
33 gl_Position = a_position;
37 <script id=
"shader-fs" type=
"x-shader/x-fragment">
38 precision mediump float;
41 const float TEXEL_COUNT_V =
256.0;
42 const float TEXEL_HEIGHT =
1.0 / TEXEL_COUNT_V;
43 const float SEP_IX = TEXEL_COUNT_V /
2.0;
45 const vec4 GREEN = vec4(
0.0,
1.0,
0.0,
1.0);
46 const vec4 BLUE = vec4(
0.0,
0.0,
1.0,
1.0);
49 varying vec2 v_tex_coords;
51 uniform sampler2D u_data;
53 // Without this function or directly returning the data, the issue does not occur
54 mediump vec4 UnpackData(in vec4 inData) {
58 // So return value = (
0,
0, -
1,
0)
59 return vec4(
0.0,
0.0, mod(s,
1.0) -
1.0,
0.0);
61 // Comment out the line above and uncomment the line below and the test succeeds on angle-dx11
62 // return vec4(
0.0,
0.0, -
1.0,
0.0);
69 if (gl_FragCoord.y <= SEP_IX) {
70 mediump vec2 addr = vec2(v_tex_coords.x, TEXEL_HEIGHT);
72 for (float e_ix =
0.0; e_ix < TEXEL_COUNT_V; ++e_ix) {
73 vec4 entry = texture2D(u_data, addr);
74 mediump vec4 unpack = UnpackData(entry);
76 // Buffer is filled with
0, unpack is always (
0,
0, -
1,
0)
77 // So discard is always triggered
78 if (unpack.z == -
1.0) {
82 addr.y += unpack.z * TEXEL_HEIGHT;
84 // If discard is not triggered the output color is blue
98 debug("If the code is executed correctly, the upper half of the viewport will be green, the lower half will be red.");
99 debug("This is a conformance suite test for the issue reported here : https://code.google.com/p/angleproject/issues/detail?id=706");
101 var wtu
= WebGLTestUtils
;
102 var canvas
= document
.getElementById("output");
103 var gl
= wtu
.create3DContext(canvas
);
105 testFailed("context does not exist");
108 // Create texture filled with zero's
109 var tex
= gl
.createTexture();
110 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
111 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
112 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
113 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
114 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
115 wtu
.fillTexture(gl
, tex
, 256, 256, [0, 0, 0, 0]);
117 // Clear complete viewport to red
118 gl
.clearColor(1.0, 0.0, 0.0, 1.0);
119 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
121 var attribBuffers
= wtu
.setupUnitQuad(gl
, 0, 1);
122 var program
= wtu
.setupProgram(gl
, ["shader-vs", "shader-fs"], ["a_position", "a_tex_coords"], [0, 1], true);
125 var uniformMap
= wtu
.getUniformMap(gl
, program
);
126 gl
.activeTexture(gl
.TEXTURE0
);
127 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
128 gl
.uniform1i(uniformMap
.u_data
.location
, 0);
131 wtu
.drawUnitQuad(gl
);
134 wtu
.checkCanvasRect(gl
, 0, 0, 256, 128, [ 255, 0, 0, 255 ], "should be red", 1);
135 wtu
.checkCanvasRect(gl
, 0, 128, 256, 128, [ 0, 255, 0, 255 ], "should be green", 1);
138 var successfullyParsed
= true;
140 <script src=
"../../../js/js-test-post.js"></script>