summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/bugs/complex-glsl-does-not-crash.html
blob: 7b324def84998266075aea3290fc17d19cf419d7 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!--
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>Driver Bug - complex glsl should not crash</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>
<canvas id="example" width="2" height="2"> </canvas>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 a_position;
void main()
{
    gl_Position = a_position;
}
</script>
<script id="fshader" type="x-shader/x-vertex">
precision mediump float;
varying vec4 v_varying;
void main()
{
    gl_FragColor = v_varying;
}
</script>
<script id="vshaderArrayTest" type="x-shader/x-vertex">
attribute vec4 a_position;
varying vec4 v_varying;
uniform $(type) u_uniform[$(numTestType)];
void main()
{
    v_varying = $(code);
    gl_Position = a_position;
}
</script>
<script id="fshaderArrayTest" type="x-shader/x-fragment">
precision mediump float;
uniform $(type) u_uniform[$(numTestType)];
void main()
{
    gl_FragColor = $(code);
}
</script>
<script id="vshaderUniformTest" type="x-shader/x-fragment">
attribute vec4 a_position;
varying vec4 v_varying;
$(uniforms)
void main()
{
    v_varying = $(code);
    gl_Position = a_position;
}
</script>
<script id="fshaderUniformTest" type="x-shader/x-fragment">
precision mediump float;
$(uniforms)
void main()
{
    gl_FragColor = $(code);
}
</script>
<script>
"use strict";
description();
debug("");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");

var uniformTypes = [
  { type: "bool",        componentsPerRow: 1, rows: 1, code: "vec4(u_uniform$(id)$(index), 0, 0, 0)", },
  { type: "float",       componentsPerRow: 1, rows: 1, code: "vec4(u_uniform$(id)$(index), 0, 0, 0)", },
  { type: "int",         componentsPerRow: 1, rows: 1, code: "vec4(u_uniform$(id)$(index), 0, 0, 0)", },
  { type: "vec2",        componentsPerRow: 2, rows: 1, code: "vec4(u_uniform$(id)$(index), 0, 0)", },
  { type: "ivec2",       componentsPerRow: 2, rows: 1, code: "vec4(u_uniform$(id)$(index), 0, 0)", },
  { type: "bvec2",       componentsPerRow: 2, rows: 1, code: "vec4(u_uniform$(id)$(index), 0, 0)", },
  { type: "vec3",        componentsPerRow: 3, rows: 1, code: "vec4(u_uniform$(id)$(index), 0)", },
  { type: "ivec3",       componentsPerRow: 3, rows: 1, code: "vec4(u_uniform$(id)$(index), 0)", },
  { type: "bvec3",       componentsPerRow: 3, rows: 1, code: "vec4(u_uniform$(id)$(index), 0)", },
  { type: "vec4",        componentsPerRow: 4, rows: 1, code: "vec4(u_uniform$(id)$(index))", },
  { type: "ivec4",       componentsPerRow: 4, rows: 1, code: "vec4(u_uniform$(id)$(index))", },
  { type: "bvec4",       componentsPerRow: 4, rows: 1, code: "vec4(u_uniform$(id)$(index))", },
// Yes, the spec says mat2 takes 4 columns, 2 rows.
  { type: "mat2",        componentsPerRow: 4, rows: 2, code: "vec4(u_uniform$(id)$(index)[0], 0, 0)", },
  { type: "mat3",        componentsPerRow: 3, rows: 3, code: "vec4(u_uniform$(id)$(index)[0], 0)", },
  { type: "mat4",        componentsPerRow: 4, rows: 4, code: "vec4(u_uniform$(id)$(index)[0])", },
// Samplers generally have more restictive limits.
//  { type: "sampler2D",   componentsPerRow: 1, rows: 1, code: "vec4(texture2D(u_uniform[$(index)], vec2(0, 0)))", },
//  { type: "samplerCube", componentsPerRow: 1, rows: 1, code: "vec4(textureCube(u_uniform[$(index)], vec3(0, 0, 0)))", },
];

var vBaseSource = wtu.getScript("vshader");
var fBaseSource = wtu.getScript("fshader");
var vArrayTestSource = wtu.getScript("vshaderArrayTest");
var fArrayTestSource = wtu.getScript("fshaderArrayTest");
var vUniformTestSource = wtu.getScript("vshaderUniformTest");
var fUniformTestSource = wtu.getScript("fshaderUniformTest");

var tests = [];
var shaderTypes = [
  { type: "vertex",
    // For tests that expect failure which shader might fail.
    vertExpectation: false,
    fragExpectation: true,
    vertArrayTest: vArrayTestSource,
    fragArrayTest: fBaseSource,
    vertUniformTest: vUniformTestSource,
    fragUniformTest: fBaseSource,
    maxVectors: gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS),
    minVectors: 128,  // GLSL ES 1.0.17 Appendix A.7,
  },
  { type: "fragment",
    // For tests that expect failure which shader might fail.
    vertExpectation: true,
    fragExpectation: false,
    vertArrayTest: vBaseSource,
    fragArrayTest: fArrayTestSource,
    vertUniformTest: vBaseSource,
    fragUniformTest: fUniformTestSource,
    maxVectors: gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS),
    minVectors: 16,  // GLSL ES 1.0.17 Appendix A.7,
  },
];
for (var ss = 0; ss < shaderTypes.length; ++ss) {
  var shaderType = shaderTypes[ss];
  debug("max " + shaderType.type + ": " + shaderType.maxVectors);
  for (var ii = 0; ii < uniformTypes.length; ++ii) {
    var info = uniformTypes[ii];
    wtu.log("checking: " + info.type);
    // Compute the maximum amount of this type allowed in a single array.
    var numVars = Math.floor(shaderType.maxVectors / info.rows);
    // Compute the minimum required to work in a single array.
    var minVars = Math.floor(shaderType.minVectors / info.rows);
    // Compute the maximum allowed as single elements
    var numPerRow = Math.floor(4 / info.componentsPerRow);
    var numMax = Math.floor(shaderType.maxVectors * numPerRow / info.rows);

    // Test array[max] of the type
    // Note: We can't test for success or failer as actual GL drivers are only required to be able to
    // do the minimum number. After that it can fail for any reason.
    var code = wtu.replaceParams(info.code, {id: "", index: "[" + (numVars - 1) + "]"});
    tests.push({
      vShaderSource: wtu.replaceParams(shaderType.vertArrayTest, {numTestType: numVars, code: code}, info),
      vShaderSuccess: true,
      fShaderSource: wtu.replaceParams(shaderType.fragArrayTest, {numTestType: numVars, code: code}, info),
      fShaderSuccess: true,
      linkSuccess: true,
      ignoreResults: true,
      passMsg: shaderType.type + " shader with uniform array of " + info.type + " with " + numVars + " elements (the maximum)",
    });

    var generateCode = function(numVars) {
      var uniforms = [];
      var codes = [];
      for (var uu = 0; uu < numVars; ++uu) {
        uniforms.push("    uniform " + info.type + " u_uniform" + uu + ";");
        codes.push(wtu.replaceParams(info.code, {id: uu, index: ""}));
      }
      return {
        uniforms: uniforms.join("\n"),
        code: codes.join(" + \n            "),
      };
    };

    // Test max uniforms of type.
    tests.push({
      vShaderSource: wtu.replaceParams(shaderType.vertUniformTest, generateCode(numMax), info),
      vShaderSuccess: shaderType.vertExpectation,
      fShaderSource: wtu.replaceParams(shaderType.fragUniformTest, generateCode(numMax), info),
      fShaderSuccess: shaderType.fragExpectation,
      linkSuccess: true,
      ignoreResults: true,
      passMsg: shaderType.type + " shader with " + (numMax) + " uniforms of " + info.type,
    });
  }
}
GLSLConformanceTester.runTests(tests);
var successfullyParsed = true;
</script>
</body>
</html>