Title: [161605] trunk/Source/WebCore
Revision
161605
Author
bfulg...@apple.com
Date
2014-01-09 17:12:57 -0800 (Thu, 09 Jan 2014)

Log Message

[WebGL] Return filtered results for getProgramParameter for ACTIVE_ATTRIBUTES and ACTIVE_UNIFORMS
https://bugs.webkit.org/show_bug.cgi?id=126718
<rdar://problem/15202048>

Reviewed by Dean Jackson.

Covered by webgl/conformance/ogles/GL/biuDepthRange/biuDepthRange_001_to_002.html and
webgl/conformance/ogles/GL/gl_FragCoord/gl_FragCoord_001_to_003.html.

* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::getActiveAttrib): Added loging.
(WebCore::WebGLRenderingContext::getActiveUniform): Added logging.
(WebCore::WebGLRenderingContext::getAttribLocation): Drive-by-fix. Return
-1 on link failure (an invalid location) rather than 0 (a valid
location) when link fails.
(WebCore::WebGLRenderingContext::getProgramParameter): Use new
method to return filtered count.
(WebCore::WebGLRenderingContext::getUniformLocation): Use nullptr
rather than returning 0.
* platform/graphics/GraphicsContext3D.h:
(WebCore::GraphicsContext3D::ActiveShaderSymbolCounts::ActiveShaderSymbolCounts):
(WebCore::GraphicsContext3D::ActiveShaderSymbolCounts::countForType):
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::precisionsMatch): Drive-by-fix. Don't
copy giant objects to read a single value.
(WebCore::GraphicsContext3D::compileShader): Release filtered count
when we change shader source code.
(WebCore::GraphicsContext3D::getActiveAttribImpl): Renamed from getActiveAttrib.
(WebCore::GraphicsContext3D::getActiveAttrib): Maps filtered indices to
real OpenGL indices.
(WebCore::GraphicsContext3D::getActiveUniformImpl): Renamed from getActiveUniform.
(WebCore::GraphicsContext3D::getActiveUniform): Maps filtered indices to
real OpenGL indices.
(WebCore::GraphicsContext3D::originalSymbolName): Use C++11 loop.
(WebCore::GraphicsContext3D::getAttribLocation): Added logging.
(WebCore::GraphicsContext3D::getNonBuiltinActiveSymbolCount): Added.
(WebCore::GraphicsContext3D::getShaderiv): Const correctness.
(WebCore::GraphicsContext3D::getShaderInfoLog): Ditto.
(WebCore::GraphicsContext3D::getShaderSource): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (161604 => 161605)


--- trunk/Source/WebCore/ChangeLog	2014-01-10 00:55:37 UTC (rev 161604)
+++ trunk/Source/WebCore/ChangeLog	2014-01-10 01:12:57 UTC (rev 161605)
@@ -1,3 +1,45 @@
+2014-01-09  Brent Fulgham  <bfulg...@apple.com>
+
+        [WebGL] Return filtered results for getProgramParameter for ACTIVE_ATTRIBUTES and ACTIVE_UNIFORMS
+        https://bugs.webkit.org/show_bug.cgi?id=126718
+        <rdar://problem/15202048>
+
+        Reviewed by Dean Jackson.
+
+        Covered by webgl/conformance/ogles/GL/biuDepthRange/biuDepthRange_001_to_002.html and
+        webgl/conformance/ogles/GL/gl_FragCoord/gl_FragCoord_001_to_003.html.
+
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::getActiveAttrib): Added loging.
+        (WebCore::WebGLRenderingContext::getActiveUniform): Added logging.
+        (WebCore::WebGLRenderingContext::getAttribLocation): Drive-by-fix. Return
+        -1 on link failure (an invalid location) rather than 0 (a valid
+        location) when link fails.
+        (WebCore::WebGLRenderingContext::getProgramParameter): Use new
+        method to return filtered count.
+        (WebCore::WebGLRenderingContext::getUniformLocation): Use nullptr
+        rather than returning 0.
+        * platform/graphics/GraphicsContext3D.h:
+        (WebCore::GraphicsContext3D::ActiveShaderSymbolCounts::ActiveShaderSymbolCounts):
+        (WebCore::GraphicsContext3D::ActiveShaderSymbolCounts::countForType):
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::GraphicsContext3D::precisionsMatch): Drive-by-fix. Don't
+        copy giant objects to read a single value.
+        (WebCore::GraphicsContext3D::compileShader): Release filtered count
+        when we change shader source code.
+        (WebCore::GraphicsContext3D::getActiveAttribImpl): Renamed from getActiveAttrib.
+        (WebCore::GraphicsContext3D::getActiveAttrib): Maps filtered indices to
+        real OpenGL indices.
+        (WebCore::GraphicsContext3D::getActiveUniformImpl): Renamed from getActiveUniform.
+        (WebCore::GraphicsContext3D::getActiveUniform): Maps filtered indices to
+        real OpenGL indices.
+        (WebCore::GraphicsContext3D::originalSymbolName): Use C++11 loop.
+        (WebCore::GraphicsContext3D::getAttribLocation): Added logging.
+        (WebCore::GraphicsContext3D::getNonBuiltinActiveSymbolCount): Added.
+        (WebCore::GraphicsContext3D::getShaderiv): Const correctness.
+        (WebCore::GraphicsContext3D::getShaderInfoLog): Ditto.
+        (WebCore::GraphicsContext3D::getShaderSource): Ditto.
+
 2014-01-09  Zoltan Horvath  <zol...@webkit.org>
 
         [CSS Shapes] First line gets incorrectly adjusted in shape-inside due to rounding

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (161604 => 161605)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2014-01-10 00:55:37 UTC (rev 161604)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2014-01-10 01:12:57 UTC (rev 161605)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -45,6 +45,7 @@
 #include "ImageBuffer.h"
 #include "ImageData.h"
 #include "IntSize.h"
+#include "Logging.h"
 #include "NotImplemented.h"
 #include "OESElementIndexUint.h"
 #include "OESStandardDerivatives.h"
@@ -2259,6 +2260,9 @@
     ActiveInfo info;
     if (!m_context->getActiveAttrib(objectOrZero(program), index, info))
         return 0;
+
+    LOG(WebGL, "Returning active attribute %d: %s", index, info.name.utf8().data());
+
     return WebGLActiveInfo::create(info.name, info.type, info.size);
 }
 
@@ -2273,6 +2277,9 @@
     if (!isGLES2Compliant())
         if (info.size > 1 && !info.name.endsWith("[0]"))
             info.name.append("[0]");
+
+    LOG(WebGL, "Returning active uniform %d: %s", index, info.name.utf8().data());
+
     return WebGLActiveInfo::create(info.name, info.type, info.size);
 }
 
@@ -2307,7 +2314,7 @@
         return -1;
     if (!program->getLinkStatus()) {
         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getAttribLocation", "program not linked");
-        return 0;
+        return -1;
     }
     return m_context->getAttribLocation(objectOrZero(program), name);
 }
@@ -2787,9 +2794,11 @@
     case GraphicsContext3D::LINK_STATUS:
         return WebGLGetInfo(program->getLinkStatus());
     case GraphicsContext3D::ATTACHED_SHADERS:
+        m_context->getProgramiv(objectOrZero(program), pname, &value);
+        return WebGLGetInfo(value);
     case GraphicsContext3D::ACTIVE_ATTRIBUTES:
     case GraphicsContext3D::ACTIVE_UNIFORMS:
-        m_context->getProgramiv(objectOrZero(program), pname, &value);
+        m_context->getNonBuiltInActiveSymbolCount(objectOrZero(program), pname, &value);
         return WebGLGetInfo(value);
     default:
         synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getProgramParameter", "invalid parameter name");
@@ -3147,21 +3156,21 @@
 {
     UNUSED_PARAM(ec);
     if (isContextLost() || !validateWebGLObject("getUniformLocation", program))
-        return 0;
+        return nullptr;
     if (!validateLocationLength("getUniformLocation", name))
-        return 0;
+        return nullptr;
     if (!validateString("getUniformLocation", name))
-        return 0;
+        return nullptr;
     if (isPrefixReserved(name))
-        return 0;
+        return nullptr;
     if (!program->getLinkStatus()) {
         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniformLocation", "program not linked");
-        return 0;
+        return nullptr;
     }
     WebGLStateRestorer(this, false);
     GC3Dint uniformLocation = m_context->getUniformLocation(objectOrZero(program), name);
     if (uniformLocation == -1)
-        return 0;
+        return nullptr;
 
     GC3Dint activeUniforms = 0;
     m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms);
@@ -3180,7 +3189,7 @@
                 return WebGLUniformLocation::create(program, uniformLocation, info.type);
         }
     }
-    return 0;
+    return nullptr;
 }
 
 WebGLGetInfo WebGLRenderingContext::getVertexAttrib(GC3Duint index, GC3Denum pname, ExceptionCode& ec)

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (161604 => 161605)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2014-01-10 00:55:37 UTC (rev 161604)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2014-01-10 01:12:57 UTC (rev 161605)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -688,7 +688,9 @@
     void generateMipmap(GC3Denum target);
 
     bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&);
+    bool getActiveAttribImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
     bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&);
+    bool getActiveUniformImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
     void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders);
     GC3Dint getAttribLocation(Platform3DObject, const String& name);
     void getBooleanv(GC3Denum pname, GC3Dboolean* value);
@@ -699,6 +701,7 @@
     void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value);
     void getIntegerv(GC3Denum pname, GC3Dint* value);
     void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
+    void getNonBuiltInActiveSymbolCount(Platform3DObject program, GC3Denum pname, GC3Dint* value);
     String getProgramInfoLog(Platform3DObject);
     void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
     void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
@@ -1044,6 +1047,25 @@
     typedef HashMap<Platform3DObject, ShaderSourceEntry> ShaderSourceMap;
     ShaderSourceMap m_shaderSourceMap;
 
+    struct ActiveShaderSymbolCounts {
+        Vector<GC3Dint> filteredToActualAttributeIndexMap;
+        Vector<GC3Dint> filteredToActualUniformIndexMap;
+
+        ActiveShaderSymbolCounts()
+        {
+        }
+
+        GC3Dint countForType(GC3Denum activeType)
+        {
+            ASSERT(activeType == ACTIVE_ATTRIBUTES || activeType == ACTIVE_UNIFORMS);
+            if (activeType == ACTIVE_ATTRIBUTES)
+                return filteredToActualAttributeIndexMap.size();
+
+            return filteredToActualUniformIndexMap.size();
+        }
+    };
+    std::unique_ptr<ActiveShaderSymbolCounts> m_shaderSymbolCount;
+
     String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
     String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
 

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


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2014-01-10 00:55:37 UTC (rev 161604)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2014-01-10 01:12:57 UTC (rev 161605)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2014 Apple Inc. All rights reserved.
  * Copyright (C) 2011 Google Inc. All rights reserved.
  * Copyright (C) 2012 ChangSeok Oh <shivami...@gmail.com>
  * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
@@ -337,17 +337,19 @@
 
 bool GraphicsContext3D::precisionsMatch(Platform3DObject vertexShader, Platform3DObject fragmentShader) const
 {
-    ShaderSourceEntry vertexEntry = m_shaderSourceMap.find(vertexShader)->value;
-    ShaderSourceEntry fragmentEntry = m_shaderSourceMap.find(fragmentShader)->value;
+    ASSERT(m_shaderSourceMap.contains(vertexShader));
+    ASSERT(m_shaderSourceMap.contains(fragmentShader));
+    const auto& vertexEntry = m_shaderSourceMap.find(vertexShader)->value;
+    const auto& fragmentEntry = m_shaderSourceMap.find(fragmentShader)->value;
 
     HashMap<String, ShPrecisionType> vertexSymbolPrecisionMap;
 
-    for (auto it = vertexEntry.uniformMap.begin(); it != vertexEntry.uniformMap.end(); ++it)
-        vertexSymbolPrecisionMap.add(it->value.mappedName, it->value.precision);
+    for (const auto& entry : vertexEntry.uniformMap)
+        vertexSymbolPrecisionMap.add(entry.value.mappedName, entry.value.precision);
 
-    for (auto it = fragmentEntry.uniformMap.begin(); it != fragmentEntry.uniformMap.end(); ++it) {
-        HashMap<String, ShPrecisionType>::iterator vertexSymbol = vertexSymbolPrecisionMap.find(it->value.mappedName);
-        if (vertexSymbol != vertexSymbolPrecisionMap.end() && vertexSymbol->value != it->value.precision)
+    for (const auto& entry : fragmentEntry.uniformMap) {
+        const auto& vertexSymbol = vertexSymbolPrecisionMap.find(entry.value.mappedName);
+        if (vertexSymbol != vertexSymbolPrecisionMap.end() && vertexSymbol->value != entry.value.precision)
             return false;
     }
 
@@ -564,6 +566,8 @@
         BBLOG(BlackBerry::Platform::LogLevelWarn, "The shader validated, but didn't compile.\n");
 #endif
     }
+
+    m_shaderSymbolCount = nullptr;
 }
 
 void GraphicsContext3D::copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border)
@@ -696,7 +700,7 @@
     ::glGenerateMipmap(target);
 }
 
-bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo& info)
+bool GraphicsContext3D::getActiveAttribImpl(Platform3DObject program, GC3Duint index, ActiveInfo& info)
 {
     if (!program) {
         synthesizeGLError(INVALID_VALUE);
@@ -715,14 +719,27 @@
     
     String originalName = originalSymbolName(program, SHADER_SYMBOL_TYPE_ATTRIBUTE, String(name.get(), nameLength));
     
+#ifndef NDEBUG
+    String uniformName(name.get(), nameLength);
+    LOG(WebGL, "Program %d is mapping active attribute %d from '%s' to '%s'", program, index, uniformName.utf8().data(), originalName.utf8().data());
+#endif
+
     info.name = originalName;
     info.type = type;
     info.size = size;
     return true;
 }
 
-bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info)
+bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo& info)
 {
+    ASSERT(!m_shaderSymbolCount || index < m_shaderSymbolCount->filteredToActualAttributeIndexMap.size());
+    GC3Duint rawIndex = (m_shaderSymbolCount) ? m_shaderSymbolCount->filteredToActualAttributeIndexMap[index] : index;
+
+    return getActiveAttribImpl(program, rawIndex, info);
+}
+
+bool GraphicsContext3D::getActiveUniformImpl(Platform3DObject program, GC3Duint index, ActiveInfo& info)
+{
     if (!program) {
         synthesizeGLError(INVALID_VALUE);
         return false;
@@ -742,12 +759,25 @@
     
     String originalName = originalSymbolName(program, SHADER_SYMBOL_TYPE_UNIFORM, String(name.get(), nameLength));
     
+#ifndef NDEBUG
+    String uniformName(name.get(), nameLength);
+    LOG(WebGL, "Program %d is mapping active uniform %d from '%s' to '%s'", program, index, uniformName.utf8().data(), originalName.utf8().data());
+#endif
+    
     info.name = originalName;
     info.type = type;
     info.size = size;
     return true;
 }
+
+bool GraphicsContext3D::getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo& info)
+{
+    ASSERT(!m_shaderSymbolCount || index < m_shaderSymbolCount->filteredToActualUniformIndexMap.size());
+    GC3Duint rawIndex = (m_shaderSymbolCount) ? m_shaderSymbolCount->filteredToActualUniformIndexMap[index] : index;
     
+    return getActiveUniformImpl(program, rawIndex, info);
+}
+
 void GraphicsContext3D::getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders)
 {
     if (!program) {
@@ -789,10 +819,9 @@
             continue;
         
         const ShaderSymbolMap& symbolMap = result->value.symbolMap(symbolType);
-        ShaderSymbolMap::const_iterator symbolEntry;
-        for (symbolEntry = symbolMap.begin(); symbolEntry != symbolMap.end(); ++symbolEntry) {
-            if (symbolEntry->value.mappedName == name)
-                return symbolEntry->key;
+        for (const auto& symbolEntry : symbolMap) {
+            if (symbolEntry.value.mappedName == name)
+                return symbolEntry.key;
         }
     }
     return name;
@@ -806,7 +835,7 @@
     makeContextCurrent();
 
     String mappedName = mappedSymbolName(program, SHADER_SYMBOL_TYPE_ATTRIBUTE, name);
-    LOG(WebGL, "::getAttribLocation is mapping %s to %s", name.utf8().data(), mappedName.utf8().data());
+    LOG(WebGL, "::glGetAttribLocation is mapping %s to %s", name.utf8().data(), mappedName.utf8().data());
     return ::glGetAttribLocation(program, mappedName.utf8().data());
 }
 
@@ -1227,6 +1256,49 @@
     ::glGetProgramiv(program, pname, value);
 }
 
+void GraphicsContext3D::getNonBuiltInActiveSymbolCount(Platform3DObject program, GC3Denum pname, GC3Dint* value)
+{
+    ASSERT(ACTIVE_ATTRIBUTES == pname || ACTIVE_UNIFORMS == pname);
+    if (!value)
+        return;
+
+    makeContextCurrent();
+
+    if (m_shaderSymbolCount) {
+        *value = m_shaderSymbolCount->countForType(pname);
+        return;
+    }
+
+    m_shaderSymbolCount = std::make_unique<ActiveShaderSymbolCounts>();
+
+    // Retrieve the active attributes, build a filtered count, and a mapping of
+    // our internal attributes indexes to the real unfiltered indexes inside OpenGL.
+    GC3Dint attributeCount = 0;
+    ::glGetProgramiv(program, ACTIVE_ATTRIBUTES, &attributeCount);
+    for (GC3Dint i = 0; i < attributeCount; ++i) {
+        ActiveInfo info;
+        getActiveAttribImpl(program, i, info);
+        if (info.name.startsWith("gl_"))
+            continue;
+
+        m_shaderSymbolCount->filteredToActualAttributeIndexMap.append(i);
+    }
+    
+    // Do the same for uniforms.
+    GC3Dint uniformCount = 0;
+    ::glGetProgramiv(program, ACTIVE_UNIFORMS, &uniformCount);
+    for (GC3Dint i = 0; i < uniformCount; ++i) {
+        ActiveInfo info;
+        getActiveUniformImpl(program, i, info);
+        if (info.name.startsWith("gl_"))
+            continue;
+        
+        m_shaderSymbolCount->filteredToActualUniformIndexMap.append(i);
+    }
+    
+    *value = m_shaderSymbolCount->countForType(pname);
+}
+
 String GraphicsContext3D::getProgramInfoLog(Platform3DObject program)
 {
     ASSERT(program);
@@ -1256,7 +1328,7 @@
 
     makeContextCurrent();
 
-    ShaderSourceMap::iterator result = m_shaderSourceMap.find(shader);
+    const auto& result = m_shaderSourceMap.find(shader);
     
     switch (pname) {
     case DELETE_STATUS:
@@ -1291,11 +1363,11 @@
 
     makeContextCurrent();
 
-    ShaderSourceMap::iterator result = m_shaderSourceMap.find(shader);
+    const auto& result = m_shaderSourceMap.find(shader);
     if (result == m_shaderSourceMap.end())
         return String(); 
 
-    ShaderSourceEntry entry = result->value;
+    const ShaderSourceEntry& entry = result->value;
     if (!entry.isValid)
         return entry.log;
 
@@ -1317,7 +1389,7 @@
 
     makeContextCurrent();
 
-    ShaderSourceMap::iterator result = m_shaderSourceMap.find(shader);
+    const auto& result = m_shaderSourceMap.find(shader);
     if (result == m_shaderSourceMap.end())
         return String(); 
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to