tor-browser

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

active-3d-texture-bug.html (3877B)


      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>WebGL Active TEXTURE1 Bug Tests</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 <div id="description"></div>
     18 <canvas id="canvas" width="64" height="64"> </canvas>
     19 <div id="console"></div>
     20 <script id="vshader" type="x-shader/x-vertex">#version 300 es
     21 precision mediump float;
     22 in vec4 a_position;
     23 in vec2 a_coord;
     24 out vec2 v_coord;
     25 void main() {
     26    gl_Position = a_position;
     27    v_coord = a_coord;
     28 }
     29 </script>
     30 <script id="fshader" type="x-shader/x-fragment">#version 300 es
     31 precision mediump float;
     32 in vec2 v_coord;
     33 uniform mediump sampler3D u_sampler;
     34 out vec4 o_color;
     35 void main () {
     36    o_color = texture(u_sampler, vec3(v_coord, 0.0));
     37 }
     38 </script>
     39 <script>
     40 "use strict";
     41 description("Test for a MacOSX 10.12 with Intel GPUs driver crash bug activating TEXTURE1 for 3d texture");
     42 debug("");
     43 
     44 var wtu = WebGLTestUtils;
     45 var canvas = document.getElementById("canvas");
     46 var gl = wtu.create3DContext(canvas, null, 2);
     47 var samplerLoc;
     48 
     49 function render(textureUnit, width, height, expectedColor, msg) {
     50    gl.uniform1i(samplerLoc, textureUnit);
     51    wtu.setupUnitQuad(gl, 0, 1);
     52    wtu.clearAndDrawUnitQuad(gl);
     53    wtu.checkCanvasRect(gl, 0, 0, width, height, expectedColor, msg);
     54 }
     55 
     56 function activeTextureTest() {
     57    var texture = gl.createTexture();
     58    var sampler = gl.createSampler();
     59    var width = 64;
     60    var height = 64;
     61    var depth = 4;
     62    var black = [0, 0, 0, 255];
     63    var size = width * height * depth * 4;
     64 
     65    var buf = new Uint8Array(size);
     66    for (var i = 0; i < size; i += 4) {
     67        buf[i + 0] = 0;
     68        buf[i + 1] = 255;
     69        buf[i + 2] = 0;
     70        buf[i + 3] = 255;
     71    }
     72 
     73    var program = wtu.setupProgram(gl, ["vshader", "fshader"], ['a_position', 'a_coord'], [0, 1]);
     74    samplerLoc = gl.getUniformLocation(program, "u_sampler");
     75 
     76    gl.viewport(0, 0, width, height);
     77 
     78    gl.bindTexture(gl.TEXTURE_3D, texture);
     79    gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, buf);
     80    // texture is unbound from the default texture unit TEXTURE0,
     81    // then a default black texture will be bound to TEXTURE0.
     82    gl.bindTexture(gl.TEXTURE_3D, null);
     83 
     84    // Active TEXTURE1 and 3d texture are necessary to reproduce the crash bug.
     85    gl.activeTexture(gl.TEXTURE1);
     86 
     87    gl.bindSampler(0, sampler);
     88    gl.samplerParameteri(sampler, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
     89    gl.samplerParameteri(sampler, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
     90    gl.bindTexture(gl.TEXTURE_3D, texture);
     91    gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
     92    gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
     93 
     94    // Render using sampler
     95    // When rendering from texture unit 0, the black texture will be drawn.
     96    render(0, width, height, black, "Result pixels rendering from TEXTURE0 should be black");
     97 
     98    gl.bindSampler(0, null);
     99    gl.deleteSampler(sampler);
    100 
    101    // Render using texture
    102    // When rendering from texture unit 0, the black texture will be drawn.
    103    // Crash happens when calling gl.drawArrays during this rendering.
    104    render(0, width, height, black, "Result pixels rendering from TEXTURE0 should be black");
    105 
    106    gl.bindTexture(gl.TEXTURE_3D, null);
    107    gl.deleteTexture(texture);
    108    gl.deleteProgram(program);
    109 }
    110 
    111 if (!gl) {
    112    testFailed("Fail to get a WebGL2 context");
    113 } else {
    114    testPassed("Created WebGL2 context successfully");
    115    activeTextureTest();
    116 }
    117 
    118 debug("");
    119 var successfullyParsed = true;
    120 </script>
    121 <script src="../../../js/js-test-post.js"></script>
    122 
    123 </body>
    124 </html>