reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 2 | * Copyright 2019 Google Inc. |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 8 | #include "src/gpu/GrOpsTask.h" |
Brian Salomon | 4d2d6f4 | 2019-07-26 14:15:11 -0400 | [diff] [blame] | 9 | |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 10 | #include "include/gpu/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/core/SkRectPriv.h" |
Brian Salomon | 3b8486a | 2020-04-21 12:43:26 -0400 | [diff] [blame] | 12 | #include "src/core/SkScopeExit.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/core/SkTraceEvent.h" |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrAttachment.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrCaps.h" |
| 17 | #include "src/gpu/GrGpu.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrMemoryPool.h" |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrOpFlushState.h" |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrOpsRenderPass.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrRecordingContextPriv.h" |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 22 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrRenderTargetContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrResourceAllocator.h" |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 25 | #include "src/gpu/GrTexture.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 26 | #include "src/gpu/geometry/GrRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/ops/GrClearOp.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 28 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 29 | //////////////////////////////////////////////////////////////////////////////// |
| 30 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 31 | // Experimentally we have found that most combining occurs within the first 10 comparisons. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 32 | static const int kMaxOpMergeDistance = 10; |
| 33 | static const int kMaxOpChainDistance = 10; |
| 34 | |
| 35 | //////////////////////////////////////////////////////////////////////////////// |
| 36 | |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 37 | using DstProxyView = GrXferProcessor::DstProxyView; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 38 | |
| 39 | //////////////////////////////////////////////////////////////////////////////// |
| 40 | |
Brian Salomon | 3b8486a | 2020-04-21 12:43:26 -0400 | [diff] [blame] | 41 | GrOpsTaskClosedObserver::~GrOpsTaskClosedObserver() = default; |
| 42 | |
| 43 | //////////////////////////////////////////////////////////////////////////////// |
| 44 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 45 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); } |
| 46 | |
| 47 | //////////////////////////////////////////////////////////////////////////////// |
| 48 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 49 | inline GrOpsTask::OpChain::List::List(GrOp::Owner op) |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 50 | : fHead(std::move(op)), fTail(fHead.get()) { |
| 51 | this->validate(); |
| 52 | } |
| 53 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 54 | inline GrOpsTask::OpChain::List::List(List&& that) { *this = std::move(that); } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 55 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 56 | inline GrOpsTask::OpChain::List& GrOpsTask::OpChain::List::operator=(List&& that) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 57 | fHead = std::move(that.fHead); |
| 58 | fTail = that.fTail; |
| 59 | that.fTail = nullptr; |
| 60 | this->validate(); |
| 61 | return *this; |
| 62 | } |
| 63 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 64 | inline GrOp::Owner GrOpsTask::OpChain::List::popHead() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 65 | SkASSERT(fHead); |
| 66 | auto temp = fHead->cutChain(); |
| 67 | std::swap(temp, fHead); |
| 68 | if (!fHead) { |
| 69 | SkASSERT(fTail == temp.get()); |
| 70 | fTail = nullptr; |
| 71 | } |
| 72 | return temp; |
| 73 | } |
| 74 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 75 | inline GrOp::Owner GrOpsTask::OpChain::List::removeOp(GrOp* op) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 76 | #ifdef SK_DEBUG |
| 77 | auto head = op; |
| 78 | while (head->prevInChain()) { head = head->prevInChain(); } |
| 79 | SkASSERT(head == fHead.get()); |
| 80 | #endif |
| 81 | auto prev = op->prevInChain(); |
| 82 | if (!prev) { |
| 83 | SkASSERT(op == fHead.get()); |
| 84 | return this->popHead(); |
| 85 | } |
| 86 | auto temp = prev->cutChain(); |
| 87 | if (auto next = temp->cutChain()) { |
| 88 | prev->chainConcat(std::move(next)); |
| 89 | } else { |
| 90 | SkASSERT(fTail == op); |
| 91 | fTail = prev; |
| 92 | } |
| 93 | this->validate(); |
| 94 | return temp; |
| 95 | } |
| 96 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 97 | inline void GrOpsTask::OpChain::List::pushHead(GrOp::Owner op) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 98 | SkASSERT(op); |
| 99 | SkASSERT(op->isChainHead()); |
| 100 | SkASSERT(op->isChainTail()); |
| 101 | if (fHead) { |
| 102 | op->chainConcat(std::move(fHead)); |
| 103 | fHead = std::move(op); |
| 104 | } else { |
| 105 | fHead = std::move(op); |
| 106 | fTail = fHead.get(); |
| 107 | } |
| 108 | } |
| 109 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 110 | inline void GrOpsTask::OpChain::List::pushTail(GrOp::Owner op) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 111 | SkASSERT(op->isChainTail()); |
| 112 | fTail->chainConcat(std::move(op)); |
| 113 | fTail = fTail->nextInChain(); |
| 114 | } |
| 115 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 116 | inline void GrOpsTask::OpChain::List::validate() const { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 117 | #ifdef SK_DEBUG |
| 118 | if (fHead) { |
| 119 | SkASSERT(fTail); |
| 120 | fHead->validateChain(fTail); |
| 121 | } |
| 122 | #endif |
| 123 | } |
| 124 | |
| 125 | //////////////////////////////////////////////////////////////////////////////// |
| 126 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 127 | GrOpsTask::OpChain::OpChain(GrOp::Owner op, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 128 | GrProcessorSet::Analysis processorAnalysis, |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 129 | GrAppliedClip* appliedClip, const DstProxyView* dstProxyView) |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 130 | : fList{std::move(op)} |
| 131 | , fProcessorAnalysis(processorAnalysis) |
| 132 | , fAppliedClip(appliedClip) { |
| 133 | if (fProcessorAnalysis.requiresDstTexture()) { |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 134 | SkASSERT(dstProxyView && dstProxyView->proxy()); |
| 135 | fDstProxyView = *dstProxyView; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 136 | } |
| 137 | fBounds = fList.head()->bounds(); |
| 138 | } |
| 139 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 140 | void GrOpsTask::OpChain::visitProxies(const GrOp::VisitProxyFunc& func) const { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 141 | if (fList.empty()) { |
| 142 | return; |
| 143 | } |
| 144 | for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 145 | op.visitProxies(func); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 146 | } |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 147 | if (fDstProxyView.proxy()) { |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 148 | func(fDstProxyView.proxy(), GrMipmapped::kNo); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 149 | } |
| 150 | if (fAppliedClip) { |
| 151 | fAppliedClip->visitProxies(func); |
| 152 | } |
| 153 | } |
| 154 | |
Herb Derby | e32e1ab | 2020-10-27 10:29:46 -0400 | [diff] [blame^] | 155 | void GrOpsTask::OpChain::deleteOps() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 156 | while (!fList.empty()) { |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 157 | // Since the value goes out of scope immediately, the GrOp::Owner deletes the op. |
| 158 | fList.popHead(); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
| 162 | // Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that |
| 163 | // the two chains are chainable. Returns the new chain. |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 164 | GrOpsTask::OpChain::List GrOpsTask::OpChain::DoConcat( |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 165 | List chainA, List chainB, const GrCaps& caps, GrRecordingContext::Arenas* arenas, |
| 166 | GrAuditTrail* auditTrail) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 167 | // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting |
| 168 | // at chain a's tail and working toward the head. We produce one of the following outcomes: |
| 169 | // 1) b's head is merged into an op in a. |
| 170 | // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.) |
| 171 | // 3) b's head is popped from chain a and added at the tail of a. |
| 172 | // After result 3 we don't want to attempt to merge the next head of b with the new tail of a, |
| 173 | // as we assume merges were already attempted when chain b was created. So we keep track of the |
| 174 | // original tail of a and start our iteration of a there. We also track the bounds of the nodes |
| 175 | // appended to chain a that will be skipped for bounds testing. If the original tail of a is |
| 176 | // merged into an op in b (case 2) then we advance the "original tail" towards the head of a. |
| 177 | GrOp* origATail = chainA.tail(); |
| 178 | SkRect skipBounds = SkRectPriv::MakeLargestInverted(); |
| 179 | do { |
| 180 | int numMergeChecks = 0; |
| 181 | bool merged = false; |
| 182 | bool noSkip = (origATail == chainA.tail()); |
| 183 | SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted())); |
| 184 | bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds); |
| 185 | SkRect forwardMergeBounds = skipBounds; |
| 186 | GrOp* a = origATail; |
| 187 | while (a) { |
| 188 | bool canForwardMerge = |
| 189 | (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds); |
| 190 | if (canForwardMerge || canBackwardMerge) { |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 191 | auto result = a->combineIfPossible(chainB.head(), arenas, caps); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 192 | SkASSERT(result != GrOp::CombineResult::kCannotCombine); |
| 193 | merged = (result == GrOp::CombineResult::kMerged); |
Robert Phillips | 9548c3b42 | 2019-01-08 12:35:43 -0500 | [diff] [blame] | 194 | GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n", |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 195 | chainB.head()->name(), chainB.head()->uniqueID(), a->name(), |
| 196 | a->uniqueID()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 197 | } |
| 198 | if (merged) { |
Brian Salomon | 52a6ed3 | 2018-11-26 10:30:58 -0500 | [diff] [blame] | 199 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 200 | if (canBackwardMerge) { |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 201 | // The GrOp::Owner releases the op. |
| 202 | chainB.popHead(); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 203 | } else { |
| 204 | // We merged the contents of b's head into a. We will replace b's head with a in |
| 205 | // chain b. |
| 206 | SkASSERT(canForwardMerge); |
| 207 | if (a == origATail) { |
| 208 | origATail = a->prevInChain(); |
| 209 | } |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 210 | GrOp::Owner detachedA = chainA.removeOp(a); |
| 211 | // The GrOp::Owner releases the op. |
| 212 | chainB.popHead(); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 213 | chainB.pushHead(std::move(detachedA)); |
| 214 | if (chainA.empty()) { |
| 215 | // We merged all the nodes in chain a to chain b. |
| 216 | return chainB; |
| 217 | } |
| 218 | } |
| 219 | break; |
| 220 | } else { |
| 221 | if (++numMergeChecks == kMaxOpMergeDistance) { |
| 222 | break; |
| 223 | } |
| 224 | forwardMergeBounds.joinNonEmptyArg(a->bounds()); |
| 225 | canBackwardMerge = |
| 226 | canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds()); |
| 227 | a = a->prevInChain(); |
| 228 | } |
| 229 | } |
| 230 | // If we weren't able to merge b's head then pop b's head from chain b and make it the new |
| 231 | // tail of a. |
| 232 | if (!merged) { |
| 233 | chainA.pushTail(chainB.popHead()); |
| 234 | skipBounds.joinNonEmptyArg(chainA.tail()->bounds()); |
| 235 | } |
| 236 | } while (!chainB.empty()); |
| 237 | return chainA; |
| 238 | } |
| 239 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 240 | // Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns |
| 241 | // whether the operation succeeded. On success, the provided list will be returned empty. |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 242 | bool GrOpsTask::OpChain::tryConcat( |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 243 | List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxyView& dstProxyView, |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 244 | const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps, |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 245 | GrRecordingContext::Arenas* arenas, GrAuditTrail* auditTrail) { |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 246 | SkASSERT(!fList.empty()); |
| 247 | SkASSERT(!list->empty()); |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 248 | SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy())); |
| 249 | SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy())); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 250 | // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug. |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 251 | if (fList.head()->classID() != list->head()->classID() || |
| 252 | SkToBool(fAppliedClip) != SkToBool(appliedClip) || |
| 253 | (fAppliedClip && *fAppliedClip != *appliedClip) || |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 254 | (fProcessorAnalysis.requiresNonOverlappingDraws() != |
| 255 | processorAnalysis.requiresNonOverlappingDraws()) || |
| 256 | (fProcessorAnalysis.requiresNonOverlappingDraws() && |
| 257 | // Non-overlaping draws are only required when Ganesh will either insert a barrier, |
| 258 | // or read back a new dst texture between draws. In either case, we can neither |
| 259 | // chain nor combine overlapping Ops. |
| 260 | GrRectsTouchOrOverlap(fBounds, bounds)) || |
| 261 | (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) || |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 262 | (fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) { |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 263 | return false; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 264 | } |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 265 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 266 | SkDEBUGCODE(bool first = true;) |
| 267 | do { |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 268 | switch (fList.tail()->combineIfPossible(list->head(), arenas, caps)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 269 | case GrOp::CombineResult::kCannotCombine: |
| 270 | // If an op supports chaining then it is required that chaining is transitive and |
| 271 | // that if any two ops in two different chains can merge then the two chains |
| 272 | // may also be chained together. Thus, we should only hit this on the first |
| 273 | // iteration. |
| 274 | SkASSERT(first); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 275 | return false; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 276 | case GrOp::CombineResult::kMayChain: |
Adlai Holler | 5ba50af | 2020-04-29 21:11:14 -0400 | [diff] [blame] | 277 | fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, arenas, |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 278 | auditTrail); |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 279 | // The above exchange cleared out 'list'. The list needs to be empty now for the |
| 280 | // loop to terminate. |
| 281 | SkASSERT(list->empty()); |
| 282 | break; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 283 | case GrOp::CombineResult::kMerged: { |
Robert Phillips | 9548c3b42 | 2019-01-08 12:35:43 -0500 | [diff] [blame] | 284 | GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n", |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 285 | list->tail()->name(), list->tail()->uniqueID(), list->head()->name(), |
| 286 | list->head()->uniqueID()); |
| 287 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head()); |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 288 | // The GrOp::Owner releases the op. |
| 289 | list->popHead(); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 290 | break; |
| 291 | } |
| 292 | } |
| 293 | SkDEBUGCODE(first = false); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 294 | } while (!list->empty()); |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 295 | |
| 296 | // The new ops were successfully merged and/or chained onto our own. |
| 297 | fBounds.joinPossiblyEmptyRect(bounds); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 298 | return true; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 299 | } |
| 300 | |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 301 | bool GrOpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, |
| 302 | GrRecordingContext::Arenas* arenas, |
| 303 | GrAuditTrail* auditTrail) { |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 304 | if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps, |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 305 | arenas, auditTrail)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 306 | this->validate(); |
| 307 | // append failed |
| 308 | return false; |
| 309 | } |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 310 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 311 | // 'that' owns the combined chain. Move it into 'this'. |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 312 | SkASSERT(fList.empty()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 313 | fList = std::move(that->fList); |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 314 | fBounds = that->fBounds; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 315 | |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 316 | that->fDstProxyView.setProxyView({}); |
John Stiles | 59e18dc | 2020-07-22 18:18:12 -0400 | [diff] [blame] | 317 | if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) { |
| 318 | // Obliterates the processor. |
| 319 | that->fAppliedClip->detachCoverageFragmentProcessor(); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 320 | } |
| 321 | this->validate(); |
| 322 | return true; |
| 323 | } |
| 324 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 325 | GrOp::Owner GrOpsTask::OpChain::appendOp( |
| 326 | GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis, |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 327 | const DstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps, |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 328 | GrRecordingContext::Arenas* arenas, GrAuditTrail* auditTrail) { |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 329 | const GrXferProcessor::DstProxyView noDstProxyView; |
| 330 | if (!dstProxyView) { |
| 331 | dstProxyView = &noDstProxyView; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 332 | } |
| 333 | SkASSERT(op->isChainHead() && op->isChainTail()); |
| 334 | SkRect opBounds = op->bounds(); |
| 335 | List chain(std::move(op)); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 336 | if (!this->tryConcat( |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 337 | &chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps, |
| 338 | arenas, auditTrail)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 339 | // append failed, give the op back to the caller. |
| 340 | this->validate(); |
| 341 | return chain.popHead(); |
| 342 | } |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 343 | |
| 344 | SkASSERT(chain.empty()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 345 | this->validate(); |
| 346 | return nullptr; |
| 347 | } |
| 348 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 349 | inline void GrOpsTask::OpChain::validate() const { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 350 | #ifdef SK_DEBUG |
| 351 | fList.validate(); |
| 352 | for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
| 353 | // Not using SkRect::contains because we allow empty rects. |
| 354 | SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop && |
| 355 | fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom); |
| 356 | } |
| 357 | #endif |
| 358 | } |
| 359 | |
| 360 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 361 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 362 | GrOpsTask::GrOpsTask(GrDrawingManager* drawingMgr, GrRecordingContext::Arenas arenas, |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 363 | GrSurfaceProxyView view, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 364 | GrAuditTrail* auditTrail) |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 365 | : GrRenderTask() |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 366 | , fArenas(arenas) |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 367 | , fAuditTrail(auditTrail) |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 368 | SkDEBUGCODE(, fNumClips(0)) { |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 369 | this->addTarget(drawingMgr, std::move(view)); |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 372 | void GrOpsTask::deleteOps() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 373 | for (auto& chain : fOpChains) { |
Herb Derby | e32e1ab | 2020-10-27 10:29:46 -0400 | [diff] [blame^] | 374 | chain.deleteOps(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 375 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 376 | fOpChains.reset(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 377 | } |
| 378 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 379 | GrOpsTask::~GrOpsTask() { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 380 | this->deleteOps(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Brian Salomon | f1c9eae | 2020-05-01 15:00:34 -0400 | [diff] [blame] | 383 | void GrOpsTask::removeClosedObserver(GrOpsTaskClosedObserver* observer) { |
| 384 | SkASSERT(observer); |
| 385 | for (int i = 0; i < fClosedObservers.count(); ++i) { |
| 386 | if (fClosedObservers[i] == observer) { |
| 387 | fClosedObservers.removeShuffle(i); |
| 388 | --i; |
| 389 | } |
| 390 | } |
| 391 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 392 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 393 | void GrOpsTask::endFlush(GrDrawingManager* drawingMgr) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 394 | fLastClipStackGenID = SK_InvalidUniqueID; |
| 395 | this->deleteOps(); |
| 396 | fClipAllocator.reset(); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 397 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 398 | fDeferredProxies.reset(); |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 399 | fSampledProxies.reset(); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 400 | fAuditTrail = nullptr; |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 401 | |
| 402 | GrRenderTask::endFlush(drawingMgr); |
Greg Daniel | f21bf9e | 2019-08-22 20:12:20 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 405 | void GrOpsTask::onPrePrepare(GrRecordingContext* context) { |
Robert Phillips | 7327c9d | 2019-10-08 16:32:56 -0400 | [diff] [blame] | 406 | SkASSERT(this->isClosed()); |
| 407 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 408 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 409 | #endif |
| 410 | // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we |
| 411 | // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation |
| 412 | // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled |
| 413 | // we shouldn't end up with GrOpsTasks with only discard. |
| 414 | if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) { |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | for (const auto& chain : fOpChains) { |
| 419 | if (chain.shouldExecute()) { |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 420 | chain.head()->prePrepare(context, |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 421 | &fTargets[0], |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 422 | chain.appliedClip(), |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 423 | chain.dstProxyView(), |
| 424 | fRenderPassXferBarriers); |
Robert Phillips | 7327c9d | 2019-10-08 16:32:56 -0400 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 429 | void GrOpsTask::onPrepare(GrOpFlushState* flushState) { |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 430 | SkASSERT(this->target(0).proxy()->peekRenderTarget()); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 431 | SkASSERT(this->isClosed()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 432 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 433 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 434 | #endif |
Greg Daniel | 94ed83f | 2019-09-27 13:05:43 -0400 | [diff] [blame] | 435 | // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we |
| 436 | // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation |
| 437 | // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled |
| 438 | // we shouldn't end up with GrOpsTasks with only discard. |
| 439 | if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) { |
| 440 | return; |
| 441 | } |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 442 | |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 443 | flushState->setSampledProxyArray(&fSampledProxies); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 444 | // Loop over the ops that haven't yet been prepared. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 445 | for (const auto& chain : fOpChains) { |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 446 | if (chain.shouldExecute()) { |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 447 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 448 | TRACE_EVENT0("skia.gpu", chain.head()->name()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 449 | #endif |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 450 | GrOpFlushState::OpArgs opArgs(chain.head(), |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 451 | &fTargets[0], |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 452 | chain.appliedClip(), |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 453 | chain.dstProxyView(), |
| 454 | fRenderPassXferBarriers); |
Robert Phillips | 405413f | 2019-10-04 10:39:28 -0400 | [diff] [blame] | 455 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 456 | flushState->setOpArgs(&opArgs); |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 457 | |
| 458 | // Temporary debugging helper: for debugging prePrepare w/o going through DDLs |
| 459 | // Delete once most of the GrOps have an onPrePrepare. |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 460 | // chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0), |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 461 | // chain.appliedClip()); |
| 462 | |
Robert Phillips | 7327c9d | 2019-10-08 16:32:56 -0400 | [diff] [blame] | 463 | // GrOp::prePrepare may or may not have been called at this point |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 464 | chain.head()->prepare(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 465 | flushState->setOpArgs(nullptr); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 466 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 467 | } |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 468 | flushState->setSampledProxyArray(nullptr); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 469 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 470 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 471 | static GrOpsRenderPass* create_render_pass(GrGpu* gpu, |
| 472 | GrRenderTarget* rt, |
| 473 | GrAttachment* stencil, |
| 474 | GrSurfaceOrigin origin, |
| 475 | const SkIRect& bounds, |
| 476 | GrLoadOp colorLoadOp, |
| 477 | const SkPMColor4f& loadClearColor, |
| 478 | GrLoadOp stencilLoadOp, |
| 479 | GrStoreOp stencilStoreOp, |
| 480 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 481 | GrXferBarrierFlags renderPassXferBarriers) { |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 482 | const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 483 | colorLoadOp, |
| 484 | GrStoreOp::kStore, |
| 485 | loadClearColor |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 486 | }; |
| 487 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 488 | // TODO: |
| 489 | // We would like to (at this level) only ever clear & discard. We would need |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 490 | // to stop splitting up higher level OpsTasks for copyOps to achieve that. |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 491 | // Note: we would still need SB loads and stores but they would happen at a |
| 492 | // lower level (inside the VK command buffer). |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 493 | const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 494 | stencilLoadOp, |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 495 | stencilStoreOp, |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 496 | }; |
| 497 | |
Robert Phillips | 96f2237 | 2020-05-20 12:31:18 -0400 | [diff] [blame] | 498 | return gpu->getOpsRenderPass(rt, stencil, origin, bounds, |
Greg Daniel | 9a18b08 | 2020-08-14 14:03:50 -0400 | [diff] [blame] | 499 | kColorLoadStoreInfo, stencilLoadAndStoreInfo, sampledProxies, |
Greg Daniel | 2177436 | 2020-09-14 10:36:43 -0400 | [diff] [blame] | 500 | renderPassXferBarriers); |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 501 | } |
| 502 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 503 | // TODO: this is where GrOp::renderTarget is used (which is fine since it |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 504 | // is at flush time). However, we need to store the RenderTargetProxy in the |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 505 | // Ops and instantiate them here. |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 506 | bool GrOpsTask::onExecute(GrOpFlushState* flushState) { |
Greg Daniel | 94ed83f | 2019-09-27 13:05:43 -0400 | [diff] [blame] | 507 | // TODO: remove the check for discard here once reduced op splitting is turned on. Currently we |
| 508 | // can end up with GrOpsTasks that only have a discard load op and no ops. For vulkan validation |
| 509 | // we need to keep that discard and not drop it. Once we have reduce op list splitting enabled |
| 510 | // we shouldn't end up with GrOpsTasks with only discard. |
| 511 | if (this->isNoOp() || (fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 512 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 513 | } |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 514 | |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 515 | SkASSERT(this->numTargets() == 1); |
| 516 | GrRenderTargetProxy* proxy = this->target(0).proxy()->asRenderTargetProxy(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 517 | SkASSERT(proxy); |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 518 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 519 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 520 | // Make sure load ops are not kClear if the GPU needs to use draws for clears |
| 521 | SkASSERT(fColorLoadOp != GrLoadOp::kClear || |
| 522 | !flushState->gpu()->caps()->performColorClearsAsDraws()); |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 523 | |
| 524 | const GrCaps& caps = *flushState->gpu()->caps(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 525 | GrRenderTarget* renderTarget = proxy->peekRenderTarget(); |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 526 | SkASSERT(renderTarget); |
Chris Dalton | 0b68dda | 2019-11-07 21:08:03 -0700 | [diff] [blame] | 527 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 528 | GrAttachment* stencil = nullptr; |
Chris Dalton | 0b68dda | 2019-11-07 21:08:03 -0700 | [diff] [blame] | 529 | if (int numStencilSamples = proxy->numStencilSamples()) { |
| 530 | if (!flushState->resourceProvider()->attachStencilAttachment( |
| 531 | renderTarget, numStencilSamples)) { |
| 532 | SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n"); |
| 533 | return false; |
| 534 | } |
Brian Salomon | f7f5433 | 2020-07-28 09:23:35 -0400 | [diff] [blame] | 535 | stencil = renderTarget->getStencilAttachment(); |
Chris Dalton | 0b68dda | 2019-11-07 21:08:03 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Chris Dalton | f00b95b | 2019-11-07 21:14:41 -0700 | [diff] [blame] | 538 | SkASSERT(!stencil || stencil->numSamples() == proxy->numStencilSamples()); |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 539 | |
| 540 | GrLoadOp stencilLoadOp; |
| 541 | switch (fInitialStencilContent) { |
| 542 | case StencilContent::kDontCare: |
| 543 | stencilLoadOp = GrLoadOp::kDiscard; |
| 544 | break; |
| 545 | case StencilContent::kUserBitsCleared: |
| 546 | SkASSERT(!caps.performStencilClearsAsDraws()); |
| 547 | SkASSERT(stencil); |
| 548 | if (caps.discardStencilValuesAfterRenderPass()) { |
| 549 | // Always clear the stencil if it is being discarded after render passes. This is |
| 550 | // also an optimization because we are on a tiler and it avoids loading the values |
| 551 | // from memory. |
| 552 | stencilLoadOp = GrLoadOp::kClear; |
| 553 | break; |
| 554 | } |
| 555 | if (!stencil->hasPerformedInitialClear()) { |
| 556 | stencilLoadOp = GrLoadOp::kClear; |
| 557 | stencil->markHasPerformedInitialClear(); |
| 558 | break; |
| 559 | } |
| 560 | // renderTargetContexts are required to leave the user stencil bits in a cleared state |
| 561 | // once finished, meaning the stencil values will always remain cleared after the |
| 562 | // initial clear. Just fall through to reloading the existing (cleared) stencil values |
| 563 | // from memory. |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame] | 564 | [[fallthrough]]; |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 565 | case StencilContent::kPreserved: |
| 566 | SkASSERT(stencil); |
| 567 | stencilLoadOp = GrLoadOp::kLoad; |
| 568 | break; |
| 569 | } |
| 570 | |
| 571 | // NOTE: If fMustPreserveStencil is set, then we are executing a renderTargetContext that split |
| 572 | // its opsTask. |
| 573 | // |
| 574 | // FIXME: We don't currently flag render passes that don't use stencil at all. In that case |
| 575 | // their store op might be "discard", and we currently make the assumption that a discard will |
| 576 | // not invalidate what's already in main memory. This is probably ok for now, but certainly |
| 577 | // something we want to address soon. |
| 578 | GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil) |
| 579 | ? GrStoreOp::kDiscard |
| 580 | : GrStoreOp::kStore; |
| 581 | |
Greg Daniel | 4a0d36d | 2019-09-30 12:24:36 -0400 | [diff] [blame] | 582 | GrOpsRenderPass* renderPass = create_render_pass( |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 583 | flushState->gpu(), proxy->peekRenderTarget(), stencil, this->target(0).origin(), |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 584 | fClippedContentBounds, fColorLoadOp, fLoadClearColor, stencilLoadOp, stencilStoreOp, |
Greg Daniel | 2177436 | 2020-09-14 10:36:43 -0400 | [diff] [blame] | 585 | fSampledProxies, fRenderPassXferBarriers); |
| 586 | |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame] | 587 | if (!renderPass) { |
| 588 | return false; |
| 589 | } |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 590 | flushState->setOpsRenderPass(renderPass); |
| 591 | renderPass->begin(); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 592 | |
| 593 | // Draw all the generated geometry. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 594 | for (const auto& chain : fOpChains) { |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 595 | if (!chain.shouldExecute()) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 596 | continue; |
| 597 | } |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 598 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 599 | TRACE_EVENT0("skia.gpu", chain.head()->name()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 600 | #endif |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 601 | |
Robert Phillips | 405413f | 2019-10-04 10:39:28 -0400 | [diff] [blame] | 602 | GrOpFlushState::OpArgs opArgs(chain.head(), |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 603 | &fTargets[0], |
Robert Phillips | 405413f | 2019-10-04 10:39:28 -0400 | [diff] [blame] | 604 | chain.appliedClip(), |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 605 | chain.dstProxyView(), |
| 606 | fRenderPassXferBarriers); |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 607 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 608 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 609 | chain.head()->execute(flushState, chain.bounds()); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 610 | flushState->setOpArgs(nullptr); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 611 | } |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 612 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 613 | renderPass->end(); |
| 614 | flushState->gpu()->submit(renderPass); |
| 615 | flushState->setOpsRenderPass(nullptr); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 616 | |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 617 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 620 | void GrOpsTask::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 621 | fColorLoadOp = op; |
| 622 | fLoadClearColor = color; |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 623 | if (GrLoadOp::kClear == fColorLoadOp) { |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 624 | GrSurfaceProxy* proxy = this->target(0).proxy(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 625 | SkASSERT(proxy); |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 626 | fTotalBounds = proxy->backingStoreBoundsRect(); |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 627 | } |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 628 | } |
| 629 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 630 | bool GrOpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) { |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 631 | if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 632 | this->deleteOps(); |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 633 | fDeferredProxies.reset(); |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 634 | fSampledProxies.reset(); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 635 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 636 | // If the opsTask is using a render target which wraps a vulkan command buffer, we can't do |
| 637 | // a clear load since we cannot change the render pass that we are using. Thus we fall back |
| 638 | // to making a clear op in this case. |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 639 | return !this->target(0).asRenderTargetProxy()->wrapsVkSecondaryCB(); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 640 | } |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 641 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 642 | // Could not empty the task, so an op must be added to handle the clear |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 643 | return false; |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 646 | void GrOpsTask::discard() { |
| 647 | // Discard calls to in-progress opsTasks are ignored. Calls at the start update the |
| 648 | // opsTasks' color & stencil load ops. |
| 649 | if (this->isEmpty()) { |
| 650 | fColorLoadOp = GrLoadOp::kDiscard; |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 651 | fInitialStencilContent = StencilContent::kDontCare; |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 652 | fTotalBounds.setEmpty(); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 656 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 657 | |
John Stiles | 1e0136e | 2020-08-12 18:44:00 -0400 | [diff] [blame] | 658 | #if GR_TEST_UTILS |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 659 | void GrOpsTask::dump(bool printDependencies) const { |
| 660 | GrRenderTask::dump(printDependencies); |
| 661 | |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 662 | SkDebugf("fColorLoadOp: "); |
| 663 | switch (fColorLoadOp) { |
| 664 | case GrLoadOp::kLoad: |
| 665 | SkDebugf("kLoad\n"); |
| 666 | break; |
| 667 | case GrLoadOp::kClear: |
| 668 | SkDebugf("kClear (0x%x)\n", fLoadClearColor.toBytes_RGBA()); |
| 669 | break; |
| 670 | case GrLoadOp::kDiscard: |
| 671 | SkDebugf("kDiscard\n"); |
| 672 | break; |
| 673 | } |
| 674 | |
| 675 | SkDebugf("fInitialStencilContent: "); |
| 676 | switch (fInitialStencilContent) { |
| 677 | case StencilContent::kDontCare: |
| 678 | SkDebugf("kDontCare\n"); |
| 679 | break; |
| 680 | case StencilContent::kUserBitsCleared: |
| 681 | SkDebugf("kUserBitsCleared\n"); |
| 682 | break; |
| 683 | case StencilContent::kPreserved: |
| 684 | SkDebugf("kPreserved\n"); |
| 685 | break; |
| 686 | } |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 687 | |
| 688 | SkDebugf("ops (%d):\n", fOpChains.count()); |
| 689 | for (int i = 0; i < fOpChains.count(); ++i) { |
| 690 | SkDebugf("*******************************\n"); |
| 691 | if (!fOpChains[i].head()) { |
| 692 | SkDebugf("%d: <combined forward or failed instantiation>\n", i); |
| 693 | } else { |
| 694 | SkDebugf("%d: %s\n", i, fOpChains[i].head()->name()); |
| 695 | SkRect bounds = fOpChains[i].bounds(); |
| 696 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 697 | bounds.fTop, bounds.fRight, bounds.fBottom); |
| 698 | for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) { |
| 699 | SkString info = SkTabString(op.dumpInfo(), 1); |
| 700 | SkDebugf("%s\n", info.c_str()); |
| 701 | bounds = op.bounds(); |
| 702 | SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 703 | bounds.fTop, bounds.fRight, bounds.fBottom); |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | } |
John Stiles | 1e0136e | 2020-08-12 18:44:00 -0400 | [diff] [blame] | 708 | #endif |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 709 | |
John Stiles | 1e0136e | 2020-08-12 18:44:00 -0400 | [diff] [blame] | 710 | #ifdef SK_DEBUG |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 711 | void GrOpsTask::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const { |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 712 | auto textureFunc = [ func ] (GrSurfaceProxy* tex, GrMipmapped mipmapped) { |
Greg Daniel | dcf9ca1 | 2019-08-27 14:30:21 -0400 | [diff] [blame] | 713 | func(tex, mipmapped); |
| 714 | }; |
| 715 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 716 | for (const OpChain& chain : fOpChains) { |
Greg Daniel | dcf9ca1 | 2019-08-27 14:30:21 -0400 | [diff] [blame] | 717 | chain.visitProxies(textureFunc); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | #endif |
| 722 | |
| 723 | //////////////////////////////////////////////////////////////////////////////// |
| 724 | |
| 725 | bool GrOpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const { |
| 726 | bool used = false; |
| 727 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 728 | auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p, GrMipmapped) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 729 | if (p == proxyToCheck) { |
| 730 | used = true; |
| 731 | } |
| 732 | }; |
| 733 | for (const OpChain& recordedOp : fOpChains) { |
| 734 | recordedOp.visitProxies(visit); |
| 735 | } |
| 736 | |
| 737 | return used; |
| 738 | } |
| 739 | |
| 740 | void GrOpsTask::handleInternalAllocationFailure() { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 741 | bool hasUninstantiatedProxy = false; |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 742 | auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p, GrMipmapped) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 743 | if (!p->isInstantiated()) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 744 | hasUninstantiatedProxy = true; |
| 745 | } |
| 746 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 747 | for (OpChain& recordedOp : fOpChains) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 748 | hasUninstantiatedProxy = false; |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 749 | recordedOp.visitProxies(checkInstantiation); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 750 | if (hasUninstantiatedProxy) { |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 751 | recordedOp.setSkipExecuteFlag(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | } |
| 755 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 756 | void GrOpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 757 | for (int i = 0; i < fDeferredProxies.count(); ++i) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 758 | SkASSERT(!fDeferredProxies[i]->isInstantiated()); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 759 | // We give all the deferred proxies a write usage at the very start of flushing. This |
| 760 | // locks them out of being reused for the entire flush until they are read - and then |
| 761 | // they can be recycled. This is a bit unfortunate because a flush can proceed in waves |
| 762 | // with sub-flushes. The deferred proxies only need to be pinned from the start of |
| 763 | // the sub-flush in which they appear. |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 764 | alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 765 | } |
| 766 | |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 767 | GrSurfaceProxy* targetProxy = this->target(0).proxy(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 768 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 769 | // Add the interval for all the writes to this GrOpsTasks's target |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 770 | if (fOpChains.count()) { |
Robert Phillips | 3bf3d4a | 2019-03-27 07:09:09 -0400 | [diff] [blame] | 771 | unsigned int cur = alloc->curOp(); |
| 772 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 773 | alloc->addInterval(targetProxy, cur, cur + fOpChains.count() - 1, |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 774 | GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 775 | } else { |
| 776 | // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we |
| 777 | // still need to add an interval for the destination so we create a fake op# for |
| 778 | // the missing clear op. |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 779 | alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(), |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 780 | GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 781 | alloc->incOps(); |
| 782 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 783 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 784 | auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipmapped) { |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 785 | alloc->addInterval(p, alloc->curOp(), alloc->curOp(), GrResourceAllocator::ActualUse::kYes |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 786 | SkDEBUGCODE(, this->target(0).proxy() == p)); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 787 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 788 | for (const OpChain& recordedOp : fOpChains) { |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 789 | recordedOp.visitProxies(gather); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 790 | |
Robert Phillips | 3bf3d4a | 2019-03-27 07:09:09 -0400 | [diff] [blame] | 791 | // Even though the op may have been (re)moved we still need to increment the op count to |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 792 | // keep all the math consistent. |
| 793 | alloc->incOps(); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 797 | void GrOpsTask::recordOp( |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 798 | GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip, |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 799 | const DstProxyView* dstProxyView, const GrCaps& caps) { |
Ethan Nicholas | 029b22c | 2018-10-18 16:49:56 -0400 | [diff] [blame] | 800 | SkDEBUGCODE(op->validate();) |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 801 | SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy())); |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 802 | GrSurfaceProxy* proxy = this->target(0).proxy(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 803 | SkASSERT(proxy); |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 804 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 805 | // A closed GrOpsTask should never receive new/more ops |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 806 | SkASSERT(!this->isClosed()); |
Brian Salomon | 19ec80f | 2018-11-16 13:27:30 -0500 | [diff] [blame] | 807 | if (!op->bounds().isFinite()) { |
Brian Salomon | 19ec80f | 2018-11-16 13:27:30 -0500 | [diff] [blame] | 808 | return; |
| 809 | } |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 810 | |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 811 | // Account for this op's bounds before we attempt to combine. |
| 812 | // NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable. |
| 813 | fTotalBounds.join(op->bounds()); |
| 814 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 815 | // Check if there is an op we can combine with by linearly searching back until we either |
| 816 | // 1) check every op |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 817 | // 2) intersect with something |
| 818 | // 3) find a 'blocker' |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 819 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID()); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 820 | GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n" |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 821 | "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n", |
| 822 | this->uniqueID(), |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 823 | op->name(), |
| 824 | op->uniqueID(), |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 825 | op->bounds().fLeft, op->bounds().fTop, |
| 826 | op->bounds().fRight, op->bounds().fBottom); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 827 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 828 | GrOP_INFO("\tOutcome:\n"); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 829 | int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.count()); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 830 | if (maxCandidates) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 831 | int i = 0; |
| 832 | while (true) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 833 | OpChain& candidate = fOpChains.fromBack(i); |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 834 | op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps, |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 835 | &fArenas, fAuditTrail); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 836 | if (!op) { |
| 837 | return; |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 838 | } |
Brian Salomon | a7682c8 | 2018-10-24 10:04:37 -0400 | [diff] [blame] | 839 | // Stop going backwards if we would cause a painter's order violation. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 840 | if (!can_reorder(candidate.bounds(), op->bounds())) { |
| 841 | GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n", |
| 842 | candidate.head()->name(), candidate.head()->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 843 | break; |
| 844 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 845 | if (++i == maxCandidates) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 846 | GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 847 | break; |
| 848 | } |
| 849 | } |
| 850 | } else { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 851 | GrOP_INFO("\t\tBackward: FirstOp\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 852 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 853 | if (clip) { |
| 854 | clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip)); |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 855 | SkDEBUGCODE(fNumClips++;) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 856 | } |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 857 | fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 860 | void GrOpsTask::forwardCombine(const GrCaps& caps) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 861 | SkASSERT(!this->isClosed()); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 862 | GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count()); |
Robert Phillips | 48567ac | 2017-06-01 08:46:00 -0400 | [diff] [blame] | 863 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 864 | for (int i = 0; i < fOpChains.count() - 1; ++i) { |
| 865 | OpChain& chain = fOpChains[i]; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 866 | int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 867 | int j = i + 1; |
| 868 | while (true) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 869 | OpChain& candidate = fOpChains[j]; |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 870 | if (candidate.prependChain(&chain, caps, &fArenas, fAuditTrail)) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 871 | break; |
| 872 | } |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 873 | // Stop traversing if we would cause a painter's order violation. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 874 | if (!can_reorder(chain.bounds(), candidate.bounds())) { |
| 875 | GrOP_INFO( |
| 876 | "\t\t%d: chain (%s head opID: %u) -> " |
| 877 | "Intersects with chain (%s, head opID: %u)\n", |
| 878 | i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(), |
| 879 | candidate.head()->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 880 | break; |
| 881 | } |
Brian Salomon | a7682c8 | 2018-10-24 10:04:37 -0400 | [diff] [blame] | 882 | if (++j > maxCandidateIdx) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 883 | GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n", |
| 884 | i, chain.head()->name(), chain.head()->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 885 | break; |
| 886 | } |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 891 | GrRenderTask::ExpectedOutcome GrOpsTask::onMakeClosed( |
| 892 | const GrCaps& caps, SkIRect* targetUpdateBounds) { |
| 893 | this->forwardCombine(caps); |
Brian Salomon | f1c9eae | 2020-05-01 15:00:34 -0400 | [diff] [blame] | 894 | SkScopeExit triggerObservers([&] { |
| 895 | for (const auto& o : fClosedObservers) { |
| 896 | o->wasClosed(*this); |
Brian Salomon | 3b8486a | 2020-04-21 12:43:26 -0400 | [diff] [blame] | 897 | } |
Brian Salomon | f1c9eae | 2020-05-01 15:00:34 -0400 | [diff] [blame] | 898 | fClosedObservers.reset(); |
Brian Salomon | 3b8486a | 2020-04-21 12:43:26 -0400 | [diff] [blame] | 899 | }); |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 900 | if (!this->isNoOp()) { |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 901 | GrSurfaceProxy* proxy = this->target(0).proxy(); |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 902 | // Use the entire backing store bounds since the GPU doesn't clip automatically to the |
| 903 | // logical dimensions. |
| 904 | SkRect clippedContentBounds = proxy->backingStoreBoundsRect(); |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 905 | // TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 906 | // then we can simply assert here that the bounds intersect. |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 907 | if (clippedContentBounds.intersect(fTotalBounds)) { |
Greg Daniel | 94ed83f | 2019-09-27 13:05:43 -0400 | [diff] [blame] | 908 | clippedContentBounds.roundOut(&fClippedContentBounds); |
| 909 | *targetUpdateBounds = fClippedContentBounds; |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 910 | return ExpectedOutcome::kTargetDirty; |
| 911 | } |
| 912 | } |
| 913 | return ExpectedOutcome::kTargetUnchanged; |
| 914 | } |