tor-browser

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

floor-div-cos-should-not-truncate.html (2335B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>Floor + divide + cosine should not truncate intermediate results.</title>
      6 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
      7 <script src="../../../js/js-test-pre.js"></script>
      8 <script src="../../../js/webgl-test-utils.js"></script>
      9 </head>
     10 <body>
     11 <canvas id="canvas" width="256" height="256"> </canvas>
     12 <div id="description"></div>
     13 <div id="console"></div>
     14 
     15 <script id="vshader" type="x-shader/x-vertex">
     16 precision highp float;
     17 
     18 attribute vec3 pos;
     19 
     20 // This divisor must be greater than the 32-bit floating point
     21 // representation of 1e6 / (2 * pi) to repro.
     22 const float magic = 159154.953125;
     23 
     24 void main(void) {
     25  // This floor must be present to repro.
     26  float x = floor(pos.x);
     27 
     28  // This divide and cosine must be present to repro.
     29  x = cos(x / magic);
     30 
     31  // If the GPU truncated 'x / magic' to 0, then 'cos(x / magic)' will produce
     32  // 1.0, the green square will be moved offscreen, and the red background
     33  // will be visible.
     34  gl_Position.x = pos.y + x * 2.0;
     35  gl_Position.y = pos.z;
     36  gl_Position.z = 0.0;
     37  gl_Position.w = 1.0;
     38 }
     39 </script>
     40 
     41 <script id="fshader" type="x-shader/x-fragment">
     42 precision highp float;
     43 
     44 void main(void) {
     45  gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
     46 }
     47 </script>
     48 
     49 <script type="application/javascript">
     50 "use strict";
     51 description("Flooring a number, then dividing by a large number, then computing the cosine of that should not truncate the intermediate values.");
     52 debug("Regression test for <a href='https://code.google.com/p/angleproject/issues/detail?id=1179'>https://code.google.com/p/angleproject/issues/detail?id=1179</a>");
     53 var wtu = WebGLTestUtils;
     54 var gl = wtu.create3DContext("canvas");
     55 var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['pos'], undefined, true);
     56 
     57 gl.clearColor(1, 0, 0, 1);
     58 gl.clear(gl.COLOR_BUFFER_BIT);
     59 
     60 var magic = 159154.953125;
     61 var x = (Math.PI / 2.0) * magic;
     62 var data = [
     63  x, -1, -1,
     64  x, 1, -1,
     65  x, 1, 1,
     66  x, -1, -1,
     67  x, 1, 1,
     68  x, -1, 1
     69 ];
     70 
     71 gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
     72 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl.STATIC_DRAW);
     73 gl.enableVertexAttribArray(0);
     74 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 12, 0);
     75 
     76 gl.drawArrays(gl.TRIANGLES, 0, 6);
     77 
     78 wtu.checkCanvas(gl, [0,255,0,255], "should be 0,255,0,255");
     79 finishTest();
     80 </script>