blob: 5f2884cda2c95fc8700f49f79aae05a69d8c9c84 [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"
Herb Derby93250092021-04-06 12:19:20 -040012#include "src/core/SkScopeExit.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/core/SkTraceEvent.h"
Greg Danielc0d69152020-10-08 14:59:00 -040014#include "src/gpu/GrAttachment.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040015#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/GrCaps.h"
17#include "src/gpu/GrGpu.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrMemoryPool.h"
Greg Daniele227fe42019-08-21 13:52:24 -040019#include "src/gpu/GrOpFlushState.h"
Greg Daniel2d41d0d2019-08-26 11:08:51 -040020#include "src/gpu/GrOpsRenderPass.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/gpu/GrRecordingContextPriv.h"
Chris Dalton674f77a2019-09-30 20:49:39 -060022#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/GrResourceAllocator.h"
Brian Salomoneebe7352020-12-09 16:37:04 -050024#include "src/gpu/GrSurfaceDrawContext.h"
Brian Salomon4cfae3b2020-07-23 10:33:24 -040025#include "src/gpu/GrTexture.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040026#include "src/gpu/geometry/GrRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/ops/GrClearOp.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040028
reed@google.comac10a2d2010-12-22 21:39:39 +000029////////////////////////////////////////////////////////////////////////////////
30
Brian Salomon09d994e2016-12-21 11:14:46 -050031// Experimentally we have found that most combining occurs within the first 10 comparisons.
Brian Salomon588cec72018-11-14 13:56:37 -050032static const int kMaxOpMergeDistance = 10;
33static const int kMaxOpChainDistance = 10;
34
35////////////////////////////////////////////////////////////////////////////////
36
Brian Salomon588cec72018-11-14 13:56:37 -050037static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
38
39////////////////////////////////////////////////////////////////////////////////
40
Herb Derbyc76d4092020-10-07 16:46:15 -040041inline GrOpsTask::OpChain::List::List(GrOp::Owner op)
Brian Salomon588cec72018-11-14 13:56:37 -050042 : fHead(std::move(op)), fTail(fHead.get()) {
43 this->validate();
44}
45
Greg Danielf41b2bd2019-08-22 16:19:24 -040046inline GrOpsTask::OpChain::List::List(List&& that) { *this = std::move(that); }
Brian Salomon588cec72018-11-14 13:56:37 -050047
Greg Danielf41b2bd2019-08-22 16:19:24 -040048inline GrOpsTask::OpChain::List& GrOpsTask::OpChain::List::operator=(List&& that) {
Brian Salomon588cec72018-11-14 13:56:37 -050049 fHead = std::move(that.fHead);
50 fTail = that.fTail;
51 that.fTail = nullptr;
52 this->validate();
53 return *this;
54}
55
Herb Derbyc76d4092020-10-07 16:46:15 -040056inline GrOp::Owner GrOpsTask::OpChain::List::popHead() {
Brian Salomon588cec72018-11-14 13:56:37 -050057 SkASSERT(fHead);
58 auto temp = fHead->cutChain();
59 std::swap(temp, fHead);
60 if (!fHead) {
61 SkASSERT(fTail == temp.get());
62 fTail = nullptr;
63 }
64 return temp;
65}
66
Herb Derbyc76d4092020-10-07 16:46:15 -040067inline GrOp::Owner GrOpsTask::OpChain::List::removeOp(GrOp* op) {
Brian Salomon588cec72018-11-14 13:56:37 -050068#ifdef SK_DEBUG
69 auto head = op;
70 while (head->prevInChain()) { head = head->prevInChain(); }
71 SkASSERT(head == fHead.get());
72#endif
73 auto prev = op->prevInChain();
74 if (!prev) {
75 SkASSERT(op == fHead.get());
76 return this->popHead();
77 }
78 auto temp = prev->cutChain();
79 if (auto next = temp->cutChain()) {
80 prev->chainConcat(std::move(next));
81 } else {
82 SkASSERT(fTail == op);
83 fTail = prev;
84 }
85 this->validate();
86 return temp;
87}
88
Herb Derbyc76d4092020-10-07 16:46:15 -040089inline void GrOpsTask::OpChain::List::pushHead(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -050090 SkASSERT(op);
91 SkASSERT(op->isChainHead());
92 SkASSERT(op->isChainTail());
93 if (fHead) {
94 op->chainConcat(std::move(fHead));
95 fHead = std::move(op);
96 } else {
97 fHead = std::move(op);
98 fTail = fHead.get();
99 }
100}
101
Herb Derbyc76d4092020-10-07 16:46:15 -0400102inline void GrOpsTask::OpChain::List::pushTail(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -0500103 SkASSERT(op->isChainTail());
104 fTail->chainConcat(std::move(op));
105 fTail = fTail->nextInChain();
106}
107
Greg Danielf41b2bd2019-08-22 16:19:24 -0400108inline void GrOpsTask::OpChain::List::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500109#ifdef SK_DEBUG
110 if (fHead) {
111 SkASSERT(fTail);
112 fHead->validateChain(fTail);
113 }
114#endif
115}
116
117////////////////////////////////////////////////////////////////////////////////
118
John Stiles52cb1d02021-06-02 11:58:05 -0400119GrOpsTask::OpChain::OpChain(GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
120 GrAppliedClip* appliedClip, const GrDstProxyView* dstProxyView)
Chris Dalton945ee652019-01-23 09:10:36 -0700121 : fList{std::move(op)}
122 , fProcessorAnalysis(processorAnalysis)
123 , fAppliedClip(appliedClip) {
124 if (fProcessorAnalysis.requiresDstTexture()) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400125 SkASSERT(dstProxyView && dstProxyView->proxy());
126 fDstProxyView = *dstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500127 }
128 fBounds = fList.head()->bounds();
129}
130
Robert Phillips294723d2021-06-17 09:23:58 -0400131void GrOpsTask::OpChain::visitProxies(const GrVisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500132 if (fList.empty()) {
133 return;
134 }
135 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600136 op.visitProxies(func);
Brian Salomon588cec72018-11-14 13:56:37 -0500137 }
Greg Daniel524e28b2019-11-01 11:48:53 -0400138 if (fDstProxyView.proxy()) {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400139 func(fDstProxyView.proxy(), GrMipmapped::kNo);
Brian Salomon588cec72018-11-14 13:56:37 -0500140 }
141 if (fAppliedClip) {
142 fAppliedClip->visitProxies(func);
143 }
144}
145
Herb Derbye32e1ab2020-10-27 10:29:46 -0400146void GrOpsTask::OpChain::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500147 while (!fList.empty()) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400148 // Since the value goes out of scope immediately, the GrOp::Owner deletes the op.
149 fList.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500150 }
151}
152
153// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
154// the two chains are chainable. Returns the new chain.
Chris Daltonf8d75c62021-04-02 11:24:58 -0600155GrOpsTask::OpChain::List GrOpsTask::OpChain::DoConcat(List chainA, List chainB, const GrCaps& caps,
156 SkArenaAlloc* opsTaskArena,
157 GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500158 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
159 // at chain a's tail and working toward the head. We produce one of the following outcomes:
160 // 1) b's head is merged into an op in a.
161 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
162 // 3) b's head is popped from chain a and added at the tail of a.
163 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
164 // as we assume merges were already attempted when chain b was created. So we keep track of the
165 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
166 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
167 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
168 GrOp* origATail = chainA.tail();
169 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
170 do {
171 int numMergeChecks = 0;
172 bool merged = false;
173 bool noSkip = (origATail == chainA.tail());
174 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
175 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
176 SkRect forwardMergeBounds = skipBounds;
177 GrOp* a = origATail;
178 while (a) {
179 bool canForwardMerge =
180 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
181 if (canForwardMerge || canBackwardMerge) {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600182 auto result = a->combineIfPossible(chainB.head(), opsTaskArena, caps);
Brian Salomon588cec72018-11-14 13:56:37 -0500183 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
184 merged = (result == GrOp::CombineResult::kMerged);
Robert Phillips9548c3b422019-01-08 12:35:43 -0500185 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Brian Salomon588cec72018-11-14 13:56:37 -0500186 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
187 a->uniqueID());
Brian Salomon588cec72018-11-14 13:56:37 -0500188 }
189 if (merged) {
Brian Salomon52a6ed32018-11-26 10:30:58 -0500190 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
Brian Salomon588cec72018-11-14 13:56:37 -0500191 if (canBackwardMerge) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400192 // The GrOp::Owner releases the op.
193 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500194 } else {
195 // We merged the contents of b's head into a. We will replace b's head with a in
196 // chain b.
197 SkASSERT(canForwardMerge);
198 if (a == origATail) {
199 origATail = a->prevInChain();
200 }
Herb Derbyc76d4092020-10-07 16:46:15 -0400201 GrOp::Owner detachedA = chainA.removeOp(a);
202 // The GrOp::Owner releases the op.
203 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500204 chainB.pushHead(std::move(detachedA));
205 if (chainA.empty()) {
206 // We merged all the nodes in chain a to chain b.
207 return chainB;
208 }
209 }
210 break;
211 } else {
212 if (++numMergeChecks == kMaxOpMergeDistance) {
213 break;
214 }
215 forwardMergeBounds.joinNonEmptyArg(a->bounds());
216 canBackwardMerge =
217 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
218 a = a->prevInChain();
219 }
220 }
221 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
222 // tail of a.
223 if (!merged) {
224 chainA.pushTail(chainB.popHead());
225 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
226 }
227 } while (!chainB.empty());
228 return chainA;
229}
230
Chris Dalton945ee652019-01-23 09:10:36 -0700231// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
232// whether the operation succeeded. On success, the provided list will be returned empty.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400233bool GrOpsTask::OpChain::tryConcat(
John Stiles52cb1d02021-06-02 11:58:05 -0400234 List* list, GrProcessorSet::Analysis processorAnalysis, const GrDstProxyView& dstProxyView,
Chris Dalton945ee652019-01-23 09:10:36 -0700235 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600236 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700237 SkASSERT(!fList.empty());
238 SkASSERT(!list->empty());
Greg Daniel524e28b2019-11-01 11:48:53 -0400239 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy()));
240 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy()));
Brian Salomon588cec72018-11-14 13:56:37 -0500241 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700242 if (fList.head()->classID() != list->head()->classID() ||
243 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
244 (fAppliedClip && *fAppliedClip != *appliedClip) ||
Chris Dalton945ee652019-01-23 09:10:36 -0700245 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
246 processorAnalysis.requiresNonOverlappingDraws()) ||
247 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
248 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
249 // or read back a new dst texture between draws. In either case, we can neither
250 // chain nor combine overlapping Ops.
251 GrRectsTouchOrOverlap(fBounds, bounds)) ||
252 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
Greg Daniel524e28b2019-11-01 11:48:53 -0400253 (fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700254 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500255 }
Chris Daltonee21e6b2019-01-22 14:04:43 -0700256
Brian Salomon588cec72018-11-14 13:56:37 -0500257 SkDEBUGCODE(bool first = true;)
258 do {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600259 switch (fList.tail()->combineIfPossible(list->head(), opsTaskArena, caps))
Herb Derbye25c3002020-10-27 15:57:27 -0400260 {
Brian Salomon588cec72018-11-14 13:56:37 -0500261 case GrOp::CombineResult::kCannotCombine:
262 // If an op supports chaining then it is required that chaining is transitive and
263 // that if any two ops in two different chains can merge then the two chains
264 // may also be chained together. Thus, we should only hit this on the first
265 // iteration.
266 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700267 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500268 case GrOp::CombineResult::kMayChain:
Chris Daltonf8d75c62021-04-02 11:24:58 -0600269 fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500270 auditTrail);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700271 // The above exchange cleared out 'list'. The list needs to be empty now for the
272 // loop to terminate.
273 SkASSERT(list->empty());
274 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500275 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500276 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700277 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
278 list->head()->uniqueID());
279 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
Herb Derbyc76d4092020-10-07 16:46:15 -0400280 // The GrOp::Owner releases the op.
281 list->popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500282 break;
283 }
284 }
285 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700286 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700287
288 // The new ops were successfully merged and/or chained onto our own.
289 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700290 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500291}
292
Chris Daltonf8d75c62021-04-02 11:24:58 -0600293bool GrOpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, SkArenaAlloc* opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500294 GrAuditTrail* auditTrail) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400295 if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600296 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500297 this->validate();
298 // append failed
299 return false;
300 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700301
Brian Salomon588cec72018-11-14 13:56:37 -0500302 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700303 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500304 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700305 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500306
Greg Daniel524e28b2019-11-01 11:48:53 -0400307 that->fDstProxyView.setProxyView({});
John Stiles59e18dc2020-07-22 18:18:12 -0400308 if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) {
309 // Obliterates the processor.
310 that->fAppliedClip->detachCoverageFragmentProcessor();
Brian Salomon588cec72018-11-14 13:56:37 -0500311 }
312 this->validate();
313 return true;
314}
315
Herb Derbyc76d4092020-10-07 16:46:15 -0400316GrOp::Owner GrOpsTask::OpChain::appendOp(
317 GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
John Stiles52cb1d02021-06-02 11:58:05 -0400318 const GrDstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600319 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
John Stiles52cb1d02021-06-02 11:58:05 -0400320 const GrDstProxyView noDstProxyView;
Greg Daniel524e28b2019-11-01 11:48:53 -0400321 if (!dstProxyView) {
322 dstProxyView = &noDstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500323 }
324 SkASSERT(op->isChainHead() && op->isChainTail());
325 SkRect opBounds = op->bounds();
326 List chain(std::move(op));
Chris Daltonf8d75c62021-04-02 11:24:58 -0600327 if (!this->tryConcat(&chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps,
328 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500329 // append failed, give the op back to the caller.
330 this->validate();
331 return chain.popHead();
332 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700333
334 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500335 this->validate();
336 return nullptr;
337}
338
Greg Danielf41b2bd2019-08-22 16:19:24 -0400339inline void GrOpsTask::OpChain::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500340#ifdef SK_DEBUG
341 fList.validate();
342 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
343 // Not using SkRect::contains because we allow empty rects.
344 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
345 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
346 }
347#endif
348}
349
350////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800351
Brian Salomon982127b2021-01-21 10:43:35 -0500352GrOpsTask::GrOpsTask(GrDrawingManager* drawingMgr,
Greg Daniel16f5c652019-10-29 11:26:01 -0400353 GrSurfaceProxyView view,
Herb Derby0b1228d2021-04-05 18:38:35 -0400354 GrAuditTrail* auditTrail,
355 sk_sp<GrArenas> arenas)
Adlai Holler33d569e2020-06-16 14:30:08 -0400356 : GrRenderTask()
Greg Danielf41b2bd2019-08-22 16:19:24 -0400357 , fAuditTrail(auditTrail)
Chris Dalton2517ce32021-04-13 00:21:15 -0600358 , fUsesMSAASurface(view.asRenderTargetProxy()->numSamples() > 1)
Brian Salomon982127b2021-01-21 10:43:35 -0500359 , fTargetSwizzle(view.swizzle())
360 , fTargetOrigin(view.origin())
Herb Derby0b1228d2021-04-05 18:38:35 -0400361 , fArenas{std::move(arenas)}
Brian Salomon982127b2021-01-21 10:43:35 -0500362 SkDEBUGCODE(, fNumClips(0)) {
363 this->addTarget(drawingMgr, view.detachProxy());
bsalomon4061b122015-05-29 10:26:19 -0700364}
365
Greg Danielf41b2bd2019-08-22 16:19:24 -0400366void GrOpsTask::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500367 for (auto& chain : fOpChains) {
Herb Derbye32e1ab2020-10-27 10:29:46 -0400368 chain.deleteOps();
Robert Phillipsc994a932018-06-19 13:09:54 -0400369 }
Brian Salomon588cec72018-11-14 13:56:37 -0500370 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400371}
372
Greg Danielf41b2bd2019-08-22 16:19:24 -0400373GrOpsTask::~GrOpsTask() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400374 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000375}
376
Adlai Hollerabe45182020-11-17 09:22:13 -0500377void GrOpsTask::addOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
378 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
379 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
380 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
381 };
382
383 op->visitProxies(addDependency);
384
Chris Dalton83420eb2021-06-23 18:47:09 -0600385 this->recordOp(std::move(op), false/*usesMSAA*/, GrProcessorSet::EmptySetAnalysis(), nullptr,
386 nullptr, caps);
Adlai Hollerabe45182020-11-17 09:22:13 -0500387}
388
Chris Daltonb4403a92021-05-27 14:59:27 -0600389void GrOpsTask::addDrawOp(GrDrawingManager* drawingMgr, GrOp::Owner op, bool usesMSAA,
Chris Dalton710e1c92021-04-23 13:07:52 -0600390 const GrProcessorSet::Analysis& processorAnalysis, GrAppliedClip&& clip,
John Stiles52cb1d02021-06-02 11:58:05 -0400391 const GrDstProxyView& dstProxyView,
Adlai Hollerabe45182020-11-17 09:22:13 -0500392 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
393 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
394 this->addSampledTexture(p);
395 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
396 };
397
398 op->visitProxies(addDependency);
399 clip.visitProxies(addDependency);
400 if (dstProxyView.proxy()) {
Greg Daniel87fab9f2021-06-07 15:18:23 -0400401 if (!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment)) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500402 this->addSampledTexture(dstProxyView.proxy());
403 }
Greg Daniel87fab9f2021-06-07 15:18:23 -0400404 if (dstProxyView.dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500405 fRenderPassXferBarriers |= GrXferBarrierFlags::kTexture;
406 }
Greg Daniel87fab9f2021-06-07 15:18:23 -0400407 addDependency(dstProxyView.proxy(), GrMipmapped::kNo);
408 SkASSERT(!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment) ||
Adlai Hollerabe45182020-11-17 09:22:13 -0500409 dstProxyView.offset().isZero());
410 }
411
412 if (processorAnalysis.usesNonCoherentHWBlending()) {
413 fRenderPassXferBarriers |= GrXferBarrierFlags::kBlend;
414 }
415
Chris Dalton83420eb2021-06-23 18:47:09 -0600416 this->recordOp(std::move(op), usesMSAA, processorAnalysis, clip.doesClip() ? &clip : nullptr,
Adlai Hollerabe45182020-11-17 09:22:13 -0500417 &dstProxyView, caps);
418}
419
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400420void GrOpsTask::endFlush(GrDrawingManager* drawingMgr) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400421 fLastClipStackGenID = SK_InvalidUniqueID;
422 this->deleteOps();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700423
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500424 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400425 fSampledProxies.reset();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400426 fAuditTrail = nullptr;
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400427
428 GrRenderTask::endFlush(drawingMgr);
Greg Danielf21bf9e2019-08-22 20:12:20 +0000429}
430
Robert Phillips29f38542019-10-16 09:20:25 -0400431void GrOpsTask::onPrePrepare(GrRecordingContext* context) {
Robert Phillips7327c9d2019-10-08 16:32:56 -0400432 SkASSERT(this->isClosed());
Robert Phillips7327c9d2019-10-08 16:32:56 -0400433 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
434 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
435 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
436 // we shouldn't end up with GrOpsTasks with only discard.
Greg Daniel9a2d3d12021-06-23 22:36:06 +0000437 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
Robert Phillips7327c9d2019-10-08 16:32:56 -0400438 return;
439 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500440 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400441
Brian Salomon982127b2021-01-21 10:43:35 -0500442 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400443 for (const auto& chain : fOpChains) {
444 if (chain.shouldExecute()) {
Robert Phillips8053c972019-11-21 10:44:53 -0500445 chain.head()->prePrepare(context,
Brian Salomon982127b2021-01-21 10:43:35 -0500446 dstView,
Robert Phillips8053c972019-11-21 10:44:53 -0500447 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400448 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500449 fRenderPassXferBarriers,
450 fColorLoadOp);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400451 }
452 }
453}
454
Greg Danielf41b2bd2019-08-22 16:19:24 -0400455void GrOpsTask::onPrepare(GrOpFlushState* flushState) {
Brian Salomon982127b2021-01-21 10:43:35 -0500456 SkASSERT(this->target(0)->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400457 SkASSERT(this->isClosed());
Greg Daniel94ed83f2019-09-27 13:05:43 -0400458 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
459 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
460 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
461 // we shouldn't end up with GrOpsTasks with only discard.
Greg Daniel9a2d3d12021-06-23 22:36:06 +0000462 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
Greg Daniel94ed83f2019-09-27 13:05:43 -0400463 return;
464 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500465 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
robertphillipsa106c622015-10-16 09:07:06 -0700466
Greg Danielb20d7e52019-09-03 13:54:39 -0400467 flushState->setSampledProxyArray(&fSampledProxies);
Brian Salomon982127b2021-01-21 10:43:35 -0500468 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500469 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500470 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400471 if (chain.shouldExecute()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400472#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400473 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400474#endif
Robert Phillips901aff02019-10-08 12:32:56 -0400475 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500476 dstView,
Chris Dalton2517ce32021-04-13 00:21:15 -0600477 fUsesMSAASurface,
Robert Phillips901aff02019-10-08 12:32:56 -0400478 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400479 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500480 fRenderPassXferBarriers,
481 fColorLoadOp);
Robert Phillips405413f2019-10-04 10:39:28 -0400482
Brian Salomon29b60c92017-10-31 14:42:10 -0400483 flushState->setOpArgs(&opArgs);
Robert Phillipsdf70f152019-11-15 14:57:05 -0500484
485 // Temporary debugging helper: for debugging prePrepare w/o going through DDLs
486 // Delete once most of the GrOps have an onPrePrepare.
Adlai Holler33d569e2020-06-16 14:30:08 -0400487 // chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0),
Robert Phillipsdf70f152019-11-15 14:57:05 -0500488 // chain.appliedClip());
489
Robert Phillips7327c9d2019-10-08 16:32:56 -0400490 // GrOp::prePrepare may or may not have been called at this point
Brian Salomon588cec72018-11-14 13:56:37 -0500491 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400492 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800493 }
bsalomon512be532015-09-10 10:42:55 -0700494 }
Greg Danielb20d7e52019-09-03 13:54:39 -0400495 flushState->setSampledProxyArray(nullptr);
robertphillipsa13e2022015-11-11 12:01:09 -0800496}
bsalomon512be532015-09-10 10:42:55 -0700497
Greg Danielc0d69152020-10-08 14:59:00 -0400498static GrOpsRenderPass* create_render_pass(GrGpu* gpu,
499 GrRenderTarget* rt,
Chris Daltonda2b0f42021-04-13 00:19:45 -0600500 bool useMSAASurface,
Greg Danielc0d69152020-10-08 14:59:00 -0400501 GrAttachment* stencil,
502 GrSurfaceOrigin origin,
503 const SkIRect& bounds,
504 GrLoadOp colorLoadOp,
Brian Salomon07bc9a22020-12-02 13:37:16 -0500505 const std::array<float, 4>& loadClearColor,
Greg Danielc0d69152020-10-08 14:59:00 -0400506 GrLoadOp stencilLoadOp,
507 GrStoreOp stencilStoreOp,
508 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
509 GrXferBarrierFlags renderPassXferBarriers) {
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400510 const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400511 colorLoadOp,
512 GrStoreOp::kStore,
513 loadClearColor
Robert Phillips178ce3e2017-04-13 09:15:47 -0400514 };
515
Robert Phillips95214472017-08-08 18:00:03 -0400516 // TODO:
517 // We would like to (at this level) only ever clear & discard. We would need
Greg Danielf41b2bd2019-08-22 16:19:24 -0400518 // to stop splitting up higher level OpsTasks for copyOps to achieve that.
Robert Phillips95214472017-08-08 18:00:03 -0400519 // Note: we would still need SB loads and stores but they would happen at a
520 // lower level (inside the VK command buffer).
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400521 const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400522 stencilLoadOp,
Chris Dalton674f77a2019-09-30 20:49:39 -0600523 stencilStoreOp,
Robert Phillips95214472017-08-08 18:00:03 -0400524 };
525
Chris Daltonda2b0f42021-04-13 00:19:45 -0600526 return gpu->getOpsRenderPass(rt, useMSAASurface, stencil, origin, bounds, kColorLoadStoreInfo,
527 stencilLoadAndStoreInfo, sampledProxies, renderPassXferBarriers);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400528}
529
Brian Salomon25a88092016-12-01 09:36:50 -0500530// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500531// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500532// Ops and instantiate them here.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400533bool GrOpsTask::onExecute(GrOpFlushState* flushState) {
Herb Derby93250092021-04-06 12:19:20 -0400534 SkASSERT(this->numTargets() == 1);
535 GrRenderTargetProxy* proxy = this->target(0)->asRenderTargetProxy();
536 SkASSERT(proxy);
537 SK_AT_SCOPE_EXIT(proxy->clearArenas());
538
Greg Daniel94ed83f2019-09-27 13:05:43 -0400539 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
540 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
541 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
542 // we shouldn't end up with GrOpsTasks with only discard.
Greg Daniel9a2d3d12021-06-23 22:36:06 +0000543 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
bsalomondc438982016-08-31 11:53:49 -0700544 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700545 }
Robert Phillips4a395042017-04-24 16:27:17 +0000546
Brian Salomon5f394272019-07-02 14:07:49 -0400547 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400548
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500549 // Make sure load ops are not kClear if the GPU needs to use draws for clears
550 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
551 !flushState->gpu()->caps()->performColorClearsAsDraws());
Chris Dalton674f77a2019-09-30 20:49:39 -0600552
553 const GrCaps& caps = *flushState->gpu()->caps();
Greg Daniel16f5c652019-10-29 11:26:01 -0400554 GrRenderTarget* renderTarget = proxy->peekRenderTarget();
Chris Dalton674f77a2019-09-30 20:49:39 -0600555 SkASSERT(renderTarget);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700556
Greg Danielc0d69152020-10-08 14:59:00 -0400557 GrAttachment* stencil = nullptr;
Chris Dalton57ab06c2021-04-22 12:57:28 -0600558 if (proxy->needsStencil()) {
Chris Dalton537293bf2021-05-03 15:54:24 -0600559 SkASSERT(proxy->canUseStencil(caps));
Chris Daltone0fe23a2021-04-23 13:11:44 -0600560 if (!flushState->resourceProvider()->attachStencilAttachment(renderTarget,
561 fUsesMSAASurface)) {
Chris Dalton0b68dda2019-11-07 21:08:03 -0700562 SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n");
563 return false;
564 }
Chris Daltone0fe23a2021-04-23 13:11:44 -0600565 stencil = renderTarget->getStencilAttachment(fUsesMSAASurface);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700566 }
567
Chris Dalton674f77a2019-09-30 20:49:39 -0600568 GrLoadOp stencilLoadOp;
569 switch (fInitialStencilContent) {
570 case StencilContent::kDontCare:
571 stencilLoadOp = GrLoadOp::kDiscard;
572 break;
573 case StencilContent::kUserBitsCleared:
574 SkASSERT(!caps.performStencilClearsAsDraws());
575 SkASSERT(stencil);
576 if (caps.discardStencilValuesAfterRenderPass()) {
577 // Always clear the stencil if it is being discarded after render passes. This is
578 // also an optimization because we are on a tiler and it avoids loading the values
579 // from memory.
580 stencilLoadOp = GrLoadOp::kClear;
581 break;
582 }
583 if (!stencil->hasPerformedInitialClear()) {
584 stencilLoadOp = GrLoadOp::kClear;
585 stencil->markHasPerformedInitialClear();
586 break;
587 }
John Stiles0fbc6a32021-06-04 14:40:57 -0400588 // SurfaceDrawContexts are required to leave the user stencil bits in a cleared state
Chris Dalton674f77a2019-09-30 20:49:39 -0600589 // once finished, meaning the stencil values will always remain cleared after the
590 // initial clear. Just fall through to reloading the existing (cleared) stencil values
591 // from memory.
John Stiles30212b72020-06-11 17:55:07 -0400592 [[fallthrough]];
Chris Dalton674f77a2019-09-30 20:49:39 -0600593 case StencilContent::kPreserved:
594 SkASSERT(stencil);
595 stencilLoadOp = GrLoadOp::kLoad;
596 break;
597 }
598
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500599 // NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split
Chris Dalton674f77a2019-09-30 20:49:39 -0600600 // its opsTask.
601 //
602 // FIXME: We don't currently flag render passes that don't use stencil at all. In that case
603 // their store op might be "discard", and we currently make the assumption that a discard will
604 // not invalidate what's already in main memory. This is probably ok for now, but certainly
605 // something we want to address soon.
606 GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil)
607 ? GrStoreOp::kDiscard
608 : GrStoreOp::kStore;
609
Brian Salomon982127b2021-01-21 10:43:35 -0500610 GrOpsRenderPass* renderPass = create_render_pass(flushState->gpu(),
611 proxy->peekRenderTarget(),
Chris Dalton2517ce32021-04-13 00:21:15 -0600612 fUsesMSAASurface,
Brian Salomon982127b2021-01-21 10:43:35 -0500613 stencil,
614 fTargetOrigin,
615 fClippedContentBounds,
616 fColorLoadOp,
617 fLoadClearColor,
618 stencilLoadOp,
619 stencilStoreOp,
620 fSampledProxies,
621 fRenderPassXferBarriers);
Greg Daniel21774362020-09-14 10:36:43 -0400622
Greg Danielfa3adf72019-11-07 09:53:41 -0500623 if (!renderPass) {
624 return false;
625 }
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400626 flushState->setOpsRenderPass(renderPass);
627 renderPass->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400628
Brian Salomon982127b2021-01-21 10:43:35 -0500629 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
630
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400631 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500632 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400633 if (!chain.shouldExecute()) {
bsalomonaecc0182016-03-07 11:50:44 -0800634 continue;
635 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400636#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400637 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400638#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400639
Robert Phillips405413f2019-10-04 10:39:28 -0400640 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500641 dstView,
Chris Dalton2517ce32021-04-13 00:21:15 -0600642 fUsesMSAASurface,
Robert Phillips405413f2019-10-04 10:39:28 -0400643 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400644 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500645 fRenderPassXferBarriers,
646 fColorLoadOp);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400647
Brian Salomon29b60c92017-10-31 14:42:10 -0400648 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500649 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400650 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700651 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400652
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400653 renderPass->end();
654 flushState->gpu()->submit(renderPass);
655 flushState->setOpsRenderPass(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800656
bsalomondc438982016-08-31 11:53:49 -0700657 return true;
bsalomona73239a2015-04-28 13:35:17 -0700658}
659
Brian Salomon07bc9a22020-12-02 13:37:16 -0500660void GrOpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500661 fColorLoadOp = op;
662 fLoadClearColor = color;
Chris Dalton16a33c62019-09-24 22:19:17 -0600663 if (GrLoadOp::kClear == fColorLoadOp) {
Brian Salomon982127b2021-01-21 10:43:35 -0500664 GrSurfaceProxy* proxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400665 SkASSERT(proxy);
Michael Ludwigd1d997e2020-06-04 15:52:44 -0400666 fTotalBounds = proxy->backingStoreBoundsRect();
Chris Dalton16a33c62019-09-24 22:19:17 -0600667 }
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500668}
669
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500670void GrOpsTask::reset() {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500671 fDeferredProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500672 fSampledProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500673 fClippedContentBounds = SkIRect::MakeEmpty();
674 fTotalBounds = SkRect::MakeEmpty();
Adlai Holler026851a2021-03-29 14:47:11 -0400675 this->deleteOps();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500676 fRenderPassXferBarriers = GrXferBarrierFlags::kNone;
677}
678
Adlai Holler93439d92021-01-26 09:20:39 -0500679int GrOpsTask::mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks) {
Adlai Holler93439d92021-01-26 09:20:39 -0500680 int mergedCount = 0;
681 for (const sk_sp<GrRenderTask>& task : tasks) {
682 auto opsTask = task->asOpsTask();
Greg Daniel9a2d3d12021-06-23 22:36:06 +0000683 if (!opsTask || opsTask->target(0) != this->target(0)
684 || this->fArenas != opsTask->fArenas) {
Adlai Holler93439d92021-01-26 09:20:39 -0500685 break;
686 }
687 SkASSERT(fTargetSwizzle == opsTask->fTargetSwizzle);
688 SkASSERT(fTargetOrigin == opsTask->fTargetOrigin);
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500689 if (GrLoadOp::kClear == opsTask->fColorLoadOp) {
Adlai Hollerb0ada772021-04-23 17:02:24 -0400690 // TODO(11903): Go back to actually dropping ops tasks when we are merged with
691 // color clear.
692 return 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500693 }
Adlai Holler93439d92021-01-26 09:20:39 -0500694 mergedCount += 1;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500695 }
696 if (0 == mergedCount) {
697 return 0;
698 }
699
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400700 SkSpan<const sk_sp<GrOpsTask>> mergingNodes(
Herb Derby93250092021-04-06 12:19:20 -0400701 reinterpret_cast<const sk_sp<GrOpsTask>*>(tasks.data()), SkToSizeT(mergedCount));
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500702 int addlDeferredProxyCount = 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500703 int addlProxyCount = 0;
704 int addlOpChainCount = 0;
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400705 for (const auto& toMerge : mergingNodes) {
706 addlDeferredProxyCount += toMerge->fDeferredProxies.count();
707 addlProxyCount += toMerge->fSampledProxies.count();
708 addlOpChainCount += toMerge->fOpChains.count();
709 fClippedContentBounds.join(toMerge->fClippedContentBounds);
710 fTotalBounds.join(toMerge->fTotalBounds);
711 fRenderPassXferBarriers |= toMerge->fRenderPassXferBarriers;
Chris Daltonffbeda72021-05-05 09:55:47 -0600712 if (fInitialStencilContent == StencilContent::kDontCare) {
713 // Propogate the first stencil content that isn't kDontCare.
714 //
715 // Once the stencil has any kind of initial content that isn't kDontCare, then the
716 // inital contents of subsequent opsTasks that get merged in don't matter.
717 //
718 // (This works because the opsTask all target the same render target and are in
719 // painter's order. kPreserved obviously happens automatically with a merge, and kClear
720 // is also automatic because the contract is for ops to leave the stencil buffer in a
721 // cleared state when finished.)
722 fInitialStencilContent = toMerge->fInitialStencilContent;
723 }
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400724 fUsesMSAASurface |= toMerge->fUsesMSAASurface;
725 SkDEBUGCODE(fNumClips += toMerge->fNumClips);
Adlai Holler93439d92021-01-26 09:20:39 -0500726 }
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500727
Adlai Holler93439d92021-01-26 09:20:39 -0500728 fLastClipStackGenID = SK_InvalidUniqueID;
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500729 fDeferredProxies.reserve_back(addlDeferredProxyCount);
Adlai Holler93439d92021-01-26 09:20:39 -0500730 fSampledProxies.reserve_back(addlProxyCount);
731 fOpChains.reserve_back(addlOpChainCount);
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400732 for (const auto& toMerge : mergingNodes) {
733 for (GrRenderTask* renderTask : toMerge->dependents()) {
734 renderTask->replaceDependency(toMerge.get(), this);
735 }
736 for (GrRenderTask* renderTask : toMerge->dependencies()) {
737 renderTask->replaceDependent(toMerge.get(), this);
738 }
739 fDeferredProxies.move_back_n(toMerge->fDeferredProxies.count(),
740 toMerge->fDeferredProxies.data());
741 fSampledProxies.move_back_n(toMerge->fSampledProxies.count(),
742 toMerge->fSampledProxies.data());
743 fOpChains.move_back_n(toMerge->fOpChains.count(),
744 toMerge->fOpChains.data());
745 toMerge->fDeferredProxies.reset();
746 toMerge->fSampledProxies.reset();
747 toMerge->fOpChains.reset();
Adlai Holler93439d92021-01-26 09:20:39 -0500748 }
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400749 fMustPreserveStencil = mergingNodes.back()->fMustPreserveStencil;
Adlai Holler93439d92021-01-26 09:20:39 -0500750 return mergedCount;
751}
752
Greg Danielf41b2bd2019-08-22 16:19:24 -0400753bool GrOpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
Chris Dalton6b982802019-06-27 13:53:46 -0600754 if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400755 this->deleteOps();
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500756 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400757 fSampledProxies.reset();
Greg Daniel070cbaf2019-01-03 17:35:54 -0500758
Greg Danielf41b2bd2019-08-22 16:19:24 -0400759 // If the opsTask is using a render target which wraps a vulkan command buffer, we can't do
760 // a clear load since we cannot change the render pass that we are using. Thus we fall back
761 // to making a clear op in this case.
Brian Salomon982127b2021-01-21 10:43:35 -0500762 return !this->target(0)->asRenderTargetProxy()->wrapsVkSecondaryCB();
bsalomonfd8d0132016-08-11 11:25:33 -0700763 }
Robert Phillips380b90c2017-08-30 07:41:07 -0400764
Greg Danielf41b2bd2019-08-22 16:19:24 -0400765 // Could not empty the task, so an op must be added to handle the clear
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500766 return false;
bsalomon9f129de2016-08-10 16:31:05 -0700767}
768
Greg Danielf41b2bd2019-08-22 16:19:24 -0400769void GrOpsTask::discard() {
770 // Discard calls to in-progress opsTasks are ignored. Calls at the start update the
771 // opsTasks' color & stencil load ops.
772 if (this->isEmpty()) {
773 fColorLoadOp = GrLoadOp::kDiscard;
Chris Dalton674f77a2019-09-30 20:49:39 -0600774 fInitialStencilContent = StencilContent::kDontCare;
Chris Dalton16a33c62019-09-24 22:19:17 -0600775 fTotalBounds.setEmpty();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400776 }
777}
778
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000779////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000780
John Stiles1e0136e2020-08-12 18:44:00 -0400781#if GR_TEST_UTILS
Robert Phillips047d5bb2021-01-08 13:39:19 -0500782void GrOpsTask::dump(const SkString& label,
783 SkString indent,
784 bool printDependencies,
785 bool close) const {
786 GrRenderTask::dump(label, indent, printDependencies, false);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400787
Robert Phillips047d5bb2021-01-08 13:39:19 -0500788 SkDebugf("%sfColorLoadOp: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600789 switch (fColorLoadOp) {
790 case GrLoadOp::kLoad:
791 SkDebugf("kLoad\n");
792 break;
793 case GrLoadOp::kClear:
Brian Salomon07bc9a22020-12-02 13:37:16 -0500794 SkDebugf("kClear {%g, %g, %g, %g}\n",
795 fLoadClearColor[0],
796 fLoadClearColor[1],
797 fLoadClearColor[2],
798 fLoadClearColor[3]);
Chris Dalton674f77a2019-09-30 20:49:39 -0600799 break;
800 case GrLoadOp::kDiscard:
801 SkDebugf("kDiscard\n");
802 break;
803 }
804
Robert Phillips047d5bb2021-01-08 13:39:19 -0500805 SkDebugf("%sfInitialStencilContent: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600806 switch (fInitialStencilContent) {
807 case StencilContent::kDontCare:
808 SkDebugf("kDontCare\n");
809 break;
810 case StencilContent::kUserBitsCleared:
811 SkDebugf("kUserBitsCleared\n");
812 break;
813 case StencilContent::kPreserved:
814 SkDebugf("kPreserved\n");
815 break;
816 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400817
Robert Phillips047d5bb2021-01-08 13:39:19 -0500818 SkDebugf("%s%d ops:\n", indent.c_str(), fOpChains.count());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400819 for (int i = 0; i < fOpChains.count(); ++i) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500820 SkDebugf("%s*******************************\n", indent.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400821 if (!fOpChains[i].head()) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500822 SkDebugf("%s%d: <combined forward or failed instantiation>\n", indent.c_str(), i);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400823 } else {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500824 SkDebugf("%s%d: %s\n", indent.c_str(), i, fOpChains[i].head()->name());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400825 SkRect bounds = fOpChains[i].bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500826 SkDebugf("%sClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
827 indent.c_str(),
828 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400829 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
830 SkString info = SkTabString(op.dumpInfo(), 1);
Robert Phillips047d5bb2021-01-08 13:39:19 -0500831 SkDebugf("%s%s\n", indent.c_str(), info.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400832 bounds = op.bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500833 SkDebugf("%s\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
834 indent.c_str(),
835 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400836 }
837 }
838 }
Robert Phillips047d5bb2021-01-08 13:39:19 -0500839
840 if (close) {
841 SkDebugf("%s--------------------------------------------------------------\n\n",
842 indent.c_str());
843 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400844}
John Stiles1e0136e2020-08-12 18:44:00 -0400845#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400846
John Stiles1e0136e2020-08-12 18:44:00 -0400847#ifdef SK_DEBUG
Robert Phillips294723d2021-06-17 09:23:58 -0400848void GrOpsTask::visitProxies_debugOnly(const GrVisitProxyFunc& func) const {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400849 auto textureFunc = [ func ] (GrSurfaceProxy* tex, GrMipmapped mipmapped) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400850 func(tex, mipmapped);
851 };
852
Greg Danielf41b2bd2019-08-22 16:19:24 -0400853 for (const OpChain& chain : fOpChains) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400854 chain.visitProxies(textureFunc);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400855 }
856}
857
858#endif
859
860////////////////////////////////////////////////////////////////////////////////
861
Adlai Hollere9ea4142021-04-27 14:31:56 -0400862void GrOpsTask::onMakeSkippable() {
Brian Salomond63638b2021-03-05 14:00:07 -0500863 this->deleteOps();
864 fDeferredProxies.reset();
865 fColorLoadOp = GrLoadOp::kLoad;
Greg Daniel9a2d3d12021-06-23 22:36:06 +0000866 SkASSERT(this->isNoOp());
Brian Salomond63638b2021-03-05 14:00:07 -0500867}
868
Greg Danielf41b2bd2019-08-22 16:19:24 -0400869bool GrOpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
870 bool used = false;
Adlai Holler304f6532021-05-17 13:26:46 -0400871 for (GrSurfaceProxy* proxy : fSampledProxies) {
872 if (proxy == proxyToCheck) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400873 used = true;
Adlai Holler304f6532021-05-17 13:26:46 -0400874 break;
875 }
876 }
877#ifdef SK_DEBUG
878 bool usedSlow = false;
879 auto visit = [ proxyToCheck, &usedSlow ] (GrSurfaceProxy* p, GrMipmapped) {
880 if (p == proxyToCheck) {
881 usedSlow = true;
Greg Danielf41b2bd2019-08-22 16:19:24 -0400882 }
883 };
Adlai Holler304f6532021-05-17 13:26:46 -0400884 this->visitProxies_debugOnly(visit);
885 SkASSERT(used == usedSlow);
886#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400887
888 return used;
889}
890
Greg Danielf41b2bd2019-08-22 16:19:24 -0400891void GrOpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Adlai Hollerc17a3e92021-04-27 14:34:28 -0400892 SkASSERT(this->isClosed());
Greg Daniel9a2d3d12021-06-23 22:36:06 +0000893 if (this->isNoOp()) {
Adlai Hollerc17a3e92021-04-27 14:34:28 -0400894 return;
895 }
896
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500897 for (int i = 0; i < fDeferredProxies.count(); ++i) {
898 SkASSERT(!fDeferredProxies[i]->isInstantiated());
899 // We give all the deferred proxies a write usage at the very start of flushing. This
900 // locks them out of being reused for the entire flush until they are read - and then
901 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
902 // with sub-flushes. The deferred proxies only need to be pinned from the start of
903 // the sub-flush in which they appear.
904 alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo);
905 }
906
Brian Salomon982127b2021-01-21 10:43:35 -0500907 GrSurfaceProxy* targetProxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400908
Greg Danielf41b2bd2019-08-22 16:19:24 -0400909 // Add the interval for all the writes to this GrOpsTasks's target
Brian Salomon588cec72018-11-14 13:56:37 -0500910 if (fOpChains.count()) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400911 unsigned int cur = alloc->curOp();
912
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000913 alloc->addInterval(targetProxy, cur, cur + fOpChains.count() - 1,
914 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500915 } else {
916 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
917 // still need to add an interval for the destination so we create a fake op# for
918 // the missing clear op.
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000919 alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(),
920 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500921 alloc->incOps();
922 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400923
Brian Salomon7e67dca2020-07-21 09:27:25 -0400924 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipmapped) {
Brian Salomon982127b2021-01-21 10:43:35 -0500925 alloc->addInterval(p,
926 alloc->curOp(),
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000927 alloc->curOp(),
928 GrResourceAllocator::ActualUse::kYes
Brian Salomon982127b2021-01-21 10:43:35 -0500929 SkDEBUGCODE(, this->target(0) == p));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400930 };
Adlai Holler304f6532021-05-17 13:26:46 -0400931 // TODO: visitProxies is expensive. Can we do this with fSampledProxies instead?
Brian Salomon588cec72018-11-14 13:56:37 -0500932 for (const OpChain& recordedOp : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600933 recordedOp.visitProxies(gather);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500934
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400935 // 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 -0500936 // keep all the math consistent.
937 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400938 }
939}
940
Greg Danielf41b2bd2019-08-22 16:19:24 -0400941void GrOpsTask::recordOp(
Chris Dalton83420eb2021-06-23 18:47:09 -0600942 GrOp::Owner op, bool usesMSAA, GrProcessorSet::Analysis processorAnalysis,
943 GrAppliedClip* clip, const GrDstProxyView* dstProxyView, const GrCaps& caps) {
Brian Salomon982127b2021-01-21 10:43:35 -0500944 GrSurfaceProxy* proxy = this->target(0);
Chris Dalton83420eb2021-06-23 18:47:09 -0600945#ifdef SK_DEBUG
946 op->validate();
947 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy()));
Greg Daniel16f5c652019-10-29 11:26:01 -0400948 SkASSERT(proxy);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400949 // A closed GrOpsTask should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700950 SkASSERT(!this->isClosed());
Chris Dalton83420eb2021-06-23 18:47:09 -0600951 // Ensure we can support dynamic msaa if the caller is trying to trigger it.
952 if (proxy->asRenderTargetProxy()->numSamples() == 1 && usesMSAA) {
953 SkASSERT(caps.supportsDynamicMSAA(proxy->asRenderTargetProxy()));
954 }
955#endif
956
Brian Salomon19ec80f2018-11-16 13:27:30 -0500957 if (!op->bounds().isFinite()) {
Brian Salomon19ec80f2018-11-16 13:27:30 -0500958 return;
959 }
robertphillipsa106c622015-10-16 09:07:06 -0700960
Chris Dalton83420eb2021-06-23 18:47:09 -0600961 fUsesMSAASurface |= usesMSAA;
962
Chris Dalton16a33c62019-09-24 22:19:17 -0600963 // Account for this op's bounds before we attempt to combine.
964 // NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable.
965 fTotalBounds.join(op->bounds());
966
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500967 // Check if there is an op we can combine with by linearly searching back until we either
968 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700969 // 2) intersect with something
970 // 3) find a 'blocker'
Greg Daniel16f5c652019-10-29 11:26:01 -0400971 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400972 GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n"
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400973 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
974 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500975 op->name(),
976 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400977 op->bounds().fLeft, op->bounds().fTop,
978 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500979 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500980 GrOP_INFO("\tOutcome:\n");
Brian Osman788b9162020-02-07 10:36:46 -0500981 int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.count());
Robert Phillips318c4192017-05-17 09:36:38 -0400982 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700983 int i = 0;
984 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500985 OpChain& candidate = fOpChains.fromBack(i);
Greg Daniel524e28b2019-11-01 11:48:53 -0400986 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps,
Herb Derby93250092021-04-06 12:19:20 -0400987 fArenas->arenaAlloc(), fAuditTrail);
Brian Salomon588cec72018-11-14 13:56:37 -0500988 if (!op) {
989 return;
bsalomon512be532015-09-10 10:42:55 -0700990 }
Brian Salomona7682c82018-10-24 10:04:37 -0400991 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -0500992 if (!can_reorder(candidate.bounds(), op->bounds())) {
993 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
994 candidate.head()->name(), candidate.head()->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700995 break;
996 }
Brian Salomon588cec72018-11-14 13:56:37 -0500997 if (++i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400998 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -0700999 break;
1000 }
1001 }
1002 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001003 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -07001004 }
Brian Salomon54d212e2017-03-21 14:22:38 -04001005 if (clip) {
Herb Derby93250092021-04-06 12:19:20 -04001006 clip = fArenas->arenaAlloc()->make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -04001007 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -04001008 }
Greg Daniel524e28b2019-11-01 11:48:53 -04001009 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView);
bsalomon512be532015-09-10 10:42:55 -07001010}
1011
Greg Danielf41b2bd2019-08-22 16:19:24 -04001012void GrOpsTask::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001013 SkASSERT(!this->isClosed());
Greg Danielf41b2bd2019-08-22 16:19:24 -04001014 GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
Robert Phillips48567ac2017-06-01 08:46:00 -04001015
Brian Salomon588cec72018-11-14 13:56:37 -05001016 for (int i = 0; i < fOpChains.count() - 1; ++i) {
1017 OpChain& chain = fOpChains[i];
Brian Osman788b9162020-02-07 10:36:46 -05001018 int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -08001019 int j = i + 1;
1020 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -05001021 OpChain& candidate = fOpChains[j];
Herb Derby93250092021-04-06 12:19:20 -04001022 if (candidate.prependChain(&chain, caps, fArenas->arenaAlloc(), fAuditTrail)) {
bsalomonaecc0182016-03-07 11:50:44 -08001023 break;
1024 }
Robert Phillipsc84c0302017-05-08 15:35:11 -04001025 // Stop traversing if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -05001026 if (!can_reorder(chain.bounds(), candidate.bounds())) {
1027 GrOP_INFO(
1028 "\t\t%d: chain (%s head opID: %u) -> "
1029 "Intersects with chain (%s, head opID: %u)\n",
1030 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
1031 candidate.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001032 break;
1033 }
Brian Salomona7682c82018-10-24 10:04:37 -04001034 if (++j > maxCandidateIdx) {
Brian Salomon588cec72018-11-14 13:56:37 -05001035 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
1036 i, chain.head()->name(), chain.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001037 break;
1038 }
1039 }
1040 }
1041}
1042
Chris Daltonaa938ce2021-06-23 18:13:59 -06001043GrRenderTask::ExpectedOutcome GrOpsTask::onMakeClosed(GrRecordingContext* rContext,
Robert Phillips07f675d2020-11-16 13:44:01 -05001044 SkIRect* targetUpdateBounds) {
Chris Daltonaa938ce2021-06-23 18:13:59 -06001045 this->forwardCombine(*rContext->priv().caps());
Greg Daniel9a2d3d12021-06-23 22:36:06 +00001046 if (!this->isNoOp()) {
Brian Salomon982127b2021-01-21 10:43:35 -05001047 GrSurfaceProxy* proxy = this->target(0);
Michael Ludwigd1d997e2020-06-04 15:52:44 -04001048 // Use the entire backing store bounds since the GPU doesn't clip automatically to the
1049 // logical dimensions.
1050 SkRect clippedContentBounds = proxy->backingStoreBoundsRect();
Adlai Holler33d569e2020-06-16 14:30:08 -04001051 // TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds
Greg Daniel16f5c652019-10-29 11:26:01 -04001052 // then we can simply assert here that the bounds intersect.
Chris Dalton16a33c62019-09-24 22:19:17 -06001053 if (clippedContentBounds.intersect(fTotalBounds)) {
Greg Daniel94ed83f2019-09-27 13:05:43 -04001054 clippedContentBounds.roundOut(&fClippedContentBounds);
Brian Salomon982127b2021-01-21 10:43:35 -05001055 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
1056 fTargetOrigin,
1057 this->target(0)->backingStoreDimensions().height(),
1058 fClippedContentBounds);
Chris Dalton16a33c62019-09-24 22:19:17 -06001059 return ExpectedOutcome::kTargetDirty;
1060 }
1061 }
1062 return ExpectedOutcome::kTargetUnchanged;
1063}