floored-division-accuracy.html (1851B)
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 <!-- author: Bill Baxter (wbaxter at google.com) --> 8 9 <!DOCTYPE html> 10 <html> 11 <head> 12 <meta charset="utf-8"> 13 <title>Floored Division Accuracy Bug</title> 14 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 15 <script src="../../../js/js-test-pre.js"></script> 16 <script src="../../../js/webgl-test-utils.js"></script> 17 <script src="../../../js/glsl-conformance-test.js"></script> 18 </head> 19 20 <body> 21 <div id="description"></div> 22 <div id="console"></div> 23 24 <script id="shader-vs" type="x-shader/x-vertex"> 25 attribute vec4 vPosition; 26 uniform float divisor; 27 varying vec4 vColor; 28 void main(void) { 29 gl_Position = vPosition; 30 float index = 9.0; 31 // Floating point operations don't have any guaranteed precision, but they 32 // should at least be accurate to 1 part in 10^5. 33 float value = floor((index / divisor) * 1.00001); 34 vColor = (value == 3.) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); 35 } 36 </script> 37 38 <script id="shader-fs" type="x-shader/x-fragment"> 39 precision mediump float; 40 varying vec4 vColor; 41 void main(void) { 42 gl_FragColor = vColor; 43 } 44 </script> 45 <script> 46 "use strict"; 47 description(); 48 49 debug(""); 50 // Reproduces bug seen on Mac OS X with AMD Radeon HD 6490 GPU 51 debug("If things are working correctly, then the square will be green."); 52 debug("If your card thinks floor(9. / 3.) is not 3 to within 1 part in 10^5, "); 53 debug("then the square will be red."); 54 55 GLSLConformanceTester.runRenderTests([ 56 { 57 vShaderId: 'shader-vs', 58 vShaderSuccess: true, 59 fShaderId: 'shader-fs', 60 fShaderSuccess: true, 61 linkSuccess: true, 62 passMsg: 'Test that floor(9. / 3.) is 3 to within 1 part in 10^5', 63 uniforms: [{name: "divisor", functionName: "uniform1f", value: 3}] 64 } 65 ]); 66 67 </script> 68 </body> 69 </html>