blob: 5e34c7a3cc02874bc56c24907b0d35b92ced0cc0 [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
Brian Salomonbbf05752017-11-30 11:30:48 -0500367 // This is all *very* approximate.
368 switch (ctxInfo.vendor()) {
369 case kNVIDIA_GrGLVendor:
370 // We've seen a range from 100 x 100 (TegraK1, GTX660) up to 300 x 300 (GTX 1070)
371 // but it doesn't clearly align with Pascal vs Maxwell vs Kepler.
372 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 150 * 150;
373 break;
Brian Salomon64fa70a2017-11-30 11:56:25 -0500374 case kImagination_GrGLVendor:
375 // Two PowerVR Rogues, Nexus Player and Chromebook Cb5-312T (PowerVR GX6250), show that
376 // it is always a win to use multitexturing.
377 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
378 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold =
379 std::numeric_limits<size_t>::max();
380 }
381 break;
Brian Salomon0c56d472017-12-04 08:37:44 -0500382 case kATI_GrGLVendor:
383 // So far no AMD GPU shows a performance difference. A tie goes to disabling
384 // multitexturing for simplicity's sake.
385 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 0;
386 break;
Brian Salomonbbf05752017-11-30 11:30:48 -0500387 default:
388 break;
389 }
390
csmartdalton485a1202016-07-13 10:16:32 -0700391 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
392 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
393 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
394 // limit this decision to specific GPU families rather than basing it on the vendor alone.
395 if (!GR_GL_MUST_USE_VBO &&
396 !fIsCoreProfile &&
397 (kARM_GrGLVendor == ctxInfo.vendor() ||
398 kImagination_GrGLVendor == ctxInfo.vendor() ||
399 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
400 fPreferClientSideDynamicBuffers = true;
401 }
402
Eric Karl5c779752017-05-08 12:02:07 -0700403 if (!contextOptions.fAvoidStencilBuffers) {
404 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
405 this->initFSAASupport(contextOptions, ctxInfo, gli);
406 this->initStencilSupport(ctxInfo);
407 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400408
409 // Setup blit framebuffer
410 if (kGL_GrGLStandard != ctxInfo.standard()) {
411 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
412 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
413 kNoMSAADst_BlitFramebufferFlag |
414 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
415 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
416 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
417 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
418 // limitations.
419 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
420 kResolveMustBeFull_BlitFrambufferFlag |
421 kNoMSAADst_BlitFramebufferFlag |
422 kNoFormatConversion_BlitFramebufferFlag |
423 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
424 }
425 } else {
426 if (fUsesMixedSamples ||
427 ctxInfo.version() >= GR_GL_VER(3,0) ||
428 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
429 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
430 fBlitFramebufferFlags = 0;
431 }
432 }
433
cdalton1dd05422015-06-12 09:01:18 -0700434 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000435
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000436 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000437 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
438 // extension includes glMapBuffer.
439 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
440 fMapBufferFlags |= kSubset_MapFlag;
441 fMapBufferType = kMapBufferRange_MapBufferType;
442 } else {
443 fMapBufferType = kMapBuffer_MapBufferType;
444 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000445 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000446 // Unextended GLES2 doesn't have any buffer mapping.
447 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800448 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800449 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
450 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800451 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
452 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
453 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000454 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
455 fMapBufferFlags = kCanMap_MapFlag;
456 fMapBufferType = kMapBuffer_MapBufferType;
457 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000458 }
459
jvanverthd7a2c1f2015-12-07 07:36:44 -0800460 if (kGL_GrGLStandard == standard) {
461 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
462 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700463 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500464 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400465 if (version >= GR_GL_VER(3, 0) ||
466 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
467 // GL_EXT_unpack_subimage needed to support subtexture rectangles
468 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800469 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400470// TODO: get transfer buffers working in Chrome
471// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
472// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800473 }
474 }
475
joshualitte5b74c62015-06-01 14:17:47 -0700476 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
477 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700478 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700479#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500480 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
481 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
482 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700483 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700484#else
cdalton397536c2016-03-25 12:15:03 -0700485 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700486#endif
joshualitte5b74c62015-06-01 14:17:47 -0700487 }
488
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000489 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000490 fNPOTTextureTileSupport = true;
491 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000492 } else {
493 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000494 // ES3 has no limitations.
495 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
496 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000497 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
498 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
499 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
500 // to alllow arbitrary wrap modes, however.
501 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000502 }
503
bsalomon@google.combcce8922013-03-25 15:38:39 +0000504 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700505
506 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
507 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
508 }
509
bsalomon@google.combcce8922013-03-25 15:38:39 +0000510 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
511 // Our render targets are always created with textures as the color
512 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000513 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700514 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
515
516 if (kARM_GrGLVendor == ctxInfo.vendor()) {
517 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
518 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
519 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000520
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000521 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
522
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000523 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700524 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000525
robertphillips1b8e1b52015-06-24 06:54:10 -0700526#if 0
527 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
528 kQualcomm_GrGLVendor != ctxInfo.vendor();
529#endif
530
csmartdalton9bc11872016-08-09 12:42:47 -0700531 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
532 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700533 }
534
robertphillips63926682015-08-20 09:39:02 -0700535#ifdef SK_BUILD_FOR_WIN
536 // On ANGLE deferring flushes can lead to GPU starvation
537 fPreferVRAMUseOverFlushes = !isANGLE;
538#endif
539
bsalomon7dea7b72015-08-19 08:26:51 -0700540 if (kChromium_GrGLDriver == ctxInfo.driver()) {
541 fMustClearUploadedBufferData = true;
542 }
543
bsalomond08ea5f2015-02-20 06:58:13 -0800544 if (kGL_GrGLStandard == standard) {
545 // ARB allows mixed size FBO attachments, EXT does not.
546 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
547 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
548 fOversizedStencilSupport = true;
549 } else {
550 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
551 }
552 } else {
553 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
554 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
555 }
556
joshualitt58001552015-06-26 12:46:36 -0700557 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700558 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
559 ctxInfo.hasExtension("GL_ARB_draw_indirect");
560 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
561 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700562 (fDrawIndirectSupport &&
563 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700564 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700565 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800566 } else {
567 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700568 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
569 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
570 fBaseInstanceSupport = fDrawIndirectSupport &&
571 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700572 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800573 }
574
ethannicholas28ef4452016-03-25 09:26:03 -0700575 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500576 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700577 fSampleShadingSupport = true;
578 }
579 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
580 fSampleShadingSupport = true;
581 }
582
jvanverth84741b32016-09-30 08:39:02 -0700583 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
584 if (kGL_GrGLStandard == standard) {
585 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
586 fFenceSyncSupport = true;
587 }
Brian Osman93a23462017-06-21 15:13:39 -0400588 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700589 fFenceSyncSupport = true;
590 }
591
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400592 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500593 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500594
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400595 if (kGL_GrGLStandard == standard) {
596 if (version >= GR_GL_VER(4, 1)) {
597 fProgramBinarySupport = true;
598 }
599 } else if (version >= GR_GL_VER(3, 0)) {
600 fProgramBinarySupport = true;
601 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400602 if (fProgramBinarySupport) {
603 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400604 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400605 fProgramBinarySupport = count > 0;
606 }
bsalomoncdee0092016-01-08 13:20:12 -0800607 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
608 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800609 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700610
Brian Salomon01b476a2018-01-23 11:06:41 -0500611 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
612 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
613 }
614
cdalton4cd67132015-06-10 19:23:46 -0700615 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500616 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700617
Brian Salomon01b476a2018-01-23 11:06:41 -0500618 // For now these two are equivalent but we could have dst read in shader via some other method.
619 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000620}
621
egdaniel472d44e2015-10-22 08:20:00 -0700622const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
623 bool isCoreProfile) {
624 switch (generation) {
625 case k110_GrGLSLGeneration:
626 if (kGLES_GrGLStandard == standard) {
627 // ES2s shader language is based on version 1.20 but is version
628 // 1.00 of the ES language.
629 return "#version 100\n";
630 } else {
631 SkASSERT(kGL_GrGLStandard == standard);
632 return "#version 110\n";
633 }
634 case k130_GrGLSLGeneration:
635 SkASSERT(kGL_GrGLStandard == standard);
636 return "#version 130\n";
637 case k140_GrGLSLGeneration:
638 SkASSERT(kGL_GrGLStandard == standard);
639 return "#version 140\n";
640 case k150_GrGLSLGeneration:
641 SkASSERT(kGL_GrGLStandard == standard);
642 if (isCoreProfile) {
643 return "#version 150\n";
644 } else {
645 return "#version 150 compatibility\n";
646 }
647 case k330_GrGLSLGeneration:
648 if (kGLES_GrGLStandard == standard) {
649 return "#version 300 es\n";
650 } else {
651 SkASSERT(kGL_GrGLStandard == standard);
652 if (isCoreProfile) {
653 return "#version 330\n";
654 } else {
655 return "#version 330 compatibility\n";
656 }
657 }
cdalton33ad7012016-02-22 07:55:44 -0800658 case k400_GrGLSLGeneration:
659 SkASSERT(kGL_GrGLStandard == standard);
660 if (isCoreProfile) {
661 return "#version 400\n";
662 } else {
663 return "#version 400 compatibility\n";
664 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500665 case k420_GrGLSLGeneration:
666 SkASSERT(kGL_GrGLStandard == standard);
667 if (isCoreProfile) {
668 return "#version 420\n";
669 }
670 else {
671 return "#version 420 compatibility\n";
672 }
egdaniel472d44e2015-10-22 08:20:00 -0700673 case k310es_GrGLSLGeneration:
674 SkASSERT(kGLES_GrGLStandard == standard);
675 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800676 case k320es_GrGLSLGeneration:
677 SkASSERT(kGLES_GrGLStandard == standard);
678 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700679 }
680 return "<no version>";
681}
682
Chris Dalton47c8ed32017-11-15 18:27:09 -0700683bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
684 if (kGLES_GrGLStandard != ctxInfo.standard() &&
685 ctxInfo.version() < GR_GL_VER(4,1) &&
686 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
687 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
688 return true;
689 }
690 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
691 // geometry shaders don't have lower precision than vertex and fragment.
692 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
693 GrGLint range[2];
694 GrGLint bits;
695 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
696 if (range[0] < 127 || range[1] < 127 || bits < 23) {
697 return false;
698 }
699 }
700 return true;
701}
702
703void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700704 GrGLStandard standard = ctxInfo.standard();
705 GrGLVersion version = ctxInfo.version();
706
707 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500708 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700709 **************************************************************************/
710
Brian Salomon1edc5b92016-11-29 13:43:46 -0500711 GrShaderCaps* shaderCaps = fShaderCaps.get();
712 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700713 if (kGLES_GrGLStandard == standard) {
714 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500715 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
716 shaderCaps->fFBFetchSupport = true;
717 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
718 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700719 }
720 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
721 // 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 -0500722 shaderCaps->fFBFetchNeedsCustomOutput = false;
723 shaderCaps->fFBFetchSupport = true;
724 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
725 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700726 }
727 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
728 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500729 shaderCaps->fFBFetchNeedsCustomOutput = false;
730 shaderCaps->fFBFetchSupport = true;
731 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
732 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700733 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500734 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700735 }
736
cdaltonc08f1962016-02-12 12:14:06 -0800737 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500738 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800739 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500740 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800741 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
742 }
Brian Salomon41274562017-09-15 09:40:03 -0700743 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
744 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
745 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800746 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500747 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800748 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
749 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400750 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
751 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500752 shaderCaps->fNoPerspectiveInterpolationSupport = true;
753 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800754 "GL_NV_shader_noperspective_interpolation";
755 }
756 }
757
Brian Salomon1edc5b92016-11-29 13:43:46 -0500758 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
759 shaderCaps->fGLSLGeneration,
760 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800761
Brian Salomon1edc5b92016-11-29 13:43:46 -0500762 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
763 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800764 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800765
766 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500767 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800768 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
769 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500770 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800771 }
772
773 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500774 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800775 }
776
cdalton9c3f1432016-03-11 10:07:37 -0800777 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400778 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
779 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400780 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400781 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
782 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
783 // At least one driver has been found that has this extension without the "GL_" prefix.
784 shaderCaps->fExternalTextureSupport = true;
785 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800786 }
787 }
788
cdaltonc04ce672016-03-11 14:07:38 -0800789 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600790 shaderCaps->fVertexIDSupport = true;
791 } else {
792 // Desktop GLSL 3.30 == ES GLSL 3.00.
793 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
794 }
795
Chris Dalton7c7ff032018-03-28 20:09:58 -0600796 if (kGL_GrGLStandard == standard) {
797 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
798 } else {
799 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
800 }
801
Chris Dalton47c8ed32017-11-15 18:27:09 -0700802 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
803 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400804
805 // Unsigned integers only supported in and after GLSL 1.30.
806 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700807}
808
kkinnunencfe62e32015-07-01 02:58:50 -0700809bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700810 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
811
812 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700813 return false;
814 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700815
kkinnunencfe62e32015-07-01 02:58:50 -0700816 if (kGL_GrGLStandard == ctxInfo.standard()) {
817 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
818 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
819 return false;
820 }
821 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700822 if (!hasChromiumPathRendering &&
823 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700824 return false;
825 }
826 }
827 // We only support v1.3+ of GL_NV_path_rendering which allows us to
828 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
829 // additions are detected by checking the existence of the function.
830 // We also use *Then* functions that not all drivers might have. Check
831 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800832 if (!gli->fFunctions.fStencilThenCoverFillPath ||
833 !gli->fFunctions.fStencilThenCoverStrokePath ||
834 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
835 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
836 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700837 return false;
838 }
839 return true;
840}
bsalomon1aa20292016-01-22 08:16:09 -0800841
Brian Salomon71d9d842016-11-03 13:42:00 -0400842bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800843 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800844 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800845 std::function<bool ()> bindRenderTarget,
846 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400847 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800848 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400849 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800850 return false;
851 }
bsalomon7928ef62016-01-05 10:26:39 -0800852
bsalomon76148af2016-01-12 11:13:47 -0800853 GrGLenum readFormat;
854 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400855 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800856 return false;
857 }
858
bsalomon1aa20292016-01-22 08:16:09 -0800859 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800860 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
861 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
862 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
863 // 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 -0500864 // The manual does not seem to fully match the spec as the spec allows integer formats
865 // when the bound color buffer is an integer buffer. It doesn't specify which integer
866 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500867 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
868 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
869 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800870 return false;
871 }
872 // There is also a set of allowed types, but all the types we use are in the set:
873 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
874 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
875 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
876 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
877 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
878 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
879 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800880 return true;
piotaixre4b23142014-10-02 10:57:53 -0700881 }
bsalomon7928ef62016-01-05 10:26:39 -0800882
bsalomon76148af2016-01-12 11:13:47 -0800883 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500884 switch (fConfigTable[surfaceConfig].fFormatType) {
885 case kNormalizedFixedPoint_FormatType:
886 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
887 return true;
888 }
889 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500890 case kFloat_FormatType:
891 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
892 return true;
893 }
894 break;
bsalomon7928ef62016-01-05 10:26:39 -0800895 }
896
Brian Salomon71d9d842016-11-03 13:42:00 -0400897 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800898 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400899 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800900 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800901 if (!bindRenderTarget()) {
902 return false;
903 }
904 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
905 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800906 rpFormat->fFormat = format;
907 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800908 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800909 }
910
Brian Salomon71d9d842016-11-03 13:42:00 -0400911 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
912 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700913}
914
Eric Karl5c779752017-05-08 12:02:07 -0700915void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
916 const GrGLInterface* gli) {
917 // We need dual source blending and the ability to disable multisample in order to support mixed
918 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
919 // renderer is available and enabled; no other path renderers support this feature.
920 if (fMultisampleDisableSupport &&
921 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400922 this->shaderCaps()->pathRenderingSupport()
923#if GR_TEST_UTILS
924 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
925#endif
926 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700927 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400928 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700929 }
930
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000931 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400932 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
933 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
934 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
935 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
936 fAlpha8IsRenderable = true;
937 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500938 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
939 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
940 // mixed samples we can't use multisampled-render-to-texture.
941 if (fUsesMixedSamples) {
942 fMSFBOType = kMixedSamples_MSFBOType;
943 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000944 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
945 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
946 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400947 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
948 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400949 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400950 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400951 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400952 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000953 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
954 fMSFBOType = kES_Apple_MSFBOType;
955 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000956 } else {
egdanieleed519e2016-01-15 11:36:18 -0800957 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700958 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400959 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
960 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400961
Brian Salomon00731b42016-10-14 11:30:51 -0400962 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400963 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
964 // Core profile removes ALPHA8 support.
965 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
966 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
967 // present.
968 fAlpha8IsRenderable = true;
969 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000970 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
971 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400972 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000973 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000974 }
Eric Karl5c779752017-05-08 12:02:07 -0700975
Brian Salomon01b476a2018-01-23 11:06:41 -0500976 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400977 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
978 fMSFBOType = kNone_MSFBOType;
979 }
980
Eric Karl5c779752017-05-08 12:02:07 -0700981 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
982 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
983 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700984 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000985}
986
cdalton1dd05422015-06-12 09:01:18 -0700987void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500988 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700989
Greg Daniel210883c2017-11-27 15:14:01 -0500990 bool layoutQualifierSupport = false;
991 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
992 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
993 layoutQualifierSupport = true;
994 }
995
cdalton1dd05422015-06-12 09:01:18 -0700996 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
997 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500998 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500999 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
1000 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001001 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001002 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001003 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1004 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001005 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001006 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001007 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001008 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001009 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1010 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -07001011 }
cdalton1dd05422015-06-12 09:01:18 -07001012}
1013
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001014namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001015const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001016}
1017
Eric Karl5c779752017-05-08 12:02:07 -07001018void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001019
1020 // Build up list of legal stencil formats (though perhaps not supported on
1021 // the particular gpu/driver) from most preferred to least.
1022
1023 // these consts are in order of most preferred to least preferred
1024 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1025
1026 static const StencilFormat
1027 // internal Format stencil bits total bits packed?
1028 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1029 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1030 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1031 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001032 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001033 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1034
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001035 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001036 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001037 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001038 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1039 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1040
1041 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1042 // require FBO support we can expect these are legal formats and don't
1043 // check. These also all support the unsized GL_STENCIL_INDEX.
1044 fStencilFormats.push_back() = gS8;
1045 fStencilFormats.push_back() = gS16;
1046 if (supportsPackedDS) {
1047 fStencilFormats.push_back() = gD24S8;
1048 }
1049 fStencilFormats.push_back() = gS4;
1050 if (supportsPackedDS) {
1051 fStencilFormats.push_back() = gDS;
1052 }
1053 } else {
1054 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1055 // for other formats.
1056 // ES doesn't support using the unsized format.
1057
1058 fStencilFormats.push_back() = gS8;
1059 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001060 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1061 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001062 fStencilFormats.push_back() = gD24S8;
1063 }
1064 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1065 fStencilFormats.push_back() = gS4;
1066 }
1067 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001068}
1069
Brian Osman71a18892017-08-10 10:23:25 -04001070void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001071
Brian Osman71a18892017-08-10 10:23:25 -04001072 // We are called by the base class, which has already called beginObject(). We choose to nest
1073 // all of our caps information in a named sub-object.
1074 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001075
Brian Osman71a18892017-08-10 10:23:25 -04001076 writer->beginArray("Stencil Formats");
1077
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001078 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001079 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001080 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1081 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1082 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001083 }
1084
Brian Osman71a18892017-08-10 10:23:25 -04001085 writer->endArray();
1086
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001087 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001088 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001089 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001090 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001091 "IMG MS To Texture",
1092 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001093 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001094 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001095 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001096 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1097 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1098 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1099 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1100 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001101 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001102
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001103 static const char* kInvalidateFBTypeStr[] = {
1104 "None",
1105 "Discard",
1106 "Invalidate",
1107 };
1108 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1109 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1110 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1111 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001112
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001113 static const char* kMapBufferTypeStr[] = {
1114 "None",
1115 "MapBuffer",
1116 "MapBufferRange",
1117 "Chromium",
1118 };
1119 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1120 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1121 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1122 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1123 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1124
Brian Osman71a18892017-08-10 10:23:25 -04001125 writer->appendBool("Core Profile", fIsCoreProfile);
1126 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1127 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1128 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1129 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1130 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1131 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1132 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1133 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001134
Brian Osman71a18892017-08-10 10:23:25 -04001135 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001136 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1137 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1138 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001139 writer->appendBool("Debug support", fDebugSupport);
1140 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1141 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1142 writer->appendBool("Base instance support", fBaseInstanceSupport);
1143 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1144 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1145 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1146 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1147 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1148 writer->appendBool("BGRA to RGBA readback conversions are slow",
1149 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001150 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001151 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1152 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001153 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1154 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1155 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1156 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001157 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1158 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001159
Brian Osman71a18892017-08-10 10:23:25 -04001160 writer->beginArray("configs");
1161
bsalomon41e4384e2016-01-08 09:12:44 -08001162 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001163 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001164 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1165 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1166 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001167 writer->appendHexU32("e_format_read_pixels",
1168 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001169 writer->appendHexU32(
1170 "e_format_teximage",
1171 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1172 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1173 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1174 writer->appendHexU32("i_for_renderbuffer",
1175 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1176 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001177 }
1178
Brian Osman71a18892017-08-10 10:23:25 -04001179 writer->endArray();
1180 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001181}
1182
bsalomon41e4384e2016-01-08 09:12:44 -08001183bool GrGLCaps::bgraIsInternalFormat() const {
1184 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1185}
1186
bsalomon76148af2016-01-12 11:13:47 -08001187bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1188 GrGLenum* internalFormat, GrGLenum* externalFormat,
1189 GrGLenum* externalType) const {
1190 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1191 externalFormat, externalType)) {
1192 return false;
1193 }
1194 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1195 return true;
1196}
1197
bsalomon76148af2016-01-12 11:13:47 -08001198bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1199 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001200 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001201 externalFormat, externalType)) {
1202 return false;
1203 }
1204 return true;
1205}
1206
1207bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001208 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1209 return true;
1210}
1211
1212bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1213 ExternalFormatUsage usage, GrGLenum* externalFormat,
1214 GrGLenum* externalType) const {
1215 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001216
1217 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1218 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1219
1220 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001221 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1222 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001223 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1224 return false;
1225 }
1226
1227 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1228 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1229
bsalomone9573312016-01-25 14:33:25 -08001230 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1231 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1232 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1233 // texture, not the red component.
1234 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001235 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001236 *externalFormat = GR_GL_ALPHA;
1237 }
1238 }
1239
bsalomon76148af2016-01-12 11:13:47 -08001240 return true;
1241}
1242
brianosman20471892016-12-02 06:43:32 -08001243void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1244 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001245 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001246 /*
1247 Comments on renderability of configs on various GL versions.
1248 OpenGL < 3.0:
1249 no built in support for render targets.
1250 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1251 format RGB, RGBA and NV float formats we don't use.
1252 This is the following:
1253 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1254 RGB10_A2, RGBA12,RGBA16
1255 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1256 since they aren't required by later standards and the driver can simply return
1257 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1258 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1259 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1260 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1261 This adds a lot of additional renderable sized formats, including ALPHA8.
1262 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1263 16F, 32I, 32UI, and 32F variants).
1264 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1265
1266 For both the above extensions we limit ourselves to those that are also required by
1267 OpenGL 3.0.
1268
1269 OpenGL 3.0:
1270 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1271 but are not required to be supported as renderable textures/renderbuffer.
1272 Required renderable color formats:
1273 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1274 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1275 RGB10_A2.
1276 - R11F_G11F_B10F.
1277 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1278 and RG8UI.
1279 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1280 - ALPHA8
1281
1282 OpenGL 3.1, 3.2, 3.3
1283 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1284 OpengGL 3.3, 4.0, 4.1
1285 Adds RGB10_A2UI.
1286 OpengGL 4.2
1287 Adds
1288 - RGB5_A1, RGBA4
1289 - RGB565
1290 OpenGL 4.4
1291 Does away with the separate list and adds a column to the sized internal color format
1292 table. However, no new formats become required color renderable.
1293
1294 ES 2.0
1295 color renderable: RGBA4, RGB5_A1, RGB565
1296 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1297 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1298 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1299 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1300 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1301 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1302
1303 ES 3.0
1304 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1305 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1306 RGB5_A1.
1307 - RGB8 and RGB565.
1308 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1309 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1310 ES 3.1
1311 Adds RGB10_A2, RGB10_A2UI,
1312 ES 3.2
1313 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1314 */
Brian Salomon44804c02018-01-23 16:51:28 -05001315
1316 // Correctness workarounds.
1317 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001318 bool disableSRGBForX86PowerVR = false;
1319 bool disableSRGBWriteControlForAdreno4xx = false;
1320 bool disableR8TexStorageForANGLEGL = false;
1321 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001322 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001323 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001324
1325 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1326 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1327 // and GL_RG on FBO textures.
1328 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1329
Greg Daniel09c94002018-06-08 22:11:51 +00001330 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1331
Brian Salomon44804c02018-01-23 16:51:28 -05001332 bool isX86PowerVR = false;
1333#if defined(SK_CPU_X86)
1334 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1335 isX86PowerVR = true;
1336 }
1337#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001338 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1339 // blacklist that device (and any others that might be sharing the same driver).
1340 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001341 disableSRGBWriteControlForAdreno4xx =
1342 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1343 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001344
1345 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1346 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1347 // check that we are not going to OpenGL.
1348 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1349
1350 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1351#if defined(SK_BUILD_FOR_MAC)
1352 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1353#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001354 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1355 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001356 }
1357
Brian Salomon71d9d842016-11-03 13:42:00 -04001358 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1359 ConfigInfo::kFBOColorAttachment_Flag;
1360 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001361 if (kNone_MSFBOType != fMSFBOType) {
1362 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1363 }
bsalomon41e4384e2016-01-08 09:12:44 -08001364 GrGLStandard standard = ctxInfo.standard();
1365 GrGLVersion version = ctxInfo.version();
1366
cblume790d5132016-02-29 11:13:29 -08001367 bool texStorageSupported = false;
1368 if (kGL_GrGLStandard == standard) {
1369 // The EXT version can apply to either GL or GLES.
1370 texStorageSupported = version >= GR_GL_VER(4,2) ||
1371 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1372 ctxInfo.hasExtension("GL_EXT_texture_storage");
1373 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001374 texStorageSupported = version >= GR_GL_VER(3,0) ||
1375 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001376 }
1377
Brian Salomone609e812018-01-17 14:00:47 -05001378 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001379
1380 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001381 if (kGL_GrGLStandard == standard) {
1382 textureRedSupport =
1383 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1384 } else {
1385 textureRedSupport =
1386 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1387 }
1388 }
1389
bsalomon30447372015-12-21 09:03:05 -08001390 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1391 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001392 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001393 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001394 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001395 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001396
1397 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1398 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001399 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001400 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001401 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001402 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001403 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1404 if (kGL_GrGLStandard == standard) {
1405 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1406 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001407 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001408 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1409 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1410 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1411 }
egdaniel4999df82016-01-07 17:06:04 -08001412 }
cblume790d5132016-02-29 11:13:29 -08001413 if (texStorageSupported) {
1414 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1415 }
bsalomoncdee0092016-01-08 13:20:12 -08001416 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001417
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001418 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1419 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1420 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1421 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1422 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1423 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1424 // supportedReadPixelsColorType never returns it.
1425 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1426 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1427 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1428 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1429 if (kGL_GrGLStandard == standard) {
1430 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1431 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1432 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1433 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1434 // becomes an issue.
1435 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1436 // but we don't support that just for simplicity's sake.
1437 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1438 } else {
1439 // 3.0 and the extension support this as a render buffer format.
1440 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1441 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1442 }
1443 }
1444 if (texStorageSupported) {
1445 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1446 }
1447 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1448 if (disableRGB8ForMali400) {
1449 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1450 }
1451
1452 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001453 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001454 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001455 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001456
1457 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1458 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1459 // GL_EXT_texture_format_BGRA8888.
1460 bool supportsBGRATexStorage = false;
1461
bsalomon41e4384e2016-01-08 09:12:44 -08001462 if (kGL_GrGLStandard == standard) {
1463 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1464 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1465 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1466 // Since the internal format is RGBA8, it is also renderable.
1467 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1468 allRenderFlags;
1469 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001470 // Since we are using RGBA8 we can use tex storage.
1471 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001472 } else {
1473 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1474 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001475 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1476 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1477 nonMSAARenderFlags;
1478
1479 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1480 supportsBGRATexStorage = true;
1481 }
1482 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1483 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1484 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1485 ConfigInfo::kRenderableWithMSAA_Flag;
1486 }
1487 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001488 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1489 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1490 // driver remembers the external format when the texture is created (with TexImage).
1491 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1492 // We could work around this, but it adds even more state tracking to code that is
1493 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1494 // This also side-steps some ambiguous interactions with the texture storage extension.
1495 if (version >= GR_GL_VER(3,0)) {
1496 // The APPLE extension doesn't make this renderable.
1497 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001498 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001499 }
bsalomon41e4384e2016-01-08 09:12:44 -08001500 }
1501 }
Brian Osman48c99192017-06-02 08:45:06 -04001502
Greg Daniel0ff79b22018-02-15 12:33:33 -05001503 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001504 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001505 }
bsalomoncdee0092016-01-08 13:20:12 -08001506 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001507
Brian Osman2b23c4b2018-06-01 12:25:08 -04001508 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001509 if (kGL_GrGLStandard == standard) {
1510 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001511 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001512 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1513 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1514 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001515 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001516 }
1517 }
1518 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001519 if (fSRGBSupport) {
1520 fSRGBWriteControl = true;
1521 }
bsalomon41e4384e2016-01-08 09:12:44 -08001522 } else {
brianosman20471892016-12-02 06:43:32 -08001523 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001524 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001525 fSRGBSupport = false;
1526 }
bsalomon41e4384e2016-01-08 09:12:44 -08001527 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1528 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001529 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001530 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001531 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001532 }
brianosman20471892016-12-02 06:43:32 -08001533
1534 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1535 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1536 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1537 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1538 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1539 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1540 // affects Windows.
1541 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1542 fSRGBSupport = false;
1543 }
1544
Brian Osman48c99192017-06-02 08:45:06 -04001545 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1546 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1547 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1548
Brian Osman67999392017-05-31 16:19:34 -04001549 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001550 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001551 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1552 }
Brian Osman67999392017-05-31 16:19:34 -04001553
bsalomon30447372015-12-21 09:03:05 -08001554 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1555 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1556 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1557 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001558 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001559 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001560 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001561 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001562 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001563 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001564 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001565 }
Brian Osman48c99192017-06-02 08:45:06 -04001566 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1567 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001568 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1569 }
bsalomoncdee0092016-01-08 13:20:12 -08001570 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001571 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1572 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1573 // is in this format, for example).
1574 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1575 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1576 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1577 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001578 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001579 GR_GL_BGRA;
1580 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1581 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001582 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001583 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001584 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001585 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001586
brianosmana6359362016-03-21 06:55:37 -07001587 if (texStorageSupported) {
1588 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1589 }
1590 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1591
bsalomon30447372015-12-21 09:03:05 -08001592 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1593 if (this->ES2CompatibilitySupport()) {
1594 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1595 } else {
1596 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1597 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001598 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001599 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001600 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001601 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001602 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1603 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001604 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001605 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1606 }
1607 } else {
1608 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1609 }
cblume790d5132016-02-29 11:13:29 -08001610 // 565 is not a sized internal format on desktop GL. So on desktop with
1611 // 565 we always use an unsized internal format to let the system pick
1612 // the best sized format to convert the 565 data to. Since TexStorage
1613 // only allows sized internal formats we disallow it.
1614 //
1615 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1616 // update.
1617 if (texStorageSupported && kGL_GrGLStandard != standard) {
1618 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1619 }
bsalomoncdee0092016-01-08 13:20:12 -08001620 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001621
1622 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1623 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001624 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001625 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001626 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001627 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001628 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1629 if (kGL_GrGLStandard == standard) {
1630 if (version >= GR_GL_VER(4, 2)) {
1631 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1632 }
1633 } else {
1634 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1635 }
cblume790d5132016-02-29 11:13:29 -08001636 if (texStorageSupported) {
1637 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1638 }
bsalomoncdee0092016-01-08 13:20:12 -08001639 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001640
Brian Osman10fc6fd2018-03-02 11:01:10 -05001641 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1642 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001643 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001644 GR_GL_RGBA;
1645 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1646 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1647 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1648 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1649 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1650 allRenderFlags;
1651 }
1652 if (texStorageSupported) {
1653 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1654 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001655 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1656
Greg Danielef59d872017-11-17 16:47:21 -05001657 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1658 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1659
1660 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1661 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1662 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1663 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1664 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001665 }
Greg Danielef59d872017-11-17 16:47:21 -05001666 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1667 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001668 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001669 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1670 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1671 alphaInfo.fFlags |= allRenderFlags;
1672 }
1673
1674 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1675 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1676 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1677 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1678 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001679 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001680 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001681
Brian Osman48c99192017-06-02 08:45:06 -04001682 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1683 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001684 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001685 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1686 }
1687 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1688 }
1689
Brian Salomone609e812018-01-17 14:00:47 -05001690 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001691 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001692 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1693 } else {
1694 redInfo.fFlags = 0;
1695
1696 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001697 }
bsalomon41e4384e2016-01-08 09:12:44 -08001698
Greg Daniel7af060a2017-12-05 16:27:11 -05001699 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1700 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1701 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1702 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1703 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001704 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001705 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1706 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1707 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1708 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001709 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001710
1711 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1712 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1713 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1714 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1715 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001716 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001717 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1718 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1719
Greg Daniel09c94002018-06-08 22:11:51 +00001720 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1721 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1722 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1723 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1724 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001725 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1726 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1727 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001728 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001729 }
Brian Osman48c99192017-06-02 08:45:06 -04001730 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001731 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001732 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1733 }
1734 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1735 }
1736
Brian Salomone609e812018-01-17 14:00:47 -05001737 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001738 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1739 } else {
1740 grayRedInfo.fFlags = 0;
1741 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001742 }
1743
bsalomon41e4384e2016-01-08 09:12:44 -08001744 // Check for [half] floating point texture support
1745 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1746 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1747 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1748 bool hasFPTextures = false;
1749 bool hasHalfFPTextures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001750 bool rgIsTexturable = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001751 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001752 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001753
1754 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001755 if (version >= GR_GL_VER(3, 0)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001756 hasFPTextures = true;
1757 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001758 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001759 }
1760 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001761 if (version >= GR_GL_VER(3, 0)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001762 hasFPTextures = true;
1763 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001764 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001765 } else {
1766 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1767 ctxInfo.hasExtension("GL_OES_texture_float")) {
1768 hasFPTextures = true;
1769 }
1770 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1771 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1772 hasHalfFPTextures = true;
1773 }
1774 }
1775 }
bsalomon30447372015-12-21 09:03:05 -08001776
csmartdalton6aa0e112017-02-08 16:14:11 -05001777 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1778 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1779 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1780 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1781 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001782 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001783 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1784 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
1785 if (hasFPTextures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001786 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
csmartdalton6aa0e112017-02-08 16:14:11 -05001787 // For now we only enable rendering to float on desktop, because on ES we'd have to
1788 // solve many precision issues and no clients actually want this yet.
1789 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1790 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1791 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1792 }
bsalomon41e4384e2016-01-08 09:12:44 -08001793 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001794 if (texStorageSupported) {
1795 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1796 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001797 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001798 }
bsalomon30447372015-12-21 09:03:05 -08001799
Greg Danielef59d872017-11-17 16:47:21 -05001800 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001801 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001802 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001803 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001804 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001805 }
Greg Danielef59d872017-11-17 16:47:21 -05001806 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1807 redHalf.fFormats.fExternalType = redHalfExternalType;
1808 redHalf.fFormatType = kFloat_FormatType;
1809 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1810 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001811 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001812 redHalf.fSwizzle = GrSwizzle::RRRR();
Brian Salomone609e812018-01-17 14:00:47 -05001813 if (textureRedSupport && hasHalfFPTextures) {
Greg Danielef59d872017-11-17 16:47:21 -05001814 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1815
csmartdalton6aa0e112017-02-08 16:14:11 -05001816 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
Brian Salomone609e812018-01-17 14:00:47 -05001817 (textureRedSupport && ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
Greg Danielef59d872017-11-17 16:47:21 -05001818 redHalf.fFlags |= fpRenderFlags;
1819 }
1820
1821 if (texStorageSupported && !isCommandBufferES2) {
1822 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1823 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001824 }
Greg Danielef59d872017-11-17 16:47:21 -05001825 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001826
1827 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1828 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001829 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001830 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001831 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001832 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1833 } else {
1834 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1835 }
bsalomon7928ef62016-01-05 10:26:39 -08001836 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001837 if (hasHalfFPTextures) {
1838 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1839 // ES requires 3.2 or EXT_color_buffer_half_float.
1840 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1841 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1842 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1843 }
1844 }
cblume790d5132016-02-29 11:13:29 -08001845 if (texStorageSupported) {
1846 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1847 }
bsalomoncdee0092016-01-08 13:20:12 -08001848 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001849
bsalomon30447372015-12-21 09:03:05 -08001850 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1851
1852 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001853 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1854 ctxInfo.version() >= GR_GL_VER(3,0));
1855 // All ES versions (thus far) require sized internal formats for render buffers.
1856 // TODO: Always use sized internal format?
1857 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1858
bsalomon30447372015-12-21 09:03:05 -08001859 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001860 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1861 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001862 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001863 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001864 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1865 fConfigTable[i].fFormats.fSizedInternalFormat :
1866 fConfigTable[i].fFormats.fBaseInternalFormat;
1867 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001868 fConfigTable[i].fFormats.fSizedInternalFormat :
1869 fConfigTable[i].fFormats.fBaseInternalFormat;
1870 }
Brian Salomon44804c02018-01-23 16:51:28 -05001871 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1872 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1873 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1874 // in ES.
1875 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1876 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1877 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1878 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001879 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1880 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001881 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1882 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001883 }
1884
bsalomon30447372015-12-21 09:03:05 -08001885 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1886 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1887 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1888 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1889 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001890 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001891 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001892
1893 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1894 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1895 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1896 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001897 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001898 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1899 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1900 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1901 // slot.
1902 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1903 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001904
1905 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1906 // as a base format.
1907 // GL_EXT_texture_format_BGRA8888:
1908 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1909 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1910 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001911 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001912 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1913 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1914 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001915 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001916 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1917 }
1918
bsalomoncdee0092016-01-08 13:20:12 -08001919 // If we don't have texture swizzle support then the shader generator must insert the
1920 // swizzle into shader code.
1921 if (!this->textureSwizzleSupport()) {
1922 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001923 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001924 }
1925 }
1926
bsalomon7f9b2e42016-01-12 13:29:26 -08001927 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1928 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1929 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001930 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001931 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1932 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1933 if (GrPixelConfigIsAlphaOnly(config) &&
1934 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001935 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001936 }
1937 }
1938 }
1939
Greg Daniel81e7bf82017-07-19 14:47:42 -04001940 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1941 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001942 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1943 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001944 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001945 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1946 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001947 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001948 int count;
1949 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1950 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1951 1, &count);
1952 if (count) {
1953 int* temp = new int[count];
1954 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1955 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001956 // GL has a concept of MSAA rasterization with a single sample but we do not.
1957 if (count && temp[count - 1] == 1) {
1958 --count;
1959 SkASSERT(!count || temp[count -1] > 1);
1960 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001961 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001962 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001963 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001964 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001965 for (int j = 0; j < count; ++j) {
1966 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1967 }
1968 delete[] temp;
1969 }
1970 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001971 // Fake out the table using some semi-standard counts up to the max allowed sample
1972 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001973 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001974 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1975 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1976 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1977 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1978 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001979 // Chrome has a mock GL implementation that returns 0.
1980 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05001981
Brian Salomonbdecacf2018-02-02 20:32:49 -05001982 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04001983 int count = SK_ARRAY_COUNT(kDefaultSamples);
1984 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001985 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001986 break;
1987 }
1988 }
1989 if (count > 0) {
1990 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
1991 }
1992 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001993 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
1994 fConfigTable[i].fColorSampleCounts.setCount(1);
1995 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001996 }
1997 }
1998
bsalomon30447372015-12-21 09:03:05 -08001999#ifdef SK_DEBUG
2000 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002001 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002002 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002003 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2004 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002005 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2006 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2007 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2008 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002009 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2010 fConfigTable[i].fFormats.fBaseInternalFormat);
2011 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002012 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002013 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2014 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2015 fConfigTable[i].fFormats.fExternalFormat[j]);
2016 }
2017 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002018 }
2019#endif
2020}
2021
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002022bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2023 bool dstIsTextureable, bool dstIsGLTexture2D,
2024 GrSurfaceOrigin dstOrigin,
2025 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2026 bool srcIsTextureable, bool srcIsGLTexture2D,
2027 GrSurfaceOrigin srcOrigin) const {
2028 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2029 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2030 // many drivers would allow it to work, but ANGLE does not.
2031 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2032 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2033 return false;
2034 }
2035
2036 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2037 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2038 return false;
2039 }
2040
2041 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2042 // texture.
2043 if (!dstIsTextureable) {
2044 return false;
2045 }
2046
2047 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2048 // is required
2049 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2050 (!srcIsTextureable || srcIsGLTexture2D) &&
2051 dstIsGLTexture2D &&
2052 dstOrigin == srcOrigin) {
2053 return true;
2054 } else {
2055 return false;
2056 }
2057}
2058
2059bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2060 bool dstIsTextureable, bool dstIsGLTexture2D,
2061 GrSurfaceOrigin dstOrigin,
2062 GrPixelConfig srcConfig, int srcSampleCnt,
2063 bool srcIsTextureable, bool srcIsGLTexture2D,
2064 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2065 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2066 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2067 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2068 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2069 return false;
2070 }
2071
2072 if (dstIsTextureable && !dstIsGLTexture2D) {
2073 return false;
2074 }
2075 if (srcIsTextureable && !srcIsGLTexture2D) {
2076 return false;
2077 }
2078
2079 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2080 return false;
2081 }
2082 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2083 // We would mirror to compensate for origin changes. Note that copySurface is
2084 // specified such that the src and dst rects are the same.
2085 if (dstOrigin != srcOrigin) {
2086 return false;
2087 }
2088 }
2089
2090 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2091 if (srcSampleCnt > 1) {
2092 if (1 == dstSampleCnt) {
2093 return false;
2094 }
2095 if (SkRect::Make(srcRect) != srcBounds) {
2096 return false;
2097 }
2098 }
2099 }
2100
2101 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2102 if (dstSampleCnt > 1) {
2103 return false;
2104 }
2105 }
2106
2107 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2108 if (dstConfig != srcConfig) {
2109 return false;
2110 }
2111 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2112 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2113 return false;
2114 }
2115 }
2116
2117 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2118 if (srcSampleCnt > 1) {
2119 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2120 return false;
2121 }
2122 if (dstOrigin != srcOrigin) {
2123 return false;
2124 }
2125 }
2126 }
2127 return true;
2128}
2129
2130bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2131 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2132}
2133
2134static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2135 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2136 if (!rt) {
2137 return false;
2138 }
2139 // A RT has a separate MSAA renderbuffer if:
2140 // 1) It's multisampled
2141 // 2) We're using an extension with separate MSAA renderbuffers
2142 // 3) It's not FBO 0, which is special and always auto-resolves
2143 return rt->numColorSamples() > 1 &&
2144 glCaps.usesMSAARenderBuffers() &&
2145 !rt->rtPriv().glRTFBOIDIs0();
2146}
2147
2148bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2149 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2150 GrSurfaceOrigin dstOrigin = dst->origin();
2151 GrSurfaceOrigin srcOrigin = src->origin();
2152
2153 GrPixelConfig dstConfig = dst->config();
2154 GrPixelConfig srcConfig = src->config();
2155
2156 int dstSampleCnt = 0;
2157 int srcSampleCnt = 0;
2158 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2159 dstSampleCnt = rtProxy->numColorSamples();
2160 }
2161 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2162 srcSampleCnt = rtProxy->numColorSamples();
2163 }
2164 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2165 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2166
2167 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2168 // swizzle.
2169 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2170 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2171 return false;
2172 }
2173
2174 const GrTextureProxy* dstTex = dst->asTextureProxy();
2175 const GrTextureProxy* srcTex = src->asTextureProxy();
2176
2177 bool dstIsTex2D = dstTex ? dstTex->texPriv().isGLTexture2D() : false;
2178 bool srcIsTex2D = srcTex ? srcTex->texPriv().isGLTexture2D() : false;
2179
2180 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2181 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2182 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2183 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2184 // know we will at least be able to do it as a draw.
2185#ifdef SK_DEBUG
2186 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2187 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2188 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2189 !src->priv().isExact()) {
2190 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2191 }
2192#endif
2193
2194 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2195 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2196 srcConfig, has_msaa_render_buffer(src, *this),
2197 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2198 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2199 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2200 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2201 dstPoint) ||
2202 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2203}
2204
Robert Phillipsbf25d432017-04-07 10:08:53 -04002205bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002206 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2207 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002208 // By default, we don't require rects to match.
2209 *rectsMustMatch = false;
2210
2211 // By default, we allow subrects.
2212 *disallowSubrect = false;
2213
Brian Salomon467921e2017-03-06 16:17:12 -05002214 // If the src is a texture, we can implement the blit as a draw assuming the config is
2215 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002216 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002217 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002218 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2219 desc->fConfig = src->config();
2220 return true;
2221 }
2222
Robert Phillipsbf25d432017-04-07 10:08:53 -04002223 {
2224 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2225 // wrapped. In that case the proxy would already be instantiated.
2226 const GrTexture* srcTexture = src->priv().peekTexture();
2227 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2228 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2229 // Not supported for FBO blit or CopyTexSubImage
2230 return false;
2231 }
Brian Salomon467921e2017-03-06 16:17:12 -05002232 }
2233
2234 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2235 // possible and we return false to fallback to creating a render target dst for render-to-
2236 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2237 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002238 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002239 bool rectsMustMatchForBlitFramebuffer = false;
2240 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002241 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002242 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2243 rectsMustMatchForBlitFramebuffer = true;
2244 disallowSubrectForBlitFramebuffer = true;
2245 // Mirroring causes rects to mismatch later, don't allow it.
2246 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002247 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2248 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002249 rectsMustMatchForBlitFramebuffer = true;
2250 // Mirroring causes rects to mismatch later, don't allow it.
2251 originForBlitFramebuffer = src->origin();
2252 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002253 originForBlitFramebuffer = src->origin();
2254 }
2255
2256 // Check for format issues with glCopyTexSubImage2D
2257 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2258 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2259 // then we set up for that, otherwise fail.
2260 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002261 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002262 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002263 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2264 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002265 return true;
2266 }
2267 return false;
2268 }
2269
Robert Phillipsbf25d432017-04-07 10:08:53 -04002270 {
Brian Salomon63e79732017-05-15 21:23:13 -04002271 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2272 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002273 if (srcIsMSAARenderbuffer) {
2274 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2275 // blit or fail.
2276 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002277 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002278 desc->fConfig = src->config();
2279 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2280 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2281 return true;
2282 }
2283 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002284 }
Brian Salomon467921e2017-03-06 16:17:12 -05002285 }
2286
2287 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002288 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002289 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002290 desc->fFlags = kNone_GrSurfaceFlags;
2291 return true;
2292}
2293
Greg Daniel691f5e72018-02-28 14:21:34 -05002294void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2295 const GrContextOptions& contextOptions,
2296 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002297 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2298 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002299 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2300 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002301 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002302 fDiscardRenderTargetSupport = false;
2303 fInvalidateFBType = kNone_InvalidateFBType;
2304 }
2305
2306 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2307 // 340.96 and 367.57.
2308 if (kGL_GrGLStandard == ctxInfo.standard() &&
2309 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002310 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002311 fClearTextureSupport = false;
2312 }
2313
2314 // Calling glClearTexImage crashes on the NexusPlayer.
2315 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2316 fClearTextureSupport = false;
2317 }
2318
2319 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2320#ifdef SK_BUILD_FOR_MAC
2321 if (shaderCaps->fGeometryShaderSupport) {
2322 shaderCaps->fGSInvocationsSupport = false;
2323 }
2324#endif
2325
2326 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2327 // shaders. @127.0 is the earliest verified driver to not crash.
2328 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002329 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002330 shaderCaps->fGeometryShaderSupport = false;
2331 }
2332
2333#if defined(__has_feature)
2334#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2335 // See skbug.com/7058
2336 fMapBufferType = kNone_MapBufferType;
2337 fMapBufferFlags = kNone_MapFlags;
2338#endif
2339#endif
2340
2341 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2342 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2343 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2344 // unclear whether this really affects a wide range of devices.
2345 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002346 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002347 fMapBufferType = kNone_MapBufferType;
2348 fMapBufferFlags = kNone_MapFlags;
2349 }
2350
2351 // TODO: re-enable for ANGLE
2352 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2353 fTransferBufferType = kNone_TransferBufferType;
2354 }
2355
2356 // Using MIPs on this GPU seems to be a source of trouble.
2357 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2358 fMipMapSupport = false;
2359 }
2360
2361 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2362 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2363 // around a driver bug related to gl_FragCoord.
2364 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2365 fMaxClipAnalyticFPs = 0;
2366 }
2367
2368#ifndef SK_BUILD_FOR_IOS
2369 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2370 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2371 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2372 ctxInfo.driver() != kChromium_GrGLDriver)) {
2373 fUseDrawToClearColor = true;
2374 }
2375#endif
2376
2377 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2378 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2379 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2380 fUseDrawToClearColor = true;
2381 }
2382
2383#ifdef SK_BUILD_FOR_MAC
2384 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2385 // full screen clears
2386 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2387 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002388 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2389 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2390 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2391 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002392 fUseDrawToClearColor = true;
2393 }
2394#endif
2395
2396 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2397 // bugs seems to involve clearing too much and not skipping the clear.
2398 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2399 // but only for D3D11 ANGLE.
2400 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2401 fUseDrawToClearColor = true;
2402 }
2403
Chris Dalton1214be92018-06-28 19:06:27 -06002404 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2405 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002406 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002407 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002408 fUseDrawToClearStencilClip = true;
2409 }
2410 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2411 }
2412
Adrienne Walker94f585e2018-05-15 11:47:07 -07002413 if (fDriverBugWorkarounds.gl_clear_broken) {
2414 fUseDrawToClearColor = true;
2415 fUseDrawToClearStencilClip = true;
2416 }
2417
Brian Salomon01b476a2018-01-23 11:06:41 -05002418 // This was reproduced on the following configurations:
2419 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2420 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2421 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2422 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2423 // and not produced on:
2424 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2425 // The particular lines that get dropped from test images varies across different devices.
2426 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002427 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002428 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2429 }
2430
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002431 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2432 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2433 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002434 fRequiresFlushBetweenNonAndInstancedDraws = true;
2435 }
2436
Brian Salomon01b476a2018-01-23 11:06:41 -05002437 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2438 // given 1 << 15 or more instances.
2439 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2440 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
Adrienne Walker001cae02018-05-15 11:38:44 -07002441 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
2442 fMaxInstancesPerDrawArraysWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002443 }
2444
2445 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002446 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002447 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2448 fUseDrawInsteadOfAllRenderTargetWrites = true;
2449 }
2450
2451 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2452 fSampleShadingSupport = false;
2453 }
2454
2455#ifdef SK_BUILD_FOR_MAC
2456 static constexpr bool isMAC = true;
2457#else
2458 static constexpr bool isMAC = false;
2459#endif
2460
2461 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2462 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2463 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2464 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2465 if (fMipMapLevelAndLodControlSupport &&
2466 (contextOptions.fDoManualMipmapping ||
2467 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2468 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2469 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2470 fDoManualMipmapping = true;
2471 }
2472
2473 // See http://crbug.com/710443
2474#ifdef SK_BUILD_FOR_MAC
2475 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2476 fClearToBoundaryValuesIsBroken = true;
2477 }
2478#endif
2479 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2480 fDrawArraysBaseVertexIsBroken = true;
2481 }
2482
Brian Salomon01b476a2018-01-23 11:06:41 -05002483 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2484 // Galaxy S7.
2485 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2486 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2487 shaderCaps->fFBFetchSupport = false;
2488 }
2489
Brian Salomon01b476a2018-01-23 11:06:41 -05002490 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2491 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2492
2493 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2494 // function that may require a gradient calculation inside a conditional block may return
2495 // undefined results". This appears to be an issue with the 'any' call since even the simple
2496 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2497 // from our GrTextureDomain processor.
2498 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2499
2500 // Known issue on at least some Intel platforms:
2501 // http://code.google.com/p/skia/issues/detail?id=946
2502 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2503 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2504 }
2505
Chris Dalton0090ef62018-03-28 17:35:00 -06002506 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002507 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2508 // so we must do the abs first in a separate expression.
2509 shaderCaps->fCanUseMinAndAbsTogether = false;
2510
2511 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2512 // must avoid this condition.
2513 shaderCaps->fCanUseFractForNegativeValues = false;
2514 }
2515
2516 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2517 // thus must us -1.0 * %s.x to work correctly
2518 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2519 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2520 }
2521
2522 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2523 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2524 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2525 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2526 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2527 }
2528
2529 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2530 // the original dst color when reading the outColor even after being written to. By using a
2531 // local outColor we can work around this bug.
2532 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2533 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2534 }
2535
2536 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2537 // color, and that uniform contains an opaque color, and the output of the shader is only based
2538 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2539 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2540 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2541 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2542 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2543 shaderCaps->fMustObfuscateUniformColor = true;
2544 }
2545#ifdef SK_BUILD_FOR_WIN
2546 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2547 //
2548 // Basically, if a shader has a construct like:
2549 //
2550 // float x = someCondition ? someValue : 0;
2551 // float2 result = (0 == x) ? float2(x, x)
2552 // : float2(2 * x / x, 0);
2553 //
2554 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2555 // we've explicitly guarded the division with a check against zero. This manifests in much
2556 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2557 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2558 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2559 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2560 }
2561#endif
2562
2563 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002564 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002565 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2566 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002567 }
2568
Chris Dalton0090ef62018-03-28 17:35:00 -06002569 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2570 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2571 shaderCaps->fCanUseFragCoord = false;
2572 }
2573
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002574 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2575 // (Are they implemented with fp16?)
2576 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2577 shaderCaps->fIncompleteShortIntPrecision = true;
2578 }
2579
Brian Salomon01b476a2018-01-23 11:06:41 -05002580 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2581 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002582 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2583 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002584 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2585 kIntel_GrGLDriver == ctxInfo.driver() ||
2586 kChromium_GrGLDriver == ctxInfo.driver()) {
2587 fBlendEquationSupport = kBasic_BlendEquationSupport;
2588 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2589 }
2590
2591 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2592 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002593 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002594 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002595 fBlendEquationSupport = kBasic_BlendEquationSupport;
2596 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2597 }
2598
Adrienne Walker68314842018-05-14 14:02:53 -07002599 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2600 fBlendEquationSupport = kBasic_BlendEquationSupport;
2601 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2602 }
2603
Brian Salomon01b476a2018-01-23 11:06:41 -05002604 if (this->advancedBlendEquationSupport()) {
2605 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002606 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002607 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2608 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2609 (1 << kColorBurn_GrBlendEquation);
2610 }
2611 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2612 // Blacklist color-burn on ARM until the fix is released.
2613 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2614 }
2615 }
2616
2617 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2618 if (fMultisampleDisableSupport &&
2619 this->shaderCaps()->dualSourceBlendingSupport() &&
2620 this->shaderCaps()->pathRenderingSupport() &&
2621 fUsesMixedSamples &&
2622#if GR_TEST_UTILS
2623 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2624#endif
2625 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2626 kChromium_GrGLDriver == ctxInfo.driver())) {
2627 fDiscardRenderTargetSupport = false;
2628 fInvalidateFBType = kNone_InvalidateFBType;
2629 }
Brian Osmanc585e202018-04-04 14:08:27 -04002630
Brian Osman061020e2018-04-17 14:22:15 -04002631 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2632 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2633 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2634 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002635 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2636 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002637 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002638 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002639 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2640 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002641 }
Brian Osman2fa53742018-05-03 15:05:12 -04002642
2643#ifdef SK_BUILD_FOR_IOS
2644 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2645 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2646 // is to just blacklist the feature.
2647 // https://github.com/flutter/flutter/issues/16718
2648 // https://bugreport.apple.com/web/?problemID=39948888
2649 fUnpackRowLengthSupport = false;
2650#endif
Chris Daltona2b5b642018-06-24 13:08:57 -06002651
2652#ifdef SK_BUILD_FOR_MAC
2653 // Radeon MacBooks hit a crash in glReadPixels() when using CCPR.
2654 // http://skbug.com/8097
2655 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2656 fBlacklistCoverageCounting = true;
2657 }
2658#endif
Chris Daltonc4e72a42018-06-25 06:44:01 -06002659
2660 // "shapes_mixed_10000_32x33" bench crashes PowerVRGX6250 in Release mode with ccpr.
2661 // http://skbug.com/8098
2662 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2663 fBlacklistCoverageCounting = true;
2664 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002665}
2666
csmartdaltone0d36292016-07-29 08:14:20 -07002667void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002668 if (options.fDisableDriverCorrectnessWorkarounds) {
2669 SkASSERT(!fDoManualMipmapping);
2670 SkASSERT(!fClearToBoundaryValuesIsBroken);
2671 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2672 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2673 SkASSERT(!fUseDrawToClearColor);
2674 SkASSERT(!fUseDrawToClearStencilClip);
2675 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2676 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2677 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002678 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Salomon01b476a2018-01-23 11:06:41 -05002679 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002680 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2681 fUseDrawToClearColor = false;
2682 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2683 fUseDrawToClearColor = true;
2684 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002685 if (options.fDoManualMipmapping) {
2686 fDoManualMipmapping = true;
2687 }
csmartdaltone0d36292016-07-29 08:14:20 -07002688}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002689
Brian Salomon3d86a192018-02-27 16:46:11 -05002690bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2691 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2692 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2693 if (tex->hasBaseLevelBeenBoundToFBO()) {
2694 return false;
2695 }
2696 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002697 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002698 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2699 return false;
2700 }
2701 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2702 return false;
2703 }
2704 return SkToBool(surface->asTexture());
2705 }
2706 return true;
2707}
2708
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002709bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2710 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2711 // We don't support reading pixels directly from EXTERNAL textures as it would require
2712 // binding the texture to a FBO.
2713 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2714 return false;
2715 }
2716 }
2717 return true;
2718}
2719
2720GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2721 GrColorType dstColorType) const {
2722 // For now, we mostly report the read back format that is required by the ES spec without
2723 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2724 // this as makes sense to increase performance and correctness.
2725 switch (fConfigTable[config].fFormatType) {
2726 case kNormalizedFixedPoint_FormatType:
2727 return GrColorType::kRGBA_8888;
2728 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002729 if ((kAlpha_half_GrPixelConfig == config ||
2730 kAlpha_half_as_Red_GrPixelConfig == config) &&
2731 GrColorType::kAlpha_F16 == dstColorType) {
2732 return GrColorType::kAlpha_F16;
2733 }
2734 // And similar for full float RG.
2735 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2736 return GrColorType::kRG_F32;
2737 }
2738 return GrColorType::kRGBA_F32;
2739 }
2740 return GrColorType::kUnknown;
2741}
2742
Greg Daniel2a303902018-02-20 10:25:54 -05002743bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002744 GrGLFramebufferInfo fbInfo;
2745 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002746 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002747 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002748}
2749
Brian Salomonbdecacf2018-02-02 20:32:49 -05002750int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2751 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002752 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002753 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002754 return 0;
2755 }
2756
Brian Salomonbdecacf2018-02-02 20:32:49 -05002757 if (1 == requestedCount) {
2758 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2759 }
2760
Greg Daniel81e7bf82017-07-19 14:47:42 -04002761 for (int i = 0; i < count; ++i) {
2762 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002763 int count = fConfigTable[config].fColorSampleCounts[i];
2764 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2765 count = SkTMin(count, 4);
2766 }
2767 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002768 }
2769 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002770 return 0;
2771}
2772
2773int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2774 const auto& table = fConfigTable[config].fColorSampleCounts;
2775 if (!table.count()) {
2776 return 0;
2777 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002778 int count = table[table.count() - 1];
2779 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2780 count = SkTMin(count, 4);
2781 }
2782 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002783}
2784
Greg Danielfaa095e2017-12-19 13:15:02 -05002785bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2786 GrGLStandard standard) {
2787 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002788
2789 switch (ct) {
2790 case kUnknown_SkColorType:
2791 return false;
2792 case kAlpha_8_SkColorType:
2793 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002794 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002795 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002796 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002797 }
2798 break;
2799 case kRGB_565_SkColorType:
2800 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002801 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002802 }
2803 break;
2804 case kARGB_4444_SkColorType:
2805 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002806 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002807 }
2808 break;
2809 case kRGBA_8888_SkColorType:
2810 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002811 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002812 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002813 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002814 }
2815 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002816 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002817 if (GR_GL_RGB8 == format) {
2818 *config = kRGB_888_GrPixelConfig;
2819 }
2820 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002821 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002822 if (GR_GL_RGBA8 == format) {
2823 if (kGL_GrGLStandard == standard) {
2824 *config = kBGRA_8888_GrPixelConfig;
2825 }
2826 } else if (GR_GL_BGRA8 == format) {
2827 if (kGLES_GrGLStandard == standard) {
2828 *config = kBGRA_8888_GrPixelConfig;
2829 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002830 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002831 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002832 }
2833 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002834 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002835 if (GR_GL_RGB10_A2 == format) {
2836 *config = kRGBA_1010102_GrPixelConfig;
2837 }
2838 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002839 case kRGB_101010x_SkColorType:
2840 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002841 case kGray_8_SkColorType:
2842 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002843 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002844 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002845 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002846 }
2847 break;
2848 case kRGBA_F16_SkColorType:
2849 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002850 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002851 }
2852 break;
Mike Klein37854712018-06-26 11:43:06 -04002853 case kRGBA_F32_SkColorType:
2854 if (GR_GL_RGBA32F == format) {
2855 *config = kRGBA_float_GrPixelConfig;
2856 }
2857 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002858 }
2859
Greg Danielfaa095e2017-12-19 13:15:02 -05002860 return kUnknown_GrPixelConfig != *config;
2861}
2862
2863bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2864 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002865 GrGLTextureInfo texInfo;
2866 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002867 return false;
2868 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002869 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002870}
2871
2872bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2873 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002874 GrGLFramebufferInfo fbInfo;
2875 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002876 return false;
2877 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002878 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002879}
2880
Robert Phillipsfc711a22018-02-13 17:03:00 -05002881bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2882 GrPixelConfig* config) const {
2883 const GrGLenum* glFormat = format.getGLFormat();
2884 if (!glFormat) {
2885 return false;
2886 }
2887 return validate_sized_format(*glFormat, ct, config, fStandard);
2888}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002889
Timothy Liang036fdfe2018-06-28 15:50:36 -04002890#ifdef GR_TEST_UTILS
2891GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2892 const GrBackendTexture& backendTex) const {
2893 GrGLTextureInfo glInfo;
2894 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2895 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2896}
2897#endif