Misc batch->op cleanup Part 2 of 2
authorBrian Salomon <bsalomon@google.com>
Wed, 21 Dec 2016 16:38:53 +0000 (11:38 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 21 Dec 2016 17:18:42 +0000 (17:18 +0000)
Change-Id: Iedfe5bd019ca1171ab09de569f74c57975aa54c9
Reviewed-on: https://skia-review.googlesource.com/6384
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
21 files changed:
src/gpu/ops/GrAAFillRectOp.cpp
src/gpu/ops/GrAAHairLinePathRenderer.cpp
src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
src/gpu/ops/GrAAStrokeRectOp.cpp
src/gpu/ops/GrAnalyticRectOp.cpp
src/gpu/ops/GrClearOp.h
src/gpu/ops/GrDefaultPathRenderer.cpp
src/gpu/ops/GrDrawAtlasOp.cpp
src/gpu/ops/GrDrawOp.h
src/gpu/ops/GrDrawVerticesOp.cpp
src/gpu/ops/GrDrawVerticesOp.h
src/gpu/ops/GrMeshDrawOp.h
src/gpu/ops/GrNonAAFillRectOp.cpp
src/gpu/ops/GrNonAAFillRectPerspectiveOp.cpp
src/gpu/ops/GrNonAAStrokeRectOp.cpp
src/gpu/ops/GrOp.h
src/gpu/ops/GrOvalOpFactory.cpp
src/gpu/ops/GrRectOpFactory.h
src/gpu/ops/GrRegionOp.cpp
src/gpu/ops/GrShadowRRectOp.cpp
src/gpu/ops/GrTestMeshDrawOp.h

index e00ed55..0158d60 100644 (file)
@@ -182,7 +182,7 @@ public:
 
     SkString dumpInfo() const override {
         SkString str;
-        str.appendf("# batched: %d\n", fRectCnt);
+        str.appendf("# combined: %d\n", fRectCnt);
         const RectInfo* info = this->first();
         for (int i = 0; i < fRectCnt; ++i) {
             const SkRect& rect = info->rect();
index 9228318..affef55 100644 (file)
@@ -754,8 +754,8 @@ private:
             return false;
         }
 
-        // TODO we can actually batch hairlines if they are the same color in a kind of bulk method
-        // but we haven't implemented this yet
+        // TODO we can actually combine hairlines if they are the same color in a kind of bulk
+        // method but we haven't implemented this yet
         // TODO investigate going to vertex color and coverage?
         if (this->coverage() != that->coverage()) {
             return false;
index 40d6083..b96e90a 100644 (file)
@@ -189,7 +189,6 @@ private:
         }
         optimizations.getOverrideColorIfSet(&fPaths[0].fColor);
 
-        // setup batch properties
         fColor = fPaths[0].fColor;
         fUsesLocalCoords = optimizations.readsLocalCoords();
         fCoverageIgnored = !optimizations.readsCoverage();
index 711129f..1c70059 100644 (file)
@@ -385,13 +385,13 @@ bool AAStrokeRectOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
         return false;
     }
 
-    // TODO batch across miterstroke changes
+    // TODO combine across miterstroke changes
     if (this->miterStroke() != that->miterStroke()) {
         return false;
     }
 
     // We apply the viewmatrix to the rect points on the cpu.  However, if the pipeline uses
-    // local coords then we won't be able to batch.  We could actually upload the viewmatrix
+    // local coords then we won't be able to combine.  We could actually upload the viewmatrix
     // using vertex attributes in these cases, but haven't investigated that
     if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
         return false;
index cd4b690..01e9e33 100644 (file)
@@ -252,7 +252,7 @@ public:
         this->setBounds(bounds, HasAABloat::kYes, IsZeroArea::kNo);
     }
 
-    const char* name() const override { return "AnalyticRectBatch"; }
+    const char* name() const override { return "AnalyticRectOp"; }
 
     SkString dumpInfo() const override {
         SkString string;
index f2baefd..03722ca 100644 (file)
@@ -60,7 +60,7 @@ private:
         , fColor(color) {
         SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height());
         if (fClip.scissorEnabled()) {
-            // Don't let scissors extend outside the RT. This may improve batching.
+            // Don't let scissors extend outside the RT. This may improve op combining.
             if (!fClip.intersect(rtRect)) {
                 return;
             }
index e6c6f31..47c7ada 100644 (file)
@@ -620,8 +620,8 @@ DRAW_OP_TEST_DEFINE(DefaultPathOp) {
     GrColor color = GrRandomColor(random);
     SkMatrix viewMatrix = GrTest::TestMatrix(random);
 
-    // For now just hairlines because the other types of draws require two batches.
-    // TODO we should figure out a way to combine the stencil and cover steps into one batch
+    // For now just hairlines because the other types of draws require two ops.
+    // TODO we should figure out a way to combine the stencil and cover steps into one op.
     GrStyle style(SkStrokeRec::kHairline_InitStyle);
     SkPath path = GrTest::TestPath(random);
 
index 3ce079b..eac8f96 100644 (file)
@@ -27,7 +27,6 @@ void GrDrawAtlasOp::applyPipelineOptimizations(const GrPipelineOptimizations& op
         }
     }
 
-    // setup batch properties
     fColorIgnored = !optimizations.readsColor();
     fColor = fGeoData[0].fColor;
     // We'd like to assert this, but we can't because of GLPrograms test
index 929513c..ad8a545 100644 (file)
@@ -5,8 +5,8 @@
  * found in the LICENSE file.
  */
 
-#ifndef GrDrawBatch_DEFINED
-#define GrDrawBatch_DEFINED
+#ifndef GrDrawOp_DEFINED
+#define GrDrawOp_DEFINED
 
 #include <functional>
 #include "GrOp.h"
@@ -40,7 +40,7 @@ private:
 };
 
 /**
- * Base class for GrOps that draw. These batches have a GrPipeline installed by GrOpList.
+ * Base class for GrOps that draw. These ops have a GrPipeline installed by GrOpList.
  */
 class GrDrawOp : public GrOp {
 public:
index 12c2a0b..db505f9 100644 (file)
@@ -175,7 +175,7 @@ bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
         return false;
     }
 
-    if (!this->batchablePrimitiveType() || this->primitiveType() != that->primitiveType()) {
+    if (!this->combinablePrimitive() || this->primitiveType() != that->primitiveType()) {
         return false;
     }
 
index 57215fc..2c1580d 100644 (file)
@@ -54,7 +54,7 @@ private:
     void onPrepareDraws(Target*) const override;
 
     GrPrimitiveType primitiveType() const { return fPrimitiveType; }
-    bool batchablePrimitiveType() const {
+    bool combinablePrimitive() const {
         return kTriangles_GrPrimitiveType == fPrimitiveType ||
                kLines_GrPrimitiveType == fPrimitiveType ||
                kPoints_GrPrimitiveType == fPrimitiveType;
index 6100166..20e55c9 100644 (file)
@@ -5,8 +5,8 @@
  * found in the LICENSE file.
  */
 
-#ifndef GrVertexBatch_DEFINED
-#define GrVertexBatch_DEFINED
+#ifndef GrMeshDrawOp_DEFINED
+#define GrMeshDrawOp_DEFINED
 
 #include "GrDrawOp.h"
 #include "GrGeometryProcessor.h"
@@ -28,7 +28,7 @@ public:
 
 protected:
     /** Helper for rendering instances using an instanced index index buffer. This class creates the
-        space for the vertices and flushes the draws to the batch target. */
+        space for the vertices and flushes the draws to the GrMeshDrawOp::Target. */
     class InstancedHelper {
     public:
         InstancedHelper() {}
@@ -37,7 +37,7 @@ protected:
         void* init(Target*, GrPrimitiveType, size_t vertexStride, const GrBuffer*,
                    int verticesPerInstance, int indicesPerInstance, int instancesToDraw);
 
-        /** Call after init() to issue draws to the batch target.*/
+        /** Call after init() to issue draws to the GrMeshDrawOp::Target.*/
         void recordDraw(Target*, const GrGeometryProcessor*);
 
     private:
@@ -69,7 +69,7 @@ private:
     virtual void onPrepareDraws(Target*) const = 0;
 
     // A set of contiguous draws that share a draw token and primitive processor. The draws all use
-    // the batch's pipeline. The meshes for the draw are stored in the fMeshes array and each
+    // the op's pipeline. The meshes for the draw are stored in the fMeshes array and each
     // Queued draw uses fMeshCnt meshes from the fMeshes array. The reason for coallescing meshes
     // that share a primitive processor into a QueuedDraw is that it allows the Gpu object to setup
     // the shared state once and then issue draws for each mesh.
@@ -78,8 +78,8 @@ private:
         GrPendingProgramElement<const GrGeometryProcessor> fGeometryProcessor;
     };
 
-    // All draws in all the vertex batches have implicit tokens based on the order they are
-    // enqueued globally across all batches. This is the offset of the first entry in fQueuedDraws.
+    // All draws in all the GrMeshDrawOps have implicit tokens based on the order they are enqueued
+    // globally across all ops. This is the offset of the first entry in fQueuedDraws.
     // fQueuedDraws[i]'s token is fBaseDrawToken + i.
     GrDrawOpUploadToken fBaseDrawToken;
 
index 3995790..afef8e6 100644 (file)
@@ -20,7 +20,7 @@
 static const int kVertsPerInstance = 4;
 static const int kIndicesPerInstance = 6;
 
-/** We always use per-vertex colors so that rects can be batched across color changes. Sometimes
+/** We always use per-vertex colors so that rects can be combined across color changes. Sometimes
     we  have explicit local coords and sometimes not. We *could* always provide explicit local
     coords and just duplicate the positions when the caller hasn't provided a local coord rect,
     but we haven't seen a use case which frequently switches between local rect and no local
@@ -98,7 +98,7 @@ public:
 
     SkString dumpInfo() const override {
         SkString str;
-        str.appendf("# batched: %d\n", fRects.count());
+        str.appendf("# combined: %d\n", fRects.count());
         for (int i = 0; i < fRects.count(); ++i) {
             const RectInfo& info = fRects[i];
             str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", i,
index d58e52c..9b6a857 100644 (file)
@@ -18,7 +18,7 @@
 static const int kVertsPerInstance = 4;
 static const int kIndicesPerInstance = 6;
 
-/** We always use per-vertex colors so that rects can be batched across color changes. Sometimes
+/** We always use per-vertex colors so that rects can be combined across color changes. Sometimes
     we  have explicit local coords and sometimes not. We *could* always provide explicit local
     coords and just duplicate the positions when the caller hasn't provided a local coord rect,
     but we haven't seen a use case which frequently switches between local rect and no local
@@ -88,7 +88,7 @@ static void tesselate(intptr_t vertices,
     }
 }
 
-// We handle perspective in the local matrix or viewmatrix with special batches
+// We handle perspective in the local matrix or viewmatrix with special ops.
 class NonAAFillRectPerspectiveOp final : public GrMeshDrawOp {
 public:
     DEFINE_OP_CLASS_ID
@@ -111,11 +111,11 @@ public:
         this->setTransformedBounds(rect, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
     }
 
-    const char* name() const override { return "NonAAFillRectPerspectiveBatch"; }
+    const char* name() const override { return "NonAAFillRectPerspectiveOp"; }
 
     SkString dumpInfo() const override {
         SkString str;
-        str.appendf("# batched: %d\n", fRects.count());
+        str.appendf("# combined: %d\n", fRects.count());
         for (int i = 0; i < fRects.count(); ++i) {
             const RectInfo& geo = fRects[0];
             str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", i,
@@ -189,7 +189,7 @@ private:
             return false;
         }
 
-        // We could batch across perspective vm changes if we really wanted to
+        // We could combine across perspective vm changes if we really wanted to.
         if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) {
             return false;
         }
@@ -200,8 +200,8 @@ private:
             return false;
         }
 
-        // In the event of two batches, one who can tweak, one who cannot, we just fall back to
-        // not tweaking
+        // In the event of two ops, one who can tweak, one who cannot, we just fall back to not
+        // tweaking.
         if (fOptimizations.canTweakAlphaForCoverage() &&
             !that->fOptimizations.canTweakAlphaForCoverage()) {
             fOptimizations = that->fOptimizations;
index 09eb656..1600241 100644 (file)
@@ -49,7 +49,7 @@ class NonAAStrokeRectOp final : public GrMeshDrawOp {
 public:
     DEFINE_OP_CLASS_ID
 
-    const char* name() const override { return "NonAAStrokeRectBatch"; }
+    const char* name() const override { return "NonAAStrokeRectOp"; }
 
     SkString dumpInfo() const override {
         SkString string;
@@ -165,8 +165,8 @@ private:
     }
 
     bool onCombineIfPossible(GrOp* t, const GrCaps&) override {
-        // NonAA stroke rects cannot batch right now
-        // TODO make these batchable
+        // NonAA stroke rects cannot combine right now
+        // TODO make these combinable.
         return false;
     }
 
index 827e58e..586d685 100644 (file)
@@ -5,8 +5,8 @@
  * found in the LICENSE file.
  */
 
-#ifndef GrBatch_DEFINED
-#define GrBatch_DEFINED
+#ifndef GrOp_DEFINED
+#define GrOp_DEFINED
 
 #include "../private/SkAtomics.h"
 #include "GrGpuResource.h"
@@ -22,10 +22,11 @@ class GrGpuCommandBuffer;
 class GrOpFlushState;
 
 /**
- * GrOp is the base class for all Ganesh deferred GPU operations. To facilitate reorderable
- * batching, Ganesh does not generate geometry inline with draw calls. Instead, it captures the
- * arguments to the draw and then generates the geometry on demand. This gives GrOp subclasses
- * complete freedom to decide how/what they can batch.
+ * GrOp is the base class for all Ganesh deferred GPU operations. To facilitate reordering and to
+ * minimize draw calls, Ganesh does not generate geometry inline with draw calls. Instead, it
+ * captures the arguments to the draw and then generates the geometry when flushing. This gives GrOp
+ * subclasses complete freedom to decide how/when to combine in order to produce fewer draw calls
+ * and minimize state changes.
  *
  * Ops of the same subclass may be merged using combineIfPossible. When two ops merge, one
  * takes on the union of the data and the other is left empty. The merged op becomes responsible
@@ -126,7 +127,7 @@ public:
     /** Issues the op's commands to GrGpu. */
     void draw(GrOpFlushState* state, const SkRect& bounds) { this->onDraw(state, bounds); }
 
-    /** Used to block batching across render target changes. Remove this once we store
+    /** Used to block combining across render target changes. Remove this once we store
         GrOps for different RTs in different targets. */
     // TODO: this needs to be updated to return GrSurfaceProxy::UniqueID
     virtual GrGpuResource::UniqueID renderTargetUniqueID() const = 0;
index 321d15d..5a9a077 100644 (file)
@@ -69,7 +69,7 @@ static inline bool circle_stays_circle(const SkMatrix& m) { return m.isSimilarit
  * Additional clip planes are supported for rendering circular arcs. The additional planes are
  * either intersected or unioned together. Up to three planes are supported (an initial plane,
  * a plane intersected with the initial plane, and a plane unioned with the first two). Only two
- * are useful for any given arc, but having all three in one instance allows batching different
+ * are useful for any given arc, but having all three in one instance allows combining different
  * types of arcs.
  */
 
@@ -2275,8 +2275,8 @@ static sk_sp<GrDrawOp> make_rrect_op(GrColor color,
     SkASSERT(rrect.isSimple());
     SkASSERT(!rrect.isOval());
 
-    // RRect batchs only handle simple, but not too simple, rrects
-    // do any matrix crunching before we reset the draw state for device coords
+    // RRect ops only handle simple, but not too simple, rrects.
+    // Do any matrix crunching before we reset the draw state for device coords.
     const SkRect& rrectBounds = rrect.getBounds();
     SkRect bounds;
     viewMatrix.mapRect(&bounds, rrectBounds);
index 8d06cda..90263a0 100644 (file)
@@ -23,7 +23,7 @@ struct SkRect;
 class SkStrokeRec;
 
 /**
- * A factory for returning batches which can draw rectangles.
+ * A factory for returning GrDrawOps which can draw rectangles.
  */
 namespace GrRectOpFactory {
 
index 1128b92..4d45d80 100644 (file)
@@ -68,7 +68,7 @@ public:
 
     SkString dumpInfo() const override {
         SkString str;
-        str.appendf("# batched: %d\n", fRegions.count());
+        str.appendf("# combined: %d\n", fRegions.count());
         for (int i = 0; i < fRegions.count(); ++i) {
             const RegionInfo& info = fRegions[i];
             str.appendf("%d: Color: 0x%08x, Region with %d rects\n", i, info.fColor,
index 5da8c29..b5829f4 100755 (executable)
@@ -826,12 +826,12 @@ private:
 
 ///////////////////////////////////////////////////////////////////////////////
 
-sk_sp<GrDrawOp> make_shadow_circle_batch(GrColor color,
-                                         const SkMatrix& viewMatrix,
-                                         const SkRect& oval,
-                                         SkScalar blurRadius,
-                                         const SkStrokeRec& stroke,
-                                         const GrShaderCaps* shaderCaps) {
+sk_sp<GrDrawOp> make_shadow_circle_op(GrColor color,
+                                      const SkMatrix& viewMatrix,
+                                      const SkRect& oval,
+                                      SkScalar blurRadius,
+                                      const SkStrokeRec& stroke,
+                                      const GrShaderCaps* shaderCaps) {
     // we can only draw circles
     SkScalar width = oval.width();
     SkASSERT(SkScalarNearlyEqual(width, oval.height()) && viewMatrix.isSimilarity());
@@ -840,17 +840,17 @@ sk_sp<GrDrawOp> make_shadow_circle_batch(GrColor color,
                                 GrStyle(stroke, nullptr));
 }
 
-static sk_sp<GrDrawOp> make_shadow_rrect_batch(GrColor color,
-                                               const SkMatrix& viewMatrix,
-                                               const SkRRect& rrect,
-                                               SkScalar blurRadius,
-                                               const SkStrokeRec& stroke) {
+static sk_sp<GrDrawOp> make_shadow_rrect_op(GrColor color,
+                                            const SkMatrix& viewMatrix,
+                                            const SkRRect& rrect,
+                                            SkScalar blurRadius,
+                                            const SkStrokeRec& stroke) {
     SkASSERT(viewMatrix.rectStaysRect());
     SkASSERT(rrect.isSimple());
     SkASSERT(!rrect.isOval());
 
-    // Shadow rrect batchs only handle simple circular rrects
-    // do any matrix crunching before we reset the draw state for device coords
+    // Shadow rrect ops only handle simple circular rrects.
+    // Do any matrix crunching before we reset the draw state for device coords.
     const SkRect& rrectBounds = rrect.getBounds();
     SkRect bounds;
     viewMatrix.mapRect(&bounds, rrectBounds);
@@ -909,15 +909,15 @@ sk_sp<GrDrawOp> Make(GrColor color,
                      const SkStrokeRec& stroke,
                      const GrShaderCaps* shaderCaps) {
     if (rrect.isOval()) {
-        return make_shadow_circle_batch(color, viewMatrix, rrect.getBounds(), blurRadius, stroke,
-                                        shaderCaps);
+        return make_shadow_circle_op(color, viewMatrix, rrect.getBounds(), blurRadius, stroke,
+                                     shaderCaps);
     }
 
     if (!viewMatrix.rectStaysRect() || !rrect.isSimple()) {
         return nullptr;
     }
 
-    return make_shadow_rrect_batch(color, viewMatrix, rrect, blurRadius, stroke);
+    return make_shadow_rrect_op(color, viewMatrix, rrect, blurRadius, stroke);
 }
 }
 ///////////////////////////////////////////////////////////////////////////////
@@ -953,8 +953,8 @@ DRAW_OP_TEST_DEFINE(ShadowRRectOp) {
     GrColor color = GrRandomColor(random);
     const SkRRect& rrect = GrTest::TestRRectSimple(random);
     SkScalar blurRadius = random->nextSScalar1() * 72.f;
-    return make_shadow_rrect_batch(color, viewMatrix, rrect, blurRadius,
-                                   GrTest::TestStrokeRec(random));
+    return make_shadow_rrect_op(color, viewMatrix, rrect, blurRadius,
+                                GrTest::TestStrokeRec(random));
 }
 
 #endif
index 2878b6b..7fc44e1 100644 (file)
@@ -14,8 +14,8 @@
 #include "ops/GrMeshDrawOp.h"
 
 /*
- * A simple solid color batch only for testing purposes which actually doesn't batch at all. It
- * saves having to fill out some boiler plate methods.
+ * A simple solid color GrMeshDrawOp for testing purposes which doesn't ever combine. Subclassing
+ * this in tests saves having to fill out some boiler plate methods.
  */
 class GrTestMeshDrawOp : public GrMeshDrawOp {
 public:
@@ -28,6 +28,17 @@ protected:
         this->setBounds(bounds, HasAABloat::kYes, IsZeroArea::kYes);
     }
 
+    GrColor color() const { return fColor; }
+
+    struct Optimizations {
+        bool fColorIgnored = false;
+        bool fUsesLocalCoords = false;
+        bool fCoverageIgnored = false;
+    };
+
+    const Optimizations optimizations() const { return fOptimizations; }
+
+private:
     void getPipelineAnalysisInput(GrPipelineAnalysisDrawOpInput* input) const override {
         input->pipelineColorInput()->setKnownFourComponents(fColor);
         input->pipelineCoverageInput()->setUnknownSingleComponent();
@@ -41,16 +52,6 @@ protected:
         fOptimizations.fCoverageIgnored = !optimizations.readsCoverage();
     }
 
-    struct Optimizations {
-        bool fColorIgnored = false;
-        bool fUsesLocalCoords = false;
-        bool fCoverageIgnored = false;
-    };
-
-    GrColor color() const { return fColor; }
-    const Optimizations optimizations() const { return fOptimizations; }
-
-private:
     bool onCombineIfPossible(GrOp*, const GrCaps&) override { return false; }
 
     GrColor       fColor;