summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/misc/shader-with-too-many-uniforms.html
blob: b5e87f9c854f6802529303f89604814d9acdd40a (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
<!--
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="vshader" type="x-shader/x-vertex">
attribute vec4 a_position;
void main()
{
    gl_Position = a_position;
}
</script>
<script id="vshader-max" type="x-shader/x-vertex">
attribute vec4 a_position;
uniform vec4 u_color[$(maxUniformVectors)];
void main()
{
    vec4 v = vec4(0, 0, 0, 0);
    for (int i = 0; i < $(maxUniformVectors); ++i) {
        v = v + vec4(u_color[i]);
    }
    gl_Position = a_position + v;
}
</script>
<script id="fshader" type="x-shader/x-fragment">
precision mediump float;
void main()
{
    gl_FragColor = vec4(0, 1, 0, 1);
}
</script>
<script id="fshader-max" type="x-shader/x-fragment">
precision mediump float;
uniform vec4 u_color[$(maxUniformVectors)];
void main()
{
    vec4 v = vec4(0, 0, 0, 0);
    for (int i = 0; i < $(maxUniformVectors); ++i) {
        v = v + vec4(u_color[i]);
    }
    gl_FragColor = v;
}
</script>
<script>
"use strict";
description("checks shader with too many uniforms fails");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext();
var maxFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
var maxVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);

// Up to 2 uniform vector registers may be spent for literal constants in
// vshader-max or fshader-max code. One vector row is used for the vec4, and
// another may be used for integer constants that are allowed to be treated
// internally as floats and are packable to the space of one row. This is
// according to the GLSL ES variable packing algorithm detailed in Section 7 of
// Appendix A of the GLSL ES Specification 10.0.17.
var maxVectorStorageUsedForLiterals = 2;

var tests = [
 { desc: "using all uniforms in vertex shader should succeed",
   maxUniformVectors: maxVertexUniformVectors - maxVectorStorageUsedForLiterals,
   vShader: "vshader-max",
   fShader: "fshader",
   success: true,
 },
 { desc: "using too many uniforms in vertex shader should fail",
   maxUniformVectors: maxVertexUniformVectors + 1,
   vShader: "vshader-max",
   fShader: "fshader",
   color: [0, 1, 0, 1],
   success: false,
 },
 { desc: "using all uniforms in fragment shader should succeed",
   maxUniformVectors: maxFragmentUniformVectors - maxVectorStorageUsedForLiterals,
   vShader: "vshader",
   fShader: "fshader-max",
   success: true,
 },
 { desc: "using too many uniforms in fragment shader should fail",
   maxUniformVectors: maxFragmentUniformVectors + 1,
   vShader: "vshader",
   fShader: "fshader-max",
   color: [0, 1, 0, 1],
   success: false,
 },
];

var glslTests = [];

for (var ii = 0; ii < tests.length; ++ii) {
  var test = tests[ii];
  var vSrc = wtu.replaceParams(wtu.getScript(test.vShader), test);
  var fSrc = wtu.replaceParams(wtu.getScript(test.fShader), test);
  glslTests.push({
    vShaderSource: vSrc,
    fShaderSource: fSrc,
    linkSuccess: test.success,
    passMsg: 'shader ' + test.desc,
  });
}

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