reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 8 | #include "GrRenderTargetOpList.h" |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 9 | #include "GrAuditTrail.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 11 | #include "GrGpu.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 12 | #include "GrGpuCommandBuffer.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 13 | #include "GrRenderTarget.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 14 | #include "GrRenderTargetContext.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 15 | #include "GrResourceProvider.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 16 | #include "ops/GrClearOp.h" |
| 17 | #include "ops/GrClearStencilClipOp.h" |
| 18 | #include "ops/GrCopySurfaceOp.h" |
| 19 | #include "ops/GrDiscardOp.h" |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 20 | #include "instanced/InstancedRendering.h" |
| 21 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 22 | using gr_instanced::InstancedRendering; |
| 23 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | //////////////////////////////////////////////////////////////////////////////// |
| 25 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 26 | // Experimentally we have found that most combining occurs within the first 10 comparisons. |
| 27 | static const int kDefaultMaxOpLookback = 10; |
| 28 | static const int kDefaultMaxOpLookahead = 10; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 29 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 30 | GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* rtp, GrGpu* gpu, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 31 | GrResourceProvider* resourceProvider, |
| 32 | GrAuditTrail* auditTrail, const Options& options) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 33 | : INHERITED(rtp, auditTrail) |
| 34 | , fGpu(SkRef(gpu)) |
| 35 | , fResourceProvider(resourceProvider) |
| 36 | , fLastClipStackGenID(SK_InvalidUniqueID) |
| 37 | , fClipAllocator(fClipAllocatorStorage, sizeof(fClipAllocatorStorage), |
| 38 | sizeof(fClipAllocatorStorage)) { |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 39 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 40 | fMaxOpLookback = (options.fMaxOpCombineLookback < 0) ? kDefaultMaxOpLookback |
| 41 | : options.fMaxOpCombineLookback; |
| 42 | fMaxOpLookahead = (options.fMaxOpCombineLookahead < 0) ? kDefaultMaxOpLookahead |
| 43 | : options.fMaxOpCombineLookahead; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 44 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 45 | if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) { |
| 46 | fInstancedRendering.reset(fGpu->createInstancedRendering()); |
| 47 | } |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 50 | GrRenderTargetOpList::~GrRenderTargetOpList() { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 51 | fGpu->unref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | //////////////////////////////////////////////////////////////////////////////// |
| 55 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 56 | #ifdef SK_DEBUG |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 57 | void GrRenderTargetOpList::dump() const { |
| 58 | INHERITED::dump(); |
| 59 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 60 | SkDebugf("ops (%d):\n", fRecordedOps.count()); |
| 61 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 62 | SkDebugf("*******************************\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 63 | if (!fRecordedOps[i].fOp) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 64 | SkDebugf("%d: <combined forward>\n", i); |
| 65 | } else { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 66 | SkDebugf("%d: %s\n", i, fRecordedOps[i].fOp->name()); |
| 67 | SkString str = fRecordedOps[i].fOp->dumpInfo(); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 68 | SkDebugf("%s\n", str.c_str()); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 69 | const SkRect& bounds = fRecordedOps[i].fOp->bounds(); |
| 70 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 71 | bounds.fTop, bounds.fRight, bounds.fBottom); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 72 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 75 | |
| 76 | void GrRenderTargetOpList::validateTargetsSingleRenderTarget() const { |
| 77 | GrRenderTarget* rt = nullptr; |
| 78 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 79 | if (!fRecordedOps[i].fOp) { |
| 80 | continue; // combined forward |
| 81 | } |
| 82 | |
| 83 | if (!rt) { |
| 84 | rt = fRecordedOps[i].fRenderTarget.get(); |
| 85 | } else { |
| 86 | SkASSERT(fRecordedOps[i].fRenderTarget.get() == rt); |
| 87 | } |
| 88 | } |
| 89 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 90 | #endif |
| 91 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 92 | void GrRenderTargetOpList::prepareOps(GrOpFlushState* flushState) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 93 | // MDB TODO: add SkASSERT(this->isClosed()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 94 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 95 | // Loop over the ops that haven't yet been prepared. |
| 96 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 97 | if (fRecordedOps[i].fOp) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 98 | GrOpFlushState::DrawOpArgs opArgs; |
| 99 | if (fRecordedOps[i].fRenderTarget) { |
| 100 | opArgs = { |
| 101 | fRecordedOps[i].fRenderTarget.get(), |
| 102 | fRecordedOps[i].fAppliedClip, |
| 103 | fRecordedOps[i].fDstTexture |
| 104 | }; |
| 105 | } |
| 106 | flushState->setDrawOpArgs(&opArgs); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 107 | fRecordedOps[i].fOp->prepare(flushState); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 108 | flushState->setDrawOpArgs(nullptr); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 109 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 110 | } |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 111 | |
| 112 | if (fInstancedRendering) { |
| 113 | fInstancedRendering->beginFlush(flushState->resourceProvider()); |
| 114 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 115 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 116 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 117 | // 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] | 118 | // 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] | 119 | // Ops and instantiate them here. |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 120 | bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 121 | if (0 == fRecordedOps.count()) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 122 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 123 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 124 | // Draw all the generated geometry. |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 125 | SkRandom random; |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 126 | const GrRenderTarget* currentRenderTarget = nullptr; |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 127 | std::unique_ptr<GrGpuCommandBuffer> commandBuffer; |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 128 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 129 | if (!fRecordedOps[i].fOp) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 130 | continue; |
| 131 | } |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 132 | if (fRecordedOps[i].fRenderTarget.get() != currentRenderTarget) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 133 | if (commandBuffer) { |
| 134 | commandBuffer->end(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 135 | commandBuffer->submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 136 | commandBuffer.reset(); |
| 137 | } |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 138 | currentRenderTarget = fRecordedOps[i].fRenderTarget.get(); |
| 139 | if (currentRenderTarget) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 140 | static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo |
| 141 | { GrGpuCommandBuffer::LoadOp::kLoad,GrGpuCommandBuffer::StoreOp::kStore, |
| 142 | GrColor_ILLEGAL }; |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 143 | commandBuffer.reset(fGpu->createCommandBuffer(kBasicLoadStoreInfo, // Color |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 144 | kBasicLoadStoreInfo)); // Stencil |
| 145 | } |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 146 | flushState->setCommandBuffer(commandBuffer.get()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 147 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 148 | GrOpFlushState::DrawOpArgs opArgs; |
| 149 | if (fRecordedOps[i].fRenderTarget) { |
| 150 | opArgs = { |
| 151 | fRecordedOps[i].fRenderTarget.get(), |
| 152 | fRecordedOps[i].fAppliedClip, |
| 153 | fRecordedOps[i].fDstTexture |
| 154 | }; |
| 155 | flushState->setDrawOpArgs(&opArgs); |
| 156 | } |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 157 | fRecordedOps[i].fOp->execute(flushState); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 158 | flushState->setDrawOpArgs(nullptr); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 159 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 160 | if (commandBuffer) { |
| 161 | commandBuffer->end(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 162 | commandBuffer->submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 163 | flushState->setCommandBuffer(nullptr); |
| 164 | } |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 165 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 166 | fGpu->finishOpList(); |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 167 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 170 | void GrRenderTargetOpList::reset() { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 171 | fLastFullClearOp = nullptr; |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 172 | fLastFullClearResourceID.makeInvalid(); |
| 173 | fLastFullClearProxyID.makeInvalid(); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 174 | fRecordedOps.reset(); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 175 | if (fInstancedRendering) { |
| 176 | fInstancedRendering->endFlush(); |
| 177 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 180 | void GrRenderTargetOpList::abandonGpuResources() { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 181 | if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 182 | InstancedRendering* ir = this->instancedRendering(); |
| 183 | ir->resetGpuResources(InstancedRendering::ResetType::kAbandon); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void GrRenderTargetOpList::freeGpuResources() { |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 188 | if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 189 | InstancedRendering* ir = this->instancedRendering(); |
| 190 | ir->resetGpuResources(InstancedRendering::ResetType::kDestroy); |
| 191 | } |
| 192 | } |
| 193 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 194 | void GrRenderTargetOpList::fullClear(GrRenderTargetContext* renderTargetContext, GrColor color) { |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 195 | // MDB TODO: remove this. Right now we need the renderTargetContext for the |
| 196 | // accessRenderTarget call. This method should just take the renderTargetProxy. |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 197 | GrRenderTarget* renderTarget = renderTargetContext->accessRenderTarget(); |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 198 | if (!renderTarget) { |
| 199 | return; |
| 200 | } |
| 201 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 202 | // Currently this just inserts or updates the last clear op. However, once in MDB this can |
| 203 | // remove all the previously recorded ops and change the load op to clear with supplied |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 204 | // color. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 205 | // TODO: this needs to be updated to use GrSurfaceProxy::UniqueID |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 206 | SkASSERT((fLastFullClearResourceID == renderTarget->uniqueID()) == |
| 207 | (fLastFullClearProxyID == renderTargetContext->asRenderTargetProxy()->uniqueID())); |
| 208 | if (fLastFullClearResourceID == renderTarget->uniqueID()) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 209 | // As currently implemented, fLastFullClearOp should be the last op because we would |
| 210 | // have cleared it when another op was recorded. |
| 211 | SkASSERT(fRecordedOps.back().fOp.get() == fLastFullClearOp); |
| 212 | fLastFullClearOp->setColor(color); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 213 | return; |
| 214 | } |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 215 | std::unique_ptr<GrClearOp> op(GrClearOp::Make(GrFixedClip::Disabled(), color, |
| 216 | renderTargetContext)); |
| 217 | if (!op) { |
| 218 | return; |
| 219 | } |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 220 | if (GrOp* clearOp = this->recordOp(std::move(op), renderTargetContext)) { |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 221 | // This is either the clear op we just created or another one that it combined with. |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 222 | fLastFullClearOp = static_cast<GrClearOp*>(clearOp); |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 223 | fLastFullClearResourceID = renderTarget->uniqueID(); |
| 224 | fLastFullClearProxyID = renderTargetContext->asRenderTargetProxy()->uniqueID(); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 225 | } |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 228 | void GrRenderTargetOpList::discard(GrRenderTargetContext* renderTargetContext) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 229 | // Currently this just inserts a discard op. However, once in MDB this can remove all the |
| 230 | // previously recorded ops and change the load op to discard. |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 231 | if (this->caps()->discardRenderTargetSupport()) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 232 | this->recordOp(GrDiscardOp::Make(renderTargetContext->accessRenderTarget()), |
| 233 | renderTargetContext); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 237 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 238 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 239 | bool GrRenderTargetOpList::copySurface(GrResourceProvider* resourceProvider, |
| 240 | GrSurfaceProxy* dst, |
| 241 | GrSurfaceProxy* src, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 242 | const SkIRect& srcRect, |
| 243 | const SkIPoint& dstPoint) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 244 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(resourceProvider, dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 245 | if (!op) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 246 | return false; |
| 247 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 248 | #ifdef ENABLE_MDB |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 249 | this->addDependency(src); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 250 | #endif |
| 251 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 252 | // Copy surface doesn't work through a GrGpuCommandBuffer. By passing nullptr for the context we |
| 253 | // force this to occur between command buffers and execute directly on GrGpu. This workaround |
| 254 | // goes away with MDB. |
| 255 | this->recordOp(std::move(op), nullptr); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 256 | return true; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 257 | } |
| 258 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 259 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 260 | return a.fRight <= b.fLeft || a.fBottom <= b.fTop || |
| 261 | b.fRight <= a.fLeft || b.fBottom <= a.fTop; |
| 262 | } |
| 263 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 264 | bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b, |
| 265 | const GrAppliedClip* bClip, |
| 266 | const DstTexture* bDstTexture) { |
| 267 | if (a.fAppliedClip) { |
| 268 | if (!bClip) { |
| 269 | return false; |
| 270 | } |
| 271 | if (*a.fAppliedClip != *bClip) { |
| 272 | return false; |
| 273 | } |
| 274 | } else if (bClip) { |
| 275 | return false; |
| 276 | } |
| 277 | if (bDstTexture) { |
| 278 | if (a.fDstTexture != *bDstTexture) { |
| 279 | return false; |
| 280 | } |
| 281 | } else if (a.fDstTexture.texture()) { |
| 282 | return false; |
| 283 | } |
| 284 | return a.fOp->combineIfPossible(b, *this->caps()); |
| 285 | } |
| 286 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 287 | GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op, |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 288 | GrRenderTargetContext* renderTargetContext, |
| 289 | GrAppliedClip* clip, |
| 290 | const DstTexture* dstTexture) { |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 291 | GrRenderTarget* renderTarget = |
| 292 | renderTargetContext ? renderTargetContext->accessRenderTarget() |
| 293 | : nullptr; |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 294 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 295 | // A closed GrOpList should never receive new/more ops |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 296 | SkASSERT(!this->isClosed()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 297 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 298 | // Check if there is an op we can combine with by linearly searching back until we either |
| 299 | // 1) check every op |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 300 | // 2) intersect with something |
| 301 | // 3) find a 'blocker' |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 302 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTarget->uniqueID(), |
| 303 | renderTargetContext->asRenderTargetProxy()->uniqueID()); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 304 | GrOP_INFO("Recording (%s, B%u)\n" |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 305 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 306 | op->name(), |
| 307 | op->uniqueID(), |
| 308 | op->bounds().fLeft, op->bounds().fRight, |
| 309 | op->bounds().fTop, op->bounds().fBottom); |
| 310 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 311 | GrOP_INFO("\tClipped Bounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", op->bounds().fLeft, |
| 312 | op->bounds().fTop, op->bounds().fRight, op->bounds().fBottom); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 313 | GrOP_INFO("\tOutcome:\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 314 | int maxCandidates = SkTMin(fMaxOpLookback, fRecordedOps.count()); |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 315 | // If we don't have a valid destination render target then we cannot reorder. |
| 316 | if (maxCandidates && renderTarget) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 317 | int i = 0; |
| 318 | while (true) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 319 | const RecordedOp& candidate = fRecordedOps.fromBack(i); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 320 | // We cannot continue to search backwards if the render target changes |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 321 | if (candidate.fRenderTarget.get() != renderTarget) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 322 | GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(), |
| 323 | candidate.fOp->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 324 | break; |
| 325 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 326 | if (this->combineIfPossible(candidate, op.get(), clip, dstTexture)) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 327 | GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(), |
| 328 | candidate.fOp->uniqueID()); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 329 | GrOP_INFO("\t\t\tCombined op info:\n"); |
| 330 | GrOP_INFO(SkTabString(candidate.fOp->dumpInfo(), 4).c_str()); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 331 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, candidate.fOp.get(), op.get()); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 332 | return candidate.fOp.get(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 333 | } |
| 334 | // Stop going backwards if we would cause a painter's order violation. |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 335 | if (!can_reorder(fRecordedOps.fromBack(i).fOp->bounds(), op->bounds())) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 336 | GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(), |
| 337 | candidate.fOp->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 338 | break; |
| 339 | } |
| 340 | ++i; |
| 341 | if (i == maxCandidates) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 342 | GrOP_INFO("\t\tReached max lookback or beginning of op array %d\n", i); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 343 | break; |
| 344 | } |
| 345 | } |
| 346 | } else { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 347 | GrOP_INFO("\t\tFirstOp\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 348 | } |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 349 | GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 350 | if (clip) { |
| 351 | clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip)); |
| 352 | } |
| 353 | fRecordedOps.emplace_back(std::move(op), renderTarget, clip, dstTexture); |
Brian Salomon | d543e0a | 2017-03-06 16:36:49 -0500 | [diff] [blame] | 354 | fRecordedOps.back().fOp->wasRecorded(); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 355 | fLastFullClearOp = nullptr; |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 356 | fLastFullClearResourceID.makeInvalid(); |
| 357 | fLastFullClearProxyID.makeInvalid(); |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 358 | return fRecordedOps.back().fOp.get(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 361 | void GrRenderTargetOpList::forwardCombine() { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 362 | if (fMaxOpLookahead <= 0) { |
bsalomon | db27fc5 | 2016-08-29 12:43:27 -0700 | [diff] [blame] | 363 | return; |
| 364 | } |
Brian Salomon | 337432d | 2017-03-21 17:36:10 -0400 | [diff] [blame] | 365 | for (int i = 0; i < fRecordedOps.count() - 1; ++i) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 366 | GrOp* op = fRecordedOps[i].fOp.get(); |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 367 | GrRenderTarget* renderTarget = fRecordedOps[i].fRenderTarget.get(); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 368 | // If we don't have a valid destination render target ID then we cannot reorder. |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 369 | if (!renderTarget) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 370 | continue; |
| 371 | } |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 372 | int maxCandidateIdx = SkTMin(i + fMaxOpLookahead, fRecordedOps.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 373 | int j = i + 1; |
| 374 | while (true) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 375 | const RecordedOp& candidate = fRecordedOps[j]; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 376 | // We cannot continue to search if the render target changes |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 377 | if (candidate.fRenderTarget.get() != renderTarget) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 378 | GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(), |
| 379 | candidate.fOp->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 380 | break; |
| 381 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 382 | if (this->combineIfPossible(fRecordedOps[i], candidate.fOp.get(), |
| 383 | candidate.fAppliedClip, &candidate.fDstTexture)) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 384 | GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(), |
| 385 | candidate.fOp->uniqueID()); |
| 386 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 387 | fRecordedOps[j].fOp = std::move(fRecordedOps[i].fOp); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 388 | break; |
| 389 | } |
| 390 | // Stop going traversing if we would cause a painter's order violation. |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 391 | if (!can_reorder(fRecordedOps[j].fOp->bounds(), op->bounds())) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 392 | GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(), |
| 393 | candidate.fOp->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 394 | break; |
| 395 | } |
| 396 | ++j; |
| 397 | if (j > maxCandidateIdx) { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 398 | GrOP_INFO("\t\tReached max lookahead or end of op array %d\n", i); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 399 | break; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |