blob: a731f9407bb0b1e2cdda2a23f92d91afc2d4158c [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00008#include "GrGLCaps.h"
egdanielb7e7d572015-11-04 04:23:53 -08009#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000010#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080011#include "GrGLRenderTarget.h"
Brian Salomon467921e2017-03-06 16:17:12 -050012#include "GrGLTexture.h"
Greg Daniel26dbe3b2018-05-03 10:35:42 -040013#include "GrRenderTargetProxyPriv.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050014#include "GrShaderCaps.h"
Robert Phillipsbf25d432017-04-07 10:08:53 -040015#include "GrSurfaceProxyPriv.h"
Greg Daniel26dbe3b2018-05-03 10:35:42 -040016#include "GrTextureProxyPriv.h"
Brian Osman71a18892017-08-10 10:23:25 -040017#include "SkJSONWriter.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000018#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000019#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000020
bsalomon682c2692015-05-22 14:01:46 -070021GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
22 const GrGLContextInfo& ctxInfo,
23 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080024 fStandard = ctxInfo.standard();
25
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000027 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000028 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000029 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080030 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032 fUnpackRowLengthSupport = false;
33 fUnpackFlipYSupport = false;
34 fPackRowLengthSupport = false;
35 fPackFlipYSupport = false;
36 fTextureUsageSupport = false;
Robert Phillips5ab72762017-06-07 12:04:18 -040037 fAlpha8IsRenderable = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080041 fES2CompatibilitySupport = false;
cdalton06604b92016-02-05 10:09:51 -080042 fDrawIndirectSupport = false;
43 fMultiDrawIndirectSupport = false;
44 fBaseInstanceSupport = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080047 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080048 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070049 fRGBA8888PixelsOpsAreSlow = false;
50 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080051 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080052 fRGBAToBGRAReadbackConversionsAreSlow = false;
Robert Phillipsf2ec0242018-03-01 16:51:25 -050053 fUseBufferDataNullHint = SkToBool(GR_GL_USE_BUFFER_DATA_NULL_HINT);
brianosman09563ce2016-06-02 08:59:34 -070054 fDoManualMipmapping = false;
Eric Karlaeaf22b2017-05-18 15:08:09 -070055 fClearToBoundaryValuesIsBroken = false;
Brian Salomond17b4a62017-05-23 16:53:47 -040056 fClearTextureSupport = false;
Chris Dalton9926f4b2017-05-17 15:15:50 -060057 fDrawArraysBaseVertexIsBroken = false;
Brian Salomon43f8bf02017-10-18 08:33:29 -040058 fUseDrawToClearColor = false;
Mike Klein31550db2017-06-06 23:29:53 +000059 fUseDrawToClearStencilClip = false;
Brian Salomon9bada542017-06-12 12:09:30 -040060 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
61 fUseDrawInsteadOfAllRenderTargetWrites = false;
Brian Salomon6d9c88b2017-06-12 10:24:42 -040062 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
Chris Daltonda40cd22018-04-16 13:19:58 -060063 fRequiresFlushBetweenNonAndInstancedDraws = false;
Brian Osman1348ed02018-09-12 09:08:39 -040064 fDetachStencilFromMSAABuffersBeforeReadPixels = false;
Ethan Nicholas06d55fb2017-11-08 09:48:50 -050065 fProgramBinarySupport = false;
piotaixre4b23142014-10-02 10:57:53 -070066
Brian Salomone5e7eb12016-10-14 16:18:33 -040067 fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
Chris Daltoncc604e52017-10-06 16:27:32 -060068 fMaxInstancesPerDrawArraysWithoutCrashing = 0;
bsalomon083617b2016-02-12 12:10:14 -080069
Brian Salomon94efbf52016-11-29 13:43:05 -050070 fShaderCaps.reset(new GrShaderCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070071
cdalton4cd67132015-06-10 19:23:46 -070072 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073}
74
cdalton4cd67132015-06-10 19:23:46 -070075void GrGLCaps::init(const GrContextOptions& contextOptions,
76 const GrGLContextInfo& ctxInfo,
77 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000078 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079 GrGLVersion version = ctxInfo.version();
80
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000081 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000082 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
83 &fMaxFragmentUniformVectors);
84 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000085 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086 GrGLint max;
87 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
88 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000089 if (version >= GR_GL_VER(3, 2)) {
90 GrGLint profileMask;
91 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
92 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
93 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094 }
Adrienne Walker87785d52018-08-09 12:01:43 -070095 if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
96 fMaxFragmentUniformVectors = SkMin32(fMaxFragmentUniformVectors, 32);
97 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000098 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000100 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 fUnpackRowLengthSupport = true;
102 fUnpackFlipYSupport = false;
103 fPackRowLengthSupport = true;
104 fPackFlipYSupport = false;
105 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000106 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
107 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000109 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
110 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 fPackFlipYSupport =
112 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
113 }
114
Adrienne Walkerc48f7762018-05-15 13:03:13 -0700115 if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
116 // In some cases drivers handle copying the last row incorrectly
117 // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
118 // through every row and conditionally clobbering that value, but
119 // Skia already has a scratch buffer workaround when pack row length
120 // is not supported, so just use that.
121 fPackRowLengthSupport = false;
122 }
123
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000124 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000125 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
126
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000127 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700128 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
129 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
130 ctxInfo.hasExtension("GL_NV_texture_barrier");
131 } else {
132 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
133 }
134
Robert Phillips7f861922018-01-30 13:13:42 +0000135 if (kGL_GrGLStandard == standard) {
136 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
137 ctxInfo.hasExtension("GL_ARB_texture_multisample");
138 } else {
139 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
140 }
141
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000142 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000143 ctxInfo.hasExtension("GL_ARB_imaging");
144
Brian Salomon01b476a2018-01-23 11:06:41 -0500145 if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
egdaniel9250d242015-05-18 13:04:26 -0700146 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
147 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000148 fDiscardRenderTargetSupport = true;
149 fInvalidateFBType = kInvalidate_InvalidateFBType;
150 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
151 fDiscardRenderTargetSupport = true;
152 fInvalidateFBType = kDiscard_InvalidateFBType;
153 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000154
Chris Dalton27059d32018-01-23 14:06:50 -0700155 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
156 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
157 if (kGLES_GrGLStandard == standard) {
158 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
159 // TODO: Evaluate on PowerVR.
160 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
161 if (kARM_GrGLVendor == ctxInfo.vendor()) {
162 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
163 }
164 }
165
Chris Dalton344e9032017-12-11 15:42:09 -0700166 if (kARM_GrGLVendor == ctxInfo.vendor() ||
167 kImagination_GrGLVendor == ctxInfo.vendor() ||
168 kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
169 fPreferFullscreenClears = true;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000170 }
171
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000172 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000173 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800174 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
175 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000176 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000177 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
178 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000179 }
180
cdalton626e1ff2015-06-12 13:56:46 -0700181 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
182 fDebugSupport = true;
183 } else {
184 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
185 }
186
jvanverth3f801cb2014-12-16 09:49:38 -0800187 if (kGL_GrGLStandard == standard) {
188 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
189 }
190 else {
191 fES2CompatibilitySupport = true;
192 }
193
cdalton0edea2c2015-05-21 08:27:44 -0700194 if (kGL_GrGLStandard == standard) {
195 fMultisampleDisableSupport = true;
196 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700197 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700198 }
199
kkinnunend94708e2015-07-30 22:47:04 -0700200 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600201 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
202 // instanced arrays, but we could make this more granular if we wanted
203 fInstanceAttribSupport =
204 version >= GR_GL_VER(3, 2) ||
205 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
206 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
207 } else {
208 fInstanceAttribSupport =
209 version >= GR_GL_VER(3, 0) ||
210 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
211 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
212 }
213
214 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700215 if (version >= GR_GL_VER(3, 0)) {
216 fBindFragDataLocationSupport = true;
217 }
218 } else {
219 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
220 fBindFragDataLocationSupport = true;
221 }
joshualittc1f56b52015-06-22 12:31:31 -0700222 }
223
joshualitt7bdd70a2015-10-01 06:28:11 -0700224 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
225
kkinnunene06ed252016-02-16 23:15:40 -0800226 if (kGL_GrGLStandard == standard) {
Weiliang Chen1e04b362018-07-12 17:13:35 -0400227 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
228 ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
kkinnunene06ed252016-02-16 23:15:40 -0800229 // We also require textureSize() support for rectangle 2D samplers which was added in
230 // GLSL 1.40.
231 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
232 fRectangleTextureSupport = true;
233 }
bsalomone179a912016-01-20 06:18:10 -0800234 }
kkinnunene06ed252016-02-16 23:15:40 -0800235 } else {
236 // Command buffer exposes this in GL ES context for Chromium reasons,
237 // but it should not be used. Also, at the time of writing command buffer
238 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800239 }
240
bsalomoncdee0092016-01-08 13:20:12 -0800241 if (kGL_GrGLStandard == standard) {
242 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
243 fTextureSwizzleSupport = true;
244 }
245 } else {
246 if (version >= GR_GL_VER(3,0)) {
247 fTextureSwizzleSupport = true;
248 }
249 }
250
cblume09bd2c02016-03-01 14:08:28 -0800251 if (kGL_GrGLStandard == standard) {
252 fMipMapLevelAndLodControlSupport = true;
253 } else if (kGLES_GrGLStandard == standard) {
254 if (version >= GR_GL_VER(3,0)) {
255 fMipMapLevelAndLodControlSupport = true;
256 }
257 }
258
bsalomon88c7b982015-07-31 11:20:16 -0700259#ifdef SK_BUILD_FOR_WIN
260 // We're assuming that on Windows Chromium we're using ANGLE.
261 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
262 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700263 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700264 fRGBA8888PixelsOpsAreSlow = isANGLE;
265 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
266 // check DX11 ANGLE.
267 fPartialFBOReadIsSlow = isANGLE;
268#endif
269
ericrkb4ecabd2016-03-11 15:18:20 -0800270 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
271 bool isMAC = false;
272#ifdef SK_BUILD_FOR_MAC
273 isMAC = true;
274#endif
275
276 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
277 // vis-versa.
278 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
279
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500280 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
281 fUseBufferDataNullHint = false;
282 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
283 fUseBufferDataNullHint = true;
284 }
285
Brian Salomond17b4a62017-05-23 16:53:47 -0400286 if (kGL_GrGLStandard == standard) {
287 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400288 fClearTextureSupport = true;
289 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500290 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
291 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400292 }
293
Greg Danielb2acf0a2018-09-12 09:17:11 -0400294#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
295 fSupportsAHardwareBufferImages = true;
296#endif
297
cdalton4cd67132015-06-10 19:23:46 -0700298 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700299 * GrShaderCaps fields
300 **************************************************************************/
301
egdaniel0a482332015-10-26 08:59:10 -0700302 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700303 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500304 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700305
Brian Osman195c05b2017-08-30 15:14:04 -0400306 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
307#if GR_TEST_UTILS
308 if (contextOptions.fSuppressPathRendering) {
309 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700310 }
Brian Osman195c05b2017-08-30 15:14:04 -0400311#endif
egdaniel05ded892015-10-26 07:38:05 -0700312
egdaniel05ded892015-10-26 07:38:05 -0700313 // Enable supported shader-related caps
314 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500315 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700316 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
Brian Salomon23c55b62018-06-19 16:28:41 -0400317 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600318
Brian Salomon1edc5b92016-11-29 13:43:46 -0500319 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600320
egdaniel05ded892015-10-26 07:38:05 -0700321 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500322 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700323 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600324 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600325 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
326 shaderCaps->fGSInvocationsSupport = true;
327 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
328 shaderCaps->fGSInvocationsSupport = true;
329 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
330 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600331 }
332
Brian Salomon1edc5b92016-11-29 13:43:46 -0500333 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800334 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500335 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500336 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700337
Brian Salomon1edc5b92016-11-29 13:43:46 -0500338 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700339 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800340
Chris Dalton1214be92018-06-28 19:06:27 -0600341 // Mali and early Adreno both have support for geometry shaders, but they appear to be
342 // implemented in software. In practice with ccpr, they are slower than the backup impl that
343 // only uses vertex shaders.
344 if (kARM_GrGLVendor != ctxInfo.vendor() &&
345 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
346 kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
347
Chris Daltonfaca00d2018-01-19 15:56:07 -0700348 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
349 shaderCaps->fGeometryShaderSupport = true;
350 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
351 shaderCaps->fGeometryShaderSupport = true;
352 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
353 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700354 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500355 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700356
Brian Salomon1edc5b92016-11-29 13:43:46 -0500357 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800358 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700359 }
360
cdalton9c3f1432016-03-11 10:07:37 -0800361 // Protect ourselves against tracking huge amounts of texture state.
362 static const uint8_t kMaxSaneSamplers = 32;
363 GrGLint maxSamplers;
364 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500365 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
366 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800367 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500368 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800369 }
370 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500371 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800372 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500373 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800374
csmartdalton485a1202016-07-13 10:16:32 -0700375 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
376 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
377 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
378 // limit this decision to specific GPU families rather than basing it on the vendor alone.
379 if (!GR_GL_MUST_USE_VBO &&
380 !fIsCoreProfile &&
381 (kARM_GrGLVendor == ctxInfo.vendor() ||
382 kImagination_GrGLVendor == ctxInfo.vendor() ||
383 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
384 fPreferClientSideDynamicBuffers = true;
385 }
386
Eric Karl5c779752017-05-08 12:02:07 -0700387 if (!contextOptions.fAvoidStencilBuffers) {
388 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
389 this->initFSAASupport(contextOptions, ctxInfo, gli);
390 this->initStencilSupport(ctxInfo);
391 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400392
393 // Setup blit framebuffer
394 if (kGL_GrGLStandard != ctxInfo.standard()) {
395 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
396 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
397 kNoMSAADst_BlitFramebufferFlag |
398 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
399 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
400 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
401 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
402 // limitations.
403 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
404 kResolveMustBeFull_BlitFrambufferFlag |
405 kNoMSAADst_BlitFramebufferFlag |
406 kNoFormatConversion_BlitFramebufferFlag |
407 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
408 }
409 } else {
410 if (fUsesMixedSamples ||
411 ctxInfo.version() >= GR_GL_VER(3,0) ||
412 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
413 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
414 fBlitFramebufferFlags = 0;
415 }
416 }
417
cdalton1dd05422015-06-12 09:01:18 -0700418 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000419
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000420 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000421 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
422 // extension includes glMapBuffer.
423 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
424 fMapBufferFlags |= kSubset_MapFlag;
425 fMapBufferType = kMapBufferRange_MapBufferType;
426 } else {
427 fMapBufferType = kMapBuffer_MapBufferType;
428 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000429 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000430 // Unextended GLES2 doesn't have any buffer mapping.
431 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800432 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800433 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
434 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800435 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
436 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
437 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000438 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
439 fMapBufferFlags = kCanMap_MapFlag;
440 fMapBufferType = kMapBuffer_MapBufferType;
441 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000442 }
443
jvanverthd7a2c1f2015-12-07 07:36:44 -0800444 if (kGL_GrGLStandard == standard) {
445 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
446 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700447 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500448 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400449 if (version >= GR_GL_VER(3, 0) ||
450 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
451 // GL_EXT_unpack_subimage needed to support subtexture rectangles
452 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800453 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400454// TODO: get transfer buffers working in Chrome
455// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
456// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800457 }
458 }
459
joshualitte5b74c62015-06-01 14:17:47 -0700460 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
461 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700462 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700463#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500464 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
465 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
466 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700467 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700468#else
cdalton397536c2016-03-25 12:15:03 -0700469 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700470#endif
joshualitte5b74c62015-06-01 14:17:47 -0700471 }
472
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000473 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000474 fNPOTTextureTileSupport = true;
475 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000476 } else {
477 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000478 // ES3 has no limitations.
479 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
480 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000481 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
482 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
483 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
484 // to alllow arbitrary wrap modes, however.
485 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000486 }
487
bsalomon@google.combcce8922013-03-25 15:38:39 +0000488 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700489
490 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
491 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
492 }
493
bsalomon@google.combcce8922013-03-25 15:38:39 +0000494 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
495 // Our render targets are always created with textures as the color
496 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000497 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700498 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
499
500 if (kARM_GrGLVendor == ctxInfo.vendor()) {
501 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
502 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
503 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000504
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000505 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
506
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000507 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700508 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000509
robertphillips1b8e1b52015-06-24 06:54:10 -0700510#if 0
511 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
512 kQualcomm_GrGLVendor != ctxInfo.vendor();
513#endif
514
csmartdalton9bc11872016-08-09 12:42:47 -0700515 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
516 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700517 }
518
robertphillips63926682015-08-20 09:39:02 -0700519#ifdef SK_BUILD_FOR_WIN
520 // On ANGLE deferring flushes can lead to GPU starvation
521 fPreferVRAMUseOverFlushes = !isANGLE;
522#endif
523
bsalomon7dea7b72015-08-19 08:26:51 -0700524 if (kChromium_GrGLDriver == ctxInfo.driver()) {
525 fMustClearUploadedBufferData = true;
526 }
527
bsalomond08ea5f2015-02-20 06:58:13 -0800528 if (kGL_GrGLStandard == standard) {
529 // ARB allows mixed size FBO attachments, EXT does not.
530 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
531 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
532 fOversizedStencilSupport = true;
533 } else {
534 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
535 }
536 } else {
537 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
538 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
539 }
540
joshualitt58001552015-06-26 12:46:36 -0700541 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700542 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
543 ctxInfo.hasExtension("GL_ARB_draw_indirect");
544 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
545 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700546 (fDrawIndirectSupport &&
547 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700548 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700549 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800550 } else {
551 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700552 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
553 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
554 fBaseInstanceSupport = fDrawIndirectSupport &&
555 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700556 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800557 }
558
ethannicholas28ef4452016-03-25 09:26:03 -0700559 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500560 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700561 fSampleShadingSupport = true;
562 }
563 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
564 fSampleShadingSupport = true;
565 }
566
jvanverth84741b32016-09-30 08:39:02 -0700567 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
568 if (kGL_GrGLStandard == standard) {
569 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
570 fFenceSyncSupport = true;
571 }
Brian Osman93a23462017-06-21 15:13:39 -0400572 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700573 fFenceSyncSupport = true;
574 }
575
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400576 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500577 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500578
Brian Osman499bf1a2018-09-17 11:32:42 -0400579 // Half float vertex attributes requires GL3 or ES3
580 // It can also work with OES_VERTEX_HALF_FLOAT, but that requires a different enum.
581 if (kGL_GrGLStandard == standard) {
582 if (version >= GR_GL_VER(3, 0)) {
583 fHalfFloatVertexAttributeSupport = true;
584 }
585 } else if (version >= GR_GL_VER(3, 0)) {
586 fHalfFloatVertexAttributeSupport = true;
587 }
588
Brian Salomonf7232642018-09-19 08:58:08 -0400589 fDynamicStateArrayGeometryProcessorTextureSupport = true;
590
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400591 if (kGL_GrGLStandard == standard) {
592 if (version >= GR_GL_VER(4, 1)) {
593 fProgramBinarySupport = true;
594 }
595 } else if (version >= GR_GL_VER(3, 0)) {
596 fProgramBinarySupport = true;
597 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400598 if (fProgramBinarySupport) {
599 GrGLint count;
Ethan Nicholasad77dce2018-07-11 13:59:03 -0400600 GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400601 fProgramBinarySupport = count > 0;
602 }
bsalomoncdee0092016-01-08 13:20:12 -0800603 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
604 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800605 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700606
Brian Salomon01b476a2018-01-23 11:06:41 -0500607 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
608 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
609 }
610
cdalton4cd67132015-06-10 19:23:46 -0700611 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500612 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700613
Brian Salomon01b476a2018-01-23 11:06:41 -0500614 // For now these two are equivalent but we could have dst read in shader via some other method.
615 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000616}
617
egdaniel472d44e2015-10-22 08:20:00 -0700618const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
619 bool isCoreProfile) {
620 switch (generation) {
621 case k110_GrGLSLGeneration:
622 if (kGLES_GrGLStandard == standard) {
623 // ES2s shader language is based on version 1.20 but is version
624 // 1.00 of the ES language.
625 return "#version 100\n";
626 } else {
627 SkASSERT(kGL_GrGLStandard == standard);
628 return "#version 110\n";
629 }
630 case k130_GrGLSLGeneration:
631 SkASSERT(kGL_GrGLStandard == standard);
632 return "#version 130\n";
633 case k140_GrGLSLGeneration:
634 SkASSERT(kGL_GrGLStandard == standard);
635 return "#version 140\n";
636 case k150_GrGLSLGeneration:
637 SkASSERT(kGL_GrGLStandard == standard);
638 if (isCoreProfile) {
639 return "#version 150\n";
640 } else {
641 return "#version 150 compatibility\n";
642 }
643 case k330_GrGLSLGeneration:
644 if (kGLES_GrGLStandard == standard) {
645 return "#version 300 es\n";
646 } else {
647 SkASSERT(kGL_GrGLStandard == standard);
648 if (isCoreProfile) {
649 return "#version 330\n";
650 } else {
651 return "#version 330 compatibility\n";
652 }
653 }
cdalton33ad7012016-02-22 07:55:44 -0800654 case k400_GrGLSLGeneration:
655 SkASSERT(kGL_GrGLStandard == standard);
656 if (isCoreProfile) {
657 return "#version 400\n";
658 } else {
659 return "#version 400 compatibility\n";
660 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500661 case k420_GrGLSLGeneration:
662 SkASSERT(kGL_GrGLStandard == standard);
663 if (isCoreProfile) {
664 return "#version 420\n";
665 }
666 else {
667 return "#version 420 compatibility\n";
668 }
egdaniel472d44e2015-10-22 08:20:00 -0700669 case k310es_GrGLSLGeneration:
670 SkASSERT(kGLES_GrGLStandard == standard);
671 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800672 case k320es_GrGLSLGeneration:
673 SkASSERT(kGLES_GrGLStandard == standard);
674 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700675 }
676 return "<no version>";
677}
678
Chris Dalton47c8ed32017-11-15 18:27:09 -0700679bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
680 if (kGLES_GrGLStandard != ctxInfo.standard() &&
681 ctxInfo.version() < GR_GL_VER(4,1) &&
682 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
683 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
684 return true;
685 }
686 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
687 // geometry shaders don't have lower precision than vertex and fragment.
688 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
689 GrGLint range[2];
690 GrGLint bits;
691 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
692 if (range[0] < 127 || range[1] < 127 || bits < 23) {
693 return false;
694 }
695 }
696 return true;
697}
698
699void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700700 GrGLStandard standard = ctxInfo.standard();
701 GrGLVersion version = ctxInfo.version();
702
703 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500704 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700705 **************************************************************************/
706
Brian Salomon1edc5b92016-11-29 13:43:46 -0500707 GrShaderCaps* shaderCaps = fShaderCaps.get();
708 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700709 if (kGLES_GrGLStandard == standard) {
710 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500711 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
712 shaderCaps->fFBFetchSupport = true;
713 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
714 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700715 }
716 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
717 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
Brian Salomon1edc5b92016-11-29 13:43:46 -0500718 shaderCaps->fFBFetchNeedsCustomOutput = false;
719 shaderCaps->fFBFetchSupport = true;
720 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
721 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700722 }
723 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
724 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500725 shaderCaps->fFBFetchNeedsCustomOutput = false;
726 shaderCaps->fFBFetchSupport = true;
727 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
728 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700729 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500730 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700731 }
732
cdaltonc08f1962016-02-12 12:14:06 -0800733 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500734 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800735 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500736 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800737 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
738 }
Brian Salomon41274562017-09-15 09:40:03 -0700739 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
740 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
741 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800742 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500743 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800744 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
745 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400746 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
747 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500748 shaderCaps->fNoPerspectiveInterpolationSupport = true;
749 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800750 "GL_NV_shader_noperspective_interpolation";
751 }
752 }
753
Brian Salomon1edc5b92016-11-29 13:43:46 -0500754 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
755 shaderCaps->fGLSLGeneration,
756 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800757
Brian Salomon1edc5b92016-11-29 13:43:46 -0500758 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
759 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800760 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800761
762 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500763 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800764 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
765 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500766 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800767 }
768
769 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500770 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800771 }
772
cdalton9c3f1432016-03-11 10:07:37 -0800773 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400774 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
775 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400776 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400777 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
778 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
779 // At least one driver has been found that has this extension without the "GL_" prefix.
780 shaderCaps->fExternalTextureSupport = true;
781 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800782 }
783 }
784
cdaltonc04ce672016-03-11 14:07:38 -0800785 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600786 shaderCaps->fVertexIDSupport = true;
787 } else {
788 // Desktop GLSL 3.30 == ES GLSL 3.00.
789 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
790 }
791
Chris Dalton7c7ff032018-03-28 20:09:58 -0600792 if (kGL_GrGLStandard == standard) {
793 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
794 } else {
795 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
796 }
797
Chris Dalton47c8ed32017-11-15 18:27:09 -0700798 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
799 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400800
801 // Unsigned integers only supported in and after GLSL 1.30.
802 shaderCaps->fUnsignedSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel472d44e2015-10-22 08:20:00 -0700803}
804
kkinnunencfe62e32015-07-01 02:58:50 -0700805bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700806 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
807
808 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700809 return false;
810 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700811
kkinnunencfe62e32015-07-01 02:58:50 -0700812 if (kGL_GrGLStandard == ctxInfo.standard()) {
813 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
814 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
815 return false;
816 }
817 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700818 if (!hasChromiumPathRendering &&
819 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700820 return false;
821 }
822 }
823 // We only support v1.3+ of GL_NV_path_rendering which allows us to
824 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
825 // additions are detected by checking the existence of the function.
826 // We also use *Then* functions that not all drivers might have. Check
827 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800828 if (!gli->fFunctions.fStencilThenCoverFillPath ||
829 !gli->fFunctions.fStencilThenCoverStrokePath ||
830 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
831 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
832 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700833 return false;
834 }
835 return true;
836}
bsalomon1aa20292016-01-22 08:16:09 -0800837
Brian Salomon71d9d842016-11-03 13:42:00 -0400838bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800839 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800840 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800841 std::function<bool ()> bindRenderTarget,
842 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400843 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800844 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400845 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800846 return false;
847 }
bsalomon7928ef62016-01-05 10:26:39 -0800848
bsalomon76148af2016-01-12 11:13:47 -0800849 GrGLenum readFormat;
850 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400851 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800852 return false;
853 }
854
bsalomon1aa20292016-01-22 08:16:09 -0800855 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800856 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
857 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
858 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
859 // 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 -0500860 // The manual does not seem to fully match the spec as the spec allows integer formats
861 // when the bound color buffer is an integer buffer. It doesn't specify which integer
862 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500863 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
864 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
865 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800866 return false;
867 }
868 // There is also a set of allowed types, but all the types we use are in the set:
869 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
870 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
871 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
872 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
873 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
874 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
875 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800876 return true;
piotaixre4b23142014-10-02 10:57:53 -0700877 }
bsalomon7928ef62016-01-05 10:26:39 -0800878
bsalomon76148af2016-01-12 11:13:47 -0800879 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500880 switch (fConfigTable[surfaceConfig].fFormatType) {
881 case kNormalizedFixedPoint_FormatType:
882 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
883 return true;
884 }
885 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500886 case kFloat_FormatType:
887 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
888 return true;
889 }
890 break;
bsalomon7928ef62016-01-05 10:26:39 -0800891 }
892
Brian Salomon71d9d842016-11-03 13:42:00 -0400893 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800894 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400895 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800896 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800897 if (!bindRenderTarget()) {
898 return false;
899 }
900 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
901 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800902 rpFormat->fFormat = format;
903 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800904 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800905 }
906
Brian Salomon71d9d842016-11-03 13:42:00 -0400907 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
908 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700909}
910
Eric Karl5c779752017-05-08 12:02:07 -0700911void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
912 const GrGLInterface* gli) {
913 // We need dual source blending and the ability to disable multisample in order to support mixed
914 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
915 // renderer is available and enabled; no other path renderers support this feature.
916 if (fMultisampleDisableSupport &&
917 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400918 this->shaderCaps()->pathRenderingSupport()
919#if GR_TEST_UTILS
920 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
921#endif
922 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700923 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400924 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700925 }
926
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000927 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400928 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
929 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
930 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
931 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
932 fAlpha8IsRenderable = true;
933 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500934 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
935 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
936 // mixed samples we can't use multisampled-render-to-texture.
937 if (fUsesMixedSamples) {
938 fMSFBOType = kMixedSamples_MSFBOType;
939 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000940 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
941 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
942 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400943 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
944 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400945 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400946 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400947 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400948 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000949 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
950 fMSFBOType = kES_Apple_MSFBOType;
951 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000952 } else {
egdanieleed519e2016-01-15 11:36:18 -0800953 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700954 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400955 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
956 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400957
Brian Salomon00731b42016-10-14 11:30:51 -0400958 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400959 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
960 // Core profile removes ALPHA8 support.
961 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
962 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
963 // present.
964 fAlpha8IsRenderable = true;
965 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000966 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
967 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400968 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000969 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000970 }
Eric Karl5c779752017-05-08 12:02:07 -0700971
Brian Salomon01b476a2018-01-23 11:06:41 -0500972 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400973 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
974 fMSFBOType = kNone_MSFBOType;
975 }
976
Eric Karl5c779752017-05-08 12:02:07 -0700977 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
978 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
979 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700980 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000981}
982
cdalton1dd05422015-06-12 09:01:18 -0700983void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500984 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700985
Greg Daniel210883c2017-11-27 15:14:01 -0500986 bool layoutQualifierSupport = false;
987 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
988 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
989 layoutQualifierSupport = true;
990 }
991
cdalton1dd05422015-06-12 09:01:18 -0700992 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
993 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500994 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -0500995 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
996 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -0700997 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500998 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -0700999 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1000 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001001 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001002 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001003 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001004 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001005 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1006 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -07001007 }
cdalton1dd05422015-06-12 09:01:18 -07001008}
1009
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001010namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001011const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001012}
1013
Eric Karl5c779752017-05-08 12:02:07 -07001014void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001015
1016 // Build up list of legal stencil formats (though perhaps not supported on
1017 // the particular gpu/driver) from most preferred to least.
1018
1019 // these consts are in order of most preferred to least preferred
1020 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1021
1022 static const StencilFormat
1023 // internal Format stencil bits total bits packed?
1024 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1025 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1026 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1027 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001028 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001029 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1030
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001031 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001032 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001033 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001034 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1035 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1036
1037 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1038 // require FBO support we can expect these are legal formats and don't
1039 // check. These also all support the unsized GL_STENCIL_INDEX.
1040 fStencilFormats.push_back() = gS8;
1041 fStencilFormats.push_back() = gS16;
1042 if (supportsPackedDS) {
1043 fStencilFormats.push_back() = gD24S8;
1044 }
1045 fStencilFormats.push_back() = gS4;
1046 if (supportsPackedDS) {
1047 fStencilFormats.push_back() = gDS;
1048 }
1049 } else {
1050 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1051 // for other formats.
1052 // ES doesn't support using the unsized format.
1053
1054 fStencilFormats.push_back() = gS8;
1055 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001056 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1057 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001058 fStencilFormats.push_back() = gD24S8;
1059 }
1060 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1061 fStencilFormats.push_back() = gS4;
1062 }
1063 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001064}
1065
Brian Osman71a18892017-08-10 10:23:25 -04001066void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001067
Brian Osman71a18892017-08-10 10:23:25 -04001068 // We are called by the base class, which has already called beginObject(). We choose to nest
1069 // all of our caps information in a named sub-object.
1070 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001071
Brian Osman71a18892017-08-10 10:23:25 -04001072 writer->beginArray("Stencil Formats");
1073
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001074 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001075 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001076 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1077 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1078 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001079 }
1080
Brian Osman71a18892017-08-10 10:23:25 -04001081 writer->endArray();
1082
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001083 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001084 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001085 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001086 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001087 "IMG MS To Texture",
1088 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001089 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001090 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001091 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001092 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1093 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1094 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1095 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1096 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001097 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001098
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001099 static const char* kInvalidateFBTypeStr[] = {
1100 "None",
1101 "Discard",
1102 "Invalidate",
1103 };
1104 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1105 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1106 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1107 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001108
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001109 static const char* kMapBufferTypeStr[] = {
1110 "None",
1111 "MapBuffer",
1112 "MapBufferRange",
1113 "Chromium",
1114 };
1115 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1116 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1117 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1118 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1119 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1120
Brian Osman71a18892017-08-10 10:23:25 -04001121 writer->appendBool("Core Profile", fIsCoreProfile);
1122 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1123 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1124 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1125 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1126 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1127 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1128 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1129 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001130
Brian Osman71a18892017-08-10 10:23:25 -04001131 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001132 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1133 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1134 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001135 writer->appendBool("Debug support", fDebugSupport);
1136 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1137 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1138 writer->appendBool("Base instance support", fBaseInstanceSupport);
1139 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1140 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1141 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1142 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1143 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1144 writer->appendBool("BGRA to RGBA readback conversions are slow",
1145 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001146 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001147 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1148 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001149 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1150 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1151 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1152 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001153 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1154 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001155
Brian Osman71a18892017-08-10 10:23:25 -04001156 writer->beginArray("configs");
1157
bsalomon41e4384e2016-01-08 09:12:44 -08001158 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001159 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001160 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1161 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1162 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001163 writer->appendHexU32("e_format_read_pixels",
1164 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001165 writer->appendHexU32(
1166 "e_format_teximage",
1167 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1168 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1169 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1170 writer->appendHexU32("i_for_renderbuffer",
1171 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1172 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001173 }
1174
Brian Osman71a18892017-08-10 10:23:25 -04001175 writer->endArray();
1176 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001177}
1178
bsalomon41e4384e2016-01-08 09:12:44 -08001179bool GrGLCaps::bgraIsInternalFormat() const {
1180 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1181}
1182
bsalomon76148af2016-01-12 11:13:47 -08001183bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1184 GrGLenum* internalFormat, GrGLenum* externalFormat,
1185 GrGLenum* externalType) const {
1186 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1187 externalFormat, externalType)) {
1188 return false;
1189 }
1190 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1191 return true;
1192}
1193
bsalomon76148af2016-01-12 11:13:47 -08001194bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1195 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001196 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001197 externalFormat, externalType)) {
1198 return false;
1199 }
1200 return true;
1201}
1202
Brian Salomon93348dd2018-08-29 12:56:23 -04001203void GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001204 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
Brian Salomon93348dd2018-08-29 12:56:23 -04001205}
1206
1207void GrGLCaps::getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1208 *internalFormat = fConfigTable[config].fFormats.fSizedInternalFormat;
bsalomon76148af2016-01-12 11:13:47 -08001209}
1210
1211bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1212 ExternalFormatUsage usage, GrGLenum* externalFormat,
1213 GrGLenum* externalType) const {
1214 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001215
1216 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1217 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1218
1219 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001220 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1221 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001222 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1223 return false;
1224 }
1225
1226 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1227 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1228
bsalomone9573312016-01-25 14:33:25 -08001229 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1230 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1231 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1232 // texture, not the red component.
1233 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001234 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001235 *externalFormat = GR_GL_ALPHA;
1236 }
1237 }
1238
bsalomon76148af2016-01-12 11:13:47 -08001239 return true;
1240}
1241
brianosman20471892016-12-02 06:43:32 -08001242void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1243 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001244 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001245 /*
1246 Comments on renderability of configs on various GL versions.
1247 OpenGL < 3.0:
1248 no built in support for render targets.
1249 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1250 format RGB, RGBA and NV float formats we don't use.
1251 This is the following:
1252 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1253 RGB10_A2, RGBA12,RGBA16
1254 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1255 since they aren't required by later standards and the driver can simply return
1256 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1257 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1258 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1259 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1260 This adds a lot of additional renderable sized formats, including ALPHA8.
1261 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1262 16F, 32I, 32UI, and 32F variants).
1263 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1264
1265 For both the above extensions we limit ourselves to those that are also required by
1266 OpenGL 3.0.
1267
1268 OpenGL 3.0:
1269 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1270 but are not required to be supported as renderable textures/renderbuffer.
1271 Required renderable color formats:
1272 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1273 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1274 RGB10_A2.
1275 - R11F_G11F_B10F.
1276 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1277 and RG8UI.
1278 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1279 - ALPHA8
1280
1281 OpenGL 3.1, 3.2, 3.3
1282 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1283 OpengGL 3.3, 4.0, 4.1
1284 Adds RGB10_A2UI.
1285 OpengGL 4.2
1286 Adds
1287 - RGB5_A1, RGBA4
1288 - RGB565
1289 OpenGL 4.4
1290 Does away with the separate list and adds a column to the sized internal color format
1291 table. However, no new formats become required color renderable.
1292
1293 ES 2.0
1294 color renderable: RGBA4, RGB5_A1, RGB565
1295 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1296 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1297 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1298 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1299 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1300 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1301
1302 ES 3.0
1303 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1304 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1305 RGB5_A1.
1306 - RGB8 and RGB565.
1307 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1308 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1309 ES 3.1
1310 Adds RGB10_A2, RGB10_A2UI,
1311 ES 3.2
1312 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1313 */
Brian Salomon44804c02018-01-23 16:51:28 -05001314
1315 // Correctness workarounds.
1316 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001317 bool disableSRGBForX86PowerVR = false;
1318 bool disableSRGBWriteControlForAdreno4xx = false;
1319 bool disableR8TexStorageForANGLEGL = false;
1320 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001321 bool disableRGB8ForMali400 = false;
Greg Daniel09c94002018-06-08 22:11:51 +00001322 bool disableGrayLumFBOForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001323
1324 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1325 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1326 // and GL_RG on FBO textures.
1327 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1328
Greg Daniel09c94002018-06-08 22:11:51 +00001329 disableGrayLumFBOForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1330
Brian Salomon44804c02018-01-23 16:51:28 -05001331 bool isX86PowerVR = false;
1332#if defined(SK_CPU_X86)
1333 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1334 isX86PowerVR = true;
1335 }
1336#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001337 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1338 // blacklist that device (and any others that might be sharing the same driver).
1339 disableSRGBForX86PowerVR = isX86PowerVR;
Chris Dalton1214be92018-06-28 19:06:27 -06001340 disableSRGBWriteControlForAdreno4xx =
1341 (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
1342 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer());
Brian Salomon44804c02018-01-23 16:51:28 -05001343
1344 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1345 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1346 // check that we are not going to OpenGL.
1347 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1348
1349 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1350#if defined(SK_BUILD_FOR_MAC)
1351 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1352#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001353 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1354 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001355 }
1356
Brian Salomon71d9d842016-11-03 13:42:00 -04001357 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1358 ConfigInfo::kFBOColorAttachment_Flag;
1359 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001360 if (kNone_MSFBOType != fMSFBOType) {
1361 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1362 }
bsalomon41e4384e2016-01-08 09:12:44 -08001363 GrGLStandard standard = ctxInfo.standard();
1364 GrGLVersion version = ctxInfo.version();
1365
cblume790d5132016-02-29 11:13:29 -08001366 bool texStorageSupported = false;
1367 if (kGL_GrGLStandard == standard) {
1368 // The EXT version can apply to either GL or GLES.
1369 texStorageSupported = version >= GR_GL_VER(4,2) ||
1370 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1371 ctxInfo.hasExtension("GL_EXT_texture_storage");
1372 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001373 texStorageSupported = version >= GR_GL_VER(3,0) ||
1374 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001375 }
Adrienne Walker70e468f2018-08-22 16:05:27 -07001376 if (fDriverBugWorkarounds.disable_texture_storage) {
1377 texStorageSupported = false;
1378 }
cblume790d5132016-02-29 11:13:29 -08001379
Brian Salomone609e812018-01-17 14:00:47 -05001380 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001381
1382 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001383 if (kGL_GrGLStandard == standard) {
1384 textureRedSupport =
1385 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1386 } else {
1387 textureRedSupport =
1388 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1389 }
1390 }
1391
bsalomon30447372015-12-21 09:03:05 -08001392 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1393 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001394 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001395 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001396 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001397 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001398
1399 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1400 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001401 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001402 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001403 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001404 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001405 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1406 if (kGL_GrGLStandard == standard) {
1407 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1408 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001409 } else {
Kevin Lubick217056c2018-09-20 17:39:31 -04001410 bool isWebGL = false;
1411 // hack for skbug:8378
1412 #if IS_WEBGL==1
1413 isWebGL = true;
1414 #endif
1415 if (isWebGL || version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon41e4384e2016-01-08 09:12:44 -08001416 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1417 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1418 }
egdaniel4999df82016-01-07 17:06:04 -08001419 }
cblume790d5132016-02-29 11:13:29 -08001420 if (texStorageSupported) {
1421 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1422 }
bsalomoncdee0092016-01-08 13:20:12 -08001423 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001424
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001425 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1426 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1427 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1428 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1429 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1430 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1431 // supportedReadPixelsColorType never returns it.
1432 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1433 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1434 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1435 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1436 if (kGL_GrGLStandard == standard) {
1437 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1438 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1439 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1440 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1441 // becomes an issue.
1442 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1443 // but we don't support that just for simplicity's sake.
1444 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1445 } else {
1446 // 3.0 and the extension support this as a render buffer format.
1447 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1448 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1449 }
1450 }
1451 if (texStorageSupported) {
1452 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1453 }
1454 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1455 if (disableRGB8ForMali400) {
1456 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1457 }
1458
1459 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001460 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001461 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001462 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001463
1464 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1465 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1466 // GL_EXT_texture_format_BGRA8888.
1467 bool supportsBGRATexStorage = false;
1468
bsalomon41e4384e2016-01-08 09:12:44 -08001469 if (kGL_GrGLStandard == standard) {
1470 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1471 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1472 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1473 // Since the internal format is RGBA8, it is also renderable.
1474 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1475 allRenderFlags;
1476 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001477 // Since we are using RGBA8 we can use tex storage.
1478 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001479 } else {
1480 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1481 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001482 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1483 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1484 nonMSAARenderFlags;
1485
1486 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1487 supportsBGRATexStorage = true;
1488 }
1489 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1490 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1491 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1492 ConfigInfo::kRenderableWithMSAA_Flag;
1493 }
1494 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001495 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1496 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1497 // driver remembers the external format when the texture is created (with TexImage).
1498 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1499 // We could work around this, but it adds even more state tracking to code that is
1500 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1501 // This also side-steps some ambiguous interactions with the texture storage extension.
1502 if (version >= GR_GL_VER(3,0)) {
1503 // The APPLE extension doesn't make this renderable.
1504 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001505 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001506 }
bsalomon41e4384e2016-01-08 09:12:44 -08001507 }
1508 }
Brian Osman48c99192017-06-02 08:45:06 -04001509
Greg Daniel0ff79b22018-02-15 12:33:33 -05001510 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001511 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001512 }
bsalomoncdee0092016-01-08 13:20:12 -08001513 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001514
Brian Osman2b23c4b2018-06-01 12:25:08 -04001515 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001516 if (kGL_GrGLStandard == standard) {
1517 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001518 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001519 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1520 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1521 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001522 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001523 }
1524 }
1525 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001526 if (fSRGBSupport) {
1527 fSRGBWriteControl = true;
1528 }
bsalomon41e4384e2016-01-08 09:12:44 -08001529 } else {
brianosman20471892016-12-02 06:43:32 -08001530 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001531 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001532 fSRGBSupport = false;
1533 }
bsalomon41e4384e2016-01-08 09:12:44 -08001534 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1535 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001536 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001537 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001538 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001539 }
brianosman20471892016-12-02 06:43:32 -08001540
1541 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1542 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1543 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1544 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1545 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1546 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1547 // affects Windows.
1548 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1549 fSRGBSupport = false;
1550 }
1551
Brian Osman48c99192017-06-02 08:45:06 -04001552 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1553 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1554 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1555
Brian Osman67999392017-05-31 16:19:34 -04001556 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001557 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001558 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1559 }
Brian Osman67999392017-05-31 16:19:34 -04001560
bsalomon30447372015-12-21 09:03:05 -08001561 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1562 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1563 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1564 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001565 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001566 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001567 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001568 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001569 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001570 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001571 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001572 }
Brian Osman48c99192017-06-02 08:45:06 -04001573 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1574 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001575 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1576 }
bsalomoncdee0092016-01-08 13:20:12 -08001577 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001578 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1579 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1580 // is in this format, for example).
1581 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1582 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1583 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1584 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001585 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001586 GR_GL_BGRA;
1587 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1588 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001589 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001590 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001591 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001592 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001593
brianosmana6359362016-03-21 06:55:37 -07001594 if (texStorageSupported) {
1595 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1596 }
1597 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1598
bsalomon30447372015-12-21 09:03:05 -08001599 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1600 if (this->ES2CompatibilitySupport()) {
1601 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1602 } else {
1603 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1604 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001605 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001606 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001607 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001608 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001609 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1610 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001611 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001612 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1613 }
1614 } else {
1615 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1616 }
cblume790d5132016-02-29 11:13:29 -08001617 // 565 is not a sized internal format on desktop GL. So on desktop with
1618 // 565 we always use an unsized internal format to let the system pick
1619 // the best sized format to convert the 565 data to. Since TexStorage
1620 // only allows sized internal formats we disallow it.
1621 //
1622 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1623 // update.
1624 if (texStorageSupported && kGL_GrGLStandard != standard) {
1625 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1626 }
bsalomoncdee0092016-01-08 13:20:12 -08001627 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001628
1629 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1630 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001631 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001632 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001633 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001634 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001635 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1636 if (kGL_GrGLStandard == standard) {
1637 if (version >= GR_GL_VER(4, 2)) {
1638 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1639 }
1640 } else {
1641 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1642 }
cblume790d5132016-02-29 11:13:29 -08001643 if (texStorageSupported) {
1644 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1645 }
bsalomoncdee0092016-01-08 13:20:12 -08001646 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001647
Brian Osman10fc6fd2018-03-02 11:01:10 -05001648 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1649 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001650 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001651 GR_GL_RGBA;
1652 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1653 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1654 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1655 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1656 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1657 allRenderFlags;
1658 }
1659 if (texStorageSupported) {
1660 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1661 }
Brian Osman10fc6fd2018-03-02 11:01:10 -05001662 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1663
Greg Danielef59d872017-11-17 16:47:21 -05001664 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1665 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1666
1667 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1668 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1669 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1670 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1671 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001672 }
Greg Danielef59d872017-11-17 16:47:21 -05001673 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1674 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001675 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001676 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1677 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1678 alphaInfo.fFlags |= allRenderFlags;
1679 }
1680
1681 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1682 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1683 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1684 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1685 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001686 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001687 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001688
Brian Osman48c99192017-06-02 08:45:06 -04001689 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1690 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001691 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001692 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1693 }
1694 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1695 }
1696
Brian Salomone609e812018-01-17 14:00:47 -05001697 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001698 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
Greg Danielef59d872017-11-17 16:47:21 -05001699 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1700 } else {
1701 redInfo.fFlags = 0;
1702
1703 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001704 }
bsalomon41e4384e2016-01-08 09:12:44 -08001705
Greg Daniel7af060a2017-12-05 16:27:11 -05001706 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1707 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1708 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1709 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1710 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001711 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001712 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1713 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1714 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1715 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001716 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001717
1718 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1719 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1720 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1721 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1722 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001723 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001724 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1725 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1726
Greg Daniel09c94002018-06-08 22:11:51 +00001727 // Leaving Gray8 as non-renderable, to keep things simple and match raster. However, we do
1728 // enable the FBOColorAttachment_Flag so that we can bind it to an FBO for copies.
1729 grayRedInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
1730 if (kStandard_MSFBOType == this->msFBOType() && kGL_GrGLStandard == standard &&
1731 !disableGrayLumFBOForMesa) {
Brian Osman986563b2017-01-10 14:20:02 -05001732 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1733 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1734 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
Greg Daniel09c94002018-06-08 22:11:51 +00001735 grayLumInfo.fFlags |= ConfigInfo::kFBOColorAttachment_Flag;;
Brian Osman986563b2017-01-10 14:20:02 -05001736 }
Brian Osman48c99192017-06-02 08:45:06 -04001737 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001738 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001739 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1740 }
1741 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1742 }
1743
Brian Salomone609e812018-01-17 14:00:47 -05001744 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001745 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1746 } else {
1747 grayRedInfo.fFlags = 0;
1748 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001749 }
1750
bsalomon41e4384e2016-01-08 09:12:44 -08001751 // Check for [half] floating point texture support
1752 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1753 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1754 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
Chris Daltoneff01a72018-07-19 17:06:39 -06001755 bool hasFP32Textures = false;
1756 bool hasFP16Textures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001757 bool rgIsTexturable = false;
Chris Daltoneff01a72018-07-19 17:06:39 -06001758 bool hasFP32RenderTargets = false;
Brian Salomon75975512018-10-02 12:21:38 -04001759 enum class HalfFPRenderTargetSupport { kNone, kRGBAOnly, kAll };
1760 HalfFPRenderTargetSupport halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kNone;
bsalomon41e4384e2016-01-08 09:12:44 -08001761 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001762 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001763
1764 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001765 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001766 hasFP32Textures = true;
1767 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001768 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001769 hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001770 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
bsalomon41e4384e2016-01-08 09:12:44 -08001771 }
1772 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001773 if (version >= GR_GL_VER(3, 0)) {
Chris Daltoneff01a72018-07-19 17:06:39 -06001774 hasFP32Textures = true;
1775 hasFP16Textures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001776 rgIsTexturable = true;
Chris Daltoneff01a72018-07-19 17:06:39 -06001777 } else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1778 ctxInfo.hasExtension("GL_OES_texture_float")) {
1779 hasFP32Textures = true;
1780 hasFP16Textures = true;
1781 } else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1782 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1783 hasFP16Textures = true;
1784 }
1785
1786 if (version >= GR_GL_VER(3, 2)) {
1787 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to solve
1788 // many precision issues and no clients actually want this yet.
1789 // hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001790 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
Chris Daltoneff01a72018-07-19 17:06:39 -06001791 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
1792 // For now we only enable rendering to fp32 on desktop, because on ES we'd have to
1793 // solve many precision issues and no clients actually want this yet.
1794 // hasFP32RenderTargets = true;
Brian Salomon75975512018-10-02 12:21:38 -04001795 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
Chris Daltoneff01a72018-07-19 17:06:39 -06001796 } else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
Brian Salomon75975512018-10-02 12:21:38 -04001797 // This extension only enables half float support rendering for RGBA.
1798 halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kRGBAOnly;
bsalomon41e4384e2016-01-08 09:12:44 -08001799 }
1800 }
bsalomon30447372015-12-21 09:03:05 -08001801
csmartdalton6aa0e112017-02-08 16:14:11 -05001802 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1803 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1804 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1805 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1806 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001807 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001808 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1809 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001810 if (hasFP32Textures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001811 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
Chris Daltoneff01a72018-07-19 17:06:39 -06001812 if (hasFP32RenderTargets) {
csmartdalton6aa0e112017-02-08 16:14:11 -05001813 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1814 }
bsalomon41e4384e2016-01-08 09:12:44 -08001815 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001816 if (texStorageSupported) {
1817 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1818 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001819 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001820 }
bsalomon30447372015-12-21 09:03:05 -08001821
Greg Danielef59d872017-11-17 16:47:21 -05001822 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001823 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001824 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001825 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001826 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001827 }
Greg Danielef59d872017-11-17 16:47:21 -05001828 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1829 redHalf.fFormats.fExternalType = redHalfExternalType;
1830 redHalf.fFormatType = kFloat_FormatType;
1831 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1832 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001833 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001834 redHalf.fSwizzle = GrSwizzle::RRRR();
Chris Daltoneff01a72018-07-19 17:06:39 -06001835 if (textureRedSupport && hasFP16Textures) {
Greg Danielef59d872017-11-17 16:47:21 -05001836 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1837
Brian Salomon75975512018-10-02 12:21:38 -04001838 if (halfFPRenderTargetSupport == HalfFPRenderTargetSupport::kAll) {
Greg Danielef59d872017-11-17 16:47:21 -05001839 redHalf.fFlags |= fpRenderFlags;
1840 }
1841
1842 if (texStorageSupported && !isCommandBufferES2) {
1843 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1844 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001845 }
Greg Danielef59d872017-11-17 16:47:21 -05001846 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001847
1848 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1849 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001850 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001851 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001852 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001853 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1854 } else {
1855 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1856 }
bsalomon7928ef62016-01-05 10:26:39 -08001857 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
Chris Daltoneff01a72018-07-19 17:06:39 -06001858 if (hasFP16Textures) {
bsalomon41e4384e2016-01-08 09:12:44 -08001859 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1860 // ES requires 3.2 or EXT_color_buffer_half_float.
Brian Salomon75975512018-10-02 12:21:38 -04001861 if (halfFPRenderTargetSupport != HalfFPRenderTargetSupport::kNone) {
bsalomon41e4384e2016-01-08 09:12:44 -08001862 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1863 }
1864 }
cblume790d5132016-02-29 11:13:29 -08001865 if (texStorageSupported) {
1866 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1867 }
bsalomoncdee0092016-01-08 13:20:12 -08001868 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001869
bsalomon30447372015-12-21 09:03:05 -08001870 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1871
1872 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001873 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1874 ctxInfo.version() >= GR_GL_VER(3,0));
1875 // All ES versions (thus far) require sized internal formats for render buffers.
1876 // TODO: Always use sized internal format?
1877 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1878
bsalomon30447372015-12-21 09:03:05 -08001879 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001880 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1881 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001882 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001883 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001884 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1885 fConfigTable[i].fFormats.fSizedInternalFormat :
1886 fConfigTable[i].fFormats.fBaseInternalFormat;
1887 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001888 fConfigTable[i].fFormats.fSizedInternalFormat :
1889 fConfigTable[i].fFormats.fBaseInternalFormat;
1890 }
Brian Salomon44804c02018-01-23 16:51:28 -05001891 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1892 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1893 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1894 // in ES.
1895 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1896 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1897 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1898 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001899 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1900 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001901 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1902 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001903 }
1904
bsalomon30447372015-12-21 09:03:05 -08001905 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1906 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1907 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1908 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1909 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001910 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001911 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001912
1913 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1914 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1915 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1916 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001917 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001918 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1919 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1920 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1921 // slot.
1922 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1923 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001924
1925 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1926 // as a base format.
1927 // GL_EXT_texture_format_BGRA8888:
1928 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1929 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1930 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001931 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001932 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1933 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1934 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001935 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001936 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1937 }
1938
bsalomoncdee0092016-01-08 13:20:12 -08001939 // If we don't have texture swizzle support then the shader generator must insert the
1940 // swizzle into shader code.
1941 if (!this->textureSwizzleSupport()) {
1942 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001943 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001944 }
1945 }
1946
bsalomon7f9b2e42016-01-12 13:29:26 -08001947 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1948 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1949 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001950 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001951 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1952 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1953 if (GrPixelConfigIsAlphaOnly(config) &&
1954 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001955 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001956 }
1957 }
1958 }
1959
Greg Daniel81e7bf82017-07-19 14:47:42 -04001960 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1961 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001962 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1963 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001964 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001965 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1966 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001967 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001968 int count;
1969 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1970 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1971 1, &count);
1972 if (count) {
1973 int* temp = new int[count];
1974 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1975 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001976 // GL has a concept of MSAA rasterization with a single sample but we do not.
1977 if (count && temp[count - 1] == 1) {
1978 --count;
1979 SkASSERT(!count || temp[count -1] > 1);
1980 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001981 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001982 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04001983 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001984 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04001985 for (int j = 0; j < count; ++j) {
1986 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
1987 }
1988 delete[] temp;
1989 }
1990 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05001991 // Fake out the table using some semi-standard counts up to the max allowed sample
1992 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05001993 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05001994 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1995 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
1996 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1997 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
1998 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05001999 // Chrome has a mock GL implementation that returns 0.
2000 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05002001
Brian Salomonbdecacf2018-02-02 20:32:49 -05002002 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04002003 int count = SK_ARRAY_COUNT(kDefaultSamples);
2004 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002005 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002006 break;
2007 }
2008 }
2009 if (count > 0) {
2010 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
2011 }
2012 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002013 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
2014 fConfigTable[i].fColorSampleCounts.setCount(1);
2015 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002016 }
2017 }
2018
bsalomon30447372015-12-21 09:03:05 -08002019#ifdef SK_DEBUG
2020 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002021 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002022 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002023 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2024 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002025 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2026 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2027 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2028 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002029 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2030 fConfigTable[i].fFormats.fBaseInternalFormat);
2031 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002032 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002033 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2034 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2035 fConfigTable[i].fFormats.fExternalFormat[j]);
2036 }
2037 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002038 }
2039#endif
2040}
2041
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002042bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2043 bool dstIsTextureable, bool dstIsGLTexture2D,
2044 GrSurfaceOrigin dstOrigin,
2045 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2046 bool srcIsTextureable, bool srcIsGLTexture2D,
2047 GrSurfaceOrigin srcOrigin) const {
2048 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2049 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2050 // many drivers would allow it to work, but ANGLE does not.
2051 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2052 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2053 return false;
2054 }
2055
2056 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2057 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2058 return false;
2059 }
2060
2061 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2062 // texture.
2063 if (!dstIsTextureable) {
2064 return false;
2065 }
2066
2067 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2068 // is required
2069 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2070 (!srcIsTextureable || srcIsGLTexture2D) &&
2071 dstIsGLTexture2D &&
2072 dstOrigin == srcOrigin) {
2073 return true;
2074 } else {
2075 return false;
2076 }
2077}
2078
2079bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2080 bool dstIsTextureable, bool dstIsGLTexture2D,
2081 GrSurfaceOrigin dstOrigin,
2082 GrPixelConfig srcConfig, int srcSampleCnt,
2083 bool srcIsTextureable, bool srcIsGLTexture2D,
2084 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2085 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2086 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2087 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2088 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2089 return false;
2090 }
2091
2092 if (dstIsTextureable && !dstIsGLTexture2D) {
2093 return false;
2094 }
2095 if (srcIsTextureable && !srcIsGLTexture2D) {
2096 return false;
2097 }
2098
2099 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2100 return false;
2101 }
2102 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2103 // We would mirror to compensate for origin changes. Note that copySurface is
2104 // specified such that the src and dst rects are the same.
2105 if (dstOrigin != srcOrigin) {
2106 return false;
2107 }
2108 }
2109
2110 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2111 if (srcSampleCnt > 1) {
2112 if (1 == dstSampleCnt) {
2113 return false;
2114 }
2115 if (SkRect::Make(srcRect) != srcBounds) {
2116 return false;
2117 }
2118 }
2119 }
2120
2121 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2122 if (dstSampleCnt > 1) {
2123 return false;
2124 }
2125 }
2126
2127 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2128 if (dstConfig != srcConfig) {
2129 return false;
2130 }
2131 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2132 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2133 return false;
2134 }
2135 }
2136
2137 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2138 if (srcSampleCnt > 1) {
2139 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2140 return false;
2141 }
2142 if (dstOrigin != srcOrigin) {
2143 return false;
2144 }
2145 }
2146 }
2147 return true;
2148}
2149
2150bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2151 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2152}
2153
2154static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2155 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2156 if (!rt) {
2157 return false;
2158 }
2159 // A RT has a separate MSAA renderbuffer if:
2160 // 1) It's multisampled
2161 // 2) We're using an extension with separate MSAA renderbuffers
2162 // 3) It's not FBO 0, which is special and always auto-resolves
2163 return rt->numColorSamples() > 1 &&
2164 glCaps.usesMSAARenderBuffers() &&
2165 !rt->rtPriv().glRTFBOIDIs0();
2166}
2167
2168bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2169 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2170 GrSurfaceOrigin dstOrigin = dst->origin();
2171 GrSurfaceOrigin srcOrigin = src->origin();
2172
2173 GrPixelConfig dstConfig = dst->config();
2174 GrPixelConfig srcConfig = src->config();
2175
2176 int dstSampleCnt = 0;
2177 int srcSampleCnt = 0;
2178 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2179 dstSampleCnt = rtProxy->numColorSamples();
2180 }
2181 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2182 srcSampleCnt = rtProxy->numColorSamples();
2183 }
2184 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2185 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2186
2187 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2188 // swizzle.
2189 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2190 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2191 return false;
2192 }
2193
2194 const GrTextureProxy* dstTex = dst->asTextureProxy();
2195 const GrTextureProxy* srcTex = src->asTextureProxy();
2196
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002197 bool dstIsTex2D = dstTex ? (dstTex->textureType() == GrTextureType::k2D) : false;
2198 bool srcIsTex2D = srcTex ? (srcTex->textureType() == GrTextureType::k2D) : false;
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002199
2200 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2201 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2202 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2203 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2204 // know we will at least be able to do it as a draw.
2205#ifdef SK_DEBUG
2206 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2207 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2208 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2209 !src->priv().isExact()) {
2210 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2211 }
2212#endif
2213
2214 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2215 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2216 srcConfig, has_msaa_render_buffer(src, *this),
2217 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2218 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2219 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2220 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2221 dstPoint) ||
2222 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2223}
2224
Robert Phillipsbf25d432017-04-07 10:08:53 -04002225bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002226 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2227 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002228 // By default, we don't require rects to match.
2229 *rectsMustMatch = false;
2230
2231 // By default, we allow subrects.
2232 *disallowSubrect = false;
2233
Brian Salomon467921e2017-03-06 16:17:12 -05002234 // If the src is a texture, we can implement the blit as a draw assuming the config is
2235 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002236 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002237 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002238 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2239 desc->fConfig = src->config();
2240 return true;
2241 }
2242
Robert Phillipsbf25d432017-04-07 10:08:53 -04002243 {
2244 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2245 // wrapped. In that case the proxy would already be instantiated.
Brian Salomonfd98c2c2018-07-31 17:25:29 -04002246 const GrTexture* srcTexture = src->peekTexture();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002247 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2248 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2249 // Not supported for FBO blit or CopyTexSubImage
2250 return false;
2251 }
Brian Salomon467921e2017-03-06 16:17:12 -05002252 }
2253
2254 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2255 // possible and we return false to fallback to creating a render target dst for render-to-
2256 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2257 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002258 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002259 bool rectsMustMatchForBlitFramebuffer = false;
2260 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002261 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002262 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2263 rectsMustMatchForBlitFramebuffer = true;
2264 disallowSubrectForBlitFramebuffer = true;
2265 // Mirroring causes rects to mismatch later, don't allow it.
2266 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002267 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2268 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002269 rectsMustMatchForBlitFramebuffer = true;
2270 // Mirroring causes rects to mismatch later, don't allow it.
2271 originForBlitFramebuffer = src->origin();
2272 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002273 originForBlitFramebuffer = src->origin();
2274 }
2275
2276 // Check for format issues with glCopyTexSubImage2D
2277 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2278 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2279 // then we set up for that, otherwise fail.
2280 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002281 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002282 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002283 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2284 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002285 return true;
2286 }
2287 return false;
2288 }
2289
Robert Phillipsbf25d432017-04-07 10:08:53 -04002290 {
Brian Salomon63e79732017-05-15 21:23:13 -04002291 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2292 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002293 if (srcIsMSAARenderbuffer) {
2294 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2295 // blit or fail.
2296 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002297 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002298 desc->fConfig = src->config();
2299 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2300 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2301 return true;
2302 }
2303 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002304 }
Brian Salomon467921e2017-03-06 16:17:12 -05002305 }
2306
2307 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002308 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002309 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002310 desc->fFlags = kNone_GrSurfaceFlags;
2311 return true;
2312}
2313
Greg Daniel691f5e72018-02-28 14:21:34 -05002314void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2315 const GrContextOptions& contextOptions,
2316 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002317 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2318 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Chris Dalton1214be92018-06-28 19:06:27 -06002319 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2320 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Adrienne Walker0e383942018-05-15 11:33:47 -07002321 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002322 fDiscardRenderTargetSupport = false;
2323 fInvalidateFBType = kNone_InvalidateFBType;
2324 }
2325
2326 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2327 // 340.96 and 367.57.
2328 if (kGL_GrGLStandard == ctxInfo.standard() &&
2329 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002330 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002331 fClearTextureSupport = false;
2332 }
2333
2334 // Calling glClearTexImage crashes on the NexusPlayer.
2335 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2336 fClearTextureSupport = false;
2337 }
2338
Brian Salomon01b476a2018-01-23 11:06:41 -05002339#ifdef SK_BUILD_FOR_MAC
Chris Dalton6989ba42018-10-03 10:34:09 -06002340 // Radeon MacBooks hit a crash in glReadPixels() when using geometry shaders.
2341 // http://skbug.com/8097
2342 if (kATI_GrGLVendor == ctxInfo.vendor()) {
2343 shaderCaps->fGeometryShaderSupport = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002344 }
Chris Dalton6989ba42018-10-03 10:34:09 -06002345 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2346 shaderCaps->fGSInvocationsSupport = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002347#endif
2348
2349 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2350 // shaders. @127.0 is the earliest verified driver to not crash.
2351 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002352 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002353 shaderCaps->fGeometryShaderSupport = false;
2354 }
2355
2356#if defined(__has_feature)
2357#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2358 // See skbug.com/7058
2359 fMapBufferType = kNone_MapBufferType;
2360 fMapBufferFlags = kNone_MapFlags;
2361#endif
2362#endif
2363
2364 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2365 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2366 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2367 // unclear whether this really affects a wide range of devices.
2368 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002369 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002370 fMapBufferType = kNone_MapBufferType;
2371 fMapBufferFlags = kNone_MapFlags;
2372 }
2373
2374 // TODO: re-enable for ANGLE
2375 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2376 fTransferBufferType = kNone_TransferBufferType;
2377 }
2378
2379 // Using MIPs on this GPU seems to be a source of trouble.
2380 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2381 fMipMapSupport = false;
2382 }
2383
2384 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2385 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2386 // around a driver bug related to gl_FragCoord.
2387 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2388 fMaxClipAnalyticFPs = 0;
2389 }
2390
2391#ifndef SK_BUILD_FOR_IOS
2392 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2393 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2394 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2395 ctxInfo.driver() != kChromium_GrGLDriver)) {
2396 fUseDrawToClearColor = true;
2397 }
2398#endif
2399
2400 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2401 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2402 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2403 fUseDrawToClearColor = true;
2404 }
2405
2406#ifdef SK_BUILD_FOR_MAC
2407 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2408 // full screen clears
2409 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2410 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002411 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2412 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2413 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2414 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002415 fUseDrawToClearColor = true;
2416 }
2417#endif
2418
2419 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2420 // bugs seems to involve clearing too much and not skipping the clear.
2421 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2422 // but only for D3D11 ANGLE.
2423 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2424 fUseDrawToClearColor = true;
2425 }
2426
Chris Dalton1214be92018-06-28 19:06:27 -06002427 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2428 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002429 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002430 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002431 fUseDrawToClearStencilClip = true;
2432 }
2433 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2434 }
2435
Adrienne Walker94f585e2018-05-15 11:47:07 -07002436 if (fDriverBugWorkarounds.gl_clear_broken) {
2437 fUseDrawToClearColor = true;
2438 fUseDrawToClearStencilClip = true;
2439 }
2440
Brian Salomon01b476a2018-01-23 11:06:41 -05002441 // This was reproduced on the following configurations:
2442 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2443 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2444 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2445 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2446 // and not produced on:
2447 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2448 // The particular lines that get dropped from test images varies across different devices.
2449 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002450 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002451 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2452 }
2453
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002454 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2455 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2456 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002457 fRequiresFlushBetweenNonAndInstancedDraws = true;
2458 }
2459
Brian Osman1348ed02018-09-12 09:08:39 -04002460 // This was reproduced on a Pixel 1, but the unit test + config + options that exercise it are
2461 // only tested on very specific bots. The driver claims that ReadPixels is an invalid operation
2462 // when reading from an auto-resolving MSAA framebuffer that has stencil attached.
2463 if (kQualcomm_GrGLDriver == ctxInfo.driver()) {
2464 fDetachStencilFromMSAABuffersBeforeReadPixels = true;
2465 }
2466
Brian Salomon01b476a2018-01-23 11:06:41 -05002467 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2468 // given 1 << 15 or more instances.
2469 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2470 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
Adrienne Walker001cae02018-05-15 11:38:44 -07002471 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
2472 fMaxInstancesPerDrawArraysWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002473 }
2474
2475 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002476 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002477 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2478 fUseDrawInsteadOfAllRenderTargetWrites = true;
2479 }
2480
2481 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2482 fSampleShadingSupport = false;
2483 }
2484
2485#ifdef SK_BUILD_FOR_MAC
2486 static constexpr bool isMAC = true;
2487#else
2488 static constexpr bool isMAC = false;
2489#endif
2490
2491 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2492 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2493 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2494 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2495 if (fMipMapLevelAndLodControlSupport &&
2496 (contextOptions.fDoManualMipmapping ||
2497 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2498 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2499 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2500 fDoManualMipmapping = true;
2501 }
2502
2503 // See http://crbug.com/710443
2504#ifdef SK_BUILD_FOR_MAC
2505 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2506 fClearToBoundaryValuesIsBroken = true;
2507 }
2508#endif
2509 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2510 fDrawArraysBaseVertexIsBroken = true;
2511 }
2512
Brian Salomon01b476a2018-01-23 11:06:41 -05002513 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2514 // Galaxy S7.
2515 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2516 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2517 shaderCaps->fFBFetchSupport = false;
2518 }
2519
Brian Salomon01b476a2018-01-23 11:06:41 -05002520 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2521 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2522
2523 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2524 // function that may require a gradient calculation inside a conditional block may return
2525 // undefined results". This appears to be an issue with the 'any' call since even the simple
2526 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2527 // from our GrTextureDomain processor.
2528 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2529
2530 // Known issue on at least some Intel platforms:
2531 // http://code.google.com/p/skia/issues/detail?id=946
2532 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2533 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2534 }
2535
Chris Dalton0090ef62018-03-28 17:35:00 -06002536 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002537 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2538 // so we must do the abs first in a separate expression.
2539 shaderCaps->fCanUseMinAndAbsTogether = false;
2540
2541 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2542 // must avoid this condition.
2543 shaderCaps->fCanUseFractForNegativeValues = false;
2544 }
2545
2546 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2547 // thus must us -1.0 * %s.x to work correctly
2548 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2549 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2550 }
2551
2552 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2553 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2554 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2555 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2556 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2557 }
2558
2559 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2560 // the original dst color when reading the outColor even after being written to. By using a
2561 // local outColor we can work around this bug.
2562 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2563 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2564 }
2565
2566 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2567 // color, and that uniform contains an opaque color, and the output of the shader is only based
2568 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2569 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2570 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2571 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2572 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2573 shaderCaps->fMustObfuscateUniformColor = true;
2574 }
2575#ifdef SK_BUILD_FOR_WIN
2576 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2577 //
2578 // Basically, if a shader has a construct like:
2579 //
2580 // float x = someCondition ? someValue : 0;
2581 // float2 result = (0 == x) ? float2(x, x)
2582 // : float2(2 * x / x, 0);
2583 //
2584 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2585 // we've explicitly guarded the division with a check against zero. This manifests in much
2586 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2587 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2588 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2589 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2590 }
2591#endif
2592
2593 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
Brian Salomon9b4bd592018-07-10 09:23:40 -04002594 // (rare) situations. It's sporadic, and mostly on older drivers.
Brian Salomon01b476a2018-01-23 11:06:41 -05002595 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2596 shaderCaps->fCanUseFragCoord = false;
Brian Salomon01b476a2018-01-23 11:06:41 -05002597 }
2598
Chris Dalton0090ef62018-03-28 17:35:00 -06002599 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2600 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2601 shaderCaps->fCanUseFragCoord = false;
2602 }
2603
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002604 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2605 // (Are they implemented with fp16?)
2606 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2607 shaderCaps->fIncompleteShortIntPrecision = true;
2608 }
2609
Adrienne Walkeree8295c2018-08-21 10:56:30 -07002610 if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
2611 shaderCaps->fAddAndTrueToLoopCondition = true;
2612 }
2613
Adrienne Walkerc02165f2018-08-21 11:08:11 -07002614 if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
2615 shaderCaps->fUnfoldShortCircuitAsTernary = true;
2616 }
2617
Adrienne Walker92b161f2018-08-22 10:41:52 -07002618 if (fDriverBugWorkarounds.emulate_abs_int_function) {
2619 shaderCaps->fEmulateAbsIntFunction = true;
2620 }
2621
Adrienne Walker8b23ca62018-08-22 10:45:41 -07002622 if (fDriverBugWorkarounds.rewrite_do_while_loops) {
2623 shaderCaps->fRewriteDoWhileLoops = true;
2624 }
2625
Adrienne Walker2f4c09b2018-08-22 16:04:57 -07002626 if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
2627 shaderCaps->fRemovePowWithConstantExponent = true;
2628 }
2629
Brian Salomon01b476a2018-01-23 11:06:41 -05002630 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2631 // for now until its own blacklists can be updated.
Chris Dalton1214be92018-06-28 19:06:27 -06002632 if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
2633 kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon01b476a2018-01-23 11:06:41 -05002634 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2635 kIntel_GrGLDriver == ctxInfo.driver() ||
2636 kChromium_GrGLDriver == ctxInfo.driver()) {
2637 fBlendEquationSupport = kBasic_BlendEquationSupport;
2638 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2639 }
2640
2641 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2642 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002643 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002644 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002645 fBlendEquationSupport = kBasic_BlendEquationSupport;
2646 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2647 }
2648
Adrienne Walker68314842018-05-14 14:02:53 -07002649 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2650 fBlendEquationSupport = kBasic_BlendEquationSupport;
2651 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2652 }
2653
Brian Salomon01b476a2018-01-23 11:06:41 -05002654 if (this->advancedBlendEquationSupport()) {
2655 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002656 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002657 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2658 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2659 (1 << kColorBurn_GrBlendEquation);
2660 }
2661 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2662 // Blacklist color-burn on ARM until the fix is released.
2663 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2664 }
2665 }
2666
2667 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2668 if (fMultisampleDisableSupport &&
2669 this->shaderCaps()->dualSourceBlendingSupport() &&
2670 this->shaderCaps()->pathRenderingSupport() &&
2671 fUsesMixedSamples &&
2672#if GR_TEST_UTILS
2673 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2674#endif
2675 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2676 kChromium_GrGLDriver == ctxInfo.driver())) {
2677 fDiscardRenderTargetSupport = false;
2678 fInvalidateFBType = kNone_InvalidateFBType;
2679 }
Brian Osmanc585e202018-04-04 14:08:27 -04002680
Brian Osman061020e2018-04-17 14:22:15 -04002681 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2682 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2683 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2684 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002685 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2686 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002687 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002688 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002689 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2690 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002691 }
Brian Osman2fa53742018-05-03 15:05:12 -04002692
2693#ifdef SK_BUILD_FOR_IOS
2694 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2695 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2696 // is to just blacklist the feature.
2697 // https://github.com/flutter/flutter/issues/16718
2698 // https://bugreport.apple.com/web/?problemID=39948888
2699 fUnpackRowLengthSupport = false;
2700#endif
Chris Daltona2b5b642018-06-24 13:08:57 -06002701
Chris Daltonc4e72a42018-06-25 06:44:01 -06002702 // "shapes_mixed_10000_32x33" bench crashes PowerVRGX6250 in Release mode with ccpr.
2703 // http://skbug.com/8098
2704 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2705 fBlacklistCoverageCounting = true;
2706 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002707}
2708
csmartdaltone0d36292016-07-29 08:14:20 -07002709void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002710 if (options.fDisableDriverCorrectnessWorkarounds) {
2711 SkASSERT(!fDoManualMipmapping);
2712 SkASSERT(!fClearToBoundaryValuesIsBroken);
2713 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2714 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2715 SkASSERT(!fUseDrawToClearColor);
2716 SkASSERT(!fUseDrawToClearStencilClip);
2717 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2718 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2719 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002720 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Osman1348ed02018-09-12 09:08:39 -04002721 SkASSERT(!fDetachStencilFromMSAABuffersBeforeReadPixels);
Brian Salomon01b476a2018-01-23 11:06:41 -05002722 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002723 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2724 fUseDrawToClearColor = false;
2725 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2726 fUseDrawToClearColor = true;
2727 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002728 if (options.fDoManualMipmapping) {
2729 fDoManualMipmapping = true;
2730 }
csmartdaltone0d36292016-07-29 08:14:20 -07002731}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002732
Brian Salomon3d86a192018-02-27 16:46:11 -05002733bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2734 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2735 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2736 if (tex->hasBaseLevelBeenBoundToFBO()) {
2737 return false;
2738 }
2739 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002740 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002741 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2742 return false;
2743 }
2744 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2745 return false;
2746 }
2747 return SkToBool(surface->asTexture());
2748 }
2749 return true;
2750}
2751
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002752bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2753 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2754 // We don't support reading pixels directly from EXTERNAL textures as it would require
2755 // binding the texture to a FBO.
2756 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2757 return false;
2758 }
2759 }
2760 return true;
2761}
2762
2763GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2764 GrColorType dstColorType) const {
2765 // For now, we mostly report the read back format that is required by the ES spec without
2766 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2767 // this as makes sense to increase performance and correctness.
2768 switch (fConfigTable[config].fFormatType) {
2769 case kNormalizedFixedPoint_FormatType:
2770 return GrColorType::kRGBA_8888;
2771 case kFloat_FormatType:
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002772 if ((kAlpha_half_GrPixelConfig == config ||
2773 kAlpha_half_as_Red_GrPixelConfig == config) &&
2774 GrColorType::kAlpha_F16 == dstColorType) {
2775 return GrColorType::kAlpha_F16;
2776 }
2777 // And similar for full float RG.
2778 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2779 return GrColorType::kRG_F32;
2780 }
2781 return GrColorType::kRGBA_F32;
2782 }
2783 return GrColorType::kUnknown;
2784}
2785
Greg Daniel2a303902018-02-20 10:25:54 -05002786bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002787 GrGLFramebufferInfo fbInfo;
2788 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002789 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002790 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002791}
2792
Brian Salomonbdecacf2018-02-02 20:32:49 -05002793int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2794 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002795 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002796 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002797 return 0;
2798 }
2799
Brian Salomonbdecacf2018-02-02 20:32:49 -05002800 if (1 == requestedCount) {
2801 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2802 }
2803
Greg Daniel81e7bf82017-07-19 14:47:42 -04002804 for (int i = 0; i < count; ++i) {
2805 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002806 int count = fConfigTable[config].fColorSampleCounts[i];
2807 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2808 count = SkTMin(count, 4);
2809 }
2810 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002811 }
2812 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002813 return 0;
2814}
2815
2816int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2817 const auto& table = fConfigTable[config].fColorSampleCounts;
2818 if (!table.count()) {
2819 return 0;
2820 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002821 int count = table[table.count() - 1];
2822 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2823 count = SkTMin(count, 4);
2824 }
2825 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002826}
2827
Greg Danielfaa095e2017-12-19 13:15:02 -05002828bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2829 GrGLStandard standard) {
2830 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002831
2832 switch (ct) {
2833 case kUnknown_SkColorType:
2834 return false;
2835 case kAlpha_8_SkColorType:
2836 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002837 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002838 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002839 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002840 }
2841 break;
2842 case kRGB_565_SkColorType:
2843 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002844 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002845 }
2846 break;
2847 case kARGB_4444_SkColorType:
2848 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002849 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002850 }
2851 break;
2852 case kRGBA_8888_SkColorType:
2853 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002854 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002855 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002856 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002857 }
2858 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002859 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002860 if (GR_GL_RGB8 == format) {
2861 *config = kRGB_888_GrPixelConfig;
2862 }
2863 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002864 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002865 if (GR_GL_RGBA8 == format) {
2866 if (kGL_GrGLStandard == standard) {
2867 *config = kBGRA_8888_GrPixelConfig;
2868 }
2869 } else if (GR_GL_BGRA8 == format) {
2870 if (kGLES_GrGLStandard == standard) {
2871 *config = kBGRA_8888_GrPixelConfig;
2872 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002873 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002874 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002875 }
2876 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002877 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002878 if (GR_GL_RGB10_A2 == format) {
2879 *config = kRGBA_1010102_GrPixelConfig;
2880 }
2881 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002882 case kRGB_101010x_SkColorType:
2883 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002884 case kGray_8_SkColorType:
2885 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002886 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002887 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002888 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002889 }
2890 break;
2891 case kRGBA_F16_SkColorType:
2892 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002893 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002894 }
2895 break;
Mike Klein37854712018-06-26 11:43:06 -04002896 case kRGBA_F32_SkColorType:
2897 if (GR_GL_RGBA32F == format) {
2898 *config = kRGBA_float_GrPixelConfig;
2899 }
2900 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002901 }
2902
Greg Danielfaa095e2017-12-19 13:15:02 -05002903 return kUnknown_GrPixelConfig != *config;
2904}
2905
2906bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2907 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002908 GrGLTextureInfo texInfo;
2909 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002910 return false;
2911 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002912 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002913}
2914
2915bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2916 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002917 GrGLFramebufferInfo fbInfo;
2918 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002919 return false;
2920 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002921 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002922}
2923
Robert Phillipsfc711a22018-02-13 17:03:00 -05002924bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2925 GrPixelConfig* config) const {
2926 const GrGLenum* glFormat = format.getGLFormat();
2927 if (!glFormat) {
2928 return false;
2929 }
2930 return validate_sized_format(*glFormat, ct, config, fStandard);
2931}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002932
Timothy Liang036fdfe2018-06-28 15:50:36 -04002933#ifdef GR_TEST_UTILS
2934GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
2935 const GrBackendTexture& backendTex) const {
2936 GrGLTextureInfo glInfo;
2937 SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
2938 return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
2939}
2940#endif