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