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.
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>
17 <canvas width=
"32" height=
"32" id=
"c"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
22 description("This test verifies the functionality of the EXT_conservative_depth extension, if it is available.");
26 var wtu
= WebGLTestUtils
;
27 var gl
= wtu
.create3DContext("c", null, 2);
30 function runShaderTests(extensionEnabled
) {
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;
38 #ifdef GL_EXT_conservative_depth
39 my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
41 #error no GL_EXT_conservative_depth;
45 const missingExtension
= `#version 300 es
46 precision mediump float;
47 out vec4 my_FragColor;
48 layout (depth_any) out float gl_FragDepth;
50 my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
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;
60 my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
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;
70 my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
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");
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");
86 testFailed("Macro defined in shaders when extension is disabled");
89 if (extensionEnabled
) {
90 testFailed("Macro not defined in shaders when extension is enabled");
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");
101 testFailed("Depth layout qualifier compiled successfully when extension disabled");
104 if (extensionEnabled
) {
105 testFailed("Depth layout qualifier failed to compile when extension enabled");
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");
115 testPassed("Unsupported depth layout qualifier failed to compile");
121 testFailed("WebGL context does not exist");
124 testPassed("WebGL context exists");
126 runShaderTests(false);
128 ext
= gl
.getExtension("EXT_conservative_depth");
129 wtu
.runExtensionSupportedTest(gl
, "EXT_conservative_depth", ext
!== null);
132 testPassed("No EXT_conservative_depth support -- this is legal");
134 testPassed("Successfully enabled EXT_conservative_depth extension");
135 runShaderTests(true);
141 var successfullyParsed
= true;
143 <script src=
"../../js/js-test-post.js"></script>