Index: src/gpu/instanced/InstancedRendering.cpp |
diff --git a/src/gpu/instanced/InstancedRendering.cpp b/src/gpu/instanced/InstancedRendering.cpp |
index 165bff494b3fa0ab1f241c844ec59afb8b582da9..12edc986c3534a34906421dff313af830d340af8 100644 |
--- a/src/gpu/instanced/InstancedRendering.cpp |
+++ b/src/gpu/instanced/InstancedRendering.cpp |
@@ -184,6 +184,7 @@ InstancedRendering::Batch* InstancedRendering::recordShape(ShapeType type, const |
const float* rectAsFloats = localRect.asScalars(); // Ensure SkScalar == float. |
memcpy(&instance.fLocalRect, rectAsFloats, 4 * sizeof(float)); |
+ batch->fPixelLoad = batch->fBounds.height() * batch->fBounds.width(); |
return batch; |
} |
@@ -366,14 +367,29 @@ bool InstancedRendering::Batch::onCombineIfPossible(GrBatch* other, const GrCaps |
SkASSERT(fTailDraw); |
SkASSERT(that->fTailDraw); |
- if (!fInfo.canJoin(that->fInfo) || |
+ if (!BatchInfo::CanCombine(fInfo, that->fInfo) || |
!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), |
*that->pipeline(), that->bounds(), caps)) { |
return false; |
} |
+ BatchInfo combinedInfo = fInfo | that->fInfo; |
+ if (!combinedInfo.isSimpleRects()) { |
+ // This threshold was chosen with the "shapes_mixed" bench on a MacBook with Intel graphics. |
+ // There seems to be a wide range where it doesn't matter if we combine or not. What matters |
+ // is that the itty bitty rects combine with other shapes and the giant ones don't. |
+ constexpr SkScalar kMaxPixelsToGeneralizeRects = 256 * 256; |
+ if (fInfo.isSimpleRects() && fPixelLoad > kMaxPixelsToGeneralizeRects) { |
+ return false; |
+ } |
+ if (that->fInfo.isSimpleRects() && that->fPixelLoad > kMaxPixelsToGeneralizeRects) { |
+ return false; |
+ } |
+ } |
+ |
fBounds.join(that->fBounds); |
- fInfo.join(that->fInfo); |
+ fInfo = combinedInfo; |
+ fPixelLoad += that->fPixelLoad; |
// Adopt the other batch's draws. |
fNumDraws += that->fNumDraws; |