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 2011 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 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrGpu_DEFINED |
| 9 | #define GrGpu_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkPath.h" |
Brian Osman | a5842bc | 2021-05-11 13:41:46 -0400 | [diff] [blame] | 12 | #include "include/core/SkSpan.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkSurface.h" |
| 14 | #include "include/gpu/GrTypes.h" |
| 15 | #include "include/private/SkTArray.h" |
Stephen White | f3d5d44 | 2020-04-08 10:35:58 -0400 | [diff] [blame] | 16 | #include "src/core/SkTInternalLList.h" |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrAttachment.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrCaps.h" |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrOpsRenderPass.h" |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrPixmap.h" |
Brian Salomon | 3ec1f54 | 2019-06-17 17:54:57 +0000 | [diff] [blame] | 21 | #include "src/gpu/GrSwizzle.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "src/gpu/GrXferProcessor.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 23 | |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 24 | class GrAttachment; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 25 | class GrBackendRenderTarget; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 26 | class GrBackendSemaphore; |
Brian Salomon | 05487ab | 2020-12-23 20:32:22 -0500 | [diff] [blame] | 27 | struct GrContextOptions; |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 28 | class GrDirectContext; |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 29 | class GrGpuBuffer; |
reed | f9ad558 | 2015-06-25 21:29:25 -0700 | [diff] [blame] | 30 | class GrGLContext; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 31 | class GrPath; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 32 | class GrPathRenderer; |
| 33 | class GrPathRendererChain; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 34 | class GrPipeline; |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 35 | class GrGeometryProcessor; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 36 | class GrRenderTarget; |
Jim Van Verth | 7e829b2 | 2020-07-30 17:04:35 -0400 | [diff] [blame] | 37 | class GrRingBuffer; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 38 | class GrSemaphore; |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 39 | class GrStagingBufferManager; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 40 | class GrStencilSettings; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 41 | class GrSurface; |
| 42 | class GrTexture; |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 43 | class GrThreadSafePipelineBuilder; |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame] | 44 | struct GrVkDrawableInfo; |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 45 | class SkJSONWriter; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame] | 47 | namespace SkSL { |
| 48 | class Compiler; |
| 49 | } |
| 50 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 51 | class GrGpu : public SkRefCnt { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 52 | public: |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 53 | GrGpu(GrDirectContext* direct); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 54 | ~GrGpu() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 55 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 56 | GrDirectContext* getContext() { return fContext; } |
| 57 | const GrDirectContext* getContext() const { return fContext; } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Gets the capabilities of the draw target. |
| 61 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 62 | const GrCaps* caps() const { return fCaps.get(); } |
Robert Phillips | e42edcc | 2017-12-13 11:50:22 -0500 | [diff] [blame] | 63 | sk_sp<const GrCaps> refCaps() const { return fCaps; } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 64 | |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 65 | virtual GrStagingBufferManager* stagingBufferManager() { return nullptr; } |
| 66 | |
Jim Van Verth | 7e829b2 | 2020-07-30 17:04:35 -0400 | [diff] [blame] | 67 | virtual GrRingBuffer* uniformsRingBuffer() { return nullptr; } |
| 68 | |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame] | 69 | SkSL::Compiler* shaderCompiler() const { return fCompiler.get(); } |
| 70 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 71 | enum class DisconnectType { |
| 72 | // No cleanup should be attempted, immediately cease making backend API calls |
| 73 | kAbandon, |
| 74 | // Free allocated resources (not known by GrResourceCache) before returning and |
| 75 | // ensure no backend backend 3D API calls will be made after disconnect() returns. |
| 76 | kCleanup, |
| 77 | }; |
| 78 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 79 | // Called by context when the underlying backend context is already or will be destroyed |
| 80 | // before GrDirectContext. |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 81 | virtual void disconnect(DisconnectType); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 82 | |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 83 | virtual GrThreadSafePipelineBuilder* pipelineBuilder() = 0; |
| 84 | virtual sk_sp<GrThreadSafePipelineBuilder> refPipelineBuilder() = 0; |
| 85 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 86 | // Called by GrDirectContext::isContextLost. Returns true if the backend Gpu object has gotten |
| 87 | // into an unrecoverable, lost state. |
Greg Daniel | 6e35a00 | 2020-04-01 13:29:59 -0400 | [diff] [blame] | 88 | virtual bool isDeviceLost() const { return false; } |
| 89 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 90 | /** |
| 91 | * The GrGpu object normally assumes that no outsider is setting state |
| 92 | * within the underlying 3D API's context/device/whatever. This call informs |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 93 | * the GrGpu that the state was modified and it shouldn't make assumptions |
| 94 | * about the state. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | */ |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 96 | void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 97 | |
| 98 | /** |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 99 | * Creates a texture object. If renderable is kYes then the returned texture can |
bsalomon | 6d467ec | 2014-11-18 07:36:19 -0800 | [diff] [blame] | 100 | * be used as a render target by calling GrTexture::asRenderTarget(). Not all |
| 101 | * pixel configs can be used as render targets. Support for configs as textures |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 102 | * or render targets can be checked using GrCaps. |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 103 | * |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 104 | * @param dimensions dimensions of the texture to be created. |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 105 | * @param format the format for the texture (not currently used). |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 106 | * @param renderable should the resulting texture be renderable |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 107 | * @param renderTargetSampleCnt The number of samples to use for rendering if renderable is |
| 108 | * kYes. If renderable is kNo then this must be 1. |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 109 | * @param budgeted does this texture count against the resource cache budget? |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 110 | * @param isProtected should the texture be created as protected. |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 111 | * @param texels array of mipmap levels containing texel data to load. |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 112 | * If level i has pixels then it is assumed that its dimensions are |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 113 | * max(1, floor(dimensions.fWidth / 2)) by |
| 114 | * max(1, floor(dimensions.fHeight / 2)). |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 115 | * If texels[i].fPixels == nullptr for all i <= mipLevelCount or |
| 116 | * mipLevelCount is 0 then the texture's contents are uninitialized. |
| 117 | * If a level has non-null pixels, its row bytes must be a multiple of the |
| 118 | * config's bytes-per-pixel. The row bytes must be tight to the |
| 119 | * level width if !caps->writePixelsRowBytesSupport(). |
| 120 | * If mipLevelCount > 1 and texels[i].fPixels != nullptr for any i > 0 |
| 121 | * then all levels must have non-null pixels. All levels must have |
| 122 | * non-null pixels if GrCaps::createTextureMustSpecifyAllLevels() is true. |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 123 | * @param textureColorType The color type interpretation of the texture for the purpose of |
| 124 | * of uploading texel data. |
| 125 | * @param srcColorType The color type of data in texels[]. |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 126 | * @param texelLevelCount the number of levels in 'texels'. May be 0, 1, or |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 127 | * floor(max((log2(dimensions.fWidth), log2(dimensions.fHeight)))). It |
| 128 | * must be the latter if GrCaps::createTextureMustSpecifyAllLevels() is |
| 129 | * true. |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 130 | * @return The texture object if successful, otherwise nullptr. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 131 | */ |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 132 | sk_sp<GrTexture> createTexture(SkISize dimensions, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 133 | const GrBackendFormat& format, |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 134 | GrTextureType textureType, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 135 | GrRenderable renderable, |
| 136 | int renderTargetSampleCnt, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 137 | SkBudgeted budgeted, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 138 | GrProtected isProtected, |
| 139 | GrColorType textureColorType, |
| 140 | GrColorType srcColorType, |
| 141 | const GrMipLevel texels[], |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 142 | int texelLevelCount); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 143 | |
Brian Salomon | c7dced5 | 2019-07-18 15:02:01 +0000 | [diff] [blame] | 144 | /** |
| 145 | * Simplified createTexture() interface for when there is no initial texel data to upload. |
| 146 | */ |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 147 | sk_sp<GrTexture> createTexture(SkISize dimensions, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 148 | const GrBackendFormat& format, |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 149 | GrTextureType textureType, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 150 | GrRenderable renderable, |
| 151 | int renderTargetSampleCnt, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 152 | GrMipmapped mipMapped, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 153 | SkBudgeted budgeted, |
| 154 | GrProtected isProtected); |
Brian Salomon | c7dced5 | 2019-07-18 15:02:01 +0000 | [diff] [blame] | 155 | |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 156 | sk_sp<GrTexture> createCompressedTexture(SkISize dimensions, |
| 157 | const GrBackendFormat& format, |
| 158 | SkBudgeted budgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 159 | GrMipmapped mipMapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 160 | GrProtected isProtected, |
Robert Phillips | e4720c6 | 2020-01-14 14:33:24 -0500 | [diff] [blame] | 161 | const void* data, size_t dataSize); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 162 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 163 | /** |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 164 | * Implements GrResourceProvider::wrapBackendTexture |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 165 | */ |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 166 | sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, |
| 167 | GrWrapOwnership, |
| 168 | GrWrapCacheable, |
| 169 | GrIOType); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 170 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 171 | sk_sp<GrTexture> wrapCompressedBackendTexture(const GrBackendTexture&, |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 172 | GrWrapOwnership, |
| 173 | GrWrapCacheable); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 174 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 175 | /** |
| 176 | * Implements GrResourceProvider::wrapRenderableBackendTexture |
| 177 | */ |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 178 | sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture&, |
| 179 | int sampleCnt, |
| 180 | GrWrapOwnership, |
| 181 | GrWrapCacheable); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 182 | |
| 183 | /** |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 184 | * Implements GrResourceProvider::wrapBackendRenderTarget |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 185 | */ |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 186 | sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTarget&); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 187 | |
| 188 | /** |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 189 | * Implements GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget |
| 190 | */ |
| 191 | sk_sp<GrRenderTarget> wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, |
| 192 | const GrVkDrawableInfo&); |
| 193 | |
| 194 | /** |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 195 | * Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 196 | * |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 197 | * @param size size of buffer to create. |
| 198 | * @param intendedType hint to the graphics subsystem about what the buffer will be used for. |
| 199 | * @param accessPattern hint to the graphics subsystem about how the data will be accessed. |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 200 | * @param data optional data with which to initialize the buffer. |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 201 | * |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 202 | * @return the buffer if successful, otherwise nullptr. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 203 | */ |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 204 | sk_sp<GrGpuBuffer> createBuffer(size_t size, GrGpuBufferType intendedType, |
| 205 | GrAccessPattern accessPattern, const void* data = nullptr); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 206 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 207 | /** |
Greg Daniel | 242536f | 2020-02-13 14:12:46 -0500 | [diff] [blame] | 208 | * Resolves MSAA. The resolveRect must already be in the native destination space. |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 209 | */ |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 210 | void resolveRenderTarget(GrRenderTarget*, const SkIRect& resolveRect); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 211 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 212 | /** |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 213 | * Uses the base of the texture to recompute the contents of the other levels. |
| 214 | */ |
| 215 | bool regenerateMipMapLevels(GrTexture*); |
| 216 | |
| 217 | /** |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 218 | * If the backend API has stateful texture bindings, this resets them back to defaults. |
| 219 | */ |
| 220 | void resetTextureBindings(); |
| 221 | |
| 222 | /** |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 223 | * Reads a rectangle of pixels from a render target. No sRGB/linear conversions are performed. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 224 | * |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 225 | * @param surface the surface to read from |
| 226 | * @param rect the rectangle of pixels to read |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 227 | * @param surfaceColorType the color type for this use of the surface. |
| 228 | * @param dstColorType the color type of the destination buffer. |
| 229 | * @param buffer memory to read the rectangle into. |
| 230 | * @param rowBytes the number of bytes between consecutive rows. Must be a multiple of |
| 231 | * dstColorType's bytes-per-pixel. Must be tight to width if |
| 232 | * !caps->readPixelsRowBytesSupport(). |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 233 | * |
| 234 | * @return true if the read succeeded, false if not. The read can fail |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 235 | * because of the surface doesn't support reading, the color type |
| 236 | * is not allowed for the format of the surface or if the rectangle |
| 237 | * read is not contained in the surface. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 238 | */ |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 239 | bool readPixels(GrSurface* surface, |
| 240 | SkIRect rect, |
| 241 | GrColorType surfaceColorType, |
| 242 | GrColorType dstColorType, |
| 243 | void* buffer, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 244 | size_t rowBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 245 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 246 | /** |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 247 | * Updates the pixels in a rectangle of a surface. No sRGB/linear conversions are performed. |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 248 | * |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 249 | * @param surface the surface to write to. |
| 250 | * @param rect the rectangle of pixels to overwrite |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 251 | * @param surfaceColorType the color type for this use of the surface. |
| 252 | * @param srcColorType the color type of the source buffer. |
| 253 | * @param texels array of mipmap levels containing texture data. Row bytes must be a |
| 254 | * multiple of srcColorType's bytes-per-pixel. Must be tight to level |
| 255 | * width if !caps->writePixelsRowBytesSupport(). |
| 256 | * @param mipLevelCount number of levels in 'texels' |
| 257 | * @param prepForTexSampling After doing write pixels should the surface be prepared for texture |
| 258 | * sampling. This is currently only used by Vulkan for inline uploads |
| 259 | * to set that layout back to sampled after doing the upload. Inline |
| 260 | * uploads currently can happen between draws in a single op so it is |
Robert Phillips | 3e87a8e | 2021-08-25 13:22:24 -0400 | [diff] [blame] | 261 | * not trivial to break up the OpsTask into two tasks when we see |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 262 | * an inline upload. However, once we are able to support doing that |
| 263 | * we can remove this parameter. |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 264 | * |
| 265 | * @return true if the write succeeded, false if not. The read can fail |
| 266 | * because of the surface doesn't support writing (e.g. read only), |
| 267 | * the color type is not allowed for the format of the surface or |
| 268 | * if the rectangle written is not contained in the surface. |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 269 | */ |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 270 | bool writePixels(GrSurface* surface, |
| 271 | SkIRect rect, |
| 272 | GrColorType surfaceColorType, |
| 273 | GrColorType srcColorType, |
| 274 | const GrMipLevel texels[], |
| 275 | int mipLevelCount, |
| 276 | bool prepForTexSampling = false); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 277 | |
| 278 | /** |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 279 | * Helper for the case of a single level. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 280 | */ |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 281 | bool writePixels(GrSurface* surface, |
| 282 | SkIRect rect, |
| 283 | GrColorType surfaceColorType, |
| 284 | GrColorType srcColorType, |
| 285 | const void* buffer, |
| 286 | size_t rowBytes, |
| 287 | bool prepForTexSampling = false) { |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame] | 288 | GrMipLevel mipLevel = {buffer, rowBytes, nullptr}; |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 289 | return this->writePixels(surface, |
| 290 | rect, |
| 291 | surfaceColorType, |
| 292 | srcColorType, |
| 293 | &mipLevel, |
| 294 | 1, |
| 295 | prepForTexSampling); |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /** |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 299 | * Updates the pixels in a rectangle of a texture using a buffer. If the texture is MIP mapped, |
| 300 | * the base level is written to. |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 301 | * |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 302 | * @param texture the texture to write to. |
| 303 | * @param rect the rectangle of pixels in the texture to overwrite |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 304 | * @param textureColorType the color type for this use of the surface. |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 305 | * @param bufferColorType the color type of the transfer buffer's pixel data |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 306 | * @param transferBuffer GrBuffer to read pixels from (type must be "kXferCpuToGpu") |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 307 | * @param offset offset from the start of the buffer |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 308 | * @param rowBytes number of bytes between consecutive rows in the buffer. Must be a |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 309 | * multiple of bufferColorType's bytes-per-pixel. Must be tight to |
| 310 | * rect.width() if !caps->writePixelsRowBytesSupport(). |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 311 | */ |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 312 | bool transferPixelsTo(GrTexture* texture, |
| 313 | SkIRect rect, |
| 314 | GrColorType textureColorType, |
| 315 | GrColorType bufferColorType, |
| 316 | sk_sp<GrGpuBuffer> transferBuffer, |
| 317 | size_t offset, |
| 318 | size_t rowBytes); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 319 | |
| 320 | /** |
| 321 | * Reads the pixels from a rectangle of a surface into a buffer. Use |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 322 | * GrCaps::SupportedRead::fOffsetAlignmentForTransferBuffer to determine the requirements for |
| 323 | * the buffer offset alignment. If the surface is a MIP mapped texture, the base level is read. |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 324 | * |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 325 | * If successful the row bytes in the buffer is always: |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 326 | * GrColorTypeBytesPerPixel(bufferColorType) * rect.width() |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 327 | * |
| 328 | * Asserts that the caller has passed a properly aligned offset and that the buffer is |
| 329 | * large enough to hold the result |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 330 | * |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 331 | * @param surface the surface to read from. |
| 332 | * @param rect the rectangle of pixels to read |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 333 | * @param surfaceColorType the color type for this use of the surface. |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 334 | * @param bufferColorType the color type of the transfer buffer's pixel data |
| 335 | * @param transferBuffer GrBuffer to write pixels to (type must be "kXferGpuToCpu") |
| 336 | * @param offset offset from the start of the buffer |
| 337 | */ |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 338 | bool transferPixelsFrom(GrSurface* surface, |
| 339 | SkIRect rect, |
| 340 | GrColorType surfaceColorType, |
| 341 | GrColorType bufferColorType, |
| 342 | sk_sp<GrGpuBuffer> transferBuffer, |
| 343 | size_t offset); |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 344 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 345 | // Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 346 | // take place at higher levels and this function implement faster copy paths. The rect |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 347 | // and point are pre-clipped. The src rect and implied dst rect are guaranteed to be within the |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 348 | // src/dst bounds and non-empty. They must also be in their exact device space coords, including |
| 349 | // already being transformed for origin if need be. If canDiscardOutsideDstRect is set to true |
| 350 | // then we don't need to preserve any data on the dst surface outside of the copy. |
| 351 | bool copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 352 | const SkIPoint& dstPoint); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 353 | |
Robert Phillips | 3e87a8e | 2021-08-25 13:22:24 -0400 | [diff] [blame] | 354 | // Returns a GrOpsRenderPass which OpsTasks send draw commands to instead of directly |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 355 | // to the Gpu object. The 'bounds' rect is the content rect of the renderTarget. |
Robert Phillips | 96f2237 | 2020-05-20 12:31:18 -0400 | [diff] [blame] | 356 | // If a 'stencil' is provided it will be the one bound to 'renderTarget'. If one is not |
| 357 | // provided but 'renderTarget' has a stencil buffer then that is a signal that the |
| 358 | // render target's stencil buffer should be ignored. |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 359 | GrOpsRenderPass* getOpsRenderPass(GrRenderTarget* renderTarget, |
Chris Dalton | da2b0f4 | 2021-04-13 00:19:45 -0600 | [diff] [blame] | 360 | bool useMSAASurface, |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 361 | GrAttachment* stencil, |
| 362 | GrSurfaceOrigin, |
| 363 | const SkIRect& bounds, |
| 364 | const GrOpsRenderPass::LoadAndStoreInfo&, |
| 365 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
| 366 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 367 | GrXferBarrierFlags renderPassXferBarriers); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 368 | |
Robert Phillips | 18e9484 | 2017-05-15 13:06:44 -0400 | [diff] [blame] | 369 | // Called by GrDrawingManager when flushing. |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 370 | // Provides a hook for post-flush actions (e.g. Vulkan command buffer submits). This will also |
| 371 | // insert any numSemaphore semaphores on the gpu and set the backendSemaphores to match the |
| 372 | // inserted semaphores. |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 373 | void executeFlushInfo(SkSpan<GrSurfaceProxy*>, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 374 | SkSurface::BackendSurfaceAccess access, |
| 375 | const GrFlushInfo&, |
| 376 | const GrBackendSurfaceMutableState* newState); |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 377 | |
| 378 | bool submitToGpu(bool syncCpu); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 379 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 380 | virtual void submit(GrOpsRenderPass*) = 0; |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 381 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 382 | virtual GrFence SK_WARN_UNUSED_RESULT insertFence() = 0; |
Stephen White | b353c9b | 2020-04-16 14:14:13 -0400 | [diff] [blame] | 383 | virtual bool waitFence(GrFence) = 0; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 384 | virtual void deleteFence(GrFence) const = 0; |
| 385 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 386 | virtual std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore( |
| 387 | bool isOwned = true) = 0; |
Robert Phillips | 1a82a4e | 2021-07-01 10:27:44 -0400 | [diff] [blame] | 388 | virtual std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&, |
| 389 | GrSemaphoreWrapType, |
| 390 | GrWrapOwnership) = 0; |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 391 | virtual void insertSemaphore(GrSemaphore* semaphore) = 0; |
| 392 | virtual void waitSemaphore(GrSemaphore* semaphore) = 0; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 393 | |
Jim Van Verth | 1aaf41b | 2020-07-29 09:24:29 -0400 | [diff] [blame] | 394 | virtual void addFinishedProc(GrGpuFinishedProc finishedProc, |
| 395 | GrGpuFinishedContext finishedContext) = 0; |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 396 | virtual void checkFinishProcs() = 0; |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame] | 397 | virtual void finishOutstandingGpuWork() = 0; |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 398 | |
Jim Van Verth | 1aaf41b | 2020-07-29 09:24:29 -0400 | [diff] [blame] | 399 | virtual void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) {} |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 400 | |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 401 | /** |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 402 | * Checks if we detected an OOM from the underlying 3D API and if so returns true and resets |
| 403 | * the internal OOM state to false. Otherwise, returns false. |
| 404 | */ |
| 405 | bool checkAndResetOOMed(); |
| 406 | |
| 407 | /** |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 408 | * Put this texture in a safe and known state for use across multiple contexts. Depending on |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 409 | * the backend, this may return a GrSemaphore. If so, other contexts should wait on that |
| 410 | * semaphore before using this texture. |
| 411 | */ |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 412 | virtual std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) = 0; |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 413 | |
Greg Daniel | 428523f | 2021-03-30 14:22:54 -0400 | [diff] [blame] | 414 | /** |
| 415 | * Frees any backend specific objects that are not currently in use by the GPU. This is called |
| 416 | * when the client is trying to free up as much GPU memory as possible. We will not release |
| 417 | * resources connected to programs/pipelines since the cost to recreate those is significantly |
| 418 | * higher that other resources. |
| 419 | */ |
| 420 | virtual void releaseUnlockedBackendObjects() {} |
| 421 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 422 | /////////////////////////////////////////////////////////////////////////// |
| 423 | // Debugging and Stats |
| 424 | |
| 425 | class Stats { |
| 426 | public: |
| 427 | #if GR_GPU_STATS |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 428 | Stats() = default; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 429 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 430 | void reset() { *this = {}; } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 431 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 432 | int textureCreates() const { return fTextureCreates; } |
| 433 | void incTextureCreates() { fTextureCreates++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 434 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 435 | int textureUploads() const { return fTextureUploads; } |
| 436 | void incTextureUploads() { fTextureUploads++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 437 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 438 | int transfersToTexture() const { return fTransfersToTexture; } |
| 439 | void incTransfersToTexture() { fTransfersToTexture++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 440 | |
| 441 | int transfersFromSurface() const { return fTransfersFromSurface; } |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 442 | void incTransfersFromSurface() { fTransfersFromSurface++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 443 | |
| 444 | int stencilAttachmentCreates() const { return fStencilAttachmentCreates; } |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 445 | void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 446 | |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 447 | int msaaAttachmentCreates() const { return fMSAAAttachmentCreates; } |
| 448 | void incMSAAAttachmentCreates() { fMSAAAttachmentCreates++; } |
| 449 | |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 450 | int numDraws() const { return fNumDraws; } |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 451 | void incNumDraws() { fNumDraws++; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 452 | |
| 453 | int numFailedDraws() const { return fNumFailedDraws; } |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 454 | void incNumFailedDraws() { ++fNumFailedDraws; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 455 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 456 | int numSubmitToGpus() const { return fNumSubmitToGpus; } |
| 457 | void incNumSubmitToGpus() { ++fNumSubmitToGpus; } |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 458 | |
| 459 | int numScratchTexturesReused() const { return fNumScratchTexturesReused; } |
| 460 | void incNumScratchTexturesReused() { ++fNumScratchTexturesReused; } |
| 461 | |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 462 | int numScratchMSAAAttachmentsReused() const { return fNumScratchMSAAAttachmentsReused; } |
| 463 | void incNumScratchMSAAAttachmentsReused() { ++fNumScratchMSAAAttachmentsReused; } |
| 464 | |
Adlai Holler | 78d51ff | 2021-03-12 10:51:44 -0500 | [diff] [blame] | 465 | int renderPasses() const { return fRenderPasses; } |
| 466 | void incRenderPasses() { fRenderPasses++; } |
| 467 | |
Adlai Holler | fe91974 | 2021-04-10 07:42:15 -0400 | [diff] [blame] | 468 | int numReorderedDAGsOverBudget() const { return fNumReorderedDAGsOverBudget; } |
| 469 | void incNumReorderedDAGsOverBudget() { fNumReorderedDAGsOverBudget++; } |
| 470 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 471 | #if GR_TEST_UTILS |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 472 | void dump(SkString*); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 473 | void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 474 | #endif |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 475 | private: |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 476 | int fTextureCreates = 0; |
| 477 | int fTextureUploads = 0; |
| 478 | int fTransfersToTexture = 0; |
| 479 | int fTransfersFromSurface = 0; |
| 480 | int fStencilAttachmentCreates = 0; |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 481 | int fMSAAAttachmentCreates = 0; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 482 | int fNumDraws = 0; |
| 483 | int fNumFailedDraws = 0; |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 484 | int fNumSubmitToGpus = 0; |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 485 | int fNumScratchTexturesReused = 0; |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 486 | int fNumScratchMSAAAttachmentsReused = 0; |
Adlai Holler | 78d51ff | 2021-03-12 10:51:44 -0500 | [diff] [blame] | 487 | int fRenderPasses = 0; |
Adlai Holler | fe91974 | 2021-04-10 07:42:15 -0400 | [diff] [blame] | 488 | int fNumReorderedDAGsOverBudget = 0; |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 489 | |
Adlai Holler | 78d51ff | 2021-03-12 10:51:44 -0500 | [diff] [blame] | 490 | #else // !GR_GPU_STATS |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 491 | |
| 492 | #if GR_TEST_UTILS |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 493 | void dump(SkString*) {} |
| 494 | void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {} |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 495 | #endif |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 496 | void incTextureCreates() {} |
| 497 | void incTextureUploads() {} |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 498 | void incTransfersToTexture() {} |
Greg Daniel | a28ea67 | 2020-09-25 11:12:56 -0400 | [diff] [blame] | 499 | void incTransfersFromSurface() {} |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 500 | void incStencilAttachmentCreates() {} |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 501 | void incMSAAAttachmentCreates() {} |
joshualitt | 87a5c9f | 2015-09-08 13:42:05 -0700 | [diff] [blame] | 502 | void incNumDraws() {} |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 503 | void incNumFailedDraws() {} |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 504 | void incNumSubmitToGpus() {} |
Greg Daniel | a28ea67 | 2020-09-25 11:12:56 -0400 | [diff] [blame] | 505 | void incNumScratchTexturesReused() {} |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 506 | void incNumScratchMSAAAttachmentsReused() {} |
Adlai Holler | 78d51ff | 2021-03-12 10:51:44 -0500 | [diff] [blame] | 507 | void incRenderPasses() {} |
Adlai Holler | fe91974 | 2021-04-10 07:42:15 -0400 | [diff] [blame] | 508 | void incNumReorderedDAGsOverBudget() {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 509 | #endif |
| 510 | }; |
| 511 | |
| 512 | Stats* stats() { return &fStats; } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 513 | void dumpJSON(SkJSONWriter*) const; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 514 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 515 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 516 | /** |
| 517 | * Creates a texture directly in the backend API without wrapping it in a GrTexture. |
| 518 | * Must be matched with a call to deleteBackendTexture(). |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 519 | * |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 520 | * If data is null the texture is uninitialized. |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 521 | * |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 522 | * If data represents a color then all texture levels are cleared to that color. |
| 523 | * |
Robert Phillips | ba5c7ad | 2020-01-24 11:03:33 -0500 | [diff] [blame] | 524 | * If data represents pixmaps then it must have a either one pixmap or, if mipmapping |
| 525 | * is specified, a complete MIP hierarchy of pixmaps. Additionally, if provided, the mip |
| 526 | * levels must be sized correctly according to the MIP sizes implied by dimensions. They |
| 527 | * must all have the same color type and that color type must be compatible with the |
| 528 | * texture format. |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 529 | */ |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 530 | GrBackendTexture createBackendTexture(SkISize dimensions, |
| 531 | const GrBackendFormat&, |
| 532 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 533 | GrMipmapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 534 | GrProtected); |
| 535 | |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 536 | bool clearBackendTexture(const GrBackendTexture&, |
| 537 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 538 | std::array<float, 4> color); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 539 | |
Robert Phillips | ba5c7ad | 2020-01-24 11:03:33 -0500 | [diff] [blame] | 540 | /** |
| 541 | * Same as the createBackendTexture case except compressed backend textures can |
| 542 | * never be renderable. |
| 543 | */ |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 544 | GrBackendTexture createCompressedBackendTexture(SkISize dimensions, |
| 545 | const GrBackendFormat&, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 546 | GrMipmapped, |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 547 | GrProtected); |
| 548 | |
| 549 | bool updateCompressedBackendTexture(const GrBackendTexture&, |
| 550 | sk_sp<GrRefCntedCallback> finishedCallback, |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 551 | const void* data, |
| 552 | size_t length); |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 553 | |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 554 | virtual bool setBackendTextureState(const GrBackendTexture&, |
| 555 | const GrBackendSurfaceMutableState&, |
Greg Daniel | 1d3c8c1 | 2020-09-23 14:23:36 -0400 | [diff] [blame] | 556 | GrBackendSurfaceMutableState* previousState, |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 557 | sk_sp<GrRefCntedCallback> finishedCallback) { |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | virtual bool setBackendRenderTargetState(const GrBackendRenderTarget&, |
| 562 | const GrBackendSurfaceMutableState&, |
Greg Daniel | 1d3c8c1 | 2020-09-23 14:23:36 -0400 | [diff] [blame] | 563 | GrBackendSurfaceMutableState* previousState, |
Greg Daniel | 1db8e79 | 2020-06-09 17:29:32 -0400 | [diff] [blame] | 564 | sk_sp<GrRefCntedCallback> finishedCallback) { |
| 565 | return false; |
| 566 | } |
| 567 | |
Brian Salomon | e64b064 | 2018-03-07 11:47:54 -0500 | [diff] [blame] | 568 | /** |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 569 | * Frees a texture created by createBackendTexture(). If ownership of the backend |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 570 | * texture has been transferred to a context using adopt semantics this should not be called. |
Brian Salomon | e64b064 | 2018-03-07 11:47:54 -0500 | [diff] [blame] | 571 | */ |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 572 | virtual void deleteBackendTexture(const GrBackendTexture&) = 0; |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 573 | |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 574 | /** |
| 575 | * In this case we have a program descriptor and a program info but no render target. |
| 576 | */ |
| 577 | virtual bool compile(const GrProgramDesc&, const GrProgramInfo&) = 0; |
| 578 | |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 579 | virtual bool precompileShader(const SkData& key, const SkData& data) { return false; } |
| 580 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 581 | #if GR_TEST_UTILS |
| 582 | /** Check a handle represents an actual texture in the backend API that has not been freed. */ |
| 583 | virtual bool isTestingOnlyBackendTexture(const GrBackendTexture&) const = 0; |
| 584 | |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 585 | /** |
| 586 | * Creates a GrBackendRenderTarget that can be wrapped using |
| 587 | * SkSurface::MakeFromBackendRenderTarget. Ideally this is a non-textureable allocation to |
| 588 | * differentiate from testing with SkSurface::MakeFromBackendTexture. When sampleCnt > 1 this |
| 589 | * is used to test client wrapped allocations with MSAA where Skia does not allocate a separate |
| 590 | * buffer for resolving. If the color is non-null the backing store should be cleared to the |
| 591 | * passed in color. |
| 592 | */ |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 593 | virtual GrBackendRenderTarget createTestingOnlyBackendRenderTarget( |
| 594 | SkISize dimensions, |
| 595 | GrColorType, |
| 596 | int sampleCount = 1, |
| 597 | GrProtected = GrProtected::kNo) = 0; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 598 | |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 599 | /** |
| 600 | * Deletes a GrBackendRenderTarget allocated with the above. Synchronization to make this safe |
| 601 | * is up to the caller. |
| 602 | */ |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 603 | virtual void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) = 0; |
| 604 | |
| 605 | // This is only to be used in GL-specific tests. |
| 606 | virtual const GrGLContext* glContextForTesting() const { return nullptr; } |
| 607 | |
| 608 | // This is only to be used by testing code |
| 609 | virtual void resetShaderCacheForTesting() const {} |
| 610 | |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 611 | /** |
Jim Van Verth | 052761f | 2019-09-27 15:05:51 -0400 | [diff] [blame] | 612 | * Inserted as a pair around a block of code to do a GPU frame capture. |
| 613 | * Currently only works with the Metal backend. |
| 614 | */ |
| 615 | virtual void testingOnly_startCapture() {} |
| 616 | virtual void testingOnly_endCapture() {} |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 617 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 618 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 619 | // width and height may be larger than rt (if underlying API allows it). |
| 620 | // Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 621 | // the GrAttachment. |
Chris Dalton | e0fe23a | 2021-04-23 13:11:44 -0600 | [diff] [blame] | 622 | virtual sk_sp<GrAttachment> makeStencilAttachment(const GrBackendFormat& colorFormat, |
| 623 | SkISize dimensions, |
| 624 | int numStencilSamples) = 0; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 625 | |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame] | 626 | virtual GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) = 0; |
| 627 | |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 628 | // Creates an MSAA surface to be used as an MSAA attachment on a framebuffer. |
| 629 | virtual sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions, |
| 630 | const GrBackendFormat& format, |
| 631 | int numSamples, |
Jim Van Verth | 8d59fe0 | 2021-09-20 11:48:21 -0400 | [diff] [blame] | 632 | GrProtected isProtected, |
| 633 | GrMemoryless isMemoryless) = 0; |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 634 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 635 | void handleDirtyContext() { |
| 636 | if (fResetBits) { |
| 637 | this->resetContext(); |
| 638 | } |
| 639 | } |
| 640 | |
Greg Daniel | a870b46 | 2019-01-08 15:49:46 -0500 | [diff] [blame] | 641 | virtual void storeVkPipelineCacheData() {} |
| 642 | |
Chris Dalton | e1196c5 | 2019-12-28 14:31:09 -0700 | [diff] [blame] | 643 | // http://skbug.com/9739 |
| 644 | virtual void insertManualFramebufferBarrier() { |
| 645 | SkASSERT(!this->caps()->requiresManualFBBarrierAfterTessellatedStencilDraw()); |
| 646 | SK_ABORT("Manual framebuffer barrier not supported."); |
| 647 | } |
| 648 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 649 | // Called before certain draws in order to guarantee coherent results from dst reads. |
| 650 | virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; |
| 651 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 652 | protected: |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 653 | static bool CompressedDataIsCorrect(SkISize dimensions, |
| 654 | SkImage::CompressionType, |
| 655 | GrMipmapped, |
| 656 | const void* data, |
| 657 | size_t length); |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 658 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 659 | // Handles cases where a surface will be updated without a call to flushRenderTarget. |
| 660 | void didWriteToSurface(GrSurface* surface, GrSurfaceOrigin origin, const SkIRect* bounds, |
| 661 | uint32_t mipLevels = 1) const; |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 662 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 663 | void setOOMed() { fOOMed = true; } |
| 664 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 665 | Stats fStats; |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame] | 666 | |
| 667 | // Subclass must call this to initialize caps & compiler in its constructor. |
| 668 | void initCapsAndCompiler(sk_sp<const GrCaps> caps); |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 669 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 670 | private: |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 671 | virtual GrBackendTexture onCreateBackendTexture(SkISize dimensions, |
| 672 | const GrBackendFormat&, |
| 673 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 674 | GrMipmapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 675 | GrProtected) = 0; |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 676 | |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 677 | virtual GrBackendTexture onCreateCompressedBackendTexture( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 678 | SkISize dimensions, const GrBackendFormat&, GrMipmapped, GrProtected) = 0; |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 679 | |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 680 | virtual bool onClearBackendTexture(const GrBackendTexture&, |
| 681 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 682 | std::array<float, 4> color) = 0; |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 683 | |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 684 | virtual bool onUpdateCompressedBackendTexture(const GrBackendTexture&, |
| 685 | sk_sp<GrRefCntedCallback> finishedCallback, |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 686 | const void* data, |
| 687 | size_t length) = 0; |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 688 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 689 | // called when the 3D context state is unknown. Subclass should emit any |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 690 | // assumed 3D context state and dirty any state cache. |
Robert Phillips | 15f6d74 | 2021-01-26 13:03:39 -0500 | [diff] [blame] | 691 | virtual void onResetContext(uint32_t resetBits) {} |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 692 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 693 | // Implementation of resetTextureBindings. |
| 694 | virtual void onResetTextureBindings() {} |
| 695 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 696 | // overridden by backend-specific derived class to create objects. |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 697 | // Texture size, renderablility, format support, sample count will have already been validated |
| 698 | // in base class before onCreateTexture is called. |
| 699 | // If the ith bit is set in levelClearMask then the ith MIP level should be cleared. |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 700 | virtual sk_sp<GrTexture> onCreateTexture(SkISize dimensions, |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 701 | const GrBackendFormat&, |
| 702 | GrRenderable, |
| 703 | int renderTargetSampleCnt, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 704 | SkBudgeted, |
| 705 | GrProtected, |
| 706 | int mipLevelCoont, |
| 707 | uint32_t levelClearMask) = 0; |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 708 | virtual sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 709 | const GrBackendFormat&, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 710 | SkBudgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 711 | GrMipmapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 712 | GrProtected, |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 713 | const void* data, size_t dataSize) = 0; |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 714 | virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
| 715 | GrWrapOwnership, |
| 716 | GrWrapCacheable, |
| 717 | GrIOType) = 0; |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 718 | |
| 719 | virtual sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, |
| 720 | GrWrapOwnership, |
| 721 | GrWrapCacheable) = 0; |
| 722 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 723 | virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
| 724 | int sampleCnt, |
| 725 | GrWrapOwnership, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 726 | GrWrapCacheable) = 0; |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 727 | virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0; |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 728 | virtual sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&, |
| 729 | const GrVkDrawableInfo&); |
| 730 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 731 | virtual sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, |
| 732 | GrAccessPattern, const void* data) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 733 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 734 | // overridden by backend-specific derived class to perform the surface read |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 735 | virtual bool onReadPixels(GrSurface*, |
| 736 | SkIRect, |
| 737 | GrColorType surfaceColorType, |
| 738 | GrColorType dstColorType, |
| 739 | void*, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 740 | size_t rowBytes) = 0; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 741 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 742 | // overridden by backend-specific derived class to perform the surface write |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 743 | virtual bool onWritePixels(GrSurface*, |
| 744 | SkIRect, |
| 745 | GrColorType surfaceColorType, |
| 746 | GrColorType srcColorType, |
| 747 | const GrMipLevel[], |
| 748 | int mipLevelCount, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 749 | bool prepForTexSampling) = 0; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 750 | |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 751 | // overridden by backend-specific derived class to perform the texture transfer |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 752 | virtual bool onTransferPixelsTo(GrTexture*, |
| 753 | SkIRect, |
| 754 | GrColorType textiueColorType, |
| 755 | GrColorType bufferColorType, |
| 756 | sk_sp<GrGpuBuffer> transferBuffer, |
| 757 | size_t offset, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 758 | size_t rowBytes) = 0; |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 759 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 760 | // overridden by backend-specific derived class to perform the surface transfer |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 761 | virtual bool onTransferPixelsFrom(GrSurface*, |
| 762 | SkIRect, |
| 763 | GrColorType surfaceColorType, |
| 764 | GrColorType bufferColorType, |
Greg Daniel | 5ad5a37 | 2021-02-01 13:34:04 -0500 | [diff] [blame] | 765 | sk_sp<GrGpuBuffer> transferBuffer, |
| 766 | size_t offset) = 0; |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 767 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 768 | // overridden by backend-specific derived class to perform the resolve |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 769 | virtual void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) = 0; |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 770 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 771 | // overridden by backend specific derived class to perform mip map level regeneration. |
| 772 | virtual bool onRegenerateMipMapLevels(GrTexture*) = 0; |
| 773 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 774 | // overridden by backend specific derived class to perform the copy surface |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 775 | virtual bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 776 | const SkIPoint& dstPoint) = 0; |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 777 | |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 778 | virtual GrOpsRenderPass* onGetOpsRenderPass( |
| 779 | GrRenderTarget* renderTarget, |
Chris Dalton | da2b0f4 | 2021-04-13 00:19:45 -0600 | [diff] [blame] | 780 | bool useMSAASurface, |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 781 | GrAttachment* stencil, |
| 782 | GrSurfaceOrigin, |
| 783 | const SkIRect& bounds, |
| 784 | const GrOpsRenderPass::LoadAndStoreInfo&, |
| 785 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
| 786 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 787 | GrXferBarrierFlags renderPassXferBarriers) = 0; |
| 788 | |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 789 | virtual void prepareSurfacesForBackendAccessAndStateUpdates( |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 790 | SkSpan<GrSurfaceProxy*> proxies, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 791 | SkSurface::BackendSurfaceAccess access, |
| 792 | const GrBackendSurfaceMutableState* newState) {} |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 793 | |
| 794 | virtual bool onSubmitToGpu(bool syncCpu) = 0; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 795 | |
Greg Daniel | b432754 | 2020-11-20 10:50:50 -0500 | [diff] [blame] | 796 | void reportSubmitHistograms(); |
| 797 | virtual void onReportSubmitHistograms() {} |
| 798 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 799 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 800 | virtual void onDumpJSON(SkJSONWriter*) const {} |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 801 | #endif |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 802 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 803 | sk_sp<GrTexture> createTextureCommon(SkISize, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 804 | const GrBackendFormat&, |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame] | 805 | GrTextureType textureType, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 806 | GrRenderable, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 807 | int renderTargetSampleCnt, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 808 | SkBudgeted, |
| 809 | GrProtected, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 810 | int mipLevelCnt, |
| 811 | uint32_t levelClearMask); |
| 812 | |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 813 | void resetContext() { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 814 | this->onResetContext(fResetBits); |
| 815 | fResetBits = 0; |
bsalomon@google.com | b635d39 | 2011-11-05 12:47:43 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 818 | void callSubmittedProcs(bool success); |
| 819 | |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame] | 820 | sk_sp<const GrCaps> fCaps; |
| 821 | // Compiler used for compiling SkSL into backend shader code. We only want to create the |
| 822 | // compiler once, as there is significant overhead to the first compile. |
| 823 | std::unique_ptr<SkSL::Compiler> fCompiler; |
| 824 | |
Chris Dalton | 535ba8d | 2018-02-20 09:51:59 -0700 | [diff] [blame] | 825 | uint32_t fResetBits; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 826 | // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 827 | GrDirectContext* fContext; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 828 | |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 829 | struct SubmittedProc { |
| 830 | SubmittedProc(GrGpuSubmittedProc proc, GrGpuSubmittedContext context) |
| 831 | : fProc(proc), fContext(context) {} |
| 832 | |
| 833 | GrGpuSubmittedProc fProc; |
| 834 | GrGpuSubmittedContext fContext; |
| 835 | }; |
| 836 | SkSTArray<4, SubmittedProc> fSubmittedProcs; |
| 837 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 838 | bool fOOMed = false; |
| 839 | |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 840 | #if SK_HISTOGRAMS_ENABLED |
| 841 | int fCurrentSubmitRenderPassCount = 0; |
| 842 | #endif |
| 843 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 844 | friend class GrPathRendering; |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 845 | using INHERITED = SkRefCnt; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 846 | }; |
| 847 | |
| 848 | #endif |