blob: 082994520450d4d68829caafdd7d3cef18dbaad5 [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;
Brian Salomona2a94a42018-10-16 10:54:10 -040066 fSamplerObjectSupport = false;
piotaixre4b23142014-10-02 10:57:53 -070067
Brian Salomone5e7eb12016-10-14 16:18:33 -040068 fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
Chris Dalton1b4ad762018-10-04 11:58:09 -060069 fMaxInstancesPerDrawWithoutCrashing = 0;
bsalomon083617b2016-02-12 12:10:14 -080070
Brian Salomon94efbf52016-11-29 13:43:05 -050071 fShaderCaps.reset(new GrShaderCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070072
cdalton4cd67132015-06-10 19:23:46 -070073 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000074}
75
cdalton4cd67132015-06-10 19:23:46 -070076void GrGLCaps::init(const GrContextOptions& contextOptions,
77 const GrGLContextInfo& ctxInfo,
78 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000079 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000080 GrGLVersion version = ctxInfo.version();
81
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000082 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000083 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
84 &fMaxFragmentUniformVectors);
85 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000086 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087 GrGLint max;
88 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
89 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000090 if (version >= GR_GL_VER(3, 2)) {
91 GrGLint profileMask;
92 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
93 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
94 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095 }
Adrienne Walker87785d52018-08-09 12:01:43 -070096 if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
97 fMaxFragmentUniformVectors = SkMin32(fMaxFragmentUniformVectors, 32);
98 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000099 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000100
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000101 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000102 fUnpackRowLengthSupport = true;
103 fUnpackFlipYSupport = false;
104 fPackRowLengthSupport = true;
105 fPackFlipYSupport = false;
106 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000107 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
108 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000110 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
111 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112 fPackFlipYSupport =
113 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
114 }
115
Adrienne Walkerc48f7762018-05-15 13:03:13 -0700116 if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
117 // In some cases drivers handle copying the last row incorrectly
118 // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
119 // through every row and conditionally clobbering that value, but
120 // Skia already has a scratch buffer workaround when pack row length
121 // is not supported, so just use that.
122 fPackRowLengthSupport = false;
123 }
124
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000125 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000126 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
127
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000128 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700129 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
130 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
131 ctxInfo.hasExtension("GL_NV_texture_barrier");
132 } else {
133 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
134 }
135
Robert Phillips7f861922018-01-30 13:13:42 +0000136 if (kGL_GrGLStandard == standard) {
137 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
138 ctxInfo.hasExtension("GL_ARB_texture_multisample");
139 } else {
140 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
141 }
142
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000143 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000144 ctxInfo.hasExtension("GL_ARB_imaging");
145
Brian Salomon01b476a2018-01-23 11:06:41 -0500146 if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
egdaniel9250d242015-05-18 13:04:26 -0700147 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
148 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000149 fDiscardRenderTargetSupport = true;
150 fInvalidateFBType = kInvalidate_InvalidateFBType;
151 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
152 fDiscardRenderTargetSupport = true;
153 fInvalidateFBType = kDiscard_InvalidateFBType;
154 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000155
Chris Dalton27059d32018-01-23 14:06:50 -0700156 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
157 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
158 if (kGLES_GrGLStandard == standard) {
159 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
Chris Dalton27059d32018-01-23 14:06:50 -0700160 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
161 if (kARM_GrGLVendor == ctxInfo.vendor()) {
162 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
163 }
164 }
165
Chris Dalton344e9032017-12-11 15:42:09 -0700166 if (kARM_GrGLVendor == ctxInfo.vendor() ||
167 kImagination_GrGLVendor == ctxInfo.vendor() ||
168 kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
169 fPreferFullscreenClears = true;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000170 }
171
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000172 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000173 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800174 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
175 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000176 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000177 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
178 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000179 }
180
cdalton626e1ff2015-06-12 13:56:46 -0700181 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
182 fDebugSupport = true;
183 } else {
184 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
185 }
186
jvanverth3f801cb2014-12-16 09:49:38 -0800187 if (kGL_GrGLStandard == standard) {
188 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
189 }
190 else {
191 fES2CompatibilitySupport = true;
192 }
193
cdalton0edea2c2015-05-21 08:27:44 -0700194 if (kGL_GrGLStandard == standard) {
195 fMultisampleDisableSupport = true;
196 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700197 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700198 }
199
kkinnunend94708e2015-07-30 22:47:04 -0700200 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600201 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
202 // instanced arrays, but we could make this more granular if we wanted
203 fInstanceAttribSupport =
204 version >= GR_GL_VER(3, 2) ||
205 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
206 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
207 } else {
208 fInstanceAttribSupport =
209 version >= GR_GL_VER(3, 0) ||
210 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
211 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
212 }
213
214 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700215 if (version >= GR_GL_VER(3, 0)) {
216 fBindFragDataLocationSupport = true;
217 }
218 } else {
219 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
220 fBindFragDataLocationSupport = true;
221 }
joshualittc1f56b52015-06-22 12:31:31 -0700222 }
223
joshualitt7bdd70a2015-10-01 06:28:11 -0700224 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
225
kkinnunene06ed252016-02-16 23:15:40 -0800226 if (kGL_GrGLStandard == standard) {
Weiliang Chen1e04b362018-07-12 17:13:35 -0400227 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
228 ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
kkinnunene06ed252016-02-16 23:15:40 -0800229 // We also require textureSize() support for rectangle 2D samplers which was added in
230 // GLSL 1.40.
231 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
232 fRectangleTextureSupport = true;
233 }
bsalomone179a912016-01-20 06:18:10 -0800234 }
kkinnunene06ed252016-02-16 23:15:40 -0800235 } else {
236 // Command buffer exposes this in GL ES context for Chromium reasons,
237 // but it should not be used. Also, at the time of writing command buffer
238 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800239 }
240
bsalomoncdee0092016-01-08 13:20:12 -0800241 if (kGL_GrGLStandard == standard) {
242 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
243 fTextureSwizzleSupport = true;
244 }
245 } else {
246 if (version >= GR_GL_VER(3,0)) {
247 fTextureSwizzleSupport = true;
248 }
249 }
250
cblume09bd2c02016-03-01 14:08:28 -0800251 if (kGL_GrGLStandard == standard) {
252 fMipMapLevelAndLodControlSupport = true;
253 } else if (kGLES_GrGLStandard == standard) {
254 if (version >= GR_GL_VER(3,0)) {
255 fMipMapLevelAndLodControlSupport = true;
256 }
257 }
258
bsalomon88c7b982015-07-31 11:20:16 -0700259#ifdef SK_BUILD_FOR_WIN
260 // We're assuming that on Windows Chromium we're using ANGLE.
261 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
262 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700263 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700264 fRGBA8888PixelsOpsAreSlow = isANGLE;
265 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
266 // check DX11 ANGLE.
267 fPartialFBOReadIsSlow = isANGLE;
268#endif
269
ericrkb4ecabd2016-03-11 15:18:20 -0800270 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
271 bool isMAC = false;
272#ifdef SK_BUILD_FOR_MAC
273 isMAC = true;
274#endif
275
276 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
277 // vis-versa.
278 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
279
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500280 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
281 fUseBufferDataNullHint = false;
282 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
283 fUseBufferDataNullHint = true;
284 }
285
Brian Salomond17b4a62017-05-23 16:53:47 -0400286 if (kGL_GrGLStandard == standard) {
287 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400288 fClearTextureSupport = true;
289 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500290 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
291 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400292 }
293
Greg Danielb2acf0a2018-09-12 09:17:11 -0400294#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
295 fSupportsAHardwareBufferImages = true;
296#endif
297
cdalton4cd67132015-06-10 19:23:46 -0700298 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700299 * GrShaderCaps fields
300 **************************************************************************/
301
egdaniel0a482332015-10-26 08:59:10 -0700302 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700303 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500304 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700305
Brian Osman195c05b2017-08-30 15:14:04 -0400306 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
307#if GR_TEST_UTILS
308 if (contextOptions.fSuppressPathRendering) {
309 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700310 }
Brian Osman195c05b2017-08-30 15:14:04 -0400311#endif
egdaniel05ded892015-10-26 07:38:05 -0700312
egdaniel05ded892015-10-26 07:38:05 -0700313 // Enable supported shader-related caps
314 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500315 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700316 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
Brian Salomon23c55b62018-06-19 16:28:41 -0400317 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600318
Brian Salomon1edc5b92016-11-29 13:43:46 -0500319 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600320
egdaniel05ded892015-10-26 07:38:05 -0700321 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500322 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700323 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600324 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600325 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
326 shaderCaps->fGSInvocationsSupport = true;
327 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
328 shaderCaps->fGSInvocationsSupport = true;
329 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
330 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600331 }
332
Brian Salomon1edc5b92016-11-29 13:43:46 -0500333 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800334 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500335 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500336 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700337
Brian Salomon1edc5b92016-11-29 13:43:46 -0500338 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700339 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800340
Chris Dalton1214be92018-06-28 19:06:27 -0600341 // Mali and early Adreno both have support for geometry shaders, but they appear to be
342 // implemented in software. In practice with ccpr, they are slower than the backup impl that
343 // only uses vertex shaders.
344 if (kARM_GrGLVendor != ctxInfo.vendor() &&
345 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
346 kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
347
Chris Daltonfaca00d2018-01-19 15:56:07 -0700348 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
349 shaderCaps->fGeometryShaderSupport = true;
350 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
351 shaderCaps->fGeometryShaderSupport = true;
352 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
353 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700354 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500355 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700356
Brian Salomon1edc5b92016-11-29 13:43:46 -0500357 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800358 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700359 }
360
cdalton9c3f1432016-03-11 10:07:37 -0800361 // Protect ourselves against tracking huge amounts of texture state.
362 static const uint8_t kMaxSaneSamplers = 32;
363 GrGLint maxSamplers;
cdalton9c3f1432016-03-11 10:07:37 -0800364 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500365 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800366
csmartdalton485a1202016-07-13 10:16:32 -0700367 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
368 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
369 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
370 // limit this decision to specific GPU families rather than basing it on the vendor alone.
371 if (!GR_GL_MUST_USE_VBO &&
372 !fIsCoreProfile &&
373 (kARM_GrGLVendor == ctxInfo.vendor() ||
374 kImagination_GrGLVendor == ctxInfo.vendor() ||
375 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
376 fPreferClientSideDynamicBuffers = true;
377 }
378
Eric Karl5c779752017-05-08 12:02:07 -0700379 if (!contextOptions.fAvoidStencilBuffers) {
380 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
381 this->initFSAASupport(contextOptions, ctxInfo, gli);
382 this->initStencilSupport(ctxInfo);
383 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400384
385 // Setup blit framebuffer
386 if (kGL_GrGLStandard != ctxInfo.standard()) {
387 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
388 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
389 kNoMSAADst_BlitFramebufferFlag |
390 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
391 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
392 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
393 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
394 // limitations.
395 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
396 kResolveMustBeFull_BlitFrambufferFlag |
397 kNoMSAADst_BlitFramebufferFlag |
398 kNoFormatConversion_BlitFramebufferFlag |
399 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
400 }
401 } else {
402 if (fUsesMixedSamples ||
403 ctxInfo.version() >= GR_GL_VER(3,0) ||
404 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
405 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
406 fBlitFramebufferFlags = 0;
407 }
408 }
409
cdalton1dd05422015-06-12 09:01:18 -0700410 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000411
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000412 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000413 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
414 // extension includes glMapBuffer.
415 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
416 fMapBufferFlags |= kSubset_MapFlag;
417 fMapBufferType = kMapBufferRange_MapBufferType;
418 } else {
419 fMapBufferType = kMapBuffer_MapBufferType;
420 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000421 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000422 // Unextended GLES2 doesn't have any buffer mapping.
423 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800424 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800425 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
426 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800427 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
428 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
429 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000430 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
431 fMapBufferFlags = kCanMap_MapFlag;
432 fMapBufferType = kMapBuffer_MapBufferType;
433 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000434 }
435
jvanverthd7a2c1f2015-12-07 07:36:44 -0800436 if (kGL_GrGLStandard == standard) {
437 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
438 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700439 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500440 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400441 if (version >= GR_GL_VER(3, 0) ||
442 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
443 // GL_EXT_unpack_subimage needed to support subtexture rectangles
444 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800445 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400446// TODO: get transfer buffers working in Chrome
447// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
448// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800449 }
450 }
451
joshualitte5b74c62015-06-01 14:17:47 -0700452 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
453 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700454 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700455#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500456 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
457 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
458 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700459 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700460#else
cdalton397536c2016-03-25 12:15:03 -0700461 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700462#endif
joshualitte5b74c62015-06-01 14:17:47 -0700463 }
464
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000465 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000466 fNPOTTextureTileSupport = true;
467 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000468 } else {
469 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000470 // ES3 has no limitations.
471 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
472 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000473 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
474 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
475 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
476 // to alllow arbitrary wrap modes, however.
477 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000478 }
479
bsalomon@google.combcce8922013-03-25 15:38:39 +0000480 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700481
482 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
483 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
484 }
485
bsalomon@google.combcce8922013-03-25 15:38:39 +0000486 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
487 // Our render targets are always created with textures as the color
488 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000489 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700490 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
491
492 if (kARM_GrGLVendor == ctxInfo.vendor()) {
493 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
494 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
495 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000496
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000497 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
498
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000499 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700500 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000501
robertphillips1b8e1b52015-06-24 06:54:10 -0700502#if 0
503 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
504 kQualcomm_GrGLVendor != ctxInfo.vendor();
505#endif
506
csmartdalton9bc11872016-08-09 12:42:47 -0700507 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
508 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700509 }
510
robertphillips63926682015-08-20 09:39:02 -0700511#ifdef SK_BUILD_FOR_WIN
512 // On ANGLE deferring flushes can lead to GPU starvation
513 fPreferVRAMUseOverFlushes = !isANGLE;
514#endif
515
bsalomon7dea7b72015-08-19 08:26:51 -0700516 if (kChromium_GrGLDriver == ctxInfo.driver()) {
517 fMustClearUploadedBufferData = true;
518 }
519
bsalomond08ea5f2015-02-20 06:58:13 -0800520 if (kGL_GrGLStandard == standard) {
521 // ARB allows mixed size FBO attachments, EXT does not.
522 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
523 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
524 fOversizedStencilSupport = true;
525 } else {
526 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
527 }
528 } else {
529 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
530 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
531 }
532
joshualitt58001552015-06-26 12:46:36 -0700533 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700534 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
535 ctxInfo.hasExtension("GL_ARB_draw_indirect");
536 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
537 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700538 (fDrawIndirectSupport &&
539 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700540 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700541 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800542 } else {
543 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700544 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
545 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
546 fBaseInstanceSupport = fDrawIndirectSupport &&
547 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700548 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800549 }
550
ethannicholas28ef4452016-03-25 09:26:03 -0700551 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500552 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700553 fSampleShadingSupport = true;
554 }
555 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
556 fSampleShadingSupport = true;
557 }
558
jvanverth84741b32016-09-30 08:39:02 -0700559 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
560 if (kGL_GrGLStandard == standard) {
561 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
562 fFenceSyncSupport = true;
563 }
Brian Osman93a23462017-06-21 15:13:39 -0400564 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700565 fFenceSyncSupport = true;
566 }
567
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400568 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500569 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500570
Brian Osman499bf1a2018-09-17 11:32:42 -0400571 // Half float vertex attributes requires GL3 or ES3
572 // It can also work with OES_VERTEX_HALF_FLOAT, but that requires a different enum.
573 if (kGL_GrGLStandard == standard) {
574 if (version >= GR_GL_VER(3, 0)) {
575 fHalfFloatVertexAttributeSupport = true;
576 }
577 } else if (version >= GR_GL_VER(3, 0)) {
578 fHalfFloatVertexAttributeSupport = true;
579 }
580
Brian Salomonf7232642018-09-19 08:58:08 -0400581 fDynamicStateArrayGeometryProcessorTextureSupport = true;
582
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400583 if (kGL_GrGLStandard == standard) {
584 if (version >= GR_GL_VER(4, 1)) {
585 fProgramBinarySupport = true;
586 }
587 } else if (version >= GR_GL_VER(3, 0)) {
588 fProgramBinarySupport = true;
589 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400590 if (fProgramBinarySupport) {
591 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400592 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400593 fProgramBinarySupport = count > 0;
594 }
Brian Salomona2a94a42018-10-16 10:54:10 -0400595 if (kGL_GrGLStandard == standard) {
596 fSamplerObjectSupport =
597 version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_sampler_objects");
598 } else {
599 fSamplerObjectSupport = version >= GR_GL_VER(3,0);
600 }
bsalomoncdee0092016-01-08 13:20:12 -0800601 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
602 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800603 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700604
Brian Salomon01b476a2018-01-23 11:06:41 -0500605 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
606 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
607 }
608
cdalton4cd67132015-06-10 19:23:46 -0700609 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500610 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700611
Brian Salomon01b476a2018-01-23 11:06:41 -0500612 // For now these two are equivalent but we could have dst read in shader via some other method.
613 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000614}
615
egdaniel472d44e2015-10-22 08:20:00 -0700616const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
617 bool isCoreProfile) {
618 switch (generation) {
619 case k110_GrGLSLGeneration:
620 if (kGLES_GrGLStandard == standard) {
621 // ES2s shader language is based on version 1.20 but is version
622 // 1.00 of the ES language.
623 return "#version 100\n";
624 } else {
625 SkASSERT(kGL_GrGLStandard == standard);
626 return "#version 110\n";
627 }
628 case k130_GrGLSLGeneration:
629 SkASSERT(kGL_GrGLStandard == standard);
630 return "#version 130\n";
631 case k140_GrGLSLGeneration:
632 SkASSERT(kGL_GrGLStandard == standard);
633 return "#version 140\n";
634 case k150_GrGLSLGeneration:
635 SkASSERT(kGL_GrGLStandard == standard);
636 if (isCoreProfile) {
637 return "#version 150\n";
638 } else {
639 return "#version 150 compatibility\n";
640 }
641 case k330_GrGLSLGeneration:
642 if (kGLES_GrGLStandard == standard) {
643 return "#version 300 es\n";
644 } else {
645 SkASSERT(kGL_GrGLStandard == standard);
646 if (isCoreProfile) {
647 return "#version 330\n";
648 } else {
649 return "#version 330 compatibility\n";
650 }
651 }
cdalton33ad7012016-02-22 07:55:44 -0800652 case k400_GrGLSLGeneration:
653 SkASSERT(kGL_GrGLStandard == standard);
654 if (isCoreProfile) {
655 return "#version 400\n";
656 } else {
657 return "#version 400 compatibility\n";
658 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500659 case k420_GrGLSLGeneration:
660 SkASSERT(kGL_GrGLStandard == standard);
661 if (isCoreProfile) {
662 return "#version 420\n";
663 }
664 else {
665 return "#version 420 compatibility\n";
666 }
egdaniel472d44e2015-10-22 08:20:00 -0700667 case k310es_GrGLSLGeneration:
668 SkASSERT(kGLES_GrGLStandard == standard);
669 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800670 case k320es_GrGLSLGeneration:
671 SkASSERT(kGLES_GrGLStandard == standard);
672 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700673 }
674 return "<no version>";
675}
676
Chris Dalton47c8ed32017-11-15 18:27:09 -0700677bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
678 if (kGLES_GrGLStandard != ctxInfo.standard() &&
679 ctxInfo.version() < GR_GL_VER(4,1) &&
680 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
681 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
682 return true;
683 }
684 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
685 // geometry shaders don't have lower precision than vertex and fragment.
686 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
687 GrGLint range[2];
688 GrGLint bits;
689 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
690 if (range[0] < 127 || range[1] < 127 || bits < 23) {
691 return false;
692 }
693 }
694 return true;
695}
696
697void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700698 GrGLStandard standard = ctxInfo.standard();
699 GrGLVersion version = ctxInfo.version();
700
701 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500702 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700703 **************************************************************************/
704
Brian Salomon1edc5b92016-11-29 13:43:46 -0500705 GrShaderCaps* shaderCaps = fShaderCaps.get();
706 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700707 if (kGLES_GrGLStandard == standard) {
708 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500709 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
710 shaderCaps->fFBFetchSupport = true;
711 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
712 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700713 }
714 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
715 // 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 -0500716 shaderCaps->fFBFetchNeedsCustomOutput = false;
717 shaderCaps->fFBFetchSupport = true;
718 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
719 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700720 }
721 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
722 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500723 shaderCaps->fFBFetchNeedsCustomOutput = false;
724 shaderCaps->fFBFetchSupport = true;
725 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
726 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700727 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500728 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700729 }
730
cdaltonc08f1962016-02-12 12:14:06 -0800731 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500732 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800733 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500734 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800735 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
736 }
Brian Salomon41274562017-09-15 09:40:03 -0700737 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
738 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
739 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800740 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500741 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800742 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
743 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400744 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
745 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500746 shaderCaps->fNoPerspectiveInterpolationSupport = true;
747 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800748 "GL_NV_shader_noperspective_interpolation";
749 }
750 }
751
Brian Salomon1edc5b92016-11-29 13:43:46 -0500752 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
753 shaderCaps->fGLSLGeneration,
754 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800755
Brian Salomon1edc5b92016-11-29 13:43:46 -0500756 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
757 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800758 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800759
760 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500761 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800762 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
763 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500764 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800765 }
766
767 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500768 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800769 }
770
cdalton9c3f1432016-03-11 10:07:37 -0800771 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400772 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
773 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400774 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400775 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
776 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
777 // At least one driver has been found that has this extension without the "GL_" prefix.
778 shaderCaps->fExternalTextureSupport = true;
779 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800780 }
781 }
782
cdaltonc04ce672016-03-11 14:07:38 -0800783 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600784 shaderCaps->fVertexIDSupport = true;
785 } else {
786 // Desktop GLSL 3.30 == ES GLSL 3.00.
787 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
788 }
789
Chris Dalton7c7ff032018-03-28 20:09:58 -0600790 if (kGL_GrGLStandard == standard) {
791 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
792 } else {
793 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
794 }
795
Chris Dalton47c8ed32017-11-15 18:27:09 -0700796 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
797 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400798
799 // Unsigned integers only supported in and after GLSL 1.30.
800 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700801}
802
kkinnunencfe62e32015-07-01 02:58:50 -0700803bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700804 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
805
806 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700807 return false;
808 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700809
kkinnunencfe62e32015-07-01 02:58:50 -0700810 if (kGL_GrGLStandard == ctxInfo.standard()) {
811 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
812 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
813 return false;
814 }
815 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700816 if (!hasChromiumPathRendering &&
817 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700818 return false;
819 }
820 }
821 // We only support v1.3+ of GL_NV_path_rendering which allows us to
822 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
823 // additions are detected by checking the existence of the function.
824 // We also use *Then* functions that not all drivers might have. Check
825 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800826 if (!gli->fFunctions.fStencilThenCoverFillPath ||
827 !gli->fFunctions.fStencilThenCoverStrokePath ||
828 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
829 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
830 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700831 return false;
832 }
833 return true;
834}
bsalomon1aa20292016-01-22 08:16:09 -0800835
Brian Salomon71d9d842016-11-03 13:42:00 -0400836bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800837 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800838 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800839 std::function<bool ()> bindRenderTarget,
840 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400841 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800842 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400843 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800844 return false;
845 }
bsalomon7928ef62016-01-05 10:26:39 -0800846
bsalomon76148af2016-01-12 11:13:47 -0800847 GrGLenum readFormat;
848 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400849 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800850 return false;
851 }
852
bsalomon1aa20292016-01-22 08:16:09 -0800853 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800854 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
855 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
856 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
857 // 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 -0500858 // The manual does not seem to fully match the spec as the spec allows integer formats
859 // when the bound color buffer is an integer buffer. It doesn't specify which integer
860 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500861 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
862 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
863 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800864 return false;
865 }
866 // There is also a set of allowed types, but all the types we use are in the set:
867 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
868 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
869 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
870 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
871 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
872 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
873 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800874 return true;
piotaixre4b23142014-10-02 10:57:53 -0700875 }
bsalomon7928ef62016-01-05 10:26:39 -0800876
bsalomon76148af2016-01-12 11:13:47 -0800877 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500878 switch (fConfigTable[surfaceConfig].fFormatType) {
879 case kNormalizedFixedPoint_FormatType:
880 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
881 return true;
882 }
883 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500884 case kFloat_FormatType:
885 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
886 return true;
887 }
888 break;
bsalomon7928ef62016-01-05 10:26:39 -0800889 }
890
Brian Salomon71d9d842016-11-03 13:42:00 -0400891 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800892 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400893 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800894 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800895 if (!bindRenderTarget()) {
896 return false;
897 }
898 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
899 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800900 rpFormat->fFormat = format;
901 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800902 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800903 }
904
Brian Salomon71d9d842016-11-03 13:42:00 -0400905 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
906 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700907}
908
Eric Karl5c779752017-05-08 12:02:07 -0700909void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
910 const GrGLInterface* gli) {
911 // We need dual source blending and the ability to disable multisample in order to support mixed
912 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
913 // renderer is available and enabled; no other path renderers support this feature.
914 if (fMultisampleDisableSupport &&
915 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400916 this->shaderCaps()->pathRenderingSupport()
917#if GR_TEST_UTILS
918 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
919#endif
920 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700921 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400922 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700923 }
924
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000925 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400926 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
927 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
928 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
929 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
930 fAlpha8IsRenderable = true;
931 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500932 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
933 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
934 // mixed samples we can't use multisampled-render-to-texture.
935 if (fUsesMixedSamples) {
936 fMSFBOType = kMixedSamples_MSFBOType;
937 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000938 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
939 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
940 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400941 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
942 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400943 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400944 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400945 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400946 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000947 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
948 fMSFBOType = kES_Apple_MSFBOType;
949 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000950 } else {
egdanieleed519e2016-01-15 11:36:18 -0800951 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700952 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400953 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
954 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400955
Brian Salomon00731b42016-10-14 11:30:51 -0400956 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400957 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
958 // Core profile removes ALPHA8 support.
959 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
960 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
961 // present.
962 fAlpha8IsRenderable = true;
963 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000964 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
965 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400966 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000967 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000968 }
Eric Karl5c779752017-05-08 12:02:07 -0700969
Brian Salomon01b476a2018-01-23 11:06:41 -0500970 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400971 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
972 fMSFBOType = kNone_MSFBOType;
973 }
974
Eric Karl5c779752017-05-08 12:02:07 -0700975 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
976 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
977 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700978 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000979}
980
cdalton1dd05422015-06-12 09:01:18 -0700981void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500982 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700983
Greg Daniel210883c2017-11-27 15:14:01 -0500984 bool layoutQualifierSupport = false;
985 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
986 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
987 layoutQualifierSupport = true;
988 }
989
cdalton1dd05422015-06-12 09:01:18 -0700990 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
991 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500992 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500993 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
994 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700995 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500996 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700997 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
998 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500999 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001000 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001001 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001002 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001003 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1004 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -07001005 }
cdalton1dd05422015-06-12 09:01:18 -07001006}
1007
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001008namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001009const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001010}
1011
Eric Karl5c779752017-05-08 12:02:07 -07001012void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001013
1014 // Build up list of legal stencil formats (though perhaps not supported on
1015 // the particular gpu/driver) from most preferred to least.
1016
1017 // these consts are in order of most preferred to least preferred
1018 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1019
1020 static const StencilFormat
1021 // internal Format stencil bits total bits packed?
1022 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1023 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1024 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1025 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001026 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001027 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1028
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001029 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001030 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001031 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001032 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1033 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1034
1035 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1036 // require FBO support we can expect these are legal formats and don't
1037 // check. These also all support the unsized GL_STENCIL_INDEX.
1038 fStencilFormats.push_back() = gS8;
1039 fStencilFormats.push_back() = gS16;
1040 if (supportsPackedDS) {
1041 fStencilFormats.push_back() = gD24S8;
1042 }
1043 fStencilFormats.push_back() = gS4;
1044 if (supportsPackedDS) {
1045 fStencilFormats.push_back() = gDS;
1046 }
1047 } else {
1048 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1049 // for other formats.
1050 // ES doesn't support using the unsized format.
1051
1052 fStencilFormats.push_back() = gS8;
1053 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001054 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1055 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001056 fStencilFormats.push_back() = gD24S8;
1057 }
1058 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1059 fStencilFormats.push_back() = gS4;
1060 }
1061 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001062}
1063
Kevin Lubickf4def342018-10-04 12:52:50 -04001064#ifdef SK_ENABLE_DUMP_GPU
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}
Kevin Lubickf4def342018-10-04 12:52:50 -04001177#else
1178void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { }
1179#endif
jvanverthe9c0fc62015-04-29 11:18:05 -07001180
bsalomon41e4384e2016-01-08 09:12:44 -08001181bool GrGLCaps::bgraIsInternalFormat() const {
1182 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1183}
1184
bsalomon76148af2016-01-12 11:13:47 -08001185bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1186 GrGLenum* internalFormat, GrGLenum* externalFormat,
1187 GrGLenum* externalType) const {
1188 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1189 externalFormat, externalType)) {
1190 return false;
1191 }
1192 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1193 return true;
1194}
1195
bsalomon76148af2016-01-12 11:13:47 -08001196bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1197 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001198 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001199 externalFormat, externalType)) {
1200 return false;
1201 }
1202 return true;
1203}
1204
Brian Salomon93348dd2018-08-29 12:56:23 -04001205void GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001206 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
Brian Salomon93348dd2018-08-29 12:56:23 -04001207}
1208
1209void GrGLCaps::getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1210 *internalFormat = fConfigTable[config].fFormats.fSizedInternalFormat;
bsalomon76148af2016-01-12 11:13:47 -08001211}
1212
1213bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1214 ExternalFormatUsage usage, GrGLenum* externalFormat,
1215 GrGLenum* externalType) const {
1216 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001217
1218 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1219 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1220
1221 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001222 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1223 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001224 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1225 return false;
1226 }
1227
1228 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1229 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1230
bsalomone9573312016-01-25 14:33:25 -08001231 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1232 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1233 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1234 // texture, not the red component.
1235 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001236 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001237 *externalFormat = GR_GL_ALPHA;
1238 }
1239 }
1240
bsalomon76148af2016-01-12 11:13:47 -08001241 return true;
1242}
1243
brianosman20471892016-12-02 06:43:32 -08001244void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1245 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001246 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001247 /*
1248 Comments on renderability of configs on various GL versions.
1249 OpenGL < 3.0:
1250 no built in support for render targets.
1251 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1252 format RGB, RGBA and NV float formats we don't use.
1253 This is the following:
1254 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1255 RGB10_A2, RGBA12,RGBA16
1256 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1257 since they aren't required by later standards and the driver can simply return
1258 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1259 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1260 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1261 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1262 This adds a lot of additional renderable sized formats, including ALPHA8.
1263 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1264 16F, 32I, 32UI, and 32F variants).
1265 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1266
1267 For both the above extensions we limit ourselves to those that are also required by
1268 OpenGL 3.0.
1269
1270 OpenGL 3.0:
1271 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1272 but are not required to be supported as renderable textures/renderbuffer.
1273 Required renderable color formats:
1274 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1275 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1276 RGB10_A2.
1277 - R11F_G11F_B10F.
1278 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1279 and RG8UI.
1280 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1281 - ALPHA8
1282
1283 OpenGL 3.1, 3.2, 3.3
1284 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1285 OpengGL 3.3, 4.0, 4.1
1286 Adds RGB10_A2UI.
1287 OpengGL 4.2
1288 Adds
1289 - RGB5_A1, RGBA4
1290 - RGB565
1291 OpenGL 4.4
1292 Does away with the separate list and adds a column to the sized internal color format
1293 table. However, no new formats become required color renderable.
1294
1295 ES 2.0
1296 color renderable: RGBA4, RGB5_A1, RGB565
1297 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1298 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1299 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1300 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1301 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1302 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1303
1304 ES 3.0
1305 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1306 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1307 RGB5_A1.
1308 - RGB8 and RGB565.
1309 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1310 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1311 ES 3.1
1312 Adds RGB10_A2, RGB10_A2UI,
1313 ES 3.2
1314 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1315 */
Brian Salomon44804c02018-01-23 16:51:28 -05001316
1317 // Correctness workarounds.
1318 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001319 bool disableSRGBForX86PowerVR = false;
1320 bool disableSRGBWriteControlForAdreno4xx = false;
1321 bool disableR8TexStorageForANGLEGL = false;
1322 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001323 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001324 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001325
1326 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1327 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1328 // and GL_RG on FBO textures.
1329 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1330
Greg Daniel09c94002018-06-08 22:11:51 +00001331 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1332
Brian Salomon44804c02018-01-23 16:51:28 -05001333 bool isX86PowerVR = false;
1334#if defined(SK_CPU_X86)
1335 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1336 isX86PowerVR = true;
1337 }
1338#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001339 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1340 // blacklist that device (and any others that might be sharing the same driver).
1341 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001342 disableSRGBWriteControlForAdreno4xx =
1343 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1344 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001345
1346 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1347 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1348 // check that we are not going to OpenGL.
1349 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1350
1351 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1352#if defined(SK_BUILD_FOR_MAC)
1353 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1354#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001355 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1356 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001357 }
1358
Brian Salomon71d9d842016-11-03 13:42:00 -04001359 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1360 ConfigInfo::kFBOColorAttachment_Flag;
1361 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001362 if (kNone_MSFBOType != fMSFBOType) {
1363 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1364 }
bsalomon41e4384e2016-01-08 09:12:44 -08001365 GrGLStandard standard = ctxInfo.standard();
1366 GrGLVersion version = ctxInfo.version();
1367
cblume790d5132016-02-29 11:13:29 -08001368 bool texStorageSupported = false;
1369 if (kGL_GrGLStandard == standard) {
1370 // The EXT version can apply to either GL or GLES.
1371 texStorageSupported = version >= GR_GL_VER(4,2) ||
1372 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1373 ctxInfo.hasExtension("GL_EXT_texture_storage");
1374 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001375 texStorageSupported = version >= GR_GL_VER(3,0) ||
1376 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001377 }
Adrienne Walker70e468f2018-08-22 16:05:27 -07001378 if (fDriverBugWorkarounds.disable_texture_storage) {
1379 texStorageSupported = false;
1380 }
cblume790d5132016-02-29 11:13:29 -08001381
Brian Salomone609e812018-01-17 14:00:47 -05001382 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001383
1384 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001385 if (kGL_GrGLStandard == standard) {
1386 textureRedSupport =
1387 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1388 } else {
1389 textureRedSupport =
1390 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1391 }
1392 }
1393
bsalomon30447372015-12-21 09:03:05 -08001394 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1395 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001396 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001397 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001398 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001399 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001400
1401 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1402 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001403 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001404 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001405 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001406 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001407 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1408 if (kGL_GrGLStandard == standard) {
1409 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1410 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001411 } else {
Kevin Lubick217056c2018-09-20 17:39:31 -04001412 bool isWebGL = false;
1413 // hack for skbug:8378
1414 #if IS_WEBGL==1
1415 isWebGL = true;
1416 #endif
1417 if (isWebGL || version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon41e4384e2016-01-08 09:12:44 -08001418 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1419 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1420 }
egdaniel4999df82016-01-07 17:06:04 -08001421 }
cblume790d5132016-02-29 11:13:29 -08001422 if (texStorageSupported) {
1423 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1424 }
bsalomoncdee0092016-01-08 13:20:12 -08001425 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001426
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001427 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1428 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1429 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1430 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1431 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1432 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1433 // supportedReadPixelsColorType never returns it.
1434 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1435 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1436 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1437 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1438 if (kGL_GrGLStandard == standard) {
1439 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1440 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1441 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1442 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1443 // becomes an issue.
1444 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1445 // but we don't support that just for simplicity's sake.
1446 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1447 } else {
1448 // 3.0 and the extension support this as a render buffer format.
1449 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1450 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1451 }
1452 }
1453 if (texStorageSupported) {
1454 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1455 }
1456 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1457 if (disableRGB8ForMali400) {
1458 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1459 }
1460
1461 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001462 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001463 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001464 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001465
1466 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1467 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1468 // GL_EXT_texture_format_BGRA8888.
1469 bool supportsBGRATexStorage = false;
1470
bsalomon41e4384e2016-01-08 09:12:44 -08001471 if (kGL_GrGLStandard == standard) {
1472 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1473 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1474 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1475 // Since the internal format is RGBA8, it is also renderable.
1476 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1477 allRenderFlags;
1478 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001479 // Since we are using RGBA8 we can use tex storage.
1480 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001481 } else {
1482 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1483 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001484 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1485 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1486 nonMSAARenderFlags;
1487
1488 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1489 supportsBGRATexStorage = true;
1490 }
1491 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1492 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1493 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1494 ConfigInfo::kRenderableWithMSAA_Flag;
1495 }
1496 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001497 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1498 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1499 // driver remembers the external format when the texture is created (with TexImage).
1500 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1501 // We could work around this, but it adds even more state tracking to code that is
1502 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1503 // This also side-steps some ambiguous interactions with the texture storage extension.
1504 if (version >= GR_GL_VER(3,0)) {
1505 // The APPLE extension doesn't make this renderable.
1506 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001507 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001508 }
bsalomon41e4384e2016-01-08 09:12:44 -08001509 }
1510 }
Brian Osman48c99192017-06-02 08:45:06 -04001511
Greg Daniel0ff79b22018-02-15 12:33:33 -05001512 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001513 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001514 }
bsalomoncdee0092016-01-08 13:20:12 -08001515 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001516
Brian Osman2b23c4b2018-06-01 12:25:08 -04001517 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001518 if (kGL_GrGLStandard == standard) {
1519 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001520 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001521 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1522 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1523 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001524 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001525 }
1526 }
1527 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001528 if (fSRGBSupport) {
1529 fSRGBWriteControl = true;
1530 }
bsalomon41e4384e2016-01-08 09:12:44 -08001531 } else {
brianosman20471892016-12-02 06:43:32 -08001532 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001533 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001534 fSRGBSupport = false;
1535 }
bsalomon41e4384e2016-01-08 09:12:44 -08001536 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1537 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001538 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001539 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001540 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001541 }
brianosman20471892016-12-02 06:43:32 -08001542
1543 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1544 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1545 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1546 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1547 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1548 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1549 // affects Windows.
1550 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1551 fSRGBSupport = false;
1552 }
1553
Brian Osman48c99192017-06-02 08:45:06 -04001554 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1555 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1556 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1557
Brian Osman67999392017-05-31 16:19:34 -04001558 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001559 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001560 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1561 }
Brian Osman67999392017-05-31 16:19:34 -04001562
bsalomon30447372015-12-21 09:03:05 -08001563 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1564 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1565 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1566 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001567 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001568 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001569 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001570 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001571 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001572 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001573 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001574 }
Brian Osman48c99192017-06-02 08:45:06 -04001575 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1576 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001577 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1578 }
bsalomoncdee0092016-01-08 13:20:12 -08001579 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001580 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1581 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1582 // is in this format, for example).
1583 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1584 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1585 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1586 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001587 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001588 GR_GL_BGRA;
1589 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1590 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001591 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001592 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001593 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001594 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001595
brianosmana6359362016-03-21 06:55:37 -07001596 if (texStorageSupported) {
1597 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1598 }
1599 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1600
bsalomon30447372015-12-21 09:03:05 -08001601 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1602 if (this->ES2CompatibilitySupport()) {
1603 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1604 } else {
1605 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1606 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001607 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001608 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001609 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001610 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001611 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1612 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001613 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001614 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1615 }
1616 } else {
1617 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1618 }
cblume790d5132016-02-29 11:13:29 -08001619 // 565 is not a sized internal format on desktop GL. So on desktop with
1620 // 565 we always use an unsized internal format to let the system pick
1621 // the best sized format to convert the 565 data to. Since TexStorage
1622 // only allows sized internal formats we disallow it.
1623 //
1624 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1625 // update.
1626 if (texStorageSupported && kGL_GrGLStandard != standard) {
1627 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1628 }
bsalomoncdee0092016-01-08 13:20:12 -08001629 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001630
1631 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1632 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001633 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001634 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001635 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001636 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001637 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1638 if (kGL_GrGLStandard == standard) {
1639 if (version >= GR_GL_VER(4, 2)) {
1640 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1641 }
1642 } else {
1643 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1644 }
cblume790d5132016-02-29 11:13:29 -08001645 if (texStorageSupported) {
1646 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1647 }
bsalomoncdee0092016-01-08 13:20:12 -08001648 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001649
Brian Osman10fc6fd2018-03-02 11:01:10 -05001650 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1651 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001652 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001653 GR_GL_RGBA;
1654 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1655 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1656 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1657 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1658 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1659 allRenderFlags;
1660 }
1661 if (texStorageSupported) {
1662 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1663 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001664 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1665
Greg Danielef59d872017-11-17 16:47:21 -05001666 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1667 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1668
1669 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1670 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1671 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1672 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1673 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001674 }
Greg Danielef59d872017-11-17 16:47:21 -05001675 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1676 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001677 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001678 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1679 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1680 alphaInfo.fFlags |= allRenderFlags;
1681 }
1682
1683 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1684 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1685 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1686 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1687 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001688 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001689 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001690
Brian Osman48c99192017-06-02 08:45:06 -04001691 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1692 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001693 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001694 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1695 }
1696 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1697 }
1698
Brian Salomone609e812018-01-17 14:00:47 -05001699 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001700 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001701 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1702 } else {
1703 redInfo.fFlags = 0;
1704
1705 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001706 }
bsalomon41e4384e2016-01-08 09:12:44 -08001707
Greg Daniel7af060a2017-12-05 16:27:11 -05001708 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1709 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1710 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1711 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1712 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001713 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001714 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1715 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1716 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1717 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001718 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001719
1720 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1721 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1722 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1723 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1724 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001725 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001726 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1727 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1728
Greg Daniel09c94002018-06-08 22:11:51 +00001729 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1730 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1731 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1732 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1733 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001734 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1735 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1736 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001737 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001738 }
Brian Osman48c99192017-06-02 08:45:06 -04001739 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001740 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001741 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1742 }
1743 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1744 }
1745
Brian Salomone609e812018-01-17 14:00:47 -05001746 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001747 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1748 } else {
1749 grayRedInfo.fFlags = 0;
1750 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001751 }
1752
bsalomon41e4384e2016-01-08 09:12:44 -08001753 // Check for [half] floating point texture support
1754 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1755 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1756 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
Chris Daltoneff01a72018-07-19 17:06:39 -06001757 bool hasFP32Textures = false;
1758 bool hasFP16Textures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001759 bool rgIsTexturable = false;
Chris Daltoneff01a72018-07-19 17:06:39 -06001760 bool hasFP32RenderTargets = false;
Brian Salomon75975512018-10-02 12:21:38 -04001761 enum class HalfFPRenderTargetSupport { kNone, kRGBAOnly, kAll };
1762 HalfFPRenderTargetSupport halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kNone;
bsalomon41e4384e2016-01-08 09:12:44 -08001763 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001764 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001765
1766 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001767 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001768 hasFP32Textures = true;
1769 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001770 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001771 hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001772 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
bsalomon41e4384e2016-01-08 09:12:44 -08001773 }
1774 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001775 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001776 hasFP32Textures = true;
1777 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001778 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001779 } else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1780 ctxInfo.hasExtension("GL_OES_texture_float")) {
1781 hasFP32Textures = true;
1782 hasFP16Textures = true;
1783 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1784 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1785 hasFP16Textures = true;
1786 }
1787
1788 if (version >= GR_GL_VER(3, 2)) {
1789 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to solve
1790 // many precision issues and no clients actually want this yet.
1791 // hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001792 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
Chris Daltoneff01a72018-07-19 17:06:39 -06001793 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
1794 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to
1795 // solve many precision issues and no clients actually want this yet.
1796 // hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001797 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
Chris Daltoneff01a72018-07-19 17:06:39 -06001798 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
Brian Salomon75975512018-10-02 12:21:38 -04001799 // This extension only enables half float support rendering for RGBA.
1800 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kRGBAOnly;
bsalomon41e4384e2016-01-08 09:12:44 -08001801 }
1802 }
bsalomon30447372015-12-21 09:03:05 -08001803
csmartdalton6aa0e112017-02-08 16:14:11 -05001804 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1805 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1806 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1807 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1808 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001809 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001810 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1811 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001812 if (hasFP32Textures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001813 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
Chris Daltoneff01a72018-07-19 17:06:39 -06001814 if (hasFP32RenderTargets) {
csmartdalton6aa0e112017-02-08 16:14:11 -05001815 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1816 }
bsalomon41e4384e2016-01-08 09:12:44 -08001817 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001818 if (texStorageSupported) {
1819 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1820 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001821 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001822 }
bsalomon30447372015-12-21 09:03:05 -08001823
Greg Danielef59d872017-11-17 16:47:21 -05001824 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001825 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001826 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001827 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001828 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001829 }
Greg Danielef59d872017-11-17 16:47:21 -05001830 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1831 redHalf.fFormats.fExternalType = redHalfExternalType;
1832 redHalf.fFormatType = kFloat_FormatType;
1833 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1834 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001835 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001836 redHalf.fSwizzle = GrSwizzle::RRRR();
Chris Daltoneff01a72018-07-19 17:06:39 -06001837 if (textureRedSupport && hasFP16Textures) {
Greg Danielef59d872017-11-17 16:47:21 -05001838 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1839
Brian Salomon75975512018-10-02 12:21:38 -04001840 if (halfFPRenderTargetSupport == HalfFPRenderTargetSupport::kAll) {
Greg Danielef59d872017-11-17 16:47:21 -05001841 redHalf.fFlags |= fpRenderFlags;
1842 }
1843
1844 if (texStorageSupported && !isCommandBufferES2) {
1845 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1846 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001847 }
Greg Danielef59d872017-11-17 16:47:21 -05001848 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001849
1850 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1851 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001852 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001853 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001854 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001855 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1856 } else {
1857 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1858 }
bsalomon7928ef62016-01-05 10:26:39 -08001859 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001860 if (hasFP16Textures) {
bsalomon41e4384e2016-01-08 09:12:44 -08001861 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1862 // ES requires 3.2 or EXT_color_buffer_half_float.
Brian Salomon75975512018-10-02 12:21:38 -04001863 if (halfFPRenderTargetSupport != HalfFPRenderTargetSupport::kNone) {
bsalomon41e4384e2016-01-08 09:12:44 -08001864 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1865 }
1866 }
cblume790d5132016-02-29 11:13:29 -08001867 if (texStorageSupported) {
1868 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1869 }
bsalomoncdee0092016-01-08 13:20:12 -08001870 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001871
bsalomon30447372015-12-21 09:03:05 -08001872 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1873
1874 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001875 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1876 ctxInfo.version() >= GR_GL_VER(3,0));
1877 // All ES versions (thus far) require sized internal formats for render buffers.
1878 // TODO: Always use sized internal format?
1879 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1880
bsalomon30447372015-12-21 09:03:05 -08001881 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001882 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1883 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001884 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001885 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001886 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1887 fConfigTable[i].fFormats.fSizedInternalFormat :
1888 fConfigTable[i].fFormats.fBaseInternalFormat;
1889 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001890 fConfigTable[i].fFormats.fSizedInternalFormat :
1891 fConfigTable[i].fFormats.fBaseInternalFormat;
1892 }
Brian Salomon44804c02018-01-23 16:51:28 -05001893 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1894 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1895 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1896 // in ES.
1897 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1898 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1899 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1900 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001901 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1902 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001903 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1904 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001905 }
1906
bsalomon30447372015-12-21 09:03:05 -08001907 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1908 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1909 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1910 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1911 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001912 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001913 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001914
1915 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1916 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1917 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1918 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001919 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001920 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1921 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1922 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1923 // slot.
1924 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1925 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001926
1927 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1928 // as a base format.
1929 // GL_EXT_texture_format_BGRA8888:
1930 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1931 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1932 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001933 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001934 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1935 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1936 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001937 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001938 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1939 }
1940
bsalomoncdee0092016-01-08 13:20:12 -08001941 // If we don't have texture swizzle support then the shader generator must insert the
1942 // swizzle into shader code.
1943 if (!this->textureSwizzleSupport()) {
1944 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001945 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001946 }
1947 }
1948
bsalomon7f9b2e42016-01-12 13:29:26 -08001949 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1950 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1951 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001952 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001953 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1954 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1955 if (GrPixelConfigIsAlphaOnly(config) &&
1956 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001957 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001958 }
1959 }
1960 }
1961
Greg Daniel81e7bf82017-07-19 14:47:42 -04001962 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1963 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001964 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1965 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001966 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001967 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1968 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001969 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001970 int count;
1971 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1972 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1973 1, &count);
1974 if (count) {
1975 int* temp = new int[count];
1976 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1977 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001978 // GL has a concept of MSAA rasterization with a single sample but we do not.
1979 if (count && temp[count - 1] == 1) {
1980 --count;
1981 SkASSERT(!count || temp[count -1] > 1);
1982 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001983 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001984 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001985 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001986 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001987 for (int j = 0; j < count; ++j) {
1988 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1989 }
1990 delete[] temp;
1991 }
1992 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001993 // Fake out the table using some semi-standard counts up to the max allowed sample
1994 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001995 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001996 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1997 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1998 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1999 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
2000 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002001 // Chrome has a mock GL implementation that returns 0.
2002 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05002003
Brian Salomonbdecacf2018-02-02 20:32:49 -05002004 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04002005 int count = SK_ARRAY_COUNT(kDefaultSamples);
2006 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002007 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002008 break;
2009 }
2010 }
2011 if (count > 0) {
2012 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
2013 }
2014 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002015 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
2016 fConfigTable[i].fColorSampleCounts.setCount(1);
2017 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002018 }
2019 }
2020
bsalomon30447372015-12-21 09:03:05 -08002021#ifdef SK_DEBUG
2022 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002023 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002024 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002025 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2026 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002027 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2028 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2029 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2030 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002031 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2032 fConfigTable[i].fFormats.fBaseInternalFormat);
2033 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002034 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002035 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2036 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2037 fConfigTable[i].fFormats.fExternalFormat[j]);
2038 }
2039 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002040 }
2041#endif
2042}
2043
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002044bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2045 bool dstIsTextureable, bool dstIsGLTexture2D,
2046 GrSurfaceOrigin dstOrigin,
2047 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2048 bool srcIsTextureable, bool srcIsGLTexture2D,
2049 GrSurfaceOrigin srcOrigin) const {
2050 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2051 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2052 // many drivers would allow it to work, but ANGLE does not.
2053 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2054 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2055 return false;
2056 }
2057
2058 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2059 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2060 return false;
2061 }
2062
2063 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2064 // texture.
2065 if (!dstIsTextureable) {
2066 return false;
2067 }
2068
2069 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2070 // is required
2071 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2072 (!srcIsTextureable || srcIsGLTexture2D) &&
2073 dstIsGLTexture2D &&
2074 dstOrigin == srcOrigin) {
2075 return true;
2076 } else {
2077 return false;
2078 }
2079}
2080
2081bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2082 bool dstIsTextureable, bool dstIsGLTexture2D,
2083 GrSurfaceOrigin dstOrigin,
2084 GrPixelConfig srcConfig, int srcSampleCnt,
2085 bool srcIsTextureable, bool srcIsGLTexture2D,
2086 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2087 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2088 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2089 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2090 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2091 return false;
2092 }
2093
2094 if (dstIsTextureable && !dstIsGLTexture2D) {
2095 return false;
2096 }
2097 if (srcIsTextureable && !srcIsGLTexture2D) {
2098 return false;
2099 }
2100
2101 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2102 return false;
2103 }
2104 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2105 // We would mirror to compensate for origin changes. Note that copySurface is
2106 // specified such that the src and dst rects are the same.
2107 if (dstOrigin != srcOrigin) {
2108 return false;
2109 }
2110 }
2111
2112 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2113 if (srcSampleCnt > 1) {
2114 if (1 == dstSampleCnt) {
2115 return false;
2116 }
2117 if (SkRect::Make(srcRect) != srcBounds) {
2118 return false;
2119 }
2120 }
2121 }
2122
2123 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2124 if (dstSampleCnt > 1) {
2125 return false;
2126 }
2127 }
2128
2129 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2130 if (dstConfig != srcConfig) {
2131 return false;
2132 }
2133 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2134 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2135 return false;
2136 }
2137 }
2138
2139 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2140 if (srcSampleCnt > 1) {
2141 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2142 return false;
2143 }
2144 if (dstOrigin != srcOrigin) {
2145 return false;
2146 }
2147 }
2148 }
2149 return true;
2150}
2151
2152bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2153 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2154}
2155
2156static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2157 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2158 if (!rt) {
2159 return false;
2160 }
2161 // A RT has a separate MSAA renderbuffer if:
2162 // 1) It's multisampled
2163 // 2) We're using an extension with separate MSAA renderbuffers
2164 // 3) It's not FBO 0, which is special and always auto-resolves
2165 return rt->numColorSamples() > 1 &&
2166 glCaps.usesMSAARenderBuffers() &&
2167 !rt->rtPriv().glRTFBOIDIs0();
2168}
2169
2170bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2171 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2172 GrSurfaceOrigin dstOrigin = dst->origin();
2173 GrSurfaceOrigin srcOrigin = src->origin();
2174
2175 GrPixelConfig dstConfig = dst->config();
2176 GrPixelConfig srcConfig = src->config();
2177
2178 int dstSampleCnt = 0;
2179 int srcSampleCnt = 0;
2180 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2181 dstSampleCnt = rtProxy->numColorSamples();
2182 }
2183 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2184 srcSampleCnt = rtProxy->numColorSamples();
2185 }
2186 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2187 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2188
2189 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2190 // swizzle.
2191 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2192 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2193 return false;
2194 }
2195
2196 const GrTextureProxy* dstTex = dst->asTextureProxy();
2197 const GrTextureProxy* srcTex = src->asTextureProxy();
2198
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002199 bool dstIsTex2D = dstTex ? (dstTex->textureType() == GrTextureType::k2D) : false;
2200 bool srcIsTex2D = srcTex ? (srcTex->textureType() == GrTextureType::k2D) : false;
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002201
2202 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2203 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2204 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2205 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2206 // know we will at least be able to do it as a draw.
2207#ifdef SK_DEBUG
2208 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2209 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2210 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2211 !src->priv().isExact()) {
2212 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2213 }
2214#endif
2215
2216 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2217 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2218 srcConfig, has_msaa_render_buffer(src, *this),
2219 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2220 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2221 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2222 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2223 dstPoint) ||
2224 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2225}
2226
Robert Phillipsbf25d432017-04-07 10:08:53 -04002227bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002228 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2229 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002230 // By default, we don't require rects to match.
2231 *rectsMustMatch = false;
2232
2233 // By default, we allow subrects.
2234 *disallowSubrect = false;
2235
Brian Salomon467921e2017-03-06 16:17:12 -05002236 // If the src is a texture, we can implement the blit as a draw assuming the config is
2237 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002238 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002239 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002240 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2241 desc->fConfig = src->config();
2242 return true;
2243 }
2244
Robert Phillipsbf25d432017-04-07 10:08:53 -04002245 {
2246 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2247 // wrapped. In that case the proxy would already be instantiated.
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002248 const GrTexture* srcTexture = src->peekTexture();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002249 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2250 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2251 // Not supported for FBO blit or CopyTexSubImage
2252 return false;
2253 }
Brian Salomon467921e2017-03-06 16:17:12 -05002254 }
2255
2256 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2257 // possible and we return false to fallback to creating a render target dst for render-to-
2258 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2259 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002260 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002261 bool rectsMustMatchForBlitFramebuffer = false;
2262 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002263 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002264 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2265 rectsMustMatchForBlitFramebuffer = true;
2266 disallowSubrectForBlitFramebuffer = true;
2267 // Mirroring causes rects to mismatch later, don't allow it.
2268 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002269 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2270 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002271 rectsMustMatchForBlitFramebuffer = true;
2272 // Mirroring causes rects to mismatch later, don't allow it.
2273 originForBlitFramebuffer = src->origin();
2274 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002275 originForBlitFramebuffer = src->origin();
2276 }
2277
2278 // Check for format issues with glCopyTexSubImage2D
2279 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2280 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2281 // then we set up for that, otherwise fail.
2282 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002283 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002284 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002285 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2286 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002287 return true;
2288 }
2289 return false;
2290 }
2291
Robert Phillipsbf25d432017-04-07 10:08:53 -04002292 {
Brian Salomon63e79732017-05-15 21:23:13 -04002293 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2294 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002295 if (srcIsMSAARenderbuffer) {
2296 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2297 // blit or fail.
2298 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002299 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002300 desc->fConfig = src->config();
2301 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2302 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2303 return true;
2304 }
2305 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002306 }
Brian Salomon467921e2017-03-06 16:17:12 -05002307 }
2308
2309 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002310 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002311 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002312 desc->fFlags = kNone_GrSurfaceFlags;
2313 return true;
2314}
2315
Greg Daniel691f5e72018-02-28 14:21:34 -05002316void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2317 const GrContextOptions& contextOptions,
2318 GrShaderCaps* shaderCaps) {
Brian Salomondc829942018-10-23 16:07:24 -04002319 bool isX86PowerVRRogue = false;
2320#if defined(SK_CPU_X86)
2321 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2322 isX86PowerVRRogue = true;
2323 }
2324#endif
2325
Brian Salomon01b476a2018-01-23 11:06:41 -05002326 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2327 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002328 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2329 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002330 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002331 fDiscardRenderTargetSupport = false;
2332 fInvalidateFBType = kNone_InvalidateFBType;
2333 }
2334
2335 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2336 // 340.96 and 367.57.
2337 if (kGL_GrGLStandard == ctxInfo.standard() &&
2338 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002339 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002340 fClearTextureSupport = false;
2341 }
2342
Brian Salomondc829942018-10-23 16:07:24 -04002343 // Calling glClearTexImage crashes on the NexusPlayer. TODO: Use isX86PowerVRRogue?
Brian Salomon01b476a2018-01-23 11:06:41 -05002344 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2345 fClearTextureSupport = false;
2346 }
2347
Brian Salomon01b476a2018-01-23 11:06:41 -05002348#ifdef SK_BUILD_FOR_MAC
Chris Dalton6989ba42018-10-03 10:34:09 -06002349 // Radeon MacBooks hit a crash in glReadPixels() when using geometry shaders.
2350 // http://skbug.com/8097
2351 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2352 shaderCaps->fGeometryShaderSupport = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002353 }
Chris Dalton6989ba42018-10-03 10:34:09 -06002354 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2355 shaderCaps->fGSInvocationsSupport = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002356#endif
2357
2358 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2359 // shaders. @127.0 is the earliest verified driver to not crash.
2360 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002361 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002362 shaderCaps->fGeometryShaderSupport = false;
2363 }
2364
2365#if defined(__has_feature)
2366#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2367 // See skbug.com/7058
2368 fMapBufferType = kNone_MapBufferType;
2369 fMapBufferFlags = kNone_MapFlags;
2370#endif
2371#endif
2372
2373 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2374 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2375 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2376 // unclear whether this really affects a wide range of devices.
2377 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002378 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002379 fMapBufferType = kNone_MapBufferType;
2380 fMapBufferFlags = kNone_MapFlags;
2381 }
2382
2383 // TODO: re-enable for ANGLE
2384 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2385 fTransferBufferType = kNone_TransferBufferType;
2386 }
2387
2388 // Using MIPs on this GPU seems to be a source of trouble.
2389 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2390 fMipMapSupport = false;
2391 }
2392
Brian Salomondc829942018-10-23 16:07:24 -04002393 // TODO: Use isX86PowerVRRogue?
Brian Salomon01b476a2018-01-23 11:06:41 -05002394 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2395 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2396 // around a driver bug related to gl_FragCoord.
2397 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2398 fMaxClipAnalyticFPs = 0;
2399 }
2400
2401#ifndef SK_BUILD_FOR_IOS
2402 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2403 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2404 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2405 ctxInfo.driver() != kChromium_GrGLDriver)) {
2406 fUseDrawToClearColor = true;
2407 }
2408#endif
2409
2410 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2411 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2412 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2413 fUseDrawToClearColor = true;
2414 }
2415
2416#ifdef SK_BUILD_FOR_MAC
2417 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2418 // full screen clears
2419 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2420 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002421 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2422 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2423 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2424 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002425 fUseDrawToClearColor = true;
2426 }
2427#endif
2428
2429 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2430 // bugs seems to involve clearing too much and not skipping the clear.
2431 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2432 // but only for D3D11 ANGLE.
2433 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2434 fUseDrawToClearColor = true;
2435 }
2436
Chris Dalton1214be92018-06-28 19:06:27 -06002437 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2438 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002439 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002440 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002441 fUseDrawToClearStencilClip = true;
2442 }
2443 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2444 }
2445
Adrienne Walker94f585e2018-05-15 11:47:07 -07002446 if (fDriverBugWorkarounds.gl_clear_broken) {
2447 fUseDrawToClearColor = true;
2448 fUseDrawToClearStencilClip = true;
2449 }
2450
Brian Salomon01b476a2018-01-23 11:06:41 -05002451 // This was reproduced on the following configurations:
2452 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2453 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2454 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2455 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2456 // and not produced on:
2457 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2458 // The particular lines that get dropped from test images varies across different devices.
2459 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002460 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002461 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2462 }
2463
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002464 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2465 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2466 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002467 fRequiresFlushBetweenNonAndInstancedDraws = true;
2468 }
2469
Brian Osman1348ed02018-09-12 09:08:39 -04002470 // This was reproduced on a Pixel 1, but the unit test + config + options that exercise it are
2471 // only tested on very specific bots. The driver claims that ReadPixels is an invalid operation
2472 // when reading from an auto-resolving MSAA framebuffer that has stencil attached.
2473 if (kQualcomm_GrGLDriver == ctxInfo.driver()) {
2474 fDetachStencilFromMSAABuffersBeforeReadPixels = true;
2475 }
2476
Brian Salomondc829942018-10-23 16:07:24 -04002477 // TODO: Don't apply this on iOS?
Brian Salomon01b476a2018-01-23 11:06:41 -05002478 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
Chris Dalton1b4ad762018-10-04 11:58:09 -06002479 // Our Chromebook with kPowerVRRogue_GrGLRenderer crashes on large instanced draws. The
2480 // current minimum number of instances observed to crash is somewhere between 2^14 and 2^15.
2481 // Keep the number of instances below 1000, just to be safe.
2482 fMaxInstancesPerDrawWithoutCrashing = 999;
Adrienne Walker001cae02018-05-15 11:38:44 -07002483 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
Chris Dalton1b4ad762018-10-04 11:58:09 -06002484 fMaxInstancesPerDrawWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002485 }
2486
2487 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002488 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002489 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2490 fUseDrawInsteadOfAllRenderTargetWrites = true;
2491 }
2492
2493 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2494 fSampleShadingSupport = false;
2495 }
2496
2497#ifdef SK_BUILD_FOR_MAC
2498 static constexpr bool isMAC = true;
2499#else
2500 static constexpr bool isMAC = false;
2501#endif
2502
2503 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2504 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2505 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2506 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2507 if (fMipMapLevelAndLodControlSupport &&
2508 (contextOptions.fDoManualMipmapping ||
2509 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2510 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2511 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2512 fDoManualMipmapping = true;
2513 }
2514
2515 // See http://crbug.com/710443
2516#ifdef SK_BUILD_FOR_MAC
2517 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2518 fClearToBoundaryValuesIsBroken = true;
2519 }
2520#endif
2521 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2522 fDrawArraysBaseVertexIsBroken = true;
2523 }
2524
Brian Salomon01b476a2018-01-23 11:06:41 -05002525 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2526 // Galaxy S7.
2527 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2528 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2529 shaderCaps->fFBFetchSupport = false;
2530 }
2531
Brian Salomon01b476a2018-01-23 11:06:41 -05002532 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2533 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2534
2535 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2536 // function that may require a gradient calculation inside a conditional block may return
2537 // undefined results". This appears to be an issue with the 'any' call since even the simple
2538 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2539 // from our GrTextureDomain processor.
2540 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2541
2542 // Known issue on at least some Intel platforms:
2543 // http://code.google.com/p/skia/issues/detail?id=946
2544 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2545 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2546 }
2547
Chris Dalton0090ef62018-03-28 17:35:00 -06002548 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002549 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2550 // so we must do the abs first in a separate expression.
2551 shaderCaps->fCanUseMinAndAbsTogether = false;
2552
2553 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2554 // must avoid this condition.
2555 shaderCaps->fCanUseFractForNegativeValues = false;
2556 }
2557
2558 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2559 // thus must us -1.0 * %s.x to work correctly
2560 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2561 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2562 }
2563
2564 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2565 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2566 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2567 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2568 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2569 }
2570
2571 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2572 // the original dst color when reading the outColor even after being written to. By using a
2573 // local outColor we can work around this bug.
2574 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2575 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2576 }
2577
2578 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2579 // color, and that uniform contains an opaque color, and the output of the shader is only based
2580 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2581 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2582 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2583 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2584 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2585 shaderCaps->fMustObfuscateUniformColor = true;
2586 }
2587#ifdef SK_BUILD_FOR_WIN
2588 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2589 //
2590 // Basically, if a shader has a construct like:
2591 //
2592 // float x = someCondition ? someValue : 0;
2593 // float2 result = (0 == x) ? float2(x, x)
2594 // : float2(2 * x / x, 0);
2595 //
2596 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2597 // we've explicitly guarded the division with a check against zero. This manifests in much
2598 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2599 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2600 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2601 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2602 }
2603#endif
2604
2605 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002606 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002607 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2608 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002609 }
2610
Chris Dalton0090ef62018-03-28 17:35:00 -06002611 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2612 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2613 shaderCaps->fCanUseFragCoord = false;
2614 }
2615
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002616 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2617 // (Are they implemented with fp16?)
2618 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2619 shaderCaps->fIncompleteShortIntPrecision = true;
2620 }
2621
Adrienne Walkeree8295c2018-08-21 10:56:30 -07002622 if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
2623 shaderCaps->fAddAndTrueToLoopCondition = true;
2624 }
2625
Adrienne Walkerc02165f2018-08-21 11:08:11 -07002626 if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
2627 shaderCaps->fUnfoldShortCircuitAsTernary = true;
2628 }
2629
Adrienne Walker92b161f2018-08-22 10:41:52 -07002630 if (fDriverBugWorkarounds.emulate_abs_int_function) {
2631 shaderCaps->fEmulateAbsIntFunction = true;
2632 }
2633
Adrienne Walker8b23ca62018-08-22 10:45:41 -07002634 if (fDriverBugWorkarounds.rewrite_do_while_loops) {
2635 shaderCaps->fRewriteDoWhileLoops = true;
2636 }
2637
Adrienne Walker2f4c09b2018-08-22 16:04:57 -07002638 if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
2639 shaderCaps->fRemovePowWithConstantExponent = true;
2640 }
2641
Brian Salomon01b476a2018-01-23 11:06:41 -05002642 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2643 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002644 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2645 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002646 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2647 kIntel_GrGLDriver == ctxInfo.driver() ||
2648 kChromium_GrGLDriver == ctxInfo.driver()) {
2649 fBlendEquationSupport = kBasic_BlendEquationSupport;
2650 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2651 }
2652
2653 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2654 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002655 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002656 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002657 fBlendEquationSupport = kBasic_BlendEquationSupport;
2658 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2659 }
2660
Adrienne Walker68314842018-05-14 14:02:53 -07002661 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2662 fBlendEquationSupport = kBasic_BlendEquationSupport;
2663 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2664 }
2665
Brian Salomon01b476a2018-01-23 11:06:41 -05002666 if (this->advancedBlendEquationSupport()) {
2667 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002668 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002669 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2670 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2671 (1 << kColorBurn_GrBlendEquation);
2672 }
2673 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2674 // Blacklist color-burn on ARM until the fix is released.
2675 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2676 }
2677 }
2678
2679 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2680 if (fMultisampleDisableSupport &&
2681 this->shaderCaps()->dualSourceBlendingSupport() &&
2682 this->shaderCaps()->pathRenderingSupport() &&
2683 fUsesMixedSamples &&
2684#if GR_TEST_UTILS
2685 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2686#endif
2687 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2688 kChromium_GrGLDriver == ctxInfo.driver())) {
2689 fDiscardRenderTargetSupport = false;
2690 fInvalidateFBType = kNone_InvalidateFBType;
2691 }
Brian Osmanc585e202018-04-04 14:08:27 -04002692
Brian Osman061020e2018-04-17 14:22:15 -04002693 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2694 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2695 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2696 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002697 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2698 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002699 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002700 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002701 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2702 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002703 }
Brian Osman2fa53742018-05-03 15:05:12 -04002704
2705#ifdef SK_BUILD_FOR_IOS
2706 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2707 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2708 // is to just blacklist the feature.
2709 // https://github.com/flutter/flutter/issues/16718
2710 // https://bugreport.apple.com/web/?problemID=39948888
2711 fUnpackRowLengthSupport = false;
2712#endif
Brian Salomondc829942018-10-23 16:07:24 -04002713
2714 if (isX86PowerVRRogue) {
2715 // On Nexus Player we get incorrect filter modes when using sampler objects.
2716 fSamplerObjectSupport = false;
2717 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002718}
2719
csmartdaltone0d36292016-07-29 08:14:20 -07002720void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002721 if (options.fDisableDriverCorrectnessWorkarounds) {
2722 SkASSERT(!fDoManualMipmapping);
2723 SkASSERT(!fClearToBoundaryValuesIsBroken);
Chris Dalton1b4ad762018-10-04 11:58:09 -06002724 SkASSERT(0 == fMaxInstancesPerDrawWithoutCrashing);
Brian Salomon01b476a2018-01-23 11:06:41 -05002725 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2726 SkASSERT(!fUseDrawToClearColor);
2727 SkASSERT(!fUseDrawToClearStencilClip);
2728 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2729 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2730 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002731 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Osman1348ed02018-09-12 09:08:39 -04002732 SkASSERT(!fDetachStencilFromMSAABuffersBeforeReadPixels);
Brian Salomon01b476a2018-01-23 11:06:41 -05002733 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002734 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2735 fUseDrawToClearColor = false;
2736 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2737 fUseDrawToClearColor = true;
2738 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002739 if (options.fDoManualMipmapping) {
2740 fDoManualMipmapping = true;
2741 }
csmartdaltone0d36292016-07-29 08:14:20 -07002742}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002743
Brian Salomon3d86a192018-02-27 16:46:11 -05002744bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2745 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2746 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2747 if (tex->hasBaseLevelBeenBoundToFBO()) {
2748 return false;
2749 }
2750 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002751 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002752 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2753 return false;
2754 }
2755 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2756 return false;
2757 }
2758 return SkToBool(surface->asTexture());
2759 }
2760 return true;
2761}
2762
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002763bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2764 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2765 // We don't support reading pixels directly from EXTERNAL textures as it would require
2766 // binding the texture to a FBO.
2767 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2768 return false;
2769 }
2770 }
2771 return true;
2772}
2773
2774GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2775 GrColorType dstColorType) const {
2776 // For now, we mostly report the read back format that is required by the ES spec without
2777 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2778 // this as makes sense to increase performance and correctness.
2779 switch (fConfigTable[config].fFormatType) {
2780 case kNormalizedFixedPoint_FormatType:
2781 return GrColorType::kRGBA_8888;
2782 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002783 if ((kAlpha_half_GrPixelConfig == config ||
2784 kAlpha_half_as_Red_GrPixelConfig == config) &&
2785 GrColorType::kAlpha_F16 == dstColorType) {
2786 return GrColorType::kAlpha_F16;
2787 }
2788 // And similar for full float RG.
2789 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2790 return GrColorType::kRG_F32;
2791 }
2792 return GrColorType::kRGBA_F32;
2793 }
2794 return GrColorType::kUnknown;
2795}
2796
Greg Daniel2a303902018-02-20 10:25:54 -05002797bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002798 GrGLFramebufferInfo fbInfo;
2799 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002800 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002801 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002802}
2803
Brian Salomonbdecacf2018-02-02 20:32:49 -05002804int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2805 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002806 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002807 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002808 return 0;
2809 }
2810
Brian Salomonbdecacf2018-02-02 20:32:49 -05002811 if (1 == requestedCount) {
2812 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2813 }
2814
Greg Daniel81e7bf82017-07-19 14:47:42 -04002815 for (int i = 0; i < count; ++i) {
2816 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002817 int count = fConfigTable[config].fColorSampleCounts[i];
2818 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2819 count = SkTMin(count, 4);
2820 }
2821 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002822 }
2823 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002824 return 0;
2825}
2826
2827int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2828 const auto& table = fConfigTable[config].fColorSampleCounts;
2829 if (!table.count()) {
2830 return 0;
2831 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002832 int count = table[table.count() - 1];
2833 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2834 count = SkTMin(count, 4);
2835 }
2836 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002837}
2838
Greg Danielfaa095e2017-12-19 13:15:02 -05002839bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2840 GrGLStandard standard) {
2841 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002842
2843 switch (ct) {
2844 case kUnknown_SkColorType:
2845 return false;
2846 case kAlpha_8_SkColorType:
2847 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002848 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002849 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002850 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002851 }
2852 break;
2853 case kRGB_565_SkColorType:
2854 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002855 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002856 }
2857 break;
2858 case kARGB_4444_SkColorType:
2859 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002860 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002861 }
2862 break;
2863 case kRGBA_8888_SkColorType:
2864 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002865 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002866 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002867 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002868 }
2869 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002870 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002871 if (GR_GL_RGB8 == format) {
2872 *config = kRGB_888_GrPixelConfig;
2873 }
2874 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002875 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002876 if (GR_GL_RGBA8 == format) {
2877 if (kGL_GrGLStandard == standard) {
2878 *config = kBGRA_8888_GrPixelConfig;
2879 }
2880 } else if (GR_GL_BGRA8 == format) {
2881 if (kGLES_GrGLStandard == standard) {
2882 *config = kBGRA_8888_GrPixelConfig;
2883 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002884 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002885 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002886 }
2887 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002888 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002889 if (GR_GL_RGB10_A2 == format) {
2890 *config = kRGBA_1010102_GrPixelConfig;
2891 }
2892 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002893 case kRGB_101010x_SkColorType:
2894 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002895 case kGray_8_SkColorType:
2896 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002897 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002898 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002899 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002900 }
2901 break;
2902 case kRGBA_F16_SkColorType:
2903 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002904 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002905 }
2906 break;
Mike Klein37854712018-06-26 11:43:06 -04002907 case kRGBA_F32_SkColorType:
2908 if (GR_GL_RGBA32F == format) {
2909 *config = kRGBA_float_GrPixelConfig;
2910 }
2911 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002912 }
2913
Greg Danielfaa095e2017-12-19 13:15:02 -05002914 return kUnknown_GrPixelConfig != *config;
2915}
2916
2917bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2918 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002919 GrGLTextureInfo texInfo;
2920 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002921 return false;
2922 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002923 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002924}
2925
2926bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2927 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002928 GrGLFramebufferInfo fbInfo;
2929 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002930 return false;
2931 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002932 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002933}
2934
Robert Phillipsfc711a22018-02-13 17:03:00 -05002935bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2936 GrPixelConfig* config) const {
2937 const GrGLenum* glFormat = format.getGLFormat();
2938 if (!glFormat) {
2939 return false;
2940 }
2941 return validate_sized_format(*glFormat, ct, config, fStandard);
2942}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002943
Jim Van Verth9bf81202018-10-30 15:53:36 -04002944static bool get_yuva_config(GrGLenum format, GrPixelConfig* config) {
2945 *config = kUnknown_GrPixelConfig;
Jim Van Verthb7f0b9c2018-10-22 14:12:03 -04002946
Jim Van Verth9bf81202018-10-30 15:53:36 -04002947 switch (format) {
Jim Van Verthb7f0b9c2018-10-22 14:12:03 -04002948 case GR_GL_ALPHA8:
2949 *config = kAlpha_8_as_Alpha_GrPixelConfig;
2950 break;
2951 case GR_GL_R8:
2952 *config = kAlpha_8_as_Red_GrPixelConfig;
2953 break;
2954 case GR_GL_RGBA8:
2955 *config = kRGBA_8888_GrPixelConfig;
2956 break;
2957 case GR_GL_RGB8:
2958 *config = kRGB_888_GrPixelConfig;
2959 break;
2960 case GR_GL_BGRA8:
2961 *config = kBGRA_8888_GrPixelConfig;
2962 break;
2963 default:
2964 return false;
2965 }
2966
2967 return true;
2968}
2969
Jim Van Verth9bf81202018-10-30 15:53:36 -04002970bool GrGLCaps::getYUVAConfigFromBackendTexture(const GrBackendTexture& tex,
2971 GrPixelConfig* config) const {
2972 GrGLTextureInfo texInfo;
2973 if (!tex.getGLTextureInfo(&texInfo)) {
2974 return false;
2975 }
2976 return get_yuva_config(texInfo.fFormat, config);
2977}
2978
2979bool GrGLCaps::getYUVAConfigFromBackendFormat(const GrBackendFormat& format,
2980 GrPixelConfig* config) const {
2981 const GrGLenum* glFormat = format.getGLFormat();
2982 if (!glFormat) {
2983 return false;
2984 }
2985 return get_yuva_config(*glFormat, config);
2986}
2987
Jim Van Verthb7f0b9c2018-10-22 14:12:03 -04002988
Timothy Liang036fdfe2018-06-28 15:50:36 -04002989#ifdef GR_TEST_UTILS
2990GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2991 const GrBackendTexture& backendTex) const {
2992 GrGLTextureInfo glInfo;
2993 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2994 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2995}
2996#endif