blob: 55e85d9b0e71aa17e57debaefddb70982d89c0ff [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
cdalton4cd67132015-06-10 19:23:46 -0700294 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700295 * GrShaderCaps fields
296 **************************************************************************/
297
egdaniel0a482332015-10-26 08:59:10 -0700298 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700299 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500300 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700301
Brian Osman195c05b2017-08-30 15:14:04 -0400302 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
303#if GR_TEST_UTILS
304 if (contextOptions.fSuppressPathRendering) {
305 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700306 }
Brian Osman195c05b2017-08-30 15:14:04 -0400307#endif
egdaniel05ded892015-10-26 07:38:05 -0700308
egdaniel05ded892015-10-26 07:38:05 -0700309 // Enable supported shader-related caps
310 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500311 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700312 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
Brian Salomon23c55b62018-06-19 16:28:41 -0400313 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600314
Brian Salomon1edc5b92016-11-29 13:43:46 -0500315 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600316
egdaniel05ded892015-10-26 07:38:05 -0700317 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500318 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700319 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600320 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600321 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
322 shaderCaps->fGSInvocationsSupport = true;
323 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
324 shaderCaps->fGSInvocationsSupport = true;
325 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
326 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600327 }
328
Brian Salomon1edc5b92016-11-29 13:43:46 -0500329 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800330 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500331 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500332 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700333
Brian Salomon1edc5b92016-11-29 13:43:46 -0500334 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700335 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800336
Chris Dalton1214be92018-06-28 19:06:27 -0600337 // Mali and early Adreno both have support for geometry shaders, but they appear to be
338 // implemented in software. In practice with ccpr, they are slower than the backup impl that
339 // only uses vertex shaders.
340 if (kARM_GrGLVendor != ctxInfo.vendor() &&
341 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
342 kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
343
Chris Daltonfaca00d2018-01-19 15:56:07 -0700344 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
345 shaderCaps->fGeometryShaderSupport = true;
346 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
347 shaderCaps->fGeometryShaderSupport = true;
348 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
349 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700350 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500351 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700352
Brian Salomon1edc5b92016-11-29 13:43:46 -0500353 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800354 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700355 }
356
cdalton9c3f1432016-03-11 10:07:37 -0800357 // Protect ourselves against tracking huge amounts of texture state.
358 static const uint8_t kMaxSaneSamplers = 32;
359 GrGLint maxSamplers;
360 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500361 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
362 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800363 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500364 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800365 }
366 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500367 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800368 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500369 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800370
csmartdalton485a1202016-07-13 10:16:32 -0700371 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
372 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
373 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
374 // limit this decision to specific GPU families rather than basing it on the vendor alone.
375 if (!GR_GL_MUST_USE_VBO &&
376 !fIsCoreProfile &&
377 (kARM_GrGLVendor == ctxInfo.vendor() ||
378 kImagination_GrGLVendor == ctxInfo.vendor() ||
379 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
380 fPreferClientSideDynamicBuffers = true;
381 }
382
Eric Karl5c779752017-05-08 12:02:07 -0700383 if (!contextOptions.fAvoidStencilBuffers) {
384 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
385 this->initFSAASupport(contextOptions, ctxInfo, gli);
386 this->initStencilSupport(ctxInfo);
387 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400388
389 // Setup blit framebuffer
390 if (kGL_GrGLStandard != ctxInfo.standard()) {
391 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
392 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
393 kNoMSAADst_BlitFramebufferFlag |
394 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
395 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
396 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
397 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
398 // limitations.
399 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
400 kResolveMustBeFull_BlitFrambufferFlag |
401 kNoMSAADst_BlitFramebufferFlag |
402 kNoFormatConversion_BlitFramebufferFlag |
403 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
404 }
405 } else {
406 if (fUsesMixedSamples ||
407 ctxInfo.version() >= GR_GL_VER(3,0) ||
408 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
409 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
410 fBlitFramebufferFlags = 0;
411 }
412 }
413
cdalton1dd05422015-06-12 09:01:18 -0700414 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000415
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000416 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000417 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
418 // extension includes glMapBuffer.
419 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
420 fMapBufferFlags |= kSubset_MapFlag;
421 fMapBufferType = kMapBufferRange_MapBufferType;
422 } else {
423 fMapBufferType = kMapBuffer_MapBufferType;
424 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000425 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000426 // Unextended GLES2 doesn't have any buffer mapping.
427 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800428 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800429 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
430 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800431 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
432 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
433 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000434 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
435 fMapBufferFlags = kCanMap_MapFlag;
436 fMapBufferType = kMapBuffer_MapBufferType;
437 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000438 }
439
jvanverthd7a2c1f2015-12-07 07:36:44 -0800440 if (kGL_GrGLStandard == standard) {
441 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
442 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700443 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500444 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400445 if (version >= GR_GL_VER(3, 0) ||
446 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
447 // GL_EXT_unpack_subimage needed to support subtexture rectangles
448 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800449 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400450// TODO: get transfer buffers working in Chrome
451// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
452// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800453 }
454 }
455
joshualitte5b74c62015-06-01 14:17:47 -0700456 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
457 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700458 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700459#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500460 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
461 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
462 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700463 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700464#else
cdalton397536c2016-03-25 12:15:03 -0700465 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700466#endif
joshualitte5b74c62015-06-01 14:17:47 -0700467 }
468
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000469 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000470 fNPOTTextureTileSupport = true;
471 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000472 } else {
473 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000474 // ES3 has no limitations.
475 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
476 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000477 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
478 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
479 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
480 // to alllow arbitrary wrap modes, however.
481 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000482 }
483
bsalomon@google.combcce8922013-03-25 15:38:39 +0000484 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700485
486 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
487 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
488 }
489
bsalomon@google.combcce8922013-03-25 15:38:39 +0000490 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
491 // Our render targets are always created with textures as the color
492 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000493 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700494 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
495
496 if (kARM_GrGLVendor == ctxInfo.vendor()) {
497 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
498 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
499 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000500
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000501 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
502
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000503 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700504 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000505
robertphillips1b8e1b52015-06-24 06:54:10 -0700506#if 0
507 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
508 kQualcomm_GrGLVendor != ctxInfo.vendor();
509#endif
510
csmartdalton9bc11872016-08-09 12:42:47 -0700511 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
512 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700513 }
514
robertphillips63926682015-08-20 09:39:02 -0700515#ifdef SK_BUILD_FOR_WIN
516 // On ANGLE deferring flushes can lead to GPU starvation
517 fPreferVRAMUseOverFlushes = !isANGLE;
518#endif
519
bsalomon7dea7b72015-08-19 08:26:51 -0700520 if (kChromium_GrGLDriver == ctxInfo.driver()) {
521 fMustClearUploadedBufferData = true;
522 }
523
bsalomond08ea5f2015-02-20 06:58:13 -0800524 if (kGL_GrGLStandard == standard) {
525 // ARB allows mixed size FBO attachments, EXT does not.
526 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
527 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
528 fOversizedStencilSupport = true;
529 } else {
530 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
531 }
532 } else {
533 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
534 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
535 }
536
joshualitt58001552015-06-26 12:46:36 -0700537 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700538 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
539 ctxInfo.hasExtension("GL_ARB_draw_indirect");
540 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
541 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700542 (fDrawIndirectSupport &&
543 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700544 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700545 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800546 } else {
547 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700548 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
549 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
550 fBaseInstanceSupport = fDrawIndirectSupport &&
551 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700552 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800553 }
554
ethannicholas28ef4452016-03-25 09:26:03 -0700555 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500556 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700557 fSampleShadingSupport = true;
558 }
559 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
560 fSampleShadingSupport = true;
561 }
562
jvanverth84741b32016-09-30 08:39:02 -0700563 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
564 if (kGL_GrGLStandard == standard) {
565 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
566 fFenceSyncSupport = true;
567 }
Brian Osman93a23462017-06-21 15:13:39 -0400568 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700569 fFenceSyncSupport = true;
570 }
571
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400572 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500573 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500574
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400575 if (kGL_GrGLStandard == standard) {
576 if (version >= GR_GL_VER(4, 1)) {
577 fProgramBinarySupport = true;
578 }
579 } else if (version >= GR_GL_VER(3, 0)) {
580 fProgramBinarySupport = true;
581 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400582 if (fProgramBinarySupport) {
583 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400584 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400585 fProgramBinarySupport = count > 0;
586 }
bsalomoncdee0092016-01-08 13:20:12 -0800587 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
588 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800589 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700590
Brian Salomon01b476a2018-01-23 11:06:41 -0500591 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
592 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
593 }
594
cdalton4cd67132015-06-10 19:23:46 -0700595 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500596 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700597
Brian Salomon01b476a2018-01-23 11:06:41 -0500598 // For now these two are equivalent but we could have dst read in shader via some other method.
599 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000600}
601
egdaniel472d44e2015-10-22 08:20:00 -0700602const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
603 bool isCoreProfile) {
604 switch (generation) {
605 case k110_GrGLSLGeneration:
606 if (kGLES_GrGLStandard == standard) {
607 // ES2s shader language is based on version 1.20 but is version
608 // 1.00 of the ES language.
609 return "#version 100\n";
610 } else {
611 SkASSERT(kGL_GrGLStandard == standard);
612 return "#version 110\n";
613 }
614 case k130_GrGLSLGeneration:
615 SkASSERT(kGL_GrGLStandard == standard);
616 return "#version 130\n";
617 case k140_GrGLSLGeneration:
618 SkASSERT(kGL_GrGLStandard == standard);
619 return "#version 140\n";
620 case k150_GrGLSLGeneration:
621 SkASSERT(kGL_GrGLStandard == standard);
622 if (isCoreProfile) {
623 return "#version 150\n";
624 } else {
625 return "#version 150 compatibility\n";
626 }
627 case k330_GrGLSLGeneration:
628 if (kGLES_GrGLStandard == standard) {
629 return "#version 300 es\n";
630 } else {
631 SkASSERT(kGL_GrGLStandard == standard);
632 if (isCoreProfile) {
633 return "#version 330\n";
634 } else {
635 return "#version 330 compatibility\n";
636 }
637 }
cdalton33ad7012016-02-22 07:55:44 -0800638 case k400_GrGLSLGeneration:
639 SkASSERT(kGL_GrGLStandard == standard);
640 if (isCoreProfile) {
641 return "#version 400\n";
642 } else {
643 return "#version 400 compatibility\n";
644 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500645 case k420_GrGLSLGeneration:
646 SkASSERT(kGL_GrGLStandard == standard);
647 if (isCoreProfile) {
648 return "#version 420\n";
649 }
650 else {
651 return "#version 420 compatibility\n";
652 }
egdaniel472d44e2015-10-22 08:20:00 -0700653 case k310es_GrGLSLGeneration:
654 SkASSERT(kGLES_GrGLStandard == standard);
655 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800656 case k320es_GrGLSLGeneration:
657 SkASSERT(kGLES_GrGLStandard == standard);
658 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700659 }
660 return "<no version>";
661}
662
Chris Dalton47c8ed32017-11-15 18:27:09 -0700663bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
664 if (kGLES_GrGLStandard != ctxInfo.standard() &&
665 ctxInfo.version() < GR_GL_VER(4,1) &&
666 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
667 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
668 return true;
669 }
670 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
671 // geometry shaders don't have lower precision than vertex and fragment.
672 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
673 GrGLint range[2];
674 GrGLint bits;
675 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
676 if (range[0] < 127 || range[1] < 127 || bits < 23) {
677 return false;
678 }
679 }
680 return true;
681}
682
683void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700684 GrGLStandard standard = ctxInfo.standard();
685 GrGLVersion version = ctxInfo.version();
686
687 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500688 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700689 **************************************************************************/
690
Brian Salomon1edc5b92016-11-29 13:43:46 -0500691 GrShaderCaps* shaderCaps = fShaderCaps.get();
692 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700693 if (kGLES_GrGLStandard == standard) {
694 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500695 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
696 shaderCaps->fFBFetchSupport = true;
697 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
698 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700699 }
700 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
701 // 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 -0500702 shaderCaps->fFBFetchNeedsCustomOutput = false;
703 shaderCaps->fFBFetchSupport = true;
704 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
705 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700706 }
707 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
708 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500709 shaderCaps->fFBFetchNeedsCustomOutput = false;
710 shaderCaps->fFBFetchSupport = true;
711 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
712 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700713 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500714 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700715 }
716
cdaltonc08f1962016-02-12 12:14:06 -0800717 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500718 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800719 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500720 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800721 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
722 }
Brian Salomon41274562017-09-15 09:40:03 -0700723 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
724 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
725 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800726 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500727 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800728 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
729 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400730 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
731 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500732 shaderCaps->fNoPerspectiveInterpolationSupport = true;
733 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800734 "GL_NV_shader_noperspective_interpolation";
735 }
736 }
737
Brian Salomon1edc5b92016-11-29 13:43:46 -0500738 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
739 shaderCaps->fGLSLGeneration,
740 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800741
Brian Salomon1edc5b92016-11-29 13:43:46 -0500742 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
743 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800744 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800745
746 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500747 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800748 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
749 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500750 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800751 }
752
753 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500754 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800755 }
756
cdalton9c3f1432016-03-11 10:07:37 -0800757 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400758 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
759 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400760 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400761 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
762 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
763 // At least one driver has been found that has this extension without the "GL_" prefix.
764 shaderCaps->fExternalTextureSupport = true;
765 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800766 }
767 }
768
cdaltonc04ce672016-03-11 14:07:38 -0800769 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600770 shaderCaps->fVertexIDSupport = true;
771 } else {
772 // Desktop GLSL 3.30 == ES GLSL 3.00.
773 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
774 }
775
Chris Dalton7c7ff032018-03-28 20:09:58 -0600776 if (kGL_GrGLStandard == standard) {
777 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
778 } else {
779 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
780 }
781
Chris Dalton47c8ed32017-11-15 18:27:09 -0700782 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
783 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400784
785 // Unsigned integers only supported in and after GLSL 1.30.
786 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700787}
788
kkinnunencfe62e32015-07-01 02:58:50 -0700789bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700790 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
791
792 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700793 return false;
794 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700795
kkinnunencfe62e32015-07-01 02:58:50 -0700796 if (kGL_GrGLStandard == ctxInfo.standard()) {
797 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
798 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
799 return false;
800 }
801 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700802 if (!hasChromiumPathRendering &&
803 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700804 return false;
805 }
806 }
807 // We only support v1.3+ of GL_NV_path_rendering which allows us to
808 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
809 // additions are detected by checking the existence of the function.
810 // We also use *Then* functions that not all drivers might have. Check
811 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800812 if (!gli->fFunctions.fStencilThenCoverFillPath ||
813 !gli->fFunctions.fStencilThenCoverStrokePath ||
814 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
815 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
816 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700817 return false;
818 }
819 return true;
820}
bsalomon1aa20292016-01-22 08:16:09 -0800821
Brian Salomon71d9d842016-11-03 13:42:00 -0400822bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800823 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800824 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800825 std::function<bool ()> bindRenderTarget,
826 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400827 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800828 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400829 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800830 return false;
831 }
bsalomon7928ef62016-01-05 10:26:39 -0800832
bsalomon76148af2016-01-12 11:13:47 -0800833 GrGLenum readFormat;
834 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400835 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800836 return false;
837 }
838
bsalomon1aa20292016-01-22 08:16:09 -0800839 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800840 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
841 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
842 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
843 // 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 -0500844 // The manual does not seem to fully match the spec as the spec allows integer formats
845 // when the bound color buffer is an integer buffer. It doesn't specify which integer
846 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500847 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
848 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
849 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800850 return false;
851 }
852 // There is also a set of allowed types, but all the types we use are in the set:
853 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
854 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
855 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
856 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
857 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
858 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
859 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800860 return true;
piotaixre4b23142014-10-02 10:57:53 -0700861 }
bsalomon7928ef62016-01-05 10:26:39 -0800862
bsalomon76148af2016-01-12 11:13:47 -0800863 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500864 switch (fConfigTable[surfaceConfig].fFormatType) {
865 case kNormalizedFixedPoint_FormatType:
866 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
867 return true;
868 }
869 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500870 case kFloat_FormatType:
871 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
872 return true;
873 }
874 break;
bsalomon7928ef62016-01-05 10:26:39 -0800875 }
876
Brian Salomon71d9d842016-11-03 13:42:00 -0400877 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800878 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400879 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800880 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800881 if (!bindRenderTarget()) {
882 return false;
883 }
884 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
885 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800886 rpFormat->fFormat = format;
887 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800888 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800889 }
890
Brian Salomon71d9d842016-11-03 13:42:00 -0400891 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
892 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700893}
894
Eric Karl5c779752017-05-08 12:02:07 -0700895void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
896 const GrGLInterface* gli) {
897 // We need dual source blending and the ability to disable multisample in order to support mixed
898 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
899 // renderer is available and enabled; no other path renderers support this feature.
900 if (fMultisampleDisableSupport &&
901 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400902 this->shaderCaps()->pathRenderingSupport()
903#if GR_TEST_UTILS
904 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
905#endif
906 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700907 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400908 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700909 }
910
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000911 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400912 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
913 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
914 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
915 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
916 fAlpha8IsRenderable = true;
917 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500918 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
919 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
920 // mixed samples we can't use multisampled-render-to-texture.
921 if (fUsesMixedSamples) {
922 fMSFBOType = kMixedSamples_MSFBOType;
923 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000924 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
925 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
926 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400927 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
928 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400929 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400930 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400931 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400932 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000933 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
934 fMSFBOType = kES_Apple_MSFBOType;
935 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000936 } else {
egdanieleed519e2016-01-15 11:36:18 -0800937 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700938 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400939 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
940 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400941
Brian Salomon00731b42016-10-14 11:30:51 -0400942 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400943 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
944 // Core profile removes ALPHA8 support.
945 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
946 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
947 // present.
948 fAlpha8IsRenderable = true;
949 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000950 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
951 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400952 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000953 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000954 }
Eric Karl5c779752017-05-08 12:02:07 -0700955
Brian Salomon01b476a2018-01-23 11:06:41 -0500956 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400957 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
958 fMSFBOType = kNone_MSFBOType;
959 }
960
Eric Karl5c779752017-05-08 12:02:07 -0700961 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
962 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
963 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700964 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000965}
966
cdalton1dd05422015-06-12 09:01:18 -0700967void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500968 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700969
Greg Daniel210883c2017-11-27 15:14:01 -0500970 bool layoutQualifierSupport = false;
971 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
972 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
973 layoutQualifierSupport = true;
974 }
975
cdalton1dd05422015-06-12 09:01:18 -0700976 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
977 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500978 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500979 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
980 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700981 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500982 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700983 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
984 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500985 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500986 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700987 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500988 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700989 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
990 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -0700991 }
cdalton1dd05422015-06-12 09:01:18 -0700992}
993
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000994namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700995const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000996}
997
Eric Karl5c779752017-05-08 12:02:07 -0700998void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000999
1000 // Build up list of legal stencil formats (though perhaps not supported on
1001 // the particular gpu/driver) from most preferred to least.
1002
1003 // these consts are in order of most preferred to least preferred
1004 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1005
1006 static const StencilFormat
1007 // internal Format stencil bits total bits packed?
1008 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1009 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1010 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1011 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001012 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001013 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1014
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001015 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001016 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001017 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001018 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1019 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1020
1021 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1022 // require FBO support we can expect these are legal formats and don't
1023 // check. These also all support the unsized GL_STENCIL_INDEX.
1024 fStencilFormats.push_back() = gS8;
1025 fStencilFormats.push_back() = gS16;
1026 if (supportsPackedDS) {
1027 fStencilFormats.push_back() = gD24S8;
1028 }
1029 fStencilFormats.push_back() = gS4;
1030 if (supportsPackedDS) {
1031 fStencilFormats.push_back() = gDS;
1032 }
1033 } else {
1034 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1035 // for other formats.
1036 // ES doesn't support using the unsized format.
1037
1038 fStencilFormats.push_back() = gS8;
1039 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001040 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1041 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001042 fStencilFormats.push_back() = gD24S8;
1043 }
1044 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1045 fStencilFormats.push_back() = gS4;
1046 }
1047 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001048}
1049
Brian Osman71a18892017-08-10 10:23:25 -04001050void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001051
Brian Osman71a18892017-08-10 10:23:25 -04001052 // We are called by the base class, which has already called beginObject(). We choose to nest
1053 // all of our caps information in a named sub-object.
1054 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001055
Brian Osman71a18892017-08-10 10:23:25 -04001056 writer->beginArray("Stencil Formats");
1057
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001058 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001059 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001060 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1061 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1062 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001063 }
1064
Brian Osman71a18892017-08-10 10:23:25 -04001065 writer->endArray();
1066
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001067 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001068 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001069 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001070 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001071 "IMG MS To Texture",
1072 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001073 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001074 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001075 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001076 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1077 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1078 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1079 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1080 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001081 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001082
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001083 static const char* kInvalidateFBTypeStr[] = {
1084 "None",
1085 "Discard",
1086 "Invalidate",
1087 };
1088 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1089 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1090 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1091 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001092
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001093 static const char* kMapBufferTypeStr[] = {
1094 "None",
1095 "MapBuffer",
1096 "MapBufferRange",
1097 "Chromium",
1098 };
1099 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1100 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1101 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1102 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1103 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1104
Brian Osman71a18892017-08-10 10:23:25 -04001105 writer->appendBool("Core Profile", fIsCoreProfile);
1106 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1107 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1108 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1109 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1110 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1111 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1112 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1113 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001114
Brian Osman71a18892017-08-10 10:23:25 -04001115 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001116 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1117 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1118 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001119 writer->appendBool("Debug support", fDebugSupport);
1120 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1121 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1122 writer->appendBool("Base instance support", fBaseInstanceSupport);
1123 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1124 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1125 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1126 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1127 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1128 writer->appendBool("BGRA to RGBA readback conversions are slow",
1129 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001130 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001131 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1132 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001133 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1134 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1135 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1136 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001137 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1138 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001139
Brian Osman71a18892017-08-10 10:23:25 -04001140 writer->beginArray("configs");
1141
bsalomon41e4384e2016-01-08 09:12:44 -08001142 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001143 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001144 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1145 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1146 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001147 writer->appendHexU32("e_format_read_pixels",
1148 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001149 writer->appendHexU32(
1150 "e_format_teximage",
1151 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1152 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1153 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1154 writer->appendHexU32("i_for_renderbuffer",
1155 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1156 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001157 }
1158
Brian Osman71a18892017-08-10 10:23:25 -04001159 writer->endArray();
1160 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001161}
1162
bsalomon41e4384e2016-01-08 09:12:44 -08001163bool GrGLCaps::bgraIsInternalFormat() const {
1164 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1165}
1166
bsalomon76148af2016-01-12 11:13:47 -08001167bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1168 GrGLenum* internalFormat, GrGLenum* externalFormat,
1169 GrGLenum* externalType) const {
1170 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1171 externalFormat, externalType)) {
1172 return false;
1173 }
1174 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1175 return true;
1176}
1177
bsalomon76148af2016-01-12 11:13:47 -08001178bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1179 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001180 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001181 externalFormat, externalType)) {
1182 return false;
1183 }
1184 return true;
1185}
1186
Brian Salomon93348dd2018-08-29 12:56:23 -04001187void GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001188 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
Brian Salomon93348dd2018-08-29 12:56:23 -04001189}
1190
1191void GrGLCaps::getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1192 *internalFormat = fConfigTable[config].fFormats.fSizedInternalFormat;
bsalomon76148af2016-01-12 11:13:47 -08001193}
1194
1195bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1196 ExternalFormatUsage usage, GrGLenum* externalFormat,
1197 GrGLenum* externalType) const {
1198 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001199
1200 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1201 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1202
1203 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001204 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1205 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001206 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1207 return false;
1208 }
1209
1210 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1211 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1212
bsalomone9573312016-01-25 14:33:25 -08001213 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1214 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1215 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1216 // texture, not the red component.
1217 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001218 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001219 *externalFormat = GR_GL_ALPHA;
1220 }
1221 }
1222
bsalomon76148af2016-01-12 11:13:47 -08001223 return true;
1224}
1225
brianosman20471892016-12-02 06:43:32 -08001226void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1227 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001228 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001229 /*
1230 Comments on renderability of configs on various GL versions.
1231 OpenGL < 3.0:
1232 no built in support for render targets.
1233 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1234 format RGB, RGBA and NV float formats we don't use.
1235 This is the following:
1236 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1237 RGB10_A2, RGBA12,RGBA16
1238 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1239 since they aren't required by later standards and the driver can simply return
1240 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1241 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1242 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1243 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1244 This adds a lot of additional renderable sized formats, including ALPHA8.
1245 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1246 16F, 32I, 32UI, and 32F variants).
1247 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1248
1249 For both the above extensions we limit ourselves to those that are also required by
1250 OpenGL 3.0.
1251
1252 OpenGL 3.0:
1253 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1254 but are not required to be supported as renderable textures/renderbuffer.
1255 Required renderable color formats:
1256 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1257 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1258 RGB10_A2.
1259 - R11F_G11F_B10F.
1260 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1261 and RG8UI.
1262 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1263 - ALPHA8
1264
1265 OpenGL 3.1, 3.2, 3.3
1266 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1267 OpengGL 3.3, 4.0, 4.1
1268 Adds RGB10_A2UI.
1269 OpengGL 4.2
1270 Adds
1271 - RGB5_A1, RGBA4
1272 - RGB565
1273 OpenGL 4.4
1274 Does away with the separate list and adds a column to the sized internal color format
1275 table. However, no new formats become required color renderable.
1276
1277 ES 2.0
1278 color renderable: RGBA4, RGB5_A1, RGB565
1279 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1280 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1281 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1282 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1283 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1284 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1285
1286 ES 3.0
1287 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1288 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1289 RGB5_A1.
1290 - RGB8 and RGB565.
1291 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1292 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1293 ES 3.1
1294 Adds RGB10_A2, RGB10_A2UI,
1295 ES 3.2
1296 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1297 */
Brian Salomon44804c02018-01-23 16:51:28 -05001298
1299 // Correctness workarounds.
1300 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001301 bool disableSRGBForX86PowerVR = false;
1302 bool disableSRGBWriteControlForAdreno4xx = false;
1303 bool disableR8TexStorageForANGLEGL = false;
1304 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001305 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001306 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001307
1308 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1309 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1310 // and GL_RG on FBO textures.
1311 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1312
Greg Daniel09c94002018-06-08 22:11:51 +00001313 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1314
Brian Salomon44804c02018-01-23 16:51:28 -05001315 bool isX86PowerVR = false;
1316#if defined(SK_CPU_X86)
1317 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1318 isX86PowerVR = true;
1319 }
1320#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001321 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1322 // blacklist that device (and any others that might be sharing the same driver).
1323 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001324 disableSRGBWriteControlForAdreno4xx =
1325 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1326 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001327
1328 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1329 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1330 // check that we are not going to OpenGL.
1331 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1332
1333 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1334#if defined(SK_BUILD_FOR_MAC)
1335 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1336#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001337 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1338 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001339 }
1340
Brian Salomon71d9d842016-11-03 13:42:00 -04001341 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1342 ConfigInfo::kFBOColorAttachment_Flag;
1343 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001344 if (kNone_MSFBOType != fMSFBOType) {
1345 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1346 }
bsalomon41e4384e2016-01-08 09:12:44 -08001347 GrGLStandard standard = ctxInfo.standard();
1348 GrGLVersion version = ctxInfo.version();
1349
cblume790d5132016-02-29 11:13:29 -08001350 bool texStorageSupported = false;
1351 if (kGL_GrGLStandard == standard) {
1352 // The EXT version can apply to either GL or GLES.
1353 texStorageSupported = version >= GR_GL_VER(4,2) ||
1354 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1355 ctxInfo.hasExtension("GL_EXT_texture_storage");
1356 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001357 texStorageSupported = version >= GR_GL_VER(3,0) ||
1358 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001359 }
Adrienne Walker70e468f2018-08-22 16:05:27 -07001360 if (fDriverBugWorkarounds.disable_texture_storage) {
1361 texStorageSupported = false;
1362 }
cblume790d5132016-02-29 11:13:29 -08001363
Brian Salomone609e812018-01-17 14:00:47 -05001364 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001365
1366 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001367 if (kGL_GrGLStandard == standard) {
1368 textureRedSupport =
1369 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1370 } else {
1371 textureRedSupport =
1372 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1373 }
1374 }
1375
bsalomon30447372015-12-21 09:03:05 -08001376 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1377 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001378 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001379 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001380 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001381 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001382
1383 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1384 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001385 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001386 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001387 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001388 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001389 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1390 if (kGL_GrGLStandard == standard) {
1391 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1392 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001393 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001394 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1395 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1396 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1397 }
egdaniel4999df82016-01-07 17:06:04 -08001398 }
cblume790d5132016-02-29 11:13:29 -08001399 if (texStorageSupported) {
1400 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1401 }
bsalomoncdee0092016-01-08 13:20:12 -08001402 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001403
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001404 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1405 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1406 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1407 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1408 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1409 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1410 // supportedReadPixelsColorType never returns it.
1411 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1412 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1413 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1414 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1415 if (kGL_GrGLStandard == standard) {
1416 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1417 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1418 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1419 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1420 // becomes an issue.
1421 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1422 // but we don't support that just for simplicity's sake.
1423 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1424 } else {
1425 // 3.0 and the extension support this as a render buffer format.
1426 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1427 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1428 }
1429 }
1430 if (texStorageSupported) {
1431 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1432 }
1433 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1434 if (disableRGB8ForMali400) {
1435 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1436 }
1437
1438 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001439 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001440 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001441 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001442
1443 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1444 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1445 // GL_EXT_texture_format_BGRA8888.
1446 bool supportsBGRATexStorage = false;
1447
bsalomon41e4384e2016-01-08 09:12:44 -08001448 if (kGL_GrGLStandard == standard) {
1449 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1450 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1451 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1452 // Since the internal format is RGBA8, it is also renderable.
1453 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1454 allRenderFlags;
1455 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001456 // Since we are using RGBA8 we can use tex storage.
1457 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001458 } else {
1459 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1460 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001461 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1462 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1463 nonMSAARenderFlags;
1464
1465 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1466 supportsBGRATexStorage = true;
1467 }
1468 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1469 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1470 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1471 ConfigInfo::kRenderableWithMSAA_Flag;
1472 }
1473 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001474 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1475 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1476 // driver remembers the external format when the texture is created (with TexImage).
1477 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1478 // We could work around this, but it adds even more state tracking to code that is
1479 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1480 // This also side-steps some ambiguous interactions with the texture storage extension.
1481 if (version >= GR_GL_VER(3,0)) {
1482 // The APPLE extension doesn't make this renderable.
1483 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001484 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001485 }
bsalomon41e4384e2016-01-08 09:12:44 -08001486 }
1487 }
Brian Osman48c99192017-06-02 08:45:06 -04001488
Greg Daniel0ff79b22018-02-15 12:33:33 -05001489 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001490 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001491 }
bsalomoncdee0092016-01-08 13:20:12 -08001492 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001493
Brian Osman2b23c4b2018-06-01 12:25:08 -04001494 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001495 if (kGL_GrGLStandard == standard) {
1496 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001497 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001498 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1499 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1500 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001501 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001502 }
1503 }
1504 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001505 if (fSRGBSupport) {
1506 fSRGBWriteControl = true;
1507 }
bsalomon41e4384e2016-01-08 09:12:44 -08001508 } else {
brianosman20471892016-12-02 06:43:32 -08001509 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001510 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001511 fSRGBSupport = false;
1512 }
bsalomon41e4384e2016-01-08 09:12:44 -08001513 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1514 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001515 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001516 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001517 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001518 }
brianosman20471892016-12-02 06:43:32 -08001519
1520 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1521 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1522 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1523 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1524 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1525 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1526 // affects Windows.
1527 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1528 fSRGBSupport = false;
1529 }
1530
Brian Osman48c99192017-06-02 08:45:06 -04001531 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1532 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1533 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1534
Brian Osman67999392017-05-31 16:19:34 -04001535 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001536 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001537 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1538 }
Brian Osman67999392017-05-31 16:19:34 -04001539
bsalomon30447372015-12-21 09:03:05 -08001540 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1541 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1542 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1543 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001544 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001545 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001546 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001547 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001548 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001549 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001550 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001551 }
Brian Osman48c99192017-06-02 08:45:06 -04001552 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1553 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001554 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1555 }
bsalomoncdee0092016-01-08 13:20:12 -08001556 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001557 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1558 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1559 // is in this format, for example).
1560 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1561 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1562 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1563 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001564 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001565 GR_GL_BGRA;
1566 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1567 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001568 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001569 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001570 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001571 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001572
brianosmana6359362016-03-21 06:55:37 -07001573 if (texStorageSupported) {
1574 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1575 }
1576 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1577
bsalomon30447372015-12-21 09:03:05 -08001578 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1579 if (this->ES2CompatibilitySupport()) {
1580 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1581 } else {
1582 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1583 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001584 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001585 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001586 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001587 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001588 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1589 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001590 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001591 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1592 }
1593 } else {
1594 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1595 }
cblume790d5132016-02-29 11:13:29 -08001596 // 565 is not a sized internal format on desktop GL. So on desktop with
1597 // 565 we always use an unsized internal format to let the system pick
1598 // the best sized format to convert the 565 data to. Since TexStorage
1599 // only allows sized internal formats we disallow it.
1600 //
1601 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1602 // update.
1603 if (texStorageSupported && kGL_GrGLStandard != standard) {
1604 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1605 }
bsalomoncdee0092016-01-08 13:20:12 -08001606 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001607
1608 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1609 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001610 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001611 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001612 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001613 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001614 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1615 if (kGL_GrGLStandard == standard) {
1616 if (version >= GR_GL_VER(4, 2)) {
1617 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1618 }
1619 } else {
1620 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1621 }
cblume790d5132016-02-29 11:13:29 -08001622 if (texStorageSupported) {
1623 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1624 }
bsalomoncdee0092016-01-08 13:20:12 -08001625 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001626
Brian Osman10fc6fd2018-03-02 11:01:10 -05001627 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1628 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001629 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001630 GR_GL_RGBA;
1631 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1632 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1633 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1634 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1635 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1636 allRenderFlags;
1637 }
1638 if (texStorageSupported) {
1639 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1640 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001641 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1642
Greg Danielef59d872017-11-17 16:47:21 -05001643 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1644 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1645
1646 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1647 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1648 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1649 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1650 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001651 }
Greg Danielef59d872017-11-17 16:47:21 -05001652 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1653 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001654 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001655 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1656 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1657 alphaInfo.fFlags |= allRenderFlags;
1658 }
1659
1660 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1661 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1662 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1663 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1664 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001665 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001666 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001667
Brian Osman48c99192017-06-02 08:45:06 -04001668 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1669 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001670 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001671 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1672 }
1673 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1674 }
1675
Brian Salomone609e812018-01-17 14:00:47 -05001676 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001677 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001678 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1679 } else {
1680 redInfo.fFlags = 0;
1681
1682 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001683 }
bsalomon41e4384e2016-01-08 09:12:44 -08001684
Greg Daniel7af060a2017-12-05 16:27:11 -05001685 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1686 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1687 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1688 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1689 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001690 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001691 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1692 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1693 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1694 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001695 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001696
1697 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1698 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1699 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1700 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1701 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001702 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001703 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1704 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1705
Greg Daniel09c94002018-06-08 22:11:51 +00001706 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1707 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1708 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1709 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1710 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001711 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1712 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1713 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001714 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001715 }
Brian Osman48c99192017-06-02 08:45:06 -04001716 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001717 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001718 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1719 }
1720 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1721 }
1722
Brian Salomone609e812018-01-17 14:00:47 -05001723 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001724 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1725 } else {
1726 grayRedInfo.fFlags = 0;
1727 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001728 }
1729
bsalomon41e4384e2016-01-08 09:12:44 -08001730 // Check for [half] floating point texture support
1731 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1732 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1733 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
Chris Daltoneff01a72018-07-19 17:06:39 -06001734 bool hasFP32Textures = false;
1735 bool hasFP16Textures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001736 bool rgIsTexturable = false;
Chris Daltoneff01a72018-07-19 17:06:39 -06001737 bool hasFP32RenderTargets = false;
1738 bool hasFP16RenderTargets = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001739 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001740 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001741
1742 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001743 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001744 hasFP32Textures = true;
1745 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001746 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001747 hasFP32RenderTargets = true;
1748 hasFP16RenderTargets = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001749 }
1750 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001751 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001752 hasFP32Textures = true;
1753 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001754 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001755 } else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1756 ctxInfo.hasExtension("GL_OES_texture_float")) {
1757 hasFP32Textures = true;
1758 hasFP16Textures = true;
1759 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1760 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1761 hasFP16Textures = true;
1762 }
1763
1764 if (version >= GR_GL_VER(3, 2)) {
1765 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to solve
1766 // many precision issues and no clients actually want this yet.
1767 // hasFP32RenderTargets = true;
1768 hasFP16RenderTargets = true;
1769 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
1770 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to
1771 // solve many precision issues and no clients actually want this yet.
1772 // hasFP32RenderTargets = true;
1773 hasFP16RenderTargets = true;
1774 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1775 hasFP16RenderTargets = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001776 }
1777 }
bsalomon30447372015-12-21 09:03:05 -08001778
csmartdalton6aa0e112017-02-08 16:14:11 -05001779 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1780 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1781 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1782 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1783 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001784 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001785 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1786 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001787 if (hasFP32Textures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001788 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
Chris Daltoneff01a72018-07-19 17:06:39 -06001789 if (hasFP32RenderTargets) {
csmartdalton6aa0e112017-02-08 16:14:11 -05001790 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1791 }
bsalomon41e4384e2016-01-08 09:12:44 -08001792 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001793 if (texStorageSupported) {
1794 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1795 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001796 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001797 }
bsalomon30447372015-12-21 09:03:05 -08001798
Greg Danielef59d872017-11-17 16:47:21 -05001799 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001800 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001801 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001802 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001803 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001804 }
Greg Danielef59d872017-11-17 16:47:21 -05001805 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1806 redHalf.fFormats.fExternalType = redHalfExternalType;
1807 redHalf.fFormatType = kFloat_FormatType;
1808 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1809 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001810 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001811 redHalf.fSwizzle = GrSwizzle::RRRR();
Chris Daltoneff01a72018-07-19 17:06:39 -06001812 if (textureRedSupport && hasFP16Textures) {
Greg Danielef59d872017-11-17 16:47:21 -05001813 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1814
Chris Daltoneff01a72018-07-19 17:06:39 -06001815 if (hasFP16RenderTargets) {
Greg Danielef59d872017-11-17 16:47:21 -05001816 redHalf.fFlags |= fpRenderFlags;
1817 }
1818
1819 if (texStorageSupported && !isCommandBufferES2) {
1820 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1821 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001822 }
Greg Danielef59d872017-11-17 16:47:21 -05001823 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001824
1825 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1826 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001827 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001828 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001829 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001830 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1831 } else {
1832 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1833 }
bsalomon7928ef62016-01-05 10:26:39 -08001834 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001835 if (hasFP16Textures) {
bsalomon41e4384e2016-01-08 09:12:44 -08001836 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1837 // ES requires 3.2 or EXT_color_buffer_half_float.
Chris Daltoneff01a72018-07-19 17:06:39 -06001838 if (hasFP16RenderTargets) {
bsalomon41e4384e2016-01-08 09:12:44 -08001839 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1840 }
1841 }
cblume790d5132016-02-29 11:13:29 -08001842 if (texStorageSupported) {
1843 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1844 }
bsalomoncdee0092016-01-08 13:20:12 -08001845 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001846
bsalomon30447372015-12-21 09:03:05 -08001847 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1848
1849 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001850 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1851 ctxInfo.version() >= GR_GL_VER(3,0));
1852 // All ES versions (thus far) require sized internal formats for render buffers.
1853 // TODO: Always use sized internal format?
1854 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1855
bsalomon30447372015-12-21 09:03:05 -08001856 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001857 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1858 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001859 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001860 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001861 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1862 fConfigTable[i].fFormats.fSizedInternalFormat :
1863 fConfigTable[i].fFormats.fBaseInternalFormat;
1864 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001865 fConfigTable[i].fFormats.fSizedInternalFormat :
1866 fConfigTable[i].fFormats.fBaseInternalFormat;
1867 }
Brian Salomon44804c02018-01-23 16:51:28 -05001868 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1869 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1870 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1871 // in ES.
1872 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1873 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1874 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1875 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001876 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1877 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001878 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1879 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001880 }
1881
bsalomon30447372015-12-21 09:03:05 -08001882 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1883 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1884 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1885 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1886 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001887 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001888 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001889
1890 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1891 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1892 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1893 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001894 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001895 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1896 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1897 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1898 // slot.
1899 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1900 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001901
1902 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1903 // as a base format.
1904 // GL_EXT_texture_format_BGRA8888:
1905 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1906 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1907 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001908 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001909 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1910 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1911 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001912 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001913 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1914 }
1915
bsalomoncdee0092016-01-08 13:20:12 -08001916 // If we don't have texture swizzle support then the shader generator must insert the
1917 // swizzle into shader code.
1918 if (!this->textureSwizzleSupport()) {
1919 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001920 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001921 }
1922 }
1923
bsalomon7f9b2e42016-01-12 13:29:26 -08001924 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1925 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1926 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001927 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001928 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1929 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1930 if (GrPixelConfigIsAlphaOnly(config) &&
1931 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001932 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001933 }
1934 }
1935 }
1936
Greg Daniel81e7bf82017-07-19 14:47:42 -04001937 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1938 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001939 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1940 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001941 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001942 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1943 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001944 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001945 int count;
1946 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1947 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1948 1, &count);
1949 if (count) {
1950 int* temp = new int[count];
1951 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1952 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001953 // GL has a concept of MSAA rasterization with a single sample but we do not.
1954 if (count && temp[count - 1] == 1) {
1955 --count;
1956 SkASSERT(!count || temp[count -1] > 1);
1957 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001958 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001959 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001960 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001961 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001962 for (int j = 0; j < count; ++j) {
1963 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1964 }
1965 delete[] temp;
1966 }
1967 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001968 // Fake out the table using some semi-standard counts up to the max allowed sample
1969 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001970 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001971 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1972 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1973 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1974 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1975 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001976 // Chrome has a mock GL implementation that returns 0.
1977 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05001978
Brian Salomonbdecacf2018-02-02 20:32:49 -05001979 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04001980 int count = SK_ARRAY_COUNT(kDefaultSamples);
1981 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001982 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001983 break;
1984 }
1985 }
1986 if (count > 0) {
1987 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
1988 }
1989 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001990 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
1991 fConfigTable[i].fColorSampleCounts.setCount(1);
1992 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001993 }
1994 }
1995
bsalomon30447372015-12-21 09:03:05 -08001996#ifdef SK_DEBUG
1997 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001998 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001999 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002000 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2001 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002002 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2003 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2004 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2005 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002006 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2007 fConfigTable[i].fFormats.fBaseInternalFormat);
2008 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002009 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002010 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2011 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2012 fConfigTable[i].fFormats.fExternalFormat[j]);
2013 }
2014 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002015 }
2016#endif
2017}
2018
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002019bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2020 bool dstIsTextureable, bool dstIsGLTexture2D,
2021 GrSurfaceOrigin dstOrigin,
2022 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2023 bool srcIsTextureable, bool srcIsGLTexture2D,
2024 GrSurfaceOrigin srcOrigin) const {
2025 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2026 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2027 // many drivers would allow it to work, but ANGLE does not.
2028 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2029 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2030 return false;
2031 }
2032
2033 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2034 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2035 return false;
2036 }
2037
2038 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2039 // texture.
2040 if (!dstIsTextureable) {
2041 return false;
2042 }
2043
2044 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2045 // is required
2046 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2047 (!srcIsTextureable || srcIsGLTexture2D) &&
2048 dstIsGLTexture2D &&
2049 dstOrigin == srcOrigin) {
2050 return true;
2051 } else {
2052 return false;
2053 }
2054}
2055
2056bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2057 bool dstIsTextureable, bool dstIsGLTexture2D,
2058 GrSurfaceOrigin dstOrigin,
2059 GrPixelConfig srcConfig, int srcSampleCnt,
2060 bool srcIsTextureable, bool srcIsGLTexture2D,
2061 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2062 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2063 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2064 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2065 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2066 return false;
2067 }
2068
2069 if (dstIsTextureable && !dstIsGLTexture2D) {
2070 return false;
2071 }
2072 if (srcIsTextureable && !srcIsGLTexture2D) {
2073 return false;
2074 }
2075
2076 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2077 return false;
2078 }
2079 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2080 // We would mirror to compensate for origin changes. Note that copySurface is
2081 // specified such that the src and dst rects are the same.
2082 if (dstOrigin != srcOrigin) {
2083 return false;
2084 }
2085 }
2086
2087 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2088 if (srcSampleCnt > 1) {
2089 if (1 == dstSampleCnt) {
2090 return false;
2091 }
2092 if (SkRect::Make(srcRect) != srcBounds) {
2093 return false;
2094 }
2095 }
2096 }
2097
2098 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2099 if (dstSampleCnt > 1) {
2100 return false;
2101 }
2102 }
2103
2104 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2105 if (dstConfig != srcConfig) {
2106 return false;
2107 }
2108 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2109 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2110 return false;
2111 }
2112 }
2113
2114 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2115 if (srcSampleCnt > 1) {
2116 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2117 return false;
2118 }
2119 if (dstOrigin != srcOrigin) {
2120 return false;
2121 }
2122 }
2123 }
2124 return true;
2125}
2126
2127bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2128 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2129}
2130
2131static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2132 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2133 if (!rt) {
2134 return false;
2135 }
2136 // A RT has a separate MSAA renderbuffer if:
2137 // 1) It's multisampled
2138 // 2) We're using an extension with separate MSAA renderbuffers
2139 // 3) It's not FBO 0, which is special and always auto-resolves
2140 return rt->numColorSamples() > 1 &&
2141 glCaps.usesMSAARenderBuffers() &&
2142 !rt->rtPriv().glRTFBOIDIs0();
2143}
2144
2145bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2146 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2147 GrSurfaceOrigin dstOrigin = dst->origin();
2148 GrSurfaceOrigin srcOrigin = src->origin();
2149
2150 GrPixelConfig dstConfig = dst->config();
2151 GrPixelConfig srcConfig = src->config();
2152
2153 int dstSampleCnt = 0;
2154 int srcSampleCnt = 0;
2155 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2156 dstSampleCnt = rtProxy->numColorSamples();
2157 }
2158 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2159 srcSampleCnt = rtProxy->numColorSamples();
2160 }
2161 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2162 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2163
2164 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2165 // swizzle.
2166 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2167 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2168 return false;
2169 }
2170
2171 const GrTextureProxy* dstTex = dst->asTextureProxy();
2172 const GrTextureProxy* srcTex = src->asTextureProxy();
2173
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002174 bool dstIsTex2D = dstTex ? (dstTex->textureType() == GrTextureType::k2D) : false;
2175 bool srcIsTex2D = srcTex ? (srcTex->textureType() == GrTextureType::k2D) : false;
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002176
2177 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2178 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2179 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2180 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2181 // know we will at least be able to do it as a draw.
2182#ifdef SK_DEBUG
2183 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2184 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2185 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2186 !src->priv().isExact()) {
2187 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2188 }
2189#endif
2190
2191 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2192 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2193 srcConfig, has_msaa_render_buffer(src, *this),
2194 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2195 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2196 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2197 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2198 dstPoint) ||
2199 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2200}
2201
Robert Phillipsbf25d432017-04-07 10:08:53 -04002202bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002203 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2204 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002205 // By default, we don't require rects to match.
2206 *rectsMustMatch = false;
2207
2208 // By default, we allow subrects.
2209 *disallowSubrect = false;
2210
Brian Salomon467921e2017-03-06 16:17:12 -05002211 // If the src is a texture, we can implement the blit as a draw assuming the config is
2212 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002213 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002214 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002215 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2216 desc->fConfig = src->config();
2217 return true;
2218 }
2219
Robert Phillipsbf25d432017-04-07 10:08:53 -04002220 {
2221 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2222 // wrapped. In that case the proxy would already be instantiated.
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002223 const GrTexture* srcTexture = src->peekTexture();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002224 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2225 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2226 // Not supported for FBO blit or CopyTexSubImage
2227 return false;
2228 }
Brian Salomon467921e2017-03-06 16:17:12 -05002229 }
2230
2231 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2232 // possible and we return false to fallback to creating a render target dst for render-to-
2233 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2234 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002235 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002236 bool rectsMustMatchForBlitFramebuffer = false;
2237 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002238 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002239 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2240 rectsMustMatchForBlitFramebuffer = true;
2241 disallowSubrectForBlitFramebuffer = true;
2242 // Mirroring causes rects to mismatch later, don't allow it.
2243 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002244 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2245 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002246 rectsMustMatchForBlitFramebuffer = true;
2247 // Mirroring causes rects to mismatch later, don't allow it.
2248 originForBlitFramebuffer = src->origin();
2249 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002250 originForBlitFramebuffer = src->origin();
2251 }
2252
2253 // Check for format issues with glCopyTexSubImage2D
2254 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2255 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2256 // then we set up for that, otherwise fail.
2257 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002258 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002259 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002260 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2261 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002262 return true;
2263 }
2264 return false;
2265 }
2266
Robert Phillipsbf25d432017-04-07 10:08:53 -04002267 {
Brian Salomon63e79732017-05-15 21:23:13 -04002268 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2269 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002270 if (srcIsMSAARenderbuffer) {
2271 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2272 // blit or fail.
2273 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002274 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002275 desc->fConfig = src->config();
2276 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2277 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2278 return true;
2279 }
2280 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002281 }
Brian Salomon467921e2017-03-06 16:17:12 -05002282 }
2283
2284 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002285 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002286 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002287 desc->fFlags = kNone_GrSurfaceFlags;
2288 return true;
2289}
2290
Greg Daniel691f5e72018-02-28 14:21:34 -05002291void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2292 const GrContextOptions& contextOptions,
2293 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002294 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2295 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002296 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2297 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002298 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002299 fDiscardRenderTargetSupport = false;
2300 fInvalidateFBType = kNone_InvalidateFBType;
2301 }
2302
2303 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2304 // 340.96 and 367.57.
2305 if (kGL_GrGLStandard == ctxInfo.standard() &&
2306 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002307 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002308 fClearTextureSupport = false;
2309 }
2310
2311 // Calling glClearTexImage crashes on the NexusPlayer.
2312 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2313 fClearTextureSupport = false;
2314 }
2315
2316 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2317#ifdef SK_BUILD_FOR_MAC
2318 if (shaderCaps->fGeometryShaderSupport) {
2319 shaderCaps->fGSInvocationsSupport = false;
2320 }
2321#endif
2322
2323 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2324 // shaders. @127.0 is the earliest verified driver to not crash.
2325 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002326 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002327 shaderCaps->fGeometryShaderSupport = false;
2328 }
2329
2330#if defined(__has_feature)
2331#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2332 // See skbug.com/7058
2333 fMapBufferType = kNone_MapBufferType;
2334 fMapBufferFlags = kNone_MapFlags;
2335#endif
2336#endif
2337
2338 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2339 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2340 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2341 // unclear whether this really affects a wide range of devices.
2342 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002343 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002344 fMapBufferType = kNone_MapBufferType;
2345 fMapBufferFlags = kNone_MapFlags;
2346 }
2347
2348 // TODO: re-enable for ANGLE
2349 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2350 fTransferBufferType = kNone_TransferBufferType;
2351 }
2352
2353 // Using MIPs on this GPU seems to be a source of trouble.
2354 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2355 fMipMapSupport = false;
2356 }
2357
2358 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2359 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2360 // around a driver bug related to gl_FragCoord.
2361 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2362 fMaxClipAnalyticFPs = 0;
2363 }
2364
2365#ifndef SK_BUILD_FOR_IOS
2366 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2367 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2368 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2369 ctxInfo.driver() != kChromium_GrGLDriver)) {
2370 fUseDrawToClearColor = true;
2371 }
2372#endif
2373
2374 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2375 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2376 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2377 fUseDrawToClearColor = true;
2378 }
2379
2380#ifdef SK_BUILD_FOR_MAC
2381 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2382 // full screen clears
2383 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2384 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002385 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2386 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2387 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2388 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002389 fUseDrawToClearColor = true;
2390 }
2391#endif
2392
2393 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2394 // bugs seems to involve clearing too much and not skipping the clear.
2395 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2396 // but only for D3D11 ANGLE.
2397 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2398 fUseDrawToClearColor = true;
2399 }
2400
Chris Dalton1214be92018-06-28 19:06:27 -06002401 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2402 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002403 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002404 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002405 fUseDrawToClearStencilClip = true;
2406 }
2407 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2408 }
2409
Adrienne Walker94f585e2018-05-15 11:47:07 -07002410 if (fDriverBugWorkarounds.gl_clear_broken) {
2411 fUseDrawToClearColor = true;
2412 fUseDrawToClearStencilClip = true;
2413 }
2414
Brian Salomon01b476a2018-01-23 11:06:41 -05002415 // This was reproduced on the following configurations:
2416 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2417 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2418 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2419 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2420 // and not produced on:
2421 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2422 // The particular lines that get dropped from test images varies across different devices.
2423 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002424 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002425 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2426 }
2427
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002428 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2429 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2430 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002431 fRequiresFlushBetweenNonAndInstancedDraws = true;
2432 }
2433
Brian Osman1348ed02018-09-12 09:08:39 -04002434 // This was reproduced on a Pixel 1, but the unit test + config + options that exercise it are
2435 // only tested on very specific bots. The driver claims that ReadPixels is an invalid operation
2436 // when reading from an auto-resolving MSAA framebuffer that has stencil attached.
2437 if (kQualcomm_GrGLDriver == ctxInfo.driver()) {
2438 fDetachStencilFromMSAABuffersBeforeReadPixels = true;
2439 }
2440
Brian Salomon01b476a2018-01-23 11:06:41 -05002441 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2442 // given 1 << 15 or more instances.
2443 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2444 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
Adrienne Walker001cae02018-05-15 11:38:44 -07002445 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
2446 fMaxInstancesPerDrawArraysWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002447 }
2448
2449 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002450 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002451 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2452 fUseDrawInsteadOfAllRenderTargetWrites = true;
2453 }
2454
2455 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2456 fSampleShadingSupport = false;
2457 }
2458
2459#ifdef SK_BUILD_FOR_MAC
2460 static constexpr bool isMAC = true;
2461#else
2462 static constexpr bool isMAC = false;
2463#endif
2464
2465 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2466 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2467 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2468 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2469 if (fMipMapLevelAndLodControlSupport &&
2470 (contextOptions.fDoManualMipmapping ||
2471 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2472 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2473 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2474 fDoManualMipmapping = true;
2475 }
2476
2477 // See http://crbug.com/710443
2478#ifdef SK_BUILD_FOR_MAC
2479 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2480 fClearToBoundaryValuesIsBroken = true;
2481 }
2482#endif
2483 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2484 fDrawArraysBaseVertexIsBroken = true;
2485 }
2486
Brian Salomon01b476a2018-01-23 11:06:41 -05002487 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2488 // Galaxy S7.
2489 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2490 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2491 shaderCaps->fFBFetchSupport = false;
2492 }
2493
Brian Salomon01b476a2018-01-23 11:06:41 -05002494 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2495 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2496
2497 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2498 // function that may require a gradient calculation inside a conditional block may return
2499 // undefined results". This appears to be an issue with the 'any' call since even the simple
2500 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2501 // from our GrTextureDomain processor.
2502 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2503
2504 // Known issue on at least some Intel platforms:
2505 // http://code.google.com/p/skia/issues/detail?id=946
2506 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2507 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2508 }
2509
Chris Dalton0090ef62018-03-28 17:35:00 -06002510 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002511 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2512 // so we must do the abs first in a separate expression.
2513 shaderCaps->fCanUseMinAndAbsTogether = false;
2514
2515 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2516 // must avoid this condition.
2517 shaderCaps->fCanUseFractForNegativeValues = false;
2518 }
2519
2520 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2521 // thus must us -1.0 * %s.x to work correctly
2522 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2523 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2524 }
2525
2526 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2527 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2528 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2529 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2530 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2531 }
2532
2533 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2534 // the original dst color when reading the outColor even after being written to. By using a
2535 // local outColor we can work around this bug.
2536 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2537 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2538 }
2539
2540 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2541 // color, and that uniform contains an opaque color, and the output of the shader is only based
2542 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2543 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2544 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2545 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2546 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2547 shaderCaps->fMustObfuscateUniformColor = true;
2548 }
2549#ifdef SK_BUILD_FOR_WIN
2550 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2551 //
2552 // Basically, if a shader has a construct like:
2553 //
2554 // float x = someCondition ? someValue : 0;
2555 // float2 result = (0 == x) ? float2(x, x)
2556 // : float2(2 * x / x, 0);
2557 //
2558 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2559 // we've explicitly guarded the division with a check against zero. This manifests in much
2560 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2561 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2562 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2563 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2564 }
2565#endif
2566
2567 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002568 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002569 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2570 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002571 }
2572
Chris Dalton0090ef62018-03-28 17:35:00 -06002573 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2574 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2575 shaderCaps->fCanUseFragCoord = false;
2576 }
2577
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002578 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2579 // (Are they implemented with fp16?)
2580 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2581 shaderCaps->fIncompleteShortIntPrecision = true;
2582 }
2583
Adrienne Walkeree8295c2018-08-21 10:56:30 -07002584 if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
2585 shaderCaps->fAddAndTrueToLoopCondition = true;
2586 }
2587
Adrienne Walkerc02165f2018-08-21 11:08:11 -07002588 if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
2589 shaderCaps->fUnfoldShortCircuitAsTernary = true;
2590 }
2591
Adrienne Walker92b161f2018-08-22 10:41:52 -07002592 if (fDriverBugWorkarounds.emulate_abs_int_function) {
2593 shaderCaps->fEmulateAbsIntFunction = true;
2594 }
2595
Adrienne Walker8b23ca62018-08-22 10:45:41 -07002596 if (fDriverBugWorkarounds.rewrite_do_while_loops) {
2597 shaderCaps->fRewriteDoWhileLoops = true;
2598 }
2599
Adrienne Walker2f4c09b2018-08-22 16:04:57 -07002600 if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
2601 shaderCaps->fRemovePowWithConstantExponent = true;
2602 }
2603
Brian Salomon01b476a2018-01-23 11:06:41 -05002604 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2605 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002606 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2607 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002608 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2609 kIntel_GrGLDriver == ctxInfo.driver() ||
2610 kChromium_GrGLDriver == ctxInfo.driver()) {
2611 fBlendEquationSupport = kBasic_BlendEquationSupport;
2612 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2613 }
2614
2615 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2616 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002617 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002618 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002619 fBlendEquationSupport = kBasic_BlendEquationSupport;
2620 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2621 }
2622
Adrienne Walker68314842018-05-14 14:02:53 -07002623 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2624 fBlendEquationSupport = kBasic_BlendEquationSupport;
2625 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2626 }
2627
Brian Salomon01b476a2018-01-23 11:06:41 -05002628 if (this->advancedBlendEquationSupport()) {
2629 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002630 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002631 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2632 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2633 (1 << kColorBurn_GrBlendEquation);
2634 }
2635 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2636 // Blacklist color-burn on ARM until the fix is released.
2637 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2638 }
2639 }
2640
2641 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2642 if (fMultisampleDisableSupport &&
2643 this->shaderCaps()->dualSourceBlendingSupport() &&
2644 this->shaderCaps()->pathRenderingSupport() &&
2645 fUsesMixedSamples &&
2646#if GR_TEST_UTILS
2647 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2648#endif
2649 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2650 kChromium_GrGLDriver == ctxInfo.driver())) {
2651 fDiscardRenderTargetSupport = false;
2652 fInvalidateFBType = kNone_InvalidateFBType;
2653 }
Brian Osmanc585e202018-04-04 14:08:27 -04002654
Brian Osman061020e2018-04-17 14:22:15 -04002655 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2656 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2657 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2658 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002659 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2660 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002661 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002662 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002663 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2664 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002665 }
Brian Osman2fa53742018-05-03 15:05:12 -04002666
2667#ifdef SK_BUILD_FOR_IOS
2668 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2669 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2670 // is to just blacklist the feature.
2671 // https://github.com/flutter/flutter/issues/16718
2672 // https://bugreport.apple.com/web/?problemID=39948888
2673 fUnpackRowLengthSupport = false;
2674#endif
Chris Daltona2b5b642018-06-24 13:08:57 -06002675
2676#ifdef SK_BUILD_FOR_MAC
2677 // Radeon MacBooks hit a crash in glReadPixels() when using CCPR.
2678 // http://skbug.com/8097
2679 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2680 fBlacklistCoverageCounting = true;
2681 }
2682#endif
Chris Daltonc4e72a42018-06-25 06:44:01 -06002683
2684 // "shapes_mixed_10000_32x33" bench crashes PowerVRGX6250 in Release mode with ccpr.
2685 // http://skbug.com/8098
2686 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2687 fBlacklistCoverageCounting = true;
2688 }
Chris Dalton1c1391c2018-07-20 12:21:14 -06002689
Chris Daltonb70beea2018-07-23 12:17:10 -06002690 // CCPR edge AA is busted on Mesa, Sandy Bridge/Bay Trail.
Chris Dalton1c1391c2018-07-20 12:21:14 -06002691 // http://skbug.com/8162
Chris Daltonb70beea2018-07-23 12:17:10 -06002692 if (kMesa_GrGLDriver == ctxInfo.driver() &&
2693 (kIntelSandyBridge_GrGLRenderer == ctxInfo.renderer() ||
2694 kIntelBayTrail_GrGLRenderer == ctxInfo.renderer())) {
Chris Dalton1c1391c2018-07-20 12:21:14 -06002695 fBlacklistCoverageCounting = true;
2696 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002697}
2698
csmartdaltone0d36292016-07-29 08:14:20 -07002699void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002700 if (options.fDisableDriverCorrectnessWorkarounds) {
2701 SkASSERT(!fDoManualMipmapping);
2702 SkASSERT(!fClearToBoundaryValuesIsBroken);
2703 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2704 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2705 SkASSERT(!fUseDrawToClearColor);
2706 SkASSERT(!fUseDrawToClearStencilClip);
2707 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2708 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2709 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002710 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Osman1348ed02018-09-12 09:08:39 -04002711 SkASSERT(!fDetachStencilFromMSAABuffersBeforeReadPixels);
Brian Salomon01b476a2018-01-23 11:06:41 -05002712 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002713 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2714 fUseDrawToClearColor = false;
2715 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2716 fUseDrawToClearColor = true;
2717 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002718 if (options.fDoManualMipmapping) {
2719 fDoManualMipmapping = true;
2720 }
csmartdaltone0d36292016-07-29 08:14:20 -07002721}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002722
Brian Salomon3d86a192018-02-27 16:46:11 -05002723bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2724 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2725 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2726 if (tex->hasBaseLevelBeenBoundToFBO()) {
2727 return false;
2728 }
2729 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002730 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002731 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2732 return false;
2733 }
2734 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2735 return false;
2736 }
2737 return SkToBool(surface->asTexture());
2738 }
2739 return true;
2740}
2741
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002742bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2743 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2744 // We don't support reading pixels directly from EXTERNAL textures as it would require
2745 // binding the texture to a FBO.
2746 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2747 return false;
2748 }
2749 }
2750 return true;
2751}
2752
2753GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2754 GrColorType dstColorType) const {
2755 // For now, we mostly report the read back format that is required by the ES spec without
2756 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2757 // this as makes sense to increase performance and correctness.
2758 switch (fConfigTable[config].fFormatType) {
2759 case kNormalizedFixedPoint_FormatType:
2760 return GrColorType::kRGBA_8888;
2761 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002762 if ((kAlpha_half_GrPixelConfig == config ||
2763 kAlpha_half_as_Red_GrPixelConfig == config) &&
2764 GrColorType::kAlpha_F16 == dstColorType) {
2765 return GrColorType::kAlpha_F16;
2766 }
2767 // And similar for full float RG.
2768 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2769 return GrColorType::kRG_F32;
2770 }
2771 return GrColorType::kRGBA_F32;
2772 }
2773 return GrColorType::kUnknown;
2774}
2775
Greg Daniel2a303902018-02-20 10:25:54 -05002776bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002777 GrGLFramebufferInfo fbInfo;
2778 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002779 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002780 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002781}
2782
Brian Salomonbdecacf2018-02-02 20:32:49 -05002783int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2784 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002785 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002786 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002787 return 0;
2788 }
2789
Brian Salomonbdecacf2018-02-02 20:32:49 -05002790 if (1 == requestedCount) {
2791 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2792 }
2793
Greg Daniel81e7bf82017-07-19 14:47:42 -04002794 for (int i = 0; i < count; ++i) {
2795 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002796 int count = fConfigTable[config].fColorSampleCounts[i];
2797 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2798 count = SkTMin(count, 4);
2799 }
2800 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002801 }
2802 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002803 return 0;
2804}
2805
2806int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2807 const auto& table = fConfigTable[config].fColorSampleCounts;
2808 if (!table.count()) {
2809 return 0;
2810 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002811 int count = table[table.count() - 1];
2812 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2813 count = SkTMin(count, 4);
2814 }
2815 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002816}
2817
Greg Danielfaa095e2017-12-19 13:15:02 -05002818bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2819 GrGLStandard standard) {
2820 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002821
2822 switch (ct) {
2823 case kUnknown_SkColorType:
2824 return false;
2825 case kAlpha_8_SkColorType:
2826 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002827 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002828 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002829 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002830 }
2831 break;
2832 case kRGB_565_SkColorType:
2833 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002834 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002835 }
2836 break;
2837 case kARGB_4444_SkColorType:
2838 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002839 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002840 }
2841 break;
2842 case kRGBA_8888_SkColorType:
2843 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002844 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002845 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002846 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002847 }
2848 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002849 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002850 if (GR_GL_RGB8 == format) {
2851 *config = kRGB_888_GrPixelConfig;
2852 }
2853 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002854 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002855 if (GR_GL_RGBA8 == format) {
2856 if (kGL_GrGLStandard == standard) {
2857 *config = kBGRA_8888_GrPixelConfig;
2858 }
2859 } else if (GR_GL_BGRA8 == format) {
2860 if (kGLES_GrGLStandard == standard) {
2861 *config = kBGRA_8888_GrPixelConfig;
2862 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002863 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002864 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002865 }
2866 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002867 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002868 if (GR_GL_RGB10_A2 == format) {
2869 *config = kRGBA_1010102_GrPixelConfig;
2870 }
2871 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002872 case kRGB_101010x_SkColorType:
2873 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002874 case kGray_8_SkColorType:
2875 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002876 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002877 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002878 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002879 }
2880 break;
2881 case kRGBA_F16_SkColorType:
2882 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002883 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002884 }
2885 break;
Mike Klein37854712018-06-26 11:43:06 -04002886 case kRGBA_F32_SkColorType:
2887 if (GR_GL_RGBA32F == format) {
2888 *config = kRGBA_float_GrPixelConfig;
2889 }
2890 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002891 }
2892
Greg Danielfaa095e2017-12-19 13:15:02 -05002893 return kUnknown_GrPixelConfig != *config;
2894}
2895
2896bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2897 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002898 GrGLTextureInfo texInfo;
2899 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002900 return false;
2901 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002902 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002903}
2904
2905bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2906 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002907 GrGLFramebufferInfo fbInfo;
2908 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002909 return false;
2910 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002911 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002912}
2913
Robert Phillipsfc711a22018-02-13 17:03:00 -05002914bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2915 GrPixelConfig* config) const {
2916 const GrGLenum* glFormat = format.getGLFormat();
2917 if (!glFormat) {
2918 return false;
2919 }
2920 return validate_sized_format(*glFormat, ct, config, fStandard);
2921}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002922
Timothy Liang036fdfe2018-06-28 15:50:36 -04002923#ifdef GR_TEST_UTILS
2924GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2925 const GrBackendTexture& backendTex) const {
2926 GrGLTextureInfo glInfo;
2927 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2928 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2929}
2930#endif