summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/extensions/ext-conservative-depth.html
blob: c9c9f85bdbeaa912771c8b62b90d4cbc594313b6 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!--
Copyright (c) 2023 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 EXT_conservative_depth 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>
<canvas width="32" height="32" id="c"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("This test verifies the functionality of the EXT_conservative_depth extension, if it is available.");

debug("");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("c", null, 2);
var ext;

function runShaderTests(extensionEnabled) {
    debug("");
    debug("Testing various shader compiles with extension " + (extensionEnabled ? "enabled" : "disabled"));

    const macro = `#version 300 es
        precision mediump float;
        out vec4 my_FragColor;
        void main() {
        #ifdef GL_EXT_conservative_depth
            my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
        #else
            #error no GL_EXT_conservative_depth;
        #endif
        }`;

    const missingExtension = `#version 300 es
        precision mediump float;
        out vec4 my_FragColor;
        layout (depth_any) out float gl_FragDepth;
        void main() {
            my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
            gl_FragDepth = 1.0;
        }`;

    const valid = `#version 300 es
        #extension GL_EXT_conservative_depth : enable
        precision mediump float;
        out vec4 my_FragColor;
        layout (depth_any) out float gl_FragDepth;
        void main() {
            my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
            gl_FragDepth = 1.0;
        }`;

    const invalid = `#version 300 es
        #extension GL_EXT_conservative_depth : enable
        precision mediump float;
        out vec4 my_FragColor;
        layout (depth_unchanged) out float gl_FragDepth;
        void main() {
            my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
            gl_FragDepth = 1.0;
        }`;

    // Always expect the shader missing the #extension pragma to fail (whether enabled or not)
    if (wtu.setupProgram(gl, [wtu.simpleVertexShaderESSL300, missingExtension])) {
        testFailed("Depth layout qualifier allowed without #extension pragma");
    } else {
        testPassed("Depth layout qualifier disallowed without #extension pragma");
    }

    // Expect the macro shader to succeed ONLY if enabled
    if (wtu.setupProgram(gl, [wtu.simpleVertexShaderESSL300, macro])) {
        if (extensionEnabled) {
            testPassed("Macro defined in shaders when extension is enabled");
        } else {
            testFailed("Macro defined in shaders when extension is disabled");
        }
    } else {
        if (extensionEnabled) {
            testFailed("Macro not defined in shaders when extension is enabled");
        } else {
            testPassed("Macro not defined in shaders when extension is disabled");
        }
    }

    // Try to compile a shader using a layout qualifier that should only succeed if enabled
    if (wtu.setupProgram(gl, [wtu.simpleVertexShaderESSL300, valid])) {
        if (extensionEnabled) {
            testPassed("Depth layout qualifier compiled successfully when extension enabled");
        } else {
            testFailed("Depth layout qualifier compiled successfully when extension disabled");
        }
    } else {
        if (extensionEnabled) {
            testFailed("Depth layout qualifier failed to compile when extension enabled");
        } else {
            testPassed("Depth layout qualifier failed to compile when extension disabled");
        }
    }

    // Try to compile a shader using a disallowed layout qualifier
    if (wtu.setupProgram(gl, [wtu.simpleVertexShaderESSL300, invalid])) {
        testFailed("Unsupported depth layout qualifier compiled successfully");
    } else {
        testPassed("Unsupported depth layout qualifier failed to compile");
    }
}

function runTest() {
    if (!gl) {
        testFailed("WebGL context does not exist");
        return;
    }
    testPassed("WebGL context exists");

    runShaderTests(false);

    ext = gl.getExtension("EXT_conservative_depth");
    wtu.runExtensionSupportedTest(gl, "EXT_conservative_depth", ext !== null);

    if (!ext) {
        testPassed("No EXT_conservative_depth support -- this is legal");
    } else {
        testPassed("Successfully enabled EXT_conservative_depth extension");
        runShaderTests(true);
    }
}

runTest();

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