precision-side-effects-bug.html (3915B)
1 <!-- 2 Copyright (c) 2020 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>Verify precision side effects (Adreno driver bug)</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="2" height="2"> </canvas> 18 <div id="description"></div> 19 <div id="console"></div> 20 21 <script id="vshader-simple" type="x-shader/x-vertex">#version 300 es 22 in vec3 aPosition; 23 24 void main() { 25 gl_Position = vec4(aPosition, 1.0); 26 } 27 </script> 28 <script id="fshader-int" type="x-shader/x-fragment">#version 300 es 29 out highp vec4 myFragColor; 30 void main() { 31 highp int t; 32 t = 0 | (int(t == t) * 0x8000); 33 34 if (t == 0x8000) 35 myFragColor = vec4(1.0, 0.0, 0.0, 1.0); 36 else 37 myFragColor = vec4(0.0, 0.0, 0.0, 1.0); 38 } 39 </script> 40 <script id="fshader-ivec2" type="x-shader/x-fragment">#version 300 es 41 out highp vec4 myFragColor; 42 void main() { 43 highp ivec2 t; 44 t = 0 | (ivec2(t == t) * 0x8000); 45 46 if (t == ivec2(0x8000)) 47 myFragColor = vec4(1.0, 0.0, 0.0, 1.0); 48 else 49 myFragColor = vec4(0.0, 0.0, 0.0, 1.0); 50 } 51 </script> 52 <script id="fshader-ivec3" type="x-shader/x-fragment">#version 300 es 53 out highp vec4 myFragColor; 54 void main() { 55 highp ivec3 t; 56 t = 0 | (ivec3(t == t) * 0x8000); 57 58 if (t == ivec3(0x8000)) 59 myFragColor = vec4(1.0, 0.0, 0.0, 1.0); 60 else 61 myFragColor = vec4(0.0, 0.0, 0.0, 1.0); 62 } 63 </script> 64 <script id="fshader-ivec4" type="x-shader/x-fragment">#version 300 es 65 out highp vec4 myFragColor; 66 void main() { 67 highp ivec4 t; 68 t = 0 | (ivec4(t == t) * 0x8000); 69 70 if (t == ivec4(0x8000)) 71 myFragColor = vec4(1.0, 0.0, 0.0, 1.0); 72 else 73 myFragColor = vec4(0.0, 0.0, 0.0, 1.0); 74 } 75 </script> 76 <script type="application/javascript"> 77 "use strict"; 78 description("Verify precision side effects"); 79 debug(""); 80 debug("When this test is run on Adreno (no repros on other vendors so far):"); 81 debug(" - the result of the expression 0 | (int(e0 == e0) * 0x8000) somehow returns -32768 instead of 32768 despite the variable using highp precision;"); 82 debug(" - splitting the expression along | fixes the issue (could also be observed with other operators)."); 83 debug('For additional reference see this <a href="https://github.com/KhronosGroup/WebGL/pull/3192">pull request</a> and <a href="http://crbug.com/1155942">Chromium bug</a>'); 84 debug(""); 85 var wtu = WebGLTestUtils; 86 function test() { 87 var gl = wtu.create3DContext("canvas", undefined, 2); 88 if (!gl) { 89 testFailed("context does not exist"); 90 return; 91 } 92 wtu.setupUnitQuad(gl); 93 94 var testCases = [ 95 { vshader: "vshader-simple", fshader: "fshader-int", desc: "fragment shader int" }, 96 { vshader: "vshader-simple", fshader: "fshader-ivec2", desc: "fragment shader ivec2" }, 97 { vshader: "vshader-simple", fshader: "fshader-ivec3", desc: "fragment shader ivec3" }, 98 { vshader: "vshader-simple", fshader: "fshader-ivec4", desc: "fragment shader ivec4" }, 99 ]; 100 101 for (var idx = 0; idx < testCases.length; ++idx) { 102 var test = testCases[idx]; 103 104 debug(""); 105 var program = wtu.setupProgram(gl, [test.vshader, test.fshader], ["aPosition"]); 106 if (!program) { 107 testFailed("Fail to set up program"); 108 } else { 109 debug("Testing " + test.desc); 110 wtu.drawUnitQuad(gl); 111 wtu.checkCanvas(gl, [255, 0, 0, 255]); 112 gl.deleteProgram(program); 113 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from testing"); 114 } 115 } 116 }; 117 118 test(); 119 120 debug(""); 121 var successfullyParsed = true; 122 </script> 123 <script src="../../js/js-test-post.js"></script> 124 </body> 125 </html>