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