blob: 43f285e941dad04cbd6eecba430d7485b85519d5 [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;
brianosman851c2382016-12-07 10:03:25 -080055 fSRGBDecodeDisableAffectsMipmaps = false;
Eric Karlaeaf22b2017-05-18 15:08:09 -070056 fClearToBoundaryValuesIsBroken = false;
Brian Salomond17b4a62017-05-23 16:53:47 -040057 fClearTextureSupport = false;
Chris Dalton9926f4b2017-05-17 15:15:50 -060058 fDrawArraysBaseVertexIsBroken = false;
Brian Salomon43f8bf02017-10-18 08:33:29 -040059 fUseDrawToClearColor = false;
Mike Klein31550db2017-06-06 23:29:53 +000060 fUseDrawToClearStencilClip = false;
Brian Salomon9bada542017-06-12 12:09:30 -040061 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
62 fUseDrawInsteadOfAllRenderTargetWrites = false;
Brian Salomon6d9c88b2017-06-12 10:24:42 -040063 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
Chris Daltonda40cd22018-04-16 13:19:58 -060064 fRequiresFlushBetweenNonAndInstancedDraws = 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 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000095 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000097 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 fUnpackRowLengthSupport = true;
99 fUnpackFlipYSupport = false;
100 fPackRowLengthSupport = true;
101 fPackFlipYSupport = false;
102 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000103 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
104 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000105 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000106 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
107 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 fPackFlipYSupport =
109 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
110 }
111
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000112 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000113 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
114
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000115 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700116 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
117 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
118 ctxInfo.hasExtension("GL_NV_texture_barrier");
119 } else {
120 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
121 }
122
Robert Phillips7f861922018-01-30 13:13:42 +0000123 if (kGL_GrGLStandard == standard) {
124 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
125 ctxInfo.hasExtension("GL_ARB_texture_multisample");
126 } else {
127 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
128 }
129
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000130 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000131 ctxInfo.hasExtension("GL_ARB_imaging");
132
Brian Salomon01b476a2018-01-23 11:06:41 -0500133 if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
egdaniel9250d242015-05-18 13:04:26 -0700134 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
135 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000136 fDiscardRenderTargetSupport = true;
137 fInvalidateFBType = kInvalidate_InvalidateFBType;
138 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
139 fDiscardRenderTargetSupport = true;
140 fInvalidateFBType = kDiscard_InvalidateFBType;
141 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000142
Chris Dalton27059d32018-01-23 14:06:50 -0700143 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
144 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
145 if (kGLES_GrGLStandard == standard) {
146 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
147 // TODO: Evaluate on PowerVR.
148 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
149 if (kARM_GrGLVendor == ctxInfo.vendor()) {
150 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
151 }
152 }
153
Chris Dalton344e9032017-12-11 15:42:09 -0700154 if (kARM_GrGLVendor == ctxInfo.vendor() ||
155 kImagination_GrGLVendor == ctxInfo.vendor() ||
156 kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
157 fPreferFullscreenClears = true;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000158 }
159
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000160 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000161 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800162 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
163 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000164 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000165 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
166 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000167 }
168
cdalton626e1ff2015-06-12 13:56:46 -0700169 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
170 fDebugSupport = true;
171 } else {
172 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
173 }
174
jvanverth3f801cb2014-12-16 09:49:38 -0800175 if (kGL_GrGLStandard == standard) {
176 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
177 }
178 else {
179 fES2CompatibilitySupport = true;
180 }
181
cdalton0edea2c2015-05-21 08:27:44 -0700182 if (kGL_GrGLStandard == standard) {
183 fMultisampleDisableSupport = true;
184 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700185 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700186 }
187
kkinnunend94708e2015-07-30 22:47:04 -0700188 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600189 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
190 // instanced arrays, but we could make this more granular if we wanted
191 fInstanceAttribSupport =
192 version >= GR_GL_VER(3, 2) ||
193 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
194 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
195 } else {
196 fInstanceAttribSupport =
197 version >= GR_GL_VER(3, 0) ||
198 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
199 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
200 }
201
202 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700203 if (version >= GR_GL_VER(3, 0)) {
204 fBindFragDataLocationSupport = true;
205 }
206 } else {
207 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
208 fBindFragDataLocationSupport = true;
209 }
joshualittc1f56b52015-06-22 12:31:31 -0700210 }
211
joshualitt7bdd70a2015-10-01 06:28:11 -0700212 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
213
kkinnunene06ed252016-02-16 23:15:40 -0800214 if (kGL_GrGLStandard == standard) {
215 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
216 // We also require textureSize() support for rectangle 2D samplers which was added in
217 // GLSL 1.40.
218 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
219 fRectangleTextureSupport = true;
220 }
bsalomone179a912016-01-20 06:18:10 -0800221 }
kkinnunene06ed252016-02-16 23:15:40 -0800222 } else {
223 // Command buffer exposes this in GL ES context for Chromium reasons,
224 // but it should not be used. Also, at the time of writing command buffer
225 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800226 }
227
bsalomoncdee0092016-01-08 13:20:12 -0800228 if (kGL_GrGLStandard == standard) {
229 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
230 fTextureSwizzleSupport = true;
231 }
232 } else {
233 if (version >= GR_GL_VER(3,0)) {
234 fTextureSwizzleSupport = true;
235 }
236 }
237
cblume09bd2c02016-03-01 14:08:28 -0800238 if (kGL_GrGLStandard == standard) {
239 fMipMapLevelAndLodControlSupport = true;
240 } else if (kGLES_GrGLStandard == standard) {
241 if (version >= GR_GL_VER(3,0)) {
242 fMipMapLevelAndLodControlSupport = true;
243 }
244 }
245
bsalomon88c7b982015-07-31 11:20:16 -0700246#ifdef SK_BUILD_FOR_WIN
247 // We're assuming that on Windows Chromium we're using ANGLE.
248 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
249 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700250 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700251 fRGBA8888PixelsOpsAreSlow = isANGLE;
252 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
253 // check DX11 ANGLE.
254 fPartialFBOReadIsSlow = isANGLE;
255#endif
256
ericrkb4ecabd2016-03-11 15:18:20 -0800257 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
258 bool isMAC = false;
259#ifdef SK_BUILD_FOR_MAC
260 isMAC = true;
261#endif
262
263 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
264 // vis-versa.
265 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
266
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500267 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
268 fUseBufferDataNullHint = false;
269 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
270 fUseBufferDataNullHint = true;
271 }
272
Brian Salomond17b4a62017-05-23 16:53:47 -0400273 if (kGL_GrGLStandard == standard) {
274 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400275 fClearTextureSupport = true;
276 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500277 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
278 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400279 }
280
cdalton4cd67132015-06-10 19:23:46 -0700281 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700282 * GrShaderCaps fields
283 **************************************************************************/
284
egdaniel0a482332015-10-26 08:59:10 -0700285 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700286 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500287 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700288
Brian Osman195c05b2017-08-30 15:14:04 -0400289 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
290#if GR_TEST_UTILS
291 if (contextOptions.fSuppressPathRendering) {
292 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700293 }
Brian Osman195c05b2017-08-30 15:14:04 -0400294#endif
egdaniel05ded892015-10-26 07:38:05 -0700295
egdaniel05ded892015-10-26 07:38:05 -0700296 // Enable supported shader-related caps
297 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500298 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700299 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
300 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600301
Brian Salomon1edc5b92016-11-29 13:43:46 -0500302 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600303
egdaniel05ded892015-10-26 07:38:05 -0700304 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500305 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700306 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600307 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600308 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
309 shaderCaps->fGSInvocationsSupport = true;
310 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
311 shaderCaps->fGSInvocationsSupport = true;
312 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
313 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600314 }
315
Brian Salomon1edc5b92016-11-29 13:43:46 -0500316 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800317 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500318 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500319 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700320
Brian Salomon1edc5b92016-11-29 13:43:46 -0500321 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700322 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800323
Chris Daltonfaca00d2018-01-19 15:56:07 -0700324 // Mali has support for geometry shaders, but in practice with ccpr they are slower than the
325 // backup impl that only uses vertex shaders.
326 if (kARM_GrGLVendor != ctxInfo.vendor()) {
327 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
328 shaderCaps->fGeometryShaderSupport = true;
329 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
330 shaderCaps->fGeometryShaderSupport = true;
331 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
332 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700333 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500334 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700335
Brian Salomon1edc5b92016-11-29 13:43:46 -0500336 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800337 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700338 }
339
cdalton9c3f1432016-03-11 10:07:37 -0800340 // Protect ourselves against tracking huge amounts of texture state.
341 static const uint8_t kMaxSaneSamplers = 32;
342 GrGLint maxSamplers;
343 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500344 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
345 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800346 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500347 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800348 }
349 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500350 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800351 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500352 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800353
Brian Salomonbbf05752017-11-30 11:30:48 -0500354 // This is all *very* approximate.
355 switch (ctxInfo.vendor()) {
356 case kNVIDIA_GrGLVendor:
357 // We've seen a range from 100 x 100 (TegraK1, GTX660) up to 300 x 300 (GTX 1070)
358 // but it doesn't clearly align with Pascal vs Maxwell vs Kepler.
359 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 150 * 150;
360 break;
Brian Salomon64fa70a2017-11-30 11:56:25 -0500361 case kImagination_GrGLVendor:
362 // Two PowerVR Rogues, Nexus Player and Chromebook Cb5-312T (PowerVR GX6250), show that
363 // it is always a win to use multitexturing.
364 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
365 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold =
366 std::numeric_limits<size_t>::max();
367 }
368 break;
Brian Salomon0c56d472017-12-04 08:37:44 -0500369 case kATI_GrGLVendor:
370 // So far no AMD GPU shows a performance difference. A tie goes to disabling
371 // multitexturing for simplicity's sake.
372 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 0;
373 break;
Brian Salomonbbf05752017-11-30 11:30:48 -0500374 default:
375 break;
376 }
377
csmartdalton485a1202016-07-13 10:16:32 -0700378 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
379 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
380 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
381 // limit this decision to specific GPU families rather than basing it on the vendor alone.
382 if (!GR_GL_MUST_USE_VBO &&
383 !fIsCoreProfile &&
384 (kARM_GrGLVendor == ctxInfo.vendor() ||
385 kImagination_GrGLVendor == ctxInfo.vendor() ||
386 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
387 fPreferClientSideDynamicBuffers = true;
388 }
389
Eric Karl5c779752017-05-08 12:02:07 -0700390 if (!contextOptions.fAvoidStencilBuffers) {
391 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
392 this->initFSAASupport(contextOptions, ctxInfo, gli);
393 this->initStencilSupport(ctxInfo);
394 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400395
396 // Setup blit framebuffer
397 if (kGL_GrGLStandard != ctxInfo.standard()) {
398 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
399 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
400 kNoMSAADst_BlitFramebufferFlag |
401 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
402 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
403 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
404 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
405 // limitations.
406 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
407 kResolveMustBeFull_BlitFrambufferFlag |
408 kNoMSAADst_BlitFramebufferFlag |
409 kNoFormatConversion_BlitFramebufferFlag |
410 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
411 }
412 } else {
413 if (fUsesMixedSamples ||
414 ctxInfo.version() >= GR_GL_VER(3,0) ||
415 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
416 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
417 fBlitFramebufferFlags = 0;
418 }
419 }
420
cdalton1dd05422015-06-12 09:01:18 -0700421 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000422
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000423 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000424 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
425 // extension includes glMapBuffer.
426 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
427 fMapBufferFlags |= kSubset_MapFlag;
428 fMapBufferType = kMapBufferRange_MapBufferType;
429 } else {
430 fMapBufferType = kMapBuffer_MapBufferType;
431 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000432 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000433 // Unextended GLES2 doesn't have any buffer mapping.
434 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800435 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800436 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
437 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800438 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
439 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
440 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000441 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
442 fMapBufferFlags = kCanMap_MapFlag;
443 fMapBufferType = kMapBuffer_MapBufferType;
444 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000445 }
446
jvanverthd7a2c1f2015-12-07 07:36:44 -0800447 if (kGL_GrGLStandard == standard) {
448 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
449 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700450 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500451 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400452 if (version >= GR_GL_VER(3, 0) ||
453 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
454 // GL_EXT_unpack_subimage needed to support subtexture rectangles
455 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800456 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400457// TODO: get transfer buffers working in Chrome
458// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
459// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800460 }
461 }
462
joshualitte5b74c62015-06-01 14:17:47 -0700463 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
464 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700465 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700466#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500467 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
468 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
469 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700470 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700471#else
cdalton397536c2016-03-25 12:15:03 -0700472 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700473#endif
joshualitte5b74c62015-06-01 14:17:47 -0700474 }
475
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000476 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000477 fNPOTTextureTileSupport = true;
478 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000479 } else {
480 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000481 // ES3 has no limitations.
482 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
483 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000484 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
485 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
486 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
487 // to alllow arbitrary wrap modes, however.
488 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000489 }
490
bsalomon@google.combcce8922013-03-25 15:38:39 +0000491 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
492 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
493 // Our render targets are always created with textures as the color
494 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000495 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700496 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
497
498 if (kARM_GrGLVendor == ctxInfo.vendor()) {
499 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
500 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
501 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000502
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000503 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
504
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000505 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700506 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000507
robertphillips1b8e1b52015-06-24 06:54:10 -0700508#if 0
509 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
510 kQualcomm_GrGLVendor != ctxInfo.vendor();
511#endif
512
csmartdalton9bc11872016-08-09 12:42:47 -0700513 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
514 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700515 }
516
robertphillips63926682015-08-20 09:39:02 -0700517#ifdef SK_BUILD_FOR_WIN
518 // On ANGLE deferring flushes can lead to GPU starvation
519 fPreferVRAMUseOverFlushes = !isANGLE;
520#endif
521
bsalomon7dea7b72015-08-19 08:26:51 -0700522 if (kChromium_GrGLDriver == ctxInfo.driver()) {
523 fMustClearUploadedBufferData = true;
524 }
525
bsalomond08ea5f2015-02-20 06:58:13 -0800526 if (kGL_GrGLStandard == standard) {
527 // ARB allows mixed size FBO attachments, EXT does not.
528 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
529 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
530 fOversizedStencilSupport = true;
531 } else {
532 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
533 }
534 } else {
535 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
536 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
537 }
538
joshualitt58001552015-06-26 12:46:36 -0700539 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700540 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
541 ctxInfo.hasExtension("GL_ARB_draw_indirect");
542 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
543 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700544 (fDrawIndirectSupport &&
545 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700546 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700547 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800548 } else {
549 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700550 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
551 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
552 fBaseInstanceSupport = fDrawIndirectSupport &&
553 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700554 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800555 }
556
ethannicholas28ef4452016-03-25 09:26:03 -0700557 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500558 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700559 fSampleShadingSupport = true;
560 }
561 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
562 fSampleShadingSupport = true;
563 }
564
jvanverth84741b32016-09-30 08:39:02 -0700565 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
566 if (kGL_GrGLStandard == standard) {
567 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
568 fFenceSyncSupport = true;
569 }
Brian Osman93a23462017-06-21 15:13:39 -0400570 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700571 fFenceSyncSupport = true;
572 }
573
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400574 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500575 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500576
brianosman20471892016-12-02 06:43:32 -0800577 fSRGBDecodeDisableSupport = ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode");
Brian Salomon01b476a2018-01-23 11:06:41 -0500578
brianosman851c2382016-12-07 10:03:25 -0800579 fSRGBDecodeDisableAffectsMipmaps = fSRGBDecodeDisableSupport &&
580 kChromium_GrGLDriver != ctxInfo.driver();
brianosman20471892016-12-02 06:43:32 -0800581
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400582 if (kGL_GrGLStandard == standard) {
583 if (version >= GR_GL_VER(4, 1)) {
584 fProgramBinarySupport = true;
585 }
586 } else if (version >= GR_GL_VER(3, 0)) {
587 fProgramBinarySupport = true;
588 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400589 if (fProgramBinarySupport) {
590 GrGLint count;
591 GR_GL_GetIntegerv(gli, GR_GL_NUM_SHADER_BINARY_FORMATS, &count);
592 fProgramBinarySupport = count > 0;
593 }
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400594
bsalomoncdee0092016-01-08 13:20:12 -0800595 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
596 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800597 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700598
Brian Salomon01b476a2018-01-23 11:06:41 -0500599 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
600 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
601 }
602
cdalton4cd67132015-06-10 19:23:46 -0700603 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500604 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700605
Brian Salomon01b476a2018-01-23 11:06:41 -0500606 // For now these two are equivalent but we could have dst read in shader via some other method.
607 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000608}
609
egdaniel472d44e2015-10-22 08:20:00 -0700610const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
611 bool isCoreProfile) {
612 switch (generation) {
613 case k110_GrGLSLGeneration:
614 if (kGLES_GrGLStandard == standard) {
615 // ES2s shader language is based on version 1.20 but is version
616 // 1.00 of the ES language.
617 return "#version 100\n";
618 } else {
619 SkASSERT(kGL_GrGLStandard == standard);
620 return "#version 110\n";
621 }
622 case k130_GrGLSLGeneration:
623 SkASSERT(kGL_GrGLStandard == standard);
624 return "#version 130\n";
625 case k140_GrGLSLGeneration:
626 SkASSERT(kGL_GrGLStandard == standard);
627 return "#version 140\n";
628 case k150_GrGLSLGeneration:
629 SkASSERT(kGL_GrGLStandard == standard);
630 if (isCoreProfile) {
631 return "#version 150\n";
632 } else {
633 return "#version 150 compatibility\n";
634 }
635 case k330_GrGLSLGeneration:
636 if (kGLES_GrGLStandard == standard) {
637 return "#version 300 es\n";
638 } else {
639 SkASSERT(kGL_GrGLStandard == standard);
640 if (isCoreProfile) {
641 return "#version 330\n";
642 } else {
643 return "#version 330 compatibility\n";
644 }
645 }
cdalton33ad7012016-02-22 07:55:44 -0800646 case k400_GrGLSLGeneration:
647 SkASSERT(kGL_GrGLStandard == standard);
648 if (isCoreProfile) {
649 return "#version 400\n";
650 } else {
651 return "#version 400 compatibility\n";
652 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500653 case k420_GrGLSLGeneration:
654 SkASSERT(kGL_GrGLStandard == standard);
655 if (isCoreProfile) {
656 return "#version 420\n";
657 }
658 else {
659 return "#version 420 compatibility\n";
660 }
egdaniel472d44e2015-10-22 08:20:00 -0700661 case k310es_GrGLSLGeneration:
662 SkASSERT(kGLES_GrGLStandard == standard);
663 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800664 case k320es_GrGLSLGeneration:
665 SkASSERT(kGLES_GrGLStandard == standard);
666 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700667 }
668 return "<no version>";
669}
670
Chris Dalton47c8ed32017-11-15 18:27:09 -0700671bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
672 if (kGLES_GrGLStandard != ctxInfo.standard() &&
673 ctxInfo.version() < GR_GL_VER(4,1) &&
674 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
675 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
676 return true;
677 }
678 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
679 // geometry shaders don't have lower precision than vertex and fragment.
680 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
681 GrGLint range[2];
682 GrGLint bits;
683 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
684 if (range[0] < 127 || range[1] < 127 || bits < 23) {
685 return false;
686 }
687 }
688 return true;
689}
690
691void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700692 GrGLStandard standard = ctxInfo.standard();
693 GrGLVersion version = ctxInfo.version();
694
695 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500696 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700697 **************************************************************************/
698
Brian Salomon1edc5b92016-11-29 13:43:46 -0500699 GrShaderCaps* shaderCaps = fShaderCaps.get();
700 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700701 if (kGLES_GrGLStandard == standard) {
702 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500703 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
704 shaderCaps->fFBFetchSupport = true;
705 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
706 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700707 }
708 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
709 // 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 -0500710 shaderCaps->fFBFetchNeedsCustomOutput = false;
711 shaderCaps->fFBFetchSupport = true;
712 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
713 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700714 }
715 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
716 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500717 shaderCaps->fFBFetchNeedsCustomOutput = false;
718 shaderCaps->fFBFetchSupport = true;
719 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
720 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700721 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500722 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700723 }
724
cdaltonc08f1962016-02-12 12:14:06 -0800725 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500726 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800727 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500728 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800729 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
730 }
Brian Salomon41274562017-09-15 09:40:03 -0700731 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
732 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
733 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800734 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500735 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800736 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
737 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400738 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
739 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500740 shaderCaps->fNoPerspectiveInterpolationSupport = true;
741 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800742 "GL_NV_shader_noperspective_interpolation";
743 }
744 }
745
Brian Salomon1edc5b92016-11-29 13:43:46 -0500746 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
747 shaderCaps->fGLSLGeneration,
748 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800749
Brian Salomon1edc5b92016-11-29 13:43:46 -0500750 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
751 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800752 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800753
754 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500755 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800756 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
757 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500758 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800759 }
760
761 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500762 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800763 }
764
cdalton9c3f1432016-03-11 10:07:37 -0800765 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400766 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
767 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400768 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400769 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
770 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
771 // At least one driver has been found that has this extension without the "GL_" prefix.
772 shaderCaps->fExternalTextureSupport = true;
773 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800774 }
775 }
776
cdaltonc04ce672016-03-11 14:07:38 -0800777 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500778 shaderCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800779 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500780 shaderCaps->fTexelFetchSupport =
cdaltonf8a6ce82016-04-11 13:02:05 -0700781 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
782 }
783
Brian Salomon1edc5b92016-11-29 13:43:46 -0500784 if (shaderCaps->fTexelFetchSupport) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700785 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500786 shaderCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
cdaltonf8a6ce82016-04-11 13:02:05 -0700787 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
788 } else {
789 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
790 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500791 shaderCaps->fTexelBufferSupport = true;
cdaltonf8a6ce82016-04-11 13:02:05 -0700792 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500793 shaderCaps->fTexelBufferSupport = true;
794 shaderCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700795 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500796 shaderCaps->fTexelBufferSupport = true;
797 shaderCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700798 }
cdaltonc04ce672016-03-11 14:07:38 -0800799 }
800 }
801
Chris Dalton1d616352017-05-31 12:51:23 -0600802 if (kGL_GrGLStandard == standard) {
803 shaderCaps->fVertexIDSupport = true;
804 } else {
805 // Desktop GLSL 3.30 == ES GLSL 3.00.
806 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
807 }
808
Chris Dalton7c7ff032018-03-28 20:09:58 -0600809 if (kGL_GrGLStandard == standard) {
810 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
811 } else {
812 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
813 }
814
Chris Dalton47c8ed32017-11-15 18:27:09 -0700815 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
816 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
egdaniel472d44e2015-10-22 08:20:00 -0700817}
818
kkinnunencfe62e32015-07-01 02:58:50 -0700819bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700820 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
821
822 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700823 return false;
824 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700825
kkinnunencfe62e32015-07-01 02:58:50 -0700826 if (kGL_GrGLStandard == ctxInfo.standard()) {
827 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
828 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
829 return false;
830 }
831 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700832 if (!hasChromiumPathRendering &&
833 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700834 return false;
835 }
836 }
837 // We only support v1.3+ of GL_NV_path_rendering which allows us to
838 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
839 // additions are detected by checking the existence of the function.
840 // We also use *Then* functions that not all drivers might have. Check
841 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800842 if (!gli->fFunctions.fStencilThenCoverFillPath ||
843 !gli->fFunctions.fStencilThenCoverStrokePath ||
844 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
845 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
846 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700847 return false;
848 }
849 return true;
850}
bsalomon1aa20292016-01-22 08:16:09 -0800851
Brian Salomon71d9d842016-11-03 13:42:00 -0400852bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800853 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800854 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800855 std::function<bool ()> bindRenderTarget,
856 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400857 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800858 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400859 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800860 return false;
861 }
bsalomon7928ef62016-01-05 10:26:39 -0800862
bsalomon76148af2016-01-12 11:13:47 -0800863 GrGLenum readFormat;
864 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400865 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800866 return false;
867 }
868
bsalomon1aa20292016-01-22 08:16:09 -0800869 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800870 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
871 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
872 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
873 // 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 -0500874 // The manual does not seem to fully match the spec as the spec allows integer formats
875 // when the bound color buffer is an integer buffer. It doesn't specify which integer
876 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500877 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
878 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
879 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800880 return false;
881 }
882 // There is also a set of allowed types, but all the types we use are in the set:
883 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
884 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
885 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
886 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
887 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
888 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
889 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800890 return true;
piotaixre4b23142014-10-02 10:57:53 -0700891 }
bsalomon7928ef62016-01-05 10:26:39 -0800892
bsalomon76148af2016-01-12 11:13:47 -0800893 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500894 switch (fConfigTable[surfaceConfig].fFormatType) {
895 case kNormalizedFixedPoint_FormatType:
896 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
897 return true;
898 }
899 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500900 case kFloat_FormatType:
901 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
902 return true;
903 }
904 break;
bsalomon7928ef62016-01-05 10:26:39 -0800905 }
906
Brian Salomon71d9d842016-11-03 13:42:00 -0400907 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800908 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400909 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800910 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800911 if (!bindRenderTarget()) {
912 return false;
913 }
914 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
915 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800916 rpFormat->fFormat = format;
917 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800918 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800919 }
920
Brian Salomon71d9d842016-11-03 13:42:00 -0400921 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
922 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700923}
924
Eric Karl5c779752017-05-08 12:02:07 -0700925void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
926 const GrGLInterface* gli) {
927 // We need dual source blending and the ability to disable multisample in order to support mixed
928 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
929 // renderer is available and enabled; no other path renderers support this feature.
930 if (fMultisampleDisableSupport &&
931 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400932 this->shaderCaps()->pathRenderingSupport()
933#if GR_TEST_UTILS
934 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
935#endif
936 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700937 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400938 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700939 }
940
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000941 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400942 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
943 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
944 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
945 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
946 fAlpha8IsRenderable = true;
947 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500948 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
949 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
950 // mixed samples we can't use multisampled-render-to-texture.
951 if (fUsesMixedSamples) {
952 fMSFBOType = kMixedSamples_MSFBOType;
953 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000954 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
955 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
956 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400957 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
958 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400959 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400960 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400961 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400962 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000963 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
964 fMSFBOType = kES_Apple_MSFBOType;
965 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000966 } else {
egdanieleed519e2016-01-15 11:36:18 -0800967 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700968 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400969 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
970 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400971
Brian Salomon00731b42016-10-14 11:30:51 -0400972 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400973 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
974 // Core profile removes ALPHA8 support.
975 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
976 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
977 // present.
978 fAlpha8IsRenderable = true;
979 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000980 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
981 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400982 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000983 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000984 }
Eric Karl5c779752017-05-08 12:02:07 -0700985
Brian Salomon01b476a2018-01-23 11:06:41 -0500986 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400987 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
988 fMSFBOType = kNone_MSFBOType;
989 }
990
Eric Karl5c779752017-05-08 12:02:07 -0700991 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
992 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
993 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -0700994 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000995}
996
cdalton1dd05422015-06-12 09:01:18 -0700997void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500998 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -0700999
Greg Daniel210883c2017-11-27 15:14:01 -05001000 bool layoutQualifierSupport = false;
1001 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
1002 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
1003 layoutQualifierSupport = true;
1004 }
1005
cdalton1dd05422015-06-12 09:01:18 -07001006 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1007 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001008 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001009 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
1010 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001011 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001012 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001013 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1014 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001015 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001016 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001017 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001018 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001019 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1020 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -07001021 }
cdalton1dd05422015-06-12 09:01:18 -07001022}
1023
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001024namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001025const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001026}
1027
Eric Karl5c779752017-05-08 12:02:07 -07001028void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001029
1030 // Build up list of legal stencil formats (though perhaps not supported on
1031 // the particular gpu/driver) from most preferred to least.
1032
1033 // these consts are in order of most preferred to least preferred
1034 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1035
1036 static const StencilFormat
1037 // internal Format stencil bits total bits packed?
1038 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1039 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1040 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1041 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001042 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001043 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1044
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001045 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001046 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001047 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001048 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1049 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1050
1051 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1052 // require FBO support we can expect these are legal formats and don't
1053 // check. These also all support the unsized GL_STENCIL_INDEX.
1054 fStencilFormats.push_back() = gS8;
1055 fStencilFormats.push_back() = gS16;
1056 if (supportsPackedDS) {
1057 fStencilFormats.push_back() = gD24S8;
1058 }
1059 fStencilFormats.push_back() = gS4;
1060 if (supportsPackedDS) {
1061 fStencilFormats.push_back() = gDS;
1062 }
1063 } else {
1064 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1065 // for other formats.
1066 // ES doesn't support using the unsized format.
1067
1068 fStencilFormats.push_back() = gS8;
1069 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001070 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1071 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001072 fStencilFormats.push_back() = gD24S8;
1073 }
1074 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1075 fStencilFormats.push_back() = gS4;
1076 }
1077 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001078}
1079
Brian Osman71a18892017-08-10 10:23:25 -04001080void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001081
Brian Osman71a18892017-08-10 10:23:25 -04001082 // We are called by the base class, which has already called beginObject(). We choose to nest
1083 // all of our caps information in a named sub-object.
1084 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001085
Brian Osman71a18892017-08-10 10:23:25 -04001086 writer->beginArray("Stencil Formats");
1087
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001088 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001089 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001090 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1091 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1092 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001093 }
1094
Brian Osman71a18892017-08-10 10:23:25 -04001095 writer->endArray();
1096
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001097 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001098 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001099 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001100 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001101 "IMG MS To Texture",
1102 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001103 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001104 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001105 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001106 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1107 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1108 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1109 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1110 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001111 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001112
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001113 static const char* kInvalidateFBTypeStr[] = {
1114 "None",
1115 "Discard",
1116 "Invalidate",
1117 };
1118 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1119 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1120 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1121 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001122
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001123 static const char* kMapBufferTypeStr[] = {
1124 "None",
1125 "MapBuffer",
1126 "MapBufferRange",
1127 "Chromium",
1128 };
1129 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1130 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1131 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1132 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1133 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1134
Brian Osman71a18892017-08-10 10:23:25 -04001135 writer->appendBool("Core Profile", fIsCoreProfile);
1136 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1137 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1138 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1139 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1140 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1141 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1142 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1143 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001144
Brian Osman71a18892017-08-10 10:23:25 -04001145 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001146 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1147 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1148 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001149 writer->appendBool("Debug support", fDebugSupport);
1150 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1151 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1152 writer->appendBool("Base instance support", fBaseInstanceSupport);
1153 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1154 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1155 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1156 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1157 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1158 writer->appendBool("BGRA to RGBA readback conversions are slow",
1159 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001160 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001161 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1162 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001163 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1164 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1165 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1166 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001167 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1168 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001169
Brian Osman71a18892017-08-10 10:23:25 -04001170 writer->beginArray("configs");
1171
bsalomon41e4384e2016-01-08 09:12:44 -08001172 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001173 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001174 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1175 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1176 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001177 writer->appendHexU32("e_format_read_pixels",
1178 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001179 writer->appendHexU32(
1180 "e_format_teximage",
1181 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1182 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1183 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1184 writer->appendHexU32("i_for_renderbuffer",
1185 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1186 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001187 }
1188
Brian Osman71a18892017-08-10 10:23:25 -04001189 writer->endArray();
1190 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001191}
1192
bsalomon41e4384e2016-01-08 09:12:44 -08001193bool GrGLCaps::bgraIsInternalFormat() const {
1194 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1195}
1196
bsalomon76148af2016-01-12 11:13:47 -08001197bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1198 GrGLenum* internalFormat, GrGLenum* externalFormat,
1199 GrGLenum* externalType) const {
1200 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1201 externalFormat, externalType)) {
1202 return false;
1203 }
1204 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1205 return true;
1206}
1207
bsalomon76148af2016-01-12 11:13:47 -08001208bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1209 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001210 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001211 externalFormat, externalType)) {
1212 return false;
1213 }
1214 return true;
1215}
1216
1217bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001218 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1219 return true;
1220}
1221
1222bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1223 ExternalFormatUsage usage, GrGLenum* externalFormat,
1224 GrGLenum* externalType) const {
1225 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001226
1227 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1228 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1229
1230 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001231 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1232 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001233 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1234 return false;
1235 }
1236
1237 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1238 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1239
bsalomone9573312016-01-25 14:33:25 -08001240 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1241 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1242 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1243 // texture, not the red component.
1244 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001245 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001246 *externalFormat = GR_GL_ALPHA;
1247 }
1248 }
1249
bsalomon76148af2016-01-12 11:13:47 -08001250 return true;
1251}
1252
brianosman20471892016-12-02 06:43:32 -08001253void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1254 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001255 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001256 /*
1257 Comments on renderability of configs on various GL versions.
1258 OpenGL < 3.0:
1259 no built in support for render targets.
1260 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1261 format RGB, RGBA and NV float formats we don't use.
1262 This is the following:
1263 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1264 RGB10_A2, RGBA12,RGBA16
1265 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1266 since they aren't required by later standards and the driver can simply return
1267 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1268 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1269 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1270 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1271 This adds a lot of additional renderable sized formats, including ALPHA8.
1272 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1273 16F, 32I, 32UI, and 32F variants).
1274 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1275
1276 For both the above extensions we limit ourselves to those that are also required by
1277 OpenGL 3.0.
1278
1279 OpenGL 3.0:
1280 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1281 but are not required to be supported as renderable textures/renderbuffer.
1282 Required renderable color formats:
1283 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1284 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1285 RGB10_A2.
1286 - R11F_G11F_B10F.
1287 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1288 and RG8UI.
1289 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1290 - ALPHA8
1291
1292 OpenGL 3.1, 3.2, 3.3
1293 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1294 OpengGL 3.3, 4.0, 4.1
1295 Adds RGB10_A2UI.
1296 OpengGL 4.2
1297 Adds
1298 - RGB5_A1, RGBA4
1299 - RGB565
1300 OpenGL 4.4
1301 Does away with the separate list and adds a column to the sized internal color format
1302 table. However, no new formats become required color renderable.
1303
1304 ES 2.0
1305 color renderable: RGBA4, RGB5_A1, RGB565
1306 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1307 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1308 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1309 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1310 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1311 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1312
1313 ES 3.0
1314 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1315 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1316 RGB5_A1.
1317 - RGB8 and RGB565.
1318 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1319 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1320 ES 3.1
1321 Adds RGB10_A2, RGB10_A2UI,
1322 ES 3.2
1323 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1324 */
Brian Salomon44804c02018-01-23 16:51:28 -05001325
1326 // Correctness workarounds.
1327 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001328 bool disableSRGBForX86PowerVR = false;
1329 bool disableSRGBWriteControlForAdreno4xx = false;
1330 bool disableR8TexStorageForANGLEGL = false;
1331 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001332 bool disableRGB8ForMali400 = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001333
1334 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1335 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1336 // and GL_RG on FBO textures.
1337 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1338
1339 bool isX86PowerVR = false;
1340#if defined(SK_CPU_X86)
1341 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1342 isX86PowerVR = true;
1343 }
1344#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001345 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1346 // blacklist that device (and any others that might be sharing the same driver).
1347 disableSRGBForX86PowerVR = isX86PowerVR;
1348 disableSRGBWriteControlForAdreno4xx = kAdreno4xx_GrGLRenderer == ctxInfo.renderer();
1349
1350 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1351 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1352 // check that we are not going to OpenGL.
1353 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1354
1355 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1356#if defined(SK_BUILD_FOR_MAC)
1357 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1358#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001359 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1360 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001361 }
1362
Brian Salomon71d9d842016-11-03 13:42:00 -04001363 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1364 ConfigInfo::kFBOColorAttachment_Flag;
1365 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001366 if (kNone_MSFBOType != fMSFBOType) {
1367 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1368 }
bsalomon41e4384e2016-01-08 09:12:44 -08001369 GrGLStandard standard = ctxInfo.standard();
1370 GrGLVersion version = ctxInfo.version();
1371
cblume790d5132016-02-29 11:13:29 -08001372 bool texStorageSupported = false;
1373 if (kGL_GrGLStandard == standard) {
1374 // The EXT version can apply to either GL or GLES.
1375 texStorageSupported = version >= GR_GL_VER(4,2) ||
1376 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1377 ctxInfo.hasExtension("GL_EXT_texture_storage");
1378 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001379 texStorageSupported = version >= GR_GL_VER(3,0) ||
1380 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001381 }
1382
cdalton74b8d322016-04-11 14:47:28 -07001383 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1384
Brian Salomone609e812018-01-17 14:00:47 -05001385 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001386
1387 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001388 if (kGL_GrGLStandard == standard) {
1389 textureRedSupport =
1390 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1391 } else {
1392 textureRedSupport =
1393 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1394 }
1395 }
1396
bsalomon30447372015-12-21 09:03:05 -08001397 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1398 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001399 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001400 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001401 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001402 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001403
1404 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1405 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001406 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001407 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001408 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001409 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001410 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1411 if (kGL_GrGLStandard == standard) {
1412 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1413 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001414 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001415 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1416 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 }
cdalton74b8d322016-04-11 14:47:28 -07001423 if (texelBufferSupport) {
1424 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1425 }
bsalomoncdee0092016-01-08 13:20:12 -08001426 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001427
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001428 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1429 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1430 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1431 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1432 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1433 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1434 // supportedReadPixelsColorType never returns it.
1435 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1436 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1437 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1438 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1439 if (kGL_GrGLStandard == standard) {
1440 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1441 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1442 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1443 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1444 // becomes an issue.
1445 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1446 // but we don't support that just for simplicity's sake.
1447 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1448 } else {
1449 // 3.0 and the extension support this as a render buffer format.
1450 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1451 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1452 }
1453 }
1454 if (texStorageSupported) {
1455 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1456 }
1457 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1458 if (disableRGB8ForMali400) {
1459 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1460 }
1461
1462 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001463 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001464 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001465 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001466
1467 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1468 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1469 // GL_EXT_texture_format_BGRA8888.
1470 bool supportsBGRATexStorage = false;
1471
bsalomon41e4384e2016-01-08 09:12:44 -08001472 if (kGL_GrGLStandard == standard) {
1473 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1474 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1475 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1476 // Since the internal format is RGBA8, it is also renderable.
1477 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1478 allRenderFlags;
1479 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001480 // Since we are using RGBA8 we can use tex storage.
1481 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001482 } else {
1483 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1484 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001485 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1486 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1487 nonMSAARenderFlags;
1488
1489 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1490 supportsBGRATexStorage = true;
1491 }
1492 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1493 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1494 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1495 ConfigInfo::kRenderableWithMSAA_Flag;
1496 }
1497 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001498 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1499 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1500 // driver remembers the external format when the texture is created (with TexImage).
1501 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1502 // We could work around this, but it adds even more state tracking to code that is
1503 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1504 // This also side-steps some ambiguous interactions with the texture storage extension.
1505 if (version >= GR_GL_VER(3,0)) {
1506 // The APPLE extension doesn't make this renderable.
1507 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001508 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001509 }
bsalomon41e4384e2016-01-08 09:12:44 -08001510 }
1511 }
Brian Osman48c99192017-06-02 08:45:06 -04001512
Greg Daniel0ff79b22018-02-15 12:33:33 -05001513 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001514 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001515 }
bsalomoncdee0092016-01-08 13:20:12 -08001516 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001517
brianosmana6359362016-03-21 06:55:37 -07001518 // We only enable srgb support if both textures and FBOs support srgb,
brianosman35b784d2016-05-05 11:52:53 -07001519 // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
bsalomon41e4384e2016-01-08 09:12:44 -08001520 if (kGL_GrGLStandard == standard) {
1521 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001522 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001523 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1524 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1525 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001526 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001527 }
1528 }
1529 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001530 if (fSRGBSupport) {
1531 fSRGBWriteControl = true;
1532 }
bsalomon41e4384e2016-01-08 09:12:44 -08001533 } else {
brianosman20471892016-12-02 06:43:32 -08001534 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001535 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001536 fSRGBSupport = false;
1537 }
bsalomon41e4384e2016-01-08 09:12:44 -08001538 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1539 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001540 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001541 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001542 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001543 }
brianosman20471892016-12-02 06:43:32 -08001544 if (contextOptions.fRequireDecodeDisableForSRGB && !fSRGBDecodeDisableSupport) {
1545 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode. Clients
1546 // can opt-out of that requirement, if they intend to always do linear blending.
brianosmana6359362016-03-21 06:55:37 -07001547 fSRGBSupport = false;
1548 }
brianosman20471892016-12-02 06:43:32 -08001549
1550 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1551 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1552 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1553 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1554 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1555 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1556 // affects Windows.
1557 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1558 fSRGBSupport = false;
1559 }
1560
Brian Osman48c99192017-06-02 08:45:06 -04001561 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1562 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1563 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1564
Brian Osman67999392017-05-31 16:19:34 -04001565 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001566 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001567 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1568 }
Brian Osman67999392017-05-31 16:19:34 -04001569
bsalomon30447372015-12-21 09:03:05 -08001570 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1571 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1572 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1573 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001574 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001575 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001576 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001577 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001578 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001579 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001580 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001581 }
Brian Osman48c99192017-06-02 08:45:06 -04001582 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1583 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001584 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1585 }
bsalomoncdee0092016-01-08 13:20:12 -08001586 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001587 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1588 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1589 // is in this format, for example).
1590 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1591 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1592 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1593 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001594 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001595 GR_GL_BGRA;
1596 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1597 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001598 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001599 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001600 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001601 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001602
brianosmana6359362016-03-21 06:55:37 -07001603 if (texStorageSupported) {
1604 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1605 }
1606 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1607
bsalomon30447372015-12-21 09:03:05 -08001608 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1609 if (this->ES2CompatibilitySupport()) {
1610 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1611 } else {
1612 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1613 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001614 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001615 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001616 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001617 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001618 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1619 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001620 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001621 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1622 }
1623 } else {
1624 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1625 }
cblume790d5132016-02-29 11:13:29 -08001626 // 565 is not a sized internal format on desktop GL. So on desktop with
1627 // 565 we always use an unsized internal format to let the system pick
1628 // the best sized format to convert the 565 data to. Since TexStorage
1629 // only allows sized internal formats we disallow it.
1630 //
1631 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1632 // update.
1633 if (texStorageSupported && kGL_GrGLStandard != standard) {
1634 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1635 }
bsalomoncdee0092016-01-08 13:20:12 -08001636 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001637
1638 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1639 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001640 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001641 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001642 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001643 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001644 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1645 if (kGL_GrGLStandard == standard) {
1646 if (version >= GR_GL_VER(4, 2)) {
1647 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1648 }
1649 } else {
1650 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1651 }
cblume790d5132016-02-29 11:13:29 -08001652 if (texStorageSupported) {
1653 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1654 }
bsalomoncdee0092016-01-08 13:20:12 -08001655 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001656
Brian Osman10fc6fd2018-03-02 11:01:10 -05001657 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1658 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001659 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001660 GR_GL_RGBA;
1661 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1662 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1663 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1664 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1665 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1666 allRenderFlags;
1667 }
1668 if (texStorageSupported) {
1669 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1670 }
1671 if (texelBufferSupport) {
1672 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1673 }
1674 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1675
Greg Danielef59d872017-11-17 16:47:21 -05001676 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1677 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1678
1679 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1680 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1681 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1682 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1683 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001684 }
Greg Danielef59d872017-11-17 16:47:21 -05001685 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1686 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001687 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001688 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1689 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1690 alphaInfo.fFlags |= allRenderFlags;
1691 }
1692
1693 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1694 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1695 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1696 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1697 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001698 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001699 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001700
Brian Osman48c99192017-06-02 08:45:06 -04001701 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1702 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001703 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001704 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1705 }
1706 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1707 }
1708
Brian Salomone609e812018-01-17 14:00:47 -05001709 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001710 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
1711 if (texelBufferSupport) {
1712 redInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1713 }
1714
1715 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1716 } else {
1717 redInfo.fFlags = 0;
1718
1719 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001720 }
bsalomon41e4384e2016-01-08 09:12:44 -08001721
Greg Daniel7af060a2017-12-05 16:27:11 -05001722 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1723 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1724 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1725 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1726 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001727 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001728 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1729 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1730 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1731 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001732 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001733
1734 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1735 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1736 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1737 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1738 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001739 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001740 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1741 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1742
1743#if 0 // Leaving Gray8 as non-renderable, to keep things simple and match raster. Needs to be
1744 // updated to support Gray8_as_Lum and Gray8_as_red if this is ever enabled.
Brian Osman986563b2017-01-10 14:20:02 -05001745 if (this->textureRedSupport() ||
1746 (kDesktop_ARB_MSFBOType == this->msFBOType() &&
1747 ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
1748 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1749 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1750 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
1751 fConfigTable[kGray_8_GrPixelConfig].fFlags |= allRenderFlags;
1752 }
1753#endif
Brian Osman48c99192017-06-02 08:45:06 -04001754 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001755 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001756 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1757 }
1758 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1759 }
1760
Brian Salomone609e812018-01-17 14:00:47 -05001761 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001762 if (texelBufferSupport) {
1763 grayRedInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1764 }
1765 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1766 } else {
1767 grayRedInfo.fFlags = 0;
1768 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001769 }
1770
bsalomon41e4384e2016-01-08 09:12:44 -08001771 // Check for [half] floating point texture support
1772 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1773 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1774 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1775 bool hasFPTextures = false;
1776 bool hasHalfFPTextures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001777 bool rgIsTexturable = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001778 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001779 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001780
1781 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001782 if (version >= GR_GL_VER(3, 0)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001783 hasFPTextures = true;
1784 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001785 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001786 }
1787 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001788 if (version >= GR_GL_VER(3, 0)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001789 hasFPTextures = true;
1790 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001791 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001792 } else {
1793 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1794 ctxInfo.hasExtension("GL_OES_texture_float")) {
1795 hasFPTextures = true;
1796 }
1797 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1798 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1799 hasHalfFPTextures = true;
1800 }
1801 }
1802 }
bsalomon30447372015-12-21 09:03:05 -08001803
csmartdalton6aa0e112017-02-08 16:14:11 -05001804 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1805 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1806 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1807 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1808 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001809 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001810 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1811 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
1812 if (hasFPTextures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001813 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
csmartdalton6aa0e112017-02-08 16:14:11 -05001814 // For now we only enable rendering to float on desktop, because on ES we'd have to
1815 // solve many precision issues and no clients actually want this yet.
1816 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1817 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1818 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1819 }
bsalomon41e4384e2016-01-08 09:12:44 -08001820 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001821 if (texStorageSupported) {
1822 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1823 }
1824 if (texelBufferSupport) {
1825 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1826 }
1827 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001828 }
bsalomon30447372015-12-21 09:03:05 -08001829
Greg Danielef59d872017-11-17 16:47:21 -05001830 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001831 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001832 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001833 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001834 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001835 }
Greg Danielef59d872017-11-17 16:47:21 -05001836 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1837 redHalf.fFormats.fExternalType = redHalfExternalType;
1838 redHalf.fFormatType = kFloat_FormatType;
1839 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1840 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001841 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001842 redHalf.fSwizzle = GrSwizzle::RRRR();
Brian Salomone609e812018-01-17 14:00:47 -05001843 if (textureRedSupport && hasHalfFPTextures) {
Greg Danielef59d872017-11-17 16:47:21 -05001844 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1845
csmartdalton6aa0e112017-02-08 16:14:11 -05001846 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
Brian Salomone609e812018-01-17 14:00:47 -05001847 (textureRedSupport && ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
Greg Danielef59d872017-11-17 16:47:21 -05001848 redHalf.fFlags |= fpRenderFlags;
1849 }
1850
1851 if (texStorageSupported && !isCommandBufferES2) {
1852 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1853 }
1854
1855 if (texelBufferSupport) {
1856 redHalf.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
csmartdalton6aa0e112017-02-08 16:14:11 -05001857 }
1858 }
Greg Danielef59d872017-11-17 16:47:21 -05001859 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001860
1861 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1862 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001863 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001864 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001865 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001866 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1867 } else {
1868 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1869 }
bsalomon7928ef62016-01-05 10:26:39 -08001870 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001871 if (hasHalfFPTextures) {
1872 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1873 // ES requires 3.2 or EXT_color_buffer_half_float.
1874 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1875 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1876 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1877 }
1878 }
cblume790d5132016-02-29 11:13:29 -08001879 if (texStorageSupported) {
1880 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1881 }
cdalton74b8d322016-04-11 14:47:28 -07001882 if (texelBufferSupport) {
1883 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1884 }
bsalomoncdee0092016-01-08 13:20:12 -08001885 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001886
bsalomon30447372015-12-21 09:03:05 -08001887 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1888
1889 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001890 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1891 ctxInfo.version() >= GR_GL_VER(3,0));
1892 // All ES versions (thus far) require sized internal formats for render buffers.
1893 // TODO: Always use sized internal format?
1894 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1895
bsalomon30447372015-12-21 09:03:05 -08001896 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001897 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1898 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001899 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001900 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001901 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1902 fConfigTable[i].fFormats.fSizedInternalFormat :
1903 fConfigTable[i].fFormats.fBaseInternalFormat;
1904 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001905 fConfigTable[i].fFormats.fSizedInternalFormat :
1906 fConfigTable[i].fFormats.fBaseInternalFormat;
1907 }
Brian Salomon44804c02018-01-23 16:51:28 -05001908 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1909 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1910 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1911 // in ES.
1912 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1913 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1914 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1915 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001916 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1917 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001918 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1919 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001920 }
1921
bsalomon30447372015-12-21 09:03:05 -08001922 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1923 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1924 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1925 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1926 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001927 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001928 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001929
1930 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1931 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1932 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1933 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001934 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001935 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1936 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1937 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1938 // slot.
1939 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1940 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001941
1942 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1943 // as a base format.
1944 // GL_EXT_texture_format_BGRA8888:
1945 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1946 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1947 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001948 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001949 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1950 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1951 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001952 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001953 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1954 }
1955
bsalomoncdee0092016-01-08 13:20:12 -08001956 // If we don't have texture swizzle support then the shader generator must insert the
1957 // swizzle into shader code.
1958 if (!this->textureSwizzleSupport()) {
1959 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001960 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001961 }
1962 }
1963
bsalomon7f9b2e42016-01-12 13:29:26 -08001964 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1965 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1966 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001967 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001968 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1969 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1970 if (GrPixelConfigIsAlphaOnly(config) &&
1971 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001972 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001973 }
1974 }
1975 }
1976
Greg Daniel81e7bf82017-07-19 14:47:42 -04001977 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1978 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001979 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1980 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001981 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001982 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1983 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001984 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001985 int count;
1986 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1987 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1988 1, &count);
1989 if (count) {
1990 int* temp = new int[count];
1991 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1992 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001993 // GL has a concept of MSAA rasterization with a single sample but we do not.
1994 if (count && temp[count - 1] == 1) {
1995 --count;
1996 SkASSERT(!count || temp[count -1] > 1);
1997 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04001998 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001999 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04002000 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002001 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002002 for (int j = 0; j < count; ++j) {
2003 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
2004 }
2005 delete[] temp;
2006 }
2007 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002008 // Fake out the table using some semi-standard counts up to the max allowed sample
2009 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002010 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05002011 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
2012 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
2013 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
2014 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
2015 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002016 // Chrome has a mock GL implementation that returns 0.
2017 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05002018
Brian Salomonbdecacf2018-02-02 20:32:49 -05002019 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04002020 int count = SK_ARRAY_COUNT(kDefaultSamples);
2021 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002022 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002023 break;
2024 }
2025 }
2026 if (count > 0) {
2027 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
2028 }
2029 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002030 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
2031 fConfigTable[i].fColorSampleCounts.setCount(1);
2032 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002033 }
2034 }
2035
bsalomon30447372015-12-21 09:03:05 -08002036#ifdef SK_DEBUG
2037 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002038 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002039 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002040 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2041 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002042 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2043 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2044 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2045 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002046 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2047 fConfigTable[i].fFormats.fBaseInternalFormat);
2048 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002049 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002050 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2051 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2052 fConfigTable[i].fFormats.fExternalFormat[j]);
2053 }
2054 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002055 }
2056#endif
2057}
2058
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002059bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2060 bool dstIsTextureable, bool dstIsGLTexture2D,
2061 GrSurfaceOrigin dstOrigin,
2062 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2063 bool srcIsTextureable, bool srcIsGLTexture2D,
2064 GrSurfaceOrigin srcOrigin) const {
2065 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2066 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2067 // many drivers would allow it to work, but ANGLE does not.
2068 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2069 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2070 return false;
2071 }
2072
2073 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2074 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2075 return false;
2076 }
2077
2078 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2079 // texture.
2080 if (!dstIsTextureable) {
2081 return false;
2082 }
2083
2084 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2085 // is required
2086 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2087 (!srcIsTextureable || srcIsGLTexture2D) &&
2088 dstIsGLTexture2D &&
2089 dstOrigin == srcOrigin) {
2090 return true;
2091 } else {
2092 return false;
2093 }
2094}
2095
2096bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2097 bool dstIsTextureable, bool dstIsGLTexture2D,
2098 GrSurfaceOrigin dstOrigin,
2099 GrPixelConfig srcConfig, int srcSampleCnt,
2100 bool srcIsTextureable, bool srcIsGLTexture2D,
2101 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2102 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2103 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2104 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2105 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2106 return false;
2107 }
2108
2109 if (dstIsTextureable && !dstIsGLTexture2D) {
2110 return false;
2111 }
2112 if (srcIsTextureable && !srcIsGLTexture2D) {
2113 return false;
2114 }
2115
2116 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2117 return false;
2118 }
2119 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2120 // We would mirror to compensate for origin changes. Note that copySurface is
2121 // specified such that the src and dst rects are the same.
2122 if (dstOrigin != srcOrigin) {
2123 return false;
2124 }
2125 }
2126
2127 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2128 if (srcSampleCnt > 1) {
2129 if (1 == dstSampleCnt) {
2130 return false;
2131 }
2132 if (SkRect::Make(srcRect) != srcBounds) {
2133 return false;
2134 }
2135 }
2136 }
2137
2138 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2139 if (dstSampleCnt > 1) {
2140 return false;
2141 }
2142 }
2143
2144 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2145 if (dstConfig != srcConfig) {
2146 return false;
2147 }
2148 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2149 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2150 return false;
2151 }
2152 }
2153
2154 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2155 if (srcSampleCnt > 1) {
2156 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2157 return false;
2158 }
2159 if (dstOrigin != srcOrigin) {
2160 return false;
2161 }
2162 }
2163 }
2164 return true;
2165}
2166
2167bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2168 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2169}
2170
2171static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2172 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2173 if (!rt) {
2174 return false;
2175 }
2176 // A RT has a separate MSAA renderbuffer if:
2177 // 1) It's multisampled
2178 // 2) We're using an extension with separate MSAA renderbuffers
2179 // 3) It's not FBO 0, which is special and always auto-resolves
2180 return rt->numColorSamples() > 1 &&
2181 glCaps.usesMSAARenderBuffers() &&
2182 !rt->rtPriv().glRTFBOIDIs0();
2183}
2184
2185bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2186 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2187 GrSurfaceOrigin dstOrigin = dst->origin();
2188 GrSurfaceOrigin srcOrigin = src->origin();
2189
2190 GrPixelConfig dstConfig = dst->config();
2191 GrPixelConfig srcConfig = src->config();
2192
2193 int dstSampleCnt = 0;
2194 int srcSampleCnt = 0;
2195 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2196 dstSampleCnt = rtProxy->numColorSamples();
2197 }
2198 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2199 srcSampleCnt = rtProxy->numColorSamples();
2200 }
2201 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2202 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2203
2204 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2205 // swizzle.
2206 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2207 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2208 return false;
2209 }
2210
2211 const GrTextureProxy* dstTex = dst->asTextureProxy();
2212 const GrTextureProxy* srcTex = src->asTextureProxy();
2213
2214 bool dstIsTex2D = dstTex ? dstTex->texPriv().isGLTexture2D() : false;
2215 bool srcIsTex2D = srcTex ? srcTex->texPriv().isGLTexture2D() : false;
2216
2217 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2218 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2219 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2220 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2221 // know we will at least be able to do it as a draw.
2222#ifdef SK_DEBUG
2223 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2224 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2225 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2226 !src->priv().isExact()) {
2227 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2228 }
2229#endif
2230
2231 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2232 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2233 srcConfig, has_msaa_render_buffer(src, *this),
2234 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2235 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2236 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2237 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2238 dstPoint) ||
2239 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2240}
2241
Robert Phillipsbf25d432017-04-07 10:08:53 -04002242bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002243 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2244 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002245 // By default, we don't require rects to match.
2246 *rectsMustMatch = false;
2247
2248 // By default, we allow subrects.
2249 *disallowSubrect = false;
2250
Brian Salomon467921e2017-03-06 16:17:12 -05002251 // If the src is a texture, we can implement the blit as a draw assuming the config is
2252 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002253 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002254 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002255 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2256 desc->fConfig = src->config();
2257 return true;
2258 }
2259
Robert Phillipsbf25d432017-04-07 10:08:53 -04002260 {
2261 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2262 // wrapped. In that case the proxy would already be instantiated.
2263 const GrTexture* srcTexture = src->priv().peekTexture();
2264 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2265 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2266 // Not supported for FBO blit or CopyTexSubImage
2267 return false;
2268 }
Brian Salomon467921e2017-03-06 16:17:12 -05002269 }
2270
2271 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2272 // possible and we return false to fallback to creating a render target dst for render-to-
2273 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2274 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002275 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002276 bool rectsMustMatchForBlitFramebuffer = false;
2277 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002278 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002279 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2280 rectsMustMatchForBlitFramebuffer = true;
2281 disallowSubrectForBlitFramebuffer = true;
2282 // Mirroring causes rects to mismatch later, don't allow it.
2283 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002284 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2285 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002286 rectsMustMatchForBlitFramebuffer = true;
2287 // Mirroring causes rects to mismatch later, don't allow it.
2288 originForBlitFramebuffer = src->origin();
2289 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002290 originForBlitFramebuffer = src->origin();
2291 }
2292
2293 // Check for format issues with glCopyTexSubImage2D
2294 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2295 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2296 // then we set up for that, otherwise fail.
2297 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002298 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002299 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002300 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2301 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002302 return true;
2303 }
2304 return false;
2305 }
2306
Robert Phillipsbf25d432017-04-07 10:08:53 -04002307 {
Brian Salomon63e79732017-05-15 21:23:13 -04002308 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2309 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002310 if (srcIsMSAARenderbuffer) {
2311 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2312 // blit or fail.
2313 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002314 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002315 desc->fConfig = src->config();
2316 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2317 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2318 return true;
2319 }
2320 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002321 }
Brian Salomon467921e2017-03-06 16:17:12 -05002322 }
2323
2324 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002325 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002326 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002327 desc->fFlags = kNone_GrSurfaceFlags;
2328 return true;
2329}
2330
Greg Daniel691f5e72018-02-28 14:21:34 -05002331void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2332 const GrContextOptions& contextOptions,
2333 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002334 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2335 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Greg Daniel0b1e6282018-05-10 17:24:47 +00002336 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002337 fDiscardRenderTargetSupport = false;
2338 fInvalidateFBType = kNone_InvalidateFBType;
2339 }
2340
2341 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2342 // 340.96 and 367.57.
2343 if (kGL_GrGLStandard == ctxInfo.standard() &&
2344 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002345 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002346 fClearTextureSupport = false;
2347 }
2348
2349 // Calling glClearTexImage crashes on the NexusPlayer.
2350 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2351 fClearTextureSupport = false;
2352 }
2353
2354 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2355#ifdef SK_BUILD_FOR_MAC
2356 if (shaderCaps->fGeometryShaderSupport) {
2357 shaderCaps->fGSInvocationsSupport = false;
2358 }
2359#endif
2360
2361 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2362 // shaders. @127.0 is the earliest verified driver to not crash.
2363 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002364 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002365 shaderCaps->fGeometryShaderSupport = false;
2366 }
2367
2368#if defined(__has_feature)
2369#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2370 // See skbug.com/7058
2371 fMapBufferType = kNone_MapBufferType;
2372 fMapBufferFlags = kNone_MapFlags;
2373#endif
2374#endif
2375
2376 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2377 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2378 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2379 // unclear whether this really affects a wide range of devices.
2380 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002381 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002382 fMapBufferType = kNone_MapBufferType;
2383 fMapBufferFlags = kNone_MapFlags;
2384 }
2385
2386 // TODO: re-enable for ANGLE
2387 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2388 fTransferBufferType = kNone_TransferBufferType;
2389 }
2390
2391 // Using MIPs on this GPU seems to be a source of trouble.
2392 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2393 fMipMapSupport = false;
2394 }
2395
2396 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2397 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2398 // around a driver bug related to gl_FragCoord.
2399 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2400 fMaxClipAnalyticFPs = 0;
2401 }
2402
2403#ifndef SK_BUILD_FOR_IOS
2404 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2405 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2406 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2407 ctxInfo.driver() != kChromium_GrGLDriver)) {
2408 fUseDrawToClearColor = true;
2409 }
2410#endif
2411
2412 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2413 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2414 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2415 fUseDrawToClearColor = true;
2416 }
2417
2418#ifdef SK_BUILD_FOR_MAC
2419 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2420 // full screen clears
2421 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2422 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002423 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2424 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2425 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2426 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002427 fUseDrawToClearColor = true;
2428 }
2429#endif
2430
2431 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2432 // bugs seems to involve clearing too much and not skipping the clear.
2433 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2434 // but only for D3D11 ANGLE.
2435 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2436 fUseDrawToClearColor = true;
2437 }
2438
2439 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
2440 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002441 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002442 fUseDrawToClearStencilClip = true;
2443 }
2444 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2445 }
2446
2447 // This was reproduced on the following configurations:
2448 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2449 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2450 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2451 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2452 // and not produced on:
2453 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2454 // The particular lines that get dropped from test images varies across different devices.
2455 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002456 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002457 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2458 }
2459
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002460 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2461 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2462 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002463 fRequiresFlushBetweenNonAndInstancedDraws = true;
2464 }
2465
Brian Salomon01b476a2018-01-23 11:06:41 -05002466 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2467 // given 1 << 15 or more instances.
2468 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2469 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
2470 }
2471
2472 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002473 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002474 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2475 fUseDrawInsteadOfAllRenderTargetWrites = true;
2476 }
2477
2478 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2479 fSampleShadingSupport = false;
2480 }
2481
2482#ifdef SK_BUILD_FOR_MAC
2483 static constexpr bool isMAC = true;
2484#else
2485 static constexpr bool isMAC = false;
2486#endif
2487
2488 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2489 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2490 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2491 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2492 if (fMipMapLevelAndLodControlSupport &&
2493 (contextOptions.fDoManualMipmapping ||
2494 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2495 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2496 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2497 fDoManualMipmapping = true;
2498 }
2499
2500 // See http://crbug.com/710443
2501#ifdef SK_BUILD_FOR_MAC
2502 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2503 fClearToBoundaryValuesIsBroken = true;
2504 }
2505#endif
2506 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2507 fDrawArraysBaseVertexIsBroken = true;
2508 }
2509
Brian Salomon01b476a2018-01-23 11:06:41 -05002510 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2511 // Galaxy S7.
2512 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2513 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2514 shaderCaps->fFBFetchSupport = false;
2515 }
2516
Brian Salomon01b476a2018-01-23 11:06:41 -05002517 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2518 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2519
2520 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2521 // function that may require a gradient calculation inside a conditional block may return
2522 // undefined results". This appears to be an issue with the 'any' call since even the simple
2523 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2524 // from our GrTextureDomain processor.
2525 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2526
2527 // Known issue on at least some Intel platforms:
2528 // http://code.google.com/p/skia/issues/detail?id=946
2529 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2530 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2531 }
2532
Chris Dalton0090ef62018-03-28 17:35:00 -06002533 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002534 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2535 // so we must do the abs first in a separate expression.
2536 shaderCaps->fCanUseMinAndAbsTogether = false;
2537
2538 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2539 // must avoid this condition.
2540 shaderCaps->fCanUseFractForNegativeValues = false;
2541 }
2542
2543 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2544 // thus must us -1.0 * %s.x to work correctly
2545 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2546 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2547 }
2548
2549 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2550 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2551 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2552 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2553 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2554 }
2555
2556 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2557 // the original dst color when reading the outColor even after being written to. By using a
2558 // local outColor we can work around this bug.
2559 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2560 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2561 }
2562
2563 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2564 // color, and that uniform contains an opaque color, and the output of the shader is only based
2565 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2566 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2567 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2568 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2569 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2570 shaderCaps->fMustObfuscateUniformColor = true;
2571 }
2572#ifdef SK_BUILD_FOR_WIN
2573 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2574 //
2575 // Basically, if a shader has a construct like:
2576 //
2577 // float x = someCondition ? someValue : 0;
2578 // float2 result = (0 == x) ? float2(x, x)
2579 // : float2(2 * x / x, 0);
2580 //
2581 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2582 // we've explicitly guarded the division with a check against zero. This manifests in much
2583 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2584 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2585 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2586 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2587 }
2588#endif
2589
2590 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
2591 // (rare) situations. It's sporadic, and mostly on older drivers. It also seems to be the case
2592 // that the interpolation of vertex shader outputs is quite inaccurate.
2593 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2594 shaderCaps->fCanUseFragCoord = false;
2595 shaderCaps->fInterpolantsAreInaccurate = true;
2596 }
2597
Chris Dalton0090ef62018-03-28 17:35:00 -06002598 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2599 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2600 shaderCaps->fCanUseFragCoord = false;
2601 }
2602
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002603 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2604 // (Are they implemented with fp16?)
2605 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2606 shaderCaps->fIncompleteShortIntPrecision = true;
2607 }
2608
Brian Salomon01b476a2018-01-23 11:06:41 -05002609 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2610 // for now until its own blacklists can be updated.
2611 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
2612 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2613 kIntel_GrGLDriver == ctxInfo.driver() ||
2614 kChromium_GrGLDriver == ctxInfo.driver()) {
2615 fBlendEquationSupport = kBasic_BlendEquationSupport;
2616 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2617 }
2618
2619 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2620 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002621 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002622 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002623 fBlendEquationSupport = kBasic_BlendEquationSupport;
2624 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2625 }
2626
Adrienne Walker68314842018-05-14 14:02:53 -07002627 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2628 fBlendEquationSupport = kBasic_BlendEquationSupport;
2629 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2630 }
2631
Brian Salomon01b476a2018-01-23 11:06:41 -05002632 if (this->advancedBlendEquationSupport()) {
2633 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002634 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002635 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2636 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2637 (1 << kColorBurn_GrBlendEquation);
2638 }
2639 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2640 // Blacklist color-burn on ARM until the fix is released.
2641 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2642 }
2643 }
2644
2645 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2646 if (fMultisampleDisableSupport &&
2647 this->shaderCaps()->dualSourceBlendingSupport() &&
2648 this->shaderCaps()->pathRenderingSupport() &&
2649 fUsesMixedSamples &&
2650#if GR_TEST_UTILS
2651 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2652#endif
2653 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2654 kChromium_GrGLDriver == ctxInfo.driver())) {
2655 fDiscardRenderTargetSupport = false;
2656 fInvalidateFBType = kNone_InvalidateFBType;
2657 }
Brian Osmanc585e202018-04-04 14:08:27 -04002658
Brian Osman061020e2018-04-17 14:22:15 -04002659 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2660 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2661 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2662 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002663 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2664 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002665 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002666 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002667 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2668 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002669 }
Brian Osman2fa53742018-05-03 15:05:12 -04002670
2671#ifdef SK_BUILD_FOR_IOS
2672 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2673 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2674 // is to just blacklist the feature.
2675 // https://github.com/flutter/flutter/issues/16718
2676 // https://bugreport.apple.com/web/?problemID=39948888
2677 fUnpackRowLengthSupport = false;
2678#endif
Brian Salomon01b476a2018-01-23 11:06:41 -05002679}
2680
csmartdaltone0d36292016-07-29 08:14:20 -07002681void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002682 if (options.fDisableDriverCorrectnessWorkarounds) {
2683 SkASSERT(!fDoManualMipmapping);
2684 SkASSERT(!fClearToBoundaryValuesIsBroken);
2685 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2686 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2687 SkASSERT(!fUseDrawToClearColor);
2688 SkASSERT(!fUseDrawToClearStencilClip);
2689 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2690 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2691 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002692 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Salomon01b476a2018-01-23 11:06:41 -05002693 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002694 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2695 fUseDrawToClearColor = false;
2696 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2697 fUseDrawToClearColor = true;
2698 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002699 if (options.fDoManualMipmapping) {
2700 fDoManualMipmapping = true;
2701 }
csmartdaltone0d36292016-07-29 08:14:20 -07002702}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002703
Brian Salomon3d86a192018-02-27 16:46:11 -05002704bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2705 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2706 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2707 if (tex->hasBaseLevelBeenBoundToFBO()) {
2708 return false;
2709 }
2710 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002711 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002712 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2713 return false;
2714 }
2715 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2716 return false;
2717 }
2718 return SkToBool(surface->asTexture());
2719 }
2720 return true;
2721}
2722
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002723bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2724 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2725 // We don't support reading pixels directly from EXTERNAL textures as it would require
2726 // binding the texture to a FBO.
2727 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2728 return false;
2729 }
2730 }
2731 return true;
2732}
2733
2734GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2735 GrColorType dstColorType) const {
2736 // For now, we mostly report the read back format that is required by the ES spec without
2737 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2738 // this as makes sense to increase performance and correctness.
2739 switch (fConfigTable[config].fFormatType) {
2740 case kNormalizedFixedPoint_FormatType:
2741 return GrColorType::kRGBA_8888;
2742 case kFloat_FormatType:
2743 // We cheat a little here and allow F16 read back if the src and dst match.
2744 if (kRGBA_half_GrPixelConfig == config && GrColorType::kRGBA_F16 == dstColorType) {
2745 return GrColorType::kRGBA_F16;
2746 }
2747 if ((kAlpha_half_GrPixelConfig == config ||
2748 kAlpha_half_as_Red_GrPixelConfig == config) &&
2749 GrColorType::kAlpha_F16 == dstColorType) {
2750 return GrColorType::kAlpha_F16;
2751 }
2752 // And similar for full float RG.
2753 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2754 return GrColorType::kRG_F32;
2755 }
2756 return GrColorType::kRGBA_F32;
2757 }
2758 return GrColorType::kUnknown;
2759}
2760
Greg Daniel2a303902018-02-20 10:25:54 -05002761bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002762 GrGLFramebufferInfo fbInfo;
2763 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002764 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002765 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002766}
2767
Brian Salomonbdecacf2018-02-02 20:32:49 -05002768int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2769 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002770 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002771 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002772 return 0;
2773 }
2774
Brian Salomonbdecacf2018-02-02 20:32:49 -05002775 if (1 == requestedCount) {
2776 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2777 }
2778
Greg Daniel81e7bf82017-07-19 14:47:42 -04002779 for (int i = 0; i < count; ++i) {
2780 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
2781 return fConfigTable[config].fColorSampleCounts[i];
2782 }
2783 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002784 return 0;
2785}
2786
2787int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2788 const auto& table = fConfigTable[config].fColorSampleCounts;
2789 if (!table.count()) {
2790 return 0;
2791 }
2792 return table[table.count() - 1];
Brian Salomond653cac2018-02-01 13:58:00 -05002793}
2794
Greg Danielfaa095e2017-12-19 13:15:02 -05002795bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2796 GrGLStandard standard) {
2797 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002798
2799 switch (ct) {
2800 case kUnknown_SkColorType:
2801 return false;
2802 case kAlpha_8_SkColorType:
2803 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002804 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002805 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002806 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002807 }
2808 break;
2809 case kRGB_565_SkColorType:
2810 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002811 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002812 }
2813 break;
2814 case kARGB_4444_SkColorType:
2815 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002816 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002817 }
2818 break;
2819 case kRGBA_8888_SkColorType:
2820 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002821 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002822 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002823 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002824 }
2825 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002826 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002827 if (GR_GL_RGB8 == format) {
2828 *config = kRGB_888_GrPixelConfig;
2829 }
2830 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002831 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002832 if (GR_GL_RGBA8 == format) {
2833 if (kGL_GrGLStandard == standard) {
2834 *config = kBGRA_8888_GrPixelConfig;
2835 }
2836 } else if (GR_GL_BGRA8 == format) {
2837 if (kGLES_GrGLStandard == standard) {
2838 *config = kBGRA_8888_GrPixelConfig;
2839 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002840 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002841 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002842 }
2843 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002844 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002845 if (GR_GL_RGB10_A2 == format) {
2846 *config = kRGBA_1010102_GrPixelConfig;
2847 }
2848 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002849 case kRGB_101010x_SkColorType:
2850 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002851 case kGray_8_SkColorType:
2852 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002853 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002854 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002855 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002856 }
2857 break;
2858 case kRGBA_F16_SkColorType:
2859 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002860 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002861 }
2862 break;
2863 }
2864
Greg Danielfaa095e2017-12-19 13:15:02 -05002865 return kUnknown_GrPixelConfig != *config;
2866}
2867
2868bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2869 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002870 GrGLTextureInfo texInfo;
2871 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002872 return false;
2873 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002874 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002875}
2876
2877bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2878 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002879 GrGLFramebufferInfo fbInfo;
2880 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002881 return false;
2882 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002883 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002884}
2885
Robert Phillipsfc711a22018-02-13 17:03:00 -05002886bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2887 GrPixelConfig* config) const {
2888 const GrGLenum* glFormat = format.getGLFormat();
2889 if (!glFormat) {
2890 return false;
2891 }
2892 return validate_sized_format(*glFormat, ct, config, fStandard);
2893}
2894
2895