Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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. |
| 6 | */ |
| 7 | |
| 8 | #include "GrTextureOpList.h" |
| 9 | |
| 10 | #include "GrAuditTrail.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 11 | #include "GrContext.h" |
| 12 | #include "GrContextPriv.h" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 13 | #include "GrGpu.h" |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 14 | #include "GrMemoryPool.h" |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 15 | #include "GrResourceAllocator.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 16 | #include "GrTextureProxy.h" |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 17 | #include "SkStringUtils.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 18 | #include "ops/GrCopySurfaceOp.h" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 19 | |
| 20 | //////////////////////////////////////////////////////////////////////////////// |
| 21 | |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 22 | GrTextureOpList::GrTextureOpList(GrResourceProvider* resourceProvider, |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 23 | sk_sp<GrOpMemoryPool> opMemoryPool, |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 24 | GrTextureProxy* proxy, |
| 25 | GrAuditTrail* auditTrail) |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 26 | : INHERITED(resourceProvider, std::move(opMemoryPool), proxy, auditTrail) { |
| 27 | SkASSERT(fOpMemoryPool); |
| 28 | } |
| 29 | |
| 30 | void GrTextureOpList::deleteOp(int index) { |
| 31 | SkASSERT(index >= 0 && index < fRecordedOps.count()); |
| 32 | fOpMemoryPool->release(std::move(fRecordedOps[index])); |
| 33 | } |
| 34 | |
| 35 | void GrTextureOpList::deleteOps() { |
| 36 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Robert Phillips | d46f009 | 2018-07-12 11:49:25 -0400 | [diff] [blame] | 37 | if (fRecordedOps[i]) { |
| 38 | fOpMemoryPool->release(std::move(fRecordedOps[i])); |
| 39 | } |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 40 | } |
| 41 | fRecordedOps.reset(); |
| 42 | fOpMemoryPool = nullptr; |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | GrTextureOpList::~GrTextureOpList() { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 46 | this->deleteOps(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | //////////////////////////////////////////////////////////////////////////////// |
| 50 | |
| 51 | #ifdef SK_DEBUG |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 52 | void GrTextureOpList::dump(bool printDependencies) const { |
| 53 | INHERITED::dump(printDependencies); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 54 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 55 | SkDebugf("ops (%d):\n", fRecordedOps.count()); |
| 56 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 57 | if (!fRecordedOps[i]) { |
| 58 | SkDebugf("%d: <failed instantiation>\n", i); |
| 59 | } else { |
| 60 | SkDebugf("*******************************\n"); |
| 61 | SkDebugf("%d: %s\n", i, fRecordedOps[i]->name()); |
| 62 | SkString str = fRecordedOps[i]->dumpInfo(); |
| 63 | SkDebugf("%s\n", str.c_str()); |
| 64 | const SkRect& clippedBounds = fRecordedOps[i]->bounds(); |
| 65 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 66 | clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight, |
| 67 | clippedBounds.fBottom); |
| 68 | } |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 69 | } |
| 70 | } |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame] | 71 | |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 72 | #endif |
| 73 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 74 | void GrTextureOpList::onPrepare(GrOpFlushState* flushState) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 75 | SkASSERT(fTarget.get()->peekTexture()); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 76 | SkASSERT(this->isClosed()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 77 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 78 | // Loop over the ops that haven't yet generated their geometry |
| 79 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 80 | if (fRecordedOps[i]) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 81 | SkASSERT(fRecordedOps[i]->isChainHead()); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 82 | GrOpFlushState::OpArgs opArgs = { |
| 83 | fRecordedOps[i].get(), |
| 84 | nullptr, |
| 85 | nullptr, |
| 86 | GrXferProcessor::DstProxy() |
| 87 | }; |
| 88 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 89 | fRecordedOps[i]->prepare(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 90 | flushState->setOpArgs(nullptr); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 95 | bool GrTextureOpList::onExecute(GrOpFlushState* flushState) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 96 | if (0 == fRecordedOps.count()) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 97 | return false; |
| 98 | } |
| 99 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 100 | SkASSERT(fTarget.get()->peekTexture()); |
Robert Phillips | 3a9710b | 2018-03-27 17:51:55 -0400 | [diff] [blame] | 101 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 102 | GrGpuTextureCommandBuffer* commandBuffer( |
| 103 | flushState->gpu()->getCommandBuffer(fTarget.get()->peekTexture(), |
| 104 | fTarget.get()->origin())); |
| 105 | flushState->setCommandBuffer(commandBuffer); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 106 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 107 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Robert Phillips | 3a9710b | 2018-03-27 17:51:55 -0400 | [diff] [blame] | 108 | if (!fRecordedOps[i]) { |
| 109 | continue; |
| 110 | } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 111 | SkASSERT(fRecordedOps[i]->isChainHead()); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 112 | GrOpFlushState::OpArgs opArgs = { |
| 113 | fRecordedOps[i].get(), |
| 114 | nullptr, |
| 115 | nullptr, |
| 116 | GrXferProcessor::DstProxy() |
| 117 | }; |
| 118 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 119 | fRecordedOps[i]->execute(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 120 | flushState->setOpArgs(nullptr); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 121 | } |
| 122 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 123 | flushState->gpu()->submit(commandBuffer); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 124 | flushState->setCommandBuffer(nullptr); |
| 125 | |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 126 | return true; |
| 127 | } |
| 128 | |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 129 | void GrTextureOpList::endFlush() { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 130 | this->deleteOps(); |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 131 | INHERITED::endFlush(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | //////////////////////////////////////////////////////////////////////////////// |
| 135 | |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame] | 136 | // This closely parallels GrRenderTargetOpList::copySurface but renderTargetOpList |
| 137 | // stores extra data with the op |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 138 | bool GrTextureOpList::copySurface(GrContext* context, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 139 | GrSurfaceProxy* dst, |
| 140 | GrSurfaceProxy* src, |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 141 | const SkIRect& srcRect, |
| 142 | const SkIPoint& dstPoint) { |
Robert Phillips | a16f6cb | 2017-06-01 11:06:13 -0400 | [diff] [blame] | 143 | SkASSERT(dst == fTarget.get()); |
| 144 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 145 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(context, dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 146 | if (!op) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 147 | return false; |
| 148 | } |
Robert Phillips | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 149 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 150 | const GrCaps* caps = context->contextPriv().caps(); |
| 151 | auto addDependency = [ caps, this ] (GrSurfaceProxy* p) { |
| 152 | this->addDependency(p, *caps); |
Robert Phillips | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 153 | }; |
| 154 | op->visitProxies(addDependency); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 155 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 156 | this->recordOp(std::move(op)); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 157 | return true; |
| 158 | } |
| 159 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 160 | void GrTextureOpList::purgeOpsWithUninstantiatedProxies() { |
| 161 | bool hasUninstantiatedProxy = false; |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 162 | auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p) { |
| 163 | if (!p->isInstantiated()) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 164 | hasUninstantiatedProxy = true; |
| 165 | } |
| 166 | }; |
| 167 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 168 | const GrOp* op = fRecordedOps[i].get(); // only diff from the GrRenderTargetOpList version |
| 169 | hasUninstantiatedProxy = false; |
| 170 | if (op) { |
| 171 | op->visitProxies(checkInstantiation); |
| 172 | } |
| 173 | if (hasUninstantiatedProxy) { |
| 174 | // When instantiation of the proxy fails we drop the Op |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 175 | this->deleteOp(i); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 180 | void GrTextureOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 181 | unsigned int cur = alloc->numOps(); |
| 182 | |
| 183 | // Add the interval for all the writes to this opList's target |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 184 | if (fRecordedOps.count()) { |
| 185 | alloc->addInterval(fTarget.get(), cur, cur+fRecordedOps.count()-1); |
| 186 | } else { |
| 187 | // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we |
| 188 | // still need to add an interval for the destination so we create a fake op# for |
| 189 | // the missing clear op. |
| 190 | alloc->addInterval(fTarget.get()); |
| 191 | alloc->incOps(); |
| 192 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 193 | |
Chris Dalton | 8816b93 | 2017-11-29 16:48:25 -0700 | [diff] [blame] | 194 | auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p) { |
| 195 | alloc->addInterval(p SkDEBUGCODE(, p == fTarget.get())); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 196 | }; |
| 197 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 198 | const GrOp* op = fRecordedOps[i].get(); // only diff from the GrRenderTargetOpList version |
Robert Phillips | 8186cbe | 2017-11-01 17:32:39 -0400 | [diff] [blame] | 199 | if (op) { |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 200 | op->visitProxies(gather, GrOp::VisitorType::kAllocatorGather); |
Greg Daniel | 065b41d | 2017-11-08 19:58:51 +0000 | [diff] [blame] | 201 | } |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 202 | |
| 203 | // Even though the op may have been moved we still need to increment the op count to |
| 204 | // keep all the math consistent. |
| 205 | alloc->incOps(); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 209 | void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op) { |
| 210 | SkASSERT(fTarget.get()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 211 | // A closed GrOpList should never receive new/more ops |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 212 | SkASSERT(!this->isClosed()); |
| 213 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 214 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID()); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 215 | GrOP_INFO("Re-Recording (%s, opID: %u)\n" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 216 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 217 | op->name(), |
| 218 | op->uniqueID(), |
| 219 | op->bounds().fLeft, op->bounds().fRight, |
| 220 | op->bounds().fTop, op->bounds().fBottom); |
| 221 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 222 | GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 223 | |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 224 | fRecordedOps.emplace_back(std::move(op)); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 225 | } |