blob: ab5c7cbe06dcec8dd24dd1cc3f7c96ac18856155 [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
Robert Phillips3e87a8e2021-08-25 13:22:24 -04008#include "src/gpu/ops/OpsTask.h"
Brian Salomon4d2d6f42019-07-26 14:15:11 -04009
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040010#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/core/SkRectPriv.h"
Herb Derby93250092021-04-06 12:19:20 -040012#include "src/core/SkScopeExit.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/core/SkTraceEvent.h"
Greg Danielc0d69152020-10-08 14:59:00 -040014#include "src/gpu/GrAttachment.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040015#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/GrCaps.h"
17#include "src/gpu/GrGpu.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrMemoryPool.h"
Greg Daniele227fe42019-08-21 13:52:24 -040019#include "src/gpu/GrOpFlushState.h"
Greg Daniel2d41d0d2019-08-26 11:08:51 -040020#include "src/gpu/GrOpsRenderPass.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/gpu/GrRecordingContextPriv.h"
Chris Dalton674f77a2019-09-30 20:49:39 -060022#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/GrResourceAllocator.h"
Robert Phillips1a82a4e2021-07-01 10:27:44 -040024#include "src/gpu/GrResourceProvider.h"
Brian 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
Robert Phillips3e87a8e2021-08-25 13:22:24 -040031namespace {
32
Brian Salomon09d994e2016-12-21 11:14:46 -050033// Experimentally we have found that most combining occurs within the first 10 comparisons.
Brian Salomon588cec72018-11-14 13:56:37 -050034static const int kMaxOpMergeDistance = 10;
35static const int kMaxOpChainDistance = 10;
36
37////////////////////////////////////////////////////////////////////////////////
38
Robert Phillips3e87a8e2021-08-25 13:22:24 -040039inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
40
41GrOpsRenderPass* create_render_pass(GrGpu* gpu,
42 GrRenderTarget* rt,
43 bool useMSAASurface,
44 GrAttachment* stencil,
45 GrSurfaceOrigin origin,
46 const SkIRect& bounds,
47 GrLoadOp colorLoadOp,
48 const std::array<float, 4>& loadClearColor,
49 GrLoadOp stencilLoadOp,
50 GrStoreOp stencilStoreOp,
51 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
52 GrXferBarrierFlags renderPassXferBarriers) {
53 const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo {
54 colorLoadOp,
55 GrStoreOp::kStore,
56 loadClearColor
57 };
58
59 // TODO:
60 // We would like to (at this level) only ever clear & discard. We would need
61 // to stop splitting up higher level OpsTasks for copyOps to achieve that.
62 // Note: we would still need SB loads and stores but they would happen at a
63 // lower level (inside the VK command buffer).
64 const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
65 stencilLoadOp,
66 stencilStoreOp,
67 };
68
69 return gpu->getOpsRenderPass(rt, useMSAASurface, stencil, origin, bounds, kColorLoadStoreInfo,
70 stencilLoadAndStoreInfo, sampledProxies, renderPassXferBarriers);
71}
72
73} // anonymous namespace
Brian Salomon588cec72018-11-14 13:56:37 -050074
75////////////////////////////////////////////////////////////////////////////////
76
Robert Phillips3e87a8e2021-08-25 13:22:24 -040077namespace skgpu::v1 {
78
79inline OpsTask::OpChain::List::List(GrOp::Owner op)
Brian Salomon588cec72018-11-14 13:56:37 -050080 : fHead(std::move(op)), fTail(fHead.get()) {
81 this->validate();
82}
83
Robert Phillips3e87a8e2021-08-25 13:22:24 -040084inline OpsTask::OpChain::List::List(List&& that) { *this = std::move(that); }
Brian Salomon588cec72018-11-14 13:56:37 -050085
Robert Phillips3e87a8e2021-08-25 13:22:24 -040086inline OpsTask::OpChain::List& OpsTask::OpChain::List::operator=(List&& that) {
Brian Salomon588cec72018-11-14 13:56:37 -050087 fHead = std::move(that.fHead);
88 fTail = that.fTail;
89 that.fTail = nullptr;
90 this->validate();
91 return *this;
92}
93
Robert Phillips3e87a8e2021-08-25 13:22:24 -040094inline GrOp::Owner OpsTask::OpChain::List::popHead() {
Brian Salomon588cec72018-11-14 13:56:37 -050095 SkASSERT(fHead);
96 auto temp = fHead->cutChain();
97 std::swap(temp, fHead);
98 if (!fHead) {
99 SkASSERT(fTail == temp.get());
100 fTail = nullptr;
101 }
102 return temp;
103}
104
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400105inline GrOp::Owner OpsTask::OpChain::List::removeOp(GrOp* op) {
Brian Salomon588cec72018-11-14 13:56:37 -0500106#ifdef SK_DEBUG
107 auto head = op;
108 while (head->prevInChain()) { head = head->prevInChain(); }
109 SkASSERT(head == fHead.get());
110#endif
111 auto prev = op->prevInChain();
112 if (!prev) {
113 SkASSERT(op == fHead.get());
114 return this->popHead();
115 }
116 auto temp = prev->cutChain();
117 if (auto next = temp->cutChain()) {
118 prev->chainConcat(std::move(next));
119 } else {
120 SkASSERT(fTail == op);
121 fTail = prev;
122 }
123 this->validate();
124 return temp;
125}
126
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400127inline void OpsTask::OpChain::List::pushHead(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -0500128 SkASSERT(op);
129 SkASSERT(op->isChainHead());
130 SkASSERT(op->isChainTail());
131 if (fHead) {
132 op->chainConcat(std::move(fHead));
133 fHead = std::move(op);
134 } else {
135 fHead = std::move(op);
136 fTail = fHead.get();
137 }
138}
139
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400140inline void OpsTask::OpChain::List::pushTail(GrOp::Owner op) {
Brian Salomon588cec72018-11-14 13:56:37 -0500141 SkASSERT(op->isChainTail());
142 fTail->chainConcat(std::move(op));
143 fTail = fTail->nextInChain();
144}
145
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400146inline void OpsTask::OpChain::List::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500147#ifdef SK_DEBUG
148 if (fHead) {
149 SkASSERT(fTail);
150 fHead->validateChain(fTail);
151 }
152#endif
153}
154
155////////////////////////////////////////////////////////////////////////////////
156
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400157OpsTask::OpChain::OpChain(GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
158 GrAppliedClip* appliedClip, const GrDstProxyView* dstProxyView)
Chris Dalton945ee652019-01-23 09:10:36 -0700159 : fList{std::move(op)}
160 , fProcessorAnalysis(processorAnalysis)
161 , fAppliedClip(appliedClip) {
162 if (fProcessorAnalysis.requiresDstTexture()) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400163 SkASSERT(dstProxyView && dstProxyView->proxy());
164 fDstProxyView = *dstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500165 }
166 fBounds = fList.head()->bounds();
167}
168
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400169void OpsTask::OpChain::visitProxies(const GrVisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500170 if (fList.empty()) {
171 return;
172 }
173 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600174 op.visitProxies(func);
Brian Salomon588cec72018-11-14 13:56:37 -0500175 }
Greg Daniel524e28b2019-11-01 11:48:53 -0400176 if (fDstProxyView.proxy()) {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400177 func(fDstProxyView.proxy(), GrMipmapped::kNo);
Brian Salomon588cec72018-11-14 13:56:37 -0500178 }
179 if (fAppliedClip) {
180 fAppliedClip->visitProxies(func);
181 }
182}
183
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400184void OpsTask::OpChain::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500185 while (!fList.empty()) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400186 // Since the value goes out of scope immediately, the GrOp::Owner deletes the op.
187 fList.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500188 }
189}
190
191// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
192// the two chains are chainable. Returns the new chain.
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400193OpsTask::OpChain::List OpsTask::OpChain::DoConcat(List chainA, List chainB, const GrCaps& caps,
194 SkArenaAlloc* opsTaskArena,
195 GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500196 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
197 // at chain a's tail and working toward the head. We produce one of the following outcomes:
198 // 1) b's head is merged into an op in a.
199 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
200 // 3) b's head is popped from chain a and added at the tail of a.
201 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
202 // as we assume merges were already attempted when chain b was created. So we keep track of the
203 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
204 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
205 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
206 GrOp* origATail = chainA.tail();
207 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
208 do {
209 int numMergeChecks = 0;
210 bool merged = false;
211 bool noSkip = (origATail == chainA.tail());
212 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
213 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
214 SkRect forwardMergeBounds = skipBounds;
215 GrOp* a = origATail;
216 while (a) {
217 bool canForwardMerge =
218 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
219 if (canForwardMerge || canBackwardMerge) {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600220 auto result = a->combineIfPossible(chainB.head(), opsTaskArena, caps);
Brian Salomon588cec72018-11-14 13:56:37 -0500221 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
222 merged = (result == GrOp::CombineResult::kMerged);
Robert Phillips9548c3b422019-01-08 12:35:43 -0500223 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Brian Salomon588cec72018-11-14 13:56:37 -0500224 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
225 a->uniqueID());
Brian Salomon588cec72018-11-14 13:56:37 -0500226 }
227 if (merged) {
Brian Salomon52a6ed32018-11-26 10:30:58 -0500228 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
Brian Salomon588cec72018-11-14 13:56:37 -0500229 if (canBackwardMerge) {
Herb Derbyc76d4092020-10-07 16:46:15 -0400230 // The GrOp::Owner releases the op.
231 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500232 } else {
233 // We merged the contents of b's head into a. We will replace b's head with a in
234 // chain b.
235 SkASSERT(canForwardMerge);
236 if (a == origATail) {
237 origATail = a->prevInChain();
238 }
Herb Derbyc76d4092020-10-07 16:46:15 -0400239 GrOp::Owner detachedA = chainA.removeOp(a);
240 // The GrOp::Owner releases the op.
241 chainB.popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500242 chainB.pushHead(std::move(detachedA));
243 if (chainA.empty()) {
244 // We merged all the nodes in chain a to chain b.
245 return chainB;
246 }
247 }
248 break;
249 } else {
250 if (++numMergeChecks == kMaxOpMergeDistance) {
251 break;
252 }
253 forwardMergeBounds.joinNonEmptyArg(a->bounds());
254 canBackwardMerge =
255 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
256 a = a->prevInChain();
257 }
258 }
259 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
260 // tail of a.
261 if (!merged) {
262 chainA.pushTail(chainB.popHead());
263 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
264 }
265 } while (!chainB.empty());
266 return chainA;
267}
268
Chris Dalton945ee652019-01-23 09:10:36 -0700269// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
270// whether the operation succeeded. On success, the provided list will be returned empty.
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400271bool OpsTask::OpChain::tryConcat(
John Stiles52cb1d02021-06-02 11:58:05 -0400272 List* list, GrProcessorSet::Analysis processorAnalysis, const GrDstProxyView& dstProxyView,
Chris Dalton945ee652019-01-23 09:10:36 -0700273 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600274 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700275 SkASSERT(!fList.empty());
276 SkASSERT(!list->empty());
Greg Daniel524e28b2019-11-01 11:48:53 -0400277 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy()));
278 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy()));
Brian Salomon588cec72018-11-14 13:56:37 -0500279 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700280 if (fList.head()->classID() != list->head()->classID() ||
281 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
282 (fAppliedClip && *fAppliedClip != *appliedClip) ||
Chris Dalton945ee652019-01-23 09:10:36 -0700283 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
284 processorAnalysis.requiresNonOverlappingDraws()) ||
285 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
286 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
287 // or read back a new dst texture between draws. In either case, we can neither
288 // chain nor combine overlapping Ops.
289 GrRectsTouchOrOverlap(fBounds, bounds)) ||
290 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
Greg Daniel524e28b2019-11-01 11:48:53 -0400291 (fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700292 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500293 }
Chris Daltonee21e6b2019-01-22 14:04:43 -0700294
Brian Salomon588cec72018-11-14 13:56:37 -0500295 SkDEBUGCODE(bool first = true;)
296 do {
Chris Daltonf8d75c62021-04-02 11:24:58 -0600297 switch (fList.tail()->combineIfPossible(list->head(), opsTaskArena, caps))
Herb Derbye25c3002020-10-27 15:57:27 -0400298 {
Brian Salomon588cec72018-11-14 13:56:37 -0500299 case GrOp::CombineResult::kCannotCombine:
300 // If an op supports chaining then it is required that chaining is transitive and
301 // that if any two ops in two different chains can merge then the two chains
302 // may also be chained together. Thus, we should only hit this on the first
303 // iteration.
304 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700305 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500306 case GrOp::CombineResult::kMayChain:
Chris Daltonf8d75c62021-04-02 11:24:58 -0600307 fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, opsTaskArena,
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500308 auditTrail);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700309 // The above exchange cleared out 'list'. The list needs to be empty now for the
310 // loop to terminate.
311 SkASSERT(list->empty());
312 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500313 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500314 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700315 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
316 list->head()->uniqueID());
317 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
Herb Derbyc76d4092020-10-07 16:46:15 -0400318 // The GrOp::Owner releases the op.
319 list->popHead();
Brian Salomon588cec72018-11-14 13:56:37 -0500320 break;
321 }
322 }
323 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700324 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700325
326 // The new ops were successfully merged and/or chained onto our own.
327 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700328 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500329}
330
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400331bool OpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, SkArenaAlloc* opsTaskArena,
332 GrAuditTrail* auditTrail) {
Greg Daniel524e28b2019-11-01 11:48:53 -0400333 if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600334 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500335 this->validate();
336 // append failed
337 return false;
338 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700339
Brian Salomon588cec72018-11-14 13:56:37 -0500340 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700341 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500342 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700343 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500344
Greg Daniel524e28b2019-11-01 11:48:53 -0400345 that->fDstProxyView.setProxyView({});
John Stiles59e18dc2020-07-22 18:18:12 -0400346 if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) {
347 // Obliterates the processor.
348 that->fAppliedClip->detachCoverageFragmentProcessor();
Brian Salomon588cec72018-11-14 13:56:37 -0500349 }
350 this->validate();
351 return true;
352}
353
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400354GrOp::Owner OpsTask::OpChain::appendOp(
Herb Derbyc76d4092020-10-07 16:46:15 -0400355 GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
John Stiles52cb1d02021-06-02 11:58:05 -0400356 const GrDstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps,
Chris Daltonf8d75c62021-04-02 11:24:58 -0600357 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
John Stiles52cb1d02021-06-02 11:58:05 -0400358 const GrDstProxyView noDstProxyView;
Greg Daniel524e28b2019-11-01 11:48:53 -0400359 if (!dstProxyView) {
360 dstProxyView = &noDstProxyView;
Brian Salomon588cec72018-11-14 13:56:37 -0500361 }
362 SkASSERT(op->isChainHead() && op->isChainTail());
363 SkRect opBounds = op->bounds();
364 List chain(std::move(op));
Chris Daltonf8d75c62021-04-02 11:24:58 -0600365 if (!this->tryConcat(&chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps,
366 opsTaskArena, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500367 // append failed, give the op back to the caller.
368 this->validate();
369 return chain.popHead();
370 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700371
372 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500373 this->validate();
374 return nullptr;
375}
376
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400377inline void OpsTask::OpChain::validate() const {
Brian Salomon588cec72018-11-14 13:56:37 -0500378#ifdef SK_DEBUG
379 fList.validate();
380 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
381 // Not using SkRect::contains because we allow empty rects.
382 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
383 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
384 }
385#endif
386}
387
388////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800389
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400390OpsTask::OpsTask(GrDrawingManager* drawingMgr,
391 GrSurfaceProxyView view,
392 GrAuditTrail* auditTrail,
393 sk_sp<GrArenas> arenas)
Adlai Holler33d569e2020-06-16 14:30:08 -0400394 : GrRenderTask()
Greg Danielf41b2bd2019-08-22 16:19:24 -0400395 , fAuditTrail(auditTrail)
Chris Dalton2517ce32021-04-13 00:21:15 -0600396 , fUsesMSAASurface(view.asRenderTargetProxy()->numSamples() > 1)
Brian Salomon982127b2021-01-21 10:43:35 -0500397 , fTargetSwizzle(view.swizzle())
398 , fTargetOrigin(view.origin())
Herb Derby0b1228d2021-04-05 18:38:35 -0400399 , fArenas{std::move(arenas)}
Brian Salomon982127b2021-01-21 10:43:35 -0500400 SkDEBUGCODE(, fNumClips(0)) {
401 this->addTarget(drawingMgr, view.detachProxy());
bsalomon4061b122015-05-29 10:26:19 -0700402}
403
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400404void OpsTask::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500405 for (auto& chain : fOpChains) {
Herb Derbye32e1ab2020-10-27 10:29:46 -0400406 chain.deleteOps();
Robert Phillipsc994a932018-06-19 13:09:54 -0400407 }
Brian Salomon588cec72018-11-14 13:56:37 -0500408 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400409}
410
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400411OpsTask::~OpsTask() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400412 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000413}
414
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400415void OpsTask::addOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
416 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500417 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
418 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
419 };
420
421 op->visitProxies(addDependency);
422
Chris Dalton83420eb2021-06-23 18:47:09 -0600423 this->recordOp(std::move(op), false/*usesMSAA*/, GrProcessorSet::EmptySetAnalysis(), nullptr,
424 nullptr, caps);
Adlai Hollerabe45182020-11-17 09:22:13 -0500425}
426
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400427void OpsTask::addDrawOp(GrDrawingManager* drawingMgr, GrOp::Owner op, bool usesMSAA,
428 const GrProcessorSet::Analysis& processorAnalysis, GrAppliedClip&& clip,
429 const GrDstProxyView& dstProxyView,
430 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500431 auto addDependency = [&](GrSurfaceProxy* p, GrMipmapped mipmapped) {
432 this->addSampledTexture(p);
433 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
434 };
435
436 op->visitProxies(addDependency);
437 clip.visitProxies(addDependency);
438 if (dstProxyView.proxy()) {
Greg Daniel87fab9f2021-06-07 15:18:23 -0400439 if (!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment)) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500440 this->addSampledTexture(dstProxyView.proxy());
441 }
Greg Daniel87fab9f2021-06-07 15:18:23 -0400442 if (dstProxyView.dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) {
Adlai Hollerabe45182020-11-17 09:22:13 -0500443 fRenderPassXferBarriers |= GrXferBarrierFlags::kTexture;
444 }
Greg Daniel87fab9f2021-06-07 15:18:23 -0400445 addDependency(dstProxyView.proxy(), GrMipmapped::kNo);
446 SkASSERT(!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment) ||
Adlai Hollerabe45182020-11-17 09:22:13 -0500447 dstProxyView.offset().isZero());
448 }
449
450 if (processorAnalysis.usesNonCoherentHWBlending()) {
451 fRenderPassXferBarriers |= GrXferBarrierFlags::kBlend;
452 }
453
Chris Dalton83420eb2021-06-23 18:47:09 -0600454 this->recordOp(std::move(op), usesMSAA, processorAnalysis, clip.doesClip() ? &clip : nullptr,
Adlai Hollerabe45182020-11-17 09:22:13 -0500455 &dstProxyView, caps);
456}
457
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400458void OpsTask::endFlush(GrDrawingManager* drawingMgr) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400459 fLastClipStackGenID = SK_InvalidUniqueID;
460 this->deleteOps();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700461
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500462 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400463 fSampledProxies.reset();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400464 fAuditTrail = nullptr;
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400465
466 GrRenderTask::endFlush(drawingMgr);
Greg Danielf21bf9e2019-08-22 20:12:20 +0000467}
468
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400469void OpsTask::onPrePrepare(GrRecordingContext* context) {
Robert Phillips7327c9d2019-10-08 16:32:56 -0400470 SkASSERT(this->isClosed());
Robert Phillips7327c9d2019-10-08 16:32:56 -0400471 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400472 // can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation
Robert Phillips7327c9d2019-10-08 16:32:56 -0400473 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400474 // we shouldn't end up with OpsTasks with only discard.
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400475 if (this->isColorNoOp() ||
476 (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
Robert Phillips7327c9d2019-10-08 16:32:56 -0400477 return;
478 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500479 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400480
Brian Salomon982127b2021-01-21 10:43:35 -0500481 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400482 for (const auto& chain : fOpChains) {
483 if (chain.shouldExecute()) {
Robert Phillips8053c972019-11-21 10:44:53 -0500484 chain.head()->prePrepare(context,
Brian Salomon982127b2021-01-21 10:43:35 -0500485 dstView,
Robert Phillips8053c972019-11-21 10:44:53 -0500486 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400487 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500488 fRenderPassXferBarriers,
489 fColorLoadOp);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400490 }
491 }
492}
493
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400494void OpsTask::onPrepare(GrOpFlushState* flushState) {
Brian Salomon982127b2021-01-21 10:43:35 -0500495 SkASSERT(this->target(0)->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400496 SkASSERT(this->isClosed());
Greg Daniel94ed83f2019-09-27 13:05:43 -0400497 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400498 // can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation
Greg Daniel94ed83f2019-09-27 13:05:43 -0400499 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400500 // we shouldn't end up with OpsTasks with only discard.
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400501 if (this->isColorNoOp() ||
502 (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
Greg Daniel94ed83f2019-09-27 13:05:43 -0400503 return;
504 }
Greg Daniel0a0ad5b2021-01-29 22:49:30 -0500505 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
robertphillipsa106c622015-10-16 09:07:06 -0700506
Greg Danielb20d7e52019-09-03 13:54:39 -0400507 flushState->setSampledProxyArray(&fSampledProxies);
Brian Salomon982127b2021-01-21 10:43:35 -0500508 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500509 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500510 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400511 if (chain.shouldExecute()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400512#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400513 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400514#endif
Robert Phillips901aff02019-10-08 12:32:56 -0400515 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500516 dstView,
Chris Dalton2517ce32021-04-13 00:21:15 -0600517 fUsesMSAASurface,
Robert Phillips901aff02019-10-08 12:32:56 -0400518 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400519 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500520 fRenderPassXferBarriers,
521 fColorLoadOp);
Robert Phillips405413f2019-10-04 10:39:28 -0400522
Brian Salomon29b60c92017-10-31 14:42:10 -0400523 flushState->setOpArgs(&opArgs);
Robert Phillipsdf70f152019-11-15 14:57:05 -0500524
525 // Temporary debugging helper: for debugging prePrepare w/o going through DDLs
526 // Delete once most of the GrOps have an onPrePrepare.
Adlai Holler33d569e2020-06-16 14:30:08 -0400527 // chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0),
Robert Phillipsdf70f152019-11-15 14:57:05 -0500528 // chain.appliedClip());
529
Robert Phillips7327c9d2019-10-08 16:32:56 -0400530 // GrOp::prePrepare may or may not have been called at this point
Brian Salomon588cec72018-11-14 13:56:37 -0500531 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400532 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800533 }
bsalomon512be532015-09-10 10:42:55 -0700534 }
Greg Danielb20d7e52019-09-03 13:54:39 -0400535 flushState->setSampledProxyArray(nullptr);
robertphillipsa13e2022015-11-11 12:01:09 -0800536}
bsalomon512be532015-09-10 10:42:55 -0700537
Brian Salomon25a88092016-12-01 09:36:50 -0500538// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500539// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500540// Ops and instantiate them here.
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400541bool OpsTask::onExecute(GrOpFlushState* flushState) {
Herb Derby93250092021-04-06 12:19:20 -0400542 SkASSERT(this->numTargets() == 1);
543 GrRenderTargetProxy* proxy = this->target(0)->asRenderTargetProxy();
544 SkASSERT(proxy);
545 SK_AT_SCOPE_EXIT(proxy->clearArenas());
546
Greg Daniel94ed83f2019-09-27 13:05:43 -0400547 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400548 // can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation
Greg Daniel94ed83f2019-09-27 13:05:43 -0400549 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400550 // we shouldn't end up with OpsTasks with only discard.
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400551 if (this->isColorNoOp() ||
552 (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
bsalomondc438982016-08-31 11:53:49 -0700553 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700554 }
Robert Phillips4a395042017-04-24 16:27:17 +0000555
Brian Salomon5f394272019-07-02 14:07:49 -0400556 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400557
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500558 // Make sure load ops are not kClear if the GPU needs to use draws for clears
559 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
560 !flushState->gpu()->caps()->performColorClearsAsDraws());
Chris Dalton674f77a2019-09-30 20:49:39 -0600561
562 const GrCaps& caps = *flushState->gpu()->caps();
Greg Daniel16f5c652019-10-29 11:26:01 -0400563 GrRenderTarget* renderTarget = proxy->peekRenderTarget();
Chris Dalton674f77a2019-09-30 20:49:39 -0600564 SkASSERT(renderTarget);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700565
Greg Danielc0d69152020-10-08 14:59:00 -0400566 GrAttachment* stencil = nullptr;
Chris Dalton57ab06c2021-04-22 12:57:28 -0600567 if (proxy->needsStencil()) {
Chris Dalton537293bf2021-05-03 15:54:24 -0600568 SkASSERT(proxy->canUseStencil(caps));
Chris Daltone0fe23a2021-04-23 13:11:44 -0600569 if (!flushState->resourceProvider()->attachStencilAttachment(renderTarget,
570 fUsesMSAASurface)) {
Chris Dalton0b68dda2019-11-07 21:08:03 -0700571 SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n");
572 return false;
573 }
Chris Daltone0fe23a2021-04-23 13:11:44 -0600574 stencil = renderTarget->getStencilAttachment(fUsesMSAASurface);
Chris Dalton0b68dda2019-11-07 21:08:03 -0700575 }
576
Chris Dalton674f77a2019-09-30 20:49:39 -0600577 GrLoadOp stencilLoadOp;
578 switch (fInitialStencilContent) {
579 case StencilContent::kDontCare:
580 stencilLoadOp = GrLoadOp::kDiscard;
581 break;
582 case StencilContent::kUserBitsCleared:
583 SkASSERT(!caps.performStencilClearsAsDraws());
584 SkASSERT(stencil);
585 if (caps.discardStencilValuesAfterRenderPass()) {
586 // Always clear the stencil if it is being discarded after render passes. This is
587 // also an optimization because we are on a tiler and it avoids loading the values
588 // from memory.
589 stencilLoadOp = GrLoadOp::kClear;
590 break;
591 }
592 if (!stencil->hasPerformedInitialClear()) {
593 stencilLoadOp = GrLoadOp::kClear;
594 stencil->markHasPerformedInitialClear();
595 break;
596 }
John Stiles0fbc6a32021-06-04 14:40:57 -0400597 // SurfaceDrawContexts are required to leave the user stencil bits in a cleared state
Chris Dalton674f77a2019-09-30 20:49:39 -0600598 // once finished, meaning the stencil values will always remain cleared after the
599 // initial clear. Just fall through to reloading the existing (cleared) stencil values
600 // from memory.
John Stiles30212b72020-06-11 17:55:07 -0400601 [[fallthrough]];
Chris Dalton674f77a2019-09-30 20:49:39 -0600602 case StencilContent::kPreserved:
603 SkASSERT(stencil);
604 stencilLoadOp = GrLoadOp::kLoad;
605 break;
606 }
607
Brian Salomon1aa1f5f2020-12-11 17:25:17 -0500608 // NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split
Chris Dalton674f77a2019-09-30 20:49:39 -0600609 // its opsTask.
610 //
611 // FIXME: We don't currently flag render passes that don't use stencil at all. In that case
612 // their store op might be "discard", and we currently make the assumption that a discard will
613 // not invalidate what's already in main memory. This is probably ok for now, but certainly
614 // something we want to address soon.
615 GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil)
616 ? GrStoreOp::kDiscard
617 : GrStoreOp::kStore;
618
Brian Salomon982127b2021-01-21 10:43:35 -0500619 GrOpsRenderPass* renderPass = create_render_pass(flushState->gpu(),
620 proxy->peekRenderTarget(),
Chris Dalton2517ce32021-04-13 00:21:15 -0600621 fUsesMSAASurface,
Brian Salomon982127b2021-01-21 10:43:35 -0500622 stencil,
623 fTargetOrigin,
624 fClippedContentBounds,
625 fColorLoadOp,
626 fLoadClearColor,
627 stencilLoadOp,
628 stencilStoreOp,
629 fSampledProxies,
630 fRenderPassXferBarriers);
Greg Daniel21774362020-09-14 10:36:43 -0400631
Greg Danielfa3adf72019-11-07 09:53:41 -0500632 if (!renderPass) {
633 return false;
634 }
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400635 flushState->setOpsRenderPass(renderPass);
636 renderPass->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400637
Brian Salomon982127b2021-01-21 10:43:35 -0500638 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
639
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400640 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500641 for (const auto& chain : fOpChains) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400642 if (!chain.shouldExecute()) {
bsalomonaecc0182016-03-07 11:50:44 -0800643 continue;
644 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400645#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon5f394272019-07-02 14:07:49 -0400646 TRACE_EVENT0("skia.gpu", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400647#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400648
Robert Phillips405413f2019-10-04 10:39:28 -0400649 GrOpFlushState::OpArgs opArgs(chain.head(),
Brian Salomon982127b2021-01-21 10:43:35 -0500650 dstView,
Chris Dalton2517ce32021-04-13 00:21:15 -0600651 fUsesMSAASurface,
Robert Phillips405413f2019-10-04 10:39:28 -0400652 chain.appliedClip(),
Greg Danield358cbe2020-09-11 09:33:54 -0400653 chain.dstProxyView(),
Greg Daniel42dbca52020-11-20 10:22:43 -0500654 fRenderPassXferBarriers,
655 fColorLoadOp);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400656
Brian Salomon29b60c92017-10-31 14:42:10 -0400657 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500658 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400659 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700660 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400661
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400662 renderPass->end();
663 flushState->gpu()->submit(renderPass);
664 flushState->setOpsRenderPass(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800665
bsalomondc438982016-08-31 11:53:49 -0700666 return true;
bsalomona73239a2015-04-28 13:35:17 -0700667}
668
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400669void OpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500670 fColorLoadOp = op;
671 fLoadClearColor = color;
Chris Dalton16a33c62019-09-24 22:19:17 -0600672 if (GrLoadOp::kClear == fColorLoadOp) {
Brian Salomon982127b2021-01-21 10:43:35 -0500673 GrSurfaceProxy* proxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400674 SkASSERT(proxy);
Michael Ludwigd1d997e2020-06-04 15:52:44 -0400675 fTotalBounds = proxy->backingStoreBoundsRect();
Chris Dalton16a33c62019-09-24 22:19:17 -0600676 }
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500677}
678
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400679void OpsTask::reset() {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500680 fDeferredProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500681 fSampledProxies.reset();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500682 fClippedContentBounds = SkIRect::MakeEmpty();
683 fTotalBounds = SkRect::MakeEmpty();
Adlai Holler026851a2021-03-29 14:47:11 -0400684 this->deleteOps();
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500685 fRenderPassXferBarriers = GrXferBarrierFlags::kNone;
686}
687
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400688bool OpsTask::canMerge(const OpsTask* opsTask) const {
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400689 return this->target(0) == opsTask->target(0) &&
690 fArenas == opsTask->fArenas &&
691 !opsTask->fCannotMergeBackward;
692}
693
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400694int OpsTask::mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks) {
Adlai Holler93439d92021-01-26 09:20:39 -0500695 int mergedCount = 0;
696 for (const sk_sp<GrRenderTask>& task : tasks) {
697 auto opsTask = task->asOpsTask();
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400698 if (!opsTask || !this->canMerge(opsTask)) {
Adlai Holler93439d92021-01-26 09:20:39 -0500699 break;
700 }
701 SkASSERT(fTargetSwizzle == opsTask->fTargetSwizzle);
702 SkASSERT(fTargetOrigin == opsTask->fTargetOrigin);
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500703 if (GrLoadOp::kClear == opsTask->fColorLoadOp) {
Adlai Hollerb0ada772021-04-23 17:02:24 -0400704 // TODO(11903): Go back to actually dropping ops tasks when we are merged with
705 // color clear.
706 return 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500707 }
Adlai Holler93439d92021-01-26 09:20:39 -0500708 mergedCount += 1;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500709 }
710 if (0 == mergedCount) {
711 return 0;
712 }
713
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400714 SkSpan<const sk_sp<OpsTask>> mergingNodes(
715 reinterpret_cast<const sk_sp<OpsTask>*>(tasks.data()), SkToSizeT(mergedCount));
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500716 int addlDeferredProxyCount = 0;
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500717 int addlProxyCount = 0;
718 int addlOpChainCount = 0;
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400719 for (const auto& toMerge : mergingNodes) {
720 addlDeferredProxyCount += toMerge->fDeferredProxies.count();
721 addlProxyCount += toMerge->fSampledProxies.count();
722 addlOpChainCount += toMerge->fOpChains.count();
723 fClippedContentBounds.join(toMerge->fClippedContentBounds);
724 fTotalBounds.join(toMerge->fTotalBounds);
725 fRenderPassXferBarriers |= toMerge->fRenderPassXferBarriers;
Chris Daltonffbeda72021-05-05 09:55:47 -0600726 if (fInitialStencilContent == StencilContent::kDontCare) {
727 // Propogate the first stencil content that isn't kDontCare.
728 //
729 // Once the stencil has any kind of initial content that isn't kDontCare, then the
730 // inital contents of subsequent opsTasks that get merged in don't matter.
731 //
732 // (This works because the opsTask all target the same render target and are in
733 // painter's order. kPreserved obviously happens automatically with a merge, and kClear
734 // is also automatic because the contract is for ops to leave the stencil buffer in a
735 // cleared state when finished.)
736 fInitialStencilContent = toMerge->fInitialStencilContent;
737 }
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400738 fUsesMSAASurface |= toMerge->fUsesMSAASurface;
739 SkDEBUGCODE(fNumClips += toMerge->fNumClips);
Adlai Holler93439d92021-01-26 09:20:39 -0500740 }
Adlai Holler9c3b6df2021-02-08 11:31:57 -0500741
Adlai Holler93439d92021-01-26 09:20:39 -0500742 fLastClipStackGenID = SK_InvalidUniqueID;
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500743 fDeferredProxies.reserve_back(addlDeferredProxyCount);
Adlai Holler93439d92021-01-26 09:20:39 -0500744 fSampledProxies.reserve_back(addlProxyCount);
745 fOpChains.reserve_back(addlOpChainCount);
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400746 for (const auto& toMerge : mergingNodes) {
747 for (GrRenderTask* renderTask : toMerge->dependents()) {
748 renderTask->replaceDependency(toMerge.get(), this);
749 }
750 for (GrRenderTask* renderTask : toMerge->dependencies()) {
751 renderTask->replaceDependent(toMerge.get(), this);
752 }
753 fDeferredProxies.move_back_n(toMerge->fDeferredProxies.count(),
754 toMerge->fDeferredProxies.data());
755 fSampledProxies.move_back_n(toMerge->fSampledProxies.count(),
756 toMerge->fSampledProxies.data());
757 fOpChains.move_back_n(toMerge->fOpChains.count(),
758 toMerge->fOpChains.data());
759 toMerge->fDeferredProxies.reset();
760 toMerge->fSampledProxies.reset();
761 toMerge->fOpChains.reset();
Adlai Holler93439d92021-01-26 09:20:39 -0500762 }
Herb Derbyf5b03fc2021-04-29 14:01:12 -0400763 fMustPreserveStencil = mergingNodes.back()->fMustPreserveStencil;
Adlai Holler93439d92021-01-26 09:20:39 -0500764 return mergedCount;
765}
766
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400767bool OpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
Chris Dalton6b982802019-06-27 13:53:46 -0600768 if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400769 this->deleteOps();
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500770 fDeferredProxies.reset();
Greg Danielb20d7e52019-09-03 13:54:39 -0400771 fSampledProxies.reset();
Greg Daniel070cbaf2019-01-03 17:35:54 -0500772
Greg Danielf41b2bd2019-08-22 16:19:24 -0400773 // If the opsTask is using a render target which wraps a vulkan command buffer, we can't do
774 // a clear load since we cannot change the render pass that we are using. Thus we fall back
775 // to making a clear op in this case.
Brian Salomon982127b2021-01-21 10:43:35 -0500776 return !this->target(0)->asRenderTargetProxy()->wrapsVkSecondaryCB();
bsalomonfd8d0132016-08-11 11:25:33 -0700777 }
Robert Phillips380b90c2017-08-30 07:41:07 -0400778
Greg Danielf41b2bd2019-08-22 16:19:24 -0400779 // Could not empty the task, so an op must be added to handle the clear
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500780 return false;
bsalomon9f129de2016-08-10 16:31:05 -0700781}
782
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400783void OpsTask::discard() {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400784 // Discard calls to in-progress opsTasks are ignored. Calls at the start update the
785 // opsTasks' color & stencil load ops.
786 if (this->isEmpty()) {
787 fColorLoadOp = GrLoadOp::kDiscard;
Chris Dalton674f77a2019-09-30 20:49:39 -0600788 fInitialStencilContent = StencilContent::kDontCare;
Chris Dalton16a33c62019-09-24 22:19:17 -0600789 fTotalBounds.setEmpty();
Greg Danielf41b2bd2019-08-22 16:19:24 -0400790 }
791}
792
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000793////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000794
John Stiles1e0136e2020-08-12 18:44:00 -0400795#if GR_TEST_UTILS
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400796void OpsTask::dump(const SkString& label,
797 SkString indent,
798 bool printDependencies,
799 bool close) const {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500800 GrRenderTask::dump(label, indent, printDependencies, false);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400801
Robert Phillips047d5bb2021-01-08 13:39:19 -0500802 SkDebugf("%sfColorLoadOp: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600803 switch (fColorLoadOp) {
804 case GrLoadOp::kLoad:
805 SkDebugf("kLoad\n");
806 break;
807 case GrLoadOp::kClear:
Brian Salomon07bc9a22020-12-02 13:37:16 -0500808 SkDebugf("kClear {%g, %g, %g, %g}\n",
809 fLoadClearColor[0],
810 fLoadClearColor[1],
811 fLoadClearColor[2],
812 fLoadClearColor[3]);
Chris Dalton674f77a2019-09-30 20:49:39 -0600813 break;
814 case GrLoadOp::kDiscard:
815 SkDebugf("kDiscard\n");
816 break;
817 }
818
Robert Phillips047d5bb2021-01-08 13:39:19 -0500819 SkDebugf("%sfInitialStencilContent: ", indent.c_str());
Chris Dalton674f77a2019-09-30 20:49:39 -0600820 switch (fInitialStencilContent) {
821 case StencilContent::kDontCare:
822 SkDebugf("kDontCare\n");
823 break;
824 case StencilContent::kUserBitsCleared:
825 SkDebugf("kUserBitsCleared\n");
826 break;
827 case StencilContent::kPreserved:
828 SkDebugf("kPreserved\n");
829 break;
830 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400831
Robert Phillips047d5bb2021-01-08 13:39:19 -0500832 SkDebugf("%s%d ops:\n", indent.c_str(), fOpChains.count());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400833 for (int i = 0; i < fOpChains.count(); ++i) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500834 SkDebugf("%s*******************************\n", indent.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400835 if (!fOpChains[i].head()) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500836 SkDebugf("%s%d: <combined forward or failed instantiation>\n", indent.c_str(), i);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400837 } else {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500838 SkDebugf("%s%d: %s\n", indent.c_str(), i, fOpChains[i].head()->name());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400839 SkRect bounds = fOpChains[i].bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500840 SkDebugf("%sClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
841 indent.c_str(),
842 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400843 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
844 SkString info = SkTabString(op.dumpInfo(), 1);
Robert Phillips047d5bb2021-01-08 13:39:19 -0500845 SkDebugf("%s%s\n", indent.c_str(), info.c_str());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400846 bounds = op.bounds();
Robert Phillips047d5bb2021-01-08 13:39:19 -0500847 SkDebugf("%s\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
848 indent.c_str(),
849 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400850 }
851 }
852 }
Robert Phillips047d5bb2021-01-08 13:39:19 -0500853
854 if (close) {
855 SkDebugf("%s--------------------------------------------------------------\n\n",
856 indent.c_str());
857 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400858}
John Stiles1e0136e2020-08-12 18:44:00 -0400859#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400860
John Stiles1e0136e2020-08-12 18:44:00 -0400861#ifdef SK_DEBUG
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400862void OpsTask::visitProxies_debugOnly(const GrVisitProxyFunc& func) const {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400863 auto textureFunc = [ func ] (GrSurfaceProxy* tex, GrMipmapped mipmapped) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400864 func(tex, mipmapped);
865 };
866
Greg Danielf41b2bd2019-08-22 16:19:24 -0400867 for (const OpChain& chain : fOpChains) {
Greg Danieldcf9ca12019-08-27 14:30:21 -0400868 chain.visitProxies(textureFunc);
Greg Danielf41b2bd2019-08-22 16:19:24 -0400869 }
870}
871
872#endif
873
874////////////////////////////////////////////////////////////////////////////////
875
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400876void OpsTask::onMakeSkippable() {
Brian Salomond63638b2021-03-05 14:00:07 -0500877 this->deleteOps();
878 fDeferredProxies.reset();
879 fColorLoadOp = GrLoadOp::kLoad;
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400880 SkASSERT(this->isColorNoOp());
Brian Salomond63638b2021-03-05 14:00:07 -0500881}
882
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400883bool OpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400884 bool used = false;
Adlai Holler304f6532021-05-17 13:26:46 -0400885 for (GrSurfaceProxy* proxy : fSampledProxies) {
886 if (proxy == proxyToCheck) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400887 used = true;
Adlai Holler304f6532021-05-17 13:26:46 -0400888 break;
889 }
890 }
891#ifdef SK_DEBUG
892 bool usedSlow = false;
893 auto visit = [ proxyToCheck, &usedSlow ] (GrSurfaceProxy* p, GrMipmapped) {
894 if (p == proxyToCheck) {
895 usedSlow = true;
Greg Danielf41b2bd2019-08-22 16:19:24 -0400896 }
897 };
Adlai Holler304f6532021-05-17 13:26:46 -0400898 this->visitProxies_debugOnly(visit);
899 SkASSERT(used == usedSlow);
900#endif
Greg Danielf41b2bd2019-08-22 16:19:24 -0400901
902 return used;
903}
904
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400905void OpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Adlai Hollerc17a3e92021-04-27 14:34:28 -0400906 SkASSERT(this->isClosed());
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400907 if (this->isColorNoOp()) {
Adlai Hollerc17a3e92021-04-27 14:34:28 -0400908 return;
909 }
910
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500911 for (int i = 0; i < fDeferredProxies.count(); ++i) {
912 SkASSERT(!fDeferredProxies[i]->isInstantiated());
913 // We give all the deferred proxies a write usage at the very start of flushing. This
914 // locks them out of being reused for the entire flush until they are read - and then
915 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
916 // with sub-flushes. The deferred proxies only need to be pinned from the start of
917 // the sub-flush in which they appear.
918 alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo);
919 }
920
Brian Salomon982127b2021-01-21 10:43:35 -0500921 GrSurfaceProxy* targetProxy = this->target(0);
Greg Daniel16f5c652019-10-29 11:26:01 -0400922
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400923 // Add the interval for all the writes to this OpsTasks's target
Brian Salomon588cec72018-11-14 13:56:37 -0500924 if (fOpChains.count()) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400925 unsigned int cur = alloc->curOp();
926
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000927 alloc->addInterval(targetProxy, cur, cur + fOpChains.count() - 1,
928 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500929 } else {
930 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
931 // still need to add an interval for the destination so we create a fake op# for
932 // the missing clear op.
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000933 alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(),
934 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500935 alloc->incOps();
936 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400937
Brian Salomon7e67dca2020-07-21 09:27:25 -0400938 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipmapped) {
Brian Salomon982127b2021-01-21 10:43:35 -0500939 alloc->addInterval(p,
940 alloc->curOp(),
Adlai Holler7f7a5df2021-02-09 17:41:10 +0000941 alloc->curOp(),
942 GrResourceAllocator::ActualUse::kYes
Brian Salomon982127b2021-01-21 10:43:35 -0500943 SkDEBUGCODE(, this->target(0) == p));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400944 };
Adlai Holler304f6532021-05-17 13:26:46 -0400945 // TODO: visitProxies is expensive. Can we do this with fSampledProxies instead?
Brian Salomon588cec72018-11-14 13:56:37 -0500946 for (const OpChain& recordedOp : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600947 recordedOp.visitProxies(gather);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500948
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400949 // 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 -0500950 // keep all the math consistent.
951 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400952 }
953}
954
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400955void OpsTask::recordOp(
Chris Dalton83420eb2021-06-23 18:47:09 -0600956 GrOp::Owner op, bool usesMSAA, GrProcessorSet::Analysis processorAnalysis,
957 GrAppliedClip* clip, const GrDstProxyView* dstProxyView, const GrCaps& caps) {
Brian Salomon982127b2021-01-21 10:43:35 -0500958 GrSurfaceProxy* proxy = this->target(0);
Chris Dalton83420eb2021-06-23 18:47:09 -0600959#ifdef SK_DEBUG
960 op->validate();
961 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy()));
Greg Daniel16f5c652019-10-29 11:26:01 -0400962 SkASSERT(proxy);
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400963 // A closed OpsTask should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700964 SkASSERT(!this->isClosed());
Chris Dalton83420eb2021-06-23 18:47:09 -0600965 // Ensure we can support dynamic msaa if the caller is trying to trigger it.
966 if (proxy->asRenderTargetProxy()->numSamples() == 1 && usesMSAA) {
967 SkASSERT(caps.supportsDynamicMSAA(proxy->asRenderTargetProxy()));
968 }
969#endif
970
Brian Salomon19ec80f2018-11-16 13:27:30 -0500971 if (!op->bounds().isFinite()) {
Brian Salomon19ec80f2018-11-16 13:27:30 -0500972 return;
973 }
robertphillipsa106c622015-10-16 09:07:06 -0700974
Chris Dalton83420eb2021-06-23 18:47:09 -0600975 fUsesMSAASurface |= usesMSAA;
976
Chris Dalton16a33c62019-09-24 22:19:17 -0600977 // Account for this op's bounds before we attempt to combine.
978 // NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable.
979 fTotalBounds.join(op->bounds());
980
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500981 // Check if there is an op we can combine with by linearly searching back until we either
982 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700983 // 2) intersect with something
984 // 3) find a 'blocker'
Greg Daniel16f5c652019-10-29 11:26:01 -0400985 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400986 GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n"
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400987 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
988 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500989 op->name(),
990 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400991 op->bounds().fLeft, op->bounds().fTop,
992 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500993 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500994 GrOP_INFO("\tOutcome:\n");
Brian Osman788b9162020-02-07 10:36:46 -0500995 int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.count());
Robert Phillips318c4192017-05-17 09:36:38 -0400996 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700997 int i = 0;
998 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500999 OpChain& candidate = fOpChains.fromBack(i);
Greg Daniel524e28b2019-11-01 11:48:53 -04001000 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps,
Herb Derby93250092021-04-06 12:19:20 -04001001 fArenas->arenaAlloc(), fAuditTrail);
Brian Salomon588cec72018-11-14 13:56:37 -05001002 if (!op) {
1003 return;
bsalomon512be532015-09-10 10:42:55 -07001004 }
Brian Salomona7682c82018-10-24 10:04:37 -04001005 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -05001006 if (!can_reorder(candidate.bounds(), op->bounds())) {
1007 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
1008 candidate.head()->name(), candidate.head()->uniqueID());
bsalomon512be532015-09-10 10:42:55 -07001009 break;
1010 }
Brian Salomon588cec72018-11-14 13:56:37 -05001011 if (++i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001012 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -07001013 break;
1014 }
1015 }
1016 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001017 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -07001018 }
Brian Salomon54d212e2017-03-21 14:22:38 -04001019 if (clip) {
Herb Derby93250092021-04-06 12:19:20 -04001020 clip = fArenas->arenaAlloc()->make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -04001021 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -04001022 }
Greg Daniel524e28b2019-11-01 11:48:53 -04001023 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView);
bsalomon512be532015-09-10 10:42:55 -07001024}
1025
Robert Phillips3e87a8e2021-08-25 13:22:24 -04001026void OpsTask::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -04001027 SkASSERT(!this->isClosed());
Greg Danielf41b2bd2019-08-22 16:19:24 -04001028 GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
Robert Phillips48567ac2017-06-01 08:46:00 -04001029
Brian Salomon588cec72018-11-14 13:56:37 -05001030 for (int i = 0; i < fOpChains.count() - 1; ++i) {
1031 OpChain& chain = fOpChains[i];
Brian Osman788b9162020-02-07 10:36:46 -05001032 int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -08001033 int j = i + 1;
1034 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -05001035 OpChain& candidate = fOpChains[j];
Herb Derby93250092021-04-06 12:19:20 -04001036 if (candidate.prependChain(&chain, caps, fArenas->arenaAlloc(), fAuditTrail)) {
bsalomonaecc0182016-03-07 11:50:44 -08001037 break;
1038 }
Robert Phillipsc84c0302017-05-08 15:35:11 -04001039 // Stop traversing if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -05001040 if (!can_reorder(chain.bounds(), candidate.bounds())) {
1041 GrOP_INFO(
1042 "\t\t%d: chain (%s head opID: %u) -> "
1043 "Intersects with chain (%s, head opID: %u)\n",
1044 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
1045 candidate.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001046 break;
1047 }
Brian Salomona7682c82018-10-24 10:04:37 -04001048 if (++j > maxCandidateIdx) {
Brian Salomon588cec72018-11-14 13:56:37 -05001049 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
1050 i, chain.head()->name(), chain.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -08001051 break;
1052 }
1053 }
1054 }
1055}
1056
Robert Phillips3e87a8e2021-08-25 13:22:24 -04001057GrRenderTask::ExpectedOutcome OpsTask::onMakeClosed(GrRecordingContext* rContext,
1058 SkIRect* targetUpdateBounds) {
Chris Daltonaa938ce2021-06-23 18:13:59 -06001059 this->forwardCombine(*rContext->priv().caps());
Greg Daniel0b04b6b2021-06-24 19:19:00 -04001060 if (!this->isColorNoOp()) {
Brian Salomon982127b2021-01-21 10:43:35 -05001061 GrSurfaceProxy* proxy = this->target(0);
Michael Ludwigd1d997e2020-06-04 15:52:44 -04001062 // Use the entire backing store bounds since the GPU doesn't clip automatically to the
1063 // logical dimensions.
1064 SkRect clippedContentBounds = proxy->backingStoreBoundsRect();
Adlai Holler33d569e2020-06-16 14:30:08 -04001065 // TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds
Greg Daniel16f5c652019-10-29 11:26:01 -04001066 // then we can simply assert here that the bounds intersect.
Chris Dalton16a33c62019-09-24 22:19:17 -06001067 if (clippedContentBounds.intersect(fTotalBounds)) {
Greg Daniel94ed83f2019-09-27 13:05:43 -04001068 clippedContentBounds.roundOut(&fClippedContentBounds);
Brian Salomon982127b2021-01-21 10:43:35 -05001069 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
1070 fTargetOrigin,
1071 this->target(0)->backingStoreDimensions().height(),
1072 fClippedContentBounds);
Chris Dalton16a33c62019-09-24 22:19:17 -06001073 return ExpectedOutcome::kTargetDirty;
1074 }
1075 }
1076 return ExpectedOutcome::kTargetUnchanged;
1077}
Robert Phillips3e87a8e2021-08-25 13:22:24 -04001078
1079} // namespace skgpu::v1