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