gecko/content/canvas/test/webgl/conformance/glsl-conformance.html
Benoit Jacob 2c0eb7e54e Bug 657748 - Update ANGLE to r653 - a=joe
This ANGLE update fixes bugs, brings large performance improvements, and adds major new features that web devs are looking forward to: vertex shader texture lookup and float textures.

http://code.google.com/p/angleproject/

This update is also needed because the version we're currently using is the chrome_m10 branch and that's no longer maintained. This update will make it much easier to apply security fixes if needed.
2011-05-24 11:05:56 -04:00

723 lines
22 KiB
HTML
Raw Blame History

<!--
Copyright (c) 2009 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WebGL GLSL Conformance Tests</title>
<link rel="stylesheet" href="../resources/js-test-style.css"/>
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
<script src="../resources/js-test-pre.js"></script>
<script src="resources/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshader" type="text/something-not-javascript">
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithPrecision" type="text/something-not-javascript">
void main()
{
gl_FragColor = mediump vec4(1.0,0.0,0.0,1.0);
}
</script>
<script id="vshaderWithDefaultPrecision" type="text/something-not-javascript">
precision mediump float;
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshaderWithDefaultPrecision" type="text/something-not-javascript">
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithOutPrecision" type="text/something-not-javascript">
uniform vec4 color;
void main()
{
gl_FragColor = color;
}
</script>
<script id="fshaderWithInvalidIdentifier" type="text/something-not-javascript">
precision mediump float;
uniform float gl_foo;
void main()
{
gl_FragColor = vec4(gl_foo,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithGL_ESeq1" type="text/something-not-javascript">
#if GL_ES == 1
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
#else
foo
#endif
</script>
<script id="fshaderWithGLSLPreprocessorSymbol" type="text/something-not-javascript">
#if defined(GL_ES)
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
#else
foo
#endif
</script>
<script id="fshaderWithVERSION100PreprocessorSymbol" type="text/something-not-javascript">
#if __VERSION__ == 100
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
#else
foo
#endif
</script>
<script id="fshaderWithUndefinedPreprocessorSymbol" type="text/something-not-javascript">
#if UNDEFINED_FOO
// according to ES GLSL spec 3.4 undefined symbols should fail.
#else
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
#endif
</script>
<script id="fshaderWithFragDepth" type="text/something-not-javascript">
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
gl_FragDepth = 1.0;
}
</script>
<script id="vshaderWithClipVertex" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
gl_ClipVertex = vPosition;
}
</script>
<script id="fshaderWith__Define" type="text/something-not-javascript">
#define __foo 1
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithGL_Define" type="text/something-not-javascript">
#define GL_FOO 1
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithDefineLineContinuation" type="text/something-not-javascript">
#define foo this \
is a test
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
</script>
<script id="vshaderWithgl_Color" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
gl_Position = gl_Color;
}
</script>
<script id="vshaderWithgl_ProjectionMatrix" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition * gl_ProjectionMatrix;
}
</script>
<script id="vshaderWithAttributeArray" type="text/something-not-javascript">
attribute vec4 vPosition[2];
void main()
{
gl_Position = vPosition[0] + vPosition[1];
}
</script>
<script id="vshaderWithwebgl_" type="text/something-not-javascript">
attribute vec4 webgl_vPosition;
void main()
{
gl_Position = webgl_vPosition;
}
</script>
<script id="vshaderWith_webgl_" type="text/something-not-javascript">
attribute vec4 _webgl_vPosition;
void main()
{
gl_Position = _webgl_vPosition;
}
</script>
<script id="vshaderWithImplicitVec3Cast" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
highp vec3 k = vec3(1, 2, 3);
gl_Position = k;
}
</script>
<script id="vshaderWithExplicitIntCast" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
int k = 123;
gl_Position = vec4(vPosition.x, vPosition.y, vPosition.z, float(k));
}
</script>
<script id="vshaderWithVersion130" type="text/something-not-javascript">
#version 130
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="vshaderWithVersion120" type="text/something-not-javascript">
#version 120
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="vshaderWithVersion100" type="text/something-not-javascript">
#version 100
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="vshaderWithLineDirective" type="text/something-not-javascript">
#line 123
foo
</script>
<script id="vshaderWith__FILE__" type="text/something-not-javascript">
__FILE__
</script>
<script id="vshaderWithIncludeDirective" type="text/something-not-javascript">
// Sadly I can not force the current path so this could fail beacuse include.vs
// does not exist, not because #include is disallowed.
#include "include.vs"
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshaderWithdFdx" type="text/something-not-javascript">
#extension GL_OES_standard_derivatives:enable
precision mediump float;
void main()
{
gl_FragColor = vec4(dFdx(0.5),0.0,0.0,1.0);
}
</script>
<script id="fshaderWithdFdxNoExt" type="text/something-not-javascript">
precision mediump float;
void main()
{
gl_FragColor = vec4(dFdx(0.5),0.0,0.0,1.0);
}
</script>
<script id="fshaderWith256CharacterIdentifier" type="text/something-not-javascript">
precision mediump float;
uniform float a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345;
void main()
{
gl_FragColor = vec4(a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345,0.0,0.0,1.0);
}
</script>
<script id="fshaderWith257CharacterIdentifier" type="text/something-not-javascript">
precision mediump float;
uniform float a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
void main()
{
gl_FragColor = vec4(a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithLongLine" type="text/something-not-javascript">
precision mediump float;
uniform float fooo;
#if defined(someSymbolNotDefined)
#error long
#endif
void main()
{
gl_FragColor = vec4(fooo+fooo+fooo+fooo, fooo+fooo+fooo+fooo, fooo+fooo+fooo+fooo, 1.0);
}
</script>
<script id="fshaderWithErrorDirective" type="text/something-not-javascript">
#error testing123 testing123
void main()
{
gl_FragColor = vec4(0,0,0,0);
}
</script>
<script id="fshaderWithQuotedErrorDirective" type="text/something-not-javascript">
#error "testing123 testing123" // will return INVALID_VALUE. See WebGL 6.18
void main()
{
gl_FragColor = vec4(0,0,0,0);
}
</script>
<script id="fshaderWithNonASCIIErrorDirective" type="text/something-not-javascript">
#error <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Í‚`<EFBFBD>r<EFBFBD>b<EFBFBD>h<EFBFBD>h<EFBFBD>Å‚Í‚È‚<EFBFBD> // will return INVALID_VALUE. See WebGL 6.18
void main()
{
gl_FragColor = vec4(0,0,0,0);
}
</script>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
description("This test ensures WebGL implementations allow proper GLES2 shaders compile and improper ones fail.");
debug("");
debug("Canvas.getContext");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext(document.getElementById("canvas"));
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
debug("Checking various GLSL programs.");
function log(msg) {
if (window.console && window.console.log) {
window.console.log(msg);
}
}
var shaderInfo = [
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithPrecision',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'frament shader with precision compiled and linked'
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithDefaultPrecision',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'fragment shader with default precision compiled and linked'
},
{ vShaderId: 'vshaderWithDefaultPrecision',
vShaderSuccess: true,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'vertex shader with default precision compiled and linked'
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithOutPrecision',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader without precision should fail',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithInvalidIdentifier',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader with gl_ identifier should fail',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithGL_ESeq1',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'fragment shader that expects GL_ES == 1 should succeed',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithGLSLPreprocessorSymbol',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'fragment shader that uses GL_ES preprocessor symbol should succeed',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithVERSION100PreprocessorSymbol',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'fragment shader that uses __VERSION__==100 should succeed',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithUndefinedPreprocessorSymbol',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader undefined preprocessor symbol should fail (3.4)',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithFragDepth',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader that uses gl_FragDepth should fail',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithdFdx',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader that uses dFdx should fail',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithdFdxNoExt',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader that uses dFdx without #extension should fail',
},
{ vShaderId: 'vshaderWithClipVertex',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses gl_ClipVertex should fail',
},
//{ vShaderId: 'vshader',
// vShaderSuccess: true,
// fShaderId: 'fshaderWith__Define',
// fShaderSuccess: false,
// linkSuccess: false,
// passMsg: 'fragment shader that uses __ define should fail',
//},
//{ vShaderId: 'vshader',
// vShaderSuccess: true,
// fShaderId: 'fshaderWithGL_Define',
// fShaderSuccess: false,
// linkSuccess: false,
// passMsg: 'fragment shader that uses GL_ define should fail',
//},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithDefineLineContinuation',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader that uses has line continuation macro should fail',
},
{ vShaderId: 'vshaderWithgl_Color',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses gl_Color should fail',
},
{ vShaderId: 'vshaderWithgl_ProjectionMatrix',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses gl_ProjectionMatrix should fail',
},
{ vShaderId: 'vshaderWithAttributeArray',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses attribute array should fail as per GLSL page 110, appendix A, section 5',
},
{ vShaderId: 'vshaderWithwebgl_',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses _webgl identifier should fail',
},
{ vShaderId: 'vshaderWith_webgl_',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses _webgl_ identifier should fail',
},
{ vShaderId: 'vshaderWithExplicitIntCast',
vShaderSuccess: true,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'vertex shader that explicit int to float cast should succeed',
},
{ vShaderId: 'vshaderWithImplicitVec3Cast',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that implicit vec3 to vec4 cast should fail',
},
{ vShaderId: 'vshaderWithVersion130',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader uses the #version not 100 directive should fail',
},
{ vShaderId: 'vshaderWithVersion120',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader uses the #version not 100 directive should fail',
},
{ vShaderId: 'vshaderWithVersion100',
vShaderSuccess: true,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'vertex shader uses the #version 100 directive should succeed',
},
{ vShaderId: 'vshaderWithLineDirective',
vShaderSuccess: false,
vShaderTest: (function() { return wtu.getLastError().indexOf("124") >= 0; }),
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader uses #line directive should report correct line',
},
{ vShaderId: 'vshaderWithIncludeDirective',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader uses #include should fail',
},
//{ vShaderId: 'vshader',
// vShaderSuccess: true,
// fShaderId: 'fshaderWith257CharacterIdentifier',
// fShaderSuccess: false,
// linkSuccess: false,
// passMsg: 'shader that uses 257 character identifier should fail',
//},
//{ vShaderId: 'vshader',
// vShaderSuccess: true,
// fShaderId: 'fshaderWith256CharacterIdentifier',
// fShaderSuccess: true,
// linkSuccess: true,
// passMsg: 'shader that uses 256 character identifier should succeed',
//},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithLongLine',
fShaderSuccess: true,
fShaderPrep: function(str) {
function expand(str, re, replacement, count) {
for (var ii = 0; ii < count; ++ii) {
str = str.replace(re, replacement);
}
return str;
}
str = expand(str, new RegExp(" ", 'g'), " ", 12);
str = expand(str, new RegExp("0", 'g'), "00", 8);
str = expand(str, new RegExp("fooo", 'g'), "fooofooo", 6);
str = expand(str, new RegExp("long", 'g'), "longlong", 6);
//debug("len:" + str.length);
//debug(str);
return str;
},
linkSuccess: true,
passMsg: 'shader that uses long lines should succeed',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithErrorDirective',
fShaderSuccess: false,
fShaderTest: (function() {
return wtu.getLastError().indexOf("testing123 testing123") >= 0; }),
linkSuccess: false,
passMsg: "error directive returns error user's error message",
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithQuotedErrorDirective',
fShaderSuccess: false,
linkSuccess: false,
passMsg: "error directive using quotes fails",
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithNonASCIIErrorDirective',
fShaderSuccess: false,
linkSuccess: false,
passMsg: "error directive using characters outside of allowed set fails",
}
];
// Read in all the shader source.
for (var ii = 0; ii < shaderInfo.length; ++ii) {
var si = shaderInfo[ii];
si.vShaderSource = document.getElementById(si.vShaderId).text;
si.fShaderSource = document.getElementById(si.fShaderId).text;
}
// Add more tests from external file
var simpleVertShader = document.getElementById('vshader').text;
var simpleFragShader = document.getElementById('fshader').text;
function addExternalShaders(filename, passMsg) {
var files = wtu.readFileList(filename);
for (var ii = 0; ii < files.length; ++ii) {
var file = files[ii];
var shaderSource = wtu.readFile(file);
var firstLine = shaderSource.split("\n")[0];
var success = undefined;
if (wtu.endsWith(firstLine, " fail") ||
wtu.endsWith(firstLine, " fail.")) {
success = false;
} else if (wtu.endsWith(firstLine, " succeed") ||
wtu.endsWith(firstLine, " succeed.")) {
success = true;
}
if (success === undefined) {
testFailed("bad first line in " + file);
continue;
}
if (!wtu.startsWith(firstLine, "// ")) {
testFailed("bad first line in " + file);
continue;
}
var passMsg = firstLine.substr(3);
if (wtu.endsWith(file, ".vert")) {
shaderInfo.push({
vShaderId: file,
vShaderSource: shaderSource,
vShaderSuccess: success,
fShaderId: 'fshader',
fShaderSource: simpleFragShader,
fShaderSuccess: true,
linkSuccess: success,
passMsg: passMsg,
});
} else if (wtu.endsWith(file, ".frag")) {
shaderInfo.push({
vShaderId: 'vshader',
vShaderSource: simpleVertShader,
vShaderSuccess: true,
fShaderId: file,
fShaderSource: shaderSource,
fShaderSuccess: success,
linkSuccess: success,
passMsg: passMsg,
});
}
}
}
addExternalShaders('shaders/00_shaders.txt');
for (var ii = 0; ii < shaderInfo.length; ++ii) {
var info = shaderInfo[ii];
var passMsg = '[' + info.vShaderId + '/' + info.fShaderId + ']: ' +
info.passMsg
log(passMsg);
//debug(info.fShaderId);
var vSource = info.vShaderPrep ? info.vShaderPrep(info.vShaderSource) :
info.vShaderSource;
var vShader = wtu.loadShader(gl, vSource, gl.VERTEX_SHADER);
if (info.vShaderTest) {
if (!info.vShaderTest(vShader)) {
testFailed(passMsg);
continue;
}
}
if ((vShader != null) != info.vShaderSuccess) {
testFailed(passMsg);
continue;
}
var fSource = info.fShaderPrep ? info.fShaderPrep(info.fShaderSource) :
info.fShaderSource;
var fShader = wtu.loadShader(gl, fSource, gl.FRAGMENT_SHADER);
if (info.fShaderTest) {
if (!info.fShaderTest(fShader)) {
testFailed(passMsg);
continue;
}
}
//debug(fShader == null ? "fail" : "succeed");
if ((fShader != null) != info.fShaderSuccess) {
testFailed(passMsg);
continue;
}
if (vShader && fShader) {
var program = gl.createProgram();
gl.attachShader(program, vShader);
gl.attachShader(program, fShader);
gl.linkProgram(program);
var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
if (!linked) {
var error = gl.getProgramInfoLog(program);
log("*** Error linking program '"+program+"':"+error);
}
if (linked != info.linkSuccess) {
testFailed(passMsg);
continue;
}
} else {
if (info.linkSuccess) {
testFailed(passMsg);
continue;
}
}
testPassed(passMsg);
}
}
debug("");
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>
<script>
</script>
</body>
</html>