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