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.
10 <meta charset=
"utf-8">
11 <title>WebGL GLSL Conformance Tests
</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>
19 <div id=
"description"></div>
20 <div id=
"console"></div>
21 <script id=
"vshader" type=
"x-shader/x-vertex">
22 attribute vec4 a_position;
25 gl_Position = a_position;
28 <script id=
"vshader-max" type=
"x-shader/x-vertex">
29 attribute vec4 a_position;
30 uniform vec4 u_color[$(maxUniformVectors)];
33 vec4 v = vec4(
0,
0,
0,
0);
34 for (int i =
0; i < $(maxUniformVectors); ++i) {
35 v = v + vec4(u_color[i]);
37 gl_Position = a_position + v;
40 <script id=
"fshader" type=
"x-shader/x-fragment">
41 precision mediump float;
44 gl_FragColor = vec4(
0,
1,
0,
1);
47 <script id=
"fshader-max" type=
"x-shader/x-fragment">
48 precision mediump float;
49 uniform vec4 u_color[$(maxUniformVectors)];
52 vec4 v = vec4(
0,
0,
0,
0);
53 for (int i =
0; i < $(maxUniformVectors); ++i) {
54 v = v + vec4(u_color[i]);
61 description("checks shader with too many uniforms fails");
63 var wtu
= WebGLTestUtils
;
64 var gl
= wtu
.create3DContext();
65 var maxFragmentUniformVectors
= gl
.getParameter(gl
.MAX_FRAGMENT_UNIFORM_VECTORS
);
66 var maxVertexUniformVectors
= gl
.getParameter(gl
.MAX_VERTEX_UNIFORM_VECTORS
);
68 // Up to 2 uniform vector registers may be spent for literal constants in
69 // vshader-max or fshader-max code. One vector row is used for the vec4, and
70 // another may be used for integer constants that are allowed to be treated
71 // internally as floats and are packable to the space of one row. This is
72 // according to the GLSL ES variable packing algorithm detailed in Section 7 of
73 // Appendix A of the GLSL ES Specification 10.0.17.
74 var maxVectorStorageUsedForLiterals
= 2;
77 { desc
: "using all uniforms in vertex shader should succeed",
78 maxUniformVectors
: maxVertexUniformVectors
- maxVectorStorageUsedForLiterals
,
79 vShader
: "vshader-max",
83 { desc
: "using too many uniforms in vertex shader should fail",
84 maxUniformVectors
: maxVertexUniformVectors
+ 1,
85 vShader
: "vshader-max",
90 { desc
: "using all uniforms in fragment shader should succeed",
91 maxUniformVectors
: maxFragmentUniformVectors
- maxVectorStorageUsedForLiterals
,
93 fShader
: "fshader-max",
96 { desc
: "using too many uniforms in fragment shader should fail",
97 maxUniformVectors
: maxFragmentUniformVectors
+ 1,
99 fShader
: "fshader-max",
107 for (var ii
= 0; ii
< tests
.length
; ++ii
) {
108 var test
= tests
[ii
];
109 var vSrc
= wtu
.replaceParams(wtu
.getScript(test
.vShader
), test
);
110 var fSrc
= wtu
.replaceParams(wtu
.getScript(test
.fShader
), test
);
114 linkSuccess
: test
.success
,
115 passMsg
: 'shader ' + test
.desc
,
119 GLSLConformanceTester
.runTests(glslTests
);
120 var successfullyParsed
= true;