blob: a3872696539d7a6e386bc9aecbb40a425c1b9b32 [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
Greg Daniel524e28b2019-11-01 11:48:53 -040037using DstProxyView = GrXferProcessor::DstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -050038
39////////////////////////////////////////////////////////////////////////////////
40
41static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
42
43////////////////////////////////////////////////////////////////////////////////
44
Herb Derbyc76d4092020-10-07 16:46:15 -040045inline GrOpsTask::OpChain::List::List(GrOp::Owner op)
Brian Salomon588cec72018-11-14 13:56:37 -050046 : fHead(std::move(op)), fTail(fHead.get()) {
47 this->validate();
48}
49
Greg Danielf41b2bd2019-08-22 16:19:24 -040050inline GrOpsTask::OpChain::List::List(List&& that) { *this = std::move(that); }
Brian Salomon588cec72018-11-14 13:56:37 -050051
Greg Danielf41b2bd2019-08-22 16:19:24 -040052inline GrOpsTask::OpChain::List& GrOpsTask::OpChain::List::operator=(List&& that) {
Brian Salomon588cec72018-11-14 13:56:37 -050053 fHead = std::move(that.fHead);
54 fTail = that.fTail;
55 that.fTail = nullptr;
56 this->validate();
57 return *this;
58}
59
Herb Derbyc76d4092020-10-07 16:46:15 -040060inline GrOp::Owner GrOpsTask::OpChain::List::popHead() {
Brian Salomon588cec72018-11-14 13:56:37 -050061 SkASSERT(fHead);
62 auto temp = fHead->cutChain();
63 std::swap(temp, fHead);
64 if (!fHead) {
65 SkASSERT(fTail == temp.get());
66 fTail = nullptr;
67 }
68 return temp;
69}
70
Herb Derbyc76d4092020-10-07 16:46:15 -040071inline GrOp::Owner GrOpsTask::OpChain::List::removeOp(GrOp* op) {
Brian Salomon588cec72018-11-14 13:56:37 -050072#ifdef SK_DEBUG
73 auto head = op;
74 while (head->prevInChain()) { head = head->prevInChain(); }
75 SkASSERT(head == fHead.get());
76#endif
77 auto prev = op->prevInChain();
78 if (!prev) {
79 SkASSERT(op == fHead.get());
80 return this->popHead();
81 }
82 auto temp = prev->cutChain();
83 if (auto next = temp->cutChain()) {
84 prev->chainConcat(std::move(next));
85 } else {
86 SkASSERT(fTail == op);
87 fTail = prev;
88 }
89 this->validate();
90 return temp;
91}
92
Herb Derbyc76d4092020-10-07 16:46:15 -040093inline void GrOpsTask::OpChain::List::pushHead(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -050094 SkASSERT(op);
95 SkASSERT(op->isChainHead());
96 SkASSERT(op->isChainTail());
97 if (fHead) {
98 op->chainConcat(std::move(fHead));
99 fHead = std::move(op);
100 } else {
101 fHead = std::move(op);
102 fTail = fHead.get();
103 }
104}
105
Herb Derbyc76d4092020-10-07 16:46:15 -0400106inline void GrOpsTask::OpChain::List::pushTail(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -0500107 SkASSERT(op->isChainTail());
108 fTail->chainConcat(std::move(op));
109 fTail = fTail->nextInChain();
110}
111
Greg Danielf41b2bd2019-08-22 16:19:24 -0400112inline void GrOpsTask::OpChain::List::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500113#ifdef SK_DEBUG
114 if (fHead) {
115 SkASSERT(fTail);
116 fHead->validateChain(fTail);
117 }
118#endif
119}
120
121////////////////////////////////////////////////////////////////////////////////
122
Herb Derbyc76d4092020-10-07 16:46:15 -0400123GrOpsTask::OpChain::OpChain(GrOp::Owner op,
Greg Danielf41b2bd2019-08-22 16:19:24 -0400124 GrProcessorSet::Analysis processorAnalysis,
Greg Daniel524e28b2019-11-01 11:48:53 -0400125 GrAppliedClip* appliedClip, const DstProxyView* dstProxyView)
Chris Dalton945ee652019-01-23 09:10:36 -0700126 : fList{std::move(op)}
127 , fProcessorAnalysis(processorAnalysis)
128 , fAppliedClip(appliedClip) {
129 if (fProcessorAnalysis.requiresDstTexture()) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400130 SkASSERT(dstProxyView && dstProxyView->proxy());
131 fDstProxyView = *dstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500132 }
133 fBounds = fList.head()->bounds();
134}
135
Greg Danielf41b2bd2019-08-22 16:19:24 -0400136void GrOpsTask::OpChain::visitProxies(const GrOp::VisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500137 if (fList.empty()) {
138 return;
139 }
140 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600141 op.visitProxies(func);
Brian Salomon588cec72018-11-14 13:56:37 -0500142 }
Greg Daniel524e28b2019-11-01 11:48:53 -0400143 if (fDstProxyView.proxy()) {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400144 func(fDstProxyView.proxy(), GrMipmapped::kNo);
Brian Salomon588cec72018-11-14 13:56:37 -0500145 }
146 if (fAppliedClip) {
147 fAppliedClip->visitProxies(func);
148 }
149}
150
Herb Derbye32e1ab2020-10-27 10:29:46 -0400151void GrOpsTask::OpChain::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500152 while (!fList.empty()) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400153 // Since the value goes out of scope immediately, the GrOp::Owner deletes the op.
154 fList.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500155 }
156}
157
158// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
159// the two chains are chainable. Returns the new chain.
Chris Daltonf8d75c62021-04-02 11:24:58 -0600160GrOpsTask::OpChain::List GrOpsTask::OpChain::DoConcat(List chainA, List chainB, const GrCaps& caps,
161 SkArenaAlloc* opsTaskArena,
162 GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500163 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
164 // at chain a's tail and working toward the head. We produce one of the following outcomes:
165 // 1) b's head is merged into an op in a.
166 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
167 // 3) b's head is popped from chain a and added at the tail of a.
168 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
169 // as we assume merges were already attempted when chain b was created. So we keep track of the
170 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
171 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
172 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
173 GrOp* origATail = chainA.tail();
174 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
175 do {
176 int numMergeChecks = 0;
177 bool merged = false;
178 bool noSkip = (origATail == chainA.tail());
179 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
180 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
181 SkRect forwardMergeBounds = skipBounds;
182 GrOp* a = origATail;
183 while (a) {
184 bool canForwardMerge =
185 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
186 if (canForwardMerge || canBackwardMerge) {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600187 auto result = a->combineIfPossible(chainB.head(), opsTaskArena, caps);
Brian Salomon588cec72018-11-14 13:56:37 -0500188 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
189 merged = (result == GrOp::CombineResult::kMerged);
Robert Phillips9548c3b422019-01-08 12:35:43 -0500190 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Brian Salomon588cec72018-11-14 13:56:37 -0500191 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
192 a->uniqueID());
Brian Salomon588cec72018-11-14 13:56:37 -0500193 }
194 if (merged) {
Brian Salomon52a6ed32018-11-26 10:30:58 -0500195 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
Brian Salomon588cec72018-11-14 13:56:37 -0500196 if (canBackwardMerge) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400197 // The GrOp::Owner releases the op.
198 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500199 } else {
200 // We merged the contents of b's head into a. We will replace b's head with a in
201 // chain b.
202 SkASSERT(canForwardMerge);
203 if (a == origATail) {
204 origATail = a->prevInChain();
205 }
Herb Derbyc76d4092020-10-07 16:46:15 -0400206 GrOp::Owner detachedA = chainA.removeOp(a);
207 // The GrOp::Owner releases the op.
208 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500209 chainB.pushHead(std::move(detachedA));
210 if (chainA.empty()) {
211 // We merged all the nodes in chain a to chain b.
212 return chainB;
213 }
214 }
215 break;
216 } else {
217 if (++numMergeChecks == kMaxOpMergeDistance) {
218 break;
219 }
220 forwardMergeBounds.joinNonEmptyArg(a->bounds());
221 canBackwardMerge =
222 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
223 a = a->prevInChain();
224 }
225 }
226 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
227 // tail of a.
228 if (!merged) {
229 chainA.pushTail(chainB.popHead());
230 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
231 }
232 } while (!chainB.empty());
233 return chainA;
234}
235
Chris Dalton945ee652019-01-23 09:10:36 -0700236// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
237// whether the operation succeeded. On success, the provided list will be returned empty.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400238bool GrOpsTask::OpChain::tryConcat(
Greg Daniel524e28b2019-11-01 11:48:53 -0400239 List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxyView& dstProxyView,
Chris Dalton945ee652019-01-23 09:10:36 -0700240 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600241 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700242 SkASSERT(!fList.empty());
243 SkASSERT(!list->empty());
Greg Daniel524e28b2019-11-01 11:48:53 -0400244 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy()));
245 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy()));
Brian Salomon588cec72018-11-14 13:56:37 -0500246 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700247 if (fList.head()->classID() != list->head()->classID() ||
248 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
249 (fAppliedClip && *fAppliedClip != *appliedClip) ||
Chris Dalton945ee652019-01-23 09:10:36 -0700250 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
251 processorAnalysis.requiresNonOverlappingDraws()) ||
252 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
253 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
254 // or read back a new dst texture between draws. In either case, we can neither
255 // chain nor combine overlapping Ops.
256 GrRectsTouchOrOverlap(fBounds, bounds)) ||
257 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
Greg Daniel524e28b2019-11-01 11:48:53 -0400258 (fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700259 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500260 }
Chris Daltonee21e6b2019-01-22 14:04:43 -0700261
Brian Salomon588cec72018-11-14 13:56:37 -0500262 SkDEBUGCODE(bool first = true;)
263 do {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600264 switch (fList.tail()->combineIfPossible(list->head(), opsTaskArena, caps))
Herb Derbye25c3002020-10-27 15:57:27 -0400265 {
Brian Salomon588cec72018-11-14 13:56:37 -0500266 case GrOp::CombineResult::kCannotCombine:
267 // If an op supports chaining then it is required that chaining is transitive and
268 // that if any two ops in two different chains can merge then the two chains
269 // may also be chained together. Thus, we should only hit this on the first
270 // iteration.
271 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700272 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500273 case GrOp::CombineResult::kMayChain:
Chris Daltonf8d75c62021-04-02 11:24:58 -0600274 fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500275 auditTrail);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700276 // The above exchange cleared out 'list'. The list needs to be empty now for the
277 // loop to terminate.
278 SkASSERT(list->empty());
279 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500280 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500281 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700282 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
283 list->head()->uniqueID());
284 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
Herb Derbyc76d4092020-10-07 16:46:15 -0400285 // The GrOp::Owner releases the op.
286 list->popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500287 break;
288 }
289 }
290 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700291 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700292
293 // The new ops were successfully merged and/or chained onto our own.
294 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700295 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500296}
297
Chris Daltonf8d75c62021-04-02 11:24:58 -0600298bool GrOpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, SkArenaAlloc* opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500299 GrAuditTrail* auditTrail) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400300 if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600301 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500302 this->validate();
303 // append failed
304 return false;
305 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700306
Brian Salomon588cec72018-11-14 13:56:37 -0500307 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700308 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500309 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700310 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500311
Greg Daniel524e28b2019-11-01 11:48:53 -0400312 that->fDstProxyView.setProxyView({});
John Stiles59e18dc2020-07-22 18:18:12 -0400313 if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) {
314 // Obliterates the processor.
315 that->fAppliedClip->detachCoverageFragmentProcessor();
Brian Salomon588cec72018-11-14 13:56:37 -0500316 }
317 this->validate();
318 return true;
319}
320
Herb Derbyc76d4092020-10-07 16:46:15 -0400321GrOp::Owner GrOpsTask::OpChain::appendOp(
322 GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
Greg Daniel524e28b2019-11-01 11:48:53 -0400323 const DstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600324 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400325 const GrXferProcessor::DstProxyView noDstProxyView;
326 if (!dstProxyView) {
327 dstProxyView = &noDstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500328 }
329 SkASSERT(op->isChainHead() && op->isChainTail());
330 SkRect opBounds = op->bounds();
331 List chain(std::move(op));
Chris Daltonf8d75c62021-04-02 11:24:58 -0600332 if (!this->tryConcat(&chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps,
333 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500334 // append failed, give the op back to the caller.
335 this->validate();
336 return chain.popHead();
337 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700338
339 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500340 this->validate();
341 return nullptr;
342}
343
Greg Danielf41b2bd2019-08-22 16:19:24 -0400344inline void GrOpsTask::OpChain::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500345#ifdef SK_DEBUG
346 fList.validate();
347 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
348 // Not using SkRect::contains because we allow empty rects.
349 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
350 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
351 }
352#endif
353}
354
355////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800356
Brian Salomon982127b2021-01-21 10:43:35 -0500357GrOpsTask::GrOpsTask(GrDrawingManager* drawingMgr,
Greg Daniel16f5c652019-10-29 11:26:01 -0400358 GrSurfaceProxyView view,
Herb Derby0b1228d2021-04-05 18:38:35 -0400359 GrAuditTrail* auditTrail,
360 sk_sp<GrArenas> arenas)
Adlai Holler33d569e2020-06-16 14:30:08 -0400361 : GrRenderTask()
Greg Danielf41b2bd2019-08-22 16:19:24 -0400362 , fAuditTrail(auditTrail)
Chris Dalton2517ce32021-04-13 00:21:15 -0600363 , fUsesMSAASurface(view.asRenderTargetProxy()->numSamples() > 1)
Brian Salomon982127b2021-01-21 10:43:35 -0500364 , fTargetSwizzle(view.swizzle())
365 , fTargetOrigin(view.origin())
Herb Derby0b1228d2021-04-05 18:38:35 -0400366 , fArenas{std::move(arenas)}
Brian Salomon982127b2021-01-21 10:43:35 -0500367 SkDEBUGCODE(, fNumClips(0)) {
368 this->addTarget(drawingMgr, view.detachProxy());
bsalomon4061b122015-05-29 10:26:19 -0700369}
370
Greg Danielf41b2bd2019-08-22 16:19:24 -0400371void GrOpsTask::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500372 for (auto& chain : fOpChains) {
Herb Derbye32e1ab2020-10-27 10:29:46 -0400373 chain.deleteOps();
Robert Phillipsc994a932018-06-19 13:09:54 -0400374 }
Brian Salomon588cec72018-11-14 13:56:37 -0500375 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400376}
377
Greg Danielf41b2bd2019-08-22 16:19:24 -0400378GrOpsTask::~GrOpsTask() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400379 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000380}
381
Adlai Hollerabe45182020-11-17 09:22:13 -0500382void GrOpsTask::addOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
383 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
384 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
385 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
386 };
387
388 op->visitProxies(addDependency);
389
390 this->recordOp(std::move(op), GrProcessorSet::EmptySetAnalysis(), nullptr, nullptr, caps);
391}
392
393void GrOpsTask::addDrawOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
Chris Dalton710e1c92021-04-23 13:07:52 -0600394 GrDrawOp::FixedFunctionFlags fixedFunctionFlags,
395 const GrProcessorSet::Analysis& processorAnalysis, GrAppliedClip&& clip,
396 const DstProxyView& dstProxyView,
Adlai Hollerabe45182020-11-17 09:22:13 -0500397 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
398 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
399 this->addSampledTexture(p);
400 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
401 };
402
403 op->visitProxies(addDependency);
404 clip.visitProxies(addDependency);
405 if (dstProxyView.proxy()) {
406 if (GrDstSampleTypeUsesTexture(dstProxyView.dstSampleType())) {
407 this->addSampledTexture(dstProxyView.proxy());
408 }
409 addDependency(dstProxyView.proxy(), GrMipmapped::kNo);
Brian Salomon982127b2021-01-21 10:43:35 -0500410 if (this->target(0) == dstProxyView.proxy()) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500411 // Since we are sampling and drawing to the same surface we will need to use
412 // texture barriers.
413 SkASSERT(GrDstSampleTypeDirectlySamplesDst(dstProxyView.dstSampleType()));
414 fRenderPassXferBarriers |= GrXferBarrierFlags::kTexture;
415 }
416 SkASSERT(dstProxyView.dstSampleType() != GrDstSampleType::kAsInputAttachment ||
417 dstProxyView.offset().isZero());
418 }
419
420 if (processorAnalysis.usesNonCoherentHWBlending()) {
421 fRenderPassXferBarriers |= GrXferBarrierFlags::kBlend;
422 }
423
Chris Dalton710e1c92021-04-23 13:07:52 -0600424#ifdef SK_DEBUG
425 // Ensure we can support dynamic msaa if the caller is trying to trigger it.
426 GrRenderTargetProxy* rtProxy = this->target(0)->asRenderTargetProxy();
427 if (rtProxy->numSamples() == 1 &&
428 (fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA)) {
429 SkASSERT(caps.supportsDynamicMSAA(rtProxy));
430 }
431#endif
432 fUsesMSAASurface |= (fixedFunctionFlags & GrDrawOp::FixedFunctionFlags::kUsesHWAA);
433
Adlai Hollerabe45182020-11-17 09:22:13 -0500434 this->recordOp(std::move(op), processorAnalysis, clip.doesClip() ? &clip : nullptr,
435 &dstProxyView, caps);
436}
437
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400438void GrOpsTask::endFlush(GrDrawingManager* drawingMgr) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400439 fLastClipStackGenID = SK_InvalidUniqueID;
440 this->deleteOps();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700441
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500442 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400443 fSampledProxies.reset();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400444 fAuditTrail = nullptr;
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400445
446 GrRenderTask::endFlush(drawingMgr);
Greg Danielf21bf9e2019-08-22 20:12:20 +0000447}
448
Robert Phillips29f38542019-10-16 09:20:25 -0400449void GrOpsTask::onPrePrepare(GrRecordingContext* context) {
Robert Phillips7327c9d2019-10-08 16:32:56 -0400450 SkASSERT(this->isClosed());
Robert Phillips7327c9d2019-10-08 16:32:56 -0400451 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
452 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
453 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
454 // we shouldn't end up with GrOpsTasks with only discard.
455 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
456 return;
457 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500458 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400459
Brian Salomon982127b2021-01-21 10:43:35 -0500460 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400461 for (const auto& chain : fOpChains) {
462 if (chain.shouldExecute()) {
Robert Phillips8053c972019-11-21 10:44:53 -0500463 chain.head()->prePrepare(context,
Brian Salomon982127b2021-01-21 10:43:35 -0500464 dstView,
Robert Phillips8053c972019-11-21 10:44:53 -0500465 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400466 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500467 fRenderPassXferBarriers,
468 fColorLoadOp);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400469 }
470 }
471}
472
Greg Danielf41b2bd2019-08-22 16:19:24 -0400473void GrOpsTask::onPrepare(GrOpFlushState* flushState) {
Brian Salomon982127b2021-01-21 10:43:35 -0500474 SkASSERT(this->target(0)->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400475 SkASSERT(this->isClosed());
Greg Daniel94ed83f2019-09-27 13:05:43 -0400476 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
477 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
478 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
479 // we shouldn't end up with GrOpsTasks with only discard.
480 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
481 return;
482 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500483 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
robertphillipsa106c622015-10-16 09:07:06 -0700484
Greg Danielb20d7e52019-09-03 13:54:39 -0400485 flushState->setSampledProxyArray(&fSampledProxies);
Brian Salomon982127b2021-01-21 10:43:35 -0500486 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500487 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500488 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400489 if (chain.shouldExecute()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400490#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400491 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400492#endif
Robert Phillips901aff02019-10-08 12:32:56 -0400493 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500494 dstView,
Chris Dalton2517ce32021-04-13 00:21:15 -0600495 fUsesMSAASurface,
Robert Phillips901aff02019-10-08 12:32:56 -0400496 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400497 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500498 fRenderPassXferBarriers,
499 fColorLoadOp);
Robert Phillips405413f2019-10-04 10:39:28 -0400500
Brian Salomon29b60c92017-10-31 14:42:10 -0400501 flushState->setOpArgs(&opArgs);
Robert Phillipsdf70f152019-11-15 14:57:05 -0500502
503 // Temporary debugging helper: for debugging prePrepare w/o going through DDLs
504 // Delete once most of the GrOps have an onPrePrepare.
Adlai Holler33d569e2020-06-16 14:30:08 -0400505 // chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0),
Robert Phillipsdf70f152019-11-15 14:57:05 -0500506 // chain.appliedClip());
507
Robert Phillips7327c9d2019-10-08 16:32:56 -0400508 // GrOp::prePrepare may or may not have been called at this point
Brian Salomon588cec72018-11-14 13:56:37 -0500509 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400510 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800511 }
bsalomon512be532015-09-10 10:42:55 -0700512 }
Greg Danielb20d7e52019-09-03 13:54:39 -0400513 flushState->setSampledProxyArray(nullptr);
robertphillipsa13e2022015-11-11 12:01:09 -0800514}
bsalomon512be532015-09-10 10:42:55 -0700515
Greg Danielc0d69152020-10-08 14:59:00 -0400516static GrOpsRenderPass* create_render_pass(GrGpu* gpu,
517 GrRenderTarget* rt,
Chris Daltonda2b0f42021-04-13 00:19:45 -0600518 bool useMSAASurface,
Greg Danielc0d69152020-10-08 14:59:00 -0400519 GrAttachment* stencil,
520 GrSurfaceOrigin origin,
521 const SkIRect& bounds,
522 GrLoadOp colorLoadOp,
Brian Salomon07bc9a22020-12-02 13:37:16 -0500523 const std::array<float, 4>& loadClearColor,
Greg Danielc0d69152020-10-08 14:59:00 -0400524 GrLoadOp stencilLoadOp,
525 GrStoreOp stencilStoreOp,
526 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
527 GrXferBarrierFlags renderPassXferBarriers) {
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400528 const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400529 colorLoadOp,
530 GrStoreOp::kStore,
531 loadClearColor
Robert Phillips178ce3e2017-04-13 09:15:47 -0400532 };
533
Robert Phillips95214472017-08-08 18:00:03 -0400534 // TODO:
535 // We would like to (at this level) only ever clear & discard. We would need
Greg Danielf41b2bd2019-08-22 16:19:24 -0400536 // to stop splitting up higher level OpsTasks for copyOps to achieve that.
Robert Phillips95214472017-08-08 18:00:03 -0400537 // Note: we would still need SB loads and stores but they would happen at a
538 // lower level (inside the VK command buffer).
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400539 const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400540 stencilLoadOp,
Chris Dalton674f77a2019-09-30 20:49:39 -0600541 stencilStoreOp,
Robert Phillips95214472017-08-08 18:00:03 -0400542 };
543
Chris Daltonda2b0f42021-04-13 00:19:45 -0600544 return gpu->getOpsRenderPass(rt, useMSAASurface, stencil, origin, bounds, kColorLoadStoreInfo,
545 stencilLoadAndStoreInfo, sampledProxies, renderPassXferBarriers);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400546}
547
Brian Salomon25a88092016-12-01 09:36:50 -0500548// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500549// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500550// Ops and instantiate them here.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400551bool GrOpsTask::onExecute(GrOpFlushState* flushState) {
Herb Derby93250092021-04-06 12:19:20 -0400552 SkASSERT(this->numTargets() == 1);
553 GrRenderTargetProxy* proxy = this->target(0)->asRenderTargetProxy();
554 SkASSERT(proxy);
555 SK_AT_SCOPE_EXIT(proxy->clearArenas());
556
Greg Daniel94ed83f2019-09-27 13:05:43 -0400557 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
558 // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation
559 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
560 // we shouldn't end up with GrOpsTasks with only discard.
561 if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
bsalomondc438982016-08-31 11:53:49 -0700562 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700563 }
Robert Phillips4a395042017-04-24 16:27:17 +0000564
Brian Salomon5f394272019-07-02 14:07:49 -0400565 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400566
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500567 // Make sure load ops are not kClear if the GPU needs to use draws for clears
568 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
569 !flushState->gpu()->caps()->performColorClearsAsDraws());
Chris Dalton674f77a2019-09-30 20:49:39 -0600570
571 const GrCaps& caps = *flushState->gpu()->caps();
Greg Daniel16f5c652019-10-29 11:26:01 -0400572 GrRenderTarget* renderTarget = proxy->peekRenderTarget();
Chris Dalton674f77a2019-09-30 20:49:39 -0600573 SkASSERT(renderTarget);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700574
Greg Danielc0d69152020-10-08 14:59:00 -0400575 GrAttachment* stencil = nullptr;
Chris Dalton57ab06c2021-04-22 12:57:28 -0600576 if (proxy->needsStencil()) {
Chris Dalton537293bf2021-05-03 15:54:24 -0600577 SkASSERT(proxy->canUseStencil(caps));
Chris Daltone0fe23a2021-04-23 13:11:44 -0600578 if (!flushState->resourceProvider()->attachStencilAttachment(renderTarget,
579 fUsesMSAASurface)) {
Chris Dalton0b68dda2019-11-07 21:08:03 -0700580 SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n");
581 return false;
582 }
Chris Daltone0fe23a2021-04-23 13:11:44 -0600583 stencil = renderTarget->getStencilAttachment(fUsesMSAASurface);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700584 }
585
Chris Dalton674f77a2019-09-30 20:49:39 -0600586 GrLoadOp stencilLoadOp;
587 switch (fInitialStencilContent) {
588 case StencilContent::kDontCare:
589 stencilLoadOp = GrLoadOp::kDiscard;
590 break;
591 case StencilContent::kUserBitsCleared:
592 SkASSERT(!caps.performStencilClearsAsDraws());
593 SkASSERT(stencil);
594 if (caps.discardStencilValuesAfterRenderPass()) {
595 // Always clear the stencil if it is being discarded after render passes. This is
596 // also an optimization because we are on a tiler and it avoids loading the values
597 // from memory.
598 stencilLoadOp = GrLoadOp::kClear;
599 break;
600 }
601 if (!stencil->hasPerformedInitialClear()) {
602 stencilLoadOp = GrLoadOp::kClear;
603 stencil->markHasPerformedInitialClear();
604 break;
605 }
606 // renderTargetContexts are required to leave the user stencil bits in a cleared state
607 // once finished, meaning the stencil values will always remain cleared after the
608 // initial clear. Just fall through to reloading the existing (cleared) stencil values
609 // from memory.
John Stiles30212b72020-06-11 17:55:07 -0400610 [[fallthrough]];
Chris Dalton674f77a2019-09-30 20:49:39 -0600611 case StencilContent::kPreserved:
612 SkASSERT(stencil);
613 stencilLoadOp = GrLoadOp::kLoad;
614 break;
615 }
616
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500617 // NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split
Chris Dalton674f77a2019-09-30 20:49:39 -0600618 // its opsTask.
619 //
620 // FIXME: We don't currently flag render passes that don't use stencil at all. In that case
621 // their store op might be "discard", and we currently make the assumption that a discard will
622 // not invalidate what's already in main memory. This is probably ok for now, but certainly
623 // something we want to address soon.
624 GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil)
625 ? GrStoreOp::kDiscard
626 : GrStoreOp::kStore;
627
Brian Salomon982127b2021-01-21 10:43:35 -0500628 GrOpsRenderPass* renderPass = create_render_pass(flushState->gpu(),
629 proxy->peekRenderTarget(),
Chris Dalton2517ce32021-04-13 00:21:15 -0600630 fUsesMSAASurface,
Brian Salomon982127b2021-01-21 10:43:35 -0500631 stencil,
632 fTargetOrigin,
633 fClippedContentBounds,
634 fColorLoadOp,
635 fLoadClearColor,
636 stencilLoadOp,
637 stencilStoreOp,
638 fSampledProxies,
639 fRenderPassXferBarriers);
Greg Daniel21774362020-09-14 10:36:43 -0400640
Greg Danielfa3adf72019-11-07 09:53:41 -0500641 if (!renderPass) {
642 return false;
643 }
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400644 flushState->setOpsRenderPass(renderPass);
645 renderPass->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400646
Brian Salomon982127b2021-01-21 10:43:35 -0500647 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
648
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400649 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500650 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400651 if (!chain.shouldExecute()) {
bsalomonaecc0182016-03-07 11:50:44 -0800652 continue;
653 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400654#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400655 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400656#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400657
Robert Phillips405413f2019-10-04 10:39:28 -0400658 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500659 dstView,
Chris Dalton2517ce32021-04-13 00:21:15 -0600660 fUsesMSAASurface,
Robert Phillips405413f2019-10-04 10:39:28 -0400661 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400662 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500663 fRenderPassXferBarriers,
664 fColorLoadOp);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400665
Brian Salomon29b60c92017-10-31 14:42:10 -0400666 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500667 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400668 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700669 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400670
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400671 renderPass->end();
672 flushState->gpu()->submit(renderPass);
673 flushState->setOpsRenderPass(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800674
bsalomondc438982016-08-31 11:53:49 -0700675 return true;
bsalomona73239a2015-04-28 13:35:17 -0700676}
677
Brian Salomon07bc9a22020-12-02 13:37:16 -0500678void GrOpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500679 fColorLoadOp = op;
680 fLoadClearColor = color;
Chris Dalton16a33c62019-09-24 22:19:17 -0600681 if (GrLoadOp::kClear == fColorLoadOp) {
Brian Salomon982127b2021-01-21 10:43:35 -0500682 GrSurfaceProxy* proxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400683 SkASSERT(proxy);
Michael Ludwigd1d997e2020-06-04 15:52:44 -0400684 fTotalBounds = proxy->backingStoreBoundsRect();
Chris Dalton16a33c62019-09-24 22:19:17 -0600685 }
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500686}
687
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500688void GrOpsTask::reset() {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500689 fDeferredProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500690 fSampledProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500691 fClippedContentBounds = SkIRect::MakeEmpty();
692 fTotalBounds = SkRect::MakeEmpty();
Adlai Holler026851a2021-03-29 14:47:11 -0400693 this->deleteOps();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500694 fRenderPassXferBarriers = GrXferBarrierFlags::kNone;
695}
696
Adlai Holler93439d92021-01-26 09:20:39 -0500697int GrOpsTask::mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks) {
Adlai Holler93439d92021-01-26 09:20:39 -0500698 int mergedCount = 0;
699 for (const sk_sp<GrRenderTask>& task : tasks) {
700 auto opsTask = task->asOpsTask();
Herb Derby93250092021-04-06 12:19:20 -0400701 if (!opsTask || opsTask->target(0) != this->target(0)
702 || this->fArenas != opsTask->fArenas) {
Adlai Holler93439d92021-01-26 09:20:39 -0500703 break;
704 }
705 SkASSERT(fTargetSwizzle == opsTask->fTargetSwizzle);
706 SkASSERT(fTargetOrigin == opsTask->fTargetOrigin);
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500707 if (GrLoadOp::kClear == opsTask->fColorLoadOp) {
Adlai Hollerb0ada772021-04-23 17:02:24 -0400708 // TODO(11903): Go back to actually dropping ops tasks when we are merged with
709 // color clear.
710 return 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500711 }
Adlai Holler93439d92021-01-26 09:20:39 -0500712 mergedCount += 1;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500713 }
714 if (0 == mergedCount) {
715 return 0;
716 }
717
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400718 SkSpan<const sk_sp<GrOpsTask>> mergingNodes(
Herb Derby93250092021-04-06 12:19:20 -0400719 reinterpret_cast<const sk_sp<GrOpsTask>*>(tasks.data()), SkToSizeT(mergedCount));
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500720 int addlDeferredProxyCount = 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500721 int addlProxyCount = 0;
722 int addlOpChainCount = 0;
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400723 for (const auto& toMerge : mergingNodes) {
724 addlDeferredProxyCount += toMerge->fDeferredProxies.count();
725 addlProxyCount += toMerge->fSampledProxies.count();
726 addlOpChainCount += toMerge->fOpChains.count();
727 fClippedContentBounds.join(toMerge->fClippedContentBounds);
728 fTotalBounds.join(toMerge->fTotalBounds);
729 fRenderPassXferBarriers |= toMerge->fRenderPassXferBarriers;
Chris Daltonffbeda72021-05-05 09:55:47 -0600730 if (fInitialStencilContent == StencilContent::kDontCare) {
731 // Propogate the first stencil content that isn't kDontCare.
732 //
733 // Once the stencil has any kind of initial content that isn't kDontCare, then the
734 // inital contents of subsequent opsTasks that get merged in don't matter.
735 //
736 // (This works because the opsTask all target the same render target and are in
737 // painter's order. kPreserved obviously happens automatically with a merge, and kClear
738 // is also automatic because the contract is for ops to leave the stencil buffer in a
739 // cleared state when finished.)
740 fInitialStencilContent = toMerge->fInitialStencilContent;
741 }
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400742 fUsesMSAASurface |= toMerge->fUsesMSAASurface;
743 SkDEBUGCODE(fNumClips += toMerge->fNumClips);
Adlai Holler93439d92021-01-26 09:20:39 -0500744 }
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500745
Adlai Holler93439d92021-01-26 09:20:39 -0500746 fLastClipStackGenID = SK_InvalidUniqueID;
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500747 fDeferredProxies.reserve_back(addlDeferredProxyCount);
Adlai Holler93439d92021-01-26 09:20:39 -0500748 fSampledProxies.reserve_back(addlProxyCount);
749 fOpChains.reserve_back(addlOpChainCount);
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400750 for (const auto& toMerge : mergingNodes) {
751 for (GrRenderTask* renderTask : toMerge->dependents()) {
752 renderTask->replaceDependency(toMerge.get(), this);
753 }
754 for (GrRenderTask* renderTask : toMerge->dependencies()) {
755 renderTask->replaceDependent(toMerge.get(), this);
756 }
757 fDeferredProxies.move_back_n(toMerge->fDeferredProxies.count(),
758 toMerge->fDeferredProxies.data());
759 fSampledProxies.move_back_n(toMerge->fSampledProxies.count(),
760 toMerge->fSampledProxies.data());
761 fOpChains.move_back_n(toMerge->fOpChains.count(),
762 toMerge->fOpChains.data());
763 toMerge->fDeferredProxies.reset();
764 toMerge->fSampledProxies.reset();
765 toMerge->fOpChains.reset();
Adlai Holler93439d92021-01-26 09:20:39 -0500766 }
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400767 fMustPreserveStencil = mergingNodes.back()->fMustPreserveStencil;
Adlai Holler93439d92021-01-26 09:20:39 -0500768 return mergedCount;
769}
770
Greg Danielf41b2bd2019-08-22 16:19:24 -0400771bool GrOpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
Chris Dalton6b982802019-06-27 13:53:46 -0600772 if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400773 this->deleteOps();
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500774 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400775 fSampledProxies.reset();
Greg Daniel070cbaf2019-01-03 17:35:54 -0500776
Greg Danielf41b2bd2019-08-22 16:19:24 -0400777 // If the opsTask is using a render target which wraps a vulkan command buffer, we can't do
778 // a clear load since we cannot change the render pass that we are using. Thus we fall back
779 // to making a clear op in this case.
Brian Salomon982127b2021-01-21 10:43:35 -0500780 return !this->target(0)->asRenderTargetProxy()->wrapsVkSecondaryCB();
bsalomonfd8d0132016-08-11 11:25:33 -0700781 }
Robert Phillips380b90c2017-08-30 07:41:07 -0400782
Greg Danielf41b2bd2019-08-22 16:19:24 -0400783 // Could not empty the task, so an op must be added to handle the clear
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500784 return false;
bsalomon9f129de2016-08-10 16:31:05 -0700785}
786
Greg Danielf41b2bd2019-08-22 16:19:24 -0400787void GrOpsTask::discard() {
788 // Discard calls to in-progress opsTasks are ignored. Calls at the start update the
789 // opsTasks' color & stencil load ops.
790 if (this->isEmpty()) {
791 fColorLoadOp = GrLoadOp::kDiscard;
Chris Dalton674f77a2019-09-30 20:49:39 -0600792 fInitialStencilContent = StencilContent::kDontCare;
Chris Dalton16a33c62019-09-24 22:19:17 -0600793 fTotalBounds.setEmpty();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400794 }
795}
796
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000797////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000798
John Stiles1e0136e2020-08-12 18:44:00 -0400799#if GR_TEST_UTILS
Robert Phillips047d5bb2021-01-08 13:39:19 -0500800void GrOpsTask::dump(const SkString& label,
801 SkString indent,
802 bool printDependencies,
803 bool close) const {
804 GrRenderTask::dump(label, indent, printDependencies, false);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400805
Robert Phillips047d5bb2021-01-08 13:39:19 -0500806 SkDebugf("%sfColorLoadOp: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600807 switch (fColorLoadOp) {
808 case GrLoadOp::kLoad:
809 SkDebugf("kLoad\n");
810 break;
811 case GrLoadOp::kClear:
Brian Salomon07bc9a22020-12-02 13:37:16 -0500812 SkDebugf("kClear {%g, %g, %g, %g}\n",
813 fLoadClearColor[0],
814 fLoadClearColor[1],
815 fLoadClearColor[2],
816 fLoadClearColor[3]);
Chris Dalton674f77a2019-09-30 20:49:39 -0600817 break;
818 case GrLoadOp::kDiscard:
819 SkDebugf("kDiscard\n");
820 break;
821 }
822
Robert Phillips047d5bb2021-01-08 13:39:19 -0500823 SkDebugf("%sfInitialStencilContent: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600824 switch (fInitialStencilContent) {
825 case StencilContent::kDontCare:
826 SkDebugf("kDontCare\n");
827 break;
828 case StencilContent::kUserBitsCleared:
829 SkDebugf("kUserBitsCleared\n");
830 break;
831 case StencilContent::kPreserved:
832 SkDebugf("kPreserved\n");
833 break;
834 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400835
Robert Phillips047d5bb2021-01-08 13:39:19 -0500836 SkDebugf("%s%d ops:\n", indent.c_str(), fOpChains.count());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400837 for (int i = 0; i < fOpChains.count(); ++i) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500838 SkDebugf("%s*******************************\n", indent.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400839 if (!fOpChains[i].head()) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500840 SkDebugf("%s%d: <combined forward or failed instantiation>\n", indent.c_str(), i);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400841 } else {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500842 SkDebugf("%s%d: %s\n", indent.c_str(), i, fOpChains[i].head()->name());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400843 SkRect bounds = fOpChains[i].bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500844 SkDebugf("%sClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
845 indent.c_str(),
846 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400847 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
848 SkString info = SkTabString(op.dumpInfo(), 1);
Robert Phillips047d5bb2021-01-08 13:39:19 -0500849 SkDebugf("%s%s\n", indent.c_str(), info.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400850 bounds = op.bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500851 SkDebugf("%s\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
852 indent.c_str(),
853 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400854 }
855 }
856 }
Robert Phillips047d5bb2021-01-08 13:39:19 -0500857
858 if (close) {
859 SkDebugf("%s--------------------------------------------------------------\n\n",
860 indent.c_str());
861 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400862}
John Stiles1e0136e2020-08-12 18:44:00 -0400863#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400864
John Stiles1e0136e2020-08-12 18:44:00 -0400865#ifdef SK_DEBUG
Michael Ludwigfcdd0612019-11-25 08:34:31 -0500866void GrOpsTask::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400867 auto textureFunc = [ func ] (GrSurfaceProxy* tex, GrMipmapped mipmapped) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400868 func(tex, mipmapped);
869 };
870
Greg Danielf41b2bd2019-08-22 16:19:24 -0400871 for (const OpChain& chain : fOpChains) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400872 chain.visitProxies(textureFunc);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400873 }
874}
875
876#endif
877
878////////////////////////////////////////////////////////////////////////////////
879
Adlai Hollere9ea4142021-04-27 14:31:56 -0400880void GrOpsTask::onMakeSkippable() {
Brian Salomond63638b2021-03-05 14:00:07 -0500881 this->deleteOps();
882 fDeferredProxies.reset();
883 fColorLoadOp = GrLoadOp::kLoad;
884 SkASSERT(this->isNoOp());
885}
886
Greg Danielf41b2bd2019-08-22 16:19:24 -0400887bool GrOpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
888 bool used = false;
Adlai Holler304f6532021-05-17 13:26:46 -0400889 for (GrSurfaceProxy* proxy : fSampledProxies) {
890 if (proxy == proxyToCheck) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400891 used = true;
Adlai Holler304f6532021-05-17 13:26:46 -0400892 break;
893 }
894 }
895#ifdef SK_DEBUG
896 bool usedSlow = false;
897 auto visit = [ proxyToCheck, &usedSlow ] (GrSurfaceProxy* p, GrMipmapped) {
898 if (p == proxyToCheck) {
899 usedSlow = true;
Greg Danielf41b2bd2019-08-22 16:19:24 -0400900 }
901 };
Adlai Holler304f6532021-05-17 13:26:46 -0400902 this->visitProxies_debugOnly(visit);
903 SkASSERT(used == usedSlow);
904#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400905
906 return used;
907}
908
Greg Danielf41b2bd2019-08-22 16:19:24 -0400909void GrOpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Adlai Hollerc17a3e92021-04-27 14:34:28 -0400910 SkASSERT(this->isClosed());
911 if (this->isNoOp()) {
912 return;
913 }
914
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500915 for (int i = 0; i < fDeferredProxies.count(); ++i) {
916 SkASSERT(!fDeferredProxies[i]->isInstantiated());
917 // We give all the deferred proxies a write usage at the very start of flushing. This
918 // locks them out of being reused for the entire flush until they are read - and then
919 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
920 // with sub-flushes. The deferred proxies only need to be pinned from the start of
921 // the sub-flush in which they appear.
922 alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo);
923 }
924
Brian Salomon982127b2021-01-21 10:43:35 -0500925 GrSurfaceProxy* targetProxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400926
Greg Danielf41b2bd2019-08-22 16:19:24 -0400927 // Add the interval for all the writes to this GrOpsTasks's target
Brian Salomon588cec72018-11-14 13:56:37 -0500928 if (fOpChains.count()) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400929 unsigned int cur = alloc->curOp();
930
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000931 alloc->addInterval(targetProxy, cur, cur + fOpChains.count() - 1,
932 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500933 } else {
934 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
935 // still need to add an interval for the destination so we create a fake op# for
936 // the missing clear op.
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000937 alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(),
938 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500939 alloc->incOps();
940 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400941
Brian Salomon7e67dca2020-07-21 09:27:25 -0400942 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipmapped) {
Brian Salomon982127b2021-01-21 10:43:35 -0500943 alloc->addInterval(p,
944 alloc->curOp(),
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000945 alloc->curOp(),
946 GrResourceAllocator::ActualUse::kYes
Brian Salomon982127b2021-01-21 10:43:35 -0500947 SkDEBUGCODE(, this->target(0) == p));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400948 };
Adlai Holler304f6532021-05-17 13:26:46 -0400949 // TODO: visitProxies is expensive. Can we do this with fSampledProxies instead?
Brian Salomon588cec72018-11-14 13:56:37 -0500950 for (const OpChain& recordedOp : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600951 recordedOp.visitProxies(gather);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500952
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400953 // 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 -0500954 // keep all the math consistent.
955 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400956 }
957}
958
Greg Danielf41b2bd2019-08-22 16:19:24 -0400959void GrOpsTask::recordOp(
Herb Derbyc76d4092020-10-07 16:46:15 -0400960 GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip,
Greg Daniel524e28b2019-11-01 11:48:53 -0400961 const DstProxyView* dstProxyView, const GrCaps& caps) {
Ethan Nicholas029b22c2018-10-18 16:49:56 -0400962 SkDEBUGCODE(op->validate();)
Greg Daniel524e28b2019-11-01 11:48:53 -0400963 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy()));
Brian Salomon982127b2021-01-21 10:43:35 -0500964 GrSurfaceProxy* proxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400965 SkASSERT(proxy);
Robert Phillipsee683652017-04-26 11:53:10 -0400966
Greg Danielf41b2bd2019-08-22 16:19:24 -0400967 // A closed GrOpsTask should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700968 SkASSERT(!this->isClosed());
Brian Salomon19ec80f2018-11-16 13:27:30 -0500969 if (!op->bounds().isFinite()) {
Brian Salomon19ec80f2018-11-16 13:27:30 -0500970 return;
971 }
robertphillipsa106c622015-10-16 09:07:06 -0700972
Chris Dalton16a33c62019-09-24 22:19:17 -0600973 // Account for this op's bounds before we attempt to combine.
974 // NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable.
975 fTotalBounds.join(op->bounds());
976
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500977 // Check if there is an op we can combine with by linearly searching back until we either
978 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700979 // 2) intersect with something
980 // 3) find a 'blocker'
Greg Daniel16f5c652019-10-29 11:26:01 -0400981 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400982 GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n"
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400983 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
984 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500985 op->name(),
986 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400987 op->bounds().fLeft, op->bounds().fTop,
988 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500989 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500990 GrOP_INFO("\tOutcome:\n");
Brian Osman788b9162020-02-07 10:36:46 -0500991 int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.count());
Robert Phillips318c4192017-05-17 09:36:38 -0400992 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700993 int i = 0;
994 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500995 OpChain& candidate = fOpChains.fromBack(i);
Greg Daniel524e28b2019-11-01 11:48:53 -0400996 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps,
Herb Derby93250092021-04-06 12:19:20 -0400997 fArenas->arenaAlloc(), fAuditTrail);
Brian Salomon588cec72018-11-14 13:56:37 -0500998 if (!op) {
999 return;
bsalomon512be532015-09-10 10:42:55 -07001000 }
Brian Salomona7682c82018-10-24 10:04:37 -04001001 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -05001002 if (!can_reorder(candidate.bounds(), op->bounds())) {
1003 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
1004 candidate.head()->name(), candidate.head()->uniqueID());
bsalomon512be532015-09-10 10:42:55 -07001005 break;
1006 }
Brian Salomon588cec72018-11-14 13:56:37 -05001007 if (++i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001008 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -07001009 break;
1010 }
1011 }
1012 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001013 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -07001014 }
Brian Salomon54d212e2017-03-21 14:22:38 -04001015 if (clip) {
Herb Derby93250092021-04-06 12:19:20 -04001016 clip = fArenas->arenaAlloc()->make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -04001017 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -04001018 }
Greg Daniel524e28b2019-11-01 11:48:53 -04001019 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView);
bsalomon512be532015-09-10 10:42:55 -07001020}
1021
Greg Danielf41b2bd2019-08-22 16:19:24 -04001022void GrOpsTask::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001023 SkASSERT(!this->isClosed());
Greg Danielf41b2bd2019-08-22 16:19:24 -04001024 GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
Robert Phillips48567ac2017-06-01 08:46:00 -04001025
Brian Salomon588cec72018-11-14 13:56:37 -05001026 for (int i = 0; i < fOpChains.count() - 1; ++i) {
1027 OpChain& chain = fOpChains[i];
Brian Osman788b9162020-02-07 10:36:46 -05001028 int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -08001029 int j = i + 1;
1030 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -05001031 OpChain& candidate = fOpChains[j];
Herb Derby93250092021-04-06 12:19:20 -04001032 if (candidate.prependChain(&chain, caps, fArenas->arenaAlloc(), fAuditTrail)) {
bsalomonaecc0182016-03-07 11:50:44 -08001033 break;
1034 }
Robert Phillipsc84c0302017-05-08 15:35:11 -04001035 // Stop traversing if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -05001036 if (!can_reorder(chain.bounds(), candidate.bounds())) {
1037 GrOP_INFO(
1038 "\t\t%d: chain (%s head opID: %u) -> "
1039 "Intersects with chain (%s, head opID: %u)\n",
1040 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
1041 candidate.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001042 break;
1043 }
Brian Salomona7682c82018-10-24 10:04:37 -04001044 if (++j > maxCandidateIdx) {
Brian Salomon588cec72018-11-14 13:56:37 -05001045 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
1046 i, chain.head()->name(), chain.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001047 break;
1048 }
1049 }
1050 }
1051}
1052
Robert Phillips07f675d2020-11-16 13:44:01 -05001053GrRenderTask::ExpectedOutcome GrOpsTask::onMakeClosed(const GrCaps& caps,
1054 SkIRect* targetUpdateBounds) {
Chris Dalton16a33c62019-09-24 22:19:17 -06001055 this->forwardCombine(caps);
1056 if (!this->isNoOp()) {
Brian Salomon982127b2021-01-21 10:43:35 -05001057 GrSurfaceProxy* proxy = this->target(0);
Michael Ludwigd1d997e2020-06-04 15:52:44 -04001058 // Use the entire backing store bounds since the GPU doesn't clip automatically to the
1059 // logical dimensions.
1060 SkRect clippedContentBounds = proxy->backingStoreBoundsRect();
Adlai Holler33d569e2020-06-16 14:30:08 -04001061 // TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds
Greg Daniel16f5c652019-10-29 11:26:01 -04001062 // then we can simply assert here that the bounds intersect.
Chris Dalton16a33c62019-09-24 22:19:17 -06001063 if (clippedContentBounds.intersect(fTotalBounds)) {
Greg Daniel94ed83f2019-09-27 13:05:43 -04001064 clippedContentBounds.roundOut(&fClippedContentBounds);
Brian Salomon982127b2021-01-21 10:43:35 -05001065 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
1066 fTargetOrigin,
1067 this->target(0)->backingStoreDimensions().height(),
1068 fClippedContentBounds);
Chris Dalton16a33c62019-09-24 22:19:17 -06001069 return ExpectedOutcome::kTargetDirty;
1070 }
1071 }
1072 return ExpectedOutcome::kTargetUnchanged;
1073}