tor-browser

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

pow-of-small-constant-in-user-defined-function.html (2154B)


      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 <!DOCTYPE html>
      8 <html>
      9 <head>
     10 <meta charset="utf-8">
     11 <title>Bug - calculating powers of constants smaller than 1.0e-5 in user-defined functions should work</title>
     12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     13 <script src="../../../js/js-test-pre.js"></script>
     14 <script src="../../../js/webgl-test-utils.js"></script>
     15 </head>
     16 <body>
     17 <canvas id="canvas" width="256" height="256"> </canvas>
     18 <div id="description"></div>
     19 <div id="console"></div>
     20 <script id="vshader" type="x-shader/x-vertex">
     21 attribute vec3 aPosition;
     22 
     23 void main() {
     24    gl_Position = vec4(aPosition, 1);
     25 }
     26 </script>
     27 <script id="fshader" type="x-shader/x-fragment">
     28 precision highp float;
     29 
     30 float fun(float arg) {
     31    // These values are still easily within the highp range.
     32    // The minimum range in terms of 10's exponent is around -19 to 19, and IEEE-754 single precision range is higher than that.
     33    return 1.0e12 * pow(arg, 2.0);
     34 }
     35 
     36 void main() {
     37    // Note that the bug did not reproduce if an uniform was passed to the function instead of a constant,
     38    // or if the expression was moved outside the user-defined function.
     39    const float a = 1.0e-6;
     40    float b = fun(a);
     41    if (abs(b - 1.0) < 0.01) {
     42        gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // green
     43    } else {
     44        gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // red
     45    }
     46 }
     47 </script>
     48 <script type="application/javascript">
     49 "use strict";
     50 description();
     51 debug("");
     52 var wtu = WebGLTestUtils;
     53 function test() {
     54  var gl = wtu.create3DContext("canvas");
     55  if (!gl) {
     56    testFailed("context does not exist");
     57    return;
     58  }
     59  if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision == 0) {
     60    testPassed("highp precision not supported");
     61  } else {
     62    wtu.setupUnitQuad(gl);
     63    var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["aPosition"], undefined, true);
     64    wtu.drawUnitQuad(gl);
     65    wtu.checkCanvasRect(gl, 0, 0, 256, 256, [0, 255, 0, 255]);
     66  }
     67 };
     68 
     69 test();
     70 finishTest();
     71 </script>
     72 </body>
     73 </html>