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 | 804f6a0 | 2019-08-26 12:07:30 -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 | |
| 17 | sk_sp<GrRenderTask> GrTextureResolveRenderTask::Make( |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 18 | sk_sp<GrTextureProxy> textureProxy, GrTextureResolveFlags flags, const GrCaps& caps) { |
| 19 | GrTextureProxy* textureProxyPtr = textureProxy.get(); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 20 | sk_sp<GrTextureResolveRenderTask> resolveTask( |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 21 | new GrTextureResolveRenderTask(std::move(textureProxy), flags)); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 22 | |
Chris Dalton | 804f6a0 | 2019-08-26 12:07:30 -0600 | [diff] [blame] | 23 | // Ensure the last render task that operated on the textureProxy is closed. That's where msaa |
| 24 | // and mipmaps should have been marked dirty. |
| 25 | SkASSERT(!textureProxyPtr->getLastRenderTask() || |
| 26 | textureProxyPtr->getLastRenderTask()->isClosed()); |
| 27 | |
| 28 | if (GrTextureResolveFlags::kMSAA & flags) { |
| 29 | GrRenderTargetProxy* renderTargetProxy = textureProxyPtr->asRenderTargetProxy(); |
| 30 | SkASSERT(renderTargetProxy); |
| 31 | SkASSERT(renderTargetProxy->isMSAADirty()); |
| 32 | renderTargetProxy->markMSAAResolved(); |
| 33 | } |
| 34 | |
| 35 | if (GrTextureResolveFlags::kMipMaps & flags) { |
| 36 | SkASSERT(GrMipMapped::kYes == textureProxyPtr->mipMapped()); |
| 37 | SkASSERT(textureProxyPtr->mipMapsAreDirty()); |
| 38 | textureProxyPtr->markMipMapsClean(); |
| 39 | } |
| 40 | |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 41 | // Add the target as a dependency: We will read the existing contents of this texture while |
| 42 | // generating mipmap levels and/or resolving MSAA. |
| 43 | // |
| 44 | // NOTE: This must be called before makeClosed. |
| 45 | resolveTask->addDependency( |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 46 | textureProxyPtr, GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps); |
| 47 | textureProxyPtr->setLastRenderTask(resolveTask.get()); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 48 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 49 | // We only resolve the texture; nobody should try to do anything else with this opsTask. |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 50 | resolveTask->makeClosed(caps); |
| 51 | |
Chris Dalton | 804f6a0 | 2019-08-26 12:07:30 -0600 | [diff] [blame] | 52 | return std::move(resolveTask); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 56 | // This renderTask doesn't have "normal" ops. In this case we still need to add an interval (so |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 57 | // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 58 | // we manipulate fTarget. |
| 59 | alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(), |
| 60 | GrResourceAllocator::ActualUse::kYes); |
| 61 | alloc->incOps(); |
| 62 | } |
| 63 | |
| 64 | bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) { |
Chris Dalton | 804f6a0 | 2019-08-26 12:07:30 -0600 | [diff] [blame] | 65 | // Resolve msaa before regenerating mipmaps. |
| 66 | if (GrTextureResolveFlags::kMSAA & fResolveFlags) { |
| 67 | GrRenderTarget* renderTarget = fTarget->peekRenderTarget(); |
| 68 | SkASSERT(renderTarget); |
| 69 | SkASSERT(renderTarget->needsResolve()); |
| 70 | flushState->gpu()->resolveRenderTarget(renderTarget); |
| 71 | } |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 72 | |
| 73 | if (GrTextureResolveFlags::kMipMaps & fResolveFlags) { |
Chris Dalton | 804f6a0 | 2019-08-26 12:07:30 -0600 | [diff] [blame] | 74 | GrTexture* texture = fTarget->peekTexture(); |
| 75 | SkASSERT(texture); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 76 | SkASSERT(texture->texturePriv().mipMapsAreDirty()); |
| 77 | flushState->gpu()->regenerateMipMapLevels(texture); |
| 78 | } |
| 79 | |
| 80 | return true; |
| 81 | } |