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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/private/GrRecordingContext.h" |
| 11 | #include "src/core/SkExchange.h" |
| 12 | #include "src/core/SkRectPriv.h" |
| 13 | #include "src/core/SkTraceEvent.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrCaps.h" |
| 16 | #include "src/gpu/GrGpu.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrMemoryPool.h" |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrOpFlushState.h" |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrOpsRenderPass.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrRecordingContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrRenderTargetContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "src/gpu/GrResourceAllocator.h" |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 23 | #include "src/gpu/GrTexturePriv.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 24 | #include "src/gpu/geometry/GrRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/ops/GrClearOp.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 26 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | //////////////////////////////////////////////////////////////////////////////// |
| 28 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 29 | // 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] | 30 | static const int kMaxOpMergeDistance = 10; |
| 31 | static const int kMaxOpChainDistance = 10; |
| 32 | |
| 33 | //////////////////////////////////////////////////////////////////////////////// |
| 34 | |
| 35 | using DstProxy = GrXferProcessor::DstProxy; |
| 36 | |
| 37 | //////////////////////////////////////////////////////////////////////////////// |
| 38 | |
| 39 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); } |
| 40 | |
| 41 | //////////////////////////////////////////////////////////////////////////////// |
| 42 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 43 | inline GrOpsTask::OpChain::List::List(std::unique_ptr<GrOp> op) |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 44 | : fHead(std::move(op)), fTail(fHead.get()) { |
| 45 | this->validate(); |
| 46 | } |
| 47 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 48 | inline GrOpsTask::OpChain::List::List(List&& that) { *this = std::move(that); } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 49 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 50 | inline GrOpsTask::OpChain::List& GrOpsTask::OpChain::List::operator=(List&& that) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 51 | fHead = std::move(that.fHead); |
| 52 | fTail = that.fTail; |
| 53 | that.fTail = nullptr; |
| 54 | this->validate(); |
| 55 | return *this; |
| 56 | } |
| 57 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 58 | inline std::unique_ptr<GrOp> GrOpsTask::OpChain::List::popHead() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 59 | SkASSERT(fHead); |
| 60 | auto temp = fHead->cutChain(); |
| 61 | std::swap(temp, fHead); |
| 62 | if (!fHead) { |
| 63 | SkASSERT(fTail == temp.get()); |
| 64 | fTail = nullptr; |
| 65 | } |
| 66 | return temp; |
| 67 | } |
| 68 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 69 | inline std::unique_ptr<GrOp> GrOpsTask::OpChain::List::removeOp(GrOp* op) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 70 | #ifdef SK_DEBUG |
| 71 | auto head = op; |
| 72 | while (head->prevInChain()) { head = head->prevInChain(); } |
| 73 | SkASSERT(head == fHead.get()); |
| 74 | #endif |
| 75 | auto prev = op->prevInChain(); |
| 76 | if (!prev) { |
| 77 | SkASSERT(op == fHead.get()); |
| 78 | return this->popHead(); |
| 79 | } |
| 80 | auto temp = prev->cutChain(); |
| 81 | if (auto next = temp->cutChain()) { |
| 82 | prev->chainConcat(std::move(next)); |
| 83 | } else { |
| 84 | SkASSERT(fTail == op); |
| 85 | fTail = prev; |
| 86 | } |
| 87 | this->validate(); |
| 88 | return temp; |
| 89 | } |
| 90 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 91 | inline void GrOpsTask::OpChain::List::pushHead(std::unique_ptr<GrOp> op) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 92 | SkASSERT(op); |
| 93 | SkASSERT(op->isChainHead()); |
| 94 | SkASSERT(op->isChainTail()); |
| 95 | if (fHead) { |
| 96 | op->chainConcat(std::move(fHead)); |
| 97 | fHead = std::move(op); |
| 98 | } else { |
| 99 | fHead = std::move(op); |
| 100 | fTail = fHead.get(); |
| 101 | } |
| 102 | } |
| 103 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 104 | inline void GrOpsTask::OpChain::List::pushTail(std::unique_ptr<GrOp> op) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 105 | SkASSERT(op->isChainTail()); |
| 106 | fTail->chainConcat(std::move(op)); |
| 107 | fTail = fTail->nextInChain(); |
| 108 | } |
| 109 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 110 | inline void GrOpsTask::OpChain::List::validate() const { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 111 | #ifdef SK_DEBUG |
| 112 | if (fHead) { |
| 113 | SkASSERT(fTail); |
| 114 | fHead->validateChain(fTail); |
| 115 | } |
| 116 | #endif |
| 117 | } |
| 118 | |
| 119 | //////////////////////////////////////////////////////////////////////////////// |
| 120 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 121 | GrOpsTask::OpChain::OpChain(std::unique_ptr<GrOp> op, |
| 122 | GrProcessorSet::Analysis processorAnalysis, |
| 123 | GrAppliedClip* appliedClip, const DstProxy* dstProxy) |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 124 | : fList{std::move(op)} |
| 125 | , fProcessorAnalysis(processorAnalysis) |
| 126 | , fAppliedClip(appliedClip) { |
| 127 | if (fProcessorAnalysis.requiresDstTexture()) { |
| 128 | SkASSERT(dstProxy && dstProxy->proxy()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 129 | fDstProxy = *dstProxy; |
| 130 | } |
| 131 | fBounds = fList.head()->bounds(); |
| 132 | } |
| 133 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 134 | void GrOpsTask::OpChain::visitProxies(const GrOp::VisitProxyFunc& func) const { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 135 | if (fList.empty()) { |
| 136 | return; |
| 137 | } |
| 138 | for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 139 | op.visitProxies(func); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 140 | } |
| 141 | if (fDstProxy.proxy()) { |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 142 | func(fDstProxy.proxy(), GrMipMapped::kNo); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 143 | } |
| 144 | if (fAppliedClip) { |
| 145 | fAppliedClip->visitProxies(func); |
| 146 | } |
| 147 | } |
| 148 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 149 | void GrOpsTask::OpChain::deleteOps(GrOpMemoryPool* pool) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 150 | while (!fList.empty()) { |
| 151 | pool->release(fList.popHead()); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that |
| 156 | // the two chains are chainable. Returns the new chain. |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 157 | GrOpsTask::OpChain::List GrOpsTask::OpChain::DoConcat( |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 158 | List chainA, List chainB, const GrCaps& caps, GrOpMemoryPool* pool, |
| 159 | GrAuditTrail* auditTrail) { |
| 160 | // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting |
| 161 | // at chain a's tail and working toward the head. We produce one of the following outcomes: |
| 162 | // 1) b's head is merged into an op in a. |
| 163 | // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.) |
| 164 | // 3) b's head is popped from chain a and added at the tail of a. |
| 165 | // After result 3 we don't want to attempt to merge the next head of b with the new tail of a, |
| 166 | // as we assume merges were already attempted when chain b was created. So we keep track of the |
| 167 | // original tail of a and start our iteration of a there. We also track the bounds of the nodes |
| 168 | // appended to chain a that will be skipped for bounds testing. If the original tail of a is |
| 169 | // merged into an op in b (case 2) then we advance the "original tail" towards the head of a. |
| 170 | GrOp* origATail = chainA.tail(); |
| 171 | SkRect skipBounds = SkRectPriv::MakeLargestInverted(); |
| 172 | do { |
| 173 | int numMergeChecks = 0; |
| 174 | bool merged = false; |
| 175 | bool noSkip = (origATail == chainA.tail()); |
| 176 | SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted())); |
| 177 | bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds); |
| 178 | SkRect forwardMergeBounds = skipBounds; |
| 179 | GrOp* a = origATail; |
| 180 | while (a) { |
| 181 | bool canForwardMerge = |
| 182 | (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds); |
| 183 | if (canForwardMerge || canBackwardMerge) { |
| 184 | auto result = a->combineIfPossible(chainB.head(), caps); |
| 185 | SkASSERT(result != GrOp::CombineResult::kCannotCombine); |
| 186 | merged = (result == GrOp::CombineResult::kMerged); |
Robert Phillips | 9548c3b42 | 2019-01-08 12:35:43 -0500 | [diff] [blame] | 187 | 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] | 188 | chainB.head()->name(), chainB.head()->uniqueID(), a->name(), |
| 189 | a->uniqueID()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 190 | } |
| 191 | if (merged) { |
Brian Salomon | 52a6ed3 | 2018-11-26 10:30:58 -0500 | [diff] [blame] | 192 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 193 | if (canBackwardMerge) { |
| 194 | pool->release(chainB.popHead()); |
| 195 | } else { |
| 196 | // We merged the contents of b's head into a. We will replace b's head with a in |
| 197 | // chain b. |
| 198 | SkASSERT(canForwardMerge); |
| 199 | if (a == origATail) { |
| 200 | origATail = a->prevInChain(); |
| 201 | } |
| 202 | std::unique_ptr<GrOp> detachedA = chainA.removeOp(a); |
| 203 | pool->release(chainB.popHead()); |
| 204 | chainB.pushHead(std::move(detachedA)); |
| 205 | if (chainA.empty()) { |
| 206 | // We merged all the nodes in chain a to chain b. |
| 207 | return chainB; |
| 208 | } |
| 209 | } |
| 210 | break; |
| 211 | } else { |
| 212 | if (++numMergeChecks == kMaxOpMergeDistance) { |
| 213 | break; |
| 214 | } |
| 215 | forwardMergeBounds.joinNonEmptyArg(a->bounds()); |
| 216 | canBackwardMerge = |
| 217 | canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds()); |
| 218 | a = a->prevInChain(); |
| 219 | } |
| 220 | } |
| 221 | // If we weren't able to merge b's head then pop b's head from chain b and make it the new |
| 222 | // tail of a. |
| 223 | if (!merged) { |
| 224 | chainA.pushTail(chainB.popHead()); |
| 225 | skipBounds.joinNonEmptyArg(chainA.tail()->bounds()); |
| 226 | } |
| 227 | } while (!chainB.empty()); |
| 228 | return chainA; |
| 229 | } |
| 230 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 231 | // Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns |
| 232 | // 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] | 233 | bool GrOpsTask::OpChain::tryConcat( |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 234 | List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxy& dstProxy, |
| 235 | const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps, |
| 236 | GrOpMemoryPool* pool, GrAuditTrail* auditTrail) { |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 237 | SkASSERT(!fList.empty()); |
| 238 | SkASSERT(!list->empty()); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 239 | SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxy.proxy())); |
| 240 | SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxy.proxy())); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 241 | // 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] | 242 | if (fList.head()->classID() != list->head()->classID() || |
| 243 | SkToBool(fAppliedClip) != SkToBool(appliedClip) || |
| 244 | (fAppliedClip && *fAppliedClip != *appliedClip) || |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 245 | (fProcessorAnalysis.requiresNonOverlappingDraws() != |
| 246 | processorAnalysis.requiresNonOverlappingDraws()) || |
| 247 | (fProcessorAnalysis.requiresNonOverlappingDraws() && |
| 248 | // Non-overlaping draws are only required when Ganesh will either insert a barrier, |
| 249 | // or read back a new dst texture between draws. In either case, we can neither |
| 250 | // chain nor combine overlapping Ops. |
| 251 | GrRectsTouchOrOverlap(fBounds, bounds)) || |
| 252 | (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) || |
| 253 | (fProcessorAnalysis.requiresDstTexture() && fDstProxy != dstProxy)) { |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 254 | return false; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 255 | } |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 256 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 257 | SkDEBUGCODE(bool first = true;) |
| 258 | do { |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 259 | switch (fList.tail()->combineIfPossible(list->head(), caps)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 260 | case GrOp::CombineResult::kCannotCombine: |
| 261 | // If an op supports chaining then it is required that chaining is transitive and |
| 262 | // that if any two ops in two different chains can merge then the two chains |
| 263 | // may also be chained together. Thus, we should only hit this on the first |
| 264 | // iteration. |
| 265 | SkASSERT(first); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 266 | return false; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 267 | case GrOp::CombineResult::kMayChain: |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 268 | fList = DoConcat(std::move(fList), skstd::exchange(*list, List()), caps, pool, |
| 269 | auditTrail); |
| 270 | // The above exchange cleared out 'list'. The list needs to be empty now for the |
| 271 | // loop to terminate. |
| 272 | SkASSERT(list->empty()); |
| 273 | break; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 274 | case GrOp::CombineResult::kMerged: { |
Robert Phillips | 9548c3b42 | 2019-01-08 12:35:43 -0500 | [diff] [blame] | 275 | 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] | 276 | list->tail()->name(), list->tail()->uniqueID(), list->head()->name(), |
| 277 | list->head()->uniqueID()); |
| 278 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head()); |
| 279 | pool->release(list->popHead()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 280 | break; |
| 281 | } |
| 282 | } |
| 283 | SkDEBUGCODE(first = false); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 284 | } while (!list->empty()); |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 285 | |
| 286 | // The new ops were successfully merged and/or chained onto our own. |
| 287 | fBounds.joinPossiblyEmptyRect(bounds); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 288 | return true; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 289 | } |
| 290 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 291 | bool GrOpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, GrOpMemoryPool* pool, |
| 292 | GrAuditTrail* auditTrail) { |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 293 | if (!that->tryConcat( |
| 294 | &fList, fProcessorAnalysis, fDstProxy, fAppliedClip, fBounds, caps, pool, auditTrail)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 295 | this->validate(); |
| 296 | // append failed |
| 297 | return false; |
| 298 | } |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 299 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 300 | // 'that' owns the combined chain. Move it into 'this'. |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 301 | SkASSERT(fList.empty()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 302 | fList = std::move(that->fList); |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 303 | fBounds = that->fBounds; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 304 | |
| 305 | that->fDstProxy.setProxy(nullptr); |
| 306 | if (that->fAppliedClip) { |
| 307 | for (int i = 0; i < that->fAppliedClip->numClipCoverageFragmentProcessors(); ++i) { |
| 308 | that->fAppliedClip->detachClipCoverageFragmentProcessor(i); |
| 309 | } |
| 310 | } |
| 311 | this->validate(); |
| 312 | return true; |
| 313 | } |
| 314 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 315 | std::unique_ptr<GrOp> GrOpsTask::OpChain::appendOp( |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 316 | std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, |
| 317 | const DstProxy* dstProxy, const GrAppliedClip* appliedClip, const GrCaps& caps, |
| 318 | GrOpMemoryPool* pool, GrAuditTrail* auditTrail) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 319 | const GrXferProcessor::DstProxy noDstProxy; |
| 320 | if (!dstProxy) { |
| 321 | dstProxy = &noDstProxy; |
| 322 | } |
| 323 | SkASSERT(op->isChainHead() && op->isChainTail()); |
| 324 | SkRect opBounds = op->bounds(); |
| 325 | List chain(std::move(op)); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 326 | if (!this->tryConcat( |
| 327 | &chain, processorAnalysis, *dstProxy, appliedClip, opBounds, caps, pool, auditTrail)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 328 | // append failed, give the op back to the caller. |
| 329 | this->validate(); |
| 330 | return chain.popHead(); |
| 331 | } |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 332 | |
| 333 | SkASSERT(chain.empty()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 334 | this->validate(); |
| 335 | return nullptr; |
| 336 | } |
| 337 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 338 | inline void GrOpsTask::OpChain::validate() const { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 339 | #ifdef SK_DEBUG |
| 340 | fList.validate(); |
| 341 | for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
| 342 | // Not using SkRect::contains because we allow empty rects. |
| 343 | SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop && |
| 344 | fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom); |
| 345 | } |
| 346 | #endif |
| 347 | } |
| 348 | |
| 349 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 350 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 351 | GrOpsTask::GrOpsTask(sk_sp<GrOpMemoryPool> opMemoryPool, |
| 352 | sk_sp<GrRenderTargetProxy> rtProxy, |
| 353 | GrAuditTrail* auditTrail) |
| 354 | : GrRenderTask(std::move(rtProxy)) |
| 355 | , fOpMemoryPool(std::move(opMemoryPool)) |
| 356 | , fAuditTrail(auditTrail) |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 357 | , fLastClipStackGenID(SK_InvalidUniqueID) |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 358 | SkDEBUGCODE(, fNumClips(0)) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 359 | SkASSERT(fOpMemoryPool); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 360 | fTarget->setLastRenderTask(this); |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 363 | void GrOpsTask::deleteOps() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 364 | for (auto& chain : fOpChains) { |
| 365 | chain.deleteOps(fOpMemoryPool.get()); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 366 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 367 | fOpChains.reset(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 368 | } |
| 369 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 370 | GrOpsTask::~GrOpsTask() { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 371 | this->deleteOps(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | //////////////////////////////////////////////////////////////////////////////// |
| 375 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 376 | void GrOpsTask::endFlush() { |
| 377 | fLastClipStackGenID = SK_InvalidUniqueID; |
| 378 | this->deleteOps(); |
| 379 | fClipAllocator.reset(); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 380 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 381 | if (fTarget && this == fTarget->getLastRenderTask()) { |
| 382 | fTarget->setLastRenderTask(nullptr); |
Greg Daniel | f21bf9e | 2019-08-22 20:12:20 +0000 | [diff] [blame] | 383 | } |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 384 | |
| 385 | fTarget.reset(); |
| 386 | fDeferredProxies.reset(); |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame^] | 387 | fSampledProxies.reset(); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 388 | fAuditTrail = nullptr; |
Greg Daniel | f21bf9e | 2019-08-22 20:12:20 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 391 | void GrOpsTask::onPrepare(GrOpFlushState* flushState) { |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 392 | SkASSERT(fTarget->peekRenderTarget()); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 393 | SkASSERT(this->isClosed()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 394 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 395 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 396 | #endif |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 397 | |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame^] | 398 | flushState->setSampledProxyArray(&fSampledProxies); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 399 | // Loop over the ops that haven't yet been prepared. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 400 | for (const auto& chain : fOpChains) { |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 401 | if (chain.shouldExecute()) { |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 402 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 403 | TRACE_EVENT0("skia.gpu", chain.head()->name()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 404 | #endif |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 405 | GrOpFlushState::OpArgs opArgs = { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 406 | chain.head(), |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 407 | fTarget->asRenderTargetProxy(), |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 408 | chain.appliedClip(), |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 409 | fTarget.get()->asRenderTargetProxy()->outputSwizzle(), |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 410 | chain.dstProxy() |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 411 | }; |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 412 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 413 | chain.head()->prepare(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 414 | flushState->setOpArgs(nullptr); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 415 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 416 | } |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame^] | 417 | flushState->setSampledProxyArray(nullptr); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 418 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 419 | |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame^] | 420 | static GrOpsRenderPass* create_command_buffer( |
| 421 | GrGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin, const SkRect& bounds, |
| 422 | GrLoadOp colorLoadOp, const SkPMColor4f& loadClearColor, GrLoadOp stencilLoadOp, |
| 423 | const SkTArray<GrTextureProxy*, true>& sampledProxies) { |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 424 | const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 425 | colorLoadOp, |
| 426 | GrStoreOp::kStore, |
| 427 | loadClearColor |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 428 | }; |
| 429 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 430 | // TODO: |
| 431 | // 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] | 432 | // to stop splitting up higher level OpsTasks for copyOps to achieve that. |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 433 | // Note: we would still need SB loads and stores but they would happen at a |
| 434 | // lower level (inside the VK command buffer). |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 435 | const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 436 | stencilLoadOp, |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 437 | GrStoreOp::kStore, |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 438 | }; |
| 439 | |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame^] | 440 | return gpu->getOpsRenderPass(rt, origin, bounds, kColorLoadStoreInfo, stencilLoadAndStoreInfo, |
| 441 | sampledProxies); |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 442 | } |
| 443 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 444 | // 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] | 445 | // 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] | 446 | // Ops and instantiate them here. |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 447 | bool GrOpsTask::onExecute(GrOpFlushState* flushState) { |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 448 | if (this->isNoOp()) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 449 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 450 | } |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 451 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 452 | SkASSERT(fTarget->peekRenderTarget()); |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 453 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 454 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 455 | // TODO: at the very least, we want the stencil store op to always be discard (at this |
| 456 | // level). In Vulkan, sub-command buffers would still need to load & store the stencil buffer. |
| 457 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 458 | // Make sure load ops are not kClear if the GPU needs to use draws for clears |
| 459 | SkASSERT(fColorLoadOp != GrLoadOp::kClear || |
| 460 | !flushState->gpu()->caps()->performColorClearsAsDraws()); |
| 461 | SkASSERT(fStencilLoadOp != GrLoadOp::kClear || |
| 462 | !flushState->gpu()->caps()->performStencilClearsAsDraws()); |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 463 | GrOpsRenderPass* renderPass = create_command_buffer( |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 464 | flushState->gpu(), |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 465 | fTarget->peekRenderTarget(), |
| 466 | fTarget->origin(), |
| 467 | fTarget->getBoundsRect(), |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 468 | fColorLoadOp, |
| 469 | fLoadClearColor, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame^] | 470 | fStencilLoadOp, |
| 471 | fSampledProxies); |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 472 | flushState->setOpsRenderPass(renderPass); |
| 473 | renderPass->begin(); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 474 | |
| 475 | // Draw all the generated geometry. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 476 | for (const auto& chain : fOpChains) { |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 477 | if (!chain.shouldExecute()) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 478 | continue; |
| 479 | } |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 480 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 481 | TRACE_EVENT0("skia.gpu", chain.head()->name()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 482 | #endif |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 483 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 484 | GrOpFlushState::OpArgs opArgs { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 485 | chain.head(), |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 486 | fTarget->asRenderTargetProxy(), |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 487 | chain.appliedClip(), |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 488 | fTarget.get()->asRenderTargetProxy()->outputSwizzle(), |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 489 | chain.dstProxy() |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 490 | }; |
| 491 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 492 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 493 | chain.head()->execute(flushState, chain.bounds()); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 494 | flushState->setOpArgs(nullptr); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 495 | } |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 496 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 497 | renderPass->end(); |
| 498 | flushState->gpu()->submit(renderPass); |
| 499 | flushState->setOpsRenderPass(nullptr); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 500 | |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 501 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 504 | void GrOpsTask::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 505 | fColorLoadOp = op; |
| 506 | fLoadClearColor = color; |
| 507 | } |
| 508 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 509 | bool GrOpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 510 | // Mark the color load op as discard (this may be followed by a clearColorOnLoad call to make |
| 511 | // the load op kClear, or it may be followed by an explicit op). In the event of an absClear() |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 512 | // after a regular clear(), we could end up with a clear load op and a real clear op in the task |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 513 | // if the load op were not reset here. |
| 514 | fColorLoadOp = GrLoadOp::kDiscard; |
| 515 | |
Chris Dalton | 6b98280 | 2019-06-27 13:53:46 -0600 | [diff] [blame] | 516 | // If we previously recorded a wait op, we cannot delete the wait op. Until we track the wait |
| 517 | // ops separately from normal ops, we have to avoid clearing out any ops in this case as well. |
| 518 | if (fHasWaitOp) { |
| 519 | canDiscardPreviousOps = CanDiscardPreviousOps::kNo; |
| 520 | } |
| 521 | |
| 522 | if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 523 | this->deleteOps(); |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 524 | fDeferredProxies.reset(); |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame^] | 525 | fSampledProxies.reset(); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 526 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 527 | // If the opsTask is using a render target which wraps a vulkan command buffer, we can't do |
| 528 | // a clear load since we cannot change the render pass that we are using. Thus we fall back |
| 529 | // to making a clear op in this case. |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 530 | return !fTarget->asRenderTargetProxy()->wrapsVkSecondaryCB(); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 531 | } |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 532 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 533 | // 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] | 534 | return false; |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 537 | void GrOpsTask::discard() { |
| 538 | // Discard calls to in-progress opsTasks are ignored. Calls at the start update the |
| 539 | // opsTasks' color & stencil load ops. |
| 540 | if (this->isEmpty()) { |
| 541 | fColorLoadOp = GrLoadOp::kDiscard; |
| 542 | fStencilLoadOp = GrLoadOp::kDiscard; |
| 543 | } |
| 544 | } |
| 545 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 546 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 547 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 548 | #ifdef SK_DEBUG |
| 549 | static const char* load_op_to_name(GrLoadOp op) { |
| 550 | return GrLoadOp::kLoad == op ? "load" : GrLoadOp::kClear == op ? "clear" : "discard"; |
| 551 | } |
| 552 | |
| 553 | void GrOpsTask::dump(bool printDependencies) const { |
| 554 | GrRenderTask::dump(printDependencies); |
| 555 | |
| 556 | SkDebugf("ColorLoadOp: %s %x StencilLoadOp: %s\n", |
| 557 | load_op_to_name(fColorLoadOp), |
| 558 | GrLoadOp::kClear == fColorLoadOp ? fLoadClearColor.toBytes_RGBA() : 0x0, |
| 559 | load_op_to_name(fStencilLoadOp)); |
| 560 | |
| 561 | SkDebugf("ops (%d):\n", fOpChains.count()); |
| 562 | for (int i = 0; i < fOpChains.count(); ++i) { |
| 563 | SkDebugf("*******************************\n"); |
| 564 | if (!fOpChains[i].head()) { |
| 565 | SkDebugf("%d: <combined forward or failed instantiation>\n", i); |
| 566 | } else { |
| 567 | SkDebugf("%d: %s\n", i, fOpChains[i].head()->name()); |
| 568 | SkRect bounds = fOpChains[i].bounds(); |
| 569 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 570 | bounds.fTop, bounds.fRight, bounds.fBottom); |
| 571 | for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) { |
| 572 | SkString info = SkTabString(op.dumpInfo(), 1); |
| 573 | SkDebugf("%s\n", info.c_str()); |
| 574 | bounds = op.bounds(); |
| 575 | SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 576 | bounds.fTop, bounds.fRight, bounds.fBottom); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
Greg Daniel | dcf9ca1 | 2019-08-27 14:30:21 -0400 | [diff] [blame] | 582 | void GrOpsTask::visitProxies_debugOnly(const VisitSurfaceProxyFunc& func) const { |
| 583 | auto textureFunc = [ func ] (GrTextureProxy* tex, GrMipMapped mipmapped) { |
| 584 | func(tex, mipmapped); |
| 585 | }; |
| 586 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 587 | for (const OpChain& chain : fOpChains) { |
Greg Daniel | dcf9ca1 | 2019-08-27 14:30:21 -0400 | [diff] [blame] | 588 | chain.visitProxies(textureFunc); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
| 592 | #endif |
| 593 | |
| 594 | //////////////////////////////////////////////////////////////////////////////// |
| 595 | |
| 596 | bool GrOpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const { |
| 597 | bool used = false; |
| 598 | |
| 599 | auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p, GrMipMapped) { |
| 600 | if (p == proxyToCheck) { |
| 601 | used = true; |
| 602 | } |
| 603 | }; |
| 604 | for (const OpChain& recordedOp : fOpChains) { |
| 605 | recordedOp.visitProxies(visit); |
| 606 | } |
| 607 | |
| 608 | return used; |
| 609 | } |
| 610 | |
| 611 | void GrOpsTask::handleInternalAllocationFailure() { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 612 | bool hasUninstantiatedProxy = false; |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 613 | auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p, GrMipMapped) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 614 | if (!p->isInstantiated()) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 615 | hasUninstantiatedProxy = true; |
| 616 | } |
| 617 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 618 | for (OpChain& recordedOp : fOpChains) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 619 | hasUninstantiatedProxy = false; |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 620 | recordedOp.visitProxies(checkInstantiation); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 621 | if (hasUninstantiatedProxy) { |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 622 | recordedOp.setSkipExecuteFlag(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | } |
| 626 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 627 | void GrOpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 628 | for (int i = 0; i < fDeferredProxies.count(); ++i) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 629 | SkASSERT(!fDeferredProxies[i]->isInstantiated()); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 630 | // We give all the deferred proxies a write usage at the very start of flushing. This |
| 631 | // locks them out of being reused for the entire flush until they are read - and then |
| 632 | // they can be recycled. This is a bit unfortunate because a flush can proceed in waves |
| 633 | // with sub-flushes. The deferred proxies only need to be pinned from the start of |
| 634 | // the sub-flush in which they appear. |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 635 | alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 636 | } |
| 637 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 638 | // Add the interval for all the writes to this GrOpsTasks's target |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 639 | if (fOpChains.count()) { |
Robert Phillips | 3bf3d4a | 2019-03-27 07:09:09 -0400 | [diff] [blame] | 640 | unsigned int cur = alloc->curOp(); |
| 641 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 642 | alloc->addInterval(fTarget.get(), cur, cur + fOpChains.count() - 1, |
| 643 | GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 644 | } else { |
| 645 | // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we |
| 646 | // still need to add an interval for the destination so we create a fake op# for |
| 647 | // the missing clear op. |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 648 | alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(), |
| 649 | GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 650 | alloc->incOps(); |
| 651 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 652 | |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 653 | auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipMapped) { |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 654 | alloc->addInterval(p, alloc->curOp(), alloc->curOp(), GrResourceAllocator::ActualUse::kYes |
| 655 | SkDEBUGCODE(, fTarget.get() == p)); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 656 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 657 | for (const OpChain& recordedOp : fOpChains) { |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 658 | recordedOp.visitProxies(gather); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 659 | |
Robert Phillips | 3bf3d4a | 2019-03-27 07:09:09 -0400 | [diff] [blame] | 660 | // 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] | 661 | // keep all the math consistent. |
| 662 | alloc->incOps(); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 666 | void GrOpsTask::recordOp( |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 667 | std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip, |
| 668 | const DstProxy* dstProxy, const GrCaps& caps) { |
Ethan Nicholas | 029b22c | 2018-10-18 16:49:56 -0400 | [diff] [blame] | 669 | SkDEBUGCODE(op->validate();) |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 670 | SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxy && dstProxy->proxy())); |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 671 | SkASSERT(fTarget); |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 672 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 673 | // A closed GrOpsTask should never receive new/more ops |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 674 | SkASSERT(!this->isClosed()); |
Brian Salomon | 19ec80f | 2018-11-16 13:27:30 -0500 | [diff] [blame] | 675 | if (!op->bounds().isFinite()) { |
| 676 | fOpMemoryPool->release(std::move(op)); |
| 677 | return; |
| 678 | } |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 679 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 680 | // Check if there is an op we can combine with by linearly searching back until we either |
| 681 | // 1) check every op |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 682 | // 2) intersect with something |
| 683 | // 3) find a 'blocker' |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 684 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget->uniqueID()); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 685 | GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n" |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 686 | "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n", |
| 687 | this->uniqueID(), |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 688 | op->name(), |
| 689 | op->uniqueID(), |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 690 | op->bounds().fLeft, op->bounds().fTop, |
| 691 | op->bounds().fRight, op->bounds().fBottom); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 692 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 693 | GrOP_INFO("\tOutcome:\n"); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 694 | int maxCandidates = SkTMin(kMaxOpChainDistance, fOpChains.count()); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 695 | if (maxCandidates) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 696 | int i = 0; |
| 697 | while (true) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 698 | OpChain& candidate = fOpChains.fromBack(i); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 699 | op = candidate.appendOp(std::move(op), processorAnalysis, dstProxy, clip, caps, |
| 700 | fOpMemoryPool.get(), fAuditTrail); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 701 | if (!op) { |
| 702 | return; |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 703 | } |
Brian Salomon | a7682c8 | 2018-10-24 10:04:37 -0400 | [diff] [blame] | 704 | // Stop going backwards if we would cause a painter's order violation. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 705 | if (!can_reorder(candidate.bounds(), op->bounds())) { |
| 706 | GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n", |
| 707 | candidate.head()->name(), candidate.head()->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 708 | break; |
| 709 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 710 | if (++i == maxCandidates) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 711 | 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] | 712 | break; |
| 713 | } |
| 714 | } |
| 715 | } else { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 716 | GrOP_INFO("\t\tBackward: FirstOp\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 717 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 718 | if (clip) { |
| 719 | clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip)); |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 720 | SkDEBUGCODE(fNumClips++;) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 721 | } |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 722 | fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxy); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 725 | void GrOpsTask::forwardCombine(const GrCaps& caps) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 726 | SkASSERT(!this->isClosed()); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 727 | GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count()); |
Robert Phillips | 48567ac | 2017-06-01 08:46:00 -0400 | [diff] [blame] | 728 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 729 | for (int i = 0; i < fOpChains.count() - 1; ++i) { |
| 730 | OpChain& chain = fOpChains[i]; |
| 731 | int maxCandidateIdx = SkTMin(i + kMaxOpChainDistance, fOpChains.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 732 | int j = i + 1; |
| 733 | while (true) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 734 | OpChain& candidate = fOpChains[j]; |
| 735 | if (candidate.prependChain(&chain, caps, fOpMemoryPool.get(), fAuditTrail)) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 736 | break; |
| 737 | } |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 738 | // Stop traversing if we would cause a painter's order violation. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 739 | if (!can_reorder(chain.bounds(), candidate.bounds())) { |
| 740 | GrOP_INFO( |
| 741 | "\t\t%d: chain (%s head opID: %u) -> " |
| 742 | "Intersects with chain (%s, head opID: %u)\n", |
| 743 | i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(), |
| 744 | candidate.head()->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 745 | break; |
| 746 | } |
Brian Salomon | a7682c8 | 2018-10-24 10:04:37 -0400 | [diff] [blame] | 747 | if (++j > maxCandidateIdx) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 748 | GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n", |
| 749 | i, chain.head()->name(), chain.head()->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 750 | break; |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | |