123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752 |
- /*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
- #include "include/private/GrRecordingContext.h"
- #include "src/core/SkExchange.h"
- #include "src/core/SkRectPriv.h"
- #include "src/core/SkTraceEvent.h"
- #include "src/gpu/GrAuditTrail.h"
- #include "src/gpu/GrCaps.h"
- #include "src/gpu/GrGpu.h"
- #include "src/gpu/GrGpuCommandBuffer.h"
- #include "src/gpu/GrMemoryPool.h"
- #include "src/gpu/GrRecordingContextPriv.h"
- #include "src/gpu/GrRenderTargetContext.h"
- #include "src/gpu/GrRenderTargetOpList.h"
- #include "src/gpu/GrResourceAllocator.h"
- #include "src/gpu/geometry/GrRect.h"
- #include "src/gpu/ops/GrClearOp.h"
- #include "src/gpu/ops/GrCopySurfaceOp.h"
- ////////////////////////////////////////////////////////////////////////////////
- // Experimentally we have found that most combining occurs within the first 10 comparisons.
- static const int kMaxOpMergeDistance = 10;
- static const int kMaxOpChainDistance = 10;
- ////////////////////////////////////////////////////////////////////////////////
- using DstProxy = GrXferProcessor::DstProxy;
- ////////////////////////////////////////////////////////////////////////////////
- static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
- ////////////////////////////////////////////////////////////////////////////////
- inline GrRenderTargetOpList::OpChain::List::List(std::unique_ptr<GrOp> op)
- : fHead(std::move(op)), fTail(fHead.get()) {
- this->validate();
- }
- inline GrRenderTargetOpList::OpChain::List::List(List&& that) { *this = std::move(that); }
- inline GrRenderTargetOpList::OpChain::List& GrRenderTargetOpList::OpChain::List::operator=(
- List&& that) {
- fHead = std::move(that.fHead);
- fTail = that.fTail;
- that.fTail = nullptr;
- this->validate();
- return *this;
- }
- inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::popHead() {
- SkASSERT(fHead);
- auto temp = fHead->cutChain();
- std::swap(temp, fHead);
- if (!fHead) {
- SkASSERT(fTail == temp.get());
- fTail = nullptr;
- }
- return temp;
- }
- inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::removeOp(GrOp* op) {
- #ifdef SK_DEBUG
- auto head = op;
- while (head->prevInChain()) { head = head->prevInChain(); }
- SkASSERT(head == fHead.get());
- #endif
- auto prev = op->prevInChain();
- if (!prev) {
- SkASSERT(op == fHead.get());
- return this->popHead();
- }
- auto temp = prev->cutChain();
- if (auto next = temp->cutChain()) {
- prev->chainConcat(std::move(next));
- } else {
- SkASSERT(fTail == op);
- fTail = prev;
- }
- this->validate();
- return temp;
- }
- inline void GrRenderTargetOpList::OpChain::List::pushHead(std::unique_ptr<GrOp> op) {
- SkASSERT(op);
- SkASSERT(op->isChainHead());
- SkASSERT(op->isChainTail());
- if (fHead) {
- op->chainConcat(std::move(fHead));
- fHead = std::move(op);
- } else {
- fHead = std::move(op);
- fTail = fHead.get();
- }
- }
- inline void GrRenderTargetOpList::OpChain::List::pushTail(std::unique_ptr<GrOp> op) {
- SkASSERT(op->isChainTail());
- fTail->chainConcat(std::move(op));
- fTail = fTail->nextInChain();
- }
- inline void GrRenderTargetOpList::OpChain::List::validate() const {
- #ifdef SK_DEBUG
- if (fHead) {
- SkASSERT(fTail);
- fHead->validateChain(fTail);
- }
- #endif
- }
- ////////////////////////////////////////////////////////////////////////////////
- GrRenderTargetOpList::OpChain::OpChain(std::unique_ptr<GrOp> op,
- GrProcessorSet::Analysis processorAnalysis,
- GrAppliedClip* appliedClip, const DstProxy* dstProxy)
- : fList{std::move(op)}
- , fProcessorAnalysis(processorAnalysis)
- , fAppliedClip(appliedClip) {
- if (fProcessorAnalysis.requiresDstTexture()) {
- SkASSERT(dstProxy && dstProxy->proxy());
- fDstProxy = *dstProxy;
- }
- fBounds = fList.head()->bounds();
- }
- void GrRenderTargetOpList::OpChain::visitProxies(const GrOp::VisitProxyFunc& func) const {
- if (fList.empty()) {
- return;
- }
- for (const auto& op : GrOp::ChainRange<>(fList.head())) {
- op.visitProxies(func);
- }
- if (fDstProxy.proxy()) {
- func(fDstProxy.proxy(), GrMipMapped::kNo);
- }
- if (fAppliedClip) {
- fAppliedClip->visitProxies(func);
- }
- }
- void GrRenderTargetOpList::OpChain::deleteOps(GrOpMemoryPool* pool) {
- while (!fList.empty()) {
- pool->release(fList.popHead());
- }
- }
- // Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
- // the two chains are chainable. Returns the new chain.
- GrRenderTargetOpList::OpChain::List GrRenderTargetOpList::OpChain::DoConcat(
- List chainA, List chainB, const GrCaps& caps, GrOpMemoryPool* pool,
- GrAuditTrail* auditTrail) {
- // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
- // at chain a's tail and working toward the head. We produce one of the following outcomes:
- // 1) b's head is merged into an op in a.
- // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
- // 3) b's head is popped from chain a and added at the tail of a.
- // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
- // as we assume merges were already attempted when chain b was created. So we keep track of the
- // original tail of a and start our iteration of a there. We also track the bounds of the nodes
- // appended to chain a that will be skipped for bounds testing. If the original tail of a is
- // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
- GrOp* origATail = chainA.tail();
- SkRect skipBounds = SkRectPriv::MakeLargestInverted();
- do {
- int numMergeChecks = 0;
- bool merged = false;
- bool noSkip = (origATail == chainA.tail());
- SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
- bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
- SkRect forwardMergeBounds = skipBounds;
- GrOp* a = origATail;
- while (a) {
- bool canForwardMerge =
- (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
- if (canForwardMerge || canBackwardMerge) {
- auto result = a->combineIfPossible(chainB.head(), caps);
- SkASSERT(result != GrOp::CombineResult::kCannotCombine);
- merged = (result == GrOp::CombineResult::kMerged);
- GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
- chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
- a->uniqueID());
- }
- if (merged) {
- GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
- if (canBackwardMerge) {
- pool->release(chainB.popHead());
- } else {
- // We merged the contents of b's head into a. We will replace b's head with a in
- // chain b.
- SkASSERT(canForwardMerge);
- if (a == origATail) {
- origATail = a->prevInChain();
- }
- std::unique_ptr<GrOp> detachedA = chainA.removeOp(a);
- pool->release(chainB.popHead());
- chainB.pushHead(std::move(detachedA));
- if (chainA.empty()) {
- // We merged all the nodes in chain a to chain b.
- return chainB;
- }
- }
- break;
- } else {
- if (++numMergeChecks == kMaxOpMergeDistance) {
- break;
- }
- forwardMergeBounds.joinNonEmptyArg(a->bounds());
- canBackwardMerge =
- canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
- a = a->prevInChain();
- }
- }
- // If we weren't able to merge b's head then pop b's head from chain b and make it the new
- // tail of a.
- if (!merged) {
- chainA.pushTail(chainB.popHead());
- skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
- }
- } while (!chainB.empty());
- return chainA;
- }
- // Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
- // whether the operation succeeded. On success, the provided list will be returned empty.
- bool GrRenderTargetOpList::OpChain::tryConcat(
- List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxy& dstProxy,
- const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
- GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
- SkASSERT(!fList.empty());
- SkASSERT(!list->empty());
- SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxy.proxy()));
- SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxy.proxy()));
- // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
- if (fList.head()->classID() != list->head()->classID() ||
- SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
- (fAppliedClip && *fAppliedClip != *appliedClip) ||
- (fProcessorAnalysis.requiresNonOverlappingDraws() !=
- processorAnalysis.requiresNonOverlappingDraws()) ||
- (fProcessorAnalysis.requiresNonOverlappingDraws() &&
- // Non-overlaping draws are only required when Ganesh will either insert a barrier,
- // or read back a new dst texture between draws. In either case, we can neither
- // chain nor combine overlapping Ops.
- GrRectsTouchOrOverlap(fBounds, bounds)) ||
- (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
- (fProcessorAnalysis.requiresDstTexture() && fDstProxy != dstProxy)) {
- return false;
- }
- SkDEBUGCODE(bool first = true;)
- do {
- switch (fList.tail()->combineIfPossible(list->head(), caps)) {
- case GrOp::CombineResult::kCannotCombine:
- // If an op supports chaining then it is required that chaining is transitive and
- // that if any two ops in two different chains can merge then the two chains
- // may also be chained together. Thus, we should only hit this on the first
- // iteration.
- SkASSERT(first);
- return false;
- case GrOp::CombineResult::kMayChain:
- fList = DoConcat(std::move(fList), skstd::exchange(*list, List()), caps, pool,
- auditTrail);
- // The above exchange cleared out 'list'. The list needs to be empty now for the
- // loop to terminate.
- SkASSERT(list->empty());
- break;
- case GrOp::CombineResult::kMerged: {
- GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
- list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
- list->head()->uniqueID());
- GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
- pool->release(list->popHead());
- break;
- }
- }
- SkDEBUGCODE(first = false);
- } while (!list->empty());
- // The new ops were successfully merged and/or chained onto our own.
- fBounds.joinPossiblyEmptyRect(bounds);
- return true;
- }
- bool GrRenderTargetOpList::OpChain::prependChain(OpChain* that, const GrCaps& caps,
- GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
- if (!that->tryConcat(
- &fList, fProcessorAnalysis, fDstProxy, fAppliedClip, fBounds, caps, pool, auditTrail)) {
- this->validate();
- // append failed
- return false;
- }
- // 'that' owns the combined chain. Move it into 'this'.
- SkASSERT(fList.empty());
- fList = std::move(that->fList);
- fBounds = that->fBounds;
- that->fDstProxy.setProxy(nullptr);
- if (that->fAppliedClip) {
- for (int i = 0; i < that->fAppliedClip->numClipCoverageFragmentProcessors(); ++i) {
- that->fAppliedClip->detachClipCoverageFragmentProcessor(i);
- }
- }
- this->validate();
- return true;
- }
- std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::appendOp(
- std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis,
- const DstProxy* dstProxy, const GrAppliedClip* appliedClip, const GrCaps& caps,
- GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
- const GrXferProcessor::DstProxy noDstProxy;
- if (!dstProxy) {
- dstProxy = &noDstProxy;
- }
- SkASSERT(op->isChainHead() && op->isChainTail());
- SkRect opBounds = op->bounds();
- List chain(std::move(op));
- if (!this->tryConcat(
- &chain, processorAnalysis, *dstProxy, appliedClip, opBounds, caps, pool, auditTrail)) {
- // append failed, give the op back to the caller.
- this->validate();
- return chain.popHead();
- }
- SkASSERT(chain.empty());
- this->validate();
- return nullptr;
- }
- inline void GrRenderTargetOpList::OpChain::validate() const {
- #ifdef SK_DEBUG
- fList.validate();
- for (const auto& op : GrOp::ChainRange<>(fList.head())) {
- // Not using SkRect::contains because we allow empty rects.
- SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
- fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
- }
- #endif
- }
- ////////////////////////////////////////////////////////////////////////////////
- GrRenderTargetOpList::GrRenderTargetOpList(sk_sp<GrOpMemoryPool> opMemoryPool,
- sk_sp<GrRenderTargetProxy> proxy,
- GrAuditTrail* auditTrail)
- : INHERITED(std::move(opMemoryPool), std::move(proxy), auditTrail)
- , fLastClipStackGenID(SK_InvalidUniqueID)
- SkDEBUGCODE(, fNumClips(0)) {
- }
- void GrRenderTargetOpList::deleteOps() {
- for (auto& chain : fOpChains) {
- chain.deleteOps(fOpMemoryPool.get());
- }
- fOpChains.reset();
- }
- GrRenderTargetOpList::~GrRenderTargetOpList() {
- this->deleteOps();
- }
- ////////////////////////////////////////////////////////////////////////////////
- #ifdef SK_DEBUG
- void GrRenderTargetOpList::dump(bool printDependencies) const {
- INHERITED::dump(printDependencies);
- SkDebugf("ops (%d):\n", fOpChains.count());
- for (int i = 0; i < fOpChains.count(); ++i) {
- SkDebugf("*******************************\n");
- if (!fOpChains[i].head()) {
- SkDebugf("%d: <combined forward or failed instantiation>\n", i);
- } else {
- SkDebugf("%d: %s\n", i, fOpChains[i].head()->name());
- SkRect bounds = fOpChains[i].bounds();
- SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
- bounds.fTop, bounds.fRight, bounds.fBottom);
- for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
- SkString info = SkTabString(op.dumpInfo(), 1);
- SkDebugf("%s\n", info.c_str());
- bounds = op.bounds();
- SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
- bounds.fTop, bounds.fRight, bounds.fBottom);
- }
- }
- }
- }
- void GrRenderTargetOpList::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const {
- for (const OpChain& chain : fOpChains) {
- chain.visitProxies(func);
- }
- }
- #endif
- void GrRenderTargetOpList::onPrepare(GrOpFlushState* flushState) {
- SkASSERT(fTarget->peekRenderTarget());
- SkASSERT(this->isClosed());
- #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
- TRACE_EVENT0("skia.gpu", TRACE_FUNC);
- #endif
- // Loop over the ops that haven't yet been prepared.
- for (const auto& chain : fOpChains) {
- if (chain.head()) {
- #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
- TRACE_EVENT0("skia.gpu", chain.head()->name());
- #endif
- GrOpFlushState::OpArgs opArgs = {
- chain.head(),
- fTarget->asRenderTargetProxy(),
- chain.appliedClip(),
- fTarget.get()->asRenderTargetProxy()->outputSwizzle(),
- chain.dstProxy()
- };
- flushState->setOpArgs(&opArgs);
- chain.head()->prepare(flushState);
- flushState->setOpArgs(nullptr);
- }
- }
- }
- static GrGpuRTCommandBuffer* create_command_buffer(GrGpu* gpu,
- GrRenderTarget* rt,
- GrSurfaceOrigin origin,
- const SkRect& bounds,
- GrLoadOp colorLoadOp,
- const SkPMColor4f& loadClearColor,
- GrLoadOp stencilLoadOp) {
- const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo {
- colorLoadOp,
- GrStoreOp::kStore,
- loadClearColor
- };
- // TODO:
- // We would like to (at this level) only ever clear & discard. We would need
- // to stop splitting up higher level opLists for copyOps to achieve that.
- // Note: we would still need SB loads and stores but they would happen at a
- // lower level (inside the VK command buffer).
- const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
- stencilLoadOp,
- GrStoreOp::kStore,
- };
- return gpu->getCommandBuffer(rt, origin, bounds, kColorLoadStoreInfo, stencilLoadAndStoreInfo);
- }
- // TODO: this is where GrOp::renderTarget is used (which is fine since it
- // is at flush time). However, we need to store the RenderTargetProxy in the
- // Ops and instantiate them here.
- bool GrRenderTargetOpList::onExecute(GrOpFlushState* flushState) {
- // TODO: Forcing the execution of the discard here isn't ideal since it will cause us to do a
- // discard and then store the data back in memory so that the load op on future draws doesn't
- // think the memory is unitialized. Ideally we would want a system where we are tracking whether
- // the proxy itself has valid data or not, and then use that as a signal on whether we should be
- // loading or discarding. In that world we wouldni;t need to worry about executing oplists with
- // no ops just to do a discard.
- if (fOpChains.empty() && GrLoadOp::kClear != fColorLoadOp &&
- GrLoadOp::kDiscard != fColorLoadOp) {
- return false;
- }
- SkASSERT(fTarget->peekRenderTarget());
- TRACE_EVENT0("skia.gpu", TRACE_FUNC);
- // TODO: at the very least, we want the stencil store op to always be discard (at this
- // level). In Vulkan, sub-command buffers would still need to load & store the stencil buffer.
- // Make sure load ops are not kClear if the GPU needs to use draws for clears
- SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
- !flushState->gpu()->caps()->performColorClearsAsDraws());
- SkASSERT(fStencilLoadOp != GrLoadOp::kClear ||
- !flushState->gpu()->caps()->performStencilClearsAsDraws());
- GrGpuRTCommandBuffer* commandBuffer = create_command_buffer(
- flushState->gpu(),
- fTarget->peekRenderTarget(),
- fTarget->origin(),
- fTarget->getBoundsRect(),
- fColorLoadOp,
- fLoadClearColor,
- fStencilLoadOp);
- flushState->setCommandBuffer(commandBuffer);
- commandBuffer->begin();
- // Draw all the generated geometry.
- for (const auto& chain : fOpChains) {
- if (!chain.head()) {
- continue;
- }
- #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
- TRACE_EVENT0("skia.gpu", chain.head()->name());
- #endif
- GrOpFlushState::OpArgs opArgs {
- chain.head(),
- fTarget->asRenderTargetProxy(),
- chain.appliedClip(),
- fTarget.get()->asRenderTargetProxy()->outputSwizzle(),
- chain.dstProxy()
- };
- flushState->setOpArgs(&opArgs);
- chain.head()->execute(flushState, chain.bounds());
- flushState->setOpArgs(nullptr);
- }
- commandBuffer->end();
- flushState->gpu()->submit(commandBuffer);
- flushState->setCommandBuffer(nullptr);
- return true;
- }
- void GrRenderTargetOpList::endFlush() {
- fLastClipStackGenID = SK_InvalidUniqueID;
- this->deleteOps();
- fClipAllocator.reset();
- INHERITED::endFlush();
- }
- void GrRenderTargetOpList::discard() {
- // Discard calls to in-progress opLists are ignored. Calls at the start update the
- // opLists' color & stencil load ops.
- if (this->isEmpty()) {
- fColorLoadOp = GrLoadOp::kDiscard;
- fStencilLoadOp = GrLoadOp::kDiscard;
- }
- }
- void GrRenderTargetOpList::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) {
- fColorLoadOp = op;
- fLoadClearColor = color;
- }
- bool GrRenderTargetOpList::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) {
- // Mark the color load op as discard (this may be followed by a clearColorOnLoad call to make
- // the load op kClear, or it may be followed by an explicit op). In the event of an absClear()
- // after a regular clear(), we could end up with a clear load op and a real clear op in the list
- // if the load op were not reset here.
- fColorLoadOp = GrLoadOp::kDiscard;
- // If we previously recorded a wait op, we cannot delete the wait op. Until we track the wait
- // ops separately from normal ops, we have to avoid clearing out any ops in this case as well.
- if (fHasWaitOp) {
- canDiscardPreviousOps = CanDiscardPreviousOps::kNo;
- }
- if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) {
- this->deleteOps();
- fDeferredProxies.reset();
- // If the opList is using a render target which wraps a vulkan command buffer, we can't do a
- // clear load since we cannot change the render pass that we are using. Thus we fall back to
- // making a clear op in this case.
- return !fTarget->asRenderTargetProxy()->wrapsVkSecondaryCB();
- }
- // Could not empty the list, so an op must be added to handle the clear
- return false;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // This closely parallels GrTextureOpList::copySurface but renderTargetOpLists
- // also store the applied clip and dest proxy with the op
- bool GrRenderTargetOpList::copySurface(GrRecordingContext* context,
- GrSurfaceProxy* dst,
- GrSurfaceProxy* src,
- const SkIRect& srcRect,
- const SkIPoint& dstPoint) {
- SkASSERT(dst->asRenderTargetProxy() == fTarget.get());
- std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(context, dst, src, srcRect, dstPoint);
- if (!op) {
- return false;
- }
- this->addOp(std::move(op), *context->priv().caps());
- return true;
- }
- void GrRenderTargetOpList::purgeOpsWithUninstantiatedProxies() {
- bool hasUninstantiatedProxy = false;
- auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p, GrMipMapped) {
- if (!p->isInstantiated()) {
- hasUninstantiatedProxy = true;
- }
- };
- for (OpChain& recordedOp : fOpChains) {
- hasUninstantiatedProxy = false;
- recordedOp.visitProxies(checkInstantiation);
- if (hasUninstantiatedProxy) {
- // When instantiation of the proxy fails we drop the Op
- recordedOp.deleteOps(fOpMemoryPool.get());
- }
- }
- }
- bool GrRenderTargetOpList::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
- bool used = false;
- auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p, GrMipMapped) {
- if (p == proxyToCheck) {
- used = true;
- }
- };
- for (const OpChain& recordedOp : fOpChains) {
- recordedOp.visitProxies(visit);
- }
- return used;
- }
- void GrRenderTargetOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const {
- for (int i = 0; i < fDeferredProxies.count(); ++i) {
- SkASSERT(!fDeferredProxies[i]->isInstantiated());
- // We give all the deferred proxies a write usage at the very start of flushing. This
- // locks them out of being reused for the entire flush until they are read - and then
- // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
- // with sub-flushes. The deferred proxies only need to be pinned from the start of
- // the sub-flush in which they appear.
- alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo);
- }
- // Add the interval for all the writes to this opList's target
- if (fOpChains.count()) {
- unsigned int cur = alloc->curOp();
- alloc->addInterval(fTarget.get(), cur, cur + fOpChains.count() - 1,
- GrResourceAllocator::ActualUse::kYes);
- } else {
- // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
- // still need to add an interval for the destination so we create a fake op# for
- // the missing clear op.
- alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
- GrResourceAllocator::ActualUse::kYes);
- alloc->incOps();
- }
- auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipMapped) {
- alloc->addInterval(p, alloc->curOp(), alloc->curOp(), GrResourceAllocator::ActualUse::kYes
- SkDEBUGCODE(, fTarget.get() == p));
- };
- for (const OpChain& recordedOp : fOpChains) {
- // only diff from the GrTextureOpList version
- recordedOp.visitProxies(gather);
- // Even though the op may have been (re)moved we still need to increment the op count to
- // keep all the math consistent.
- alloc->incOps();
- }
- }
- void GrRenderTargetOpList::recordOp(
- std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip,
- const DstProxy* dstProxy, const GrCaps& caps) {
- SkDEBUGCODE(op->validate();)
- SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxy && dstProxy->proxy()));
- SkASSERT(fTarget);
- // A closed GrOpList should never receive new/more ops
- SkASSERT(!this->isClosed());
- if (!op->bounds().isFinite()) {
- fOpMemoryPool->release(std::move(op));
- return;
- }
- // Check if there is an op we can combine with by linearly searching back until we either
- // 1) check every op
- // 2) intersect with something
- // 3) find a 'blocker'
- GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget->uniqueID());
- GrOP_INFO("opList: %d Recording (%s, opID: %u)\n"
- "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
- this->uniqueID(),
- op->name(),
- op->uniqueID(),
- op->bounds().fLeft, op->bounds().fTop,
- op->bounds().fRight, op->bounds().fBottom);
- GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
- GrOP_INFO("\tOutcome:\n");
- int maxCandidates = SkTMin(kMaxOpChainDistance, fOpChains.count());
- if (maxCandidates) {
- int i = 0;
- while (true) {
- OpChain& candidate = fOpChains.fromBack(i);
- op = candidate.appendOp(std::move(op), processorAnalysis, dstProxy, clip, caps,
- fOpMemoryPool.get(), fAuditTrail);
- if (!op) {
- return;
- }
- // Stop going backwards if we would cause a painter's order violation.
- if (!can_reorder(candidate.bounds(), op->bounds())) {
- GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
- candidate.head()->name(), candidate.head()->uniqueID());
- break;
- }
- if (++i == maxCandidates) {
- GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
- break;
- }
- }
- } else {
- GrOP_INFO("\t\tBackward: FirstOp\n");
- }
- if (clip) {
- clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip));
- SkDEBUGCODE(fNumClips++;)
- }
- fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxy);
- }
- void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) {
- SkASSERT(!this->isClosed());
- GrOP_INFO("opList: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
- for (int i = 0; i < fOpChains.count() - 1; ++i) {
- OpChain& chain = fOpChains[i];
- int maxCandidateIdx = SkTMin(i + kMaxOpChainDistance, fOpChains.count() - 1);
- int j = i + 1;
- while (true) {
- OpChain& candidate = fOpChains[j];
- if (candidate.prependChain(&chain, caps, fOpMemoryPool.get(), fAuditTrail)) {
- break;
- }
- // Stop traversing if we would cause a painter's order violation.
- if (!can_reorder(chain.bounds(), candidate.bounds())) {
- GrOP_INFO(
- "\t\t%d: chain (%s head opID: %u) -> "
- "Intersects with chain (%s, head opID: %u)\n",
- i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
- candidate.head()->uniqueID());
- break;
- }
- if (++j > maxCandidateIdx) {
- GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
- i, chain.head()->name(), chain.head()->uniqueID());
- break;
- }
- }
- }
- }
|