blob: 689a6a169f9da710316e8f067bf28aa7e2a47626 [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"
Robert Phillips1a82a4e2021-07-01 10:27:44 -040024#include "src/gpu/GrResourceProvider.h"
Brian Salomoneebe7352020-12-09 16:37:04 -050025#include "src/gpu/GrSurfaceDrawContext.h"
Brian Salomon4cfae3b2020-07-23 10:33:24 -040026#include "src/gpu/GrTexture.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040027#include "src/gpu/geometry/GrRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050028#include "src/gpu/ops/GrClearOp.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040029
reed@google.comac10a2d2010-12-22 21:39:39 +000030////////////////////////////////////////////////////////////////////////////////
31
Brian Salomon09d994e2016-12-21 11:14:46 -050032// Experimentally we have found that most combining occurs within the first 10 comparisons.
Brian Salomon588cec72018-11-14 13:56:37 -050033static const int kMaxOpMergeDistance = 10;
34static const int kMaxOpChainDistance = 10;
35
36////////////////////////////////////////////////////////////////////////////////
37
Brian Salomon588cec72018-11-14 13:56:37 -050038static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
39
40////////////////////////////////////////////////////////////////////////////////
41
Herb Derbyc76d4092020-10-07 16:46:15 -040042inline GrOpsTask::OpChain::List::List(GrOp::Owner op)
Brian Salomon588cec72018-11-14 13:56:37 -050043 : fHead(std::move(op)), fTail(fHead.get()) {
44 this->validate();
45}
46
Greg Danielf41b2bd2019-08-22 16:19:24 -040047inline GrOpsTask::OpChain::List::List(List&& that) { *this = std::move(that); }
Brian Salomon588cec72018-11-14 13:56:37 -050048
Greg Danielf41b2bd2019-08-22 16:19:24 -040049inline GrOpsTask::OpChain::List& GrOpsTask::OpChain::List::operator=(List&& that) {
Brian Salomon588cec72018-11-14 13:56:37 -050050 fHead = std::move(that.fHead);
51 fTail = that.fTail;
52 that.fTail = nullptr;
53 this->validate();
54 return *this;
55}
56
Herb Derbyc76d4092020-10-07 16:46:15 -040057inline GrOp::Owner GrOpsTask::OpChain::List::popHead() {
Brian Salomon588cec72018-11-14 13:56:37 -050058 SkASSERT(fHead);
59 auto temp = fHead->cutChain();
60 std::swap(temp, fHead);
61 if (!fHead) {
62 SkASSERT(fTail == temp.get());
63 fTail = nullptr;
64 }
65 return temp;
66}
67
Herb Derbyc76d4092020-10-07 16:46:15 -040068inline GrOp::Owner GrOpsTask::OpChain::List::removeOp(GrOp* op) {
Brian Salomon588cec72018-11-14 13:56:37 -050069#ifdef SK_DEBUG
70 auto head = op;
71 while (head->prevInChain()) { head = head->prevInChain(); }
72 SkASSERT(head == fHead.get());
73#endif
74 auto prev = op->prevInChain();
75 if (!prev) {
76 SkASSERT(op == fHead.get());
77 return this->popHead();
78 }
79 auto temp = prev->cutChain();
80 if (auto next = temp->cutChain()) {
81 prev->chainConcat(std::move(next));
82 } else {
83 SkASSERT(fTail == op);
84 fTail = prev;
85 }
86 this->validate();
87 return temp;
88}
89
Herb Derbyc76d4092020-10-07 16:46:15 -040090inline void GrOpsTask::OpChain::List::pushHead(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -050091 SkASSERT(op);
92 SkASSERT(op->isChainHead());
93 SkASSERT(op->isChainTail());
94 if (fHead) {
95 op->chainConcat(std::move(fHead));
96 fHead = std::move(op);
97 } else {
98 fHead = std::move(op);
99 fTail = fHead.get();
100 }
101}
102
Herb Derbyc76d4092020-10-07 16:46:15 -0400103inline void GrOpsTask::OpChain::List::pushTail(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -0500104 SkASSERT(op->isChainTail());
105 fTail->chainConcat(std::move(op));
106 fTail = fTail->nextInChain();
107}
108
Greg Danielf41b2bd2019-08-22 16:19:24 -0400109inline void GrOpsTask::OpChain::List::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500110#ifdef SK_DEBUG
111 if (fHead) {
112 SkASSERT(fTail);
113 fHead->validateChain(fTail);
114 }
115#endif
116}
117
118////////////////////////////////////////////////////////////////////////////////
119
John Stiles52cb1d02021-06-02 11:58:05 -0400120GrOpsTask::OpChain::OpChain(GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
121 GrAppliedClip* appliedClip, const GrDstProxyView* dstProxyView)
Chris Dalton945ee652019-01-23 09:10:36 -0700122 : fList{std::move(op)}
123 , fProcessorAnalysis(processorAnalysis)
124 , fAppliedClip(appliedClip) {
125 if (fProcessorAnalysis.requiresDstTexture()) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400126 SkASSERT(dstProxyView && dstProxyView->proxy());
127 fDstProxyView = *dstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500128 }
129 fBounds = fList.head()->bounds();
130}
131
Robert Phillips294723d2021-06-17 09:23:58 -0400132void GrOpsTask::OpChain::visitProxies(const GrVisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500133 if (fList.empty()) {
134 return;
135 }
136 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600137 op.visitProxies(func);
Brian Salomon588cec72018-11-14 13:56:37 -0500138 }
Greg Daniel524e28b2019-11-01 11:48:53 -0400139 if (fDstProxyView.proxy()) {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400140 func(fDstProxyView.proxy(), GrMipmapped::kNo);
Brian Salomon588cec72018-11-14 13:56:37 -0500141 }
142 if (fAppliedClip) {
143 fAppliedClip->visitProxies(func);
144 }
145}
146
Herb Derbye32e1ab2020-10-27 10:29:46 -0400147void GrOpsTask::OpChain::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500148 while (!fList.empty()) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400149 // Since the value goes out of scope immediately, the GrOp::Owner deletes the op.
150 fList.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500151 }
152}
153
154// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
155// the two chains are chainable. Returns the new chain.
Chris Daltonf8d75c62021-04-02 11:24:58 -0600156GrOpsTask::OpChain::List GrOpsTask::OpChain::DoConcat(List chainA, List chainB, const GrCaps& caps,
157 SkArenaAlloc* opsTaskArena,
158 GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500159 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
160 // at chain a's tail and working toward the head. We produce one of the following outcomes:
161 // 1) b's head is merged into an op in a.
162 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
163 // 3) b's head is popped from chain a and added at the tail of a.
164 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
165 // as we assume merges were already attempted when chain b was created. So we keep track of the
166 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
167 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
168 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
169 GrOp* origATail = chainA.tail();
170 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
171 do {
172 int numMergeChecks = 0;
173 bool merged = false;
174 bool noSkip = (origATail == chainA.tail());
175 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
176 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
177 SkRect forwardMergeBounds = skipBounds;
178 GrOp* a = origATail;
179 while (a) {
180 bool canForwardMerge =
181 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
182 if (canForwardMerge || canBackwardMerge) {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600183 auto result = a->combineIfPossible(chainB.head(), opsTaskArena, caps);
Brian Salomon588cec72018-11-14 13:56:37 -0500184 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
185 merged = (result == GrOp::CombineResult::kMerged);
Robert Phillips9548c3b422019-01-08 12:35:43 -0500186 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Brian Salomon588cec72018-11-14 13:56:37 -0500187 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
188 a->uniqueID());
Brian Salomon588cec72018-11-14 13:56:37 -0500189 }
190 if (merged) {
Brian Salomon52a6ed32018-11-26 10:30:58 -0500191 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
Brian Salomon588cec72018-11-14 13:56:37 -0500192 if (canBackwardMerge) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400193 // The GrOp::Owner releases the op.
194 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500195 } else {
196 // We merged the contents of b's head into a. We will replace b's head with a in
197 // chain b.
198 SkASSERT(canForwardMerge);
199 if (a == origATail) {
200 origATail = a->prevInChain();
201 }
Herb Derbyc76d4092020-10-07 16:46:15 -0400202 GrOp::Owner detachedA = chainA.removeOp(a);
203 // The GrOp::Owner releases the op.
204 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500205 chainB.pushHead(std::move(detachedA));
206 if (chainA.empty()) {
207 // We merged all the nodes in chain a to chain b.
208 return chainB;
209 }
210 }
211 break;
212 } else {
213 if (++numMergeChecks == kMaxOpMergeDistance) {
214 break;
215 }
216 forwardMergeBounds.joinNonEmptyArg(a->bounds());
217 canBackwardMerge =
218 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
219 a = a->prevInChain();
220 }
221 }
222 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
223 // tail of a.
224 if (!merged) {
225 chainA.pushTail(chainB.popHead());
226 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
227 }
228 } while (!chainB.empty());
229 return chainA;
230}
231
Chris Dalton945ee652019-01-23 09:10:36 -0700232// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
233// whether the operation succeeded. On success, the provided list will be returned empty.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400234bool GrOpsTask::OpChain::tryConcat(
John Stiles52cb1d02021-06-02 11:58:05 -0400235 List* list, GrProcessorSet::Analysis processorAnalysis, const GrDstProxyView& dstProxyView,
Chris Dalton945ee652019-01-23 09:10:36 -0700236 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600237 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700238 SkASSERT(!fList.empty());
239 SkASSERT(!list->empty());
Greg Daniel524e28b2019-11-01 11:48:53 -0400240 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy()));
241 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy()));
Brian Salomon588cec72018-11-14 13:56:37 -0500242 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700243 if (fList.head()->classID() != list->head()->classID() ||
244 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
245 (fAppliedClip && *fAppliedClip != *appliedClip) ||
Chris Dalton945ee652019-01-23 09:10:36 -0700246 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
247 processorAnalysis.requiresNonOverlappingDraws()) ||
248 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
249 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
250 // or read back a new dst texture between draws. In either case, we can neither
251 // chain nor combine overlapping Ops.
252 GrRectsTouchOrOverlap(fBounds, bounds)) ||
253 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
Greg Daniel524e28b2019-11-01 11:48:53 -0400254 (fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700255 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500256 }
Chris Daltonee21e6b2019-01-22 14:04:43 -0700257
Brian Salomon588cec72018-11-14 13:56:37 -0500258 SkDEBUGCODE(bool first = true;)
259 do {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600260 switch (fList.tail()->combineIfPossible(list->head(), opsTaskArena, caps))
Herb Derbye25c3002020-10-27 15:57:27 -0400261 {
Brian Salomon588cec72018-11-14 13:56:37 -0500262 case GrOp::CombineResult::kCannotCombine:
263 // If an op supports chaining then it is required that chaining is transitive and
264 // that if any two ops in two different chains can merge then the two chains
265 // may also be chained together. Thus, we should only hit this on the first
266 // iteration.
267 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700268 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500269 case GrOp::CombineResult::kMayChain:
Chris Daltonf8d75c62021-04-02 11:24:58 -0600270 fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500271 auditTrail);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700272 // The above exchange cleared out 'list'. The list needs to be empty now for the
273 // loop to terminate.
274 SkASSERT(list->empty());
275 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500276 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500277 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700278 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
279 list->head()->uniqueID());
280 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
Herb Derbyc76d4092020-10-07 16:46:15 -0400281 // The GrOp::Owner releases the op.
282 list->popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500283 break;
284 }
285 }
286 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700287 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700288
289 // The new ops were successfully merged and/or chained onto our own.
290 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700291 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500292}
293
Chris Daltonf8d75c62021-04-02 11:24:58 -0600294bool GrOpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, SkArenaAlloc* opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500295 GrAuditTrail* auditTrail) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400296 if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600297 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500298 this->validate();
299 // append failed
300 return false;
301 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700302
Brian Salomon588cec72018-11-14 13:56:37 -0500303 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700304 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500305 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700306 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500307
Greg Daniel524e28b2019-11-01 11:48:53 -0400308 that->fDstProxyView.setProxyView({});
John Stiles59e18dc2020-07-22 18:18:12 -0400309 if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) {
310 // Obliterates the processor.
311 that->fAppliedClip->detachCoverageFragmentProcessor();
Brian Salomon588cec72018-11-14 13:56:37 -0500312 }
313 this->validate();
314 return true;
315}
316
Herb Derbyc76d4092020-10-07 16:46:15 -0400317GrOp::Owner GrOpsTask::OpChain::appendOp(
318 GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
John Stiles52cb1d02021-06-02 11:58:05 -0400319 const GrDstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600320 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
John Stiles52cb1d02021-06-02 11:58:05 -0400321 const GrDstProxyView noDstProxyView;
Greg Daniel524e28b2019-11-01 11:48:53 -0400322 if (!dstProxyView) {
323 dstProxyView = &noDstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500324 }
325 SkASSERT(op->isChainHead() && op->isChainTail());
326 SkRect opBounds = op->bounds();
327 List chain(std::move(op));
Chris Daltonf8d75c62021-04-02 11:24:58 -0600328 if (!this->tryConcat(&chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps,
329 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500330 // append failed, give the op back to the caller.
331 this->validate();
332 return chain.popHead();
333 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700334
335 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500336 this->validate();
337 return nullptr;
338}
339
Greg Danielf41b2bd2019-08-22 16:19:24 -0400340inline void GrOpsTask::OpChain::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500341#ifdef SK_DEBUG
342 fList.validate();
343 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
344 // Not using SkRect::contains because we allow empty rects.
345 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
346 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
347 }
348#endif
349}
350
351////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800352
Brian Salomon982127b2021-01-21 10:43:35 -0500353GrOpsTask::GrOpsTask(GrDrawingManager* drawingMgr,
Greg Daniel16f5c652019-10-29 11:26:01 -0400354 GrSurfaceProxyView view,
Herb Derby0b1228d2021-04-05 18:38:35 -0400355 GrAuditTrail* auditTrail,
356 sk_sp<GrArenas> arenas)
Adlai Holler33d569e2020-06-16 14:30:08 -0400357 : GrRenderTask()
Greg Danielf41b2bd2019-08-22 16:19:24 -0400358 , fAuditTrail(auditTrail)
Chris Dalton2517ce32021-04-13 00:21:15 -0600359 , fUsesMSAASurface(view.asRenderTargetProxy()->numSamples() > 1)
Brian Salomon982127b2021-01-21 10:43:35 -0500360 , fTargetSwizzle(view.swizzle())
361 , fTargetOrigin(view.origin())
Herb Derby0b1228d2021-04-05 18:38:35 -0400362 , fArenas{std::move(arenas)}
Brian Salomon982127b2021-01-21 10:43:35 -0500363 SkDEBUGCODE(, fNumClips(0)) {
364 this->addTarget(drawingMgr, view.detachProxy());
bsalomon4061b122015-05-29 10:26:19 -0700365}
366
Greg Danielf41b2bd2019-08-22 16:19:24 -0400367void GrOpsTask::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500368 for (auto& chain : fOpChains) {
Herb Derbye32e1ab2020-10-27 10:29:46 -0400369 chain.deleteOps();
Robert Phillipsc994a932018-06-19 13:09:54 -0400370 }
Brian Salomon588cec72018-11-14 13:56:37 -0500371 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400372}
373
Greg Danielf41b2bd2019-08-22 16:19:24 -0400374GrOpsTask::~GrOpsTask() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400375 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000376}
377
Adlai Hollerabe45182020-11-17 09:22:13 -0500378void GrOpsTask::addOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
379 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
380 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
381 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
382 };
383
384 op->visitProxies(addDependency);
385
Chris Dalton83420eb2021-06-23 18:47:09 -0600386 this->recordOp(std::move(op), false/*usesMSAA*/, GrProcessorSet::EmptySetAnalysis(), nullptr,
387 nullptr, caps);
Adlai Hollerabe45182020-11-17 09:22:13 -0500388}
389
Chris Daltonb4403a92021-05-27 14:59:27 -0600390void GrOpsTask::addDrawOp(GrDrawingManager* drawingMgr, GrOp::Owner op, bool usesMSAA,
Chris Dalton710e1c92021-04-23 13:07:52 -0600391 const GrProcessorSet::Analysis& processorAnalysis, GrAppliedClip&& clip,
John Stiles52cb1d02021-06-02 11:58:05 -0400392 const GrDstProxyView& dstProxyView,
Adlai Hollerabe45182020-11-17 09:22:13 -0500393 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()) {
Greg Daniel87fab9f2021-06-07 15:18:23 -0400402 if (!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment)) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500403 this->addSampledTexture(dstProxyView.proxy());
404 }
Greg Daniel87fab9f2021-06-07 15:18:23 -0400405 if (dstProxyView.dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500406 fRenderPassXferBarriers |= GrXferBarrierFlags::kTexture;
407 }
Greg Daniel87fab9f2021-06-07 15:18:23 -0400408 addDependency(dstProxyView.proxy(), GrMipmapped::kNo);
409 SkASSERT(!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment) ||
Adlai Hollerabe45182020-11-17 09:22:13 -0500410 dstProxyView.offset().isZero());
411 }
412
413 if (processorAnalysis.usesNonCoherentHWBlending()) {
414 fRenderPassXferBarriers |= GrXferBarrierFlags::kBlend;
415 }
416
Chris Dalton83420eb2021-06-23 18:47:09 -0600417 this->recordOp(std::move(op), usesMSAA, processorAnalysis, clip.doesClip() ? &clip : nullptr,
Adlai Hollerabe45182020-11-17 09:22:13 -0500418 &dstProxyView, caps);
419}
420
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400421void GrOpsTask::endFlush(GrDrawingManager* drawingMgr) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400422 fLastClipStackGenID = SK_InvalidUniqueID;
423 this->deleteOps();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700424
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500425 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400426 fSampledProxies.reset();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400427 fAuditTrail = nullptr;
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400428
429 GrRenderTask::endFlush(drawingMgr);
Greg Danielf21bf9e2019-08-22 20:12:20 +0000430}
431
Robert Phillips29f38542019-10-16 09:20:25 -0400432void GrOpsTask::onPrePrepare(GrRecordingContext* context) {
Robert Phillips7327c9d2019-10-08 16:32:56 -0400433 SkASSERT(this->isClosed());
Robert Phillips7327c9d2019-10-08 16:32:56 -0400434 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
435 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
436 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
437 // we shouldn't end up with GrOpsTasks with only discard.
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400438 if (this->isColorNoOp() ||
439 (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
Robert Phillips7327c9d2019-10-08 16:32:56 -0400440 return;
441 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500442 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400443
Brian Salomon982127b2021-01-21 10:43:35 -0500444 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400445 for (const auto& chain : fOpChains) {
446 if (chain.shouldExecute()) {
Robert Phillips8053c972019-11-21 10:44:53 -0500447 chain.head()->prePrepare(context,
Brian Salomon982127b2021-01-21 10:43:35 -0500448 dstView,
Robert Phillips8053c972019-11-21 10:44:53 -0500449 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400450 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500451 fRenderPassXferBarriers,
452 fColorLoadOp);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400453 }
454 }
455}
456
Greg Danielf41b2bd2019-08-22 16:19:24 -0400457void GrOpsTask::onPrepare(GrOpFlushState* flushState) {
Brian Salomon982127b2021-01-21 10:43:35 -0500458 SkASSERT(this->target(0)->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400459 SkASSERT(this->isClosed());
Greg Daniel94ed83f2019-09-27 13:05:43 -0400460 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
461 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
462 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
463 // we shouldn't end up with GrOpsTasks with only discard.
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400464 if (this->isColorNoOp() ||
465 (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
Greg Daniel94ed83f2019-09-27 13:05:43 -0400466 return;
467 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500468 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
robertphillipsa106c622015-10-16 09:07:06 -0700469
Greg Danielb20d7e52019-09-03 13:54:39 -0400470 flushState->setSampledProxyArray(&fSampledProxies);
Brian Salomon982127b2021-01-21 10:43:35 -0500471 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500472 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500473 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400474 if (chain.shouldExecute()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400475#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400476 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400477#endif
Robert Phillips901aff02019-10-08 12:32:56 -0400478 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500479 dstView,
Chris Dalton2517ce32021-04-13 00:21:15 -0600480 fUsesMSAASurface,
Robert Phillips901aff02019-10-08 12:32:56 -0400481 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400482 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500483 fRenderPassXferBarriers,
484 fColorLoadOp);
Robert Phillips405413f2019-10-04 10:39:28 -0400485
Brian Salomon29b60c92017-10-31 14:42:10 -0400486 flushState->setOpArgs(&opArgs);
Robert Phillipsdf70f152019-11-15 14:57:05 -0500487
488 // Temporary debugging helper: for debugging prePrepare w/o going through DDLs
489 // Delete once most of the GrOps have an onPrePrepare.
Adlai Holler33d569e2020-06-16 14:30:08 -0400490 // chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0),
Robert Phillipsdf70f152019-11-15 14:57:05 -0500491 // chain.appliedClip());
492
Robert Phillips7327c9d2019-10-08 16:32:56 -0400493 // GrOp::prePrepare may or may not have been called at this point
Brian Salomon588cec72018-11-14 13:56:37 -0500494 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400495 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800496 }
bsalomon512be532015-09-10 10:42:55 -0700497 }
Greg Danielb20d7e52019-09-03 13:54:39 -0400498 flushState->setSampledProxyArray(nullptr);
robertphillipsa13e2022015-11-11 12:01:09 -0800499}
bsalomon512be532015-09-10 10:42:55 -0700500
Greg Danielc0d69152020-10-08 14:59:00 -0400501static GrOpsRenderPass* create_render_pass(GrGpu* gpu,
502 GrRenderTarget* rt,
Chris Daltonda2b0f42021-04-13 00:19:45 -0600503 bool useMSAASurface,
Greg Danielc0d69152020-10-08 14:59:00 -0400504 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
Chris Daltonda2b0f42021-04-13 00:19:45 -0600529 return gpu->getOpsRenderPass(rt, useMSAASurface, stencil, origin, bounds, kColorLoadStoreInfo,
530 stencilLoadAndStoreInfo, sampledProxies, renderPassXferBarriers);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400531}
532
Brian Salomon25a88092016-12-01 09:36:50 -0500533// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500534// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500535// Ops and instantiate them here.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400536bool GrOpsTask::onExecute(GrOpFlushState* flushState) {
Herb Derby93250092021-04-06 12:19:20 -0400537 SkASSERT(this->numTargets() == 1);
538 GrRenderTargetProxy* proxy = this->target(0)->asRenderTargetProxy();
539 SkASSERT(proxy);
540 SK_AT_SCOPE_EXIT(proxy->clearArenas());
541
Greg Daniel94ed83f2019-09-27 13:05:43 -0400542 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
543 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
544 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
545 // we shouldn't end up with GrOpsTasks with only discard.
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400546 if (this->isColorNoOp() ||
547 (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
bsalomondc438982016-08-31 11:53:49 -0700548 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700549 }
Robert Phillips4a395042017-04-24 16:27:17 +0000550
Brian Salomon5f394272019-07-02 14:07:49 -0400551 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400552
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500553 // Make sure load ops are not kClear if the GPU needs to use draws for clears
554 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
555 !flushState->gpu()->caps()->performColorClearsAsDraws());
Chris Dalton674f77a2019-09-30 20:49:39 -0600556
557 const GrCaps& caps = *flushState->gpu()->caps();
Greg Daniel16f5c652019-10-29 11:26:01 -0400558 GrRenderTarget* renderTarget = proxy->peekRenderTarget();
Chris Dalton674f77a2019-09-30 20:49:39 -0600559 SkASSERT(renderTarget);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700560
Greg Danielc0d69152020-10-08 14:59:00 -0400561 GrAttachment* stencil = nullptr;
Chris Dalton57ab06c2021-04-22 12:57:28 -0600562 if (proxy->needsStencil()) {
Chris Dalton537293bf2021-05-03 15:54:24 -0600563 SkASSERT(proxy->canUseStencil(caps));
Chris Daltone0fe23a2021-04-23 13:11:44 -0600564 if (!flushState->resourceProvider()->attachStencilAttachment(renderTarget,
565 fUsesMSAASurface)) {
Chris Dalton0b68dda2019-11-07 21:08:03 -0700566 SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n");
567 return false;
568 }
Chris Daltone0fe23a2021-04-23 13:11:44 -0600569 stencil = renderTarget->getStencilAttachment(fUsesMSAASurface);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700570 }
571
Chris Dalton674f77a2019-09-30 20:49:39 -0600572 GrLoadOp stencilLoadOp;
573 switch (fInitialStencilContent) {
574 case StencilContent::kDontCare:
575 stencilLoadOp = GrLoadOp::kDiscard;
576 break;
577 case StencilContent::kUserBitsCleared:
578 SkASSERT(!caps.performStencilClearsAsDraws());
579 SkASSERT(stencil);
580 if (caps.discardStencilValuesAfterRenderPass()) {
581 // Always clear the stencil if it is being discarded after render passes. This is
582 // also an optimization because we are on a tiler and it avoids loading the values
583 // from memory.
584 stencilLoadOp = GrLoadOp::kClear;
585 break;
586 }
587 if (!stencil->hasPerformedInitialClear()) {
588 stencilLoadOp = GrLoadOp::kClear;
589 stencil->markHasPerformedInitialClear();
590 break;
591 }
John Stiles0fbc6a32021-06-04 14:40:57 -0400592 // SurfaceDrawContexts are required to leave the user stencil bits in a cleared state
Chris Dalton674f77a2019-09-30 20:49:39 -0600593 // once finished, meaning the stencil values will always remain cleared after the
594 // initial clear. Just fall through to reloading the existing (cleared) stencil values
595 // from memory.
John Stiles30212b72020-06-11 17:55:07 -0400596 [[fallthrough]];
Chris Dalton674f77a2019-09-30 20:49:39 -0600597 case StencilContent::kPreserved:
598 SkASSERT(stencil);
599 stencilLoadOp = GrLoadOp::kLoad;
600 break;
601 }
602
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500603 // NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split
Chris Dalton674f77a2019-09-30 20:49:39 -0600604 // its opsTask.
605 //
606 // FIXME: We don't currently flag render passes that don't use stencil at all. In that case
607 // their store op might be "discard", and we currently make the assumption that a discard will
608 // not invalidate what's already in main memory. This is probably ok for now, but certainly
609 // something we want to address soon.
610 GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil)
611 ? GrStoreOp::kDiscard
612 : GrStoreOp::kStore;
613
Brian Salomon982127b2021-01-21 10:43:35 -0500614 GrOpsRenderPass* renderPass = create_render_pass(flushState->gpu(),
615 proxy->peekRenderTarget(),
Chris Dalton2517ce32021-04-13 00:21:15 -0600616 fUsesMSAASurface,
Brian Salomon982127b2021-01-21 10:43:35 -0500617 stencil,
618 fTargetOrigin,
619 fClippedContentBounds,
620 fColorLoadOp,
621 fLoadClearColor,
622 stencilLoadOp,
623 stencilStoreOp,
624 fSampledProxies,
625 fRenderPassXferBarriers);
Greg Daniel21774362020-09-14 10:36:43 -0400626
Greg Danielfa3adf72019-11-07 09:53:41 -0500627 if (!renderPass) {
628 return false;
629 }
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400630 flushState->setOpsRenderPass(renderPass);
631 renderPass->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400632
Brian Salomon982127b2021-01-21 10:43:35 -0500633 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
634
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400635 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500636 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400637 if (!chain.shouldExecute()) {
bsalomonaecc0182016-03-07 11:50:44 -0800638 continue;
639 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400640#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400641 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400642#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400643
Robert Phillips405413f2019-10-04 10:39:28 -0400644 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500645 dstView,
Chris Dalton2517ce32021-04-13 00:21:15 -0600646 fUsesMSAASurface,
Robert Phillips405413f2019-10-04 10:39:28 -0400647 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400648 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500649 fRenderPassXferBarriers,
650 fColorLoadOp);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400651
Brian Salomon29b60c92017-10-31 14:42:10 -0400652 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500653 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400654 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700655 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400656
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400657 renderPass->end();
658 flushState->gpu()->submit(renderPass);
659 flushState->setOpsRenderPass(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800660
bsalomondc438982016-08-31 11:53:49 -0700661 return true;
bsalomona73239a2015-04-28 13:35:17 -0700662}
663
Brian Salomon07bc9a22020-12-02 13:37:16 -0500664void GrOpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500665 fColorLoadOp = op;
666 fLoadClearColor = color;
Chris Dalton16a33c62019-09-24 22:19:17 -0600667 if (GrLoadOp::kClear == fColorLoadOp) {
Brian Salomon982127b2021-01-21 10:43:35 -0500668 GrSurfaceProxy* proxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400669 SkASSERT(proxy);
Michael Ludwigd1d997e2020-06-04 15:52:44 -0400670 fTotalBounds = proxy->backingStoreBoundsRect();
Chris Dalton16a33c62019-09-24 22:19:17 -0600671 }
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500672}
673
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500674void GrOpsTask::reset() {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500675 fDeferredProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500676 fSampledProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500677 fClippedContentBounds = SkIRect::MakeEmpty();
678 fTotalBounds = SkRect::MakeEmpty();
Adlai Holler026851a2021-03-29 14:47:11 -0400679 this->deleteOps();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500680 fRenderPassXferBarriers = GrXferBarrierFlags::kNone;
681}
682
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400683bool GrOpsTask::canMerge(const GrOpsTask* opsTask) const {
684 return this->target(0) == opsTask->target(0) &&
685 fArenas == opsTask->fArenas &&
686 !opsTask->fCannotMergeBackward;
687}
688
Adlai Holler93439d92021-01-26 09:20:39 -0500689int GrOpsTask::mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks) {
Adlai Holler93439d92021-01-26 09:20:39 -0500690 int mergedCount = 0;
691 for (const sk_sp<GrRenderTask>& task : tasks) {
692 auto opsTask = task->asOpsTask();
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400693 if (!opsTask || !this->canMerge(opsTask)) {
Adlai Holler93439d92021-01-26 09:20:39 -0500694 break;
695 }
696 SkASSERT(fTargetSwizzle == opsTask->fTargetSwizzle);
697 SkASSERT(fTargetOrigin == opsTask->fTargetOrigin);
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500698 if (GrLoadOp::kClear == opsTask->fColorLoadOp) {
Adlai Hollerb0ada772021-04-23 17:02:24 -0400699 // TODO(11903): Go back to actually dropping ops tasks when we are merged with
700 // color clear.
701 return 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500702 }
Adlai Holler93439d92021-01-26 09:20:39 -0500703 mergedCount += 1;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500704 }
705 if (0 == mergedCount) {
706 return 0;
707 }
708
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400709 SkSpan<const sk_sp<GrOpsTask>> mergingNodes(
Herb Derby93250092021-04-06 12:19:20 -0400710 reinterpret_cast<const sk_sp<GrOpsTask>*>(tasks.data()), SkToSizeT(mergedCount));
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500711 int addlDeferredProxyCount = 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500712 int addlProxyCount = 0;
713 int addlOpChainCount = 0;
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400714 for (const auto& toMerge : mergingNodes) {
715 addlDeferredProxyCount += toMerge->fDeferredProxies.count();
716 addlProxyCount += toMerge->fSampledProxies.count();
717 addlOpChainCount += toMerge->fOpChains.count();
718 fClippedContentBounds.join(toMerge->fClippedContentBounds);
719 fTotalBounds.join(toMerge->fTotalBounds);
720 fRenderPassXferBarriers |= toMerge->fRenderPassXferBarriers;
Chris Daltonffbeda72021-05-05 09:55:47 -0600721 if (fInitialStencilContent == StencilContent::kDontCare) {
722 // Propogate the first stencil content that isn't kDontCare.
723 //
724 // Once the stencil has any kind of initial content that isn't kDontCare, then the
725 // inital contents of subsequent opsTasks that get merged in don't matter.
726 //
727 // (This works because the opsTask all target the same render target and are in
728 // painter's order. kPreserved obviously happens automatically with a merge, and kClear
729 // is also automatic because the contract is for ops to leave the stencil buffer in a
730 // cleared state when finished.)
731 fInitialStencilContent = toMerge->fInitialStencilContent;
732 }
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400733 fUsesMSAASurface |= toMerge->fUsesMSAASurface;
734 SkDEBUGCODE(fNumClips += toMerge->fNumClips);
Adlai Holler93439d92021-01-26 09:20:39 -0500735 }
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500736
Adlai Holler93439d92021-01-26 09:20:39 -0500737 fLastClipStackGenID = SK_InvalidUniqueID;
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500738 fDeferredProxies.reserve_back(addlDeferredProxyCount);
Adlai Holler93439d92021-01-26 09:20:39 -0500739 fSampledProxies.reserve_back(addlProxyCount);
740 fOpChains.reserve_back(addlOpChainCount);
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400741 for (const auto& toMerge : mergingNodes) {
742 for (GrRenderTask* renderTask : toMerge->dependents()) {
743 renderTask->replaceDependency(toMerge.get(), this);
744 }
745 for (GrRenderTask* renderTask : toMerge->dependencies()) {
746 renderTask->replaceDependent(toMerge.get(), this);
747 }
748 fDeferredProxies.move_back_n(toMerge->fDeferredProxies.count(),
749 toMerge->fDeferredProxies.data());
750 fSampledProxies.move_back_n(toMerge->fSampledProxies.count(),
751 toMerge->fSampledProxies.data());
752 fOpChains.move_back_n(toMerge->fOpChains.count(),
753 toMerge->fOpChains.data());
754 toMerge->fDeferredProxies.reset();
755 toMerge->fSampledProxies.reset();
756 toMerge->fOpChains.reset();
Adlai Holler93439d92021-01-26 09:20:39 -0500757 }
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400758 fMustPreserveStencil = mergingNodes.back()->fMustPreserveStencil;
Adlai Holler93439d92021-01-26 09:20:39 -0500759 return mergedCount;
760}
761
Greg Danielf41b2bd2019-08-22 16:19:24 -0400762bool GrOpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
Chris Dalton6b982802019-06-27 13:53:46 -0600763 if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400764 this->deleteOps();
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500765 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400766 fSampledProxies.reset();
Greg Daniel070cbaf2019-01-03 17:35:54 -0500767
Greg Danielf41b2bd2019-08-22 16:19:24 -0400768 // If the opsTask is using a render target which wraps a vulkan command buffer, we can't do
769 // a clear load since we cannot change the render pass that we are using. Thus we fall back
770 // to making a clear op in this case.
Brian Salomon982127b2021-01-21 10:43:35 -0500771 return !this->target(0)->asRenderTargetProxy()->wrapsVkSecondaryCB();
bsalomonfd8d0132016-08-11 11:25:33 -0700772 }
Robert Phillips380b90c2017-08-30 07:41:07 -0400773
Greg Danielf41b2bd2019-08-22 16:19:24 -0400774 // Could not empty the task, so an op must be added to handle the clear
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500775 return false;
bsalomon9f129de2016-08-10 16:31:05 -0700776}
777
Greg Danielf41b2bd2019-08-22 16:19:24 -0400778void GrOpsTask::discard() {
779 // Discard calls to in-progress opsTasks are ignored. Calls at the start update the
780 // opsTasks' color & stencil load ops.
781 if (this->isEmpty()) {
782 fColorLoadOp = GrLoadOp::kDiscard;
Chris Dalton674f77a2019-09-30 20:49:39 -0600783 fInitialStencilContent = StencilContent::kDontCare;
Chris Dalton16a33c62019-09-24 22:19:17 -0600784 fTotalBounds.setEmpty();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400785 }
786}
787
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000788////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000789
John Stiles1e0136e2020-08-12 18:44:00 -0400790#if GR_TEST_UTILS
Robert Phillips047d5bb2021-01-08 13:39:19 -0500791void GrOpsTask::dump(const SkString& label,
792 SkString indent,
793 bool printDependencies,
794 bool close) const {
795 GrRenderTask::dump(label, indent, printDependencies, false);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400796
Robert Phillips047d5bb2021-01-08 13:39:19 -0500797 SkDebugf("%sfColorLoadOp: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600798 switch (fColorLoadOp) {
799 case GrLoadOp::kLoad:
800 SkDebugf("kLoad\n");
801 break;
802 case GrLoadOp::kClear:
Brian Salomon07bc9a22020-12-02 13:37:16 -0500803 SkDebugf("kClear {%g, %g, %g, %g}\n",
804 fLoadClearColor[0],
805 fLoadClearColor[1],
806 fLoadClearColor[2],
807 fLoadClearColor[3]);
Chris Dalton674f77a2019-09-30 20:49:39 -0600808 break;
809 case GrLoadOp::kDiscard:
810 SkDebugf("kDiscard\n");
811 break;
812 }
813
Robert Phillips047d5bb2021-01-08 13:39:19 -0500814 SkDebugf("%sfInitialStencilContent: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600815 switch (fInitialStencilContent) {
816 case StencilContent::kDontCare:
817 SkDebugf("kDontCare\n");
818 break;
819 case StencilContent::kUserBitsCleared:
820 SkDebugf("kUserBitsCleared\n");
821 break;
822 case StencilContent::kPreserved:
823 SkDebugf("kPreserved\n");
824 break;
825 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400826
Robert Phillips047d5bb2021-01-08 13:39:19 -0500827 SkDebugf("%s%d ops:\n", indent.c_str(), fOpChains.count());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400828 for (int i = 0; i < fOpChains.count(); ++i) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500829 SkDebugf("%s*******************************\n", indent.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400830 if (!fOpChains[i].head()) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500831 SkDebugf("%s%d: <combined forward or failed instantiation>\n", indent.c_str(), i);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400832 } else {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500833 SkDebugf("%s%d: %s\n", indent.c_str(), i, fOpChains[i].head()->name());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400834 SkRect bounds = fOpChains[i].bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500835 SkDebugf("%sClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
836 indent.c_str(),
837 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400838 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
839 SkString info = SkTabString(op.dumpInfo(), 1);
Robert Phillips047d5bb2021-01-08 13:39:19 -0500840 SkDebugf("%s%s\n", indent.c_str(), info.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400841 bounds = op.bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500842 SkDebugf("%s\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
843 indent.c_str(),
844 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400845 }
846 }
847 }
Robert Phillips047d5bb2021-01-08 13:39:19 -0500848
849 if (close) {
850 SkDebugf("%s--------------------------------------------------------------\n\n",
851 indent.c_str());
852 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400853}
John Stiles1e0136e2020-08-12 18:44:00 -0400854#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400855
John Stiles1e0136e2020-08-12 18:44:00 -0400856#ifdef SK_DEBUG
Robert Phillips294723d2021-06-17 09:23:58 -0400857void GrOpsTask::visitProxies_debugOnly(const GrVisitProxyFunc& func) const {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400858 auto textureFunc = [ func ] (GrSurfaceProxy* tex, GrMipmapped mipmapped) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400859 func(tex, mipmapped);
860 };
861
Greg Danielf41b2bd2019-08-22 16:19:24 -0400862 for (const OpChain& chain : fOpChains) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400863 chain.visitProxies(textureFunc);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400864 }
865}
866
867#endif
868
869////////////////////////////////////////////////////////////////////////////////
870
Adlai Hollere9ea4142021-04-27 14:31:56 -0400871void GrOpsTask::onMakeSkippable() {
Brian Salomond63638b2021-03-05 14:00:07 -0500872 this->deleteOps();
873 fDeferredProxies.reset();
874 fColorLoadOp = GrLoadOp::kLoad;
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400875 SkASSERT(this->isColorNoOp());
Brian Salomond63638b2021-03-05 14:00:07 -0500876}
877
Greg Danielf41b2bd2019-08-22 16:19:24 -0400878bool GrOpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
879 bool used = false;
Adlai Holler304f6532021-05-17 13:26:46 -0400880 for (GrSurfaceProxy* proxy : fSampledProxies) {
881 if (proxy == proxyToCheck) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400882 used = true;
Adlai Holler304f6532021-05-17 13:26:46 -0400883 break;
884 }
885 }
886#ifdef SK_DEBUG
887 bool usedSlow = false;
888 auto visit = [ proxyToCheck, &usedSlow ] (GrSurfaceProxy* p, GrMipmapped) {
889 if (p == proxyToCheck) {
890 usedSlow = true;
Greg Danielf41b2bd2019-08-22 16:19:24 -0400891 }
892 };
Adlai Holler304f6532021-05-17 13:26:46 -0400893 this->visitProxies_debugOnly(visit);
894 SkASSERT(used == usedSlow);
895#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400896
897 return used;
898}
899
Greg Danielf41b2bd2019-08-22 16:19:24 -0400900void GrOpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Adlai Hollerc17a3e92021-04-27 14:34:28 -0400901 SkASSERT(this->isClosed());
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400902 if (this->isColorNoOp()) {
Adlai Hollerc17a3e92021-04-27 14:34:28 -0400903 return;
904 }
905
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500906 for (int i = 0; i < fDeferredProxies.count(); ++i) {
907 SkASSERT(!fDeferredProxies[i]->isInstantiated());
908 // We give all the deferred proxies a write usage at the very start of flushing. This
909 // locks them out of being reused for the entire flush until they are read - and then
910 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
911 // with sub-flushes. The deferred proxies only need to be pinned from the start of
912 // the sub-flush in which they appear.
913 alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo);
914 }
915
Brian Salomon982127b2021-01-21 10:43:35 -0500916 GrSurfaceProxy* targetProxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400917
Greg Danielf41b2bd2019-08-22 16:19:24 -0400918 // Add the interval for all the writes to this GrOpsTasks's target
Brian Salomon588cec72018-11-14 13:56:37 -0500919 if (fOpChains.count()) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400920 unsigned int cur = alloc->curOp();
921
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000922 alloc->addInterval(targetProxy, cur, cur + fOpChains.count() - 1,
923 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500924 } else {
925 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
926 // still need to add an interval for the destination so we create a fake op# for
927 // the missing clear op.
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000928 alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(),
929 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500930 alloc->incOps();
931 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400932
Brian Salomon7e67dca2020-07-21 09:27:25 -0400933 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipmapped) {
Brian Salomon982127b2021-01-21 10:43:35 -0500934 alloc->addInterval(p,
935 alloc->curOp(),
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000936 alloc->curOp(),
937 GrResourceAllocator::ActualUse::kYes
Brian Salomon982127b2021-01-21 10:43:35 -0500938 SkDEBUGCODE(, this->target(0) == p));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400939 };
Adlai Holler304f6532021-05-17 13:26:46 -0400940 // TODO: visitProxies is expensive. Can we do this with fSampledProxies instead?
Brian Salomon588cec72018-11-14 13:56:37 -0500941 for (const OpChain& recordedOp : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600942 recordedOp.visitProxies(gather);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500943
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400944 // 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 -0500945 // keep all the math consistent.
946 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400947 }
948}
949
Greg Danielf41b2bd2019-08-22 16:19:24 -0400950void GrOpsTask::recordOp(
Chris Dalton83420eb2021-06-23 18:47:09 -0600951 GrOp::Owner op, bool usesMSAA, GrProcessorSet::Analysis processorAnalysis,
952 GrAppliedClip* clip, const GrDstProxyView* dstProxyView, const GrCaps& caps) {
Brian Salomon982127b2021-01-21 10:43:35 -0500953 GrSurfaceProxy* proxy = this->target(0);
Chris Dalton83420eb2021-06-23 18:47:09 -0600954#ifdef SK_DEBUG
955 op->validate();
956 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy()));
Greg Daniel16f5c652019-10-29 11:26:01 -0400957 SkASSERT(proxy);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400958 // A closed GrOpsTask should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700959 SkASSERT(!this->isClosed());
Chris Dalton83420eb2021-06-23 18:47:09 -0600960 // Ensure we can support dynamic msaa if the caller is trying to trigger it.
961 if (proxy->asRenderTargetProxy()->numSamples() == 1 && usesMSAA) {
962 SkASSERT(caps.supportsDynamicMSAA(proxy->asRenderTargetProxy()));
963 }
964#endif
965
Brian Salomon19ec80f2018-11-16 13:27:30 -0500966 if (!op->bounds().isFinite()) {
Brian Salomon19ec80f2018-11-16 13:27:30 -0500967 return;
968 }
robertphillipsa106c622015-10-16 09:07:06 -0700969
Chris Dalton83420eb2021-06-23 18:47:09 -0600970 fUsesMSAASurface |= usesMSAA;
971
Chris Dalton16a33c62019-09-24 22:19:17 -0600972 // Account for this op's bounds before we attempt to combine.
973 // NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable.
974 fTotalBounds.join(op->bounds());
975
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500976 // Check if there is an op we can combine with by linearly searching back until we either
977 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700978 // 2) intersect with something
979 // 3) find a 'blocker'
Greg Daniel16f5c652019-10-29 11:26:01 -0400980 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400981 GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n"
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400982 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
983 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500984 op->name(),
985 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400986 op->bounds().fLeft, op->bounds().fTop,
987 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500988 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500989 GrOP_INFO("\tOutcome:\n");
Brian Osman788b9162020-02-07 10:36:46 -0500990 int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.count());
Robert Phillips318c4192017-05-17 09:36:38 -0400991 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700992 int i = 0;
993 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500994 OpChain& candidate = fOpChains.fromBack(i);
Greg Daniel524e28b2019-11-01 11:48:53 -0400995 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps,
Herb Derby93250092021-04-06 12:19:20 -0400996 fArenas->arenaAlloc(), fAuditTrail);
Brian Salomon588cec72018-11-14 13:56:37 -0500997 if (!op) {
998 return;
bsalomon512be532015-09-10 10:42:55 -0700999 }
Brian Salomona7682c82018-10-24 10:04:37 -04001000 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -05001001 if (!can_reorder(candidate.bounds(), op->bounds())) {
1002 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
1003 candidate.head()->name(), candidate.head()->uniqueID());
bsalomon512be532015-09-10 10:42:55 -07001004 break;
1005 }
Brian Salomon588cec72018-11-14 13:56:37 -05001006 if (++i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001007 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -07001008 break;
1009 }
1010 }
1011 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001012 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -07001013 }
Brian Salomon54d212e2017-03-21 14:22:38 -04001014 if (clip) {
Herb Derby93250092021-04-06 12:19:20 -04001015 clip = fArenas->arenaAlloc()->make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -04001016 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -04001017 }
Greg Daniel524e28b2019-11-01 11:48:53 -04001018 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView);
bsalomon512be532015-09-10 10:42:55 -07001019}
1020
Greg Danielf41b2bd2019-08-22 16:19:24 -04001021void GrOpsTask::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001022 SkASSERT(!this->isClosed());
Greg Danielf41b2bd2019-08-22 16:19:24 -04001023 GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
Robert Phillips48567ac2017-06-01 08:46:00 -04001024
Brian Salomon588cec72018-11-14 13:56:37 -05001025 for (int i = 0; i < fOpChains.count() - 1; ++i) {
1026 OpChain& chain = fOpChains[i];
Brian Osman788b9162020-02-07 10:36:46 -05001027 int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -08001028 int j = i + 1;
1029 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -05001030 OpChain& candidate = fOpChains[j];
Herb Derby93250092021-04-06 12:19:20 -04001031 if (candidate.prependChain(&chain, caps, fArenas->arenaAlloc(), fAuditTrail)) {
bsalomonaecc0182016-03-07 11:50:44 -08001032 break;
1033 }
Robert Phillipsc84c0302017-05-08 15:35:11 -04001034 // Stop traversing if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -05001035 if (!can_reorder(chain.bounds(), candidate.bounds())) {
1036 GrOP_INFO(
1037 "\t\t%d: chain (%s head opID: %u) -> "
1038 "Intersects with chain (%s, head opID: %u)\n",
1039 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
1040 candidate.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001041 break;
1042 }
Brian Salomona7682c82018-10-24 10:04:37 -04001043 if (++j > maxCandidateIdx) {
Brian Salomon588cec72018-11-14 13:56:37 -05001044 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
1045 i, chain.head()->name(), chain.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001046 break;
1047 }
1048 }
1049 }
1050}
1051
Chris Daltonaa938ce2021-06-23 18:13:59 -06001052GrRenderTask::ExpectedOutcome GrOpsTask::onMakeClosed(GrRecordingContext* rContext,
Robert Phillips07f675d2020-11-16 13:44:01 -05001053 SkIRect* targetUpdateBounds) {
Chris Daltonaa938ce2021-06-23 18:13:59 -06001054 this->forwardCombine(*rContext->priv().caps());
Greg Daniel0b04b6b2021-06-24 19:19:00 -04001055 if (!this->isColorNoOp()) {
Brian Salomon982127b2021-01-21 10:43:35 -05001056 GrSurfaceProxy* proxy = this->target(0);
Michael Ludwigd1d997e2020-06-04 15:52:44 -04001057 // Use the entire backing store bounds since the GPU doesn't clip automatically to the
1058 // logical dimensions.
1059 SkRect clippedContentBounds = proxy->backingStoreBoundsRect();
Adlai Holler33d569e2020-06-16 14:30:08 -04001060 // TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds
Greg Daniel16f5c652019-10-29 11:26:01 -04001061 // then we can simply assert here that the bounds intersect.
Chris Dalton16a33c62019-09-24 22:19:17 -06001062 if (clippedContentBounds.intersect(fTotalBounds)) {
Greg Daniel94ed83f2019-09-27 13:05:43 -04001063 clippedContentBounds.roundOut(&fClippedContentBounds);
Brian Salomon982127b2021-01-21 10:43:35 -05001064 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
1065 fTargetOrigin,
1066 this->target(0)->backingStoreDimensions().height(),
1067 fClippedContentBounds);
Chris Dalton16a33c62019-09-24 22:19:17 -06001068 return ExpectedOutcome::kTargetDirty;
1069 }
1070 }
1071 return ExpectedOutcome::kTargetUnchanged;
1072}