blob: cc7c8f3ab42d05e0c98128765bb3824bbdc70f2f [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
Greg Danielf41b2bd2019-08-22 16:19:24 -04002 * Copyright 2019 Google Inc.
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
Greg Danielf41b2bd2019-08-22 16:19:24 -04008#include "src/gpu/GrOpsTask.h"
Brian Salomon4d2d6f42019-07-26 14:15:11 -04009
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040010#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/core/SkRectPriv.h"
12#include "src/core/SkTraceEvent.h"
Greg Danielc0d69152020-10-08 14:59:00 -040013#include "src/gpu/GrAttachment.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040014#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrCaps.h"
16#include "src/gpu/GrGpu.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrMemoryPool.h"
Greg Daniele227fe42019-08-21 13:52:24 -040018#include "src/gpu/GrOpFlushState.h"
Greg Daniel2d41d0d2019-08-26 11:08:51 -040019#include "src/gpu/GrOpsRenderPass.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/GrRecordingContextPriv.h"
Chris Dalton674f77a2019-09-30 20:49:39 -060021#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/gpu/GrResourceAllocator.h"
Brian Salomoneebe7352020-12-09 16:37:04 -050023#include "src/gpu/GrSurfaceDrawContext.h"
Brian Salomon4cfae3b2020-07-23 10:33:24 -040024#include "src/gpu/GrTexture.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040025#include "src/gpu/geometry/GrRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050026#include "src/gpu/ops/GrClearOp.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040027
reed@google.comac10a2d2010-12-22 21:39:39 +000028////////////////////////////////////////////////////////////////////////////////
29
Brian Salomon09d994e2016-12-21 11:14:46 -050030// Experimentally we have found that most combining occurs within the first 10 comparisons.
Brian Salomon588cec72018-11-14 13:56:37 -050031static const int kMaxOpMergeDistance = 10;
32static const int kMaxOpChainDistance = 10;
33
34////////////////////////////////////////////////////////////////////////////////
35
Greg Daniel524e28b2019-11-01 11:48:53 -040036using DstProxyView = GrXferProcessor::DstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -050037
38////////////////////////////////////////////////////////////////////////////////
39
40static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
41
42////////////////////////////////////////////////////////////////////////////////
43
Herb Derbyc76d4092020-10-07 16:46:15 -040044inline GrOpsTask::OpChain::List::List(GrOp::Owner op)
Brian Salomon588cec72018-11-14 13:56:37 -050045 : fHead(std::move(op)), fTail(fHead.get()) {
46 this->validate();
47}
48
Greg Danielf41b2bd2019-08-22 16:19:24 -040049inline GrOpsTask::OpChain::List::List(List&& that) { *this = std::move(that); }
Brian Salomon588cec72018-11-14 13:56:37 -050050
Greg Danielf41b2bd2019-08-22 16:19:24 -040051inline GrOpsTask::OpChain::List& GrOpsTask::OpChain::List::operator=(List&& that) {
Brian Salomon588cec72018-11-14 13:56:37 -050052 fHead = std::move(that.fHead);
53 fTail = that.fTail;
54 that.fTail = nullptr;
55 this->validate();
56 return *this;
57}
58
Herb Derbyc76d4092020-10-07 16:46:15 -040059inline GrOp::Owner GrOpsTask::OpChain::List::popHead() {
Brian Salomon588cec72018-11-14 13:56:37 -050060 SkASSERT(fHead);
61 auto temp = fHead->cutChain();
62 std::swap(temp, fHead);
63 if (!fHead) {
64 SkASSERT(fTail == temp.get());
65 fTail = nullptr;
66 }
67 return temp;
68}
69
Herb Derbyc76d4092020-10-07 16:46:15 -040070inline GrOp::Owner GrOpsTask::OpChain::List::removeOp(GrOp* op) {
Brian Salomon588cec72018-11-14 13:56:37 -050071#ifdef SK_DEBUG
72 auto head = op;
73 while (head->prevInChain()) { head = head->prevInChain(); }
74 SkASSERT(head == fHead.get());
75#endif
76 auto prev = op->prevInChain();
77 if (!prev) {
78 SkASSERT(op == fHead.get());
79 return this->popHead();
80 }
81 auto temp = prev->cutChain();
82 if (auto next = temp->cutChain()) {
83 prev->chainConcat(std::move(next));
84 } else {
85 SkASSERT(fTail == op);
86 fTail = prev;
87 }
88 this->validate();
89 return temp;
90}
91
Herb Derbyc76d4092020-10-07 16:46:15 -040092inline void GrOpsTask::OpChain::List::pushHead(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -050093 SkASSERT(op);
94 SkASSERT(op->isChainHead());
95 SkASSERT(op->isChainTail());
96 if (fHead) {
97 op->chainConcat(std::move(fHead));
98 fHead = std::move(op);
99 } else {
100 fHead = std::move(op);
101 fTail = fHead.get();
102 }
103}
104
Herb Derbyc76d4092020-10-07 16:46:15 -0400105inline void GrOpsTask::OpChain::List::pushTail(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -0500106 SkASSERT(op->isChainTail());
107 fTail->chainConcat(std::move(op));
108 fTail = fTail->nextInChain();
109}
110
Greg Danielf41b2bd2019-08-22 16:19:24 -0400111inline void GrOpsTask::OpChain::List::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500112#ifdef SK_DEBUG
113 if (fHead) {
114 SkASSERT(fTail);
115 fHead->validateChain(fTail);
116 }
117#endif
118}
119
120////////////////////////////////////////////////////////////////////////////////
121
Herb Derbyc76d4092020-10-07 16:46:15 -0400122GrOpsTask::OpChain::OpChain(GrOp::Owner op,
Greg Danielf41b2bd2019-08-22 16:19:24 -0400123 GrProcessorSet::Analysis processorAnalysis,
Greg Daniel524e28b2019-11-01 11:48:53 -0400124 GrAppliedClip* appliedClip, const DstProxyView* dstProxyView)
Chris Dalton945ee652019-01-23 09:10:36 -0700125 : fList{std::move(op)}
126 , fProcessorAnalysis(processorAnalysis)
127 , fAppliedClip(appliedClip) {
128 if (fProcessorAnalysis.requiresDstTexture()) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400129 SkASSERT(dstProxyView && dstProxyView->proxy());
130 fDstProxyView = *dstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500131 }
132 fBounds = fList.head()->bounds();
133}
134
Greg Danielf41b2bd2019-08-22 16:19:24 -0400135void GrOpsTask::OpChain::visitProxies(const GrOp::VisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500136 if (fList.empty()) {
137 return;
138 }
139 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600140 op.visitProxies(func);
Brian Salomon588cec72018-11-14 13:56:37 -0500141 }
Greg Daniel524e28b2019-11-01 11:48:53 -0400142 if (fDstProxyView.proxy()) {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400143 func(fDstProxyView.proxy(), GrMipmapped::kNo);
Brian Salomon588cec72018-11-14 13:56:37 -0500144 }
145 if (fAppliedClip) {
146 fAppliedClip->visitProxies(func);
147 }
148}
149
Herb Derbye32e1ab2020-10-27 10:29:46 -0400150void GrOpsTask::OpChain::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500151 while (!fList.empty()) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400152 // Since the value goes out of scope immediately, the GrOp::Owner deletes the op.
153 fList.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500154 }
155}
156
157// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
158// the two chains are chainable. Returns the new chain.
Chris Daltonf8d75c62021-04-02 11:24:58 -0600159GrOpsTask::OpChain::List GrOpsTask::OpChain::DoConcat(List chainA, List chainB, const GrCaps& caps,
160 SkArenaAlloc* opsTaskArena,
161 GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500162 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
163 // at chain a's tail and working toward the head. We produce one of the following outcomes:
164 // 1) b's head is merged into an op in a.
165 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
166 // 3) b's head is popped from chain a and added at the tail of a.
167 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
168 // as we assume merges were already attempted when chain b was created. So we keep track of the
169 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
170 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
171 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
172 GrOp* origATail = chainA.tail();
173 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
174 do {
175 int numMergeChecks = 0;
176 bool merged = false;
177 bool noSkip = (origATail == chainA.tail());
178 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
179 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
180 SkRect forwardMergeBounds = skipBounds;
181 GrOp* a = origATail;
182 while (a) {
183 bool canForwardMerge =
184 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
185 if (canForwardMerge || canBackwardMerge) {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600186 auto result = a->combineIfPossible(chainB.head(), opsTaskArena, caps);
Brian Salomon588cec72018-11-14 13:56:37 -0500187 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
188 merged = (result == GrOp::CombineResult::kMerged);
Robert Phillips9548c3b422019-01-08 12:35:43 -0500189 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Brian Salomon588cec72018-11-14 13:56:37 -0500190 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
191 a->uniqueID());
Brian Salomon588cec72018-11-14 13:56:37 -0500192 }
193 if (merged) {
Brian Salomon52a6ed32018-11-26 10:30:58 -0500194 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
Brian Salomon588cec72018-11-14 13:56:37 -0500195 if (canBackwardMerge) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400196 // The GrOp::Owner releases the op.
197 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500198 } else {
199 // We merged the contents of b's head into a. We will replace b's head with a in
200 // chain b.
201 SkASSERT(canForwardMerge);
202 if (a == origATail) {
203 origATail = a->prevInChain();
204 }
Herb Derbyc76d4092020-10-07 16:46:15 -0400205 GrOp::Owner detachedA = chainA.removeOp(a);
206 // The GrOp::Owner releases the op.
207 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500208 chainB.pushHead(std::move(detachedA));
209 if (chainA.empty()) {
210 // We merged all the nodes in chain a to chain b.
211 return chainB;
212 }
213 }
214 break;
215 } else {
216 if (++numMergeChecks == kMaxOpMergeDistance) {
217 break;
218 }
219 forwardMergeBounds.joinNonEmptyArg(a->bounds());
220 canBackwardMerge =
221 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
222 a = a->prevInChain();
223 }
224 }
225 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
226 // tail of a.
227 if (!merged) {
228 chainA.pushTail(chainB.popHead());
229 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
230 }
231 } while (!chainB.empty());
232 return chainA;
233}
234
Chris Dalton945ee652019-01-23 09:10:36 -0700235// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
236// whether the operation succeeded. On success, the provided list will be returned empty.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400237bool GrOpsTask::OpChain::tryConcat(
Greg Daniel524e28b2019-11-01 11:48:53 -0400238 List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxyView& dstProxyView,
Chris Dalton945ee652019-01-23 09:10:36 -0700239 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600240 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700241 SkASSERT(!fList.empty());
242 SkASSERT(!list->empty());
Greg Daniel524e28b2019-11-01 11:48:53 -0400243 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy()));
244 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy()));
Brian Salomon588cec72018-11-14 13:56:37 -0500245 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700246 if (fList.head()->classID() != list->head()->classID() ||
247 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
248 (fAppliedClip && *fAppliedClip != *appliedClip) ||
Chris Dalton945ee652019-01-23 09:10:36 -0700249 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
250 processorAnalysis.requiresNonOverlappingDraws()) ||
251 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
252 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
253 // or read back a new dst texture between draws. In either case, we can neither
254 // chain nor combine overlapping Ops.
255 GrRectsTouchOrOverlap(fBounds, bounds)) ||
256 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
Greg Daniel524e28b2019-11-01 11:48:53 -0400257 (fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700258 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500259 }
Chris Daltonee21e6b2019-01-22 14:04:43 -0700260
Brian Salomon588cec72018-11-14 13:56:37 -0500261 SkDEBUGCODE(bool first = true;)
262 do {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600263 switch (fList.tail()->combineIfPossible(list->head(), opsTaskArena, caps))
Herb Derbye25c3002020-10-27 15:57:27 -0400264 {
Brian Salomon588cec72018-11-14 13:56:37 -0500265 case GrOp::CombineResult::kCannotCombine:
266 // If an op supports chaining then it is required that chaining is transitive and
267 // that if any two ops in two different chains can merge then the two chains
268 // may also be chained together. Thus, we should only hit this on the first
269 // iteration.
270 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700271 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500272 case GrOp::CombineResult::kMayChain:
Chris Daltonf8d75c62021-04-02 11:24:58 -0600273 fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500274 auditTrail);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700275 // The above exchange cleared out 'list'. The list needs to be empty now for the
276 // loop to terminate.
277 SkASSERT(list->empty());
278 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500279 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500280 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700281 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
282 list->head()->uniqueID());
283 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
Herb Derbyc76d4092020-10-07 16:46:15 -0400284 // The GrOp::Owner releases the op.
285 list->popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500286 break;
287 }
288 }
289 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700290 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700291
292 // The new ops were successfully merged and/or chained onto our own.
293 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700294 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500295}
296
Chris Daltonf8d75c62021-04-02 11:24:58 -0600297bool GrOpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, SkArenaAlloc* opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500298 GrAuditTrail* auditTrail) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400299 if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600300 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500301 this->validate();
302 // append failed
303 return false;
304 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700305
Brian Salomon588cec72018-11-14 13:56:37 -0500306 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700307 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500308 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700309 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500310
Greg Daniel524e28b2019-11-01 11:48:53 -0400311 that->fDstProxyView.setProxyView({});
John Stiles59e18dc2020-07-22 18:18:12 -0400312 if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) {
313 // Obliterates the processor.
314 that->fAppliedClip->detachCoverageFragmentProcessor();
Brian Salomon588cec72018-11-14 13:56:37 -0500315 }
316 this->validate();
317 return true;
318}
319
Herb Derbyc76d4092020-10-07 16:46:15 -0400320GrOp::Owner GrOpsTask::OpChain::appendOp(
321 GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
Greg Daniel524e28b2019-11-01 11:48:53 -0400322 const DstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600323 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400324 const GrXferProcessor::DstProxyView noDstProxyView;
325 if (!dstProxyView) {
326 dstProxyView = &noDstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500327 }
328 SkASSERT(op->isChainHead() && op->isChainTail());
329 SkRect opBounds = op->bounds();
330 List chain(std::move(op));
Chris Daltonf8d75c62021-04-02 11:24:58 -0600331 if (!this->tryConcat(&chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps,
332 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500333 // append failed, give the op back to the caller.
334 this->validate();
335 return chain.popHead();
336 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700337
338 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500339 this->validate();
340 return nullptr;
341}
342
Greg Danielf41b2bd2019-08-22 16:19:24 -0400343inline void GrOpsTask::OpChain::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500344#ifdef SK_DEBUG
345 fList.validate();
346 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
347 // Not using SkRect::contains because we allow empty rects.
348 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
349 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
350 }
351#endif
352}
353
354////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800355
Brian Salomon982127b2021-01-21 10:43:35 -0500356GrOpsTask::GrOpsTask(GrDrawingManager* drawingMgr,
Greg Daniel16f5c652019-10-29 11:26:01 -0400357 GrSurfaceProxyView view,
Herb Derby27ce7df2021-04-06 20:15:50 +0000358 GrAuditTrail* auditTrail)
Adlai Holler33d569e2020-06-16 14:30:08 -0400359 : GrRenderTask()
Greg Danielf41b2bd2019-08-22 16:19:24 -0400360 , fAuditTrail(auditTrail)
Brian Salomon982127b2021-01-21 10:43:35 -0500361 , fTargetSwizzle(view.swizzle())
362 , fTargetOrigin(view.origin())
363 SkDEBUGCODE(, fNumClips(0)) {
Herb Derby220dd692021-04-06 19:53:54 +0000364 fAllocators.push_back(std::make_unique<SkArenaAlloc>(4096));
Brian Salomon982127b2021-01-21 10:43:35 -0500365 this->addTarget(drawingMgr, view.detachProxy());
bsalomon4061b122015-05-29 10:26:19 -0700366}
367
Greg Danielf41b2bd2019-08-22 16:19:24 -0400368void GrOpsTask::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500369 for (auto& chain : fOpChains) {
Herb Derbye32e1ab2020-10-27 10:29:46 -0400370 chain.deleteOps();
Robert Phillipsc994a932018-06-19 13:09:54 -0400371 }
Brian Salomon588cec72018-11-14 13:56:37 -0500372 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400373}
374
Greg Danielf41b2bd2019-08-22 16:19:24 -0400375GrOpsTask::~GrOpsTask() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400376 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000377}
378
Adlai Hollerabe45182020-11-17 09:22:13 -0500379void GrOpsTask::addOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
380 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
381 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
382 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
383 };
384
385 op->visitProxies(addDependency);
386
387 this->recordOp(std::move(op), GrProcessorSet::EmptySetAnalysis(), nullptr, nullptr, caps);
388}
389
390void GrOpsTask::addDrawOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
391 const GrProcessorSet::Analysis& processorAnalysis,
392 GrAppliedClip&& clip, const DstProxyView& dstProxyView,
393 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
394 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
395 this->addSampledTexture(p);
396 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
397 };
398
399 op->visitProxies(addDependency);
400 clip.visitProxies(addDependency);
401 if (dstProxyView.proxy()) {
402 if (GrDstSampleTypeUsesTexture(dstProxyView.dstSampleType())) {
403 this->addSampledTexture(dstProxyView.proxy());
404 }
405 addDependency(dstProxyView.proxy(), GrMipmapped::kNo);
Brian Salomon982127b2021-01-21 10:43:35 -0500406 if (this->target(0) == dstProxyView.proxy()) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500407 // Since we are sampling and drawing to the same surface we will need to use
408 // texture barriers.
409 SkASSERT(GrDstSampleTypeDirectlySamplesDst(dstProxyView.dstSampleType()));
410 fRenderPassXferBarriers |= GrXferBarrierFlags::kTexture;
411 }
412 SkASSERT(dstProxyView.dstSampleType() != GrDstSampleType::kAsInputAttachment ||
413 dstProxyView.offset().isZero());
414 }
415
416 if (processorAnalysis.usesNonCoherentHWBlending()) {
417 fRenderPassXferBarriers |= GrXferBarrierFlags::kBlend;
418 }
419
420 this->recordOp(std::move(op), processorAnalysis, clip.doesClip() ? &clip : nullptr,
421 &dstProxyView, caps);
422}
423
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400424void GrOpsTask::endFlush(GrDrawingManager* drawingMgr) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400425 fLastClipStackGenID = SK_InvalidUniqueID;
426 this->deleteOps();
Herb Derby220dd692021-04-06 19:53:54 +0000427 fAllocators.reset();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700428
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500429 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400430 fSampledProxies.reset();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400431 fAuditTrail = nullptr;
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400432
433 GrRenderTask::endFlush(drawingMgr);
Greg Danielf21bf9e2019-08-22 20:12:20 +0000434}
435
Robert Phillips29f38542019-10-16 09:20:25 -0400436void GrOpsTask::onPrePrepare(GrRecordingContext* context) {
Robert Phillips7327c9d2019-10-08 16:32:56 -0400437 SkASSERT(this->isClosed());
Robert Phillips7327c9d2019-10-08 16:32:56 -0400438 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
439 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
440 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
441 // we shouldn't end up with GrOpsTasks with only discard.
442 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
443 return;
444 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500445 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400446
Brian Salomon982127b2021-01-21 10:43:35 -0500447 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400448 for (const auto& chain : fOpChains) {
449 if (chain.shouldExecute()) {
Robert Phillips8053c972019-11-21 10:44:53 -0500450 chain.head()->prePrepare(context,
Brian Salomon982127b2021-01-21 10:43:35 -0500451 dstView,
Robert Phillips8053c972019-11-21 10:44:53 -0500452 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400453 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500454 fRenderPassXferBarriers,
455 fColorLoadOp);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400456 }
457 }
458}
459
Greg Danielf41b2bd2019-08-22 16:19:24 -0400460void GrOpsTask::onPrepare(GrOpFlushState* flushState) {
Brian Salomon982127b2021-01-21 10:43:35 -0500461 SkASSERT(this->target(0)->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400462 SkASSERT(this->isClosed());
Greg Daniel94ed83f2019-09-27 13:05:43 -0400463 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
464 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
465 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
466 // we shouldn't end up with GrOpsTasks with only discard.
467 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
468 return;
469 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500470 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
robertphillipsa106c622015-10-16 09:07:06 -0700471
Greg Danielb20d7e52019-09-03 13:54:39 -0400472 flushState->setSampledProxyArray(&fSampledProxies);
Brian Salomon982127b2021-01-21 10:43:35 -0500473 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500474 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500475 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400476 if (chain.shouldExecute()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400477#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400478 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400479#endif
Robert Phillips901aff02019-10-08 12:32:56 -0400480 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500481 dstView,
Robert Phillips901aff02019-10-08 12:32:56 -0400482 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400483 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500484 fRenderPassXferBarriers,
485 fColorLoadOp);
Robert Phillips405413f2019-10-04 10:39:28 -0400486
Brian Salomon29b60c92017-10-31 14:42:10 -0400487 flushState->setOpArgs(&opArgs);
Robert Phillipsdf70f152019-11-15 14:57:05 -0500488
489 // Temporary debugging helper: for debugging prePrepare w/o going through DDLs
490 // Delete once most of the GrOps have an onPrePrepare.
Adlai Holler33d569e2020-06-16 14:30:08 -0400491 // chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0),
Robert Phillipsdf70f152019-11-15 14:57:05 -0500492 // chain.appliedClip());
493
Robert Phillips7327c9d2019-10-08 16:32:56 -0400494 // GrOp::prePrepare may or may not have been called at this point
Brian Salomon588cec72018-11-14 13:56:37 -0500495 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400496 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800497 }
bsalomon512be532015-09-10 10:42:55 -0700498 }
Greg Danielb20d7e52019-09-03 13:54:39 -0400499 flushState->setSampledProxyArray(nullptr);
robertphillipsa13e2022015-11-11 12:01:09 -0800500}
bsalomon512be532015-09-10 10:42:55 -0700501
Greg Danielc0d69152020-10-08 14:59:00 -0400502static GrOpsRenderPass* create_render_pass(GrGpu* gpu,
503 GrRenderTarget* rt,
504 GrAttachment* stencil,
505 GrSurfaceOrigin origin,
506 const SkIRect& bounds,
507 GrLoadOp colorLoadOp,
Brian Salomon07bc9a22020-12-02 13:37:16 -0500508 const std::array<float, 4>& loadClearColor,
Greg Danielc0d69152020-10-08 14:59:00 -0400509 GrLoadOp stencilLoadOp,
510 GrStoreOp stencilStoreOp,
511 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
512 GrXferBarrierFlags renderPassXferBarriers) {
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400513 const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400514 colorLoadOp,
515 GrStoreOp::kStore,
516 loadClearColor
Robert Phillips178ce3e2017-04-13 09:15:47 -0400517 };
518
Robert Phillips95214472017-08-08 18:00:03 -0400519 // TODO:
520 // We would like to (at this level) only ever clear & discard. We would need
Greg Danielf41b2bd2019-08-22 16:19:24 -0400521 // to stop splitting up higher level OpsTasks for copyOps to achieve that.
Robert Phillips95214472017-08-08 18:00:03 -0400522 // Note: we would still need SB loads and stores but they would happen at a
523 // lower level (inside the VK command buffer).
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400524 const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400525 stencilLoadOp,
Chris Dalton674f77a2019-09-30 20:49:39 -0600526 stencilStoreOp,
Robert Phillips95214472017-08-08 18:00:03 -0400527 };
528
Robert Phillips96f22372020-05-20 12:31:18 -0400529 return gpu->getOpsRenderPass(rt, stencil, origin, bounds,
Greg Daniel9a18b082020-08-14 14:03:50 -0400530 kColorLoadStoreInfo, stencilLoadAndStoreInfo, sampledProxies,
Greg Daniel21774362020-09-14 10:36:43 -0400531 renderPassXferBarriers);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400532}
533
Brian Salomon25a88092016-12-01 09:36:50 -0500534// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500535// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500536// Ops and instantiate them here.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400537bool GrOpsTask::onExecute(GrOpFlushState* flushState) {
Greg Daniel94ed83f2019-09-27 13:05:43 -0400538 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
539 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
540 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
541 // we shouldn't end up with GrOpsTasks with only discard.
542 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
bsalomondc438982016-08-31 11:53:49 -0700543 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700544 }
Robert Phillips4a395042017-04-24 16:27:17 +0000545
Adlai Holler33d569e2020-06-16 14:30:08 -0400546 SkASSERT(this->numTargets() == 1);
Brian Salomon982127b2021-01-21 10:43:35 -0500547 GrRenderTargetProxy* proxy = this->target(0)->asRenderTargetProxy();
Greg Daniel16f5c652019-10-29 11:26:01 -0400548 SkASSERT(proxy);
Brian Salomon5f394272019-07-02 14:07:49 -0400549 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400550
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500551 // 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());
Chris Dalton674f77a2019-09-30 20:49:39 -0600554
555 const GrCaps& caps = *flushState->gpu()->caps();
Greg Daniel16f5c652019-10-29 11:26:01 -0400556 GrRenderTarget* renderTarget = proxy->peekRenderTarget();
Chris Dalton674f77a2019-09-30 20:49:39 -0600557 SkASSERT(renderTarget);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700558
Greg Danielc0d69152020-10-08 14:59:00 -0400559 GrAttachment* stencil = nullptr;
Chris Dalton0b68dda2019-11-07 21:08:03 -0700560 if (int numStencilSamples = proxy->numStencilSamples()) {
561 if (!flushState->resourceProvider()->attachStencilAttachment(
562 renderTarget, numStencilSamples)) {
563 SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n");
564 return false;
565 }
Brian Salomonf7f54332020-07-28 09:23:35 -0400566 stencil = renderTarget->getStencilAttachment();
Chris Dalton0b68dda2019-11-07 21:08:03 -0700567 }
568
Chris Daltonf00b95b2019-11-07 21:14:41 -0700569 SkASSERT(!stencil || stencil->numSamples() == proxy->numStencilSamples());
Chris Dalton674f77a2019-09-30 20:49:39 -0600570
571 GrLoadOp stencilLoadOp;
572 switch (fInitialStencilContent) {
573 case StencilContent::kDontCare:
574 stencilLoadOp = GrLoadOp::kDiscard;
575 break;
576 case StencilContent::kUserBitsCleared:
577 SkASSERT(!caps.performStencilClearsAsDraws());
578 SkASSERT(stencil);
579 if (caps.discardStencilValuesAfterRenderPass()) {
580 // Always clear the stencil if it is being discarded after render passes. This is
581 // also an optimization because we are on a tiler and it avoids loading the values
582 // from memory.
583 stencilLoadOp = GrLoadOp::kClear;
584 break;
585 }
586 if (!stencil->hasPerformedInitialClear()) {
587 stencilLoadOp = GrLoadOp::kClear;
588 stencil->markHasPerformedInitialClear();
589 break;
590 }
591 // renderTargetContexts are required to leave the user stencil bits in a cleared state
592 // once finished, meaning the stencil values will always remain cleared after the
593 // initial clear. Just fall through to reloading the existing (cleared) stencil values
594 // from memory.
John Stiles30212b72020-06-11 17:55:07 -0400595 [[fallthrough]];
Chris Dalton674f77a2019-09-30 20:49:39 -0600596 case StencilContent::kPreserved:
597 SkASSERT(stencil);
598 stencilLoadOp = GrLoadOp::kLoad;
599 break;
600 }
601
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500602 // NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split
Chris Dalton674f77a2019-09-30 20:49:39 -0600603 // its opsTask.
604 //
605 // FIXME: We don't currently flag render passes that don't use stencil at all. In that case
606 // their store op might be "discard", and we currently make the assumption that a discard will
607 // not invalidate what's already in main memory. This is probably ok for now, but certainly
608 // something we want to address soon.
609 GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil)
610 ? GrStoreOp::kDiscard
611 : GrStoreOp::kStore;
612
Brian Salomon982127b2021-01-21 10:43:35 -0500613 GrOpsRenderPass* renderPass = create_render_pass(flushState->gpu(),
614 proxy->peekRenderTarget(),
615 stencil,
616 fTargetOrigin,
617 fClippedContentBounds,
618 fColorLoadOp,
619 fLoadClearColor,
620 stencilLoadOp,
621 stencilStoreOp,
622 fSampledProxies,
623 fRenderPassXferBarriers);
Greg Daniel21774362020-09-14 10:36:43 -0400624
Greg Danielfa3adf72019-11-07 09:53:41 -0500625 if (!renderPass) {
626 return false;
627 }
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400628 flushState->setOpsRenderPass(renderPass);
629 renderPass->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400630
Brian Salomon982127b2021-01-21 10:43:35 -0500631 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
632
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400633 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500634 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400635 if (!chain.shouldExecute()) {
bsalomonaecc0182016-03-07 11:50:44 -0800636 continue;
637 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400638#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400639 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400640#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400641
Robert Phillips405413f2019-10-04 10:39:28 -0400642 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500643 dstView,
Robert Phillips405413f2019-10-04 10:39:28 -0400644 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400645 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500646 fRenderPassXferBarriers,
647 fColorLoadOp);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400648
Brian Salomon29b60c92017-10-31 14:42:10 -0400649 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500650 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400651 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700652 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400653
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400654 renderPass->end();
655 flushState->gpu()->submit(renderPass);
656 flushState->setOpsRenderPass(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800657
bsalomondc438982016-08-31 11:53:49 -0700658 return true;
bsalomona73239a2015-04-28 13:35:17 -0700659}
660
Brian Salomon07bc9a22020-12-02 13:37:16 -0500661void GrOpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500662 fColorLoadOp = op;
663 fLoadClearColor = color;
Chris Dalton16a33c62019-09-24 22:19:17 -0600664 if (GrLoadOp::kClear == fColorLoadOp) {
Brian Salomon982127b2021-01-21 10:43:35 -0500665 GrSurfaceProxy* proxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400666 SkASSERT(proxy);
Michael Ludwigd1d997e2020-06-04 15:52:44 -0400667 fTotalBounds = proxy->backingStoreBoundsRect();
Chris Dalton16a33c62019-09-24 22:19:17 -0600668 }
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500669}
670
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500671void GrOpsTask::reset() {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500672 fDeferredProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500673 fSampledProxies.reset();
Herb Derby220dd692021-04-06 19:53:54 +0000674 fAllocators.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500675 fClippedContentBounds = SkIRect::MakeEmpty();
676 fTotalBounds = SkRect::MakeEmpty();
Adlai Holler026851a2021-03-29 14:47:11 -0400677 this->deleteOps();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500678 fRenderPassXferBarriers = GrXferBarrierFlags::kNone;
679}
680
Adlai Holler93439d92021-01-26 09:20:39 -0500681int GrOpsTask::mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks) {
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500682 // Find the index of the last color-clearing task. -1 indicates this or "there are none."
683 int indexOfLastColorClear = -1;
Adlai Holler93439d92021-01-26 09:20:39 -0500684 int mergedCount = 0;
685 for (const sk_sp<GrRenderTask>& task : tasks) {
686 auto opsTask = task->asOpsTask();
687 if (!opsTask || opsTask->target(0) != this->target(0)) {
688 break;
689 }
690 SkASSERT(fTargetSwizzle == opsTask->fTargetSwizzle);
691 SkASSERT(fTargetOrigin == opsTask->fTargetOrigin);
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500692 if (GrLoadOp::kClear == opsTask->fColorLoadOp) {
693 indexOfLastColorClear = &task - tasks.begin();
694 }
Adlai Holler93439d92021-01-26 09:20:39 -0500695 mergedCount += 1;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500696 }
697 if (0 == mergedCount) {
698 return 0;
699 }
700
701 SkSpan<const sk_sp<GrOpsTask>> opsTasks(reinterpret_cast<const sk_sp<GrOpsTask>*>(tasks.data()),
702 SkToSizeT(mergedCount));
703 if (indexOfLastColorClear >= 0) {
704 // If any dropped task needs to preserve stencil, for now just bail on the merge.
705 // Could keep the merge and insert a clear op, but might be tricky due to closed task.
706 if (fMustPreserveStencil) {
707 return 0;
708 }
709 for (const auto& opsTask : opsTasks.first(indexOfLastColorClear)) {
710 if (opsTask->fMustPreserveStencil) {
711 return 0;
712 }
713 }
714 // Clear `this` and forget about the tasks pre-color-clear.
715 this->reset();
716 opsTasks = opsTasks.last(opsTasks.count() - indexOfLastColorClear);
717 // Copy the color-clear into `this`.
718 fColorLoadOp = GrLoadOp::kClear;
719 fLoadClearColor = opsTasks.front()->fLoadClearColor;
720 }
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500721 int addlDeferredProxyCount = 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500722 int addlProxyCount = 0;
723 int addlOpChainCount = 0;
724 for (const auto& opsTask : opsTasks) {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500725 addlDeferredProxyCount += opsTask->fDeferredProxies.count();
Adlai Holler93439d92021-01-26 09:20:39 -0500726 addlProxyCount += opsTask->fSampledProxies.count();
727 addlOpChainCount += opsTask->fOpChains.count();
728 fClippedContentBounds.join(opsTask->fClippedContentBounds);
729 fTotalBounds.join(opsTask->fTotalBounds);
730 fRenderPassXferBarriers |= opsTask->fRenderPassXferBarriers;
731 SkDEBUGCODE(fNumClips += opsTask->fNumClips);
Adlai Holler93439d92021-01-26 09:20:39 -0500732 }
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500733
Adlai Holler93439d92021-01-26 09:20:39 -0500734 fLastClipStackGenID = SK_InvalidUniqueID;
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500735 fDeferredProxies.reserve_back(addlDeferredProxyCount);
Adlai Holler93439d92021-01-26 09:20:39 -0500736 fSampledProxies.reserve_back(addlProxyCount);
737 fOpChains.reserve_back(addlOpChainCount);
Herb Derby220dd692021-04-06 19:53:54 +0000738 fAllocators.reserve_back(opsTasks.count());
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500739 for (const auto& opsTask : opsTasks) {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500740 fDeferredProxies.move_back_n(opsTask->fDeferredProxies.count(),
741 opsTask->fDeferredProxies.data());
Adlai Holler93439d92021-01-26 09:20:39 -0500742 fSampledProxies.move_back_n(opsTask->fSampledProxies.count(),
743 opsTask->fSampledProxies.data());
744 fOpChains.move_back_n(opsTask->fOpChains.count(),
745 opsTask->fOpChains.data());
Herb Derby220dd692021-04-06 19:53:54 +0000746 SkASSERT(1 == opsTask->fAllocators.count());
747 fAllocators.push_back(std::move(opsTask->fAllocators[0]));
748 opsTask->fAllocators.reset();
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500749 opsTask->fDeferredProxies.reset();
Adlai Holler93439d92021-01-26 09:20:39 -0500750 opsTask->fSampledProxies.reset();
751 opsTask->fOpChains.reset();
752 }
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500753 fMustPreserveStencil = opsTasks.back()->fMustPreserveStencil;
Adlai Holler93439d92021-01-26 09:20:39 -0500754 return mergedCount;
755}
756
Greg Danielf41b2bd2019-08-22 16:19:24 -0400757bool GrOpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
Chris Dalton6b982802019-06-27 13:53:46 -0600758 if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400759 this->deleteOps();
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500760 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400761 fSampledProxies.reset();
Greg Daniel070cbaf2019-01-03 17:35:54 -0500762
Greg Danielf41b2bd2019-08-22 16:19:24 -0400763 // 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.
Brian Salomon982127b2021-01-21 10:43:35 -0500766 return !this->target(0)->asRenderTargetProxy()->wrapsVkSecondaryCB();
bsalomonfd8d0132016-08-11 11:25:33 -0700767 }
Robert Phillips380b90c2017-08-30 07:41:07 -0400768
Greg Danielf41b2bd2019-08-22 16:19:24 -0400769 // Could not empty the task, so an op must be added to handle the clear
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500770 return false;
bsalomon9f129de2016-08-10 16:31:05 -0700771}
772
Greg Danielf41b2bd2019-08-22 16:19:24 -0400773void GrOpsTask::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;
Chris Dalton674f77a2019-09-30 20:49:39 -0600778 fInitialStencilContent = StencilContent::kDontCare;
Chris Dalton16a33c62019-09-24 22:19:17 -0600779 fTotalBounds.setEmpty();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400780 }
781}
782
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000783////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000784
John Stiles1e0136e2020-08-12 18:44:00 -0400785#if GR_TEST_UTILS
Robert Phillips047d5bb2021-01-08 13:39:19 -0500786void GrOpsTask::dump(const SkString& label,
787 SkString indent,
788 bool printDependencies,
789 bool close) const {
790 GrRenderTask::dump(label, indent, printDependencies, false);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400791
Robert Phillips047d5bb2021-01-08 13:39:19 -0500792 SkDebugf("%sfColorLoadOp: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600793 switch (fColorLoadOp) {
794 case GrLoadOp::kLoad:
795 SkDebugf("kLoad\n");
796 break;
797 case GrLoadOp::kClear:
Brian Salomon07bc9a22020-12-02 13:37:16 -0500798 SkDebugf("kClear {%g, %g, %g, %g}\n",
799 fLoadClearColor[0],
800 fLoadClearColor[1],
801 fLoadClearColor[2],
802 fLoadClearColor[3]);
Chris Dalton674f77a2019-09-30 20:49:39 -0600803 break;
804 case GrLoadOp::kDiscard:
805 SkDebugf("kDiscard\n");
806 break;
807 }
808
Robert Phillips047d5bb2021-01-08 13:39:19 -0500809 SkDebugf("%sfInitialStencilContent: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600810 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 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400821
Robert Phillips047d5bb2021-01-08 13:39:19 -0500822 SkDebugf("%s%d ops:\n", indent.c_str(), fOpChains.count());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400823 for (int i = 0; i < fOpChains.count(); ++i) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500824 SkDebugf("%s*******************************\n", indent.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400825 if (!fOpChains[i].head()) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500826 SkDebugf("%s%d: <combined forward or failed instantiation>\n", indent.c_str(), i);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400827 } else {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500828 SkDebugf("%s%d: %s\n", indent.c_str(), i, fOpChains[i].head()->name());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400829 SkRect bounds = fOpChains[i].bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500830 SkDebugf("%sClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
831 indent.c_str(),
832 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400833 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
834 SkString info = SkTabString(op.dumpInfo(), 1);
Robert Phillips047d5bb2021-01-08 13:39:19 -0500835 SkDebugf("%s%s\n", indent.c_str(), info.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400836 bounds = op.bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500837 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);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400840 }
841 }
842 }
Robert Phillips047d5bb2021-01-08 13:39:19 -0500843
844 if (close) {
845 SkDebugf("%s--------------------------------------------------------------\n\n",
846 indent.c_str());
847 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400848}
John Stiles1e0136e2020-08-12 18:44:00 -0400849#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400850
John Stiles1e0136e2020-08-12 18:44:00 -0400851#ifdef SK_DEBUG
Michael Ludwigfcdd0612019-11-25 08:34:31 -0500852void GrOpsTask::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400853 auto textureFunc = [ func ] (GrSurfaceProxy* tex, GrMipmapped mipmapped) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400854 func(tex, mipmapped);
855 };
856
Greg Danielf41b2bd2019-08-22 16:19:24 -0400857 for (const OpChain& chain : fOpChains) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400858 chain.visitProxies(textureFunc);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400859 }
860}
861
862#endif
863
864////////////////////////////////////////////////////////////////////////////////
865
Brian Salomond63638b2021-03-05 14:00:07 -0500866void GrOpsTask::onCanSkip() {
867 this->deleteOps();
868 fDeferredProxies.reset();
869 fColorLoadOp = GrLoadOp::kLoad;
870 SkASSERT(this->isNoOp());
871}
872
Greg Danielf41b2bd2019-08-22 16:19:24 -0400873bool GrOpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
874 bool used = false;
875
Brian Salomon7e67dca2020-07-21 09:27:25 -0400876 auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p, GrMipmapped) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400877 if (p == proxyToCheck) {
878 used = true;
879 }
880 };
881 for (const OpChain& recordedOp : fOpChains) {
882 recordedOp.visitProxies(visit);
883 }
884
885 return used;
886}
887
Greg Danielf41b2bd2019-08-22 16:19:24 -0400888void GrOpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500889 for (int i = 0; i < fDeferredProxies.count(); ++i) {
890 SkASSERT(!fDeferredProxies[i]->isInstantiated());
891 // We give all the deferred proxies a write usage at the very start of flushing. This
892 // locks them out of being reused for the entire flush until they are read - and then
893 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
894 // with sub-flushes. The deferred proxies only need to be pinned from the start of
895 // the sub-flush in which they appear.
896 alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo);
897 }
898
Brian Salomon982127b2021-01-21 10:43:35 -0500899 GrSurfaceProxy* targetProxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400900
Greg Danielf41b2bd2019-08-22 16:19:24 -0400901 // Add the interval for all the writes to this GrOpsTasks's target
Brian Salomon588cec72018-11-14 13:56:37 -0500902 if (fOpChains.count()) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400903 unsigned int cur = alloc->curOp();
904
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000905 alloc->addInterval(targetProxy, cur, cur + fOpChains.count() - 1,
906 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500907 } else {
908 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
909 // still need to add an interval for the destination so we create a fake op# for
910 // the missing clear op.
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000911 alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(),
912 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500913 alloc->incOps();
914 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400915
Brian Salomon7e67dca2020-07-21 09:27:25 -0400916 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipmapped) {
Brian Salomon982127b2021-01-21 10:43:35 -0500917 alloc->addInterval(p,
918 alloc->curOp(),
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000919 alloc->curOp(),
920 GrResourceAllocator::ActualUse::kYes
Brian Salomon982127b2021-01-21 10:43:35 -0500921 SkDEBUGCODE(, this->target(0) == p));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400922 };
Brian Salomon588cec72018-11-14 13:56:37 -0500923 for (const OpChain& recordedOp : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600924 recordedOp.visitProxies(gather);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500925
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400926 // Even though the op may have been (re)moved we still need to increment the op count to
Robert Phillipsf8e25022017-11-08 15:24:31 -0500927 // keep all the math consistent.
928 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400929 }
930}
931
Greg Danielf41b2bd2019-08-22 16:19:24 -0400932void GrOpsTask::recordOp(
Herb Derbyc76d4092020-10-07 16:46:15 -0400933 GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip,
Greg Daniel524e28b2019-11-01 11:48:53 -0400934 const DstProxyView* dstProxyView, const GrCaps& caps) {
Ethan Nicholas029b22c2018-10-18 16:49:56 -0400935 SkDEBUGCODE(op->validate();)
Greg Daniel524e28b2019-11-01 11:48:53 -0400936 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy()));
Brian Salomon982127b2021-01-21 10:43:35 -0500937 GrSurfaceProxy* proxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400938 SkASSERT(proxy);
Robert Phillipsee683652017-04-26 11:53:10 -0400939
Greg Danielf41b2bd2019-08-22 16:19:24 -0400940 // A closed GrOpsTask should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700941 SkASSERT(!this->isClosed());
Brian Salomon19ec80f2018-11-16 13:27:30 -0500942 if (!op->bounds().isFinite()) {
Brian Salomon19ec80f2018-11-16 13:27:30 -0500943 return;
944 }
robertphillipsa106c622015-10-16 09:07:06 -0700945
Chris Dalton16a33c62019-09-24 22:19:17 -0600946 // Account for this op's bounds before we attempt to combine.
947 // NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable.
948 fTotalBounds.join(op->bounds());
949
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500950 // Check if there is an op we can combine with by linearly searching back until we either
951 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700952 // 2) intersect with something
953 // 3) find a 'blocker'
Greg Daniel16f5c652019-10-29 11:26:01 -0400954 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400955 GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n"
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400956 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
957 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500958 op->name(),
959 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400960 op->bounds().fLeft, op->bounds().fTop,
961 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500962 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500963 GrOP_INFO("\tOutcome:\n");
Brian Osman788b9162020-02-07 10:36:46 -0500964 int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.count());
Robert Phillips318c4192017-05-17 09:36:38 -0400965 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700966 int i = 0;
967 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500968 OpChain& candidate = fOpChains.fromBack(i);
Greg Daniel524e28b2019-11-01 11:48:53 -0400969 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps,
Herb Derby220dd692021-04-06 19:53:54 +0000970 fAllocators.front().get(), fAuditTrail);
Brian Salomon588cec72018-11-14 13:56:37 -0500971 if (!op) {
972 return;
bsalomon512be532015-09-10 10:42:55 -0700973 }
Brian Salomona7682c82018-10-24 10:04:37 -0400974 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -0500975 if (!can_reorder(candidate.bounds(), op->bounds())) {
976 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
977 candidate.head()->name(), candidate.head()->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700978 break;
979 }
Brian Salomon588cec72018-11-14 13:56:37 -0500980 if (++i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400981 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -0700982 break;
983 }
984 }
985 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400986 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -0700987 }
Brian Salomon54d212e2017-03-21 14:22:38 -0400988 if (clip) {
Herb Derby220dd692021-04-06 19:53:54 +0000989 clip = fAllocators[0]->make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -0400990 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400991 }
Greg Daniel524e28b2019-11-01 11:48:53 -0400992 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView);
bsalomon512be532015-09-10 10:42:55 -0700993}
994
Greg Danielf41b2bd2019-08-22 16:19:24 -0400995void GrOpsTask::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400996 SkASSERT(!this->isClosed());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400997 GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
Robert Phillips48567ac2017-06-01 08:46:00 -0400998
Brian Salomon588cec72018-11-14 13:56:37 -0500999 for (int i = 0; i < fOpChains.count() - 1; ++i) {
1000 OpChain& chain = fOpChains[i];
Brian Osman788b9162020-02-07 10:36:46 -05001001 int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -08001002 int j = i + 1;
1003 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -05001004 OpChain& candidate = fOpChains[j];
Herb Derby220dd692021-04-06 19:53:54 +00001005 if (candidate.prependChain(&chain, caps, fAllocators.front().get(), fAuditTrail)) {
bsalomonaecc0182016-03-07 11:50:44 -08001006 break;
1007 }
Robert Phillipsc84c0302017-05-08 15:35:11 -04001008 // Stop traversing if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -05001009 if (!can_reorder(chain.bounds(), candidate.bounds())) {
1010 GrOP_INFO(
1011 "\t\t%d: chain (%s head opID: %u) -> "
1012 "Intersects with chain (%s, head opID: %u)\n",
1013 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
1014 candidate.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001015 break;
1016 }
Brian Salomona7682c82018-10-24 10:04:37 -04001017 if (++j > maxCandidateIdx) {
Brian Salomon588cec72018-11-14 13:56:37 -05001018 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
1019 i, chain.head()->name(), chain.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001020 break;
1021 }
1022 }
1023 }
1024}
1025
Robert Phillips07f675d2020-11-16 13:44:01 -05001026GrRenderTask::ExpectedOutcome GrOpsTask::onMakeClosed(const GrCaps& caps,
1027 SkIRect* targetUpdateBounds) {
Chris Dalton16a33c62019-09-24 22:19:17 -06001028 this->forwardCombine(caps);
1029 if (!this->isNoOp()) {
Brian Salomon982127b2021-01-21 10:43:35 -05001030 GrSurfaceProxy* proxy = this->target(0);
Michael Ludwigd1d997e2020-06-04 15:52:44 -04001031 // Use the entire backing store bounds since the GPU doesn't clip automatically to the
1032 // logical dimensions.
1033 SkRect clippedContentBounds = proxy->backingStoreBoundsRect();
Adlai Holler33d569e2020-06-16 14:30:08 -04001034 // TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds
Greg Daniel16f5c652019-10-29 11:26:01 -04001035 // then we can simply assert here that the bounds intersect.
Chris Dalton16a33c62019-09-24 22:19:17 -06001036 if (clippedContentBounds.intersect(fTotalBounds)) {
Greg Daniel94ed83f2019-09-27 13:05:43 -04001037 clippedContentBounds.roundOut(&fClippedContentBounds);
Brian Salomon982127b2021-01-21 10:43:35 -05001038 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
1039 fTargetOrigin,
1040 this->target(0)->backingStoreDimensions().height(),
1041 fClippedContentBounds);
Chris Dalton16a33c62019-09-24 22:19:17 -06001042 return ExpectedOutcome::kTargetDirty;
1043 }
1044 }
1045 return ExpectedOutcome::kTargetUnchanged;
1046}