Add some backend flexibility for shader declarations in ProgramBuilding.
authoregdaniel <egdaniel@google.com>
Tue, 9 Feb 2016 17:54:43 +0000 (09:54 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 9 Feb 2016 17:54:43 +0000 (09:54 -0800)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1682703003

Review URL: https://codereview.chromium.org/1682703003

src/gpu/gl/GrGLVaryingHandler.h
src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
src/gpu/glsl/GrGLSLProgramBuilder.h
src/gpu/glsl/GrGLSLVarying.cpp
src/gpu/glsl/GrGLSLVarying.h

index 50a87ad..fe8c3dc 100644 (file)
@@ -24,6 +24,8 @@ public:
                                            GrSLPrecision fsPrecision = kDefault_GrSLPrecision);
 
 private:
+    void onFinalize() override {}
+
     typedef GrGLProgramDataManager::VaryingInfo VaryingInfo;
     typedef GrGLProgramDataManager::VaryingInfoArray VaryingInfoArray;
 
index f97b854..7ec18a2 100644 (file)
@@ -216,6 +216,7 @@ void GrGLSLFragmentShaderBuilder::enableCustomOutput() {
         fOutputs.push_back().set(kVec4f_GrSLType,
                                  GrGLSLShaderVar::kOut_TypeModifier,
                                  DeclaredColorOutputName());
+        fProgramBuilder->finalizeFragmentOutputColor(fOutputs.back());
     }
 }
 
@@ -234,6 +235,7 @@ void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() {
     if (caps.mustDeclareFragmentShaderOutput()) {
         fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModifier,
                                  DeclaredSecondaryColorOutputName());
+        fProgramBuilder->finalizeFragmentSecondaryColor(fOutputs.back());
     }
 }
 
index 2249c3c..a277595 100644 (file)
@@ -69,6 +69,11 @@ public:
     virtual const GrGLSLUniformHandler* uniformHandler() const = 0;
     virtual GrGLSLVaryingHandler* varyingHandler() = 0;
 
+    // Used for backend customization of the output color and secondary color variables from the
+    // fragment processor. Only used if the outputs are explicitly declared in the shaders
+    virtual void finalizeFragmentOutputColor(GrGLSLShaderVar& outputColor) {}
+    virtual void finalizeFragmentSecondaryColor(GrGLSLShaderVar& outputColor) {}
+
     // number of each input/output type in a single allocation block, used by many builders
     static const int kVarsPerBlock;
 
index 279dd59..ea52fbe 100644 (file)
@@ -105,6 +105,10 @@ void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) {
     fVertexInputs.push_back(var);
 }
 
+void GrGLSLVaryingHandler::finalize() {
+    this->onFinalize();
+}
+
 void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) const {
     for (int i = 0; i < vars.count(); ++i) {
         vars[i].appendDecl(fProgramBuilder->glslCaps(), out);
index 116ba09..2243197 100644 (file)
@@ -79,6 +79,8 @@ public:
         , fFragOutputs(kVaryingsPerBlock)
         , fProgramBuilder(program) {}
 
+    virtual ~GrGLSLVaryingHandler() {}
+
     typedef GrTAllocator<GrGLSLShaderVar> VarArray;
     typedef GrGLSLProgramDataManager::VaryingHandle VaryingHandle;
 
@@ -106,6 +108,10 @@ public:
 
     void emitAttributes(const GrGeometryProcessor& gp);
 
+    // This should be called once all attributes and varyings have been added to the
+    // GrGLSLVaryingHanlder and before getting/adding any of the declarations to the shaders.
+    void finalize();
+
     void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const;
     void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const;
     void getFragDecls(SkString* inputDecls, SkString* outputDecls) const;
@@ -127,6 +133,8 @@ private:
 
     void addAttribute(const GrShaderVar& var);
 
+    virtual void onFinalize() = 0;
+
     // helper function for get*Decls
     void appendDecls(const VarArray& vars, SkString* out) const;