blob: 68d5e2e902fd27ac02ef660c714411ba1e42f5cd [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 }
Adrienne Walker87785d52018-08-09 12:01:43 -070094 if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
95 fMaxFragmentUniformVectors = SkMin32(fMaxFragmentUniformVectors, 32);
96 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000097 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000099 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000100 fUnpackRowLengthSupport = true;
101 fUnpackFlipYSupport = false;
102 fPackRowLengthSupport = true;
103 fPackFlipYSupport = false;
104 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000105 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
106 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000108 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
109 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000110 fPackFlipYSupport =
111 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
112 }
113
Adrienne Walkerc48f7762018-05-15 13:03:13 -0700114 if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
115 // In some cases drivers handle copying the last row incorrectly
116 // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
117 // through every row and conditionally clobbering that value, but
118 // Skia already has a scratch buffer workaround when pack row length
119 // is not supported, so just use that.
120 fPackRowLengthSupport = false;
121 }
122
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000123 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
125
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000126 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700127 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
128 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
129 ctxInfo.hasExtension("GL_NV_texture_barrier");
130 } else {
131 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
132 }
133
Robert Phillips7f861922018-01-30 13:13:42 +0000134 if (kGL_GrGLStandard == standard) {
135 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
136 ctxInfo.hasExtension("GL_ARB_texture_multisample");
137 } else {
138 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
139 }
140
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000141 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000142 ctxInfo.hasExtension("GL_ARB_imaging");
143
Brian Salomon01b476a2018-01-23 11:06:41 -0500144 if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
egdaniel9250d242015-05-18 13:04:26 -0700145 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
146 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000147 fDiscardRenderTargetSupport = true;
148 fInvalidateFBType = kInvalidate_InvalidateFBType;
149 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
150 fDiscardRenderTargetSupport = true;
151 fInvalidateFBType = kDiscard_InvalidateFBType;
152 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000153
Chris Dalton27059d32018-01-23 14:06:50 -0700154 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
155 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
156 if (kGLES_GrGLStandard == standard) {
157 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
158 // TODO: Evaluate on PowerVR.
159 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
160 if (kARM_GrGLVendor == ctxInfo.vendor()) {
161 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
162 }
163 }
164
Chris Dalton344e9032017-12-11 15:42:09 -0700165 if (kARM_GrGLVendor == ctxInfo.vendor() ||
166 kImagination_GrGLVendor == ctxInfo.vendor() ||
167 kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
168 fPreferFullscreenClears = true;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000169 }
170
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000171 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000172 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800173 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
174 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000175 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000176 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
177 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000178 }
179
cdalton626e1ff2015-06-12 13:56:46 -0700180 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
181 fDebugSupport = true;
182 } else {
183 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
184 }
185
jvanverth3f801cb2014-12-16 09:49:38 -0800186 if (kGL_GrGLStandard == standard) {
187 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
188 }
189 else {
190 fES2CompatibilitySupport = true;
191 }
192
cdalton0edea2c2015-05-21 08:27:44 -0700193 if (kGL_GrGLStandard == standard) {
194 fMultisampleDisableSupport = true;
195 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700196 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700197 }
198
kkinnunend94708e2015-07-30 22:47:04 -0700199 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600200 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
201 // instanced arrays, but we could make this more granular if we wanted
202 fInstanceAttribSupport =
203 version >= GR_GL_VER(3, 2) ||
204 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
205 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
206 } else {
207 fInstanceAttribSupport =
208 version >= GR_GL_VER(3, 0) ||
209 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
210 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
211 }
212
213 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700214 if (version >= GR_GL_VER(3, 0)) {
215 fBindFragDataLocationSupport = true;
216 }
217 } else {
218 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
219 fBindFragDataLocationSupport = true;
220 }
joshualittc1f56b52015-06-22 12:31:31 -0700221 }
222
joshualitt7bdd70a2015-10-01 06:28:11 -0700223 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
224
kkinnunene06ed252016-02-16 23:15:40 -0800225 if (kGL_GrGLStandard == standard) {
Weiliang Chen1e04b362018-07-12 17:13:35 -0400226 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
227 ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
kkinnunene06ed252016-02-16 23:15:40 -0800228 // We also require textureSize() support for rectangle 2D samplers which was added in
229 // GLSL 1.40.
230 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
231 fRectangleTextureSupport = true;
232 }
bsalomone179a912016-01-20 06:18:10 -0800233 }
kkinnunene06ed252016-02-16 23:15:40 -0800234 } else {
235 // Command buffer exposes this in GL ES context for Chromium reasons,
236 // but it should not be used. Also, at the time of writing command buffer
237 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800238 }
239
bsalomoncdee0092016-01-08 13:20:12 -0800240 if (kGL_GrGLStandard == standard) {
241 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
242 fTextureSwizzleSupport = true;
243 }
244 } else {
245 if (version >= GR_GL_VER(3,0)) {
246 fTextureSwizzleSupport = true;
247 }
248 }
249
cblume09bd2c02016-03-01 14:08:28 -0800250 if (kGL_GrGLStandard == standard) {
251 fMipMapLevelAndLodControlSupport = true;
252 } else if (kGLES_GrGLStandard == standard) {
253 if (version >= GR_GL_VER(3,0)) {
254 fMipMapLevelAndLodControlSupport = true;
255 }
256 }
257
bsalomon88c7b982015-07-31 11:20:16 -0700258#ifdef SK_BUILD_FOR_WIN
259 // We're assuming that on Windows Chromium we're using ANGLE.
260 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
261 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700262 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700263 fRGBA8888PixelsOpsAreSlow = isANGLE;
264 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
265 // check DX11 ANGLE.
266 fPartialFBOReadIsSlow = isANGLE;
267#endif
268
ericrkb4ecabd2016-03-11 15:18:20 -0800269 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
270 bool isMAC = false;
271#ifdef SK_BUILD_FOR_MAC
272 isMAC = true;
273#endif
274
275 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
276 // vis-versa.
277 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
278
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500279 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
280 fUseBufferDataNullHint = false;
281 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
282 fUseBufferDataNullHint = true;
283 }
284
Brian Salomond17b4a62017-05-23 16:53:47 -0400285 if (kGL_GrGLStandard == standard) {
286 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400287 fClearTextureSupport = true;
288 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500289 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
290 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400291 }
292
cdalton4cd67132015-06-10 19:23:46 -0700293 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700294 * GrShaderCaps fields
295 **************************************************************************/
296
egdaniel0a482332015-10-26 08:59:10 -0700297 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700298 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500299 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700300
Brian Osman195c05b2017-08-30 15:14:04 -0400301 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
302#if GR_TEST_UTILS
303 if (contextOptions.fSuppressPathRendering) {
304 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700305 }
Brian Osman195c05b2017-08-30 15:14:04 -0400306#endif
egdaniel05ded892015-10-26 07:38:05 -0700307
egdaniel05ded892015-10-26 07:38:05 -0700308 // Enable supported shader-related caps
309 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500310 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700311 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
Brian Salomon23c55b62018-06-19 16:28:41 -0400312 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600313
Brian Salomon1edc5b92016-11-29 13:43:46 -0500314 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600315
egdaniel05ded892015-10-26 07:38:05 -0700316 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500317 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700318 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600319 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600320 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
321 shaderCaps->fGSInvocationsSupport = true;
322 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
323 shaderCaps->fGSInvocationsSupport = true;
324 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
325 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600326 }
327
Brian Salomon1edc5b92016-11-29 13:43:46 -0500328 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800329 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500330 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500331 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700332
Brian Salomon1edc5b92016-11-29 13:43:46 -0500333 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700334 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800335
Chris Dalton1214be92018-06-28 19:06:27 -0600336 // Mali and early Adreno both have support for geometry shaders, but they appear to be
337 // implemented in software. In practice with ccpr, they are slower than the backup impl that
338 // only uses vertex shaders.
339 if (kARM_GrGLVendor != ctxInfo.vendor() &&
340 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
341 kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
342
Chris Daltonfaca00d2018-01-19 15:56:07 -0700343 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
344 shaderCaps->fGeometryShaderSupport = true;
345 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
346 shaderCaps->fGeometryShaderSupport = true;
347 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
348 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700349 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500350 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700351
Brian Salomon1edc5b92016-11-29 13:43:46 -0500352 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800353 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700354 }
355
cdalton9c3f1432016-03-11 10:07:37 -0800356 // Protect ourselves against tracking huge amounts of texture state.
357 static const uint8_t kMaxSaneSamplers = 32;
358 GrGLint maxSamplers;
359 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500360 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
361 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800362 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500363 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800364 }
365 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500366 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800367 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500368 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800369
csmartdalton485a1202016-07-13 10:16:32 -0700370 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
371 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
372 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
373 // limit this decision to specific GPU families rather than basing it on the vendor alone.
374 if (!GR_GL_MUST_USE_VBO &&
375 !fIsCoreProfile &&
376 (kARM_GrGLVendor == ctxInfo.vendor() ||
377 kImagination_GrGLVendor == ctxInfo.vendor() ||
378 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
379 fPreferClientSideDynamicBuffers = true;
380 }
381
Eric Karl5c779752017-05-08 12:02:07 -0700382 if (!contextOptions.fAvoidStencilBuffers) {
383 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
384 this->initFSAASupport(contextOptions, ctxInfo, gli);
385 this->initStencilSupport(ctxInfo);
386 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400387
388 // Setup blit framebuffer
389 if (kGL_GrGLStandard != ctxInfo.standard()) {
390 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
391 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
392 kNoMSAADst_BlitFramebufferFlag |
393 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
394 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
395 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
396 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
397 // limitations.
398 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
399 kResolveMustBeFull_BlitFrambufferFlag |
400 kNoMSAADst_BlitFramebufferFlag |
401 kNoFormatConversion_BlitFramebufferFlag |
402 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
403 }
404 } else {
405 if (fUsesMixedSamples ||
406 ctxInfo.version() >= GR_GL_VER(3,0) ||
407 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
408 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
409 fBlitFramebufferFlags = 0;
410 }
411 }
412
cdalton1dd05422015-06-12 09:01:18 -0700413 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000414
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000415 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000416 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
417 // extension includes glMapBuffer.
418 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
419 fMapBufferFlags |= kSubset_MapFlag;
420 fMapBufferType = kMapBufferRange_MapBufferType;
421 } else {
422 fMapBufferType = kMapBuffer_MapBufferType;
423 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000424 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000425 // Unextended GLES2 doesn't have any buffer mapping.
426 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800427 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800428 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
429 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800430 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
431 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
432 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000433 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
434 fMapBufferFlags = kCanMap_MapFlag;
435 fMapBufferType = kMapBuffer_MapBufferType;
436 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000437 }
438
jvanverthd7a2c1f2015-12-07 07:36:44 -0800439 if (kGL_GrGLStandard == standard) {
440 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
441 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700442 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500443 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400444 if (version >= GR_GL_VER(3, 0) ||
445 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
446 // GL_EXT_unpack_subimage needed to support subtexture rectangles
447 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800448 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400449// TODO: get transfer buffers working in Chrome
450// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
451// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800452 }
453 }
454
joshualitte5b74c62015-06-01 14:17:47 -0700455 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
456 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700457 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700458#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500459 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
460 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
461 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700462 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700463#else
cdalton397536c2016-03-25 12:15:03 -0700464 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700465#endif
joshualitte5b74c62015-06-01 14:17:47 -0700466 }
467
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000468 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000469 fNPOTTextureTileSupport = true;
470 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000471 } else {
472 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000473 // ES3 has no limitations.
474 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
475 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000476 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
477 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
478 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
479 // to alllow arbitrary wrap modes, however.
480 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000481 }
482
bsalomon@google.combcce8922013-03-25 15:38:39 +0000483 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700484
485 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
486 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
487 }
488
bsalomon@google.combcce8922013-03-25 15:38:39 +0000489 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
490 // Our render targets are always created with textures as the color
491 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000492 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700493 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
494
495 if (kARM_GrGLVendor == ctxInfo.vendor()) {
496 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
497 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
498 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000499
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000500 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
501
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000502 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700503 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000504
robertphillips1b8e1b52015-06-24 06:54:10 -0700505#if 0
506 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
507 kQualcomm_GrGLVendor != ctxInfo.vendor();
508#endif
509
csmartdalton9bc11872016-08-09 12:42:47 -0700510 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
511 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700512 }
513
robertphillips63926682015-08-20 09:39:02 -0700514#ifdef SK_BUILD_FOR_WIN
515 // On ANGLE deferring flushes can lead to GPU starvation
516 fPreferVRAMUseOverFlushes = !isANGLE;
517#endif
518
bsalomon7dea7b72015-08-19 08:26:51 -0700519 if (kChromium_GrGLDriver == ctxInfo.driver()) {
520 fMustClearUploadedBufferData = true;
521 }
522
bsalomond08ea5f2015-02-20 06:58:13 -0800523 if (kGL_GrGLStandard == standard) {
524 // ARB allows mixed size FBO attachments, EXT does not.
525 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
526 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
527 fOversizedStencilSupport = true;
528 } else {
529 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
530 }
531 } else {
532 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
533 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
534 }
535
joshualitt58001552015-06-26 12:46:36 -0700536 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700537 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
538 ctxInfo.hasExtension("GL_ARB_draw_indirect");
539 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
540 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700541 (fDrawIndirectSupport &&
542 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700543 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700544 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800545 } else {
546 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700547 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
548 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
549 fBaseInstanceSupport = fDrawIndirectSupport &&
550 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700551 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800552 }
553
ethannicholas28ef4452016-03-25 09:26:03 -0700554 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500555 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700556 fSampleShadingSupport = true;
557 }
558 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
559 fSampleShadingSupport = true;
560 }
561
jvanverth84741b32016-09-30 08:39:02 -0700562 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
563 if (kGL_GrGLStandard == standard) {
564 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
565 fFenceSyncSupport = true;
566 }
Brian Osman93a23462017-06-21 15:13:39 -0400567 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700568 fFenceSyncSupport = true;
569 }
570
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400571 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500572 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500573
Brian Salomon2d0a6a12018-08-22 15:22:24 +0000574 fDynamicStateArrayGeometryProcessorTextureSupport = true;
575
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400576 if (kGL_GrGLStandard == standard) {
577 if (version >= GR_GL_VER(4, 1)) {
578 fProgramBinarySupport = true;
579 }
580 } else if (version >= GR_GL_VER(3, 0)) {
581 fProgramBinarySupport = true;
582 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400583 if (fProgramBinarySupport) {
584 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400585 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400586 fProgramBinarySupport = count > 0;
587 }
bsalomoncdee0092016-01-08 13:20:12 -0800588 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
589 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800590 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700591
Brian Salomon01b476a2018-01-23 11:06:41 -0500592 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
593 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
594 }
595
cdalton4cd67132015-06-10 19:23:46 -0700596 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500597 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700598
Brian Salomon01b476a2018-01-23 11:06:41 -0500599 // For now these two are equivalent but we could have dst read in shader via some other method.
600 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000601}
602
egdaniel472d44e2015-10-22 08:20:00 -0700603const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
604 bool isCoreProfile) {
605 switch (generation) {
606 case k110_GrGLSLGeneration:
607 if (kGLES_GrGLStandard == standard) {
608 // ES2s shader language is based on version 1.20 but is version
609 // 1.00 of the ES language.
610 return "#version 100\n";
611 } else {
612 SkASSERT(kGL_GrGLStandard == standard);
613 return "#version 110\n";
614 }
615 case k130_GrGLSLGeneration:
616 SkASSERT(kGL_GrGLStandard == standard);
617 return "#version 130\n";
618 case k140_GrGLSLGeneration:
619 SkASSERT(kGL_GrGLStandard == standard);
620 return "#version 140\n";
621 case k150_GrGLSLGeneration:
622 SkASSERT(kGL_GrGLStandard == standard);
623 if (isCoreProfile) {
624 return "#version 150\n";
625 } else {
626 return "#version 150 compatibility\n";
627 }
628 case k330_GrGLSLGeneration:
629 if (kGLES_GrGLStandard == standard) {
630 return "#version 300 es\n";
631 } else {
632 SkASSERT(kGL_GrGLStandard == standard);
633 if (isCoreProfile) {
634 return "#version 330\n";
635 } else {
636 return "#version 330 compatibility\n";
637 }
638 }
cdalton33ad7012016-02-22 07:55:44 -0800639 case k400_GrGLSLGeneration:
640 SkASSERT(kGL_GrGLStandard == standard);
641 if (isCoreProfile) {
642 return "#version 400\n";
643 } else {
644 return "#version 400 compatibility\n";
645 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500646 case k420_GrGLSLGeneration:
647 SkASSERT(kGL_GrGLStandard == standard);
648 if (isCoreProfile) {
649 return "#version 420\n";
650 }
651 else {
652 return "#version 420 compatibility\n";
653 }
egdaniel472d44e2015-10-22 08:20:00 -0700654 case k310es_GrGLSLGeneration:
655 SkASSERT(kGLES_GrGLStandard == standard);
656 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800657 case k320es_GrGLSLGeneration:
658 SkASSERT(kGLES_GrGLStandard == standard);
659 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700660 }
661 return "<no version>";
662}
663
Chris Dalton47c8ed32017-11-15 18:27:09 -0700664bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
665 if (kGLES_GrGLStandard != ctxInfo.standard() &&
666 ctxInfo.version() < GR_GL_VER(4,1) &&
667 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
668 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
669 return true;
670 }
671 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
672 // geometry shaders don't have lower precision than vertex and fragment.
673 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
674 GrGLint range[2];
675 GrGLint bits;
676 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
677 if (range[0] < 127 || range[1] < 127 || bits < 23) {
678 return false;
679 }
680 }
681 return true;
682}
683
684void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700685 GrGLStandard standard = ctxInfo.standard();
686 GrGLVersion version = ctxInfo.version();
687
688 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500689 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700690 **************************************************************************/
691
Brian Salomon1edc5b92016-11-29 13:43:46 -0500692 GrShaderCaps* shaderCaps = fShaderCaps.get();
693 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700694 if (kGLES_GrGLStandard == standard) {
695 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500696 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
697 shaderCaps->fFBFetchSupport = true;
698 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
699 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700700 }
701 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
702 // 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 -0500703 shaderCaps->fFBFetchNeedsCustomOutput = false;
704 shaderCaps->fFBFetchSupport = true;
705 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
706 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700707 }
708 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
709 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500710 shaderCaps->fFBFetchNeedsCustomOutput = false;
711 shaderCaps->fFBFetchSupport = true;
712 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
713 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700714 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500715 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700716 }
717
cdaltonc08f1962016-02-12 12:14:06 -0800718 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500719 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800720 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500721 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800722 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
723 }
Brian Salomon41274562017-09-15 09:40:03 -0700724 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
725 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
726 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800727 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500728 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800729 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
730 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400731 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
732 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500733 shaderCaps->fNoPerspectiveInterpolationSupport = true;
734 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800735 "GL_NV_shader_noperspective_interpolation";
736 }
737 }
738
Brian Salomon1edc5b92016-11-29 13:43:46 -0500739 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
740 shaderCaps->fGLSLGeneration,
741 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800742
Brian Salomon1edc5b92016-11-29 13:43:46 -0500743 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
744 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800745 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800746
747 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500748 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800749 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
750 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500751 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800752 }
753
754 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500755 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800756 }
757
cdalton9c3f1432016-03-11 10:07:37 -0800758 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400759 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
760 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400761 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400762 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
763 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
764 // At least one driver has been found that has this extension without the "GL_" prefix.
765 shaderCaps->fExternalTextureSupport = true;
766 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800767 }
768 }
769
cdaltonc04ce672016-03-11 14:07:38 -0800770 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600771 shaderCaps->fVertexIDSupport = true;
772 } else {
773 // Desktop GLSL 3.30 == ES GLSL 3.00.
774 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
775 }
776
Chris Dalton7c7ff032018-03-28 20:09:58 -0600777 if (kGL_GrGLStandard == standard) {
778 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
779 } else {
780 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
781 }
782
Chris Dalton47c8ed32017-11-15 18:27:09 -0700783 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
784 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400785
786 // Unsigned integers only supported in and after GLSL 1.30.
787 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700788}
789
kkinnunencfe62e32015-07-01 02:58:50 -0700790bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700791 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
792
793 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700794 return false;
795 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700796
kkinnunencfe62e32015-07-01 02:58:50 -0700797 if (kGL_GrGLStandard == ctxInfo.standard()) {
798 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
799 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
800 return false;
801 }
802 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700803 if (!hasChromiumPathRendering &&
804 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700805 return false;
806 }
807 }
808 // We only support v1.3+ of GL_NV_path_rendering which allows us to
809 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
810 // additions are detected by checking the existence of the function.
811 // We also use *Then* functions that not all drivers might have. Check
812 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800813 if (!gli->fFunctions.fStencilThenCoverFillPath ||
814 !gli->fFunctions.fStencilThenCoverStrokePath ||
815 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
816 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
817 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700818 return false;
819 }
820 return true;
821}
bsalomon1aa20292016-01-22 08:16:09 -0800822
Brian Salomon71d9d842016-11-03 13:42:00 -0400823bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800824 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800825 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800826 std::function<bool ()> bindRenderTarget,
827 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400828 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800829 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400830 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800831 return false;
832 }
bsalomon7928ef62016-01-05 10:26:39 -0800833
bsalomon76148af2016-01-12 11:13:47 -0800834 GrGLenum readFormat;
835 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400836 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800837 return false;
838 }
839
bsalomon1aa20292016-01-22 08:16:09 -0800840 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800841 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
842 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
843 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
844 // 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 -0500845 // The manual does not seem to fully match the spec as the spec allows integer formats
846 // when the bound color buffer is an integer buffer. It doesn't specify which integer
847 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500848 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
849 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
850 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800851 return false;
852 }
853 // There is also a set of allowed types, but all the types we use are in the set:
854 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
855 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
856 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
857 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
858 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
859 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
860 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800861 return true;
piotaixre4b23142014-10-02 10:57:53 -0700862 }
bsalomon7928ef62016-01-05 10:26:39 -0800863
bsalomon76148af2016-01-12 11:13:47 -0800864 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500865 switch (fConfigTable[surfaceConfig].fFormatType) {
866 case kNormalizedFixedPoint_FormatType:
867 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
868 return true;
869 }
870 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500871 case kFloat_FormatType:
872 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
873 return true;
874 }
875 break;
bsalomon7928ef62016-01-05 10:26:39 -0800876 }
877
Brian Salomon71d9d842016-11-03 13:42:00 -0400878 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800879 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400880 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800881 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800882 if (!bindRenderTarget()) {
883 return false;
884 }
885 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
886 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800887 rpFormat->fFormat = format;
888 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800889 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800890 }
891
Brian Salomon71d9d842016-11-03 13:42:00 -0400892 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
893 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700894}
895
Eric Karl5c779752017-05-08 12:02:07 -0700896void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
897 const GrGLInterface* gli) {
898 // We need dual source blending and the ability to disable multisample in order to support mixed
899 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
900 // renderer is available and enabled; no other path renderers support this feature.
901 if (fMultisampleDisableSupport &&
902 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400903 this->shaderCaps()->pathRenderingSupport()
904#if GR_TEST_UTILS
905 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
906#endif
907 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700908 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400909 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700910 }
911
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000912 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400913 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
914 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
915 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
916 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
917 fAlpha8IsRenderable = true;
918 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500919 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
920 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
921 // mixed samples we can't use multisampled-render-to-texture.
922 if (fUsesMixedSamples) {
923 fMSFBOType = kMixedSamples_MSFBOType;
924 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000925 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
926 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
927 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400928 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
929 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400930 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400931 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400932 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400933 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000934 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
935 fMSFBOType = kES_Apple_MSFBOType;
936 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000937 } else {
egdanieleed519e2016-01-15 11:36:18 -0800938 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700939 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400940 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
941 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400942
Brian Salomon00731b42016-10-14 11:30:51 -0400943 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400944 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
945 // Core profile removes ALPHA8 support.
946 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
947 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
948 // present.
949 fAlpha8IsRenderable = true;
950 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000951 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
952 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400953 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000954 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000955 }
Eric Karl5c779752017-05-08 12:02:07 -0700956
Brian Salomon01b476a2018-01-23 11:06:41 -0500957 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400958 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
959 fMSFBOType = kNone_MSFBOType;
960 }
961
Eric Karl5c779752017-05-08 12:02:07 -0700962 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
963 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
964 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700965 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000966}
967
cdalton1dd05422015-06-12 09:01:18 -0700968void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500969 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700970
Greg Daniel210883c2017-11-27 15:14:01 -0500971 bool layoutQualifierSupport = false;
972 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
973 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
974 layoutQualifierSupport = true;
975 }
976
cdalton1dd05422015-06-12 09:01:18 -0700977 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
978 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500979 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500980 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
981 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700982 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500983 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700984 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
985 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500986 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500987 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700988 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500989 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700990 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
991 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -0700992 }
cdalton1dd05422015-06-12 09:01:18 -0700993}
994
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000995namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700996const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000997}
998
Eric Karl5c779752017-05-08 12:02:07 -0700999void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001000
1001 // Build up list of legal stencil formats (though perhaps not supported on
1002 // the particular gpu/driver) from most preferred to least.
1003
1004 // these consts are in order of most preferred to least preferred
1005 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1006
1007 static const StencilFormat
1008 // internal Format stencil bits total bits packed?
1009 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1010 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1011 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1012 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001013 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001014 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1015
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001016 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001017 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001018 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001019 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1020 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1021
1022 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1023 // require FBO support we can expect these are legal formats and don't
1024 // check. These also all support the unsized GL_STENCIL_INDEX.
1025 fStencilFormats.push_back() = gS8;
1026 fStencilFormats.push_back() = gS16;
1027 if (supportsPackedDS) {
1028 fStencilFormats.push_back() = gD24S8;
1029 }
1030 fStencilFormats.push_back() = gS4;
1031 if (supportsPackedDS) {
1032 fStencilFormats.push_back() = gDS;
1033 }
1034 } else {
1035 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1036 // for other formats.
1037 // ES doesn't support using the unsized format.
1038
1039 fStencilFormats.push_back() = gS8;
1040 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001041 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1042 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001043 fStencilFormats.push_back() = gD24S8;
1044 }
1045 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1046 fStencilFormats.push_back() = gS4;
1047 }
1048 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001049}
1050
Brian Osman71a18892017-08-10 10:23:25 -04001051void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001052
Brian Osman71a18892017-08-10 10:23:25 -04001053 // We are called by the base class, which has already called beginObject(). We choose to nest
1054 // all of our caps information in a named sub-object.
1055 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001056
Brian Osman71a18892017-08-10 10:23:25 -04001057 writer->beginArray("Stencil Formats");
1058
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001059 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001060 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001061 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1062 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1063 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001064 }
1065
Brian Osman71a18892017-08-10 10:23:25 -04001066 writer->endArray();
1067
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001068 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001069 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001070 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001071 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001072 "IMG MS To Texture",
1073 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001074 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001075 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001076 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001077 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1078 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1079 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1080 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1081 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001082 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001083
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001084 static const char* kInvalidateFBTypeStr[] = {
1085 "None",
1086 "Discard",
1087 "Invalidate",
1088 };
1089 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1090 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1091 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1092 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001093
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001094 static const char* kMapBufferTypeStr[] = {
1095 "None",
1096 "MapBuffer",
1097 "MapBufferRange",
1098 "Chromium",
1099 };
1100 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1101 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1102 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1103 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1104 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1105
Brian Osman71a18892017-08-10 10:23:25 -04001106 writer->appendBool("Core Profile", fIsCoreProfile);
1107 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1108 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1109 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1110 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1111 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1112 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1113 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1114 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001115
Brian Osman71a18892017-08-10 10:23:25 -04001116 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001117 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1118 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1119 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001120 writer->appendBool("Debug support", fDebugSupport);
1121 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1122 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1123 writer->appendBool("Base instance support", fBaseInstanceSupport);
1124 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1125 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1126 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1127 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1128 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1129 writer->appendBool("BGRA to RGBA readback conversions are slow",
1130 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001131 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001132 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1133 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001134 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1135 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1136 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1137 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001138 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1139 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001140
Brian Osman71a18892017-08-10 10:23:25 -04001141 writer->beginArray("configs");
1142
bsalomon41e4384e2016-01-08 09:12:44 -08001143 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001144 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001145 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1146 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1147 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001148 writer->appendHexU32("e_format_read_pixels",
1149 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001150 writer->appendHexU32(
1151 "e_format_teximage",
1152 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1153 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1154 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1155 writer->appendHexU32("i_for_renderbuffer",
1156 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1157 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001158 }
1159
Brian Osman71a18892017-08-10 10:23:25 -04001160 writer->endArray();
1161 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001162}
1163
bsalomon41e4384e2016-01-08 09:12:44 -08001164bool GrGLCaps::bgraIsInternalFormat() const {
1165 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1166}
1167
bsalomon76148af2016-01-12 11:13:47 -08001168bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1169 GrGLenum* internalFormat, GrGLenum* externalFormat,
1170 GrGLenum* externalType) const {
1171 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1172 externalFormat, externalType)) {
1173 return false;
1174 }
1175 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1176 return true;
1177}
1178
bsalomon76148af2016-01-12 11:13:47 -08001179bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1180 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001181 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001182 externalFormat, externalType)) {
1183 return false;
1184 }
1185 return true;
1186}
1187
1188bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001189 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1190 return true;
1191}
1192
1193bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1194 ExternalFormatUsage usage, GrGLenum* externalFormat,
1195 GrGLenum* externalType) const {
1196 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001197
1198 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1199 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1200
1201 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001202 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1203 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001204 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1205 return false;
1206 }
1207
1208 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1209 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1210
bsalomone9573312016-01-25 14:33:25 -08001211 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1212 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1213 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1214 // texture, not the red component.
1215 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001216 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001217 *externalFormat = GR_GL_ALPHA;
1218 }
1219 }
1220
bsalomon76148af2016-01-12 11:13:47 -08001221 return true;
1222}
1223
brianosman20471892016-12-02 06:43:32 -08001224void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1225 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001226 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001227 /*
1228 Comments on renderability of configs on various GL versions.
1229 OpenGL < 3.0:
1230 no built in support for render targets.
1231 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1232 format RGB, RGBA and NV float formats we don't use.
1233 This is the following:
1234 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1235 RGB10_A2, RGBA12,RGBA16
1236 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1237 since they aren't required by later standards and the driver can simply return
1238 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1239 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1240 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1241 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1242 This adds a lot of additional renderable sized formats, including ALPHA8.
1243 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1244 16F, 32I, 32UI, and 32F variants).
1245 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1246
1247 For both the above extensions we limit ourselves to those that are also required by
1248 OpenGL 3.0.
1249
1250 OpenGL 3.0:
1251 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1252 but are not required to be supported as renderable textures/renderbuffer.
1253 Required renderable color formats:
1254 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1255 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1256 RGB10_A2.
1257 - R11F_G11F_B10F.
1258 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1259 and RG8UI.
1260 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1261 - ALPHA8
1262
1263 OpenGL 3.1, 3.2, 3.3
1264 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1265 OpengGL 3.3, 4.0, 4.1
1266 Adds RGB10_A2UI.
1267 OpengGL 4.2
1268 Adds
1269 - RGB5_A1, RGBA4
1270 - RGB565
1271 OpenGL 4.4
1272 Does away with the separate list and adds a column to the sized internal color format
1273 table. However, no new formats become required color renderable.
1274
1275 ES 2.0
1276 color renderable: RGBA4, RGB5_A1, RGB565
1277 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1278 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1279 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1280 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1281 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1282 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1283
1284 ES 3.0
1285 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1286 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1287 RGB5_A1.
1288 - RGB8 and RGB565.
1289 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1290 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1291 ES 3.1
1292 Adds RGB10_A2, RGB10_A2UI,
1293 ES 3.2
1294 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1295 */
Brian Salomon44804c02018-01-23 16:51:28 -05001296
1297 // Correctness workarounds.
1298 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001299 bool disableSRGBForX86PowerVR = false;
1300 bool disableSRGBWriteControlForAdreno4xx = false;
1301 bool disableR8TexStorageForANGLEGL = false;
1302 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001303 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001304 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001305
1306 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1307 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1308 // and GL_RG on FBO textures.
1309 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1310
Greg Daniel09c94002018-06-08 22:11:51 +00001311 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1312
Brian Salomon44804c02018-01-23 16:51:28 -05001313 bool isX86PowerVR = false;
1314#if defined(SK_CPU_X86)
1315 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1316 isX86PowerVR = true;
1317 }
1318#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001319 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1320 // blacklist that device (and any others that might be sharing the same driver).
1321 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001322 disableSRGBWriteControlForAdreno4xx =
1323 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1324 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001325
1326 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1327 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1328 // check that we are not going to OpenGL.
1329 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1330
1331 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1332#if defined(SK_BUILD_FOR_MAC)
1333 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1334#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001335 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1336 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001337 }
1338
Brian Salomon71d9d842016-11-03 13:42:00 -04001339 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1340 ConfigInfo::kFBOColorAttachment_Flag;
1341 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001342 if (kNone_MSFBOType != fMSFBOType) {
1343 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1344 }
bsalomon41e4384e2016-01-08 09:12:44 -08001345 GrGLStandard standard = ctxInfo.standard();
1346 GrGLVersion version = ctxInfo.version();
1347
cblume790d5132016-02-29 11:13:29 -08001348 bool texStorageSupported = false;
1349 if (kGL_GrGLStandard == standard) {
1350 // The EXT version can apply to either GL or GLES.
1351 texStorageSupported = version >= GR_GL_VER(4,2) ||
1352 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1353 ctxInfo.hasExtension("GL_EXT_texture_storage");
1354 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001355 texStorageSupported = version >= GR_GL_VER(3,0) ||
1356 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001357 }
Adrienne Walker70e468f2018-08-22 16:05:27 -07001358 if (fDriverBugWorkarounds.disable_texture_storage) {
1359 texStorageSupported = false;
1360 }
cblume790d5132016-02-29 11:13:29 -08001361
Brian Salomone609e812018-01-17 14:00:47 -05001362 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001363
1364 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001365 if (kGL_GrGLStandard == standard) {
1366 textureRedSupport =
1367 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1368 } else {
1369 textureRedSupport =
1370 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1371 }
1372 }
1373
bsalomon30447372015-12-21 09:03:05 -08001374 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1375 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001376 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001377 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001378 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001379 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001380
1381 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1382 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001383 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001384 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001385 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001386 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001387 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1388 if (kGL_GrGLStandard == standard) {
1389 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1390 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001391 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001392 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1393 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1394 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1395 }
egdaniel4999df82016-01-07 17:06:04 -08001396 }
cblume790d5132016-02-29 11:13:29 -08001397 if (texStorageSupported) {
1398 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1399 }
bsalomoncdee0092016-01-08 13:20:12 -08001400 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001401
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001402 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1403 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1404 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1405 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1406 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1407 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1408 // supportedReadPixelsColorType never returns it.
1409 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1410 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1411 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1412 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1413 if (kGL_GrGLStandard == standard) {
1414 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1415 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1416 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1417 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1418 // becomes an issue.
1419 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1420 // but we don't support that just for simplicity's sake.
1421 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1422 } else {
1423 // 3.0 and the extension support this as a render buffer format.
1424 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1425 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1426 }
1427 }
1428 if (texStorageSupported) {
1429 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1430 }
1431 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1432 if (disableRGB8ForMali400) {
1433 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1434 }
1435
1436 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001437 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001438 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001439 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001440
1441 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1442 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1443 // GL_EXT_texture_format_BGRA8888.
1444 bool supportsBGRATexStorage = false;
1445
bsalomon41e4384e2016-01-08 09:12:44 -08001446 if (kGL_GrGLStandard == standard) {
1447 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1448 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1449 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1450 // Since the internal format is RGBA8, it is also renderable.
1451 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1452 allRenderFlags;
1453 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001454 // Since we are using RGBA8 we can use tex storage.
1455 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001456 } else {
1457 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1458 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001459 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1460 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1461 nonMSAARenderFlags;
1462
1463 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1464 supportsBGRATexStorage = true;
1465 }
1466 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1467 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1468 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1469 ConfigInfo::kRenderableWithMSAA_Flag;
1470 }
1471 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001472 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1473 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1474 // driver remembers the external format when the texture is created (with TexImage).
1475 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1476 // We could work around this, but it adds even more state tracking to code that is
1477 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1478 // This also side-steps some ambiguous interactions with the texture storage extension.
1479 if (version >= GR_GL_VER(3,0)) {
1480 // The APPLE extension doesn't make this renderable.
1481 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001482 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001483 }
bsalomon41e4384e2016-01-08 09:12:44 -08001484 }
1485 }
Brian Osman48c99192017-06-02 08:45:06 -04001486
Greg Daniel0ff79b22018-02-15 12:33:33 -05001487 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001488 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001489 }
bsalomoncdee0092016-01-08 13:20:12 -08001490 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001491
Brian Osman2b23c4b2018-06-01 12:25:08 -04001492 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001493 if (kGL_GrGLStandard == standard) {
1494 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001495 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001496 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1497 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1498 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001499 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001500 }
1501 }
1502 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001503 if (fSRGBSupport) {
1504 fSRGBWriteControl = true;
1505 }
bsalomon41e4384e2016-01-08 09:12:44 -08001506 } else {
brianosman20471892016-12-02 06:43:32 -08001507 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001508 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001509 fSRGBSupport = false;
1510 }
bsalomon41e4384e2016-01-08 09:12:44 -08001511 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1512 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001513 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001514 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001515 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001516 }
brianosman20471892016-12-02 06:43:32 -08001517
1518 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1519 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1520 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1521 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1522 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1523 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1524 // affects Windows.
1525 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1526 fSRGBSupport = false;
1527 }
1528
Brian Osman48c99192017-06-02 08:45:06 -04001529 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1530 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1531 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1532
Brian Osman67999392017-05-31 16:19:34 -04001533 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001534 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001535 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1536 }
Brian Osman67999392017-05-31 16:19:34 -04001537
bsalomon30447372015-12-21 09:03:05 -08001538 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1539 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1540 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1541 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001542 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001543 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001544 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001545 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001546 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001547 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001548 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001549 }
Brian Osman48c99192017-06-02 08:45:06 -04001550 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1551 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001552 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1553 }
bsalomoncdee0092016-01-08 13:20:12 -08001554 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001555 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1556 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1557 // is in this format, for example).
1558 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1559 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1560 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1561 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001562 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001563 GR_GL_BGRA;
1564 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1565 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001566 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001567 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001568 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001569 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001570
brianosmana6359362016-03-21 06:55:37 -07001571 if (texStorageSupported) {
1572 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1573 }
1574 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1575
bsalomon30447372015-12-21 09:03:05 -08001576 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1577 if (this->ES2CompatibilitySupport()) {
1578 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1579 } else {
1580 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1581 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001582 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001583 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001584 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001585 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001586 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1587 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001588 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001589 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1590 }
1591 } else {
1592 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1593 }
cblume790d5132016-02-29 11:13:29 -08001594 // 565 is not a sized internal format on desktop GL. So on desktop with
1595 // 565 we always use an unsized internal format to let the system pick
1596 // the best sized format to convert the 565 data to. Since TexStorage
1597 // only allows sized internal formats we disallow it.
1598 //
1599 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1600 // update.
1601 if (texStorageSupported && kGL_GrGLStandard != standard) {
1602 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1603 }
bsalomoncdee0092016-01-08 13:20:12 -08001604 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001605
1606 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1607 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001608 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001609 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001610 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001611 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001612 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1613 if (kGL_GrGLStandard == standard) {
1614 if (version >= GR_GL_VER(4, 2)) {
1615 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1616 }
1617 } else {
1618 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1619 }
cblume790d5132016-02-29 11:13:29 -08001620 if (texStorageSupported) {
1621 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1622 }
bsalomoncdee0092016-01-08 13:20:12 -08001623 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001624
Brian Osman10fc6fd2018-03-02 11:01:10 -05001625 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1626 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001627 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001628 GR_GL_RGBA;
1629 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1630 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1631 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1632 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1633 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1634 allRenderFlags;
1635 }
1636 if (texStorageSupported) {
1637 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1638 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001639 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1640
Greg Danielef59d872017-11-17 16:47:21 -05001641 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1642 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1643
1644 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1645 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1646 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1647 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1648 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001649 }
Greg Danielef59d872017-11-17 16:47:21 -05001650 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1651 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001652 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001653 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1654 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1655 alphaInfo.fFlags |= allRenderFlags;
1656 }
1657
1658 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1659 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1660 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1661 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1662 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001663 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001664 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001665
Brian Osman48c99192017-06-02 08:45:06 -04001666 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1667 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001668 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001669 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1670 }
1671 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1672 }
1673
Brian Salomone609e812018-01-17 14:00:47 -05001674 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001675 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001676 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1677 } else {
1678 redInfo.fFlags = 0;
1679
1680 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001681 }
bsalomon41e4384e2016-01-08 09:12:44 -08001682
Greg Daniel7af060a2017-12-05 16:27:11 -05001683 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1684 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1685 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1686 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1687 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001688 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001689 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1690 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1691 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1692 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001693 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001694
1695 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1696 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1697 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1698 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1699 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001700 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001701 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1702 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1703
Greg Daniel09c94002018-06-08 22:11:51 +00001704 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1705 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1706 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1707 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1708 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001709 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1710 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1711 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001712 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001713 }
Brian Osman48c99192017-06-02 08:45:06 -04001714 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001715 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001716 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1717 }
1718 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1719 }
1720
Brian Salomone609e812018-01-17 14:00:47 -05001721 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001722 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1723 } else {
1724 grayRedInfo.fFlags = 0;
1725 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001726 }
1727
bsalomon41e4384e2016-01-08 09:12:44 -08001728 // Check for [half] floating point texture support
1729 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1730 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1731 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
Chris Daltoneff01a72018-07-19 17:06:39 -06001732 bool hasFP32Textures = false;
1733 bool hasFP16Textures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001734 bool rgIsTexturable = false;
Chris Daltoneff01a72018-07-19 17:06:39 -06001735 bool hasFP32RenderTargets = false;
1736 bool hasFP16RenderTargets = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001737 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001738 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001739
1740 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001741 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001742 hasFP32Textures = true;
1743 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001744 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001745 hasFP32RenderTargets = true;
1746 hasFP16RenderTargets = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001747 }
1748 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001749 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001750 hasFP32Textures = true;
1751 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001752 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001753 } else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1754 ctxInfo.hasExtension("GL_OES_texture_float")) {
1755 hasFP32Textures = true;
1756 hasFP16Textures = true;
1757 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1758 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1759 hasFP16Textures = true;
1760 }
1761
1762 if (version >= GR_GL_VER(3, 2)) {
1763 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to solve
1764 // many precision issues and no clients actually want this yet.
1765 // hasFP32RenderTargets = true;
1766 hasFP16RenderTargets = true;
1767 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
1768 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to
1769 // solve many precision issues and no clients actually want this yet.
1770 // hasFP32RenderTargets = true;
1771 hasFP16RenderTargets = true;
1772 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1773 hasFP16RenderTargets = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001774 }
1775 }
bsalomon30447372015-12-21 09:03:05 -08001776
csmartdalton6aa0e112017-02-08 16:14:11 -05001777 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1778 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1779 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1780 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1781 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001782 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001783 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1784 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001785 if (hasFP32Textures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001786 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
Chris Daltoneff01a72018-07-19 17:06:39 -06001787 if (hasFP32RenderTargets) {
csmartdalton6aa0e112017-02-08 16:14:11 -05001788 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1789 }
bsalomon41e4384e2016-01-08 09:12:44 -08001790 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001791 if (texStorageSupported) {
1792 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1793 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001794 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001795 }
bsalomon30447372015-12-21 09:03:05 -08001796
Greg Danielef59d872017-11-17 16:47:21 -05001797 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001798 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001799 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001800 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001801 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001802 }
Greg Danielef59d872017-11-17 16:47:21 -05001803 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1804 redHalf.fFormats.fExternalType = redHalfExternalType;
1805 redHalf.fFormatType = kFloat_FormatType;
1806 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1807 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001808 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001809 redHalf.fSwizzle = GrSwizzle::RRRR();
Chris Daltoneff01a72018-07-19 17:06:39 -06001810 if (textureRedSupport && hasFP16Textures) {
Greg Danielef59d872017-11-17 16:47:21 -05001811 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1812
Chris Daltoneff01a72018-07-19 17:06:39 -06001813 if (hasFP16RenderTargets) {
Greg Danielef59d872017-11-17 16:47:21 -05001814 redHalf.fFlags |= fpRenderFlags;
1815 }
1816
1817 if (texStorageSupported && !isCommandBufferES2) {
1818 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1819 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001820 }
Greg Danielef59d872017-11-17 16:47:21 -05001821 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001822
1823 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1824 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001825 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001826 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001827 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001828 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1829 } else {
1830 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1831 }
bsalomon7928ef62016-01-05 10:26:39 -08001832 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001833 if (hasFP16Textures) {
bsalomon41e4384e2016-01-08 09:12:44 -08001834 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1835 // ES requires 3.2 or EXT_color_buffer_half_float.
Chris Daltoneff01a72018-07-19 17:06:39 -06001836 if (hasFP16RenderTargets) {
bsalomon41e4384e2016-01-08 09:12:44 -08001837 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1838 }
1839 }
cblume790d5132016-02-29 11:13:29 -08001840 if (texStorageSupported) {
1841 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1842 }
bsalomoncdee0092016-01-08 13:20:12 -08001843 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001844
bsalomon30447372015-12-21 09:03:05 -08001845 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1846
1847 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001848 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1849 ctxInfo.version() >= GR_GL_VER(3,0));
1850 // All ES versions (thus far) require sized internal formats for render buffers.
1851 // TODO: Always use sized internal format?
1852 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1853
bsalomon30447372015-12-21 09:03:05 -08001854 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001855 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1856 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001857 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001858 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001859 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1860 fConfigTable[i].fFormats.fSizedInternalFormat :
1861 fConfigTable[i].fFormats.fBaseInternalFormat;
1862 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001863 fConfigTable[i].fFormats.fSizedInternalFormat :
1864 fConfigTable[i].fFormats.fBaseInternalFormat;
1865 }
Brian Salomon44804c02018-01-23 16:51:28 -05001866 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1867 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1868 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1869 // in ES.
1870 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1871 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1872 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1873 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001874 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1875 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001876 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1877 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001878 }
1879
bsalomon30447372015-12-21 09:03:05 -08001880 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1881 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1882 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1883 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1884 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001885 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001886 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001887
1888 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1889 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1890 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1891 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001892 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001893 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1894 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1895 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1896 // slot.
1897 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1898 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001899
1900 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1901 // as a base format.
1902 // GL_EXT_texture_format_BGRA8888:
1903 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1904 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1905 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001906 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001907 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1908 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1909 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001910 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001911 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1912 }
1913
bsalomoncdee0092016-01-08 13:20:12 -08001914 // If we don't have texture swizzle support then the shader generator must insert the
1915 // swizzle into shader code.
1916 if (!this->textureSwizzleSupport()) {
1917 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001918 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001919 }
1920 }
1921
bsalomon7f9b2e42016-01-12 13:29:26 -08001922 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1923 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1924 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001925 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001926 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1927 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1928 if (GrPixelConfigIsAlphaOnly(config) &&
1929 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001930 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001931 }
1932 }
1933 }
1934
Greg Daniel81e7bf82017-07-19 14:47:42 -04001935 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1936 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001937 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1938 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001939 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001940 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1941 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001942 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001943 int count;
1944 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1945 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1946 1, &count);
1947 if (count) {
1948 int* temp = new int[count];
1949 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1950 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001951 // GL has a concept of MSAA rasterization with a single sample but we do not.
1952 if (count && temp[count - 1] == 1) {
1953 --count;
1954 SkASSERT(!count || temp[count -1] > 1);
1955 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001956 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001957 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001958 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001959 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001960 for (int j = 0; j < count; ++j) {
1961 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1962 }
1963 delete[] temp;
1964 }
1965 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001966 // Fake out the table using some semi-standard counts up to the max allowed sample
1967 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001968 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001969 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1970 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1971 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1972 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1973 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001974 // Chrome has a mock GL implementation that returns 0.
1975 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05001976
Brian Salomonbdecacf2018-02-02 20:32:49 -05001977 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04001978 int count = SK_ARRAY_COUNT(kDefaultSamples);
1979 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001980 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001981 break;
1982 }
1983 }
1984 if (count > 0) {
1985 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
1986 }
1987 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001988 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
1989 fConfigTable[i].fColorSampleCounts.setCount(1);
1990 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001991 }
1992 }
1993
bsalomon30447372015-12-21 09:03:05 -08001994#ifdef SK_DEBUG
1995 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001996 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001997 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04001998 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
1999 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002000 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2001 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2002 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2003 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002004 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2005 fConfigTable[i].fFormats.fBaseInternalFormat);
2006 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002007 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002008 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2009 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2010 fConfigTable[i].fFormats.fExternalFormat[j]);
2011 }
2012 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002013 }
2014#endif
2015}
2016
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002017bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2018 bool dstIsTextureable, bool dstIsGLTexture2D,
2019 GrSurfaceOrigin dstOrigin,
2020 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2021 bool srcIsTextureable, bool srcIsGLTexture2D,
2022 GrSurfaceOrigin srcOrigin) const {
2023 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2024 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2025 // many drivers would allow it to work, but ANGLE does not.
2026 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2027 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2028 return false;
2029 }
2030
2031 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2032 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2033 return false;
2034 }
2035
2036 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2037 // texture.
2038 if (!dstIsTextureable) {
2039 return false;
2040 }
2041
2042 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2043 // is required
2044 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2045 (!srcIsTextureable || srcIsGLTexture2D) &&
2046 dstIsGLTexture2D &&
2047 dstOrigin == srcOrigin) {
2048 return true;
2049 } else {
2050 return false;
2051 }
2052}
2053
2054bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2055 bool dstIsTextureable, bool dstIsGLTexture2D,
2056 GrSurfaceOrigin dstOrigin,
2057 GrPixelConfig srcConfig, int srcSampleCnt,
2058 bool srcIsTextureable, bool srcIsGLTexture2D,
2059 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2060 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2061 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2062 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2063 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2064 return false;
2065 }
2066
2067 if (dstIsTextureable && !dstIsGLTexture2D) {
2068 return false;
2069 }
2070 if (srcIsTextureable && !srcIsGLTexture2D) {
2071 return false;
2072 }
2073
2074 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2075 return false;
2076 }
2077 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2078 // We would mirror to compensate for origin changes. Note that copySurface is
2079 // specified such that the src and dst rects are the same.
2080 if (dstOrigin != srcOrigin) {
2081 return false;
2082 }
2083 }
2084
2085 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2086 if (srcSampleCnt > 1) {
2087 if (1 == dstSampleCnt) {
2088 return false;
2089 }
2090 if (SkRect::Make(srcRect) != srcBounds) {
2091 return false;
2092 }
2093 }
2094 }
2095
2096 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2097 if (dstSampleCnt > 1) {
2098 return false;
2099 }
2100 }
2101
2102 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2103 if (dstConfig != srcConfig) {
2104 return false;
2105 }
2106 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2107 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2108 return false;
2109 }
2110 }
2111
2112 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2113 if (srcSampleCnt > 1) {
2114 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2115 return false;
2116 }
2117 if (dstOrigin != srcOrigin) {
2118 return false;
2119 }
2120 }
2121 }
2122 return true;
2123}
2124
2125bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2126 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2127}
2128
2129static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2130 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2131 if (!rt) {
2132 return false;
2133 }
2134 // A RT has a separate MSAA renderbuffer if:
2135 // 1) It's multisampled
2136 // 2) We're using an extension with separate MSAA renderbuffers
2137 // 3) It's not FBO 0, which is special and always auto-resolves
2138 return rt->numColorSamples() > 1 &&
2139 glCaps.usesMSAARenderBuffers() &&
2140 !rt->rtPriv().glRTFBOIDIs0();
2141}
2142
2143bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2144 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2145 GrSurfaceOrigin dstOrigin = dst->origin();
2146 GrSurfaceOrigin srcOrigin = src->origin();
2147
2148 GrPixelConfig dstConfig = dst->config();
2149 GrPixelConfig srcConfig = src->config();
2150
2151 int dstSampleCnt = 0;
2152 int srcSampleCnt = 0;
2153 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2154 dstSampleCnt = rtProxy->numColorSamples();
2155 }
2156 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2157 srcSampleCnt = rtProxy->numColorSamples();
2158 }
2159 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2160 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2161
2162 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2163 // swizzle.
2164 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2165 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2166 return false;
2167 }
2168
2169 const GrTextureProxy* dstTex = dst->asTextureProxy();
2170 const GrTextureProxy* srcTex = src->asTextureProxy();
2171
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002172 bool dstIsTex2D = dstTex ? (dstTex->textureType() == GrTextureType::k2D) : false;
2173 bool srcIsTex2D = srcTex ? (srcTex->textureType() == GrTextureType::k2D) : false;
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002174
2175 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2176 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2177 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2178 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2179 // know we will at least be able to do it as a draw.
2180#ifdef SK_DEBUG
2181 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2182 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2183 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2184 !src->priv().isExact()) {
2185 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2186 }
2187#endif
2188
2189 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2190 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2191 srcConfig, has_msaa_render_buffer(src, *this),
2192 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2193 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2194 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2195 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2196 dstPoint) ||
2197 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2198}
2199
Robert Phillipsbf25d432017-04-07 10:08:53 -04002200bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002201 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2202 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002203 // By default, we don't require rects to match.
2204 *rectsMustMatch = false;
2205
2206 // By default, we allow subrects.
2207 *disallowSubrect = false;
2208
Brian Salomon467921e2017-03-06 16:17:12 -05002209 // If the src is a texture, we can implement the blit as a draw assuming the config is
2210 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002211 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002212 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002213 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2214 desc->fConfig = src->config();
2215 return true;
2216 }
2217
Robert Phillipsbf25d432017-04-07 10:08:53 -04002218 {
2219 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2220 // wrapped. In that case the proxy would already be instantiated.
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002221 const GrTexture* srcTexture = src->peekTexture();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002222 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2223 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2224 // Not supported for FBO blit or CopyTexSubImage
2225 return false;
2226 }
Brian Salomon467921e2017-03-06 16:17:12 -05002227 }
2228
2229 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2230 // possible and we return false to fallback to creating a render target dst for render-to-
2231 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2232 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002233 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002234 bool rectsMustMatchForBlitFramebuffer = false;
2235 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002236 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002237 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2238 rectsMustMatchForBlitFramebuffer = true;
2239 disallowSubrectForBlitFramebuffer = true;
2240 // Mirroring causes rects to mismatch later, don't allow it.
2241 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002242 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2243 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002244 rectsMustMatchForBlitFramebuffer = true;
2245 // Mirroring causes rects to mismatch later, don't allow it.
2246 originForBlitFramebuffer = src->origin();
2247 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002248 originForBlitFramebuffer = src->origin();
2249 }
2250
2251 // Check for format issues with glCopyTexSubImage2D
2252 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2253 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2254 // then we set up for that, otherwise fail.
2255 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002256 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002257 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002258 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2259 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002260 return true;
2261 }
2262 return false;
2263 }
2264
Robert Phillipsbf25d432017-04-07 10:08:53 -04002265 {
Brian Salomon63e79732017-05-15 21:23:13 -04002266 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2267 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002268 if (srcIsMSAARenderbuffer) {
2269 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2270 // blit or fail.
2271 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002272 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002273 desc->fConfig = src->config();
2274 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2275 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2276 return true;
2277 }
2278 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002279 }
Brian Salomon467921e2017-03-06 16:17:12 -05002280 }
2281
2282 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002283 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002284 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002285 desc->fFlags = kNone_GrSurfaceFlags;
2286 return true;
2287}
2288
Greg Daniel691f5e72018-02-28 14:21:34 -05002289void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2290 const GrContextOptions& contextOptions,
2291 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002292 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2293 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002294 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2295 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002296 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002297 fDiscardRenderTargetSupport = false;
2298 fInvalidateFBType = kNone_InvalidateFBType;
2299 }
2300
2301 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2302 // 340.96 and 367.57.
2303 if (kGL_GrGLStandard == ctxInfo.standard() &&
2304 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002305 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002306 fClearTextureSupport = false;
2307 }
2308
2309 // Calling glClearTexImage crashes on the NexusPlayer.
2310 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2311 fClearTextureSupport = false;
2312 }
2313
2314 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2315#ifdef SK_BUILD_FOR_MAC
2316 if (shaderCaps->fGeometryShaderSupport) {
2317 shaderCaps->fGSInvocationsSupport = false;
2318 }
2319#endif
2320
2321 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2322 // shaders. @127.0 is the earliest verified driver to not crash.
2323 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002324 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002325 shaderCaps->fGeometryShaderSupport = false;
2326 }
2327
2328#if defined(__has_feature)
2329#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2330 // See skbug.com/7058
2331 fMapBufferType = kNone_MapBufferType;
2332 fMapBufferFlags = kNone_MapFlags;
2333#endif
2334#endif
2335
2336 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2337 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2338 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2339 // unclear whether this really affects a wide range of devices.
2340 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002341 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002342 fMapBufferType = kNone_MapBufferType;
2343 fMapBufferFlags = kNone_MapFlags;
2344 }
2345
2346 // TODO: re-enable for ANGLE
2347 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2348 fTransferBufferType = kNone_TransferBufferType;
2349 }
2350
2351 // Using MIPs on this GPU seems to be a source of trouble.
2352 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2353 fMipMapSupport = false;
2354 }
2355
2356 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2357 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2358 // around a driver bug related to gl_FragCoord.
2359 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2360 fMaxClipAnalyticFPs = 0;
2361 }
2362
2363#ifndef SK_BUILD_FOR_IOS
2364 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2365 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2366 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2367 ctxInfo.driver() != kChromium_GrGLDriver)) {
2368 fUseDrawToClearColor = true;
2369 }
2370#endif
2371
2372 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2373 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2374 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2375 fUseDrawToClearColor = true;
2376 }
2377
2378#ifdef SK_BUILD_FOR_MAC
2379 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2380 // full screen clears
2381 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2382 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002383 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2384 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2385 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2386 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002387 fUseDrawToClearColor = true;
2388 }
2389#endif
2390
2391 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2392 // bugs seems to involve clearing too much and not skipping the clear.
2393 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2394 // but only for D3D11 ANGLE.
2395 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2396 fUseDrawToClearColor = true;
2397 }
2398
Chris Dalton1214be92018-06-28 19:06:27 -06002399 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2400 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002401 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002402 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002403 fUseDrawToClearStencilClip = true;
2404 }
2405 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2406 }
2407
Adrienne Walker94f585e2018-05-15 11:47:07 -07002408 if (fDriverBugWorkarounds.gl_clear_broken) {
2409 fUseDrawToClearColor = true;
2410 fUseDrawToClearStencilClip = true;
2411 }
2412
Brian Salomon01b476a2018-01-23 11:06:41 -05002413 // This was reproduced on the following configurations:
2414 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2415 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2416 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2417 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2418 // and not produced on:
2419 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2420 // The particular lines that get dropped from test images varies across different devices.
2421 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002422 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002423 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2424 }
2425
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002426 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2427 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2428 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002429 fRequiresFlushBetweenNonAndInstancedDraws = true;
2430 }
2431
Brian Salomon01b476a2018-01-23 11:06:41 -05002432 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2433 // given 1 << 15 or more instances.
2434 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2435 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
Adrienne Walker001cae02018-05-15 11:38:44 -07002436 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
2437 fMaxInstancesPerDrawArraysWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002438 }
2439
2440 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002441 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002442 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2443 fUseDrawInsteadOfAllRenderTargetWrites = true;
2444 }
2445
2446 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2447 fSampleShadingSupport = false;
2448 }
2449
2450#ifdef SK_BUILD_FOR_MAC
2451 static constexpr bool isMAC = true;
2452#else
2453 static constexpr bool isMAC = false;
2454#endif
2455
2456 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2457 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2458 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2459 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2460 if (fMipMapLevelAndLodControlSupport &&
2461 (contextOptions.fDoManualMipmapping ||
2462 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2463 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2464 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2465 fDoManualMipmapping = true;
2466 }
2467
2468 // See http://crbug.com/710443
2469#ifdef SK_BUILD_FOR_MAC
2470 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2471 fClearToBoundaryValuesIsBroken = true;
2472 }
2473#endif
2474 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2475 fDrawArraysBaseVertexIsBroken = true;
2476 }
2477
Brian Salomon01b476a2018-01-23 11:06:41 -05002478 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2479 // Galaxy S7.
2480 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2481 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2482 shaderCaps->fFBFetchSupport = false;
2483 }
2484
Brian Salomon01b476a2018-01-23 11:06:41 -05002485 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2486 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2487
2488 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2489 // function that may require a gradient calculation inside a conditional block may return
2490 // undefined results". This appears to be an issue with the 'any' call since even the simple
2491 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2492 // from our GrTextureDomain processor.
2493 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2494
2495 // Known issue on at least some Intel platforms:
2496 // http://code.google.com/p/skia/issues/detail?id=946
2497 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2498 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2499 }
2500
Chris Dalton0090ef62018-03-28 17:35:00 -06002501 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002502 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2503 // so we must do the abs first in a separate expression.
2504 shaderCaps->fCanUseMinAndAbsTogether = false;
2505
2506 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2507 // must avoid this condition.
2508 shaderCaps->fCanUseFractForNegativeValues = false;
2509 }
2510
2511 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2512 // thus must us -1.0 * %s.x to work correctly
2513 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2514 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2515 }
2516
2517 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2518 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2519 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2520 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2521 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2522 }
2523
2524 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2525 // the original dst color when reading the outColor even after being written to. By using a
2526 // local outColor we can work around this bug.
2527 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2528 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2529 }
2530
2531 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2532 // color, and that uniform contains an opaque color, and the output of the shader is only based
2533 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2534 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2535 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2536 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2537 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2538 shaderCaps->fMustObfuscateUniformColor = true;
2539 }
2540#ifdef SK_BUILD_FOR_WIN
2541 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2542 //
2543 // Basically, if a shader has a construct like:
2544 //
2545 // float x = someCondition ? someValue : 0;
2546 // float2 result = (0 == x) ? float2(x, x)
2547 // : float2(2 * x / x, 0);
2548 //
2549 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2550 // we've explicitly guarded the division with a check against zero. This manifests in much
2551 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2552 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2553 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2554 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2555 }
2556#endif
2557
2558 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002559 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002560 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2561 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002562 }
2563
Chris Dalton0090ef62018-03-28 17:35:00 -06002564 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2565 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2566 shaderCaps->fCanUseFragCoord = false;
2567 }
2568
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002569 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2570 // (Are they implemented with fp16?)
2571 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2572 shaderCaps->fIncompleteShortIntPrecision = true;
2573 }
2574
Adrienne Walkeree8295c2018-08-21 10:56:30 -07002575 if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
2576 shaderCaps->fAddAndTrueToLoopCondition = true;
2577 }
2578
Adrienne Walkerc02165f2018-08-21 11:08:11 -07002579 if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
2580 shaderCaps->fUnfoldShortCircuitAsTernary = true;
2581 }
2582
Adrienne Walker92b161f2018-08-22 10:41:52 -07002583 if (fDriverBugWorkarounds.emulate_abs_int_function) {
2584 shaderCaps->fEmulateAbsIntFunction = true;
2585 }
2586
Adrienne Walker8b23ca62018-08-22 10:45:41 -07002587 if (fDriverBugWorkarounds.rewrite_do_while_loops) {
2588 shaderCaps->fRewriteDoWhileLoops = true;
2589 }
2590
Adrienne Walker2f4c09b2018-08-22 16:04:57 -07002591 if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
2592 shaderCaps->fRemovePowWithConstantExponent = true;
2593 }
2594
Brian Salomon01b476a2018-01-23 11:06:41 -05002595 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2596 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002597 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2598 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002599 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2600 kIntel_GrGLDriver == ctxInfo.driver() ||
2601 kChromium_GrGLDriver == ctxInfo.driver()) {
2602 fBlendEquationSupport = kBasic_BlendEquationSupport;
2603 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2604 }
2605
2606 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2607 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002608 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002609 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002610 fBlendEquationSupport = kBasic_BlendEquationSupport;
2611 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2612 }
2613
Adrienne Walker68314842018-05-14 14:02:53 -07002614 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2615 fBlendEquationSupport = kBasic_BlendEquationSupport;
2616 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2617 }
2618
Brian Salomon01b476a2018-01-23 11:06:41 -05002619 if (this->advancedBlendEquationSupport()) {
2620 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002621 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002622 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2623 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2624 (1 << kColorBurn_GrBlendEquation);
2625 }
2626 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2627 // Blacklist color-burn on ARM until the fix is released.
2628 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2629 }
2630 }
2631
2632 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2633 if (fMultisampleDisableSupport &&
2634 this->shaderCaps()->dualSourceBlendingSupport() &&
2635 this->shaderCaps()->pathRenderingSupport() &&
2636 fUsesMixedSamples &&
2637#if GR_TEST_UTILS
2638 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2639#endif
2640 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2641 kChromium_GrGLDriver == ctxInfo.driver())) {
2642 fDiscardRenderTargetSupport = false;
2643 fInvalidateFBType = kNone_InvalidateFBType;
2644 }
Brian Osmanc585e202018-04-04 14:08:27 -04002645
Brian Osman061020e2018-04-17 14:22:15 -04002646 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2647 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2648 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2649 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002650 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2651 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002652 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002653 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002654 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2655 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002656 }
Brian Osman2fa53742018-05-03 15:05:12 -04002657
2658#ifdef SK_BUILD_FOR_IOS
2659 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2660 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2661 // is to just blacklist the feature.
2662 // https://github.com/flutter/flutter/issues/16718
2663 // https://bugreport.apple.com/web/?problemID=39948888
2664 fUnpackRowLengthSupport = false;
2665#endif
Chris Daltona2b5b642018-06-24 13:08:57 -06002666
2667#ifdef SK_BUILD_FOR_MAC
2668 // Radeon MacBooks hit a crash in glReadPixels() when using CCPR.
2669 // http://skbug.com/8097
2670 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2671 fBlacklistCoverageCounting = true;
2672 }
2673#endif
Chris Daltonc4e72a42018-06-25 06:44:01 -06002674
2675 // "shapes_mixed_10000_32x33" bench crashes PowerVRGX6250 in Release mode with ccpr.
2676 // http://skbug.com/8098
2677 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2678 fBlacklistCoverageCounting = true;
2679 }
Chris Dalton1c1391c2018-07-20 12:21:14 -06002680
Chris Daltonb70beea2018-07-23 12:17:10 -06002681 // CCPR edge AA is busted on Mesa, Sandy Bridge/Bay Trail.
Chris Dalton1c1391c2018-07-20 12:21:14 -06002682 // http://skbug.com/8162
Chris Daltonb70beea2018-07-23 12:17:10 -06002683 if (kMesa_GrGLDriver == ctxInfo.driver() &&
2684 (kIntelSandyBridge_GrGLRenderer == ctxInfo.renderer() ||
2685 kIntelBayTrail_GrGLRenderer == ctxInfo.renderer())) {
Chris Dalton1c1391c2018-07-20 12:21:14 -06002686 fBlacklistCoverageCounting = true;
2687 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002688}
2689
csmartdaltone0d36292016-07-29 08:14:20 -07002690void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002691 if (options.fDisableDriverCorrectnessWorkarounds) {
2692 SkASSERT(!fDoManualMipmapping);
2693 SkASSERT(!fClearToBoundaryValuesIsBroken);
2694 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2695 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2696 SkASSERT(!fUseDrawToClearColor);
2697 SkASSERT(!fUseDrawToClearStencilClip);
2698 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2699 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2700 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002701 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Salomon01b476a2018-01-23 11:06:41 -05002702 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002703 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2704 fUseDrawToClearColor = false;
2705 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2706 fUseDrawToClearColor = true;
2707 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002708 if (options.fDoManualMipmapping) {
2709 fDoManualMipmapping = true;
2710 }
csmartdaltone0d36292016-07-29 08:14:20 -07002711}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002712
Brian Salomon3d86a192018-02-27 16:46:11 -05002713bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2714 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2715 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2716 if (tex->hasBaseLevelBeenBoundToFBO()) {
2717 return false;
2718 }
2719 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002720 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002721 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2722 return false;
2723 }
2724 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2725 return false;
2726 }
2727 return SkToBool(surface->asTexture());
2728 }
2729 return true;
2730}
2731
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002732bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2733 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2734 // We don't support reading pixels directly from EXTERNAL textures as it would require
2735 // binding the texture to a FBO.
2736 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2737 return false;
2738 }
2739 }
2740 return true;
2741}
2742
2743GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2744 GrColorType dstColorType) const {
2745 // For now, we mostly report the read back format that is required by the ES spec without
2746 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2747 // this as makes sense to increase performance and correctness.
2748 switch (fConfigTable[config].fFormatType) {
2749 case kNormalizedFixedPoint_FormatType:
2750 return GrColorType::kRGBA_8888;
2751 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002752 if ((kAlpha_half_GrPixelConfig == config ||
2753 kAlpha_half_as_Red_GrPixelConfig == config) &&
2754 GrColorType::kAlpha_F16 == dstColorType) {
2755 return GrColorType::kAlpha_F16;
2756 }
2757 // And similar for full float RG.
2758 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2759 return GrColorType::kRG_F32;
2760 }
2761 return GrColorType::kRGBA_F32;
2762 }
2763 return GrColorType::kUnknown;
2764}
2765
Greg Daniel2a303902018-02-20 10:25:54 -05002766bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002767 GrGLFramebufferInfo fbInfo;
2768 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002769 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002770 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002771}
2772
Brian Salomonbdecacf2018-02-02 20:32:49 -05002773int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2774 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002775 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002776 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002777 return 0;
2778 }
2779
Brian Salomonbdecacf2018-02-02 20:32:49 -05002780 if (1 == requestedCount) {
2781 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2782 }
2783
Greg Daniel81e7bf82017-07-19 14:47:42 -04002784 for (int i = 0; i < count; ++i) {
2785 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002786 int count = fConfigTable[config].fColorSampleCounts[i];
2787 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2788 count = SkTMin(count, 4);
2789 }
2790 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002791 }
2792 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002793 return 0;
2794}
2795
2796int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2797 const auto& table = fConfigTable[config].fColorSampleCounts;
2798 if (!table.count()) {
2799 return 0;
2800 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002801 int count = table[table.count() - 1];
2802 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2803 count = SkTMin(count, 4);
2804 }
2805 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002806}
2807
Greg Danielfaa095e2017-12-19 13:15:02 -05002808bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2809 GrGLStandard standard) {
2810 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002811
2812 switch (ct) {
2813 case kUnknown_SkColorType:
2814 return false;
2815 case kAlpha_8_SkColorType:
2816 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002817 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002818 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002819 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002820 }
2821 break;
2822 case kRGB_565_SkColorType:
2823 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002824 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002825 }
2826 break;
2827 case kARGB_4444_SkColorType:
2828 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002829 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002830 }
2831 break;
2832 case kRGBA_8888_SkColorType:
2833 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002834 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002835 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002836 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002837 }
2838 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002839 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002840 if (GR_GL_RGB8 == format) {
2841 *config = kRGB_888_GrPixelConfig;
2842 }
2843 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002844 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002845 if (GR_GL_RGBA8 == format) {
2846 if (kGL_GrGLStandard == standard) {
2847 *config = kBGRA_8888_GrPixelConfig;
2848 }
2849 } else if (GR_GL_BGRA8 == format) {
2850 if (kGLES_GrGLStandard == standard) {
2851 *config = kBGRA_8888_GrPixelConfig;
2852 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002853 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002854 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002855 }
2856 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002857 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002858 if (GR_GL_RGB10_A2 == format) {
2859 *config = kRGBA_1010102_GrPixelConfig;
2860 }
2861 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002862 case kRGB_101010x_SkColorType:
2863 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002864 case kGray_8_SkColorType:
2865 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002866 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002867 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002868 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002869 }
2870 break;
2871 case kRGBA_F16_SkColorType:
2872 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002873 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002874 }
2875 break;
Mike Klein37854712018-06-26 11:43:06 -04002876 case kRGBA_F32_SkColorType:
2877 if (GR_GL_RGBA32F == format) {
2878 *config = kRGBA_float_GrPixelConfig;
2879 }
2880 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002881 }
2882
Greg Danielfaa095e2017-12-19 13:15:02 -05002883 return kUnknown_GrPixelConfig != *config;
2884}
2885
2886bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2887 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002888 GrGLTextureInfo texInfo;
2889 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002890 return false;
2891 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002892 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002893}
2894
2895bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2896 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002897 GrGLFramebufferInfo fbInfo;
2898 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002899 return false;
2900 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002901 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002902}
2903
Robert Phillipsfc711a22018-02-13 17:03:00 -05002904bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2905 GrPixelConfig* config) const {
2906 const GrGLenum* glFormat = format.getGLFormat();
2907 if (!glFormat) {
2908 return false;
2909 }
2910 return validate_sized_format(*glFormat, ct, config, fStandard);
2911}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002912
Timothy Liang036fdfe2018-06-28 15:50:36 -04002913#ifdef GR_TEST_UTILS
2914GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2915 const GrBackendTexture& backendTex) const {
2916 GrGLTextureInfo glInfo;
2917 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2918 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2919}
2920#endif