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