Revert "Add a requiresVertexShader method to GrGLEffect"
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 30 Sep 2013 15:13:58 +0000 (15:13 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 30 Sep 2013 15:13:58 +0000 (15:13 +0000)
This reverts commit 1a30a3af805b7ea688d4a0f0bfe373c204085a27. We're
going to take a different direction for vertexless shaders.

R=bsalomon@google.com

Author: cdalton@nvidia.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@11521 2bbb7eff-a529-9590-31e7-b0007b416f81

src/gpu/GrAAConvexPathRenderer.cpp
src/gpu/GrAARectRenderer.cpp
src/gpu/GrOvalRenderer.cpp
src/gpu/effects/GrBezierEffect.cpp
src/gpu/effects/GrSimpleTextureEffect.cpp
src/gpu/gl/GrGLEffect.h
src/gpu/gl/GrGLEffectMatrix.cpp
src/gpu/gl/GrGLProgram.cpp
src/gpu/gl/GrGLProgram.h
src/gpu/gl/GrGLShaderBuilder.cpp
src/gpu/gl/GrGLShaderBuilder.h

index 8fa9499..6749b46 100644 (file)
@@ -524,8 +524,6 @@ public:
         GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
             : INHERITED (factory) {}
 
-        virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
-
         virtual void emitCode(GrGLShaderBuilder* builder,
                               const GrDrawEffect& drawEffect,
                               EffectKey key,
index 76a5c8c..4856bb5 100644 (file)
@@ -43,8 +43,6 @@ public:
         GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
         : INHERITED (factory) {}
 
-        virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
-
         virtual void emitCode(GrGLShaderBuilder* builder,
                               const GrDrawEffect& drawEffect,
                               EffectKey key,
@@ -165,8 +163,6 @@ public:
         GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
         : INHERITED (factory) {}
 
-        virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
-
         virtual void emitCode(GrGLShaderBuilder* builder,
                               const GrDrawEffect& drawEffect,
                               EffectKey key,
index 946cdc0..013c7ab 100644 (file)
@@ -91,8 +91,6 @@ public:
         GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
         : INHERITED (factory) {}
 
-        virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
-
         virtual void emitCode(GrGLShaderBuilder* builder,
                               const GrDrawEffect& drawEffect,
                               EffectKey key,
@@ -207,8 +205,6 @@ public:
         GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
         : INHERITED (factory) {}
 
-        virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
-
         virtual void emitCode(GrGLShaderBuilder* builder,
                               const GrDrawEffect& drawEffect,
                               EffectKey key,
index 0131690..c7eadb7 100644 (file)
@@ -15,8 +15,6 @@ class GrGLConicEffect : public GrGLEffect {
 public:
     GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
 
-    virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
-
     virtual void emitCode(GrGLShaderBuilder* builder,
                           const GrDrawEffect& drawEffect,
                           EffectKey key,
@@ -160,8 +158,6 @@ class GrGLQuadEffect : public GrGLEffect {
 public:
     GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
 
-    virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
-
     virtual void emitCode(GrGLShaderBuilder* builder,
                           const GrDrawEffect& drawEffect,
                           EffectKey key,
@@ -294,8 +290,6 @@ class GrGLCubicEffect : public GrGLEffect {
 public:
     GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
 
-    virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
-
     virtual void emitCode(GrGLShaderBuilder* builder,
                           const GrDrawEffect& drawEffect,
                           EffectKey key,
index 88ba56a..cf08d3b 100644 (file)
@@ -24,11 +24,6 @@ public:
         }
     }
 
-    virtual bool requiresVertexShader(const GrDrawEffect& drawEffect) const SK_OVERRIDE {
-        const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
-        return GrEffect::kCustom_CoordsType == ste.coordsType();
-    }
-
     virtual void emitCode(GrGLShaderBuilder* builder,
                           const GrDrawEffect& drawEffect,
                           EffectKey key,
index 2d7258e..5df2281 100644 (file)
@@ -51,13 +51,6 @@ public:
 
     virtual ~GrGLEffect();
 
-    /** Called when GrGLProgram is about to create its GrGLShaderBuilder. When possible, effects
-        should handle programs that don't have a vertex shader. But if an effect requires special
-        vertex processing that can't be accomplished with the fixed pipeline, it can override this
-        method and return true to guarantee the GrGLShaderBuilder in emitCode has a VertexBuilder.
-        */
-    virtual bool requiresVertexShader(const GrDrawEffect&) const { return false; }
-
     /** Called when the program stage should insert its code into the shaders. The code in each
         shader will be in its own block ({}) and so locally scoped names will not collide across
         stages.
index 512bef9..880df12 100644 (file)
@@ -48,7 +48,6 @@ GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
                                     SkString* fsCoordName,
                                     SkString* vsCoordName,
                                     const char* suffix) {
-    // TODO: Handle vertexless shaders here before we start enabling them.
     GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder();
     SkASSERT(NULL != vertexBuilder);
 
index ebc5782..ac9794d 100644 (file)
@@ -446,32 +446,10 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
     SkASSERT(0 == fProgramID);
 
     const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
-    bool hasExplicitLocalCoords = -1 != header.fLocalCoordAttributeIndex;
 
-    // Get the coeffs for the Mode-based color filter, determine if color is needed.
-    SkXfermode::Coeff colorCoeff;
-    SkXfermode::Coeff filterColorCoeff;
-    SkAssertResult(
-        SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilterXfermode),
-                                &filterColorCoeff,
-                                &colorCoeff));
-    bool needColor, needFilterColor;
-    need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor);
+    bool needsVertexShader = true;
 
-    // Create the GL effects.
-    bool hasVertexShaderEffects = false;
-
-    SkTArray<GrDrawEffect> colorDrawEffects(needColor ? fDesc.numColorEffects() : 0);
-    if (needColor) {
-        this->buildGLEffects(&GrGLProgram::fColorEffects, colorStages, fDesc.numColorEffects(),
-                             hasExplicitLocalCoords, &colorDrawEffects, &hasVertexShaderEffects);
-    }
-
-    SkTArray<GrDrawEffect> coverageDrawEffects(fDesc.numCoverageEffects());
-    this->buildGLEffects(&GrGLProgram::fCoverageEffects, coverageStages, fDesc.numCoverageEffects(),
-                         hasExplicitLocalCoords, &coverageDrawEffects, &hasVertexShaderEffects);
-
-    GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, hasVertexShaderEffects);
+    GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, needsVertexShader);
 
     if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuilder()) {
         const char* viewMName;
@@ -508,6 +486,16 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
     SkString inColor;
     GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor);
 
+    // Get the coeffs for the Mode-based color filter, determine if color is needed.
+    SkXfermode::Coeff colorCoeff;
+    SkXfermode::Coeff filterColorCoeff;
+    SkAssertResult(
+        SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilterXfermode),
+                                &filterColorCoeff,
+                                &colorCoeff));
+    bool needColor, needFilterColor;
+    need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor);
+
     // used in order for builder to return the per-stage uniform handles.
     typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr;
     int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverageEffects());
@@ -516,17 +504,20 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
 
     if (needColor) {
         for (int e = 0; e < fDesc.numColorEffects(); ++e) {
-            glEffects[e] = fColorEffects[e].fGLEffect;
             effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis;
         }
 
-        builder.emitEffects(glEffects.get(),
-                            colorDrawEffects.begin(),
+        builder.emitEffects(colorStages,
                             fDesc.effectKeys(),
                             fDesc.numColorEffects(),
                             &inColor,
                             &knownColorValue,
-                            effectUniformArrays.get());
+                            effectUniformArrays.get(),
+                            glEffects.get());
+
+        for (int e = 0; e < fDesc.numColorEffects(); ++e) {
+            fColorEffects[e].fGLEffect = glEffects[e];
+        }
     }
 
     // Insert the color filter. This will soon be replaced by a color effect.
@@ -557,17 +548,19 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
     GrSLConstantVec knownCoverageValue = this->genInputCoverage(&builder, &inCoverage);
 
     for (int e = 0; e < fDesc.numCoverageEffects(); ++e) {
-        glEffects[e] = fCoverageEffects[e].fGLEffect;
         effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis;
     }
 
-    builder.emitEffects(glEffects.get(),
-                        coverageDrawEffects.begin(),
+    builder.emitEffects(coverageStages,
                         fDesc.getEffectKeys() + fDesc.numColorEffects(),
                         fDesc.numCoverageEffects(),
                         &inCoverage,
                         &knownCoverageValue,
-                        effectUniformArrays.get());
+                        effectUniformArrays.get(),
+                        glEffects.get());
+    for (int e = 0; e < fDesc.numCoverageEffects(); ++e) {
+        fCoverageEffects[e].fGLEffect = glEffects[e];
+    }
 
     // discard if coverage is zero
     if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageValue) {
@@ -696,28 +689,6 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
     return true;
 }
 
-void GrGLProgram::buildGLEffects(SkTArray<EffectAndSamplers> GrGLProgram::* effectSet,
-                                 const GrEffectStage* stages[],
-                                 int count,
-                                 bool hasExplicitLocalCoords,
-                                 SkTArray<GrDrawEffect>* drawEffects,
-                                 bool* hasVertexShaderEffects) {
-    for (int e = 0; e < count; ++e) {
-        SkASSERT(NULL != stages[e] && NULL != stages[e]->getEffect());
-
-        const GrEffectStage& stage = *stages[e];
-        SkNEW_APPEND_TO_TARRAY(drawEffects, GrDrawEffect, (stage, hasExplicitLocalCoords));
-
-        const GrDrawEffect& drawEffect = (*drawEffects)[e];
-        GrGLEffect* effect = (this->*effectSet)[e].fGLEffect =
-            (*stage.getEffect())->getFactory().createGLInstance(drawEffect);
-
-        if (!*hasVertexShaderEffects && effect->requiresVertexShader(drawEffect)) {
-            *hasVertexShaderEffects = true;
-        }
-    }
-}
-
 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
                                                    bool bindColorOut,
                                                    bool bindDualSrcOut) {
index b18b8ae..09f7668 100644 (file)
@@ -178,14 +178,6 @@ private:
 
     void genGeometryShader(GrGLShaderBuilder::VertexBuilder* vertexBuilder) const;
 
-    // Creates a set of GrGLEffects and GrGLDrawEffects.
-    void buildGLEffects(SkTArray<EffectAndSamplers> GrGLProgram::* effectSet,
-                        const GrEffectStage* stages[],
-                        int count,
-                        bool hasExplicitLocalCoords,
-                        SkTArray<GrDrawEffect>* drawEffects,
-                        bool* hasVertexShaderEffects);
-
     // Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program
     bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
                                           bool bindColorOut,
index f73520c..d11394a 100644 (file)
@@ -94,7 +94,7 @@ static const char kDstCopyColorName[] = "_dstColor";
 GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
                                      GrGLUniformManager& uniformManager,
                                      const GrGLProgramDesc& desc,
-                                     bool hasVertexShaderEffects)
+                                     bool needsVertexShader)
     : fUniforms(kVarsPerBlock)
     , fCtxInfo(ctxInfo)
     , fUniformManager(uniformManager)
@@ -106,8 +106,9 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
 
     const GrGLProgramDesc::KeyHeader& header = desc.getHeader();
 
-    // TODO: go vertexless when possible.
-    fVertexBuilder.reset(SkNEW_ARGS(VertexBuilder, (this, desc)));
+    if (needsVertexShader) {
+        fVertexBuilder.reset(SkNEW_ARGS(VertexBuilder, (this, desc)));
+    }
 
     // Emit code to read the dst copy textue if necessary.
     if (kNoDstRead_DstReadKey != header.fDstReadKey &&
@@ -216,7 +217,7 @@ void GrGLShaderBuilder::nameVariable(SkString* out, char prefix, const char* nam
 
 const char* GrGLShaderBuilder::dstColor() {
     if (fCodeStage.inStageCode()) {
-        const GrEffectRef& effect = *fCodeStage.effect();
+        const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
         if (!effect->willReadDstColor()) {
             GrDebugCrash("GrGLEffect asked for dst color but its generating GrEffect "
                          "did not request access.");
@@ -362,7 +363,7 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t vi
 
 const char* GrGLShaderBuilder::fragmentPosition() {
     if (fCodeStage.inStageCode()) {
-        const GrEffectRef& effect = *fCodeStage.effect();
+        const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
         if (!effect->willReadFragmentPosition()) {
             GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect "
                          "did not request access.");
@@ -499,23 +500,24 @@ void GrGLShaderBuilder::finished(GrGLuint programID) {
 }
 
 void GrGLShaderBuilder::emitEffects(
-                        GrGLEffect* const glEffects[],
-                        const GrDrawEffect drawEffects[],
+                        const GrEffectStage* effectStages[],
                         const GrBackendEffectFactory::EffectKey effectKeys[],
                         int effectCnt,
                         SkString* fsInOutColor,
                         GrSLConstantVec* fsInOutColorKnownValue,
-                        SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[]) {
+                        SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[],
+                        GrGLEffect* glEffects[]) {
     bool effectEmitted = false;
 
     SkString inColor = *fsInOutColor;
     SkString outColor;
 
     for (int e = 0; e < effectCnt; ++e) {
-        const GrDrawEffect& drawEffect = drawEffects[e];
-        const GrEffectRef& effect = *drawEffect.effect();
+        SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect());
+        const GrEffectStage& stage = *effectStages[e];
+        const GrEffectRef& effect = *stage.getEffect();
 
-        CodeStage::AutoStageRestore csar(&fCodeStage, &effect);
+        CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
 
         int numTextures = effect->numTextures();
         SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers;
@@ -524,9 +526,11 @@ void GrGLShaderBuilder::emitEffects(
             textureSamplers[t].init(this, &effect->textureAccess(t), t);
             effectSamplerHandles[e]->push_back(textureSamplers[t].fSamplerUniform);
         }
+        GrDrawEffect drawEffect(stage, fVertexBuilder.get()
+                                       && fVertexBuilder->hasExplicitLocalCoords());
 
-        int numAttributes = drawEffect.getVertexAttribIndexCount();
-        const int* attributeIndices = drawEffect.getVertexAttribIndices();
+        int numAttributes = stage.getVertexAttribIndexCount();
+        const int* attributeIndices = stage.getVertexAttribIndices();
         SkSTArray<GrEffect::kMaxVertexAttribs, SkString> attributeNames;
         for (int a = 0; a < numAttributes; ++a) {
             // TODO: Make addAttribute mangle the name.
@@ -538,6 +542,8 @@ void GrGLShaderBuilder::emitEffects(
                                                attributeName);
         }
 
+        glEffects[e] = effect->getFactory().createGLInstance(drawEffect);
+
         if (kZeros_GrSLConstantVec == *fsInOutColorKnownValue) {
             // Effects have no way to communicate zeros, they treat an empty string as ones.
             this->nameVariable(&inColor, '\0', "input");
index 5f2983d..3c3275c 100644 (file)
@@ -108,7 +108,7 @@ public:
     GrGLShaderBuilder(const GrGLContextInfo&,
                       GrGLUniformManager&,
                       const GrGLProgramDesc&,
-                      bool hasVertexShaderEffects);
+                      bool needsVertexShader);
 
     /**
      * Use of these features may require a GLSL extension to be enabled. Shaders may not compile
@@ -257,13 +257,13 @@ public:
      * glEffects array is updated to contain the GrGLEffect generated for each entry in
      * effectStages.
      */
-    void emitEffects(GrGLEffect* const glEffects[],
-                     const GrDrawEffect drawEffects[],
+    void emitEffects(const GrEffectStage* effectStages[],
                      const GrBackendEffectFactory::EffectKey effectKeys[],
                      int effectCnt,
                      SkString*  inOutFSColor,
                      GrSLConstantVec* fsInOutColorKnownValue,
-                     SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[]);
+                     SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[],
+                     GrGLEffect* glEffects[]);
 
     GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
     GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const {
@@ -389,16 +389,16 @@ private:
 private:
     class CodeStage : public SkNoncopyable {
     public:
-        CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffect(NULL) {}
+        CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {}
 
         bool inStageCode() const {
             this->validate();
-            return NULL != fEffect;
+            return NULL != fEffectStage;
         }
 
-        const GrEffectRef* effect() const {
+        const GrEffectStage* effectStage() const {
             this->validate();
-            return fEffect;
+            return fEffectStage;
         }
 
         int stageIndex() const {
@@ -408,34 +408,34 @@ private:
 
         class AutoStageRestore : public SkNoncopyable {
         public:
-            AutoStageRestore(CodeStage* codeStage, const GrEffectRef* effect) {
+            AutoStageRestore(CodeStage* codeStage, const GrEffectStage* newStage) {
                 SkASSERT(NULL != codeStage);
                 fSavedIndex = codeStage->fCurrentIndex;
-                fSavedEffect = codeStage->fEffect;
+                fSavedEffectStage = codeStage->fEffectStage;
 
-                if (NULL == effect) {
+                if (NULL == newStage) {
                     codeStage->fCurrentIndex = -1;
                 } else {
                     codeStage->fCurrentIndex = codeStage->fNextIndex++;
                 }
-                codeStage->fEffect = effect;
+                codeStage->fEffectStage = newStage;
 
                 fCodeStage = codeStage;
             }
             ~AutoStageRestore() {
                 fCodeStage->fCurrentIndex = fSavedIndex;
-                fCodeStage->fEffect = fSavedEffect;
+                fCodeStage->fEffectStage = fSavedEffectStage;
             }
         private:
-            CodeStage*            fCodeStage;
-            int                   fSavedIndex;
-            const GrEffectRef*    fSavedEffect;
+            CodeStage*              fCodeStage;
+            int                     fSavedIndex;
+            const GrEffectStage*    fSavedEffectStage;
         };
     private:
-        void validate() const { SkASSERT((NULL == fEffect) == (-1 == fCurrentIndex)); }
-        int                   fNextIndex;
-        int                   fCurrentIndex;
-        const GrEffectRef*    fEffect;
+        void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurrentIndex)); }
+        int                     fNextIndex;
+        int                     fCurrentIndex;
+        const GrEffectStage*    fEffectStage;
     } fCodeStage;
 
     /**