Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 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 "src/gpu/GrTextureResolveRenderTask.h" |
| 9 | |
| 10 | #include "src/gpu/GrGpu.h" |
| 11 | #include "src/gpu/GrMemoryPool.h" |
| 12 | #include "src/gpu/GrOpFlushState.h" |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 13 | #include "src/gpu/GrRenderTarget.h" |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 14 | #include "src/gpu/GrResourceAllocator.h" |
| 15 | #include "src/gpu/GrTexturePriv.h" |
| 16 | |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 17 | GrTextureResolveRenderTask::~GrTextureResolveRenderTask() { |
| 18 | for (const auto& resolve : fResolves) { |
| 19 | // Ensure the proxy doesn't keep hold of a dangling back pointer. |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 20 | resolve.fProxyView.proxy()->setLastRenderTask(nullptr); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 21 | } |
| 22 | } |
| 23 | |
| 24 | void GrTextureResolveRenderTask::addProxy( |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 25 | GrSurfaceProxyView proxyView, GrSurfaceProxy::ResolveFlags flags, const GrCaps& caps) { |
| 26 | fResolves.emplace_back(std::move(proxyView), flags); |
| 27 | GrSurfaceProxy* proxy = fResolves.back().fProxyView.proxy(); |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 28 | |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 29 | // Ensure the last render task that operated on the proxy is closed. That's where msaa and |
| 30 | // mipmaps should have been marked dirty. |
| 31 | SkASSERT(!proxy->getLastRenderTask() || proxy->getLastRenderTask()->isClosed()); |
| 32 | SkASSERT(GrSurfaceProxy::ResolveFlags::kNone != flags); |
| 33 | |
| 34 | if (GrSurfaceProxy::ResolveFlags::kMSAA & flags) { |
| 35 | GrRenderTargetProxy* renderTargetProxy = proxy->asRenderTargetProxy(); |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 36 | SkASSERT(renderTargetProxy); |
| 37 | SkASSERT(renderTargetProxy->isMSAADirty()); |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 38 | fResolves.back().fMSAAResolveRect = renderTargetProxy->msaaDirtyRect(); |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 39 | renderTargetProxy->markMSAAResolved(); |
| 40 | } |
| 41 | |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 42 | if (GrSurfaceProxy::ResolveFlags::kMipMaps & flags) { |
| 43 | GrTextureProxy* textureProxy = proxy->asTextureProxy(); |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 44 | SkASSERT(GrMipMapped::kYes == textureProxy->mipMapped()); |
| 45 | SkASSERT(textureProxy->mipMapsAreDirty()); |
| 46 | textureProxy->markMipMapsClean(); |
| 47 | } |
| 48 | |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 49 | // Add the proxy as a dependency: We will read the existing contents of this texture while |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 50 | // generating mipmap levels and/or resolving MSAA. |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 51 | this->addDependency(proxy, GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 52 | proxy->setLastRenderTask(this); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 56 | // This renderTask doesn't have "normal" ops, however we still need to add intervals so |
| 57 | // fEndOfOpsTaskOpIndices will remain in sync. We create fake op#'s to capture the fact that we |
| 58 | // manipulate the resolve proxies. |
| 59 | auto fakeOp = alloc->curOp(); |
| 60 | for (const auto& resolve : fResolves) { |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 61 | alloc->addInterval(resolve.fProxyView.proxy(), fakeOp, fakeOp, |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 62 | GrResourceAllocator::ActualUse::kYes); |
| 63 | } |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 64 | alloc->incOps(); |
| 65 | } |
| 66 | |
| 67 | bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) { |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 68 | // Resolve all msaa back-to-back, before regenerating mipmaps. |
| 69 | for (const auto& resolve : fResolves) { |
| 70 | if (GrSurfaceProxy::ResolveFlags::kMSAA & resolve.fFlags) { |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 71 | GrSurfaceProxy* proxy = resolve.fProxyView.proxy(); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 72 | // peekRenderTarget might be null if there was an instantiation error. |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 73 | if (GrRenderTarget* renderTarget = proxy->peekRenderTarget()) { |
Chris Dalton | 798a31d | 2019-09-26 19:28:32 +0000 | [diff] [blame] | 74 | flushState->gpu()->resolveRenderTarget(renderTarget, resolve.fMSAAResolveRect, |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 75 | resolve.fProxyView.origin(), |
Chris Dalton | 798a31d | 2019-09-26 19:28:32 +0000 | [diff] [blame] | 76 | GrGpu::ForExternalIO::kNo); |
Chris Dalton | 798a31d | 2019-09-26 19:28:32 +0000 | [diff] [blame] | 77 | } |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 78 | } |
| 79 | } |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 80 | // Regenerate all mipmaps back-to-back. |
| 81 | for (const auto& resolve : fResolves) { |
| 82 | if (GrSurfaceProxy::ResolveFlags::kMipMaps & resolve.fFlags) { |
| 83 | // peekTexture might be null if there was an instantiation error. |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 84 | GrTexture* texture = resolve.fProxyView.proxy()->peekTexture(); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 85 | if (texture && texture->texturePriv().mipMapsAreDirty()) { |
| 86 | flushState->gpu()->regenerateMipMapLevels(texture); |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 87 | SkASSERT(!texture->texturePriv().mipMapsAreDirty()); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 88 | } |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 89 | } |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | return true; |
| 93 | } |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 94 | |
| 95 | #ifdef SK_DEBUG |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 96 | void GrTextureResolveRenderTask::visitProxies_debugOnly(const GrOp::VisitProxyFunc& fn) const { |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 97 | for (const auto& resolve : fResolves) { |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 98 | fn(resolve.fProxyView.proxy(), GrMipMapped::kNo); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | #endif |