blob: 1596dfd9deb813af2e18a5570c894854d88c9644 [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 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.
6 */
7
8
9#ifndef GrGLCaps_DEFINED
10#define GrGLCaps_DEFINED
11
bsalomon1aa20292016-01-22 08:16:09 -080012#include <functional>
13
bsalomoncdee0092016-01-08 13:20:12 -080014#include "GrCaps.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070015#include "GrGLStencilAttachment.h"
bsalomoncdee0092016-01-08 13:20:12 -080016#include "GrSwizzle.h"
piotaixre4b23142014-10-02 10:57:53 -070017#include "SkChecksum.h"
mtklein2aa1f7e2015-02-20 12:35:32 -080018#include "SkTHash.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000019#include "SkTArray.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050020#include "../private/GrGLSL.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000021
22class GrGLContextInfo;
bsalomon1aa20292016-01-22 08:16:09 -080023class GrGLRenderTarget;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024
25/**
26 * Stores some capabilities of a GL context. Most are determined by the GL
27 * version and the extensions string. It also tracks formats that have passed
28 * the FBO completeness test.
29 */
bsalomon4b91f762015-05-19 09:29:46 -070030class GrGLCaps : public GrCaps {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031public:
egdaniel8dc7c3a2015-04-16 11:22:42 -070032 typedef GrGLStencilAttachment::Format StencilFormat;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000033
34 /**
35 * The type of MSAA for FBOs supported. Different extensions have different
36 * semantics of how / when a resolve is performed.
37 */
38 enum MSFBOType {
39 /**
40 * no support for MSAA FBOs
41 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000042 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000043 /**
Robert Phillips5ab72762017-06-07 12:04:18 -040044 * OpenGL 3.0+, OpenGL ES 3.0+, GL_ARB_framebuffer_object,
45 * GL_CHROMIUM_framebuffer_multisample, GL_ANGLE_framebuffer_multisample,
46 * or GL_EXT_framebuffer_multisample
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000047 */
Brian Salomon00731b42016-10-14 11:30:51 -040048 kStandard_MSFBOType,
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000049 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000050 * GL_APPLE_framebuffer_multisample ES extension
51 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000052 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000053 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000054 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
55 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
56 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
57 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000058 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000059 kES_IMG_MsToTexture_MSFBOType,
60 /**
61 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
62 * GL_MAX_SAMPLES value.
63 */
64 kES_EXT_MsToTexture_MSFBOType,
vbuzinovdded6962015-06-12 08:59:45 -070065 /**
66 * GL_NV_framebuffer_mixed_samples.
67 */
68 kMixedSamples_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000069
vbuzinovdded6962015-06-12 08:59:45 -070070 kLast_MSFBOType = kMixedSamples_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000071 };
72
Brian Salomone5e7eb12016-10-14 16:18:33 -040073 enum BlitFramebufferFlags {
74 kNoSupport_BlitFramebufferFlag = 1 << 0,
75 kNoScalingOrMirroring_BlitFramebufferFlag = 1 << 1,
76 kResolveMustBeFull_BlitFrambufferFlag = 1 << 2,
77 kNoMSAADst_BlitFramebufferFlag = 1 << 3,
78 kNoFormatConversion_BlitFramebufferFlag = 1 << 4,
79 kNoFormatConversionForMSAASrc_BlitFramebufferFlag = 1 << 5,
80 kRectsMustMatchForMSAASrc_BlitFramebufferFlag = 1 << 6,
bsalomon083617b2016-02-12 12:10:14 -080081 };
82
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000083 enum InvalidateFBType {
84 kNone_InvalidateFBType,
85 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
bsalomon083617b2016-02-12 12:10:14 -080086 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000087
88 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089 };
90
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000091 enum MapBufferType {
92 kNone_MapBufferType,
93 kMapBuffer_MapBufferType, // glMapBuffer()
94 kMapBufferRange_MapBufferType, // glMapBufferRange()
95 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
96
97 kLast_MapBufferType = kChromium_MapBufferType,
98 };
99
jvanverthd7a2c1f2015-12-07 07:36:44 -0800100 enum TransferBufferType {
101 kNone_TransferBufferType,
102 kPBO_TransferBufferType, // ARB_pixel_buffer_object
103 kChromium_TransferBufferType, // CHROMIUM_pixel_transfer_buffer_object
104
105 kLast_TransferBufferType = kChromium_TransferBufferType,
106 };
107
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 * Initializes the GrGLCaps to the set of features supported in the current
110 * OpenGL context accessible via ctxInfo.
111 */
bsalomon682c2692015-05-22 14:01:46 -0700112 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
113 const GrGLInterface* glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000114
bsalomon41e4384e2016-01-08 09:12:44 -0800115 bool isConfigTexturable(GrPixelConfig config) const override {
bsalomon41e4384e2016-01-08 09:12:44 -0800116 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
117 }
118
Brian Salomonbdecacf2018-02-02 20:32:49 -0500119 int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override;
120 int maxRenderTargetSampleCount(GrPixelConfig config) const override;
Greg Danielbb76ace2017-09-29 15:58:22 -0400121
122 bool isConfigCopyable(GrPixelConfig config) const override {
123 // In GL we have three ways to be able to copy. CopyTexImage, blit, and draw. CopyTexImage
124 // requires the src to be an FBO attachment, blit requires both src and dst to be FBO
125 // attachments, and draw requires the dst to be an FBO attachment. Thus to copy from and to
Greg Daniel9eb36b92018-06-08 13:02:22 -0400126 // the same config, we need that config to be bindable to an FBO.
127 return this->canConfigBeFBOColorAttachment(config);
Greg Danielbb76ace2017-09-29 15:58:22 -0400128 }
129
Brian Salomon71d9d842016-11-03 13:42:00 -0400130 bool canConfigBeFBOColorAttachment(GrPixelConfig config) const {
131 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kFBOColorAttachment_Flag);
132 }
133
cblume790d5132016-02-29 11:13:29 -0800134 bool isConfigTexSupportEnabled(GrPixelConfig config) const {
cblume790d5132016-02-29 11:13:29 -0800135 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseTexStorage_Flag);
136 }
137
cdalton74b8d322016-04-11 14:47:28 -0700138 bool canUseConfigWithTexelBuffer(GrPixelConfig config) const {
139 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kCanUseWithTexelBuffer_Flag);
140 }
141
bsalomoncdee0092016-01-08 13:20:12 -0800142 /** Returns the mapping between GrPixelConfig components and GL internal format components. */
143 const GrSwizzle& configSwizzle(GrPixelConfig config) const {
144 return fConfigTable[config].fSwizzle;
145 }
146
cdalton74b8d322016-04-11 14:47:28 -0700147 GrGLenum configSizedInternalFormat(GrPixelConfig config) const {
148 return fConfigTable[config].fFormats.fSizedInternalFormat;
149 }
150
bsalomon76148af2016-01-12 11:13:47 -0800151 bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
152 GrGLenum* internalFormat, GrGLenum* externalFormat,
153 GrGLenum* externalType) const;
154
bsalomon76148af2016-01-12 11:13:47 -0800155 bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
156 GrGLenum* externalFormat, GrGLenum* externalType) const;
157
158 bool getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const;
159
Brian Salomonf9f45122016-11-29 11:59:17 -0500160 /** The format to use read/write a texture as an image in a shader */
161 GrGLenum getImageFormat(GrPixelConfig config) const {
162 return fConfigTable[config].fFormats.fSizedInternalFormat;
163 }
164
bsalomon30447372015-12-21 09:03:05 -0800165 /**
166 * Gets an array of legal stencil formats. These formats are not guaranteed
167 * to be supported by the driver but are legal GLenum names given the GL
168 * version and extensions supported.
169 */
170 const SkTArray<StencilFormat, true>& stencilFormats() const {
171 return fStencilFormats;
172 }
173
174 /**
175 * Has a stencil format index been found for the config (or we've found that no format works).
176 */
177 bool hasStencilFormatBeenDeterminedForConfig(GrPixelConfig config) const {
178 return fConfigTable[config].fStencilFormatIndex != ConfigInfo::kUnknown_StencilIndex;
179 }
180
181 /**
182 * Gets the stencil format index for the config. This assumes
183 * hasStencilFormatBeenDeterminedForConfig has already been checked. Returns a value < 0 if
184 * no stencil format is supported with the config. Otherwise, returned index refers to the array
185 * returned by stencilFormats().
186 */
187 int getStencilFormatIndexForConfig(GrPixelConfig config) const {
188 SkASSERT(this->hasStencilFormatBeenDeterminedForConfig(config));
189 return fConfigTable[config].fStencilFormatIndex;
190 }
191
192 /**
193 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for
194 * the config. If < 0 it records that the config has no supported stencil format index.
195 */
196 void setStencilFormatIndexForConfig(GrPixelConfig config, int index) {
197 SkASSERT(!this->hasStencilFormatBeenDeterminedForConfig(config));
198 if (index < 0) {
199 fConfigTable[config].fStencilFormatIndex = ConfigInfo::kUnsupported_StencilFormatIndex;
200 } else {
201 fConfigTable[config].fStencilFormatIndex = index;
202 }
203 }
204
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000205 /**
206 * Call to note that a color config has been verified as a valid color
207 * attachment. This may save future calls to glCheckFramebufferStatus
208 * using isConfigVerifiedColorAttachment().
209 */
210 void markConfigAsValidColorAttachment(GrPixelConfig config) {
bsalomon480e8c02015-12-21 13:44:18 -0800211 fConfigTable[config].fFlags |= ConfigInfo::kVerifiedColorAttachment_Flag;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000212 }
213
214 /**
215 * Call to check whether a config has been verified as a valid color
216 * attachment.
217 */
218 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
bsalomon480e8c02015-12-21 13:44:18 -0800219 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kVerifiedColorAttachment_Flag);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000220 }
221
222 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000223 * Reports the type of MSAA FBO support.
224 */
225 MSFBOType msFBOType() const { return fMSFBOType; }
226
227 /**
bsalomon083617b2016-02-12 12:10:14 -0800228 * Does the preferred MSAA FBO extension have MSAA renderbuffers?
bsalomon@google.com347c3822013-05-01 20:10:01 +0000229 */
230 bool usesMSAARenderBuffers() const {
231 return kNone_MSFBOType != fMSFBOType &&
232 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
vbuzinovdded6962015-06-12 08:59:45 -0700233 kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
234 kMixedSamples_MSFBOType != fMSFBOType;
bsalomon@google.com347c3822013-05-01 20:10:01 +0000235 }
236
237 /**
bsalomon083617b2016-02-12 12:10:14 -0800238 * What functionality is supported by glBlitFramebuffer.
239 */
Brian Salomone5e7eb12016-10-14 16:18:33 -0400240 uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; }
bsalomon083617b2016-02-12 12:10:14 -0800241
242 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000243 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
244 * then implicitly resolved when read.
245 */
246 bool usesImplicitMSAAResolve() const {
247 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
248 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
249 }
250
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000251 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
252
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000253 /// What type of buffer mapping is supported?
254 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000255
jvanverthd7a2c1f2015-12-07 07:36:44 -0800256 /// What type of transfer buffer is supported?
257 TransferBufferType transferBufferType() const { return fTransferBufferType; }
258
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000259 /// The maximum number of fragment uniform vectors (GLES has min. 16).
260 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
261
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000262 /**
263 * Depending on the ES extensions present the BGRA external format may
bsalomon41e4384e2016-01-08 09:12:44 -0800264 * correspond to either a BGRA or RGBA internalFormat. On desktop GL it is
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000265 * RGBA.
266 */
bsalomon41e4384e2016-01-08 09:12:44 -0800267 bool bgraIsInternalFormat() const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000268
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000269 /// Is there support for GL_UNPACK_ROW_LENGTH
270 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
271
272 /// Is there support for GL_UNPACK_FLIP_Y
273 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
274
275 /// Is there support for GL_PACK_ROW_LENGTH
276 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
277
278 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
279 bool packFlipYSupport() const { return fPackFlipYSupport; }
280
281 /// Is there support for texture parameter GL_TEXTURE_USAGE
282 bool textureUsageSupport() const { return fTextureUsageSupport; }
283
Robert Phillips5ab72762017-06-07 12:04:18 -0400284 /// Is GL_ALPHA8 renderable
285 bool alpha8IsRenderable() const { return fAlpha8IsRenderable; }
286
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000287 /// Is GL_ARB_IMAGING supported
288 bool imagingSupport() const { return fImagingSupport; }
289
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000290 /// Is there support for Vertex Array Objects?
291 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
292
cdalton626e1ff2015-06-12 13:56:46 -0700293 /// Is there support for GL_KHR_debug?
294 bool debugSupport() const { return fDebugSupport; }
295
jvanverth3f801cb2014-12-16 09:49:38 -0800296 /// Is there support for ES2 compatability?
297 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
298
csmartdalton4c18b622016-07-29 12:19:28 -0700299 /// Is there support for glDraw*Instanced?
300 bool drawInstancedSupport() const { return fDrawInstancedSupport; }
301
cdalton06604b92016-02-05 10:09:51 -0800302 /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw
303 /// commands cannot be used unless we have base instance support.
304 bool drawIndirectSupport() const { return fDrawIndirectSupport; }
305
306 /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect
307 /// draw commands cannot be used unless we have base instance support.
308 bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; }
309
bsalomonfc9527a2016-08-29 09:18:39 -0700310 /// Is there support for glDrawRangeElements?
311 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; }
312
cdalton06604b92016-02-05 10:09:51 -0800313 /// Are the baseInstance fields supported in indirect draw commands?
314 bool baseInstanceSupport() const { return fBaseInstanceSupport; }
315
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000316 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon76148af2016-01-12 11:13:47 -0800317 bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000318
Brian Salomon19eaf2d2018-03-19 16:06:44 -0400319 bool surfaceSupportsWritePixels(const GrSurface*) const override;
320 bool surfaceSupportsReadPixels(const GrSurface*) const override;
321 GrColorType supportedReadPixelsColorType(GrPixelConfig, GrColorType) const override;
Brian Salomon5f33a8c2018-02-26 14:32:39 -0500322
Brian Salomon71d9d842016-11-03 13:42:00 -0400323 /// Does ReadPixels support reading readConfig pixels from a FBO that is surfaceConfig?
324 bool readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800325 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800326 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800327 std::function<bool ()> bindRenderTarget,
328 std::function<void ()> unbindRenderTarget) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000329
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000330 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000331
joshualittc1f56b52015-06-22 12:31:31 -0700332 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
333
joshualitt7bdd70a2015-10-01 06:28:11 -0700334 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; }
335
bsalomone5286e02016-01-14 09:24:09 -0800336 /// Are textures with GL_TEXTURE_RECTANGLE type supported.
337 bool rectangleTextureSupport() const { return fRectangleTextureSupport; }
338
bsalomoncdee0092016-01-08 13:20:12 -0800339 /// GL_ARB_texture_swizzle
340 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
341
cblume09bd2c02016-03-01 14:08:28 -0800342 bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; }
343
brianosman09563ce2016-06-02 08:59:34 -0700344 bool doManualMipmapping() const { return fDoManualMipmapping; }
345
Brian Osman71a18892017-08-10 10:23:25 -0400346 void onDumpJSON(SkJSONWriter*) const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000347
bsalomon88c7b982015-07-31 11:20:16 -0700348 bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; }
349 bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; }
ericrkb4ecabd2016-03-11 15:18:20 -0800350 bool rgbaToBgraReadbackConversionsAreSlow() const {
351 return fRGBAToBGRAReadbackConversionsAreSlow;
352 }
bsalomon88c7b982015-07-31 11:20:16 -0700353
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500354 bool useBufferDataNullHint() const { return fUseBufferDataNullHint; }
355
Eric Karlaeaf22b2017-05-18 15:08:09 -0700356 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s.
357 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; }
Chris Dalton9926f4b2017-05-17 15:15:50 -0600358
Brian Salomond17b4a62017-05-23 16:53:47 -0400359 /// glClearTex(Sub)Image support
360 bool clearTextureSupport() const { return fClearTextureSupport; }
361
Chris Dalton9926f4b2017-05-17 15:15:50 -0600362 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to
363 // glDrawArrays is nonzero.
364 // https://bugs.chromium.org/p/skia/issues/detail?id=6650
365 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; }
366
Brian Salomon43f8bf02017-10-18 08:33:29 -0400367 // Many drivers have issues with color clears.
368 bool useDrawToClearColor() const { return fUseDrawToClearColor; }
369
Mike Klein31550db2017-06-06 23:29:53 +0000370 /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit
371 /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil
372 /// op instead of using glClear seems to resolve the issue.
373 bool useDrawToClearStencilClip() const { return fUseDrawToClearStencilClip; }
374
Brian Salomon9bada542017-06-12 12:09:30 -0400375 // If true then we must use an intermediate surface to perform partial updates to unorm textures
376 // that have ever been bound to a FBO.
377 bool disallowTexSubImageForUnormConfigTexturesEverBoundToFBO() const {
378 return fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO;
379 }
380
381 // Use an intermediate surface to write pixels (full or partial overwrite) to into a texture
382 // that is bound to an FBO.
383 bool useDrawInsteadOfAllRenderTargetWrites() const {
384 return fUseDrawInsteadOfAllRenderTargetWrites;
385 }
386
Brian Salomon6d9c88b2017-06-12 10:24:42 -0400387 // At least some Adreno 3xx drivers draw lines incorrectly after drawing non-lines. Toggling
388 // face culling on and off seems to resolve this.
389 bool requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() const {
390 return fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines;
Brian Salomonaf971de2017-06-08 16:11:33 -0400391 }
392
Chris Daltonda40cd22018-04-16 13:19:58 -0600393 // Intel Skylake instanced draws get corrupted if we mix them with normal ones. Adding a flush
394 // in between seems to resolve this.
395 bool requiresFlushBetweenNonAndInstancedDraws() const {
396 return fRequiresFlushBetweenNonAndInstancedDraws;
397 }
398
Chris Daltoncc604e52017-10-06 16:27:32 -0600399 // Returns the observed maximum number of instances the driver can handle in a single call to
400 // glDrawArraysInstanced without crashing, or 'pendingInstanceCount' if this
401 // workaround is not necessary.
402 // NOTE: the return value may be larger than pendingInstanceCount.
403 int maxInstancesPerDrawArraysWithoutCrashing(int pendingInstanceCount) const {
404 return fMaxInstancesPerDrawArraysWithoutCrashing ? fMaxInstancesPerDrawArraysWithoutCrashing
405 : pendingInstanceCount;
406 }
407
Greg Daniel26dbe3b2018-05-03 10:35:42 -0400408 bool canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
409 bool dstIsTextureable, bool dstIsGLTexture2D,
410 GrSurfaceOrigin dstOrigin,
411 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
412 bool srcIsTextureable, bool srcIsGLTexture2D,
413 GrSurfaceOrigin srcOrigin) const;
414 bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
415 bool dstIsTextureable, bool dstIsGLTexture2D,
416 GrSurfaceOrigin dstOrigin,
417 GrPixelConfig srcConfig, int srcSampleCnt,
418 bool srcIsTextureable, bool srcIsGLTexture2D,
419 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
420 const SkIRect& srcRect, const SkIPoint& dstPoint) const;
421 bool canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const;
422
423 bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
424 const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
425
Brian Salomon2a4f9832018-03-03 22:43:43 -0500426 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400427 bool* rectsMustMatch, bool* disallowSubrect) const override;
Brian Salomon467921e2017-03-06 16:17:12 -0500428
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400429 bool programBinarySupport() const {
430 return fProgramBinarySupport;
431 }
432
Greg Danielfaa095e2017-12-19 13:15:02 -0500433 bool validateBackendTexture(const GrBackendTexture&, SkColorType,
434 GrPixelConfig*) const override;
435 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
436 GrPixelConfig*) const override;
Greg Danielf5d87582017-12-18 14:48:15 -0500437
Robert Phillipsfc711a22018-02-13 17:03:00 -0500438 bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
439 GrPixelConfig*) const override;
440
Robert Phillipsbe77a022018-04-03 17:17:05 -0400441#if GR_TEST_UTILS
442 GrGLStandard standard() const { return fStandard; }
443#endif
444
Greg Danielfaa095e2017-12-19 13:15:02 -0500445private:
bsalomon76148af2016-01-12 11:13:47 -0800446 enum ExternalFormatUsage {
447 kTexImage_ExternalFormatUsage,
Brian Salomon5fba7ad2018-03-22 10:01:16 -0400448 kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -0800449
Brian Salomon5fba7ad2018-03-22 10:01:16 -0400450 kLast_ExternalFormatUsage = kReadPixels_ExternalFormatUsage
bsalomon76148af2016-01-12 11:13:47 -0800451 };
452 static const int kExternalFormatUsageCnt = kLast_ExternalFormatUsage + 1;
453 bool getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
454 ExternalFormatUsage usage, GrGLenum* externalFormat,
455 GrGLenum* externalType) const;
456
cdalton4cd67132015-06-10 19:23:46 -0700457 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
Chris Dalton47c8ed32017-11-15 18:27:09 -0700458 void initGLSL(const GrGLContextInfo&, const GrGLInterface*);
kkinnunencfe62e32015-07-01 02:58:50 -0700459 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
bsalomon424cc262015-05-22 10:37:30 -0700460
Brian Salomon01b476a2018-01-23 11:06:41 -0500461 void applyDriverCorrectnessWorkarounds(const GrGLContextInfo&, const GrContextOptions&,
462 GrShaderCaps*);
463
egdanielb7e7d572015-11-04 04:23:53 -0800464 void onApplyOptionsOverrides(const GrContextOptions& options) override;
465
Greg Daniel2a303902018-02-20 10:25:54 -0500466 bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override;
467
Eric Karl5c779752017-05-08 12:02:07 -0700468 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&,
469 const GrGLInterface*);
cdalton1dd05422015-06-12 09:01:18 -0700470 void initBlendEqationSupport(const GrGLContextInfo&);
Eric Karl5c779752017-05-08 12:02:07 -0700471 void initStencilSupport(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000472 // This must be called after initFSAASupport().
brianosman20471892016-12-02 06:43:32 -0800473 void initConfigTable(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*,
474 GrShaderCaps*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000475
bsalomon1aa20292016-01-22 08:16:09 -0800476 GrGLStandard fStandard;
477
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000478 SkTArray<StencilFormat, true> fStencilFormats;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000479
480 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000481
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000482 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000483 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000484 MapBufferType fMapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800485 TransferBufferType fTransferBufferType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000486
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000487 bool fUnpackRowLengthSupport : 1;
488 bool fUnpackFlipYSupport : 1;
489 bool fPackRowLengthSupport : 1;
490 bool fPackFlipYSupport : 1;
491 bool fTextureUsageSupport : 1;
Robert Phillips5ab72762017-06-07 12:04:18 -0400492 bool fAlpha8IsRenderable: 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000493 bool fImagingSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000494 bool fVertexArrayObjectSupport : 1;
cdalton626e1ff2015-06-12 13:56:46 -0700495 bool fDebugSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800496 bool fES2CompatibilitySupport : 1;
csmartdalton4c18b622016-07-29 12:19:28 -0700497 bool fDrawInstancedSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800498 bool fDrawIndirectSupport : 1;
bsalomonfc9527a2016-08-29 09:18:39 -0700499 bool fDrawRangeElementsSupport : 1;
cdalton06604b92016-02-05 10:09:51 -0800500 bool fMultiDrawIndirectSupport : 1;
501 bool fBaseInstanceSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000502 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000503 bool fIsCoreProfile : 1;
joshualittc1f56b52015-06-22 12:31:31 -0700504 bool fBindFragDataLocationSupport : 1;
bsalomon88c7b982015-07-31 11:20:16 -0700505 bool fRGBA8888PixelsOpsAreSlow : 1;
506 bool fPartialFBOReadIsSlow : 1;
joshualitt7bdd70a2015-10-01 06:28:11 -0700507 bool fBindUniformLocationSupport : 1;
bsalomone5286e02016-01-14 09:24:09 -0800508 bool fRectangleTextureSupport : 1;
bsalomoncdee0092016-01-08 13:20:12 -0800509 bool fTextureSwizzleSupport : 1;
cblume09bd2c02016-03-01 14:08:28 -0800510 bool fMipMapLevelAndLodControlSupport : 1;
ericrkb4ecabd2016-03-11 15:18:20 -0800511 bool fRGBAToBGRAReadbackConversionsAreSlow : 1;
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500512 bool fUseBufferDataNullHint : 1;
Brian Salomon01b476a2018-01-23 11:06:41 -0500513 bool fClearTextureSupport : 1;
514 bool fProgramBinarySupport : 1;
515
516 // Driver workarounds
brianosman09563ce2016-06-02 08:59:34 -0700517 bool fDoManualMipmapping : 1;
Eric Karlaeaf22b2017-05-18 15:08:09 -0700518 bool fClearToBoundaryValuesIsBroken : 1;
Chris Dalton9926f4b2017-05-17 15:15:50 -0600519 bool fDrawArraysBaseVertexIsBroken : 1;
Brian Salomon43f8bf02017-10-18 08:33:29 -0400520 bool fUseDrawToClearColor : 1;
Mike Klein31550db2017-06-06 23:29:53 +0000521 bool fUseDrawToClearStencilClip : 1;
Brian Salomon9bada542017-06-12 12:09:30 -0400522 bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1;
523 bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
Brian Salomon6d9c88b2017-06-12 10:24:42 -0400524 bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1;
Chris Daltonda40cd22018-04-16 13:19:58 -0600525 bool fRequiresFlushBetweenNonAndInstancedDraws : 1;
Brian Salomon01b476a2018-01-23 11:06:41 -0500526 int fMaxInstancesPerDrawArraysWithoutCrashing;
joshualitt58162332014-08-01 06:44:53 -0700527
Brian Salomone5e7eb12016-10-14 16:18:33 -0400528 uint32_t fBlitFramebufferFlags;
bsalomon083617b2016-02-12 12:10:14 -0800529
bsalomon7928ef62016-01-05 10:26:39 -0800530 /** Number type of the components (with out considering number of bits.) */
531 enum FormatType {
532 kNormalizedFixedPoint_FormatType,
533 kFloat_FormatType,
534 };
535
536 struct ReadPixelsFormat {
537 ReadPixelsFormat() : fFormat(0), fType(0) {}
538 GrGLenum fFormat;
539 GrGLenum fType;
540 };
541
bsalomon76148af2016-01-12 11:13:47 -0800542 struct ConfigFormats {
543 ConfigFormats() {
544 // Inits to known bad GL enum values.
545 memset(this, 0xAB, sizeof(ConfigFormats));
546 }
547 GrGLenum fBaseInternalFormat;
548 GrGLenum fSizedInternalFormat;
549
550 /** The external format and type are to be used when uploading/downloading data using this
551 config where both the CPU data and GrSurface are the same config. To get the external
552 format and type when converting between configs while copying to/from memory use
halcanary9d524f22016-03-29 09:03:52 -0700553 getExternalFormat().
bsalomon76148af2016-01-12 11:13:47 -0800554 The kTexImage external format is usually the same as kOther except for kSRGBA on some
555 GL contexts. */
556 GrGLenum fExternalFormat[kExternalFormatUsageCnt];
557 GrGLenum fExternalType;
558
bsalomon76148af2016-01-12 11:13:47 -0800559 // Either the base or sized internal format depending on the GL and config.
560 GrGLenum fInternalFormatTexImage;
561 GrGLenum fInternalFormatRenderbuffer;
562 };
563
bsalomon30447372015-12-21 09:03:05 -0800564 struct ConfigInfo {
bsalomon7928ef62016-01-05 10:26:39 -0800565 ConfigInfo() : fStencilFormatIndex(kUnknown_StencilIndex), fFlags(0) {}
bsalomon30447372015-12-21 09:03:05 -0800566
567 ConfigFormats fFormats;
568
bsalomon7928ef62016-01-05 10:26:39 -0800569 FormatType fFormatType;
570
571 // On ES contexts there are restrictions on type type/format that may be used for
572 // ReadPixels. One is implicitly specified by the current FBO's format. The other is
573 // queryable. This stores the queried option (lazily).
574 ReadPixelsFormat fSecondReadPixelsFormat;
575
bsalomon30447372015-12-21 09:03:05 -0800576 enum {
577 // This indicates that a stencil format has not yet been determined for the config.
578 kUnknown_StencilIndex = -1,
579 // This indicates that there is no supported stencil format for the config.
580 kUnsupported_StencilFormatIndex = -2
581 };
bsalomon480e8c02015-12-21 13:44:18 -0800582
583 // Index fStencilFormats.
Greg Daniel81e7bf82017-07-19 14:47:42 -0400584 int fStencilFormatIndex;
585
586 SkTDArray<int> fColorSampleCounts;
bsalomon480e8c02015-12-21 13:44:18 -0800587
588 enum {
bsalomon41e4384e2016-01-08 09:12:44 -0800589 kVerifiedColorAttachment_Flag = 0x1,
590 kTextureable_Flag = 0x2,
591 kRenderable_Flag = 0x4,
592 kRenderableWithMSAA_Flag = 0x8,
Brian Salomon71d9d842016-11-03 13:42:00 -0400593 /** kFBOColorAttachment means that even if the config cannot be a GrRenderTarget, we can
594 still attach it to a FBO for blitting or reading pixels. */
595 kFBOColorAttachment_Flag = 0x10,
596 kCanUseTexStorage_Flag = 0x20,
597 kCanUseWithTexelBuffer_Flag = 0x40,
bsalomon480e8c02015-12-21 13:44:18 -0800598 };
599 uint32_t fFlags;
bsalomoncdee0092016-01-08 13:20:12 -0800600
601 GrSwizzle fSwizzle;
bsalomon30447372015-12-21 09:03:05 -0800602 };
603
604 ConfigInfo fConfigTable[kGrPixelConfigCnt];
605
bsalomon4b91f762015-05-19 09:29:46 -0700606 typedef GrCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000607};
608
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000609#endif