Bug 1328559 - (flattened) Built-in attribs should have location of -1. - r=daoshengmu a=jcristau
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 04 Jan 2017 13:38:19 -0800
changeset 359300 71dcbe4ec7a105ac93e288d68e48c2f0824751c7
parent 359299 e0b425ab0e852c6fef7eaae8c7801070341d14a9
child 359301 c47060095bd6fe0f4db0c402376ad82406cbb0bc
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaoshengmu, jcristau
bugs1328559
milestone51.0
Bug 1328559 - (flattened) Built-in attribs should have location of -1. - r=daoshengmu a=jcristau But ANGLE gives back valid >=0 locations! MozReview-Commit-ID: 9zYiX5BGGud
dom/canvas/WebGLProgram.cpp
dom/canvas/test/webgl-conf/checkout/conformance2/00_test_list.txt
dom/canvas/test/webgl-conf/checkout/conformance2/programs/00_test_list.txt
dom/canvas/test/webgl-conf/checkout/conformance2/programs/active-built-in-attribs.html
dom/canvas/test/webgl-conf/checkout/conformance2/programs/gl-get-frag-data-location.html
dom/canvas/test/webgl-conf/generated-mochitest.ini
dom/canvas/test/webgl-conf/generated/test_2_conformance2__programs__active-built-in-attribs.html
dom/canvas/test/webgl-conf/generated/test_2_conformance2__programs__gl-get-frag-data-location.html
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -167,17 +167,17 @@ webgl::UniformInfo::UniformInfo(WebGLAct
 {
     if (mSamplerTexList) {
         mSamplerValues.assign(mActiveInfo->mElemCount, 0);
     }
 }
 
 //////////
 
-#define DUMP_SHADERVAR_MAPPINGS
+//#define DUMP_SHADERVAR_MAPPINGS
 
 static already_AddRefed<const webgl::LinkedProgramInfo>
 QueryProgramInfo(WebGLProgram* prog, gl::GLContext* gl)
 {
     WebGLContext* const webgl = prog->mContext;
 
     RefPtr<webgl::LinkedProgramInfo> info(new webgl::LinkedProgramInfo(prog));
 
@@ -235,22 +235,29 @@ QueryProgramInfo(WebGLProgram* prog, gl:
 
         nsCString userName;
         if (!prog->FindAttribUserNameByMappedName(mappedName, &userName)) {
             userName = mappedName;
         }
 
         ///////
 
-        const GLint loc = gl->fGetAttribLocation(prog->mGLName,
-                                                 mappedName.BeginReading());
+        GLint loc = gl->fGetAttribLocation(prog->mGLName,
+                                           mappedName.BeginReading());
+        if (gl->WorkAroundDriverBugs() &&
+            mappedName.EqualsIgnoreCase("gl_", 3))
+        {
+            // Bug 1328559: Appears problematic on ANGLE and OSX, but not Linux or Win+GL.
+            loc = -1;
+        }
 #ifdef DUMP_SHADERVAR_MAPPINGS
         printf_stderr("[attrib %u/%u] @%i %s->%s\n", i, numActiveAttribs, loc,
                       userName.BeginReading(), mappedName.BeginReading());
 #endif
+        MOZ_ASSERT_IF(mappedName.EqualsIgnoreCase("gl_", 3), loc == -1);
 
         ///////
 
         const bool isArray = false;
         const RefPtr<WebGLActiveInfo> activeInfo = new WebGLActiveInfo(webgl, elemCount,
                                                                        elemType, isArray,
                                                                        userName,
                                                                        mappedName);
--- a/dom/canvas/test/webgl-conf/checkout/conformance2/00_test_list.txt
+++ b/dom/canvas/test/webgl-conf/checkout/conformance2/00_test_list.txt
@@ -1,14 +1,15 @@
 attribs/00_test_list.txt
 buffers/00_test_list.txt
 context/00_test_list.txt
 extensions/00_test_list.txt
 glsl3/00_test_list.txt
 misc/00_test_list.txt
+programs/00_test_list.txt
 query/00_test_list.txt
 reading/00_test_list.txt
 renderbuffers/00_test_list.txt
 rendering/00_test_list.txt
 samplers/00_test_list.txt
 state/00_test_list.txt
 textures/00_test_list.txt
 transform_feedback/00_test_list.txt
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/00_test_list.txt
@@ -0,0 +1,2 @@
+active-built-in-attribs.html
+gl-get-frag-data-location.html
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/active-built-in-attribs.html
@@ -0,0 +1,107 @@
+<!--
+
+/*
+** Copyright (c) 2016 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>WebGL Conformance Tests: Verify validation for active built-in attribs</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/desktop-gl-constants.js"></script>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<canvas id="canvas" style="width: 64px; height: 64px;"> </canvas>
+<div id="console"></div>
+<script id="vs" type="x-shader/x-vertex">#version 300 es
+void main() {
+  gl_Position = vec4(gl_VertexID % 2, (gl_VertexID/2) % 2, 0, 1);
+}
+</script>
+
+<script id="fs" type="x-shader/x-fragment">#version 300 es
+precision mediump float;
+out vec4 fragColor;
+void main() {
+  fragColor = vec4(0, 1, 0, 1);
+}
+</script>
+
+<script>
+"use strict";
+description("This test verifies validation for active built-in attribs.");
+
+debug("");
+
+var wtu = WebGLTestUtils;
+var canvas = document.getElementById("canvas");
+var gl = wtu.create3DContext(canvas, null, 2);
+
+if (!gl) {
+  testFailed("WebGL context does not exist");
+} else {
+  testPassed("WebGL context exists");
+  runTests();
+}
+
+var activeInfo, attribLoc;
+
+function runTests() {
+  var prog = wtu.setupProgram(gl, ["vs", "fs"]);
+  if (!prog) {
+    testFailed("Set up program failed");
+    return;
+  }
+  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from set up");
+
+  var numActive = gl.getProgramParameter(prog, gl.ACTIVE_ATTRIBUTES);
+  if (numActive != 1) {
+    testFailed('ACTIVE_ATTRIBUTES should be 1.');
+    return;
+  }
+  testPassed('ACTIVE_ATTRIBUTES should be 1.');
+
+  activeInfo = gl.getActiveAttrib(prog, 0);
+  if (!activeInfo) {
+    testFailed('getActiveAttrib should return an info object.');
+    return;
+  }
+
+  shouldBe('activeInfo.name', '"gl_VertexID"');
+  attribLoc = gl.getAttribLocation(prog, 'gl_VertexID');
+  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be able to request the location of a built-in.");
+  shouldBe('attribLoc', '-1');
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../../js/js-test-post.js"></script>
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/gl-get-frag-data-location.html
@@ -0,0 +1,121 @@
+<!--
+
+/*
+** Copyright (c) 2016 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>WebGL Conformance Tests: Verify getFragDataLocation</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/desktop-gl-constants.js"></script>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<canvas id="canvas" style="width: 4px; height: 4px;"> </canvas>
+<div id="console"></div>
+<script id="vs" type="x-shader/x-vertex">#version 300 es
+void main() {
+  gl_Position = vec4(0, 0, 0, 1);
+}
+</script>
+
+<script id="fs" type="x-shader/x-fragment">#version 300 es
+precision mediump float;
+layout(location = 2) out vec4 fragColor0;
+layout(location = 0) out vec4 fragColor1;
+void main() {
+  fragColor0 = vec4(0, 1, 0, 1);
+  fragColor1 = vec4(1, 0, 0, 1);
+}
+</script>
+
+<script id="fs-array" type="x-shader/x-fragment">#version 300 es
+precision mediump float;
+out vec4 fragColor[2];
+void main() {
+  fragColor[0] = vec4(0, 1, 0, 1);
+  fragColor[1] = vec4(1, 0, 0, 1);
+}
+</script>
+
+<script>
+"use strict";
+description("This test verifies getFragDataLocation behaviors.");
+
+debug("");
+
+var wtu = WebGLTestUtils;
+var canvas = document.getElementById("canvas");
+var gl = wtu.create3DContext(canvas, null, 2);
+
+if (!gl) {
+  testFailed("WebGL context does not exist");
+} else {
+  testPassed("WebGL context exists");
+  runTests();
+}
+
+function runTests() {
+  var program = wtu.setupProgram(gl, ["vs", "fs"]);
+  var programArray = wtu.setupProgram(gl, ["vs", "fs-array"]);
+  if (!program || !programArray) {
+    testFailed("Set up program failed");
+    return;
+  }
+  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from set up");
+
+  var loc0 = gl.getFragDataLocation(program, "fragColor0");
+  var loc1 = gl.getFragDataLocation(program, "fragColor1");
+  if (loc0 != 2 || loc1 != 0) {
+    testFailed("Fail to query scalar output variable locations, " +
+               "expected: fragColor0->2, fragColor1->0, " +
+               "got: fragColor0->" + loc0 + ", fragColor1->" + loc1);
+  } else {
+    testPassed("getFragDataLocation on scalar variables works fine");
+  }
+
+  var loc = gl.getFragDataLocation(programArray, "fragColor");
+  loc0 = gl.getFragDataLocation(programArray, "fragColor[0]");
+  loc1 = gl.getFragDataLocation(programArray, "fragColor[1]");
+  if (loc < 0 || loc0 < 0 || loc1 < 0 || loc != loc0 || loc0 + 1 != loc1) {
+    testFailed("Fail to query scalar output variable locations, " +
+               "expected: fragColor->0, fragColor[0]->0, fragColor[1]->1, " +
+               "got: fragColor->" + loc + ", fragColor[0]->" + loc0 + ", fragColor[1]->" + loc1);
+  } else {
+    testPassed("getFragDataLocation on variable arrays works fine");
+  }
+  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from testing");
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../../js/js-test-post.js"></script>
+
+</body>
+</html>
--- a/dom/canvas/test/webgl-conf/generated-mochitest.ini
+++ b/dom/canvas/test/webgl-conf/generated-mochitest.ini
@@ -2451,16 +2451,19 @@ support-files = always-fail.html
                 checkout/conformance2/glsl3/short-circuiting-in-loop-condition.html
                 checkout/conformance2/glsl3/texture-offset-out-of-range.html
                 checkout/conformance2/glsl3/uniform-location-length-limits.html
                 checkout/conformance2/glsl3/vector-dynamic-indexing.html
                 checkout/conformance2/misc/00_test_list.txt
                 checkout/conformance2/misc/expando-loss-2.html
                 checkout/conformance2/misc/instanceof-test.html
                 checkout/conformance2/misc/uninitialized-test-2.html
+                checkout/conformance2/programs/00_test_list.txt
+                checkout/conformance2/programs/active-built-in-attribs.html
+                checkout/conformance2/programs/gl-get-frag-data-location.html
                 checkout/conformance2/query/00_test_list.txt
                 checkout/conformance2/query/occlusion-query.html
                 checkout/conformance2/query/query.html
                 checkout/conformance2/reading/00_test_list.txt
                 checkout/conformance2/reading/read-pixels-from-fbo-test.html
                 checkout/conformance2/reading/read-pixels-into-pixel-pack-buffer.html
                 checkout/conformance2/reading/read-pixels-pack-parameters.html
                 checkout/conformance2/renderbuffers/00_test_list.txt
@@ -4542,16 +4545,20 @@ skip-if = (os == 'win' && debug) || (os 
 [generated/test_2_conformance2__glsl3__vector-dynamic-indexing.html]
 skip-if = (os == 'win') || (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
 [generated/test_2_conformance2__misc__expando-loss-2.html]
 skip-if = (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
 [generated/test_2_conformance2__misc__instanceof-test.html]
 skip-if = (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
 [generated/test_2_conformance2__misc__uninitialized-test-2.html]
 skip-if = (os == 'mac') || (os == 'win') || (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
+[generated/test_2_conformance2__programs__active-built-in-attribs.html]
+skip-if = (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
+[generated/test_2_conformance2__programs__gl-get-frag-data-location.html]
+skip-if = (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
 [generated/test_2_conformance2__query__occlusion-query.html]
 skip-if = (os == 'win') || (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
 [generated/test_2_conformance2__query__query.html]
 skip-if = (os == 'win') || (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
 [generated/test_2_conformance2__reading__read-pixels-from-fbo-test.html]
 skip-if = (os == 'mac') || (os == 'win') || (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
 [generated/test_2_conformance2__reading__read-pixels-into-pixel-pack-buffer.html]
 skip-if = (os == 'android' || os == 'linux' || (os == 'win' && os_version == '5.1'))
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/generated/test_2_conformance2__programs__active-built-in-attribs.html
@@ -0,0 +1,17 @@
+<!-- GENERATED FILE, DO NOT EDIT -->
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <meta charset='utf-8'/>
+    <title>
+      Mochitest wrapper for WebGL Conformance Test Suite tests
+    </title>
+    <link rel='stylesheet' type='text/css' href='../iframe-passthrough.css'/>
+
+    <script src='/tests/SimpleTest/SimpleTest.js'></script>
+    <link rel='stylesheet' type='text/css' href='/tests/SimpleTest/test.css'/>
+  </head>
+  <body>
+    <iframe src='../mochi-single.html?checkout/conformance2/programs/active-built-in-attribs.html?webglVersion=2'></iframe>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/generated/test_2_conformance2__programs__gl-get-frag-data-location.html
@@ -0,0 +1,17 @@
+<!-- GENERATED FILE, DO NOT EDIT -->
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <meta charset='utf-8'/>
+    <title>
+      Mochitest wrapper for WebGL Conformance Test Suite tests
+    </title>
+    <link rel='stylesheet' type='text/css' href='../iframe-passthrough.css'/>
+
+    <script src='/tests/SimpleTest/SimpleTest.js'></script>
+    <link rel='stylesheet' type='text/css' href='/tests/SimpleTest/test.css'/>
+  </head>
+  <body>
+    <iframe src='../mochi-single.html?checkout/conformance2/programs/gl-get-frag-data-location.html?webglVersion=2'></iframe>
+  </body>
+</html>