tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

conditional-discard-in-loop.html (4121B)


      1 <!--
      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.
      5 -->
      6 
      7 
      8 <!DOCTYPE html>
      9 <html>
     10 <head>
     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>
     16 </head>
     17 
     18 <body>
     19 <canvas id="output" style="border: none;" width="256" height="256"></canvas>
     20 <div id="description"></div>
     21 <div id="console"></div>
     22 
     23 <script id="shader-vs" type="x-shader/x-vertex">
     24 // Inputs
     25 attribute vec4 a_position;
     26 attribute vec2 a_tex_coords;
     27 
     28 // Output
     29 varying vec2   v_tex_coords;
     30 
     31 void main(void) {
     32    v_tex_coords = a_tex_coords;
     33    gl_Position  = a_position;
     34 }
     35 </script>
     36 
     37 <script id="shader-fs" type="x-shader/x-fragment">
     38 precision mediump float;
     39 
     40 // Constants
     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;
     44 
     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);
     47 
     48 // Input
     49 varying vec2 v_tex_coords;
     50 
     51 uniform sampler2D u_data;
     52 
     53 // Without this function or directly returning the data, the issue does not occur
     54 mediump vec4 UnpackData(in vec4 inData) {
     55     float s = inData.x;
     56     // Note s is always 0
     57     // mod(0, 1) = 0
     58     // So return value = (0, 0, -1, 0)
     59    return vec4(0.0, 0.0, mod(s, 1.0) - 1.0, 0.0);
     60 
     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);
     63 }
     64 
     65 void main(void) {
     66     // Set initial color
     67    gl_FragColor = BLUE;
     68 
     69    if (gl_FragCoord.y <= SEP_IX) {
     70        mediump vec2 addr = vec2(v_tex_coords.x, TEXEL_HEIGHT);
     71 
     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);
     75 
     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) {
     79                discard;
     80            }
     81 
     82            addr.y += unpack.z * TEXEL_HEIGHT;
     83        }
     84        // If discard is not triggered the output color is blue
     85    }
     86    else {
     87        gl_FragColor = GREEN;
     88    }
     89 }
     90 </script>
     91 
     92 
     93 <script>
     94 "use strict";
     95 
     96 description();
     97 debug("");
     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");
    100 
    101 var wtu = WebGLTestUtils;
    102 var canvas = document.getElementById("output");
    103 var gl = wtu.create3DContext(canvas);
    104 if (!gl) {
    105  testFailed("context does not exist");
    106 } else {
    107 
    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]);
    116 
    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);
    120 
    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);
    123 
    124  // Bind texture
    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);
    129 
    130  // Draw
    131  wtu.drawUnitQuad(gl);
    132 
    133  // Verify output
    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);
    136 }
    137 
    138 var successfullyParsed = true;
    139 </script>
    140 <script src="../../../js/js-test-post.js"></script>
    141 </body>
    142 </html>