reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrGpu.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrBackendSemaphore.h" |
| 12 | #include "include/gpu/GrBackendSurface.h" |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 13 | #include "include/gpu/GrDirectContext.h" |
Robert Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 14 | #include "src/core/SkCompressedDataUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/core/SkMathPriv.h" |
Mike Reed | 13711eb | 2020-07-14 17:16:32 -0400 | [diff] [blame] | 16 | #include "src/core/SkMipmap.h" |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrAttachment.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrAuditTrail.h" |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrBackendUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrCaps.h" |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrDataUtils.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrGpuResourcePriv.h" |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 24 | #include "src/gpu/GrNativeRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrPathRendering.h" |
| 26 | #include "src/gpu/GrPipeline.h" |
Brian Salomon | f7f5433 | 2020-07-28 09:23:35 -0400 | [diff] [blame] | 27 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "src/gpu/GrResourceCache.h" |
| 29 | #include "src/gpu/GrResourceProvider.h" |
Jim Van Verth | 7e829b2 | 2020-07-30 17:04:35 -0400 | [diff] [blame] | 30 | #include "src/gpu/GrRingBuffer.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 31 | #include "src/gpu/GrSemaphore.h" |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 32 | #include "src/gpu/GrStagingBufferManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 33 | #include "src/gpu/GrStencilSettings.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 34 | #include "src/gpu/GrTextureProxyPriv.h" |
| 35 | #include "src/gpu/GrTracing.h" |
| 36 | #include "src/utils/SkJSONWriter.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 37 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 38 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 40 | GrGpu::GrGpu(GrDirectContext* direct) : fResetBits(kAll_GrBackendState), fContext(direct) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | |
Stephen White | f3d5d44 | 2020-04-08 10:35:58 -0400 | [diff] [blame] | 42 | GrGpu::~GrGpu() { |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 43 | this->callSubmittedProcs(false); |
Stephen White | f3d5d44 | 2020-04-08 10:35:58 -0400 | [diff] [blame] | 44 | } |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 45 | |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 46 | void GrGpu::disconnect(DisconnectType type) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 48 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 50 | static bool validate_texel_levels(SkISize dimensions, GrColorType texelColorType, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 51 | const GrMipLevel* texels, int mipLevelCount, const GrCaps* caps) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 52 | SkASSERT(mipLevelCount > 0); |
| 53 | bool hasBasePixels = texels[0].fPixels; |
| 54 | int levelsWithPixelsCnt = 0; |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 55 | auto bpp = GrColorTypeBytesPerPixel(texelColorType); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 56 | int w = dimensions.fWidth; |
| 57 | int h = dimensions.fHeight; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 58 | for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; ++currentMipLevel) { |
| 59 | if (texels[currentMipLevel].fPixels) { |
| 60 | const size_t minRowBytes = w * bpp; |
| 61 | if (caps->writePixelsRowBytesSupport()) { |
| 62 | if (texels[currentMipLevel].fRowBytes < minRowBytes) { |
| 63 | return false; |
| 64 | } |
| 65 | if (texels[currentMipLevel].fRowBytes % bpp) { |
| 66 | return false; |
| 67 | } |
| 68 | } else { |
| 69 | if (texels[currentMipLevel].fRowBytes != minRowBytes) { |
| 70 | return false; |
| 71 | } |
| 72 | } |
| 73 | ++levelsWithPixelsCnt; |
| 74 | } |
| 75 | if (w == 1 && h == 1) { |
| 76 | if (currentMipLevel != mipLevelCount - 1) { |
| 77 | return false; |
| 78 | } |
| 79 | } else { |
| 80 | w = std::max(w / 2, 1); |
| 81 | h = std::max(h / 2, 1); |
| 82 | } |
| 83 | } |
| 84 | // Either just a base layer or a full stack is required. |
| 85 | if (mipLevelCount != 1 && (w != 1 || h != 1)) { |
| 86 | return false; |
| 87 | } |
| 88 | // Can specify just the base, all levels, or no levels. |
| 89 | if (!hasBasePixels) { |
| 90 | return levelsWithPixelsCnt == 0; |
| 91 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 92 | return levelsWithPixelsCnt == 1 || levelsWithPixelsCnt == mipLevelCount; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 95 | sk_sp<GrTexture> GrGpu::createTextureCommon(SkISize dimensions, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 96 | const GrBackendFormat& format, |
| 97 | GrRenderable renderable, |
| 98 | int renderTargetSampleCnt, |
| 99 | SkBudgeted budgeted, |
| 100 | GrProtected isProtected, |
| 101 | int mipLevelCount, |
| 102 | uint32_t levelClearMask) { |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 103 | if (this->caps()->isFormatCompressed(format)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 104 | // Call GrGpu::createCompressedTexture. |
| 105 | return nullptr; |
| 106 | } |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 107 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 108 | GrMipmapped mipMapped = mipLevelCount > 1 ? GrMipmapped::kYes : GrMipmapped::kNo; |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 109 | if (!this->caps()->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, |
| 110 | mipMapped)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 111 | return nullptr; |
egdaniel | 8c9b6f1 | 2015-05-12 13:36:30 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 114 | if (renderable == GrRenderable::kYes) { |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 115 | renderTargetSampleCnt = |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 116 | this->caps()->getRenderTargetSampleCount(renderTargetSampleCnt, format); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 117 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 118 | // Attempt to catch un- or wrongly initialized sample counts. |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 119 | SkASSERT(renderTargetSampleCnt > 0 && renderTargetSampleCnt <= 64); |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 120 | this->handleDirtyContext(); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 121 | auto tex = this->onCreateTexture(dimensions, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 122 | format, |
| 123 | renderable, |
| 124 | renderTargetSampleCnt, |
| 125 | budgeted, |
| 126 | isProtected, |
| 127 | mipLevelCount, |
| 128 | levelClearMask); |
| 129 | if (tex) { |
| 130 | SkASSERT(tex->backendFormat() == format); |
| 131 | SkASSERT(GrRenderable::kNo == renderable || tex->asRenderTarget()); |
| 132 | if (!this->caps()->reuseScratchTextures() && renderable == GrRenderable::kNo) { |
| 133 | tex->resourcePriv().removeScratchKey(); |
| 134 | } |
| 135 | fStats.incTextureCreates(); |
| 136 | if (renderTargetSampleCnt > 1 && !this->caps()->msaaResolvesAutomatically()) { |
| 137 | SkASSERT(GrRenderable::kYes == renderable); |
| 138 | tex->asRenderTarget()->setRequiresManualMSAAResolve(); |
| 139 | } |
| 140 | } |
| 141 | return tex; |
| 142 | } |
| 143 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 144 | sk_sp<GrTexture> GrGpu::createTexture(SkISize dimensions, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 145 | const GrBackendFormat& format, |
| 146 | GrRenderable renderable, |
| 147 | int renderTargetSampleCnt, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 148 | GrMipmapped mipMapped, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 149 | SkBudgeted budgeted, |
| 150 | GrProtected isProtected) { |
| 151 | int mipLevelCount = 1; |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 152 | if (mipMapped == GrMipmapped::kYes) { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 153 | mipLevelCount = |
| 154 | 32 - SkCLZ(static_cast<uint32_t>(std::max(dimensions.fWidth, dimensions.fHeight))); |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 155 | } |
| 156 | uint32_t levelClearMask = |
| 157 | this->caps()->shouldInitializeTextures() ? (1 << mipLevelCount) - 1 : 0; |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 158 | auto tex = this->createTextureCommon(dimensions, format, renderable, renderTargetSampleCnt, |
| 159 | budgeted, isProtected, mipLevelCount, levelClearMask); |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 160 | if (tex && mipMapped == GrMipmapped::kYes && levelClearMask) { |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 161 | tex->markMipmapsClean(); |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 162 | } |
| 163 | return tex; |
| 164 | } |
| 165 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 166 | sk_sp<GrTexture> GrGpu::createTexture(SkISize dimensions, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 167 | const GrBackendFormat& format, |
| 168 | GrRenderable renderable, |
| 169 | int renderTargetSampleCnt, |
| 170 | SkBudgeted budgeted, |
| 171 | GrProtected isProtected, |
| 172 | GrColorType textureColorType, |
| 173 | GrColorType srcColorType, |
| 174 | const GrMipLevel texels[], |
| 175 | int texelLevelCount) { |
| 176 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 177 | if (texelLevelCount) { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 178 | if (!validate_texel_levels(dimensions, srcColorType, texels, texelLevelCount, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 179 | this->caps())) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 180 | return nullptr; |
| 181 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 182 | } |
| 183 | |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 184 | int mipLevelCount = std::max(1, texelLevelCount); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 185 | uint32_t levelClearMask = 0; |
| 186 | if (this->caps()->shouldInitializeTextures()) { |
| 187 | if (texelLevelCount) { |
| 188 | for (int i = 0; i < mipLevelCount; ++i) { |
| 189 | if (!texels->fPixels) { |
| 190 | levelClearMask |= static_cast<uint32_t>(1 << i); |
| 191 | } |
| 192 | } |
| 193 | } else { |
| 194 | levelClearMask = static_cast<uint32_t>((1 << mipLevelCount) - 1); |
| 195 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 198 | auto tex = this->createTextureCommon(dimensions, format, renderable, renderTargetSampleCnt, |
| 199 | budgeted, isProtected, texelLevelCount, levelClearMask); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 200 | if (tex) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 201 | bool markMipLevelsClean = false; |
| 202 | // Currently if level 0 does not have pixels then no other level may, as enforced by |
| 203 | // validate_texel_levels. |
| 204 | if (texelLevelCount && texels[0].fPixels) { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 205 | if (!this->writePixels(tex.get(), 0, 0, dimensions.fWidth, dimensions.fHeight, |
| 206 | textureColorType, srcColorType, texels, texelLevelCount)) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 207 | return nullptr; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 208 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 209 | // Currently if level[1] of mip map has pixel data then so must all other levels. |
| 210 | // as enforced by validate_texel_levels. |
| 211 | markMipLevelsClean = (texelLevelCount > 1 && !levelClearMask && texels[1].fPixels); |
| 212 | fStats.incTextureUploads(); |
| 213 | } else if (levelClearMask && mipLevelCount > 1) { |
| 214 | markMipLevelsClean = true; |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 215 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 216 | if (markMipLevelsClean) { |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 217 | tex->markMipmapsClean(); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 218 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 219 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 220 | return tex; |
| 221 | } |
| 222 | |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 223 | sk_sp<GrTexture> GrGpu::createCompressedTexture(SkISize dimensions, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 224 | const GrBackendFormat& format, |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 225 | SkBudgeted budgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 226 | GrMipmapped mipMapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 227 | GrProtected isProtected, |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 228 | const void* data, |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 229 | size_t dataSize) { |
| 230 | this->handleDirtyContext(); |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 231 | if (dimensions.width() < 1 || dimensions.width() > this->caps()->maxTextureSize() || |
| 232 | dimensions.height() < 1 || dimensions.height() > this->caps()->maxTextureSize()) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 233 | return nullptr; |
| 234 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 235 | // Note if we relax the requirement that data must be provided then we must check |
| 236 | // caps()->shouldInitializeTextures() here. |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 237 | if (!data) { |
| 238 | return nullptr; |
| 239 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 240 | if (!this->caps()->isFormatTexturable(format)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 241 | return nullptr; |
| 242 | } |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 243 | |
| 244 | // TODO: expand CompressedDataIsCorrect to work here too |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 245 | SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format); |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 246 | |
Robert Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 247 | if (dataSize < SkCompressedDataSize(compressionType, dimensions, nullptr, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 248 | mipMapped == GrMipmapped::kYes)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 249 | return nullptr; |
| 250 | } |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 251 | return this->onCreateCompressedTexture(dimensions, format, budgeted, mipMapped, isProtected, |
| 252 | data, dataSize); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 253 | } |
| 254 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 255 | sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 256 | GrWrapOwnership ownership, |
| 257 | GrWrapCacheable cacheable, |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 258 | GrIOType ioType) { |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 259 | SkASSERT(ioType != kWrite_GrIOType); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 260 | this->handleDirtyContext(); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 261 | |
| 262 | const GrCaps* caps = this->caps(); |
| 263 | SkASSERT(caps); |
| 264 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 265 | if (!caps->isFormatTexturable(backendTex.getBackendFormat())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 266 | return nullptr; |
| 267 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 268 | if (backendTex.width() > caps->maxTextureSize() || |
| 269 | backendTex.height() > caps->maxTextureSize()) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 270 | return nullptr; |
| 271 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 272 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 273 | return this->onWrapBackendTexture(backendTex, ownership, cacheable, ioType); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 274 | } |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 275 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 276 | sk_sp<GrTexture> GrGpu::wrapCompressedBackendTexture(const GrBackendTexture& backendTex, |
| 277 | GrWrapOwnership ownership, |
| 278 | GrWrapCacheable cacheable) { |
| 279 | this->handleDirtyContext(); |
| 280 | |
| 281 | const GrCaps* caps = this->caps(); |
| 282 | SkASSERT(caps); |
| 283 | |
| 284 | if (!caps->isFormatTexturable(backendTex.getBackendFormat())) { |
| 285 | return nullptr; |
| 286 | } |
| 287 | if (backendTex.width() > caps->maxTextureSize() || |
| 288 | backendTex.height() > caps->maxTextureSize()) { |
| 289 | return nullptr; |
| 290 | } |
| 291 | |
| 292 | return this->onWrapCompressedBackendTexture(backendTex, ownership, cacheable); |
| 293 | } |
| 294 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 295 | sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex, |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 296 | int sampleCnt, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 297 | GrWrapOwnership ownership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 298 | GrWrapCacheable cacheable) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 299 | this->handleDirtyContext(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 300 | if (sampleCnt < 1) { |
| 301 | return nullptr; |
| 302 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 303 | |
| 304 | const GrCaps* caps = this->caps(); |
| 305 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 306 | if (!caps->isFormatTexturable(backendTex.getBackendFormat()) || |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 307 | !caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 308 | return nullptr; |
| 309 | } |
| 310 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 311 | if (backendTex.width() > caps->maxRenderTargetSize() || |
| 312 | backendTex.height() > caps->maxRenderTargetSize()) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 313 | return nullptr; |
| 314 | } |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 315 | sk_sp<GrTexture> tex = |
| 316 | this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership, cacheable); |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 317 | SkASSERT(!tex || tex->asRenderTarget()); |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 318 | if (tex && sampleCnt > 1 && !caps->msaaResolvesAutomatically()) { |
| 319 | tex->asRenderTarget()->setRequiresManualMSAAResolve(); |
| 320 | } |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 321 | return tex; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 324 | sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) { |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 325 | this->handleDirtyContext(); |
| 326 | |
| 327 | const GrCaps* caps = this->caps(); |
| 328 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 329 | if (!caps->isFormatRenderable(backendRT.getBackendFormat(), backendRT.sampleCnt())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 330 | return nullptr; |
| 331 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 332 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 333 | sk_sp<GrRenderTarget> rt = this->onWrapBackendRenderTarget(backendRT); |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 334 | if (backendRT.isFramebufferOnly()) { |
| 335 | rt->setFramebufferOnly(); |
| 336 | } |
| 337 | return rt; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 340 | sk_sp<GrRenderTarget> GrGpu::wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo, |
| 341 | const GrVkDrawableInfo& vkInfo) { |
| 342 | return this->onWrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo); |
| 343 | } |
| 344 | |
| 345 | sk_sp<GrRenderTarget> GrGpu::onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo, |
| 346 | const GrVkDrawableInfo& vkInfo) { |
| 347 | // This is only supported on Vulkan so we default to returning nullptr here |
| 348 | return nullptr; |
| 349 | } |
| 350 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 351 | sk_sp<GrGpuBuffer> GrGpu::createBuffer(size_t size, GrGpuBufferType intendedType, |
| 352 | GrAccessPattern accessPattern, const void* data) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 353 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 354 | this->handleDirtyContext(); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 355 | sk_sp<GrGpuBuffer> buffer = this->onCreateBuffer(size, intendedType, accessPattern, data); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 356 | if (!this->caps()->reuseScratchBuffers()) { |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 357 | buffer->resourcePriv().removeScratchKey(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 358 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 359 | return buffer; |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 362 | bool GrGpu::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 363 | const SkIPoint& dstPoint) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 364 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 365 | SkASSERT(dst && src); |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 366 | SkASSERT(!src->framebufferOnly()); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 367 | |
| 368 | if (dst->readOnly()) { |
| 369 | return false; |
| 370 | } |
| 371 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 372 | this->handleDirtyContext(); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 373 | |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 374 | return this->onCopySurface(dst, src, srcRect, dstPoint); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Brian Salomon | a694870 | 2018-06-01 15:33:20 -0400 | [diff] [blame] | 377 | bool GrGpu::readPixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 378 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
| 379 | size_t rowBytes) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 380 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 381 | SkASSERT(surface); |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 382 | SkASSERT(!surface->framebufferOnly()); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 383 | SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 384 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 385 | auto subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 386 | auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 387 | if (!bounds.contains(subRect)) { |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 388 | return false; |
| 389 | } |
| 390 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 391 | size_t minRowBytes = SkToSizeT(GrColorTypeBytesPerPixel(dstColorType) * width); |
| 392 | if (!this->caps()->readPixelsRowBytesSupport()) { |
| 393 | if (rowBytes != minRowBytes) { |
| 394 | return false; |
| 395 | } |
| 396 | } else { |
| 397 | if (rowBytes < minRowBytes) { |
| 398 | return false; |
| 399 | } |
| 400 | if (rowBytes % GrColorTypeBytesPerPixel(dstColorType)) { |
| 401 | return false; |
| 402 | } |
| 403 | } |
| 404 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 405 | this->handleDirtyContext(); |
| 406 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 407 | return this->onReadPixels(surface, left, top, width, height, surfaceColorType, dstColorType, |
| 408 | buffer, rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 411 | bool GrGpu::writePixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 412 | GrColorType surfaceColorType, GrColorType srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 413 | const GrMipLevel texels[], int mipLevelCount, bool prepForTexSampling) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 414 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Leon Scroggins III | 569f07c | 2020-07-24 16:10:58 -0400 | [diff] [blame] | 415 | ATRACE_ANDROID_FRAMEWORK_ALWAYS("Upload %ix%i Texture", width, height); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 416 | SkASSERT(surface); |
Stephen White | 3c0a50f | 2020-01-16 18:19:54 -0500 | [diff] [blame] | 417 | SkASSERT(!surface->framebufferOnly()); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 418 | |
| 419 | if (surface->readOnly()) { |
| 420 | return false; |
| 421 | } |
| 422 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 423 | if (mipLevelCount == 0) { |
| 424 | return false; |
| 425 | } else if (mipLevelCount == 1) { |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 426 | // We require that if we are not mipped, then the write region is contained in the surface |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 427 | auto subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 428 | auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 429 | if (!bounds.contains(subRect)) { |
| 430 | return false; |
| 431 | } |
| 432 | } else if (0 != left || 0 != top || width != surface->width() || height != surface->height()) { |
| 433 | // We require that if the texels are mipped, than the write region is the entire surface |
| 434 | return false; |
| 435 | } |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 436 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 437 | if (!validate_texel_levels({width, height}, srcColorType, texels, mipLevelCount, |
| 438 | this->caps())) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 439 | return false; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 440 | } |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 441 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 442 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 443 | if (this->onWritePixels(surface, left, top, width, height, surfaceColorType, srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 444 | texels, mipLevelCount, prepForTexSampling)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 445 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 446 | this->didWriteToSurface(surface, kTopLeft_GrSurfaceOrigin, &rect, mipLevelCount); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 447 | fStats.incTextureUploads(); |
| 448 | return true; |
| 449 | } |
| 450 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 453 | bool GrGpu::transferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 454 | GrColorType textureColorType, GrColorType bufferColorType, |
| 455 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 456 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 457 | SkASSERT(texture); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 458 | SkASSERT(transferBuffer); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 459 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 460 | if (texture->readOnly()) { |
| 461 | return false; |
| 462 | } |
| 463 | |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 464 | // We require that the write region is contained in the texture |
| 465 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 466 | SkIRect bounds = SkIRect::MakeWH(texture->width(), texture->height()); |
| 467 | if (!bounds.contains(subRect)) { |
| 468 | return false; |
| 469 | } |
| 470 | |
Brian Salomon | b28cb68 | 2019-07-26 12:48:47 -0400 | [diff] [blame] | 471 | size_t bpp = GrColorTypeBytesPerPixel(bufferColorType); |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 472 | if (this->caps()->writePixelsRowBytesSupport()) { |
| 473 | if (rowBytes < SkToSizeT(bpp * width)) { |
| 474 | return false; |
| 475 | } |
| 476 | if (rowBytes % bpp) { |
| 477 | return false; |
| 478 | } |
| 479 | } else { |
| 480 | if (rowBytes != SkToSizeT(bpp * width)) { |
| 481 | return false; |
| 482 | } |
| 483 | } |
| 484 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 485 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 486 | if (this->onTransferPixelsTo(texture, left, top, width, height, textureColorType, |
| 487 | bufferColorType, transferBuffer, offset, rowBytes)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 488 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 489 | this->didWriteToSurface(texture, kTopLeft_GrSurfaceOrigin, &rect); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 490 | fStats.incTransfersToTexture(); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 491 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 492 | return true; |
| 493 | } |
| 494 | return false; |
| 495 | } |
| 496 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 497 | bool GrGpu::transferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 498 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 499 | GrGpuBuffer* transferBuffer, size_t offset) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 500 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 501 | SkASSERT(surface); |
| 502 | SkASSERT(transferBuffer); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 503 | SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 504 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 505 | #ifdef SK_DEBUG |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 506 | auto supportedRead = this->caps()->supportedReadPixelsColorType( |
| 507 | surfaceColorType, surface->backendFormat(), bufferColorType); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 508 | SkASSERT(supportedRead.fOffsetAlignmentForTransferBuffer); |
| 509 | SkASSERT(offset % supportedRead.fOffsetAlignmentForTransferBuffer == 0); |
| 510 | #endif |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 511 | |
| 512 | // We require that the write region is contained in the texture |
| 513 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 514 | SkIRect bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 515 | if (!bounds.contains(subRect)) { |
| 516 | return false; |
| 517 | } |
| 518 | |
| 519 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 520 | if (this->onTransferPixelsFrom(surface, left, top, width, height, surfaceColorType, |
| 521 | bufferColorType, transferBuffer, offset)) { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 522 | fStats.incTransfersFromSurface(); |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 523 | return true; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 524 | } |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 525 | return false; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 526 | } |
| 527 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 528 | bool GrGpu::regenerateMipMapLevels(GrTexture* texture) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 529 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 530 | SkASSERT(texture); |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 531 | SkASSERT(this->caps()->mipmapSupport()); |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 532 | SkASSERT(texture->mipmapped() == GrMipmapped::kYes); |
| 533 | if (!texture->mipmapsAreDirty()) { |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 534 | // This can happen when the proxy expects mipmaps to be dirty, but they are not dirty on the |
| 535 | // actual target. This may be caused by things that the drawingManager could not predict, |
| 536 | // i.e., ops that don't draw anything, aborting a draw for exceptional circumstances, etc. |
| 537 | // NOTE: This goes away once we quit tracking mipmap state on the actual texture. |
| 538 | return true; |
| 539 | } |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 540 | if (texture->readOnly()) { |
| 541 | return false; |
| 542 | } |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 543 | if (this->onRegenerateMipMapLevels(texture)) { |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 544 | texture->markMipmapsClean(); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 545 | return true; |
| 546 | } |
| 547 | return false; |
| 548 | } |
| 549 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 550 | void GrGpu::resetTextureBindings() { |
| 551 | this->handleDirtyContext(); |
| 552 | this->onResetTextureBindings(); |
| 553 | } |
| 554 | |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 555 | void GrGpu::resolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 556 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 557 | this->handleDirtyContext(); |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 558 | this->onResolveRenderTarget(target, resolveRect); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 561 | void GrGpu::didWriteToSurface(GrSurface* surface, GrSurfaceOrigin origin, const SkIRect* bounds, |
| 562 | uint32_t mipLevels) const { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 563 | SkASSERT(surface); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 564 | SkASSERT(!surface->readOnly()); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 565 | // Mark any MIP chain and resolve buffer as dirty if and only if there is a non-empty bounds. |
| 566 | if (nullptr == bounds || !bounds->isEmpty()) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 567 | GrTexture* texture = surface->asTexture(); |
| 568 | if (texture && 1 == mipLevels) { |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 569 | texture->markMipmapsDirty(); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 574 | int GrGpu::findOrAssignSamplePatternKey(GrRenderTarget* renderTarget) { |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 575 | SkASSERT(this->caps()->sampleLocationsSupport()); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 576 | SkASSERT(renderTarget->numSamples() > 1 || |
Brian Salomon | f7f5433 | 2020-07-28 09:23:35 -0400 | [diff] [blame] | 577 | (renderTarget->getStencilAttachment() && |
| 578 | renderTarget->getStencilAttachment()->numSamples() > 1)); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 579 | |
| 580 | SkSTArray<16, SkPoint> sampleLocations; |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 581 | this->querySampleLocations(renderTarget, &sampleLocations); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 582 | return fSamplePatternDictionary.findOrAssignSamplePatternKey(sampleLocations); |
| 583 | } |
| 584 | |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 585 | void GrGpu::executeFlushInfo(SkSpan<GrSurfaceProxy*> proxies, |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 586 | SkSurface::BackendSurfaceAccess access, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 587 | const GrFlushInfo& info, |
| 588 | const GrBackendSurfaceMutableState* newState) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 589 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 590 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 591 | GrResourceProvider* resourceProvider = fContext->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 592 | |
Greg Daniel | 8561fc2 | 2020-04-08 12:52:51 -0400 | [diff] [blame] | 593 | std::unique_ptr<std::unique_ptr<GrSemaphore>[]> semaphores( |
| 594 | new std::unique_ptr<GrSemaphore>[info.fNumSemaphores]); |
Greg Daniel | 30a35e8 | 2019-11-19 14:12:25 -0500 | [diff] [blame] | 595 | if (this->caps()->semaphoreSupport() && info.fNumSemaphores) { |
Greg Daniel | 8561fc2 | 2020-04-08 12:52:51 -0400 | [diff] [blame] | 596 | for (int i = 0; i < info.fNumSemaphores; ++i) { |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 597 | if (info.fSignalSemaphores[i].isInitialized()) { |
Greg Daniel | 8561fc2 | 2020-04-08 12:52:51 -0400 | [diff] [blame] | 598 | semaphores[i] = resourceProvider->wrapBackendSemaphore( |
| 599 | info.fSignalSemaphores[i], |
| 600 | GrResourceProvider::SemaphoreWrapType::kWillSignal, |
| 601 | kBorrow_GrWrapOwnership); |
Greg Daniel | 0106fcc | 2020-07-01 17:40:12 -0400 | [diff] [blame] | 602 | // If we failed to wrap the semaphore it means the client didn't give us a valid |
| 603 | // semaphore to begin with. Therefore, it is fine to not signal it. |
| 604 | if (semaphores[i]) { |
| 605 | this->insertSemaphore(semaphores[i].get()); |
| 606 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 607 | } else { |
Greg Daniel | 8561fc2 | 2020-04-08 12:52:51 -0400 | [diff] [blame] | 608 | semaphores[i] = resourceProvider->makeSemaphore(false); |
| 609 | if (semaphores[i]) { |
| 610 | this->insertSemaphore(semaphores[i].get()); |
| 611 | info.fSignalSemaphores[i] = semaphores[i]->backendSemaphore(); |
| 612 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | } |
Greg Daniel | 30a35e8 | 2019-11-19 14:12:25 -0500 | [diff] [blame] | 616 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 617 | if (info.fFinishedProc) { |
| 618 | this->addFinishedProc(info.fFinishedProc, info.fFinishedContext); |
| 619 | } |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 620 | |
| 621 | if (info.fSubmittedProc) { |
| 622 | fSubmittedProcs.emplace_back(info.fSubmittedProc, info.fSubmittedContext); |
| 623 | } |
| 624 | |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 625 | // We currently don't support passing in new surface state for multiple proxies here. The only |
| 626 | // time we have multiple proxies is if we are flushing a yuv SkImage which won't have state |
| 627 | // updates anyways. |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 628 | SkASSERT(!newState || proxies.count() == 1); |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 629 | SkASSERT(!newState || access == SkSurface::BackendSurfaceAccess::kNoAccess); |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 630 | this->prepareSurfacesForBackendAccessAndStateUpdates(proxies, access, newState); |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 633 | GrOpsRenderPass* GrGpu::getOpsRenderPass( |
| 634 | GrRenderTarget* renderTarget, |
| 635 | GrAttachment* stencil, |
| 636 | GrSurfaceOrigin origin, |
| 637 | const SkIRect& bounds, |
| 638 | const GrOpsRenderPass::LoadAndStoreInfo& colorInfo, |
| 639 | const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo, |
| 640 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 641 | GrXferBarrierFlags renderPassXferBarriers) { |
| 642 | #if SK_HISTOGRAMS_ENABLED |
| 643 | fCurrentSubmitRenderPassCount++; |
| 644 | #endif |
| 645 | return this->onGetOpsRenderPass(renderTarget, stencil, origin, bounds, colorInfo, stencilInfo, |
| 646 | sampledProxies, renderPassXferBarriers); |
| 647 | } |
| 648 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 649 | bool GrGpu::submitToGpu(bool syncCpu) { |
| 650 | this->stats()->incNumSubmitToGpus(); |
| 651 | |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 652 | if (auto manager = this->stagingBufferManager()) { |
| 653 | manager->detachBuffers(); |
| 654 | } |
Stephen White | f3d5d44 | 2020-04-08 10:35:58 -0400 | [diff] [blame] | 655 | |
Jim Van Verth | 7e829b2 | 2020-07-30 17:04:35 -0400 | [diff] [blame] | 656 | if (auto uniformsBuffer = this->uniformsRingBuffer()) { |
| 657 | uniformsBuffer->startSubmit(this); |
| 658 | } |
| 659 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 660 | bool submitted = this->onSubmitToGpu(syncCpu); |
Greg Daniel | 8561fc2 | 2020-04-08 12:52:51 -0400 | [diff] [blame] | 661 | |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 662 | this->callSubmittedProcs(submitted); |
| 663 | |
Greg Daniel | b432754 | 2020-11-20 10:50:50 -0500 | [diff] [blame^] | 664 | this->reportSubmitHistograms(); |
| 665 | |
| 666 | return submitted; |
| 667 | } |
| 668 | |
| 669 | void GrGpu::reportSubmitHistograms() { |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 670 | #if SK_HISTOGRAMS_ENABLED |
| 671 | // The max allowed value for SK_HISTOGRAM_EXACT_LINEAR is 100. If we want to support higher |
| 672 | // values we can add SK_HISTOGRAM_CUSTOM_COUNTS but this has a number of buckets that is less |
| 673 | // than the number of actual values |
| 674 | static constexpr int kMaxRenderPassBucketValue = 100; |
| 675 | SK_HISTOGRAM_EXACT_LINEAR("SubmitRenderPasses", |
Greg Daniel | ca107f3 | 2020-10-28 09:36:20 -0400 | [diff] [blame] | 676 | std::min(fCurrentSubmitRenderPassCount, kMaxRenderPassBucketValue), |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 677 | kMaxRenderPassBucketValue); |
| 678 | fCurrentSubmitRenderPassCount = 0; |
| 679 | #endif |
| 680 | |
Greg Daniel | b432754 | 2020-11-20 10:50:50 -0500 | [diff] [blame^] | 681 | this->onReportSubmitHistograms(); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 682 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 683 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 684 | bool GrGpu::checkAndResetOOMed() { |
| 685 | if (fOOMed) { |
| 686 | fOOMed = false; |
| 687 | return true; |
| 688 | } |
| 689 | return false; |
| 690 | } |
| 691 | |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 692 | void GrGpu::callSubmittedProcs(bool success) { |
| 693 | for (int i = 0; i < fSubmittedProcs.count(); ++i) { |
| 694 | fSubmittedProcs[i].fProc(fSubmittedProcs[i].fContext, success); |
| 695 | } |
| 696 | fSubmittedProcs.reset(); |
| 697 | } |
| 698 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 699 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 700 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { |
| 701 | writer->beginObject(); |
| 702 | |
| 703 | // TODO: Is there anything useful in the base class to dump here? |
| 704 | |
| 705 | this->onDumpJSON(writer); |
| 706 | |
| 707 | writer->endObject(); |
| 708 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 709 | #else |
| 710 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { } |
| 711 | #endif |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 712 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 713 | #if GR_TEST_UTILS |
| 714 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 715 | #if GR_GPU_STATS |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 716 | static const char* cache_result_to_str(int i) { |
| 717 | const char* kCacheResultStrings[GrGpu::Stats::kNumProgramCacheResults] = { |
| 718 | "hits", |
| 719 | "misses", |
| 720 | "partials" |
| 721 | }; |
| 722 | static_assert(0 == (int) GrGpu::Stats::ProgramCacheResult::kHit); |
| 723 | static_assert(1 == (int) GrGpu::Stats::ProgramCacheResult::kMiss); |
| 724 | static_assert(2 == (int) GrGpu::Stats::ProgramCacheResult::kPartial); |
| 725 | static_assert(GrGpu::Stats::kNumProgramCacheResults == 3); |
| 726 | return kCacheResultStrings[i]; |
| 727 | } |
| 728 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 729 | void GrGpu::Stats::dump(SkString* out) { |
| 730 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 731 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
| 732 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 733 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
| 734 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 735 | out->appendf("Transfers from Surface: %d\n", fTransfersFromSurface); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 736 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 737 | out->appendf("MSAA Attachment Creates: %d\n", fMSAAAttachmentCreates); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 738 | out->appendf("Number of draws: %d\n", fNumDraws); |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 739 | out->appendf("Number of Scratch Textures reused %d\n", fNumScratchTexturesReused); |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 740 | out->appendf("Number of Scratch MSAA Attachments reused %d\n", |
| 741 | fNumScratchMSAAAttachmentsReused); |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 742 | |
| 743 | SkASSERT(fNumInlineCompilationFailures == 0); |
| 744 | out->appendf("Number of Inline compile failures %d\n", fNumInlineCompilationFailures); |
| 745 | for (int i = 0; i < Stats::kNumProgramCacheResults-1; ++i) { |
| 746 | out->appendf("Inline Program Cache %s %d\n", cache_result_to_str(i), |
| 747 | fInlineProgramCacheStats[i]); |
| 748 | } |
| 749 | |
| 750 | SkASSERT(fNumPreCompilationFailures == 0); |
| 751 | out->appendf("Number of precompile failures %d\n", fNumPreCompilationFailures); |
| 752 | for (int i = 0; i < Stats::kNumProgramCacheResults-1; ++i) { |
| 753 | out->appendf("Precompile Program Cache %s %d\n", cache_result_to_str(i), |
| 754 | fPreProgramCacheStats[i]); |
| 755 | } |
| 756 | |
| 757 | SkASSERT(fNumCompilationFailures == 0); |
| 758 | out->appendf("Total number of compilation failures %d\n", fNumCompilationFailures); |
| 759 | out->appendf("Total number of partial compilation successes %d\n", |
| 760 | fNumPartialCompilationSuccesses); |
| 761 | out->appendf("Total number of compilation successes %d\n", fNumCompilationSuccesses); |
Robert Phillips | 6eb5cb9 | 2020-03-05 12:52:45 -0500 | [diff] [blame] | 762 | |
| 763 | // enable this block to output CSV-style stats for program pre-compilation |
| 764 | #if 0 |
| 765 | SkASSERT(fNumInlineCompilationFailures == 0); |
| 766 | SkASSERT(fNumPreCompilationFailures == 0); |
| 767 | SkASSERT(fNumCompilationFailures == 0); |
| 768 | SkASSERT(fNumPartialCompilationSuccesses == 0); |
| 769 | |
| 770 | SkDebugf("%d, %d, %d, %d, %d\n", |
| 771 | fInlineProgramCacheStats[(int) Stats::ProgramCacheResult::kHit], |
| 772 | fInlineProgramCacheStats[(int) Stats::ProgramCacheResult::kMiss], |
| 773 | fPreProgramCacheStats[(int) Stats::ProgramCacheResult::kHit], |
| 774 | fPreProgramCacheStats[(int) Stats::ProgramCacheResult::kMiss], |
| 775 | fNumCompilationSuccesses); |
| 776 | #endif |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 780 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 781 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 782 | } |
| 783 | |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 784 | #endif // GR_GPU_STATS |
| 785 | #endif // GR_TEST_UTILS |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 786 | |
Robert Phillips | ba5c7ad | 2020-01-24 11:03:33 -0500 | [diff] [blame] | 787 | bool GrGpu::MipMapsAreCorrect(SkISize dimensions, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 788 | GrMipmapped mipMapped, |
Robert Phillips | ba5c7ad | 2020-01-24 11:03:33 -0500 | [diff] [blame] | 789 | const BackendTextureData* data) { |
| 790 | int numMipLevels = 1; |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 791 | if (mipMapped == GrMipmapped::kYes) { |
Mike Reed | 13711eb | 2020-07-14 17:16:32 -0400 | [diff] [blame] | 792 | numMipLevels = SkMipmap::ComputeLevelCount(dimensions.width(), dimensions.height()) + 1; |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 793 | } |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 794 | |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 795 | if (!data || data->type() == BackendTextureData::Type::kColor) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 796 | return true; |
| 797 | } |
| 798 | |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 799 | if (data->type() == BackendTextureData::Type::kCompressed) { |
Robert Phillips | ba5c7ad | 2020-01-24 11:03:33 -0500 | [diff] [blame] | 800 | return false; // This should be going through CompressedDataIsCorrect |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | SkASSERT(data->type() == BackendTextureData::Type::kPixmaps); |
| 804 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 805 | if (data->pixmap(0).dimensions() != dimensions) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 806 | return false; |
| 807 | } |
| 808 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 809 | SkColorType colorType = data->pixmap(0).colorType(); |
Robert Phillips | ba5c7ad | 2020-01-24 11:03:33 -0500 | [diff] [blame] | 810 | for (int i = 1; i < numMipLevels; ++i) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 811 | dimensions = {std::max(1, dimensions.width()/2), std::max(1, dimensions.height()/2)}; |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 812 | if (dimensions != data->pixmap(i).dimensions()) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 813 | return false; |
| 814 | } |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 815 | if (colorType != data->pixmap(i).colorType()) { |
| 816 | return false; |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 817 | } |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 818 | } |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 819 | return true; |
| 820 | } |
| 821 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 822 | bool GrGpu::CompressedDataIsCorrect(SkISize dimensions, SkImage::CompressionType compressionType, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 823 | GrMipmapped mipMapped, const BackendTextureData* data) { |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 824 | |
| 825 | if (!data || data->type() == BackendTextureData::Type::kColor) { |
| 826 | return true; |
| 827 | } |
| 828 | |
| 829 | if (data->type() == BackendTextureData::Type::kPixmaps) { |
| 830 | return false; |
| 831 | } |
| 832 | |
| 833 | SkASSERT(data->type() == BackendTextureData::Type::kCompressed); |
| 834 | |
Robert Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 835 | size_t computedSize = SkCompressedDataSize(compressionType, dimensions, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 836 | nullptr, mipMapped == GrMipmapped::kYes); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 837 | |
| 838 | return computedSize == data->compressedSize(); |
| 839 | } |
| 840 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 841 | GrBackendTexture GrGpu::createBackendTexture(SkISize dimensions, |
| 842 | const GrBackendFormat& format, |
| 843 | GrRenderable renderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 844 | GrMipmapped mipMapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 845 | GrProtected isProtected) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 846 | const GrCaps* caps = this->caps(); |
| 847 | |
| 848 | if (!format.isValid()) { |
| 849 | return {}; |
| 850 | } |
| 851 | |
Robert Phillips | d34691b | 2019-09-24 13:38:43 -0400 | [diff] [blame] | 852 | if (caps->isFormatCompressed(format)) { |
| 853 | // Compressed formats must go through the createCompressedBackendTexture API |
| 854 | return {}; |
| 855 | } |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 856 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 857 | if (dimensions.isEmpty() || dimensions.width() > caps->maxTextureSize() || |
| 858 | dimensions.height() > caps->maxTextureSize()) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 859 | return {}; |
| 860 | } |
| 861 | |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 862 | if (mipMapped == GrMipmapped::kYes && !this->caps()->mipmapSupport()) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 863 | return {}; |
| 864 | } |
| 865 | |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 866 | return this->onCreateBackendTexture(dimensions, format, renderable, mipMapped, isProtected); |
| 867 | } |
| 868 | |
| 869 | bool GrGpu::updateBackendTexture(const GrBackendTexture& backendTexture, |
Greg Daniel | 2559778 | 2020-06-11 13:15:08 -0400 | [diff] [blame] | 870 | sk_sp<GrRefCntedCallback> finishedCallback, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 871 | const BackendTextureData* data) { |
| 872 | SkASSERT(data); |
| 873 | const GrCaps* caps = this->caps(); |
| 874 | |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 875 | if (!backendTexture.isValid()) { |
| 876 | return false; |
| 877 | } |
| 878 | |
| 879 | if (data->type() == BackendTextureData::Type::kPixmaps) { |
| 880 | auto ct = SkColorTypeToGrColorType(data->pixmap(0).colorType()); |
| 881 | if (!caps->areColorTypeAndFormatCompatible(ct, backendTexture.getBackendFormat())) { |
| 882 | return false; |
| 883 | } |
| 884 | } |
| 885 | |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 886 | if (backendTexture.hasMipmaps() && !this->caps()->mipmapSupport()) { |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 887 | return false; |
| 888 | } |
| 889 | |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 890 | GrMipmapped mipMapped = backendTexture.hasMipmaps() ? GrMipmapped::kYes : GrMipmapped::kNo; |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 891 | if (!MipMapsAreCorrect(backendTexture.dimensions(), mipMapped, data)) { |
| 892 | return false; |
| 893 | } |
| 894 | |
Greg Daniel | 2559778 | 2020-06-11 13:15:08 -0400 | [diff] [blame] | 895 | return this->onUpdateBackendTexture(backendTexture, std::move(finishedCallback), data); |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 896 | } |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 897 | |
| 898 | GrBackendTexture GrGpu::createCompressedBackendTexture(SkISize dimensions, |
| 899 | const GrBackendFormat& format, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 900 | GrMipmapped mipMapped, |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 901 | GrProtected isProtected) { |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 902 | const GrCaps* caps = this->caps(); |
| 903 | |
| 904 | if (!format.isValid()) { |
| 905 | return {}; |
| 906 | } |
| 907 | |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 908 | SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 909 | if (compressionType == SkImage::CompressionType::kNone) { |
| 910 | // Uncompressed formats must go through the createBackendTexture API |
| 911 | return {}; |
| 912 | } |
| 913 | |
| 914 | if (dimensions.isEmpty() || |
| 915 | dimensions.width() > caps->maxTextureSize() || |
| 916 | dimensions.height() > caps->maxTextureSize()) { |
| 917 | return {}; |
| 918 | } |
| 919 | |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 920 | if (mipMapped == GrMipmapped::kYes && !this->caps()->mipmapSupport()) { |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 921 | return {}; |
| 922 | } |
| 923 | |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 924 | return this->onCreateCompressedBackendTexture(dimensions, format, mipMapped, isProtected); |
| 925 | } |
| 926 | |
| 927 | bool GrGpu::updateCompressedBackendTexture(const GrBackendTexture& backendTexture, |
| 928 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 929 | const BackendTextureData* data) { |
| 930 | SkASSERT(data); |
| 931 | |
| 932 | if (!backendTexture.isValid()) { |
| 933 | return false; |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 934 | } |
| 935 | |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 936 | GrBackendFormat format = backendTexture.getBackendFormat(); |
| 937 | |
| 938 | SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format); |
| 939 | if (compressionType == SkImage::CompressionType::kNone) { |
| 940 | // Uncompressed formats must go through the createBackendTexture API |
| 941 | return false; |
| 942 | } |
| 943 | |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 944 | if (backendTexture.hasMipmaps() && !this->caps()->mipmapSupport()) { |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 945 | return false; |
| 946 | } |
| 947 | |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 948 | GrMipmapped mipMapped = backendTexture.hasMipmaps() ? GrMipmapped::kYes : GrMipmapped::kNo; |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 949 | |
| 950 | if (!CompressedDataIsCorrect(backendTexture.dimensions(), compressionType, mipMapped, data)) { |
| 951 | return false; |
| 952 | } |
| 953 | |
| 954 | return this->onUpdateCompressedBackendTexture(backendTexture, std::move(finishedCallback), |
| 955 | data); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 956 | } |