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