blob: 99bd22e324a683bdd015970c854546f6be32ca60 [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
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00008#include "GrGLCaps.h"
egdanielb7e7d572015-11-04 04:23:53 -08009#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000010#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080011#include "GrGLRenderTarget.h"
Brian Salomon467921e2017-03-06 16:17:12 -050012#include "GrGLTexture.h"
Greg Daniel26dbe3b2018-05-03 10:35:42 -040013#include "GrRenderTargetProxyPriv.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050014#include "GrShaderCaps.h"
Robert Phillipsbf25d432017-04-07 10:08:53 -040015#include "GrSurfaceProxyPriv.h"
Greg Daniel26dbe3b2018-05-03 10:35:42 -040016#include "GrTextureProxyPriv.h"
Brian Osman71a18892017-08-10 10:23:25 -040017#include "SkJSONWriter.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000018#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000019#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000020
bsalomon682c2692015-05-22 14:01:46 -070021GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
22 const GrGLContextInfo& ctxInfo,
23 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080024 fStandard = ctxInfo.standard();
25
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000027 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000028 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000029 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080030 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032 fUnpackRowLengthSupport = false;
33 fUnpackFlipYSupport = false;
34 fPackRowLengthSupport = false;
35 fPackFlipYSupport = false;
36 fTextureUsageSupport = false;
Robert Phillips5ab72762017-06-07 12:04:18 -040037 fAlpha8IsRenderable = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080041 fES2CompatibilitySupport = false;
cdalton06604b92016-02-05 10:09:51 -080042 fDrawIndirectSupport = false;
43 fMultiDrawIndirectSupport = false;
44 fBaseInstanceSupport = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080047 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080048 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070049 fRGBA8888PixelsOpsAreSlow = false;
50 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080051 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080052 fRGBAToBGRAReadbackConversionsAreSlow = false;
Robert Phillipsf2ec0242018-03-01 16:51:25 -050053 fUseBufferDataNullHint = SkToBool(GR_GL_USE_BUFFER_DATA_NULL_HINT);
brianosman09563ce2016-06-02 08:59:34 -070054 fDoManualMipmapping = false;
Eric Karlaeaf22b2017-05-18 15:08:09 -070055 fClearToBoundaryValuesIsBroken = false;
Brian Salomond17b4a62017-05-23 16:53:47 -040056 fClearTextureSupport = false;
Chris Dalton9926f4b2017-05-17 15:15:50 -060057 fDrawArraysBaseVertexIsBroken = false;
Brian Salomon43f8bf02017-10-18 08:33:29 -040058 fUseDrawToClearColor = false;
Mike Klein31550db2017-06-06 23:29:53 +000059 fUseDrawToClearStencilClip = false;
Brian Salomon9bada542017-06-12 12:09:30 -040060 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
61 fUseDrawInsteadOfAllRenderTargetWrites = false;
Brian Salomon6d9c88b2017-06-12 10:24:42 -040062 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
Chris Daltonda40cd22018-04-16 13:19:58 -060063 fRequiresFlushBetweenNonAndInstancedDraws = false;
Brian Osman1348ed02018-09-12 09:08:39 -040064 fDetachStencilFromMSAABuffersBeforeReadPixels = false;
Ethan Nicholas06d55fb2017-11-08 09:48:50 -050065 fProgramBinarySupport = false;
piotaixre4b23142014-10-02 10:57:53 -070066
Brian Salomone5e7eb12016-10-14 16:18:33 -040067 fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
Chris Dalton1b4ad762018-10-04 11:58:09 -060068 fMaxInstancesPerDrawWithoutCrashing = 0;
bsalomon083617b2016-02-12 12:10:14 -080069
Brian Salomon94efbf52016-11-29 13:43:05 -050070 fShaderCaps.reset(new GrShaderCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070071
cdalton4cd67132015-06-10 19:23:46 -070072 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073}
74
cdalton4cd67132015-06-10 19:23:46 -070075void GrGLCaps::init(const GrContextOptions& contextOptions,
76 const GrGLContextInfo& ctxInfo,
77 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000078 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079 GrGLVersion version = ctxInfo.version();
80
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000081 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000082 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
83 &fMaxFragmentUniformVectors);
84 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000085 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086 GrGLint max;
87 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
88 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000089 if (version >= GR_GL_VER(3, 2)) {
90 GrGLint profileMask;
91 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
92 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
93 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094 }
Adrienne Walker87785d52018-08-09 12:01:43 -070095 if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
96 fMaxFragmentUniformVectors = SkMin32(fMaxFragmentUniformVectors, 32);
97 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000098 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000100 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 fUnpackRowLengthSupport = true;
102 fUnpackFlipYSupport = false;
103 fPackRowLengthSupport = true;
104 fPackFlipYSupport = false;
105 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000106 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
107 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000109 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
110 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 fPackFlipYSupport =
112 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
113 }
114
Adrienne Walkerc48f7762018-05-15 13:03:13 -0700115 if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
116 // In some cases drivers handle copying the last row incorrectly
117 // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
118 // through every row and conditionally clobbering that value, but
119 // Skia already has a scratch buffer workaround when pack row length
120 // is not supported, so just use that.
121 fPackRowLengthSupport = false;
122 }
123
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000124 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000125 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
126
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000127 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700128 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
129 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
130 ctxInfo.hasExtension("GL_NV_texture_barrier");
131 } else {
132 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
133 }
134
Robert Phillips7f861922018-01-30 13:13:42 +0000135 if (kGL_GrGLStandard == standard) {
136 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
137 ctxInfo.hasExtension("GL_ARB_texture_multisample");
138 } else {
139 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
140 }
141
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000142 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000143 ctxInfo.hasExtension("GL_ARB_imaging");
144
Brian Salomon01b476a2018-01-23 11:06:41 -0500145 if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
egdaniel9250d242015-05-18 13:04:26 -0700146 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
147 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000148 fDiscardRenderTargetSupport = true;
149 fInvalidateFBType = kInvalidate_InvalidateFBType;
150 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
151 fDiscardRenderTargetSupport = true;
152 fInvalidateFBType = kDiscard_InvalidateFBType;
153 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000154
Chris Dalton27059d32018-01-23 14:06:50 -0700155 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
156 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
157 if (kGLES_GrGLStandard == standard) {
158 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
Chris Dalton27059d32018-01-23 14:06:50 -0700159 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
160 if (kARM_GrGLVendor == ctxInfo.vendor()) {
161 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
162 }
163 }
164
Chris Dalton344e9032017-12-11 15:42:09 -0700165 if (kARM_GrGLVendor == ctxInfo.vendor() ||
166 kImagination_GrGLVendor == ctxInfo.vendor() ||
167 kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
168 fPreferFullscreenClears = true;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000169 }
170
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000171 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000172 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800173 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
174 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000175 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000176 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
177 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000178 }
179
cdalton626e1ff2015-06-12 13:56:46 -0700180 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
181 fDebugSupport = true;
182 } else {
183 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
184 }
185
jvanverth3f801cb2014-12-16 09:49:38 -0800186 if (kGL_GrGLStandard == standard) {
187 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
188 }
189 else {
190 fES2CompatibilitySupport = true;
191 }
192
cdalton0edea2c2015-05-21 08:27:44 -0700193 if (kGL_GrGLStandard == standard) {
194 fMultisampleDisableSupport = true;
195 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700196 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700197 }
198
kkinnunend94708e2015-07-30 22:47:04 -0700199 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600200 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
201 // instanced arrays, but we could make this more granular if we wanted
202 fInstanceAttribSupport =
203 version >= GR_GL_VER(3, 2) ||
204 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
205 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
206 } else {
207 fInstanceAttribSupport =
208 version >= GR_GL_VER(3, 0) ||
209 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
210 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
211 }
212
213 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700214 if (version >= GR_GL_VER(3, 0)) {
215 fBindFragDataLocationSupport = true;
216 }
217 } else {
218 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
219 fBindFragDataLocationSupport = true;
220 }
joshualittc1f56b52015-06-22 12:31:31 -0700221 }
222
joshualitt7bdd70a2015-10-01 06:28:11 -0700223 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
224
kkinnunene06ed252016-02-16 23:15:40 -0800225 if (kGL_GrGLStandard == standard) {
Weiliang Chen1e04b362018-07-12 17:13:35 -0400226 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
227 ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
kkinnunene06ed252016-02-16 23:15:40 -0800228 // We also require textureSize() support for rectangle 2D samplers which was added in
229 // GLSL 1.40.
230 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
231 fRectangleTextureSupport = true;
232 }
bsalomone179a912016-01-20 06:18:10 -0800233 }
kkinnunene06ed252016-02-16 23:15:40 -0800234 } else {
235 // Command buffer exposes this in GL ES context for Chromium reasons,
236 // but it should not be used. Also, at the time of writing command buffer
237 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800238 }
239
bsalomoncdee0092016-01-08 13:20:12 -0800240 if (kGL_GrGLStandard == standard) {
241 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
242 fTextureSwizzleSupport = true;
243 }
244 } else {
245 if (version >= GR_GL_VER(3,0)) {
246 fTextureSwizzleSupport = true;
247 }
248 }
249
cblume09bd2c02016-03-01 14:08:28 -0800250 if (kGL_GrGLStandard == standard) {
251 fMipMapLevelAndLodControlSupport = true;
252 } else if (kGLES_GrGLStandard == standard) {
253 if (version >= GR_GL_VER(3,0)) {
254 fMipMapLevelAndLodControlSupport = true;
255 }
256 }
257
bsalomon88c7b982015-07-31 11:20:16 -0700258#ifdef SK_BUILD_FOR_WIN
259 // We're assuming that on Windows Chromium we're using ANGLE.
260 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
261 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700262 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700263 fRGBA8888PixelsOpsAreSlow = isANGLE;
264 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
265 // check DX11 ANGLE.
266 fPartialFBOReadIsSlow = isANGLE;
267#endif
268
ericrkb4ecabd2016-03-11 15:18:20 -0800269 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
270 bool isMAC = false;
271#ifdef SK_BUILD_FOR_MAC
272 isMAC = true;
273#endif
274
275 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
276 // vis-versa.
277 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
278
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500279 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
280 fUseBufferDataNullHint = false;
281 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
282 fUseBufferDataNullHint = true;
283 }
284
Brian Salomond17b4a62017-05-23 16:53:47 -0400285 if (kGL_GrGLStandard == standard) {
286 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400287 fClearTextureSupport = true;
288 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500289 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
290 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400291 }
292
Greg Danielb2acf0a2018-09-12 09:17:11 -0400293#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
294 fSupportsAHardwareBufferImages = true;
295#endif
296
cdalton4cd67132015-06-10 19:23:46 -0700297 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700298 * GrShaderCaps fields
299 **************************************************************************/
300
egdaniel0a482332015-10-26 08:59:10 -0700301 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700302 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500303 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700304
Brian Osman195c05b2017-08-30 15:14:04 -0400305 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
306#if GR_TEST_UTILS
307 if (contextOptions.fSuppressPathRendering) {
308 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700309 }
Brian Osman195c05b2017-08-30 15:14:04 -0400310#endif
egdaniel05ded892015-10-26 07:38:05 -0700311
egdaniel05ded892015-10-26 07:38:05 -0700312 // Enable supported shader-related caps
313 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500314 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700315 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
Brian Salomon23c55b62018-06-19 16:28:41 -0400316 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600317
Brian Salomon1edc5b92016-11-29 13:43:46 -0500318 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600319
egdaniel05ded892015-10-26 07:38:05 -0700320 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500321 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700322 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600323 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600324 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
325 shaderCaps->fGSInvocationsSupport = true;
326 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
327 shaderCaps->fGSInvocationsSupport = true;
328 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
329 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600330 }
331
Brian Salomon1edc5b92016-11-29 13:43:46 -0500332 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800333 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500334 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500335 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700336
Brian Salomon1edc5b92016-11-29 13:43:46 -0500337 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700338 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800339
Chris Dalton1214be92018-06-28 19:06:27 -0600340 // Mali and early Adreno both have support for geometry shaders, but they appear to be
341 // implemented in software. In practice with ccpr, they are slower than the backup impl that
342 // only uses vertex shaders.
343 if (kARM_GrGLVendor != ctxInfo.vendor() &&
344 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
345 kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
346
Chris Daltonfaca00d2018-01-19 15:56:07 -0700347 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
348 shaderCaps->fGeometryShaderSupport = true;
349 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
350 shaderCaps->fGeometryShaderSupport = true;
351 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
352 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700353 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500354 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700355
Brian Salomon1edc5b92016-11-29 13:43:46 -0500356 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800357 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700358 }
359
cdalton9c3f1432016-03-11 10:07:37 -0800360 // Protect ourselves against tracking huge amounts of texture state.
361 static const uint8_t kMaxSaneSamplers = 32;
362 GrGLint maxSamplers;
cdalton9c3f1432016-03-11 10:07:37 -0800363 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500364 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800365
csmartdalton485a1202016-07-13 10:16:32 -0700366 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
367 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
368 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
369 // limit this decision to specific GPU families rather than basing it on the vendor alone.
370 if (!GR_GL_MUST_USE_VBO &&
371 !fIsCoreProfile &&
372 (kARM_GrGLVendor == ctxInfo.vendor() ||
373 kImagination_GrGLVendor == ctxInfo.vendor() ||
374 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
375 fPreferClientSideDynamicBuffers = true;
376 }
377
Eric Karl5c779752017-05-08 12:02:07 -0700378 if (!contextOptions.fAvoidStencilBuffers) {
379 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
380 this->initFSAASupport(contextOptions, ctxInfo, gli);
381 this->initStencilSupport(ctxInfo);
382 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400383
384 // Setup blit framebuffer
385 if (kGL_GrGLStandard != ctxInfo.standard()) {
386 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
387 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
388 kNoMSAADst_BlitFramebufferFlag |
389 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
390 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
391 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
392 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
393 // limitations.
394 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
395 kResolveMustBeFull_BlitFrambufferFlag |
396 kNoMSAADst_BlitFramebufferFlag |
397 kNoFormatConversion_BlitFramebufferFlag |
398 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
399 }
400 } else {
401 if (fUsesMixedSamples ||
402 ctxInfo.version() >= GR_GL_VER(3,0) ||
403 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
404 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
405 fBlitFramebufferFlags = 0;
406 }
407 }
408
cdalton1dd05422015-06-12 09:01:18 -0700409 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000410
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000411 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000412 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
413 // extension includes glMapBuffer.
414 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
415 fMapBufferFlags |= kSubset_MapFlag;
416 fMapBufferType = kMapBufferRange_MapBufferType;
417 } else {
418 fMapBufferType = kMapBuffer_MapBufferType;
419 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000420 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000421 // Unextended GLES2 doesn't have any buffer mapping.
422 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800423 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800424 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
425 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800426 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
427 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
428 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000429 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
430 fMapBufferFlags = kCanMap_MapFlag;
431 fMapBufferType = kMapBuffer_MapBufferType;
432 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000433 }
434
jvanverthd7a2c1f2015-12-07 07:36:44 -0800435 if (kGL_GrGLStandard == standard) {
436 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
437 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700438 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500439 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400440 if (version >= GR_GL_VER(3, 0) ||
441 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
442 // GL_EXT_unpack_subimage needed to support subtexture rectangles
443 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800444 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400445// TODO: get transfer buffers working in Chrome
446// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
447// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800448 }
449 }
450
joshualitte5b74c62015-06-01 14:17:47 -0700451 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
452 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700453 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700454#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500455 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
456 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
457 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700458 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700459#else
cdalton397536c2016-03-25 12:15:03 -0700460 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700461#endif
joshualitte5b74c62015-06-01 14:17:47 -0700462 }
463
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000464 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000465 fNPOTTextureTileSupport = true;
466 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000467 } else {
468 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000469 // ES3 has no limitations.
470 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
471 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000472 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
473 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
474 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
475 // to alllow arbitrary wrap modes, however.
476 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000477 }
478
bsalomon@google.combcce8922013-03-25 15:38:39 +0000479 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700480
481 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
482 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
483 }
484
bsalomon@google.combcce8922013-03-25 15:38:39 +0000485 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
486 // Our render targets are always created with textures as the color
487 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000488 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700489 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
490
491 if (kARM_GrGLVendor == ctxInfo.vendor()) {
492 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
493 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
494 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000495
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000496 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
497
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000498 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700499 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000500
robertphillips1b8e1b52015-06-24 06:54:10 -0700501#if 0
502 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
503 kQualcomm_GrGLVendor != ctxInfo.vendor();
504#endif
505
csmartdalton9bc11872016-08-09 12:42:47 -0700506 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
507 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700508 }
509
robertphillips63926682015-08-20 09:39:02 -0700510#ifdef SK_BUILD_FOR_WIN
511 // On ANGLE deferring flushes can lead to GPU starvation
512 fPreferVRAMUseOverFlushes = !isANGLE;
513#endif
514
bsalomon7dea7b72015-08-19 08:26:51 -0700515 if (kChromium_GrGLDriver == ctxInfo.driver()) {
516 fMustClearUploadedBufferData = true;
517 }
518
bsalomond08ea5f2015-02-20 06:58:13 -0800519 if (kGL_GrGLStandard == standard) {
520 // ARB allows mixed size FBO attachments, EXT does not.
521 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
522 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
523 fOversizedStencilSupport = true;
524 } else {
525 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
526 }
527 } else {
528 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
529 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
530 }
531
joshualitt58001552015-06-26 12:46:36 -0700532 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700533 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
534 ctxInfo.hasExtension("GL_ARB_draw_indirect");
535 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
536 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700537 (fDrawIndirectSupport &&
538 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700539 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700540 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800541 } else {
542 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700543 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
544 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
545 fBaseInstanceSupport = fDrawIndirectSupport &&
546 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700547 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800548 }
549
ethannicholas28ef4452016-03-25 09:26:03 -0700550 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500551 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700552 fSampleShadingSupport = true;
553 }
554 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
555 fSampleShadingSupport = true;
556 }
557
jvanverth84741b32016-09-30 08:39:02 -0700558 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
559 if (kGL_GrGLStandard == standard) {
560 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
561 fFenceSyncSupport = true;
562 }
Brian Osman93a23462017-06-21 15:13:39 -0400563 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700564 fFenceSyncSupport = true;
565 }
566
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400567 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500568 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500569
Brian Osman499bf1a2018-09-17 11:32:42 -0400570 // Half float vertex attributes requires GL3 or ES3
571 // It can also work with OES_VERTEX_HALF_FLOAT, but that requires a different enum.
572 if (kGL_GrGLStandard == standard) {
573 if (version >= GR_GL_VER(3, 0)) {
574 fHalfFloatVertexAttributeSupport = true;
575 }
576 } else if (version >= GR_GL_VER(3, 0)) {
577 fHalfFloatVertexAttributeSupport = true;
578 }
579
Brian Salomonf7232642018-09-19 08:58:08 -0400580 fDynamicStateArrayGeometryProcessorTextureSupport = true;
581
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400582 if (kGL_GrGLStandard == standard) {
583 if (version >= GR_GL_VER(4, 1)) {
584 fProgramBinarySupport = true;
585 }
586 } else if (version >= GR_GL_VER(3, 0)) {
587 fProgramBinarySupport = true;
588 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400589 if (fProgramBinarySupport) {
590 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400591 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400592 fProgramBinarySupport = count > 0;
593 }
bsalomoncdee0092016-01-08 13:20:12 -0800594 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
595 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800596 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700597
Brian Salomon01b476a2018-01-23 11:06:41 -0500598 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
599 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
600 }
601
cdalton4cd67132015-06-10 19:23:46 -0700602 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500603 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700604
Brian Salomon01b476a2018-01-23 11:06:41 -0500605 // For now these two are equivalent but we could have dst read in shader via some other method.
606 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000607}
608
egdaniel472d44e2015-10-22 08:20:00 -0700609const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
610 bool isCoreProfile) {
611 switch (generation) {
612 case k110_GrGLSLGeneration:
613 if (kGLES_GrGLStandard == standard) {
614 // ES2s shader language is based on version 1.20 but is version
615 // 1.00 of the ES language.
616 return "#version 100\n";
617 } else {
618 SkASSERT(kGL_GrGLStandard == standard);
619 return "#version 110\n";
620 }
621 case k130_GrGLSLGeneration:
622 SkASSERT(kGL_GrGLStandard == standard);
623 return "#version 130\n";
624 case k140_GrGLSLGeneration:
625 SkASSERT(kGL_GrGLStandard == standard);
626 return "#version 140\n";
627 case k150_GrGLSLGeneration:
628 SkASSERT(kGL_GrGLStandard == standard);
629 if (isCoreProfile) {
630 return "#version 150\n";
631 } else {
632 return "#version 150 compatibility\n";
633 }
634 case k330_GrGLSLGeneration:
635 if (kGLES_GrGLStandard == standard) {
636 return "#version 300 es\n";
637 } else {
638 SkASSERT(kGL_GrGLStandard == standard);
639 if (isCoreProfile) {
640 return "#version 330\n";
641 } else {
642 return "#version 330 compatibility\n";
643 }
644 }
cdalton33ad7012016-02-22 07:55:44 -0800645 case k400_GrGLSLGeneration:
646 SkASSERT(kGL_GrGLStandard == standard);
647 if (isCoreProfile) {
648 return "#version 400\n";
649 } else {
650 return "#version 400 compatibility\n";
651 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500652 case k420_GrGLSLGeneration:
653 SkASSERT(kGL_GrGLStandard == standard);
654 if (isCoreProfile) {
655 return "#version 420\n";
656 }
657 else {
658 return "#version 420 compatibility\n";
659 }
egdaniel472d44e2015-10-22 08:20:00 -0700660 case k310es_GrGLSLGeneration:
661 SkASSERT(kGLES_GrGLStandard == standard);
662 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800663 case k320es_GrGLSLGeneration:
664 SkASSERT(kGLES_GrGLStandard == standard);
665 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700666 }
667 return "<no version>";
668}
669
Chris Dalton47c8ed32017-11-15 18:27:09 -0700670bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
671 if (kGLES_GrGLStandard != ctxInfo.standard() &&
672 ctxInfo.version() < GR_GL_VER(4,1) &&
673 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
674 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
675 return true;
676 }
677 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
678 // geometry shaders don't have lower precision than vertex and fragment.
679 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
680 GrGLint range[2];
681 GrGLint bits;
682 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
683 if (range[0] < 127 || range[1] < 127 || bits < 23) {
684 return false;
685 }
686 }
687 return true;
688}
689
690void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700691 GrGLStandard standard = ctxInfo.standard();
692 GrGLVersion version = ctxInfo.version();
693
694 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500695 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700696 **************************************************************************/
697
Brian Salomon1edc5b92016-11-29 13:43:46 -0500698 GrShaderCaps* shaderCaps = fShaderCaps.get();
699 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700700 if (kGLES_GrGLStandard == standard) {
701 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500702 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
703 shaderCaps->fFBFetchSupport = true;
704 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
705 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700706 }
707 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
708 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
Brian Salomon1edc5b92016-11-29 13:43:46 -0500709 shaderCaps->fFBFetchNeedsCustomOutput = false;
710 shaderCaps->fFBFetchSupport = true;
711 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
712 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700713 }
714 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
715 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500716 shaderCaps->fFBFetchNeedsCustomOutput = false;
717 shaderCaps->fFBFetchSupport = true;
718 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
719 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700720 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500721 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700722 }
723
cdaltonc08f1962016-02-12 12:14:06 -0800724 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500725 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800726 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500727 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800728 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
729 }
Brian Salomon41274562017-09-15 09:40:03 -0700730 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
731 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
732 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800733 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500734 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800735 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
736 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400737 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
738 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500739 shaderCaps->fNoPerspectiveInterpolationSupport = true;
740 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800741 "GL_NV_shader_noperspective_interpolation";
742 }
743 }
744
Brian Salomon1edc5b92016-11-29 13:43:46 -0500745 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
746 shaderCaps->fGLSLGeneration,
747 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800748
Brian Salomon1edc5b92016-11-29 13:43:46 -0500749 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
750 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800751 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800752
753 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500754 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800755 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
756 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500757 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800758 }
759
760 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500761 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800762 }
763
cdalton9c3f1432016-03-11 10:07:37 -0800764 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400765 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
766 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400767 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400768 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
769 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
770 // At least one driver has been found that has this extension without the "GL_" prefix.
771 shaderCaps->fExternalTextureSupport = true;
772 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800773 }
774 }
775
cdaltonc04ce672016-03-11 14:07:38 -0800776 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600777 shaderCaps->fVertexIDSupport = true;
778 } else {
779 // Desktop GLSL 3.30 == ES GLSL 3.00.
780 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
781 }
782
Chris Dalton7c7ff032018-03-28 20:09:58 -0600783 if (kGL_GrGLStandard == standard) {
784 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
785 } else {
786 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
787 }
788
Chris Dalton47c8ed32017-11-15 18:27:09 -0700789 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
790 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400791
792 // Unsigned integers only supported in and after GLSL 1.30.
793 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700794}
795
kkinnunencfe62e32015-07-01 02:58:50 -0700796bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700797 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
798
799 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700800 return false;
801 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700802
kkinnunencfe62e32015-07-01 02:58:50 -0700803 if (kGL_GrGLStandard == ctxInfo.standard()) {
804 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
805 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
806 return false;
807 }
808 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700809 if (!hasChromiumPathRendering &&
810 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700811 return false;
812 }
813 }
814 // We only support v1.3+ of GL_NV_path_rendering which allows us to
815 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
816 // additions are detected by checking the existence of the function.
817 // We also use *Then* functions that not all drivers might have. Check
818 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800819 if (!gli->fFunctions.fStencilThenCoverFillPath ||
820 !gli->fFunctions.fStencilThenCoverStrokePath ||
821 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
822 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
823 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700824 return false;
825 }
826 return true;
827}
bsalomon1aa20292016-01-22 08:16:09 -0800828
Brian Salomon71d9d842016-11-03 13:42:00 -0400829bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800830 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800831 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800832 std::function<bool ()> bindRenderTarget,
833 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400834 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800835 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400836 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800837 return false;
838 }
bsalomon7928ef62016-01-05 10:26:39 -0800839
bsalomon76148af2016-01-12 11:13:47 -0800840 GrGLenum readFormat;
841 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400842 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800843 return false;
844 }
845
bsalomon1aa20292016-01-22 08:16:09 -0800846 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800847 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
848 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
849 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
850 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500851 // The manual does not seem to fully match the spec as the spec allows integer formats
852 // when the bound color buffer is an integer buffer. It doesn't specify which integer
853 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500854 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
855 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
856 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800857 return false;
858 }
859 // There is also a set of allowed types, but all the types we use are in the set:
860 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
861 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
862 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
863 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
864 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
865 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
866 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800867 return true;
piotaixre4b23142014-10-02 10:57:53 -0700868 }
bsalomon7928ef62016-01-05 10:26:39 -0800869
bsalomon76148af2016-01-12 11:13:47 -0800870 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500871 switch (fConfigTable[surfaceConfig].fFormatType) {
872 case kNormalizedFixedPoint_FormatType:
873 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
874 return true;
875 }
876 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500877 case kFloat_FormatType:
878 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
879 return true;
880 }
881 break;
bsalomon7928ef62016-01-05 10:26:39 -0800882 }
883
Brian Salomon71d9d842016-11-03 13:42:00 -0400884 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800885 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400886 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800887 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800888 if (!bindRenderTarget()) {
889 return false;
890 }
891 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
892 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800893 rpFormat->fFormat = format;
894 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800895 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800896 }
897
Brian Salomon71d9d842016-11-03 13:42:00 -0400898 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
899 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700900}
901
Eric Karl5c779752017-05-08 12:02:07 -0700902void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
903 const GrGLInterface* gli) {
904 // We need dual source blending and the ability to disable multisample in order to support mixed
905 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
906 // renderer is available and enabled; no other path renderers support this feature.
907 if (fMultisampleDisableSupport &&
908 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400909 this->shaderCaps()->pathRenderingSupport()
910#if GR_TEST_UTILS
911 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
912#endif
913 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700914 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400915 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700916 }
917
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000918 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400919 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
920 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
921 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
922 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
923 fAlpha8IsRenderable = true;
924 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500925 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
926 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
927 // mixed samples we can't use multisampled-render-to-texture.
928 if (fUsesMixedSamples) {
929 fMSFBOType = kMixedSamples_MSFBOType;
930 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000931 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
932 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
933 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400934 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
935 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400936 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400937 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400938 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400939 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000940 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
941 fMSFBOType = kES_Apple_MSFBOType;
942 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000943 } else {
egdanieleed519e2016-01-15 11:36:18 -0800944 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700945 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400946 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
947 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400948
Brian Salomon00731b42016-10-14 11:30:51 -0400949 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400950 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
951 // Core profile removes ALPHA8 support.
952 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
953 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
954 // present.
955 fAlpha8IsRenderable = true;
956 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000957 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
958 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400959 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000960 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000961 }
Eric Karl5c779752017-05-08 12:02:07 -0700962
Brian Salomon01b476a2018-01-23 11:06:41 -0500963 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400964 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
965 fMSFBOType = kNone_MSFBOType;
966 }
967
Eric Karl5c779752017-05-08 12:02:07 -0700968 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
969 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
970 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700971 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000972}
973
cdalton1dd05422015-06-12 09:01:18 -0700974void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500975 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700976
Greg Daniel210883c2017-11-27 15:14:01 -0500977 bool layoutQualifierSupport = false;
978 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
979 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
980 layoutQualifierSupport = true;
981 }
982
cdalton1dd05422015-06-12 09:01:18 -0700983 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
984 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500985 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500986 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
987 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700988 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500989 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700990 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
991 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500992 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500993 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700994 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500995 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700996 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
997 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -0700998 }
cdalton1dd05422015-06-12 09:01:18 -0700999}
1000
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001001namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001002const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001003}
1004
Eric Karl5c779752017-05-08 12:02:07 -07001005void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001006
1007 // Build up list of legal stencil formats (though perhaps not supported on
1008 // the particular gpu/driver) from most preferred to least.
1009
1010 // these consts are in order of most preferred to least preferred
1011 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1012
1013 static const StencilFormat
1014 // internal Format stencil bits total bits packed?
1015 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1016 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1017 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1018 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001019 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001020 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1021
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001022 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001023 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001024 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001025 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1026 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1027
1028 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1029 // require FBO support we can expect these are legal formats and don't
1030 // check. These also all support the unsized GL_STENCIL_INDEX.
1031 fStencilFormats.push_back() = gS8;
1032 fStencilFormats.push_back() = gS16;
1033 if (supportsPackedDS) {
1034 fStencilFormats.push_back() = gD24S8;
1035 }
1036 fStencilFormats.push_back() = gS4;
1037 if (supportsPackedDS) {
1038 fStencilFormats.push_back() = gDS;
1039 }
1040 } else {
1041 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1042 // for other formats.
1043 // ES doesn't support using the unsized format.
1044
1045 fStencilFormats.push_back() = gS8;
1046 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001047 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1048 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001049 fStencilFormats.push_back() = gD24S8;
1050 }
1051 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1052 fStencilFormats.push_back() = gS4;
1053 }
1054 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001055}
1056
Brian Osman71a18892017-08-10 10:23:25 -04001057void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001058
Brian Osman71a18892017-08-10 10:23:25 -04001059 // We are called by the base class, which has already called beginObject(). We choose to nest
1060 // all of our caps information in a named sub-object.
1061 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001062
Brian Osman71a18892017-08-10 10:23:25 -04001063 writer->beginArray("Stencil Formats");
1064
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001065 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001066 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001067 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1068 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1069 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001070 }
1071
Brian Osman71a18892017-08-10 10:23:25 -04001072 writer->endArray();
1073
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001074 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001075 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001076 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001077 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001078 "IMG MS To Texture",
1079 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001080 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001081 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001082 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001083 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1084 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1085 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1086 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1087 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001088 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001089
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001090 static const char* kInvalidateFBTypeStr[] = {
1091 "None",
1092 "Discard",
1093 "Invalidate",
1094 };
1095 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1096 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1097 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1098 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001099
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001100 static const char* kMapBufferTypeStr[] = {
1101 "None",
1102 "MapBuffer",
1103 "MapBufferRange",
1104 "Chromium",
1105 };
1106 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1107 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1108 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1109 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1110 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1111
Brian Osman71a18892017-08-10 10:23:25 -04001112 writer->appendBool("Core Profile", fIsCoreProfile);
1113 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1114 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1115 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1116 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1117 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1118 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1119 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1120 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001121
Brian Osman71a18892017-08-10 10:23:25 -04001122 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001123 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1124 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1125 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001126 writer->appendBool("Debug support", fDebugSupport);
1127 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1128 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1129 writer->appendBool("Base instance support", fBaseInstanceSupport);
1130 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1131 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1132 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1133 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1134 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1135 writer->appendBool("BGRA to RGBA readback conversions are slow",
1136 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001137 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001138 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1139 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001140 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1141 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1142 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1143 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Dalton1b4ad762018-10-04 11:58:09 -06001144 writer->appendBool("Max instances per draw without crashing (or zero)",
1145 fMaxInstancesPerDrawWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001146
Brian Osman71a18892017-08-10 10:23:25 -04001147 writer->beginArray("configs");
1148
bsalomon41e4384e2016-01-08 09:12:44 -08001149 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001150 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001151 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1152 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1153 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001154 writer->appendHexU32("e_format_read_pixels",
1155 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001156 writer->appendHexU32(
1157 "e_format_teximage",
1158 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1159 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1160 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1161 writer->appendHexU32("i_for_renderbuffer",
1162 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1163 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001164 }
1165
Brian Osman71a18892017-08-10 10:23:25 -04001166 writer->endArray();
1167 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001168}
1169
bsalomon41e4384e2016-01-08 09:12:44 -08001170bool GrGLCaps::bgraIsInternalFormat() const {
1171 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1172}
1173
bsalomon76148af2016-01-12 11:13:47 -08001174bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1175 GrGLenum* internalFormat, GrGLenum* externalFormat,
1176 GrGLenum* externalType) const {
1177 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1178 externalFormat, externalType)) {
1179 return false;
1180 }
1181 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1182 return true;
1183}
1184
bsalomon76148af2016-01-12 11:13:47 -08001185bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1186 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001187 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001188 externalFormat, externalType)) {
1189 return false;
1190 }
1191 return true;
1192}
1193
Brian Salomon93348dd2018-08-29 12:56:23 -04001194void GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001195 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
Brian Salomon93348dd2018-08-29 12:56:23 -04001196}
1197
1198void GrGLCaps::getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1199 *internalFormat = fConfigTable[config].fFormats.fSizedInternalFormat;
bsalomon76148af2016-01-12 11:13:47 -08001200}
1201
1202bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1203 ExternalFormatUsage usage, GrGLenum* externalFormat,
1204 GrGLenum* externalType) const {
1205 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001206
1207 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1208 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1209
1210 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001211 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1212 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001213 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1214 return false;
1215 }
1216
1217 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1218 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1219
bsalomone9573312016-01-25 14:33:25 -08001220 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1221 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1222 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1223 // texture, not the red component.
1224 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001225 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001226 *externalFormat = GR_GL_ALPHA;
1227 }
1228 }
1229
bsalomon76148af2016-01-12 11:13:47 -08001230 return true;
1231}
1232
brianosman20471892016-12-02 06:43:32 -08001233void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1234 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001235 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001236 /*
1237 Comments on renderability of configs on various GL versions.
1238 OpenGL < 3.0:
1239 no built in support for render targets.
1240 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1241 format RGB, RGBA and NV float formats we don't use.
1242 This is the following:
1243 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1244 RGB10_A2, RGBA12,RGBA16
1245 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1246 since they aren't required by later standards and the driver can simply return
1247 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1248 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1249 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1250 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1251 This adds a lot of additional renderable sized formats, including ALPHA8.
1252 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1253 16F, 32I, 32UI, and 32F variants).
1254 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1255
1256 For both the above extensions we limit ourselves to those that are also required by
1257 OpenGL 3.0.
1258
1259 OpenGL 3.0:
1260 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1261 but are not required to be supported as renderable textures/renderbuffer.
1262 Required renderable color formats:
1263 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1264 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1265 RGB10_A2.
1266 - R11F_G11F_B10F.
1267 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1268 and RG8UI.
1269 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1270 - ALPHA8
1271
1272 OpenGL 3.1, 3.2, 3.3
1273 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1274 OpengGL 3.3, 4.0, 4.1
1275 Adds RGB10_A2UI.
1276 OpengGL 4.2
1277 Adds
1278 - RGB5_A1, RGBA4
1279 - RGB565
1280 OpenGL 4.4
1281 Does away with the separate list and adds a column to the sized internal color format
1282 table. However, no new formats become required color renderable.
1283
1284 ES 2.0
1285 color renderable: RGBA4, RGB5_A1, RGB565
1286 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1287 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1288 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1289 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1290 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1291 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1292
1293 ES 3.0
1294 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1295 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1296 RGB5_A1.
1297 - RGB8 and RGB565.
1298 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1299 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1300 ES 3.1
1301 Adds RGB10_A2, RGB10_A2UI,
1302 ES 3.2
1303 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1304 */
Brian Salomon44804c02018-01-23 16:51:28 -05001305
1306 // Correctness workarounds.
1307 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001308 bool disableSRGBForX86PowerVR = false;
1309 bool disableSRGBWriteControlForAdreno4xx = false;
1310 bool disableR8TexStorageForANGLEGL = false;
1311 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001312 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001313 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001314
1315 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1316 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1317 // and GL_RG on FBO textures.
1318 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1319
Greg Daniel09c94002018-06-08 22:11:51 +00001320 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1321
Brian Salomon44804c02018-01-23 16:51:28 -05001322 bool isX86PowerVR = false;
1323#if defined(SK_CPU_X86)
1324 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1325 isX86PowerVR = true;
1326 }
1327#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001328 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1329 // blacklist that device (and any others that might be sharing the same driver).
1330 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001331 disableSRGBWriteControlForAdreno4xx =
1332 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1333 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001334
1335 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1336 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1337 // check that we are not going to OpenGL.
1338 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1339
1340 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1341#if defined(SK_BUILD_FOR_MAC)
1342 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1343#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001344 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1345 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001346 }
1347
Brian Salomon71d9d842016-11-03 13:42:00 -04001348 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1349 ConfigInfo::kFBOColorAttachment_Flag;
1350 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001351 if (kNone_MSFBOType != fMSFBOType) {
1352 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1353 }
bsalomon41e4384e2016-01-08 09:12:44 -08001354 GrGLStandard standard = ctxInfo.standard();
1355 GrGLVersion version = ctxInfo.version();
1356
cblume790d5132016-02-29 11:13:29 -08001357 bool texStorageSupported = false;
1358 if (kGL_GrGLStandard == standard) {
1359 // The EXT version can apply to either GL or GLES.
1360 texStorageSupported = version >= GR_GL_VER(4,2) ||
1361 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1362 ctxInfo.hasExtension("GL_EXT_texture_storage");
1363 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001364 texStorageSupported = version >= GR_GL_VER(3,0) ||
1365 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001366 }
Adrienne Walker70e468f2018-08-22 16:05:27 -07001367 if (fDriverBugWorkarounds.disable_texture_storage) {
1368 texStorageSupported = false;
1369 }
cblume790d5132016-02-29 11:13:29 -08001370
Brian Salomone609e812018-01-17 14:00:47 -05001371 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001372
1373 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001374 if (kGL_GrGLStandard == standard) {
1375 textureRedSupport =
1376 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1377 } else {
1378 textureRedSupport =
1379 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1380 }
1381 }
1382
bsalomon30447372015-12-21 09:03:05 -08001383 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1384 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001385 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001386 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001387 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001388 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001389
1390 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1391 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001392 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001393 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001394 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001395 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001396 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1397 if (kGL_GrGLStandard == standard) {
1398 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1399 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001400 } else {
Kevin Lubick217056c2018-09-20 17:39:31 -04001401 bool isWebGL = false;
1402 // hack for skbug:8378
1403 #if IS_WEBGL==1
1404 isWebGL = true;
1405 #endif
1406 if (isWebGL || version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon41e4384e2016-01-08 09:12:44 -08001407 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1408 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1409 }
egdaniel4999df82016-01-07 17:06:04 -08001410 }
cblume790d5132016-02-29 11:13:29 -08001411 if (texStorageSupported) {
1412 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1413 }
bsalomoncdee0092016-01-08 13:20:12 -08001414 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001415
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001416 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1417 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1418 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1419 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1420 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1421 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1422 // supportedReadPixelsColorType never returns it.
1423 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1424 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1425 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1426 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1427 if (kGL_GrGLStandard == standard) {
1428 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1429 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1430 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1431 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1432 // becomes an issue.
1433 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1434 // but we don't support that just for simplicity's sake.
1435 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1436 } else {
1437 // 3.0 and the extension support this as a render buffer format.
1438 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1439 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1440 }
1441 }
1442 if (texStorageSupported) {
1443 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1444 }
1445 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1446 if (disableRGB8ForMali400) {
1447 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1448 }
1449
1450 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001451 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001452 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001453 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001454
1455 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1456 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1457 // GL_EXT_texture_format_BGRA8888.
1458 bool supportsBGRATexStorage = false;
1459
bsalomon41e4384e2016-01-08 09:12:44 -08001460 if (kGL_GrGLStandard == standard) {
1461 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1462 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1463 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1464 // Since the internal format is RGBA8, it is also renderable.
1465 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1466 allRenderFlags;
1467 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001468 // Since we are using RGBA8 we can use tex storage.
1469 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001470 } else {
1471 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1472 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001473 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1474 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1475 nonMSAARenderFlags;
1476
1477 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1478 supportsBGRATexStorage = true;
1479 }
1480 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1481 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1482 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1483 ConfigInfo::kRenderableWithMSAA_Flag;
1484 }
1485 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001486 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1487 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1488 // driver remembers the external format when the texture is created (with TexImage).
1489 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1490 // We could work around this, but it adds even more state tracking to code that is
1491 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1492 // This also side-steps some ambiguous interactions with the texture storage extension.
1493 if (version >= GR_GL_VER(3,0)) {
1494 // The APPLE extension doesn't make this renderable.
1495 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001496 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001497 }
bsalomon41e4384e2016-01-08 09:12:44 -08001498 }
1499 }
Brian Osman48c99192017-06-02 08:45:06 -04001500
Greg Daniel0ff79b22018-02-15 12:33:33 -05001501 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001502 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001503 }
bsalomoncdee0092016-01-08 13:20:12 -08001504 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001505
Brian Osman2b23c4b2018-06-01 12:25:08 -04001506 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001507 if (kGL_GrGLStandard == standard) {
1508 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001509 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001510 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1511 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1512 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001513 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001514 }
1515 }
1516 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001517 if (fSRGBSupport) {
1518 fSRGBWriteControl = true;
1519 }
bsalomon41e4384e2016-01-08 09:12:44 -08001520 } else {
brianosman20471892016-12-02 06:43:32 -08001521 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001522 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001523 fSRGBSupport = false;
1524 }
bsalomon41e4384e2016-01-08 09:12:44 -08001525 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1526 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001527 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001528 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001529 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001530 }
brianosman20471892016-12-02 06:43:32 -08001531
1532 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1533 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1534 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1535 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1536 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1537 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1538 // affects Windows.
1539 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1540 fSRGBSupport = false;
1541 }
1542
Brian Osman48c99192017-06-02 08:45:06 -04001543 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1544 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1545 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1546
Brian Osman67999392017-05-31 16:19:34 -04001547 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001548 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001549 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1550 }
Brian Osman67999392017-05-31 16:19:34 -04001551
bsalomon30447372015-12-21 09:03:05 -08001552 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1553 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1554 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1555 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001556 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001557 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001558 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001559 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001560 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001561 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001562 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001563 }
Brian Osman48c99192017-06-02 08:45:06 -04001564 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1565 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001566 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1567 }
bsalomoncdee0092016-01-08 13:20:12 -08001568 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001569 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1570 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1571 // is in this format, for example).
1572 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1573 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1574 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1575 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001576 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001577 GR_GL_BGRA;
1578 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1579 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001580 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001581 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001582 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001583 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001584
brianosmana6359362016-03-21 06:55:37 -07001585 if (texStorageSupported) {
1586 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1587 }
1588 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1589
bsalomon30447372015-12-21 09:03:05 -08001590 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1591 if (this->ES2CompatibilitySupport()) {
1592 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1593 } else {
1594 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1595 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001596 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001597 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001598 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001599 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001600 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1601 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001602 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001603 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1604 }
1605 } else {
1606 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1607 }
cblume790d5132016-02-29 11:13:29 -08001608 // 565 is not a sized internal format on desktop GL. So on desktop with
1609 // 565 we always use an unsized internal format to let the system pick
1610 // the best sized format to convert the 565 data to. Since TexStorage
1611 // only allows sized internal formats we disallow it.
1612 //
1613 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1614 // update.
1615 if (texStorageSupported && kGL_GrGLStandard != standard) {
1616 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1617 }
bsalomoncdee0092016-01-08 13:20:12 -08001618 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001619
1620 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1621 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001622 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001623 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001624 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001625 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001626 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1627 if (kGL_GrGLStandard == standard) {
1628 if (version >= GR_GL_VER(4, 2)) {
1629 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1630 }
1631 } else {
1632 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1633 }
cblume790d5132016-02-29 11:13:29 -08001634 if (texStorageSupported) {
1635 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1636 }
bsalomoncdee0092016-01-08 13:20:12 -08001637 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001638
Brian Osman10fc6fd2018-03-02 11:01:10 -05001639 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1640 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001641 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001642 GR_GL_RGBA;
1643 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1644 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1645 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1646 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1647 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1648 allRenderFlags;
1649 }
1650 if (texStorageSupported) {
1651 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1652 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001653 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1654
Greg Danielef59d872017-11-17 16:47:21 -05001655 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1656 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1657
1658 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1659 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1660 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1661 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1662 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001663 }
Greg Danielef59d872017-11-17 16:47:21 -05001664 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1665 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001666 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001667 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1668 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1669 alphaInfo.fFlags |= allRenderFlags;
1670 }
1671
1672 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1673 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1674 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1675 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1676 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001677 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001678 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001679
Brian Osman48c99192017-06-02 08:45:06 -04001680 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1681 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001682 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001683 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1684 }
1685 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1686 }
1687
Brian Salomone609e812018-01-17 14:00:47 -05001688 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001689 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001690 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1691 } else {
1692 redInfo.fFlags = 0;
1693
1694 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001695 }
bsalomon41e4384e2016-01-08 09:12:44 -08001696
Greg Daniel7af060a2017-12-05 16:27:11 -05001697 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1698 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1699 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1700 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1701 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001702 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001703 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1704 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1705 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1706 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001707 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001708
1709 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1710 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1711 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1712 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1713 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001714 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001715 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1716 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1717
Greg Daniel09c94002018-06-08 22:11:51 +00001718 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1719 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1720 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1721 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1722 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001723 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1724 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1725 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001726 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001727 }
Brian Osman48c99192017-06-02 08:45:06 -04001728 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001729 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001730 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1731 }
1732 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1733 }
1734
Brian Salomone609e812018-01-17 14:00:47 -05001735 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001736 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1737 } else {
1738 grayRedInfo.fFlags = 0;
1739 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001740 }
1741
bsalomon41e4384e2016-01-08 09:12:44 -08001742 // Check for [half] floating point texture support
1743 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1744 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1745 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
Chris Daltoneff01a72018-07-19 17:06:39 -06001746 bool hasFP32Textures = false;
1747 bool hasFP16Textures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001748 bool rgIsTexturable = false;
Chris Daltoneff01a72018-07-19 17:06:39 -06001749 bool hasFP32RenderTargets = false;
Brian Salomon75975512018-10-02 12:21:38 -04001750 enum class HalfFPRenderTargetSupport { kNone, kRGBAOnly, kAll };
1751 HalfFPRenderTargetSupport halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kNone;
bsalomon41e4384e2016-01-08 09:12:44 -08001752 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001753 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001754
1755 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001756 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001757 hasFP32Textures = true;
1758 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001759 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001760 hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001761 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
bsalomon41e4384e2016-01-08 09:12:44 -08001762 }
1763 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001764 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001765 hasFP32Textures = true;
1766 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001767 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001768 } else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1769 ctxInfo.hasExtension("GL_OES_texture_float")) {
1770 hasFP32Textures = true;
1771 hasFP16Textures = true;
1772 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1773 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1774 hasFP16Textures = true;
1775 }
1776
1777 if (version >= GR_GL_VER(3, 2)) {
1778 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to solve
1779 // many precision issues and no clients actually want this yet.
1780 // hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001781 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
Chris Daltoneff01a72018-07-19 17:06:39 -06001782 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
1783 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to
1784 // solve many precision issues and no clients actually want this yet.
1785 // hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001786 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
Chris Daltoneff01a72018-07-19 17:06:39 -06001787 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
Brian Salomon75975512018-10-02 12:21:38 -04001788 // This extension only enables half float support rendering for RGBA.
1789 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kRGBAOnly;
bsalomon41e4384e2016-01-08 09:12:44 -08001790 }
1791 }
bsalomon30447372015-12-21 09:03:05 -08001792
csmartdalton6aa0e112017-02-08 16:14:11 -05001793 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1794 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1795 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1796 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1797 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001798 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001799 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1800 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001801 if (hasFP32Textures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001802 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
Chris Daltoneff01a72018-07-19 17:06:39 -06001803 if (hasFP32RenderTargets) {
csmartdalton6aa0e112017-02-08 16:14:11 -05001804 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1805 }
bsalomon41e4384e2016-01-08 09:12:44 -08001806 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001807 if (texStorageSupported) {
1808 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1809 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001810 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001811 }
bsalomon30447372015-12-21 09:03:05 -08001812
Greg Danielef59d872017-11-17 16:47:21 -05001813 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001814 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001815 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001816 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001817 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001818 }
Greg Danielef59d872017-11-17 16:47:21 -05001819 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1820 redHalf.fFormats.fExternalType = redHalfExternalType;
1821 redHalf.fFormatType = kFloat_FormatType;
1822 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1823 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001824 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001825 redHalf.fSwizzle = GrSwizzle::RRRR();
Chris Daltoneff01a72018-07-19 17:06:39 -06001826 if (textureRedSupport && hasFP16Textures) {
Greg Danielef59d872017-11-17 16:47:21 -05001827 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1828
Brian Salomon75975512018-10-02 12:21:38 -04001829 if (halfFPRenderTargetSupport == HalfFPRenderTargetSupport::kAll) {
Greg Danielef59d872017-11-17 16:47:21 -05001830 redHalf.fFlags |= fpRenderFlags;
1831 }
1832
1833 if (texStorageSupported && !isCommandBufferES2) {
1834 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1835 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001836 }
Greg Danielef59d872017-11-17 16:47:21 -05001837 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001838
1839 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1840 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001841 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001842 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001843 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001844 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1845 } else {
1846 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1847 }
bsalomon7928ef62016-01-05 10:26:39 -08001848 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001849 if (hasFP16Textures) {
bsalomon41e4384e2016-01-08 09:12:44 -08001850 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1851 // ES requires 3.2 or EXT_color_buffer_half_float.
Brian Salomon75975512018-10-02 12:21:38 -04001852 if (halfFPRenderTargetSupport != HalfFPRenderTargetSupport::kNone) {
bsalomon41e4384e2016-01-08 09:12:44 -08001853 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1854 }
1855 }
cblume790d5132016-02-29 11:13:29 -08001856 if (texStorageSupported) {
1857 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1858 }
bsalomoncdee0092016-01-08 13:20:12 -08001859 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001860
bsalomon30447372015-12-21 09:03:05 -08001861 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1862
1863 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001864 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1865 ctxInfo.version() >= GR_GL_VER(3,0));
1866 // All ES versions (thus far) require sized internal formats for render buffers.
1867 // TODO: Always use sized internal format?
1868 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1869
bsalomon30447372015-12-21 09:03:05 -08001870 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001871 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1872 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001873 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001874 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001875 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1876 fConfigTable[i].fFormats.fSizedInternalFormat :
1877 fConfigTable[i].fFormats.fBaseInternalFormat;
1878 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001879 fConfigTable[i].fFormats.fSizedInternalFormat :
1880 fConfigTable[i].fFormats.fBaseInternalFormat;
1881 }
Brian Salomon44804c02018-01-23 16:51:28 -05001882 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1883 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1884 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1885 // in ES.
1886 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1887 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1888 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1889 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001890 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1891 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001892 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1893 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001894 }
1895
bsalomon30447372015-12-21 09:03:05 -08001896 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1897 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1898 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1899 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1900 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001901 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001902 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001903
1904 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1905 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1906 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1907 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001908 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001909 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1910 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1911 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1912 // slot.
1913 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1914 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001915
1916 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1917 // as a base format.
1918 // GL_EXT_texture_format_BGRA8888:
1919 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1920 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1921 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001922 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001923 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1924 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1925 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001926 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001927 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1928 }
1929
bsalomoncdee0092016-01-08 13:20:12 -08001930 // If we don't have texture swizzle support then the shader generator must insert the
1931 // swizzle into shader code.
1932 if (!this->textureSwizzleSupport()) {
1933 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001934 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001935 }
1936 }
1937
bsalomon7f9b2e42016-01-12 13:29:26 -08001938 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1939 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1940 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001941 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001942 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1943 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1944 if (GrPixelConfigIsAlphaOnly(config) &&
1945 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001946 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001947 }
1948 }
1949 }
1950
Greg Daniel81e7bf82017-07-19 14:47:42 -04001951 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1952 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001953 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1954 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001955 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001956 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1957 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001958 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001959 int count;
1960 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1961 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1962 1, &count);
1963 if (count) {
1964 int* temp = new int[count];
1965 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1966 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001967 // GL has a concept of MSAA rasterization with a single sample but we do not.
1968 if (count && temp[count - 1] == 1) {
1969 --count;
1970 SkASSERT(!count || temp[count -1] > 1);
1971 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001972 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001973 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001974 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001975 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001976 for (int j = 0; j < count; ++j) {
1977 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1978 }
1979 delete[] temp;
1980 }
1981 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001982 // Fake out the table using some semi-standard counts up to the max allowed sample
1983 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001984 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001985 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1986 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1987 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1988 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1989 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001990 // Chrome has a mock GL implementation that returns 0.
1991 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05001992
Brian Salomonbdecacf2018-02-02 20:32:49 -05001993 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04001994 int count = SK_ARRAY_COUNT(kDefaultSamples);
1995 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001996 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001997 break;
1998 }
1999 }
2000 if (count > 0) {
2001 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
2002 }
2003 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002004 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
2005 fConfigTable[i].fColorSampleCounts.setCount(1);
2006 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002007 }
2008 }
2009
bsalomon30447372015-12-21 09:03:05 -08002010#ifdef SK_DEBUG
2011 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002012 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002013 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002014 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2015 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002016 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2017 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2018 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2019 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002020 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2021 fConfigTable[i].fFormats.fBaseInternalFormat);
2022 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002023 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002024 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2025 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2026 fConfigTable[i].fFormats.fExternalFormat[j]);
2027 }
2028 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002029 }
2030#endif
2031}
2032
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002033bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2034 bool dstIsTextureable, bool dstIsGLTexture2D,
2035 GrSurfaceOrigin dstOrigin,
2036 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2037 bool srcIsTextureable, bool srcIsGLTexture2D,
2038 GrSurfaceOrigin srcOrigin) const {
2039 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2040 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2041 // many drivers would allow it to work, but ANGLE does not.
2042 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2043 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2044 return false;
2045 }
2046
2047 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2048 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2049 return false;
2050 }
2051
2052 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2053 // texture.
2054 if (!dstIsTextureable) {
2055 return false;
2056 }
2057
2058 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2059 // is required
2060 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2061 (!srcIsTextureable || srcIsGLTexture2D) &&
2062 dstIsGLTexture2D &&
2063 dstOrigin == srcOrigin) {
2064 return true;
2065 } else {
2066 return false;
2067 }
2068}
2069
2070bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2071 bool dstIsTextureable, bool dstIsGLTexture2D,
2072 GrSurfaceOrigin dstOrigin,
2073 GrPixelConfig srcConfig, int srcSampleCnt,
2074 bool srcIsTextureable, bool srcIsGLTexture2D,
2075 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2076 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2077 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2078 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2079 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2080 return false;
2081 }
2082
2083 if (dstIsTextureable && !dstIsGLTexture2D) {
2084 return false;
2085 }
2086 if (srcIsTextureable && !srcIsGLTexture2D) {
2087 return false;
2088 }
2089
2090 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2091 return false;
2092 }
2093 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2094 // We would mirror to compensate for origin changes. Note that copySurface is
2095 // specified such that the src and dst rects are the same.
2096 if (dstOrigin != srcOrigin) {
2097 return false;
2098 }
2099 }
2100
2101 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2102 if (srcSampleCnt > 1) {
2103 if (1 == dstSampleCnt) {
2104 return false;
2105 }
2106 if (SkRect::Make(srcRect) != srcBounds) {
2107 return false;
2108 }
2109 }
2110 }
2111
2112 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2113 if (dstSampleCnt > 1) {
2114 return false;
2115 }
2116 }
2117
2118 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2119 if (dstConfig != srcConfig) {
2120 return false;
2121 }
2122 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2123 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2124 return false;
2125 }
2126 }
2127
2128 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2129 if (srcSampleCnt > 1) {
2130 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2131 return false;
2132 }
2133 if (dstOrigin != srcOrigin) {
2134 return false;
2135 }
2136 }
2137 }
2138 return true;
2139}
2140
2141bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2142 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2143}
2144
2145static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2146 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2147 if (!rt) {
2148 return false;
2149 }
2150 // A RT has a separate MSAA renderbuffer if:
2151 // 1) It's multisampled
2152 // 2) We're using an extension with separate MSAA renderbuffers
2153 // 3) It's not FBO 0, which is special and always auto-resolves
2154 return rt->numColorSamples() > 1 &&
2155 glCaps.usesMSAARenderBuffers() &&
2156 !rt->rtPriv().glRTFBOIDIs0();
2157}
2158
2159bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2160 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2161 GrSurfaceOrigin dstOrigin = dst->origin();
2162 GrSurfaceOrigin srcOrigin = src->origin();
2163
2164 GrPixelConfig dstConfig = dst->config();
2165 GrPixelConfig srcConfig = src->config();
2166
2167 int dstSampleCnt = 0;
2168 int srcSampleCnt = 0;
2169 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2170 dstSampleCnt = rtProxy->numColorSamples();
2171 }
2172 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2173 srcSampleCnt = rtProxy->numColorSamples();
2174 }
2175 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2176 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2177
2178 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2179 // swizzle.
2180 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2181 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2182 return false;
2183 }
2184
2185 const GrTextureProxy* dstTex = dst->asTextureProxy();
2186 const GrTextureProxy* srcTex = src->asTextureProxy();
2187
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002188 bool dstIsTex2D = dstTex ? (dstTex->textureType() == GrTextureType::k2D) : false;
2189 bool srcIsTex2D = srcTex ? (srcTex->textureType() == GrTextureType::k2D) : false;
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002190
2191 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2192 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2193 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2194 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2195 // know we will at least be able to do it as a draw.
2196#ifdef SK_DEBUG
2197 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2198 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2199 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2200 !src->priv().isExact()) {
2201 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2202 }
2203#endif
2204
2205 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2206 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2207 srcConfig, has_msaa_render_buffer(src, *this),
2208 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2209 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2210 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2211 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2212 dstPoint) ||
2213 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2214}
2215
Robert Phillipsbf25d432017-04-07 10:08:53 -04002216bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002217 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2218 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002219 // By default, we don't require rects to match.
2220 *rectsMustMatch = false;
2221
2222 // By default, we allow subrects.
2223 *disallowSubrect = false;
2224
Brian Salomon467921e2017-03-06 16:17:12 -05002225 // If the src is a texture, we can implement the blit as a draw assuming the config is
2226 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002227 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002228 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002229 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2230 desc->fConfig = src->config();
2231 return true;
2232 }
2233
Robert Phillipsbf25d432017-04-07 10:08:53 -04002234 {
2235 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2236 // wrapped. In that case the proxy would already be instantiated.
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002237 const GrTexture* srcTexture = src->peekTexture();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002238 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2239 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2240 // Not supported for FBO blit or CopyTexSubImage
2241 return false;
2242 }
Brian Salomon467921e2017-03-06 16:17:12 -05002243 }
2244
2245 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2246 // possible and we return false to fallback to creating a render target dst for render-to-
2247 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2248 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002249 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002250 bool rectsMustMatchForBlitFramebuffer = false;
2251 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002252 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002253 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2254 rectsMustMatchForBlitFramebuffer = true;
2255 disallowSubrectForBlitFramebuffer = true;
2256 // Mirroring causes rects to mismatch later, don't allow it.
2257 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002258 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2259 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002260 rectsMustMatchForBlitFramebuffer = true;
2261 // Mirroring causes rects to mismatch later, don't allow it.
2262 originForBlitFramebuffer = src->origin();
2263 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002264 originForBlitFramebuffer = src->origin();
2265 }
2266
2267 // Check for format issues with glCopyTexSubImage2D
2268 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2269 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2270 // then we set up for that, otherwise fail.
2271 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002272 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002273 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002274 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2275 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002276 return true;
2277 }
2278 return false;
2279 }
2280
Robert Phillipsbf25d432017-04-07 10:08:53 -04002281 {
Brian Salomon63e79732017-05-15 21:23:13 -04002282 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2283 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002284 if (srcIsMSAARenderbuffer) {
2285 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2286 // blit or fail.
2287 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002288 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002289 desc->fConfig = src->config();
2290 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2291 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2292 return true;
2293 }
2294 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002295 }
Brian Salomon467921e2017-03-06 16:17:12 -05002296 }
2297
2298 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002299 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002300 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002301 desc->fFlags = kNone_GrSurfaceFlags;
2302 return true;
2303}
2304
Greg Daniel691f5e72018-02-28 14:21:34 -05002305void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2306 const GrContextOptions& contextOptions,
2307 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002308 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2309 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002310 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2311 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002312 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002313 fDiscardRenderTargetSupport = false;
2314 fInvalidateFBType = kNone_InvalidateFBType;
2315 }
2316
2317 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2318 // 340.96 and 367.57.
2319 if (kGL_GrGLStandard == ctxInfo.standard() &&
2320 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002321 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002322 fClearTextureSupport = false;
2323 }
2324
2325 // Calling glClearTexImage crashes on the NexusPlayer.
2326 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2327 fClearTextureSupport = false;
2328 }
2329
Brian Salomon01b476a2018-01-23 11:06:41 -05002330#ifdef SK_BUILD_FOR_MAC
Chris Dalton6989ba42018-10-03 10:34:09 -06002331 // Radeon MacBooks hit a crash in glReadPixels() when using geometry shaders.
2332 // http://skbug.com/8097
2333 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2334 shaderCaps->fGeometryShaderSupport = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002335 }
Chris Dalton6989ba42018-10-03 10:34:09 -06002336 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2337 shaderCaps->fGSInvocationsSupport = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002338#endif
2339
2340 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2341 // shaders. @127.0 is the earliest verified driver to not crash.
2342 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002343 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002344 shaderCaps->fGeometryShaderSupport = false;
2345 }
2346
2347#if defined(__has_feature)
2348#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2349 // See skbug.com/7058
2350 fMapBufferType = kNone_MapBufferType;
2351 fMapBufferFlags = kNone_MapFlags;
2352#endif
2353#endif
2354
2355 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2356 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2357 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2358 // unclear whether this really affects a wide range of devices.
2359 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002360 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002361 fMapBufferType = kNone_MapBufferType;
2362 fMapBufferFlags = kNone_MapFlags;
2363 }
2364
2365 // TODO: re-enable for ANGLE
2366 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2367 fTransferBufferType = kNone_TransferBufferType;
2368 }
2369
2370 // Using MIPs on this GPU seems to be a source of trouble.
2371 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2372 fMipMapSupport = false;
2373 }
2374
2375 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2376 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2377 // around a driver bug related to gl_FragCoord.
2378 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2379 fMaxClipAnalyticFPs = 0;
2380 }
2381
2382#ifndef SK_BUILD_FOR_IOS
2383 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2384 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2385 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2386 ctxInfo.driver() != kChromium_GrGLDriver)) {
2387 fUseDrawToClearColor = true;
2388 }
2389#endif
2390
2391 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2392 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2393 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2394 fUseDrawToClearColor = true;
2395 }
2396
2397#ifdef SK_BUILD_FOR_MAC
2398 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2399 // full screen clears
2400 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2401 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002402 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2403 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2404 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2405 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002406 fUseDrawToClearColor = true;
2407 }
2408#endif
2409
2410 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2411 // bugs seems to involve clearing too much and not skipping the clear.
2412 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2413 // but only for D3D11 ANGLE.
2414 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2415 fUseDrawToClearColor = true;
2416 }
2417
Chris Dalton1214be92018-06-28 19:06:27 -06002418 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2419 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002420 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002421 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002422 fUseDrawToClearStencilClip = true;
2423 }
2424 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2425 }
2426
Adrienne Walker94f585e2018-05-15 11:47:07 -07002427 if (fDriverBugWorkarounds.gl_clear_broken) {
2428 fUseDrawToClearColor = true;
2429 fUseDrawToClearStencilClip = true;
2430 }
2431
Brian Salomon01b476a2018-01-23 11:06:41 -05002432 // This was reproduced on the following configurations:
2433 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2434 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2435 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2436 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2437 // and not produced on:
2438 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2439 // The particular lines that get dropped from test images varies across different devices.
2440 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002441 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002442 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2443 }
2444
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002445 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2446 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2447 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002448 fRequiresFlushBetweenNonAndInstancedDraws = true;
2449 }
2450
Brian Osman1348ed02018-09-12 09:08:39 -04002451 // This was reproduced on a Pixel 1, but the unit test + config + options that exercise it are
2452 // only tested on very specific bots. The driver claims that ReadPixels is an invalid operation
2453 // when reading from an auto-resolving MSAA framebuffer that has stencil attached.
2454 if (kQualcomm_GrGLDriver == ctxInfo.driver()) {
2455 fDetachStencilFromMSAABuffersBeforeReadPixels = true;
2456 }
2457
Brian Salomon01b476a2018-01-23 11:06:41 -05002458 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
Chris Dalton1b4ad762018-10-04 11:58:09 -06002459 // Our Chromebook with kPowerVRRogue_GrGLRenderer crashes on large instanced draws. The
2460 // current minimum number of instances observed to crash is somewhere between 2^14 and 2^15.
2461 // Keep the number of instances below 1000, just to be safe.
2462 fMaxInstancesPerDrawWithoutCrashing = 999;
Adrienne Walker001cae02018-05-15 11:38:44 -07002463 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
Chris Dalton1b4ad762018-10-04 11:58:09 -06002464 fMaxInstancesPerDrawWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002465 }
2466
2467 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002468 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002469 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2470 fUseDrawInsteadOfAllRenderTargetWrites = true;
2471 }
2472
2473 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2474 fSampleShadingSupport = false;
2475 }
2476
2477#ifdef SK_BUILD_FOR_MAC
2478 static constexpr bool isMAC = true;
2479#else
2480 static constexpr bool isMAC = false;
2481#endif
2482
2483 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2484 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2485 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2486 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2487 if (fMipMapLevelAndLodControlSupport &&
2488 (contextOptions.fDoManualMipmapping ||
2489 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2490 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2491 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2492 fDoManualMipmapping = true;
2493 }
2494
2495 // See http://crbug.com/710443
2496#ifdef SK_BUILD_FOR_MAC
2497 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2498 fClearToBoundaryValuesIsBroken = true;
2499 }
2500#endif
2501 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2502 fDrawArraysBaseVertexIsBroken = true;
2503 }
2504
Brian Salomon01b476a2018-01-23 11:06:41 -05002505 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2506 // Galaxy S7.
2507 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2508 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2509 shaderCaps->fFBFetchSupport = false;
2510 }
2511
Brian Salomon01b476a2018-01-23 11:06:41 -05002512 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2513 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2514
2515 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2516 // function that may require a gradient calculation inside a conditional block may return
2517 // undefined results". This appears to be an issue with the 'any' call since even the simple
2518 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2519 // from our GrTextureDomain processor.
2520 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2521
2522 // Known issue on at least some Intel platforms:
2523 // http://code.google.com/p/skia/issues/detail?id=946
2524 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2525 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2526 }
2527
Chris Dalton0090ef62018-03-28 17:35:00 -06002528 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002529 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2530 // so we must do the abs first in a separate expression.
2531 shaderCaps->fCanUseMinAndAbsTogether = false;
2532
2533 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2534 // must avoid this condition.
2535 shaderCaps->fCanUseFractForNegativeValues = false;
2536 }
2537
2538 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2539 // thus must us -1.0 * %s.x to work correctly
2540 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2541 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2542 }
2543
2544 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2545 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2546 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2547 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2548 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2549 }
2550
2551 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2552 // the original dst color when reading the outColor even after being written to. By using a
2553 // local outColor we can work around this bug.
2554 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2555 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2556 }
2557
2558 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2559 // color, and that uniform contains an opaque color, and the output of the shader is only based
2560 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2561 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2562 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2563 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2564 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2565 shaderCaps->fMustObfuscateUniformColor = true;
2566 }
2567#ifdef SK_BUILD_FOR_WIN
2568 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2569 //
2570 // Basically, if a shader has a construct like:
2571 //
2572 // float x = someCondition ? someValue : 0;
2573 // float2 result = (0 == x) ? float2(x, x)
2574 // : float2(2 * x / x, 0);
2575 //
2576 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2577 // we've explicitly guarded the division with a check against zero. This manifests in much
2578 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2579 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2580 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2581 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2582 }
2583#endif
2584
2585 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002586 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002587 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2588 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002589 }
2590
Chris Dalton0090ef62018-03-28 17:35:00 -06002591 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2592 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2593 shaderCaps->fCanUseFragCoord = false;
2594 }
2595
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002596 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2597 // (Are they implemented with fp16?)
2598 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2599 shaderCaps->fIncompleteShortIntPrecision = true;
2600 }
2601
Adrienne Walkeree8295c2018-08-21 10:56:30 -07002602 if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
2603 shaderCaps->fAddAndTrueToLoopCondition = true;
2604 }
2605
Adrienne Walkerc02165f2018-08-21 11:08:11 -07002606 if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
2607 shaderCaps->fUnfoldShortCircuitAsTernary = true;
2608 }
2609
Adrienne Walker92b161f2018-08-22 10:41:52 -07002610 if (fDriverBugWorkarounds.emulate_abs_int_function) {
2611 shaderCaps->fEmulateAbsIntFunction = true;
2612 }
2613
Adrienne Walker8b23ca62018-08-22 10:45:41 -07002614 if (fDriverBugWorkarounds.rewrite_do_while_loops) {
2615 shaderCaps->fRewriteDoWhileLoops = true;
2616 }
2617
Adrienne Walker2f4c09b2018-08-22 16:04:57 -07002618 if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
2619 shaderCaps->fRemovePowWithConstantExponent = true;
2620 }
2621
Brian Salomon01b476a2018-01-23 11:06:41 -05002622 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2623 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002624 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2625 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002626 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2627 kIntel_GrGLDriver == ctxInfo.driver() ||
2628 kChromium_GrGLDriver == ctxInfo.driver()) {
2629 fBlendEquationSupport = kBasic_BlendEquationSupport;
2630 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2631 }
2632
2633 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2634 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002635 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002636 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002637 fBlendEquationSupport = kBasic_BlendEquationSupport;
2638 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2639 }
2640
Adrienne Walker68314842018-05-14 14:02:53 -07002641 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2642 fBlendEquationSupport = kBasic_BlendEquationSupport;
2643 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2644 }
2645
Brian Salomon01b476a2018-01-23 11:06:41 -05002646 if (this->advancedBlendEquationSupport()) {
2647 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002648 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002649 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2650 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2651 (1 << kColorBurn_GrBlendEquation);
2652 }
2653 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2654 // Blacklist color-burn on ARM until the fix is released.
2655 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2656 }
2657 }
2658
2659 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2660 if (fMultisampleDisableSupport &&
2661 this->shaderCaps()->dualSourceBlendingSupport() &&
2662 this->shaderCaps()->pathRenderingSupport() &&
2663 fUsesMixedSamples &&
2664#if GR_TEST_UTILS
2665 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2666#endif
2667 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2668 kChromium_GrGLDriver == ctxInfo.driver())) {
2669 fDiscardRenderTargetSupport = false;
2670 fInvalidateFBType = kNone_InvalidateFBType;
2671 }
Brian Osmanc585e202018-04-04 14:08:27 -04002672
Brian Osman061020e2018-04-17 14:22:15 -04002673 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2674 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2675 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2676 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002677 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2678 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002679 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002680 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002681 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2682 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002683 }
Brian Osman2fa53742018-05-03 15:05:12 -04002684
2685#ifdef SK_BUILD_FOR_IOS
2686 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2687 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2688 // is to just blacklist the feature.
2689 // https://github.com/flutter/flutter/issues/16718
2690 // https://bugreport.apple.com/web/?problemID=39948888
2691 fUnpackRowLengthSupport = false;
2692#endif
Brian Salomon01b476a2018-01-23 11:06:41 -05002693}
2694
csmartdaltone0d36292016-07-29 08:14:20 -07002695void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002696 if (options.fDisableDriverCorrectnessWorkarounds) {
2697 SkASSERT(!fDoManualMipmapping);
2698 SkASSERT(!fClearToBoundaryValuesIsBroken);
Chris Dalton1b4ad762018-10-04 11:58:09 -06002699 SkASSERT(0 == fMaxInstancesPerDrawWithoutCrashing);
Brian Salomon01b476a2018-01-23 11:06:41 -05002700 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2701 SkASSERT(!fUseDrawToClearColor);
2702 SkASSERT(!fUseDrawToClearStencilClip);
2703 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2704 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2705 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002706 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Osman1348ed02018-09-12 09:08:39 -04002707 SkASSERT(!fDetachStencilFromMSAABuffersBeforeReadPixels);
Brian Salomon01b476a2018-01-23 11:06:41 -05002708 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002709 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2710 fUseDrawToClearColor = false;
2711 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2712 fUseDrawToClearColor = true;
2713 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002714 if (options.fDoManualMipmapping) {
2715 fDoManualMipmapping = true;
2716 }
csmartdaltone0d36292016-07-29 08:14:20 -07002717}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002718
Brian Salomon3d86a192018-02-27 16:46:11 -05002719bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2720 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2721 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2722 if (tex->hasBaseLevelBeenBoundToFBO()) {
2723 return false;
2724 }
2725 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002726 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002727 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2728 return false;
2729 }
2730 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2731 return false;
2732 }
2733 return SkToBool(surface->asTexture());
2734 }
2735 return true;
2736}
2737
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002738bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2739 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2740 // We don't support reading pixels directly from EXTERNAL textures as it would require
2741 // binding the texture to a FBO.
2742 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2743 return false;
2744 }
2745 }
2746 return true;
2747}
2748
2749GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2750 GrColorType dstColorType) const {
2751 // For now, we mostly report the read back format that is required by the ES spec without
2752 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2753 // this as makes sense to increase performance and correctness.
2754 switch (fConfigTable[config].fFormatType) {
2755 case kNormalizedFixedPoint_FormatType:
2756 return GrColorType::kRGBA_8888;
2757 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002758 if ((kAlpha_half_GrPixelConfig == config ||
2759 kAlpha_half_as_Red_GrPixelConfig == config) &&
2760 GrColorType::kAlpha_F16 == dstColorType) {
2761 return GrColorType::kAlpha_F16;
2762 }
2763 // And similar for full float RG.
2764 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2765 return GrColorType::kRG_F32;
2766 }
2767 return GrColorType::kRGBA_F32;
2768 }
2769 return GrColorType::kUnknown;
2770}
2771
Greg Daniel2a303902018-02-20 10:25:54 -05002772bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002773 GrGLFramebufferInfo fbInfo;
2774 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002775 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002776 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002777}
2778
Brian Salomonbdecacf2018-02-02 20:32:49 -05002779int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2780 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002781 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002782 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002783 return 0;
2784 }
2785
Brian Salomonbdecacf2018-02-02 20:32:49 -05002786 if (1 == requestedCount) {
2787 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2788 }
2789
Greg Daniel81e7bf82017-07-19 14:47:42 -04002790 for (int i = 0; i < count; ++i) {
2791 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002792 int count = fConfigTable[config].fColorSampleCounts[i];
2793 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2794 count = SkTMin(count, 4);
2795 }
2796 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002797 }
2798 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002799 return 0;
2800}
2801
2802int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2803 const auto& table = fConfigTable[config].fColorSampleCounts;
2804 if (!table.count()) {
2805 return 0;
2806 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002807 int count = table[table.count() - 1];
2808 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2809 count = SkTMin(count, 4);
2810 }
2811 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002812}
2813
Greg Danielfaa095e2017-12-19 13:15:02 -05002814bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2815 GrGLStandard standard) {
2816 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002817
2818 switch (ct) {
2819 case kUnknown_SkColorType:
2820 return false;
2821 case kAlpha_8_SkColorType:
2822 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002823 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002824 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002825 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002826 }
2827 break;
2828 case kRGB_565_SkColorType:
2829 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002830 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002831 }
2832 break;
2833 case kARGB_4444_SkColorType:
2834 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002835 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002836 }
2837 break;
2838 case kRGBA_8888_SkColorType:
2839 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002840 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002841 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002842 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002843 }
2844 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002845 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002846 if (GR_GL_RGB8 == format) {
2847 *config = kRGB_888_GrPixelConfig;
2848 }
2849 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002850 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002851 if (GR_GL_RGBA8 == format) {
2852 if (kGL_GrGLStandard == standard) {
2853 *config = kBGRA_8888_GrPixelConfig;
2854 }
2855 } else if (GR_GL_BGRA8 == format) {
2856 if (kGLES_GrGLStandard == standard) {
2857 *config = kBGRA_8888_GrPixelConfig;
2858 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002859 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002860 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002861 }
2862 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002863 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002864 if (GR_GL_RGB10_A2 == format) {
2865 *config = kRGBA_1010102_GrPixelConfig;
2866 }
2867 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002868 case kRGB_101010x_SkColorType:
2869 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002870 case kGray_8_SkColorType:
2871 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002872 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002873 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002874 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002875 }
2876 break;
2877 case kRGBA_F16_SkColorType:
2878 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002879 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002880 }
2881 break;
Mike Klein37854712018-06-26 11:43:06 -04002882 case kRGBA_F32_SkColorType:
2883 if (GR_GL_RGBA32F == format) {
2884 *config = kRGBA_float_GrPixelConfig;
2885 }
2886 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002887 }
2888
Greg Danielfaa095e2017-12-19 13:15:02 -05002889 return kUnknown_GrPixelConfig != *config;
2890}
2891
2892bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2893 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002894 GrGLTextureInfo texInfo;
2895 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002896 return false;
2897 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002898 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002899}
2900
2901bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2902 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002903 GrGLFramebufferInfo fbInfo;
2904 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002905 return false;
2906 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002907 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002908}
2909
Robert Phillipsfc711a22018-02-13 17:03:00 -05002910bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2911 GrPixelConfig* config) const {
2912 const GrGLenum* glFormat = format.getGLFormat();
2913 if (!glFormat) {
2914 return false;
2915 }
2916 return validate_sized_format(*glFormat, ct, config, fStandard);
2917}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002918
Timothy Liang036fdfe2018-06-28 15:50:36 -04002919#ifdef GR_TEST_UTILS
2920GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2921 const GrBackendTexture& backendTex) const {
2922 GrGLTextureInfo glInfo;
2923 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2924 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2925}
2926#endif