Title: [156351] trunk
Revision
156351
Author
[email protected]
Date
2013-09-24 12:43:22 -0700 (Tue, 24 Sep 2013)

Log Message

Use mapped name in attribute location binding
https://bugs.webkit.org/show_bug.cgi?id=121847
<rdar://problem/15067526>

Reviewed by Eric Carlson.

Source/WebCore:

The shader that we send down to OpenGL to compile
may have been translated by ANGLE, so we keep a
table around that maps input symbols to output symbols.
We used the table when binding to and looking up
uniforms, and when looking up attributes, but not
when actually binding to attribute locations.

Test: fast/canvas/webgl/gl-bind-attrib-mapped-names.html

* platform/graphics/ANGLEWebKitBridge.cpp:
(WebCore::getSymbolInfo): Add logging of symbol mapping.
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::bindAttribLocation): Used the mapped name.
(WebCore::GraphicsContext3D::getAttribLocation): Remove comment since
we do the lookup everywhere.
(WebCore::GraphicsContext3D::getUniformLocation): Ditto.

LayoutTests:

New test that has an attribute name long enough
to trigger symbol mapping in all cases.

* fast/canvas/webgl/gl-bind-attrib-mapped-names-expected.txt: Added.
* fast/canvas/webgl/gl-bind-attrib-mapped-names.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (156350 => 156351)


--- trunk/LayoutTests/ChangeLog	2013-09-24 19:35:30 UTC (rev 156350)
+++ trunk/LayoutTests/ChangeLog	2013-09-24 19:43:22 UTC (rev 156351)
@@ -1,3 +1,17 @@
+2013-09-24  Dean Jackson  <[email protected]>
+
+        Use mapped name in attribute location binding
+        https://bugs.webkit.org/show_bug.cgi?id=121847
+        <rdar://problem/15067526>
+
+        Reviewed by Eric Carlson.
+
+        New test that has an attribute name long enough
+        to trigger symbol mapping in all cases.
+
+        * fast/canvas/webgl/gl-bind-attrib-mapped-names-expected.txt: Added.
+        * fast/canvas/webgl/gl-bind-attrib-mapped-names.html: Added.
+
 2013-09-24  Bem Jones-Bey  <[email protected]>
 
         Properly handle bottom margin on float with shape-outside

Added: trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names-expected.txt (0 => 156351)


--- trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names-expected.txt	2013-09-24 19:43:22 UTC (rev 156351)
@@ -0,0 +1,27 @@
+This test ensures WebGL implementations don't allow names that start with 'gl_' when calling bindAttribLocation.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Canvas.getContext
+PASS [object WebGLRenderingContext] is non-null.
+
+Checking gl.bindAttribLocation.
+PASS program linked successfully
+vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ:3
+vColor   :2
+PASS location of vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ should be 3
+PASS location of vColor should be 2
+PASS drawing is correct
+PASS program linked successfully
+vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ:3
+vColor   :0
+PASS location of vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ should be 3
+PASS location of vColor should be 0
+PASS drawing is correct
+PASS getError was expected value: NO_ERROR : 
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names-expected.txt
___________________________________________________________________

Added: svn:mime-type

Added: svn:keywords

Added: svn:eol-style

Added: trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names.html (0 => 156351)


--- trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names.html	2013-09-24 19:43:22 UTC (rev 156351)
@@ -0,0 +1,193 @@
+<!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 BindAttribLocation Mapped Names Conformance Test</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<canvas style="border: 1px solid black;" id="canvas" width="50" height="50"></canvas>
+<script id="vshader" type="text/something-not-_javascript_">
+attribute vec4 vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ;
+attribute vec4 vColor;
+varying vec4 color;
+void main()
+{
+  gl_Position = vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ;
+  color = vColor;
+}
+</script>
+<script id="fshader" type="text/something-not-_javascript_">
+#ifdef GL_ES
+precision highp float;
+#endif
+varying vec4 color;
+void main()
+{
+  gl_FragColor = color;
+}
+</script>
+<script>
+description("This test ensures WebGL implementations don't allow names that start with 'gl_' when calling bindAttribLocation.");
+
+if (window.internals)
+    window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
+
+debug("");
+debug("Canvas.getContext");
+
+var gl = create3DContext(document.getElementById("canvas"));
+shouldBeNonNull(gl);
+
+function fail(x,y, buf, shouldBe)
+{
+  var i = (y*50+x) * 4;
+  var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
+  testFailed(reason);
+}
+
+function pass()
+{
+  testPassed("drawing is correct");
+}
+
+function loadShader(shaderType, shaderId) {
+  // Get the shader source.
+  var shaderSource = document.getElementById(shaderId).text;
+
+  // Create the shader object
+  var shader = gl.createShader(shaderType);
+  if (shader == null) {
+    debug("*** Error: unable to create shader '"+shaderId+"'");
+    return null;
+  }
+
+  // Load the shader source
+  gl.shaderSource(shader, shaderSource);
+
+  // Compile the shader
+  gl.compileShader(shader);
+
+  // Check the compile status
+  var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
+  if (!compiled) {
+    // Something went wrong during compilation; get the error
+    var error = gl.getShaderInfoLog(shader);
+    debug("*** Error compiling shader '"+shader+"':"+error);
+    gl.deleteShader(shader);
+    return null;
+  }
+  return shader;
+}
+
+debug("");
+debug("Checking gl.bindAttribLocation.");
+
+var program = gl.createProgram();
+
+var vs = loadShader(gl.VERTEX_SHADER, "vshader");
+var fs = loadShader(gl.FRAGMENT_SHADER, "fshader");
+gl.attachShader(program, vs);
+gl.attachShader(program, fs);
+
+var positions = gl.createBuffer();
+gl.bindBuffer(gl.ARRAY_BUFFER, positions);
+gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
+
+var colors = gl.createBuffer();
+gl.bindBuffer(gl.ARRAY_BUFFER, colors);
+gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
+    0,1,0,1,
+    0,1,0,1,
+    0,1,0,1]), gl.STATIC_DRAW);
+
+function setBindLocations(colorLocation, positionLocation) {
+  gl.bindAttribLocation(program, positionLocation, "vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ");
+  gl.bindAttribLocation(program, colorLocation, "vColor");
+  gl.linkProgram(program);
+  gl.useProgram(program);
+  var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
+  assertMsg(linked, "program linked successfully");
+
+  debug("vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ:" + gl.getAttribLocation(program, "vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ"))
+  debug("vColor   :" + gl.getAttribLocation(program, "vColor"))
+  assertMsg(gl.getAttribLocation(program, "vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ") == positionLocation,
+            "location of vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ should be " + positionLocation);
+  assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation,
+            "location of vColor should be " + colorLocation);
+
+  var ploc = gl.getAttribLocation(program, "vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ");
+  var cloc = gl.getAttribLocation(program, "vColor");
+  gl.bindBuffer(gl.ARRAY_BUFFER, positions);
+  gl.enableVertexAttribArray(positionLocation);
+  gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
+  gl.bindBuffer(gl.ARRAY_BUFFER, colors);
+  gl.enableVertexAttribArray(colorLocation);
+  gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
+}
+
+function checkDraw(colorLocation, positionLocation, r, g, b, a) {
+  gl.clearColor(0, 0, 0, 1);
+  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+  gl.drawArrays(gl.TRIANGLES, 0, 3);
+
+  var width = 50;
+  var height = 50;
+  var buf = new Uint8Array(width * height * 4);
+  gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
+
+  function checkPixel(x, y, r, g, b, a) {
+    var offset = (y * width + x) * 4;
+    if (buf[offset + 0] != r ||
+        buf[offset + 1] != g ||
+        buf[offset + 2] != b ||
+        buf[offset + 3] != a) {
+        fail(x, y, buf, "(" + r + "," + g + "," + b + "," + a + ")");
+        return false;
+    }
+    return true;
+  }
+
+  // Test several locations
+  // First line should be all black
+  var success = true;
+  for (var i = 0; i < 50; ++i)
+    success = success && checkPixel(i, 0, 0, 0, 0, 255);
+
+  // Line 15 should be red for at least 10 rgba pixels starting 20 pixels in
+  var offset = (15 * 50 + 20) * 4;
+  for (var i = 0; i < 10; ++i)
+    success = success && checkPixel(20 + i, 15, r, g, b, a);
+
+  // Last line should be all black
+  for (var i = 0; i < 50; ++i)
+    success = success && checkPixel(i, 49, 0, 0, 0, 255);
+
+  if (success)
+    pass();
+
+  gl.disableVertexAttribArray(positionLocation);
+  gl.disableVertexAttribArray(colorLocation);
+}
+
+setBindLocations(2, 3);
+checkDraw(2, 3, 0, 255, 0, 255);
+
+setBindLocations(0, 3);
+gl.disableVertexAttribArray(0);
+gl.vertexAttrib4f(0, 1, 0, 0, 1);
+checkDraw(0, 3, 255, 0, 0, 255);
+
+glErrorShouldBe(gl, gl.NO_ERROR);
+
+debug("");
+
+</script>
+<script src=""
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names.html
___________________________________________________________________

Added: svn:mime-type

Added: svn:keywords

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (156350 => 156351)


--- trunk/Source/WebCore/ChangeLog	2013-09-24 19:35:30 UTC (rev 156350)
+++ trunk/Source/WebCore/ChangeLog	2013-09-24 19:43:22 UTC (rev 156351)
@@ -1,3 +1,28 @@
+2013-09-24  Dean Jackson  <[email protected]>
+
+        Use mapped name in attribute location binding
+        https://bugs.webkit.org/show_bug.cgi?id=121847
+        <rdar://problem/15067526>
+
+        Reviewed by Eric Carlson.
+
+        The shader that we send down to OpenGL to compile
+        may have been translated by ANGLE, so we keep a
+        table around that maps input symbols to output symbols.
+        We used the table when binding to and looking up
+        uniforms, and when looking up attributes, but not
+        when actually binding to attribute locations.
+
+        Test: fast/canvas/webgl/gl-bind-attrib-mapped-names.html
+
+        * platform/graphics/ANGLEWebKitBridge.cpp:
+        (WebCore::getSymbolInfo): Add logging of symbol mapping.
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::GraphicsContext3D::bindAttribLocation): Used the mapped name.
+        (WebCore::GraphicsContext3D::getAttribLocation): Remove comment since
+        we do the lookup everywhere.
+        (WebCore::GraphicsContext3D::getUniformLocation): Ditto.
+
 2013-09-24  Enrica Casucci  <[email protected]>
 
         Upstream changes to Pasteboard implementation for iOS.

Modified: trunk/Source/WebCore/platform/graphics/ANGLEWebKitBridge.cpp (156350 => 156351)


--- trunk/Source/WebCore/platform/graphics/ANGLEWebKitBridge.cpp	2013-09-24 19:35:30 UTC (rev 156350)
+++ trunk/Source/WebCore/platform/graphics/ANGLEWebKitBridge.cpp	2013-09-24 19:43:22 UTC (rev 156351)
@@ -28,6 +28,7 @@
 #if USE(3D_GRAPHICS)
 
 #include "ANGLEWebKitBridge.h"
+#include "Logging.h"
 #include <wtf/StdLibExtras.h>
 
 namespace WebCore {
@@ -102,6 +103,7 @@
 
         String name = String(nameBuffer.data());
         String mappedName = String(mappedNameBuffer.data());
+        LOG(WebGL, "Map shader symbol %s -> %s\n", name.utf8().data(), mappedName.utf8().data());
         
         // ANGLE returns array names in the format "array[0]".
         // The only way to know if a symbol is an array is to check if it ends with "[0]".

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (156350 => 156351)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2013-09-24 19:35:30 UTC (rev 156350)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2013-09-24 19:43:22 UTC (rev 156351)
@@ -314,7 +314,10 @@
 {
     ASSERT(program);
     makeContextCurrent();
-    ::glBindAttribLocation(program, index, name.utf8().data());
+
+    String mappedName = mappedSymbolName(program, SHADER_SYMBOL_TYPE_ATTRIBUTE, name);
+    LOG(WebGL, "::bindAttribLocation is mapping %s to %s", name.utf8().data(), mappedName.utf8().data());
+    ::glBindAttribLocation(program, index, mappedName.utf8().data());
 }
 
 void GraphicsContext3D::bindBuffer(GC3Denum target, Platform3DObject buffer)
@@ -724,11 +727,8 @@
 
     makeContextCurrent();
 
-    // The attribute name may have been translated during ANGLE compilation.
-    // Look through the corresponding ShaderSourceMap to make sure we
-    // reference the mapped name rather than the external name.
     String mappedName = mappedSymbolName(program, SHADER_SYMBOL_TYPE_ATTRIBUTE, name);
-
+    LOG(WebGL, "::getAttribLocation is mapping %s to %s", name.utf8().data(), mappedName.utf8().data());
     return ::glGetAttribLocation(program, mappedName.utf8().data());
 }
 
@@ -1277,11 +1277,8 @@
 
     makeContextCurrent();
 
-    // The uniform name may have been translated during ANGLE compilation.
-    // Look through the corresponding ShaderSourceMap to make sure we
-    // reference the mapped name rather than the external name.
     String mappedName = mappedSymbolName(program, SHADER_SYMBOL_TYPE_UNIFORM, name);
-
+    LOG(WebGL, "::getUniformLocation is mapping %s to %s", name.utf8().data(), mappedName.utf8().data());
     return ::glGetUniformLocation(program, mappedName.utf8().data());
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to