summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/programs/use-program-crash-with-discard-in-fragment-shader.html
blob: 27dac9a9ae19fc244e38c3010c04e4744f16adaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Program Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script id="vertexShader" language="x-shader/x-vertex">
attribute vec4 ATTR0;
void main()
{
  gl_Position = ATTR0;
}
</script>
<script id="fragmentShader" language="x-shader/x-fragment">
precision mediump float;
void main()
{
  float _Intensity = exp2(gl_FragCoord.w);
  if (_Intensity < 0.5) {
    discard;
  }
  gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
</script>
<script>
"use strict";
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>');

debug("");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas");
if (!gl) {
  testFailed("context does not exist");
} else {
  testPassed("context exists");
}

debug("");

var program = wtu.loadProgramFromScript(gl, 'vertexShader', 'fragmentShader');
if (program) {
  testPassed("Program linked successfully");
} else {
  testFailed("Program failed to link");
}

// Crash occurs here on affected machines
gl.useProgram(program);

// In some browsers, such as Chrome, the above crash only causes a
// lost context event to be dispatched, and not synchronously. To verify
// that everything worked, clear and read back the frame buffer.
gl.clearColor(1.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255, 0, 0, 255],
    "Color should be red");

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>

</body>
</html>