• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "src/gpu/ganesh/ops/OpsTask.h"
9 
10 #include "include/gpu/GrRecordingContext.h"
11 #include "src/base/SkScopeExit.h"
12 #include "src/core/SkRectPriv.h"
13 #include "src/core/SkTraceEvent.h"
14 #include "src/gpu/ganesh/GrAttachment.h"
15 #include "src/gpu/ganesh/GrAuditTrail.h"
16 #include "src/gpu/ganesh/GrCaps.h"
17 #include "src/gpu/ganesh/GrGpu.h"
18 #include "src/gpu/ganesh/GrMemoryPool.h"
19 #include "src/gpu/ganesh/GrNativeRect.h"
20 #include "src/gpu/ganesh/GrOpFlushState.h"
21 #include "src/gpu/ganesh/GrOpsRenderPass.h"
22 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
23 #include "src/gpu/ganesh/GrRenderTarget.h"
24 #include "src/gpu/ganesh/GrResourceAllocator.h"
25 #include "src/gpu/ganesh/GrResourceProvider.h"
26 #include "src/gpu/ganesh/GrTexture.h"
27 #include "src/gpu/ganesh/geometry/GrRect.h"
28 
29 using namespace skia_private;
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 
33 namespace {
34 
35 // Experimentally we have found that most combining occurs within the first 10 comparisons.
36 static const int kMaxOpMergeDistance = 10;
37 static const int kMaxOpChainDistance = 10;
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 
can_reorder(const SkRect & a,const SkRect & b)41 inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
42 
create_render_pass(GrGpu * gpu,GrRenderTarget * rt,bool useMSAASurface,GrAttachment * stencil,GrSurfaceOrigin origin,const SkIRect & bounds,GrLoadOp colorLoadOp,const std::array<float,4> & loadClearColor,GrLoadOp stencilLoadOp,GrStoreOp stencilStoreOp,const TArray<GrSurfaceProxy *,true> & sampledProxies,GrXferBarrierFlags renderPassXferBarriers)43 GrOpsRenderPass* create_render_pass(GrGpu* gpu,
44                                     GrRenderTarget* rt,
45                                     bool useMSAASurface,
46                                     GrAttachment* stencil,
47                                     GrSurfaceOrigin origin,
48                                     const SkIRect& bounds,
49                                     GrLoadOp colorLoadOp,
50                                     const std::array<float, 4>& loadClearColor,
51                                     GrLoadOp stencilLoadOp,
52                                     GrStoreOp stencilStoreOp,
53                                     const TArray<GrSurfaceProxy*, true>& sampledProxies,
54                                     GrXferBarrierFlags renderPassXferBarriers) {
55     const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo {
56         colorLoadOp,
57         GrStoreOp::kStore,
58         loadClearColor
59     };
60 
61     // TODO:
62     // We would like to (at this level) only ever clear & discard. We would need
63     // to stop splitting up higher level OpsTasks for copyOps to achieve that.
64     // Note: we would still need SB loads and stores but they would happen at a
65     // lower level (inside the VK command buffer).
66     const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
67         stencilLoadOp,
68         stencilStoreOp,
69     };
70 
71     return gpu->getOpsRenderPass(rt, useMSAASurface, stencil, origin, bounds, kColorLoadStoreInfo,
72                                  stencilLoadAndStoreInfo, sampledProxies, renderPassXferBarriers);
73 }
74 
75 } // anonymous namespace
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 
79 namespace skgpu::ganesh {
80 
List(GrOp::Owner op)81 inline OpsTask::OpChain::List::List(GrOp::Owner op)
82         : fHead(std::move(op)), fTail(fHead.get()) {
83     this->validate();
84 }
85 
List(List && that)86 inline OpsTask::OpChain::List::List(List&& that) { *this = std::move(that); }
87 
operator =(List && that)88 inline OpsTask::OpChain::List& OpsTask::OpChain::List::operator=(List&& that) {
89     fHead = std::move(that.fHead);
90     fTail = that.fTail;
91     that.fTail = nullptr;
92     this->validate();
93     return *this;
94 }
95 
popHead()96 inline GrOp::Owner OpsTask::OpChain::List::popHead() {
97     SkASSERT(fHead);
98     auto temp = fHead->cutChain();
99     std::swap(temp, fHead);
100     if (!fHead) {
101         SkASSERT(fTail == temp.get());
102         fTail = nullptr;
103     }
104     return temp;
105 }
106 
removeOp(GrOp * op)107 inline GrOp::Owner OpsTask::OpChain::List::removeOp(GrOp* op) {
108 #ifdef SK_DEBUG
109     auto head = op;
110     while (head->prevInChain()) { head = head->prevInChain(); }
111     SkASSERT(head == fHead.get());
112 #endif
113     auto prev = op->prevInChain();
114     if (!prev) {
115         SkASSERT(op == fHead.get());
116         return this->popHead();
117     }
118     auto temp = prev->cutChain();
119     if (auto next = temp->cutChain()) {
120         prev->chainConcat(std::move(next));
121     } else {
122         SkASSERT(fTail == op);
123         fTail = prev;
124     }
125     this->validate();
126     return temp;
127 }
128 
pushHead(GrOp::Owner op)129 inline void OpsTask::OpChain::List::pushHead(GrOp::Owner op) {
130     SkASSERT(op);
131     SkASSERT(op->isChainHead());
132     SkASSERT(op->isChainTail());
133     if (fHead) {
134         op->chainConcat(std::move(fHead));
135         fHead = std::move(op);
136     } else {
137         fHead = std::move(op);
138         fTail = fHead.get();
139     }
140 }
141 
pushTail(GrOp::Owner op)142 inline void OpsTask::OpChain::List::pushTail(GrOp::Owner op) {
143     SkASSERT(op->isChainTail());
144     fTail->chainConcat(std::move(op));
145     fTail = fTail->nextInChain();
146 }
147 
validate() const148 inline void OpsTask::OpChain::List::validate() const {
149 #ifdef SK_DEBUG
150     if (fHead) {
151         SkASSERT(fTail);
152         fHead->validateChain(fTail);
153     }
154 #endif
155 }
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 
OpChain(GrOp::Owner op,GrProcessorSet::Analysis processorAnalysis,GrAppliedClip * appliedClip,const GrDstProxyView * dstProxyView)159 OpsTask::OpChain::OpChain(GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
160                           GrAppliedClip* appliedClip, const GrDstProxyView* dstProxyView)
161         : fList{std::move(op)}
162         , fProcessorAnalysis(processorAnalysis)
163         , fAppliedClip(appliedClip) {
164     if (fProcessorAnalysis.requiresDstTexture()) {
165         SkASSERT(dstProxyView && dstProxyView->proxy());
166         fDstProxyView = *dstProxyView;
167     }
168     fBounds = fList.head()->bounds();
169 }
170 
visitProxies(const GrVisitProxyFunc & func) const171 void OpsTask::OpChain::visitProxies(const GrVisitProxyFunc& func) const {
172     if (fList.empty()) {
173         return;
174     }
175     for (const auto& op : GrOp::ChainRange<>(fList.head())) {
176         op.visitProxies(func);
177     }
178     if (fDstProxyView.proxy()) {
179         func(fDstProxyView.proxy(), skgpu::Mipmapped::kNo);
180     }
181     if (fAppliedClip) {
182         fAppliedClip->visitProxies(func);
183     }
184 }
185 
deleteOps()186 void OpsTask::OpChain::deleteOps() {
187     while (!fList.empty()) {
188         // Since the value goes out of scope immediately, the GrOp::Owner deletes the op.
189         fList.popHead();
190     }
191 }
192 
193 // Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
194 // the two chains are chainable. Returns the new chain.
DoConcat(List chainA,List chainB,const GrCaps & caps,SkArenaAlloc * opsTaskArena,GrAuditTrail * auditTrail)195 OpsTask::OpChain::List OpsTask::OpChain::DoConcat(List chainA, List chainB, const GrCaps& caps,
196                                                   SkArenaAlloc* opsTaskArena,
197                                                   GrAuditTrail* auditTrail) {
198     // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
199     // at chain a's tail and working toward the head. We produce one of the following outcomes:
200     // 1) b's head is merged into an op in a.
201     // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
202     // 3) b's head is popped from chain a and added at the tail of a.
203     // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
204     // as we assume merges were already attempted when chain b was created. So we keep track of the
205     // original tail of a and start our iteration of a there. We also track the bounds of the nodes
206     // appended to chain a that will be skipped for bounds testing. If the original tail of a is
207     // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
208     GrOp* origATail = chainA.tail();
209     SkRect skipBounds = SkRectPriv::MakeLargestInverted();
210     do {
211         int numMergeChecks = 0;
212         bool merged = false;
213         bool noSkip = (origATail == chainA.tail());
214         SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
215         bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
216         SkRect forwardMergeBounds = skipBounds;
217         GrOp* a = origATail;
218         while (a) {
219             bool canForwardMerge =
220                     (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
221             if (canForwardMerge || canBackwardMerge) {
222                 auto result = a->combineIfPossible(chainB.head(), opsTaskArena, caps);
223                 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
224                 merged = (result == GrOp::CombineResult::kMerged);
225                 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
226                           chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
227                           a->uniqueID());
228             }
229             if (merged) {
230                 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
231                 if (canBackwardMerge) {
232                     // The GrOp::Owner releases the op.
233                     chainB.popHead();
234                 } else {
235                     // We merged the contents of b's head into a. We will replace b's head with a in
236                     // chain b.
237                     SkASSERT(canForwardMerge);
238                     if (a == origATail) {
239                         origATail = a->prevInChain();
240                     }
241                     GrOp::Owner detachedA = chainA.removeOp(a);
242                     // The GrOp::Owner releases the op.
243                     chainB.popHead();
244                     chainB.pushHead(std::move(detachedA));
245                     if (chainA.empty()) {
246                         // We merged all the nodes in chain a to chain b.
247                         return chainB;
248                     }
249                 }
250                 break;
251             } else {
252                 if (++numMergeChecks == kMaxOpMergeDistance) {
253                     break;
254                 }
255                 forwardMergeBounds.joinNonEmptyArg(a->bounds());
256                 canBackwardMerge =
257                         canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
258                 a = a->prevInChain();
259             }
260         }
261         // If we weren't able to merge b's head then pop b's head from chain b and make it the new
262         // tail of a.
263         if (!merged) {
264             chainA.pushTail(chainB.popHead());
265             skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
266         }
267     } while (!chainB.empty());
268     return chainA;
269 }
270 
271 // Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
272 // whether the operation succeeded. On success, the provided list will be returned empty.
tryConcat(List * list,GrProcessorSet::Analysis processorAnalysis,const GrDstProxyView & dstProxyView,const GrAppliedClip * appliedClip,const SkRect & bounds,const GrCaps & caps,SkArenaAlloc * opsTaskArena,GrAuditTrail * auditTrail)273 bool OpsTask::OpChain::tryConcat(
274         List* list, GrProcessorSet::Analysis processorAnalysis, const GrDstProxyView& dstProxyView,
275         const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
276         SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
277     SkASSERT(!fList.empty());
278     SkASSERT(!list->empty());
279     SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy()));
280     SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy()));
281     // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
282     if (fList.head()->classID() != list->head()->classID() ||
283         SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
284         (fAppliedClip && *fAppliedClip != *appliedClip) ||
285         (fProcessorAnalysis.requiresNonOverlappingDraws() !=
286                 processorAnalysis.requiresNonOverlappingDraws()) ||
287         (fProcessorAnalysis.requiresNonOverlappingDraws() &&
288                 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
289                 // or read back a new dst texture between draws. In either case, we can neither
290                 // chain nor combine overlapping Ops.
291                 GrRectsTouchOrOverlap(fBounds, bounds)) ||
292         (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
293         (fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) {
294         return false;
295     }
296 
297     SkDEBUGCODE(bool first = true;)
298     do {
299         switch (fList.tail()->combineIfPossible(list->head(), opsTaskArena, caps))
300         {
301             case GrOp::CombineResult::kCannotCombine:
302                 // If an op supports chaining then it is required that chaining is transitive and
303                 // that if any two ops in two different chains can merge then the two chains
304                 // may also be chained together. Thus, we should only hit this on the first
305                 // iteration.
306                 SkASSERT(first);
307                 return false;
308             case GrOp::CombineResult::kMayChain:
309                 fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, opsTaskArena,
310                                  auditTrail);
311                 // The above exchange cleared out 'list'. The list needs to be empty now for the
312                 // loop to terminate.
313                 SkASSERT(list->empty());
314                 break;
315             case GrOp::CombineResult::kMerged: {
316                 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
317                           list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
318                           list->head()->uniqueID());
319                 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
320                 // The GrOp::Owner releases the op.
321                 list->popHead();
322                 break;
323             }
324         }
325         SkDEBUGCODE(first = false);
326     } while (!list->empty());
327 
328     // The new ops were successfully merged and/or chained onto our own.
329     fBounds.joinPossiblyEmptyRect(bounds);
330     return true;
331 }
332 
prependChain(OpChain * that,const GrCaps & caps,SkArenaAlloc * opsTaskArena,GrAuditTrail * auditTrail)333 bool OpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, SkArenaAlloc* opsTaskArena,
334                                     GrAuditTrail* auditTrail) {
335     if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps,
336                          opsTaskArena, auditTrail)) {
337         this->validate();
338         // append failed
339         return false;
340     }
341 
342     // 'that' owns the combined chain. Move it into 'this'.
343     SkASSERT(fList.empty());
344     fList = std::move(that->fList);
345     fBounds = that->fBounds;
346 
347     that->fDstProxyView.setProxyView({});
348     if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) {
349         // Obliterates the processor.
350         that->fAppliedClip->detachCoverageFragmentProcessor();
351     }
352     this->validate();
353     return true;
354 }
355 
appendOp(GrOp::Owner op,GrProcessorSet::Analysis processorAnalysis,const GrDstProxyView * dstProxyView,const GrAppliedClip * appliedClip,const GrCaps & caps,SkArenaAlloc * opsTaskArena,GrAuditTrail * auditTrail)356 GrOp::Owner OpsTask::OpChain::appendOp(
357         GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
358         const GrDstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps,
359         SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
360     const GrDstProxyView noDstProxyView;
361     if (!dstProxyView) {
362         dstProxyView = &noDstProxyView;
363     }
364     SkASSERT(op->isChainHead() && op->isChainTail());
365     SkRect opBounds = op->bounds();
366     List chain(std::move(op));
367     if (!this->tryConcat(&chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps,
368                          opsTaskArena, auditTrail)) {
369         // append failed, give the op back to the caller.
370         this->validate();
371         return chain.popHead();
372     }
373 
374     SkASSERT(chain.empty());
375     this->validate();
376     return nullptr;
377 }
378 
validate() const379 inline void OpsTask::OpChain::validate() const {
380 #ifdef SK_DEBUG
381     fList.validate();
382     for (const auto& op : GrOp::ChainRange<>(fList.head())) {
383         // Not using SkRect::contains because we allow empty rects.
384         SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
385                  fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
386     }
387 #endif
388 }
389 
390 ////////////////////////////////////////////////////////////////////////////////
391 
OpsTask(GrDrawingManager * drawingMgr,GrSurfaceProxyView view,GrAuditTrail * auditTrail,sk_sp<GrArenas> arenas)392 OpsTask::OpsTask(GrDrawingManager* drawingMgr,
393                  GrSurfaceProxyView view,
394                  GrAuditTrail* auditTrail,
395                  sk_sp<GrArenas> arenas)
396         : GrRenderTask()
397         , fAuditTrail(auditTrail)
398         , fUsesMSAASurface(view.asRenderTargetProxy()->numSamples() > 1)
399         , fTargetSwizzle(view.swizzle())
400         , fTargetOrigin(view.origin())
401         , fArenas{std::move(arenas)}
402           SkDEBUGCODE(, fNumClips(0)) {
403     this->addTarget(drawingMgr, view.detachProxy());
404 }
405 
deleteOps()406 void OpsTask::deleteOps() {
407     for (auto& chain : fOpChains) {
408         chain.deleteOps();
409     }
410     fOpChains.clear();
411 }
412 
~OpsTask()413 OpsTask::~OpsTask() {
414     this->deleteOps();
415 }
416 
addOp(GrDrawingManager * drawingMgr,GrOp::Owner op,GrTextureResolveManager textureResolveManager,const GrCaps & caps)417 void OpsTask::addOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
418                     GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
419     auto addDependency = [&](GrSurfaceProxy* p, skgpu::Mipmapped mipmapped) {
420         this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
421     };
422 
423     op->visitProxies(addDependency);
424 
425     this->recordOp(std::move(op), false/*usesMSAA*/, GrProcessorSet::EmptySetAnalysis(), nullptr,
426                    nullptr, caps);
427 }
428 
addDrawOp(GrDrawingManager * drawingMgr,GrOp::Owner op,bool usesMSAA,const GrProcessorSet::Analysis & processorAnalysis,GrAppliedClip && clip,const GrDstProxyView & dstProxyView,GrTextureResolveManager textureResolveManager,const GrCaps & caps)429 void OpsTask::addDrawOp(GrDrawingManager* drawingMgr, GrOp::Owner op, bool usesMSAA,
430                         const GrProcessorSet::Analysis& processorAnalysis, GrAppliedClip&& clip,
431                         const GrDstProxyView& dstProxyView,
432                         GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
433     auto addDependency = [&](GrSurfaceProxy* p, skgpu::Mipmapped mipmapped) {
434         this->addSampledTexture(p);
435         this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
436     };
437 
438     op->visitProxies(addDependency);
439     clip.visitProxies(addDependency);
440     if (dstProxyView.proxy()) {
441         if (!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment)) {
442             this->addSampledTexture(dstProxyView.proxy());
443         }
444         if (dstProxyView.dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) {
445             fRenderPassXferBarriers |= GrXferBarrierFlags::kTexture;
446         }
447         addDependency(dstProxyView.proxy(), skgpu::Mipmapped::kNo);
448         SkASSERT(!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment) ||
449                  dstProxyView.offset().isZero());
450     }
451 
452     if (processorAnalysis.usesNonCoherentHWBlending()) {
453         fRenderPassXferBarriers |= GrXferBarrierFlags::kBlend;
454     }
455 
456     this->recordOp(std::move(op), usesMSAA, processorAnalysis, clip.doesClip() ? &clip : nullptr,
457                    &dstProxyView, caps);
458 }
459 
endFlush(GrDrawingManager * drawingMgr)460 void OpsTask::endFlush(GrDrawingManager* drawingMgr) {
461     fLastClipStackGenID = SK_InvalidUniqueID;
462     this->deleteOps();
463 
464     fDeferredProxies.clear();
465     fSampledProxies.clear();
466     fAuditTrail = nullptr;
467 
468     GrRenderTask::endFlush(drawingMgr);
469 }
470 
onPrePrepare(GrRecordingContext * context)471 void OpsTask::onPrePrepare(GrRecordingContext* context) {
472     SkASSERT(this->isClosed());
473     // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
474     // can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation
475     // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
476     // we shouldn't end up with OpsTasks with only discard.
477     if (this->isColorNoOp() ||
478         (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
479         return;
480     }
481     TRACE_EVENT0("skia.gpu", TRACE_FUNC);
482 
483     GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
484     for (const auto& chain : fOpChains) {
485         if (chain.shouldExecute()) {
486             chain.head()->prePrepare(context,
487                                      dstView,
488                                      chain.appliedClip(),
489                                      chain.dstProxyView(),
490                                      fRenderPassXferBarriers,
491                                      fColorLoadOp);
492         }
493     }
494 }
495 
onPrepare(GrOpFlushState * flushState)496 void OpsTask::onPrepare(GrOpFlushState* flushState) {
497     SkASSERT(this->target(0)->peekRenderTarget());
498     SkASSERT(this->isClosed());
499     // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
500     // can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation
501     // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
502     // we shouldn't end up with OpsTasks with only discard.
503     if (this->isColorNoOp() ||
504         (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
505         return;
506     }
507     TRACE_EVENT0_ALWAYS("skia.gpu", TRACE_FUNC);
508 
509     flushState->setSampledProxyArray(&fSampledProxies);
510     GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
511     // Loop over the ops that haven't yet been prepared.
512     for (const auto& chain : fOpChains) {
513         if (chain.shouldExecute()) {
514             GrOpFlushState::OpArgs opArgs(chain.head(),
515                                           dstView,
516                                           fUsesMSAASurface,
517                                           chain.appliedClip(),
518                                           chain.dstProxyView(),
519                                           fRenderPassXferBarriers,
520                                           fColorLoadOp);
521 
522             flushState->setOpArgs(&opArgs);
523 
524             // Temporary debugging helper: for debugging prePrepare w/o going through DDLs
525             // Delete once most of the GrOps have an onPrePrepare.
526             // chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0),
527             //                          chain.appliedClip());
528 
529             // GrOp::prePrepare may or may not have been called at this point
530             chain.head()->prepare(flushState);
531             flushState->setOpArgs(nullptr);
532         }
533     }
534     flushState->setSampledProxyArray(nullptr);
535 }
536 
537 // TODO: this is where GrOp::renderTarget is used (which is fine since it
538 // is at flush time). However, we need to store the RenderTargetProxy in the
539 // Ops and instantiate them here.
onExecute(GrOpFlushState * flushState)540 bool OpsTask::onExecute(GrOpFlushState* flushState) {
541     SkASSERT(this->numTargets() == 1);
542     GrRenderTargetProxy* proxy = this->target(0)->asRenderTargetProxy();
543     SkASSERT(proxy);
544     SK_AT_SCOPE_EXIT(proxy->clearArenas());
545 
546     if (this->isColorNoOp() || fClippedContentBounds.isEmpty()) {
547         return false;
548     }
549     TRACE_EVENT0_ALWAYS("skia.gpu", TRACE_FUNC);
550 
551     // Make sure load ops are not kClear if the GPU needs to use draws for clears
552     SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
553              !flushState->gpu()->caps()->performColorClearsAsDraws());
554 
555     const GrCaps& caps = *flushState->gpu()->caps();
556     GrRenderTarget* renderTarget = proxy->peekRenderTarget();
557     SkASSERT(renderTarget);
558 
559     GrAttachment* stencil = nullptr;
560     if (proxy->needsStencil()) {
561         SkASSERT(proxy->canUseStencil(caps));
562         if (!flushState->resourceProvider()->attachStencilAttachment(renderTarget,
563                                                                      fUsesMSAASurface)) {
564             SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n");
565             return false;
566         }
567         stencil = renderTarget->getStencilAttachment(fUsesMSAASurface);
568     }
569 
570     GrLoadOp stencilLoadOp;
571     switch (fInitialStencilContent) {
572         case StencilContent::kDontCare:
573             stencilLoadOp = GrLoadOp::kDiscard;
574             break;
575         case StencilContent::kUserBitsCleared:
576             SkASSERT(!caps.performStencilClearsAsDraws());
577             SkASSERT(stencil);
578             if (caps.discardStencilValuesAfterRenderPass()) {
579                 // Always clear the stencil if it is being discarded after render passes. This is
580                 // also an optimization because we are on a tiler and it avoids loading the values
581                 // from memory.
582                 stencilLoadOp = GrLoadOp::kClear;
583                 break;
584             }
585             if (!stencil->hasPerformedInitialClear()) {
586                 stencilLoadOp = GrLoadOp::kClear;
587                 stencil->markHasPerformedInitialClear();
588                 break;
589             }
590             // SurfaceDrawContexts are required to leave the user stencil bits in a cleared state
591             // once finished, meaning the stencil values will always remain cleared after the
592             // initial clear. Just fall through to reloading the existing (cleared) stencil values
593             // from memory.
594             [[fallthrough]];
595         case StencilContent::kPreserved:
596             SkASSERT(stencil);
597             stencilLoadOp = GrLoadOp::kLoad;
598             break;
599     }
600 
601     // NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split
602     // its opsTask.
603     //
604     // FIXME: We don't currently flag render passes that don't use stencil at all. In that case
605     // their store op might be "discard", and we currently make the assumption that a discard will
606     // not invalidate what's already in main memory. This is probably ok for now, but certainly
607     // something we want to address soon.
608     GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil)
609             ? GrStoreOp::kDiscard
610             : GrStoreOp::kStore;
611 
612     GrOpsRenderPass* renderPass = create_render_pass(flushState->gpu(),
613                                                      proxy->peekRenderTarget(),
614                                                      fUsesMSAASurface,
615                                                      stencil,
616                                                      fTargetOrigin,
617                                                      fClippedContentBounds,
618                                                      fColorLoadOp,
619                                                      fLoadClearColor,
620                                                      stencilLoadOp,
621                                                      stencilStoreOp,
622                                                      fSampledProxies,
623                                                      fRenderPassXferBarriers);
624 
625     if (!renderPass) {
626         return false;
627     }
628     flushState->setOpsRenderPass(renderPass);
629     renderPass->begin();
630 
631     GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
632 
633     // Draw all the generated geometry.
634     for (const auto& chain : fOpChains) {
635         if (!chain.shouldExecute()) {
636             continue;
637         }
638 
639         GrOpFlushState::OpArgs opArgs(chain.head(),
640                                       dstView,
641                                       fUsesMSAASurface,
642                                       chain.appliedClip(),
643                                       chain.dstProxyView(),
644                                       fRenderPassXferBarriers,
645                                       fColorLoadOp);
646 
647         flushState->setOpArgs(&opArgs);
648         chain.head()->execute(flushState, chain.bounds());
649         flushState->setOpArgs(nullptr);
650     }
651 
652     renderPass->end();
653     flushState->gpu()->submit(renderPass);
654     flushState->setOpsRenderPass(nullptr);
655 
656     return true;
657 }
658 
setColorLoadOp(GrLoadOp op,std::array<float,4> color)659 void OpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) {
660     fColorLoadOp = op;
661     fLoadClearColor = color;
662     if (GrLoadOp::kClear == fColorLoadOp) {
663         GrSurfaceProxy* proxy = this->target(0);
664         SkASSERT(proxy);
665         fTotalBounds = proxy->backingStoreBoundsRect();
666     }
667 }
668 
reset()669 void OpsTask::reset() {
670     fDeferredProxies.clear();
671     fSampledProxies.clear();
672     fClippedContentBounds = SkIRect::MakeEmpty();
673     fTotalBounds = SkRect::MakeEmpty();
674     this->deleteOps();
675     fRenderPassXferBarriers = GrXferBarrierFlags::kNone;
676 }
677 
canMerge(const OpsTask * opsTask) const678 bool OpsTask::canMerge(const OpsTask* opsTask) const {
679     return this->target(0) == opsTask->target(0) &&
680            fArenas == opsTask->fArenas &&
681            !opsTask->fCannotMergeBackward;
682 }
683 
mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks)684 int OpsTask::mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks) {
685     int mergedCount = 0;
686     for (const sk_sp<GrRenderTask>& task : tasks) {
687         auto opsTask = task->asOpsTask();
688         if (!opsTask || !this->canMerge(opsTask)) {
689             break;
690         }
691         SkASSERT(fTargetSwizzle == opsTask->fTargetSwizzle);
692         SkASSERT(fTargetOrigin == opsTask->fTargetOrigin);
693         if (GrLoadOp::kClear == opsTask->fColorLoadOp) {
694             // TODO(11903): Go back to actually dropping ops tasks when we are merged with
695             // color clear.
696             return 0;
697         }
698         mergedCount += 1;
699     }
700     if (0 == mergedCount) {
701         return 0;
702     }
703 
704     SkSpan<const sk_sp<OpsTask>> mergingNodes(
705             reinterpret_cast<const sk_sp<OpsTask>*>(tasks.data()), SkToSizeT(mergedCount));
706     int addlDeferredProxyCount = 0;
707     int addlProxyCount = 0;
708     int addlOpChainCount = 0;
709     for (const auto& toMerge : mergingNodes) {
710         addlDeferredProxyCount += toMerge->fDeferredProxies.size();
711         addlProxyCount += toMerge->fSampledProxies.size();
712         addlOpChainCount += toMerge->fOpChains.size();
713         fClippedContentBounds.join(toMerge->fClippedContentBounds);
714         fTotalBounds.join(toMerge->fTotalBounds);
715         fRenderPassXferBarriers |= toMerge->fRenderPassXferBarriers;
716         if (fInitialStencilContent == StencilContent::kDontCare) {
717             // Propogate the first stencil content that isn't kDontCare.
718             //
719             // Once the stencil has any kind of initial content that isn't kDontCare, then the
720             // inital contents of subsequent opsTasks that get merged in don't matter.
721             //
722             // (This works because the opsTask all target the same render target and are in
723             // painter's order. kPreserved obviously happens automatically with a merge, and kClear
724             // is also automatic because the contract is for ops to leave the stencil buffer in a
725             // cleared state when finished.)
726             fInitialStencilContent = toMerge->fInitialStencilContent;
727         }
728         fUsesMSAASurface |= toMerge->fUsesMSAASurface;
729         SkDEBUGCODE(fNumClips += toMerge->fNumClips);
730     }
731 
732     fLastClipStackGenID = SK_InvalidUniqueID;
733     fDeferredProxies.reserve_exact(fDeferredProxies.size() + addlDeferredProxyCount);
734     fSampledProxies.reserve_exact(fSampledProxies.size() + addlProxyCount);
735     fOpChains.reserve_exact(fOpChains.size() + addlOpChainCount);
736     for (const auto& toMerge : mergingNodes) {
737         for (GrRenderTask* renderTask : toMerge->dependents()) {
738             renderTask->replaceDependency(toMerge.get(), this);
739         }
740         for (GrRenderTask* renderTask : toMerge->dependencies()) {
741             renderTask->replaceDependent(toMerge.get(), this);
742         }
743         fDeferredProxies.move_back_n(toMerge->fDeferredProxies.size(),
744                                      toMerge->fDeferredProxies.data());
745         fSampledProxies.move_back_n(toMerge->fSampledProxies.size(),
746                                     toMerge->fSampledProxies.data());
747         fOpChains.move_back_n(toMerge->fOpChains.size(),
748                               toMerge->fOpChains.data());
749         toMerge->fDeferredProxies.clear();
750         toMerge->fSampledProxies.clear();
751         toMerge->fOpChains.clear();
752     }
753     fMustPreserveStencil = mergingNodes.back()->fMustPreserveStencil;
754     return mergedCount;
755 }
756 
resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps)757 bool OpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
758     if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
759         this->deleteOps();
760         fDeferredProxies.clear();
761         fSampledProxies.clear();
762 
763         // If the opsTask is using a render target which wraps a vulkan command buffer, we can't do
764         // a clear load since we cannot change the render pass that we are using. Thus we fall back
765         // to making a clear op in this case.
766         return !this->target(0)->asRenderTargetProxy()->wrapsVkSecondaryCB();
767     }
768 
769     // Could not empty the task, so an op must be added to handle the clear
770     return false;
771 }
772 
discard()773 void OpsTask::discard() {
774     // Discard calls to in-progress opsTasks are ignored. Calls at the start update the
775     // opsTasks' color & stencil load ops.
776     if (this->isEmpty()) {
777         fColorLoadOp = GrLoadOp::kDiscard;
778         fInitialStencilContent = StencilContent::kDontCare;
779         fTotalBounds.setEmpty();
780     }
781 }
782 
783 ////////////////////////////////////////////////////////////////////////////////
784 
785 #if defined(GR_TEST_UTILS)
dump(const SkString & label,SkString indent,bool printDependencies,bool close) const786 void OpsTask::dump(const SkString& label,
787                    SkString indent,
788                    bool printDependencies,
789                    bool close) const {
790     GrRenderTask::dump(label, indent, printDependencies, false);
791 
792     SkDebugf("%sfColorLoadOp: ", indent.c_str());
793     switch (fColorLoadOp) {
794         case GrLoadOp::kLoad:
795             SkDebugf("kLoad\n");
796             break;
797         case GrLoadOp::kClear:
798             SkDebugf("kClear {%g, %g, %g, %g}\n",
799                      fLoadClearColor[0],
800                      fLoadClearColor[1],
801                      fLoadClearColor[2],
802                      fLoadClearColor[3]);
803             break;
804         case GrLoadOp::kDiscard:
805             SkDebugf("kDiscard\n");
806             break;
807     }
808 
809     SkDebugf("%sfInitialStencilContent: ", indent.c_str());
810     switch (fInitialStencilContent) {
811         case StencilContent::kDontCare:
812             SkDebugf("kDontCare\n");
813             break;
814         case StencilContent::kUserBitsCleared:
815             SkDebugf("kUserBitsCleared\n");
816             break;
817         case StencilContent::kPreserved:
818             SkDebugf("kPreserved\n");
819             break;
820     }
821 
822     SkDebugf("%s%d ops:\n", indent.c_str(), fOpChains.size());
823     for (int i = 0; i < fOpChains.size(); ++i) {
824         SkDebugf("%s*******************************\n", indent.c_str());
825         if (!fOpChains[i].head()) {
826             SkDebugf("%s%d: <combined forward or failed instantiation>\n", indent.c_str(), i);
827         } else {
828             SkDebugf("%s%d: %s\n", indent.c_str(), i, fOpChains[i].head()->name());
829             SkRect bounds = fOpChains[i].bounds();
830             SkDebugf("%sClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
831                      indent.c_str(),
832                      bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
833             for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
834                 SkString info = SkTabString(op.dumpInfo(), 1);
835                 SkDebugf("%s%s\n", indent.c_str(), info.c_str());
836                 bounds = op.bounds();
837                 SkDebugf("%s\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
838                          indent.c_str(),
839                          bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
840             }
841         }
842     }
843 
844     if (close) {
845         SkDebugf("%s--------------------------------------------------------------\n\n",
846                  indent.c_str());
847     }
848 }
849 #endif
850 
851 #ifdef SK_DEBUG
visitProxies_debugOnly(const GrVisitProxyFunc & func) const852 void OpsTask::visitProxies_debugOnly(const GrVisitProxyFunc& func) const {
853     auto textureFunc = [func](GrSurfaceProxy* tex, skgpu::Mipmapped mipmapped) {
854         func(tex, mipmapped);
855     };
856 
857     for (const OpChain& chain : fOpChains) {
858         chain.visitProxies(textureFunc);
859     }
860 }
861 
862 #endif
863 
864 ////////////////////////////////////////////////////////////////////////////////
865 
onMakeSkippable()866 void OpsTask::onMakeSkippable() {
867     this->deleteOps();
868     fDeferredProxies.clear();
869     fColorLoadOp = GrLoadOp::kLoad;
870     SkASSERT(this->isColorNoOp());
871 }
872 
onIsUsed(GrSurfaceProxy * proxyToCheck) const873 bool OpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
874     bool used = false;
875     for (GrSurfaceProxy* proxy : fSampledProxies) {
876         if (proxy == proxyToCheck) {
877             used = true;
878             break;
879         }
880     }
881 #ifdef SK_DEBUG
882     bool usedSlow = false;
883     auto visit = [proxyToCheck, &usedSlow](GrSurfaceProxy* p, skgpu::Mipmapped) {
884         if (p == proxyToCheck) {
885             usedSlow = true;
886         }
887     };
888     this->visitProxies_debugOnly(visit);
889     SkASSERT(used == usedSlow);
890 #endif
891 
892     return used;
893 }
894 
gatherProxyIntervals(GrResourceAllocator * alloc) const895 void OpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
896     SkASSERT(this->isClosed());
897     if (this->isColorNoOp()) {
898         return;
899     }
900 
901     for (int i = 0; i < fDeferredProxies.size(); ++i) {
902         SkASSERT(!fDeferredProxies[i]->isInstantiated());
903         // We give all the deferred proxies a write usage at the very start of flushing. This
904         // locks them out of being reused for the entire flush until they are read - and then
905         // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
906         // with sub-flushes. The deferred proxies only need to be pinned from the start of
907         // the sub-flush in which they appear.
908         alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo,
909                            GrResourceAllocator::AllowRecycling::kYes);
910     }
911 
912     GrSurfaceProxy* targetSurface = this->target(0);
913     SkASSERT(targetSurface);
914     GrRenderTargetProxy* targetProxy = targetSurface->asRenderTargetProxy();
915 
916     // Add the interval for all the writes to this OpsTasks's target
917     if (!fOpChains.empty()) {
918         unsigned int cur = alloc->curOp();
919 
920         alloc->addInterval(targetProxy, cur, cur + fOpChains.size() - 1,
921                            GrResourceAllocator::ActualUse::kYes,
922                            GrResourceAllocator::AllowRecycling::kYes);
923     } else {
924         // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
925         // still need to add an interval for the destination so we create a fake op# for
926         // the missing clear op.
927         alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(),
928                            GrResourceAllocator::ActualUse::kYes,
929                            GrResourceAllocator::AllowRecycling::kYes);
930         alloc->incOps();
931     }
932 
933     GrResourceAllocator::AllowRecycling allowRecycling =
934             targetProxy->wrapsVkSecondaryCB() ? GrResourceAllocator::AllowRecycling::kNo
935                                               : GrResourceAllocator::AllowRecycling::kYes;
936 
937     auto gather = [alloc, allowRecycling SkDEBUGCODE(, this)](GrSurfaceProxy* p, skgpu::Mipmapped) {
938         alloc->addInterval(p,
939                            alloc->curOp(),
940                            alloc->curOp(),
941                            GrResourceAllocator::ActualUse::kYes,
942                            allowRecycling
943                            SkDEBUGCODE(, this->target(0) == p));
944     };
945     // TODO: visitProxies is expensive. Can we do this with fSampledProxies instead?
946     for (const OpChain& recordedOp : fOpChains) {
947         recordedOp.visitProxies(gather);
948 
949         // Even though the op may have been (re)moved we still need to increment the op count to
950         // keep all the math consistent.
951         alloc->incOps();
952     }
953 }
954 
recordOp(GrOp::Owner op,bool usesMSAA,GrProcessorSet::Analysis processorAnalysis,GrAppliedClip * clip,const GrDstProxyView * dstProxyView,const GrCaps & caps)955 void OpsTask::recordOp(
956         GrOp::Owner op, bool usesMSAA, GrProcessorSet::Analysis processorAnalysis,
957         GrAppliedClip* clip, const GrDstProxyView* dstProxyView, const GrCaps& caps) {
958     GrSurfaceProxy* proxy = this->target(0);
959 #ifdef SK_DEBUG
960     op->validate();
961     SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy()));
962     SkASSERT(proxy);
963     // A closed OpsTask should never receive new/more ops
964     SkASSERT(!this->isClosed());
965     // Ensure we can support dynamic msaa if the caller is trying to trigger it.
966     if (proxy->asRenderTargetProxy()->numSamples() == 1 && usesMSAA) {
967         SkASSERT(caps.supportsDynamicMSAA(proxy->asRenderTargetProxy()));
968     }
969 #endif
970 
971     if (!op->bounds().isFinite()) {
972         return;
973     }
974 
975     fUsesMSAASurface |= usesMSAA;
976 
977     // Account for this op's bounds before we attempt to combine.
978     // NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable.
979     fTotalBounds.join(op->bounds());
980 
981     // Check if there is an op we can combine with by linearly searching back until we either
982     // 1) check every op
983     // 2) intersect with something
984     // 3) find a 'blocker'
985     GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID());
986     GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n"
987               "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
988                this->uniqueID(),
989                op->name(),
990                op->uniqueID(),
991                op->bounds().fLeft, op->bounds().fTop,
992                op->bounds().fRight, op->bounds().fBottom);
993     GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
994     GrOP_INFO("\tOutcome:\n");
995     int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.size());
996     if (maxCandidates) {
997         int i = 0;
998         while (true) {
999             OpChain& candidate = fOpChains.fromBack(i);
1000             op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps,
1001                                     fArenas->arenaAlloc(), fAuditTrail);
1002             if (!op) {
1003                 return;
1004             }
1005             // Stop going backwards if we would cause a painter's order violation.
1006             if (!can_reorder(candidate.bounds(), op->bounds())) {
1007                 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
1008                           candidate.head()->name(), candidate.head()->uniqueID());
1009                 break;
1010             }
1011             if (++i == maxCandidates) {
1012                 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
1013                 break;
1014             }
1015         }
1016     } else {
1017         GrOP_INFO("\t\tBackward: FirstOp\n");
1018     }
1019     if (clip) {
1020         clip = fArenas->arenaAlloc()->make<GrAppliedClip>(std::move(*clip));
1021         SkDEBUGCODE(fNumClips++;)
1022     }
1023     fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView);
1024 }
1025 
forwardCombine(const GrCaps & caps)1026 void OpsTask::forwardCombine(const GrCaps& caps) {
1027     SkASSERT(!this->isClosed());
1028     GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.size());
1029 
1030     for (int i = 0; i < fOpChains.size() - 1; ++i) {
1031         OpChain& chain = fOpChains[i];
1032         int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.size() - 1);
1033         int j = i + 1;
1034         while (true) {
1035             OpChain& candidate = fOpChains[j];
1036             if (candidate.prependChain(&chain, caps, fArenas->arenaAlloc(), fAuditTrail)) {
1037                 break;
1038             }
1039             // Stop traversing if we would cause a painter's order violation.
1040             if (!can_reorder(chain.bounds(), candidate.bounds())) {
1041                 GrOP_INFO(
1042                         "\t\t%d: chain (%s head opID: %u) -> "
1043                         "Intersects with chain (%s, head opID: %u)\n",
1044                         i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
1045                         candidate.head()->uniqueID());
1046                 break;
1047             }
1048             if (++j > maxCandidateIdx) {
1049                 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
1050                           i, chain.head()->name(), chain.head()->uniqueID());
1051                 break;
1052             }
1053         }
1054     }
1055 }
1056 
onMakeClosed(GrRecordingContext * rContext,SkIRect * targetUpdateBounds)1057 GrRenderTask::ExpectedOutcome OpsTask::onMakeClosed(GrRecordingContext* rContext,
1058                                                     SkIRect* targetUpdateBounds) {
1059     this->forwardCombine(*rContext->priv().caps());
1060     if (!this->isColorNoOp()) {
1061         GrSurfaceProxy* proxy = this->target(0);
1062         // Use the entire backing store bounds since the GPU doesn't clip automatically to the
1063         // logical dimensions.
1064         SkRect clippedContentBounds = proxy->backingStoreBoundsRect();
1065         // TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds
1066         // then we can simply assert here that the bounds intersect.
1067         if (clippedContentBounds.intersect(fTotalBounds)) {
1068             clippedContentBounds.roundOut(&fClippedContentBounds);
1069             *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
1070                     fTargetOrigin,
1071                     this->target(0)->backingStoreDimensions().height(),
1072                     fClippedContentBounds);
1073             return ExpectedOutcome::kTargetDirty;
1074         }
1075     }
1076     return ExpectedOutcome::kTargetUnchanged;
1077 }
1078 
1079 }  // namespace skgpu::ganesh
1080