blob: dd5964891741270fd716da026553af7074e89ff5 [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;
Ethan Nicholas06d55fb2017-11-08 09:48:50 -050064 fProgramBinarySupport = false;
piotaixre4b23142014-10-02 10:57:53 -070065
Brian Salomone5e7eb12016-10-14 16:18:33 -040066 fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
Chris Daltoncc604e52017-10-06 16:27:32 -060067 fMaxInstancesPerDrawArraysWithoutCrashing = 0;
bsalomon083617b2016-02-12 12:10:14 -080068
Brian Salomon94efbf52016-11-29 13:43:05 -050069 fShaderCaps.reset(new GrShaderCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070070
cdalton4cd67132015-06-10 19:23:46 -070071 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072}
73
cdalton4cd67132015-06-10 19:23:46 -070074void GrGLCaps::init(const GrContextOptions& contextOptions,
75 const GrGLContextInfo& ctxInfo,
76 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000077 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000078 GrGLVersion version = ctxInfo.version();
79
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000080 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000081 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
82 &fMaxFragmentUniformVectors);
83 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000084 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000085 GrGLint max;
86 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
87 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000088 if (version >= GR_GL_VER(3, 2)) {
89 GrGLint profileMask;
90 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
91 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
92 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000093 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000094 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000096 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 fUnpackRowLengthSupport = true;
98 fUnpackFlipYSupport = false;
99 fPackRowLengthSupport = true;
100 fPackFlipYSupport = false;
101 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000102 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
103 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000105 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
106 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107 fPackFlipYSupport =
108 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
109 }
110
Adrienne Walkerc48f7762018-05-15 13:03:13 -0700111 if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
112 // In some cases drivers handle copying the last row incorrectly
113 // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
114 // through every row and conditionally clobbering that value, but
115 // Skia already has a scratch buffer workaround when pack row length
116 // is not supported, so just use that.
117 fPackRowLengthSupport = false;
118 }
119
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000120 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000121 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
122
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000123 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700124 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
125 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
126 ctxInfo.hasExtension("GL_NV_texture_barrier");
127 } else {
128 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
129 }
130
Robert Phillips7f861922018-01-30 13:13:42 +0000131 if (kGL_GrGLStandard == standard) {
132 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
133 ctxInfo.hasExtension("GL_ARB_texture_multisample");
134 } else {
135 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
136 }
137
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000138 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000139 ctxInfo.hasExtension("GL_ARB_imaging");
140
Brian Salomon01b476a2018-01-23 11:06:41 -0500141 if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
egdaniel9250d242015-05-18 13:04:26 -0700142 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
143 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000144 fDiscardRenderTargetSupport = true;
145 fInvalidateFBType = kInvalidate_InvalidateFBType;
146 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
147 fDiscardRenderTargetSupport = true;
148 fInvalidateFBType = kDiscard_InvalidateFBType;
149 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000150
Chris Dalton27059d32018-01-23 14:06:50 -0700151 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
152 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
153 if (kGLES_GrGLStandard == standard) {
154 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
155 // TODO: Evaluate on PowerVR.
156 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
157 if (kARM_GrGLVendor == ctxInfo.vendor()) {
158 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
159 }
160 }
161
Chris Dalton344e9032017-12-11 15:42:09 -0700162 if (kARM_GrGLVendor == ctxInfo.vendor() ||
163 kImagination_GrGLVendor == ctxInfo.vendor() ||
164 kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
165 fPreferFullscreenClears = true;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000166 }
167
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000168 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000169 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800170 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
171 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000172 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000173 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
174 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000175 }
176
cdalton626e1ff2015-06-12 13:56:46 -0700177 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
178 fDebugSupport = true;
179 } else {
180 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
181 }
182
jvanverth3f801cb2014-12-16 09:49:38 -0800183 if (kGL_GrGLStandard == standard) {
184 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
185 }
186 else {
187 fES2CompatibilitySupport = true;
188 }
189
cdalton0edea2c2015-05-21 08:27:44 -0700190 if (kGL_GrGLStandard == standard) {
191 fMultisampleDisableSupport = true;
192 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700193 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700194 }
195
kkinnunend94708e2015-07-30 22:47:04 -0700196 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600197 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
198 // instanced arrays, but we could make this more granular if we wanted
199 fInstanceAttribSupport =
200 version >= GR_GL_VER(3, 2) ||
201 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
202 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
203 } else {
204 fInstanceAttribSupport =
205 version >= GR_GL_VER(3, 0) ||
206 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
207 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
208 }
209
210 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700211 if (version >= GR_GL_VER(3, 0)) {
212 fBindFragDataLocationSupport = true;
213 }
214 } else {
215 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
216 fBindFragDataLocationSupport = true;
217 }
joshualittc1f56b52015-06-22 12:31:31 -0700218 }
219
joshualitt7bdd70a2015-10-01 06:28:11 -0700220 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
221
kkinnunene06ed252016-02-16 23:15:40 -0800222 if (kGL_GrGLStandard == standard) {
Weiliang Chen1e04b362018-07-12 17:13:35 -0400223 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
224 ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
kkinnunene06ed252016-02-16 23:15:40 -0800225 // We also require textureSize() support for rectangle 2D samplers which was added in
226 // GLSL 1.40.
227 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
228 fRectangleTextureSupport = true;
229 }
bsalomone179a912016-01-20 06:18:10 -0800230 }
kkinnunene06ed252016-02-16 23:15:40 -0800231 } else {
232 // Command buffer exposes this in GL ES context for Chromium reasons,
233 // but it should not be used. Also, at the time of writing command buffer
234 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800235 }
236
bsalomoncdee0092016-01-08 13:20:12 -0800237 if (kGL_GrGLStandard == standard) {
238 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
239 fTextureSwizzleSupport = true;
240 }
241 } else {
242 if (version >= GR_GL_VER(3,0)) {
243 fTextureSwizzleSupport = true;
244 }
245 }
246
cblume09bd2c02016-03-01 14:08:28 -0800247 if (kGL_GrGLStandard == standard) {
248 fMipMapLevelAndLodControlSupport = true;
249 } else if (kGLES_GrGLStandard == standard) {
250 if (version >= GR_GL_VER(3,0)) {
251 fMipMapLevelAndLodControlSupport = true;
252 }
253 }
254
bsalomon88c7b982015-07-31 11:20:16 -0700255#ifdef SK_BUILD_FOR_WIN
256 // We're assuming that on Windows Chromium we're using ANGLE.
257 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
258 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700259 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700260 fRGBA8888PixelsOpsAreSlow = isANGLE;
261 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
262 // check DX11 ANGLE.
263 fPartialFBOReadIsSlow = isANGLE;
264#endif
265
ericrkb4ecabd2016-03-11 15:18:20 -0800266 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
267 bool isMAC = false;
268#ifdef SK_BUILD_FOR_MAC
269 isMAC = true;
270#endif
271
272 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
273 // vis-versa.
274 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
275
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500276 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
277 fUseBufferDataNullHint = false;
278 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
279 fUseBufferDataNullHint = true;
280 }
281
Brian Salomond17b4a62017-05-23 16:53:47 -0400282 if (kGL_GrGLStandard == standard) {
283 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400284 fClearTextureSupport = true;
285 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500286 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
287 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400288 }
289
cdalton4cd67132015-06-10 19:23:46 -0700290 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700291 * GrShaderCaps fields
292 **************************************************************************/
293
egdaniel0a482332015-10-26 08:59:10 -0700294 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700295 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500296 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700297
Brian Osman195c05b2017-08-30 15:14:04 -0400298 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
299#if GR_TEST_UTILS
300 if (contextOptions.fSuppressPathRendering) {
301 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700302 }
Brian Osman195c05b2017-08-30 15:14:04 -0400303#endif
egdaniel05ded892015-10-26 07:38:05 -0700304
egdaniel05ded892015-10-26 07:38:05 -0700305 // Enable supported shader-related caps
306 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500307 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700308 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
Brian Salomon23c55b62018-06-19 16:28:41 -0400309 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600310
Brian Salomon1edc5b92016-11-29 13:43:46 -0500311 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600312
egdaniel05ded892015-10-26 07:38:05 -0700313 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500314 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700315 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600316 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600317 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
318 shaderCaps->fGSInvocationsSupport = true;
319 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
320 shaderCaps->fGSInvocationsSupport = true;
321 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
322 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600323 }
324
Brian Salomon1edc5b92016-11-29 13:43:46 -0500325 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800326 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500327 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500328 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700329
Brian Salomon1edc5b92016-11-29 13:43:46 -0500330 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700331 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800332
Chris Dalton1214be92018-06-28 19:06:27 -0600333 // Mali and early Adreno both have support for geometry shaders, but they appear to be
334 // implemented in software. In practice with ccpr, they are slower than the backup impl that
335 // only uses vertex shaders.
336 if (kARM_GrGLVendor != ctxInfo.vendor() &&
337 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
338 kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
339
Chris Daltonfaca00d2018-01-19 15:56:07 -0700340 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
341 shaderCaps->fGeometryShaderSupport = true;
342 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
343 shaderCaps->fGeometryShaderSupport = true;
344 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
345 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700346 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500347 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700348
Brian Salomon1edc5b92016-11-29 13:43:46 -0500349 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800350 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700351 }
352
cdalton9c3f1432016-03-11 10:07:37 -0800353 // Protect ourselves against tracking huge amounts of texture state.
354 static const uint8_t kMaxSaneSamplers = 32;
355 GrGLint maxSamplers;
356 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500357 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
358 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800359 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500360 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800361 }
362 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500363 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800364 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500365 shaderCaps->fMaxCombinedSamplers = 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 Salomond1b8a162018-08-08 13:22:05 -0400571 fDynamicStateArrayGeometryProcessorTextureSupport = true;
572
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400573 if (kGL_GrGLStandard == standard) {
574 if (version >= GR_GL_VER(4, 1)) {
575 fProgramBinarySupport = true;
576 }
577 } else if (version >= GR_GL_VER(3, 0)) {
578 fProgramBinarySupport = true;
579 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400580 if (fProgramBinarySupport) {
581 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400582 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400583 fProgramBinarySupport = count > 0;
584 }
bsalomoncdee0092016-01-08 13:20:12 -0800585 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
586 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800587 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700588
Brian Salomon01b476a2018-01-23 11:06:41 -0500589 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
590 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
591 }
592
cdalton4cd67132015-06-10 19:23:46 -0700593 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500594 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700595
Brian Salomon01b476a2018-01-23 11:06:41 -0500596 // For now these two are equivalent but we could have dst read in shader via some other method.
597 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000598}
599
egdaniel472d44e2015-10-22 08:20:00 -0700600const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
601 bool isCoreProfile) {
602 switch (generation) {
603 case k110_GrGLSLGeneration:
604 if (kGLES_GrGLStandard == standard) {
605 // ES2s shader language is based on version 1.20 but is version
606 // 1.00 of the ES language.
607 return "#version 100\n";
608 } else {
609 SkASSERT(kGL_GrGLStandard == standard);
610 return "#version 110\n";
611 }
612 case k130_GrGLSLGeneration:
613 SkASSERT(kGL_GrGLStandard == standard);
614 return "#version 130\n";
615 case k140_GrGLSLGeneration:
616 SkASSERT(kGL_GrGLStandard == standard);
617 return "#version 140\n";
618 case k150_GrGLSLGeneration:
619 SkASSERT(kGL_GrGLStandard == standard);
620 if (isCoreProfile) {
621 return "#version 150\n";
622 } else {
623 return "#version 150 compatibility\n";
624 }
625 case k330_GrGLSLGeneration:
626 if (kGLES_GrGLStandard == standard) {
627 return "#version 300 es\n";
628 } else {
629 SkASSERT(kGL_GrGLStandard == standard);
630 if (isCoreProfile) {
631 return "#version 330\n";
632 } else {
633 return "#version 330 compatibility\n";
634 }
635 }
cdalton33ad7012016-02-22 07:55:44 -0800636 case k400_GrGLSLGeneration:
637 SkASSERT(kGL_GrGLStandard == standard);
638 if (isCoreProfile) {
639 return "#version 400\n";
640 } else {
641 return "#version 400 compatibility\n";
642 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500643 case k420_GrGLSLGeneration:
644 SkASSERT(kGL_GrGLStandard == standard);
645 if (isCoreProfile) {
646 return "#version 420\n";
647 }
648 else {
649 return "#version 420 compatibility\n";
650 }
egdaniel472d44e2015-10-22 08:20:00 -0700651 case k310es_GrGLSLGeneration:
652 SkASSERT(kGLES_GrGLStandard == standard);
653 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800654 case k320es_GrGLSLGeneration:
655 SkASSERT(kGLES_GrGLStandard == standard);
656 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700657 }
658 return "<no version>";
659}
660
Chris Dalton47c8ed32017-11-15 18:27:09 -0700661bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
662 if (kGLES_GrGLStandard != ctxInfo.standard() &&
663 ctxInfo.version() < GR_GL_VER(4,1) &&
664 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
665 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
666 return true;
667 }
668 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
669 // geometry shaders don't have lower precision than vertex and fragment.
670 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
671 GrGLint range[2];
672 GrGLint bits;
673 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
674 if (range[0] < 127 || range[1] < 127 || bits < 23) {
675 return false;
676 }
677 }
678 return true;
679}
680
681void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700682 GrGLStandard standard = ctxInfo.standard();
683 GrGLVersion version = ctxInfo.version();
684
685 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500686 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700687 **************************************************************************/
688
Brian Salomon1edc5b92016-11-29 13:43:46 -0500689 GrShaderCaps* shaderCaps = fShaderCaps.get();
690 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700691 if (kGLES_GrGLStandard == standard) {
692 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500693 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
694 shaderCaps->fFBFetchSupport = true;
695 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
696 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700697 }
698 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
699 // 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 -0500700 shaderCaps->fFBFetchNeedsCustomOutput = false;
701 shaderCaps->fFBFetchSupport = true;
702 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
703 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700704 }
705 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
706 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500707 shaderCaps->fFBFetchNeedsCustomOutput = false;
708 shaderCaps->fFBFetchSupport = true;
709 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
710 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700711 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500712 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700713 }
714
cdaltonc08f1962016-02-12 12:14:06 -0800715 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500716 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800717 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500718 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800719 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
720 }
Brian Salomon41274562017-09-15 09:40:03 -0700721 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
722 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
723 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800724 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500725 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800726 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
727 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400728 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
729 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500730 shaderCaps->fNoPerspectiveInterpolationSupport = true;
731 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800732 "GL_NV_shader_noperspective_interpolation";
733 }
734 }
735
Brian Salomon1edc5b92016-11-29 13:43:46 -0500736 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
737 shaderCaps->fGLSLGeneration,
738 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800739
Brian Salomon1edc5b92016-11-29 13:43:46 -0500740 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
741 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800742 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800743
744 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500745 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800746 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
747 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500748 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800749 }
750
751 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500752 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800753 }
754
cdalton9c3f1432016-03-11 10:07:37 -0800755 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400756 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
757 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400758 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400759 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
760 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
761 // At least one driver has been found that has this extension without the "GL_" prefix.
762 shaderCaps->fExternalTextureSupport = true;
763 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800764 }
765 }
766
cdaltonc04ce672016-03-11 14:07:38 -0800767 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600768 shaderCaps->fVertexIDSupport = true;
769 } else {
770 // Desktop GLSL 3.30 == ES GLSL 3.00.
771 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
772 }
773
Chris Dalton7c7ff032018-03-28 20:09:58 -0600774 if (kGL_GrGLStandard == standard) {
775 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
776 } else {
777 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
778 }
779
Chris Dalton47c8ed32017-11-15 18:27:09 -0700780 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
781 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400782
783 // Unsigned integers only supported in and after GLSL 1.30.
784 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700785}
786
kkinnunencfe62e32015-07-01 02:58:50 -0700787bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700788 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
789
790 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700791 return false;
792 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700793
kkinnunencfe62e32015-07-01 02:58:50 -0700794 if (kGL_GrGLStandard == ctxInfo.standard()) {
795 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
796 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
797 return false;
798 }
799 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700800 if (!hasChromiumPathRendering &&
801 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700802 return false;
803 }
804 }
805 // We only support v1.3+ of GL_NV_path_rendering which allows us to
806 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
807 // additions are detected by checking the existence of the function.
808 // We also use *Then* functions that not all drivers might have. Check
809 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800810 if (!gli->fFunctions.fStencilThenCoverFillPath ||
811 !gli->fFunctions.fStencilThenCoverStrokePath ||
812 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
813 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
814 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700815 return false;
816 }
817 return true;
818}
bsalomon1aa20292016-01-22 08:16:09 -0800819
Brian Salomon71d9d842016-11-03 13:42:00 -0400820bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800821 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800822 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800823 std::function<bool ()> bindRenderTarget,
824 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400825 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800826 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400827 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800828 return false;
829 }
bsalomon7928ef62016-01-05 10:26:39 -0800830
bsalomon76148af2016-01-12 11:13:47 -0800831 GrGLenum readFormat;
832 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400833 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800834 return false;
835 }
836
bsalomon1aa20292016-01-22 08:16:09 -0800837 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800838 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
839 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
840 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
841 // 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 -0500842 // The manual does not seem to fully match the spec as the spec allows integer formats
843 // when the bound color buffer is an integer buffer. It doesn't specify which integer
844 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500845 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
846 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
847 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800848 return false;
849 }
850 // There is also a set of allowed types, but all the types we use are in the set:
851 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
852 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
853 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
854 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
855 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
856 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
857 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800858 return true;
piotaixre4b23142014-10-02 10:57:53 -0700859 }
bsalomon7928ef62016-01-05 10:26:39 -0800860
bsalomon76148af2016-01-12 11:13:47 -0800861 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500862 switch (fConfigTable[surfaceConfig].fFormatType) {
863 case kNormalizedFixedPoint_FormatType:
864 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
865 return true;
866 }
867 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500868 case kFloat_FormatType:
869 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
870 return true;
871 }
872 break;
bsalomon7928ef62016-01-05 10:26:39 -0800873 }
874
Brian Salomon71d9d842016-11-03 13:42:00 -0400875 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800876 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400877 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800878 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800879 if (!bindRenderTarget()) {
880 return false;
881 }
882 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
883 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800884 rpFormat->fFormat = format;
885 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800886 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800887 }
888
Brian Salomon71d9d842016-11-03 13:42:00 -0400889 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
890 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700891}
892
Eric Karl5c779752017-05-08 12:02:07 -0700893void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
894 const GrGLInterface* gli) {
895 // We need dual source blending and the ability to disable multisample in order to support mixed
896 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
897 // renderer is available and enabled; no other path renderers support this feature.
898 if (fMultisampleDisableSupport &&
899 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400900 this->shaderCaps()->pathRenderingSupport()
901#if GR_TEST_UTILS
902 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
903#endif
904 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700905 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400906 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700907 }
908
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000909 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400910 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
911 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
912 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
913 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
914 fAlpha8IsRenderable = true;
915 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500916 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
917 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
918 // mixed samples we can't use multisampled-render-to-texture.
919 if (fUsesMixedSamples) {
920 fMSFBOType = kMixedSamples_MSFBOType;
921 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000922 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
923 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
924 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400925 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
926 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400927 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400928 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400929 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400930 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000931 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
932 fMSFBOType = kES_Apple_MSFBOType;
933 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000934 } else {
egdanieleed519e2016-01-15 11:36:18 -0800935 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700936 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400937 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
938 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400939
Brian Salomon00731b42016-10-14 11:30:51 -0400940 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400941 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
942 // Core profile removes ALPHA8 support.
943 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
944 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
945 // present.
946 fAlpha8IsRenderable = true;
947 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000948 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
949 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400950 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000951 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000952 }
Eric Karl5c779752017-05-08 12:02:07 -0700953
Brian Salomon01b476a2018-01-23 11:06:41 -0500954 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400955 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
956 fMSFBOType = kNone_MSFBOType;
957 }
958
Eric Karl5c779752017-05-08 12:02:07 -0700959 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
960 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
961 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700962 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000963}
964
cdalton1dd05422015-06-12 09:01:18 -0700965void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500966 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700967
Greg Daniel210883c2017-11-27 15:14:01 -0500968 bool layoutQualifierSupport = false;
969 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
970 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
971 layoutQualifierSupport = true;
972 }
973
cdalton1dd05422015-06-12 09:01:18 -0700974 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
975 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500976 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500977 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
978 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700979 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500980 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700981 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
982 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500983 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500984 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700985 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500986 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700987 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
988 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -0700989 }
cdalton1dd05422015-06-12 09:01:18 -0700990}
991
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000992namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700993const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000994}
995
Eric Karl5c779752017-05-08 12:02:07 -0700996void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000997
998 // Build up list of legal stencil formats (though perhaps not supported on
999 // the particular gpu/driver) from most preferred to least.
1000
1001 // these consts are in order of most preferred to least preferred
1002 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1003
1004 static const StencilFormat
1005 // internal Format stencil bits total bits packed?
1006 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1007 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1008 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1009 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001010 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001011 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1012
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001013 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001014 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001015 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001016 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1017 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1018
1019 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1020 // require FBO support we can expect these are legal formats and don't
1021 // check. These also all support the unsized GL_STENCIL_INDEX.
1022 fStencilFormats.push_back() = gS8;
1023 fStencilFormats.push_back() = gS16;
1024 if (supportsPackedDS) {
1025 fStencilFormats.push_back() = gD24S8;
1026 }
1027 fStencilFormats.push_back() = gS4;
1028 if (supportsPackedDS) {
1029 fStencilFormats.push_back() = gDS;
1030 }
1031 } else {
1032 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1033 // for other formats.
1034 // ES doesn't support using the unsized format.
1035
1036 fStencilFormats.push_back() = gS8;
1037 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001038 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1039 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001040 fStencilFormats.push_back() = gD24S8;
1041 }
1042 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1043 fStencilFormats.push_back() = gS4;
1044 }
1045 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001046}
1047
Brian Osman71a18892017-08-10 10:23:25 -04001048void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001049
Brian Osman71a18892017-08-10 10:23:25 -04001050 // We are called by the base class, which has already called beginObject(). We choose to nest
1051 // all of our caps information in a named sub-object.
1052 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001053
Brian Osman71a18892017-08-10 10:23:25 -04001054 writer->beginArray("Stencil Formats");
1055
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001056 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001057 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001058 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1059 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1060 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001061 }
1062
Brian Osman71a18892017-08-10 10:23:25 -04001063 writer->endArray();
1064
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001065 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001066 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001067 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001068 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001069 "IMG MS To Texture",
1070 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001071 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001072 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001073 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001074 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1075 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1076 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1077 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1078 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001079 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001080
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001081 static const char* kInvalidateFBTypeStr[] = {
1082 "None",
1083 "Discard",
1084 "Invalidate",
1085 };
1086 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1087 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1088 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1089 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001090
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001091 static const char* kMapBufferTypeStr[] = {
1092 "None",
1093 "MapBuffer",
1094 "MapBufferRange",
1095 "Chromium",
1096 };
1097 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1098 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1099 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1100 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1101 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1102
Brian Osman71a18892017-08-10 10:23:25 -04001103 writer->appendBool("Core Profile", fIsCoreProfile);
1104 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1105 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1106 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1107 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1108 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1109 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1110 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1111 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001112
Brian Osman71a18892017-08-10 10:23:25 -04001113 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001114 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1115 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1116 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001117 writer->appendBool("Debug support", fDebugSupport);
1118 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1119 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1120 writer->appendBool("Base instance support", fBaseInstanceSupport);
1121 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1122 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1123 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1124 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1125 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1126 writer->appendBool("BGRA to RGBA readback conversions are slow",
1127 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001128 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001129 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1130 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001131 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1132 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1133 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1134 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001135 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1136 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001137
Brian Osman71a18892017-08-10 10:23:25 -04001138 writer->beginArray("configs");
1139
bsalomon41e4384e2016-01-08 09:12:44 -08001140 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001141 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001142 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1143 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1144 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001145 writer->appendHexU32("e_format_read_pixels",
1146 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001147 writer->appendHexU32(
1148 "e_format_teximage",
1149 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1150 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1151 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1152 writer->appendHexU32("i_for_renderbuffer",
1153 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1154 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001155 }
1156
Brian Osman71a18892017-08-10 10:23:25 -04001157 writer->endArray();
1158 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001159}
1160
bsalomon41e4384e2016-01-08 09:12:44 -08001161bool GrGLCaps::bgraIsInternalFormat() const {
1162 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1163}
1164
bsalomon76148af2016-01-12 11:13:47 -08001165bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1166 GrGLenum* internalFormat, GrGLenum* externalFormat,
1167 GrGLenum* externalType) const {
1168 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1169 externalFormat, externalType)) {
1170 return false;
1171 }
1172 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1173 return true;
1174}
1175
bsalomon76148af2016-01-12 11:13:47 -08001176bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1177 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001178 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001179 externalFormat, externalType)) {
1180 return false;
1181 }
1182 return true;
1183}
1184
1185bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001186 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1187 return true;
1188}
1189
1190bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1191 ExternalFormatUsage usage, GrGLenum* externalFormat,
1192 GrGLenum* externalType) const {
1193 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001194
1195 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1196 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1197
1198 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001199 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1200 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001201 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1202 return false;
1203 }
1204
1205 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1206 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1207
bsalomone9573312016-01-25 14:33:25 -08001208 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1209 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1210 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1211 // texture, not the red component.
1212 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001213 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001214 *externalFormat = GR_GL_ALPHA;
1215 }
1216 }
1217
bsalomon76148af2016-01-12 11:13:47 -08001218 return true;
1219}
1220
brianosman20471892016-12-02 06:43:32 -08001221void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1222 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001223 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001224 /*
1225 Comments on renderability of configs on various GL versions.
1226 OpenGL < 3.0:
1227 no built in support for render targets.
1228 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1229 format RGB, RGBA and NV float formats we don't use.
1230 This is the following:
1231 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1232 RGB10_A2, RGBA12,RGBA16
1233 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1234 since they aren't required by later standards and the driver can simply return
1235 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1236 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1237 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1238 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1239 This adds a lot of additional renderable sized formats, including ALPHA8.
1240 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1241 16F, 32I, 32UI, and 32F variants).
1242 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1243
1244 For both the above extensions we limit ourselves to those that are also required by
1245 OpenGL 3.0.
1246
1247 OpenGL 3.0:
1248 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1249 but are not required to be supported as renderable textures/renderbuffer.
1250 Required renderable color formats:
1251 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1252 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1253 RGB10_A2.
1254 - R11F_G11F_B10F.
1255 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1256 and RG8UI.
1257 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1258 - ALPHA8
1259
1260 OpenGL 3.1, 3.2, 3.3
1261 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1262 OpengGL 3.3, 4.0, 4.1
1263 Adds RGB10_A2UI.
1264 OpengGL 4.2
1265 Adds
1266 - RGB5_A1, RGBA4
1267 - RGB565
1268 OpenGL 4.4
1269 Does away with the separate list and adds a column to the sized internal color format
1270 table. However, no new formats become required color renderable.
1271
1272 ES 2.0
1273 color renderable: RGBA4, RGB5_A1, RGB565
1274 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1275 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1276 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1277 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1278 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1279 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1280
1281 ES 3.0
1282 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1283 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1284 RGB5_A1.
1285 - RGB8 and RGB565.
1286 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1287 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1288 ES 3.1
1289 Adds RGB10_A2, RGB10_A2UI,
1290 ES 3.2
1291 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1292 */
Brian Salomon44804c02018-01-23 16:51:28 -05001293
1294 // Correctness workarounds.
1295 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001296 bool disableSRGBForX86PowerVR = false;
1297 bool disableSRGBWriteControlForAdreno4xx = false;
1298 bool disableR8TexStorageForANGLEGL = false;
1299 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001300 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001301 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001302
1303 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1304 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1305 // and GL_RG on FBO textures.
1306 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1307
Greg Daniel09c94002018-06-08 22:11:51 +00001308 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1309
Brian Salomon44804c02018-01-23 16:51:28 -05001310 bool isX86PowerVR = false;
1311#if defined(SK_CPU_X86)
1312 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1313 isX86PowerVR = true;
1314 }
1315#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001316 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1317 // blacklist that device (and any others that might be sharing the same driver).
1318 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001319 disableSRGBWriteControlForAdreno4xx =
1320 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1321 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001322
1323 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1324 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1325 // check that we are not going to OpenGL.
1326 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1327
1328 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1329#if defined(SK_BUILD_FOR_MAC)
1330 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1331#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001332 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1333 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001334 }
1335
Brian Salomon71d9d842016-11-03 13:42:00 -04001336 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1337 ConfigInfo::kFBOColorAttachment_Flag;
1338 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001339 if (kNone_MSFBOType != fMSFBOType) {
1340 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1341 }
bsalomon41e4384e2016-01-08 09:12:44 -08001342 GrGLStandard standard = ctxInfo.standard();
1343 GrGLVersion version = ctxInfo.version();
1344
cblume790d5132016-02-29 11:13:29 -08001345 bool texStorageSupported = false;
1346 if (kGL_GrGLStandard == standard) {
1347 // The EXT version can apply to either GL or GLES.
1348 texStorageSupported = version >= GR_GL_VER(4,2) ||
1349 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1350 ctxInfo.hasExtension("GL_EXT_texture_storage");
1351 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001352 texStorageSupported = version >= GR_GL_VER(3,0) ||
1353 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001354 }
1355
Brian Salomone609e812018-01-17 14:00:47 -05001356 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001357
1358 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001359 if (kGL_GrGLStandard == standard) {
1360 textureRedSupport =
1361 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1362 } else {
1363 textureRedSupport =
1364 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1365 }
1366 }
1367
bsalomon30447372015-12-21 09:03:05 -08001368 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1369 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001370 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001371 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001372 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001373 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001374
1375 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1376 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001377 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001378 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001379 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001380 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001381 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1382 if (kGL_GrGLStandard == standard) {
1383 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1384 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001385 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001386 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1387 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1388 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1389 }
egdaniel4999df82016-01-07 17:06:04 -08001390 }
cblume790d5132016-02-29 11:13:29 -08001391 if (texStorageSupported) {
1392 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1393 }
bsalomoncdee0092016-01-08 13:20:12 -08001394 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001395
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001396 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1397 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1398 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1399 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1400 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1401 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1402 // supportedReadPixelsColorType never returns it.
1403 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1404 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1405 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1406 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1407 if (kGL_GrGLStandard == standard) {
1408 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1409 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1410 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1411 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1412 // becomes an issue.
1413 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1414 // but we don't support that just for simplicity's sake.
1415 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1416 } else {
1417 // 3.0 and the extension support this as a render buffer format.
1418 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1419 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1420 }
1421 }
1422 if (texStorageSupported) {
1423 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1424 }
1425 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1426 if (disableRGB8ForMali400) {
1427 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1428 }
1429
1430 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001431 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001432 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001433 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001434
1435 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1436 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1437 // GL_EXT_texture_format_BGRA8888.
1438 bool supportsBGRATexStorage = false;
1439
bsalomon41e4384e2016-01-08 09:12:44 -08001440 if (kGL_GrGLStandard == standard) {
1441 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1442 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1443 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1444 // Since the internal format is RGBA8, it is also renderable.
1445 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1446 allRenderFlags;
1447 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001448 // Since we are using RGBA8 we can use tex storage.
1449 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001450 } else {
1451 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1452 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001453 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1454 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1455 nonMSAARenderFlags;
1456
1457 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1458 supportsBGRATexStorage = true;
1459 }
1460 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1461 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1462 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1463 ConfigInfo::kRenderableWithMSAA_Flag;
1464 }
1465 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001466 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1467 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1468 // driver remembers the external format when the texture is created (with TexImage).
1469 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1470 // We could work around this, but it adds even more state tracking to code that is
1471 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1472 // This also side-steps some ambiguous interactions with the texture storage extension.
1473 if (version >= GR_GL_VER(3,0)) {
1474 // The APPLE extension doesn't make this renderable.
1475 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001476 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001477 }
bsalomon41e4384e2016-01-08 09:12:44 -08001478 }
1479 }
Brian Osman48c99192017-06-02 08:45:06 -04001480
Greg Daniel0ff79b22018-02-15 12:33:33 -05001481 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001482 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001483 }
bsalomoncdee0092016-01-08 13:20:12 -08001484 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001485
Brian Osman2b23c4b2018-06-01 12:25:08 -04001486 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001487 if (kGL_GrGLStandard == standard) {
1488 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001489 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001490 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1491 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1492 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001493 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001494 }
1495 }
1496 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001497 if (fSRGBSupport) {
1498 fSRGBWriteControl = true;
1499 }
bsalomon41e4384e2016-01-08 09:12:44 -08001500 } else {
brianosman20471892016-12-02 06:43:32 -08001501 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001502 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001503 fSRGBSupport = false;
1504 }
bsalomon41e4384e2016-01-08 09:12:44 -08001505 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1506 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001507 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001508 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001509 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001510 }
brianosman20471892016-12-02 06:43:32 -08001511
1512 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1513 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1514 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1515 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1516 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1517 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1518 // affects Windows.
1519 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1520 fSRGBSupport = false;
1521 }
1522
Brian Osman48c99192017-06-02 08:45:06 -04001523 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1524 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1525 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1526
Brian Osman67999392017-05-31 16:19:34 -04001527 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001528 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001529 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1530 }
Brian Osman67999392017-05-31 16:19:34 -04001531
bsalomon30447372015-12-21 09:03:05 -08001532 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1533 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1534 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1535 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001536 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001537 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001538 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001539 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001540 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001541 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001542 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001543 }
Brian Osman48c99192017-06-02 08:45:06 -04001544 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1545 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001546 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1547 }
bsalomoncdee0092016-01-08 13:20:12 -08001548 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001549 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1550 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1551 // is in this format, for example).
1552 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1553 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1554 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1555 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001556 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001557 GR_GL_BGRA;
1558 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1559 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001560 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001561 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001562 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001563 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001564
brianosmana6359362016-03-21 06:55:37 -07001565 if (texStorageSupported) {
1566 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1567 }
1568 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1569
bsalomon30447372015-12-21 09:03:05 -08001570 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1571 if (this->ES2CompatibilitySupport()) {
1572 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1573 } else {
1574 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1575 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001576 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001577 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001578 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001579 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001580 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1581 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001582 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001583 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1584 }
1585 } else {
1586 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1587 }
cblume790d5132016-02-29 11:13:29 -08001588 // 565 is not a sized internal format on desktop GL. So on desktop with
1589 // 565 we always use an unsized internal format to let the system pick
1590 // the best sized format to convert the 565 data to. Since TexStorage
1591 // only allows sized internal formats we disallow it.
1592 //
1593 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1594 // update.
1595 if (texStorageSupported && kGL_GrGLStandard != standard) {
1596 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1597 }
bsalomoncdee0092016-01-08 13:20:12 -08001598 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001599
1600 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1601 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001602 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001603 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001604 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001605 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001606 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1607 if (kGL_GrGLStandard == standard) {
1608 if (version >= GR_GL_VER(4, 2)) {
1609 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1610 }
1611 } else {
1612 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1613 }
cblume790d5132016-02-29 11:13:29 -08001614 if (texStorageSupported) {
1615 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1616 }
bsalomoncdee0092016-01-08 13:20:12 -08001617 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001618
Brian Osman10fc6fd2018-03-02 11:01:10 -05001619 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1620 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001621 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001622 GR_GL_RGBA;
1623 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1624 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1625 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1626 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1627 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1628 allRenderFlags;
1629 }
1630 if (texStorageSupported) {
1631 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1632 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001633 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1634
Greg Danielef59d872017-11-17 16:47:21 -05001635 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1636 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1637
1638 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1639 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1640 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1641 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1642 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001643 }
Greg Danielef59d872017-11-17 16:47:21 -05001644 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1645 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001646 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001647 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1648 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1649 alphaInfo.fFlags |= allRenderFlags;
1650 }
1651
1652 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1653 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1654 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1655 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1656 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001657 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001658 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001659
Brian Osman48c99192017-06-02 08:45:06 -04001660 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1661 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001662 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001663 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1664 }
1665 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1666 }
1667
Brian Salomone609e812018-01-17 14:00:47 -05001668 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001669 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001670 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1671 } else {
1672 redInfo.fFlags = 0;
1673
1674 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001675 }
bsalomon41e4384e2016-01-08 09:12:44 -08001676
Greg Daniel7af060a2017-12-05 16:27:11 -05001677 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1678 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1679 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1680 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1681 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001682 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001683 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1684 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1685 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1686 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001687 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001688
1689 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1690 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1691 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1692 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1693 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001694 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001695 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1696 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1697
Greg Daniel09c94002018-06-08 22:11:51 +00001698 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1699 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1700 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1701 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1702 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001703 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1704 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1705 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001706 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001707 }
Brian Osman48c99192017-06-02 08:45:06 -04001708 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001709 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001710 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1711 }
1712 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1713 }
1714
Brian Salomone609e812018-01-17 14:00:47 -05001715 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001716 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1717 } else {
1718 grayRedInfo.fFlags = 0;
1719 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001720 }
1721
bsalomon41e4384e2016-01-08 09:12:44 -08001722 // Check for [half] floating point texture support
1723 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1724 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1725 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
Chris Daltoneff01a72018-07-19 17:06:39 -06001726 bool hasFP32Textures = false;
1727 bool hasFP16Textures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001728 bool rgIsTexturable = false;
Chris Daltoneff01a72018-07-19 17:06:39 -06001729 bool hasFP32RenderTargets = false;
1730 bool hasFP16RenderTargets = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001731 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001732 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001733
1734 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001735 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001736 hasFP32Textures = true;
1737 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001738 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001739 hasFP32RenderTargets = true;
1740 hasFP16RenderTargets = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001741 }
1742 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001743 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001744 hasFP32Textures = true;
1745 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001746 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001747 } else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1748 ctxInfo.hasExtension("GL_OES_texture_float")) {
1749 hasFP32Textures = true;
1750 hasFP16Textures = true;
1751 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1752 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1753 hasFP16Textures = true;
1754 }
1755
1756 if (version >= GR_GL_VER(3, 2)) {
1757 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to solve
1758 // many precision issues and no clients actually want this yet.
1759 // hasFP32RenderTargets = true;
1760 hasFP16RenderTargets = true;
1761 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
1762 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to
1763 // solve many precision issues and no clients actually want this yet.
1764 // hasFP32RenderTargets = true;
1765 hasFP16RenderTargets = true;
1766 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1767 hasFP16RenderTargets = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001768 }
1769 }
bsalomon30447372015-12-21 09:03:05 -08001770
csmartdalton6aa0e112017-02-08 16:14:11 -05001771 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1772 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1773 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1774 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1775 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001776 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001777 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1778 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001779 if (hasFP32Textures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001780 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
Chris Daltoneff01a72018-07-19 17:06:39 -06001781 if (hasFP32RenderTargets) {
csmartdalton6aa0e112017-02-08 16:14:11 -05001782 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1783 }
bsalomon41e4384e2016-01-08 09:12:44 -08001784 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001785 if (texStorageSupported) {
1786 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1787 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001788 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001789 }
bsalomon30447372015-12-21 09:03:05 -08001790
Greg Danielef59d872017-11-17 16:47:21 -05001791 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001792 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001793 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001794 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001795 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001796 }
Greg Danielef59d872017-11-17 16:47:21 -05001797 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1798 redHalf.fFormats.fExternalType = redHalfExternalType;
1799 redHalf.fFormatType = kFloat_FormatType;
1800 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1801 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001802 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001803 redHalf.fSwizzle = GrSwizzle::RRRR();
Chris Daltoneff01a72018-07-19 17:06:39 -06001804 if (textureRedSupport && hasFP16Textures) {
Greg Danielef59d872017-11-17 16:47:21 -05001805 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1806
Chris Daltoneff01a72018-07-19 17:06:39 -06001807 if (hasFP16RenderTargets) {
Greg Danielef59d872017-11-17 16:47:21 -05001808 redHalf.fFlags |= fpRenderFlags;
1809 }
1810
1811 if (texStorageSupported && !isCommandBufferES2) {
1812 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1813 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001814 }
Greg Danielef59d872017-11-17 16:47:21 -05001815 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001816
1817 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1818 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001819 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001820 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001821 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001822 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1823 } else {
1824 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1825 }
bsalomon7928ef62016-01-05 10:26:39 -08001826 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001827 if (hasFP16Textures) {
bsalomon41e4384e2016-01-08 09:12:44 -08001828 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1829 // ES requires 3.2 or EXT_color_buffer_half_float.
Chris Daltoneff01a72018-07-19 17:06:39 -06001830 if (hasFP16RenderTargets) {
bsalomon41e4384e2016-01-08 09:12:44 -08001831 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1832 }
1833 }
cblume790d5132016-02-29 11:13:29 -08001834 if (texStorageSupported) {
1835 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1836 }
bsalomoncdee0092016-01-08 13:20:12 -08001837 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001838
bsalomon30447372015-12-21 09:03:05 -08001839 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1840
1841 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001842 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1843 ctxInfo.version() >= GR_GL_VER(3,0));
1844 // All ES versions (thus far) require sized internal formats for render buffers.
1845 // TODO: Always use sized internal format?
1846 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1847
bsalomon30447372015-12-21 09:03:05 -08001848 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001849 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1850 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001851 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001852 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001853 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1854 fConfigTable[i].fFormats.fSizedInternalFormat :
1855 fConfigTable[i].fFormats.fBaseInternalFormat;
1856 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001857 fConfigTable[i].fFormats.fSizedInternalFormat :
1858 fConfigTable[i].fFormats.fBaseInternalFormat;
1859 }
Brian Salomon44804c02018-01-23 16:51:28 -05001860 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1861 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1862 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1863 // in ES.
1864 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1865 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1866 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1867 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001868 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1869 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001870 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1871 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001872 }
1873
bsalomon30447372015-12-21 09:03:05 -08001874 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1875 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1876 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1877 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1878 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001879 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001880 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001881
1882 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1883 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1884 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1885 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001886 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001887 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1888 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1889 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1890 // slot.
1891 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1892 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001893
1894 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1895 // as a base format.
1896 // GL_EXT_texture_format_BGRA8888:
1897 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1898 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1899 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001900 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001901 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1902 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1903 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001904 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001905 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1906 }
1907
bsalomoncdee0092016-01-08 13:20:12 -08001908 // If we don't have texture swizzle support then the shader generator must insert the
1909 // swizzle into shader code.
1910 if (!this->textureSwizzleSupport()) {
1911 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001912 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001913 }
1914 }
1915
bsalomon7f9b2e42016-01-12 13:29:26 -08001916 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1917 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1918 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001919 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001920 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1921 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1922 if (GrPixelConfigIsAlphaOnly(config) &&
1923 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001924 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001925 }
1926 }
1927 }
1928
Greg Daniel81e7bf82017-07-19 14:47:42 -04001929 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1930 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001931 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1932 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001933 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001934 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1935 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001936 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001937 int count;
1938 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1939 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1940 1, &count);
1941 if (count) {
1942 int* temp = new int[count];
1943 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1944 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001945 // GL has a concept of MSAA rasterization with a single sample but we do not.
1946 if (count && temp[count - 1] == 1) {
1947 --count;
1948 SkASSERT(!count || temp[count -1] > 1);
1949 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001950 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001951 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001952 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001953 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001954 for (int j = 0; j < count; ++j) {
1955 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1956 }
1957 delete[] temp;
1958 }
1959 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001960 // Fake out the table using some semi-standard counts up to the max allowed sample
1961 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001962 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001963 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1964 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1965 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1966 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1967 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001968 // Chrome has a mock GL implementation that returns 0.
1969 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05001970
Brian Salomonbdecacf2018-02-02 20:32:49 -05001971 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04001972 int count = SK_ARRAY_COUNT(kDefaultSamples);
1973 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001974 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001975 break;
1976 }
1977 }
1978 if (count > 0) {
1979 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
1980 }
1981 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001982 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
1983 fConfigTable[i].fColorSampleCounts.setCount(1);
1984 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001985 }
1986 }
1987
bsalomon30447372015-12-21 09:03:05 -08001988#ifdef SK_DEBUG
1989 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001990 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001991 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04001992 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
1993 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04001994 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
1995 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
1996 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
1997 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08001998 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1999 fConfigTable[i].fFormats.fBaseInternalFormat);
2000 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002001 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002002 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2003 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2004 fConfigTable[i].fFormats.fExternalFormat[j]);
2005 }
2006 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002007 }
2008#endif
2009}
2010
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002011bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2012 bool dstIsTextureable, bool dstIsGLTexture2D,
2013 GrSurfaceOrigin dstOrigin,
2014 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2015 bool srcIsTextureable, bool srcIsGLTexture2D,
2016 GrSurfaceOrigin srcOrigin) const {
2017 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2018 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2019 // many drivers would allow it to work, but ANGLE does not.
2020 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2021 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2022 return false;
2023 }
2024
2025 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2026 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2027 return false;
2028 }
2029
2030 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2031 // texture.
2032 if (!dstIsTextureable) {
2033 return false;
2034 }
2035
2036 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2037 // is required
2038 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2039 (!srcIsTextureable || srcIsGLTexture2D) &&
2040 dstIsGLTexture2D &&
2041 dstOrigin == srcOrigin) {
2042 return true;
2043 } else {
2044 return false;
2045 }
2046}
2047
2048bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2049 bool dstIsTextureable, bool dstIsGLTexture2D,
2050 GrSurfaceOrigin dstOrigin,
2051 GrPixelConfig srcConfig, int srcSampleCnt,
2052 bool srcIsTextureable, bool srcIsGLTexture2D,
2053 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2054 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2055 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2056 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2057 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2058 return false;
2059 }
2060
2061 if (dstIsTextureable && !dstIsGLTexture2D) {
2062 return false;
2063 }
2064 if (srcIsTextureable && !srcIsGLTexture2D) {
2065 return false;
2066 }
2067
2068 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2069 return false;
2070 }
2071 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2072 // We would mirror to compensate for origin changes. Note that copySurface is
2073 // specified such that the src and dst rects are the same.
2074 if (dstOrigin != srcOrigin) {
2075 return false;
2076 }
2077 }
2078
2079 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2080 if (srcSampleCnt > 1) {
2081 if (1 == dstSampleCnt) {
2082 return false;
2083 }
2084 if (SkRect::Make(srcRect) != srcBounds) {
2085 return false;
2086 }
2087 }
2088 }
2089
2090 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2091 if (dstSampleCnt > 1) {
2092 return false;
2093 }
2094 }
2095
2096 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2097 if (dstConfig != srcConfig) {
2098 return false;
2099 }
2100 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2101 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2102 return false;
2103 }
2104 }
2105
2106 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2107 if (srcSampleCnt > 1) {
2108 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2109 return false;
2110 }
2111 if (dstOrigin != srcOrigin) {
2112 return false;
2113 }
2114 }
2115 }
2116 return true;
2117}
2118
2119bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2120 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2121}
2122
2123static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2124 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2125 if (!rt) {
2126 return false;
2127 }
2128 // A RT has a separate MSAA renderbuffer if:
2129 // 1) It's multisampled
2130 // 2) We're using an extension with separate MSAA renderbuffers
2131 // 3) It's not FBO 0, which is special and always auto-resolves
2132 return rt->numColorSamples() > 1 &&
2133 glCaps.usesMSAARenderBuffers() &&
2134 !rt->rtPriv().glRTFBOIDIs0();
2135}
2136
2137bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2138 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2139 GrSurfaceOrigin dstOrigin = dst->origin();
2140 GrSurfaceOrigin srcOrigin = src->origin();
2141
2142 GrPixelConfig dstConfig = dst->config();
2143 GrPixelConfig srcConfig = src->config();
2144
2145 int dstSampleCnt = 0;
2146 int srcSampleCnt = 0;
2147 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2148 dstSampleCnt = rtProxy->numColorSamples();
2149 }
2150 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2151 srcSampleCnt = rtProxy->numColorSamples();
2152 }
2153 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2154 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2155
2156 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2157 // swizzle.
2158 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2159 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2160 return false;
2161 }
2162
2163 const GrTextureProxy* dstTex = dst->asTextureProxy();
2164 const GrTextureProxy* srcTex = src->asTextureProxy();
2165
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002166 bool dstIsTex2D = dstTex ? (dstTex->textureType() == GrTextureType::k2D) : false;
2167 bool srcIsTex2D = srcTex ? (srcTex->textureType() == GrTextureType::k2D) : false;
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002168
2169 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2170 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2171 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2172 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2173 // know we will at least be able to do it as a draw.
2174#ifdef SK_DEBUG
2175 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2176 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2177 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2178 !src->priv().isExact()) {
2179 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2180 }
2181#endif
2182
2183 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2184 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2185 srcConfig, has_msaa_render_buffer(src, *this),
2186 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2187 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2188 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2189 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2190 dstPoint) ||
2191 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2192}
2193
Robert Phillipsbf25d432017-04-07 10:08:53 -04002194bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002195 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2196 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002197 // By default, we don't require rects to match.
2198 *rectsMustMatch = false;
2199
2200 // By default, we allow subrects.
2201 *disallowSubrect = false;
2202
Brian Salomon467921e2017-03-06 16:17:12 -05002203 // If the src is a texture, we can implement the blit as a draw assuming the config is
2204 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002205 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002206 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002207 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2208 desc->fConfig = src->config();
2209 return true;
2210 }
2211
Robert Phillipsbf25d432017-04-07 10:08:53 -04002212 {
2213 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2214 // wrapped. In that case the proxy would already be instantiated.
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002215 const GrTexture* srcTexture = src->peekTexture();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002216 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2217 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2218 // Not supported for FBO blit or CopyTexSubImage
2219 return false;
2220 }
Brian Salomon467921e2017-03-06 16:17:12 -05002221 }
2222
2223 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2224 // possible and we return false to fallback to creating a render target dst for render-to-
2225 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2226 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002227 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002228 bool rectsMustMatchForBlitFramebuffer = false;
2229 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002230 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002231 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2232 rectsMustMatchForBlitFramebuffer = true;
2233 disallowSubrectForBlitFramebuffer = true;
2234 // Mirroring causes rects to mismatch later, don't allow it.
2235 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002236 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2237 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002238 rectsMustMatchForBlitFramebuffer = true;
2239 // Mirroring causes rects to mismatch later, don't allow it.
2240 originForBlitFramebuffer = src->origin();
2241 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002242 originForBlitFramebuffer = src->origin();
2243 }
2244
2245 // Check for format issues with glCopyTexSubImage2D
2246 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2247 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2248 // then we set up for that, otherwise fail.
2249 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002250 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002251 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002252 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2253 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002254 return true;
2255 }
2256 return false;
2257 }
2258
Robert Phillipsbf25d432017-04-07 10:08:53 -04002259 {
Brian Salomon63e79732017-05-15 21:23:13 -04002260 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2261 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002262 if (srcIsMSAARenderbuffer) {
2263 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2264 // blit or fail.
2265 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002266 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002267 desc->fConfig = src->config();
2268 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2269 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2270 return true;
2271 }
2272 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002273 }
Brian Salomon467921e2017-03-06 16:17:12 -05002274 }
2275
2276 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002277 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002278 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002279 desc->fFlags = kNone_GrSurfaceFlags;
2280 return true;
2281}
2282
Greg Daniel691f5e72018-02-28 14:21:34 -05002283void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2284 const GrContextOptions& contextOptions,
2285 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002286 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2287 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002288 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2289 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002290 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002291 fDiscardRenderTargetSupport = false;
2292 fInvalidateFBType = kNone_InvalidateFBType;
2293 }
2294
2295 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2296 // 340.96 and 367.57.
2297 if (kGL_GrGLStandard == ctxInfo.standard() &&
2298 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002299 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002300 fClearTextureSupport = false;
2301 }
2302
2303 // Calling glClearTexImage crashes on the NexusPlayer.
2304 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2305 fClearTextureSupport = false;
2306 }
2307
2308 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2309#ifdef SK_BUILD_FOR_MAC
2310 if (shaderCaps->fGeometryShaderSupport) {
2311 shaderCaps->fGSInvocationsSupport = false;
2312 }
2313#endif
2314
2315 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2316 // shaders. @127.0 is the earliest verified driver to not crash.
2317 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002318 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002319 shaderCaps->fGeometryShaderSupport = false;
2320 }
2321
2322#if defined(__has_feature)
2323#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2324 // See skbug.com/7058
2325 fMapBufferType = kNone_MapBufferType;
2326 fMapBufferFlags = kNone_MapFlags;
2327#endif
2328#endif
2329
2330 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2331 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2332 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2333 // unclear whether this really affects a wide range of devices.
2334 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002335 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002336 fMapBufferType = kNone_MapBufferType;
2337 fMapBufferFlags = kNone_MapFlags;
2338 }
2339
2340 // TODO: re-enable for ANGLE
2341 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2342 fTransferBufferType = kNone_TransferBufferType;
2343 }
2344
2345 // Using MIPs on this GPU seems to be a source of trouble.
2346 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2347 fMipMapSupport = false;
2348 }
2349
2350 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2351 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2352 // around a driver bug related to gl_FragCoord.
2353 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2354 fMaxClipAnalyticFPs = 0;
2355 }
2356
2357#ifndef SK_BUILD_FOR_IOS
2358 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2359 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2360 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2361 ctxInfo.driver() != kChromium_GrGLDriver)) {
2362 fUseDrawToClearColor = true;
2363 }
2364#endif
2365
2366 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2367 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2368 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2369 fUseDrawToClearColor = true;
2370 }
2371
2372#ifdef SK_BUILD_FOR_MAC
2373 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2374 // full screen clears
2375 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2376 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002377 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2378 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2379 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2380 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002381 fUseDrawToClearColor = true;
2382 }
2383#endif
2384
2385 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2386 // bugs seems to involve clearing too much and not skipping the clear.
2387 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2388 // but only for D3D11 ANGLE.
2389 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2390 fUseDrawToClearColor = true;
2391 }
2392
Chris Dalton1214be92018-06-28 19:06:27 -06002393 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2394 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002395 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002396 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002397 fUseDrawToClearStencilClip = true;
2398 }
2399 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2400 }
2401
Adrienne Walker94f585e2018-05-15 11:47:07 -07002402 if (fDriverBugWorkarounds.gl_clear_broken) {
2403 fUseDrawToClearColor = true;
2404 fUseDrawToClearStencilClip = true;
2405 }
2406
Brian Salomon01b476a2018-01-23 11:06:41 -05002407 // This was reproduced on the following configurations:
2408 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2409 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2410 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2411 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2412 // and not produced on:
2413 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2414 // The particular lines that get dropped from test images varies across different devices.
2415 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002416 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002417 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2418 }
2419
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002420 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2421 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2422 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002423 fRequiresFlushBetweenNonAndInstancedDraws = true;
2424 }
2425
Brian Salomon01b476a2018-01-23 11:06:41 -05002426 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2427 // given 1 << 15 or more instances.
2428 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2429 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
Adrienne Walker001cae02018-05-15 11:38:44 -07002430 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
2431 fMaxInstancesPerDrawArraysWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002432 }
2433
2434 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002435 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002436 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2437 fUseDrawInsteadOfAllRenderTargetWrites = true;
2438 }
2439
2440 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2441 fSampleShadingSupport = false;
2442 }
2443
2444#ifdef SK_BUILD_FOR_MAC
2445 static constexpr bool isMAC = true;
2446#else
2447 static constexpr bool isMAC = false;
2448#endif
2449
2450 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2451 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2452 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2453 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2454 if (fMipMapLevelAndLodControlSupport &&
2455 (contextOptions.fDoManualMipmapping ||
2456 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2457 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2458 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2459 fDoManualMipmapping = true;
2460 }
2461
2462 // See http://crbug.com/710443
2463#ifdef SK_BUILD_FOR_MAC
2464 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2465 fClearToBoundaryValuesIsBroken = true;
2466 }
2467#endif
2468 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2469 fDrawArraysBaseVertexIsBroken = true;
2470 }
2471
Brian Salomon01b476a2018-01-23 11:06:41 -05002472 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2473 // Galaxy S7.
2474 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2475 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2476 shaderCaps->fFBFetchSupport = false;
2477 }
2478
Brian Salomon01b476a2018-01-23 11:06:41 -05002479 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2480 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2481
2482 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2483 // function that may require a gradient calculation inside a conditional block may return
2484 // undefined results". This appears to be an issue with the 'any' call since even the simple
2485 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2486 // from our GrTextureDomain processor.
2487 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2488
2489 // Known issue on at least some Intel platforms:
2490 // http://code.google.com/p/skia/issues/detail?id=946
2491 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2492 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2493 }
2494
Chris Dalton0090ef62018-03-28 17:35:00 -06002495 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002496 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2497 // so we must do the abs first in a separate expression.
2498 shaderCaps->fCanUseMinAndAbsTogether = false;
2499
2500 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2501 // must avoid this condition.
2502 shaderCaps->fCanUseFractForNegativeValues = false;
2503 }
2504
2505 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2506 // thus must us -1.0 * %s.x to work correctly
2507 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2508 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2509 }
2510
2511 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2512 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2513 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2514 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2515 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2516 }
2517
2518 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2519 // the original dst color when reading the outColor even after being written to. By using a
2520 // local outColor we can work around this bug.
2521 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2522 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2523 }
2524
2525 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2526 // color, and that uniform contains an opaque color, and the output of the shader is only based
2527 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2528 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2529 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2530 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2531 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2532 shaderCaps->fMustObfuscateUniformColor = true;
2533 }
2534#ifdef SK_BUILD_FOR_WIN
2535 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2536 //
2537 // Basically, if a shader has a construct like:
2538 //
2539 // float x = someCondition ? someValue : 0;
2540 // float2 result = (0 == x) ? float2(x, x)
2541 // : float2(2 * x / x, 0);
2542 //
2543 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2544 // we've explicitly guarded the division with a check against zero. This manifests in much
2545 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2546 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2547 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2548 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2549 }
2550#endif
2551
2552 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002553 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002554 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2555 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002556 }
2557
Chris Dalton0090ef62018-03-28 17:35:00 -06002558 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2559 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2560 shaderCaps->fCanUseFragCoord = false;
2561 }
2562
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002563 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2564 // (Are they implemented with fp16?)
2565 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2566 shaderCaps->fIncompleteShortIntPrecision = true;
2567 }
2568
Brian Salomon01b476a2018-01-23 11:06:41 -05002569 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2570 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002571 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2572 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002573 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2574 kIntel_GrGLDriver == ctxInfo.driver() ||
2575 kChromium_GrGLDriver == ctxInfo.driver()) {
2576 fBlendEquationSupport = kBasic_BlendEquationSupport;
2577 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2578 }
2579
2580 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2581 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002582 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002583 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002584 fBlendEquationSupport = kBasic_BlendEquationSupport;
2585 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2586 }
2587
Adrienne Walker68314842018-05-14 14:02:53 -07002588 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2589 fBlendEquationSupport = kBasic_BlendEquationSupport;
2590 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2591 }
2592
Brian Salomon01b476a2018-01-23 11:06:41 -05002593 if (this->advancedBlendEquationSupport()) {
2594 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002595 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002596 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2597 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2598 (1 << kColorBurn_GrBlendEquation);
2599 }
2600 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2601 // Blacklist color-burn on ARM until the fix is released.
2602 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2603 }
2604 }
2605
2606 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2607 if (fMultisampleDisableSupport &&
2608 this->shaderCaps()->dualSourceBlendingSupport() &&
2609 this->shaderCaps()->pathRenderingSupport() &&
2610 fUsesMixedSamples &&
2611#if GR_TEST_UTILS
2612 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2613#endif
2614 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2615 kChromium_GrGLDriver == ctxInfo.driver())) {
2616 fDiscardRenderTargetSupport = false;
2617 fInvalidateFBType = kNone_InvalidateFBType;
2618 }
Brian Osmanc585e202018-04-04 14:08:27 -04002619
Brian Osman061020e2018-04-17 14:22:15 -04002620 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2621 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2622 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2623 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002624 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2625 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002626 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002627 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002628 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2629 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002630 }
Brian Osman2fa53742018-05-03 15:05:12 -04002631
2632#ifdef SK_BUILD_FOR_IOS
2633 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2634 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2635 // is to just blacklist the feature.
2636 // https://github.com/flutter/flutter/issues/16718
2637 // https://bugreport.apple.com/web/?problemID=39948888
2638 fUnpackRowLengthSupport = false;
2639#endif
Chris Daltona2b5b642018-06-24 13:08:57 -06002640
2641#ifdef SK_BUILD_FOR_MAC
2642 // Radeon MacBooks hit a crash in glReadPixels() when using CCPR.
2643 // http://skbug.com/8097
2644 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2645 fBlacklistCoverageCounting = true;
2646 }
2647#endif
Chris Daltonc4e72a42018-06-25 06:44:01 -06002648
2649 // "shapes_mixed_10000_32x33" bench crashes PowerVRGX6250 in Release mode with ccpr.
2650 // http://skbug.com/8098
2651 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2652 fBlacklistCoverageCounting = true;
2653 }
Chris Dalton1c1391c2018-07-20 12:21:14 -06002654
Chris Daltonb70beea2018-07-23 12:17:10 -06002655 // CCPR edge AA is busted on Mesa, Sandy Bridge/Bay Trail.
Chris Dalton1c1391c2018-07-20 12:21:14 -06002656 // http://skbug.com/8162
Chris Daltonb70beea2018-07-23 12:17:10 -06002657 if (kMesa_GrGLDriver == ctxInfo.driver() &&
2658 (kIntelSandyBridge_GrGLRenderer == ctxInfo.renderer() ||
2659 kIntelBayTrail_GrGLRenderer == ctxInfo.renderer())) {
Chris Dalton1c1391c2018-07-20 12:21:14 -06002660 fBlacklistCoverageCounting = true;
2661 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002662}
2663
csmartdaltone0d36292016-07-29 08:14:20 -07002664void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002665 if (options.fDisableDriverCorrectnessWorkarounds) {
2666 SkASSERT(!fDoManualMipmapping);
2667 SkASSERT(!fClearToBoundaryValuesIsBroken);
2668 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2669 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2670 SkASSERT(!fUseDrawToClearColor);
2671 SkASSERT(!fUseDrawToClearStencilClip);
2672 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2673 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2674 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002675 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Salomon01b476a2018-01-23 11:06:41 -05002676 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002677 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2678 fUseDrawToClearColor = false;
2679 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2680 fUseDrawToClearColor = true;
2681 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002682 if (options.fDoManualMipmapping) {
2683 fDoManualMipmapping = true;
2684 }
csmartdaltone0d36292016-07-29 08:14:20 -07002685}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002686
Brian Salomon3d86a192018-02-27 16:46:11 -05002687bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2688 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2689 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2690 if (tex->hasBaseLevelBeenBoundToFBO()) {
2691 return false;
2692 }
2693 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002694 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002695 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2696 return false;
2697 }
2698 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2699 return false;
2700 }
2701 return SkToBool(surface->asTexture());
2702 }
2703 return true;
2704}
2705
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002706bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2707 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2708 // We don't support reading pixels directly from EXTERNAL textures as it would require
2709 // binding the texture to a FBO.
2710 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2711 return false;
2712 }
2713 }
2714 return true;
2715}
2716
2717GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2718 GrColorType dstColorType) const {
2719 // For now, we mostly report the read back format that is required by the ES spec without
2720 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2721 // this as makes sense to increase performance and correctness.
2722 switch (fConfigTable[config].fFormatType) {
2723 case kNormalizedFixedPoint_FormatType:
2724 return GrColorType::kRGBA_8888;
2725 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002726 if ((kAlpha_half_GrPixelConfig == config ||
2727 kAlpha_half_as_Red_GrPixelConfig == config) &&
2728 GrColorType::kAlpha_F16 == dstColorType) {
2729 return GrColorType::kAlpha_F16;
2730 }
2731 // And similar for full float RG.
2732 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2733 return GrColorType::kRG_F32;
2734 }
2735 return GrColorType::kRGBA_F32;
2736 }
2737 return GrColorType::kUnknown;
2738}
2739
Greg Daniel2a303902018-02-20 10:25:54 -05002740bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002741 GrGLFramebufferInfo fbInfo;
2742 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002743 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002744 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002745}
2746
Brian Salomonbdecacf2018-02-02 20:32:49 -05002747int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2748 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002749 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002750 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002751 return 0;
2752 }
2753
Brian Salomonbdecacf2018-02-02 20:32:49 -05002754 if (1 == requestedCount) {
2755 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2756 }
2757
Greg Daniel81e7bf82017-07-19 14:47:42 -04002758 for (int i = 0; i < count; ++i) {
2759 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002760 int count = fConfigTable[config].fColorSampleCounts[i];
2761 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2762 count = SkTMin(count, 4);
2763 }
2764 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002765 }
2766 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002767 return 0;
2768}
2769
2770int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2771 const auto& table = fConfigTable[config].fColorSampleCounts;
2772 if (!table.count()) {
2773 return 0;
2774 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002775 int count = table[table.count() - 1];
2776 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2777 count = SkTMin(count, 4);
2778 }
2779 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002780}
2781
Greg Danielfaa095e2017-12-19 13:15:02 -05002782bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2783 GrGLStandard standard) {
2784 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002785
2786 switch (ct) {
2787 case kUnknown_SkColorType:
2788 return false;
2789 case kAlpha_8_SkColorType:
2790 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002791 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002792 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002793 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002794 }
2795 break;
2796 case kRGB_565_SkColorType:
2797 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002798 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002799 }
2800 break;
2801 case kARGB_4444_SkColorType:
2802 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002803 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002804 }
2805 break;
2806 case kRGBA_8888_SkColorType:
2807 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002808 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002809 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002810 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002811 }
2812 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002813 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002814 if (GR_GL_RGB8 == format) {
2815 *config = kRGB_888_GrPixelConfig;
2816 }
2817 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002818 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002819 if (GR_GL_RGBA8 == format) {
2820 if (kGL_GrGLStandard == standard) {
2821 *config = kBGRA_8888_GrPixelConfig;
2822 }
2823 } else if (GR_GL_BGRA8 == format) {
2824 if (kGLES_GrGLStandard == standard) {
2825 *config = kBGRA_8888_GrPixelConfig;
2826 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002827 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002828 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002829 }
2830 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002831 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002832 if (GR_GL_RGB10_A2 == format) {
2833 *config = kRGBA_1010102_GrPixelConfig;
2834 }
2835 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002836 case kRGB_101010x_SkColorType:
2837 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002838 case kGray_8_SkColorType:
2839 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002840 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002841 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002842 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002843 }
2844 break;
2845 case kRGBA_F16_SkColorType:
2846 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002847 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002848 }
2849 break;
Mike Klein37854712018-06-26 11:43:06 -04002850 case kRGBA_F32_SkColorType:
2851 if (GR_GL_RGBA32F == format) {
2852 *config = kRGBA_float_GrPixelConfig;
2853 }
2854 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002855 }
2856
Greg Danielfaa095e2017-12-19 13:15:02 -05002857 return kUnknown_GrPixelConfig != *config;
2858}
2859
2860bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2861 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002862 GrGLTextureInfo texInfo;
2863 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002864 return false;
2865 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002866 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002867}
2868
2869bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2870 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002871 GrGLFramebufferInfo fbInfo;
2872 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002873 return false;
2874 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002875 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002876}
2877
Robert Phillipsfc711a22018-02-13 17:03:00 -05002878bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2879 GrPixelConfig* config) const {
2880 const GrGLenum* glFormat = format.getGLFormat();
2881 if (!glFormat) {
2882 return false;
2883 }
2884 return validate_sized_format(*glFormat, ct, config, fStandard);
2885}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002886
Timothy Liang036fdfe2018-06-28 15:50:36 -04002887#ifdef GR_TEST_UTILS
2888GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2889 const GrBackendTexture& backendTex) const {
2890 GrGLTextureInfo glInfo;
2891 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2892 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2893}
2894#endif