shader-with-too-many-uniforms.html (3628B)
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 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 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> 17 </head> 18 <body> 19 <div id="description"></div> 20 <div id="console"></div> 21 <script id="vshader" type="x-shader/x-vertex"> 22 attribute vec4 a_position; 23 void main() 24 { 25 gl_Position = a_position; 26 } 27 </script> 28 <script id="vshader-max" type="x-shader/x-vertex"> 29 attribute vec4 a_position; 30 uniform vec4 u_color[$(maxUniformVectors)]; 31 void main() 32 { 33 vec4 v = vec4(0, 0, 0, 0); 34 for (int i = 0; i < $(maxUniformVectors); ++i) { 35 v = v + vec4(u_color[i]); 36 } 37 gl_Position = a_position + v; 38 } 39 </script> 40 <script id="fshader" type="x-shader/x-fragment"> 41 precision mediump float; 42 void main() 43 { 44 gl_FragColor = vec4(0, 1, 0, 1); 45 } 46 </script> 47 <script id="fshader-max" type="x-shader/x-fragment"> 48 precision mediump float; 49 uniform vec4 u_color[$(maxUniformVectors)]; 50 void main() 51 { 52 vec4 v = vec4(0, 0, 0, 0); 53 for (int i = 0; i < $(maxUniformVectors); ++i) { 54 v = v + vec4(u_color[i]); 55 } 56 gl_FragColor = v; 57 } 58 </script> 59 <script> 60 "use strict"; 61 description("checks shader with too many uniforms fails"); 62 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); 67 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; 75 76 var tests = [ 77 { desc: "using all uniforms in vertex shader should succeed", 78 maxUniformVectors: maxVertexUniformVectors - maxVectorStorageUsedForLiterals, 79 vShader: "vshader-max", 80 fShader: "fshader", 81 success: true, 82 }, 83 { desc: "using too many uniforms in vertex shader should fail", 84 maxUniformVectors: maxVertexUniformVectors + 1, 85 vShader: "vshader-max", 86 fShader: "fshader", 87 color: [0, 1, 0, 1], 88 success: false, 89 }, 90 { desc: "using all uniforms in fragment shader should succeed", 91 maxUniformVectors: maxFragmentUniformVectors - maxVectorStorageUsedForLiterals, 92 vShader: "vshader", 93 fShader: "fshader-max", 94 success: true, 95 }, 96 { desc: "using too many uniforms in fragment shader should fail", 97 maxUniformVectors: maxFragmentUniformVectors + 1, 98 vShader: "vshader", 99 fShader: "fshader-max", 100 color: [0, 1, 0, 1], 101 success: false, 102 }, 103 ]; 104 105 var glslTests = []; 106 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); 111 glslTests.push({ 112 vShaderSource: vSrc, 113 fShaderSource: fSrc, 114 linkSuccess: test.success, 115 passMsg: 'shader ' + test.desc, 116 }); 117 } 118 119 GLSLConformanceTester.runTests(glslTests); 120 var successfullyParsed = true; 121 </script> 122 </body> 123 </html>