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 | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 9 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 10 | #include "GrAppliedClip.h" |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 11 | #include "GrAuditTrail.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 12 | #include "GrCaps.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetContext.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 14 | #include "GrGpu.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 15 | #include "GrGpuCommandBuffer.h" |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 16 | #include "GrPath.h" |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 17 | #include "GrPipeline.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 18 | #include "GrMemoryPool.h" |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 19 | #include "GrPipelineBuilder.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 20 | #include "GrRenderTarget.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 21 | #include "GrResourceProvider.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 22 | #include "GrRenderTargetPriv.h" |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 23 | #include "GrStencilAttachment.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 24 | #include "GrSurfacePriv.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 25 | #include "GrTexture.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 27 | #include "SkStrokeRec.h" |
| 28 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 29 | #include "ops/GrClearOp.h" |
| 30 | #include "ops/GrClearStencilClipOp.h" |
| 31 | #include "ops/GrCopySurfaceOp.h" |
| 32 | #include "ops/GrDiscardOp.h" |
| 33 | #include "ops/GrDrawOp.h" |
| 34 | #include "ops/GrDrawPathOp.h" |
| 35 | #include "ops/GrRectOpFactory.h" |
| 36 | #include "ops/GrStencilPathOp.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 37 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 38 | #include "instanced/InstancedRendering.h" |
| 39 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 40 | using gr_instanced::InstancedRendering; |
| 41 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | //////////////////////////////////////////////////////////////////////////////// |
| 43 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 44 | // Experimentally we have found that most combining occurs within the first 10 comparisons. |
| 45 | static const int kDefaultMaxOpLookback = 10; |
| 46 | static const int kDefaultMaxOpLookahead = 10; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 47 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 48 | GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* rtp, GrGpu* gpu, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 49 | GrResourceProvider* resourceProvider, |
| 50 | GrAuditTrail* auditTrail, const Options& options) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 51 | : INHERITED(rtp, auditTrail) |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 52 | , fGpu(SkRef(gpu)) |
csmartdalton | 7cdda99 | 2016-11-01 07:03:03 -0700 | [diff] [blame] | 53 | , fResourceProvider(resourceProvider) |
| 54 | , fLastClipStackGenID(SK_InvalidUniqueID) { |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 55 | // TODO: Stop extracting the context (currently needed by GrClip) |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 56 | fContext = fGpu->getContext(); |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 57 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 58 | fMaxOpLookback = (options.fMaxOpCombineLookback < 0) ? kDefaultMaxOpLookback |
| 59 | : options.fMaxOpCombineLookback; |
| 60 | fMaxOpLookahead = (options.fMaxOpCombineLookahead < 0) ? kDefaultMaxOpLookahead |
| 61 | : options.fMaxOpCombineLookahead; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 62 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 63 | if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) { |
| 64 | fInstancedRendering.reset(fGpu->createInstancedRendering()); |
| 65 | } |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 68 | GrRenderTargetOpList::~GrRenderTargetOpList() { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 69 | fGpu->unref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | //////////////////////////////////////////////////////////////////////////////// |
| 73 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 74 | #ifdef SK_DEBUG |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 75 | void GrRenderTargetOpList::dump() const { |
| 76 | INHERITED::dump(); |
| 77 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 78 | SkDebugf("ops (%d):\n", fRecordedOps.count()); |
| 79 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 80 | SkDebugf("*******************************\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 81 | if (!fRecordedOps[i].fOp) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 82 | SkDebugf("%d: <combined forward>\n", i); |
| 83 | } else { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 84 | SkDebugf("%d: %s\n", i, fRecordedOps[i].fOp->name()); |
| 85 | SkString str = fRecordedOps[i].fOp->dumpInfo(); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 86 | SkDebugf("%s\n", str.c_str()); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 87 | const SkRect& bounds = fRecordedOps[i].fOp->bounds(); |
| 88 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 89 | bounds.fTop, bounds.fRight, bounds.fBottom); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 90 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | #endif |
| 94 | |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 95 | void GrRenderTargetOpList::setupDstTexture(GrRenderTarget* rt, |
| 96 | const GrClip& clip, |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 97 | const SkRect& opBounds, |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 98 | GrXferProcessor::DstTexture* dstTexture) { |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 99 | if (this->caps()->textureBarrierSupport()) { |
| 100 | if (GrTexture* rtTex = rt->asTexture()) { |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 101 | // The render target is a texture, so we can read from it directly in the shader. The XP |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 102 | // will be responsible to detect this situation and request a texture barrier. |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 103 | dstTexture->setTexture(sk_ref_sp(rtTex)); |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 104 | dstTexture->setOffset(0, 0); |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 105 | return; |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | SkIRect copyRect; |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 110 | clip.getConservativeBounds(rt->width(), rt->height(), ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 111 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 112 | SkIRect drawIBounds; |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 113 | opBounds.roundOut(&drawIBounds); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 114 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 115 | #ifdef SK_DEBUG |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 116 | GrCapsDebugf(this->caps(), "Missed an early reject. " |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 117 | "Bailing on draw from setupDstTexture.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 118 | #endif |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 119 | return; |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 120 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 121 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 122 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 123 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 124 | GrSurfaceDesc desc; |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 125 | if (!fGpu->initDescForDstCopy(rt, &desc)) { |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 126 | desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 127 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 128 | desc.fConfig = rt->config(); |
| 129 | } |
| 130 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 131 | desc.fWidth = copyRect.width(); |
| 132 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 133 | |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 134 | static const uint32_t kFlags = 0; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 135 | sk_sp<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 136 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 137 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 138 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 139 | return; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 140 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 141 | SkIPoint dstPoint = {0, 0}; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 142 | this->copySurface(copy.get(), rt, copyRect, dstPoint); |
| 143 | dstTexture->setTexture(std::move(copy)); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 144 | dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 147 | void GrRenderTargetOpList::prepareOps(GrOpFlushState* flushState) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 148 | // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh |
| 149 | // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed |
| 150 | // but need to be flushed anyway. Closing such GrOpLists here will mean new |
| 151 | // 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] | 152 | this->makeClosed(); |
| 153 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 154 | // Loop over the ops that haven't yet been prepared. |
| 155 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 156 | if (fRecordedOps[i].fOp) { |
| 157 | fRecordedOps[i].fOp->prepare(flushState); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 158 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 159 | } |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 160 | |
| 161 | if (fInstancedRendering) { |
| 162 | fInstancedRendering->beginFlush(flushState->resourceProvider()); |
| 163 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 164 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 165 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 166 | // 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] | 167 | // 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] | 168 | // Ops and instantiate them here. |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 169 | bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 170 | if (0 == fRecordedOps.count()) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 171 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 172 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 173 | // Draw all the generated geometry. |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 174 | SkRandom random; |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 175 | const GrRenderTarget* currentRenderTarget = nullptr; |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 176 | std::unique_ptr<GrGpuCommandBuffer> commandBuffer; |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 177 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 178 | if (!fRecordedOps[i].fOp) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 179 | continue; |
| 180 | } |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 181 | if (fRecordedOps[i].fRenderTarget.get() != currentRenderTarget) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 182 | if (commandBuffer) { |
| 183 | commandBuffer->end(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 184 | commandBuffer->submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 185 | commandBuffer.reset(); |
| 186 | } |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 187 | currentRenderTarget = fRecordedOps[i].fRenderTarget.get(); |
| 188 | if (currentRenderTarget) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 189 | static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo |
| 190 | { GrGpuCommandBuffer::LoadOp::kLoad,GrGpuCommandBuffer::StoreOp::kStore, |
| 191 | GrColor_ILLEGAL }; |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 192 | commandBuffer.reset(fGpu->createCommandBuffer(kBasicLoadStoreInfo, // Color |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 193 | kBasicLoadStoreInfo)); // Stencil |
| 194 | } |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 195 | flushState->setCommandBuffer(commandBuffer.get()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 196 | } |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 197 | fRecordedOps[i].fOp->execute(flushState); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 198 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 199 | if (commandBuffer) { |
| 200 | commandBuffer->end(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 201 | commandBuffer->submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 202 | flushState->setCommandBuffer(nullptr); |
| 203 | } |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 204 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 205 | fGpu->finishOpList(); |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 206 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 209 | void GrRenderTargetOpList::reset() { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 210 | fLastFullClearOp = nullptr; |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 211 | fLastFullClearRenderTargetID.makeInvalid(); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 212 | fRecordedOps.reset(); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 213 | if (fInstancedRendering) { |
| 214 | fInstancedRendering->endFlush(); |
| 215 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 218 | void GrRenderTargetOpList::abandonGpuResources() { |
| 219 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { |
| 220 | InstancedRendering* ir = this->instancedRendering(); |
| 221 | ir->resetGpuResources(InstancedRendering::ResetType::kAbandon); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void GrRenderTargetOpList::freeGpuResources() { |
| 226 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { |
| 227 | InstancedRendering* ir = this->instancedRendering(); |
| 228 | ir->resetGpuResources(InstancedRendering::ResetType::kDestroy); |
| 229 | } |
| 230 | } |
| 231 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 232 | static void op_bounds(SkRect* bounds, const GrOp* op) { |
| 233 | *bounds = op->bounds(); |
| 234 | if (op->hasZeroArea()) { |
| 235 | if (op->hasAABloat()) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 236 | bounds->outset(0.5f, 0.5f); |
| 237 | } else { |
| 238 | // We don't know which way the particular GPU will snap lines or points at integer |
| 239 | // coords. So we ensure that the bounds is large enough for either snap. |
| 240 | SkRect before = *bounds; |
| 241 | bounds->roundOut(bounds); |
| 242 | if (bounds->fLeft == before.fLeft) { |
| 243 | bounds->fLeft -= 1; |
| 244 | } |
| 245 | if (bounds->fTop == before.fTop) { |
| 246 | bounds->fTop -= 1; |
| 247 | } |
| 248 | if (bounds->fRight == before.fRight) { |
| 249 | bounds->fRight += 1; |
| 250 | } |
| 251 | if (bounds->fBottom == before.fBottom) { |
| 252 | bounds->fBottom += 1; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 258 | void GrRenderTargetOpList::addDrawOp(const GrPipelineBuilder& pipelineBuilder, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 259 | GrRenderTargetContext* renderTargetContext, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 260 | const GrClip& clip, |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 261 | std::unique_ptr<GrDrawOp> op) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 262 | // Setup clip |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 263 | SkRect bounds; |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 264 | op_bounds(&bounds, op.get()); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 265 | GrAppliedClip appliedClip(bounds); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 266 | if (!clip.apply(fContext, renderTargetContext, pipelineBuilder.isHWAntialias(), |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 267 | pipelineBuilder.hasUserStencilSettings(), &appliedClip)) { |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 268 | return; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 269 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 270 | |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 271 | if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip()) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 272 | if (!renderTargetContext->accessRenderTarget()) { |
| 273 | return; |
| 274 | } |
| 275 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 276 | if (!fResourceProvider->attachStencilAttachment( |
| 277 | renderTargetContext->accessRenderTarget())) { |
cdalton | 17bf820 | 2016-05-13 11:27:15 -0700 | [diff] [blame] | 278 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 279 | return; |
| 280 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 281 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 282 | |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 283 | GrProcessorSet::FragmentProcessorAnalysis analysis; |
| 284 | op->analyzeProcessors(&analysis, pipelineBuilder.processors(), appliedClip, *this->caps()); |
| 285 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 286 | GrPipeline::InitArgs args; |
| 287 | pipelineBuilder.getPipelineInitArgs(&args); |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 288 | args.fAppliedClip = &appliedClip; |
Brian Salomon | b16e8ac | 2017-02-22 11:52:36 -0500 | [diff] [blame] | 289 | // This forces instantiation of the render target. Pipeline creation is moving to flush time |
| 290 | // by which point instantiation must have occurred anyway. |
| 291 | args.fRenderTarget = renderTargetContext->accessRenderTarget(); |
| 292 | if (!args.fRenderTarget) { |
| 293 | return; |
| 294 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 295 | args.fCaps = this->caps(); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 296 | args.fAnalysis = &analysis; |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 297 | |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 298 | if (!renderTargetContext->accessRenderTarget()) { |
| 299 | return; |
| 300 | } |
| 301 | |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 302 | if (pipelineBuilder.willXPNeedDstTexture(*this->caps(), analysis)) { |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 303 | this->setupDstTexture(renderTargetContext->accessRenderTarget(), clip, bounds, |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 304 | &args.fDstTexture); |
| 305 | if (!args.fDstTexture.texture()) { |
| 306 | return; |
| 307 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 308 | } |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 309 | op->initPipeline(args); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 310 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 311 | #ifdef ENABLE_MDB |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 312 | SkASSERT(fSurface); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 313 | op->pipeline()->addDependenciesTo(fSurface); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 314 | #endif |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 315 | op->setClippedBounds(appliedClip.clippedDrawBounds()); |
| 316 | this->recordOp(std::move(op), renderTargetContext); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 319 | void GrRenderTargetOpList::stencilPath(GrRenderTargetContext* renderTargetContext, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 320 | const GrClip& clip, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 321 | GrAAType aaType, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 322 | const SkMatrix& viewMatrix, |
| 323 | const GrPath* path) { |
Brian Salomon | 0abc8b4 | 2016-12-13 10:22:54 -0500 | [diff] [blame] | 324 | bool useHWAA = GrAATypeIsHW(aaType); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 325 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 326 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 327 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 328 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 329 | // FIXME: Use path bounds instead of this WAR once |
| 330 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 331 | SkRect bounds = SkRect::MakeIWH(renderTargetContext->width(), renderTargetContext->height()); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 332 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 333 | // Setup clip |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 334 | GrAppliedClip appliedClip(bounds); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 335 | if (!clip.apply(fContext, renderTargetContext, useHWAA, true, &appliedClip)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 336 | return; |
| 337 | } |
| 338 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 339 | // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never |
| 340 | // attempt this in a situation that would require coverage AA. |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 341 | SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 342 | |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 343 | if (!renderTargetContext->accessRenderTarget()) { |
| 344 | return; |
| 345 | } |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 346 | GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAttachment( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 347 | renderTargetContext->accessRenderTarget()); |
cdalton | 17bf820 | 2016-05-13 11:27:15 -0700 | [diff] [blame] | 348 | if (!stencilAttachment) { |
| 349 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 350 | return; |
| 351 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 352 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 353 | std::unique_ptr<GrOp> op = GrStencilPathOp::Make(viewMatrix, |
| 354 | useHWAA, |
| 355 | path->getFillType(), |
| 356 | appliedClip.hasStencilClip(), |
| 357 | stencilAttachment->bits(), |
| 358 | appliedClip.scissorState(), |
| 359 | renderTargetContext->accessRenderTarget(), |
| 360 | path); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 361 | op->setClippedBounds(appliedClip.clippedDrawBounds()); |
| 362 | this->recordOp(std::move(op), renderTargetContext); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 365 | void GrRenderTargetOpList::fullClear(GrRenderTargetContext* renderTargetContext, GrColor color) { |
| 366 | GrRenderTarget* renderTarget = renderTargetContext->accessRenderTarget(); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 367 | // Currently this just inserts or updates the last clear op. However, once in MDB this can |
| 368 | // 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] | 369 | // color. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 370 | // TODO: this needs to be updated to use GrSurfaceProxy::UniqueID |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 371 | if (fLastFullClearRenderTargetID == renderTarget->uniqueID()) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 372 | // As currently implemented, fLastFullClearOp should be the last op because we would |
| 373 | // have cleared it when another op was recorded. |
| 374 | SkASSERT(fRecordedOps.back().fOp.get() == fLastFullClearOp); |
| 375 | fLastFullClearOp->setColor(color); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 376 | return; |
| 377 | } |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 378 | std::unique_ptr<GrClearOp> op(GrClearOp::Make(GrFixedClip::Disabled(), color, renderTarget)); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 379 | if (GrOp* clearOp = this->recordOp(std::move(op), renderTargetContext)) { |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 380 | // 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] | 381 | fLastFullClearOp = static_cast<GrClearOp*>(clearOp); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 382 | fLastFullClearRenderTargetID = renderTarget->uniqueID(); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 383 | } |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 386 | void GrRenderTargetOpList::discard(GrRenderTargetContext* renderTargetContext) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 387 | // Currently this just inserts a discard op. However, once in MDB this can remove all the |
| 388 | // previously recorded ops and change the load op to discard. |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 389 | if (this->caps()->discardRenderTargetSupport()) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 390 | this->recordOp(GrDiscardOp::Make(renderTargetContext->accessRenderTarget()), |
| 391 | renderTargetContext); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 395 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 396 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 397 | bool GrRenderTargetOpList::copySurface(GrSurface* dst, |
| 398 | GrSurface* src, |
| 399 | const SkIRect& srcRect, |
| 400 | const SkIPoint& dstPoint) { |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 401 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 402 | if (!op) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 403 | return false; |
| 404 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 405 | #ifdef ENABLE_MDB |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 406 | this->addDependency(src); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 407 | #endif |
| 408 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 409 | // Copy surface doesn't work through a GrGpuCommandBuffer. By passing nullptr for the context we |
| 410 | // force this to occur between command buffers and execute directly on GrGpu. This workaround |
| 411 | // goes away with MDB. |
| 412 | this->recordOp(std::move(op), nullptr); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 413 | return true; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 414 | } |
| 415 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 416 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 417 | return a.fRight <= b.fLeft || a.fBottom <= b.fTop || |
| 418 | b.fRight <= a.fLeft || b.fBottom <= a.fTop; |
| 419 | } |
| 420 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 421 | GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op, |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 422 | GrRenderTargetContext* renderTargetContext) { |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 423 | GrRenderTarget* renderTarget = |
| 424 | renderTargetContext ? renderTargetContext->accessRenderTarget() |
| 425 | : nullptr; |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 426 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 427 | // A closed GrOpList should never receive new/more ops |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 428 | SkASSERT(!this->isClosed()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 429 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 430 | // Check if there is an op we can combine with by linearly searching back until we either |
| 431 | // 1) check every op |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 432 | // 2) intersect with something |
| 433 | // 3) find a 'blocker' |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 434 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTarget->uniqueID()); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 435 | GrOP_INFO("Recording (%s, B%u)\n" |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 436 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 437 | op->name(), |
| 438 | op->uniqueID(), |
| 439 | op->bounds().fLeft, op->bounds().fRight, |
| 440 | op->bounds().fTop, op->bounds().fBottom); |
| 441 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 442 | GrOP_INFO("\tClipped Bounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", op->bounds().fLeft, |
| 443 | op->bounds().fTop, op->bounds().fRight, op->bounds().fBottom); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 444 | GrOP_INFO("\tOutcome:\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 445 | int maxCandidates = SkTMin(fMaxOpLookback, fRecordedOps.count()); |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 446 | // If we don't have a valid destination render target then we cannot reorder. |
| 447 | if (maxCandidates && renderTarget) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 448 | int i = 0; |
| 449 | while (true) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 450 | const RecordedOp& candidate = fRecordedOps.fromBack(i); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 451 | // We cannot continue to search backwards if the render target changes |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 452 | if (candidate.fRenderTarget.get() != renderTarget) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 453 | GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(), |
| 454 | candidate.fOp->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 455 | break; |
| 456 | } |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 457 | if (candidate.fOp->combineIfPossible(op.get(), *this->caps())) { |
| 458 | GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(), |
| 459 | candidate.fOp->uniqueID()); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 460 | GrOP_INFO("\t\t\tCombined op info:\n"); |
| 461 | GrOP_INFO(SkTabString(candidate.fOp->dumpInfo(), 4).c_str()); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 462 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, candidate.fOp.get(), op.get()); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 463 | return candidate.fOp.get(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 464 | } |
| 465 | // Stop going backwards if we would cause a painter's order violation. |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 466 | if (!can_reorder(fRecordedOps.fromBack(i).fOp->bounds(), op->bounds())) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 467 | GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(), |
| 468 | candidate.fOp->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 469 | break; |
| 470 | } |
| 471 | ++i; |
| 472 | if (i == maxCandidates) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 473 | 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] | 474 | break; |
| 475 | } |
| 476 | } |
| 477 | } else { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 478 | GrOP_INFO("\t\tFirstOp\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 479 | } |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 480 | GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 481 | fRecordedOps.emplace_back(std::move(op), renderTarget); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 482 | fLastFullClearOp = nullptr; |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 483 | fLastFullClearRenderTargetID.makeInvalid(); |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 484 | return fRecordedOps.back().fOp.get(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 487 | void GrRenderTargetOpList::forwardCombine() { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 488 | if (fMaxOpLookahead <= 0) { |
bsalomon | db27fc5 | 2016-08-29 12:43:27 -0700 | [diff] [blame] | 489 | return; |
| 490 | } |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 491 | for (int i = 0; i < fRecordedOps.count() - 2; ++i) { |
| 492 | GrOp* op = fRecordedOps[i].fOp.get(); |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 493 | GrRenderTarget* renderTarget = fRecordedOps[i].fRenderTarget.get(); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 494 | // 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] | 495 | if (!renderTarget) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 496 | continue; |
| 497 | } |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 498 | int maxCandidateIdx = SkTMin(i + fMaxOpLookahead, fRecordedOps.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 499 | int j = i + 1; |
| 500 | while (true) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 501 | const RecordedOp& candidate = fRecordedOps[j]; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 502 | // We cannot continue to search if the render target changes |
Brian Salomon | cdcc33f | 2017-02-21 09:49:20 -0500 | [diff] [blame] | 503 | if (candidate.fRenderTarget.get() != renderTarget) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 504 | GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(), |
| 505 | candidate.fOp->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 506 | break; |
| 507 | } |
| 508 | if (j == i +1) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 509 | // We assume op would have combined with candidate when the candidate was added |
| 510 | // via backwards combining in recordOp. |
Mike Reed | 27d07f0 | 2017-03-04 21:47:47 +0000 | [diff] [blame] | 511 | #ifndef SK_USE_DEVICE_CLIPPING |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 512 | // not sure why this fires with device-clipping in gm/complexclip4.cpp |
Mike Reed | 27d07f0 | 2017-03-04 21:47:47 +0000 | [diff] [blame] | 513 | SkASSERT(!op->combineIfPossible(candidate.fOp.get(), *this->caps())); |
| 514 | #endif |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 515 | } else if (op->combineIfPossible(candidate.fOp.get(), *this->caps())) { |
| 516 | GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(), |
| 517 | candidate.fOp->uniqueID()); |
| 518 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 519 | fRecordedOps[j].fOp = std::move(fRecordedOps[i].fOp); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 520 | break; |
| 521 | } |
| 522 | // Stop going traversing if we would cause a painter's order violation. |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame^] | 523 | if (!can_reorder(fRecordedOps[j].fOp->bounds(), op->bounds())) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 524 | GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(), |
| 525 | candidate.fOp->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 526 | break; |
| 527 | } |
| 528 | ++j; |
| 529 | if (j > maxCandidateIdx) { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 530 | 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] | 531 | break; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 537 | /////////////////////////////////////////////////////////////////////////////// |
| 538 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 539 | void GrRenderTargetOpList::clearStencilClip(const GrFixedClip& clip, |
| 540 | bool insideStencilMask, |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 541 | GrRenderTargetContext* renderTargetContext) { |
| 542 | this->recordOp(GrClearStencilClipOp::Make(clip, insideStencilMask, |
| 543 | renderTargetContext->accessRenderTarget()), |
| 544 | renderTargetContext); |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 545 | } |