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