[WebGL] Error messages should use source code labels, not internal mangled symbols.
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2014 01:26:11 +0000 (01:26 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2014 01:26:11 +0000 (01:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126832

Reviewed by Dean Jackson.

Source/WebCore:

Revised fast/canvas/webgl/glsl-conformance.html.

* platform/graphics/ANGLEWebKitBridge.cpp:
(WebCore::getSymbolInfo): Correct missing 'break'.
(WebCore::ANGLEWebKitBridge::compileShaderSource): Call 'getSymbolInfo'
for SH_VARYINGS.
* platform/graphics/GraphicsContext3D.h: Add new declarations.
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::compileShader): Demangle log output.
(WebCore::GraphicsContext3D::mappedSymbolName): Added.
(WebCore::GraphicsContext3D::getUnmangledInfoLog): Added.
(WebCore::GraphicsContext3D::getProgramInfoLog): Demangle log output.
(WebCore::GraphicsContext3D::getShaderInfoLog): Demangle log output.

LayoutTests:

* fast/canvas/webgl/glsl-conformance.html: Add log to program output
showing error message to confirm proper labels are being used.
* fast/canvas/webgl/glsl-conformance-expected.txt: updated.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161843 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/glsl-conformance-expected.txt
LayoutTests/fast/canvas/webgl/glsl-conformance.html
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ANGLEWebKitBridge.cpp
Source/WebCore/platform/graphics/GraphicsContext3D.h
Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp

index ee7378c..4bd0bc4 100644 (file)
@@ -1,3 +1,14 @@
+2014-01-12  Brent Fulgham  <bfulgham@apple.com>
+
+        [WebGL] Error messages should use source code labels, not internal mangled symbols.
+        https://bugs.webkit.org/show_bug.cgi?id=126832
+
+        Reviewed by Dean Jackson.
+
+        * fast/canvas/webgl/glsl-conformance.html: Add log to program output
+        showing error message to confirm proper labels are being used.
+        * fast/canvas/webgl/glsl-conformance-expected.txt: updated.
+
 2014-01-12  Benjamin Poulain  <benjamin@webkit.org>
 
         Use the Selector Code Generator for matching in SelectorQuery
index 58b7bfb..d93b188 100644 (file)
@@ -28,6 +28,9 @@ PASS [vshaderWithImplicitVec3Cast/fshader]: vertex shader that implicit vec3 to
 PASS [vshaderWithVersion130/fshader]: vertex shader uses the #version not 100 directive should fail
 PASS [vshaderWithVersion120/fshader]: vertex shader uses the #version not 100 directive should fail
 PASS [vshaderWithVersion100/fshader]: vertex shader uses the #version 100 directive should succeed
+Program link log:ERROR: Input of fragment shader 'v_varying' not written by vertex shader
+
+PASS [vshaderWithVersion100/fragmentShaderUsedVarying]: vertex shader with no varying and fragment shader with used varying must fail
 PASS [shaders/implicit/add_int_float.vert/fshader]: implicit cast adding integer to float should fail
 PASS [shaders/implicit/add_int_mat2.vert/fshader]: implicit cast adding integer to mat2 should fail
 PASS [shaders/implicit/add_int_mat3.vert/fshader]: implicit cast adding integer to mat3 should fail
index 625c875..dc1b4a5 100644 (file)
@@ -211,6 +211,16 @@ void main()
     gl_Position = vPosition;
 }
 </script>
+<script id="fragmentShaderUsedVarying" type="text/something-not-javascript">
+precision mediump float;
+
+varying vec4 v_varying;
+
+void main()
+{
+    gl_FragColor = v_varying;
+}
+</script>
 <script id="vshaderWith__FILE__" type="text/something-not-javascript">
 __FILE__
 </script>
@@ -403,6 +413,13 @@ if (!gl) {
       linkSuccess: true,
       passMsg: 'vertex shader uses the #version 100 directive should succeed',
     },
+    { vShaderId: 'vshaderWithVersion100',
+      vShaderSuccess: true,
+      fShaderId: 'fragmentShaderUsedVarying',
+      fShaderSuccess: true,
+      linkSuccess: false,
+      passMsg: 'vertex shader with no varying and fragment shader with used varying must fail',
+    },
   ];
 
   // Read in all the shader source.
@@ -498,13 +515,17 @@ if (!gl) {
       gl.linkProgram(program);
       var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
       if (!linked) {
-        var error = gl.getProgramInfoLog(shader);
+        var error = gl.getProgramInfoLog(program);
         log("*** Error linking program '"+program+"':"+error);
       }
       if (linked != info.linkSuccess) {
         testFailed(passMsg);
         continue;
       }
+      if (!info.linkSuccess) {
+        var error = gl.getProgramInfoLog(program);
+        debug("Program link log:" + error);
+      }
     } else {
       if (info.linkSuccess) {
         testFailed(passMsg);
index 9f3d39c..a96be9e 100644 (file)
@@ -1,3 +1,24 @@
+2014-01-12  Brent Fulgham  <bfulgham@apple.com>
+
+        [WebGL] Error messages should use source code labels, not internal mangled symbols.
+        https://bugs.webkit.org/show_bug.cgi?id=126832
+
+        Reviewed by Dean Jackson.
+
+        Revised fast/canvas/webgl/glsl-conformance.html.
+
+        * platform/graphics/ANGLEWebKitBridge.cpp:
+        (WebCore::getSymbolInfo): Correct missing 'break'.
+        (WebCore::ANGLEWebKitBridge::compileShaderSource): Call 'getSymbolInfo'
+        for SH_VARYINGS.
+        * platform/graphics/GraphicsContext3D.h: Add new declarations.
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::GraphicsContext3D::compileShader): Demangle log output.
+        (WebCore::GraphicsContext3D::mappedSymbolName): Added.
+        (WebCore::GraphicsContext3D::getUnmangledInfoLog): Added.
+        (WebCore::GraphicsContext3D::getProgramInfoLog): Demangle log output.
+        (WebCore::GraphicsContext3D::getShaderInfoLog): Demangle log output.
+
 2014-01-12  Dan Bernstein  <mitz@apple.com>
 
         Try to fix the Windows build after r161839.
index f0c1a1e..abfb06d 100644 (file)
@@ -60,6 +60,7 @@ static bool getSymbolInfo(ShHandle compiler, ShShaderInfo symbolType, Vector<ANG
         break;
     case SH_VARYINGS:
         symbolMaxNameLengthType = SH_VARYING_MAX_LENGTH;
+        break;
     default:
         ASSERT_NOT_REACHED();
         return false;
@@ -227,6 +228,8 @@ bool ANGLEWebKitBridge::compileShaderSource(const char* shaderSource, ANGLEShade
         return false;
     if (!getSymbolInfo(compiler, SH_ACTIVE_UNIFORMS, symbols))
         return false;
+    if (!getSymbolInfo(compiler, SH_VARYINGS, symbols))
+        return false;
 
     return true;
 }
index f1cfda2..3ef90d3 100644 (file)
@@ -739,6 +739,7 @@ public:
     void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
     void getNonBuiltInActiveSymbolCount(Platform3DObject program, GC3Denum pname, GC3Dint* value);
     String getProgramInfoLog(Platform3DObject);
+    String getUnmangledInfoLog(Platform3DObject[2], GC3Dsizei, const String&);
     void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
     void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
     String getShaderInfoLog(Platform3DObject);
@@ -1084,6 +1085,7 @@ private:
     std::unique_ptr<ActiveShaderSymbolCounts> m_shaderSymbolCount;
 
     String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
+    String mappedSymbolName(Platform3DObject shaders[2], size_t count, const String& name);
     String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
 
     ANGLEWebKitBridge m_compiler;
index 49bd44b..1c581e6 100644 (file)
@@ -47,6 +47,7 @@
 #include "IntSize.h"
 #include "Logging.h"
 #include "NotImplemented.h"
+#include "RegularExpression.h"
 #include "TemporaryOpenGLSetting.h"
 #include <cstring>
 #include <runtime/ArrayBuffer.h>
@@ -546,7 +547,8 @@ void GraphicsContext3D::compileShader(Platform3DObject shader)
         auto info = std::make_unique<GLchar[]>(length);
         ::glGetShaderInfoLog(shader, length, &size, info.get());
 
-        entry.log = info.get();
+        Platform3DObject shaders[2] = { shader, 0 };
+        entry.log = getUnmangledInfoLog(shaders, 1, String(info.get()));
     }
 
     if (GLCompileSuccess != GL_TRUE) {
@@ -806,6 +808,24 @@ String GraphicsContext3D::originalSymbolName(Platform3DObject program, ANGLEShad
     return name;
 }
 
+String GraphicsContext3D::mappedSymbolName(Platform3DObject shaders[2], size_t count, const String& name)
+{
+    for (size_t symbolType = 0; symbolType <= static_cast<size_t>(SHADER_SYMBOL_TYPE_VARYING); ++symbolType) {
+        for (size_t i = 0; i < count; ++i) {
+            ShaderSourceMap::iterator result = m_shaderSourceMap.find(shaders[i]);
+            if (result == m_shaderSourceMap.end())
+                continue;
+            
+            const ShaderSymbolMap& symbolMap = result->value.symbolMap(static_cast<enum ANGLEShaderSymbolType>(symbolType));
+            for (const auto& symbolEntry : symbolMap) {
+                if (symbolEntry.value.mappedName == name)
+                    return symbolEntry.key;
+            }
+        }
+    }
+    return name;
+}
+
 int GraphicsContext3D::getAttribLocation(Platform3DObject program, const String& name)
 {
     if (!program)
@@ -1278,6 +1298,36 @@ void GraphicsContext3D::getNonBuiltInActiveSymbolCount(Platform3DObject program,
     *value = m_shaderSymbolCount->countForType(pname);
 }
 
+String GraphicsContext3D::getUnmangledInfoLog(Platform3DObject shaders[2], GC3Dsizei count, const String& log)
+{
+    LOG(WebGL, "Was: %s", log.utf8().data());
+
+    RegularExpression regExp("webgl_[0123456789abcdefABCDEF]+", TextCaseSensitive);
+
+    String processedLog;
+    
+    int startFrom = 0;
+    int matchedLength = 0;
+    do {
+        int start = regExp.match(log, startFrom, &matchedLength);
+        if (start == -1)
+            break;
+
+        processedLog.append(log.substring(startFrom, start - startFrom));
+        startFrom = start + matchedLength;
+
+        const String& mangledSymbol = log.substring(start, matchedLength);
+        const String& mappedSymbol = mappedSymbolName(shaders, count, mangledSymbol);
+        LOG(WebGL, "Demangling: %s to %s", mangledSymbol.utf8().data(), mappedSymbol.utf8().data());
+        processedLog.append(mappedSymbol);
+    } while (startFrom < static_cast<int>(log.length()));
+
+    processedLog.append(log.substring(startFrom, log.length() - startFrom));
+
+    LOG(WebGL, "-->: %s", processedLog.utf8().data());
+    return processedLog;
+}
+
 String GraphicsContext3D::getProgramInfoLog(Platform3DObject program)
 {
     ASSERT(program);
@@ -1292,7 +1342,11 @@ String GraphicsContext3D::getProgramInfoLog(Platform3DObject program)
     auto info = std::make_unique<GLchar[]>(length);
     ::glGetProgramInfoLog(program, length, &size, info.get());
 
-    return String(info.get());
+    GC3Dsizei count;
+    Platform3DObject shaders[2];
+    getAttachedShaders(program, 2, &count, shaders);
+
+    return getUnmangledInfoLog(shaders, count, String(info.get()));
 }
 
 void GraphicsContext3D::getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value)
@@ -1359,7 +1413,8 @@ String GraphicsContext3D::getShaderInfoLog(Platform3DObject shader)
     auto info = std::make_unique<GLchar[]>(length);
     ::glGetShaderInfoLog(shader, length, &size, info.get());
 
-    return String(info.get());
+    Platform3DObject shaders[2] = { shader, 0 };
+    return getUnmangledInfoLog(shaders, 1, String(info.get()));
 }
 
 String GraphicsContext3D::getShaderSource(Platform3DObject shader)