blob: f32afb064951d7c10ee411402b55040c3123124e [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00008#include "GrGLCaps.h"
egdanielb7e7d572015-11-04 04:23:53 -08009#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000010#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080011#include "GrGLRenderTarget.h"
Brian Salomon467921e2017-03-06 16:17:12 -050012#include "GrGLTexture.h"
Greg Daniel26dbe3b2018-05-03 10:35:42 -040013#include "GrRenderTargetProxyPriv.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050014#include "GrShaderCaps.h"
Robert Phillipsbf25d432017-04-07 10:08:53 -040015#include "GrSurfaceProxyPriv.h"
Greg Daniel26dbe3b2018-05-03 10:35:42 -040016#include "GrTextureProxyPriv.h"
Brian Osman71a18892017-08-10 10:23:25 -040017#include "SkJSONWriter.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000018#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000019#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000020
bsalomon682c2692015-05-22 14:01:46 -070021GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
22 const GrGLContextInfo& ctxInfo,
23 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080024 fStandard = ctxInfo.standard();
25
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000027 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000028 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000029 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080030 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032 fUnpackRowLengthSupport = false;
33 fUnpackFlipYSupport = false;
34 fPackRowLengthSupport = false;
35 fPackFlipYSupport = false;
36 fTextureUsageSupport = false;
Robert Phillips5ab72762017-06-07 12:04:18 -040037 fAlpha8IsRenderable = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080041 fES2CompatibilitySupport = false;
cdalton06604b92016-02-05 10:09:51 -080042 fDrawIndirectSupport = false;
43 fMultiDrawIndirectSupport = false;
44 fBaseInstanceSupport = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080047 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080048 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070049 fRGBA8888PixelsOpsAreSlow = false;
50 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080051 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080052 fRGBAToBGRAReadbackConversionsAreSlow = false;
Robert Phillipsf2ec0242018-03-01 16:51:25 -050053 fUseBufferDataNullHint = SkToBool(GR_GL_USE_BUFFER_DATA_NULL_HINT);
brianosman09563ce2016-06-02 08:59:34 -070054 fDoManualMipmapping = false;
Eric Karlaeaf22b2017-05-18 15:08:09 -070055 fClearToBoundaryValuesIsBroken = false;
Brian Salomond17b4a62017-05-23 16:53:47 -040056 fClearTextureSupport = false;
Chris Dalton9926f4b2017-05-17 15:15:50 -060057 fDrawArraysBaseVertexIsBroken = false;
Brian Salomon43f8bf02017-10-18 08:33:29 -040058 fUseDrawToClearColor = false;
Mike Klein31550db2017-06-06 23:29:53 +000059 fUseDrawToClearStencilClip = false;
Brian Salomon9bada542017-06-12 12:09:30 -040060 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
61 fUseDrawInsteadOfAllRenderTargetWrites = false;
Brian Salomon6d9c88b2017-06-12 10:24:42 -040062 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
Chris Daltonda40cd22018-04-16 13:19:58 -060063 fRequiresFlushBetweenNonAndInstancedDraws = false;
Brian Osman1348ed02018-09-12 09:08:39 -040064 fDetachStencilFromMSAABuffersBeforeReadPixels = false;
Ethan Nicholas06d55fb2017-11-08 09:48:50 -050065 fProgramBinarySupport = false;
piotaixre4b23142014-10-02 10:57:53 -070066
Brian Salomone5e7eb12016-10-14 16:18:33 -040067 fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
Chris Daltoncc604e52017-10-06 16:27:32 -060068 fMaxInstancesPerDrawArraysWithoutCrashing = 0;
bsalomon083617b2016-02-12 12:10:14 -080069
Brian Salomon94efbf52016-11-29 13:43:05 -050070 fShaderCaps.reset(new GrShaderCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070071
cdalton4cd67132015-06-10 19:23:46 -070072 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073}
74
cdalton4cd67132015-06-10 19:23:46 -070075void GrGLCaps::init(const GrContextOptions& contextOptions,
76 const GrGLContextInfo& ctxInfo,
77 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000078 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079 GrGLVersion version = ctxInfo.version();
80
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000081 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000082 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
83 &fMaxFragmentUniformVectors);
84 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000085 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086 GrGLint max;
87 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
88 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000089 if (version >= GR_GL_VER(3, 2)) {
90 GrGLint profileMask;
91 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
92 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
93 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094 }
Adrienne Walker87785d52018-08-09 12:01:43 -070095 if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
96 fMaxFragmentUniformVectors = SkMin32(fMaxFragmentUniformVectors, 32);
97 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000098 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000100 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 fUnpackRowLengthSupport = true;
102 fUnpackFlipYSupport = false;
103 fPackRowLengthSupport = true;
104 fPackFlipYSupport = false;
105 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000106 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
107 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000109 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
110 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 fPackFlipYSupport =
112 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
113 }
114
Adrienne Walkerc48f7762018-05-15 13:03:13 -0700115 if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
116 // In some cases drivers handle copying the last row incorrectly
117 // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
118 // through every row and conditionally clobbering that value, but
119 // Skia already has a scratch buffer workaround when pack row length
120 // is not supported, so just use that.
121 fPackRowLengthSupport = false;
122 }
123
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000124 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000125 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
126
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000127 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700128 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
129 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
130 ctxInfo.hasExtension("GL_NV_texture_barrier");
131 } else {
132 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
133 }
134
Robert Phillips7f861922018-01-30 13:13:42 +0000135 if (kGL_GrGLStandard == standard) {
136 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
137 ctxInfo.hasExtension("GL_ARB_texture_multisample");
138 } else {
139 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
140 }
141
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000142 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000143 ctxInfo.hasExtension("GL_ARB_imaging");
144
Brian Salomon01b476a2018-01-23 11:06:41 -0500145 if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
egdaniel9250d242015-05-18 13:04:26 -0700146 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
147 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000148 fDiscardRenderTargetSupport = true;
149 fInvalidateFBType = kInvalidate_InvalidateFBType;
150 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
151 fDiscardRenderTargetSupport = true;
152 fInvalidateFBType = kDiscard_InvalidateFBType;
153 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000154
Chris Dalton27059d32018-01-23 14:06:50 -0700155 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
156 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
157 if (kGLES_GrGLStandard == standard) {
158 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
159 // TODO: Evaluate on PowerVR.
160 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
161 if (kARM_GrGLVendor == ctxInfo.vendor()) {
162 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
163 }
164 }
165
Chris Dalton344e9032017-12-11 15:42:09 -0700166 if (kARM_GrGLVendor == ctxInfo.vendor() ||
167 kImagination_GrGLVendor == ctxInfo.vendor() ||
168 kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
169 fPreferFullscreenClears = true;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000170 }
171
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000172 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000173 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800174 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
175 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000176 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000177 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
178 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000179 }
180
cdalton626e1ff2015-06-12 13:56:46 -0700181 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
182 fDebugSupport = true;
183 } else {
184 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
185 }
186
jvanverth3f801cb2014-12-16 09:49:38 -0800187 if (kGL_GrGLStandard == standard) {
188 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
189 }
190 else {
191 fES2CompatibilitySupport = true;
192 }
193
cdalton0edea2c2015-05-21 08:27:44 -0700194 if (kGL_GrGLStandard == standard) {
195 fMultisampleDisableSupport = true;
196 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700197 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700198 }
199
kkinnunend94708e2015-07-30 22:47:04 -0700200 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600201 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
202 // instanced arrays, but we could make this more granular if we wanted
203 fInstanceAttribSupport =
204 version >= GR_GL_VER(3, 2) ||
205 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
206 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
207 } else {
208 fInstanceAttribSupport =
209 version >= GR_GL_VER(3, 0) ||
210 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
211 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
212 }
213
214 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700215 if (version >= GR_GL_VER(3, 0)) {
216 fBindFragDataLocationSupport = true;
217 }
218 } else {
219 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
220 fBindFragDataLocationSupport = true;
221 }
joshualittc1f56b52015-06-22 12:31:31 -0700222 }
223
joshualitt7bdd70a2015-10-01 06:28:11 -0700224 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
225
kkinnunene06ed252016-02-16 23:15:40 -0800226 if (kGL_GrGLStandard == standard) {
Weiliang Chen1e04b362018-07-12 17:13:35 -0400227 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
228 ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
kkinnunene06ed252016-02-16 23:15:40 -0800229 // We also require textureSize() support for rectangle 2D samplers which was added in
230 // GLSL 1.40.
231 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
232 fRectangleTextureSupport = true;
233 }
bsalomone179a912016-01-20 06:18:10 -0800234 }
kkinnunene06ed252016-02-16 23:15:40 -0800235 } else {
236 // Command buffer exposes this in GL ES context for Chromium reasons,
237 // but it should not be used. Also, at the time of writing command buffer
238 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800239 }
240
bsalomoncdee0092016-01-08 13:20:12 -0800241 if (kGL_GrGLStandard == standard) {
242 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
243 fTextureSwizzleSupport = true;
244 }
245 } else {
246 if (version >= GR_GL_VER(3,0)) {
247 fTextureSwizzleSupport = true;
248 }
249 }
250
cblume09bd2c02016-03-01 14:08:28 -0800251 if (kGL_GrGLStandard == standard) {
252 fMipMapLevelAndLodControlSupport = true;
253 } else if (kGLES_GrGLStandard == standard) {
254 if (version >= GR_GL_VER(3,0)) {
255 fMipMapLevelAndLodControlSupport = true;
256 }
257 }
258
bsalomon88c7b982015-07-31 11:20:16 -0700259#ifdef SK_BUILD_FOR_WIN
260 // We're assuming that on Windows Chromium we're using ANGLE.
261 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
262 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700263 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700264 fRGBA8888PixelsOpsAreSlow = isANGLE;
265 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
266 // check DX11 ANGLE.
267 fPartialFBOReadIsSlow = isANGLE;
268#endif
269
ericrkb4ecabd2016-03-11 15:18:20 -0800270 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
271 bool isMAC = false;
272#ifdef SK_BUILD_FOR_MAC
273 isMAC = true;
274#endif
275
276 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
277 // vis-versa.
278 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
279
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500280 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
281 fUseBufferDataNullHint = false;
282 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
283 fUseBufferDataNullHint = true;
284 }
285
Brian Salomond17b4a62017-05-23 16:53:47 -0400286 if (kGL_GrGLStandard == standard) {
287 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400288 fClearTextureSupport = true;
289 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500290 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
291 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400292 }
293
Greg Danielb2acf0a2018-09-12 09:17:11 -0400294#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
295 fSupportsAHardwareBufferImages = true;
296#endif
297
cdalton4cd67132015-06-10 19:23:46 -0700298 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700299 * GrShaderCaps fields
300 **************************************************************************/
301
egdaniel0a482332015-10-26 08:59:10 -0700302 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700303 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500304 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700305
Brian Osman195c05b2017-08-30 15:14:04 -0400306 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
307#if GR_TEST_UTILS
308 if (contextOptions.fSuppressPathRendering) {
309 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700310 }
Brian Osman195c05b2017-08-30 15:14:04 -0400311#endif
egdaniel05ded892015-10-26 07:38:05 -0700312
egdaniel05ded892015-10-26 07:38:05 -0700313 // Enable supported shader-related caps
314 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500315 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700316 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
Brian Salomon23c55b62018-06-19 16:28:41 -0400317 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600318
Brian Salomon1edc5b92016-11-29 13:43:46 -0500319 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600320
egdaniel05ded892015-10-26 07:38:05 -0700321 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500322 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700323 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600324 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600325 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
326 shaderCaps->fGSInvocationsSupport = true;
327 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
328 shaderCaps->fGSInvocationsSupport = true;
329 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
330 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600331 }
332
Brian Salomon1edc5b92016-11-29 13:43:46 -0500333 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800334 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500335 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500336 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700337
Brian Salomon1edc5b92016-11-29 13:43:46 -0500338 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700339 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800340
Chris Dalton1214be92018-06-28 19:06:27 -0600341 // Mali and early Adreno both have support for geometry shaders, but they appear to be
342 // implemented in software. In practice with ccpr, they are slower than the backup impl that
343 // only uses vertex shaders.
344 if (kARM_GrGLVendor != ctxInfo.vendor() &&
345 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
346 kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
347
Chris Daltonfaca00d2018-01-19 15:56:07 -0700348 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
349 shaderCaps->fGeometryShaderSupport = true;
350 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
351 shaderCaps->fGeometryShaderSupport = true;
352 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
353 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700354 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500355 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700356
Brian Salomon1edc5b92016-11-29 13:43:46 -0500357 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800358 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700359 }
360
cdalton9c3f1432016-03-11 10:07:37 -0800361 // Protect ourselves against tracking huge amounts of texture state.
362 static const uint8_t kMaxSaneSamplers = 32;
363 GrGLint maxSamplers;
364 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500365 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
366 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800367 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500368 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800369 }
370 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500371 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800372 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500373 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800374
csmartdalton485a1202016-07-13 10:16:32 -0700375 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
376 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
377 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
378 // limit this decision to specific GPU families rather than basing it on the vendor alone.
379 if (!GR_GL_MUST_USE_VBO &&
380 !fIsCoreProfile &&
381 (kARM_GrGLVendor == ctxInfo.vendor() ||
382 kImagination_GrGLVendor == ctxInfo.vendor() ||
383 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
384 fPreferClientSideDynamicBuffers = true;
385 }
386
Eric Karl5c779752017-05-08 12:02:07 -0700387 if (!contextOptions.fAvoidStencilBuffers) {
388 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
389 this->initFSAASupport(contextOptions, ctxInfo, gli);
390 this->initStencilSupport(ctxInfo);
391 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400392
393 // Setup blit framebuffer
394 if (kGL_GrGLStandard != ctxInfo.standard()) {
395 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
396 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
397 kNoMSAADst_BlitFramebufferFlag |
398 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
399 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
400 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
401 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
402 // limitations.
403 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
404 kResolveMustBeFull_BlitFrambufferFlag |
405 kNoMSAADst_BlitFramebufferFlag |
406 kNoFormatConversion_BlitFramebufferFlag |
407 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
408 }
409 } else {
410 if (fUsesMixedSamples ||
411 ctxInfo.version() >= GR_GL_VER(3,0) ||
412 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
413 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
414 fBlitFramebufferFlags = 0;
415 }
416 }
417
cdalton1dd05422015-06-12 09:01:18 -0700418 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000419
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000420 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000421 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
422 // extension includes glMapBuffer.
423 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
424 fMapBufferFlags |= kSubset_MapFlag;
425 fMapBufferType = kMapBufferRange_MapBufferType;
426 } else {
427 fMapBufferType = kMapBuffer_MapBufferType;
428 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000429 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000430 // Unextended GLES2 doesn't have any buffer mapping.
431 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800432 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800433 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
434 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800435 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
436 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
437 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000438 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
439 fMapBufferFlags = kCanMap_MapFlag;
440 fMapBufferType = kMapBuffer_MapBufferType;
441 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000442 }
443
jvanverthd7a2c1f2015-12-07 07:36:44 -0800444 if (kGL_GrGLStandard == standard) {
445 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
446 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700447 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500448 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400449 if (version >= GR_GL_VER(3, 0) ||
450 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
451 // GL_EXT_unpack_subimage needed to support subtexture rectangles
452 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800453 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400454// TODO: get transfer buffers working in Chrome
455// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
456// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800457 }
458 }
459
joshualitte5b74c62015-06-01 14:17:47 -0700460 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
461 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700462 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700463#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500464 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
465 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
466 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700467 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700468#else
cdalton397536c2016-03-25 12:15:03 -0700469 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700470#endif
joshualitte5b74c62015-06-01 14:17:47 -0700471 }
472
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000473 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000474 fNPOTTextureTileSupport = true;
475 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000476 } else {
477 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000478 // ES3 has no limitations.
479 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
480 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000481 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
482 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
483 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
484 // to alllow arbitrary wrap modes, however.
485 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000486 }
487
bsalomon@google.combcce8922013-03-25 15:38:39 +0000488 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700489
490 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
491 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
492 }
493
bsalomon@google.combcce8922013-03-25 15:38:39 +0000494 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
495 // Our render targets are always created with textures as the color
496 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000497 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700498 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
499
500 if (kARM_GrGLVendor == ctxInfo.vendor()) {
501 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
502 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
503 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000504
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000505 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
506
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000507 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700508 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000509
robertphillips1b8e1b52015-06-24 06:54:10 -0700510#if 0
511 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
512 kQualcomm_GrGLVendor != ctxInfo.vendor();
513#endif
514
csmartdalton9bc11872016-08-09 12:42:47 -0700515 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
516 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700517 }
518
robertphillips63926682015-08-20 09:39:02 -0700519#ifdef SK_BUILD_FOR_WIN
520 // On ANGLE deferring flushes can lead to GPU starvation
521 fPreferVRAMUseOverFlushes = !isANGLE;
522#endif
523
bsalomon7dea7b72015-08-19 08:26:51 -0700524 if (kChromium_GrGLDriver == ctxInfo.driver()) {
525 fMustClearUploadedBufferData = true;
526 }
527
bsalomond08ea5f2015-02-20 06:58:13 -0800528 if (kGL_GrGLStandard == standard) {
529 // ARB allows mixed size FBO attachments, EXT does not.
530 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
531 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
532 fOversizedStencilSupport = true;
533 } else {
534 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
535 }
536 } else {
537 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
538 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
539 }
540
joshualitt58001552015-06-26 12:46:36 -0700541 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700542 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
543 ctxInfo.hasExtension("GL_ARB_draw_indirect");
544 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
545 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700546 (fDrawIndirectSupport &&
547 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700548 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700549 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800550 } else {
551 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700552 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
553 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
554 fBaseInstanceSupport = fDrawIndirectSupport &&
555 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700556 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800557 }
558
ethannicholas28ef4452016-03-25 09:26:03 -0700559 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500560 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700561 fSampleShadingSupport = true;
562 }
563 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
564 fSampleShadingSupport = true;
565 }
566
jvanverth84741b32016-09-30 08:39:02 -0700567 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
568 if (kGL_GrGLStandard == standard) {
569 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
570 fFenceSyncSupport = true;
571 }
Brian Osman93a23462017-06-21 15:13:39 -0400572 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700573 fFenceSyncSupport = true;
574 }
575
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400576 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500577 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500578
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400579 if (kGL_GrGLStandard == standard) {
580 if (version >= GR_GL_VER(4, 1)) {
581 fProgramBinarySupport = true;
582 }
583 } else if (version >= GR_GL_VER(3, 0)) {
584 fProgramBinarySupport = true;
585 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400586 if (fProgramBinarySupport) {
587 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400588 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400589 fProgramBinarySupport = count > 0;
590 }
bsalomoncdee0092016-01-08 13:20:12 -0800591 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
592 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800593 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700594
Brian Salomon01b476a2018-01-23 11:06:41 -0500595 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
596 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
597 }
598
cdalton4cd67132015-06-10 19:23:46 -0700599 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500600 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700601
Brian Salomon01b476a2018-01-23 11:06:41 -0500602 // For now these two are equivalent but we could have dst read in shader via some other method.
603 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000604}
605
egdaniel472d44e2015-10-22 08:20:00 -0700606const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
607 bool isCoreProfile) {
608 switch (generation) {
609 case k110_GrGLSLGeneration:
610 if (kGLES_GrGLStandard == standard) {
611 // ES2s shader language is based on version 1.20 but is version
612 // 1.00 of the ES language.
613 return "#version 100\n";
614 } else {
615 SkASSERT(kGL_GrGLStandard == standard);
616 return "#version 110\n";
617 }
618 case k130_GrGLSLGeneration:
619 SkASSERT(kGL_GrGLStandard == standard);
620 return "#version 130\n";
621 case k140_GrGLSLGeneration:
622 SkASSERT(kGL_GrGLStandard == standard);
623 return "#version 140\n";
624 case k150_GrGLSLGeneration:
625 SkASSERT(kGL_GrGLStandard == standard);
626 if (isCoreProfile) {
627 return "#version 150\n";
628 } else {
629 return "#version 150 compatibility\n";
630 }
631 case k330_GrGLSLGeneration:
632 if (kGLES_GrGLStandard == standard) {
633 return "#version 300 es\n";
634 } else {
635 SkASSERT(kGL_GrGLStandard == standard);
636 if (isCoreProfile) {
637 return "#version 330\n";
638 } else {
639 return "#version 330 compatibility\n";
640 }
641 }
cdalton33ad7012016-02-22 07:55:44 -0800642 case k400_GrGLSLGeneration:
643 SkASSERT(kGL_GrGLStandard == standard);
644 if (isCoreProfile) {
645 return "#version 400\n";
646 } else {
647 return "#version 400 compatibility\n";
648 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500649 case k420_GrGLSLGeneration:
650 SkASSERT(kGL_GrGLStandard == standard);
651 if (isCoreProfile) {
652 return "#version 420\n";
653 }
654 else {
655 return "#version 420 compatibility\n";
656 }
egdaniel472d44e2015-10-22 08:20:00 -0700657 case k310es_GrGLSLGeneration:
658 SkASSERT(kGLES_GrGLStandard == standard);
659 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800660 case k320es_GrGLSLGeneration:
661 SkASSERT(kGLES_GrGLStandard == standard);
662 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700663 }
664 return "<no version>";
665}
666
Chris Dalton47c8ed32017-11-15 18:27:09 -0700667bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
668 if (kGLES_GrGLStandard != ctxInfo.standard() &&
669 ctxInfo.version() < GR_GL_VER(4,1) &&
670 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
671 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
672 return true;
673 }
674 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
675 // geometry shaders don't have lower precision than vertex and fragment.
676 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
677 GrGLint range[2];
678 GrGLint bits;
679 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
680 if (range[0] < 127 || range[1] < 127 || bits < 23) {
681 return false;
682 }
683 }
684 return true;
685}
686
687void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700688 GrGLStandard standard = ctxInfo.standard();
689 GrGLVersion version = ctxInfo.version();
690
691 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500692 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700693 **************************************************************************/
694
Brian Salomon1edc5b92016-11-29 13:43:46 -0500695 GrShaderCaps* shaderCaps = fShaderCaps.get();
696 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700697 if (kGLES_GrGLStandard == standard) {
698 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500699 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
700 shaderCaps->fFBFetchSupport = true;
701 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
702 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700703 }
704 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
705 // 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 -0500706 shaderCaps->fFBFetchNeedsCustomOutput = false;
707 shaderCaps->fFBFetchSupport = true;
708 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
709 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700710 }
711 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
712 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500713 shaderCaps->fFBFetchNeedsCustomOutput = false;
714 shaderCaps->fFBFetchSupport = true;
715 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
716 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700717 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500718 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700719 }
720
cdaltonc08f1962016-02-12 12:14:06 -0800721 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500722 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800723 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500724 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800725 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
726 }
Brian Salomon41274562017-09-15 09:40:03 -0700727 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
728 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
729 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800730 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500731 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800732 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
733 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400734 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
735 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500736 shaderCaps->fNoPerspectiveInterpolationSupport = true;
737 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800738 "GL_NV_shader_noperspective_interpolation";
739 }
740 }
741
Brian Salomon1edc5b92016-11-29 13:43:46 -0500742 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
743 shaderCaps->fGLSLGeneration,
744 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800745
Brian Salomon1edc5b92016-11-29 13:43:46 -0500746 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
747 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800748 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800749
750 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500751 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800752 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
753 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500754 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800755 }
756
757 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500758 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800759 }
760
cdalton9c3f1432016-03-11 10:07:37 -0800761 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400762 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
763 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400764 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400765 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
766 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
767 // At least one driver has been found that has this extension without the "GL_" prefix.
768 shaderCaps->fExternalTextureSupport = true;
769 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800770 }
771 }
772
cdaltonc04ce672016-03-11 14:07:38 -0800773 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600774 shaderCaps->fVertexIDSupport = true;
775 } else {
776 // Desktop GLSL 3.30 == ES GLSL 3.00.
777 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
778 }
779
Chris Dalton7c7ff032018-03-28 20:09:58 -0600780 if (kGL_GrGLStandard == standard) {
781 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
782 } else {
783 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
784 }
785
Chris Dalton47c8ed32017-11-15 18:27:09 -0700786 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
787 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400788
789 // Unsigned integers only supported in and after GLSL 1.30.
790 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700791}
792
kkinnunencfe62e32015-07-01 02:58:50 -0700793bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700794 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
795
796 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700797 return false;
798 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700799
kkinnunencfe62e32015-07-01 02:58:50 -0700800 if (kGL_GrGLStandard == ctxInfo.standard()) {
801 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
802 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
803 return false;
804 }
805 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700806 if (!hasChromiumPathRendering &&
807 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700808 return false;
809 }
810 }
811 // We only support v1.3+ of GL_NV_path_rendering which allows us to
812 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
813 // additions are detected by checking the existence of the function.
814 // We also use *Then* functions that not all drivers might have. Check
815 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800816 if (!gli->fFunctions.fStencilThenCoverFillPath ||
817 !gli->fFunctions.fStencilThenCoverStrokePath ||
818 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
819 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
820 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700821 return false;
822 }
823 return true;
824}
bsalomon1aa20292016-01-22 08:16:09 -0800825
Brian Salomon71d9d842016-11-03 13:42:00 -0400826bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800827 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800828 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800829 std::function<bool ()> bindRenderTarget,
830 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400831 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800832 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400833 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800834 return false;
835 }
bsalomon7928ef62016-01-05 10:26:39 -0800836
bsalomon76148af2016-01-12 11:13:47 -0800837 GrGLenum readFormat;
838 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400839 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800840 return false;
841 }
842
bsalomon1aa20292016-01-22 08:16:09 -0800843 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800844 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
845 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
846 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
847 // 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 -0500848 // The manual does not seem to fully match the spec as the spec allows integer formats
849 // when the bound color buffer is an integer buffer. It doesn't specify which integer
850 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500851 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
852 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
853 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800854 return false;
855 }
856 // There is also a set of allowed types, but all the types we use are in the set:
857 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
858 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
859 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
860 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
861 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
862 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
863 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800864 return true;
piotaixre4b23142014-10-02 10:57:53 -0700865 }
bsalomon7928ef62016-01-05 10:26:39 -0800866
bsalomon76148af2016-01-12 11:13:47 -0800867 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500868 switch (fConfigTable[surfaceConfig].fFormatType) {
869 case kNormalizedFixedPoint_FormatType:
870 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
871 return true;
872 }
873 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500874 case kFloat_FormatType:
875 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
876 return true;
877 }
878 break;
bsalomon7928ef62016-01-05 10:26:39 -0800879 }
880
Brian Salomon71d9d842016-11-03 13:42:00 -0400881 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800882 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400883 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800884 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800885 if (!bindRenderTarget()) {
886 return false;
887 }
888 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
889 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800890 rpFormat->fFormat = format;
891 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800892 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800893 }
894
Brian Salomon71d9d842016-11-03 13:42:00 -0400895 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
896 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700897}
898
Eric Karl5c779752017-05-08 12:02:07 -0700899void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
900 const GrGLInterface* gli) {
901 // We need dual source blending and the ability to disable multisample in order to support mixed
902 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
903 // renderer is available and enabled; no other path renderers support this feature.
904 if (fMultisampleDisableSupport &&
905 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400906 this->shaderCaps()->pathRenderingSupport()
907#if GR_TEST_UTILS
908 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
909#endif
910 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700911 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400912 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700913 }
914
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000915 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400916 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
917 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
918 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
919 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
920 fAlpha8IsRenderable = true;
921 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500922 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
923 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
924 // mixed samples we can't use multisampled-render-to-texture.
925 if (fUsesMixedSamples) {
926 fMSFBOType = kMixedSamples_MSFBOType;
927 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000928 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
929 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
930 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400931 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
932 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400933 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400934 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400935 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400936 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000937 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
938 fMSFBOType = kES_Apple_MSFBOType;
939 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000940 } else {
egdanieleed519e2016-01-15 11:36:18 -0800941 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700942 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400943 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
944 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400945
Brian Salomon00731b42016-10-14 11:30:51 -0400946 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400947 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
948 // Core profile removes ALPHA8 support.
949 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
950 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
951 // present.
952 fAlpha8IsRenderable = true;
953 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000954 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
955 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400956 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000957 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000958 }
Eric Karl5c779752017-05-08 12:02:07 -0700959
Brian Salomon01b476a2018-01-23 11:06:41 -0500960 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400961 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
962 fMSFBOType = kNone_MSFBOType;
963 }
964
Eric Karl5c779752017-05-08 12:02:07 -0700965 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
966 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
967 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700968 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000969}
970
cdalton1dd05422015-06-12 09:01:18 -0700971void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500972 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700973
Greg Daniel210883c2017-11-27 15:14:01 -0500974 bool layoutQualifierSupport = false;
975 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
976 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
977 layoutQualifierSupport = true;
978 }
979
cdalton1dd05422015-06-12 09:01:18 -0700980 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
981 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500982 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500983 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
984 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700985 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500986 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700987 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
988 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500989 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500990 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700991 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500992 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700993 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
994 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -0700995 }
cdalton1dd05422015-06-12 09:01:18 -0700996}
997
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000998namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700999const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001000}
1001
Eric Karl5c779752017-05-08 12:02:07 -07001002void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001003
1004 // Build up list of legal stencil formats (though perhaps not supported on
1005 // the particular gpu/driver) from most preferred to least.
1006
1007 // these consts are in order of most preferred to least preferred
1008 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1009
1010 static const StencilFormat
1011 // internal Format stencil bits total bits packed?
1012 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1013 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1014 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1015 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001016 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001017 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1018
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001019 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001020 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001021 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001022 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1023 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1024
1025 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1026 // require FBO support we can expect these are legal formats and don't
1027 // check. These also all support the unsized GL_STENCIL_INDEX.
1028 fStencilFormats.push_back() = gS8;
1029 fStencilFormats.push_back() = gS16;
1030 if (supportsPackedDS) {
1031 fStencilFormats.push_back() = gD24S8;
1032 }
1033 fStencilFormats.push_back() = gS4;
1034 if (supportsPackedDS) {
1035 fStencilFormats.push_back() = gDS;
1036 }
1037 } else {
1038 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1039 // for other formats.
1040 // ES doesn't support using the unsized format.
1041
1042 fStencilFormats.push_back() = gS8;
1043 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001044 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1045 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001046 fStencilFormats.push_back() = gD24S8;
1047 }
1048 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1049 fStencilFormats.push_back() = gS4;
1050 }
1051 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001052}
1053
Brian Osman71a18892017-08-10 10:23:25 -04001054void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001055
Brian Osman71a18892017-08-10 10:23:25 -04001056 // We are called by the base class, which has already called beginObject(). We choose to nest
1057 // all of our caps information in a named sub-object.
1058 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001059
Brian Osman71a18892017-08-10 10:23:25 -04001060 writer->beginArray("Stencil Formats");
1061
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001062 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001063 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001064 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1065 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1066 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001067 }
1068
Brian Osman71a18892017-08-10 10:23:25 -04001069 writer->endArray();
1070
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001071 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001072 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001073 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001074 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001075 "IMG MS To Texture",
1076 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001077 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001078 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001079 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001080 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1081 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1082 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1083 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1084 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001085 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001086
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001087 static const char* kInvalidateFBTypeStr[] = {
1088 "None",
1089 "Discard",
1090 "Invalidate",
1091 };
1092 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1093 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1094 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1095 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001096
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001097 static const char* kMapBufferTypeStr[] = {
1098 "None",
1099 "MapBuffer",
1100 "MapBufferRange",
1101 "Chromium",
1102 };
1103 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1104 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1105 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1106 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1107 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1108
Brian Osman71a18892017-08-10 10:23:25 -04001109 writer->appendBool("Core Profile", fIsCoreProfile);
1110 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1111 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1112 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1113 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1114 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1115 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1116 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1117 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001118
Brian Osman71a18892017-08-10 10:23:25 -04001119 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001120 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1121 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1122 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001123 writer->appendBool("Debug support", fDebugSupport);
1124 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1125 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1126 writer->appendBool("Base instance support", fBaseInstanceSupport);
1127 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1128 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1129 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1130 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1131 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1132 writer->appendBool("BGRA to RGBA readback conversions are slow",
1133 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001134 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001135 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1136 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001137 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1138 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1139 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1140 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001141 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1142 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001143
Brian Osman71a18892017-08-10 10:23:25 -04001144 writer->beginArray("configs");
1145
bsalomon41e4384e2016-01-08 09:12:44 -08001146 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001147 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001148 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1149 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1150 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001151 writer->appendHexU32("e_format_read_pixels",
1152 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001153 writer->appendHexU32(
1154 "e_format_teximage",
1155 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1156 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1157 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1158 writer->appendHexU32("i_for_renderbuffer",
1159 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1160 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001161 }
1162
Brian Osman71a18892017-08-10 10:23:25 -04001163 writer->endArray();
1164 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001165}
1166
bsalomon41e4384e2016-01-08 09:12:44 -08001167bool GrGLCaps::bgraIsInternalFormat() const {
1168 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1169}
1170
bsalomon76148af2016-01-12 11:13:47 -08001171bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1172 GrGLenum* internalFormat, GrGLenum* externalFormat,
1173 GrGLenum* externalType) const {
1174 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1175 externalFormat, externalType)) {
1176 return false;
1177 }
1178 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1179 return true;
1180}
1181
bsalomon76148af2016-01-12 11:13:47 -08001182bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1183 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001184 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001185 externalFormat, externalType)) {
1186 return false;
1187 }
1188 return true;
1189}
1190
Brian Salomon93348dd2018-08-29 12:56:23 -04001191void GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001192 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
Brian Salomon93348dd2018-08-29 12:56:23 -04001193}
1194
1195void GrGLCaps::getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1196 *internalFormat = fConfigTable[config].fFormats.fSizedInternalFormat;
bsalomon76148af2016-01-12 11:13:47 -08001197}
1198
1199bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1200 ExternalFormatUsage usage, GrGLenum* externalFormat,
1201 GrGLenum* externalType) const {
1202 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001203
1204 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1205 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1206
1207 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001208 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1209 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001210 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1211 return false;
1212 }
1213
1214 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1215 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1216
bsalomone9573312016-01-25 14:33:25 -08001217 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1218 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1219 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1220 // texture, not the red component.
1221 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001222 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001223 *externalFormat = GR_GL_ALPHA;
1224 }
1225 }
1226
bsalomon76148af2016-01-12 11:13:47 -08001227 return true;
1228}
1229
brianosman20471892016-12-02 06:43:32 -08001230void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1231 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001232 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001233 /*
1234 Comments on renderability of configs on various GL versions.
1235 OpenGL < 3.0:
1236 no built in support for render targets.
1237 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1238 format RGB, RGBA and NV float formats we don't use.
1239 This is the following:
1240 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1241 RGB10_A2, RGBA12,RGBA16
1242 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1243 since they aren't required by later standards and the driver can simply return
1244 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1245 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1246 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1247 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1248 This adds a lot of additional renderable sized formats, including ALPHA8.
1249 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1250 16F, 32I, 32UI, and 32F variants).
1251 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1252
1253 For both the above extensions we limit ourselves to those that are also required by
1254 OpenGL 3.0.
1255
1256 OpenGL 3.0:
1257 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1258 but are not required to be supported as renderable textures/renderbuffer.
1259 Required renderable color formats:
1260 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1261 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1262 RGB10_A2.
1263 - R11F_G11F_B10F.
1264 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1265 and RG8UI.
1266 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1267 - ALPHA8
1268
1269 OpenGL 3.1, 3.2, 3.3
1270 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1271 OpengGL 3.3, 4.0, 4.1
1272 Adds RGB10_A2UI.
1273 OpengGL 4.2
1274 Adds
1275 - RGB5_A1, RGBA4
1276 - RGB565
1277 OpenGL 4.4
1278 Does away with the separate list and adds a column to the sized internal color format
1279 table. However, no new formats become required color renderable.
1280
1281 ES 2.0
1282 color renderable: RGBA4, RGB5_A1, RGB565
1283 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1284 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1285 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1286 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1287 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1288 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1289
1290 ES 3.0
1291 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1292 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1293 RGB5_A1.
1294 - RGB8 and RGB565.
1295 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1296 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1297 ES 3.1
1298 Adds RGB10_A2, RGB10_A2UI,
1299 ES 3.2
1300 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1301 */
Brian Salomon44804c02018-01-23 16:51:28 -05001302
1303 // Correctness workarounds.
1304 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001305 bool disableSRGBForX86PowerVR = false;
1306 bool disableSRGBWriteControlForAdreno4xx = false;
1307 bool disableR8TexStorageForANGLEGL = false;
1308 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001309 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001310 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001311
1312 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1313 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1314 // and GL_RG on FBO textures.
1315 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1316
Greg Daniel09c94002018-06-08 22:11:51 +00001317 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1318
Brian Salomon44804c02018-01-23 16:51:28 -05001319 bool isX86PowerVR = false;
1320#if defined(SK_CPU_X86)
1321 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1322 isX86PowerVR = true;
1323 }
1324#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001325 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1326 // blacklist that device (and any others that might be sharing the same driver).
1327 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001328 disableSRGBWriteControlForAdreno4xx =
1329 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1330 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001331
1332 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1333 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1334 // check that we are not going to OpenGL.
1335 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1336
1337 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1338#if defined(SK_BUILD_FOR_MAC)
1339 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1340#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001341 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1342 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001343 }
1344
Brian Salomon71d9d842016-11-03 13:42:00 -04001345 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1346 ConfigInfo::kFBOColorAttachment_Flag;
1347 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001348 if (kNone_MSFBOType != fMSFBOType) {
1349 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1350 }
bsalomon41e4384e2016-01-08 09:12:44 -08001351 GrGLStandard standard = ctxInfo.standard();
1352 GrGLVersion version = ctxInfo.version();
1353
cblume790d5132016-02-29 11:13:29 -08001354 bool texStorageSupported = false;
1355 if (kGL_GrGLStandard == standard) {
1356 // The EXT version can apply to either GL or GLES.
1357 texStorageSupported = version >= GR_GL_VER(4,2) ||
1358 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1359 ctxInfo.hasExtension("GL_EXT_texture_storage");
1360 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001361 texStorageSupported = version >= GR_GL_VER(3,0) ||
1362 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001363 }
Adrienne Walker70e468f2018-08-22 16:05:27 -07001364 if (fDriverBugWorkarounds.disable_texture_storage) {
1365 texStorageSupported = false;
1366 }
cblume790d5132016-02-29 11:13:29 -08001367
Brian Salomone609e812018-01-17 14:00:47 -05001368 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001369
1370 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001371 if (kGL_GrGLStandard == standard) {
1372 textureRedSupport =
1373 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1374 } else {
1375 textureRedSupport =
1376 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1377 }
1378 }
1379
bsalomon30447372015-12-21 09:03:05 -08001380 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1381 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001382 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001383 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001384 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001385 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001386
1387 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1388 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001389 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001390 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001391 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001392 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001393 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1394 if (kGL_GrGLStandard == standard) {
1395 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1396 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001397 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001398 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1399 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1400 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1401 }
egdaniel4999df82016-01-07 17:06:04 -08001402 }
cblume790d5132016-02-29 11:13:29 -08001403 if (texStorageSupported) {
1404 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1405 }
bsalomoncdee0092016-01-08 13:20:12 -08001406 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001407
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001408 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1409 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1410 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1411 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1412 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1413 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1414 // supportedReadPixelsColorType never returns it.
1415 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1416 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1417 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1418 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1419 if (kGL_GrGLStandard == standard) {
1420 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1421 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1422 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1423 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1424 // becomes an issue.
1425 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1426 // but we don't support that just for simplicity's sake.
1427 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1428 } else {
1429 // 3.0 and the extension support this as a render buffer format.
1430 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1431 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1432 }
1433 }
1434 if (texStorageSupported) {
1435 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1436 }
1437 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1438 if (disableRGB8ForMali400) {
1439 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1440 }
1441
1442 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001443 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001444 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001445 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001446
1447 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1448 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1449 // GL_EXT_texture_format_BGRA8888.
1450 bool supportsBGRATexStorage = false;
1451
bsalomon41e4384e2016-01-08 09:12:44 -08001452 if (kGL_GrGLStandard == standard) {
1453 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1454 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1455 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1456 // Since the internal format is RGBA8, it is also renderable.
1457 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1458 allRenderFlags;
1459 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001460 // Since we are using RGBA8 we can use tex storage.
1461 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001462 } else {
1463 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1464 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001465 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1466 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1467 nonMSAARenderFlags;
1468
1469 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1470 supportsBGRATexStorage = true;
1471 }
1472 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1473 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1474 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1475 ConfigInfo::kRenderableWithMSAA_Flag;
1476 }
1477 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001478 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1479 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1480 // driver remembers the external format when the texture is created (with TexImage).
1481 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1482 // We could work around this, but it adds even more state tracking to code that is
1483 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1484 // This also side-steps some ambiguous interactions with the texture storage extension.
1485 if (version >= GR_GL_VER(3,0)) {
1486 // The APPLE extension doesn't make this renderable.
1487 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001488 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001489 }
bsalomon41e4384e2016-01-08 09:12:44 -08001490 }
1491 }
Brian Osman48c99192017-06-02 08:45:06 -04001492
Greg Daniel0ff79b22018-02-15 12:33:33 -05001493 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001494 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001495 }
bsalomoncdee0092016-01-08 13:20:12 -08001496 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001497
Brian Osman2b23c4b2018-06-01 12:25:08 -04001498 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001499 if (kGL_GrGLStandard == standard) {
1500 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001501 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001502 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1503 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1504 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001505 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001506 }
1507 }
1508 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001509 if (fSRGBSupport) {
1510 fSRGBWriteControl = true;
1511 }
bsalomon41e4384e2016-01-08 09:12:44 -08001512 } else {
brianosman20471892016-12-02 06:43:32 -08001513 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001514 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001515 fSRGBSupport = false;
1516 }
bsalomon41e4384e2016-01-08 09:12:44 -08001517 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1518 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001519 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001520 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001521 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001522 }
brianosman20471892016-12-02 06:43:32 -08001523
1524 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1525 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1526 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1527 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1528 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1529 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1530 // affects Windows.
1531 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1532 fSRGBSupport = false;
1533 }
1534
Brian Osman48c99192017-06-02 08:45:06 -04001535 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1536 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1537 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1538
Brian Osman67999392017-05-31 16:19:34 -04001539 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001540 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001541 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1542 }
Brian Osman67999392017-05-31 16:19:34 -04001543
bsalomon30447372015-12-21 09:03:05 -08001544 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1545 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1546 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1547 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001548 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001549 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001550 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001551 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001552 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001553 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001554 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001555 }
Brian Osman48c99192017-06-02 08:45:06 -04001556 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1557 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001558 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1559 }
bsalomoncdee0092016-01-08 13:20:12 -08001560 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001561 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1562 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1563 // is in this format, for example).
1564 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1565 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1566 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1567 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001568 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001569 GR_GL_BGRA;
1570 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1571 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001572 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001573 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001574 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001575 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001576
brianosmana6359362016-03-21 06:55:37 -07001577 if (texStorageSupported) {
1578 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1579 }
1580 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1581
bsalomon30447372015-12-21 09:03:05 -08001582 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1583 if (this->ES2CompatibilitySupport()) {
1584 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1585 } else {
1586 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1587 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001588 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001589 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001590 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001591 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001592 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1593 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001594 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001595 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1596 }
1597 } else {
1598 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1599 }
cblume790d5132016-02-29 11:13:29 -08001600 // 565 is not a sized internal format on desktop GL. So on desktop with
1601 // 565 we always use an unsized internal format to let the system pick
1602 // the best sized format to convert the 565 data to. Since TexStorage
1603 // only allows sized internal formats we disallow it.
1604 //
1605 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1606 // update.
1607 if (texStorageSupported && kGL_GrGLStandard != standard) {
1608 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1609 }
bsalomoncdee0092016-01-08 13:20:12 -08001610 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001611
1612 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1613 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001614 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001615 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001616 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001617 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001618 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1619 if (kGL_GrGLStandard == standard) {
1620 if (version >= GR_GL_VER(4, 2)) {
1621 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1622 }
1623 } else {
1624 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1625 }
cblume790d5132016-02-29 11:13:29 -08001626 if (texStorageSupported) {
1627 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1628 }
bsalomoncdee0092016-01-08 13:20:12 -08001629 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001630
Brian Osman10fc6fd2018-03-02 11:01:10 -05001631 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1632 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001633 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001634 GR_GL_RGBA;
1635 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1636 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1637 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1638 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1639 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1640 allRenderFlags;
1641 }
1642 if (texStorageSupported) {
1643 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1644 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001645 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1646
Greg Danielef59d872017-11-17 16:47:21 -05001647 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1648 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1649
1650 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1651 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1652 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1653 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1654 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001655 }
Greg Danielef59d872017-11-17 16:47:21 -05001656 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1657 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001658 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001659 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1660 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1661 alphaInfo.fFlags |= allRenderFlags;
1662 }
1663
1664 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1665 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1666 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1667 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1668 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001669 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001670 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001671
Brian Osman48c99192017-06-02 08:45:06 -04001672 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1673 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001674 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001675 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1676 }
1677 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1678 }
1679
Brian Salomone609e812018-01-17 14:00:47 -05001680 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001681 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001682 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1683 } else {
1684 redInfo.fFlags = 0;
1685
1686 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001687 }
bsalomon41e4384e2016-01-08 09:12:44 -08001688
Greg Daniel7af060a2017-12-05 16:27:11 -05001689 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1690 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1691 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1692 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1693 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001694 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001695 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1696 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1697 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1698 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001699 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001700
1701 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1702 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1703 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1704 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1705 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001706 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001707 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1708 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1709
Greg Daniel09c94002018-06-08 22:11:51 +00001710 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1711 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1712 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1713 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1714 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001715 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1716 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1717 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001718 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001719 }
Brian Osman48c99192017-06-02 08:45:06 -04001720 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001721 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001722 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1723 }
1724 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1725 }
1726
Brian Salomone609e812018-01-17 14:00:47 -05001727 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001728 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1729 } else {
1730 grayRedInfo.fFlags = 0;
1731 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001732 }
1733
bsalomon41e4384e2016-01-08 09:12:44 -08001734 // Check for [half] floating point texture support
1735 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1736 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1737 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
Chris Daltoneff01a72018-07-19 17:06:39 -06001738 bool hasFP32Textures = false;
1739 bool hasFP16Textures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001740 bool rgIsTexturable = false;
Chris Daltoneff01a72018-07-19 17:06:39 -06001741 bool hasFP32RenderTargets = false;
1742 bool hasFP16RenderTargets = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001743 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001744 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001745
1746 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001747 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001748 hasFP32Textures = true;
1749 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001750 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001751 hasFP32RenderTargets = true;
1752 hasFP16RenderTargets = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001753 }
1754 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001755 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001756 hasFP32Textures = true;
1757 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001758 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001759 } else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1760 ctxInfo.hasExtension("GL_OES_texture_float")) {
1761 hasFP32Textures = true;
1762 hasFP16Textures = true;
1763 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1764 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1765 hasFP16Textures = true;
1766 }
1767
1768 if (version >= GR_GL_VER(3, 2)) {
1769 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to solve
1770 // many precision issues and no clients actually want this yet.
1771 // hasFP32RenderTargets = true;
1772 hasFP16RenderTargets = true;
1773 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
1774 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to
1775 // solve many precision issues and no clients actually want this yet.
1776 // hasFP32RenderTargets = true;
1777 hasFP16RenderTargets = true;
1778 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1779 hasFP16RenderTargets = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001780 }
1781 }
bsalomon30447372015-12-21 09:03:05 -08001782
csmartdalton6aa0e112017-02-08 16:14:11 -05001783 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1784 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1785 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1786 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1787 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001788 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001789 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1790 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001791 if (hasFP32Textures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001792 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
Chris Daltoneff01a72018-07-19 17:06:39 -06001793 if (hasFP32RenderTargets) {
csmartdalton6aa0e112017-02-08 16:14:11 -05001794 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1795 }
bsalomon41e4384e2016-01-08 09:12:44 -08001796 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001797 if (texStorageSupported) {
1798 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1799 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001800 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001801 }
bsalomon30447372015-12-21 09:03:05 -08001802
Greg Danielef59d872017-11-17 16:47:21 -05001803 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001804 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001805 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001806 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001807 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001808 }
Greg Danielef59d872017-11-17 16:47:21 -05001809 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1810 redHalf.fFormats.fExternalType = redHalfExternalType;
1811 redHalf.fFormatType = kFloat_FormatType;
1812 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1813 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001814 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001815 redHalf.fSwizzle = GrSwizzle::RRRR();
Chris Daltoneff01a72018-07-19 17:06:39 -06001816 if (textureRedSupport && hasFP16Textures) {
Greg Danielef59d872017-11-17 16:47:21 -05001817 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1818
Chris Daltoneff01a72018-07-19 17:06:39 -06001819 if (hasFP16RenderTargets) {
Greg Danielef59d872017-11-17 16:47:21 -05001820 redHalf.fFlags |= fpRenderFlags;
1821 }
1822
1823 if (texStorageSupported && !isCommandBufferES2) {
1824 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1825 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001826 }
Greg Danielef59d872017-11-17 16:47:21 -05001827 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001828
1829 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1830 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001831 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001832 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001833 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001834 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1835 } else {
1836 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1837 }
bsalomon7928ef62016-01-05 10:26:39 -08001838 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001839 if (hasFP16Textures) {
bsalomon41e4384e2016-01-08 09:12:44 -08001840 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1841 // ES requires 3.2 or EXT_color_buffer_half_float.
Chris Daltoneff01a72018-07-19 17:06:39 -06001842 if (hasFP16RenderTargets) {
bsalomon41e4384e2016-01-08 09:12:44 -08001843 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1844 }
1845 }
cblume790d5132016-02-29 11:13:29 -08001846 if (texStorageSupported) {
1847 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1848 }
bsalomoncdee0092016-01-08 13:20:12 -08001849 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001850
bsalomon30447372015-12-21 09:03:05 -08001851 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1852
1853 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001854 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1855 ctxInfo.version() >= GR_GL_VER(3,0));
1856 // All ES versions (thus far) require sized internal formats for render buffers.
1857 // TODO: Always use sized internal format?
1858 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1859
bsalomon30447372015-12-21 09:03:05 -08001860 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001861 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1862 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001863 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001864 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001865 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1866 fConfigTable[i].fFormats.fSizedInternalFormat :
1867 fConfigTable[i].fFormats.fBaseInternalFormat;
1868 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001869 fConfigTable[i].fFormats.fSizedInternalFormat :
1870 fConfigTable[i].fFormats.fBaseInternalFormat;
1871 }
Brian Salomon44804c02018-01-23 16:51:28 -05001872 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1873 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1874 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1875 // in ES.
1876 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1877 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1878 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1879 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001880 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1881 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001882 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1883 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001884 }
1885
bsalomon30447372015-12-21 09:03:05 -08001886 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1887 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1888 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1889 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1890 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001891 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001892 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001893
1894 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1895 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1896 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1897 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001898 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001899 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1900 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1901 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1902 // slot.
1903 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1904 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001905
1906 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1907 // as a base format.
1908 // GL_EXT_texture_format_BGRA8888:
1909 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1910 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1911 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001912 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001913 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1914 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1915 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001916 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001917 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1918 }
1919
bsalomoncdee0092016-01-08 13:20:12 -08001920 // If we don't have texture swizzle support then the shader generator must insert the
1921 // swizzle into shader code.
1922 if (!this->textureSwizzleSupport()) {
1923 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001924 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001925 }
1926 }
1927
bsalomon7f9b2e42016-01-12 13:29:26 -08001928 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1929 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1930 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001931 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001932 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1933 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1934 if (GrPixelConfigIsAlphaOnly(config) &&
1935 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001936 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001937 }
1938 }
1939 }
1940
Greg Daniel81e7bf82017-07-19 14:47:42 -04001941 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1942 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001943 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1944 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001945 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001946 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1947 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001948 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001949 int count;
1950 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1951 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1952 1, &count);
1953 if (count) {
1954 int* temp = new int[count];
1955 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1956 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001957 // GL has a concept of MSAA rasterization with a single sample but we do not.
1958 if (count && temp[count - 1] == 1) {
1959 --count;
1960 SkASSERT(!count || temp[count -1] > 1);
1961 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001962 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001963 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001964 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001965 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001966 for (int j = 0; j < count; ++j) {
1967 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1968 }
1969 delete[] temp;
1970 }
1971 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001972 // Fake out the table using some semi-standard counts up to the max allowed sample
1973 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001974 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001975 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1976 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1977 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1978 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1979 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001980 // Chrome has a mock GL implementation that returns 0.
1981 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05001982
Brian Salomonbdecacf2018-02-02 20:32:49 -05001983 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04001984 int count = SK_ARRAY_COUNT(kDefaultSamples);
1985 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001986 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001987 break;
1988 }
1989 }
1990 if (count > 0) {
1991 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
1992 }
1993 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001994 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
1995 fConfigTable[i].fColorSampleCounts.setCount(1);
1996 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001997 }
1998 }
1999
bsalomon30447372015-12-21 09:03:05 -08002000#ifdef SK_DEBUG
2001 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002002 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002003 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002004 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2005 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002006 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2007 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2008 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2009 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002010 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2011 fConfigTable[i].fFormats.fBaseInternalFormat);
2012 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002013 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002014 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2015 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2016 fConfigTable[i].fFormats.fExternalFormat[j]);
2017 }
2018 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002019 }
2020#endif
2021}
2022
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002023bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2024 bool dstIsTextureable, bool dstIsGLTexture2D,
2025 GrSurfaceOrigin dstOrigin,
2026 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2027 bool srcIsTextureable, bool srcIsGLTexture2D,
2028 GrSurfaceOrigin srcOrigin) const {
2029 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2030 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2031 // many drivers would allow it to work, but ANGLE does not.
2032 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2033 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2034 return false;
2035 }
2036
2037 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2038 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2039 return false;
2040 }
2041
2042 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2043 // texture.
2044 if (!dstIsTextureable) {
2045 return false;
2046 }
2047
2048 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2049 // is required
2050 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2051 (!srcIsTextureable || srcIsGLTexture2D) &&
2052 dstIsGLTexture2D &&
2053 dstOrigin == srcOrigin) {
2054 return true;
2055 } else {
2056 return false;
2057 }
2058}
2059
2060bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2061 bool dstIsTextureable, bool dstIsGLTexture2D,
2062 GrSurfaceOrigin dstOrigin,
2063 GrPixelConfig srcConfig, int srcSampleCnt,
2064 bool srcIsTextureable, bool srcIsGLTexture2D,
2065 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2066 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2067 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2068 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2069 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2070 return false;
2071 }
2072
2073 if (dstIsTextureable && !dstIsGLTexture2D) {
2074 return false;
2075 }
2076 if (srcIsTextureable && !srcIsGLTexture2D) {
2077 return false;
2078 }
2079
2080 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2081 return false;
2082 }
2083 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2084 // We would mirror to compensate for origin changes. Note that copySurface is
2085 // specified such that the src and dst rects are the same.
2086 if (dstOrigin != srcOrigin) {
2087 return false;
2088 }
2089 }
2090
2091 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2092 if (srcSampleCnt > 1) {
2093 if (1 == dstSampleCnt) {
2094 return false;
2095 }
2096 if (SkRect::Make(srcRect) != srcBounds) {
2097 return false;
2098 }
2099 }
2100 }
2101
2102 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2103 if (dstSampleCnt > 1) {
2104 return false;
2105 }
2106 }
2107
2108 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2109 if (dstConfig != srcConfig) {
2110 return false;
2111 }
2112 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2113 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2114 return false;
2115 }
2116 }
2117
2118 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2119 if (srcSampleCnt > 1) {
2120 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2121 return false;
2122 }
2123 if (dstOrigin != srcOrigin) {
2124 return false;
2125 }
2126 }
2127 }
2128 return true;
2129}
2130
2131bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2132 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2133}
2134
2135static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2136 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2137 if (!rt) {
2138 return false;
2139 }
2140 // A RT has a separate MSAA renderbuffer if:
2141 // 1) It's multisampled
2142 // 2) We're using an extension with separate MSAA renderbuffers
2143 // 3) It's not FBO 0, which is special and always auto-resolves
2144 return rt->numColorSamples() > 1 &&
2145 glCaps.usesMSAARenderBuffers() &&
2146 !rt->rtPriv().glRTFBOIDIs0();
2147}
2148
2149bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2150 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2151 GrSurfaceOrigin dstOrigin = dst->origin();
2152 GrSurfaceOrigin srcOrigin = src->origin();
2153
2154 GrPixelConfig dstConfig = dst->config();
2155 GrPixelConfig srcConfig = src->config();
2156
2157 int dstSampleCnt = 0;
2158 int srcSampleCnt = 0;
2159 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2160 dstSampleCnt = rtProxy->numColorSamples();
2161 }
2162 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2163 srcSampleCnt = rtProxy->numColorSamples();
2164 }
2165 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2166 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2167
2168 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2169 // swizzle.
2170 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2171 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2172 return false;
2173 }
2174
2175 const GrTextureProxy* dstTex = dst->asTextureProxy();
2176 const GrTextureProxy* srcTex = src->asTextureProxy();
2177
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002178 bool dstIsTex2D = dstTex ? (dstTex->textureType() == GrTextureType::k2D) : false;
2179 bool srcIsTex2D = srcTex ? (srcTex->textureType() == GrTextureType::k2D) : false;
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002180
2181 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2182 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2183 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2184 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2185 // know we will at least be able to do it as a draw.
2186#ifdef SK_DEBUG
2187 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2188 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2189 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2190 !src->priv().isExact()) {
2191 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2192 }
2193#endif
2194
2195 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2196 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2197 srcConfig, has_msaa_render_buffer(src, *this),
2198 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2199 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2200 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2201 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2202 dstPoint) ||
2203 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2204}
2205
Robert Phillipsbf25d432017-04-07 10:08:53 -04002206bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002207 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2208 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002209 // By default, we don't require rects to match.
2210 *rectsMustMatch = false;
2211
2212 // By default, we allow subrects.
2213 *disallowSubrect = false;
2214
Brian Salomon467921e2017-03-06 16:17:12 -05002215 // If the src is a texture, we can implement the blit as a draw assuming the config is
2216 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002217 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002218 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002219 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2220 desc->fConfig = src->config();
2221 return true;
2222 }
2223
Robert Phillipsbf25d432017-04-07 10:08:53 -04002224 {
2225 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2226 // wrapped. In that case the proxy would already be instantiated.
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002227 const GrTexture* srcTexture = src->peekTexture();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002228 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2229 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2230 // Not supported for FBO blit or CopyTexSubImage
2231 return false;
2232 }
Brian Salomon467921e2017-03-06 16:17:12 -05002233 }
2234
2235 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2236 // possible and we return false to fallback to creating a render target dst for render-to-
2237 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2238 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002239 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002240 bool rectsMustMatchForBlitFramebuffer = false;
2241 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002242 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002243 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2244 rectsMustMatchForBlitFramebuffer = true;
2245 disallowSubrectForBlitFramebuffer = true;
2246 // Mirroring causes rects to mismatch later, don't allow it.
2247 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002248 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2249 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002250 rectsMustMatchForBlitFramebuffer = true;
2251 // Mirroring causes rects to mismatch later, don't allow it.
2252 originForBlitFramebuffer = src->origin();
2253 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002254 originForBlitFramebuffer = src->origin();
2255 }
2256
2257 // Check for format issues with glCopyTexSubImage2D
2258 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2259 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2260 // then we set up for that, otherwise fail.
2261 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002262 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002263 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002264 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2265 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002266 return true;
2267 }
2268 return false;
2269 }
2270
Robert Phillipsbf25d432017-04-07 10:08:53 -04002271 {
Brian Salomon63e79732017-05-15 21:23:13 -04002272 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2273 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002274 if (srcIsMSAARenderbuffer) {
2275 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2276 // blit or fail.
2277 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002278 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002279 desc->fConfig = src->config();
2280 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2281 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2282 return true;
2283 }
2284 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002285 }
Brian Salomon467921e2017-03-06 16:17:12 -05002286 }
2287
2288 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002289 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002290 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002291 desc->fFlags = kNone_GrSurfaceFlags;
2292 return true;
2293}
2294
Greg Daniel691f5e72018-02-28 14:21:34 -05002295void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2296 const GrContextOptions& contextOptions,
2297 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002298 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2299 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002300 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2301 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002302 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002303 fDiscardRenderTargetSupport = false;
2304 fInvalidateFBType = kNone_InvalidateFBType;
2305 }
2306
2307 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2308 // 340.96 and 367.57.
2309 if (kGL_GrGLStandard == ctxInfo.standard() &&
2310 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002311 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002312 fClearTextureSupport = false;
2313 }
2314
2315 // Calling glClearTexImage crashes on the NexusPlayer.
2316 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2317 fClearTextureSupport = false;
2318 }
2319
2320 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2321#ifdef SK_BUILD_FOR_MAC
2322 if (shaderCaps->fGeometryShaderSupport) {
2323 shaderCaps->fGSInvocationsSupport = false;
2324 }
2325#endif
2326
2327 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2328 // shaders. @127.0 is the earliest verified driver to not crash.
2329 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002330 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002331 shaderCaps->fGeometryShaderSupport = false;
2332 }
2333
2334#if defined(__has_feature)
2335#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2336 // See skbug.com/7058
2337 fMapBufferType = kNone_MapBufferType;
2338 fMapBufferFlags = kNone_MapFlags;
2339#endif
2340#endif
2341
2342 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2343 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2344 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2345 // unclear whether this really affects a wide range of devices.
2346 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002347 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002348 fMapBufferType = kNone_MapBufferType;
2349 fMapBufferFlags = kNone_MapFlags;
2350 }
2351
2352 // TODO: re-enable for ANGLE
2353 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2354 fTransferBufferType = kNone_TransferBufferType;
2355 }
2356
2357 // Using MIPs on this GPU seems to be a source of trouble.
2358 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2359 fMipMapSupport = false;
2360 }
2361
2362 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2363 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2364 // around a driver bug related to gl_FragCoord.
2365 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2366 fMaxClipAnalyticFPs = 0;
2367 }
2368
2369#ifndef SK_BUILD_FOR_IOS
2370 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2371 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2372 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2373 ctxInfo.driver() != kChromium_GrGLDriver)) {
2374 fUseDrawToClearColor = true;
2375 }
2376#endif
2377
2378 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2379 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2380 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2381 fUseDrawToClearColor = true;
2382 }
2383
2384#ifdef SK_BUILD_FOR_MAC
2385 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2386 // full screen clears
2387 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2388 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002389 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2390 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2391 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2392 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002393 fUseDrawToClearColor = true;
2394 }
2395#endif
2396
2397 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2398 // bugs seems to involve clearing too much and not skipping the clear.
2399 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2400 // but only for D3D11 ANGLE.
2401 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2402 fUseDrawToClearColor = true;
2403 }
2404
Chris Dalton1214be92018-06-28 19:06:27 -06002405 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2406 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002407 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002408 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002409 fUseDrawToClearStencilClip = true;
2410 }
2411 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2412 }
2413
Adrienne Walker94f585e2018-05-15 11:47:07 -07002414 if (fDriverBugWorkarounds.gl_clear_broken) {
2415 fUseDrawToClearColor = true;
2416 fUseDrawToClearStencilClip = true;
2417 }
2418
Brian Salomon01b476a2018-01-23 11:06:41 -05002419 // This was reproduced on the following configurations:
2420 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2421 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2422 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2423 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2424 // and not produced on:
2425 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2426 // The particular lines that get dropped from test images varies across different devices.
2427 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002428 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002429 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2430 }
2431
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002432 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2433 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2434 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002435 fRequiresFlushBetweenNonAndInstancedDraws = true;
2436 }
2437
Brian Osman1348ed02018-09-12 09:08:39 -04002438 // This was reproduced on a Pixel 1, but the unit test + config + options that exercise it are
2439 // only tested on very specific bots. The driver claims that ReadPixels is an invalid operation
2440 // when reading from an auto-resolving MSAA framebuffer that has stencil attached.
2441 if (kQualcomm_GrGLDriver == ctxInfo.driver()) {
2442 fDetachStencilFromMSAABuffersBeforeReadPixels = true;
2443 }
2444
Brian Salomon01b476a2018-01-23 11:06:41 -05002445 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2446 // given 1 << 15 or more instances.
2447 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2448 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
Adrienne Walker001cae02018-05-15 11:38:44 -07002449 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
2450 fMaxInstancesPerDrawArraysWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002451 }
2452
2453 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002454 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002455 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2456 fUseDrawInsteadOfAllRenderTargetWrites = true;
2457 }
2458
2459 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2460 fSampleShadingSupport = false;
2461 }
2462
2463#ifdef SK_BUILD_FOR_MAC
2464 static constexpr bool isMAC = true;
2465#else
2466 static constexpr bool isMAC = false;
2467#endif
2468
2469 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2470 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2471 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2472 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2473 if (fMipMapLevelAndLodControlSupport &&
2474 (contextOptions.fDoManualMipmapping ||
2475 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2476 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2477 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2478 fDoManualMipmapping = true;
2479 }
2480
2481 // See http://crbug.com/710443
2482#ifdef SK_BUILD_FOR_MAC
2483 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2484 fClearToBoundaryValuesIsBroken = true;
2485 }
2486#endif
2487 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2488 fDrawArraysBaseVertexIsBroken = true;
2489 }
2490
Brian Salomon01b476a2018-01-23 11:06:41 -05002491 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2492 // Galaxy S7.
2493 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2494 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2495 shaderCaps->fFBFetchSupport = false;
2496 }
2497
Brian Salomon01b476a2018-01-23 11:06:41 -05002498 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2499 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2500
2501 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2502 // function that may require a gradient calculation inside a conditional block may return
2503 // undefined results". This appears to be an issue with the 'any' call since even the simple
2504 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2505 // from our GrTextureDomain processor.
2506 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2507
2508 // Known issue on at least some Intel platforms:
2509 // http://code.google.com/p/skia/issues/detail?id=946
2510 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2511 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2512 }
2513
Chris Dalton0090ef62018-03-28 17:35:00 -06002514 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002515 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2516 // so we must do the abs first in a separate expression.
2517 shaderCaps->fCanUseMinAndAbsTogether = false;
2518
2519 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2520 // must avoid this condition.
2521 shaderCaps->fCanUseFractForNegativeValues = false;
2522 }
2523
2524 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2525 // thus must us -1.0 * %s.x to work correctly
2526 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2527 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2528 }
2529
2530 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2531 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2532 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2533 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2534 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2535 }
2536
2537 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2538 // the original dst color when reading the outColor even after being written to. By using a
2539 // local outColor we can work around this bug.
2540 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2541 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2542 }
2543
2544 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2545 // color, and that uniform contains an opaque color, and the output of the shader is only based
2546 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2547 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2548 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2549 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2550 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2551 shaderCaps->fMustObfuscateUniformColor = true;
2552 }
2553#ifdef SK_BUILD_FOR_WIN
2554 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2555 //
2556 // Basically, if a shader has a construct like:
2557 //
2558 // float x = someCondition ? someValue : 0;
2559 // float2 result = (0 == x) ? float2(x, x)
2560 // : float2(2 * x / x, 0);
2561 //
2562 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2563 // we've explicitly guarded the division with a check against zero. This manifests in much
2564 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2565 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2566 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2567 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2568 }
2569#endif
2570
2571 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002572 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002573 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2574 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002575 }
2576
Chris Dalton0090ef62018-03-28 17:35:00 -06002577 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2578 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2579 shaderCaps->fCanUseFragCoord = false;
2580 }
2581
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002582 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2583 // (Are they implemented with fp16?)
2584 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2585 shaderCaps->fIncompleteShortIntPrecision = true;
2586 }
2587
Adrienne Walkeree8295c2018-08-21 10:56:30 -07002588 if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
2589 shaderCaps->fAddAndTrueToLoopCondition = true;
2590 }
2591
Adrienne Walkerc02165f2018-08-21 11:08:11 -07002592 if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
2593 shaderCaps->fUnfoldShortCircuitAsTernary = true;
2594 }
2595
Adrienne Walker92b161f2018-08-22 10:41:52 -07002596 if (fDriverBugWorkarounds.emulate_abs_int_function) {
2597 shaderCaps->fEmulateAbsIntFunction = true;
2598 }
2599
Adrienne Walker8b23ca62018-08-22 10:45:41 -07002600 if (fDriverBugWorkarounds.rewrite_do_while_loops) {
2601 shaderCaps->fRewriteDoWhileLoops = true;
2602 }
2603
Adrienne Walker2f4c09b2018-08-22 16:04:57 -07002604 if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
2605 shaderCaps->fRemovePowWithConstantExponent = true;
2606 }
2607
Brian Salomon01b476a2018-01-23 11:06:41 -05002608 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2609 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002610 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2611 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002612 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2613 kIntel_GrGLDriver == ctxInfo.driver() ||
2614 kChromium_GrGLDriver == ctxInfo.driver()) {
2615 fBlendEquationSupport = kBasic_BlendEquationSupport;
2616 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2617 }
2618
2619 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2620 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002621 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002622 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002623 fBlendEquationSupport = kBasic_BlendEquationSupport;
2624 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2625 }
2626
Adrienne Walker68314842018-05-14 14:02:53 -07002627 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2628 fBlendEquationSupport = kBasic_BlendEquationSupport;
2629 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2630 }
2631
Brian Salomon01b476a2018-01-23 11:06:41 -05002632 if (this->advancedBlendEquationSupport()) {
2633 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002634 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002635 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2636 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2637 (1 << kColorBurn_GrBlendEquation);
2638 }
2639 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2640 // Blacklist color-burn on ARM until the fix is released.
2641 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2642 }
2643 }
2644
2645 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2646 if (fMultisampleDisableSupport &&
2647 this->shaderCaps()->dualSourceBlendingSupport() &&
2648 this->shaderCaps()->pathRenderingSupport() &&
2649 fUsesMixedSamples &&
2650#if GR_TEST_UTILS
2651 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2652#endif
2653 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2654 kChromium_GrGLDriver == ctxInfo.driver())) {
2655 fDiscardRenderTargetSupport = false;
2656 fInvalidateFBType = kNone_InvalidateFBType;
2657 }
Brian Osmanc585e202018-04-04 14:08:27 -04002658
Brian Osman061020e2018-04-17 14:22:15 -04002659 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2660 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2661 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2662 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002663 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2664 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002665 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002666 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002667 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2668 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002669 }
Brian Osman2fa53742018-05-03 15:05:12 -04002670
2671#ifdef SK_BUILD_FOR_IOS
2672 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2673 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2674 // is to just blacklist the feature.
2675 // https://github.com/flutter/flutter/issues/16718
2676 // https://bugreport.apple.com/web/?problemID=39948888
2677 fUnpackRowLengthSupport = false;
2678#endif
Chris Daltona2b5b642018-06-24 13:08:57 -06002679
2680#ifdef SK_BUILD_FOR_MAC
2681 // Radeon MacBooks hit a crash in glReadPixels() when using CCPR.
2682 // http://skbug.com/8097
2683 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2684 fBlacklistCoverageCounting = true;
2685 }
2686#endif
Chris Daltonc4e72a42018-06-25 06:44:01 -06002687
2688 // "shapes_mixed_10000_32x33" bench crashes PowerVRGX6250 in Release mode with ccpr.
2689 // http://skbug.com/8098
2690 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2691 fBlacklistCoverageCounting = true;
2692 }
Chris Dalton1c1391c2018-07-20 12:21:14 -06002693
Chris Daltonb70beea2018-07-23 12:17:10 -06002694 // CCPR edge AA is busted on Mesa, Sandy Bridge/Bay Trail.
Chris Dalton1c1391c2018-07-20 12:21:14 -06002695 // http://skbug.com/8162
Chris Daltonb70beea2018-07-23 12:17:10 -06002696 if (kMesa_GrGLDriver == ctxInfo.driver() &&
2697 (kIntelSandyBridge_GrGLRenderer == ctxInfo.renderer() ||
2698 kIntelBayTrail_GrGLRenderer == ctxInfo.renderer())) {
Chris Dalton1c1391c2018-07-20 12:21:14 -06002699 fBlacklistCoverageCounting = true;
2700 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002701}
2702
csmartdaltone0d36292016-07-29 08:14:20 -07002703void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002704 if (options.fDisableDriverCorrectnessWorkarounds) {
2705 SkASSERT(!fDoManualMipmapping);
2706 SkASSERT(!fClearToBoundaryValuesIsBroken);
2707 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2708 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2709 SkASSERT(!fUseDrawToClearColor);
2710 SkASSERT(!fUseDrawToClearStencilClip);
2711 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2712 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2713 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002714 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Osman1348ed02018-09-12 09:08:39 -04002715 SkASSERT(!fDetachStencilFromMSAABuffersBeforeReadPixels);
Brian Salomon01b476a2018-01-23 11:06:41 -05002716 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002717 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2718 fUseDrawToClearColor = false;
2719 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2720 fUseDrawToClearColor = true;
2721 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002722 if (options.fDoManualMipmapping) {
2723 fDoManualMipmapping = true;
2724 }
csmartdaltone0d36292016-07-29 08:14:20 -07002725}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002726
Brian Salomon3d86a192018-02-27 16:46:11 -05002727bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2728 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2729 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2730 if (tex->hasBaseLevelBeenBoundToFBO()) {
2731 return false;
2732 }
2733 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002734 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002735 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2736 return false;
2737 }
2738 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2739 return false;
2740 }
2741 return SkToBool(surface->asTexture());
2742 }
2743 return true;
2744}
2745
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002746bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2747 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2748 // We don't support reading pixels directly from EXTERNAL textures as it would require
2749 // binding the texture to a FBO.
2750 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2751 return false;
2752 }
2753 }
2754 return true;
2755}
2756
2757GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2758 GrColorType dstColorType) const {
2759 // For now, we mostly report the read back format that is required by the ES spec without
2760 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2761 // this as makes sense to increase performance and correctness.
2762 switch (fConfigTable[config].fFormatType) {
2763 case kNormalizedFixedPoint_FormatType:
2764 return GrColorType::kRGBA_8888;
2765 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002766 if ((kAlpha_half_GrPixelConfig == config ||
2767 kAlpha_half_as_Red_GrPixelConfig == config) &&
2768 GrColorType::kAlpha_F16 == dstColorType) {
2769 return GrColorType::kAlpha_F16;
2770 }
2771 // And similar for full float RG.
2772 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2773 return GrColorType::kRG_F32;
2774 }
2775 return GrColorType::kRGBA_F32;
2776 }
2777 return GrColorType::kUnknown;
2778}
2779
Greg Daniel2a303902018-02-20 10:25:54 -05002780bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002781 GrGLFramebufferInfo fbInfo;
2782 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002783 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002784 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002785}
2786
Brian Salomonbdecacf2018-02-02 20:32:49 -05002787int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2788 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002789 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002790 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002791 return 0;
2792 }
2793
Brian Salomonbdecacf2018-02-02 20:32:49 -05002794 if (1 == requestedCount) {
2795 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2796 }
2797
Greg Daniel81e7bf82017-07-19 14:47:42 -04002798 for (int i = 0; i < count; ++i) {
2799 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002800 int count = fConfigTable[config].fColorSampleCounts[i];
2801 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2802 count = SkTMin(count, 4);
2803 }
2804 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002805 }
2806 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002807 return 0;
2808}
2809
2810int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2811 const auto& table = fConfigTable[config].fColorSampleCounts;
2812 if (!table.count()) {
2813 return 0;
2814 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002815 int count = table[table.count() - 1];
2816 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2817 count = SkTMin(count, 4);
2818 }
2819 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002820}
2821
Greg Danielfaa095e2017-12-19 13:15:02 -05002822bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2823 GrGLStandard standard) {
2824 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002825
2826 switch (ct) {
2827 case kUnknown_SkColorType:
2828 return false;
2829 case kAlpha_8_SkColorType:
2830 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002831 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002832 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002833 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002834 }
2835 break;
2836 case kRGB_565_SkColorType:
2837 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002838 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002839 }
2840 break;
2841 case kARGB_4444_SkColorType:
2842 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002843 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002844 }
2845 break;
2846 case kRGBA_8888_SkColorType:
2847 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002848 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002849 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002850 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002851 }
2852 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002853 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002854 if (GR_GL_RGB8 == format) {
2855 *config = kRGB_888_GrPixelConfig;
2856 }
2857 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002858 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002859 if (GR_GL_RGBA8 == format) {
2860 if (kGL_GrGLStandard == standard) {
2861 *config = kBGRA_8888_GrPixelConfig;
2862 }
2863 } else if (GR_GL_BGRA8 == format) {
2864 if (kGLES_GrGLStandard == standard) {
2865 *config = kBGRA_8888_GrPixelConfig;
2866 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002867 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002868 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002869 }
2870 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002871 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002872 if (GR_GL_RGB10_A2 == format) {
2873 *config = kRGBA_1010102_GrPixelConfig;
2874 }
2875 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002876 case kRGB_101010x_SkColorType:
2877 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002878 case kGray_8_SkColorType:
2879 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002880 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002881 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002882 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002883 }
2884 break;
2885 case kRGBA_F16_SkColorType:
2886 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002887 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002888 }
2889 break;
Mike Klein37854712018-06-26 11:43:06 -04002890 case kRGBA_F32_SkColorType:
2891 if (GR_GL_RGBA32F == format) {
2892 *config = kRGBA_float_GrPixelConfig;
2893 }
2894 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002895 }
2896
Greg Danielfaa095e2017-12-19 13:15:02 -05002897 return kUnknown_GrPixelConfig != *config;
2898}
2899
2900bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2901 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002902 GrGLTextureInfo texInfo;
2903 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002904 return false;
2905 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002906 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002907}
2908
2909bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2910 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002911 GrGLFramebufferInfo fbInfo;
2912 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002913 return false;
2914 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002915 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002916}
2917
Robert Phillipsfc711a22018-02-13 17:03:00 -05002918bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2919 GrPixelConfig* config) const {
2920 const GrGLenum* glFormat = format.getGLFormat();
2921 if (!glFormat) {
2922 return false;
2923 }
2924 return validate_sized_format(*glFormat, ct, config, fStandard);
2925}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002926
Timothy Liang036fdfe2018-06-28 15:50:36 -04002927#ifdef GR_TEST_UTILS
2928GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2929 const GrBackendTexture& backendTex) const {
2930 GrGLTextureInfo glInfo;
2931 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2932 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2933}
2934#endif