blob: f5b1753b2ff31466165f94c76d30a89b98e28336 [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
Chris Dalton7b2c8552019-05-13 15:49:33 -06008#include "include/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/private/GrAuditTrail.h"
10#include "include/private/GrRecordingContext.h"
11#include "src/core/SkExchange.h"
12#include "src/core/SkRectPriv.h"
13#include "src/core/SkTraceEvent.h"
14#include "src/gpu/GrCaps.h"
15#include "src/gpu/GrGpu.h"
16#include "src/gpu/GrGpuCommandBuffer.h"
17#include "src/gpu/GrMemoryPool.h"
18#include "src/gpu/GrRecordingContextPriv.h"
19#include "src/gpu/GrRect.h"
20#include "src/gpu/GrRenderTargetContext.h"
21#include "src/gpu/GrRenderTargetOpList.h"
Chris Dalton7b2c8552019-05-13 15:49:33 -060022#include "src/gpu/GrRenderTargetPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/GrResourceAllocator.h"
Chris Dalton7b2c8552019-05-13 15:49:33 -060024#include "src/gpu/GrStencilAttachment.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/gpu/ops/GrClearOp.h"
26#include "src/gpu/ops/GrCopySurfaceOp.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040027
reed@google.comac10a2d2010-12-22 21:39:39 +000028////////////////////////////////////////////////////////////////////////////////
29
Brian Salomon09d994e2016-12-21 11:14:46 -050030// Experimentally we have found that most combining occurs within the first 10 comparisons.
Brian Salomon588cec72018-11-14 13:56:37 -050031static const int kMaxOpMergeDistance = 10;
32static const int kMaxOpChainDistance = 10;
33
34////////////////////////////////////////////////////////////////////////////////
35
36using DstProxy = GrXferProcessor::DstProxy;
37
38////////////////////////////////////////////////////////////////////////////////
39
40static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
41
42////////////////////////////////////////////////////////////////////////////////
43
44inline GrRenderTargetOpList::OpChain::List::List(std::unique_ptr<GrOp> op)
45 : fHead(std::move(op)), fTail(fHead.get()) {
46 this->validate();
47}
48
49inline GrRenderTargetOpList::OpChain::List::List(List&& that) { *this = std::move(that); }
50
51inline GrRenderTargetOpList::OpChain::List& GrRenderTargetOpList::OpChain::List::operator=(
52 List&& that) {
53 fHead = std::move(that.fHead);
54 fTail = that.fTail;
55 that.fTail = nullptr;
56 this->validate();
57 return *this;
58}
59
60inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::popHead() {
61 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
71inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::removeOp(GrOp* op) {
72#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
93inline void GrRenderTargetOpList::OpChain::List::pushHead(std::unique_ptr<GrOp> op) {
94 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
106inline void GrRenderTargetOpList::OpChain::List::pushTail(std::unique_ptr<GrOp> op) {
107 SkASSERT(op->isChainTail());
108 fTail->chainConcat(std::move(op));
109 fTail = fTail->nextInChain();
110}
111
112inline void GrRenderTargetOpList::OpChain::List::validate() const {
113#ifdef SK_DEBUG
114 if (fHead) {
115 SkASSERT(fTail);
116 fHead->validateChain(fTail);
117 }
118#endif
119}
120
121////////////////////////////////////////////////////////////////////////////////
122
Chris Dalton945ee652019-01-23 09:10:36 -0700123GrRenderTargetOpList::OpChain::OpChain(std::unique_ptr<GrOp> op,
124 GrProcessorSet::Analysis processorAnalysis,
125 GrAppliedClip* appliedClip, const DstProxy* dstProxy)
126 : fList{std::move(op)}
127 , fProcessorAnalysis(processorAnalysis)
128 , fAppliedClip(appliedClip) {
129 if (fProcessorAnalysis.requiresDstTexture()) {
130 SkASSERT(dstProxy && dstProxy->proxy());
Brian Salomon588cec72018-11-14 13:56:37 -0500131 fDstProxy = *dstProxy;
132 }
133 fBounds = fList.head()->bounds();
134}
135
136void GrRenderTargetOpList::OpChain::visitProxies(const GrOp::VisitProxyFunc& func,
137 GrOp::VisitorType visitor) const {
138 if (fList.empty()) {
139 return;
140 }
141 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
142 op.visitProxies(func, visitor);
143 }
144 if (fDstProxy.proxy()) {
145 func(fDstProxy.proxy());
146 }
147 if (fAppliedClip) {
148 fAppliedClip->visitProxies(func);
149 }
150}
151
152void GrRenderTargetOpList::OpChain::deleteOps(GrOpMemoryPool* pool) {
153 while (!fList.empty()) {
154 pool->release(fList.popHead());
155 }
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.
160GrRenderTargetOpList::OpChain::List GrRenderTargetOpList::OpChain::DoConcat(
161 List chainA, List chainB, const GrCaps& caps, GrOpMemoryPool* pool,
162 GrAuditTrail* auditTrail) {
163 // 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) {
187 auto result = a->combineIfPossible(chainB.head(), caps);
188 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) {
197 pool->release(chainB.popHead());
198 } else {
199 // We merged the contents of b's head into a. We will replace b's head with a in
200 // chain b.
201 SkASSERT(canForwardMerge);
202 if (a == origATail) {
203 origATail = a->prevInChain();
204 }
205 std::unique_ptr<GrOp> detachedA = chainA.removeOp(a);
206 pool->release(chainB.popHead());
207 chainB.pushHead(std::move(detachedA));
208 if (chainA.empty()) {
209 // We merged all the nodes in chain a to chain b.
210 return chainB;
211 }
212 }
213 break;
214 } else {
215 if (++numMergeChecks == kMaxOpMergeDistance) {
216 break;
217 }
218 forwardMergeBounds.joinNonEmptyArg(a->bounds());
219 canBackwardMerge =
220 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
221 a = a->prevInChain();
222 }
223 }
224 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
225 // tail of a.
226 if (!merged) {
227 chainA.pushTail(chainB.popHead());
228 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
229 }
230 } while (!chainB.empty());
231 return chainA;
232}
233
Chris Dalton945ee652019-01-23 09:10:36 -0700234// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
235// whether the operation succeeded. On success, the provided list will be returned empty.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700236bool GrRenderTargetOpList::OpChain::tryConcat(
Chris Dalton945ee652019-01-23 09:10:36 -0700237 List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxy& dstProxy,
238 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
239 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700240 SkASSERT(!fList.empty());
241 SkASSERT(!list->empty());
Chris Dalton945ee652019-01-23 09:10:36 -0700242 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxy.proxy()));
243 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxy.proxy()));
Brian Salomon588cec72018-11-14 13:56:37 -0500244 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700245 if (fList.head()->classID() != list->head()->classID() ||
246 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
247 (fAppliedClip && *fAppliedClip != *appliedClip) ||
Chris Dalton945ee652019-01-23 09:10:36 -0700248 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
249 processorAnalysis.requiresNonOverlappingDraws()) ||
250 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
251 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
252 // or read back a new dst texture between draws. In either case, we can neither
253 // chain nor combine overlapping Ops.
254 GrRectsTouchOrOverlap(fBounds, bounds)) ||
255 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
256 (fProcessorAnalysis.requiresDstTexture() && fDstProxy != dstProxy)) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700257 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500258 }
Chris Daltonee21e6b2019-01-22 14:04:43 -0700259
Brian Salomon588cec72018-11-14 13:56:37 -0500260 SkDEBUGCODE(bool first = true;)
261 do {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700262 switch (fList.tail()->combineIfPossible(list->head(), caps)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500263 case GrOp::CombineResult::kCannotCombine:
264 // If an op supports chaining then it is required that chaining is transitive and
265 // that if any two ops in two different chains can merge then the two chains
266 // may also be chained together. Thus, we should only hit this on the first
267 // iteration.
268 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700269 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500270 case GrOp::CombineResult::kMayChain:
Chris Daltonee21e6b2019-01-22 14:04:43 -0700271 fList = DoConcat(std::move(fList), skstd::exchange(*list, List()), caps, pool,
272 auditTrail);
273 // The above exchange cleared out 'list'. The list needs to be empty now for the
274 // loop to terminate.
275 SkASSERT(list->empty());
276 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500277 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500278 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700279 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
280 list->head()->uniqueID());
281 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
282 pool->release(list->popHead());
Brian Salomon588cec72018-11-14 13:56:37 -0500283 break;
284 }
285 }
286 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700287 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700288
289 // The new ops were successfully merged and/or chained onto our own.
290 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700291 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500292}
293
294bool GrRenderTargetOpList::OpChain::prependChain(OpChain* that, const GrCaps& caps,
295 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Chris Dalton945ee652019-01-23 09:10:36 -0700296 if (!that->tryConcat(
297 &fList, fProcessorAnalysis, fDstProxy, fAppliedClip, fBounds, caps, pool, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500298 this->validate();
299 // append failed
300 return false;
301 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700302
Brian Salomon588cec72018-11-14 13:56:37 -0500303 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700304 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500305 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700306 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500307
308 that->fDstProxy.setProxy(nullptr);
309 if (that->fAppliedClip) {
310 for (int i = 0; i < that->fAppliedClip->numClipCoverageFragmentProcessors(); ++i) {
311 that->fAppliedClip->detachClipCoverageFragmentProcessor(i);
312 }
313 }
314 this->validate();
315 return true;
316}
317
Chris Dalton945ee652019-01-23 09:10:36 -0700318std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::appendOp(
319 std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis,
320 const DstProxy* dstProxy, const GrAppliedClip* appliedClip, const GrCaps& caps,
321 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500322 const GrXferProcessor::DstProxy noDstProxy;
323 if (!dstProxy) {
324 dstProxy = &noDstProxy;
325 }
326 SkASSERT(op->isChainHead() && op->isChainTail());
327 SkRect opBounds = op->bounds();
328 List chain(std::move(op));
Chris Dalton945ee652019-01-23 09:10:36 -0700329 if (!this->tryConcat(
330 &chain, processorAnalysis, *dstProxy, appliedClip, opBounds, caps, pool, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500331 // append failed, give the op back to the caller.
332 this->validate();
333 return chain.popHead();
334 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700335
336 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500337 this->validate();
338 return nullptr;
339}
340
341inline void GrRenderTargetOpList::OpChain::validate() const {
342#ifdef SK_DEBUG
343 fList.validate();
344 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
345 // Not using SkRect::contains because we allow empty rects.
346 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
347 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
348 }
349#endif
350}
351
352////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800353
Robert Phillips12c46292019-04-23 07:36:17 -0400354GrRenderTargetOpList::GrRenderTargetOpList(sk_sp<GrOpMemoryPool> opMemoryPool,
Robert Phillips831a2932019-04-12 17:18:39 -0400355 sk_sp<GrRenderTargetProxy> proxy,
Robert Phillips8185f592017-04-26 08:31:08 -0400356 GrAuditTrail* auditTrail)
Robert Phillips12c46292019-04-23 07:36:17 -0400357 : INHERITED(std::move(opMemoryPool), std::move(proxy), auditTrail)
Brian Salomonc3833b42018-07-09 18:23:58 +0000358 , fLastClipStackGenID(SK_InvalidUniqueID)
Robert Phillipsb6deea82017-05-11 14:14:30 -0400359 SkDEBUGCODE(, fNumClips(0)) {
bsalomon4061b122015-05-29 10:26:19 -0700360}
361
Robert Phillipsc994a932018-06-19 13:09:54 -0400362void GrRenderTargetOpList::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500363 for (auto& chain : fOpChains) {
364 chain.deleteOps(fOpMemoryPool.get());
Robert Phillipsc994a932018-06-19 13:09:54 -0400365 }
Brian Salomon588cec72018-11-14 13:56:37 -0500366 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400367}
368
Robert Phillipsf2361d22016-10-25 14:20:06 -0400369GrRenderTargetOpList::~GrRenderTargetOpList() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400370 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000371}
372
373////////////////////////////////////////////////////////////////////////////////
374
robertphillips4beb5c12015-10-20 07:50:00 -0700375#ifdef SK_DEBUG
Robert Phillips27483912018-04-20 12:43:18 -0400376void GrRenderTargetOpList::dump(bool printDependencies) const {
377 INHERITED::dump(printDependencies);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400378
Chris Dalton7b2c8552019-05-13 15:49:33 -0600379 SkDebugf("fStencilLoadOp: %s\n", GrLoadOpName(fStencilLoadOp));
380 SkDebugf("fStencilStoreOp: %s\n", GrStoreOpName(fStencilStoreOp));
381
Brian Salomon588cec72018-11-14 13:56:37 -0500382 SkDebugf("ops (%d):\n", fOpChains.count());
383 for (int i = 0; i < fOpChains.count(); ++i) {
robertphillips4beb5c12015-10-20 07:50:00 -0700384 SkDebugf("*******************************\n");
Brian Salomon588cec72018-11-14 13:56:37 -0500385 if (!fOpChains[i].head()) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500386 SkDebugf("%d: <combined forward or failed instantiation>\n", i);
bsalomonaecc0182016-03-07 11:50:44 -0800387 } else {
Brian Salomon588cec72018-11-14 13:56:37 -0500388 SkDebugf("%d: %s\n", i, fOpChains[i].head()->name());
389 SkRect bounds = fOpChains[i].bounds();
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500390 SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
391 bounds.fTop, bounds.fRight, bounds.fBottom);
Brian Salomon588cec72018-11-14 13:56:37 -0500392 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
393 SkString info = SkTabString(op.dumpInfo(), 1);
394 SkDebugf("%s\n", info.c_str());
395 bounds = op.bounds();
396 SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
397 bounds.fTop, bounds.fRight, bounds.fBottom);
398 }
bsalomonaecc0182016-03-07 11:50:44 -0800399 }
robertphillips4beb5c12015-10-20 07:50:00 -0700400 }
401}
Chris Dalton706a6ff2017-11-29 22:01:06 -0700402
403void GrRenderTargetOpList::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500404 for (const OpChain& chain : fOpChains) {
405 chain.visitProxies(func, GrOp::VisitorType::kOther);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700406 }
407}
Brian Salomonc525d4f2018-09-17 15:48:20 -0400408
robertphillips4beb5c12015-10-20 07:50:00 -0700409#endif
410
Brian Osman407b3422017-08-22 15:01:32 -0400411void GrRenderTargetOpList::onPrepare(GrOpFlushState* flushState) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400412 SkASSERT(fTarget.get()->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400413 SkASSERT(this->isClosed());
Stan Iliev2af578d2017-08-16 13:00:28 -0400414#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
415 TRACE_EVENT0("skia", TRACE_FUNC);
416#endif
robertphillipsa106c622015-10-16 09:07:06 -0700417
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500418 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500419 for (const auto& chain : fOpChains) {
420 if (chain.head()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400421#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon588cec72018-11-14 13:56:37 -0500422 TRACE_EVENT0("skia", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400423#endif
Brian Salomon29b60c92017-10-31 14:42:10 -0400424 GrOpFlushState::OpArgs opArgs = {
Brian Salomon588cec72018-11-14 13:56:37 -0500425 chain.head(),
Robert Phillips2890fbf2017-07-26 15:48:41 -0400426 fTarget.get()->asRenderTargetProxy(),
Brian Salomon588cec72018-11-14 13:56:37 -0500427 chain.appliedClip(),
428 chain.dstProxy()
Robert Phillips318c4192017-05-17 09:36:38 -0400429 };
Brian Salomon29b60c92017-10-31 14:42:10 -0400430 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500431 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400432 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800433 }
bsalomon512be532015-09-10 10:42:55 -0700434 }
robertphillipsa13e2022015-11-11 12:01:09 -0800435}
bsalomon512be532015-09-10 10:42:55 -0700436
Chris Dalton7b2c8552019-05-13 15:49:33 -0600437static GrGpuRTCommandBuffer* create_command_buffer(
438 GrGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin, const SkRect& bounds,
439 GrLoadOp colorLoadOp, const SkPMColor4f& loadClearColor, GrLoadOp stencilLoadOp, GrStoreOp
440 stencilStoreOp) {
Robert Phillipscb2e2352017-08-30 16:44:40 -0400441 const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400442 colorLoadOp,
443 GrStoreOp::kStore,
444 loadClearColor
Robert Phillips178ce3e2017-04-13 09:15:47 -0400445 };
446
Robert Phillips95214472017-08-08 18:00:03 -0400447 // TODO:
448 // We would like to (at this level) only ever clear & discard. We would need
449 // to stop splitting up higher level opLists for copyOps to achieve that.
450 // Note: we would still need SB loads and stores but they would happen at a
451 // lower level (inside the VK command buffer).
Greg Daniel500d58b2017-08-24 15:59:33 -0400452 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400453 stencilLoadOp,
Chris Dalton7b2c8552019-05-13 15:49:33 -0600454 stencilStoreOp,
Robert Phillips95214472017-08-08 18:00:03 -0400455 };
456
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400457 return gpu->getCommandBuffer(rt, origin, bounds, kColorLoadStoreInfo, stencilLoadAndStoreInfo);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400458}
459
Brian Salomon25a88092016-12-01 09:36:50 -0500460// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500461// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500462// Ops and instantiate them here.
Brian Osman407b3422017-08-22 15:01:32 -0400463bool GrRenderTargetOpList::onExecute(GrOpFlushState* flushState) {
Greg Danieldbdba602018-04-20 11:52:43 -0400464 // TODO: Forcing the execution of the discard here isn't ideal since it will cause us to do a
465 // discard and then store the data back in memory so that the load op on future draws doesn't
466 // think the memory is unitialized. Ideally we would want a system where we are tracking whether
467 // the proxy itself has valid data or not, and then use that as a signal on whether we should be
468 // loading or discarding. In that world we wouldni;t need to worry about executing oplists with
469 // no ops just to do a discard.
Brian Salomon588cec72018-11-14 13:56:37 -0500470 if (fOpChains.empty() && GrLoadOp::kClear != fColorLoadOp &&
Greg Danieldbdba602018-04-20 11:52:43 -0400471 GrLoadOp::kDiscard != fColorLoadOp) {
bsalomondc438982016-08-31 11:53:49 -0700472 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700473 }
Robert Phillips4a395042017-04-24 16:27:17 +0000474
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400475 SkASSERT(fTarget.get()->peekRenderTarget());
Stan Iliev2af578d2017-08-16 13:00:28 -0400476 TRACE_EVENT0("skia", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400477
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500478 // Make sure load ops are not kClear if the GPU needs to use draws for clears
479 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
480 !flushState->gpu()->caps()->performColorClearsAsDraws());
481 SkASSERT(fStencilLoadOp != GrLoadOp::kClear ||
482 !flushState->gpu()->caps()->performStencilClearsAsDraws());
Chris Dalton7b2c8552019-05-13 15:49:33 -0600483
484 GrRenderTarget* renderTarget = fTarget.get()->peekRenderTarget();
485 GrStencilAttachment* stencil = renderTarget->renderTargetPriv().getStencilAttachment();
486 GrLoadOp stencilLoadOp = fStencilLoadOp;
487 if (stencil && GrLoadOp::kClear == stencilLoadOp && !stencil->userBitsAreDirty()) {
488 if (!flushState->caps().preferFullscreenClears()) {
489 stencilLoadOp = GrLoadOp::kLoad;
490 }
491 }
492
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400493 GrGpuRTCommandBuffer* commandBuffer = create_command_buffer(
Chris Dalton7b2c8552019-05-13 15:49:33 -0600494 flushState->gpu(), renderTarget, fTarget.get()->origin(),
495 fTarget.get()->getBoundsRect(), fColorLoadOp, fLoadClearColor, stencilLoadOp,
496 fStencilStoreOp);
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400497 flushState->setCommandBuffer(commandBuffer);
Robert Phillips95214472017-08-08 18:00:03 -0400498 commandBuffer->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400499
500 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500501 for (const auto& chain : fOpChains) {
502 if (!chain.head()) {
bsalomonaecc0182016-03-07 11:50:44 -0800503 continue;
504 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400505#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon588cec72018-11-14 13:56:37 -0500506 TRACE_EVENT0("skia", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400507#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400508
Brian Salomon29b60c92017-10-31 14:42:10 -0400509 GrOpFlushState::OpArgs opArgs {
Brian Salomon588cec72018-11-14 13:56:37 -0500510 chain.head(),
Robert Phillips2890fbf2017-07-26 15:48:41 -0400511 fTarget.get()->asRenderTargetProxy(),
Brian Salomon588cec72018-11-14 13:56:37 -0500512 chain.appliedClip(),
513 chain.dstProxy()
Robert Phillips178ce3e2017-04-13 09:15:47 -0400514 };
515
Brian Salomon29b60c92017-10-31 14:42:10 -0400516 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500517 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400518 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700519 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400520
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400521 commandBuffer->end();
522 flushState->gpu()->submit(commandBuffer);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400523 flushState->setCommandBuffer(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800524
Chris Dalton7b2c8552019-05-13 15:49:33 -0600525 if (stencil && GrStoreOp::kStore == fStencilStoreOp) {
526 // The user stencil bits are always initialized and kept at zero for the duration of a
527 // command buffer. So if we store the stencil, we know we're storing clean user bits.
528 stencil->userBitsCleared();
529 }
530 // FIXME: We don't currently have a way to flag command buffers that don't use stencil at all.
531 // In that case, their store op will be discard, and we currently make the assumption that a
532 // store op of "discard" will not invalidate what's already in main memory. This is probably ok
533 // for now, but certainly something we want to address soon.
534
bsalomondc438982016-08-31 11:53:49 -0700535 return true;
bsalomona73239a2015-04-28 13:35:17 -0700536}
537
Chris Daltona84cacf2017-10-04 10:30:29 -0600538void GrRenderTargetOpList::endFlush() {
Brian Salomonc3833b42018-07-09 18:23:58 +0000539 fLastClipStackGenID = SK_InvalidUniqueID;
Robert Phillipsc994a932018-06-19 13:09:54 -0400540 this->deleteOps();
Chris Daltonc82dd4e2017-11-20 18:20:28 -0700541 fClipAllocator.reset();
Chris Daltona84cacf2017-10-04 10:30:29 -0600542 INHERITED::endFlush();
bsalomon512be532015-09-10 10:42:55 -0700543}
544
Robert Phillips380b90c2017-08-30 07:41:07 -0400545void GrRenderTargetOpList::discard() {
546 // Discard calls to in-progress opLists are ignored. Calls at the start update the
547 // opLists' color & stencil load ops.
548 if (this->isEmpty()) {
549 fColorLoadOp = GrLoadOp::kDiscard;
550 fStencilLoadOp = GrLoadOp::kDiscard;
551 }
552}
553
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500554void GrRenderTargetOpList::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) {
555 fColorLoadOp = op;
556 fLoadClearColor = color;
557}
558
559bool GrRenderTargetOpList::resetForFullscreenClear() {
560 // Mark the color load op as discard (this may be followed by a clearColorOnLoad call to make
561 // the load op kClear, or it may be followed by an explicit op). In the event of an absClear()
562 // after a regular clear(), we could end up with a clear load op and a real clear op in the list
563 // if the load op were not reset here.
564 fColorLoadOp = GrLoadOp::kDiscard;
565
566 // Regardless of how the clear is implemented (native clear or a fullscreen quad), all prior ops
567 // would be overwritten, so discard them entirely. The one exception is if the opList is marked
568 // as needing a stencil buffer then there may be a prior op that writes to the stencil buffer.
569 // Although the clear will ignore the stencil buffer, following draw ops may not so we can't get
570 // rid of all the preceding ops. Beware! If we ever add any ops that have a side effect beyond
571 // modifying the stencil buffer we will need a more elaborate tracking system (skbug.com/7002).
Greg Danielcb324152019-02-25 11:36:53 -0500572 // Additionally, if we previously recorded a wait op, we cannot delete the wait op. Until we
573 // track the wait ops separately from normal ops, we have to avoid clearing out any ops.
574 if (this->isEmpty() || (!fTarget.get()->asRenderTargetProxy()->needsStencil() && !fHasWaitOp)) {
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.
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500581 return !fTarget.get()->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 Phillipsa16f6cb2017-06-01 11:06:13 -0400593 GrSurfaceProxy* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400594 GrSurfaceProxy* src,
Robert Phillipsf2361d22016-10-25 14:20:06 -0400595 const SkIRect& srcRect,
596 const SkIPoint& dstPoint) {
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400597 SkASSERT(dst->asRenderTargetProxy() == fTarget.get());
Robert Phillips7c525e62018-06-12 10:11:12 -0400598 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(context, dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500599 if (!op) {
bsalomonb8fea972016-02-16 07:34:17 -0800600 return false;
601 }
robertphillips498d7ac2015-10-30 10:11:30 -0700602
Robert Phillips9da87e02019-02-04 13:26:26 -0500603 this->addOp(std::move(op), *context->priv().caps());
bsalomonb8fea972016-02-16 07:34:17 -0800604 return true;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000605}
606
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500607void GrRenderTargetOpList::purgeOpsWithUninstantiatedProxies() {
608 bool hasUninstantiatedProxy = false;
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400609 auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p) {
610 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;
Brian Salomon588cec72018-11-14 13:56:37 -0500616 recordedOp.visitProxies(checkInstantiation, GrOp::VisitorType::kOther);
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
627 auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p) {
628 if (p == proxyToCheck) {
629 used = true;
630 }
631 };
632 for (const OpChain& recordedOp : fOpChains) {
633 recordedOp.visitProxies(visit, GrOp::VisitorType::kOther);
634 }
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 Dalton8816b932017-11-29 16:48:25 -0700666 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p) {
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
672 recordedOp.visitProxies(gather, GrOp::VisitorType::kAllocatorGather);
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 Phillips318c4192017-05-17 09:36:38 -0400685 SkASSERT(fTarget.get());
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 Phillips5efd5ea2017-05-30 13:47:32 -0400698 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->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