blob: 12d99087cdfd28c8ff7ed59141a149c51c225c0b [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) {
Ravi Mistry35b40ce2018-05-30 20:54:40 +0000223 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
kkinnunene06ed252016-02-16 23:15:40 -0800224 // We also require textureSize() support for rectangle 2D samplers which was added in
225 // GLSL 1.40.
226 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
227 fRectangleTextureSupport = true;
228 }
bsalomone179a912016-01-20 06:18:10 -0800229 }
kkinnunene06ed252016-02-16 23:15:40 -0800230 } else {
231 // Command buffer exposes this in GL ES context for Chromium reasons,
232 // but it should not be used. Also, at the time of writing command buffer
233 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800234 }
235
bsalomoncdee0092016-01-08 13:20:12 -0800236 if (kGL_GrGLStandard == standard) {
237 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
238 fTextureSwizzleSupport = true;
239 }
240 } else {
241 if (version >= GR_GL_VER(3,0)) {
242 fTextureSwizzleSupport = true;
243 }
244 }
245
cblume09bd2c02016-03-01 14:08:28 -0800246 if (kGL_GrGLStandard == standard) {
247 fMipMapLevelAndLodControlSupport = true;
248 } else if (kGLES_GrGLStandard == standard) {
249 if (version >= GR_GL_VER(3,0)) {
250 fMipMapLevelAndLodControlSupport = true;
251 }
252 }
253
bsalomon88c7b982015-07-31 11:20:16 -0700254#ifdef SK_BUILD_FOR_WIN
255 // We're assuming that on Windows Chromium we're using ANGLE.
256 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
257 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700258 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700259 fRGBA8888PixelsOpsAreSlow = isANGLE;
260 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
261 // check DX11 ANGLE.
262 fPartialFBOReadIsSlow = isANGLE;
263#endif
264
ericrkb4ecabd2016-03-11 15:18:20 -0800265 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
266 bool isMAC = false;
267#ifdef SK_BUILD_FOR_MAC
268 isMAC = true;
269#endif
270
271 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
272 // vis-versa.
273 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
274
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500275 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
276 fUseBufferDataNullHint = false;
277 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
278 fUseBufferDataNullHint = true;
279 }
280
Brian Salomond17b4a62017-05-23 16:53:47 -0400281 if (kGL_GrGLStandard == standard) {
282 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400283 fClearTextureSupport = true;
284 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500285 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
286 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400287 }
288
cdalton4cd67132015-06-10 19:23:46 -0700289 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700290 * GrShaderCaps fields
291 **************************************************************************/
292
egdaniel0a482332015-10-26 08:59:10 -0700293 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700294 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500295 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700296
Brian Osman195c05b2017-08-30 15:14:04 -0400297 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
298#if GR_TEST_UTILS
299 if (contextOptions.fSuppressPathRendering) {
300 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700301 }
Brian Osman195c05b2017-08-30 15:14:04 -0400302#endif
egdaniel05ded892015-10-26 07:38:05 -0700303
egdaniel05ded892015-10-26 07:38:05 -0700304 // Enable supported shader-related caps
305 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500306 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700307 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
Brian Salomon23c55b62018-06-19 16:28:41 -0400308 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600309
Brian Salomon1edc5b92016-11-29 13:43:46 -0500310 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600311
egdaniel05ded892015-10-26 07:38:05 -0700312 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500313 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700314 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600315 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600316 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
317 shaderCaps->fGSInvocationsSupport = true;
318 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
319 shaderCaps->fGSInvocationsSupport = true;
320 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
321 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600322 }
323
Brian Salomon1edc5b92016-11-29 13:43:46 -0500324 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800325 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500326 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500327 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700328
Brian Salomon1edc5b92016-11-29 13:43:46 -0500329 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700330 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800331
Chris Daltonfaca00d2018-01-19 15:56:07 -0700332 // Mali has support for geometry shaders, but in practice with ccpr they are slower than the
333 // backup impl that only uses vertex shaders.
334 if (kARM_GrGLVendor != ctxInfo.vendor()) {
335 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
336 shaderCaps->fGeometryShaderSupport = true;
337 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
338 shaderCaps->fGeometryShaderSupport = true;
339 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
340 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700341 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500342 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700343
Brian Salomon1edc5b92016-11-29 13:43:46 -0500344 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800345 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700346 }
347
cdalton9c3f1432016-03-11 10:07:37 -0800348 // Protect ourselves against tracking huge amounts of texture state.
349 static const uint8_t kMaxSaneSamplers = 32;
350 GrGLint maxSamplers;
351 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500352 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
353 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800354 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500355 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800356 }
357 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500358 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800359 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500360 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800361
Brian Salomonbbf05752017-11-30 11:30:48 -0500362 // This is all *very* approximate.
363 switch (ctxInfo.vendor()) {
364 case kNVIDIA_GrGLVendor:
365 // We've seen a range from 100 x 100 (TegraK1, GTX660) up to 300 x 300 (GTX 1070)
366 // but it doesn't clearly align with Pascal vs Maxwell vs Kepler.
367 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 150 * 150;
368 break;
Brian Salomon64fa70a2017-11-30 11:56:25 -0500369 case kImagination_GrGLVendor:
370 // Two PowerVR Rogues, Nexus Player and Chromebook Cb5-312T (PowerVR GX6250), show that
371 // it is always a win to use multitexturing.
372 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
373 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold =
374 std::numeric_limits<size_t>::max();
375 }
376 break;
Brian Salomon0c56d472017-12-04 08:37:44 -0500377 case kATI_GrGLVendor:
378 // So far no AMD GPU shows a performance difference. A tie goes to disabling
379 // multitexturing for simplicity's sake.
380 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 0;
381 break;
Brian Salomonbbf05752017-11-30 11:30:48 -0500382 default:
383 break;
384 }
385
csmartdalton485a1202016-07-13 10:16:32 -0700386 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
387 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
388 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
389 // limit this decision to specific GPU families rather than basing it on the vendor alone.
390 if (!GR_GL_MUST_USE_VBO &&
391 !fIsCoreProfile &&
392 (kARM_GrGLVendor == ctxInfo.vendor() ||
393 kImagination_GrGLVendor == ctxInfo.vendor() ||
394 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
395 fPreferClientSideDynamicBuffers = true;
396 }
397
Eric Karl5c779752017-05-08 12:02:07 -0700398 if (!contextOptions.fAvoidStencilBuffers) {
399 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
400 this->initFSAASupport(contextOptions, ctxInfo, gli);
401 this->initStencilSupport(ctxInfo);
402 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400403
404 // Setup blit framebuffer
405 if (kGL_GrGLStandard != ctxInfo.standard()) {
406 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
407 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
408 kNoMSAADst_BlitFramebufferFlag |
409 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
410 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
411 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
412 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
413 // limitations.
414 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
415 kResolveMustBeFull_BlitFrambufferFlag |
416 kNoMSAADst_BlitFramebufferFlag |
417 kNoFormatConversion_BlitFramebufferFlag |
418 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
419 }
420 } else {
421 if (fUsesMixedSamples ||
422 ctxInfo.version() >= GR_GL_VER(3,0) ||
423 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
424 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
425 fBlitFramebufferFlags = 0;
426 }
427 }
428
cdalton1dd05422015-06-12 09:01:18 -0700429 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000430
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000431 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000432 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
433 // extension includes glMapBuffer.
434 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
435 fMapBufferFlags |= kSubset_MapFlag;
436 fMapBufferType = kMapBufferRange_MapBufferType;
437 } else {
438 fMapBufferType = kMapBuffer_MapBufferType;
439 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000440 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000441 // Unextended GLES2 doesn't have any buffer mapping.
442 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800443 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800444 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
445 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800446 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
447 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
448 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000449 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
450 fMapBufferFlags = kCanMap_MapFlag;
451 fMapBufferType = kMapBuffer_MapBufferType;
452 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000453 }
454
jvanverthd7a2c1f2015-12-07 07:36:44 -0800455 if (kGL_GrGLStandard == standard) {
456 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
457 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700458 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500459 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400460 if (version >= GR_GL_VER(3, 0) ||
461 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
462 // GL_EXT_unpack_subimage needed to support subtexture rectangles
463 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800464 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400465// TODO: get transfer buffers working in Chrome
466// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
467// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800468 }
469 }
470
joshualitte5b74c62015-06-01 14:17:47 -0700471 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
472 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700473 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700474#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500475 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
476 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
477 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700478 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700479#else
cdalton397536c2016-03-25 12:15:03 -0700480 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700481#endif
joshualitte5b74c62015-06-01 14:17:47 -0700482 }
483
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000484 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000485 fNPOTTextureTileSupport = true;
486 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000487 } else {
488 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000489 // ES3 has no limitations.
490 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
491 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000492 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
493 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
494 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
495 // to alllow arbitrary wrap modes, however.
496 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000497 }
498
bsalomon@google.combcce8922013-03-25 15:38:39 +0000499 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700500
501 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
502 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
503 }
504
bsalomon@google.combcce8922013-03-25 15:38:39 +0000505 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
506 // Our render targets are always created with textures as the color
507 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000508 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700509 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
510
511 if (kARM_GrGLVendor == ctxInfo.vendor()) {
512 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
513 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
514 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000515
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000516 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
517
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000518 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700519 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000520
robertphillips1b8e1b52015-06-24 06:54:10 -0700521#if 0
522 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
523 kQualcomm_GrGLVendor != ctxInfo.vendor();
524#endif
525
csmartdalton9bc11872016-08-09 12:42:47 -0700526 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
527 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700528 }
529
robertphillips63926682015-08-20 09:39:02 -0700530#ifdef SK_BUILD_FOR_WIN
531 // On ANGLE deferring flushes can lead to GPU starvation
532 fPreferVRAMUseOverFlushes = !isANGLE;
533#endif
534
bsalomon7dea7b72015-08-19 08:26:51 -0700535 if (kChromium_GrGLDriver == ctxInfo.driver()) {
536 fMustClearUploadedBufferData = true;
537 }
538
bsalomond08ea5f2015-02-20 06:58:13 -0800539 if (kGL_GrGLStandard == standard) {
540 // ARB allows mixed size FBO attachments, EXT does not.
541 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
542 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
543 fOversizedStencilSupport = true;
544 } else {
545 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
546 }
547 } else {
548 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
549 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
550 }
551
joshualitt58001552015-06-26 12:46:36 -0700552 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700553 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
554 ctxInfo.hasExtension("GL_ARB_draw_indirect");
555 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
556 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700557 (fDrawIndirectSupport &&
558 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700559 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700560 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800561 } else {
562 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700563 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
564 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
565 fBaseInstanceSupport = fDrawIndirectSupport &&
566 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700567 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800568 }
569
ethannicholas28ef4452016-03-25 09:26:03 -0700570 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500571 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700572 fSampleShadingSupport = true;
573 }
574 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
575 fSampleShadingSupport = true;
576 }
577
jvanverth84741b32016-09-30 08:39:02 -0700578 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
579 if (kGL_GrGLStandard == standard) {
580 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
581 fFenceSyncSupport = true;
582 }
Brian Osman93a23462017-06-21 15:13:39 -0400583 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700584 fFenceSyncSupport = true;
585 }
586
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400587 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500588 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500589
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400590 if (kGL_GrGLStandard == standard) {
591 if (version >= GR_GL_VER(4, 1)) {
592 fProgramBinarySupport = true;
593 }
594 } else if (version >= GR_GL_VER(3, 0)) {
595 fProgramBinarySupport = true;
596 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400597 if (fProgramBinarySupport) {
598 GrGLint count;
599 GR_GL_GetIntegerv(gli, GR_GL_NUM_SHADER_BINARY_FORMATS, &count);
600 fProgramBinarySupport = count > 0;
601 }
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400602
bsalomoncdee0092016-01-08 13:20:12 -0800603 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
604 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800605 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700606
Brian Salomon01b476a2018-01-23 11:06:41 -0500607 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
608 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
609 }
610
cdalton4cd67132015-06-10 19:23:46 -0700611 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500612 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700613
Brian Salomon01b476a2018-01-23 11:06:41 -0500614 // For now these two are equivalent but we could have dst read in shader via some other method.
615 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000616}
617
egdaniel472d44e2015-10-22 08:20:00 -0700618const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
619 bool isCoreProfile) {
620 switch (generation) {
621 case k110_GrGLSLGeneration:
622 if (kGLES_GrGLStandard == standard) {
623 // ES2s shader language is based on version 1.20 but is version
624 // 1.00 of the ES language.
625 return "#version 100\n";
626 } else {
627 SkASSERT(kGL_GrGLStandard == standard);
628 return "#version 110\n";
629 }
630 case k130_GrGLSLGeneration:
631 SkASSERT(kGL_GrGLStandard == standard);
632 return "#version 130\n";
633 case k140_GrGLSLGeneration:
634 SkASSERT(kGL_GrGLStandard == standard);
635 return "#version 140\n";
636 case k150_GrGLSLGeneration:
637 SkASSERT(kGL_GrGLStandard == standard);
638 if (isCoreProfile) {
639 return "#version 150\n";
640 } else {
641 return "#version 150 compatibility\n";
642 }
643 case k330_GrGLSLGeneration:
644 if (kGLES_GrGLStandard == standard) {
645 return "#version 300 es\n";
646 } else {
647 SkASSERT(kGL_GrGLStandard == standard);
648 if (isCoreProfile) {
649 return "#version 330\n";
650 } else {
651 return "#version 330 compatibility\n";
652 }
653 }
cdalton33ad7012016-02-22 07:55:44 -0800654 case k400_GrGLSLGeneration:
655 SkASSERT(kGL_GrGLStandard == standard);
656 if (isCoreProfile) {
657 return "#version 400\n";
658 } else {
659 return "#version 400 compatibility\n";
660 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500661 case k420_GrGLSLGeneration:
662 SkASSERT(kGL_GrGLStandard == standard);
663 if (isCoreProfile) {
664 return "#version 420\n";
665 }
666 else {
667 return "#version 420 compatibility\n";
668 }
egdaniel472d44e2015-10-22 08:20:00 -0700669 case k310es_GrGLSLGeneration:
670 SkASSERT(kGLES_GrGLStandard == standard);
671 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800672 case k320es_GrGLSLGeneration:
673 SkASSERT(kGLES_GrGLStandard == standard);
674 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700675 }
676 return "<no version>";
677}
678
Chris Dalton47c8ed32017-11-15 18:27:09 -0700679bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
680 if (kGLES_GrGLStandard != ctxInfo.standard() &&
681 ctxInfo.version() < GR_GL_VER(4,1) &&
682 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
683 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
684 return true;
685 }
686 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
687 // geometry shaders don't have lower precision than vertex and fragment.
688 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
689 GrGLint range[2];
690 GrGLint bits;
691 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
692 if (range[0] < 127 || range[1] < 127 || bits < 23) {
693 return false;
694 }
695 }
696 return true;
697}
698
699void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700700 GrGLStandard standard = ctxInfo.standard();
701 GrGLVersion version = ctxInfo.version();
702
703 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500704 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700705 **************************************************************************/
706
Brian Salomon1edc5b92016-11-29 13:43:46 -0500707 GrShaderCaps* shaderCaps = fShaderCaps.get();
708 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700709 if (kGLES_GrGLStandard == standard) {
710 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500711 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
712 shaderCaps->fFBFetchSupport = true;
713 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
714 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700715 }
716 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
717 // 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 -0500718 shaderCaps->fFBFetchNeedsCustomOutput = false;
719 shaderCaps->fFBFetchSupport = true;
720 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
721 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700722 }
723 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
724 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500725 shaderCaps->fFBFetchNeedsCustomOutput = false;
726 shaderCaps->fFBFetchSupport = true;
727 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
728 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700729 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500730 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700731 }
732
cdaltonc08f1962016-02-12 12:14:06 -0800733 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500734 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800735 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500736 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800737 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
738 }
Brian Salomon41274562017-09-15 09:40:03 -0700739 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
740 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
741 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800742 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500743 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800744 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
745 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400746 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
747 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500748 shaderCaps->fNoPerspectiveInterpolationSupport = true;
749 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800750 "GL_NV_shader_noperspective_interpolation";
751 }
752 }
753
Brian Salomon1edc5b92016-11-29 13:43:46 -0500754 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
755 shaderCaps->fGLSLGeneration,
756 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800757
Brian Salomon1edc5b92016-11-29 13:43:46 -0500758 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
759 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800760 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800761
762 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500763 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800764 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
765 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500766 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800767 }
768
769 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500770 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800771 }
772
cdalton9c3f1432016-03-11 10:07:37 -0800773 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400774 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
775 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400776 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400777 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
778 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
779 // At least one driver has been found that has this extension without the "GL_" prefix.
780 shaderCaps->fExternalTextureSupport = true;
781 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800782 }
783 }
784
cdaltonc04ce672016-03-11 14:07:38 -0800785 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500786 shaderCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800787 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500788 shaderCaps->fTexelFetchSupport =
cdaltonf8a6ce82016-04-11 13:02:05 -0700789 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
790 }
791
Brian Salomon1edc5b92016-11-29 13:43:46 -0500792 if (shaderCaps->fTexelFetchSupport) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700793 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500794 shaderCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
cdaltonf8a6ce82016-04-11 13:02:05 -0700795 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
796 } else {
797 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
798 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500799 shaderCaps->fTexelBufferSupport = true;
cdaltonf8a6ce82016-04-11 13:02:05 -0700800 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500801 shaderCaps->fTexelBufferSupport = true;
802 shaderCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700803 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500804 shaderCaps->fTexelBufferSupport = true;
805 shaderCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700806 }
cdaltonc04ce672016-03-11 14:07:38 -0800807 }
808 }
809
Chris Dalton1d616352017-05-31 12:51:23 -0600810 if (kGL_GrGLStandard == standard) {
811 shaderCaps->fVertexIDSupport = true;
812 } else {
813 // Desktop GLSL 3.30 == ES GLSL 3.00.
814 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
815 }
816
Chris Dalton7c7ff032018-03-28 20:09:58 -0600817 if (kGL_GrGLStandard == standard) {
818 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
819 } else {
820 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
821 }
822
Chris Dalton47c8ed32017-11-15 18:27:09 -0700823 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
824 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
egdaniel472d44e2015-10-22 08:20:00 -0700825}
826
kkinnunencfe62e32015-07-01 02:58:50 -0700827bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700828 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
829
830 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700831 return false;
832 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700833
kkinnunencfe62e32015-07-01 02:58:50 -0700834 if (kGL_GrGLStandard == ctxInfo.standard()) {
835 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
836 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
837 return false;
838 }
839 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700840 if (!hasChromiumPathRendering &&
841 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700842 return false;
843 }
844 }
845 // We only support v1.3+ of GL_NV_path_rendering which allows us to
846 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
847 // additions are detected by checking the existence of the function.
848 // We also use *Then* functions that not all drivers might have. Check
849 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800850 if (!gli->fFunctions.fStencilThenCoverFillPath ||
851 !gli->fFunctions.fStencilThenCoverStrokePath ||
852 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
853 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
854 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700855 return false;
856 }
857 return true;
858}
bsalomon1aa20292016-01-22 08:16:09 -0800859
Brian Salomon71d9d842016-11-03 13:42:00 -0400860bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800861 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800862 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800863 std::function<bool ()> bindRenderTarget,
864 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400865 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800866 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400867 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800868 return false;
869 }
bsalomon7928ef62016-01-05 10:26:39 -0800870
bsalomon76148af2016-01-12 11:13:47 -0800871 GrGLenum readFormat;
872 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400873 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800874 return false;
875 }
876
bsalomon1aa20292016-01-22 08:16:09 -0800877 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800878 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
879 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
880 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
881 // 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 -0500882 // The manual does not seem to fully match the spec as the spec allows integer formats
883 // when the bound color buffer is an integer buffer. It doesn't specify which integer
884 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500885 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
886 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
887 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800888 return false;
889 }
890 // There is also a set of allowed types, but all the types we use are in the set:
891 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
892 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
893 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
894 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
895 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
896 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
897 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800898 return true;
piotaixre4b23142014-10-02 10:57:53 -0700899 }
bsalomon7928ef62016-01-05 10:26:39 -0800900
bsalomon76148af2016-01-12 11:13:47 -0800901 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500902 switch (fConfigTable[surfaceConfig].fFormatType) {
903 case kNormalizedFixedPoint_FormatType:
904 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
905 return true;
906 }
907 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500908 case kFloat_FormatType:
909 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
910 return true;
911 }
912 break;
bsalomon7928ef62016-01-05 10:26:39 -0800913 }
914
Brian Salomon71d9d842016-11-03 13:42:00 -0400915 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800916 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400917 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800918 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800919 if (!bindRenderTarget()) {
920 return false;
921 }
922 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
923 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800924 rpFormat->fFormat = format;
925 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800926 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800927 }
928
Brian Salomon71d9d842016-11-03 13:42:00 -0400929 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
930 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700931}
932
Eric Karl5c779752017-05-08 12:02:07 -0700933void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
934 const GrGLInterface* gli) {
935 // We need dual source blending and the ability to disable multisample in order to support mixed
936 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
937 // renderer is available and enabled; no other path renderers support this feature.
938 if (fMultisampleDisableSupport &&
939 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400940 this->shaderCaps()->pathRenderingSupport()
941#if GR_TEST_UTILS
942 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
943#endif
944 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700945 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400946 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700947 }
948
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000949 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400950 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
951 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
952 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
953 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
954 fAlpha8IsRenderable = true;
955 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500956 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
957 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
958 // mixed samples we can't use multisampled-render-to-texture.
959 if (fUsesMixedSamples) {
960 fMSFBOType = kMixedSamples_MSFBOType;
961 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000962 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
963 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
964 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400965 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
966 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400967 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400968 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400969 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400970 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000971 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
972 fMSFBOType = kES_Apple_MSFBOType;
973 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000974 } else {
egdanieleed519e2016-01-15 11:36:18 -0800975 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700976 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400977 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
978 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400979
Brian Salomon00731b42016-10-14 11:30:51 -0400980 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400981 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
982 // Core profile removes ALPHA8 support.
983 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
984 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
985 // present.
986 fAlpha8IsRenderable = true;
987 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000988 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
989 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400990 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000991 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000992 }
Eric Karl5c779752017-05-08 12:02:07 -0700993
Brian Salomon01b476a2018-01-23 11:06:41 -0500994 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400995 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
996 fMSFBOType = kNone_MSFBOType;
997 }
998
Eric Karl5c779752017-05-08 12:02:07 -0700999 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
1000 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
1001 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -07001002 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001003}
1004
cdalton1dd05422015-06-12 09:01:18 -07001005void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001006 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -07001007
Greg Daniel210883c2017-11-27 15:14:01 -05001008 bool layoutQualifierSupport = false;
1009 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
1010 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
1011 layoutQualifierSupport = true;
1012 }
1013
cdalton1dd05422015-06-12 09:01:18 -07001014 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1015 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001016 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001017 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
1018 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001019 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001020 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001021 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1022 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001023 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001024 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001025 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001026 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001027 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1028 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -07001029 }
cdalton1dd05422015-06-12 09:01:18 -07001030}
1031
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001032namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001033const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001034}
1035
Eric Karl5c779752017-05-08 12:02:07 -07001036void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001037
1038 // Build up list of legal stencil formats (though perhaps not supported on
1039 // the particular gpu/driver) from most preferred to least.
1040
1041 // these consts are in order of most preferred to least preferred
1042 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1043
1044 static const StencilFormat
1045 // internal Format stencil bits total bits packed?
1046 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1047 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1048 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1049 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001050 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001051 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1052
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001053 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001054 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001055 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001056 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1057 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1058
1059 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1060 // require FBO support we can expect these are legal formats and don't
1061 // check. These also all support the unsized GL_STENCIL_INDEX.
1062 fStencilFormats.push_back() = gS8;
1063 fStencilFormats.push_back() = gS16;
1064 if (supportsPackedDS) {
1065 fStencilFormats.push_back() = gD24S8;
1066 }
1067 fStencilFormats.push_back() = gS4;
1068 if (supportsPackedDS) {
1069 fStencilFormats.push_back() = gDS;
1070 }
1071 } else {
1072 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1073 // for other formats.
1074 // ES doesn't support using the unsized format.
1075
1076 fStencilFormats.push_back() = gS8;
1077 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001078 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1079 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001080 fStencilFormats.push_back() = gD24S8;
1081 }
1082 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1083 fStencilFormats.push_back() = gS4;
1084 }
1085 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001086}
1087
Brian Osman71a18892017-08-10 10:23:25 -04001088void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001089
Brian Osman71a18892017-08-10 10:23:25 -04001090 // We are called by the base class, which has already called beginObject(). We choose to nest
1091 // all of our caps information in a named sub-object.
1092 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001093
Brian Osman71a18892017-08-10 10:23:25 -04001094 writer->beginArray("Stencil Formats");
1095
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001096 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001097 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001098 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1099 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1100 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001101 }
1102
Brian Osman71a18892017-08-10 10:23:25 -04001103 writer->endArray();
1104
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001105 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001106 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001107 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001108 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001109 "IMG MS To Texture",
1110 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001111 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001112 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001113 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001114 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1115 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1116 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1117 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1118 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001119 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001120
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001121 static const char* kInvalidateFBTypeStr[] = {
1122 "None",
1123 "Discard",
1124 "Invalidate",
1125 };
1126 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1127 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1128 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1129 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001130
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001131 static const char* kMapBufferTypeStr[] = {
1132 "None",
1133 "MapBuffer",
1134 "MapBufferRange",
1135 "Chromium",
1136 };
1137 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1138 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1139 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1140 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1141 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1142
Brian Osman71a18892017-08-10 10:23:25 -04001143 writer->appendBool("Core Profile", fIsCoreProfile);
1144 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1145 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1146 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1147 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1148 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1149 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1150 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1151 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001152
Brian Osman71a18892017-08-10 10:23:25 -04001153 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001154 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1155 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1156 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001157 writer->appendBool("Debug support", fDebugSupport);
1158 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1159 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1160 writer->appendBool("Base instance support", fBaseInstanceSupport);
1161 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1162 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1163 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1164 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1165 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1166 writer->appendBool("BGRA to RGBA readback conversions are slow",
1167 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001168 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001169 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1170 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001171 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1172 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1173 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1174 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001175 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1176 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001177
Brian Osman71a18892017-08-10 10:23:25 -04001178 writer->beginArray("configs");
1179
bsalomon41e4384e2016-01-08 09:12:44 -08001180 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001181 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001182 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1183 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1184 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001185 writer->appendHexU32("e_format_read_pixels",
1186 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001187 writer->appendHexU32(
1188 "e_format_teximage",
1189 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1190 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1191 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1192 writer->appendHexU32("i_for_renderbuffer",
1193 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1194 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001195 }
1196
Brian Osman71a18892017-08-10 10:23:25 -04001197 writer->endArray();
1198 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001199}
1200
bsalomon41e4384e2016-01-08 09:12:44 -08001201bool GrGLCaps::bgraIsInternalFormat() const {
1202 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1203}
1204
bsalomon76148af2016-01-12 11:13:47 -08001205bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1206 GrGLenum* internalFormat, GrGLenum* externalFormat,
1207 GrGLenum* externalType) const {
1208 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1209 externalFormat, externalType)) {
1210 return false;
1211 }
1212 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1213 return true;
1214}
1215
bsalomon76148af2016-01-12 11:13:47 -08001216bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1217 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001218 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001219 externalFormat, externalType)) {
1220 return false;
1221 }
1222 return true;
1223}
1224
1225bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001226 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1227 return true;
1228}
1229
1230bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1231 ExternalFormatUsage usage, GrGLenum* externalFormat,
1232 GrGLenum* externalType) const {
1233 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001234
1235 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1236 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1237
1238 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001239 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1240 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001241 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1242 return false;
1243 }
1244
1245 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1246 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1247
bsalomone9573312016-01-25 14:33:25 -08001248 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1249 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1250 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1251 // texture, not the red component.
1252 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001253 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001254 *externalFormat = GR_GL_ALPHA;
1255 }
1256 }
1257
bsalomon76148af2016-01-12 11:13:47 -08001258 return true;
1259}
1260
brianosman20471892016-12-02 06:43:32 -08001261void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1262 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001263 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001264 /*
1265 Comments on renderability of configs on various GL versions.
1266 OpenGL < 3.0:
1267 no built in support for render targets.
1268 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1269 format RGB, RGBA and NV float formats we don't use.
1270 This is the following:
1271 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1272 RGB10_A2, RGBA12,RGBA16
1273 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1274 since they aren't required by later standards and the driver can simply return
1275 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1276 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1277 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1278 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1279 This adds a lot of additional renderable sized formats, including ALPHA8.
1280 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1281 16F, 32I, 32UI, and 32F variants).
1282 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1283
1284 For both the above extensions we limit ourselves to those that are also required by
1285 OpenGL 3.0.
1286
1287 OpenGL 3.0:
1288 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1289 but are not required to be supported as renderable textures/renderbuffer.
1290 Required renderable color formats:
1291 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1292 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1293 RGB10_A2.
1294 - R11F_G11F_B10F.
1295 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1296 and RG8UI.
1297 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1298 - ALPHA8
1299
1300 OpenGL 3.1, 3.2, 3.3
1301 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1302 OpengGL 3.3, 4.0, 4.1
1303 Adds RGB10_A2UI.
1304 OpengGL 4.2
1305 Adds
1306 - RGB5_A1, RGBA4
1307 - RGB565
1308 OpenGL 4.4
1309 Does away with the separate list and adds a column to the sized internal color format
1310 table. However, no new formats become required color renderable.
1311
1312 ES 2.0
1313 color renderable: RGBA4, RGB5_A1, RGB565
1314 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1315 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1316 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1317 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1318 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1319 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1320
1321 ES 3.0
1322 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1323 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1324 RGB5_A1.
1325 - RGB8 and RGB565.
1326 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1327 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1328 ES 3.1
1329 Adds RGB10_A2, RGB10_A2UI,
1330 ES 3.2
1331 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1332 */
Brian Salomon44804c02018-01-23 16:51:28 -05001333
1334 // Correctness workarounds.
1335 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001336 bool disableSRGBForX86PowerVR = false;
1337 bool disableSRGBWriteControlForAdreno4xx = false;
1338 bool disableR8TexStorageForANGLEGL = false;
1339 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001340 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001341 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001342
1343 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1344 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1345 // and GL_RG on FBO textures.
1346 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1347
Greg Daniel09c94002018-06-08 22:11:51 +00001348 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1349
Brian Salomon44804c02018-01-23 16:51:28 -05001350 bool isX86PowerVR = false;
1351#if defined(SK_CPU_X86)
1352 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1353 isX86PowerVR = true;
1354 }
1355#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001356 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1357 // blacklist that device (and any others that might be sharing the same driver).
1358 disableSRGBForX86PowerVR = isX86PowerVR;
1359 disableSRGBWriteControlForAdreno4xx = kAdreno4xx_GrGLRenderer == ctxInfo.renderer();
1360
1361 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1362 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1363 // check that we are not going to OpenGL.
1364 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1365
1366 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1367#if defined(SK_BUILD_FOR_MAC)
1368 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1369#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001370 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1371 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001372 }
1373
Brian Salomon71d9d842016-11-03 13:42:00 -04001374 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1375 ConfigInfo::kFBOColorAttachment_Flag;
1376 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001377 if (kNone_MSFBOType != fMSFBOType) {
1378 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1379 }
bsalomon41e4384e2016-01-08 09:12:44 -08001380 GrGLStandard standard = ctxInfo.standard();
1381 GrGLVersion version = ctxInfo.version();
1382
cblume790d5132016-02-29 11:13:29 -08001383 bool texStorageSupported = false;
1384 if (kGL_GrGLStandard == standard) {
1385 // The EXT version can apply to either GL or GLES.
1386 texStorageSupported = version >= GR_GL_VER(4,2) ||
1387 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1388 ctxInfo.hasExtension("GL_EXT_texture_storage");
1389 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001390 texStorageSupported = version >= GR_GL_VER(3,0) ||
1391 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001392 }
1393
cdalton74b8d322016-04-11 14:47:28 -07001394 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1395
Brian Salomone609e812018-01-17 14:00:47 -05001396 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001397
1398 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001399 if (kGL_GrGLStandard == standard) {
1400 textureRedSupport =
1401 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1402 } else {
1403 textureRedSupport =
1404 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1405 }
1406 }
1407
bsalomon30447372015-12-21 09:03:05 -08001408 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1409 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001410 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001411 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001412 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001413 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001414
1415 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1416 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001417 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001418 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001419 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001420 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001421 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1422 if (kGL_GrGLStandard == standard) {
1423 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1424 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001425 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001426 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1427 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1428 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1429 }
egdaniel4999df82016-01-07 17:06:04 -08001430 }
cblume790d5132016-02-29 11:13:29 -08001431 if (texStorageSupported) {
1432 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1433 }
cdalton74b8d322016-04-11 14:47:28 -07001434 if (texelBufferSupport) {
1435 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1436 }
bsalomoncdee0092016-01-08 13:20:12 -08001437 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001438
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001439 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1440 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1441 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1442 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1443 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1444 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1445 // supportedReadPixelsColorType never returns it.
1446 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1447 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1448 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1449 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1450 if (kGL_GrGLStandard == standard) {
1451 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1452 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1453 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1454 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1455 // becomes an issue.
1456 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1457 // but we don't support that just for simplicity's sake.
1458 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1459 } else {
1460 // 3.0 and the extension support this as a render buffer format.
1461 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1462 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1463 }
1464 }
1465 if (texStorageSupported) {
1466 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1467 }
1468 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1469 if (disableRGB8ForMali400) {
1470 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1471 }
1472
1473 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001474 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001475 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001476 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001477
1478 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1479 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1480 // GL_EXT_texture_format_BGRA8888.
1481 bool supportsBGRATexStorage = false;
1482
bsalomon41e4384e2016-01-08 09:12:44 -08001483 if (kGL_GrGLStandard == standard) {
1484 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1485 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1486 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1487 // Since the internal format is RGBA8, it is also renderable.
1488 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1489 allRenderFlags;
1490 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001491 // Since we are using RGBA8 we can use tex storage.
1492 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001493 } else {
1494 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1495 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001496 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1497 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1498 nonMSAARenderFlags;
1499
1500 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1501 supportsBGRATexStorage = true;
1502 }
1503 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1504 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1505 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1506 ConfigInfo::kRenderableWithMSAA_Flag;
1507 }
1508 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001509 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1510 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1511 // driver remembers the external format when the texture is created (with TexImage).
1512 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1513 // We could work around this, but it adds even more state tracking to code that is
1514 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1515 // This also side-steps some ambiguous interactions with the texture storage extension.
1516 if (version >= GR_GL_VER(3,0)) {
1517 // The APPLE extension doesn't make this renderable.
1518 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001519 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001520 }
bsalomon41e4384e2016-01-08 09:12:44 -08001521 }
1522 }
Brian Osman48c99192017-06-02 08:45:06 -04001523
Greg Daniel0ff79b22018-02-15 12:33:33 -05001524 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001525 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001526 }
bsalomoncdee0092016-01-08 13:20:12 -08001527 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001528
Brian Osman2b23c4b2018-06-01 12:25:08 -04001529 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001530 if (kGL_GrGLStandard == standard) {
1531 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001532 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001533 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1534 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1535 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001536 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001537 }
1538 }
1539 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001540 if (fSRGBSupport) {
1541 fSRGBWriteControl = true;
1542 }
bsalomon41e4384e2016-01-08 09:12:44 -08001543 } else {
brianosman20471892016-12-02 06:43:32 -08001544 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001545 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001546 fSRGBSupport = false;
1547 }
bsalomon41e4384e2016-01-08 09:12:44 -08001548 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1549 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001550 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001551 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001552 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001553 }
brianosman20471892016-12-02 06:43:32 -08001554
1555 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1556 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1557 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1558 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1559 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1560 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1561 // affects Windows.
1562 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1563 fSRGBSupport = false;
1564 }
1565
Brian Osman48c99192017-06-02 08:45:06 -04001566 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1567 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1568 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1569
Brian Osman67999392017-05-31 16:19:34 -04001570 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001571 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001572 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1573 }
Brian Osman67999392017-05-31 16:19:34 -04001574
bsalomon30447372015-12-21 09:03:05 -08001575 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1576 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1577 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1578 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001579 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001580 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001581 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001582 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001583 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001584 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001585 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001586 }
Brian Osman48c99192017-06-02 08:45:06 -04001587 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1588 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001589 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1590 }
bsalomoncdee0092016-01-08 13:20:12 -08001591 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001592 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1593 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1594 // is in this format, for example).
1595 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1596 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1597 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1598 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001599 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001600 GR_GL_BGRA;
1601 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1602 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001603 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001604 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001605 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001606 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001607
brianosmana6359362016-03-21 06:55:37 -07001608 if (texStorageSupported) {
1609 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1610 }
1611 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1612
bsalomon30447372015-12-21 09:03:05 -08001613 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1614 if (this->ES2CompatibilitySupport()) {
1615 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1616 } else {
1617 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1618 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001619 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001620 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001621 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001622 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001623 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1624 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001625 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001626 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1627 }
1628 } else {
1629 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1630 }
cblume790d5132016-02-29 11:13:29 -08001631 // 565 is not a sized internal format on desktop GL. So on desktop with
1632 // 565 we always use an unsized internal format to let the system pick
1633 // the best sized format to convert the 565 data to. Since TexStorage
1634 // only allows sized internal formats we disallow it.
1635 //
1636 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1637 // update.
1638 if (texStorageSupported && kGL_GrGLStandard != standard) {
1639 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1640 }
bsalomoncdee0092016-01-08 13:20:12 -08001641 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001642
1643 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1644 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001645 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001646 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001647 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001648 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001649 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1650 if (kGL_GrGLStandard == standard) {
1651 if (version >= GR_GL_VER(4, 2)) {
1652 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1653 }
1654 } else {
1655 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1656 }
cblume790d5132016-02-29 11:13:29 -08001657 if (texStorageSupported) {
1658 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1659 }
bsalomoncdee0092016-01-08 13:20:12 -08001660 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001661
Brian Osman10fc6fd2018-03-02 11:01:10 -05001662 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1663 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001664 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001665 GR_GL_RGBA;
1666 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1667 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1668 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1669 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1670 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1671 allRenderFlags;
1672 }
1673 if (texStorageSupported) {
1674 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1675 }
1676 if (texelBufferSupport) {
1677 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1678 }
1679 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1680
Greg Danielef59d872017-11-17 16:47:21 -05001681 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1682 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1683
1684 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1685 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1686 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1687 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1688 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001689 }
Greg Danielef59d872017-11-17 16:47:21 -05001690 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1691 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001692 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001693 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1694 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1695 alphaInfo.fFlags |= allRenderFlags;
1696 }
1697
1698 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1699 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1700 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1701 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1702 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001703 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001704 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001705
Brian Osman48c99192017-06-02 08:45:06 -04001706 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1707 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001708 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001709 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1710 }
1711 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1712 }
1713
Brian Salomone609e812018-01-17 14:00:47 -05001714 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001715 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
1716 if (texelBufferSupport) {
1717 redInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1718 }
1719
1720 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1721 } else {
1722 redInfo.fFlags = 0;
1723
1724 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001725 }
bsalomon41e4384e2016-01-08 09:12:44 -08001726
Greg Daniel7af060a2017-12-05 16:27:11 -05001727 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1728 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1729 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1730 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1731 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001732 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001733 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1734 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1735 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1736 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001737 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001738
1739 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1740 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1741 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1742 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1743 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001744 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001745 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1746 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1747
Greg Daniel09c94002018-06-08 22:11:51 +00001748 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1749 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1750 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1751 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1752 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001753 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1754 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1755 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001756 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001757 }
Brian Osman48c99192017-06-02 08:45:06 -04001758 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001759 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001760 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1761 }
1762 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1763 }
1764
Brian Salomone609e812018-01-17 14:00:47 -05001765 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001766 if (texelBufferSupport) {
1767 grayRedInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1768 }
1769 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1770 } else {
1771 grayRedInfo.fFlags = 0;
1772 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001773 }
1774
bsalomon41e4384e2016-01-08 09:12:44 -08001775 // Check for [half] floating point texture support
1776 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1777 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1778 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1779 bool hasFPTextures = false;
1780 bool hasHalfFPTextures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001781 bool rgIsTexturable = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001782 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001783 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001784
1785 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001786 if (version >= GR_GL_VER(3, 0)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001787 hasFPTextures = true;
1788 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001789 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001790 }
1791 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001792 if (version >= GR_GL_VER(3, 0)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001793 hasFPTextures = true;
1794 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001795 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001796 } else {
1797 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1798 ctxInfo.hasExtension("GL_OES_texture_float")) {
1799 hasFPTextures = true;
1800 }
1801 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1802 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1803 hasHalfFPTextures = true;
1804 }
1805 }
1806 }
bsalomon30447372015-12-21 09:03:05 -08001807
csmartdalton6aa0e112017-02-08 16:14:11 -05001808 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1809 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1810 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1811 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1812 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001813 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001814 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1815 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
1816 if (hasFPTextures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001817 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
csmartdalton6aa0e112017-02-08 16:14:11 -05001818 // For now we only enable rendering to float on desktop, because on ES we'd have to
1819 // solve many precision issues and no clients actually want this yet.
1820 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1821 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1822 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1823 }
bsalomon41e4384e2016-01-08 09:12:44 -08001824 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001825 if (texStorageSupported) {
1826 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1827 }
1828 if (texelBufferSupport) {
1829 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1830 }
1831 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001832 }
bsalomon30447372015-12-21 09:03:05 -08001833
Greg Danielef59d872017-11-17 16:47:21 -05001834 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001835 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001836 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001837 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001838 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001839 }
Greg Danielef59d872017-11-17 16:47:21 -05001840 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1841 redHalf.fFormats.fExternalType = redHalfExternalType;
1842 redHalf.fFormatType = kFloat_FormatType;
1843 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1844 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001845 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001846 redHalf.fSwizzle = GrSwizzle::RRRR();
Brian Salomone609e812018-01-17 14:00:47 -05001847 if (textureRedSupport && hasHalfFPTextures) {
Greg Danielef59d872017-11-17 16:47:21 -05001848 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1849
csmartdalton6aa0e112017-02-08 16:14:11 -05001850 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
Brian Salomone609e812018-01-17 14:00:47 -05001851 (textureRedSupport && ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
Greg Danielef59d872017-11-17 16:47:21 -05001852 redHalf.fFlags |= fpRenderFlags;
1853 }
1854
1855 if (texStorageSupported && !isCommandBufferES2) {
1856 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1857 }
1858
1859 if (texelBufferSupport) {
1860 redHalf.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
csmartdalton6aa0e112017-02-08 16:14:11 -05001861 }
1862 }
Greg Danielef59d872017-11-17 16:47:21 -05001863 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001864
1865 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1866 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001867 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001868 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001869 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001870 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1871 } else {
1872 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1873 }
bsalomon7928ef62016-01-05 10:26:39 -08001874 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001875 if (hasHalfFPTextures) {
1876 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1877 // ES requires 3.2 or EXT_color_buffer_half_float.
1878 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1879 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1880 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1881 }
1882 }
cblume790d5132016-02-29 11:13:29 -08001883 if (texStorageSupported) {
1884 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1885 }
cdalton74b8d322016-04-11 14:47:28 -07001886 if (texelBufferSupport) {
1887 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1888 }
bsalomoncdee0092016-01-08 13:20:12 -08001889 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001890
bsalomon30447372015-12-21 09:03:05 -08001891 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1892
1893 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001894 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1895 ctxInfo.version() >= GR_GL_VER(3,0));
1896 // All ES versions (thus far) require sized internal formats for render buffers.
1897 // TODO: Always use sized internal format?
1898 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1899
bsalomon30447372015-12-21 09:03:05 -08001900 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001901 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1902 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001903 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001904 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001905 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1906 fConfigTable[i].fFormats.fSizedInternalFormat :
1907 fConfigTable[i].fFormats.fBaseInternalFormat;
1908 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001909 fConfigTable[i].fFormats.fSizedInternalFormat :
1910 fConfigTable[i].fFormats.fBaseInternalFormat;
1911 }
Brian Salomon44804c02018-01-23 16:51:28 -05001912 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1913 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1914 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1915 // in ES.
1916 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1917 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1918 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1919 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001920 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1921 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001922 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1923 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001924 }
1925
bsalomon30447372015-12-21 09:03:05 -08001926 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1927 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1928 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1929 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1930 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001931 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001932 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001933
1934 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1935 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1936 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1937 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001938 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001939 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1940 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1941 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1942 // slot.
1943 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1944 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001945
1946 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1947 // as a base format.
1948 // GL_EXT_texture_format_BGRA8888:
1949 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1950 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1951 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001952 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001953 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1954 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1955 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001956 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001957 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1958 }
1959
bsalomoncdee0092016-01-08 13:20:12 -08001960 // If we don't have texture swizzle support then the shader generator must insert the
1961 // swizzle into shader code.
1962 if (!this->textureSwizzleSupport()) {
1963 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001964 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001965 }
1966 }
1967
bsalomon7f9b2e42016-01-12 13:29:26 -08001968 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1969 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1970 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001971 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001972 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1973 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1974 if (GrPixelConfigIsAlphaOnly(config) &&
1975 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001976 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001977 }
1978 }
1979 }
1980
Greg Daniel81e7bf82017-07-19 14:47:42 -04001981 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1982 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001983 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1984 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001985 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001986 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1987 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001988 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001989 int count;
1990 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1991 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1992 1, &count);
1993 if (count) {
1994 int* temp = new int[count];
1995 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1996 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001997 // GL has a concept of MSAA rasterization with a single sample but we do not.
1998 if (count && temp[count - 1] == 1) {
1999 --count;
2000 SkASSERT(!count || temp[count -1] > 1);
2001 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04002002 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05002003 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04002004 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002005 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002006 for (int j = 0; j < count; ++j) {
2007 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
2008 }
2009 delete[] temp;
2010 }
2011 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002012 // Fake out the table using some semi-standard counts up to the max allowed sample
2013 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002014 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05002015 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
2016 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
2017 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
2018 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
2019 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002020 // Chrome has a mock GL implementation that returns 0.
2021 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05002022
Brian Salomonbdecacf2018-02-02 20:32:49 -05002023 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04002024 int count = SK_ARRAY_COUNT(kDefaultSamples);
2025 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002026 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002027 break;
2028 }
2029 }
2030 if (count > 0) {
2031 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
2032 }
2033 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002034 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
2035 fConfigTable[i].fColorSampleCounts.setCount(1);
2036 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002037 }
2038 }
2039
bsalomon30447372015-12-21 09:03:05 -08002040#ifdef SK_DEBUG
2041 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002042 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002043 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002044 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2045 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002046 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2047 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2048 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2049 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002050 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2051 fConfigTable[i].fFormats.fBaseInternalFormat);
2052 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002053 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002054 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2055 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2056 fConfigTable[i].fFormats.fExternalFormat[j]);
2057 }
2058 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002059 }
2060#endif
2061}
2062
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002063bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2064 bool dstIsTextureable, bool dstIsGLTexture2D,
2065 GrSurfaceOrigin dstOrigin,
2066 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2067 bool srcIsTextureable, bool srcIsGLTexture2D,
2068 GrSurfaceOrigin srcOrigin) const {
2069 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2070 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2071 // many drivers would allow it to work, but ANGLE does not.
2072 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2073 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2074 return false;
2075 }
2076
2077 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2078 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2079 return false;
2080 }
2081
2082 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2083 // texture.
2084 if (!dstIsTextureable) {
2085 return false;
2086 }
2087
2088 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2089 // is required
2090 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2091 (!srcIsTextureable || srcIsGLTexture2D) &&
2092 dstIsGLTexture2D &&
2093 dstOrigin == srcOrigin) {
2094 return true;
2095 } else {
2096 return false;
2097 }
2098}
2099
2100bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2101 bool dstIsTextureable, bool dstIsGLTexture2D,
2102 GrSurfaceOrigin dstOrigin,
2103 GrPixelConfig srcConfig, int srcSampleCnt,
2104 bool srcIsTextureable, bool srcIsGLTexture2D,
2105 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2106 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2107 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2108 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2109 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2110 return false;
2111 }
2112
2113 if (dstIsTextureable && !dstIsGLTexture2D) {
2114 return false;
2115 }
2116 if (srcIsTextureable && !srcIsGLTexture2D) {
2117 return false;
2118 }
2119
2120 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2121 return false;
2122 }
2123 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2124 // We would mirror to compensate for origin changes. Note that copySurface is
2125 // specified such that the src and dst rects are the same.
2126 if (dstOrigin != srcOrigin) {
2127 return false;
2128 }
2129 }
2130
2131 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2132 if (srcSampleCnt > 1) {
2133 if (1 == dstSampleCnt) {
2134 return false;
2135 }
2136 if (SkRect::Make(srcRect) != srcBounds) {
2137 return false;
2138 }
2139 }
2140 }
2141
2142 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2143 if (dstSampleCnt > 1) {
2144 return false;
2145 }
2146 }
2147
2148 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2149 if (dstConfig != srcConfig) {
2150 return false;
2151 }
2152 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2153 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2154 return false;
2155 }
2156 }
2157
2158 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2159 if (srcSampleCnt > 1) {
2160 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2161 return false;
2162 }
2163 if (dstOrigin != srcOrigin) {
2164 return false;
2165 }
2166 }
2167 }
2168 return true;
2169}
2170
2171bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2172 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2173}
2174
2175static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2176 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2177 if (!rt) {
2178 return false;
2179 }
2180 // A RT has a separate MSAA renderbuffer if:
2181 // 1) It's multisampled
2182 // 2) We're using an extension with separate MSAA renderbuffers
2183 // 3) It's not FBO 0, which is special and always auto-resolves
2184 return rt->numColorSamples() > 1 &&
2185 glCaps.usesMSAARenderBuffers() &&
2186 !rt->rtPriv().glRTFBOIDIs0();
2187}
2188
2189bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2190 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2191 GrSurfaceOrigin dstOrigin = dst->origin();
2192 GrSurfaceOrigin srcOrigin = src->origin();
2193
2194 GrPixelConfig dstConfig = dst->config();
2195 GrPixelConfig srcConfig = src->config();
2196
2197 int dstSampleCnt = 0;
2198 int srcSampleCnt = 0;
2199 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2200 dstSampleCnt = rtProxy->numColorSamples();
2201 }
2202 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2203 srcSampleCnt = rtProxy->numColorSamples();
2204 }
2205 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2206 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2207
2208 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2209 // swizzle.
2210 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2211 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2212 return false;
2213 }
2214
2215 const GrTextureProxy* dstTex = dst->asTextureProxy();
2216 const GrTextureProxy* srcTex = src->asTextureProxy();
2217
2218 bool dstIsTex2D = dstTex ? dstTex->texPriv().isGLTexture2D() : false;
2219 bool srcIsTex2D = srcTex ? srcTex->texPriv().isGLTexture2D() : false;
2220
2221 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2222 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2223 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2224 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2225 // know we will at least be able to do it as a draw.
2226#ifdef SK_DEBUG
2227 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2228 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2229 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2230 !src->priv().isExact()) {
2231 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2232 }
2233#endif
2234
2235 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2236 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2237 srcConfig, has_msaa_render_buffer(src, *this),
2238 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2239 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2240 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2241 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2242 dstPoint) ||
2243 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2244}
2245
Robert Phillipsbf25d432017-04-07 10:08:53 -04002246bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002247 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2248 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002249 // By default, we don't require rects to match.
2250 *rectsMustMatch = false;
2251
2252 // By default, we allow subrects.
2253 *disallowSubrect = false;
2254
Brian Salomon467921e2017-03-06 16:17:12 -05002255 // If the src is a texture, we can implement the blit as a draw assuming the config is
2256 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002257 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002258 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002259 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2260 desc->fConfig = src->config();
2261 return true;
2262 }
2263
Robert Phillipsbf25d432017-04-07 10:08:53 -04002264 {
2265 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2266 // wrapped. In that case the proxy would already be instantiated.
2267 const GrTexture* srcTexture = src->priv().peekTexture();
2268 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2269 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2270 // Not supported for FBO blit or CopyTexSubImage
2271 return false;
2272 }
Brian Salomon467921e2017-03-06 16:17:12 -05002273 }
2274
2275 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2276 // possible and we return false to fallback to creating a render target dst for render-to-
2277 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2278 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002279 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002280 bool rectsMustMatchForBlitFramebuffer = false;
2281 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002282 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002283 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2284 rectsMustMatchForBlitFramebuffer = true;
2285 disallowSubrectForBlitFramebuffer = true;
2286 // Mirroring causes rects to mismatch later, don't allow it.
2287 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002288 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2289 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002290 rectsMustMatchForBlitFramebuffer = true;
2291 // Mirroring causes rects to mismatch later, don't allow it.
2292 originForBlitFramebuffer = src->origin();
2293 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002294 originForBlitFramebuffer = src->origin();
2295 }
2296
2297 // Check for format issues with glCopyTexSubImage2D
2298 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2299 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2300 // then we set up for that, otherwise fail.
2301 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002302 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002303 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002304 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2305 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002306 return true;
2307 }
2308 return false;
2309 }
2310
Robert Phillipsbf25d432017-04-07 10:08:53 -04002311 {
Brian Salomon63e79732017-05-15 21:23:13 -04002312 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2313 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002314 if (srcIsMSAARenderbuffer) {
2315 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2316 // blit or fail.
2317 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002318 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002319 desc->fConfig = src->config();
2320 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2321 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2322 return true;
2323 }
2324 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002325 }
Brian Salomon467921e2017-03-06 16:17:12 -05002326 }
2327
2328 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002329 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002330 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002331 desc->fFlags = kNone_GrSurfaceFlags;
2332 return true;
2333}
2334
Greg Daniel691f5e72018-02-28 14:21:34 -05002335void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2336 const GrContextOptions& contextOptions,
2337 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002338 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2339 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Adrienne Walker0e383942018-05-15 11:33:47 -07002340 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
2341 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002342 fDiscardRenderTargetSupport = false;
2343 fInvalidateFBType = kNone_InvalidateFBType;
2344 }
2345
2346 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2347 // 340.96 and 367.57.
2348 if (kGL_GrGLStandard == ctxInfo.standard() &&
2349 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002350 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002351 fClearTextureSupport = false;
2352 }
2353
2354 // Calling glClearTexImage crashes on the NexusPlayer.
2355 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2356 fClearTextureSupport = false;
2357 }
2358
2359 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2360#ifdef SK_BUILD_FOR_MAC
2361 if (shaderCaps->fGeometryShaderSupport) {
2362 shaderCaps->fGSInvocationsSupport = false;
2363 }
2364#endif
2365
2366 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2367 // shaders. @127.0 is the earliest verified driver to not crash.
2368 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002369 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002370 shaderCaps->fGeometryShaderSupport = false;
2371 }
2372
2373#if defined(__has_feature)
2374#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2375 // See skbug.com/7058
2376 fMapBufferType = kNone_MapBufferType;
2377 fMapBufferFlags = kNone_MapFlags;
2378#endif
2379#endif
2380
2381 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2382 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2383 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2384 // unclear whether this really affects a wide range of devices.
2385 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002386 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002387 fMapBufferType = kNone_MapBufferType;
2388 fMapBufferFlags = kNone_MapFlags;
2389 }
2390
2391 // TODO: re-enable for ANGLE
2392 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2393 fTransferBufferType = kNone_TransferBufferType;
2394 }
2395
2396 // Using MIPs on this GPU seems to be a source of trouble.
2397 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2398 fMipMapSupport = false;
2399 }
2400
2401 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2402 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2403 // around a driver bug related to gl_FragCoord.
2404 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2405 fMaxClipAnalyticFPs = 0;
2406 }
2407
2408#ifndef SK_BUILD_FOR_IOS
2409 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2410 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2411 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2412 ctxInfo.driver() != kChromium_GrGLDriver)) {
2413 fUseDrawToClearColor = true;
2414 }
2415#endif
2416
2417 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2418 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2419 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2420 fUseDrawToClearColor = true;
2421 }
2422
2423#ifdef SK_BUILD_FOR_MAC
2424 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2425 // full screen clears
2426 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2427 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002428 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2429 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2430 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2431 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002432 fUseDrawToClearColor = true;
2433 }
2434#endif
2435
2436 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2437 // bugs seems to involve clearing too much and not skipping the clear.
2438 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2439 // but only for D3D11 ANGLE.
2440 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2441 fUseDrawToClearColor = true;
2442 }
2443
2444 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
2445 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002446 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002447 fUseDrawToClearStencilClip = true;
2448 }
2449 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2450 }
2451
Adrienne Walker94f585e2018-05-15 11:47:07 -07002452 if (fDriverBugWorkarounds.gl_clear_broken) {
2453 fUseDrawToClearColor = true;
2454 fUseDrawToClearStencilClip = true;
2455 }
2456
Brian Salomon01b476a2018-01-23 11:06:41 -05002457 // This was reproduced on the following configurations:
2458 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2459 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2460 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2461 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2462 // and not produced on:
2463 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2464 // The particular lines that get dropped from test images varies across different devices.
2465 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002466 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002467 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2468 }
2469
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002470 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2471 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2472 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002473 fRequiresFlushBetweenNonAndInstancedDraws = true;
2474 }
2475
Brian Salomon01b476a2018-01-23 11:06:41 -05002476 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2477 // given 1 << 15 or more instances.
2478 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2479 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
Adrienne Walker001cae02018-05-15 11:38:44 -07002480 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
2481 fMaxInstancesPerDrawArraysWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002482 }
2483
2484 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002485 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002486 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2487 fUseDrawInsteadOfAllRenderTargetWrites = true;
2488 }
2489
2490 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2491 fSampleShadingSupport = false;
2492 }
2493
2494#ifdef SK_BUILD_FOR_MAC
2495 static constexpr bool isMAC = true;
2496#else
2497 static constexpr bool isMAC = false;
2498#endif
2499
2500 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2501 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2502 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2503 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2504 if (fMipMapLevelAndLodControlSupport &&
2505 (contextOptions.fDoManualMipmapping ||
2506 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2507 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2508 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2509 fDoManualMipmapping = true;
2510 }
2511
2512 // See http://crbug.com/710443
2513#ifdef SK_BUILD_FOR_MAC
2514 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2515 fClearToBoundaryValuesIsBroken = true;
2516 }
2517#endif
2518 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2519 fDrawArraysBaseVertexIsBroken = true;
2520 }
2521
Brian Salomon01b476a2018-01-23 11:06:41 -05002522 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2523 // Galaxy S7.
2524 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2525 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2526 shaderCaps->fFBFetchSupport = false;
2527 }
2528
Brian Salomon01b476a2018-01-23 11:06:41 -05002529 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2530 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2531
2532 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2533 // function that may require a gradient calculation inside a conditional block may return
2534 // undefined results". This appears to be an issue with the 'any' call since even the simple
2535 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2536 // from our GrTextureDomain processor.
2537 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2538
2539 // Known issue on at least some Intel platforms:
2540 // http://code.google.com/p/skia/issues/detail?id=946
2541 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2542 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2543 }
2544
Chris Dalton0090ef62018-03-28 17:35:00 -06002545 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002546 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2547 // so we must do the abs first in a separate expression.
2548 shaderCaps->fCanUseMinAndAbsTogether = false;
2549
2550 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2551 // must avoid this condition.
2552 shaderCaps->fCanUseFractForNegativeValues = false;
2553 }
2554
2555 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2556 // thus must us -1.0 * %s.x to work correctly
2557 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2558 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2559 }
2560
2561 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2562 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2563 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2564 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2565 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2566 }
2567
2568 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2569 // the original dst color when reading the outColor even after being written to. By using a
2570 // local outColor we can work around this bug.
2571 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2572 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2573 }
2574
2575 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2576 // color, and that uniform contains an opaque color, and the output of the shader is only based
2577 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2578 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2579 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2580 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2581 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2582 shaderCaps->fMustObfuscateUniformColor = true;
2583 }
2584#ifdef SK_BUILD_FOR_WIN
2585 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2586 //
2587 // Basically, if a shader has a construct like:
2588 //
2589 // float x = someCondition ? someValue : 0;
2590 // float2 result = (0 == x) ? float2(x, x)
2591 // : float2(2 * x / x, 0);
2592 //
2593 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2594 // we've explicitly guarded the division with a check against zero. This manifests in much
2595 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2596 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2597 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2598 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2599 }
2600#endif
2601
2602 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
2603 // (rare) situations. It's sporadic, and mostly on older drivers. It also seems to be the case
2604 // that the interpolation of vertex shader outputs is quite inaccurate.
2605 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2606 shaderCaps->fCanUseFragCoord = false;
2607 shaderCaps->fInterpolantsAreInaccurate = true;
2608 }
2609
Chris Dalton0090ef62018-03-28 17:35:00 -06002610 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2611 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2612 shaderCaps->fCanUseFragCoord = false;
2613 }
2614
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002615 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2616 // (Are they implemented with fp16?)
2617 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2618 shaderCaps->fIncompleteShortIntPrecision = true;
2619 }
2620
Brian Salomon01b476a2018-01-23 11:06:41 -05002621 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2622 // for now until its own blacklists can be updated.
2623 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
2624 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2625 kIntel_GrGLDriver == ctxInfo.driver() ||
2626 kChromium_GrGLDriver == ctxInfo.driver()) {
2627 fBlendEquationSupport = kBasic_BlendEquationSupport;
2628 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2629 }
2630
2631 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2632 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002633 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002634 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002635 fBlendEquationSupport = kBasic_BlendEquationSupport;
2636 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2637 }
2638
Adrienne Walker68314842018-05-14 14:02:53 -07002639 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2640 fBlendEquationSupport = kBasic_BlendEquationSupport;
2641 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2642 }
2643
Brian Salomon01b476a2018-01-23 11:06:41 -05002644 if (this->advancedBlendEquationSupport()) {
2645 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002646 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002647 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2648 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2649 (1 << kColorBurn_GrBlendEquation);
2650 }
2651 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2652 // Blacklist color-burn on ARM until the fix is released.
2653 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2654 }
2655 }
2656
2657 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2658 if (fMultisampleDisableSupport &&
2659 this->shaderCaps()->dualSourceBlendingSupport() &&
2660 this->shaderCaps()->pathRenderingSupport() &&
2661 fUsesMixedSamples &&
2662#if GR_TEST_UTILS
2663 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2664#endif
2665 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2666 kChromium_GrGLDriver == ctxInfo.driver())) {
2667 fDiscardRenderTargetSupport = false;
2668 fInvalidateFBType = kNone_InvalidateFBType;
2669 }
Brian Osmanc585e202018-04-04 14:08:27 -04002670
Brian Osman061020e2018-04-17 14:22:15 -04002671 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2672 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2673 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2674 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002675 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2676 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002677 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002678 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002679 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2680 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002681 }
Brian Osman2fa53742018-05-03 15:05:12 -04002682
2683#ifdef SK_BUILD_FOR_IOS
2684 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2685 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2686 // is to just blacklist the feature.
2687 // https://github.com/flutter/flutter/issues/16718
2688 // https://bugreport.apple.com/web/?problemID=39948888
2689 fUnpackRowLengthSupport = false;
2690#endif
Chris Daltona2b5b642018-06-24 13:08:57 -06002691
2692#ifdef SK_BUILD_FOR_MAC
2693 // Radeon MacBooks hit a crash in glReadPixels() when using CCPR.
2694 // http://skbug.com/8097
2695 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2696 fBlacklistCoverageCounting = true;
2697 }
2698#endif
Chris Daltonc4e72a42018-06-25 06:44:01 -06002699
2700 // "shapes_mixed_10000_32x33" bench crashes PowerVRGX6250 in Release mode with ccpr.
2701 // http://skbug.com/8098
2702 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2703 fBlacklistCoverageCounting = true;
2704 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002705}
2706
csmartdaltone0d36292016-07-29 08:14:20 -07002707void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002708 if (options.fDisableDriverCorrectnessWorkarounds) {
2709 SkASSERT(!fDoManualMipmapping);
2710 SkASSERT(!fClearToBoundaryValuesIsBroken);
2711 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2712 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2713 SkASSERT(!fUseDrawToClearColor);
2714 SkASSERT(!fUseDrawToClearStencilClip);
2715 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2716 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2717 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002718 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Salomon01b476a2018-01-23 11:06:41 -05002719 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002720 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2721 fUseDrawToClearColor = false;
2722 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2723 fUseDrawToClearColor = true;
2724 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002725 if (options.fDoManualMipmapping) {
2726 fDoManualMipmapping = true;
2727 }
csmartdaltone0d36292016-07-29 08:14:20 -07002728}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002729
Brian Salomon3d86a192018-02-27 16:46:11 -05002730bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2731 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2732 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2733 if (tex->hasBaseLevelBeenBoundToFBO()) {
2734 return false;
2735 }
2736 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002737 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002738 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2739 return false;
2740 }
2741 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2742 return false;
2743 }
2744 return SkToBool(surface->asTexture());
2745 }
2746 return true;
2747}
2748
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002749bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2750 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2751 // We don't support reading pixels directly from EXTERNAL textures as it would require
2752 // binding the texture to a FBO.
2753 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2754 return false;
2755 }
2756 }
2757 return true;
2758}
2759
2760GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2761 GrColorType dstColorType) const {
2762 // For now, we mostly report the read back format that is required by the ES spec without
2763 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2764 // this as makes sense to increase performance and correctness.
2765 switch (fConfigTable[config].fFormatType) {
2766 case kNormalizedFixedPoint_FormatType:
2767 return GrColorType::kRGBA_8888;
2768 case kFloat_FormatType:
2769 // We cheat a little here and allow F16 read back if the src and dst match.
2770 if (kRGBA_half_GrPixelConfig == config && GrColorType::kRGBA_F16 == dstColorType) {
2771 return GrColorType::kRGBA_F16;
2772 }
2773 if ((kAlpha_half_GrPixelConfig == config ||
2774 kAlpha_half_as_Red_GrPixelConfig == config) &&
2775 GrColorType::kAlpha_F16 == dstColorType) {
2776 return GrColorType::kAlpha_F16;
2777 }
2778 // And similar for full float RG.
2779 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2780 return GrColorType::kRG_F32;
2781 }
2782 return GrColorType::kRGBA_F32;
2783 }
2784 return GrColorType::kUnknown;
2785}
2786
Greg Daniel2a303902018-02-20 10:25:54 -05002787bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002788 GrGLFramebufferInfo fbInfo;
2789 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002790 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002791 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002792}
2793
Brian Salomonbdecacf2018-02-02 20:32:49 -05002794int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2795 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002796 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002797 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002798 return 0;
2799 }
2800
Brian Salomonbdecacf2018-02-02 20:32:49 -05002801 if (1 == requestedCount) {
2802 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2803 }
2804
Greg Daniel81e7bf82017-07-19 14:47:42 -04002805 for (int i = 0; i < count; ++i) {
2806 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002807 int count = fConfigTable[config].fColorSampleCounts[i];
2808 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2809 count = SkTMin(count, 4);
2810 }
2811 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002812 }
2813 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002814 return 0;
2815}
2816
2817int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2818 const auto& table = fConfigTable[config].fColorSampleCounts;
2819 if (!table.count()) {
2820 return 0;
2821 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002822 int count = table[table.count() - 1];
2823 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2824 count = SkTMin(count, 4);
2825 }
2826 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002827}
2828
Greg Danielfaa095e2017-12-19 13:15:02 -05002829bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2830 GrGLStandard standard) {
2831 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002832
2833 switch (ct) {
2834 case kUnknown_SkColorType:
2835 return false;
2836 case kAlpha_8_SkColorType:
2837 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002838 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002839 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002840 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002841 }
2842 break;
2843 case kRGB_565_SkColorType:
2844 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002845 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002846 }
2847 break;
2848 case kARGB_4444_SkColorType:
2849 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002850 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002851 }
2852 break;
2853 case kRGBA_8888_SkColorType:
2854 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002855 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002856 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002857 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002858 }
2859 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002860 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002861 if (GR_GL_RGB8 == format) {
2862 *config = kRGB_888_GrPixelConfig;
2863 }
2864 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002865 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002866 if (GR_GL_RGBA8 == format) {
2867 if (kGL_GrGLStandard == standard) {
2868 *config = kBGRA_8888_GrPixelConfig;
2869 }
2870 } else if (GR_GL_BGRA8 == format) {
2871 if (kGLES_GrGLStandard == standard) {
2872 *config = kBGRA_8888_GrPixelConfig;
2873 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002874 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002875 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002876 }
2877 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002878 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002879 if (GR_GL_RGB10_A2 == format) {
2880 *config = kRGBA_1010102_GrPixelConfig;
2881 }
2882 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002883 case kRGB_101010x_SkColorType:
2884 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002885 case kGray_8_SkColorType:
2886 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002887 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002888 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002889 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002890 }
2891 break;
2892 case kRGBA_F16_SkColorType:
2893 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002894 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002895 }
2896 break;
Mike Klein37854712018-06-26 11:43:06 -04002897 case kRGBA_F32_SkColorType:
2898 if (GR_GL_RGBA32F == format) {
2899 *config = kRGBA_float_GrPixelConfig;
2900 }
2901 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002902 }
2903
Greg Danielfaa095e2017-12-19 13:15:02 -05002904 return kUnknown_GrPixelConfig != *config;
2905}
2906
2907bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2908 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002909 GrGLTextureInfo texInfo;
2910 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002911 return false;
2912 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002913 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002914}
2915
2916bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2917 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002918 GrGLFramebufferInfo fbInfo;
2919 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002920 return false;
2921 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002922 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002923}
2924
Robert Phillipsfc711a22018-02-13 17:03:00 -05002925bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2926 GrPixelConfig* config) const {
2927 const GrGLenum* glFormat = format.getGLFormat();
2928 if (!glFormat) {
2929 return false;
2930 }
2931 return validate_sized_format(*glFormat, ct, config, fStandard);
2932}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002933
Timothy Liang036fdfe2018-06-28 15:50:36 -04002934#ifdef GR_TEST_UTILS
2935GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2936 const GrBackendTexture& backendTex) const {
2937 GrGLTextureInfo glInfo;
2938 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2939 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2940}
2941#endif
2942
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002943