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