blob: 29803c39fa0315c334516949c11922c14ec31829 [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;
363 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500364 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
365 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800366 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500367 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800368 }
369 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500370 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800371 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500372 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800373
csmartdalton485a1202016-07-13 10:16:32 -0700374 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
375 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
376 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
377 // limit this decision to specific GPU families rather than basing it on the vendor alone.
378 if (!GR_GL_MUST_USE_VBO &&
379 !fIsCoreProfile &&
380 (kARM_GrGLVendor == ctxInfo.vendor() ||
381 kImagination_GrGLVendor == ctxInfo.vendor() ||
382 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
383 fPreferClientSideDynamicBuffers = true;
384 }
385
Eric Karl5c779752017-05-08 12:02:07 -0700386 if (!contextOptions.fAvoidStencilBuffers) {
387 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
388 this->initFSAASupport(contextOptions, ctxInfo, gli);
389 this->initStencilSupport(ctxInfo);
390 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400391
392 // Setup blit framebuffer
393 if (kGL_GrGLStandard != ctxInfo.standard()) {
394 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
395 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
396 kNoMSAADst_BlitFramebufferFlag |
397 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
398 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
399 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
400 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
401 // limitations.
402 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
403 kResolveMustBeFull_BlitFrambufferFlag |
404 kNoMSAADst_BlitFramebufferFlag |
405 kNoFormatConversion_BlitFramebufferFlag |
406 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
407 }
408 } else {
409 if (fUsesMixedSamples ||
410 ctxInfo.version() >= GR_GL_VER(3,0) ||
411 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
412 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
413 fBlitFramebufferFlags = 0;
414 }
415 }
416
cdalton1dd05422015-06-12 09:01:18 -0700417 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000418
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000419 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000420 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
421 // extension includes glMapBuffer.
422 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
423 fMapBufferFlags |= kSubset_MapFlag;
424 fMapBufferType = kMapBufferRange_MapBufferType;
425 } else {
426 fMapBufferType = kMapBuffer_MapBufferType;
427 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000428 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000429 // Unextended GLES2 doesn't have any buffer mapping.
430 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800431 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800432 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
433 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800434 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
435 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
436 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000437 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
438 fMapBufferFlags = kCanMap_MapFlag;
439 fMapBufferType = kMapBuffer_MapBufferType;
440 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000441 }
442
jvanverthd7a2c1f2015-12-07 07:36:44 -0800443 if (kGL_GrGLStandard == standard) {
444 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
445 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700446 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500447 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400448 if (version >= GR_GL_VER(3, 0) ||
449 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
450 // GL_EXT_unpack_subimage needed to support subtexture rectangles
451 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800452 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400453// TODO: get transfer buffers working in Chrome
454// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
455// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800456 }
457 }
458
joshualitte5b74c62015-06-01 14:17:47 -0700459 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
460 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700461 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700462#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500463 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
464 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
465 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700466 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700467#else
cdalton397536c2016-03-25 12:15:03 -0700468 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700469#endif
joshualitte5b74c62015-06-01 14:17:47 -0700470 }
471
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000472 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000473 fNPOTTextureTileSupport = true;
474 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000475 } else {
476 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000477 // ES3 has no limitations.
478 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
479 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000480 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
481 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
482 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
483 // to alllow arbitrary wrap modes, however.
484 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000485 }
486
bsalomon@google.combcce8922013-03-25 15:38:39 +0000487 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700488
489 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
490 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
491 }
492
bsalomon@google.combcce8922013-03-25 15:38:39 +0000493 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
494 // Our render targets are always created with textures as the color
495 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000496 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700497 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
498
499 if (kARM_GrGLVendor == ctxInfo.vendor()) {
500 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
501 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
502 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000503
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000504 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
505
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000506 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700507 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000508
robertphillips1b8e1b52015-06-24 06:54:10 -0700509#if 0
510 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
511 kQualcomm_GrGLVendor != ctxInfo.vendor();
512#endif
513
csmartdalton9bc11872016-08-09 12:42:47 -0700514 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
515 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700516 }
517
robertphillips63926682015-08-20 09:39:02 -0700518#ifdef SK_BUILD_FOR_WIN
519 // On ANGLE deferring flushes can lead to GPU starvation
520 fPreferVRAMUseOverFlushes = !isANGLE;
521#endif
522
bsalomon7dea7b72015-08-19 08:26:51 -0700523 if (kChromium_GrGLDriver == ctxInfo.driver()) {
524 fMustClearUploadedBufferData = true;
525 }
526
bsalomond08ea5f2015-02-20 06:58:13 -0800527 if (kGL_GrGLStandard == standard) {
528 // ARB allows mixed size FBO attachments, EXT does not.
529 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
530 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
531 fOversizedStencilSupport = true;
532 } else {
533 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
534 }
535 } else {
536 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
537 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
538 }
539
joshualitt58001552015-06-26 12:46:36 -0700540 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700541 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
542 ctxInfo.hasExtension("GL_ARB_draw_indirect");
543 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
544 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700545 (fDrawIndirectSupport &&
546 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700547 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700548 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800549 } else {
550 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700551 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
552 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
553 fBaseInstanceSupport = fDrawIndirectSupport &&
554 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700555 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800556 }
557
ethannicholas28ef4452016-03-25 09:26:03 -0700558 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500559 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700560 fSampleShadingSupport = true;
561 }
562 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
563 fSampleShadingSupport = true;
564 }
565
jvanverth84741b32016-09-30 08:39:02 -0700566 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
567 if (kGL_GrGLStandard == standard) {
568 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
569 fFenceSyncSupport = true;
570 }
Brian Osman93a23462017-06-21 15:13:39 -0400571 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700572 fFenceSyncSupport = true;
573 }
574
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400575 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500576 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500577
Brian Osman499bf1a2018-09-17 11:32:42 -0400578 // Half float vertex attributes requires GL3 or ES3
579 // It can also work with OES_VERTEX_HALF_FLOAT, but that requires a different enum.
580 if (kGL_GrGLStandard == standard) {
581 if (version >= GR_GL_VER(3, 0)) {
582 fHalfFloatVertexAttributeSupport = true;
583 }
584 } else if (version >= GR_GL_VER(3, 0)) {
585 fHalfFloatVertexAttributeSupport = true;
586 }
587
Brian Salomonf7232642018-09-19 08:58:08 -0400588 fDynamicStateArrayGeometryProcessorTextureSupport = true;
589
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400590 if (kGL_GrGLStandard == standard) {
591 if (version >= GR_GL_VER(4, 1)) {
592 fProgramBinarySupport = true;
593 }
594 } else if (version >= GR_GL_VER(3, 0)) {
595 fProgramBinarySupport = true;
596 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400597 if (fProgramBinarySupport) {
598 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400599 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400600 fProgramBinarySupport = count > 0;
601 }
bsalomoncdee0092016-01-08 13:20:12 -0800602 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
603 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800604 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700605
Brian Salomon01b476a2018-01-23 11:06:41 -0500606 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
607 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
608 }
609
cdalton4cd67132015-06-10 19:23:46 -0700610 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500611 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700612
Brian Salomon01b476a2018-01-23 11:06:41 -0500613 // For now these two are equivalent but we could have dst read in shader via some other method.
614 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000615}
616
egdaniel472d44e2015-10-22 08:20:00 -0700617const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
618 bool isCoreProfile) {
619 switch (generation) {
620 case k110_GrGLSLGeneration:
621 if (kGLES_GrGLStandard == standard) {
622 // ES2s shader language is based on version 1.20 but is version
623 // 1.00 of the ES language.
624 return "#version 100\n";
625 } else {
626 SkASSERT(kGL_GrGLStandard == standard);
627 return "#version 110\n";
628 }
629 case k130_GrGLSLGeneration:
630 SkASSERT(kGL_GrGLStandard == standard);
631 return "#version 130\n";
632 case k140_GrGLSLGeneration:
633 SkASSERT(kGL_GrGLStandard == standard);
634 return "#version 140\n";
635 case k150_GrGLSLGeneration:
636 SkASSERT(kGL_GrGLStandard == standard);
637 if (isCoreProfile) {
638 return "#version 150\n";
639 } else {
640 return "#version 150 compatibility\n";
641 }
642 case k330_GrGLSLGeneration:
643 if (kGLES_GrGLStandard == standard) {
644 return "#version 300 es\n";
645 } else {
646 SkASSERT(kGL_GrGLStandard == standard);
647 if (isCoreProfile) {
648 return "#version 330\n";
649 } else {
650 return "#version 330 compatibility\n";
651 }
652 }
cdalton33ad7012016-02-22 07:55:44 -0800653 case k400_GrGLSLGeneration:
654 SkASSERT(kGL_GrGLStandard == standard);
655 if (isCoreProfile) {
656 return "#version 400\n";
657 } else {
658 return "#version 400 compatibility\n";
659 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500660 case k420_GrGLSLGeneration:
661 SkASSERT(kGL_GrGLStandard == standard);
662 if (isCoreProfile) {
663 return "#version 420\n";
664 }
665 else {
666 return "#version 420 compatibility\n";
667 }
egdaniel472d44e2015-10-22 08:20:00 -0700668 case k310es_GrGLSLGeneration:
669 SkASSERT(kGLES_GrGLStandard == standard);
670 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800671 case k320es_GrGLSLGeneration:
672 SkASSERT(kGLES_GrGLStandard == standard);
673 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700674 }
675 return "<no version>";
676}
677
Chris Dalton47c8ed32017-11-15 18:27:09 -0700678bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
679 if (kGLES_GrGLStandard != ctxInfo.standard() &&
680 ctxInfo.version() < GR_GL_VER(4,1) &&
681 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
682 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
683 return true;
684 }
685 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
686 // geometry shaders don't have lower precision than vertex and fragment.
687 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
688 GrGLint range[2];
689 GrGLint bits;
690 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
691 if (range[0] < 127 || range[1] < 127 || bits < 23) {
692 return false;
693 }
694 }
695 return true;
696}
697
698void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700699 GrGLStandard standard = ctxInfo.standard();
700 GrGLVersion version = ctxInfo.version();
701
702 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500703 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700704 **************************************************************************/
705
Brian Salomon1edc5b92016-11-29 13:43:46 -0500706 GrShaderCaps* shaderCaps = fShaderCaps.get();
707 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700708 if (kGLES_GrGLStandard == standard) {
709 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500710 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
711 shaderCaps->fFBFetchSupport = true;
712 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
713 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700714 }
715 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
716 // 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 -0500717 shaderCaps->fFBFetchNeedsCustomOutput = false;
718 shaderCaps->fFBFetchSupport = true;
719 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
720 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700721 }
722 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
723 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500724 shaderCaps->fFBFetchNeedsCustomOutput = false;
725 shaderCaps->fFBFetchSupport = true;
726 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
727 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700728 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500729 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700730 }
731
cdaltonc08f1962016-02-12 12:14:06 -0800732 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500733 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800734 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500735 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800736 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
737 }
Brian Salomon41274562017-09-15 09:40:03 -0700738 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
739 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
740 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800741 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500742 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800743 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
744 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400745 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
746 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500747 shaderCaps->fNoPerspectiveInterpolationSupport = true;
748 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800749 "GL_NV_shader_noperspective_interpolation";
750 }
751 }
752
Brian Salomon1edc5b92016-11-29 13:43:46 -0500753 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
754 shaderCaps->fGLSLGeneration,
755 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800756
Brian Salomon1edc5b92016-11-29 13:43:46 -0500757 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
758 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800759 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800760
761 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500762 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800763 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
764 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500765 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800766 }
767
768 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500769 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800770 }
771
cdalton9c3f1432016-03-11 10:07:37 -0800772 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400773 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
774 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400775 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400776 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
777 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
778 // At least one driver has been found that has this extension without the "GL_" prefix.
779 shaderCaps->fExternalTextureSupport = true;
780 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800781 }
782 }
783
cdaltonc04ce672016-03-11 14:07:38 -0800784 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600785 shaderCaps->fVertexIDSupport = true;
786 } else {
787 // Desktop GLSL 3.30 == ES GLSL 3.00.
788 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
789 }
790
Chris Dalton7c7ff032018-03-28 20:09:58 -0600791 if (kGL_GrGLStandard == standard) {
792 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
793 } else {
794 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
795 }
796
Chris Dalton47c8ed32017-11-15 18:27:09 -0700797 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
798 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400799
800 // Unsigned integers only supported in and after GLSL 1.30.
801 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700802}
803
kkinnunencfe62e32015-07-01 02:58:50 -0700804bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700805 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
806
807 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700808 return false;
809 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700810
kkinnunencfe62e32015-07-01 02:58:50 -0700811 if (kGL_GrGLStandard == ctxInfo.standard()) {
812 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
813 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
814 return false;
815 }
816 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700817 if (!hasChromiumPathRendering &&
818 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700819 return false;
820 }
821 }
822 // We only support v1.3+ of GL_NV_path_rendering which allows us to
823 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
824 // additions are detected by checking the existence of the function.
825 // We also use *Then* functions that not all drivers might have. Check
826 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800827 if (!gli->fFunctions.fStencilThenCoverFillPath ||
828 !gli->fFunctions.fStencilThenCoverStrokePath ||
829 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
830 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
831 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700832 return false;
833 }
834 return true;
835}
bsalomon1aa20292016-01-22 08:16:09 -0800836
Brian Salomon71d9d842016-11-03 13:42:00 -0400837bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800838 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800839 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800840 std::function<bool ()> bindRenderTarget,
841 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400842 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800843 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400844 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800845 return false;
846 }
bsalomon7928ef62016-01-05 10:26:39 -0800847
bsalomon76148af2016-01-12 11:13:47 -0800848 GrGLenum readFormat;
849 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400850 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800851 return false;
852 }
853
bsalomon1aa20292016-01-22 08:16:09 -0800854 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800855 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
856 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
857 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
858 // 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 -0500859 // The manual does not seem to fully match the spec as the spec allows integer formats
860 // when the bound color buffer is an integer buffer. It doesn't specify which integer
861 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500862 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
863 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
864 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800865 return false;
866 }
867 // There is also a set of allowed types, but all the types we use are in the set:
868 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
869 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
870 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
871 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
872 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
873 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
874 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800875 return true;
piotaixre4b23142014-10-02 10:57:53 -0700876 }
bsalomon7928ef62016-01-05 10:26:39 -0800877
bsalomon76148af2016-01-12 11:13:47 -0800878 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500879 switch (fConfigTable[surfaceConfig].fFormatType) {
880 case kNormalizedFixedPoint_FormatType:
881 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
882 return true;
883 }
884 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500885 case kFloat_FormatType:
886 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
887 return true;
888 }
889 break;
bsalomon7928ef62016-01-05 10:26:39 -0800890 }
891
Brian Salomon71d9d842016-11-03 13:42:00 -0400892 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800893 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400894 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800895 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800896 if (!bindRenderTarget()) {
897 return false;
898 }
899 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
900 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800901 rpFormat->fFormat = format;
902 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800903 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800904 }
905
Brian Salomon71d9d842016-11-03 13:42:00 -0400906 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
907 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700908}
909
Eric Karl5c779752017-05-08 12:02:07 -0700910void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
911 const GrGLInterface* gli) {
912 // We need dual source blending and the ability to disable multisample in order to support mixed
913 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
914 // renderer is available and enabled; no other path renderers support this feature.
915 if (fMultisampleDisableSupport &&
916 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400917 this->shaderCaps()->pathRenderingSupport()
918#if GR_TEST_UTILS
919 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
920#endif
921 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700922 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400923 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700924 }
925
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000926 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400927 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
928 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
929 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
930 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
931 fAlpha8IsRenderable = true;
932 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500933 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
934 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
935 // mixed samples we can't use multisampled-render-to-texture.
936 if (fUsesMixedSamples) {
937 fMSFBOType = kMixedSamples_MSFBOType;
938 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000939 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
940 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
941 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400942 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
943 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400944 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400945 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400946 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400947 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000948 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
949 fMSFBOType = kES_Apple_MSFBOType;
950 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000951 } else {
egdanieleed519e2016-01-15 11:36:18 -0800952 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700953 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400954 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
955 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400956
Brian Salomon00731b42016-10-14 11:30:51 -0400957 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400958 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
959 // Core profile removes ALPHA8 support.
960 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
961 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
962 // present.
963 fAlpha8IsRenderable = true;
964 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000965 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
966 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400967 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000968 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000969 }
Eric Karl5c779752017-05-08 12:02:07 -0700970
Brian Salomon01b476a2018-01-23 11:06:41 -0500971 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400972 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
973 fMSFBOType = kNone_MSFBOType;
974 }
975
Eric Karl5c779752017-05-08 12:02:07 -0700976 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
977 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
978 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700979 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000980}
981
cdalton1dd05422015-06-12 09:01:18 -0700982void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500983 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700984
Greg Daniel210883c2017-11-27 15:14:01 -0500985 bool layoutQualifierSupport = false;
986 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
987 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
988 layoutQualifierSupport = true;
989 }
990
cdalton1dd05422015-06-12 09:01:18 -0700991 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
992 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500993 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500994 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
995 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700996 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500997 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700998 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
999 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001000 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001001 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001002 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001003 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001004 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1005 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -07001006 }
cdalton1dd05422015-06-12 09:01:18 -07001007}
1008
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001009namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001010const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001011}
1012
Eric Karl5c779752017-05-08 12:02:07 -07001013void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001014
1015 // Build up list of legal stencil formats (though perhaps not supported on
1016 // the particular gpu/driver) from most preferred to least.
1017
1018 // these consts are in order of most preferred to least preferred
1019 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1020
1021 static const StencilFormat
1022 // internal Format stencil bits total bits packed?
1023 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1024 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1025 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1026 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001027 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001028 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1029
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001030 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001031 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001032 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001033 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1034 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1035
1036 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1037 // require FBO support we can expect these are legal formats and don't
1038 // check. These also all support the unsized GL_STENCIL_INDEX.
1039 fStencilFormats.push_back() = gS8;
1040 fStencilFormats.push_back() = gS16;
1041 if (supportsPackedDS) {
1042 fStencilFormats.push_back() = gD24S8;
1043 }
1044 fStencilFormats.push_back() = gS4;
1045 if (supportsPackedDS) {
1046 fStencilFormats.push_back() = gDS;
1047 }
1048 } else {
1049 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1050 // for other formats.
1051 // ES doesn't support using the unsized format.
1052
1053 fStencilFormats.push_back() = gS8;
1054 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001055 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1056 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001057 fStencilFormats.push_back() = gD24S8;
1058 }
1059 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1060 fStencilFormats.push_back() = gS4;
1061 }
1062 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001063}
1064
Brian Osman71a18892017-08-10 10:23:25 -04001065void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001066
Brian Osman71a18892017-08-10 10:23:25 -04001067 // We are called by the base class, which has already called beginObject(). We choose to nest
1068 // all of our caps information in a named sub-object.
1069 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001070
Brian Osman71a18892017-08-10 10:23:25 -04001071 writer->beginArray("Stencil Formats");
1072
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001073 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001074 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001075 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1076 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1077 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001078 }
1079
Brian Osman71a18892017-08-10 10:23:25 -04001080 writer->endArray();
1081
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001082 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001083 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001084 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001085 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001086 "IMG MS To Texture",
1087 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001088 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001089 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001090 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001091 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1092 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1093 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1094 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1095 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001096 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001097
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001098 static const char* kInvalidateFBTypeStr[] = {
1099 "None",
1100 "Discard",
1101 "Invalidate",
1102 };
1103 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1104 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1105 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1106 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001107
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001108 static const char* kMapBufferTypeStr[] = {
1109 "None",
1110 "MapBuffer",
1111 "MapBufferRange",
1112 "Chromium",
1113 };
1114 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1115 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1116 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1117 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1118 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1119
Brian Osman71a18892017-08-10 10:23:25 -04001120 writer->appendBool("Core Profile", fIsCoreProfile);
1121 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1122 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1123 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1124 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1125 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1126 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1127 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1128 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001129
Brian Osman71a18892017-08-10 10:23:25 -04001130 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001131 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1132 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1133 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001134 writer->appendBool("Debug support", fDebugSupport);
1135 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1136 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1137 writer->appendBool("Base instance support", fBaseInstanceSupport);
1138 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1139 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1140 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1141 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1142 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1143 writer->appendBool("BGRA to RGBA readback conversions are slow",
1144 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001145 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001146 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1147 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001148 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1149 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1150 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1151 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Dalton1b4ad762018-10-04 11:58:09 -06001152 writer->appendBool("Max instances per draw without crashing (or zero)",
1153 fMaxInstancesPerDrawWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001154
Brian Osman71a18892017-08-10 10:23:25 -04001155 writer->beginArray("configs");
1156
bsalomon41e4384e2016-01-08 09:12:44 -08001157 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001158 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001159 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1160 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1161 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001162 writer->appendHexU32("e_format_read_pixels",
1163 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001164 writer->appendHexU32(
1165 "e_format_teximage",
1166 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1167 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1168 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1169 writer->appendHexU32("i_for_renderbuffer",
1170 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1171 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001172 }
1173
Brian Osman71a18892017-08-10 10:23:25 -04001174 writer->endArray();
1175 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001176}
1177
bsalomon41e4384e2016-01-08 09:12:44 -08001178bool GrGLCaps::bgraIsInternalFormat() const {
1179 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1180}
1181
bsalomon76148af2016-01-12 11:13:47 -08001182bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1183 GrGLenum* internalFormat, GrGLenum* externalFormat,
1184 GrGLenum* externalType) const {
1185 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1186 externalFormat, externalType)) {
1187 return false;
1188 }
1189 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1190 return true;
1191}
1192
bsalomon76148af2016-01-12 11:13:47 -08001193bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1194 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001195 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001196 externalFormat, externalType)) {
1197 return false;
1198 }
1199 return true;
1200}
1201
Brian Salomon93348dd2018-08-29 12:56:23 -04001202void GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001203 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
Brian Salomon93348dd2018-08-29 12:56:23 -04001204}
1205
1206void GrGLCaps::getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1207 *internalFormat = fConfigTable[config].fFormats.fSizedInternalFormat;
bsalomon76148af2016-01-12 11:13:47 -08001208}
1209
1210bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1211 ExternalFormatUsage usage, GrGLenum* externalFormat,
1212 GrGLenum* externalType) const {
1213 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001214
1215 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1216 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1217
1218 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001219 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1220 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001221 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1222 return false;
1223 }
1224
1225 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1226 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1227
bsalomone9573312016-01-25 14:33:25 -08001228 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1229 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1230 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1231 // texture, not the red component.
1232 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001233 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001234 *externalFormat = GR_GL_ALPHA;
1235 }
1236 }
1237
bsalomon76148af2016-01-12 11:13:47 -08001238 return true;
1239}
1240
brianosman20471892016-12-02 06:43:32 -08001241void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1242 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001243 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001244 /*
1245 Comments on renderability of configs on various GL versions.
1246 OpenGL < 3.0:
1247 no built in support for render targets.
1248 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1249 format RGB, RGBA and NV float formats we don't use.
1250 This is the following:
1251 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1252 RGB10_A2, RGBA12,RGBA16
1253 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1254 since they aren't required by later standards and the driver can simply return
1255 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1256 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1257 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1258 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1259 This adds a lot of additional renderable sized formats, including ALPHA8.
1260 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1261 16F, 32I, 32UI, and 32F variants).
1262 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1263
1264 For both the above extensions we limit ourselves to those that are also required by
1265 OpenGL 3.0.
1266
1267 OpenGL 3.0:
1268 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1269 but are not required to be supported as renderable textures/renderbuffer.
1270 Required renderable color formats:
1271 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1272 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1273 RGB10_A2.
1274 - R11F_G11F_B10F.
1275 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1276 and RG8UI.
1277 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1278 - ALPHA8
1279
1280 OpenGL 3.1, 3.2, 3.3
1281 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1282 OpengGL 3.3, 4.0, 4.1
1283 Adds RGB10_A2UI.
1284 OpengGL 4.2
1285 Adds
1286 - RGB5_A1, RGBA4
1287 - RGB565
1288 OpenGL 4.4
1289 Does away with the separate list and adds a column to the sized internal color format
1290 table. However, no new formats become required color renderable.
1291
1292 ES 2.0
1293 color renderable: RGBA4, RGB5_A1, RGB565
1294 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1295 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1296 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1297 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1298 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1299 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1300
1301 ES 3.0
1302 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1303 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1304 RGB5_A1.
1305 - RGB8 and RGB565.
1306 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1307 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1308 ES 3.1
1309 Adds RGB10_A2, RGB10_A2UI,
1310 ES 3.2
1311 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1312 */
Brian Salomon44804c02018-01-23 16:51:28 -05001313
1314 // Correctness workarounds.
1315 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001316 bool disableSRGBForX86PowerVR = false;
1317 bool disableSRGBWriteControlForAdreno4xx = false;
1318 bool disableR8TexStorageForANGLEGL = false;
1319 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001320 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001321 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001322
1323 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1324 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1325 // and GL_RG on FBO textures.
1326 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1327
Greg Daniel09c94002018-06-08 22:11:51 +00001328 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1329
Brian Salomon44804c02018-01-23 16:51:28 -05001330 bool isX86PowerVR = false;
1331#if defined(SK_CPU_X86)
1332 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1333 isX86PowerVR = true;
1334 }
1335#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001336 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1337 // blacklist that device (and any others that might be sharing the same driver).
1338 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001339 disableSRGBWriteControlForAdreno4xx =
1340 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1341 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001342
1343 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1344 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1345 // check that we are not going to OpenGL.
1346 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1347
1348 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1349#if defined(SK_BUILD_FOR_MAC)
1350 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1351#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001352 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1353 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001354 }
1355
Brian Salomon71d9d842016-11-03 13:42:00 -04001356 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1357 ConfigInfo::kFBOColorAttachment_Flag;
1358 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001359 if (kNone_MSFBOType != fMSFBOType) {
1360 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1361 }
bsalomon41e4384e2016-01-08 09:12:44 -08001362 GrGLStandard standard = ctxInfo.standard();
1363 GrGLVersion version = ctxInfo.version();
1364
cblume790d5132016-02-29 11:13:29 -08001365 bool texStorageSupported = false;
1366 if (kGL_GrGLStandard == standard) {
1367 // The EXT version can apply to either GL or GLES.
1368 texStorageSupported = version >= GR_GL_VER(4,2) ||
1369 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1370 ctxInfo.hasExtension("GL_EXT_texture_storage");
1371 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001372 texStorageSupported = version >= GR_GL_VER(3,0) ||
1373 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001374 }
Adrienne Walker70e468f2018-08-22 16:05:27 -07001375 if (fDriverBugWorkarounds.disable_texture_storage) {
1376 texStorageSupported = false;
1377 }
cblume790d5132016-02-29 11:13:29 -08001378
Brian Salomone609e812018-01-17 14:00:47 -05001379 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001380
1381 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001382 if (kGL_GrGLStandard == standard) {
1383 textureRedSupport =
1384 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1385 } else {
1386 textureRedSupport =
1387 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1388 }
1389 }
1390
bsalomon30447372015-12-21 09:03:05 -08001391 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1392 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001393 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001394 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001395 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001396 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001397
1398 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1399 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001400 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001401 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001402 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001403 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001404 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1405 if (kGL_GrGLStandard == standard) {
1406 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1407 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001408 } else {
Kevin Lubick217056c2018-09-20 17:39:31 -04001409 bool isWebGL = false;
1410 // hack for skbug:8378
1411 #if IS_WEBGL==1
1412 isWebGL = true;
1413 #endif
1414 if (isWebGL || version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon41e4384e2016-01-08 09:12:44 -08001415 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1416 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1417 }
egdaniel4999df82016-01-07 17:06:04 -08001418 }
cblume790d5132016-02-29 11:13:29 -08001419 if (texStorageSupported) {
1420 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1421 }
bsalomoncdee0092016-01-08 13:20:12 -08001422 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001423
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001424 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1425 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1426 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1427 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1428 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1429 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1430 // supportedReadPixelsColorType never returns it.
1431 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1432 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1433 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1434 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1435 if (kGL_GrGLStandard == standard) {
1436 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1437 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1438 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1439 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1440 // becomes an issue.
1441 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1442 // but we don't support that just for simplicity's sake.
1443 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1444 } else {
1445 // 3.0 and the extension support this as a render buffer format.
1446 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1447 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1448 }
1449 }
1450 if (texStorageSupported) {
1451 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1452 }
1453 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1454 if (disableRGB8ForMali400) {
1455 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1456 }
1457
1458 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001459 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001460 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001461 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001462
1463 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1464 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1465 // GL_EXT_texture_format_BGRA8888.
1466 bool supportsBGRATexStorage = false;
1467
bsalomon41e4384e2016-01-08 09:12:44 -08001468 if (kGL_GrGLStandard == standard) {
1469 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1470 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1471 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1472 // Since the internal format is RGBA8, it is also renderable.
1473 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1474 allRenderFlags;
1475 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001476 // Since we are using RGBA8 we can use tex storage.
1477 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001478 } else {
1479 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1480 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001481 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1482 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1483 nonMSAARenderFlags;
1484
1485 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1486 supportsBGRATexStorage = true;
1487 }
1488 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1489 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1490 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1491 ConfigInfo::kRenderableWithMSAA_Flag;
1492 }
1493 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001494 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1495 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1496 // driver remembers the external format when the texture is created (with TexImage).
1497 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1498 // We could work around this, but it adds even more state tracking to code that is
1499 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1500 // This also side-steps some ambiguous interactions with the texture storage extension.
1501 if (version >= GR_GL_VER(3,0)) {
1502 // The APPLE extension doesn't make this renderable.
1503 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001504 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001505 }
bsalomon41e4384e2016-01-08 09:12:44 -08001506 }
1507 }
Brian Osman48c99192017-06-02 08:45:06 -04001508
Greg Daniel0ff79b22018-02-15 12:33:33 -05001509 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001510 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001511 }
bsalomoncdee0092016-01-08 13:20:12 -08001512 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001513
Brian Osman2b23c4b2018-06-01 12:25:08 -04001514 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001515 if (kGL_GrGLStandard == standard) {
1516 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001517 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001518 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1519 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1520 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001521 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001522 }
1523 }
1524 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001525 if (fSRGBSupport) {
1526 fSRGBWriteControl = true;
1527 }
bsalomon41e4384e2016-01-08 09:12:44 -08001528 } else {
brianosman20471892016-12-02 06:43:32 -08001529 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001530 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001531 fSRGBSupport = false;
1532 }
bsalomon41e4384e2016-01-08 09:12:44 -08001533 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1534 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001535 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001536 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001537 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001538 }
brianosman20471892016-12-02 06:43:32 -08001539
1540 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1541 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1542 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1543 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1544 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1545 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1546 // affects Windows.
1547 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1548 fSRGBSupport = false;
1549 }
1550
Brian Osman48c99192017-06-02 08:45:06 -04001551 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1552 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1553 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1554
Brian Osman67999392017-05-31 16:19:34 -04001555 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001556 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001557 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1558 }
Brian Osman67999392017-05-31 16:19:34 -04001559
bsalomon30447372015-12-21 09:03:05 -08001560 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1561 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1562 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1563 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001564 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001565 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001566 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001567 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001568 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001569 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001570 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001571 }
Brian Osman48c99192017-06-02 08:45:06 -04001572 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1573 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001574 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1575 }
bsalomoncdee0092016-01-08 13:20:12 -08001576 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001577 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1578 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1579 // is in this format, for example).
1580 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1581 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1582 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1583 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001584 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001585 GR_GL_BGRA;
1586 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1587 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001588 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001589 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001590 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001591 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001592
brianosmana6359362016-03-21 06:55:37 -07001593 if (texStorageSupported) {
1594 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1595 }
1596 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1597
bsalomon30447372015-12-21 09:03:05 -08001598 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1599 if (this->ES2CompatibilitySupport()) {
1600 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1601 } else {
1602 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1603 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001604 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001605 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001606 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001607 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001608 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1609 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001610 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001611 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1612 }
1613 } else {
1614 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1615 }
cblume790d5132016-02-29 11:13:29 -08001616 // 565 is not a sized internal format on desktop GL. So on desktop with
1617 // 565 we always use an unsized internal format to let the system pick
1618 // the best sized format to convert the 565 data to. Since TexStorage
1619 // only allows sized internal formats we disallow it.
1620 //
1621 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1622 // update.
1623 if (texStorageSupported && kGL_GrGLStandard != standard) {
1624 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1625 }
bsalomoncdee0092016-01-08 13:20:12 -08001626 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001627
1628 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1629 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001630 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001631 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001632 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001633 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001634 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1635 if (kGL_GrGLStandard == standard) {
1636 if (version >= GR_GL_VER(4, 2)) {
1637 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1638 }
1639 } else {
1640 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1641 }
cblume790d5132016-02-29 11:13:29 -08001642 if (texStorageSupported) {
1643 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1644 }
bsalomoncdee0092016-01-08 13:20:12 -08001645 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001646
Brian Osman10fc6fd2018-03-02 11:01:10 -05001647 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1648 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001649 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001650 GR_GL_RGBA;
1651 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1652 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1653 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1654 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1655 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1656 allRenderFlags;
1657 }
1658 if (texStorageSupported) {
1659 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1660 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001661 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1662
Greg Danielef59d872017-11-17 16:47:21 -05001663 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1664 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1665
1666 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1667 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1668 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1669 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1670 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001671 }
Greg Danielef59d872017-11-17 16:47:21 -05001672 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1673 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001674 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001675 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1676 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1677 alphaInfo.fFlags |= allRenderFlags;
1678 }
1679
1680 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1681 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1682 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1683 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1684 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001685 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001686 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001687
Brian Osman48c99192017-06-02 08:45:06 -04001688 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1689 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001690 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001691 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1692 }
1693 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1694 }
1695
Brian Salomone609e812018-01-17 14:00:47 -05001696 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001697 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001698 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1699 } else {
1700 redInfo.fFlags = 0;
1701
1702 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001703 }
bsalomon41e4384e2016-01-08 09:12:44 -08001704
Greg Daniel7af060a2017-12-05 16:27:11 -05001705 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1706 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1707 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1708 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1709 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001710 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001711 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1712 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1713 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1714 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001715 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001716
1717 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1718 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1719 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1720 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1721 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001722 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001723 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1724 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1725
Greg Daniel09c94002018-06-08 22:11:51 +00001726 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1727 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1728 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1729 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1730 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001731 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1732 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1733 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001734 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001735 }
Brian Osman48c99192017-06-02 08:45:06 -04001736 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001737 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001738 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1739 }
1740 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1741 }
1742
Brian Salomone609e812018-01-17 14:00:47 -05001743 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001744 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1745 } else {
1746 grayRedInfo.fFlags = 0;
1747 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001748 }
1749
bsalomon41e4384e2016-01-08 09:12:44 -08001750 // Check for [half] floating point texture support
1751 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1752 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1753 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
Chris Daltoneff01a72018-07-19 17:06:39 -06001754 bool hasFP32Textures = false;
1755 bool hasFP16Textures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001756 bool rgIsTexturable = false;
Chris Daltoneff01a72018-07-19 17:06:39 -06001757 bool hasFP32RenderTargets = false;
Brian Salomon75975512018-10-02 12:21:38 -04001758 enum class HalfFPRenderTargetSupport { kNone, kRGBAOnly, kAll };
1759 HalfFPRenderTargetSupport halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kNone;
bsalomon41e4384e2016-01-08 09:12:44 -08001760 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001761 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001762
1763 if (kGL_GrGLStandard == standard) {
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 hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001769 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
bsalomon41e4384e2016-01-08 09:12:44 -08001770 }
1771 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001772 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001773 hasFP32Textures = true;
1774 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001775 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001776 } else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1777 ctxInfo.hasExtension("GL_OES_texture_float")) {
1778 hasFP32Textures = true;
1779 hasFP16Textures = true;
1780 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1781 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1782 hasFP16Textures = true;
1783 }
1784
1785 if (version >= GR_GL_VER(3, 2)) {
1786 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to solve
1787 // many precision issues and no clients actually want this yet.
1788 // hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001789 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
Chris Daltoneff01a72018-07-19 17:06:39 -06001790 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
1791 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to
1792 // solve many precision issues and no clients actually want this yet.
1793 // hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001794 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
Chris Daltoneff01a72018-07-19 17:06:39 -06001795 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
Brian Salomon75975512018-10-02 12:21:38 -04001796 // This extension only enables half float support rendering for RGBA.
1797 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kRGBAOnly;
bsalomon41e4384e2016-01-08 09:12:44 -08001798 }
1799 }
bsalomon30447372015-12-21 09:03:05 -08001800
csmartdalton6aa0e112017-02-08 16:14:11 -05001801 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1802 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1803 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1804 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1805 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001806 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001807 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1808 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001809 if (hasFP32Textures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001810 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
Chris Daltoneff01a72018-07-19 17:06:39 -06001811 if (hasFP32RenderTargets) {
csmartdalton6aa0e112017-02-08 16:14:11 -05001812 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1813 }
bsalomon41e4384e2016-01-08 09:12:44 -08001814 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001815 if (texStorageSupported) {
1816 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1817 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001818 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001819 }
bsalomon30447372015-12-21 09:03:05 -08001820
Greg Danielef59d872017-11-17 16:47:21 -05001821 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001822 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001823 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001824 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001825 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001826 }
Greg Danielef59d872017-11-17 16:47:21 -05001827 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1828 redHalf.fFormats.fExternalType = redHalfExternalType;
1829 redHalf.fFormatType = kFloat_FormatType;
1830 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1831 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001832 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001833 redHalf.fSwizzle = GrSwizzle::RRRR();
Chris Daltoneff01a72018-07-19 17:06:39 -06001834 if (textureRedSupport && hasFP16Textures) {
Greg Danielef59d872017-11-17 16:47:21 -05001835 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1836
Brian Salomon75975512018-10-02 12:21:38 -04001837 if (halfFPRenderTargetSupport == HalfFPRenderTargetSupport::kAll) {
Greg Danielef59d872017-11-17 16:47:21 -05001838 redHalf.fFlags |= fpRenderFlags;
1839 }
1840
1841 if (texStorageSupported && !isCommandBufferES2) {
1842 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1843 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001844 }
Greg Danielef59d872017-11-17 16:47:21 -05001845 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001846
1847 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1848 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001849 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001850 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001851 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001852 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1853 } else {
1854 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1855 }
bsalomon7928ef62016-01-05 10:26:39 -08001856 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001857 if (hasFP16Textures) {
bsalomon41e4384e2016-01-08 09:12:44 -08001858 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1859 // ES requires 3.2 or EXT_color_buffer_half_float.
Brian Salomon75975512018-10-02 12:21:38 -04001860 if (halfFPRenderTargetSupport != HalfFPRenderTargetSupport::kNone) {
bsalomon41e4384e2016-01-08 09:12:44 -08001861 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1862 }
1863 }
cblume790d5132016-02-29 11:13:29 -08001864 if (texStorageSupported) {
1865 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1866 }
bsalomoncdee0092016-01-08 13:20:12 -08001867 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001868
bsalomon30447372015-12-21 09:03:05 -08001869 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1870
1871 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001872 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1873 ctxInfo.version() >= GR_GL_VER(3,0));
1874 // All ES versions (thus far) require sized internal formats for render buffers.
1875 // TODO: Always use sized internal format?
1876 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1877
bsalomon30447372015-12-21 09:03:05 -08001878 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001879 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1880 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001881 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001882 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001883 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1884 fConfigTable[i].fFormats.fSizedInternalFormat :
1885 fConfigTable[i].fFormats.fBaseInternalFormat;
1886 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001887 fConfigTable[i].fFormats.fSizedInternalFormat :
1888 fConfigTable[i].fFormats.fBaseInternalFormat;
1889 }
Brian Salomon44804c02018-01-23 16:51:28 -05001890 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1891 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1892 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1893 // in ES.
1894 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1895 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1896 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1897 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001898 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1899 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001900 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1901 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001902 }
1903
bsalomon30447372015-12-21 09:03:05 -08001904 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1905 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1906 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1907 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1908 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001909 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001910 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001911
1912 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1913 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1914 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1915 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001916 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001917 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1918 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1919 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1920 // slot.
1921 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1922 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001923
1924 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1925 // as a base format.
1926 // GL_EXT_texture_format_BGRA8888:
1927 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1928 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1929 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001930 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001931 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1932 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1933 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001934 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001935 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1936 }
1937
bsalomoncdee0092016-01-08 13:20:12 -08001938 // If we don't have texture swizzle support then the shader generator must insert the
1939 // swizzle into shader code.
1940 if (!this->textureSwizzleSupport()) {
1941 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001942 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001943 }
1944 }
1945
bsalomon7f9b2e42016-01-12 13:29:26 -08001946 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1947 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1948 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001949 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001950 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1951 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1952 if (GrPixelConfigIsAlphaOnly(config) &&
1953 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001954 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001955 }
1956 }
1957 }
1958
Greg Daniel81e7bf82017-07-19 14:47:42 -04001959 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1960 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001961 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1962 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001963 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001964 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1965 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001966 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001967 int count;
1968 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1969 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1970 1, &count);
1971 if (count) {
1972 int* temp = new int[count];
1973 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1974 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001975 // GL has a concept of MSAA rasterization with a single sample but we do not.
1976 if (count && temp[count - 1] == 1) {
1977 --count;
1978 SkASSERT(!count || temp[count -1] > 1);
1979 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001980 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001981 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001982 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001983 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001984 for (int j = 0; j < count; ++j) {
1985 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1986 }
1987 delete[] temp;
1988 }
1989 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001990 // Fake out the table using some semi-standard counts up to the max allowed sample
1991 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001992 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001993 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1994 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1995 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1996 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1997 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001998 // Chrome has a mock GL implementation that returns 0.
1999 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05002000
Brian Salomonbdecacf2018-02-02 20:32:49 -05002001 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04002002 int count = SK_ARRAY_COUNT(kDefaultSamples);
2003 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002004 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002005 break;
2006 }
2007 }
2008 if (count > 0) {
2009 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
2010 }
2011 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002012 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
2013 fConfigTable[i].fColorSampleCounts.setCount(1);
2014 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002015 }
2016 }
2017
bsalomon30447372015-12-21 09:03:05 -08002018#ifdef SK_DEBUG
2019 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002020 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002021 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002022 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2023 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002024 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2025 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2026 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2027 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002028 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2029 fConfigTable[i].fFormats.fBaseInternalFormat);
2030 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002031 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002032 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2033 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2034 fConfigTable[i].fFormats.fExternalFormat[j]);
2035 }
2036 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002037 }
2038#endif
2039}
2040
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002041bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2042 bool dstIsTextureable, bool dstIsGLTexture2D,
2043 GrSurfaceOrigin dstOrigin,
2044 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2045 bool srcIsTextureable, bool srcIsGLTexture2D,
2046 GrSurfaceOrigin srcOrigin) const {
2047 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2048 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2049 // many drivers would allow it to work, but ANGLE does not.
2050 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2051 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2052 return false;
2053 }
2054
2055 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2056 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2057 return false;
2058 }
2059
2060 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2061 // texture.
2062 if (!dstIsTextureable) {
2063 return false;
2064 }
2065
2066 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2067 // is required
2068 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2069 (!srcIsTextureable || srcIsGLTexture2D) &&
2070 dstIsGLTexture2D &&
2071 dstOrigin == srcOrigin) {
2072 return true;
2073 } else {
2074 return false;
2075 }
2076}
2077
2078bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2079 bool dstIsTextureable, bool dstIsGLTexture2D,
2080 GrSurfaceOrigin dstOrigin,
2081 GrPixelConfig srcConfig, int srcSampleCnt,
2082 bool srcIsTextureable, bool srcIsGLTexture2D,
2083 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2084 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2085 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2086 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2087 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2088 return false;
2089 }
2090
2091 if (dstIsTextureable && !dstIsGLTexture2D) {
2092 return false;
2093 }
2094 if (srcIsTextureable && !srcIsGLTexture2D) {
2095 return false;
2096 }
2097
2098 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2099 return false;
2100 }
2101 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2102 // We would mirror to compensate for origin changes. Note that copySurface is
2103 // specified such that the src and dst rects are the same.
2104 if (dstOrigin != srcOrigin) {
2105 return false;
2106 }
2107 }
2108
2109 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2110 if (srcSampleCnt > 1) {
2111 if (1 == dstSampleCnt) {
2112 return false;
2113 }
2114 if (SkRect::Make(srcRect) != srcBounds) {
2115 return false;
2116 }
2117 }
2118 }
2119
2120 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2121 if (dstSampleCnt > 1) {
2122 return false;
2123 }
2124 }
2125
2126 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2127 if (dstConfig != srcConfig) {
2128 return false;
2129 }
2130 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2131 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2132 return false;
2133 }
2134 }
2135
2136 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2137 if (srcSampleCnt > 1) {
2138 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2139 return false;
2140 }
2141 if (dstOrigin != srcOrigin) {
2142 return false;
2143 }
2144 }
2145 }
2146 return true;
2147}
2148
2149bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2150 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2151}
2152
2153static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2154 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2155 if (!rt) {
2156 return false;
2157 }
2158 // A RT has a separate MSAA renderbuffer if:
2159 // 1) It's multisampled
2160 // 2) We're using an extension with separate MSAA renderbuffers
2161 // 3) It's not FBO 0, which is special and always auto-resolves
2162 return rt->numColorSamples() > 1 &&
2163 glCaps.usesMSAARenderBuffers() &&
2164 !rt->rtPriv().glRTFBOIDIs0();
2165}
2166
2167bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2168 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2169 GrSurfaceOrigin dstOrigin = dst->origin();
2170 GrSurfaceOrigin srcOrigin = src->origin();
2171
2172 GrPixelConfig dstConfig = dst->config();
2173 GrPixelConfig srcConfig = src->config();
2174
2175 int dstSampleCnt = 0;
2176 int srcSampleCnt = 0;
2177 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2178 dstSampleCnt = rtProxy->numColorSamples();
2179 }
2180 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2181 srcSampleCnt = rtProxy->numColorSamples();
2182 }
2183 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2184 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2185
2186 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2187 // swizzle.
2188 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2189 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2190 return false;
2191 }
2192
2193 const GrTextureProxy* dstTex = dst->asTextureProxy();
2194 const GrTextureProxy* srcTex = src->asTextureProxy();
2195
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002196 bool dstIsTex2D = dstTex ? (dstTex->textureType() == GrTextureType::k2D) : false;
2197 bool srcIsTex2D = srcTex ? (srcTex->textureType() == GrTextureType::k2D) : false;
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002198
2199 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2200 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2201 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2202 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2203 // know we will at least be able to do it as a draw.
2204#ifdef SK_DEBUG
2205 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2206 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2207 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2208 !src->priv().isExact()) {
2209 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2210 }
2211#endif
2212
2213 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2214 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2215 srcConfig, has_msaa_render_buffer(src, *this),
2216 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2217 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2218 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2219 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2220 dstPoint) ||
2221 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2222}
2223
Robert Phillipsbf25d432017-04-07 10:08:53 -04002224bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002225 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2226 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002227 // By default, we don't require rects to match.
2228 *rectsMustMatch = false;
2229
2230 // By default, we allow subrects.
2231 *disallowSubrect = false;
2232
Brian Salomon467921e2017-03-06 16:17:12 -05002233 // If the src is a texture, we can implement the blit as a draw assuming the config is
2234 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002235 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002236 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002237 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2238 desc->fConfig = src->config();
2239 return true;
2240 }
2241
Robert Phillipsbf25d432017-04-07 10:08:53 -04002242 {
2243 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2244 // wrapped. In that case the proxy would already be instantiated.
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002245 const GrTexture* srcTexture = src->peekTexture();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002246 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2247 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2248 // Not supported for FBO blit or CopyTexSubImage
2249 return false;
2250 }
Brian Salomon467921e2017-03-06 16:17:12 -05002251 }
2252
2253 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2254 // possible and we return false to fallback to creating a render target dst for render-to-
2255 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2256 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002257 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002258 bool rectsMustMatchForBlitFramebuffer = false;
2259 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002260 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002261 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2262 rectsMustMatchForBlitFramebuffer = true;
2263 disallowSubrectForBlitFramebuffer = true;
2264 // Mirroring causes rects to mismatch later, don't allow it.
2265 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002266 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2267 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002268 rectsMustMatchForBlitFramebuffer = true;
2269 // Mirroring causes rects to mismatch later, don't allow it.
2270 originForBlitFramebuffer = src->origin();
2271 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002272 originForBlitFramebuffer = src->origin();
2273 }
2274
2275 // Check for format issues with glCopyTexSubImage2D
2276 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2277 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2278 // then we set up for that, otherwise fail.
2279 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002280 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002281 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002282 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2283 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002284 return true;
2285 }
2286 return false;
2287 }
2288
Robert Phillipsbf25d432017-04-07 10:08:53 -04002289 {
Brian Salomon63e79732017-05-15 21:23:13 -04002290 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2291 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002292 if (srcIsMSAARenderbuffer) {
2293 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2294 // blit or fail.
2295 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002296 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002297 desc->fConfig = src->config();
2298 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2299 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2300 return true;
2301 }
2302 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002303 }
Brian Salomon467921e2017-03-06 16:17:12 -05002304 }
2305
2306 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002307 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002308 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002309 desc->fFlags = kNone_GrSurfaceFlags;
2310 return true;
2311}
2312
Greg Daniel691f5e72018-02-28 14:21:34 -05002313void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2314 const GrContextOptions& contextOptions,
2315 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002316 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2317 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002318 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2319 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002320 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002321 fDiscardRenderTargetSupport = false;
2322 fInvalidateFBType = kNone_InvalidateFBType;
2323 }
2324
2325 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2326 // 340.96 and 367.57.
2327 if (kGL_GrGLStandard == ctxInfo.standard() &&
2328 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002329 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002330 fClearTextureSupport = false;
2331 }
2332
2333 // Calling glClearTexImage crashes on the NexusPlayer.
2334 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2335 fClearTextureSupport = false;
2336 }
2337
Brian Salomon01b476a2018-01-23 11:06:41 -05002338#ifdef SK_BUILD_FOR_MAC
Chris Dalton6989ba42018-10-03 10:34:09 -06002339 // Radeon MacBooks hit a crash in glReadPixels() when using geometry shaders.
2340 // http://skbug.com/8097
2341 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2342 shaderCaps->fGeometryShaderSupport = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002343 }
Chris Dalton6989ba42018-10-03 10:34:09 -06002344 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2345 shaderCaps->fGSInvocationsSupport = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002346#endif
2347
2348 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2349 // shaders. @127.0 is the earliest verified driver to not crash.
2350 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002351 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002352 shaderCaps->fGeometryShaderSupport = false;
2353 }
2354
2355#if defined(__has_feature)
2356#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2357 // See skbug.com/7058
2358 fMapBufferType = kNone_MapBufferType;
2359 fMapBufferFlags = kNone_MapFlags;
2360#endif
2361#endif
2362
2363 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2364 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2365 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2366 // unclear whether this really affects a wide range of devices.
2367 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002368 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002369 fMapBufferType = kNone_MapBufferType;
2370 fMapBufferFlags = kNone_MapFlags;
2371 }
2372
2373 // TODO: re-enable for ANGLE
2374 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2375 fTransferBufferType = kNone_TransferBufferType;
2376 }
2377
2378 // Using MIPs on this GPU seems to be a source of trouble.
2379 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2380 fMipMapSupport = false;
2381 }
2382
2383 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2384 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2385 // around a driver bug related to gl_FragCoord.
2386 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2387 fMaxClipAnalyticFPs = 0;
2388 }
2389
2390#ifndef SK_BUILD_FOR_IOS
2391 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2392 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2393 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2394 ctxInfo.driver() != kChromium_GrGLDriver)) {
2395 fUseDrawToClearColor = true;
2396 }
2397#endif
2398
2399 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2400 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2401 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2402 fUseDrawToClearColor = true;
2403 }
2404
2405#ifdef SK_BUILD_FOR_MAC
2406 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2407 // full screen clears
2408 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2409 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002410 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2411 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2412 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2413 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002414 fUseDrawToClearColor = true;
2415 }
2416#endif
2417
2418 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2419 // bugs seems to involve clearing too much and not skipping the clear.
2420 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2421 // but only for D3D11 ANGLE.
2422 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2423 fUseDrawToClearColor = true;
2424 }
2425
Chris Dalton1214be92018-06-28 19:06:27 -06002426 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2427 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002428 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002429 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002430 fUseDrawToClearStencilClip = true;
2431 }
2432 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2433 }
2434
Adrienne Walker94f585e2018-05-15 11:47:07 -07002435 if (fDriverBugWorkarounds.gl_clear_broken) {
2436 fUseDrawToClearColor = true;
2437 fUseDrawToClearStencilClip = true;
2438 }
2439
Brian Salomon01b476a2018-01-23 11:06:41 -05002440 // This was reproduced on the following configurations:
2441 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2442 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2443 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2444 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2445 // and not produced on:
2446 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2447 // The particular lines that get dropped from test images varies across different devices.
2448 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002449 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002450 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2451 }
2452
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002453 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2454 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2455 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002456 fRequiresFlushBetweenNonAndInstancedDraws = true;
2457 }
2458
Brian Osman1348ed02018-09-12 09:08:39 -04002459 // This was reproduced on a Pixel 1, but the unit test + config + options that exercise it are
2460 // only tested on very specific bots. The driver claims that ReadPixels is an invalid operation
2461 // when reading from an auto-resolving MSAA framebuffer that has stencil attached.
2462 if (kQualcomm_GrGLDriver == ctxInfo.driver()) {
2463 fDetachStencilFromMSAABuffersBeforeReadPixels = true;
2464 }
2465
Brian Salomon01b476a2018-01-23 11:06:41 -05002466 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
Chris Dalton1b4ad762018-10-04 11:58:09 -06002467 // Our Chromebook with kPowerVRRogue_GrGLRenderer crashes on large instanced draws. The
2468 // current minimum number of instances observed to crash is somewhere between 2^14 and 2^15.
2469 // Keep the number of instances below 1000, just to be safe.
2470 fMaxInstancesPerDrawWithoutCrashing = 999;
Adrienne Walker001cae02018-05-15 11:38:44 -07002471 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
Chris Dalton1b4ad762018-10-04 11:58:09 -06002472 fMaxInstancesPerDrawWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002473 }
2474
2475 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002476 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002477 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2478 fUseDrawInsteadOfAllRenderTargetWrites = true;
2479 }
2480
2481 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2482 fSampleShadingSupport = false;
2483 }
2484
2485#ifdef SK_BUILD_FOR_MAC
2486 static constexpr bool isMAC = true;
2487#else
2488 static constexpr bool isMAC = false;
2489#endif
2490
2491 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2492 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2493 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2494 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2495 if (fMipMapLevelAndLodControlSupport &&
2496 (contextOptions.fDoManualMipmapping ||
2497 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2498 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2499 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2500 fDoManualMipmapping = true;
2501 }
2502
2503 // See http://crbug.com/710443
2504#ifdef SK_BUILD_FOR_MAC
2505 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2506 fClearToBoundaryValuesIsBroken = true;
2507 }
2508#endif
2509 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2510 fDrawArraysBaseVertexIsBroken = true;
2511 }
2512
Brian Salomon01b476a2018-01-23 11:06:41 -05002513 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2514 // Galaxy S7.
2515 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2516 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2517 shaderCaps->fFBFetchSupport = false;
2518 }
2519
Brian Salomon01b476a2018-01-23 11:06:41 -05002520 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2521 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2522
2523 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2524 // function that may require a gradient calculation inside a conditional block may return
2525 // undefined results". This appears to be an issue with the 'any' call since even the simple
2526 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2527 // from our GrTextureDomain processor.
2528 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2529
2530 // Known issue on at least some Intel platforms:
2531 // http://code.google.com/p/skia/issues/detail?id=946
2532 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2533 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2534 }
2535
Chris Dalton0090ef62018-03-28 17:35:00 -06002536 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002537 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2538 // so we must do the abs first in a separate expression.
2539 shaderCaps->fCanUseMinAndAbsTogether = false;
2540
2541 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2542 // must avoid this condition.
2543 shaderCaps->fCanUseFractForNegativeValues = false;
2544 }
2545
2546 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2547 // thus must us -1.0 * %s.x to work correctly
2548 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2549 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2550 }
2551
2552 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2553 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2554 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2555 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2556 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2557 }
2558
2559 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2560 // the original dst color when reading the outColor even after being written to. By using a
2561 // local outColor we can work around this bug.
2562 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2563 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2564 }
2565
2566 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2567 // color, and that uniform contains an opaque color, and the output of the shader is only based
2568 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2569 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2570 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2571 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2572 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2573 shaderCaps->fMustObfuscateUniformColor = true;
2574 }
2575#ifdef SK_BUILD_FOR_WIN
2576 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2577 //
2578 // Basically, if a shader has a construct like:
2579 //
2580 // float x = someCondition ? someValue : 0;
2581 // float2 result = (0 == x) ? float2(x, x)
2582 // : float2(2 * x / x, 0);
2583 //
2584 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2585 // we've explicitly guarded the division with a check against zero. This manifests in much
2586 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2587 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2588 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2589 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2590 }
2591#endif
2592
2593 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002594 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002595 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2596 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002597 }
2598
Chris Dalton0090ef62018-03-28 17:35:00 -06002599 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2600 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2601 shaderCaps->fCanUseFragCoord = false;
2602 }
2603
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002604 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2605 // (Are they implemented with fp16?)
2606 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2607 shaderCaps->fIncompleteShortIntPrecision = true;
2608 }
2609
Adrienne Walkeree8295c2018-08-21 10:56:30 -07002610 if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
2611 shaderCaps->fAddAndTrueToLoopCondition = true;
2612 }
2613
Adrienne Walkerc02165f2018-08-21 11:08:11 -07002614 if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
2615 shaderCaps->fUnfoldShortCircuitAsTernary = true;
2616 }
2617
Adrienne Walker92b161f2018-08-22 10:41:52 -07002618 if (fDriverBugWorkarounds.emulate_abs_int_function) {
2619 shaderCaps->fEmulateAbsIntFunction = true;
2620 }
2621
Adrienne Walker8b23ca62018-08-22 10:45:41 -07002622 if (fDriverBugWorkarounds.rewrite_do_while_loops) {
2623 shaderCaps->fRewriteDoWhileLoops = true;
2624 }
2625
Adrienne Walker2f4c09b2018-08-22 16:04:57 -07002626 if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
2627 shaderCaps->fRemovePowWithConstantExponent = true;
2628 }
2629
Brian Salomon01b476a2018-01-23 11:06:41 -05002630 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2631 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002632 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2633 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002634 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2635 kIntel_GrGLDriver == ctxInfo.driver() ||
2636 kChromium_GrGLDriver == ctxInfo.driver()) {
2637 fBlendEquationSupport = kBasic_BlendEquationSupport;
2638 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2639 }
2640
2641 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2642 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002643 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002644 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002645 fBlendEquationSupport = kBasic_BlendEquationSupport;
2646 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2647 }
2648
Adrienne Walker68314842018-05-14 14:02:53 -07002649 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2650 fBlendEquationSupport = kBasic_BlendEquationSupport;
2651 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2652 }
2653
Brian Salomon01b476a2018-01-23 11:06:41 -05002654 if (this->advancedBlendEquationSupport()) {
2655 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002656 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002657 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2658 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2659 (1 << kColorBurn_GrBlendEquation);
2660 }
2661 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2662 // Blacklist color-burn on ARM until the fix is released.
2663 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2664 }
2665 }
2666
2667 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2668 if (fMultisampleDisableSupport &&
2669 this->shaderCaps()->dualSourceBlendingSupport() &&
2670 this->shaderCaps()->pathRenderingSupport() &&
2671 fUsesMixedSamples &&
2672#if GR_TEST_UTILS
2673 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2674#endif
2675 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2676 kChromium_GrGLDriver == ctxInfo.driver())) {
2677 fDiscardRenderTargetSupport = false;
2678 fInvalidateFBType = kNone_InvalidateFBType;
2679 }
Brian Osmanc585e202018-04-04 14:08:27 -04002680
Brian Osman061020e2018-04-17 14:22:15 -04002681 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2682 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2683 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2684 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002685 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2686 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002687 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002688 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002689 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2690 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002691 }
Brian Osman2fa53742018-05-03 15:05:12 -04002692
2693#ifdef SK_BUILD_FOR_IOS
2694 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2695 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2696 // is to just blacklist the feature.
2697 // https://github.com/flutter/flutter/issues/16718
2698 // https://bugreport.apple.com/web/?problemID=39948888
2699 fUnpackRowLengthSupport = false;
2700#endif
Brian Salomon01b476a2018-01-23 11:06:41 -05002701}
2702
csmartdaltone0d36292016-07-29 08:14:20 -07002703void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002704 if (options.fDisableDriverCorrectnessWorkarounds) {
2705 SkASSERT(!fDoManualMipmapping);
2706 SkASSERT(!fClearToBoundaryValuesIsBroken);
Chris Dalton1b4ad762018-10-04 11:58:09 -06002707 SkASSERT(0 == fMaxInstancesPerDrawWithoutCrashing);
Brian Salomon01b476a2018-01-23 11:06:41 -05002708 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2709 SkASSERT(!fUseDrawToClearColor);
2710 SkASSERT(!fUseDrawToClearStencilClip);
2711 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2712 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2713 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002714 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Osman1348ed02018-09-12 09:08:39 -04002715 SkASSERT(!fDetachStencilFromMSAABuffersBeforeReadPixels);
Brian Salomon01b476a2018-01-23 11:06:41 -05002716 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002717 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2718 fUseDrawToClearColor = false;
2719 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2720 fUseDrawToClearColor = true;
2721 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002722 if (options.fDoManualMipmapping) {
2723 fDoManualMipmapping = true;
2724 }
csmartdaltone0d36292016-07-29 08:14:20 -07002725}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002726
Brian Salomon3d86a192018-02-27 16:46:11 -05002727bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2728 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2729 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2730 if (tex->hasBaseLevelBeenBoundToFBO()) {
2731 return false;
2732 }
2733 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002734 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002735 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2736 return false;
2737 }
2738 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2739 return false;
2740 }
2741 return SkToBool(surface->asTexture());
2742 }
2743 return true;
2744}
2745
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002746bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2747 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2748 // We don't support reading pixels directly from EXTERNAL textures as it would require
2749 // binding the texture to a FBO.
2750 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2751 return false;
2752 }
2753 }
2754 return true;
2755}
2756
2757GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2758 GrColorType dstColorType) const {
2759 // For now, we mostly report the read back format that is required by the ES spec without
2760 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2761 // this as makes sense to increase performance and correctness.
2762 switch (fConfigTable[config].fFormatType) {
2763 case kNormalizedFixedPoint_FormatType:
2764 return GrColorType::kRGBA_8888;
2765 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002766 if ((kAlpha_half_GrPixelConfig == config ||
2767 kAlpha_half_as_Red_GrPixelConfig == config) &&
2768 GrColorType::kAlpha_F16 == dstColorType) {
2769 return GrColorType::kAlpha_F16;
2770 }
2771 // And similar for full float RG.
2772 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2773 return GrColorType::kRG_F32;
2774 }
2775 return GrColorType::kRGBA_F32;
2776 }
2777 return GrColorType::kUnknown;
2778}
2779
Greg Daniel2a303902018-02-20 10:25:54 -05002780bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002781 GrGLFramebufferInfo fbInfo;
2782 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002783 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002784 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002785}
2786
Brian Salomonbdecacf2018-02-02 20:32:49 -05002787int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2788 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002789 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002790 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002791 return 0;
2792 }
2793
Brian Salomonbdecacf2018-02-02 20:32:49 -05002794 if (1 == requestedCount) {
2795 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2796 }
2797
Greg Daniel81e7bf82017-07-19 14:47:42 -04002798 for (int i = 0; i < count; ++i) {
2799 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002800 int count = fConfigTable[config].fColorSampleCounts[i];
2801 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2802 count = SkTMin(count, 4);
2803 }
2804 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002805 }
2806 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002807 return 0;
2808}
2809
2810int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2811 const auto& table = fConfigTable[config].fColorSampleCounts;
2812 if (!table.count()) {
2813 return 0;
2814 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002815 int count = table[table.count() - 1];
2816 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2817 count = SkTMin(count, 4);
2818 }
2819 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002820}
2821
Greg Danielfaa095e2017-12-19 13:15:02 -05002822bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2823 GrGLStandard standard) {
2824 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002825
2826 switch (ct) {
2827 case kUnknown_SkColorType:
2828 return false;
2829 case kAlpha_8_SkColorType:
2830 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002831 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002832 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002833 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002834 }
2835 break;
2836 case kRGB_565_SkColorType:
2837 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002838 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002839 }
2840 break;
2841 case kARGB_4444_SkColorType:
2842 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002843 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002844 }
2845 break;
2846 case kRGBA_8888_SkColorType:
2847 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002848 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002849 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002850 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002851 }
2852 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002853 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002854 if (GR_GL_RGB8 == format) {
2855 *config = kRGB_888_GrPixelConfig;
2856 }
2857 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002858 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002859 if (GR_GL_RGBA8 == format) {
2860 if (kGL_GrGLStandard == standard) {
2861 *config = kBGRA_8888_GrPixelConfig;
2862 }
2863 } else if (GR_GL_BGRA8 == format) {
2864 if (kGLES_GrGLStandard == standard) {
2865 *config = kBGRA_8888_GrPixelConfig;
2866 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002867 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002868 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002869 }
2870 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002871 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002872 if (GR_GL_RGB10_A2 == format) {
2873 *config = kRGBA_1010102_GrPixelConfig;
2874 }
2875 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002876 case kRGB_101010x_SkColorType:
2877 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002878 case kGray_8_SkColorType:
2879 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002880 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002881 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002882 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002883 }
2884 break;
2885 case kRGBA_F16_SkColorType:
2886 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002887 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002888 }
2889 break;
Mike Klein37854712018-06-26 11:43:06 -04002890 case kRGBA_F32_SkColorType:
2891 if (GR_GL_RGBA32F == format) {
2892 *config = kRGBA_float_GrPixelConfig;
2893 }
2894 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002895 }
2896
Greg Danielfaa095e2017-12-19 13:15:02 -05002897 return kUnknown_GrPixelConfig != *config;
2898}
2899
2900bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2901 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002902 GrGLTextureInfo texInfo;
2903 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002904 return false;
2905 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002906 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002907}
2908
2909bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2910 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002911 GrGLFramebufferInfo fbInfo;
2912 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002913 return false;
2914 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002915 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002916}
2917
Robert Phillipsfc711a22018-02-13 17:03:00 -05002918bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2919 GrPixelConfig* config) const {
2920 const GrGLenum* glFormat = format.getGLFormat();
2921 if (!glFormat) {
2922 return false;
2923 }
2924 return validate_sized_format(*glFormat, ct, config, fStandard);
2925}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002926
Timothy Liang036fdfe2018-06-28 15:50:36 -04002927#ifdef GR_TEST_UTILS
2928GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2929 const GrBackendTexture& backendTex) const {
2930 GrGLTextureInfo glInfo;
2931 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2932 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2933}
2934#endif