Keep track of filtered active attribute/uniform indices per shader program.
authorroger_fong@apple.com <roger_fong@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Apr 2014 22:08:47 +0000 (22:08 +0000)
committerroger_fong@apple.com <roger_fong@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Apr 2014 22:08:47 +0000 (22:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131235.

Reviewed by Dean Jackson.

Tests: Covered by existing Khronos Conformance tests.
Will create a test to use multiple shader programs in a follow-up patch.

* html/canvas/WebGLProgram.cpp:
(WebCore::WebGLProgram::cacheActiveAttribLocations): Use getActiveAttribImpl. We do not need to use the filtered list of attributes here.
* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::getUniformLocation): Use filtered list of uniforms for uniform count.
* platform/graphics/GraphicsContext3D.h: Create a map of shader programs to ActiveShaderSymbolCounts.
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::attachShader):
When attaching or detaching a shader the shader program's active symbols list will change. Clear it so that it will be updated later.
(WebCore::GraphicsContext3D::detachShader): Ditto.
(WebCore::GraphicsContext3D::compileShader): No need to clear symbol counts here.
(WebCore::GraphicsContext3D::getActiveAttrib): getActiveAttrib should only be able to query for attributes in the filtered list.
(WebCore::GraphicsContext3D::getActiveUniform): getActiveUniform should only be able to query for uniforms in the filtered list.
(WebCore::GraphicsContext3D::getNonBuiltInActiveSymbolCount): Return the filtered symbol count for a shader program.

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

Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLProgram.cpp
Source/WebCore/html/canvas/WebGLRenderingContext.cpp
Source/WebCore/platform/graphics/GraphicsContext3D.h
Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp

index 36ecfe8..2912bf0 100644 (file)
@@ -1,3 +1,27 @@
+2014-04-04  Roger Fong  <roger_fong@apple.com>
+
+        Keep track of filtered active attribute/uniform indices per shader program.
+        https://bugs.webkit.org/show_bug.cgi?id=131235.
+
+        Reviewed by Dean Jackson.
+
+        Tests: Covered by existing Khronos Conformance tests. 
+        Will create a test to use multiple shader programs in a follow-up patch.
+
+        * html/canvas/WebGLProgram.cpp:
+        (WebCore::WebGLProgram::cacheActiveAttribLocations): Use getActiveAttribImpl. We do not need to use the filtered list of attributes here.
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::getUniformLocation): Use filtered list of uniforms for uniform count.
+        * platform/graphics/GraphicsContext3D.h: Create a map of shader programs to ActiveShaderSymbolCounts.
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::GraphicsContext3D::attachShader): 
+        When attaching or detaching a shader the shader program's active symbols list will change. Clear it so that it will be updated later.
+        (WebCore::GraphicsContext3D::detachShader): Ditto.
+        (WebCore::GraphicsContext3D::compileShader): No need to clear symbol counts here.
+        (WebCore::GraphicsContext3D::getActiveAttrib): getActiveAttrib should only be able to query for attributes in the filtered list.
+        (WebCore::GraphicsContext3D::getActiveUniform): getActiveUniform should only be able to query for uniforms in the filtered list.
+        (WebCore::GraphicsContext3D::getNonBuiltInActiveSymbolCount): Return the filtered symbol count for a shader program.
+
 2014-04-04  Ion Rosca  <rosca@adobe.com>
 
         [CSS Blending] Add compositing reason for isolation.
index 92b6897..0841421 100644 (file)
@@ -169,7 +169,7 @@ void WebGLProgram::cacheActiveAttribLocations(GraphicsContext3D* context3d)
     m_activeAttribLocations.resize(static_cast<size_t>(numAttribs));
     for (int i = 0; i < numAttribs; ++i) {
         ActiveInfo info;
-        context3d->getActiveAttrib(object(), i, info);
+        context3d->getActiveAttribImpl(object(), i, info);
         m_activeAttribLocations[i] = context3d->getAttribLocation(object(), info.name);
     }
 }
index 460b51c..e2a4e6f 100644 (file)
@@ -3212,7 +3212,7 @@ PassRefPtr<WebGLUniformLocation> WebGLRenderingContext::getUniformLocation(WebGL
         return nullptr;
 
     GC3Dint activeUniforms = 0;
-    m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms);
+    m_context->getNonBuiltInActiveSymbolCount(objectOrZero(program), GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms);
     for (GC3Dint i = 0; i < activeUniforms; i++) {
         ActiveInfo info;
         if (!m_context->getActiveUniform(objectOrZero(program), i, info))
index 2525392..be26023 100644 (file)
@@ -1085,8 +1085,9 @@ private:
             return filteredToActualUniformIndexMap.size();
         }
     };
-    std::unique_ptr<ActiveShaderSymbolCounts> m_shaderSymbolCount;
-
+    typedef HashMap<Platform3DObject, ActiveShaderSymbolCounts> ShaderProgramSymbolCountMap;
+    ShaderProgramSymbolCountMap m_shaderProgramSymbolCountMap;
+    
     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);
index ef4703c..dfd7bb7 100644 (file)
@@ -374,6 +374,7 @@ void GraphicsContext3D::attachShader(Platform3DObject program, Platform3DObject
     ASSERT(program);
     ASSERT(shader);
     makeContextCurrent();
+    m_shaderProgramSymbolCountMap.remove(program);
     ::glAttachShader(program, shader);
 }
 
@@ -561,8 +562,6 @@ void GraphicsContext3D::compileShader(Platform3DObject shader)
         entry.isValid = false;
         LOG(WebGL, "Error: shader translator produced a shader that OpenGL would not compile.");
     }
-
-    m_shaderSymbolCount = nullptr;
 }
 
 void GraphicsContext3D::copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border)
@@ -612,6 +611,7 @@ void GraphicsContext3D::detachShader(Platform3DObject program, Platform3DObject
     ASSERT(program);
     ASSERT(shader);
     makeContextCurrent();
+    m_shaderProgramSymbolCountMap.remove(program);
     ::glDetachShader(program, shader);
 }
 
@@ -719,8 +719,15 @@ bool GraphicsContext3D::getActiveAttribImpl(Platform3DObject program, GC3Duint i
 
 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;
+    GC3Dint symbolCount;
+    auto result = m_shaderProgramSymbolCountMap.find(program);
+    if (result == m_shaderProgramSymbolCountMap.end()) {
+        getNonBuiltInActiveSymbolCount(program, GraphicsContext3D::ACTIVE_ATTRIBUTES, &symbolCount);
+        result = m_shaderProgramSymbolCountMap.find(program);
+    }
+    
+    ActiveShaderSymbolCounts& symbolCounts = result->value;
+    GC3Duint rawIndex = (index < symbolCounts.filteredToActualAttributeIndexMap.size()) ? symbolCounts.filteredToActualAttributeIndexMap[index] : -1;
 
     return getActiveAttribImpl(program, rawIndex, info);
 }
@@ -759,8 +766,15 @@ bool GraphicsContext3D::getActiveUniformImpl(Platform3DObject program, GC3Duint
 
 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;
+    GC3Dint symbolCount;
+    auto result = m_shaderProgramSymbolCountMap.find(program);
+    if (result == m_shaderProgramSymbolCountMap.end()) {
+        getNonBuiltInActiveSymbolCount(program, GraphicsContext3D::ACTIVE_UNIFORMS, &symbolCount);
+        result = m_shaderProgramSymbolCountMap.find(program);
+    }
+    
+    ActiveShaderSymbolCounts& symbolCounts = result->value;
+    GC3Duint rawIndex = (index < symbolCounts.filteredToActualUniformIndexMap.size()) ? symbolCounts.filteredToActualUniformIndexMap[index] : -1;
     
     return getActiveUniformImpl(program, rawIndex, info);
 }
@@ -1268,13 +1282,14 @@ void GraphicsContext3D::getNonBuiltInActiveSymbolCount(Platform3DObject program,
         return;
 
     makeContextCurrent();
-
-    if (m_shaderSymbolCount) {
-        *value = m_shaderSymbolCount->countForType(pname);
+    const auto& result = m_shaderProgramSymbolCountMap.find(program);
+    if (result != m_shaderProgramSymbolCountMap.end()) {
+        *value = result->value.countForType(pname);
         return;
     }
 
-    m_shaderSymbolCount = std::make_unique<ActiveShaderSymbolCounts>();
+    m_shaderProgramSymbolCountMap.set(program, ActiveShaderSymbolCounts());
+    ActiveShaderSymbolCounts& symbolCounts = m_shaderProgramSymbolCountMap.find(program)->value;
 
     // Retrieve the active attributes, build a filtered count, and a mapping of
     // our internal attributes indexes to the real unfiltered indexes inside OpenGL.
@@ -1286,7 +1301,7 @@ void GraphicsContext3D::getNonBuiltInActiveSymbolCount(Platform3DObject program,
         if (info.name.startsWith("gl_"))
             continue;
 
-        m_shaderSymbolCount->filteredToActualAttributeIndexMap.append(i);
+        symbolCounts.filteredToActualAttributeIndexMap.append(i);
     }
     
     // Do the same for uniforms.
@@ -1298,10 +1313,10 @@ void GraphicsContext3D::getNonBuiltInActiveSymbolCount(Platform3DObject program,
         if (info.name.startsWith("gl_"))
             continue;
         
-        m_shaderSymbolCount->filteredToActualUniformIndexMap.append(i);
+        symbolCounts.filteredToActualUniformIndexMap.append(i);
     }
     
-    *value = m_shaderSymbolCount->countForType(pname);
+    *value = symbolCounts.countForType(pname);
 }
 
 String GraphicsContext3D::getUnmangledInfoLog(Platform3DObject shaders[2], GC3Dsizei count, const String& log)