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