Bug 1405600 - Initialize uniform blocks before detaching shaders; r?jgilbert draft
authorDaosheng Mu <daoshengmu@gmail.com>
Mon, 30 Oct 2017 17:34:37 +0800
changeset 689155 99e0ba22dd7751e93c477e1c1ef7933c439a4ca8
parent 688337 d3910b7628b8066d3f30d58b17b5824b05768854
child 738242 dba373f0dccb3d3ef5f5bb8c52fa1c6ae3310b0d
push id86938
push userbmo:dmu@mozilla.com
push dateTue, 31 Oct 2017 06:03:26 +0000
reviewersjgilbert
bugs1405600
milestone58.0a1
Bug 1405600 - Initialize uniform blocks before detaching shaders; r?jgilbert MozReview-Commit-ID: 4fQ1XuGxWLn
gfx/angle/src/libANGLE/Program.cpp
gfx/angle/src/libANGLE/renderer/ProgramImpl.h
gfx/angle/src/libANGLE/renderer/d3d/ProgramD3D.h
--- a/gfx/angle/src/libANGLE/Program.cpp
+++ b/gfx/angle/src/libANGLE/Program.cpp
@@ -511,16 +511,22 @@ void Program::attachShader(Shader *shade
         }
         default:
             UNREACHABLE();
     }
 }
 
 void Program::detachShader(const Context *context, Shader *shader)
 {
+    // Because we do lazy init in ensureUniformBlocksInitialized,
+    // we must initialize them before detaching shaders,
+    // otherwise, we will have no shaders for getting uniform blocks
+    // information from shaders when doing draw calls.
+    mProgram->ensureUniformBlocksInitialized();
+
     switch (shader->getType())
     {
         case GL_VERTEX_SHADER:
         {
             ASSERT(mState.mAttachedVertexShader == shader);
             shader->release(context);
             mState.mAttachedVertexShader = nullptr;
             break;
--- a/gfx/angle/src/libANGLE/renderer/ProgramImpl.h
+++ b/gfx/angle/src/libANGLE/renderer/ProgramImpl.h
@@ -105,15 +105,19 @@ class ProgramImpl : angle::NonCopyable
     // Implementation-specific method for ignoring unreferenced uniforms. Some implementations may
     // perform more extensive analysis and ignore some locations that ANGLE doesn't detect as
     // unreferenced. This method is not required to be overriden by a back-end.
     virtual void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations,
                                             std::vector<gl::SamplerBinding> *samplerBindings)
     {
     }
 
+    virtual void ensureUniformBlocksInitialized()
+    {
+    }
+
   protected:
     const gl::ProgramState &mState;
 };
 
 }  // namespace rx
 
 #endif // LIBANGLE_RENDERER_PROGRAMIMPL_H_
--- a/gfx/angle/src/libANGLE/renderer/d3d/ProgramD3D.h
+++ b/gfx/angle/src/libANGLE/renderer/d3d/ProgramD3D.h
@@ -265,16 +265,17 @@ class ProgramD3D : public ProgramImpl
                                GLboolean transpose,
                                const GLfloat *value);
 
     void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override;
     void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override;
     void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override;
 
     void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) override;
+    void ensureUniformBlocksInitialized() override;
 
     UniformStorageD3D &getVertexUniformStorage() const { return *mVertexUniformStorage.get(); }
     UniformStorageD3D &getFragmentUniformStorage() const { return *mFragmentUniformStorage.get(); }
     UniformStorageD3D &getComputeUniformStorage() const { return *mComputeUniformStorage.get(); }
 
     unsigned int getSerial() const;
 
     const AttribIndexArray &getAttribLocationToD3DSemantics() const
@@ -423,17 +424,16 @@ class ProgramD3D : public ProgramImpl
                                          const BuiltinInfo &builtins);
     D3DUniform *getD3DUniformByName(const std::string &name);
     D3DUniform *getD3DUniformFromLocation(GLint location);
     const D3DUniform *getD3DUniformFromLocation(GLint location) const;
 
     void initAttribLocationsToD3DSemantic(const gl::Context *context);
 
     void reset();
-    void ensureUniformBlocksInitialized();
 
     void initUniformBlockInfo(const gl::Context *context, gl::Shader *shader);
     size_t getUniformBlockInfo(const sh::InterfaceBlock &interfaceBlock);
 
     void updateCachedInputLayoutFromShader(const gl::Context *context);
     void updateCachedOutputLayoutFromShader();
     void updateCachedVertexExecutableIndex();
     void updateCachedPixelExecutableIndex();