Debian Codegraph @

src/gpu/ganesh/ops/OpsTask.cpp

raw ◀ ▶
2 Debian patches touch this file
1 /*
2 * Copyright 2019 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.
6 */
7 #include "src/gpu/ganesh/ops/OpsTask.h"
8
9 #include "include/core/SkSize.h"
10 #include "include/core/SkString.h"
11 #include "include/gpu/GpuTypes.h"
12 #include "include/gpu/ganesh/GrRecordingContext.h"
13 #include "include/private/base/SkPoint_impl.h"
14 #include "src/base/SkArenaAlloc.h"
15 #include "src/base/SkScopeExit.h"
16 #include "src/core/SkRectPriv.h"
17 #include "src/core/SkStringUtils.h"
18 #include "src/core/SkTraceEvent.h"
19 #include "src/gpu/ganesh/GrAppliedClip.h"
20 #include "src/gpu/ganesh/GrAttachment.h"
21 #include "src/gpu/ganesh/GrAuditTrail.h"
22 #include "src/gpu/ganesh/GrCaps.h"
23 #include "src/gpu/ganesh/GrGpu.h"
24 #include "src/gpu/ganesh/GrNativeRect.h"
25 #include "src/gpu/ganesh/GrOpFlushState.h"
26 #include "src/gpu/ganesh/GrOpsRenderPass.h"
27 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
28 #include "src/gpu/ganesh/GrRenderTarget.h"
29 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
30 #include "src/gpu/ganesh/GrResourceAllocator.h"
31 #include "src/gpu/ganesh/GrResourceProvider.h"
32 #include "src/gpu/ganesh/GrSurfaceProxyView.h"
33 #include "src/gpu/ganesh/GrTextureProxy.h"
34 #include "src/gpu/ganesh/GrTextureResolveManager.h"
35 #include "src/gpu/ganesh/geometry/GrRect.h"
36
37 #include <algorithm>
38 #include <cstddef>
39 #include <cstdint>
40 #include <functional>
41 #include <memory>
42 #include <utility>
43
44 class GrDrawingManager;
45 enum GrSurfaceOrigin : int;
46
47 using namespace skia_private;
48
49 ////////////////////////////////////////////////////////////////////////////////
50
51 namespace {
52
53 // Experimentally we have found that most combining occurs within the first 10 comparisons.
54 static const int kMaxOpMergeDistance = 10;
55 static const int kMaxOpChainDistance = 10;
56
57 ////////////////////////////////////////////////////////////////////////////////
58
59 inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
60
61 GrOpsRenderPass* create_render_pass(GrGpu* gpu,
62 GrRenderTarget* rt,
63 bool useMSAASurface,
64 GrAttachment* stencil,
65 GrSurfaceOrigin origin,
66 const SkIRect& bounds,
67 GrLoadOp colorLoadOp,
68 const std::array<float, 4>& loadClearColor,
69 GrLoadOp stencilLoadOp,
70 GrStoreOp stencilStoreOp,
71 const TArray<GrSurfaceProxy*, true>& sampledProxies,
72 GrXferBarrierFlags renderPassXferBarriers) {
73 const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo {
74 colorLoadOp,
75 GrStoreOp::kStore,
76 loadClearColor
77 };
78
79 // TODO:
80 // We would like to (at this level) only ever clear & discard. We would need
81 // to stop splitting up higher level OpsTasks for copyOps to achieve that.
82 // Note: we would still need SB loads and stores but they would happen at a
83 // lower level (inside the VK command buffer).
84 const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
85 stencilLoadOp,
86 stencilStoreOp,
87 };
88
89 return gpu->getOpsRenderPass(rt, useMSAASurface, stencil, origin, bounds, kColorLoadStoreInfo,
90 stencilLoadAndStoreInfo, sampledProxies, renderPassXferBarriers);
91 }
92
93 } // anonymous namespace
94
95 ////////////////////////////////////////////////////////////////////////////////
96
97 namespace skgpu::ganesh {
98
99 inline OpsTask::OpChain::List::List(GrOp::Owner op)
100 : fHead(std::move(op)), fTail(fHead.get()) {
101 this->validate();
102 }
103
104 inline OpsTask::OpChain::List::List(List&& that) { *this = std::move(that); }
105
106 inline OpsTask::OpChain::List& OpsTask::OpChain::List::operator=(List&& that) {
107 fHead = std::move(that.fHead);
108 fTail = that.fTail;
109 that.fTail = nullptr;
110 this->validate();
111 return *this;
112 }
113
114 inline GrOp::Owner OpsTask::OpChain::List::popHead() {
115 SkASSERT(fHead);
116 auto temp = fHead->cutChain();
117 std::swap(temp, fHead);
118 if (!fHead) {
119 SkASSERT(fTail == temp.get());
120 fTail = nullptr;
121 }
122 return temp;
123 }
124
125 inline GrOp::Owner OpsTask::OpChain::List::removeOp(GrOp* op) {
126 #ifdef SK_DEBUG
127 auto head = op;
128 while (head->prevInChain()) { head = head->prevInChain(); }
129 SkASSERT(head == fHead.get());
130 #endif
131 auto prev = op->prevInChain();
132 if (!prev) {
133 SkASSERT(op == fHead.get());
134 return this->popHead();
135 }
136 auto temp = prev->cutChain();
137 if (auto next = temp->cutChain()) {
138 prev->chainConcat(std::move(next));
139 } else {
140 SkASSERT(fTail == op);
141 fTail = prev;
142 }
143 this->validate();
144 return temp;
145 }
146
147 inline void OpsTask::OpChain::List::pushHead(GrOp::Owner op) {
148 SkASSERT(op);
149 SkASSERT(op->isChainHead());
150 SkASSERT(op->isChainTail());
151 if (fHead) {
152 op->chainConcat(std::move(fHead));
153 fHead = std::move(op);
154 } else {
155 fHead = std::move(op);
156 fTail = fHead.get();
157 }
158 }
159
160 inline void OpsTask::OpChain::List::pushTail(GrOp::Owner op) {
161 SkASSERT(op->isChainTail());
162 fTail->chainConcat(std::move(op));
163 fTail = fTail->nextInChain();
164 }
165
166 inline void OpsTask::OpChain::List::validate() const {
167 #ifdef SK_DEBUG
168 if (fHead) {
169 SkASSERT(fTail);
170 fHead->validateChain(fTail);
171 }
172 #endif
173 }
174
175 ////////////////////////////////////////////////////////////////////////////////
176
177 OpsTask::OpChain::OpChain(GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
178 GrAppliedClip* appliedClip, const GrDstProxyView* dstProxyView)
179 : fList{std::move(op)}
180 , fProcessorAnalysis(processorAnalysis)
181 , fAppliedClip(appliedClip) {
182 if (fProcessorAnalysis.requiresDstTexture()) {
183 SkASSERT(dstProxyView && dstProxyView->proxy());
184 fDstProxyView = *dstProxyView;
185 }
186 fBounds = fList.head()->bounds();
187 }
188
189 void OpsTask::OpChain::visitProxies(const GrVisitProxyFunc& func) const {
190 if (fList.empty()) {
191 return;
192 }
193 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
194 op.visitProxies(func);
195 }
196 if (fDstProxyView.proxy()) {
197 func(fDstProxyView.proxy(), skgpu::Mipmapped::kNo);
198 }
199 if (fAppliedClip) {
200 fAppliedClip->visitProxies(func);
201 }
202 }
203
204 void OpsTask::OpChain::deleteOps() {
205 while (!fList.empty()) {
206 // Since the value goes out of scope immediately, the GrOp::Owner deletes the op.
207 fList.popHead();
208 }
209 }
210
211 // Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
212 // the two chains are chainable. Returns the new chain.
213 OpsTask::OpChain::List OpsTask::OpChain::DoConcat(List chainA, List chainB, const GrCaps& caps,
214 SkArenaAlloc* opsTaskArena,
215 GrAuditTrail* auditTrail) {
216 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
217 // at chain a's tail and working toward the head. We produce one of the following outcomes:
218 // 1) b's head is merged into an op in a.
219 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
220 // 3) b's head is popped from chain a and added at the tail of a.
221 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
222 // as we assume merges were already attempted when chain b was created. So we keep track of the
223 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
224 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
225 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
226 GrOp* origATail = chainA.tail();
227 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
228 do {
229 int numMergeChecks = 0;
230 bool merged = false;
231 bool noSkip = (origATail == chainA.tail());
232 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
233 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
234 SkRect forwardMergeBounds = skipBounds;
235 GrOp* a = origATail;
236 while (a) {
237 bool canForwardMerge =
238 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
239 if (canForwardMerge || canBackwardMerge) {
240 auto result = a->combineIfPossible(chainB.head(), opsTaskArena, caps);
241 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
242 merged = (result == GrOp::CombineResult::kMerged);
243 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
244 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
245 a->uniqueID());
246 }
247 if (merged) {
248 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
249 if (canBackwardMerge) {
250 // The GrOp::Owner releases the op.
251 chainB.popHead();
252 } else {
253 // We merged the contents of b's head into a. We will replace b's head with a in
254 // chain b.
255 SkASSERT(canForwardMerge);
256 if (a == origATail) {
257 origATail = a->prevInChain();
258 }
259 GrOp::Owner detachedA = chainA.removeOp(a);
260 // The GrOp::Owner releases the op.
261 chainB.popHead();
262 chainB.pushHead(std::move(detachedA));
263 if (chainA.empty()) {
264 // We merged all the nodes in chain a to chain b.
265 return chainB;
266 }
267 }
268 break;
269 } else {
270 if (++numMergeChecks == kMaxOpMergeDistance) {
271 break;
272 }
273 forwardMergeBounds.joinNonEmptyArg(a->bounds());
274 canBackwardMerge =
275 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
276 a = a->prevInChain();
277 }
278 }
279 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
280 // tail of a.
281 if (!merged) {
282 chainA.pushTail(chainB.popHead());
283 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
284 }
285 } while (!chainB.empty());
286 return chainA;
287 }
288
289 // Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
290 // whether the operation succeeded. On success, the provided list will be returned empty.
291 bool OpsTask::OpChain::tryConcat(
292 List* list, GrProcessorSet::Analysis processorAnalysis, const GrDstProxyView& dstProxyView,
293 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
294 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
295 SkASSERT(!fList.empty());
296 SkASSERT(!list->empty());
297 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy()));
298 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy()));
299 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
300 if (fList.head()->classID() != list->head()->classID() ||
301 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
302 (fAppliedClip && *fAppliedClip != *appliedClip) ||
303 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
304 processorAnalysis.requiresNonOverlappingDraws()) ||
305 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
306 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
307 // or read back a new dst texture between draws. In either case, we can neither
308 // chain nor combine overlapping Ops.
309 GrRectsTouchOrOverlap(fBounds, bounds)) ||
310 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
311 (fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) {
312 return false;
313 }
314
315 SkDEBUGCODE(bool first = true;)
316 do {
317 switch (fList.tail()->combineIfPossible(list->head(), opsTaskArena, caps))
318 {
319 case GrOp::CombineResult::kCannotCombine:
320 // If an op supports chaining then it is required that chaining is transitive and
321 // that if any two ops in two different chains can merge then the two chains
322 // may also be chained together. Thus, we should only hit this on the first
323 // iteration.
324 SkASSERT(first);
325 return false;
326 case GrOp::CombineResult::kMayChain:
327 fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, opsTaskArena,
328 auditTrail);
329 // The above exchange cleared out 'list'. The list needs to be empty now for the
330 // loop to terminate.
331 SkASSERT(list->empty());
332 break;
333 case GrOp::CombineResult::kMerged: {
334 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
335 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
336 list->head()->uniqueID());
337 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
338 // The GrOp::Owner releases the op.
339 list->popHead();
340 break;
341 }
342 }
343 SkDEBUGCODE(first = false);
344 } while (!list->empty());
345
346 // The new ops were successfully merged and/or chained onto our own.
347 fBounds.joinPossiblyEmptyRect(bounds);
348 return true;
349 }
350
351 bool OpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, SkArenaAlloc* opsTaskArena,
352 GrAuditTrail* auditTrail) {
353 if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps,
354 opsTaskArena, auditTrail)) {
355 this->validate();
356 // append failed
357 return false;
358 }
359
360 // 'that' owns the combined chain. Move it into 'this'.
361 SkASSERT(fList.empty());
362 fList = std::move(that->fList);
363 fBounds = that->fBounds;
364
365 that->fDstProxyView.setProxyView({});
366 if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) {
367 // Obliterates the processor.
368 that->fAppliedClip->detachCoverageFragmentProcessor();
369 }
370 this->validate();
371 return true;
372 }
373
374 GrOp::Owner OpsTask::OpChain::appendOp(
375 GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis,
376 const GrDstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps,
377 SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) {
378 const GrDstProxyView noDstProxyView;
379 if (!dstProxyView) {
380 dstProxyView = &noDstProxyView;
381 }
382 SkASSERT(op->isChainHead() && op->isChainTail());
383 SkRect opBounds = op->bounds();
384 List chain(std::move(op));
385 if (!this->tryConcat(&chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps,
386 opsTaskArena, auditTrail)) {
387 // append failed, give the op back to the caller.
388 this->validate();
389 return chain.popHead();
390 }
391
392 SkASSERT(chain.empty());
393 this->validate();
394 return nullptr;
395 }
396
397 inline void OpsTask::OpChain::validate() const {
398 #ifdef SK_DEBUG
399 fList.validate();
400 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
401 // Not using SkRect::contains because we allow empty rects.
402 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
403 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
404 }
405 #endif
406 }
407
408 ////////////////////////////////////////////////////////////////////////////////
409
410 OpsTask::OpsTask(GrDrawingManager* drawingMgr,
411 GrSurfaceProxyView view,
412 GrAuditTrail* auditTrail,
413 sk_sp<GrArenas> arenas)
414 : GrRenderTask()
415 , fAuditTrail(auditTrail)
416 , fUsesMSAASurface(view.asRenderTargetProxy()->numSamples() > 1)
417 , fTargetSwizzle(view.swizzle())
418 , fTargetOrigin(view.origin())
419 , fArenas{std::move(arenas)}
420 SkDEBUGCODE(, fNumClips(0)) {
421 this->addTarget(drawingMgr, view.detachProxy());
422 }
423
424 void OpsTask::deleteOps() {
425 for (auto& chain : fOpChains) {
426 chain.deleteOps();
427 }
428 fOpChains.clear();
429 }
430
431 OpsTask::~OpsTask() {
432 this->deleteOps();
433 }
434
435 void OpsTask::addOp(GrDrawingManager* drawingMgr, GrOp::Owner op,
436 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
437 auto addDependency = [&](GrSurfaceProxy* p, skgpu::Mipmapped mipmapped) {
438 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
439 };
440
441 op->visitProxies(addDependency);
442
443 this->recordOp(std::move(op), false/*usesMSAA*/, GrProcessorSet::EmptySetAnalysis(), nullptr,
444 nullptr, caps);
445 }
446
447 void OpsTask::addDrawOp(GrDrawingManager* drawingMgr, GrOp::Owner op, bool usesMSAA,
448 const GrProcessorSet::Analysis& processorAnalysis, GrAppliedClip&& clip,
449 const GrDstProxyView& dstProxyView,
450 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
451 auto addDependency = [&](GrSurfaceProxy* p, skgpu::Mipmapped mipmapped) {
452 this->addSampledTexture(p);
453 this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps);
454 };
455
456 op->visitProxies(addDependency);
457 clip.visitProxies(addDependency);
458 if (dstProxyView.proxy()) {
459 if (!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment)) {
460 this->addSampledTexture(dstProxyView.proxy());
461 }
462 if (dstProxyView.dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) {
463 fRenderPassXferBarriers |= GrXferBarrierFlags::kTexture;
464 }
465 addDependency(dstProxyView.proxy(), skgpu::Mipmapped::kNo);
466 SkASSERT(!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment) ||
467 dstProxyView.offset().isZero());
468 }
469
470 if (processorAnalysis.usesNonCoherentHWBlending()) {
471 fRenderPassXferBarriers |= GrXferBarrierFlags::kBlend;
472 }
473
474 this->recordOp(std::move(op), usesMSAA, processorAnalysis, clip.doesClip() ? &clip : nullptr,
475 &dstProxyView, caps);
476 }
477
478 void OpsTask::endFlush(GrDrawingManager* drawingMgr) {
479 fLastClipStackGenID = SK_InvalidUniqueID;
480 this->deleteOps();
481
482 fDeferredProxies.clear();
483 fSampledProxies.clear();
484 fAuditTrail = nullptr;
485
486 GrRenderTask::endFlush(drawingMgr);
487 }
488
489 void OpsTask::onPrePrepare(GrRecordingContext* context) {
490 SkASSERT(this->isClosed());
491 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
492 // can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation
493 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
494 // we shouldn't end up with OpsTasks with only discard.
495 if (this->isColorNoOp() ||
496 (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
497 return;
498 }
499 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
500
501 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
502 for (const auto& chain : fOpChains) {
503 if (chain.shouldExecute()) {
504 chain.head()->prePrepare(context,
505 dstView,
506 chain.appliedClip(),
507 chain.dstProxyView(),
508 fRenderPassXferBarriers,
509 fColorLoadOp);
510 }
511 }
512 }
513
514 void OpsTask::onPrepare(GrOpFlushState* flushState) {
515 SkASSERT(this->target(0)->peekRenderTarget());
516 SkASSERT(this->isClosed());
517 // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we
518 // can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation
519 // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled
520 // we shouldn't end up with OpsTasks with only discard.
521 if (this->isColorNoOp() ||
522 (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) {
523 return;
524 }
525 TRACE_EVENT0_ALWAYS("skia.gpu", TRACE_FUNC);
526
527 flushState->setSampledProxyArray(&fSampledProxies);
528 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
529 // Loop over the ops that haven't yet been prepared.
530 for (const auto& chain : fOpChains) {
531 if (chain.shouldExecute()) {
532 GrOpFlushState::OpArgs opArgs(chain.head(),
533 dstView,
534 fUsesMSAASurface,
535 chain.appliedClip(),
536 chain.dstProxyView(),
537 fRenderPassXferBarriers,
538 fColorLoadOp);
539
540 flushState->setOpArgs(&opArgs);
541
542 // Temporary debugging helper: for debugging prePrepare w/o going through DDLs
543 // Delete once most of the GrOps have an onPrePrepare.
544 // chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0),
545 // chain.appliedClip());
546
547 // GrOp::prePrepare may or may not have been called at this point
548 chain.head()->prepare(flushState);
549 flushState->setOpArgs(nullptr);
550 }
551 }
552 flushState->setSampledProxyArray(nullptr);
553 }
554
555 // TODO: this is where GrOp::renderTarget is used (which is fine since it
556 // is at flush time). However, we need to store the RenderTargetProxy in the
557 // Ops and instantiate them here.
558 bool OpsTask::onExecute(GrOpFlushState* flushState) {
559 SkASSERT(this->numTargets() == 1);
560 GrRenderTargetProxy* proxy = this->target(0)->asRenderTargetProxy();
561 SkASSERT(proxy);
562 SK_AT_SCOPE_EXIT(proxy->clearArenas());
563
564 if (this->isColorNoOp() || fClippedContentBounds.isEmpty()) {
565 return false;
566 }
567 TRACE_EVENT0_ALWAYS("skia.gpu", TRACE_FUNC);
568
569 // Make sure load ops are not kClear if the GPU needs to use draws for clears
570 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
571 !flushState->gpu()->caps()->performColorClearsAsDraws());
572
573 const GrCaps& caps = *flushState->gpu()->caps();
574 GrRenderTarget* renderTarget = proxy->peekRenderTarget();
575 SkASSERT(renderTarget);
576
577 GrAttachment* stencil = nullptr;
578 if (proxy->needsStencil()) {
579 SkASSERT(proxy->canUseStencil(caps));
580 if (!flushState->resourceProvider()->attachStencilAttachment(renderTarget,
581 fUsesMSAASurface)) {
582 SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n");
583 return false;
584 }
585 stencil = renderTarget->getStencilAttachment(fUsesMSAASurface);
586 }
587
588 GrLoadOp stencilLoadOp;
•589 // Determine whether the stencil attachment's cleared area should be updated.
590 bool updateClearedStencilArea = false;
•591 SkIRect boundsRequiredByStencil = fClippedContentBounds;
592 switch (fInitialStencilContent) {
593 case StencilContent::kDontCare:
•594 if (!stencil || caps.performStencilClearsAsDraws()) {
595 // This should only intentionally happen for the AtlasRenderTask which
596 // immediately inserts a clear.
597 stencilLoadOp = GrLoadOp::kDiscard;
•598 break;
599 }
600 break;
•601 // This OpTask has a stencil, doesn't care about its contents, isn't clearing it with
602 // draws, and is going to store the result. In that case, we fallthrough to clear it so
603 // that uninitialized data won't creep into the stencil buffer.
604 [[fallthrough]];
605 case StencilContent::kUserBitsCleared:
606 SkASSERT(!caps.performStencilClearsAsDraws());
607 SkASSERT(stencil);
•608 // Based upon Caps, determine which stencil load operation to use and perform any
609 // necessary updates to the renderpass's bounds and the stencil's cleared area.
610
611 // If the user bits are meant to be cleared we either do that via an initial clear the
612 // first time the area of the stencil is used, or we assume previous draws left the
613 // stencil cleared so we just load the current values. However, on some devices it is
614 // faster to just clear the stencil each time instead of doing a load.
615 //
616 // Since we'll never end up loading the stencil in this case there is no reason for us
617 // to do the clear rect tracking below, so we just break.
618 if (caps.clearsAreFasterThanLoads()) {
619 stencilLoadOp = GrLoadOp::kClear;
620 break;
621 }
622 // If stencil values are discarded after every renderpass, then we do not need to track
623 // which portion of the stencil attachment has already been cleared.
624 if (caps.discardStencilValuesAfterRenderPass()) {
625 stencilLoadOp = GrLoadOp::kClear;
626 break;
627 }
•628
629 // If the area of the stencil attachment corresponding to this renderpass's
630 // boundsRequiredByStencil has not already been cleared, calculate new, expanded
631 // renderpass bounds by joining boundsRequiredByStencil with the cleared stencil area.
632 // Using this joint area simplifies tracking of cleared areas on the stencil attachment.
633 if (!stencil->hasAreaBeenCleared(boundsRequiredByStencil)) {
634 stencilLoadOp = GrLoadOp::kClear;
•635 if (!stencil->clearedArea().isEmpty()) {
636 boundsRequiredByStencil.join(stencil->clearedArea());
637 // We need to also intersect the bounds with the color attachment's bounds since
638 // the stencil may be bigger. This could mean that we end up "forgetting" we
639 // cleared the user bits in the portion of the stencil that doesn't overlap with
640 // the color attachment - but that shouldn't have a large performance impact if
641 // we later on need to reclear that area.
642 boundsRequiredByStencil.intersect(
643 SkIRect::MakeSize(renderTarget->dimensions()));
644 }
645 // We should update the stencil's cleared area if renderpass creation succeeds.
646 updateClearedStencilArea = true;
647 break;
648 }
•649
650 // SurfaceDrawContexts are required to leave the user stencil bits in a cleared state
651 // once finished, meaning the stencil values will always remain cleared after the
652 // initial clear. Just fall through to reloading the existing (cleared) stencil values
653 // from memory.
654 [[fallthrough]];
655 case StencilContent::kPreserved:
656 SkASSERT(stencil);
657 stencilLoadOp = GrLoadOp::kLoad;
658 break;
•659 default:
660 SkUNREACHABLE;
661 }
662
663 // NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split
664 // its opsTask.
665 //
666 // FIXME: We don't currently flag render passes that don't use stencil at all. In that case
667 // their store op might be "discard", and we currently make the assumption that a discard will
668 // not invalidate what's already in main memory. This is probably ok for now, but certainly
669 // something we want to address soon.
•670 // b/160958008 forces discardStencilValuesAfterRenderPass to always return false.
671 GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil)
672 ? GrStoreOp::kDiscard
673 : GrStoreOp::kStore;
674
675 GrOpsRenderPass* renderPass = create_render_pass(flushState->gpu(),
676 proxy->peekRenderTarget(),
677 fUsesMSAASurface,
678 stencil,
679 fTargetOrigin,
•680 boundsRequiredByStencil,
681 fColorLoadOp,
682 fLoadClearColor,
683 stencilLoadOp,
684 stencilStoreOp,
685 fSampledProxies,
686 fRenderPassXferBarriers);
687
688 if (!renderPass) {
689 return false;
690 }
•691 if (updateClearedStencilArea) {
692 stencil->markAreaCleared(boundsRequiredByStencil);
693 }
694
695 #if defined(SK_DEBUG)
696 if (stencilLoadOp == GrLoadOp::kDiscard) {
697 // The only time we should have a stencil discard load-op is when either:
698 // there is no stencil buffer
699 // or stencil clears are being performed by draws
700 SkASSERT(!stencil || caps.performStencilClearsAsDraws());
701 }
702 #endif
703
704 flushState->setOpsRenderPass(renderPass);
705 renderPass->begin();
706
707 GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle);
708
709 // Draw all the generated geometry.
710 for (const auto& chain : fOpChains) {
711 if (!chain.shouldExecute()) {
712 continue;
713 }
714
715 GrOpFlushState::OpArgs opArgs(chain.head(),
716 dstView,
717 fUsesMSAASurface,
718 chain.appliedClip(),
719 chain.dstProxyView(),
720 fRenderPassXferBarriers,
721 fColorLoadOp);
722
723 flushState->setOpArgs(&opArgs);
724 chain.head()->execute(flushState, chain.bounds());
725 flushState->setOpArgs(nullptr);
726 }
727
728 renderPass->end();
729 flushState->gpu()->submit(renderPass);
730 flushState->setOpsRenderPass(nullptr);
731
732 return true;
733 }
734
735 void OpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) {
736 fColorLoadOp = op;
737 fLoadClearColor = color;
738 if (GrLoadOp::kClear == fColorLoadOp) {
739 GrSurfaceProxy* proxy = this->target(0);
740 SkASSERT(proxy);
741 fTotalBounds = proxy->backingStoreBoundsRect();
742 }
743 }
744
745 void OpsTask::reset() {
746 fDeferredProxies.clear();
747 fSampledProxies.clear();
748 fClippedContentBounds = SkIRect::MakeEmpty();
749 fTotalBounds = SkRect::MakeEmpty();
750 this->deleteOps();
751 fRenderPassXferBarriers = GrXferBarrierFlags::kNone;
752 }
753
754 bool OpsTask::canMerge(const OpsTask* opsTask) const {
755 return this->target(0) == opsTask->target(0) &&
756 fArenas == opsTask->fArenas &&
757 !opsTask->fCannotMergeBackward;
758 }
759
760 int OpsTask::mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks) {
761 int mergedCount = 0;
762 for (const sk_sp<GrRenderTask>& task : tasks) {
763 auto opsTask = task->asOpsTask();
764 if (!opsTask || !this->canMerge(opsTask)) {
765 break;
766 }
767 SkASSERT(fTargetSwizzle == opsTask->fTargetSwizzle);
768 SkASSERT(fTargetOrigin == opsTask->fTargetOrigin);
769 if (GrLoadOp::kClear == opsTask->fColorLoadOp) {
770 // TODO(11903): Go back to actually dropping ops tasks when we are merged with
771 // color clear.
772 return 0;
773 }
774 mergedCount += 1;
775 }
776 if (0 == mergedCount) {
777 return 0;
778 }
779
780 SkSpan<const sk_sp<OpsTask>> mergingNodes(
781 reinterpret_cast<const sk_sp<OpsTask>*>(tasks.data()), SkToSizeT(mergedCount));
782 int addlDeferredProxyCount = 0;
783 int addlProxyCount = 0;
784 int addlOpChainCount = 0;
785 for (const auto& toMerge : mergingNodes) {
786 addlDeferredProxyCount += toMerge->fDeferredProxies.size();
787 addlProxyCount += toMerge->fSampledProxies.size();
788 addlOpChainCount += toMerge->fOpChains.size();
789 fClippedContentBounds.join(toMerge->fClippedContentBounds);
790 fTotalBounds.join(toMerge->fTotalBounds);
791 fRenderPassXferBarriers |= toMerge->fRenderPassXferBarriers;
792 if (fInitialStencilContent == StencilContent::kDontCare) {
•793 // Propagate the first stencil content that isn't kDontCare.
794 //
795 // Once the stencil has any kind of initial content that isn't kDontCare, then the
•796 // initial contents of subsequent opsTasks that get merged in don't matter.
797 //
798 // (This works because the opsTask all target the same render target and are in
799 // painter's order. kPreserved obviously happens automatically with a merge, and kClear
800 // is also automatic because the contract is for ops to leave the stencil buffer in a
801 // cleared state when finished.)
802 fInitialStencilContent = toMerge->fInitialStencilContent;
803 }
804 fUsesMSAASurface |= toMerge->fUsesMSAASurface;
805 SkDEBUGCODE(fNumClips += toMerge->fNumClips);
806 }
807
808 fLastClipStackGenID = SK_InvalidUniqueID;
809 fDeferredProxies.reserve_exact(fDeferredProxies.size() + addlDeferredProxyCount);
810 fSampledProxies.reserve_exact(fSampledProxies.size() + addlProxyCount);
811 fOpChains.reserve_exact(fOpChains.size() + addlOpChainCount);
812 for (const auto& toMerge : mergingNodes) {
813 for (GrRenderTask* renderTask : toMerge->dependents()) {
814 renderTask->replaceDependency(toMerge.get(), this);
815 }
816 for (GrRenderTask* renderTask : toMerge->dependencies()) {
817 renderTask->replaceDependent(toMerge.get(), this);
818 }
819 fDeferredProxies.move_back_n(toMerge->fDeferredProxies.size(),
820 toMerge->fDeferredProxies.data());
821 fSampledProxies.move_back_n(toMerge->fSampledProxies.size(),
822 toMerge->fSampledProxies.data());
823 fOpChains.move_back_n(toMerge->fOpChains.size(),
824 toMerge->fOpChains.data());
825 toMerge->fDeferredProxies.clear();
826 toMerge->fSampledProxies.clear();
827 toMerge->fOpChains.clear();
828 }
829 fMustPreserveStencil = mergingNodes.back()->fMustPreserveStencil;
830 return mergedCount;
831 }
832
833 bool OpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
834 if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
835 this->deleteOps();
836 fDeferredProxies.clear();
837 fSampledProxies.clear();
838
839 // If the opsTask is using a render target which wraps a vulkan command buffer, we can't do
840 // a clear load since we cannot change the render pass that we are using. Thus we fall back
841 // to making a clear op in this case.
842 return !this->target(0)->asRenderTargetProxy()->wrapsVkSecondaryCB();
843 }
844
845 // Could not empty the task, so an op must be added to handle the clear
846 return false;
847 }
848
849 void OpsTask::discard() {
850 // Discard calls to in-progress opsTasks are ignored. Calls at the start update the
851 // opsTasks' color & stencil load ops.
852 if (this->isEmpty()) {
853 fColorLoadOp = GrLoadOp::kDiscard;
854 fInitialStencilContent = StencilContent::kDontCare;
855 fTotalBounds.setEmpty();
856 }
857 }
858
859 ////////////////////////////////////////////////////////////////////////////////
860
861 #if defined(GPU_TEST_UTILS)
862 void OpsTask::dump(const SkString& label,
863 SkString indent,
864 bool printDependencies,
865 bool close) const {
866 GrRenderTask::dump(label, indent, printDependencies, false);
867
868 SkDebugf("%sfColorLoadOp: ", indent.c_str());
869 switch (fColorLoadOp) {
870 case GrLoadOp::kLoad:
871 SkDebugf("kLoad\n");
872 break;
873 case GrLoadOp::kClear:
874 SkDebugf("kClear {%g, %g, %g, %g}\n",
875 fLoadClearColor[0],
876 fLoadClearColor[1],
877 fLoadClearColor[2],
878 fLoadClearColor[3]);
879 break;
880 case GrLoadOp::kDiscard:
881 SkDebugf("kDiscard\n");
882 break;
883 }
884
885 SkDebugf("%sfInitialStencilContent: ", indent.c_str());
886 switch (fInitialStencilContent) {
887 case StencilContent::kDontCare:
888 SkDebugf("kDontCare\n");
889 break;
890 case StencilContent::kUserBitsCleared:
891 SkDebugf("kUserBitsCleared\n");
892 break;
893 case StencilContent::kPreserved:
894 SkDebugf("kPreserved\n");
895 break;
896 }
897
898 SkDebugf("%s%d ops:\n", indent.c_str(), fOpChains.size());
899 for (int i = 0; i < fOpChains.size(); ++i) {
900 SkDebugf("%s*******************************\n", indent.c_str());
901 if (!fOpChains[i].head()) {
902 SkDebugf("%s%d: <combined forward or failed instantiation>\n", indent.c_str(), i);
903 } else {
904 SkDebugf("%s%d: %s\n", indent.c_str(), i, fOpChains[i].head()->name());
905 SkRect bounds = fOpChains[i].bounds();
906 SkDebugf("%sClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
907 indent.c_str(),
908 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
909 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
910 SkString info = SkTabString(op.dumpInfo(), 1);
911 SkDebugf("%s%s\n", indent.c_str(), info.c_str());
912 bounds = op.bounds();
913 SkDebugf("%s\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
914 indent.c_str(),
915 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
916 }
917 }
918 }
919
920 if (close) {
921 SkDebugf("%s--------------------------------------------------------------\n\n",
922 indent.c_str());
923 }
924 }
925 #endif
926
927 #ifdef SK_DEBUG
928 void OpsTask::visitProxies_debugOnly(const GrVisitProxyFunc& func) const {
929 auto textureFunc = [func](GrSurfaceProxy* tex, skgpu::Mipmapped mipmapped) {
930 func(tex, mipmapped);
931 };
932
933 for (const OpChain& chain : fOpChains) {
934 chain.visitProxies(textureFunc);
935 }
936 }
937
938 #endif
939
940 ////////////////////////////////////////////////////////////////////////////////
941
942 void OpsTask::onMakeSkippable() {
943 this->deleteOps();
944 fDeferredProxies.clear();
945 fColorLoadOp = GrLoadOp::kLoad;
946 SkASSERT(this->isColorNoOp());
947 }
948
949 bool OpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
950 bool used = false;
951 for (GrSurfaceProxy* proxy : fSampledProxies) {
952 if (proxy == proxyToCheck) {
953 used = true;
954 break;
955 }
956 }
957 #ifdef SK_DEBUG
958 bool usedSlow = false;
959 auto visit = [proxyToCheck, &usedSlow](GrSurfaceProxy* p, skgpu::Mipmapped) {
960 if (p == proxyToCheck) {
961 usedSlow = true;
962 }
963 };
964 this->visitProxies_debugOnly(visit);
965 SkASSERT(used == usedSlow);
966 #endif
967
968 return used;
969 }
970
971 void OpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
972 SkASSERT(this->isClosed());
973 if (this->isColorNoOp()) {
974 return;
975 }
976
977 for (int i = 0; i < fDeferredProxies.size(); ++i) {
978 SkASSERT(!fDeferredProxies[i]->isInstantiated());
979 // We give all the deferred proxies a write usage at the very start of flushing. This
980 // locks them out of being reused for the entire flush until they are read - and then
981 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
982 // with sub-flushes. The deferred proxies only need to be pinned from the start of
983 // the sub-flush in which they appear.
984 alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo,
985 GrResourceAllocator::AllowRecycling::kYes);
986 }
987
988 GrSurfaceProxy* targetSurface = this->target(0);
989 SkASSERT(targetSurface);
990 GrRenderTargetProxy* targetProxy = targetSurface->asRenderTargetProxy();
991
992 // Add the interval for all the writes to this OpsTasks's target
993 if (!fOpChains.empty()) {
994 unsigned int cur = alloc->curOp();
995
996 alloc->addInterval(targetProxy, cur, cur + fOpChains.size() - 1,
997 GrResourceAllocator::ActualUse::kYes,
998 GrResourceAllocator::AllowRecycling::kYes);
999 } else {
1000 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
1001 // still need to add an interval for the destination so we create a fake op# for
1002 // the missing clear op.
1003 alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(),
1004 GrResourceAllocator::ActualUse::kYes,
1005 GrResourceAllocator::AllowRecycling::kYes);
1006 alloc->incOps();
1007 }
1008
1009 GrResourceAllocator::AllowRecycling allowRecycling =
1010 targetProxy->wrapsVkSecondaryCB() ? GrResourceAllocator::AllowRecycling::kNo
1011 : GrResourceAllocator::AllowRecycling::kYes;
1012
1013 auto gather = [alloc, allowRecycling SkDEBUGCODE(, this)](GrSurfaceProxy* p, skgpu::Mipmapped) {
1014 alloc->addInterval(p,
1015 alloc->curOp(),
1016 alloc->curOp(),
1017 GrResourceAllocator::ActualUse::kYes,
1018 allowRecycling
1019 SkDEBUGCODE(, this->target(0) == p));
1020 };
1021 // TODO: visitProxies is expensive. Can we do this with fSampledProxies instead?
1022 for (const OpChain& recordedOp : fOpChains) {
1023 recordedOp.visitProxies(gather);
1024
1025 // Even though the op may have been (re)moved we still need to increment the op count to
1026 // keep all the math consistent.
1027 alloc->incOps();
1028 }
1029 }
1030
1031 void OpsTask::recordOp(
1032 GrOp::Owner op, bool usesMSAA, GrProcessorSet::Analysis processorAnalysis,
1033 GrAppliedClip* clip, const GrDstProxyView* dstProxyView, const GrCaps& caps) {
1034 GrSurfaceProxy* proxy = this->target(0);
1035 #ifdef SK_DEBUG
1036 op->validate();
1037 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy()));
1038 SkASSERT(proxy);
1039 // A closed OpsTask should never receive new/more ops
1040 SkASSERT(!this->isClosed());
1041 // Ensure we can support dynamic msaa if the caller is trying to trigger it.
1042 if (proxy->asRenderTargetProxy()->numSamples() == 1 && usesMSAA) {
1043 SkASSERT(caps.supportsDynamicMSAA(proxy->asRenderTargetProxy()));
1044 }
1045 #endif
1046
1047 if (!op->bounds().isFinite()) {
1048 return;
1049 }
1050
1051 fUsesMSAASurface |= usesMSAA;
1052
1053 // Account for this op's bounds before we attempt to combine.
1054 // NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable.
1055 fTotalBounds.join(op->bounds());
1056
1057 // Check if there is an op we can combine with by linearly searching back until we either
1058 // 1) check every op
1059 // 2) intersect with something
1060 // 3) find a 'blocker'
1061 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID());
1062 GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n"
1063 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
1064 this->uniqueID(),
1065 op->name(),
1066 op->uniqueID(),
1067 op->bounds().fLeft, op->bounds().fTop,
1068 op->bounds().fRight, op->bounds().fBottom);
1069 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
1070 GrOP_INFO("\tOutcome:\n");
1071 int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.size());
1072 if (maxCandidates) {
1073 int i = 0;
1074 while (true) {
1075 OpChain& candidate = fOpChains.fromBack(i);
1076 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps,
1077 fArenas->arenaAlloc(), fAuditTrail);
1078 if (!op) {
1079 return;
1080 }
1081 // Stop going backwards if we would cause a painter's order violation.
1082 if (!can_reorder(candidate.bounds(), op->bounds())) {
1083 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
1084 candidate.head()->name(), candidate.head()->uniqueID());
1085 break;
1086 }
1087 if (++i == maxCandidates) {
1088 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
1089 break;
1090 }
1091 }
1092 } else {
1093 GrOP_INFO("\t\tBackward: FirstOp\n");
1094 }
1095 if (clip) {
1096 clip = fArenas->arenaAlloc()->make<GrAppliedClip>(std::move(*clip));
1097 SkDEBUGCODE(fNumClips++;)
1098 }
1099 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView);
1100 }
1101
1102 void OpsTask::forwardCombine(const GrCaps& caps) {
1103 SkASSERT(!this->isClosed());
1104 GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.size());
1105
1106 for (int i = 0; i < fOpChains.size() - 1; ++i) {
1107 OpChain& chain = fOpChains[i];
1108 int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.size() - 1);
1109 int j = i + 1;
1110 while (true) {
1111 OpChain& candidate = fOpChains[j];
1112 if (candidate.prependChain(&chain, caps, fArenas->arenaAlloc(), fAuditTrail)) {
1113 break;
1114 }
1115 // Stop traversing if we would cause a painter's order violation.
1116 if (!can_reorder(chain.bounds(), candidate.bounds())) {
1117 GrOP_INFO(
1118 "\t\t%d: chain (%s head opID: %u) -> "
1119 "Intersects with chain (%s, head opID: %u)\n",
1120 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
1121 candidate.head()->uniqueID());
1122 break;
1123 }
1124 if (++j > maxCandidateIdx) {
1125 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
1126 i, chain.head()->name(), chain.head()->uniqueID());
1127 break;
1128 }
1129 }
1130 }
1131 }
1132
1133 GrRenderTask::ExpectedOutcome OpsTask::onMakeClosed(GrRecordingContext* rContext,
1134 SkIRect* targetUpdateBounds) {
1135 this->forwardCombine(*rContext->priv().caps());
1136 if (!this->isColorNoOp()) {
1137 GrSurfaceProxy* proxy = this->target(0);
1138 // Use the entire backing store bounds since the GPU doesn't clip automatically to the
1139 // logical dimensions.
1140 SkRect clippedContentBounds = proxy->backingStoreBoundsRect();
1141 // TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds
1142 // then we can simply assert here that the bounds intersect.
1143 if (clippedContentBounds.intersect(fTotalBounds)) {
1144 clippedContentBounds.roundOut(&fClippedContentBounds);
1145 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
1146 fTargetOrigin,
1147 this->target(0)->backingStoreDimensions().height(),
1148 fClippedContentBounds);
1149 return ExpectedOutcome::kTargetDirty;
1150 }
1151 }
1152 return ExpectedOutcome::kTargetUnchanged;
1153 }
1154
1155 } // namespace skgpu::ganesh