reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 8 | #include "include/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/private/GrAuditTrail.h" |
| 10 | #include "include/private/GrRecordingContext.h" |
| 11 | #include "src/core/SkExchange.h" |
| 12 | #include "src/core/SkRectPriv.h" |
| 13 | #include "src/core/SkTraceEvent.h" |
| 14 | #include "src/gpu/GrCaps.h" |
| 15 | #include "src/gpu/GrGpu.h" |
| 16 | #include "src/gpu/GrGpuCommandBuffer.h" |
| 17 | #include "src/gpu/GrMemoryPool.h" |
| 18 | #include "src/gpu/GrRecordingContextPriv.h" |
| 19 | #include "src/gpu/GrRect.h" |
| 20 | #include "src/gpu/GrRenderTargetContext.h" |
| 21 | #include "src/gpu/GrRenderTargetOpList.h" |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 22 | #include "src/gpu/GrRenderTargetPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrResourceAllocator.h" |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 24 | #include "src/gpu/GrStencilAttachment.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/ops/GrClearOp.h" |
| 26 | #include "src/gpu/ops/GrCopySurfaceOp.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 27 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | //////////////////////////////////////////////////////////////////////////////// |
| 29 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 30 | // 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] | 31 | static const int kMaxOpMergeDistance = 10; |
| 32 | static const int kMaxOpChainDistance = 10; |
| 33 | |
| 34 | //////////////////////////////////////////////////////////////////////////////// |
| 35 | |
| 36 | using DstProxy = GrXferProcessor::DstProxy; |
| 37 | |
| 38 | //////////////////////////////////////////////////////////////////////////////// |
| 39 | |
| 40 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); } |
| 41 | |
| 42 | //////////////////////////////////////////////////////////////////////////////// |
| 43 | |
| 44 | inline GrRenderTargetOpList::OpChain::List::List(std::unique_ptr<GrOp> op) |
| 45 | : fHead(std::move(op)), fTail(fHead.get()) { |
| 46 | this->validate(); |
| 47 | } |
| 48 | |
| 49 | inline GrRenderTargetOpList::OpChain::List::List(List&& that) { *this = std::move(that); } |
| 50 | |
| 51 | inline GrRenderTargetOpList::OpChain::List& GrRenderTargetOpList::OpChain::List::operator=( |
| 52 | List&& that) { |
| 53 | fHead = std::move(that.fHead); |
| 54 | fTail = that.fTail; |
| 55 | that.fTail = nullptr; |
| 56 | this->validate(); |
| 57 | return *this; |
| 58 | } |
| 59 | |
| 60 | inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::popHead() { |
| 61 | SkASSERT(fHead); |
| 62 | auto temp = fHead->cutChain(); |
| 63 | std::swap(temp, fHead); |
| 64 | if (!fHead) { |
| 65 | SkASSERT(fTail == temp.get()); |
| 66 | fTail = nullptr; |
| 67 | } |
| 68 | return temp; |
| 69 | } |
| 70 | |
| 71 | inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::removeOp(GrOp* op) { |
| 72 | #ifdef SK_DEBUG |
| 73 | auto head = op; |
| 74 | while (head->prevInChain()) { head = head->prevInChain(); } |
| 75 | SkASSERT(head == fHead.get()); |
| 76 | #endif |
| 77 | auto prev = op->prevInChain(); |
| 78 | if (!prev) { |
| 79 | SkASSERT(op == fHead.get()); |
| 80 | return this->popHead(); |
| 81 | } |
| 82 | auto temp = prev->cutChain(); |
| 83 | if (auto next = temp->cutChain()) { |
| 84 | prev->chainConcat(std::move(next)); |
| 85 | } else { |
| 86 | SkASSERT(fTail == op); |
| 87 | fTail = prev; |
| 88 | } |
| 89 | this->validate(); |
| 90 | return temp; |
| 91 | } |
| 92 | |
| 93 | inline void GrRenderTargetOpList::OpChain::List::pushHead(std::unique_ptr<GrOp> op) { |
| 94 | SkASSERT(op); |
| 95 | SkASSERT(op->isChainHead()); |
| 96 | SkASSERT(op->isChainTail()); |
| 97 | if (fHead) { |
| 98 | op->chainConcat(std::move(fHead)); |
| 99 | fHead = std::move(op); |
| 100 | } else { |
| 101 | fHead = std::move(op); |
| 102 | fTail = fHead.get(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | inline void GrRenderTargetOpList::OpChain::List::pushTail(std::unique_ptr<GrOp> op) { |
| 107 | SkASSERT(op->isChainTail()); |
| 108 | fTail->chainConcat(std::move(op)); |
| 109 | fTail = fTail->nextInChain(); |
| 110 | } |
| 111 | |
| 112 | inline void GrRenderTargetOpList::OpChain::List::validate() const { |
| 113 | #ifdef SK_DEBUG |
| 114 | if (fHead) { |
| 115 | SkASSERT(fTail); |
| 116 | fHead->validateChain(fTail); |
| 117 | } |
| 118 | #endif |
| 119 | } |
| 120 | |
| 121 | //////////////////////////////////////////////////////////////////////////////// |
| 122 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 123 | GrRenderTargetOpList::OpChain::OpChain(std::unique_ptr<GrOp> op, |
| 124 | GrProcessorSet::Analysis processorAnalysis, |
| 125 | GrAppliedClip* appliedClip, const DstProxy* dstProxy) |
| 126 | : fList{std::move(op)} |
| 127 | , fProcessorAnalysis(processorAnalysis) |
| 128 | , fAppliedClip(appliedClip) { |
| 129 | if (fProcessorAnalysis.requiresDstTexture()) { |
| 130 | SkASSERT(dstProxy && dstProxy->proxy()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 131 | fDstProxy = *dstProxy; |
| 132 | } |
| 133 | fBounds = fList.head()->bounds(); |
| 134 | } |
| 135 | |
| 136 | void GrRenderTargetOpList::OpChain::visitProxies(const GrOp::VisitProxyFunc& func, |
| 137 | GrOp::VisitorType visitor) const { |
| 138 | if (fList.empty()) { |
| 139 | return; |
| 140 | } |
| 141 | for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
| 142 | op.visitProxies(func, visitor); |
| 143 | } |
| 144 | if (fDstProxy.proxy()) { |
| 145 | func(fDstProxy.proxy()); |
| 146 | } |
| 147 | if (fAppliedClip) { |
| 148 | fAppliedClip->visitProxies(func); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void GrRenderTargetOpList::OpChain::deleteOps(GrOpMemoryPool* pool) { |
| 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. |
| 160 | GrRenderTargetOpList::OpChain::List GrRenderTargetOpList::OpChain::DoConcat( |
| 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. |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 236 | bool GrRenderTargetOpList::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 | |
| 294 | bool GrRenderTargetOpList::OpChain::prependChain(OpChain* that, const GrCaps& caps, |
| 295 | GrOpMemoryPool* pool, 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 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 318 | std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::appendOp( |
| 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 | |
| 341 | inline void GrRenderTargetOpList::OpChain::validate() const { |
| 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 | |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 354 | GrRenderTargetOpList::GrRenderTargetOpList(sk_sp<GrOpMemoryPool> opMemoryPool, |
Robert Phillips | 831a293 | 2019-04-12 17:18:39 -0400 | [diff] [blame] | 355 | sk_sp<GrRenderTargetProxy> proxy, |
Robert Phillips | 8185f59 | 2017-04-26 08:31:08 -0400 | [diff] [blame] | 356 | GrAuditTrail* auditTrail) |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 357 | : INHERITED(std::move(opMemoryPool), std::move(proxy), auditTrail) |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 358 | , fLastClipStackGenID(SK_InvalidUniqueID) |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 359 | SkDEBUGCODE(, fNumClips(0)) { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 362 | void GrRenderTargetOpList::deleteOps() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 363 | for (auto& chain : fOpChains) { |
| 364 | chain.deleteOps(fOpMemoryPool.get()); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 365 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 366 | fOpChains.reset(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 367 | } |
| 368 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 369 | GrRenderTargetOpList::~GrRenderTargetOpList() { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 370 | this->deleteOps(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | //////////////////////////////////////////////////////////////////////////////// |
| 374 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 375 | #ifdef SK_DEBUG |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 376 | void GrRenderTargetOpList::dump(bool printDependencies) const { |
| 377 | INHERITED::dump(printDependencies); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 378 | |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 379 | SkDebugf("fStencilLoadOp: %s\n", GrLoadOpName(fStencilLoadOp)); |
| 380 | SkDebugf("fStencilStoreOp: %s\n", GrStoreOpName(fStencilStoreOp)); |
| 381 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 382 | SkDebugf("ops (%d):\n", fOpChains.count()); |
| 383 | for (int i = 0; i < fOpChains.count(); ++i) { |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 384 | SkDebugf("*******************************\n"); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 385 | if (!fOpChains[i].head()) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 386 | SkDebugf("%d: <combined forward or failed instantiation>\n", i); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 387 | } else { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 388 | SkDebugf("%d: %s\n", i, fOpChains[i].head()->name()); |
| 389 | SkRect bounds = fOpChains[i].bounds(); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 390 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 391 | bounds.fTop, bounds.fRight, bounds.fBottom); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 392 | for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) { |
| 393 | SkString info = SkTabString(op.dumpInfo(), 1); |
| 394 | SkDebugf("%s\n", info.c_str()); |
| 395 | bounds = op.bounds(); |
| 396 | SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 397 | bounds.fTop, bounds.fRight, bounds.fBottom); |
| 398 | } |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 399 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 402 | |
| 403 | void GrRenderTargetOpList::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 404 | for (const OpChain& chain : fOpChains) { |
| 405 | chain.visitProxies(func, GrOp::VisitorType::kOther); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 406 | } |
| 407 | } |
Brian Salomon | c525d4f | 2018-09-17 15:48:20 -0400 | [diff] [blame] | 408 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 409 | #endif |
| 410 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 411 | void GrRenderTargetOpList::onPrepare(GrOpFlushState* flushState) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 412 | SkASSERT(fTarget.get()->peekRenderTarget()); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 413 | SkASSERT(this->isClosed()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 414 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 415 | TRACE_EVENT0("skia", TRACE_FUNC); |
| 416 | #endif |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 417 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 418 | // Loop over the ops that haven't yet been prepared. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 419 | for (const auto& chain : fOpChains) { |
| 420 | if (chain.head()) { |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 421 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 422 | TRACE_EVENT0("skia", chain.head()->name()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 423 | #endif |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 424 | GrOpFlushState::OpArgs opArgs = { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 425 | chain.head(), |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 426 | fTarget.get()->asRenderTargetProxy(), |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 427 | chain.appliedClip(), |
| 428 | chain.dstProxy() |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 429 | }; |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 430 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 431 | chain.head()->prepare(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 432 | flushState->setOpArgs(nullptr); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 433 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 434 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 435 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 436 | |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 437 | static GrGpuRTCommandBuffer* create_command_buffer( |
| 438 | GrGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin, const SkRect& bounds, |
| 439 | GrLoadOp colorLoadOp, const SkPMColor4f& loadClearColor, GrLoadOp stencilLoadOp, GrStoreOp |
| 440 | stencilStoreOp) { |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 441 | const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 442 | colorLoadOp, |
| 443 | GrStoreOp::kStore, |
| 444 | loadClearColor |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 445 | }; |
| 446 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 447 | // TODO: |
| 448 | // We would like to (at this level) only ever clear & discard. We would need |
| 449 | // to stop splitting up higher level opLists for copyOps to achieve that. |
| 450 | // Note: we would still need SB loads and stores but they would happen at a |
| 451 | // lower level (inside the VK command buffer). |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 452 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo stencilLoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 453 | stencilLoadOp, |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 454 | stencilStoreOp, |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 455 | }; |
| 456 | |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 457 | return gpu->getCommandBuffer(rt, origin, bounds, kColorLoadStoreInfo, stencilLoadAndStoreInfo); |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 458 | } |
| 459 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 460 | // 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] | 461 | // 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] | 462 | // Ops and instantiate them here. |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 463 | bool GrRenderTargetOpList::onExecute(GrOpFlushState* flushState) { |
Greg Daniel | dbdba60 | 2018-04-20 11:52:43 -0400 | [diff] [blame] | 464 | // TODO: Forcing the execution of the discard here isn't ideal since it will cause us to do a |
| 465 | // discard and then store the data back in memory so that the load op on future draws doesn't |
| 466 | // think the memory is unitialized. Ideally we would want a system where we are tracking whether |
| 467 | // the proxy itself has valid data or not, and then use that as a signal on whether we should be |
| 468 | // loading or discarding. In that world we wouldni;t need to worry about executing oplists with |
| 469 | // no ops just to do a discard. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 470 | if (fOpChains.empty() && GrLoadOp::kClear != fColorLoadOp && |
Greg Daniel | dbdba60 | 2018-04-20 11:52:43 -0400 | [diff] [blame] | 471 | GrLoadOp::kDiscard != fColorLoadOp) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 472 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 473 | } |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 474 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 475 | SkASSERT(fTarget.get()->peekRenderTarget()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 476 | TRACE_EVENT0("skia", TRACE_FUNC); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 477 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 478 | // Make sure load ops are not kClear if the GPU needs to use draws for clears |
| 479 | SkASSERT(fColorLoadOp != GrLoadOp::kClear || |
| 480 | !flushState->gpu()->caps()->performColorClearsAsDraws()); |
| 481 | SkASSERT(fStencilLoadOp != GrLoadOp::kClear || |
| 482 | !flushState->gpu()->caps()->performStencilClearsAsDraws()); |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 483 | |
| 484 | GrRenderTarget* renderTarget = fTarget.get()->peekRenderTarget(); |
| 485 | GrStencilAttachment* stencil = renderTarget->renderTargetPriv().getStencilAttachment(); |
| 486 | GrLoadOp stencilLoadOp = fStencilLoadOp; |
| 487 | if (stencil && GrLoadOp::kClear == stencilLoadOp && !stencil->userBitsAreDirty()) { |
| 488 | if (!flushState->caps().preferFullscreenClears()) { |
| 489 | stencilLoadOp = GrLoadOp::kLoad; |
| 490 | } |
| 491 | } |
| 492 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 493 | GrGpuRTCommandBuffer* commandBuffer = create_command_buffer( |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 494 | flushState->gpu(), renderTarget, fTarget.get()->origin(), |
| 495 | fTarget.get()->getBoundsRect(), fColorLoadOp, fLoadClearColor, stencilLoadOp, |
| 496 | fStencilStoreOp); |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 497 | flushState->setCommandBuffer(commandBuffer); |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 498 | commandBuffer->begin(); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 499 | |
| 500 | // Draw all the generated geometry. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 501 | for (const auto& chain : fOpChains) { |
| 502 | if (!chain.head()) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 503 | continue; |
| 504 | } |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 505 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 506 | TRACE_EVENT0("skia", chain.head()->name()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 507 | #endif |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 508 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 509 | GrOpFlushState::OpArgs opArgs { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 510 | chain.head(), |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 511 | fTarget.get()->asRenderTargetProxy(), |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 512 | chain.appliedClip(), |
| 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 | |
Chris Dalton | 7b2c855 | 2019-05-13 15:49:33 -0600 | [diff] [blame] | 525 | if (stencil && GrStoreOp::kStore == fStencilStoreOp) { |
| 526 | // The user stencil bits are always initialized and kept at zero for the duration of a |
| 527 | // command buffer. So if we store the stencil, we know we're storing clean user bits. |
| 528 | stencil->userBitsCleared(); |
| 529 | } |
| 530 | // FIXME: We don't currently have a way to flag command buffers that don't use stencil at all. |
| 531 | // In that case, their store op will be discard, and we currently make the assumption that a |
| 532 | // store op of "discard" will not invalidate what's already in main memory. This is probably ok |
| 533 | // for now, but certainly something we want to address soon. |
| 534 | |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 535 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 538 | void GrRenderTargetOpList::endFlush() { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 539 | fLastClipStackGenID = SK_InvalidUniqueID; |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 540 | this->deleteOps(); |
Chris Dalton | c82dd4e | 2017-11-20 18:20:28 -0700 | [diff] [blame] | 541 | fClipAllocator.reset(); |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 542 | INHERITED::endFlush(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 545 | void GrRenderTargetOpList::discard() { |
| 546 | // Discard calls to in-progress opLists are ignored. Calls at the start update the |
| 547 | // opLists' color & stencil load ops. |
| 548 | if (this->isEmpty()) { |
| 549 | fColorLoadOp = GrLoadOp::kDiscard; |
| 550 | fStencilLoadOp = GrLoadOp::kDiscard; |
| 551 | } |
| 552 | } |
| 553 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 554 | void GrRenderTargetOpList::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) { |
| 555 | fColorLoadOp = op; |
| 556 | fLoadClearColor = color; |
| 557 | } |
| 558 | |
| 559 | bool GrRenderTargetOpList::resetForFullscreenClear() { |
| 560 | // Mark the color load op as discard (this may be followed by a clearColorOnLoad call to make |
| 561 | // the load op kClear, or it may be followed by an explicit op). In the event of an absClear() |
| 562 | // after a regular clear(), we could end up with a clear load op and a real clear op in the list |
| 563 | // if the load op were not reset here. |
| 564 | fColorLoadOp = GrLoadOp::kDiscard; |
| 565 | |
| 566 | // Regardless of how the clear is implemented (native clear or a fullscreen quad), all prior ops |
| 567 | // would be overwritten, so discard them entirely. The one exception is if the opList is marked |
| 568 | // as needing a stencil buffer then there may be a prior op that writes to the stencil buffer. |
| 569 | // Although the clear will ignore the stencil buffer, following draw ops may not so we can't get |
| 570 | // rid of all the preceding ops. Beware! If we ever add any ops that have a side effect beyond |
| 571 | // modifying the stencil buffer we will need a more elaborate tracking system (skbug.com/7002). |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 572 | // Additionally, if we previously recorded a wait op, we cannot delete the wait op. Until we |
| 573 | // track the wait ops separately from normal ops, we have to avoid clearing out any ops. |
| 574 | if (this->isEmpty() || (!fTarget.get()->asRenderTargetProxy()->needsStencil() && !fHasWaitOp)) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 575 | this->deleteOps(); |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 576 | fDeferredProxies.reset(); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 577 | |
| 578 | // If the opList is using a render target which wraps a vulkan command buffer, we can't do a |
| 579 | // clear load since we cannot change the render pass that we are using. Thus we fall back to |
| 580 | // making a clear op in this case. |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 581 | return !fTarget.get()->asRenderTargetProxy()->wrapsVkSecondaryCB(); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 582 | } |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 583 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 584 | // Could not empty the list, so an op must be added to handle the clear |
| 585 | return false; |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 586 | } |
| 587 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 588 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 589 | |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame] | 590 | // This closely parallels GrTextureOpList::copySurface but renderTargetOpLists |
| 591 | // also store the applied clip and dest proxy with the op |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 592 | bool GrRenderTargetOpList::copySurface(GrRecordingContext* context, |
Robert Phillips | a16f6cb | 2017-06-01 11:06:13 -0400 | [diff] [blame] | 593 | GrSurfaceProxy* dst, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 594 | GrSurfaceProxy* src, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 595 | const SkIRect& srcRect, |
| 596 | const SkIPoint& dstPoint) { |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 597 | SkASSERT(dst->asRenderTargetProxy() == fTarget.get()); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 598 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(context, dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 599 | if (!op) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 600 | return false; |
| 601 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 602 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 603 | this->addOp(std::move(op), *context->priv().caps()); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 604 | return true; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 607 | void GrRenderTargetOpList::purgeOpsWithUninstantiatedProxies() { |
| 608 | bool hasUninstantiatedProxy = false; |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 609 | auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p) { |
| 610 | if (!p->isInstantiated()) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 611 | hasUninstantiatedProxy = true; |
| 612 | } |
| 613 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 614 | for (OpChain& recordedOp : fOpChains) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 615 | hasUninstantiatedProxy = false; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 616 | recordedOp.visitProxies(checkInstantiation, GrOp::VisitorType::kOther); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 617 | if (hasUninstantiatedProxy) { |
| 618 | // When instantiation of the proxy fails we drop the Op |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 619 | recordedOp.deleteOps(fOpMemoryPool.get()); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 624 | bool GrRenderTargetOpList::onIsUsed(GrSurfaceProxy* proxyToCheck) const { |
| 625 | bool used = false; |
| 626 | |
| 627 | auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p) { |
| 628 | if (p == proxyToCheck) { |
| 629 | used = true; |
| 630 | } |
| 631 | }; |
| 632 | for (const OpChain& recordedOp : fOpChains) { |
| 633 | recordedOp.visitProxies(visit, GrOp::VisitorType::kOther); |
| 634 | } |
| 635 | |
| 636 | return used; |
| 637 | } |
| 638 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 639 | void GrRenderTargetOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 640 | |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 641 | for (int i = 0; i < fDeferredProxies.count(); ++i) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 642 | SkASSERT(!fDeferredProxies[i]->isInstantiated()); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 643 | // We give all the deferred proxies a write usage at the very start of flushing. This |
| 644 | // locks them out of being reused for the entire flush until they are read - and then |
| 645 | // they can be recycled. This is a bit unfortunate because a flush can proceed in waves |
| 646 | // with sub-flushes. The deferred proxies only need to be pinned from the start of |
| 647 | // the sub-flush in which they appear. |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 648 | alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 649 | } |
| 650 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 651 | // Add the interval for all the writes to this opList's target |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 652 | if (fOpChains.count()) { |
Robert Phillips | 3bf3d4a | 2019-03-27 07:09:09 -0400 | [diff] [blame] | 653 | unsigned int cur = alloc->curOp(); |
| 654 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 655 | alloc->addInterval(fTarget.get(), cur, cur + fOpChains.count() - 1, |
| 656 | GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 657 | } else { |
| 658 | // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we |
| 659 | // still need to add an interval for the destination so we create a fake op# for |
| 660 | // the missing clear op. |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 661 | alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(), |
| 662 | GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 663 | alloc->incOps(); |
| 664 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 665 | |
Chris Dalton | 8816b93 | 2017-11-29 16:48:25 -0700 | [diff] [blame] | 666 | auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p) { |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 667 | alloc->addInterval(p, alloc->curOp(), alloc->curOp(), GrResourceAllocator::ActualUse::kYes |
| 668 | SkDEBUGCODE(, fTarget.get() == p)); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 669 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 670 | for (const OpChain& recordedOp : fOpChains) { |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 671 | // only diff from the GrTextureOpList version |
| 672 | recordedOp.visitProxies(gather, GrOp::VisitorType::kAllocatorGather); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 673 | |
Robert Phillips | 3bf3d4a | 2019-03-27 07:09:09 -0400 | [diff] [blame] | 674 | // 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] | 675 | // keep all the math consistent. |
| 676 | alloc->incOps(); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 680 | void GrRenderTargetOpList::recordOp( |
| 681 | std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip, |
| 682 | const DstProxy* dstProxy, const GrCaps& caps) { |
Ethan Nicholas | 029b22c | 2018-10-18 16:49:56 -0400 | [diff] [blame] | 683 | SkDEBUGCODE(op->validate();) |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 684 | SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxy && dstProxy->proxy())); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 685 | SkASSERT(fTarget.get()); |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 686 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 687 | // A closed GrOpList should never receive new/more ops |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 688 | SkASSERT(!this->isClosed()); |
Brian Salomon | 19ec80f | 2018-11-16 13:27:30 -0500 | [diff] [blame] | 689 | if (!op->bounds().isFinite()) { |
| 690 | fOpMemoryPool->release(std::move(op)); |
| 691 | return; |
| 692 | } |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 693 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 694 | // Check if there is an op we can combine with by linearly searching back until we either |
| 695 | // 1) check every op |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 696 | // 2) intersect with something |
| 697 | // 3) find a 'blocker' |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 698 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID()); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 699 | GrOP_INFO("opList: %d Recording (%s, opID: %u)\n" |
| 700 | "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n", |
| 701 | this->uniqueID(), |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 702 | op->name(), |
| 703 | op->uniqueID(), |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 704 | op->bounds().fLeft, op->bounds().fTop, |
| 705 | op->bounds().fRight, op->bounds().fBottom); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 706 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 707 | GrOP_INFO("\tOutcome:\n"); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 708 | int maxCandidates = SkTMin(kMaxOpChainDistance, fOpChains.count()); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 709 | if (maxCandidates) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 710 | int i = 0; |
| 711 | while (true) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 712 | OpChain& candidate = fOpChains.fromBack(i); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 713 | op = candidate.appendOp(std::move(op), processorAnalysis, dstProxy, clip, caps, |
| 714 | fOpMemoryPool.get(), fAuditTrail); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 715 | if (!op) { |
| 716 | return; |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 717 | } |
Brian Salomon | a7682c8 | 2018-10-24 10:04:37 -0400 | [diff] [blame] | 718 | // Stop going backwards if we would cause a painter's order violation. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 719 | if (!can_reorder(candidate.bounds(), op->bounds())) { |
| 720 | GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n", |
| 721 | candidate.head()->name(), candidate.head()->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 722 | break; |
| 723 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 724 | if (++i == maxCandidates) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 725 | 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] | 726 | break; |
| 727 | } |
| 728 | } |
| 729 | } else { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 730 | GrOP_INFO("\t\tBackward: FirstOp\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 731 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 732 | if (clip) { |
| 733 | clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip)); |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 734 | SkDEBUGCODE(fNumClips++;) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 735 | } |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 736 | fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxy); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 739 | void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 740 | SkASSERT(!this->isClosed()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 741 | GrOP_INFO("opList: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count()); |
Robert Phillips | 48567ac | 2017-06-01 08:46:00 -0400 | [diff] [blame] | 742 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 743 | for (int i = 0; i < fOpChains.count() - 1; ++i) { |
| 744 | OpChain& chain = fOpChains[i]; |
| 745 | int maxCandidateIdx = SkTMin(i + kMaxOpChainDistance, fOpChains.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 746 | int j = i + 1; |
| 747 | while (true) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 748 | OpChain& candidate = fOpChains[j]; |
| 749 | if (candidate.prependChain(&chain, caps, fOpMemoryPool.get(), fAuditTrail)) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 750 | break; |
| 751 | } |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 752 | // Stop traversing if we would cause a painter's order violation. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 753 | if (!can_reorder(chain.bounds(), candidate.bounds())) { |
| 754 | GrOP_INFO( |
| 755 | "\t\t%d: chain (%s head opID: %u) -> " |
| 756 | "Intersects with chain (%s, head opID: %u)\n", |
| 757 | i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(), |
| 758 | candidate.head()->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 759 | break; |
| 760 | } |
Brian Salomon | a7682c8 | 2018-10-24 10:04:37 -0400 | [diff] [blame] | 761 | if (++j > maxCandidateIdx) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 762 | GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n", |
| 763 | i, chain.head()->name(), chain.head()->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 764 | break; |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | |