Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / extensions / ext-conservative-depth.html
blobc9c9f85bdbeaa912771c8b62b90d4cbc594313b6
1 <!--
2 Copyright (c) 2023 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 EXT_conservative_depth 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 <canvas width="32" height="32" id="c"></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
20 <script>
21 "use strict";
22 description("This test verifies the functionality of the EXT_conservative_depth extension, if it is available.");
24 debug("");
26 var wtu = WebGLTestUtils;
27 var gl = wtu.create3DContext("c", null, 2);
28 var ext;
30 function runShaderTests(extensionEnabled) {
31 debug("");
32 debug("Testing various shader compiles with extension " + (extensionEnabled ? "enabled" : "disabled"));
34 const macro = `#version 300 es
35 precision mediump float;
36 out vec4 my_FragColor;
37 void main() {
38 #ifdef GL_EXT_conservative_depth
39 my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
40 #else
41 #error no GL_EXT_conservative_depth;
42 #endif
43 }`;
45 const missingExtension = `#version 300 es
46 precision mediump float;
47 out vec4 my_FragColor;
48 layout (depth_any) out float gl_FragDepth;
49 void main() {
50 my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
51 gl_FragDepth = 1.0;
52 }`;
54 const valid = `#version 300 es
55 #extension GL_EXT_conservative_depth : enable
56 precision mediump float;
57 out vec4 my_FragColor;
58 layout (depth_any) out float gl_FragDepth;
59 void main() {
60 my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
61 gl_FragDepth = 1.0;
62 }`;
64 const invalid = `#version 300 es
65 #extension GL_EXT_conservative_depth : enable
66 precision mediump float;
67 out vec4 my_FragColor;
68 layout (depth_unchanged) out float gl_FragDepth;
69 void main() {
70 my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
71 gl_FragDepth = 1.0;
72 }`;
74 // Always expect the shader missing the #extension pragma to fail (whether enabled or not)
75 if (wtu.setupProgram(gl, [wtu.simpleVertexShaderESSL300, missingExtension])) {
76 testFailed("Depth layout qualifier allowed without #extension pragma");
77 } else {
78 testPassed("Depth layout qualifier disallowed without #extension pragma");
81 // Expect the macro shader to succeed ONLY if enabled
82 if (wtu.setupProgram(gl, [wtu.simpleVertexShaderESSL300, macro])) {
83 if (extensionEnabled) {
84 testPassed("Macro defined in shaders when extension is enabled");
85 } else {
86 testFailed("Macro defined in shaders when extension is disabled");
88 } else {
89 if (extensionEnabled) {
90 testFailed("Macro not defined in shaders when extension is enabled");
91 } else {
92 testPassed("Macro not defined in shaders when extension is disabled");
96 // Try to compile a shader using a layout qualifier that should only succeed if enabled
97 if (wtu.setupProgram(gl, [wtu.simpleVertexShaderESSL300, valid])) {
98 if (extensionEnabled) {
99 testPassed("Depth layout qualifier compiled successfully when extension enabled");
100 } else {
101 testFailed("Depth layout qualifier compiled successfully when extension disabled");
103 } else {
104 if (extensionEnabled) {
105 testFailed("Depth layout qualifier failed to compile when extension enabled");
106 } else {
107 testPassed("Depth layout qualifier failed to compile when extension disabled");
111 // Try to compile a shader using a disallowed layout qualifier
112 if (wtu.setupProgram(gl, [wtu.simpleVertexShaderESSL300, invalid])) {
113 testFailed("Unsupported depth layout qualifier compiled successfully");
114 } else {
115 testPassed("Unsupported depth layout qualifier failed to compile");
119 function runTest() {
120 if (!gl) {
121 testFailed("WebGL context does not exist");
122 return;
124 testPassed("WebGL context exists");
126 runShaderTests(false);
128 ext = gl.getExtension("EXT_conservative_depth");
129 wtu.runExtensionSupportedTest(gl, "EXT_conservative_depth", ext !== null);
131 if (!ext) {
132 testPassed("No EXT_conservative_depth support -- this is legal");
133 } else {
134 testPassed("Successfully enabled EXT_conservative_depth extension");
135 runShaderTests(true);
139 runTest();
141 var successfullyParsed = true;
142 </script>
143 <script src="../../js/js-test-post.js"></script>
144 </body>
145 </html>