summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/misc/shaders-with-constant-expression-loop-conditions.html
blob: c06de87ef83cb65c63d22d82bc9e743aede6d9f5 (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
<!--
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 GLSL Conformance Tests</title>
<link rel="stylesheet" href="../../../resources/js-test-style.css" />
<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css" />
<script src="../../../js/js-test-pre.js"></script>
<script src="../../../js/webgl-test-utils.js"></script>
<script src="../../../js/glsl-conformance-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vertexShaderLiteralLoopCondition" type="text/something-not-javascript">
attribute vec4 a_position;
void main()
{
    for (int i = 0; i < 5 + 5; i++) { }
    gl_Position = a_position;
}
</script>
<script id="fragmentShaderLiteralLoopCondition" type="text/something-not-javascript">
void main()
{
    for (int i = 0; i < 5 + 5; i++) { }
    gl_FragColor = vec4(1.0);
}
</script>
<script id="vertexShaderConstVarLoopCondition" type="text/something-not-javascript">
attribute vec4 a_position;
void main()
{
    // Explicitly constant variables can be part of a constant expression
    const int constVar = 5;
    for (int i = 0; i < 5 + constVar; i++) { }
    gl_Position = a_position;
}
</script>
<script id="fragmentShaderConstVarLoopCondition" type="text/something-not-javascript">
void main()
{
    // Explicitly constant variables can be part of a constant expression
    const int constVar = 5;
    for (int i = 0; i < constVar + 5; i++) { }
    gl_FragColor = vec4(1.0);
}
</script>
<script id="vertexShaderNonConstVarLoopCondition" type="text/something-not-javascript">
attribute vec4 a_position;
void main()
{
    // Despite assigning a constant and not modifying it, nonConstVar is not semantically a constant expression
    int nonConstVar = 10;
    for (int i = 0; i < nonConstVar; i++) { }
    gl_Position = a_position;
}
</script>
<script id="fragmentShaderNonConstVarLoopCondition" type="text/something-not-javascript">
void main()
{
    // Despite assigning a constant and not modifying it, nonConstVar is not semantically a constant expression
    int nonConstVar = 10;
    for (int i = 0; i < nonConstVar; i++) { }
    gl_FragColor = vec4(1.0);
}
</script>
<script>
"use strict";
var wtu = WebGLTestUtils;

var tests = [];
tests.push({
    vShaderSource: wtu.getScript("vertexShaderLiteralLoopCondition"),
    vShaderSuccess: true,
    fShaderSource: wtu.getScript("fragmentShaderLiteralLoopCondition"),
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "Shaders with literals in the loop condition should compile and link.",
});
tests.push({
    vShaderSource: wtu.getScript("vertexShaderConstVarLoopCondition"),
    vShaderSuccess: true,
    fShaderSource: wtu.getScript("fragmentShaderConstVarLoopCondition"),
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "Shaders with constant variables in the loop condition should compile and link.",
});
tests.push({
    vShaderSource: wtu.getScript("vertexShaderNonConstVarLoopCondition"),
    vShaderSuccess: false,
    fShaderSource: wtu.getScript("fragmentShaderLiteralLoopCondition"),
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "Vertex shader with non-const variable in the loop condition should fail.",
});
tests.push({
    vShaderSource: wtu.getScript("vertexShaderLiteralLoopCondition"),
    vShaderSuccess: true,
    fShaderSource: wtu.getScript("fragmentShaderNonConstVarLoopCondition"),
    fShaderSuccess: false,
    linkSuccess: false,
    passMsg: "Fragment shader with non-const variable in the loop condition should fail.",
});

GLSLConformanceTester.runTests(tests);
var successfullyParsed = true;
</script>
</body>
</html>