bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2013 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 8 | #ifndef GrCaps_DEFINED |
| 9 | #define GrCaps_DEFINED |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkImageInfo.h" |
| 12 | #include "include/core/SkRefCnt.h" |
| 13 | #include "include/core/SkString.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/gpu/GrDriverBugWorkarounds.h" |
| 15 | #include "include/private/GrTypesPriv.h" |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 16 | #include "src/core/SkCompressedDataUtils.h" |
Brian Salomon | 096b091 | 2019-08-14 16:56:13 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrBlend.h" |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrSamplerState.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrShaderCaps.h" |
Brian Salomon | 1e03b6b1 | 2019-07-17 17:28:24 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrSurfaceProxy.h" |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 21 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 22 | class GrBackendFormat; |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 23 | class GrBackendRenderTarget; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 24 | class GrBackendTexture; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 25 | struct GrContextOptions; |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 26 | class GrProcessorKeyBuilder; |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 27 | class GrProgramDesc; |
| 28 | class GrProgramInfo; |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 29 | class GrRenderTargetProxy; |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 30 | class GrSurface; |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 31 | class SkJSONWriter; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 34 | * Represents the capabilities of a GrContext. |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 35 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 36 | class GrCaps : public SkRefCnt { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 37 | public: |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 38 | GrCaps(const GrContextOptions&); |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 39 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 40 | void dumpJSON(SkJSONWriter*) const; |
| 41 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 42 | const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); } |
Robert Phillips | 7f11fb5 | 2019-12-03 13:35:19 -0500 | [diff] [blame] | 43 | sk_sp<const GrShaderCaps> refShaderCaps() const { return fShaderCaps; } |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 44 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 45 | bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; } |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 46 | /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g. |
| 47 | only for POT textures) */ |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 48 | bool mipmapSupport() const { return fMipmapSupport; } |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 49 | |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 50 | bool gpuTracingSupport() const { return fGpuTracingSupport; } |
Greg Daniel | 28bea44 | 2021-06-25 15:06:15 +0000 | [diff] [blame] | 51 | bool oversizedStencilSupport() const { return fOversizedStencilSupport; } |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 52 | bool textureBarrierSupport() const { return fTextureBarrierSupport; } |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 53 | bool sampleLocationsSupport() const { return fSampleLocationsSupport; } |
csmartdalton | 2b5f2cb | 2016-06-10 14:06:32 -0700 | [diff] [blame] | 54 | bool multisampleDisableSupport() const { return fMultisampleDisableSupport; } |
Chris Dalton | a77cdee | 2020-04-03 14:50:43 -0600 | [diff] [blame] | 55 | bool drawInstancedSupport() const { return fDrawInstancedSupport; } |
Chris Dalton | 03fdf6a | 2020-04-07 12:31:59 -0600 | [diff] [blame] | 56 | // Is there hardware support for indirect draws? (Ganesh always supports indirect draws as long |
| 57 | // as it can polyfill them with instanced calls, but this cap tells us if they are supported |
| 58 | // natively.) |
| 59 | bool nativeDrawIndirectSupport() const { return fNativeDrawIndirectSupport; } |
Chris Dalton | bde4bb7 | 2020-07-17 14:11:04 -0600 | [diff] [blame] | 60 | bool useClientSideIndirectBuffers() const { |
| 61 | #ifdef SK_DEBUG |
| 62 | if (!fNativeDrawIndirectSupport || fNativeDrawIndexedIndirectIsBroken) { |
| 63 | // We might implement indirect draws with a polyfill, so the commands need to reside in |
| 64 | // CPU memory. |
| 65 | SkASSERT(fUseClientSideIndirectBuffers); |
| 66 | } |
| 67 | #endif |
| 68 | return fUseClientSideIndirectBuffers; |
| 69 | } |
Chris Dalton | ce425af | 2019-12-16 10:39:03 -0700 | [diff] [blame] | 70 | bool conservativeRasterSupport() const { return fConservativeRasterSupport; } |
Chris Dalton | 1215cda | 2019-12-17 21:44:04 -0700 | [diff] [blame] | 71 | bool wireframeSupport() const { return fWireframeSupport; } |
Chris Dalton | d5d8a64 | 2019-08-08 15:29:20 -0600 | [diff] [blame] | 72 | // This flag indicates that we never have to resolve MSAA. In practice, it means that we have |
| 73 | // an MSAA-render-to-texture extension: Any render target we create internally will use the |
| 74 | // extension, and any wrapped render target is the client's responsibility. |
| 75 | bool msaaResolvesAutomatically() const { return fMSAAResolvesAutomatically; } |
Brian Osman | 499bf1a | 2018-09-17 11:32:42 -0400 | [diff] [blame] | 76 | bool halfFloatVertexAttributeSupport() const { return fHalfFloatVertexAttributeSupport; } |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 77 | |
| 78 | // Primitive restart functionality is core in ES 3.0, but using it will cause slowdowns on some |
| 79 | // systems. This cap is only set if primitive restart will improve performance. |
| 80 | bool usePrimitiveRestart() const { return fUsePrimitiveRestart; } |
| 81 | |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 82 | bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; } |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 83 | |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 84 | // On tilers, an initial fullscreen clear is an OPTIMIZATION. It allows the hardware to |
| 85 | // initialize each tile with a constant value rather than loading each pixel from memory. |
| 86 | bool preferFullscreenClears() const { return fPreferFullscreenClears; } |
| 87 | |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 88 | // Should we discard stencil values after a render pass? (Tilers get better performance if we |
| 89 | // always load stencil buffers with a "clear" op, and then discard the content when finished.) |
| 90 | bool discardStencilValuesAfterRenderPass() const { |
Chris Dalton | a8b1636 | 2020-07-17 17:38:54 -0700 | [diff] [blame] | 91 | // b/160958008 |
| 92 | return false; |
| 93 | #if 0 |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 94 | // This method is actually just a duplicate of preferFullscreenClears(), with a descriptive |
| 95 | // name for the sake of readability. |
| 96 | return this->preferFullscreenClears(); |
Chris Dalton | a8b1636 | 2020-07-17 17:38:54 -0700 | [diff] [blame] | 97 | #endif |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 98 | } |
| 99 | |
Chris Dalton | 3d28b6a | 2020-04-13 11:12:28 -0600 | [diff] [blame] | 100 | // D3D does not allow the refs or masks to differ on a two-sided stencil draw. |
| 101 | bool twoSidedStencilRefsAndMasksMustMatch() const { |
| 102 | return fTwoSidedStencilRefsAndMasksMustMatch; |
| 103 | } |
| 104 | |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 105 | bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; } |
| 106 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 107 | bool avoidStencilBuffers() const { return fAvoidStencilBuffers; } |
| 108 | |
Greg Daniel | 4374e96 | 2018-09-28 15:09:47 -0400 | [diff] [blame] | 109 | bool avoidWritePixelsFastPath() const { return fAvoidWritePixelsFastPath; } |
| 110 | |
Chris Dalton | e1196c5 | 2019-12-28 14:31:09 -0700 | [diff] [blame] | 111 | // http://skbug.com/9739 |
| 112 | bool requiresManualFBBarrierAfterTessellatedStencilDraw() const { |
| 113 | return fRequiresManualFBBarrierAfterTessellatedStencilDraw; |
| 114 | } |
| 115 | |
Chris Dalton | 03fdf6a | 2020-04-07 12:31:59 -0600 | [diff] [blame] | 116 | // glDrawElementsIndirect fails GrMeshTest on every Win10 Intel bot. |
| 117 | bool nativeDrawIndexedIndirectIsBroken() const { return fNativeDrawIndexedIndirectIsBroken; } |
| 118 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 119 | /** |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 120 | * Indicates the capabilities of the fixed function blend unit. |
| 121 | */ |
| 122 | enum BlendEquationSupport { |
| 123 | kBasic_BlendEquationSupport, //<! Support to select the operator that |
| 124 | // combines src and dst terms. |
| 125 | kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific |
| 126 | // SVG/PDF blend modes. Requires blend barriers. |
| 127 | kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not |
| 128 | // require blend barriers, and permits overlap. |
| 129 | |
| 130 | kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport |
| 131 | }; |
| 132 | |
| 133 | BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; } |
| 134 | |
| 135 | bool advancedBlendEquationSupport() const { |
| 136 | return fBlendEquationSupport >= kAdvanced_BlendEquationSupport; |
| 137 | } |
| 138 | |
| 139 | bool advancedCoherentBlendEquationSupport() const { |
| 140 | return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport; |
| 141 | } |
| 142 | |
Jim Van Verth | 1bef979 | 2020-07-09 08:09:13 -0400 | [diff] [blame] | 143 | bool isAdvancedBlendEquationDisabled(GrBlendEquation equation) const { |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 144 | SkASSERT(GrBlendEquationIsAdvanced(equation)); |
Chris Dalton | 302d5be | 2019-01-22 23:41:25 -0700 | [diff] [blame] | 145 | SkASSERT(this->advancedBlendEquationSupport()); |
Jim Van Verth | 1bef979 | 2020-07-09 08:09:13 -0400 | [diff] [blame] | 146 | return SkToBool(fAdvBlendEqDisableFlags & (1 << equation)); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Greg Daniel | f6d60d3 | 2020-01-08 13:39:16 -0500 | [diff] [blame] | 149 | // On some GPUs it is a performance win to disable blending instead of doing src-over with a src |
| 150 | // alpha equal to 1. To disable blending we collapse src-over to src and the backends will |
| 151 | // handle the disabling of blending. |
| 152 | bool shouldCollapseSrcOverToSrcWhenAble() const { |
| 153 | return fShouldCollapseSrcOverToSrcWhenAble; |
| 154 | } |
| 155 | |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame] | 156 | // When abandoning the GrDirectContext do we need to sync the GPU before we start abandoning |
| 157 | // resources. |
| 158 | bool mustSyncGpuDuringAbandon() const { |
| 159 | return fMustSyncGpuDuringAbandon; |
| 160 | } |
| 161 | |
Brian Salomon | e9f2265 | 2021-04-12 11:18:32 -0400 | [diff] [blame] | 162 | // Shortcut for shaderCaps()->reducedShaderMode(). |
| 163 | bool reducedShaderMode() const { return this->shaderCaps()->reducedShaderMode(); } |
Brian Salomon | 91216d5 | 2021-04-09 11:57:59 -0400 | [diff] [blame] | 164 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 165 | /** |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 166 | * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and |
| 167 | * textures allows partial mappings or full mappings. |
| 168 | */ |
| 169 | enum MapFlags { |
Brian Salomon | 105d7c2 | 2019-04-16 13:46:14 -0400 | [diff] [blame] | 170 | kNone_MapFlags = 0x0, //<! Cannot map the resource. |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 171 | |
Brian Salomon | 105d7c2 | 2019-04-16 13:46:14 -0400 | [diff] [blame] | 172 | kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of |
| 173 | // the other flags to have meaning. |
| 174 | kSubset_MapFlag = 0x2, //<! The resource can be partially mapped. |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 175 | kAsyncRead_MapFlag = 0x4, //<! Are maps for reading asynchronous WRT GrOpsRenderPass |
Brian Salomon | 105d7c2 | 2019-04-16 13:46:14 -0400 | [diff] [blame] | 176 | // submitted to GrGpu. |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
Greg Daniel | 5af72c1 | 2021-02-08 13:52:08 -0500 | [diff] [blame] | 179 | // This returns the general mapping support for the GPU. However, even if this returns a flag |
| 180 | // that says buffers can be mapped, it does NOT mean that every buffer will be mappable. Thus |
| 181 | // calls of map should still check to see if a valid pointer was returned from the map call and |
| 182 | // handle fallbacks appropriately. If this does return kNone_MapFlags then all calls to map() on |
| 183 | // any buffer will fail. |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 184 | uint32_t mapBufferFlags() const { return fMapBufferFlags; } |
| 185 | |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 186 | // Scratch textures not being reused means that those scratch textures |
skia.committer@gmail.com | 7ed98df | 2013-10-31 07:01:53 +0000 | [diff] [blame] | 187 | // that we upload to (i.e., don't have a render target) will not be |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 188 | // recycled in the texture cache. This is to prevent ghosting by drivers |
| 189 | // (in particular for deferred architectures). |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 190 | bool reuseScratchTextures() const { return fReuseScratchTextures; } |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 191 | bool reuseScratchBuffers() const { return fReuseScratchBuffers; } |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 192 | |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 193 | /// maximum number of attribute values per vertex |
| 194 | int maxVertexAttributes() const { return fMaxVertexAttributes; } |
| 195 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 196 | int maxRenderTargetSize() const { return fMaxRenderTargetSize; } |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 197 | |
| 198 | /** This is the largest render target size that can be used without incurring extra perfomance |
| 199 | cost. It is usually the max RT size, unless larger render targets are known to be slower. */ |
| 200 | int maxPreferredRenderTargetSize() const { return fMaxPreferredRenderTargetSize; } |
| 201 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 202 | int maxTextureSize() const { return fMaxTextureSize; } |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 203 | |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 204 | int maxWindowRectangles() const { return fMaxWindowRectangles; } |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 205 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 206 | // Returns whether window rectangles are supported for the given backend render target. |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 207 | bool isWindowRectanglesSupportedForRT(const GrBackendRenderTarget& rt) const { |
| 208 | return this->maxWindowRectangles() > 0 && this->onIsWindowRectanglesSupportedForRT(rt); |
| 209 | } |
| 210 | |
Chris Dalton | 569c01b | 2021-05-25 10:11:46 -0600 | [diff] [blame] | 211 | // Hardware tessellation seems to have a fixed upfront cost. If there is a somewhat small number |
| 212 | // of verbs, we seem to be faster emulating tessellation with instanced draws instead. |
| 213 | int minPathVerbsForHwTessellation() const { return fMinPathVerbsForHwTessellation; } |
| 214 | int minStrokeVerbsForHwTessellation() const { return fMinStrokeVerbsForHwTessellation; } |
| 215 | |
Jim Van Verth | 023f2e7 | 2020-10-09 15:38:58 -0400 | [diff] [blame] | 216 | uint32_t maxPushConstantsSize() const { return fMaxPushConstantsSize; } |
Jim Van Verth | 4b3d1f3 | 2020-10-08 15:46:36 -0400 | [diff] [blame] | 217 | |
Jim Van Verth | a655f0d | 2021-05-18 15:03:27 -0400 | [diff] [blame] | 218 | size_t transferBufferAlignment() const { return fTransferBufferAlignment; } |
| 219 | |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 220 | virtual bool isFormatSRGB(const GrBackendFormat&) const = 0; |
Greg Daniel | a00bcad | 2019-10-11 13:21:48 -0400 | [diff] [blame] | 221 | |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 222 | bool isFormatCompressed(const GrBackendFormat& format) const; |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 223 | |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame^] | 224 | // Can a texture be made with the GrBackendFormat and texture type, and then be bound and |
| 225 | // sampled in a shader. |
| 226 | virtual bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const = 0; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 227 | |
Greg Daniel | 6980c4e | 2019-07-30 16:18:18 -0400 | [diff] [blame] | 228 | // Returns whether a texture of the given format can be copied to a texture of the same format. |
| 229 | virtual bool isFormatCopyable(const GrBackendFormat&) const = 0; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 230 | |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 231 | // Returns the maximum supported sample count for a format. 0 means the format is not renderable |
Brian Salomon | 469046c | 2020-03-30 14:21:04 -0400 | [diff] [blame] | 232 | // 1 means the format is renderable but doesn't support MSAA. |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 233 | virtual int maxRenderTargetSampleCount(const GrBackendFormat&) const = 0; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 234 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 235 | // Returns the number of samples to use when performing draws to the given config with internal |
| 236 | // MSAA. If 0, Ganesh should not attempt to use internal multisampling. |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 237 | int internalMultisampleCount(const GrBackendFormat& format) const { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 238 | return std::min(fInternalMultisampleCount, this->maxRenderTargetSampleCount(format)); |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 239 | } |
| 240 | |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 241 | virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, |
| 242 | int sampleCount = 1) const = 0; |
| 243 | |
| 244 | virtual bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const = 0; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 245 | |
| 246 | // Find a sample count greater than or equal to the requested count which is supported for a |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 247 | // render target of the given format or 0 if no such sample count is supported. If the requested |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 248 | // sample count is 1 then 1 will be returned if non-MSAA rendering is supported, otherwise 0. |
| 249 | // For historical reasons requestedCount==0 is handled identically to requestedCount==1. |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 250 | virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const = 0; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 251 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 252 | /** |
Brian Salomon | 3d86a19 | 2018-02-27 16:46:11 -0500 | [diff] [blame] | 253 | * Backends may have restrictions on what types of surfaces support GrGpu::writePixels(). |
| 254 | * If this returns false then the caller should implement a fallback where a temporary texture |
| 255 | * is created, pixels are written to it, and then that is copied or drawn into the the surface. |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 256 | */ |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 257 | bool surfaceSupportsWritePixels(const GrSurface*) const; |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 258 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 259 | /** |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 260 | * Indicates whether surface supports GrGpu::readPixels, must be copied, or cannot be read. |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 261 | */ |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 262 | enum class SurfaceReadPixelsSupport { |
| 263 | /** GrGpu::readPixels is supported by the surface. */ |
| 264 | kSupported, |
| 265 | /** |
| 266 | * GrGpu::readPixels is not supported by this surface but this surface can be drawn |
| 267 | * or copied to a Ganesh-created GrTextureType::kTexture2D and then that surface will be |
| 268 | * readable. |
| 269 | */ |
| 270 | kCopyToTexture2D, |
| 271 | /** |
| 272 | * Not supported |
| 273 | */ |
| 274 | kUnsupported, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 275 | }; |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 276 | /** |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 277 | * Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). We may |
| 278 | * either be able to read directly from the surface, read from a copy of the surface, or not |
| 279 | * read at all. |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 280 | */ |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 281 | virtual SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const = 0; |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 282 | |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 283 | struct SupportedWrite { |
| 284 | GrColorType fColorType; |
| 285 | // If the write is occurring using GrGpu::transferPixelsTo then this provides the |
| 286 | // minimum alignment of the offset into the transfer buffer. |
| 287 | size_t fOffsetAlignmentForTransferBuffer; |
| 288 | }; |
| 289 | |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 290 | /** |
| 291 | * Given a dst pixel config and a src color type what color type must the caller coax the |
| 292 | * the data into in order to use GrGpu::writePixels(). |
| 293 | */ |
Brian Salomon | 01915c0 | 2019-08-02 09:57:21 -0400 | [diff] [blame] | 294 | virtual SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, |
| 295 | const GrBackendFormat& surfaceFormat, |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 296 | GrColorType srcColorType) const = 0; |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 297 | |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 298 | struct SupportedRead { |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 299 | GrColorType fColorType; |
Brian Salomon | 42be09d | 2019-07-26 12:12:26 -0400 | [diff] [blame] | 300 | // If the read is occurring using GrGpu::transferPixelsFrom then this provides the |
| 301 | // minimum alignment of the offset into the transfer buffer. |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 302 | size_t fOffsetAlignmentForTransferBuffer; |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 303 | }; |
| 304 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 305 | /** |
Greg Daniel | 00fb724 | 2019-07-18 14:28:01 -0400 | [diff] [blame] | 306 | * Given a src surface's color type and its backend format as well as a color type the caller |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 307 | * would like read into, this provides a legal color type that the caller may pass to |
| 308 | * GrGpu::readPixels(). The returned color type may differ from the passed dstColorType, in |
| 309 | * which case the caller must convert the read pixel data (see GrConvertPixels). When converting |
| 310 | * to dstColorType the swizzle in the returned struct should be applied. The caller must check |
| 311 | * the returned color type for kUnknown. |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 312 | */ |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 313 | SupportedRead supportedReadPixelsColorType(GrColorType srcColorType, |
| 314 | const GrBackendFormat& srcFormat, |
| 315 | GrColorType dstColorType) const; |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 316 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 317 | /** |
Brian Salomon | dc03537 | 2021-06-07 13:39:27 -0400 | [diff] [blame] | 318 | * Does GrGpu::writePixels() support a src buffer where the row bytes is not equal to bpp * w? |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 319 | */ |
| 320 | bool writePixelsRowBytesSupport() const { return fWritePixelsRowBytesSupport; } |
Brian Salomon | dc03537 | 2021-06-07 13:39:27 -0400 | [diff] [blame] | 321 | |
| 322 | /** |
| 323 | * Does GrGpu::transferPixelsTo() support a src buffer where the row bytes is not equal to |
| 324 | * bpp * w? |
| 325 | */ |
| 326 | bool transferPixelsToRowBytesSupport() const { return fTransferPixelsToRowBytesSupport; } |
| 327 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 328 | /** |
| 329 | * Does GrGpu::readPixels() support a dst buffer where the row bytes is not equal to bpp * w? |
| 330 | */ |
| 331 | bool readPixelsRowBytesSupport() const { return fReadPixelsRowBytesSupport; } |
| 332 | |
Brian Salomon | fb28c6f | 2020-01-10 13:04:45 -0500 | [diff] [blame] | 333 | bool transferFromSurfaceToBufferSupport() const { return fTransferFromSurfaceToBufferSupport; } |
| 334 | bool transferFromBufferToTextureSupport() const { return fTransferFromBufferToTextureSupport; } |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 335 | |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 336 | bool suppressPrints() const { return fSuppressPrints; } |
| 337 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 338 | size_t bufferMapThreshold() const { |
| 339 | SkASSERT(fBufferMapThreshold >= 0); |
| 340 | return fBufferMapThreshold; |
joshualitt | 7224c86 | 2015-05-29 06:46:47 -0700 | [diff] [blame] | 341 | } |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 342 | |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 343 | /** True in environments that will issue errors if memory uploaded to buffers |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 344 | is not initialized (even if not read by draw calls). */ |
| 345 | bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; } |
| 346 | |
Kevin Lubick | 61a5f0a | 2019-03-28 09:47:15 -0400 | [diff] [blame] | 347 | /** For some environments, there is a performance or safety concern to not |
| 348 | initializing textures. For example, with WebGL and Firefox, there is a large |
| 349 | performance hit to not doing it. |
| 350 | */ |
| 351 | bool shouldInitializeTextures() const { return fShouldInitializeTextures; } |
| 352 | |
Greg Daniel | b2acf0a | 2018-09-12 09:17:11 -0400 | [diff] [blame] | 353 | /** Returns true if the given backend supports importing AHardwareBuffers via the |
| 354 | * GrAHardwarebufferImageGenerator. This will only ever be supported on Android devices with API |
| 355 | * level >= 26. |
| 356 | * */ |
| 357 | bool supportsAHardwareBufferImages() const { return fSupportsAHardwareBufferImages; } |
| 358 | |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 359 | bool wireframeMode() const { return fWireframeMode; } |
| 360 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 361 | /** Supports using GrFence. */ |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 362 | bool fenceSyncSupport() const { return fFenceSyncSupport; } |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 363 | |
| 364 | /** Supports using GrSemaphore. */ |
| 365 | bool semaphoreSupport() const { return fSemaphoreSupport; } |
| 366 | |
Brian Osman | 2c2bc11 | 2017-02-28 10:02:49 -0500 | [diff] [blame] | 367 | bool crossContextTextureSupport() const { return fCrossContextTextureSupport; } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 368 | /** |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 369 | * Returns whether or not we will be able to do a copy given the passed in params |
| 370 | */ |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 371 | bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 372 | const SkIRect& srcRect, const SkIPoint& dstPoint) const; |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 373 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 374 | bool dynamicStateArrayGeometryProcessorTextureSupport() const { |
| 375 | return fDynamicStateArrayGeometryProcessorTextureSupport; |
| 376 | } |
| 377 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 378 | // Not all backends support clearing with a scissor test (e.g. Metal), this will always |
| 379 | // return true if performColorClearsAsDraws() returns true. |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 380 | bool performPartialClearsAsDraws() const { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 381 | return fPerformColorClearsAsDraws || fPerformPartialClearsAsDraws; |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | // Many drivers have issues with color clears. |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 385 | bool performColorClearsAsDraws() const { return fPerformColorClearsAsDraws; } |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 386 | |
Robert Phillips | 2f05a48 | 2019-11-25 09:54:43 -0500 | [diff] [blame] | 387 | bool avoidLargeIndexBufferDraws() const { return fAvoidLargeIndexBufferDraws; } |
| 388 | |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 389 | /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit |
| 390 | /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil |
| 391 | /// op instead of using glClear seems to resolve the issue. |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 392 | bool performStencilClearsAsDraws() const { return fPerformStencilClearsAsDraws; } |
| 393 | |
Chris Dalton | 9431079 | 2021-03-12 11:10:24 -0700 | [diff] [blame] | 394 | // Should we disable the clip mask atlas due to a faulty driver? |
| 395 | bool driverDisableMSAAClipAtlas() const { return fDriverDisableMSAAClipAtlas; } |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 396 | |
Chris Dalton | eae5c16 | 2020-12-29 10:18:21 -0700 | [diff] [blame] | 397 | // Should we disable GrTessellationPathRenderer due to a faulty driver? |
| 398 | bool disableTessellationPathRenderer() const { return fDisableTessellationPathRenderer; } |
| 399 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 400 | // Returns how to sample the dst values for the passed in GrRenderTargetProxy. |
Greg Daniel | 0b04b6b | 2021-06-24 19:19:00 -0400 | [diff] [blame] | 401 | GrDstSampleFlags getDstSampleFlagsForProxy(const GrRenderTargetProxy*, bool drawUsesMSAA) const; |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 402 | |
Greg Daniel | 25af671 | 2018-04-25 10:44:38 -0400 | [diff] [blame] | 403 | /** |
Brian Salomon | 1e03b6b1 | 2019-07-17 17:28:24 -0400 | [diff] [blame] | 404 | * This is used to try to ensure a successful copy a dst in order to perform shader-based |
| 405 | * blending. |
| 406 | * |
| 407 | * fRectsMustMatch will be set to true if the copy operation must ensure that the src and dest |
| 408 | * rects are identical. |
| 409 | * |
| 410 | * fMustCopyWholeSrc will be set to true if copy rect must equal src's bounds. |
| 411 | * |
| 412 | * Caller will detect cases when copy cannot succeed and try copy-as-draw as a fallback. |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 413 | */ |
Brian Salomon | 1e03b6b1 | 2019-07-17 17:28:24 -0400 | [diff] [blame] | 414 | struct DstCopyRestrictions { |
| 415 | GrSurfaceProxy::RectsMustMatch fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kNo; |
| 416 | bool fMustCopyWholeSrc = false; |
| 417 | }; |
Greg Daniel | 0258c90 | 2019-08-01 13:08:33 -0400 | [diff] [blame] | 418 | virtual DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src, |
| 419 | GrColorType ct) const { |
Brian Salomon | 1e03b6b1 | 2019-07-17 17:28:24 -0400 | [diff] [blame] | 420 | return {}; |
| 421 | } |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 422 | |
Greg Daniel | 9a48beb | 2020-01-16 16:57:16 -0500 | [diff] [blame] | 423 | bool validateSurfaceParams(const SkISize&, const GrBackendFormat&, GrRenderable renderable, |
Greg Daniel | 0e9d34d | 2021-08-13 16:20:18 -0400 | [diff] [blame^] | 424 | int renderTargetSampleCnt, GrMipmapped, GrTextureType) const; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 425 | |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 426 | bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat& format) const; |
Robert Phillips | c046ff0 | 2019-07-01 10:34:03 -0400 | [diff] [blame] | 427 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 428 | /** These are used when creating a new texture internally. */ |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 429 | GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 430 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 431 | virtual GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const = 0; |
| 432 | |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 433 | /** |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 434 | * The CLAMP_TO_BORDER wrap mode for texture coordinates was added to desktop GL in 1.3, and |
| 435 | * GLES 3.2, but is also available in extensions. Vulkan and Metal always have support. |
| 436 | */ |
| 437 | bool clampToBorderSupport() const { return fClampToBorderSupport; } |
| 438 | |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 439 | /** |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 440 | * Returns the GrSwizzle to use when sampling or reading back from a texture with the passed in |
| 441 | * GrBackendFormat and GrColorType. |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 442 | */ |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 443 | GrSwizzle getReadSwizzle(const GrBackendFormat& format, GrColorType colorType) const; |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 444 | |
| 445 | /** |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 446 | * Returns the GrSwizzle to use when writing colors to a surface with the passed in |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 447 | * GrBackendFormat and GrColorType. |
| 448 | */ |
Brian Salomon | 982f546 | 2020-03-30 12:52:33 -0400 | [diff] [blame] | 449 | virtual GrSwizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const = 0; |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 450 | |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 451 | virtual uint64_t computeFormatKey(const GrBackendFormat&) const = 0; |
| 452 | |
Adrienne Walker | 3ed3399 | 2018-05-15 11:44:34 -0700 | [diff] [blame] | 453 | const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; } |
| 454 | |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 455 | /** |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 456 | * Adds fields to the key to represent the sampler that will be created for the passed |
| 457 | * in parameters. Currently this extra keying is only needed when building a vulkan pipeline |
| 458 | * with immutable samplers. |
| 459 | */ |
| 460 | virtual void addExtraSamplerKey(GrProcessorKeyBuilder*, |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 461 | GrSamplerState, |
Robert Phillips | 323471e | 2019-11-11 11:33:37 -0500 | [diff] [blame] | 462 | const GrBackendFormat&) const {} |
| 463 | |
Greg Daniel | 91b37b1 | 2021-01-05 15:40:54 -0500 | [diff] [blame] | 464 | enum class ProgramDescOverrideFlags { |
| 465 | kNone = 0, |
| 466 | // If using discardable msaa surfaces in vulkan, when we break up a render pass for an |
| 467 | // inline upload, we must do a load msaa subpass for the second render pass. However, if the |
| 468 | // original render pass did not have this load subpass (e.g. clear or discard load op), then |
| 469 | // all the GrProgramInfos for draws that end up in the second render pass will have been |
| 470 | // recorded thinking they will be in a render pass with only 1 subpass. Thus we add an |
| 471 | // override flag to the makeDesc call to force the actually VkPipeline that gets created to |
| 472 | // be created using a render pass with 2 subpasses. We do miss on the pre-compile with this |
| 473 | // approach, but inline uploads are very rare and already slow. |
| 474 | kVulkanHasResolveLoadSubpass = 0x1, |
| 475 | }; |
| 476 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(ProgramDescOverrideFlags); |
| 477 | |
| 478 | |
| 479 | virtual GrProgramDesc makeDesc( |
| 480 | GrRenderTarget*, const GrProgramInfo&, |
| 481 | ProgramDescOverrideFlags overrideFlags = ProgramDescOverrideFlags::kNone) const = 0; |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 482 | |
Greg Daniel | 638b2e8 | 2020-08-27 14:29:00 -0400 | [diff] [blame] | 483 | // This method specifies, for each backend, the extra properties of a RT when Ganesh creates one |
| 484 | // internally. For example, for Vulkan, Ganesh always creates RTs that can be used as input |
| 485 | // attachments. |
| 486 | virtual GrInternalSurfaceFlags getExtraSurfaceFlagsForDeferredRT() const { |
| 487 | return GrInternalSurfaceFlags::kNone; |
| 488 | } |
| 489 | |
Chris Dalton | 710e1c9 | 2021-04-23 13:07:52 -0600 | [diff] [blame] | 490 | bool supportsDynamicMSAA(const GrRenderTargetProxy*) const; |
| 491 | |
Adlai Holler | 75b43ce | 2021-05-03 11:37:24 -0400 | [diff] [blame] | 492 | // skbug.com/11935. Task reordering is disabled for some GPUs on GL due to driver bugs. |
| 493 | bool avoidReorderingRenderTasks() const { |
| 494 | return fAvoidReorderingRenderTasks; |
| 495 | } |
| 496 | |
Robert Phillips | 0e741e2 | 2021-08-05 15:34:15 -0400 | [diff] [blame] | 497 | bool avoidDithering() const { |
| 498 | return fAvoidDithering; |
| 499 | } |
| 500 | |
Robert Phillips | 87b57fa | 2021-06-08 13:10:04 -0400 | [diff] [blame] | 501 | /** |
| 502 | * Checks whether the passed color type is renderable. If so, the same color type is passed |
| 503 | * back along with the default format used for the color type. If not, provides an alternative |
| 504 | * (perhaps lower bit depth and/or unorm instead of float) color type that is supported |
| 505 | * along with it's default format or kUnknown if there no renderable fallback format. |
| 506 | */ |
| 507 | std::tuple<GrColorType, GrBackendFormat> getFallbackColorTypeAndFormat(GrColorType, |
| 508 | int sampleCount) const; |
| 509 | |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 510 | #if GR_TEST_UTILS |
| 511 | struct TestFormatColorTypeCombination { |
| 512 | GrColorType fColorType; |
| 513 | GrBackendFormat fFormat; |
| 514 | }; |
| 515 | |
| 516 | virtual std::vector<TestFormatColorTypeCombination> getTestingCombinations() const = 0; |
| 517 | #endif |
| 518 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 519 | protected: |
Chris Dalton | 8367e11 | 2019-11-13 12:43:21 -0700 | [diff] [blame] | 520 | // Subclasses must call this at the end of their init method in order to do final processing on |
| 521 | // the caps (including overrides requested by the client). |
| 522 | // NOTE: this method will only reduce the caps, never expand them. |
| 523 | void finishInitialization(const GrContextOptions& options); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 524 | |
Chris Dalton | 710e1c9 | 2021-04-23 13:07:52 -0600 | [diff] [blame] | 525 | virtual bool onSupportsDynamicMSAA(const GrRenderTargetProxy*) const { return false; } |
| 526 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 527 | sk_sp<GrShaderCaps> fShaderCaps; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 528 | |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 529 | bool fNPOTTextureTileSupport : 1; |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 530 | bool fMipmapSupport : 1; |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 531 | bool fReuseScratchTextures : 1; |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 532 | bool fReuseScratchBuffers : 1; |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 533 | bool fGpuTracingSupport : 1; |
Greg Daniel | 28bea44 | 2021-06-25 15:06:15 +0000 | [diff] [blame] | 534 | bool fOversizedStencilSupport : 1; |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 535 | bool fTextureBarrierSupport : 1; |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 536 | bool fSampleLocationsSupport : 1; |
csmartdalton | 2b5f2cb | 2016-06-10 14:06:32 -0700 | [diff] [blame] | 537 | bool fMultisampleDisableSupport : 1; |
Chris Dalton | a77cdee | 2020-04-03 14:50:43 -0600 | [diff] [blame] | 538 | bool fDrawInstancedSupport : 1; |
Chris Dalton | 03fdf6a | 2020-04-07 12:31:59 -0600 | [diff] [blame] | 539 | bool fNativeDrawIndirectSupport : 1; |
Chris Dalton | bde4bb7 | 2020-07-17 14:11:04 -0600 | [diff] [blame] | 540 | bool fUseClientSideIndirectBuffers : 1; |
Chris Dalton | ce425af | 2019-12-16 10:39:03 -0700 | [diff] [blame] | 541 | bool fConservativeRasterSupport : 1; |
Chris Dalton | 1215cda | 2019-12-17 21:44:04 -0700 | [diff] [blame] | 542 | bool fWireframeSupport : 1; |
Chris Dalton | d5d8a64 | 2019-08-08 15:29:20 -0600 | [diff] [blame] | 543 | bool fMSAAResolvesAutomatically : 1; |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 544 | bool fUsePrimitiveRestart : 1; |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 545 | bool fPreferClientSideDynamicBuffers : 1; |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 546 | bool fPreferFullscreenClears : 1; |
Chris Dalton | 3d28b6a | 2020-04-13 11:12:28 -0600 | [diff] [blame] | 547 | bool fTwoSidedStencilRefsAndMasksMustMatch : 1; |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 548 | bool fMustClearUploadedBufferData : 1; |
Kevin Lubick | 61a5f0a | 2019-03-28 09:47:15 -0400 | [diff] [blame] | 549 | bool fShouldInitializeTextures : 1; |
Greg Daniel | b2acf0a | 2018-09-12 09:17:11 -0400 | [diff] [blame] | 550 | bool fSupportsAHardwareBufferImages : 1; |
Brian Osman | 499bf1a | 2018-09-17 11:32:42 -0400 | [diff] [blame] | 551 | bool fHalfFloatVertexAttributeSupport : 1; |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 552 | bool fClampToBorderSupport : 1; |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 553 | bool fPerformPartialClearsAsDraws : 1; |
| 554 | bool fPerformColorClearsAsDraws : 1; |
Robert Phillips | 2f05a48 | 2019-11-25 09:54:43 -0500 | [diff] [blame] | 555 | bool fAvoidLargeIndexBufferDraws : 1; |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 556 | bool fPerformStencilClearsAsDraws : 1; |
Brian Salomon | fb28c6f | 2020-01-10 13:04:45 -0500 | [diff] [blame] | 557 | bool fTransferFromBufferToTextureSupport : 1; |
| 558 | bool fTransferFromSurfaceToBufferSupport : 1; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 559 | bool fWritePixelsRowBytesSupport : 1; |
Brian Salomon | dc03537 | 2021-06-07 13:39:27 -0400 | [diff] [blame] | 560 | bool fTransferPixelsToRowBytesSupport : 1; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 561 | bool fReadPixelsRowBytesSupport : 1; |
Greg Daniel | f6d60d3 | 2020-01-08 13:39:16 -0500 | [diff] [blame] | 562 | bool fShouldCollapseSrcOverToSrcWhenAble : 1; |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame] | 563 | bool fMustSyncGpuDuringAbandon : 1; |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 564 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 565 | // Driver workaround |
Chris Dalton | 9431079 | 2021-03-12 11:10:24 -0700 | [diff] [blame] | 566 | bool fDriverDisableMSAAClipAtlas : 1; |
Chris Dalton | eae5c16 | 2020-12-29 10:18:21 -0700 | [diff] [blame] | 567 | bool fDisableTessellationPathRenderer : 1; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 568 | bool fAvoidStencilBuffers : 1; |
Greg Daniel | 4374e96 | 2018-09-28 15:09:47 -0400 | [diff] [blame] | 569 | bool fAvoidWritePixelsFastPath : 1; |
Chris Dalton | e1196c5 | 2019-12-28 14:31:09 -0700 | [diff] [blame] | 570 | bool fRequiresManualFBBarrierAfterTessellatedStencilDraw : 1; |
Chris Dalton | 03fdf6a | 2020-04-07 12:31:59 -0600 | [diff] [blame] | 571 | bool fNativeDrawIndexedIndirectIsBroken : 1; |
Adlai Holler | 75b43ce | 2021-05-03 11:37:24 -0400 | [diff] [blame] | 572 | bool fAvoidReorderingRenderTasks : 1; |
Robert Phillips | 0e741e2 | 2021-08-05 15:34:15 -0400 | [diff] [blame] | 573 | bool fAvoidDithering : 1; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 574 | |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 575 | // ANGLE performance workaround |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 576 | bool fPreferVRAMUseOverFlushes : 1; |
| 577 | |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 578 | bool fFenceSyncSupport : 1; |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 579 | bool fSemaphoreSupport : 1; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 580 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 581 | // Requires fence sync support in GL. |
Brian Osman | 2c2bc11 | 2017-02-28 10:02:49 -0500 | [diff] [blame] | 582 | bool fCrossContextTextureSupport : 1; |
| 583 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 584 | // Not (yet) implemented in VK backend. |
| 585 | bool fDynamicStateArrayGeometryProcessorTextureSupport : 1; |
| 586 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 587 | BlendEquationSupport fBlendEquationSupport; |
Jim Van Verth | 1bef979 | 2020-07-09 08:09:13 -0400 | [diff] [blame] | 588 | uint32_t fAdvBlendEqDisableFlags; |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 589 | static_assert(kLast_GrBlendEquation < 32); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 590 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 591 | uint32_t fMapBufferFlags; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 592 | int fBufferMapThreshold; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 593 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 594 | int fMaxRenderTargetSize; |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 595 | int fMaxPreferredRenderTargetSize; |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 596 | int fMaxVertexAttributes; |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 597 | int fMaxTextureSize; |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 598 | int fMaxWindowRectangles; |
Chris Dalton | a1638a5 | 2019-06-24 11:54:24 -0600 | [diff] [blame] | 599 | int fInternalMultisampleCount; |
Chris Dalton | 569c01b | 2021-05-25 10:11:46 -0600 | [diff] [blame] | 600 | int fMinPathVerbsForHwTessellation = 25; |
| 601 | int fMinStrokeVerbsForHwTessellation = 50; |
Jim Van Verth | 023f2e7 | 2020-10-09 15:38:58 -0400 | [diff] [blame] | 602 | uint32_t fMaxPushConstantsSize = 0; |
Jim Van Verth | a655f0d | 2021-05-18 15:03:27 -0400 | [diff] [blame] | 603 | size_t fTransferBufferAlignment = 1; |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 604 | |
Adrienne Walker | 6831484 | 2018-05-14 14:02:53 -0700 | [diff] [blame] | 605 | GrDriverBugWorkarounds fDriverBugWorkarounds; |
| 606 | |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 607 | private: |
Chris Dalton | 8367e11 | 2019-11-13 12:43:21 -0700 | [diff] [blame] | 608 | void applyOptionsOverrides(const GrContextOptions& options); |
| 609 | |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 610 | virtual void onApplyOptionsOverrides(const GrContextOptions&) {} |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 611 | virtual void onDumpJSON(SkJSONWriter*) const {} |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 612 | virtual bool onSurfaceSupportsWritePixels(const GrSurface*) const = 0; |
| 613 | virtual bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 614 | const SkIRect& srcRect, const SkIPoint& dstPoint) const = 0; |
Brian Salomon | 469046c | 2020-03-30 14:21:04 -0400 | [diff] [blame] | 615 | virtual GrBackendFormat onGetDefaultBackendFormat(GrColorType) const = 0; |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 616 | |
Greg Daniel | 2a30390 | 2018-02-20 10:25:54 -0500 | [diff] [blame] | 617 | // Backends should implement this if they have any extra requirements for use of window |
| 618 | // rectangles for a specific GrBackendRenderTarget outside of basic support. |
| 619 | virtual bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const { |
| 620 | return true; |
| 621 | } |
| 622 | |
Greg Daniel | 627d053 | 2019-07-08 16:48:14 -0400 | [diff] [blame] | 623 | virtual bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const = 0; |
| 624 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 625 | virtual SupportedRead onSupportedReadPixelsColorType(GrColorType srcColorType, |
| 626 | const GrBackendFormat& srcFormat, |
| 627 | GrColorType dstColorType) const = 0; |
| 628 | |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 629 | virtual GrSwizzle onGetReadSwizzle(const GrBackendFormat&, GrColorType) const = 0; |
| 630 | |
Greg Daniel | 87fab9f | 2021-06-07 15:18:23 -0400 | [diff] [blame] | 631 | virtual GrDstSampleFlags onGetDstSampleFlagsForProxy(const GrRenderTargetProxy*) const { |
| 632 | return GrDstSampleFlags::kNone; |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 633 | } |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 634 | |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 635 | bool fSuppressPrints : 1; |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 636 | bool fWireframeMode : 1; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 637 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 638 | using INHERITED = SkRefCnt; |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 639 | }; |
| 640 | |
Brian Osman | 2421b99 | 2021-06-19 10:44:54 -0400 | [diff] [blame] | 641 | GR_MAKE_BITFIELD_CLASS_OPS(GrCaps::ProgramDescOverrideFlags) |
Greg Daniel | 91b37b1 | 2021-01-05 15:40:54 -0500 | [diff] [blame] | 642 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 643 | #endif |