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 uniform unused array elements get truncated Conformance Test
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"example" width=
"2" height=
"2"> </canvas>
20 <script id=
"vshader" type=
"x-shader/x-vertex">
21 attribute vec4 a_position;
24 gl_Position = a_position;
27 <script id=
"fshader-max" type=
"x-shader/x-fragment">
28 precision mediump float;
29 uniform vec4 colora[$(numUniformVectors)];
32 gl_FragColor = vec4(colora[$(usedUniformVector)]);
39 var wtu
= WebGLTestUtils
;
40 var gl
= wtu
.create3DContext("example");
41 var vSrc
= wtu
.getScript("vshader");
43 // This test is to test drivers the have bugs related to optimizing
44 // an array of uniforms when only 1 of those uniforms is used.
46 var maxUniformVectors
= gl
.getParameter(gl
.MAX_FRAGMENT_UNIFORM_VECTORS
);
48 { desc
: "using 5th element",
49 maxUniformVectors
: maxUniformVectors
,
50 numUniformVectors
: maxUniformVectors
* 2,
52 shader
: "fshader-max",
58 // According to the spec unused array elements must be truncated.
59 var requiredUniformLocationsExist
;
60 function testUniformIssues(testIndex
) {
61 var test
= tests
[testIndex
];
64 var fSrc
= test
.source
;
66 fSrc
= wtu
.replaceParams(wtu
.getScript(test
.shader
), test
);
69 var consoleElem
= document
.getElementById("console");
71 consoleElem
, "vertex shader", vSrc
);
73 consoleElem
, "fragment shader", fSrc
);
75 var program
= wtu
.loadProgram(gl
, vSrc
, fSrc
);
76 gl
.useProgram(program
);
77 uniforms
= wtu
.getUniformMap(gl
, program
);
78 shouldBe('uniforms["' + test
.arrayName
+ '[0]"].size', (test
.usedUniformVector
+ 1).toString());
80 requiredUniformLocationsExist
= true;
81 for (var ii
= 0; ii
<= test
.usedUniformVector
+ 1; ++ii
) {
82 var name
= test
.arrayName
+ "[" + ii
+ "]";
83 var colorLocation
= gl
.getUniformLocation(program
, name
);
84 if (ii
<= test
.usedUniformVector
) {
86 requiredUniformLocationsExist
= false
90 testFailed("uniform array was not truncated as specified in OpenGL ES 2.0.25 section 2.10.4");
94 shouldBeTrue("requiredUniformLocationsExist");
98 function runNextTest() {
99 testUniformIssues(testIndex
++);
100 if (testIndex
< tests
.length
) {
101 setTimeout(runNextTest
, 0);
103 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "there should be no errors");
110 var successfullyParsed
= true;