Don't perform analysis twice in InstancedRendering::Op
authorBrian Salomon <bsalomon@google.com>
Thu, 30 Mar 2017 01:28:20 +0000 (21:28 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 30 Mar 2017 13:36:39 +0000 (13:36 +0000)
Change-Id: Ie0aeeb7bf63090b0c27a9b062cce0cdc561a1d7e
Reviewed-on: https://skia-review.googlesource.com/10583
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>

src/gpu/GrPipelineAnalysis.h
src/gpu/instanced/InstancedRendering.cpp
src/gpu/instanced/InstancedRendering.h

index 5f4699e..caf41b8 100644 (file)
@@ -58,6 +58,20 @@ public:
         return (kColorIsKnown_Flag & fFlags) ? fColor == that.fColor : true;
     }
 
+    /** The returned value reflects the common properties of the two inputs. */
+    static GrPipelineAnalysisColor Combine(const GrPipelineAnalysisColor& a,
+                                           const GrPipelineAnalysisColor& b) {
+        GrPipelineAnalysisColor result;
+        uint32_t commonFlags = a.fFlags & b.fFlags;
+        if ((kColorIsKnown_Flag & commonFlags) && a.fColor == b.fColor) {
+            result.fColor = a.fColor;
+            result.fFlags = a.fFlags;
+        } else if (kIsOpaque_Flag & commonFlags) {
+            result.fFlags = kIsOpaque_Flag;
+        }
+        return result;
+    }
+
 private:
     enum Flags {
         kColorIsKnown_Flag = 0x1,
index 2550f9d..f6ea628 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #include "InstancedRendering.h"
-
+#include "GrAppliedClip.h"
 #include "GrCaps.h"
 #include "GrOpFlushState.h"
 #include "GrPipeline.h"
@@ -122,8 +122,6 @@ std::unique_ptr<InstancedRendering::Op> InstancedRendering::recordShape(
     op->fInfo.setAAType(aaType);
     op->fInfo.fShapeTypes = GetShapeFlag(type);
     op->fInfo.fCannotDiscard = true;
-    op->fDrawColorsAreOpaque = GrColorIsOpaque(color);
-    op->fDrawColorsAreSame = true;
     Instance& instance = op->getSingleInstance();
     instance.fInfo = (int)type << kShapeType_InfoBit;
 
@@ -343,6 +341,8 @@ bool InstancedRendering::Op::xpRequiresDstTexture(const GrCaps& caps, const GrAp
     }
     fProcessors.analyzeAndEliminateFragmentProcessors(&analysis, this->getSingleInstance().fColor,
                                                       coverageInput, clip, caps);
+    fAnalysisColor = analysis.outputColor();
+
     Draw& draw = this->getSingleDraw(); // This will assert if we have > 1 command.
     SkASSERT(draw.fGeometry.isEmpty());
     SkASSERT(SkIsPow2(fInfo.fShapeTypes));
@@ -407,9 +407,7 @@ bool InstancedRendering::Op::onCombineIfPossible(GrOp* other, const GrCaps& caps
     this->joinBounds(*that);
     fInfo = combinedInfo;
     fPixelLoad += that->fPixelLoad;
-    fDrawColorsAreOpaque = fDrawColorsAreOpaque && that->fDrawColorsAreOpaque;
-    fDrawColorsAreSame = fDrawColorsAreSame && that->fDrawColorsAreSame &&
-                         fHeadDraw->fInstance.fColor == that->fHeadDraw->fInstance.fColor;
+    fAnalysisColor = GrPipelineAnalysisColor::Combine(fAnalysisColor, that->fAnalysisColor);
     // Adopt the other op's draws.
     fNumDraws += that->fNumDraws;
     fNumChangesInGeometry += that->fNumChangesInGeometry;
@@ -466,28 +464,20 @@ void InstancedRendering::Op::onExecute(GrOpFlushState* state) {
 
     state->gpu()->handleDirtyContext();
 
-    // TODO: Don't reanalyze the processors.
-    GrProcessorSet::FragmentProcessorAnalysis analysis;
-    GrPipelineAnalysisCoverage coverageInput;
+    const GrAppliedClip* clip = state->drawOpArgs().fAppliedClip;
+    GrPipelineAnalysisCoverage coverage;
     if (GrAAType::kCoverage == fInfo.aaType() ||
+        (clip && clip->clipCoverageFragmentProcessor()) ||
         (GrAAType::kNone == fInfo.aaType() && !fInfo.isSimpleRects() && fInfo.fCannotDiscard)) {
-        coverageInput = GrPipelineAnalysisCoverage::kSingleChannel;
+        coverage = GrPipelineAnalysisCoverage::kSingleChannel;
     } else {
-        coverageInput = GrPipelineAnalysisCoverage::kNone;
+        coverage = GrPipelineAnalysisCoverage::kNone;
     }
-    GrPipelineAnalysisColor colorInput;
-    if (fDrawColorsAreSame) {
-        colorInput = fHeadDraw->fInstance.fColor;
-    } else if (fDrawColorsAreOpaque) {
-        colorInput = GrPipelineAnalysisColor::Opaque::kYes;
-    }
-    const GrAppliedClip* clip = state->drawOpArgs().fAppliedClip;
-    analysis.init(colorInput, coverageInput, fProcessors, clip, state->caps());
 
     GrPipeline pipeline;
     GrPipeline::InitArgs args;
-    args.fInputColor = analysis.outputColor();
-    args.fInputCoverage = analysis.outputCoverage();
+    args.fInputColor = fAnalysisColor;
+    args.fInputCoverage = coverage;
     args.fAppliedClip = clip;
     args.fCaps = &state->caps();
     args.fProcessors = &fProcessors;
index c2db768..2fa433f 100644 (file)
@@ -151,10 +151,9 @@ protected:
         OpInfo fInfo;
         SkScalar fPixelLoad;
         GrProcessorSet fProcessors;
+        GrPipelineAnalysisColor fAnalysisColor;
         SkSTArray<5, ParamsTexel, true> fParams;
-        bool fIsTracked : 1;
-        bool fDrawColorsAreOpaque : 1;
-        bool fDrawColorsAreSame : 1;
+        bool fIsTracked;
         int fNumDraws;
         int fNumChangesInGeometry;
         Draw* fHeadDraw;