Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / programs / use-program-crash-with-discard-in-fragment-shader.html
blob27dac9a9ae19fc244e38c3010c04e4744f16adaa
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 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL Program Conformance 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 <div id="console"></div>
19 <canvas id="canvas" width="2" height="2"> </canvas>
20 <script id="vertexShader" language="x-shader/x-vertex">
21 attribute vec4 ATTR0;
22 void main()
24 gl_Position = ATTR0;
26 </script>
27 <script id="fragmentShader" language="x-shader/x-fragment">
28 precision mediump float;
29 void main()
31 float _Intensity = exp2(gl_FragCoord.w);
32 if (_Intensity < 0.5) {
33 discard;
35 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
37 </script>
38 <script>
39 "use strict";
40 description('Regression test for crash in Mac OS AMD OpenGL driver related to use of discard in fragment shader.<br><br>More specifically, triggering the crash seems to require examination of gl_FragCoord.w, use of exp2, and a call to discard in the fragment shader. Thanks to Sheheryar Zakaria and Michael Braithwaite at Turbulenz for the original test case.<br><a href="https://bugs.webkit.org/show_bug.cgi?id=73932">WebKit bug 73932</a><br>');
42 debug("");
44 var wtu = WebGLTestUtils;
45 var gl = wtu.create3DContext("canvas");
46 if (!gl) {
47 testFailed("context does not exist");
48 } else {
49 testPassed("context exists");
52 debug("");
54 var program = wtu.loadProgramFromScript(gl, 'vertexShader', 'fragmentShader');
55 if (program) {
56 testPassed("Program linked successfully");
57 } else {
58 testFailed("Program failed to link");
61 // Crash occurs here on affected machines
62 gl.useProgram(program);
64 // In some browsers, such as Chrome, the above crash only causes a
65 // lost context event to be dispatched, and not synchronously. To verify
66 // that everything worked, clear and read back the frame buffer.
67 gl.clearColor(1.0, 0.0, 0.0, 1.0);
68 gl.clear(gl.COLOR_BUFFER_BIT);
69 wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255, 0, 0, 255],
70 "Color should be red");
72 var successfullyParsed = true;
73 </script>
74 <script src="../../js/js-test-post.js"></script>
76 </body>
77 </html>