blob: 932a818af4bb65e0c7a91610021e788620a49cb2 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
Brian Salomon4d2d6f42019-07-26 14:15:11 -04008#include "src/gpu/GrRenderTargetOpList.h"
9
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/private/GrRecordingContext.h"
11#include "src/core/SkExchange.h"
12#include "src/core/SkRectPriv.h"
13#include "src/core/SkTraceEvent.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040014#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrCaps.h"
16#include "src/gpu/GrGpu.h"
17#include "src/gpu/GrGpuCommandBuffer.h"
18#include "src/gpu/GrMemoryPool.h"
19#include "src/gpu/GrRecordingContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/GrRenderTargetContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/gpu/GrResourceAllocator.h"
Chris Dalton95d8ceb2019-07-30 11:17:59 -060022#include "src/gpu/GrTexturePriv.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040023#include "src/gpu/geometry/GrRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/ops/GrClearOp.h"
25#include "src/gpu/ops/GrCopySurfaceOp.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040026
reed@google.comac10a2d2010-12-22 21:39:39 +000027////////////////////////////////////////////////////////////////////////////////
28
Brian Salomon09d994e2016-12-21 11:14:46 -050029// Experimentally we have found that most combining occurs within the first 10 comparisons.
Brian Salomon588cec72018-11-14 13:56:37 -050030static const int kMaxOpMergeDistance = 10;
31static const int kMaxOpChainDistance = 10;
32
33////////////////////////////////////////////////////////////////////////////////
34
35using DstProxy = GrXferProcessor::DstProxy;
36
37////////////////////////////////////////////////////////////////////////////////
38
39static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
40
41////////////////////////////////////////////////////////////////////////////////
42
43inline GrRenderTargetOpList::OpChain::List::List(std::unique_ptr<GrOp> op)
44 : fHead(std::move(op)), fTail(fHead.get()) {
45 this->validate();
46}
47
48inline GrRenderTargetOpList::OpChain::List::List(List&& that) { *this = std::move(that); }
49
50inline GrRenderTargetOpList::OpChain::List& GrRenderTargetOpList::OpChain::List::operator=(
51 List&& that) {
52 fHead = std::move(that.fHead);
53 fTail = that.fTail;
54 that.fTail = nullptr;
55 this->validate();
56 return *this;
57}
58
59inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::popHead() {
60 SkASSERT(fHead);
61 auto temp = fHead->cutChain();
62 std::swap(temp, fHead);
63 if (!fHead) {
64 SkASSERT(fTail == temp.get());
65 fTail = nullptr;
66 }
67 return temp;
68}
69
70inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::removeOp(GrOp* op) {
71#ifdef SK_DEBUG
72 auto head = op;
73 while (head->prevInChain()) { head = head->prevInChain(); }
74 SkASSERT(head == fHead.get());
75#endif
76 auto prev = op->prevInChain();
77 if (!prev) {
78 SkASSERT(op == fHead.get());
79 return this->popHead();
80 }
81 auto temp = prev->cutChain();
82 if (auto next = temp->cutChain()) {
83 prev->chainConcat(std::move(next));
84 } else {
85 SkASSERT(fTail == op);
86 fTail = prev;
87 }
88 this->validate();
89 return temp;
90}
91
92inline void GrRenderTargetOpList::OpChain::List::pushHead(std::unique_ptr<GrOp> op) {
93 SkASSERT(op);
94 SkASSERT(op->isChainHead());
95 SkASSERT(op->isChainTail());
96 if (fHead) {
97 op->chainConcat(std::move(fHead));
98 fHead = std::move(op);
99 } else {
100 fHead = std::move(op);
101 fTail = fHead.get();
102 }
103}
104
105inline void GrRenderTargetOpList::OpChain::List::pushTail(std::unique_ptr<GrOp> op) {
106 SkASSERT(op->isChainTail());
107 fTail->chainConcat(std::move(op));
108 fTail = fTail->nextInChain();
109}
110
111inline void GrRenderTargetOpList::OpChain::List::validate() const {
112#ifdef SK_DEBUG
113 if (fHead) {
114 SkASSERT(fTail);
115 fHead->validateChain(fTail);
116 }
117#endif
118}
119
120////////////////////////////////////////////////////////////////////////////////
121
Chris Dalton945ee652019-01-23 09:10:36 -0700122GrRenderTargetOpList::OpChain::OpChain(std::unique_ptr<GrOp> op,
123 GrProcessorSet::Analysis processorAnalysis,
124 GrAppliedClip* appliedClip, const DstProxy* dstProxy)
125 : fList{std::move(op)}
126 , fProcessorAnalysis(processorAnalysis)
127 , fAppliedClip(appliedClip) {
128 if (fProcessorAnalysis.requiresDstTexture()) {
129 SkASSERT(dstProxy && dstProxy->proxy());
Brian Salomon588cec72018-11-14 13:56:37 -0500130 fDstProxy = *dstProxy;
131 }
132 fBounds = fList.head()->bounds();
133}
134
Chris Dalton1706cbf2019-05-21 19:35:29 -0600135void GrRenderTargetOpList::OpChain::visitProxies(const GrOp::VisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500136 if (fList.empty()) {
137 return;
138 }
139 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600140 op.visitProxies(func);
Brian Salomon588cec72018-11-14 13:56:37 -0500141 }
142 if (fDstProxy.proxy()) {
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600143 func(fDstProxy.proxy(), GrMipMapped::kNo);
Brian Salomon588cec72018-11-14 13:56:37 -0500144 }
145 if (fAppliedClip) {
146 fAppliedClip->visitProxies(func);
147 }
148}
149
150void GrRenderTargetOpList::OpChain::deleteOps(GrOpMemoryPool* pool) {
151 while (!fList.empty()) {
152 pool->release(fList.popHead());
153 }
154}
155
156// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
157// the two chains are chainable. Returns the new chain.
158GrRenderTargetOpList::OpChain::List GrRenderTargetOpList::OpChain::DoConcat(
159 List chainA, List chainB, const GrCaps& caps, GrOpMemoryPool* pool,
160 GrAuditTrail* auditTrail) {
161 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
162 // at chain a's tail and working toward the head. We produce one of the following outcomes:
163 // 1) b's head is merged into an op in a.
164 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
165 // 3) b's head is popped from chain a and added at the tail of a.
166 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
167 // as we assume merges were already attempted when chain b was created. So we keep track of the
168 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
169 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
170 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
171 GrOp* origATail = chainA.tail();
172 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
173 do {
174 int numMergeChecks = 0;
175 bool merged = false;
176 bool noSkip = (origATail == chainA.tail());
177 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
178 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
179 SkRect forwardMergeBounds = skipBounds;
180 GrOp* a = origATail;
181 while (a) {
182 bool canForwardMerge =
183 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
184 if (canForwardMerge || canBackwardMerge) {
185 auto result = a->combineIfPossible(chainB.head(), caps);
186 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
187 merged = (result == GrOp::CombineResult::kMerged);
Robert Phillips9548c3b422019-01-08 12:35:43 -0500188 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Brian Salomon588cec72018-11-14 13:56:37 -0500189 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
190 a->uniqueID());
Brian Salomon588cec72018-11-14 13:56:37 -0500191 }
192 if (merged) {
Brian Salomon52a6ed32018-11-26 10:30:58 -0500193 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
Brian Salomon588cec72018-11-14 13:56:37 -0500194 if (canBackwardMerge) {
195 pool->release(chainB.popHead());
196 } else {
197 // We merged the contents of b's head into a. We will replace b's head with a in
198 // chain b.
199 SkASSERT(canForwardMerge);
200 if (a == origATail) {
201 origATail = a->prevInChain();
202 }
203 std::unique_ptr<GrOp> detachedA = chainA.removeOp(a);
204 pool->release(chainB.popHead());
205 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.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700234bool GrRenderTargetOpList::OpChain::tryConcat(
Chris Dalton945ee652019-01-23 09:10:36 -0700235 List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxy& dstProxy,
236 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
237 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700238 SkASSERT(!fList.empty());
239 SkASSERT(!list->empty());
Chris Dalton945ee652019-01-23 09:10:36 -0700240 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxy.proxy()));
241 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxy.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()) ||
254 (fProcessorAnalysis.requiresDstTexture() && fDstProxy != dstProxy)) {
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 Dalton6f6ae6a2019-01-18 12:10:36 -0700260 switch (fList.tail()->combineIfPossible(list->head(), caps)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500261 case GrOp::CombineResult::kCannotCombine:
262 // If an op supports chaining then it is required that chaining is transitive and
263 // that if any two ops in two different chains can merge then the two chains
264 // may also be chained together. Thus, we should only hit this on the first
265 // iteration.
266 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700267 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500268 case GrOp::CombineResult::kMayChain:
Chris Daltonee21e6b2019-01-22 14:04:43 -0700269 fList = DoConcat(std::move(fList), skstd::exchange(*list, List()), caps, pool,
270 auditTrail);
271 // The above exchange cleared out 'list'. The list needs to be empty now for the
272 // loop to terminate.
273 SkASSERT(list->empty());
274 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500275 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500276 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700277 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
278 list->head()->uniqueID());
279 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
280 pool->release(list->popHead());
Brian Salomon588cec72018-11-14 13:56:37 -0500281 break;
282 }
283 }
284 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700285 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700286
287 // The new ops were successfully merged and/or chained onto our own.
288 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700289 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500290}
291
292bool GrRenderTargetOpList::OpChain::prependChain(OpChain* that, const GrCaps& caps,
293 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Chris Dalton945ee652019-01-23 09:10:36 -0700294 if (!that->tryConcat(
295 &fList, fProcessorAnalysis, fDstProxy, fAppliedClip, fBounds, caps, pool, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500296 this->validate();
297 // append failed
298 return false;
299 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700300
Brian Salomon588cec72018-11-14 13:56:37 -0500301 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700302 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500303 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700304 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500305
306 that->fDstProxy.setProxy(nullptr);
307 if (that->fAppliedClip) {
308 for (int i = 0; i < that->fAppliedClip->numClipCoverageFragmentProcessors(); ++i) {
309 that->fAppliedClip->detachClipCoverageFragmentProcessor(i);
310 }
311 }
312 this->validate();
313 return true;
314}
315
Chris Dalton945ee652019-01-23 09:10:36 -0700316std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::appendOp(
317 std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis,
318 const DstProxy* dstProxy, const GrAppliedClip* appliedClip, const GrCaps& caps,
319 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500320 const GrXferProcessor::DstProxy noDstProxy;
321 if (!dstProxy) {
322 dstProxy = &noDstProxy;
323 }
324 SkASSERT(op->isChainHead() && op->isChainTail());
325 SkRect opBounds = op->bounds();
326 List chain(std::move(op));
Chris Dalton945ee652019-01-23 09:10:36 -0700327 if (!this->tryConcat(
328 &chain, processorAnalysis, *dstProxy, appliedClip, opBounds, caps, pool, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500329 // append failed, give the op back to the caller.
330 this->validate();
331 return chain.popHead();
332 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700333
334 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500335 this->validate();
336 return nullptr;
337}
338
339inline void GrRenderTargetOpList::OpChain::validate() const {
340#ifdef SK_DEBUG
341 fList.validate();
342 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
343 // Not using SkRect::contains because we allow empty rects.
344 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
345 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
346 }
347#endif
348}
349
350////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800351
Robert Phillips12c46292019-04-23 07:36:17 -0400352GrRenderTargetOpList::GrRenderTargetOpList(sk_sp<GrOpMemoryPool> opMemoryPool,
Robert Phillips831a2932019-04-12 17:18:39 -0400353 sk_sp<GrRenderTargetProxy> proxy,
Robert Phillips8185f592017-04-26 08:31:08 -0400354 GrAuditTrail* auditTrail)
Robert Phillips12c46292019-04-23 07:36:17 -0400355 : INHERITED(std::move(opMemoryPool), std::move(proxy), auditTrail)
Brian Salomonc3833b42018-07-09 18:23:58 +0000356 , fLastClipStackGenID(SK_InvalidUniqueID)
Robert Phillipsb6deea82017-05-11 14:14:30 -0400357 SkDEBUGCODE(, fNumClips(0)) {
Chris Dalton3d770272019-08-14 09:24:37 -0600358 if (GrTextureProxy* textureProxy = fTarget->asTextureProxy()) {
359 if (GrMipMapped::kYes == textureProxy->mipMapped()) {
360 textureProxy->markMipMapsDirty();
361 }
362 }
363 fTarget->setLastRenderTask(this);
bsalomon4061b122015-05-29 10:26:19 -0700364}
365
Robert Phillipsc994a932018-06-19 13:09:54 -0400366void GrRenderTargetOpList::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500367 for (auto& chain : fOpChains) {
368 chain.deleteOps(fOpMemoryPool.get());
Robert Phillipsc994a932018-06-19 13:09:54 -0400369 }
Brian Salomon588cec72018-11-14 13:56:37 -0500370 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400371}
372
Robert Phillipsf2361d22016-10-25 14:20:06 -0400373GrRenderTargetOpList::~GrRenderTargetOpList() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400374 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000375}
376
377////////////////////////////////////////////////////////////////////////////////
378
robertphillips4beb5c12015-10-20 07:50:00 -0700379#ifdef SK_DEBUG
Robert Phillips27483912018-04-20 12:43:18 -0400380void GrRenderTargetOpList::dump(bool printDependencies) const {
381 INHERITED::dump(printDependencies);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400382
Brian Salomon588cec72018-11-14 13:56:37 -0500383 SkDebugf("ops (%d):\n", fOpChains.count());
384 for (int i = 0; i < fOpChains.count(); ++i) {
robertphillips4beb5c12015-10-20 07:50:00 -0700385 SkDebugf("*******************************\n");
Brian Salomon588cec72018-11-14 13:56:37 -0500386 if (!fOpChains[i].head()) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500387 SkDebugf("%d: <combined forward or failed instantiation>\n", i);
bsalomonaecc0182016-03-07 11:50:44 -0800388 } else {
Brian Salomon588cec72018-11-14 13:56:37 -0500389 SkDebugf("%d: %s\n", i, fOpChains[i].head()->name());
390 SkRect bounds = fOpChains[i].bounds();
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500391 SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
392 bounds.fTop, bounds.fRight, bounds.fBottom);
Brian Salomon588cec72018-11-14 13:56:37 -0500393 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
394 SkString info = SkTabString(op.dumpInfo(), 1);
395 SkDebugf("%s\n", info.c_str());
396 bounds = op.bounds();
397 SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
398 bounds.fTop, bounds.fRight, bounds.fBottom);
399 }
bsalomonaecc0182016-03-07 11:50:44 -0800400 }
robertphillips4beb5c12015-10-20 07:50:00 -0700401 }
402}
Chris Dalton706a6ff2017-11-29 22:01:06 -0700403
404void GrRenderTargetOpList::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500405 for (const OpChain& chain : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600406 chain.visitProxies(func);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700407 }
408}
Brian Salomonc525d4f2018-09-17 15:48:20 -0400409
robertphillips4beb5c12015-10-20 07:50:00 -0700410#endif
411
Brian Osman407b3422017-08-22 15:01:32 -0400412void GrRenderTargetOpList::onPrepare(GrOpFlushState* flushState) {
Robert Phillipsb5204762019-06-19 14:12:13 -0400413 SkASSERT(fTarget->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400414 SkASSERT(this->isClosed());
Stan Iliev2af578d2017-08-16 13:00:28 -0400415#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400416 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Stan Iliev2af578d2017-08-16 13:00:28 -0400417#endif
robertphillipsa106c622015-10-16 09:07:06 -0700418
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500419 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500420 for (const auto& chain : fOpChains) {
421 if (chain.head()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400422#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400423 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400424#endif
Brian Salomon29b60c92017-10-31 14:42:10 -0400425 GrOpFlushState::OpArgs opArgs = {
Brian Salomon588cec72018-11-14 13:56:37 -0500426 chain.head(),
Robert Phillipsb5204762019-06-19 14:12:13 -0400427 fTarget->asRenderTargetProxy(),
Brian Salomon588cec72018-11-14 13:56:37 -0500428 chain.appliedClip(),
Greg Daniel2c3398d2019-06-19 11:58:01 -0400429 fTarget.get()->asRenderTargetProxy()->outputSwizzle(),
Brian Salomon588cec72018-11-14 13:56:37 -0500430 chain.dstProxy()
Robert Phillips318c4192017-05-17 09:36:38 -0400431 };
Brian Salomon29b60c92017-10-31 14:42:10 -0400432 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500433 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400434 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800435 }
bsalomon512be532015-09-10 10:42:55 -0700436 }
robertphillipsa13e2022015-11-11 12:01:09 -0800437}
bsalomon512be532015-09-10 10:42:55 -0700438
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000439static GrGpuRTCommandBuffer* create_command_buffer(GrGpu* gpu,
440 GrRenderTarget* rt,
441 GrSurfaceOrigin origin,
442 const SkRect& bounds,
443 GrLoadOp colorLoadOp,
444 const SkPMColor4f& loadClearColor,
445 GrLoadOp stencilLoadOp) {
Robert Phillipscb2e2352017-08-30 16:44:40 -0400446 const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400447 colorLoadOp,
448 GrStoreOp::kStore,
449 loadClearColor
Robert Phillips178ce3e2017-04-13 09:15:47 -0400450 };
451
Robert Phillips95214472017-08-08 18:00:03 -0400452 // TODO:
453 // We would like to (at this level) only ever clear & discard. We would need
454 // to stop splitting up higher level opLists for copyOps to achieve that.
455 // Note: we would still need SB loads and stores but they would happen at a
456 // lower level (inside the VK command buffer).
Greg Daniel500d58b2017-08-24 15:59:33 -0400457 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400458 stencilLoadOp,
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000459 GrStoreOp::kStore,
Robert Phillips95214472017-08-08 18:00:03 -0400460 };
461
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400462 return gpu->getCommandBuffer(rt, origin, bounds, kColorLoadStoreInfo, stencilLoadAndStoreInfo);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400463}
464
Brian Salomon25a88092016-12-01 09:36:50 -0500465// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500466// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500467// Ops and instantiate them here.
Brian Osman407b3422017-08-22 15:01:32 -0400468bool GrRenderTargetOpList::onExecute(GrOpFlushState* flushState) {
Greg Danieldbdba602018-04-20 11:52:43 -0400469 // TODO: Forcing the execution of the discard here isn't ideal since it will cause us to do a
470 // discard and then store the data back in memory so that the load op on future draws doesn't
471 // think the memory is unitialized. Ideally we would want a system where we are tracking whether
472 // the proxy itself has valid data or not, and then use that as a signal on whether we should be
473 // loading or discarding. In that world we wouldni;t need to worry about executing oplists with
474 // no ops just to do a discard.
Brian Salomon588cec72018-11-14 13:56:37 -0500475 if (fOpChains.empty() && GrLoadOp::kClear != fColorLoadOp &&
Greg Danieldbdba602018-04-20 11:52:43 -0400476 GrLoadOp::kDiscard != fColorLoadOp) {
Chris Dalton95d8ceb2019-07-30 11:17:59 -0600477 // TEMPORARY: We are in the process of moving GrMipMapsStatus from the texture to the proxy.
478 // During this time we want to assert that the proxy resolves mipmaps at the exact same
479 // times the old code would have. A null opList is very exceptional, and the proxy will have
480 // assumed mipmaps are dirty in this scenario. We mark them dirty here on the texture as
481 // well, in order to keep the assert passing.
482 GrTexture* tex = fTarget->peekTexture();
483 if (tex && GrMipMapped::kYes == tex->texturePriv().mipMapped()) {
484 tex->texturePriv().markMipMapsDirty();
485 }
bsalomondc438982016-08-31 11:53:49 -0700486 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700487 }
Robert Phillips4a395042017-04-24 16:27:17 +0000488
Robert Phillipsb5204762019-06-19 14:12:13 -0400489 SkASSERT(fTarget->peekRenderTarget());
Brian Salomon5f394272019-07-02 14:07:49 -0400490 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400491
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000492 // TODO: at the very least, we want the stencil store op to always be discard (at this
493 // level). In Vulkan, sub-command buffers would still need to load & store the stencil buffer.
494
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500495 // Make sure load ops are not kClear if the GPU needs to use draws for clears
496 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
497 !flushState->gpu()->caps()->performColorClearsAsDraws());
498 SkASSERT(fStencilLoadOp != GrLoadOp::kClear ||
499 !flushState->gpu()->caps()->performStencilClearsAsDraws());
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400500 GrGpuRTCommandBuffer* commandBuffer = create_command_buffer(
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000501 flushState->gpu(),
Robert Phillipsb5204762019-06-19 14:12:13 -0400502 fTarget->peekRenderTarget(),
503 fTarget->origin(),
504 fTarget->getBoundsRect(),
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000505 fColorLoadOp,
506 fLoadClearColor,
507 fStencilLoadOp);
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400508 flushState->setCommandBuffer(commandBuffer);
Robert Phillips95214472017-08-08 18:00:03 -0400509 commandBuffer->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400510
511 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500512 for (const auto& chain : fOpChains) {
513 if (!chain.head()) {
bsalomonaecc0182016-03-07 11:50:44 -0800514 continue;
515 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400516#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400517 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400518#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400519
Brian Salomon29b60c92017-10-31 14:42:10 -0400520 GrOpFlushState::OpArgs opArgs {
Brian Salomon588cec72018-11-14 13:56:37 -0500521 chain.head(),
Robert Phillipsb5204762019-06-19 14:12:13 -0400522 fTarget->asRenderTargetProxy(),
Brian Salomon588cec72018-11-14 13:56:37 -0500523 chain.appliedClip(),
Greg Daniel2c3398d2019-06-19 11:58:01 -0400524 fTarget.get()->asRenderTargetProxy()->outputSwizzle(),
Brian Salomon588cec72018-11-14 13:56:37 -0500525 chain.dstProxy()
Robert Phillips178ce3e2017-04-13 09:15:47 -0400526 };
527
Brian Salomon29b60c92017-10-31 14:42:10 -0400528 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500529 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400530 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700531 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400532
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400533 commandBuffer->end();
534 flushState->gpu()->submit(commandBuffer);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400535 flushState->setCommandBuffer(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800536
bsalomondc438982016-08-31 11:53:49 -0700537 return true;
bsalomona73239a2015-04-28 13:35:17 -0700538}
539
Chris Daltona84cacf2017-10-04 10:30:29 -0600540void GrRenderTargetOpList::endFlush() {
Brian Salomonc3833b42018-07-09 18:23:58 +0000541 fLastClipStackGenID = SK_InvalidUniqueID;
Robert Phillipsc994a932018-06-19 13:09:54 -0400542 this->deleteOps();
Chris Daltonc82dd4e2017-11-20 18:20:28 -0700543 fClipAllocator.reset();
Chris Daltona84cacf2017-10-04 10:30:29 -0600544 INHERITED::endFlush();
bsalomon512be532015-09-10 10:42:55 -0700545}
546
Robert Phillips380b90c2017-08-30 07:41:07 -0400547void GrRenderTargetOpList::discard() {
548 // Discard calls to in-progress opLists are ignored. Calls at the start update the
549 // opLists' color & stencil load ops.
550 if (this->isEmpty()) {
551 fColorLoadOp = GrLoadOp::kDiscard;
552 fStencilLoadOp = GrLoadOp::kDiscard;
553 }
554}
555
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500556void GrRenderTargetOpList::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) {
557 fColorLoadOp = op;
558 fLoadClearColor = color;
559}
560
Chris Dalton6b982802019-06-27 13:53:46 -0600561bool GrRenderTargetOpList::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500562 // Mark the color load op as discard (this may be followed by a clearColorOnLoad call to make
563 // the load op kClear, or it may be followed by an explicit op). In the event of an absClear()
564 // after a regular clear(), we could end up with a clear load op and a real clear op in the list
565 // if the load op were not reset here.
566 fColorLoadOp = GrLoadOp::kDiscard;
567
Chris Dalton6b982802019-06-27 13:53:46 -0600568 // If we previously recorded a wait op, we cannot delete the wait op. Until we track the wait
569 // ops separately from normal ops, we have to avoid clearing out any ops in this case as well.
570 if (fHasWaitOp) {
571 canDiscardPreviousOps = CanDiscardPreviousOps::kNo;
572 }
573
574 if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400575 this->deleteOps();
Brian Osman099fa0f2017-10-02 16:38:32 -0400576 fDeferredProxies.reset();
Greg Daniel070cbaf2019-01-03 17:35:54 -0500577
578 // If the opList is using a render target which wraps a vulkan command buffer, we can't do a
579 // clear load since we cannot change the render pass that we are using. Thus we fall back to
580 // making a clear op in this case.
Robert Phillipsb5204762019-06-19 14:12:13 -0400581 return !fTarget->asRenderTargetProxy()->wrapsVkSecondaryCB();
bsalomonfd8d0132016-08-11 11:25:33 -0700582 }
Robert Phillips380b90c2017-08-30 07:41:07 -0400583
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500584 // Could not empty the list, so an op must be added to handle the clear
585 return false;
bsalomon9f129de2016-08-10 16:31:05 -0700586}
587
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000588////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000589
Robert Phillips81dd3e02017-06-23 11:59:24 -0400590// This closely parallels GrTextureOpList::copySurface but renderTargetOpLists
591// also store the applied clip and dest proxy with the op
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500592bool GrRenderTargetOpList::copySurface(GrRecordingContext* context,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400593 GrSurfaceProxy* src,
Robert Phillipsf2361d22016-10-25 14:20:06 -0400594 const SkIRect& srcRect,
595 const SkIPoint& dstPoint) {
Chris Daltonf8e5aad2019-08-02 12:55:23 -0600596 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(
597 context, fTarget.get(), src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500598 if (!op) {
bsalomonb8fea972016-02-16 07:34:17 -0800599 return false;
600 }
robertphillips498d7ac2015-10-30 10:11:30 -0700601
Chris Dalton08755122019-08-05 16:13:47 -0600602 this->addOp(std::move(op), GrTextureResolveManager(context->priv().drawingManager()),
603 *context->priv().caps());
bsalomonb8fea972016-02-16 07:34:17 -0800604 return true;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000605}
606
Chris Dalton6b498102019-08-01 14:14:52 -0600607void GrRenderTargetOpList::handleInternalAllocationFailure() {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500608 bool hasUninstantiatedProxy = false;
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600609 auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p, GrMipMapped) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400610 if (!p->isInstantiated()) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500611 hasUninstantiatedProxy = true;
612 }
613 };
Brian Salomon588cec72018-11-14 13:56:37 -0500614 for (OpChain& recordedOp : fOpChains) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500615 hasUninstantiatedProxy = false;
Chris Dalton1706cbf2019-05-21 19:35:29 -0600616 recordedOp.visitProxies(checkInstantiation);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500617 if (hasUninstantiatedProxy) {
618 // When instantiation of the proxy fails we drop the Op
Brian Salomon588cec72018-11-14 13:56:37 -0500619 recordedOp.deleteOps(fOpMemoryPool.get());
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500620 }
621 }
622}
623
Robert Phillips9313aa72019-04-09 18:41:27 -0400624bool GrRenderTargetOpList::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
625 bool used = false;
626
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600627 auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p, GrMipMapped) {
Robert Phillips9313aa72019-04-09 18:41:27 -0400628 if (p == proxyToCheck) {
629 used = true;
630 }
631 };
632 for (const OpChain& recordedOp : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600633 recordedOp.visitProxies(visit);
Robert Phillips9313aa72019-04-09 18:41:27 -0400634 }
635
636 return used;
637}
638
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400639void GrRenderTargetOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400640
Robert Phillips51b20f22017-12-01 15:32:35 -0500641 for (int i = 0; i < fDeferredProxies.count(); ++i) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400642 SkASSERT(!fDeferredProxies[i]->isInstantiated());
Robert Phillips51b20f22017-12-01 15:32:35 -0500643 // We give all the deferred proxies a write usage at the very start of flushing. This
644 // locks them out of being reused for the entire flush until they are read - and then
645 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
646 // with sub-flushes. The deferred proxies only need to be pinned from the start of
647 // the sub-flush in which they appear.
Robert Phillipsc73666f2019-04-24 08:49:48 -0400648 alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo);
Robert Phillips51b20f22017-12-01 15:32:35 -0500649 }
650
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400651 // Add the interval for all the writes to this opList's target
Brian Salomon588cec72018-11-14 13:56:37 -0500652 if (fOpChains.count()) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400653 unsigned int cur = alloc->curOp();
654
Robert Phillipsc73666f2019-04-24 08:49:48 -0400655 alloc->addInterval(fTarget.get(), cur, cur + fOpChains.count() - 1,
656 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500657 } else {
658 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
659 // still need to add an interval for the destination so we create a fake op# for
660 // the missing clear op.
Robert Phillipsc73666f2019-04-24 08:49:48 -0400661 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
662 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500663 alloc->incOps();
664 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400665
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600666 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipMapped) {
Robert Phillipsc73666f2019-04-24 08:49:48 -0400667 alloc->addInterval(p, alloc->curOp(), alloc->curOp(), GrResourceAllocator::ActualUse::kYes
668 SkDEBUGCODE(, fTarget.get() == p));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400669 };
Brian Salomon588cec72018-11-14 13:56:37 -0500670 for (const OpChain& recordedOp : fOpChains) {
Brian Salomon7d94bb52018-10-12 14:37:19 -0400671 // only diff from the GrTextureOpList version
Chris Dalton1706cbf2019-05-21 19:35:29 -0600672 recordedOp.visitProxies(gather);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500673
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400674 // 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 -0500675 // keep all the math consistent.
676 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400677 }
678}
679
Chris Dalton945ee652019-01-23 09:10:36 -0700680void GrRenderTargetOpList::recordOp(
681 std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip,
682 const DstProxy* dstProxy, const GrCaps& caps) {
Ethan Nicholas029b22c2018-10-18 16:49:56 -0400683 SkDEBUGCODE(op->validate();)
Chris Dalton945ee652019-01-23 09:10:36 -0700684 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxy && dstProxy->proxy()));
Robert Phillipsb5204762019-06-19 14:12:13 -0400685 SkASSERT(fTarget);
Robert Phillipsee683652017-04-26 11:53:10 -0400686
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500687 // A closed GrOpList should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700688 SkASSERT(!this->isClosed());
Brian Salomon19ec80f2018-11-16 13:27:30 -0500689 if (!op->bounds().isFinite()) {
690 fOpMemoryPool->release(std::move(op));
691 return;
692 }
robertphillipsa106c622015-10-16 09:07:06 -0700693
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500694 // Check if there is an op we can combine with by linearly searching back until we either
695 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700696 // 2) intersect with something
697 // 3) find a 'blocker'
Robert Phillipsb5204762019-06-19 14:12:13 -0400698 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget->uniqueID());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400699 GrOP_INFO("opList: %d Recording (%s, opID: %u)\n"
700 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
701 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500702 op->name(),
703 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400704 op->bounds().fLeft, op->bounds().fTop,
705 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500706 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500707 GrOP_INFO("\tOutcome:\n");
Brian Salomon588cec72018-11-14 13:56:37 -0500708 int maxCandidates = SkTMin(kMaxOpChainDistance, fOpChains.count());
Robert Phillips318c4192017-05-17 09:36:38 -0400709 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700710 int i = 0;
711 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500712 OpChain& candidate = fOpChains.fromBack(i);
Chris Dalton945ee652019-01-23 09:10:36 -0700713 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxy, clip, caps,
714 fOpMemoryPool.get(), fAuditTrail);
Brian Salomon588cec72018-11-14 13:56:37 -0500715 if (!op) {
716 return;
bsalomon512be532015-09-10 10:42:55 -0700717 }
Brian Salomona7682c82018-10-24 10:04:37 -0400718 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -0500719 if (!can_reorder(candidate.bounds(), op->bounds())) {
720 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
721 candidate.head()->name(), candidate.head()->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700722 break;
723 }
Brian Salomon588cec72018-11-14 13:56:37 -0500724 if (++i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400725 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -0700726 break;
727 }
728 }
729 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400730 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -0700731 }
Brian Salomon54d212e2017-03-21 14:22:38 -0400732 if (clip) {
733 clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -0400734 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400735 }
Chris Dalton945ee652019-01-23 09:10:36 -0700736 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxy);
bsalomon512be532015-09-10 10:42:55 -0700737}
738
Robert Phillipsee683652017-04-26 11:53:10 -0400739void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400740 SkASSERT(!this->isClosed());
Brian Salomon588cec72018-11-14 13:56:37 -0500741 GrOP_INFO("opList: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
Robert Phillips48567ac2017-06-01 08:46:00 -0400742
Brian Salomon588cec72018-11-14 13:56:37 -0500743 for (int i = 0; i < fOpChains.count() - 1; ++i) {
744 OpChain& chain = fOpChains[i];
745 int maxCandidateIdx = SkTMin(i + kMaxOpChainDistance, fOpChains.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -0800746 int j = i + 1;
747 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500748 OpChain& candidate = fOpChains[j];
749 if (candidate.prependChain(&chain, caps, fOpMemoryPool.get(), fAuditTrail)) {
bsalomonaecc0182016-03-07 11:50:44 -0800750 break;
751 }
Robert Phillipsc84c0302017-05-08 15:35:11 -0400752 // Stop traversing if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -0500753 if (!can_reorder(chain.bounds(), candidate.bounds())) {
754 GrOP_INFO(
755 "\t\t%d: chain (%s head opID: %u) -> "
756 "Intersects with chain (%s, head opID: %u)\n",
757 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
758 candidate.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800759 break;
760 }
Brian Salomona7682c82018-10-24 10:04:37 -0400761 if (++j > maxCandidateIdx) {
Brian Salomon588cec72018-11-14 13:56:37 -0500762 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
763 i, chain.head()->name(), chain.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800764 break;
765 }
766 }
767 }
768}
769