Bug 1945965 – remove new tab April Fools logo. r=home-newtab-reviewers,reemhamz
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / glsl / misc / global-variable-init.html
blob99e7417f69cf1ad5796b916e720bb8c8b938199a
1 <!--
2 Copyright (c) 2019 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>Global variable initializer restrictions</title>
12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
13 <link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
14 <script src="../../../js/js-test-pre.js"></script>
15 <script src="../../../js/webgl-test-utils.js"></script>
16 <script src="../../../js/glsl-conformance-test.js"></script>
17 </head>
18 <body>
19 <div id="description"></div>
20 <div id="console"></div>
21 <script id="constGlobalShader" type="x-shader/x-vertex">
22 precision mediump float;
23 attribute vec4 aPosition;
24 varying float v;
26 const float c = 1.0;
27 float f = c;
29 void main() {
30 v = f;
31 gl_Position = aPosition;
33 </script>
34 <script id="globalShader" type="x-shader/x-vertex">
35 precision mediump float;
36 attribute vec4 aPosition;
37 varying float v;
39 float c = 1.0;
40 float f = c;
42 void main() {
43 v = f;
44 gl_Position = aPosition;
46 </script>
47 <script id="uniformShader" type="x-shader/x-vertex">
48 precision mediump float;
49 attribute vec4 aPosition;
50 varying float v;
52 uniform float u;
53 float f = u;
55 void main() {
56 v = f;
57 gl_Position = aPosition;
59 </script>
60 <script id="builtinFunctionShader" type="x-shader/x-vertex">
61 precision mediump float;
62 attribute vec4 aPosition;
63 varying float v;
65 float c = 1.0;
66 float f = sin(c);
68 void main() {
69 v = f;
70 gl_Position = aPosition;
72 </script>
73 <script id="builtinTextureFunctionShader" type="x-shader/x-vertex">
74 precision mediump float;
75 attribute vec4 aPosition;
76 varying float v;
78 uniform sampler2D s;
79 float f = texture2DLod(s, vec2(0.5, 0.5), 0.0).x;
81 void main() {
82 v = f;
83 gl_Position = aPosition;
85 </script>
86 <script id="attributeShader" type="x-shader/x-vertex">
87 precision mediump float;
88 attribute vec4 aPosition;
89 varying float v;
91 float f = aPosition.x;
93 void main() {
94 v = f;
95 gl_Position = aPosition;
97 </script>
98 <script id="userDefinedFunctionShader" type="x-shader/x-vertex">
99 precision mediump float;
100 attribute vec4 aPosition;
101 varying float v;
103 float foo() {
104 return 1.0;
106 float f = foo();
108 void main() {
109 v = f;
110 gl_Position = aPosition;
112 </script>
113 <script id="varyingShader" type="x-shader/x-fragment">
114 precision mediump float;
115 varying float v;
116 float f = v;
118 void main() {
119 gl_FragColor = vec4(f);
121 </script>
122 <script id="globalLValueShader" type="x-shader/x-vertex">
123 precision mediump float;
124 attribute vec4 aPosition;
125 varying float v;
127 float c = 1.0;
128 float f = (c = 0.0);
130 void main() {
131 v = f;
132 gl_Position = aPosition;
134 </script>
135 <script id="globalLValueShader2" type="x-shader/x-vertex">
136 precision mediump float;
137 attribute vec4 aPosition;
138 varying float v;
140 float c = 1.0;
141 float f = (c++);
143 void main() {
144 v = f;
145 gl_Position = aPosition;
147 </script>
148 <script id="globalNonConstTernary" type="x-shader/x-fragment">
149 precision mediump float;
150 float green = 1.0;
151 float black = 0.0;
152 float f = true ? green : black;
154 void main() {
155 gl_FragColor = vec4(0.0, f, 0.0, 1.0);
157 </script>
158 <script id="globalUniformTernary" type="x-shader/x-fragment">
159 precision mediump float;
160 uniform float u_zero;
161 float green = 1.0 + u_zero;
162 float f = true ? green : u_zero;
164 void main() {
165 gl_FragColor = vec4(0.0, f, 0.0, 1.0);
167 </script>
168 <script id="globalUniformTernary2" type="x-shader/x-fragment">
169 precision mediump float;
170 uniform float u_zero;
171 float green = 1.0;
172 float f = (u_zero < 0.1) ? green : 0.0;
174 void main() {
175 gl_FragColor = vec4(0.0, f, 0.0, 1.0);
177 </script>
178 <script id="globalUniformStruct" type="x-shader/x-fragment">
179 precision mediump float;
180 struct S {
181 float zero;
182 int one;
184 uniform S us;
185 S s = us;
187 void main() {
188 float green = (s.one == 1) ? 1.0 : 0.0;
189 gl_FragColor = vec4(0.0, green, 0.0, 1.0);
191 </script>
192 <script id="builtInConstant" type="x-shader/x-fragment">
193 precision mediump float;
194 int i = gl_MaxFragmentUniformVectors;
196 void main() {
197 float green = (i > 0) ? 1.0 : 0.0;
198 gl_FragColor = vec4(0.0, green, 0.0, 1.0);
200 </script>
201 <script id="builtInNonConstant" type="x-shader/x-fragment">
202 precision mediump float;
203 vec4 v = gl_FragCoord;
205 void main() {
206 gl_FragColor = v;
208 </script>
209 <script type="application/javascript">
210 "use strict";
211 description();
212 GLSLConformanceTester.runTests([
214 vShaderId: "constGlobalShader",
215 vShaderSuccess: true,
216 linkSuccess: true,
217 passMsg: "A const global in a global variable initializer should be accepted by WebGL."
220 vShaderId: "globalShader",
221 vShaderSuccess: true,
222 linkSuccess: true,
223 passMsg: "Another global in a global variable initializer should be accepted by WebGL."
226 vShaderId: "uniformShader",
227 vShaderSuccess: true,
228 linkSuccess: true,
229 passMsg: "A uniform in a global variable initializer should be accepted by WebGL."
232 vShaderId: "builtinFunctionShader",
233 vShaderSuccess: true,
234 linkSuccess: true,
235 passMsg: "A built-in math function in a global variable initializer should be accepted by WebGL."
238 vShaderId: "builtinTextureFunctionShader",
239 vShaderSuccess: false,
240 linkSuccess: false,
241 passMsg: "A texture lookup function in a global variable initializer should not be accepted by WebGL."
244 vShaderId: "attributeShader",
245 vShaderSuccess: false,
246 linkSuccess: false,
247 passMsg: "An attribute in a global variable initializer should not be accepted by WebGL."
250 vShaderId: "userDefinedFunctionShader",
251 vShaderSuccess: false,
252 linkSuccess: false,
253 passMsg: "A user-defined function call in a global variable initializer should not be accepted by WebGL."
256 vShaderId: "constGlobalShader",
257 vShaderSuccess: true,
258 fShaderId: "varyingShader",
259 fShaderSuccess: false,
260 linkSuccess: false,
261 passMsg: "A varying in a global variable initializer should not be accepted by WebGL."
264 vShaderId: "globalLValueShader",
265 vShaderSuccess: false,
266 linkSuccess: false,
267 passMsg: "Another global as an l-value in a global variable initializer should not be accepted by WebGL."
270 vShaderId: "globalLValueShader2",
271 vShaderSuccess: false,
272 linkSuccess: false,
273 passMsg: "Another global as an l-value (parameter of ++) in a global variable initializer should not be accepted by WebGL."
276 fShaderId: "globalNonConstTernary",
277 fShaderSuccess: true,
278 linkSuccess: true,
279 render: true,
280 passMsg: "Non-const global variables as operands for a ternary operator in a global variable initializer should be accepted by WebGL."
283 fShaderId: "globalUniformTernary",
284 fShaderSuccess: true,
285 linkSuccess: true,
286 render: true,
287 passMsg: "A uniform as the second operand for a ternary operator in a global variable initializer should be accepted by WebGL."
290 fShaderId: "globalUniformTernary2",
291 fShaderSuccess: true,
292 linkSuccess: true,
293 render: true,
294 passMsg: "Referencing a uniform inside the first operand for a ternary operator in a global variable initializer should be accepted by WebGL."
297 fShaderId: "globalUniformStruct",
298 fShaderSuccess: true,
299 linkSuccess: true,
300 render: true,
301 uniforms: [
302 { name: 'us.one', functionName: 'uniform1i', value: 1 }
304 passMsg: "A global struct initialized with a uniform struct should be accepted by WebGL."
307 fShaderId: "builtInConstant",
308 fShaderSuccess: true,
309 linkSuccess: true,
310 render: true,
311 passMsg: "Referencing a built-in constant in a global variable initializer should be accepted by WebGL."
314 fShaderId: "builtInNonConstant",
315 fShaderSuccess: false,
316 linkSuccess: false,
317 passMsg: "Referencing a built-in non-constant in a global variable initializer should not be accepted by WebGL."
320 var successfullyParsed = true;
321 </script>
322 </body>
323 </html>