diff options
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance/glsl/bugs/complex-glsl-does-not-crash.html')
-rw-r--r-- | dom/canvas/test/webgl-conf/checkout/conformance/glsl/bugs/complex-glsl-does-not-crash.html | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/bugs/complex-glsl-does-not-crash.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/bugs/complex-glsl-does-not-crash.html new file mode 100644 index 000000000..246e875c4 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/bugs/complex-glsl-does-not-crash.html @@ -0,0 +1,212 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!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> |