diff options
author | Chris Dalton <csmartdalton@google.com> | 2017-11-01 19:21:24 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-01 19:21:31 +0000 |
commit | d8d1593b22d59114480cc5b7cb9eba7c4ac029fc (patch) | |
tree | 34c04f120dc4e1e6c5ab0413584662d9a5dfa7e7 /src/gpu/GrClipStackClip.cpp | |
parent | 721718059f39b0a5cff29028e30bc089e21a1244 (diff) |
Revert "Fold analytic clip FPs into GrReducedClip"
This reverts commit d29e0da3523e390eeb77b5a823d7ff86569ac1d3.
Reason for revert: More asserts
Original change's description:
> Fold analytic clip FPs into GrReducedClip
>
> Perf result on Pixel phone (sorted by impact):
>
> GEOMEAN 6.73 -> 6.49 ms [96% ]
>
> top25desk_pinterest.skp 0.45 -> 0.49 ms [107%]
> desk_pokemonwiki.skp 14.6 -> 15.9 ms [106%]
> keymobi_pinterest.skp 0.47 -> 0.49 ms [104%]
> ...
> keymobi_androidpolice_com_2012_.skp 3.69 -> 3.09 ms [83% ]
> keymobi_shop_mobileweb_ebay_com.skp 2.90 -> 2.29 ms [78% ]
> keymobi_boingboing_net.skp 2.95 -> 2.29 ms [76% ]
> desk_jsfiddlebigcar.skp 1.79 -> 1.29 ms [71% ]
> keymobi_m_youtube_com_watch_v_9.skp 12.9 -> 9.09 ms [70% ]
> keymobi_blogger.skp 3.80 -> 2.69 ms [70% ]
> keymobi_sfgate_com_.skp 8.16 -> 5.69 ms [69% ]
>
> Cleaner code, improved skps, slightly better geometric mean time.
>
> Pixel C is mostly unaffected, presumably because it uses window
> rectangles.
>
> Bug: skia:7190
> Change-Id: I9c7f3512ca57e1d1afcd42865357b63ffcc192ce
> Reviewed-on: https://skia-review.googlesource.com/66280
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Chris Dalton <csmartdalton@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com
Change-Id: Ia91076d7b7a240798f1543f892d41a2968b421ae
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:7190
Reviewed-on: https://skia-review.googlesource.com/66184
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src/gpu/GrClipStackClip.cpp')
-rw-r--r-- | src/gpu/GrClipStackClip.cpp | 159 |
1 files changed, 117 insertions, 42 deletions
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp index b18cb16c44..aa2b9fdd29 100644 --- a/src/gpu/GrClipStackClip.cpp +++ b/src/gpu/GrClipStackClip.cpp @@ -30,15 +30,7 @@ typedef SkClipStack::Element Element; typedef GrReducedClip::InitialState InitialState; typedef GrReducedClip::ElementList ElementList; -// An element count of 4 was chosen because of the common pattern in Blink of: -// isect RR -// diff RR -// isect convex_poly -// isect convex_poly -// when drawing rounded div borders. This could probably be tuned based on a configuration's -// relative costs of switching RTs to generate a mask vs longer shaders. static const int kMaxAnalyticElements = 4; - const char GrClipStackClip::kMaskTestTag[] = "clip_mask"; bool GrClipStackClip::quickContains(const SkRect& rect) const { @@ -184,6 +176,80 @@ bool GrClipStackClip::UseSWOnlyPath(GrContext* context, return false; } +static bool get_analytic_clip_processor(const ElementList& elements, + bool abortIfAA, + const SkRect& drawDevBounds, + std::unique_ptr<GrFragmentProcessor>* resultFP) { + SkASSERT(elements.count() <= kMaxAnalyticElements); + SkSTArray<kMaxAnalyticElements, std::unique_ptr<GrFragmentProcessor>> fps; + ElementList::Iter iter(elements); + while (iter.get()) { + SkClipOp op = iter.get()->getOp(); + bool invert; + bool skip = false; + switch (op) { + case kReplace_SkClipOp: + SkASSERT(iter.get() == elements.head()); + // Fallthrough, handled same as intersect. + case kIntersect_SkClipOp: + invert = false; + if (iter.get()->contains(drawDevBounds)) { + skip = true; + } + break; + case kDifference_SkClipOp: + invert = true; + // We don't currently have a cheap test for whether a rect is fully outside an + // element's primitive, so don't attempt to set skip. + break; + default: + return false; + } + if (!skip) { + GrPrimitiveEdgeType edgeType; + if (iter.get()->isAA()) { + if (abortIfAA) { + return false; + } + edgeType = + invert ? kInverseFillAA_GrProcessorEdgeType : kFillAA_GrProcessorEdgeType; + } else { + edgeType = + invert ? kInverseFillBW_GrProcessorEdgeType : kFillBW_GrProcessorEdgeType; + } + + switch (iter.get()->getDeviceSpaceType()) { + case SkClipStack::Element::DeviceSpaceType::kPath: + fps.emplace_back( + GrConvexPolyEffect::Make(edgeType, iter.get()->getDeviceSpacePath())); + break; + case SkClipStack::Element::DeviceSpaceType::kRRect: { + fps.emplace_back( + GrRRectEffect::Make(edgeType, iter.get()->getDeviceSpaceRRect())); + break; + } + case SkClipStack::Element::DeviceSpaceType::kRect: { + fps.emplace_back( + GrConvexPolyEffect::Make(edgeType, iter.get()->getDeviceSpaceRect())); + break; + } + default: + break; + } + if (!fps.back()) { + return false; + } + } + iter.next(); + } + + *resultFP = nullptr; + if (fps.count()) { + *resultFP = GrFragmentProcessor::RunInSeries(fps.begin(), fps.count()); + } + return true; +} + //////////////////////////////////////////////////////////////////////////////// // sort out what kind of clip mask needs to be created: alpha, stencil, // scissor, or entirely software @@ -199,19 +265,8 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar return true; } - int maxAnalyticFPs = kMaxAnalyticElements; - if (GrFSAAType::kNone != renderTargetContext->fsaaType()) { - // With mixed samples (non-msaa color buffer), any coverage info is lost from color once it - // hits the color buffer anyway, so we may as well use coverage AA if nothing else in the - // pipe is multisampled. - if (renderTargetContext->numColorSamples() > 0 || useHWAA || hasUserStencilSettings) { - maxAnalyticFPs = 0; - } - SkASSERT(!context->caps()->avoidStencilBuffers()); // We disable MSAA when avoiding stencil. - } - - GrReducedClip reducedClip(*fStack, devBounds, renderTargetContext->priv().maxWindowRectangles(), - maxAnalyticFPs); + const GrReducedClip reducedClip(*fStack, devBounds, + renderTargetContext->priv().maxWindowRectangles()); if (reducedClip.hasScissor() && !GrClip::IsInsideClip(reducedClip.scissor(), devBounds)) { out->addScissor(reducedClip.scissor(), bounds); @@ -222,10 +277,6 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar GrWindowRectsState::Mode::kExclusive); } - if (std::unique_ptr<GrFragmentProcessor> clipFPs = reducedClip.detachAnalyticFPs()) { - out->addCoverageFP(std::move(clipFPs)); - } - if (reducedClip.maskElements().isEmpty()) { return InitialState::kAllIn == reducedClip.initialState(); } @@ -238,9 +289,41 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar SkASSERT(rtIBounds.contains(scissor)); // Mask shouldn't be larger than the RT. #endif + bool avoidStencilBuffers = context->caps()->avoidStencilBuffers(); + + // An element count of 4 was chosen because of the common pattern in Blink of: + // isect RR + // diff RR + // isect convex_poly + // isect convex_poly + // when drawing rounded div borders. This could probably be tuned based on a + // configuration's relative costs of switching RTs to generate a mask vs + // longer shaders. + if (reducedClip.maskElements().count() <= kMaxAnalyticElements) { + // When there are multiple samples we want to do per-sample clipping, not compute a + // fractional pixel coverage. + bool disallowAnalyticAA = + GrFSAAType::kNone != renderTargetContext->fsaaType() && !avoidStencilBuffers; + if (disallowAnalyticAA && !renderTargetContext->numColorSamples()) { + // With a single color sample, any coverage info is lost from color once it hits the + // color buffer anyway, so we may as well use coverage AA if nothing else in the pipe + // is multisampled. + disallowAnalyticAA = useHWAA || hasUserStencilSettings; + } + std::unique_ptr<GrFragmentProcessor> clipFP; + if ((reducedClip.maskRequiresAA() || avoidStencilBuffers) && + get_analytic_clip_processor(reducedClip.maskElements(), disallowAnalyticAA, devBounds, + &clipFP)) { + if (clipFP) { + out->addCoverageFP(std::move(clipFP)); + } + return true; + } + } + // If the stencil buffer is multisampled we can use it to do everything. if ((GrFSAAType::kNone == renderTargetContext->fsaaType() && reducedClip.maskRequiresAA()) || - context->caps()->avoidStencilBuffers()) { + avoidStencilBuffers) { sk_sp<GrTextureProxy> result; if (UseSWOnlyPath(context, hasUserStencilSettings, renderTargetContext, reducedClip)) { // The clip geometry is complex enough that it will be more efficient to create it @@ -260,8 +343,7 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar // If alpha or software clip mask creation fails, fall through to the stencil code paths, // unless stencils are disallowed. if (context->caps()->avoidStencilBuffers()) { - SkDebugf("WARNING: Clip mask requires stencil, but stencil unavailable. " - "Clip will be ignored.\n"); + SkDebugf("WARNING: Clip mask requires stencil, but stencil unavailable. Clip will be ignored.\n"); return false; } } @@ -271,14 +353,11 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar // This relies on the property that a reduced sub-rect of the last clip will contain all the // relevant window rectangles that were in the last clip. This subtle requirement will go away // after clipping is overhauled. - if (renderTargetContext->priv().mustRenderClip(reducedClip.maskGenID(), reducedClip.scissor(), - reducedClip.numAnalyticFPs())) { + if (renderTargetContext->priv().mustRenderClip(reducedClip.maskGenID(), + reducedClip.scissor())) { reducedClip.drawStencilClipMask(context, renderTargetContext); - renderTargetContext->priv().setLastClip(reducedClip.maskGenID(), reducedClip.scissor(), - reducedClip.numAnalyticFPs()); + renderTargetContext->priv().setLastClip(reducedClip.maskGenID(), reducedClip.scissor()); } - // GrAppliedClip doesn't need to figure numAnalyticFPs into its key (used by operator==) because - // it verifies the FPs are also equal. out->addStencilClip(reducedClip.maskGenID()); return true; } @@ -286,16 +365,14 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar //////////////////////////////////////////////////////////////////////////////// // Create a 8-bit clip mask in alpha -static void create_clip_mask_key(uint32_t clipGenID, const SkIRect& bounds, int numAnalyticFPs, - GrUniqueKey* key) { +static void create_clip_mask_key(uint32_t clipGenID, const SkIRect& bounds, GrUniqueKey* key) { static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); - GrUniqueKey::Builder builder(key, kDomain, 4, GrClipStackClip::kMaskTestTag); + GrUniqueKey::Builder builder(key, kDomain, 3, GrClipStackClip::kMaskTestTag); builder[0] = clipGenID; // SkToS16 because image filters outset layers to a size indicated by the filter, which can // sometimes result in negative coordinates from device space. builder[1] = SkToS16(bounds.fLeft) | (SkToS16(bounds.fRight) << 16); builder[2] = SkToS16(bounds.fTop) | (SkToS16(bounds.fBottom) << 16); - builder[3] = numAnalyticFPs; } static void add_invalidate_on_pop_message(const SkClipStack& stack, uint32_t clipGenID, @@ -316,8 +393,7 @@ sk_sp<GrTextureProxy> GrClipStackClip::createAlphaClipMask(GrContext* context, const GrReducedClip& reducedClip) const { GrResourceProvider* resourceProvider = context->resourceProvider(); GrUniqueKey key; - create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(), - reducedClip.numAnalyticFPs(), &key); + create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(), &key); sk_sp<GrTextureProxy> proxy(resourceProvider->findOrCreateProxyByUniqueKey( key, kBottomLeft_GrSurfaceOrigin)); @@ -429,8 +505,7 @@ sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask( GrContext* context, const GrReducedClip& reducedClip, GrRenderTargetContext* renderTargetContext) const { GrUniqueKey key; - create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(), - reducedClip.numAnalyticFPs(), &key); + create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(), &key); sk_sp<GrTextureProxy> proxy(context->resourceProvider()->findOrCreateProxyByUniqueKey( key, kTopLeft_GrSurfaceOrigin)); |