blob: e20d0137e95367699305aee68345280cf784f3ad [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00008#include "GrGLCaps.h"
egdanielb7e7d572015-11-04 04:23:53 -08009#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000010#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080011#include "GrGLRenderTarget.h"
Brian Salomon467921e2017-03-06 16:17:12 -050012#include "GrGLTexture.h"
Greg Daniel26dbe3b2018-05-03 10:35:42 -040013#include "GrRenderTargetProxyPriv.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050014#include "GrShaderCaps.h"
Robert Phillipsbf25d432017-04-07 10:08:53 -040015#include "GrSurfaceProxyPriv.h"
Greg Daniel26dbe3b2018-05-03 10:35:42 -040016#include "GrTextureProxyPriv.h"
Brian Osman71a18892017-08-10 10:23:25 -040017#include "SkJSONWriter.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000018#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000019#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000020
bsalomon682c2692015-05-22 14:01:46 -070021GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
22 const GrGLContextInfo& ctxInfo,
23 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080024 fStandard = ctxInfo.standard();
25
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000027 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000028 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000029 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080030 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032 fUnpackRowLengthSupport = false;
33 fUnpackFlipYSupport = false;
34 fPackRowLengthSupport = false;
35 fPackFlipYSupport = false;
36 fTextureUsageSupport = false;
Robert Phillips5ab72762017-06-07 12:04:18 -040037 fAlpha8IsRenderable = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080041 fES2CompatibilitySupport = false;
cdalton06604b92016-02-05 10:09:51 -080042 fDrawIndirectSupport = false;
43 fMultiDrawIndirectSupport = false;
44 fBaseInstanceSupport = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080047 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080048 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070049 fRGBA8888PixelsOpsAreSlow = false;
50 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080051 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080052 fRGBAToBGRAReadbackConversionsAreSlow = false;
Robert Phillipsf2ec0242018-03-01 16:51:25 -050053 fUseBufferDataNullHint = SkToBool(GR_GL_USE_BUFFER_DATA_NULL_HINT);
brianosman09563ce2016-06-02 08:59:34 -070054 fDoManualMipmapping = false;
Eric Karlaeaf22b2017-05-18 15:08:09 -070055 fClearToBoundaryValuesIsBroken = false;
Brian Salomond17b4a62017-05-23 16:53:47 -040056 fClearTextureSupport = false;
Chris Dalton9926f4b2017-05-17 15:15:50 -060057 fDrawArraysBaseVertexIsBroken = false;
Brian Salomon43f8bf02017-10-18 08:33:29 -040058 fUseDrawToClearColor = false;
Mike Klein31550db2017-06-06 23:29:53 +000059 fUseDrawToClearStencilClip = false;
Brian Salomon9bada542017-06-12 12:09:30 -040060 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
61 fUseDrawInsteadOfAllRenderTargetWrites = false;
Brian Salomon6d9c88b2017-06-12 10:24:42 -040062 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
Chris Daltonda40cd22018-04-16 13:19:58 -060063 fRequiresFlushBetweenNonAndInstancedDraws = false;
Ethan Nicholas06d55fb2017-11-08 09:48:50 -050064 fProgramBinarySupport = false;
piotaixre4b23142014-10-02 10:57:53 -070065
Brian Salomone5e7eb12016-10-14 16:18:33 -040066 fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
Chris Daltoncc604e52017-10-06 16:27:32 -060067 fMaxInstancesPerDrawArraysWithoutCrashing = 0;
bsalomon083617b2016-02-12 12:10:14 -080068
Brian Salomon94efbf52016-11-29 13:43:05 -050069 fShaderCaps.reset(new GrShaderCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070070
cdalton4cd67132015-06-10 19:23:46 -070071 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072}
73
cdalton4cd67132015-06-10 19:23:46 -070074void GrGLCaps::init(const GrContextOptions& contextOptions,
75 const GrGLContextInfo& ctxInfo,
76 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000077 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000078 GrGLVersion version = ctxInfo.version();
79
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000080 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000081 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
82 &fMaxFragmentUniformVectors);
83 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000084 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000085 GrGLint max;
86 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
87 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000088 if (version >= GR_GL_VER(3, 2)) {
89 GrGLint profileMask;
90 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
91 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
92 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000093 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000094 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000096 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 fUnpackRowLengthSupport = true;
98 fUnpackFlipYSupport = false;
99 fPackRowLengthSupport = true;
100 fPackFlipYSupport = false;
101 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000102 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
103 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000105 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
106 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107 fPackFlipYSupport =
108 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
109 }
110
Adrienne Walkerc48f7762018-05-15 13:03:13 -0700111 if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
112 // In some cases drivers handle copying the last row incorrectly
113 // when using GL_PACK_ROW_LENGTH. Chromium handles this by iterating
114 // through every row and conditionally clobbering that value, but
115 // Skia already has a scratch buffer workaround when pack row length
116 // is not supported, so just use that.
117 fPackRowLengthSupport = false;
118 }
119
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000120 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000121 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
122
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000123 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700124 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
125 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
126 ctxInfo.hasExtension("GL_NV_texture_barrier");
127 } else {
128 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
129 }
130
Robert Phillips7f861922018-01-30 13:13:42 +0000131 if (kGL_GrGLStandard == standard) {
132 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
133 ctxInfo.hasExtension("GL_ARB_texture_multisample");
134 } else {
135 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
136 }
137
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000138 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000139 ctxInfo.hasExtension("GL_ARB_imaging");
140
Brian Salomon01b476a2018-01-23 11:06:41 -0500141 if (((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
egdaniel9250d242015-05-18 13:04:26 -0700142 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
143 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000144 fDiscardRenderTargetSupport = true;
145 fInvalidateFBType = kInvalidate_InvalidateFBType;
146 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
147 fDiscardRenderTargetSupport = true;
148 fInvalidateFBType = kDiscard_InvalidateFBType;
149 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000150
Chris Dalton27059d32018-01-23 14:06:50 -0700151 // For future reference on Desktop GL, GL_PRIMITIVE_RESTART_FIXED_INDEX appears in 4.3, and
152 // GL_PRIMITIVE_RESTART (where the client must call glPrimitiveRestartIndex) appears in 3.1.
153 if (kGLES_GrGLStandard == standard) {
154 // Primitive restart can cause a 3x slowdown on Adreno. Enable conservatively.
155 // TODO: Evaluate on PowerVR.
156 // FIXME: Primitive restart would likely be a win on iOS if we had an enum value for it.
157 if (kARM_GrGLVendor == ctxInfo.vendor()) {
158 fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
159 }
160 }
161
Chris Dalton344e9032017-12-11 15:42:09 -0700162 if (kARM_GrGLVendor == ctxInfo.vendor() ||
163 kImagination_GrGLVendor == ctxInfo.vendor() ||
164 kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
165 fPreferFullscreenClears = true;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000166 }
167
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000168 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000169 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800170 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
171 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000172 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000173 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
174 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000175 }
176
cdalton626e1ff2015-06-12 13:56:46 -0700177 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
178 fDebugSupport = true;
179 } else {
180 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
181 }
182
jvanverth3f801cb2014-12-16 09:49:38 -0800183 if (kGL_GrGLStandard == standard) {
184 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
185 }
186 else {
187 fES2CompatibilitySupport = true;
188 }
189
cdalton0edea2c2015-05-21 08:27:44 -0700190 if (kGL_GrGLStandard == standard) {
191 fMultisampleDisableSupport = true;
192 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700193 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700194 }
195
kkinnunend94708e2015-07-30 22:47:04 -0700196 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600197 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
198 // instanced arrays, but we could make this more granular if we wanted
199 fInstanceAttribSupport =
200 version >= GR_GL_VER(3, 2) ||
201 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
202 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
203 } else {
204 fInstanceAttribSupport =
205 version >= GR_GL_VER(3, 0) ||
206 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
207 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
208 }
209
210 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700211 if (version >= GR_GL_VER(3, 0)) {
212 fBindFragDataLocationSupport = true;
213 }
214 } else {
215 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
216 fBindFragDataLocationSupport = true;
217 }
joshualittc1f56b52015-06-22 12:31:31 -0700218 }
219
joshualitt7bdd70a2015-10-01 06:28:11 -0700220 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
221
kkinnunene06ed252016-02-16 23:15:40 -0800222 if (kGL_GrGLStandard == standard) {
Ravi Mistry35b40ce2018-05-30 20:54:40 +0000223 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
kkinnunene06ed252016-02-16 23:15:40 -0800224 // We also require textureSize() support for rectangle 2D samplers which was added in
225 // GLSL 1.40.
226 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
227 fRectangleTextureSupport = true;
228 }
bsalomone179a912016-01-20 06:18:10 -0800229 }
kkinnunene06ed252016-02-16 23:15:40 -0800230 } else {
231 // Command buffer exposes this in GL ES context for Chromium reasons,
232 // but it should not be used. Also, at the time of writing command buffer
233 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800234 }
235
bsalomoncdee0092016-01-08 13:20:12 -0800236 if (kGL_GrGLStandard == standard) {
237 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
238 fTextureSwizzleSupport = true;
239 }
240 } else {
241 if (version >= GR_GL_VER(3,0)) {
242 fTextureSwizzleSupport = true;
243 }
244 }
245
cblume09bd2c02016-03-01 14:08:28 -0800246 if (kGL_GrGLStandard == standard) {
247 fMipMapLevelAndLodControlSupport = true;
248 } else if (kGLES_GrGLStandard == standard) {
249 if (version >= GR_GL_VER(3,0)) {
250 fMipMapLevelAndLodControlSupport = true;
251 }
252 }
253
bsalomon88c7b982015-07-31 11:20:16 -0700254#ifdef SK_BUILD_FOR_WIN
255 // We're assuming that on Windows Chromium we're using ANGLE.
256 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
257 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700258 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700259 fRGBA8888PixelsOpsAreSlow = isANGLE;
260 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
261 // check DX11 ANGLE.
262 fPartialFBOReadIsSlow = isANGLE;
263#endif
264
ericrkb4ecabd2016-03-11 15:18:20 -0800265 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
266 bool isMAC = false;
267#ifdef SK_BUILD_FOR_MAC
268 isMAC = true;
269#endif
270
271 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
272 // vis-versa.
273 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
274
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500275 if (GrContextOptions::Enable::kNo == contextOptions.fUseGLBufferDataNullHint) {
276 fUseBufferDataNullHint = false;
277 } else if (GrContextOptions::Enable::kYes == contextOptions.fUseGLBufferDataNullHint) {
278 fUseBufferDataNullHint = true;
279 }
280
Brian Salomond17b4a62017-05-23 16:53:47 -0400281 if (kGL_GrGLStandard == standard) {
282 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
Brian Salomond17b4a62017-05-23 16:53:47 -0400283 fClearTextureSupport = true;
284 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500285 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
286 fClearTextureSupport = true;
Brian Salomond17b4a62017-05-23 16:53:47 -0400287 }
288
cdalton4cd67132015-06-10 19:23:46 -0700289 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700290 * GrShaderCaps fields
291 **************************************************************************/
292
egdaniel0a482332015-10-26 08:59:10 -0700293 // This must be called after fCoreProfile is set on the GrGLCaps
Chris Dalton47c8ed32017-11-15 18:27:09 -0700294 this->initGLSL(ctxInfo, gli);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500295 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700296
Brian Osman195c05b2017-08-30 15:14:04 -0400297 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
298#if GR_TEST_UTILS
299 if (contextOptions.fSuppressPathRendering) {
300 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700301 }
Brian Osman195c05b2017-08-30 15:14:04 -0400302#endif
egdaniel05ded892015-10-26 07:38:05 -0700303
egdaniel05ded892015-10-26 07:38:05 -0700304 // Enable supported shader-related caps
305 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500306 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700307 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
308 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600309
Brian Salomon1edc5b92016-11-29 13:43:46 -0500310 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600311
egdaniel05ded892015-10-26 07:38:05 -0700312 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500313 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700314 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600315 if (shaderCaps->fGeometryShaderSupport) {
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600316 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
317 shaderCaps->fGSInvocationsSupport = true;
318 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
319 shaderCaps->fGSInvocationsSupport = true;
320 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
321 }
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600322 }
323
Brian Salomon1edc5b92016-11-29 13:43:46 -0500324 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800325 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
Chris Dalton8fd79552018-01-11 00:46:14 -0500326 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500327 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700328
Brian Salomon1edc5b92016-11-29 13:43:46 -0500329 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700330 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800331
Chris Daltonfaca00d2018-01-19 15:56:07 -0700332 // Mali has support for geometry shaders, but in practice with ccpr they are slower than the
333 // backup impl that only uses vertex shaders.
334 if (kARM_GrGLVendor != ctxInfo.vendor()) {
335 if (ctxInfo.version() >= GR_GL_VER(3,2)) {
336 shaderCaps->fGeometryShaderSupport = true;
337 } else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
338 shaderCaps->fGeometryShaderSupport = true;
339 shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
340 }
Chris Daltonfaca00d2018-01-19 15:56:07 -0700341 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
Chris Dalton8fd79552018-01-11 00:46:14 -0500342 }
csmartdalton1d2aed02017-02-15 21:43:20 -0700343
Brian Salomon1edc5b92016-11-29 13:43:46 -0500344 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800345 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700346 }
347
cdalton9c3f1432016-03-11 10:07:37 -0800348 // Protect ourselves against tracking huge amounts of texture state.
349 static const uint8_t kMaxSaneSamplers = 32;
350 GrGLint maxSamplers;
351 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500352 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
353 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800354 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500355 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800356 }
357 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500358 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800359 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500360 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800361
Brian Salomonbbf05752017-11-30 11:30:48 -0500362 // This is all *very* approximate.
363 switch (ctxInfo.vendor()) {
364 case kNVIDIA_GrGLVendor:
365 // We've seen a range from 100 x 100 (TegraK1, GTX660) up to 300 x 300 (GTX 1070)
366 // but it doesn't clearly align with Pascal vs Maxwell vs Kepler.
367 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 150 * 150;
368 break;
Brian Salomon64fa70a2017-11-30 11:56:25 -0500369 case kImagination_GrGLVendor:
370 // Two PowerVR Rogues, Nexus Player and Chromebook Cb5-312T (PowerVR GX6250), show that
371 // it is always a win to use multitexturing.
372 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
373 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold =
374 std::numeric_limits<size_t>::max();
375 }
376 break;
Brian Salomon0c56d472017-12-04 08:37:44 -0500377 case kATI_GrGLVendor:
378 // So far no AMD GPU shows a performance difference. A tie goes to disabling
379 // multitexturing for simplicity's sake.
380 fShaderCaps->fDisableImageMultitexturingDstRectAreaThreshold = 0;
381 break;
Brian Salomonbbf05752017-11-30 11:30:48 -0500382 default:
383 break;
384 }
385
csmartdalton485a1202016-07-13 10:16:32 -0700386 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
387 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
388 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
389 // limit this decision to specific GPU families rather than basing it on the vendor alone.
390 if (!GR_GL_MUST_USE_VBO &&
391 !fIsCoreProfile &&
392 (kARM_GrGLVendor == ctxInfo.vendor() ||
393 kImagination_GrGLVendor == ctxInfo.vendor() ||
394 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
395 fPreferClientSideDynamicBuffers = true;
396 }
397
Eric Karl5c779752017-05-08 12:02:07 -0700398 if (!contextOptions.fAvoidStencilBuffers) {
399 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
400 this->initFSAASupport(contextOptions, ctxInfo, gli);
401 this->initStencilSupport(ctxInfo);
402 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400403
404 // Setup blit framebuffer
405 if (kGL_GrGLStandard != ctxInfo.standard()) {
406 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
407 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
408 kNoMSAADst_BlitFramebufferFlag |
409 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
410 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
411 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
412 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
413 // limitations.
414 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
415 kResolveMustBeFull_BlitFrambufferFlag |
416 kNoMSAADst_BlitFramebufferFlag |
417 kNoFormatConversion_BlitFramebufferFlag |
418 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
419 }
420 } else {
421 if (fUsesMixedSamples ||
422 ctxInfo.version() >= GR_GL_VER(3,0) ||
423 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
424 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
425 fBlitFramebufferFlags = 0;
426 }
427 }
428
cdalton1dd05422015-06-12 09:01:18 -0700429 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000430
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000431 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000432 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
433 // extension includes glMapBuffer.
434 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
435 fMapBufferFlags |= kSubset_MapFlag;
436 fMapBufferType = kMapBufferRange_MapBufferType;
437 } else {
438 fMapBufferType = kMapBuffer_MapBufferType;
439 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000440 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000441 // Unextended GLES2 doesn't have any buffer mapping.
442 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800443 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800444 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
445 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800446 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
447 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
448 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000449 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
450 fMapBufferFlags = kCanMap_MapFlag;
451 fMapBufferType = kMapBuffer_MapBufferType;
452 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000453 }
454
jvanverthd7a2c1f2015-12-07 07:36:44 -0800455 if (kGL_GrGLStandard == standard) {
456 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
457 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700458 }
Brian Salomon01b476a2018-01-23 11:06:41 -0500459 } else {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400460 if (version >= GR_GL_VER(3, 0) ||
461 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
462 // GL_EXT_unpack_subimage needed to support subtexture rectangles
463 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800464 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400465// TODO: get transfer buffers working in Chrome
466// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
467// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800468 }
469 }
470
joshualitte5b74c62015-06-01 14:17:47 -0700471 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
472 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700473 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700474#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500475 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
476 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
477 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700478 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700479#else
cdalton397536c2016-03-25 12:15:03 -0700480 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700481#endif
joshualitte5b74c62015-06-01 14:17:47 -0700482 }
483
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000484 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000485 fNPOTTextureTileSupport = true;
486 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000487 } else {
488 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000489 // ES3 has no limitations.
490 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
491 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000492 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
493 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
494 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
495 // to alllow arbitrary wrap modes, however.
496 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000497 }
498
bsalomon@google.combcce8922013-03-25 15:38:39 +0000499 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
Adrienne Walker724afe82018-05-15 11:36:26 -0700500
501 if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
502 fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
503 }
504
bsalomon@google.combcce8922013-03-25 15:38:39 +0000505 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
506 // Our render targets are always created with textures as the color
507 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000508 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700509 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
510
511 if (kARM_GrGLVendor == ctxInfo.vendor()) {
512 // On Mali G71, RT's above 4k have been observed to incur a performance cost.
513 fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
514 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000515
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000516 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
517
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000518 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700519 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000520
robertphillips1b8e1b52015-06-24 06:54:10 -0700521#if 0
522 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
523 kQualcomm_GrGLVendor != ctxInfo.vendor();
524#endif
525
csmartdalton9bc11872016-08-09 12:42:47 -0700526 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
527 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700528 }
529
robertphillips63926682015-08-20 09:39:02 -0700530#ifdef SK_BUILD_FOR_WIN
531 // On ANGLE deferring flushes can lead to GPU starvation
532 fPreferVRAMUseOverFlushes = !isANGLE;
533#endif
534
bsalomon7dea7b72015-08-19 08:26:51 -0700535 if (kChromium_GrGLDriver == ctxInfo.driver()) {
536 fMustClearUploadedBufferData = true;
537 }
538
bsalomond08ea5f2015-02-20 06:58:13 -0800539 if (kGL_GrGLStandard == standard) {
540 // ARB allows mixed size FBO attachments, EXT does not.
541 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
542 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
543 fOversizedStencilSupport = true;
544 } else {
545 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
546 }
547 } else {
548 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
549 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
550 }
551
joshualitt58001552015-06-26 12:46:36 -0700552 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700553 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
554 ctxInfo.hasExtension("GL_ARB_draw_indirect");
555 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
556 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700557 (fDrawIndirectSupport &&
558 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700559 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700560 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800561 } else {
562 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700563 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
564 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
565 fBaseInstanceSupport = fDrawIndirectSupport &&
566 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700567 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800568 }
569
ethannicholas28ef4452016-03-25 09:26:03 -0700570 if (kGL_GrGLStandard == standard) {
Brian Salomon01b476a2018-01-23 11:06:41 -0500571 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading"))) {
ethannicholas28ef4452016-03-25 09:26:03 -0700572 fSampleShadingSupport = true;
573 }
574 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
575 fSampleShadingSupport = true;
576 }
577
jvanverth84741b32016-09-30 08:39:02 -0700578 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
579 if (kGL_GrGLStandard == standard) {
580 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
581 fFenceSyncSupport = true;
582 }
Brian Osman93a23462017-06-21 15:13:39 -0400583 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700584 fFenceSyncSupport = true;
585 }
586
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400587 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500588 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500589
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400590 if (kGL_GrGLStandard == standard) {
591 if (version >= GR_GL_VER(4, 1)) {
592 fProgramBinarySupport = true;
593 }
594 } else if (version >= GR_GL_VER(3, 0)) {
595 fProgramBinarySupport = true;
596 }
Ethan Nicholas98ad5b72018-03-13 09:53:02 -0400597 if (fProgramBinarySupport) {
598 GrGLint count;
599 GR_GL_GetIntegerv(gli, GR_GL_NUM_SHADER_BINARY_FORMATS, &count);
600 fProgramBinarySupport = count > 0;
601 }
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400602
bsalomoncdee0092016-01-08 13:20:12 -0800603 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
604 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800605 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700606
Brian Salomon01b476a2018-01-23 11:06:41 -0500607 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
608 this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps);
609 }
610
cdalton4cd67132015-06-10 19:23:46 -0700611 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500612 shaderCaps->applyOptionsOverrides(contextOptions);
Chris Dalton0a94e4c2018-01-18 15:06:50 -0700613
Brian Salomon01b476a2018-01-23 11:06:41 -0500614 // For now these two are equivalent but we could have dst read in shader via some other method.
615 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000616}
617
egdaniel472d44e2015-10-22 08:20:00 -0700618const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
619 bool isCoreProfile) {
620 switch (generation) {
621 case k110_GrGLSLGeneration:
622 if (kGLES_GrGLStandard == standard) {
623 // ES2s shader language is based on version 1.20 but is version
624 // 1.00 of the ES language.
625 return "#version 100\n";
626 } else {
627 SkASSERT(kGL_GrGLStandard == standard);
628 return "#version 110\n";
629 }
630 case k130_GrGLSLGeneration:
631 SkASSERT(kGL_GrGLStandard == standard);
632 return "#version 130\n";
633 case k140_GrGLSLGeneration:
634 SkASSERT(kGL_GrGLStandard == standard);
635 return "#version 140\n";
636 case k150_GrGLSLGeneration:
637 SkASSERT(kGL_GrGLStandard == standard);
638 if (isCoreProfile) {
639 return "#version 150\n";
640 } else {
641 return "#version 150 compatibility\n";
642 }
643 case k330_GrGLSLGeneration:
644 if (kGLES_GrGLStandard == standard) {
645 return "#version 300 es\n";
646 } else {
647 SkASSERT(kGL_GrGLStandard == standard);
648 if (isCoreProfile) {
649 return "#version 330\n";
650 } else {
651 return "#version 330 compatibility\n";
652 }
653 }
cdalton33ad7012016-02-22 07:55:44 -0800654 case k400_GrGLSLGeneration:
655 SkASSERT(kGL_GrGLStandard == standard);
656 if (isCoreProfile) {
657 return "#version 400\n";
658 } else {
659 return "#version 400 compatibility\n";
660 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500661 case k420_GrGLSLGeneration:
662 SkASSERT(kGL_GrGLStandard == standard);
663 if (isCoreProfile) {
664 return "#version 420\n";
665 }
666 else {
667 return "#version 420 compatibility\n";
668 }
egdaniel472d44e2015-10-22 08:20:00 -0700669 case k310es_GrGLSLGeneration:
670 SkASSERT(kGLES_GrGLStandard == standard);
671 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800672 case k320es_GrGLSLGeneration:
673 SkASSERT(kGLES_GrGLStandard == standard);
674 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700675 }
676 return "<no version>";
677}
678
Chris Dalton47c8ed32017-11-15 18:27:09 -0700679bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
680 if (kGLES_GrGLStandard != ctxInfo.standard() &&
681 ctxInfo.version() < GR_GL_VER(4,1) &&
682 !ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
683 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
684 return true;
685 }
686 // glGetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Hopefully the
687 // geometry shaders don't have lower precision than vertex and fragment.
688 for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
689 GrGLint range[2];
690 GrGLint bits;
691 GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
692 if (range[0] < 127 || range[1] < 127 || bits < 23) {
693 return false;
694 }
695 }
696 return true;
697}
698
699void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
egdaniel472d44e2015-10-22 08:20:00 -0700700 GrGLStandard standard = ctxInfo.standard();
701 GrGLVersion version = ctxInfo.version();
702
703 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500704 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700705 **************************************************************************/
706
Brian Salomon1edc5b92016-11-29 13:43:46 -0500707 GrShaderCaps* shaderCaps = fShaderCaps.get();
708 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700709 if (kGLES_GrGLStandard == standard) {
710 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500711 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
712 shaderCaps->fFBFetchSupport = true;
713 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
714 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700715 }
716 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
717 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
Brian Salomon1edc5b92016-11-29 13:43:46 -0500718 shaderCaps->fFBFetchNeedsCustomOutput = false;
719 shaderCaps->fFBFetchSupport = true;
720 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
721 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700722 }
723 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
724 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500725 shaderCaps->fFBFetchNeedsCustomOutput = false;
726 shaderCaps->fFBFetchSupport = true;
727 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
728 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700729 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500730 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700731 }
732
cdaltonc08f1962016-02-12 12:14:06 -0800733 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500734 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800735 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500736 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800737 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
738 }
Brian Salomon41274562017-09-15 09:40:03 -0700739 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
740 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
741 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800742 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500743 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800744 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
745 } else {
Brian Osman71a69952018-05-07 17:07:35 -0400746 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
747 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration /* GLSL ES 3.0 */) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500748 shaderCaps->fNoPerspectiveInterpolationSupport = true;
749 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800750 "GL_NV_shader_noperspective_interpolation";
751 }
752 }
753
Brian Salomon1edc5b92016-11-29 13:43:46 -0500754 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
755 shaderCaps->fGLSLGeneration,
756 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800757
Brian Salomon1edc5b92016-11-29 13:43:46 -0500758 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
759 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800760 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800761
762 // Frag Coords Convention support is not part of ES
Brian Salomon01b476a2018-01-23 11:06:41 -0500763 if (kGLES_GrGLStandard != standard &&
egdaniel8dcdedc2015-11-11 06:27:20 -0800764 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
765 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500766 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800767 }
768
769 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500770 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800771 }
772
cdalton9c3f1432016-03-11 10:07:37 -0800773 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
Brian Osmanc585e202018-04-04 14:08:27 -0400774 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
775 shaderCaps->fExternalTextureSupport = true;
Brian Osman91fba612018-03-15 14:12:04 -0400776 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
Brian Osmanc585e202018-04-04 14:08:27 -0400777 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
778 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
779 // At least one driver has been found that has this extension without the "GL_" prefix.
780 shaderCaps->fExternalTextureSupport = true;
781 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800782 }
783 }
784
cdaltonc04ce672016-03-11 14:07:38 -0800785 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500786 shaderCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800787 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500788 shaderCaps->fTexelFetchSupport =
cdaltonf8a6ce82016-04-11 13:02:05 -0700789 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
790 }
791
Brian Salomon1edc5b92016-11-29 13:43:46 -0500792 if (shaderCaps->fTexelFetchSupport) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700793 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500794 shaderCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
cdaltonf8a6ce82016-04-11 13:02:05 -0700795 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
796 } else {
797 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
798 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500799 shaderCaps->fTexelBufferSupport = true;
cdaltonf8a6ce82016-04-11 13:02:05 -0700800 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500801 shaderCaps->fTexelBufferSupport = true;
802 shaderCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700803 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500804 shaderCaps->fTexelBufferSupport = true;
805 shaderCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700806 }
cdaltonc04ce672016-03-11 14:07:38 -0800807 }
808 }
809
Chris Dalton1d616352017-05-31 12:51:23 -0600810 if (kGL_GrGLStandard == standard) {
811 shaderCaps->fVertexIDSupport = true;
812 } else {
813 // Desktop GLSL 3.30 == ES GLSL 3.00.
814 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
815 }
816
Chris Dalton7c7ff032018-03-28 20:09:58 -0600817 if (kGL_GrGLStandard == standard) {
818 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
819 } else {
820 shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
821 }
822
Chris Dalton47c8ed32017-11-15 18:27:09 -0700823 shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
824 shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
egdaniel472d44e2015-10-22 08:20:00 -0700825}
826
kkinnunencfe62e32015-07-01 02:58:50 -0700827bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700828 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
829
830 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700831 return false;
832 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700833
kkinnunencfe62e32015-07-01 02:58:50 -0700834 if (kGL_GrGLStandard == ctxInfo.standard()) {
835 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
836 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
837 return false;
838 }
839 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700840 if (!hasChromiumPathRendering &&
841 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700842 return false;
843 }
844 }
845 // We only support v1.3+ of GL_NV_path_rendering which allows us to
846 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
847 // additions are detected by checking the existence of the function.
848 // We also use *Then* functions that not all drivers might have. Check
849 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800850 if (!gli->fFunctions.fStencilThenCoverFillPath ||
851 !gli->fFunctions.fStencilThenCoverStrokePath ||
852 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
853 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
854 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700855 return false;
856 }
857 return true;
858}
bsalomon1aa20292016-01-22 08:16:09 -0800859
Brian Salomon71d9d842016-11-03 13:42:00 -0400860bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800861 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800862 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800863 std::function<bool ()> bindRenderTarget,
864 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400865 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800866 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400867 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800868 return false;
869 }
bsalomon7928ef62016-01-05 10:26:39 -0800870
bsalomon76148af2016-01-12 11:13:47 -0800871 GrGLenum readFormat;
872 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400873 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800874 return false;
875 }
876
bsalomon1aa20292016-01-22 08:16:09 -0800877 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800878 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
879 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
880 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
881 // 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 -0500882 // The manual does not seem to fully match the spec as the spec allows integer formats
883 // when the bound color buffer is an integer buffer. It doesn't specify which integer
884 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500885 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
886 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
887 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800888 return false;
889 }
890 // There is also a set of allowed types, but all the types we use are in the set:
891 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
892 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
893 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
894 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
895 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
896 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
897 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800898 return true;
piotaixre4b23142014-10-02 10:57:53 -0700899 }
bsalomon7928ef62016-01-05 10:26:39 -0800900
bsalomon76148af2016-01-12 11:13:47 -0800901 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500902 switch (fConfigTable[surfaceConfig].fFormatType) {
903 case kNormalizedFixedPoint_FormatType:
904 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
905 return true;
906 }
907 break;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500908 case kFloat_FormatType:
909 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
910 return true;
911 }
912 break;
bsalomon7928ef62016-01-05 10:26:39 -0800913 }
914
Brian Salomon71d9d842016-11-03 13:42:00 -0400915 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800916 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -0400917 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800918 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800919 if (!bindRenderTarget()) {
920 return false;
921 }
922 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
923 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800924 rpFormat->fFormat = format;
925 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -0800926 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -0800927 }
928
Brian Salomon71d9d842016-11-03 13:42:00 -0400929 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
930 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700931}
932
Eric Karl5c779752017-05-08 12:02:07 -0700933void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
934 const GrGLInterface* gli) {
935 // We need dual source blending and the ability to disable multisample in order to support mixed
936 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
937 // renderer is available and enabled; no other path renderers support this feature.
938 if (fMultisampleDisableSupport &&
939 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -0400940 this->shaderCaps()->pathRenderingSupport()
941#if GR_TEST_UTILS
942 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
943#endif
944 ) {
Eric Karl5c779752017-05-08 12:02:07 -0700945 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -0400946 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -0700947 }
948
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000949 if (kGL_GrGLStandard != ctxInfo.standard()) {
Greg Daniel25019172017-10-26 13:32:33 -0400950 if (ctxInfo.version() >= GR_GL_VER(3,0) &&
951 ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
952 // The gallium llvmpipe renderer for es3.0 does not have textureRed support even though
953 // it is part of the spec. Thus alpha8 will not be renderable for those devices.
954 fAlpha8IsRenderable = true;
955 }
Brian Salomon25d07fc2018-03-07 09:01:05 -0500956 // We prefer multisampled-render-to-texture extensions over ES3 MSAA because we've observed
957 // ES3 driver bugs on at least one device with a tiled GPU (N10). However, if we're using
958 // mixed samples we can't use multisampled-render-to-texture.
959 if (fUsesMixedSamples) {
960 fMSFBOType = kMixedSamples_MSFBOType;
961 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000962 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
963 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
964 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400965 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
966 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400967 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -0400968 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -0400969 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400970 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000971 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
972 fMSFBOType = kES_Apple_MSFBOType;
973 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000974 } else {
egdanieleed519e2016-01-15 11:36:18 -0800975 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700976 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -0400977 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
978 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400979
Brian Salomon00731b42016-10-14 11:30:51 -0400980 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -0400981 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
982 // Core profile removes ALPHA8 support.
983 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
984 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
985 // present.
986 fAlpha8IsRenderable = true;
987 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000988 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
989 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -0400990 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000991 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000992 }
Eric Karl5c779752017-05-08 12:02:07 -0700993
Brian Salomon01b476a2018-01-23 11:06:41 -0500994 // We disable MSAA across the board for Intel GPUs for performance reasons.
Robert Phillips3b3307f2017-05-24 07:44:02 -0400995 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
996 fMSFBOType = kNone_MSFBOType;
997 }
998
Eric Karl5c779752017-05-08 12:02:07 -0700999 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
1000 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
1001 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
Eric Karl5c779752017-05-08 12:02:07 -07001002 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001003}
1004
cdalton1dd05422015-06-12 09:01:18 -07001005void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001006 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -07001007
Greg Daniel210883c2017-11-27 15:14:01 -05001008 bool layoutQualifierSupport = false;
1009 if ((kGL_GrGLStandard == fStandard && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
1010 (kGLES_GrGLStandard == fStandard && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
1011 layoutQualifierSupport = true;
1012 }
1013
cdalton1dd05422015-06-12 09:01:18 -07001014 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1015 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001016 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001017 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
1018 layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001019 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001020 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001021 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1022 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001023 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
Greg Daniel210883c2017-11-27 15:14:01 -05001024 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
cdalton1dd05422015-06-12 09:01:18 -07001025 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001026 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001027 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1028 // slow on a particular platform.
joel.liang9764c402015-07-09 19:46:18 -07001029 }
cdalton1dd05422015-06-12 09:01:18 -07001030}
1031
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001032namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001033const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001034}
1035
Eric Karl5c779752017-05-08 12:02:07 -07001036void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001037
1038 // Build up list of legal stencil formats (though perhaps not supported on
1039 // the particular gpu/driver) from most preferred to least.
1040
1041 // these consts are in order of most preferred to least preferred
1042 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1043
1044 static const StencilFormat
1045 // internal Format stencil bits total bits packed?
1046 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1047 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1048 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1049 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001050 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001051 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1052
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001053 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001054 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001055 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001056 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1057 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1058
1059 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1060 // require FBO support we can expect these are legal formats and don't
1061 // check. These also all support the unsized GL_STENCIL_INDEX.
1062 fStencilFormats.push_back() = gS8;
1063 fStencilFormats.push_back() = gS16;
1064 if (supportsPackedDS) {
1065 fStencilFormats.push_back() = gD24S8;
1066 }
1067 fStencilFormats.push_back() = gS4;
1068 if (supportsPackedDS) {
1069 fStencilFormats.push_back() = gDS;
1070 }
1071 } else {
1072 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1073 // for other formats.
1074 // ES doesn't support using the unsized format.
1075
1076 fStencilFormats.push_back() = gS8;
1077 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001078 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1079 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001080 fStencilFormats.push_back() = gD24S8;
1081 }
1082 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1083 fStencilFormats.push_back() = gS4;
1084 }
1085 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001086}
1087
Brian Osman71a18892017-08-10 10:23:25 -04001088void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001089
Brian Osman71a18892017-08-10 10:23:25 -04001090 // We are called by the base class, which has already called beginObject(). We choose to nest
1091 // all of our caps information in a named sub-object.
1092 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001093
Brian Osman71a18892017-08-10 10:23:25 -04001094 writer->beginArray("Stencil Formats");
1095
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001096 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001097 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001098 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1099 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1100 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001101 }
1102
Brian Osman71a18892017-08-10 10:23:25 -04001103 writer->endArray();
1104
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001105 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001106 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001107 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001108 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001109 "IMG MS To Texture",
1110 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001111 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001112 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001113 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001114 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1115 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1116 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1117 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1118 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001119 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001120
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001121 static const char* kInvalidateFBTypeStr[] = {
1122 "None",
1123 "Discard",
1124 "Invalidate",
1125 };
1126 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1127 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1128 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1129 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001130
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001131 static const char* kMapBufferTypeStr[] = {
1132 "None",
1133 "MapBuffer",
1134 "MapBufferRange",
1135 "Chromium",
1136 };
1137 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1138 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1139 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1140 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1141 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1142
Brian Osman71a18892017-08-10 10:23:25 -04001143 writer->appendBool("Core Profile", fIsCoreProfile);
1144 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1145 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1146 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1147 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1148 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1149 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1150 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1151 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001152
Brian Osman71a18892017-08-10 10:23:25 -04001153 writer->appendBool("Texture Usage support", fTextureUsageSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001154 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1155 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1156 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
Brian Osman71a18892017-08-10 10:23:25 -04001157 writer->appendBool("Debug support", fDebugSupport);
1158 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1159 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1160 writer->appendBool("Base instance support", fBaseInstanceSupport);
1161 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1162 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1163 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1164 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1165 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1166 writer->appendBool("BGRA to RGBA readback conversions are slow",
1167 fRGBAToBGRAReadbackConversionsAreSlow);
Robert Phillipsf2ec0242018-03-01 16:51:25 -05001168 writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
Brian Salomon43f8bf02017-10-18 08:33:29 -04001169 writer->appendBool("Draw To clear color", fUseDrawToClearColor);
1170 writer->appendBool("Draw To clear stencil clip", fUseDrawToClearStencilClip);
Brian Osman71a18892017-08-10 10:23:25 -04001171 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1172 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1173 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1174 fUseDrawInsteadOfAllRenderTargetWrites);
Chris Daltoncc604e52017-10-06 16:27:32 -06001175 writer->appendBool("Max instances per glDrawArraysInstanced without crashing (or zero)",
1176 fMaxInstancesPerDrawArraysWithoutCrashing);
bsalomon41e4384e2016-01-08 09:12:44 -08001177
Brian Osman71a18892017-08-10 10:23:25 -04001178 writer->beginArray("configs");
1179
bsalomon41e4384e2016-01-08 09:12:44 -08001180 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001181 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001182 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1183 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1184 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001185 writer->appendHexU32("e_format_read_pixels",
1186 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
Brian Osman71a18892017-08-10 10:23:25 -04001187 writer->appendHexU32(
1188 "e_format_teximage",
1189 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1190 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1191 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1192 writer->appendHexU32("i_for_renderbuffer",
1193 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1194 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001195 }
1196
Brian Osman71a18892017-08-10 10:23:25 -04001197 writer->endArray();
1198 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001199}
1200
bsalomon41e4384e2016-01-08 09:12:44 -08001201bool GrGLCaps::bgraIsInternalFormat() const {
1202 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1203}
1204
bsalomon76148af2016-01-12 11:13:47 -08001205bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1206 GrGLenum* internalFormat, GrGLenum* externalFormat,
1207 GrGLenum* externalType) const {
1208 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1209 externalFormat, externalType)) {
1210 return false;
1211 }
1212 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1213 return true;
1214}
1215
bsalomon76148af2016-01-12 11:13:47 -08001216bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1217 GrGLenum* externalFormat, GrGLenum* externalType) const {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001218 if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage,
bsalomon76148af2016-01-12 11:13:47 -08001219 externalFormat, externalType)) {
1220 return false;
1221 }
1222 return true;
1223}
1224
1225bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001226 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1227 return true;
1228}
1229
1230bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1231 ExternalFormatUsage usage, GrGLenum* externalFormat,
1232 GrGLenum* externalType) const {
1233 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001234
1235 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1236 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1237
1238 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
Brian Salomon19eaf2d2018-03-19 16:06:44 -04001239 // made to work. However, this is complicated by the use of GL_RED for alpha-only textures but
1240 // is not needed currently.
bsalomon76148af2016-01-12 11:13:47 -08001241 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1242 return false;
1243 }
1244
1245 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1246 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1247
bsalomone9573312016-01-25 14:33:25 -08001248 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1249 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1250 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1251 // texture, not the red component.
1252 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
Brian Salomone609e812018-01-17 14:00:47 -05001253 if (GR_GL_RED == *externalFormat) {
bsalomone9573312016-01-25 14:33:25 -08001254 *externalFormat = GR_GL_ALPHA;
1255 }
1256 }
1257
bsalomon76148af2016-01-12 11:13:47 -08001258 return true;
1259}
1260
brianosman20471892016-12-02 06:43:32 -08001261void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1262 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001263 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001264 /*
1265 Comments on renderability of configs on various GL versions.
1266 OpenGL < 3.0:
1267 no built in support for render targets.
1268 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1269 format RGB, RGBA and NV float formats we don't use.
1270 This is the following:
1271 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1272 RGB10_A2, RGBA12,RGBA16
1273 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1274 since they aren't required by later standards and the driver can simply return
1275 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1276 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1277 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1278 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1279 This adds a lot of additional renderable sized formats, including ALPHA8.
1280 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1281 16F, 32I, 32UI, and 32F variants).
1282 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1283
1284 For both the above extensions we limit ourselves to those that are also required by
1285 OpenGL 3.0.
1286
1287 OpenGL 3.0:
1288 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1289 but are not required to be supported as renderable textures/renderbuffer.
1290 Required renderable color formats:
1291 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1292 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1293 RGB10_A2.
1294 - R11F_G11F_B10F.
1295 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1296 and RG8UI.
1297 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1298 - ALPHA8
1299
1300 OpenGL 3.1, 3.2, 3.3
1301 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1302 OpengGL 3.3, 4.0, 4.1
1303 Adds RGB10_A2UI.
1304 OpengGL 4.2
1305 Adds
1306 - RGB5_A1, RGBA4
1307 - RGB565
1308 OpenGL 4.4
1309 Does away with the separate list and adds a column to the sized internal color format
1310 table. However, no new formats become required color renderable.
1311
1312 ES 2.0
1313 color renderable: RGBA4, RGB5_A1, RGB565
1314 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1315 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1316 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1317 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1318 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1319 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1320
1321 ES 3.0
1322 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1323 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1324 RGB5_A1.
1325 - RGB8 and RGB565.
1326 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1327 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1328 ES 3.1
1329 Adds RGB10_A2, RGB10_A2UI,
1330 ES 3.2
1331 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1332 */
Brian Salomon44804c02018-01-23 16:51:28 -05001333
1334 // Correctness workarounds.
1335 bool disableTextureRedForMesa = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001336 bool disableSRGBForX86PowerVR = false;
1337 bool disableSRGBWriteControlForAdreno4xx = false;
1338 bool disableR8TexStorageForANGLEGL = false;
1339 bool disableSRGBRenderWithMSAAForMacAMD = false;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001340 bool disableRGB8ForMali400 = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001341
1342 if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
1343 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
1344 // and GL_RG on FBO textures.
1345 disableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
1346
1347 bool isX86PowerVR = false;
1348#if defined(SK_CPU_X86)
1349 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1350 isX86PowerVR = true;
1351 }
1352#endif
Brian Salomon44804c02018-01-23 16:51:28 -05001353 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1354 // blacklist that device (and any others that might be sharing the same driver).
1355 disableSRGBForX86PowerVR = isX86PowerVR;
1356 disableSRGBWriteControlForAdreno4xx = kAdreno4xx_GrGLRenderer == ctxInfo.renderer();
1357
1358 // Angle with es2->GL has a bug where it will hang trying to call TexSubImage on GL_R8
1359 // formats on miplevels > 0. We already disable texturing on gles > 2.0 so just need to
1360 // check that we are not going to OpenGL.
1361 disableR8TexStorageForANGLEGL = GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
1362
1363 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers.
1364#if defined(SK_BUILD_FOR_MAC)
1365 disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
1366#endif
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001367 // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8.
1368 disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
Brian Salomon44804c02018-01-23 16:51:28 -05001369 }
1370
Brian Salomon71d9d842016-11-03 13:42:00 -04001371 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1372 ConfigInfo::kFBOColorAttachment_Flag;
1373 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001374 if (kNone_MSFBOType != fMSFBOType) {
1375 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1376 }
bsalomon41e4384e2016-01-08 09:12:44 -08001377 GrGLStandard standard = ctxInfo.standard();
1378 GrGLVersion version = ctxInfo.version();
1379
cblume790d5132016-02-29 11:13:29 -08001380 bool texStorageSupported = false;
1381 if (kGL_GrGLStandard == standard) {
1382 // The EXT version can apply to either GL or GLES.
1383 texStorageSupported = version >= GR_GL_VER(4,2) ||
1384 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1385 ctxInfo.hasExtension("GL_EXT_texture_storage");
1386 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001387 texStorageSupported = version >= GR_GL_VER(3,0) ||
1388 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001389 }
1390
cdalton74b8d322016-04-11 14:47:28 -07001391 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1392
Brian Salomone609e812018-01-17 14:00:47 -05001393 bool textureRedSupport = false;
Brian Salomon44804c02018-01-23 16:51:28 -05001394
1395 if (!disableTextureRedForMesa) {
Brian Salomone609e812018-01-17 14:00:47 -05001396 if (kGL_GrGLStandard == standard) {
1397 textureRedSupport =
1398 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
1399 } else {
1400 textureRedSupport =
1401 version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
1402 }
1403 }
1404
bsalomon30447372015-12-21 09:03:05 -08001405 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1406 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001407 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001408 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001409 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001410 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001411
1412 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1413 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001414 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001415 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001416 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001417 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001418 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1419 if (kGL_GrGLStandard == standard) {
1420 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1421 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001422 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001423 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1424 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1425 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1426 }
egdaniel4999df82016-01-07 17:06:04 -08001427 }
cblume790d5132016-02-29 11:13:29 -08001428 if (texStorageSupported) {
1429 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1430 }
cdalton74b8d322016-04-11 14:47:28 -07001431 if (texelBufferSupport) {
1432 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1433 }
bsalomoncdee0092016-01-08 13:20:12 -08001434 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001435
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001436 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1437 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8;
1438 // Our external RGB data always has a byte where alpha would be. When calling read pixels we
1439 // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would
1440 // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't
1441 // currently expect to ever read back GrColorType::kRGB_888x because our implementation of
1442 // supportedReadPixelsColorType never returns it.
1443 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
1444 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1445 fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1446 fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1447 if (kGL_GrGLStandard == standard) {
1448 // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a
1449 // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL
1450 // we don't support MSAA for GL_RGB8. On 4.2+ we could check using
1451 // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this
1452 // becomes an issue.
1453 // This also would probably work in mixed-samples mode where there is no MSAA color buffer
1454 // but we don't support that just for simplicity's sake.
1455 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags;
1456 } else {
1457 // 3.0 and the extension support this as a render buffer format.
1458 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
1459 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags;
1460 }
1461 }
1462 if (texStorageSupported) {
1463 fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1464 }
1465 fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1466 if (disableRGB8ForMali400) {
1467 fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0;
1468 }
1469
1470 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001471 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001472 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001473 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001474
1475 // TexStorage requires using a sized internal format and BGRA8 is only supported if we have the
1476 // GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texutre_storage and
1477 // GL_EXT_texture_format_BGRA8888.
1478 bool supportsBGRATexStorage = false;
1479
bsalomon41e4384e2016-01-08 09:12:44 -08001480 if (kGL_GrGLStandard == standard) {
1481 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1482 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1483 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1484 // Since the internal format is RGBA8, it is also renderable.
1485 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1486 allRenderFlags;
1487 }
Greg Daniel0ff79b22018-02-15 12:33:33 -05001488 // Since we are using RGBA8 we can use tex storage.
1489 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001490 } else {
1491 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1492 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
Alexis Hetu0e90f982018-03-15 10:08:42 -04001493 if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1494 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1495 nonMSAARenderFlags;
1496
1497 if (ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1498 supportsBGRATexStorage = true;
1499 }
1500 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
1501 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
1502 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1503 ConfigInfo::kRenderableWithMSAA_Flag;
1504 }
1505 } else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001506 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1507 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1508 // driver remembers the external format when the texture is created (with TexImage).
1509 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1510 // We could work around this, but it adds even more state tracking to code that is
1511 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1512 // This also side-steps some ambiguous interactions with the texture storage extension.
1513 if (version >= GR_GL_VER(3,0)) {
1514 // The APPLE extension doesn't make this renderable.
1515 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Greg Daniel0ff79b22018-02-15 12:33:33 -05001516 supportsBGRATexStorage = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001517 }
bsalomon41e4384e2016-01-08 09:12:44 -08001518 }
1519 }
Brian Osman48c99192017-06-02 08:45:06 -04001520
Greg Daniel0ff79b22018-02-15 12:33:33 -05001521 if (texStorageSupported && supportsBGRATexStorage) {
Brian Salomon44804c02018-01-23 16:51:28 -05001522 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001523 }
bsalomoncdee0092016-01-08 13:20:12 -08001524 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001525
Brian Osman2b23c4b2018-06-01 12:25:08 -04001526 // We only enable srgb support if both textures and FBOs support srgb.
bsalomon41e4384e2016-01-08 09:12:44 -08001527 if (kGL_GrGLStandard == standard) {
1528 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001529 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001530 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1531 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1532 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001533 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001534 }
1535 }
1536 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001537 if (fSRGBSupport) {
1538 fSRGBWriteControl = true;
1539 }
bsalomon41e4384e2016-01-08 09:12:44 -08001540 } else {
brianosman20471892016-12-02 06:43:32 -08001541 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Salomon44804c02018-01-23 16:51:28 -05001542 if (disableSRGBForX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001543 fSRGBSupport = false;
1544 }
bsalomon41e4384e2016-01-08 09:12:44 -08001545 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1546 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001547 // See https://bug.skia.org/5329 for Adreno4xx issue.
Brian Salomon44804c02018-01-23 16:51:28 -05001548 fSRGBWriteControl = !disableSRGBWriteControlForAdreno4xx &&
brianosmanc9986b62016-05-23 06:23:27 -07001549 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001550 }
brianosman20471892016-12-02 06:43:32 -08001551
1552 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1553 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1554 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1555 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1556 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1557 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1558 // affects Windows.
1559 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1560 fSRGBSupport = false;
1561 }
1562
Brian Osman48c99192017-06-02 08:45:06 -04001563 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1564 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1565 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1566
Brian Osman67999392017-05-31 16:19:34 -04001567 uint32_t srgbRenderFlags = allRenderFlags;
Brian Salomon44804c02018-01-23 16:51:28 -05001568 if (disableSRGBRenderWithMSAAForMacAMD) {
Brian Osman67999392017-05-31 16:19:34 -04001569 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1570 }
Brian Osman67999392017-05-31 16:19:34 -04001571
bsalomon30447372015-12-21 09:03:05 -08001572 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1573 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1574 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1575 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001576 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001577 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001578 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001579 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001580 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001581 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001582 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001583 }
Brian Osman48c99192017-06-02 08:45:06 -04001584 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1585 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001586 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1587 }
bsalomoncdee0092016-01-08 13:20:12 -08001588 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001589 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1590 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1591 // is in this format, for example).
1592 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1593 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1594 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1595 // external format is GL_BGRA.
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001596 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
brianosmana6359362016-03-21 06:55:37 -07001597 GR_GL_BGRA;
1598 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1599 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001600 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001601 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001602 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001603 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001604
brianosmana6359362016-03-21 06:55:37 -07001605 if (texStorageSupported) {
1606 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1607 }
1608 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1609
bsalomon30447372015-12-21 09:03:05 -08001610 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1611 if (this->ES2CompatibilitySupport()) {
1612 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1613 } else {
1614 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1615 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001616 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001617 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001618 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001619 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001620 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1621 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001622 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001623 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1624 }
1625 } else {
1626 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1627 }
cblume790d5132016-02-29 11:13:29 -08001628 // 565 is not a sized internal format on desktop GL. So on desktop with
1629 // 565 we always use an unsized internal format to let the system pick
1630 // the best sized format to convert the 565 data to. Since TexStorage
1631 // only allows sized internal formats we disallow it.
1632 //
1633 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1634 // update.
1635 if (texStorageSupported && kGL_GrGLStandard != standard) {
1636 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1637 }
bsalomoncdee0092016-01-08 13:20:12 -08001638 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001639
1640 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1641 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001642 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001643 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001644 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001645 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001646 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1647 if (kGL_GrGLStandard == standard) {
1648 if (version >= GR_GL_VER(4, 2)) {
1649 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1650 }
1651 } else {
1652 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1653 }
cblume790d5132016-02-29 11:13:29 -08001654 if (texStorageSupported) {
1655 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1656 }
bsalomoncdee0092016-01-08 13:20:12 -08001657 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001658
Brian Osman10fc6fd2018-03-02 11:01:10 -05001659 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1660 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001661 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
Brian Osman10fc6fd2018-03-02 11:01:10 -05001662 GR_GL_RGBA;
1663 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
1664 GR_GL_UNSIGNED_INT_2_10_10_10_REV;
1665 fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1666 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 0)) {
1667 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1668 allRenderFlags;
1669 }
1670 if (texStorageSupported) {
1671 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1672 }
1673 if (texelBufferSupport) {
1674 fConfigTable[kRGBA_1010102_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1675 }
1676 fConfigTable[kRGBA_1010102_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1677
Greg Danielef59d872017-11-17 16:47:21 -05001678 bool alpha8IsValidForGL = kGL_GrGLStandard == standard &&
1679 (!fIsCoreProfile || version <= GR_GL_VER(3, 0));
1680
1681 ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
1682 alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1683 alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1684 if (alpha8IsValidForGL || (kGL_GrGLStandard != standard && version < GR_GL_VER(3, 0))) {
1685 alphaInfo.fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001686 }
Greg Danielef59d872017-11-17 16:47:21 -05001687 alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1688 alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001689 alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
Greg Danielef59d872017-11-17 16:47:21 -05001690 alphaInfo.fSwizzle = GrSwizzle::AAAA();
1691 if (fAlpha8IsRenderable && alpha8IsValidForGL) {
1692 alphaInfo.fFlags |= allRenderFlags;
1693 }
1694
1695 ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
1696 redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1697 redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1698 redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1699 redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001700 redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001701 redInfo.fSwizzle = GrSwizzle::RRRR();
Robert Phillips5ab72762017-06-07 12:04:18 -04001702
Brian Osman48c99192017-06-02 08:45:06 -04001703 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1704 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001705 if (!disableR8TexStorageForANGLEGL) {
Greg Danielef59d872017-11-17 16:47:21 -05001706 alphaInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1707 }
1708 redInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1709 }
1710
Brian Salomone609e812018-01-17 14:00:47 -05001711 if (textureRedSupport) {
Greg Danielef59d872017-11-17 16:47:21 -05001712 redInfo.fFlags |= ConfigInfo::kTextureable_Flag | allRenderFlags;
1713 if (texelBufferSupport) {
1714 redInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1715 }
1716
1717 fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
1718 } else {
1719 redInfo.fFlags = 0;
1720
1721 fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
cblume790d5132016-02-29 11:13:29 -08001722 }
bsalomon41e4384e2016-01-08 09:12:44 -08001723
Greg Daniel7af060a2017-12-05 16:27:11 -05001724 ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
1725 grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1726 grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1727 grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1728 grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001729 grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
Greg Daniel7af060a2017-12-05 16:27:11 -05001730 grayLumInfo.fSwizzle = GrSwizzle::RGBA();
1731 if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) ||
1732 (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) {
1733 grayLumInfo.fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001734 }
Greg Daniel7af060a2017-12-05 16:27:11 -05001735
1736 ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
1737 grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1738 grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
1739 grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
1740 grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001741 grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Daniel7af060a2017-12-05 16:27:11 -05001742 grayRedInfo.fSwizzle = GrSwizzle::RRRA();
1743 grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag;
1744
1745#if 0 // Leaving Gray8 as non-renderable, to keep things simple and match raster. Needs to be
1746 // updated to support Gray8_as_Lum and Gray8_as_red if this is ever enabled.
Brian Osman986563b2017-01-10 14:20:02 -05001747 if (this->textureRedSupport() ||
1748 (kDesktop_ARB_MSFBOType == this->msFBOType() &&
1749 ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
1750 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1751 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1752 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
1753 fConfigTable[kGray_8_GrPixelConfig].fFlags |= allRenderFlags;
1754 }
1755#endif
Brian Osman48c99192017-06-02 08:45:06 -04001756 if (texStorageSupported && !isCommandBufferES2) {
Brian Salomon44804c02018-01-23 16:51:28 -05001757 if (!disableR8TexStorageForANGLEGL) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001758 grayLumInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1759 }
1760 grayRedInfo.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1761 }
1762
Brian Salomone609e812018-01-17 14:00:47 -05001763 if (textureRedSupport) {
Greg Daniel7af060a2017-12-05 16:27:11 -05001764 if (texelBufferSupport) {
1765 grayRedInfo.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1766 }
1767 fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
1768 } else {
1769 grayRedInfo.fFlags = 0;
1770 fConfigTable[kGray_8_GrPixelConfig] = grayLumInfo;
Brian Osman986563b2017-01-10 14:20:02 -05001771 }
1772
bsalomon41e4384e2016-01-08 09:12:44 -08001773 // Check for [half] floating point texture support
1774 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1775 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1776 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1777 bool hasFPTextures = false;
1778 bool hasHalfFPTextures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001779 bool rgIsTexturable = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001780 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001781 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001782
1783 if (kGL_GrGLStandard == standard) {
Greg Danielef59d872017-11-17 16:47:21 -05001784 if (version >= GR_GL_VER(3, 0)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001785 hasFPTextures = true;
1786 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001787 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001788 }
1789 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001790 if (version >= GR_GL_VER(3, 0)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001791 hasFPTextures = true;
1792 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001793 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001794 } else {
1795 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1796 ctxInfo.hasExtension("GL_OES_texture_float")) {
1797 hasFPTextures = true;
1798 }
1799 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1800 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1801 hasHalfFPTextures = true;
1802 }
1803 }
1804 }
bsalomon30447372015-12-21 09:03:05 -08001805
csmartdalton6aa0e112017-02-08 16:14:11 -05001806 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1807 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1808 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1809 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1810 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001811 fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
csmartdalton6aa0e112017-02-08 16:14:11 -05001812 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1813 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
1814 if (hasFPTextures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001815 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
csmartdalton6aa0e112017-02-08 16:14:11 -05001816 // For now we only enable rendering to float on desktop, because on ES we'd have to
1817 // solve many precision issues and no clients actually want this yet.
1818 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1819 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1820 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1821 }
bsalomon41e4384e2016-01-08 09:12:44 -08001822 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001823 if (texStorageSupported) {
1824 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1825 }
1826 if (texelBufferSupport) {
1827 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1828 }
1829 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001830 }
bsalomon30447372015-12-21 09:03:05 -08001831
Greg Danielef59d872017-11-17 16:47:21 -05001832 GrGLenum redHalfExternalType;
Brian Osmanb092cea2017-11-17 19:14:55 +00001833 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
Greg Danielef59d872017-11-17 16:47:21 -05001834 redHalfExternalType = GR_GL_HALF_FLOAT;
Brian Osmanb092cea2017-11-17 19:14:55 +00001835 } else {
Greg Danielef59d872017-11-17 16:47:21 -05001836 redHalfExternalType = GR_GL_HALF_FLOAT_OES;
Brian Osmanb092cea2017-11-17 19:14:55 +00001837 }
Greg Danielef59d872017-11-17 16:47:21 -05001838 ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
1839 redHalf.fFormats.fExternalType = redHalfExternalType;
1840 redHalf.fFormatType = kFloat_FormatType;
1841 redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
1842 redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001843 redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
Greg Danielef59d872017-11-17 16:47:21 -05001844 redHalf.fSwizzle = GrSwizzle::RRRR();
Brian Salomone609e812018-01-17 14:00:47 -05001845 if (textureRedSupport && hasHalfFPTextures) {
Greg Danielef59d872017-11-17 16:47:21 -05001846 redHalf.fFlags = ConfigInfo::kTextureable_Flag;
1847
csmartdalton6aa0e112017-02-08 16:14:11 -05001848 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
Brian Salomone609e812018-01-17 14:00:47 -05001849 (textureRedSupport && ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
Greg Danielef59d872017-11-17 16:47:21 -05001850 redHalf.fFlags |= fpRenderFlags;
1851 }
1852
1853 if (texStorageSupported && !isCommandBufferES2) {
1854 redHalf.fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1855 }
1856
1857 if (texelBufferSupport) {
1858 redHalf.fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
csmartdalton6aa0e112017-02-08 16:14:11 -05001859 }
1860 }
Greg Danielef59d872017-11-17 16:47:21 -05001861 fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
bsalomon30447372015-12-21 09:03:05 -08001862
1863 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1864 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001865 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
bsalomon76148af2016-01-12 11:13:47 -08001866 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04001867 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08001868 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1869 } else {
1870 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1871 }
bsalomon7928ef62016-01-05 10:26:39 -08001872 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001873 if (hasHalfFPTextures) {
1874 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1875 // ES requires 3.2 or EXT_color_buffer_half_float.
1876 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1877 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1878 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1879 }
1880 }
cblume790d5132016-02-29 11:13:29 -08001881 if (texStorageSupported) {
1882 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1883 }
cdalton74b8d322016-04-11 14:47:28 -07001884 if (texelBufferSupport) {
1885 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1886 }
bsalomoncdee0092016-01-08 13:20:12 -08001887 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001888
bsalomon30447372015-12-21 09:03:05 -08001889 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1890
1891 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001892 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1893 ctxInfo.version() >= GR_GL_VER(3,0));
1894 // All ES versions (thus far) require sized internal formats for render buffers.
1895 // TODO: Always use sized internal format?
1896 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1897
bsalomon30447372015-12-21 09:03:05 -08001898 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001899 // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the
1900 // <format> param to glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001901 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001902 fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage];
bsalomon76148af2016-01-12 11:13:47 -08001903 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1904 fConfigTable[i].fFormats.fSizedInternalFormat :
1905 fConfigTable[i].fFormats.fBaseInternalFormat;
1906 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001907 fConfigTable[i].fFormats.fSizedInternalFormat :
1908 fConfigTable[i].fFormats.fBaseInternalFormat;
1909 }
Brian Salomon44804c02018-01-23 16:51:28 -05001910 // If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
1911 // kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
1912 // sized internal format. This is because there is no valid 8 bit alpha sized internal format
1913 // in ES.
1914 if (useSizedTexFormats && kGLES_GrGLStandard == ctxInfo.standard() && !textureRedSupport) {
1915 SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
1916 SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
1917 GR_GL_ALPHA8);
Greg Daniel8713b882017-10-26 15:15:47 -04001918 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
1919 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Danielef59d872017-11-17 16:47:21 -05001920 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
1921 fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
Greg Daniel8713b882017-10-26 15:15:47 -04001922 }
1923
bsalomon30447372015-12-21 09:03:05 -08001924 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1925 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1926 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1927 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1928 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001929 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001930 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001931
1932 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1933 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1934 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1935 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001936 }
Brian Salomon5fba7ad2018-03-22 10:01:16 -04001937 // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must
1938 // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to
1939 // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x'
1940 // slot.
1941 fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1942 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001943
1944 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1945 // as a base format.
1946 // GL_EXT_texture_format_BGRA8888:
1947 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1948 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1949 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001950 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001951 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1952 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1953 // glTexImage (just for glTexStorage).
Greg Daniel0ff79b22018-02-15 12:33:33 -05001954 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001955 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1956 }
1957
bsalomoncdee0092016-01-08 13:20:12 -08001958 // If we don't have texture swizzle support then the shader generator must insert the
1959 // swizzle into shader code.
1960 if (!this->textureSwizzleSupport()) {
1961 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001962 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08001963 }
1964 }
1965
bsalomon7f9b2e42016-01-12 13:29:26 -08001966 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1967 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1968 // gets written to the single component.
Brian Salomone609e812018-01-17 14:00:47 -05001969 if (textureRedSupport) {
bsalomon7f9b2e42016-01-12 13:29:26 -08001970 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1971 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1972 if (GrPixelConfigIsAlphaOnly(config) &&
1973 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001974 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08001975 }
1976 }
1977 }
1978
Greg Daniel81e7bf82017-07-19 14:47:42 -04001979 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1980 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Brian Salomonbdecacf2018-02-02 20:32:49 -05001981 // We assume that MSAA rendering is supported only if we support non-MSAA rendering.
1982 SkASSERT(ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags);
Greg Daniel6bd729d2017-07-31 09:38:23 -04001983 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04001984 (ctxInfo.version() >= GR_GL_VER(4,2) ||
1985 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04001986 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04001987 int count;
1988 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
1989 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1990 1, &count);
1991 if (count) {
1992 int* temp = new int[count];
1993 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
1994 temp);
Brian Salomonbdecacf2018-02-02 20:32:49 -05001995 // GL has a concept of MSAA rasterization with a single sample but we do not.
1996 if (count && temp[count - 1] == 1) {
1997 --count;
1998 SkASSERT(!count || temp[count -1] > 1);
1999 }
Greg Daniel81e7bf82017-07-19 14:47:42 -04002000 fConfigTable[i].fColorSampleCounts.setCount(count+1);
Brian Salomonbdecacf2018-02-02 20:32:49 -05002001 // We initialize our supported values with 1 (no msaa) and reverse the order
Greg Daniel81e7bf82017-07-19 14:47:42 -04002002 // returned by GL so that the array is ascending.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002003 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002004 for (int j = 0; j < count; ++j) {
2005 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
2006 }
2007 delete[] temp;
2008 }
2009 } else {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002010 // Fake out the table using some semi-standard counts up to the max allowed sample
2011 // count.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002012 int maxSampleCnt = 1;
Brian Salomon7f1a0742018-01-29 14:24:19 -05002013 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
2014 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
2015 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
2016 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
2017 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002018 // Chrome has a mock GL implementation that returns 0.
2019 maxSampleCnt = SkTMax(1, maxSampleCnt);
Brian Salomon7f1a0742018-01-29 14:24:19 -05002020
Brian Salomonbdecacf2018-02-02 20:32:49 -05002021 static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
Greg Daniel81e7bf82017-07-19 14:47:42 -04002022 int count = SK_ARRAY_COUNT(kDefaultSamples);
2023 for (; count > 0; --count) {
Brian Salomon7f1a0742018-01-29 14:24:19 -05002024 if (kDefaultSamples[count - 1] <= maxSampleCnt) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002025 break;
2026 }
2027 }
2028 if (count > 0) {
2029 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
2030 }
2031 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002032 } else if (ConfigInfo::kRenderable_Flag & fConfigTable[i].fFlags) {
2033 fConfigTable[i].fColorSampleCounts.setCount(1);
2034 fConfigTable[i].fColorSampleCounts[0] = 1;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002035 }
2036 }
2037
bsalomon30447372015-12-21 09:03:05 -08002038#ifdef SK_DEBUG
2039 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002040 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002041 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002042 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2043 // renderable.
Ben Wagnerf8a131d2018-03-13 16:56:43 -04002044 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag) &&
2045 !(fConfigTable[i].fFlags & ConfigInfo::kFBOColorAttachment_Flag)));
2046 SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
2047 !(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002048 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2049 fConfigTable[i].fFormats.fBaseInternalFormat);
2050 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002051 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002052 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2053 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2054 fConfigTable[i].fFormats.fExternalFormat[j]);
2055 }
2056 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002057 }
2058#endif
2059}
2060
Greg Daniel26dbe3b2018-05-03 10:35:42 -04002061bool GrGLCaps::canCopyTexSubImage(GrPixelConfig dstConfig, bool dstHasMSAARenderBuffer,
2062 bool dstIsTextureable, bool dstIsGLTexture2D,
2063 GrSurfaceOrigin dstOrigin,
2064 GrPixelConfig srcConfig, bool srcHasMSAARenderBuffer,
2065 bool srcIsTextureable, bool srcIsGLTexture2D,
2066 GrSurfaceOrigin srcOrigin) const {
2067 // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage
2068 // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps
2069 // many drivers would allow it to work, but ANGLE does not.
2070 if (kGLES_GrGLStandard == fStandard && this->bgraIsInternalFormat() &&
2071 (kBGRA_8888_GrPixelConfig == dstConfig || kBGRA_8888_GrPixelConfig == srcConfig)) {
2072 return false;
2073 }
2074
2075 // CopyTexSubImage is invalid or doesn't copy what we want when we have msaa render buffers.
2076 if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
2077 return false;
2078 }
2079
2080 // CopyTex(Sub)Image writes to a texture and we have no way of dynamically wrapping a RT in a
2081 // texture.
2082 if (!dstIsTextureable) {
2083 return false;
2084 }
2085
2086 // Check that we could wrap the source in an FBO, that the dst is TEXTURE_2D, that no mirroring
2087 // is required
2088 if (this->canConfigBeFBOColorAttachment(srcConfig) &&
2089 (!srcIsTextureable || srcIsGLTexture2D) &&
2090 dstIsGLTexture2D &&
2091 dstOrigin == srcOrigin) {
2092 return true;
2093 } else {
2094 return false;
2095 }
2096}
2097
2098bool GrGLCaps::canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCnt,
2099 bool dstIsTextureable, bool dstIsGLTexture2D,
2100 GrSurfaceOrigin dstOrigin,
2101 GrPixelConfig srcConfig, int srcSampleCnt,
2102 bool srcIsTextureable, bool srcIsGLTexture2D,
2103 GrSurfaceOrigin srcOrigin, const SkRect& srcBounds,
2104 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2105 auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
2106 if (!this->canConfigBeFBOColorAttachment(dstConfig) ||
2107 !this->canConfigBeFBOColorAttachment(srcConfig)) {
2108 return false;
2109 }
2110
2111 if (dstIsTextureable && !dstIsGLTexture2D) {
2112 return false;
2113 }
2114 if (srcIsTextureable && !srcIsGLTexture2D) {
2115 return false;
2116 }
2117
2118 if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
2119 return false;
2120 }
2121 if (GrGLCaps::kNoScalingOrMirroring_BlitFramebufferFlag & blitFramebufferFlags) {
2122 // We would mirror to compensate for origin changes. Note that copySurface is
2123 // specified such that the src and dst rects are the same.
2124 if (dstOrigin != srcOrigin) {
2125 return false;
2126 }
2127 }
2128
2129 if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
2130 if (srcSampleCnt > 1) {
2131 if (1 == dstSampleCnt) {
2132 return false;
2133 }
2134 if (SkRect::Make(srcRect) != srcBounds) {
2135 return false;
2136 }
2137 }
2138 }
2139
2140 if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
2141 if (dstSampleCnt > 1) {
2142 return false;
2143 }
2144 }
2145
2146 if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
2147 if (dstConfig != srcConfig) {
2148 return false;
2149 }
2150 } else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2151 if (srcSampleCnt > 1 && dstConfig != srcConfig) {
2152 return false;
2153 }
2154 }
2155
2156 if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
2157 if (srcSampleCnt > 1) {
2158 if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
2159 return false;
2160 }
2161 if (dstOrigin != srcOrigin) {
2162 return false;
2163 }
2164 }
2165 }
2166 return true;
2167}
2168
2169bool GrGLCaps::canCopyAsDraw(GrPixelConfig dstConfig, bool srcIsTextureable) const {
2170 return this->canConfigBeFBOColorAttachment(dstConfig) && srcIsTextureable;
2171}
2172
2173static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
2174 const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
2175 if (!rt) {
2176 return false;
2177 }
2178 // A RT has a separate MSAA renderbuffer if:
2179 // 1) It's multisampled
2180 // 2) We're using an extension with separate MSAA renderbuffers
2181 // 3) It's not FBO 0, which is special and always auto-resolves
2182 return rt->numColorSamples() > 1 &&
2183 glCaps.usesMSAARenderBuffers() &&
2184 !rt->rtPriv().glRTFBOIDIs0();
2185}
2186
2187bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
2188 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
2189 GrSurfaceOrigin dstOrigin = dst->origin();
2190 GrSurfaceOrigin srcOrigin = src->origin();
2191
2192 GrPixelConfig dstConfig = dst->config();
2193 GrPixelConfig srcConfig = src->config();
2194
2195 int dstSampleCnt = 0;
2196 int srcSampleCnt = 0;
2197 if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
2198 dstSampleCnt = rtProxy->numColorSamples();
2199 }
2200 if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
2201 srcSampleCnt = rtProxy->numColorSamples();
2202 }
2203 SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
2204 SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
2205
2206 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDraw handle the
2207 // swizzle.
2208 if (this->shaderCaps()->configOutputSwizzle(src->config()) !=
2209 this->shaderCaps()->configOutputSwizzle(dst->config())) {
2210 return false;
2211 }
2212
2213 const GrTextureProxy* dstTex = dst->asTextureProxy();
2214 const GrTextureProxy* srcTex = src->asTextureProxy();
2215
2216 bool dstIsTex2D = dstTex ? dstTex->texPriv().isGLTexture2D() : false;
2217 bool srcIsTex2D = srcTex ? srcTex->texPriv().isGLTexture2D() : false;
2218
2219 // One of the possible requirements for copy as blit is that the srcRect must match the bounds
2220 // of the src surface. If we have a approx fit surface we can't know for sure what the src
2221 // bounds will be at this time. Thus we assert that if we say we can copy as blit and the src is
2222 // approx that we also can copy as draw. Therefore when it comes time to do the copy we will
2223 // know we will at least be able to do it as a draw.
2224#ifdef SK_DEBUG
2225 if (this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2226 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2227 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect, dstPoint) &&
2228 !src->priv().isExact()) {
2229 SkASSERT(this->canCopyAsDraw(dstConfig, SkToBool(srcTex)));
2230 }
2231#endif
2232
2233 return this->canCopyTexSubImage(dstConfig, has_msaa_render_buffer(dst, *this),
2234 SkToBool(dstTex), dstIsTex2D, dstOrigin,
2235 srcConfig, has_msaa_render_buffer(src, *this),
2236 SkToBool(srcTex), srcIsTex2D, srcOrigin) ||
2237 this->canCopyAsBlit(dstConfig, dstSampleCnt, SkToBool(dstTex),
2238 dstIsTex2D, dstOrigin, srcConfig, srcSampleCnt, SkToBool(srcTex),
2239 srcIsTex2D, srcOrigin, src->getBoundsRect(), srcRect,
2240 dstPoint) ||
2241 this->canCopyAsDraw(dstConfig, SkToBool(srcTex));
2242}
2243
Robert Phillipsbf25d432017-04-07 10:08:53 -04002244bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Brian Salomon2a4f9832018-03-03 22:43:43 -05002245 GrSurfaceOrigin* origin, bool* rectsMustMatch,
2246 bool* disallowSubrect) const {
Eric Karl74480882017-04-03 14:49:05 -07002247 // By default, we don't require rects to match.
2248 *rectsMustMatch = false;
2249
2250 // By default, we allow subrects.
2251 *disallowSubrect = false;
2252
Brian Salomon467921e2017-03-06 16:17:12 -05002253 // If the src is a texture, we can implement the blit as a draw assuming the config is
2254 // renderable.
Brian Salomonbdecacf2018-02-02 20:32:49 -05002255 if (src->asTextureProxy() && !this->isConfigRenderable(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002256 *origin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002257 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2258 desc->fConfig = src->config();
2259 return true;
2260 }
2261
Robert Phillipsbf25d432017-04-07 10:08:53 -04002262 {
2263 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2264 // wrapped. In that case the proxy would already be instantiated.
2265 const GrTexture* srcTexture = src->priv().peekTexture();
2266 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2267 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2268 // Not supported for FBO blit or CopyTexSubImage
2269 return false;
2270 }
Brian Salomon467921e2017-03-06 16:17:12 -05002271 }
2272
2273 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2274 // possible and we return false to fallback to creating a render target dst for render-to-
2275 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2276 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002277 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002278 bool rectsMustMatchForBlitFramebuffer = false;
2279 bool disallowSubrectForBlitFramebuffer = false;
Brian Salomonbdecacf2018-02-02 20:32:49 -05002280 if (src->numColorSamples() > 1 &&
Eric Karl74480882017-04-03 14:49:05 -07002281 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2282 rectsMustMatchForBlitFramebuffer = true;
2283 disallowSubrectForBlitFramebuffer = true;
2284 // Mirroring causes rects to mismatch later, don't allow it.
2285 originForBlitFramebuffer = src->origin();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002286 } else if (src->numColorSamples() > 1 && (this->blitFramebufferSupportFlags() &
2287 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
Eric Karl74480882017-04-03 14:49:05 -07002288 rectsMustMatchForBlitFramebuffer = true;
2289 // Mirroring causes rects to mismatch later, don't allow it.
2290 originForBlitFramebuffer = src->origin();
2291 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002292 originForBlitFramebuffer = src->origin();
2293 }
2294
2295 // Check for format issues with glCopyTexSubImage2D
2296 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2297 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2298 // then we set up for that, otherwise fail.
2299 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002300 *origin = originForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002301 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002302 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2303 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002304 return true;
2305 }
2306 return false;
2307 }
2308
Robert Phillipsbf25d432017-04-07 10:08:53 -04002309 {
Brian Salomon63e79732017-05-15 21:23:13 -04002310 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2311 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002312 if (srcIsMSAARenderbuffer) {
2313 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2314 // blit or fail.
2315 if (this->canConfigBeFBOColorAttachment(src->config())) {
Brian Salomon2a4f9832018-03-03 22:43:43 -05002316 *origin = originForBlitFramebuffer;
Robert Phillipsbf25d432017-04-07 10:08:53 -04002317 desc->fConfig = src->config();
2318 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2319 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2320 return true;
2321 }
2322 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002323 }
Brian Salomon467921e2017-03-06 16:17:12 -05002324 }
2325
2326 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
Brian Salomon2a4f9832018-03-03 22:43:43 -05002327 *origin = src->origin();
Brian Salomon467921e2017-03-06 16:17:12 -05002328 desc->fConfig = src->config();
Brian Salomon467921e2017-03-06 16:17:12 -05002329 desc->fFlags = kNone_GrSurfaceFlags;
2330 return true;
2331}
2332
Greg Daniel691f5e72018-02-28 14:21:34 -05002333void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
2334 const GrContextOptions& contextOptions,
2335 GrShaderCaps* shaderCaps) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002336 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
2337 // Thus we are blacklisting this extension for now on Adreno4xx devices.
Adrienne Walker0e383942018-05-15 11:33:47 -07002338 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
2339 fDriverBugWorkarounds.disable_discard_framebuffer) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002340 fDiscardRenderTargetSupport = false;
2341 fInvalidateFBType = kNone_InvalidateFBType;
2342 }
2343
2344 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
2345 // 340.96 and 367.57.
2346 if (kGL_GrGLStandard == ctxInfo.standard() &&
2347 ctxInfo.driver() == kNVIDIA_GrGLDriver &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002348 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002349 fClearTextureSupport = false;
2350 }
2351
2352 // Calling glClearTexImage crashes on the NexusPlayer.
2353 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2354 fClearTextureSupport = false;
2355 }
2356
2357 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
2358#ifdef SK_BUILD_FOR_MAC
2359 if (shaderCaps->fGeometryShaderSupport) {
2360 shaderCaps->fGSInvocationsSupport = false;
2361 }
2362#endif
2363
2364 // Qualcomm driver @103.0 has been observed to crash compiling ccpr geometry
2365 // shaders. @127.0 is the earliest verified driver to not crash.
2366 if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002367 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002368 shaderCaps->fGeometryShaderSupport = false;
2369 }
2370
2371#if defined(__has_feature)
2372#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
2373 // See skbug.com/7058
2374 fMapBufferType = kNone_MapBufferType;
2375 fMapBufferFlags = kNone_MapFlags;
2376#endif
2377#endif
2378
2379 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
2380 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
2381 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
2382 // unclear whether this really affects a wide range of devices.
2383 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002384 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002385 fMapBufferType = kNone_MapBufferType;
2386 fMapBufferFlags = kNone_MapFlags;
2387 }
2388
2389 // TODO: re-enable for ANGLE
2390 if (kANGLE_GrGLDriver == ctxInfo.driver()) {
2391 fTransferBufferType = kNone_TransferBufferType;
2392 }
2393
2394 // Using MIPs on this GPU seems to be a source of trouble.
2395 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
2396 fMipMapSupport = false;
2397 }
2398
2399 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2400 // Temporarily disabling clip analytic fragments processors on Nexus player while we work
2401 // around a driver bug related to gl_FragCoord.
2402 // https://bugs.chromium.org/p/skia/issues/detail?id=7286
2403 fMaxClipAnalyticFPs = 0;
2404 }
2405
2406#ifndef SK_BUILD_FOR_IOS
2407 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
2408 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
2409 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
2410 ctxInfo.driver() != kChromium_GrGLDriver)) {
2411 fUseDrawToClearColor = true;
2412 }
2413#endif
2414
2415 // A lot of GPUs have trouble with full screen clears (skbug.com/7195)
2416 if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
2417 kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
2418 fUseDrawToClearColor = true;
2419 }
2420
2421#ifdef SK_BUILD_FOR_MAC
2422 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
2423 // full screen clears
2424 // crbug.com/773107 - On MacBook Pros, a wide range of Intel GPUs don't always
2425 // perform full screen clears.
Brian Salomon9a544bc2018-04-04 16:12:31 -04002426 // Update on 4/4/2018 - This appears to be fixed on driver 10.30.12 on a macOS 10.13.2 on a
2427 // Retina MBP Early 2015 with Iris 6100. It is possibly fixed on earlier drivers as well.
2428 if (kIntel_GrGLVendor == ctxInfo.vendor() &&
2429 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002430 fUseDrawToClearColor = true;
2431 }
2432#endif
2433
2434 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
2435 // bugs seems to involve clearing too much and not skipping the clear.
2436 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
2437 // but only for D3D11 ANGLE.
2438 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
2439 fUseDrawToClearColor = true;
2440 }
2441
2442 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
2443 // This is known to be fixed sometime between driver 145.0 and 219.0
Brian Salomon9a544bc2018-04-04 16:12:31 -04002444 if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002445 fUseDrawToClearStencilClip = true;
2446 }
2447 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2448 }
2449
Adrienne Walker94f585e2018-05-15 11:47:07 -07002450 if (fDriverBugWorkarounds.gl_clear_broken) {
2451 fUseDrawToClearColor = true;
2452 fUseDrawToClearStencilClip = true;
2453 }
2454
Brian Salomon01b476a2018-01-23 11:06:41 -05002455 // This was reproduced on the following configurations:
2456 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
2457 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
2458 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
2459 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
2460 // and not produced on:
2461 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
2462 // The particular lines that get dropped from test images varies across different devices.
2463 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002464 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002465 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
2466 }
2467
Chris Dalton6f5e77a2018-04-23 21:14:42 -06002468 if (kIntelSkylake_GrGLRenderer == ctxInfo.renderer() ||
2469 (kANGLE_GrGLRenderer == ctxInfo.renderer() &&
2470 GrGLANGLERenderer::kSkylake == ctxInfo.angleRenderer())) {
Chris Daltonda40cd22018-04-16 13:19:58 -06002471 fRequiresFlushBetweenNonAndInstancedDraws = true;
2472 }
2473
Brian Salomon01b476a2018-01-23 11:06:41 -05002474 // Our Chromebook with kPowerVRRogue_GrGLRenderer seems to crash when glDrawArraysInstanced is
2475 // given 1 << 15 or more instances.
2476 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
2477 fMaxInstancesPerDrawArraysWithoutCrashing = 0x7fff;
Adrienne Walker001cae02018-05-15 11:38:44 -07002478 } else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
2479 fMaxInstancesPerDrawArraysWithoutCrashing = 0x4000000;
Brian Salomon01b476a2018-01-23 11:06:41 -05002480 }
2481
2482 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
Chris Dalton0090ef62018-03-28 17:35:00 -06002483 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002484 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
2485 fUseDrawInsteadOfAllRenderTargetWrites = true;
2486 }
2487
2488 if (kGL_GrGLStandard == ctxInfo.standard() && kIntel_GrGLVendor == ctxInfo.vendor() ) {
2489 fSampleShadingSupport = false;
2490 }
2491
2492#ifdef SK_BUILD_FOR_MAC
2493 static constexpr bool isMAC = true;
2494#else
2495 static constexpr bool isMAC = false;
2496#endif
2497
2498 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
2499 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
2500 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
2501 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
2502 if (fMipMapLevelAndLodControlSupport &&
2503 (contextOptions.fDoManualMipmapping ||
2504 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
2505 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
2506 (kATI_GrGLVendor == ctxInfo.vendor()))) {
2507 fDoManualMipmapping = true;
2508 }
2509
2510 // See http://crbug.com/710443
2511#ifdef SK_BUILD_FOR_MAC
2512 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
2513 fClearToBoundaryValuesIsBroken = true;
2514 }
2515#endif
2516 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2517 fDrawArraysBaseVertexIsBroken = true;
2518 }
2519
Brian Salomon01b476a2018-01-23 11:06:41 -05002520 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
2521 // Galaxy S7.
2522 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
2523 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
2524 shaderCaps->fFBFetchSupport = false;
2525 }
2526
Brian Salomon01b476a2018-01-23 11:06:41 -05002527 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
2528 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
2529
2530 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
2531 // function that may require a gradient calculation inside a conditional block may return
2532 // undefined results". This appears to be an issue with the 'any' call since even the simple
2533 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
2534 // from our GrTextureDomain processor.
2535 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
2536
2537 // Known issue on at least some Intel platforms:
2538 // http://code.google.com/p/skia/issues/detail?id=946
2539 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2540 shaderCaps->fFragCoordConventionsExtensionString = nullptr;
2541 }
2542
Chris Dalton0090ef62018-03-28 17:35:00 -06002543 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002544 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
2545 // so we must do the abs first in a separate expression.
2546 shaderCaps->fCanUseMinAndAbsTogether = false;
2547
2548 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
2549 // must avoid this condition.
2550 shaderCaps->fCanUseFractForNegativeValues = false;
2551 }
2552
2553 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
2554 // thus must us -1.0 * %s.x to work correctly
2555 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2556 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
2557 }
2558
2559 // On some Intel GPUs there is an issue where the driver outputs bogus values in the shader
2560 // when floor and abs are called on the same line. Thus we must execute an Op between them to
2561 // make sure the compiler doesn't re-inline them even if we break the calls apart.
2562 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
2563 shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
2564 }
2565
2566 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
2567 // the original dst color when reading the outColor even after being written to. By using a
2568 // local outColor we can work around this bug.
2569 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
2570 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
2571 }
2572
2573 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
2574 // color, and that uniform contains an opaque color, and the output of the shader is only based
2575 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
2576 // that the shader always outputs opaque values. In that case, it appears to remove the shader
2577 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
2578 // insert an extra bit of math on the uniform that confuses the compiler just enough...
2579 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
2580 shaderCaps->fMustObfuscateUniformColor = true;
2581 }
2582#ifdef SK_BUILD_FOR_WIN
2583 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
2584 //
2585 // Basically, if a shader has a construct like:
2586 //
2587 // float x = someCondition ? someValue : 0;
2588 // float2 result = (0 == x) ? float2(x, x)
2589 // : float2(2 * x / x, 0);
2590 //
2591 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
2592 // we've explicitly guarded the division with a check against zero. This manifests in much
2593 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
2594 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
2595 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
2596 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
2597 }
2598#endif
2599
2600 // We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
2601 // (rare) situations. It's sporadic, and mostly on older drivers. It also seems to be the case
2602 // that the interpolation of vertex shader outputs is quite inaccurate.
2603 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
2604 shaderCaps->fCanUseFragCoord = false;
2605 shaderCaps->fInterpolantsAreInaccurate = true;
2606 }
2607
Chris Dalton0090ef62018-03-28 17:35:00 -06002608 // gl_FragCoord has an incorrect subpixel offset on legacy Tegra hardware.
2609 if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
2610 shaderCaps->fCanUseFragCoord = false;
2611 }
2612
Chris Daltonc2d0dd62018-03-07 07:46:10 -07002613 // On Mali G71, mediump ints don't appear capable of representing every integer beyond +/-2048.
2614 // (Are they implemented with fp16?)
2615 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2616 shaderCaps->fIncompleteShortIntPrecision = true;
2617 }
2618
Brian Salomon01b476a2018-01-23 11:06:41 -05002619 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
2620 // for now until its own blacklists can be updated.
2621 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
2622 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
2623 kIntel_GrGLDriver == ctxInfo.driver() ||
2624 kChromium_GrGLDriver == ctxInfo.driver()) {
2625 fBlendEquationSupport = kBasic_BlendEquationSupport;
2626 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2627 }
2628
2629 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
2630 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002631 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
Brian Salomon4e69f142018-01-24 09:28:28 -05002632 kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002633 fBlendEquationSupport = kBasic_BlendEquationSupport;
2634 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2635 }
2636
Adrienne Walker68314842018-05-14 14:02:53 -07002637 if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
2638 fBlendEquationSupport = kBasic_BlendEquationSupport;
2639 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
2640 }
2641
Brian Salomon01b476a2018-01-23 11:06:41 -05002642 if (this->advancedBlendEquationSupport()) {
2643 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
Brian Salomon9a544bc2018-04-04 16:12:31 -04002644 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002645 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
2646 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
2647 (1 << kColorBurn_GrBlendEquation);
2648 }
2649 if (kARM_GrGLVendor == ctxInfo.vendor()) {
2650 // Blacklist color-burn on ARM until the fix is released.
2651 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
2652 }
2653 }
2654
2655 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
2656 if (fMultisampleDisableSupport &&
2657 this->shaderCaps()->dualSourceBlendingSupport() &&
2658 this->shaderCaps()->pathRenderingSupport() &&
2659 fUsesMixedSamples &&
2660#if GR_TEST_UTILS
2661 (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
2662#endif
2663 (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
2664 kChromium_GrGLDriver == ctxInfo.driver())) {
2665 fDiscardRenderTargetSupport = false;
2666 fInvalidateFBType = kNone_InvalidateFBType;
2667 }
Brian Osmanc585e202018-04-04 14:08:27 -04002668
Brian Osman061020e2018-04-17 14:22:15 -04002669 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
2670 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
2671 // extension to be enabled, even when using ESSL3. Enabling both extensions fixes both cases.
2672 // skbug.com/7713
Brian Osmanc585e202018-04-04 14:08:27 -04002673 if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
2674 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
Brian Osman061020e2018-04-17 14:22:15 -04002675 !shaderCaps->fExternalTextureSupport) { // i.e. Missing the _essl3 extension
Brian Osmanc585e202018-04-04 14:08:27 -04002676 shaderCaps->fExternalTextureSupport = true;
Brian Osman061020e2018-04-17 14:22:15 -04002677 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
2678 shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
Brian Osmanc585e202018-04-04 14:08:27 -04002679 }
Brian Osman2fa53742018-05-03 15:05:12 -04002680
2681#ifdef SK_BUILD_FOR_IOS
2682 // iOS drivers appear to implement TexSubImage by creating a staging buffer, and copying
2683 // UNPACK_ROW_LENGTH * height bytes. That's unsafe in several scenarios, and the simplest fix
2684 // is to just blacklist the feature.
2685 // https://github.com/flutter/flutter/issues/16718
2686 // https://bugreport.apple.com/web/?problemID=39948888
2687 fUnpackRowLengthSupport = false;
2688#endif
Brian Salomon01b476a2018-01-23 11:06:41 -05002689}
2690
csmartdaltone0d36292016-07-29 08:14:20 -07002691void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
Brian Salomon01b476a2018-01-23 11:06:41 -05002692 if (options.fDisableDriverCorrectnessWorkarounds) {
2693 SkASSERT(!fDoManualMipmapping);
2694 SkASSERT(!fClearToBoundaryValuesIsBroken);
2695 SkASSERT(0 == fMaxInstancesPerDrawArraysWithoutCrashing);
2696 SkASSERT(!fDrawArraysBaseVertexIsBroken);
2697 SkASSERT(!fUseDrawToClearColor);
2698 SkASSERT(!fUseDrawToClearStencilClip);
2699 SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
2700 SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
2701 SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
Chris Daltonda40cd22018-04-16 13:19:58 -06002702 SkASSERT(!fRequiresFlushBetweenNonAndInstancedDraws);
Brian Salomon01b476a2018-01-23 11:06:41 -05002703 }
Brian Salomon43f8bf02017-10-18 08:33:29 -04002704 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfGLClear) {
2705 fUseDrawToClearColor = false;
2706 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfGLClear) {
2707 fUseDrawToClearColor = true;
2708 }
Brian Salomon01b476a2018-01-23 11:06:41 -05002709 if (options.fDoManualMipmapping) {
2710 fDoManualMipmapping = true;
2711 }
csmartdaltone0d36292016-07-29 08:14:20 -07002712}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002713
Brian Salomon3d86a192018-02-27 16:46:11 -05002714bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
2715 if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
2716 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2717 if (tex->hasBaseLevelBeenBoundToFBO()) {
2718 return false;
2719 }
2720 }
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002721 } if (auto rt = surface->asRenderTarget()) {
Brian Salomon3d86a192018-02-27 16:46:11 -05002722 if (fUseDrawInsteadOfAllRenderTargetWrites) {
2723 return false;
2724 }
2725 if (rt->numColorSamples() > 1 && this->usesMSAARenderBuffers()) {
2726 return false;
2727 }
2728 return SkToBool(surface->asTexture());
2729 }
2730 return true;
2731}
2732
Brian Salomon19eaf2d2018-03-19 16:06:44 -04002733bool GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
2734 if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
2735 // We don't support reading pixels directly from EXTERNAL textures as it would require
2736 // binding the texture to a FBO.
2737 if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
2738 return false;
2739 }
2740 }
2741 return true;
2742}
2743
2744GrColorType GrGLCaps::supportedReadPixelsColorType(GrPixelConfig config,
2745 GrColorType dstColorType) const {
2746 // For now, we mostly report the read back format that is required by the ES spec without
2747 // checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
2748 // this as makes sense to increase performance and correctness.
2749 switch (fConfigTable[config].fFormatType) {
2750 case kNormalizedFixedPoint_FormatType:
2751 return GrColorType::kRGBA_8888;
2752 case kFloat_FormatType:
2753 // We cheat a little here and allow F16 read back if the src and dst match.
2754 if (kRGBA_half_GrPixelConfig == config && GrColorType::kRGBA_F16 == dstColorType) {
2755 return GrColorType::kRGBA_F16;
2756 }
2757 if ((kAlpha_half_GrPixelConfig == config ||
2758 kAlpha_half_as_Red_GrPixelConfig == config) &&
2759 GrColorType::kAlpha_F16 == dstColorType) {
2760 return GrColorType::kAlpha_F16;
2761 }
2762 // And similar for full float RG.
2763 if (kRG_float_GrPixelConfig == config && GrColorType::kRG_F32 == dstColorType) {
2764 return GrColorType::kRG_F32;
2765 }
2766 return GrColorType::kRGBA_F32;
2767 }
2768 return GrColorType::kUnknown;
2769}
2770
Greg Daniel2a303902018-02-20 10:25:54 -05002771bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002772 GrGLFramebufferInfo fbInfo;
2773 SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
Greg Daniel2a303902018-02-20 10:25:54 -05002774 // Window Rectangles are not supported for FBO 0;
Greg Daniel323fbcf2018-04-10 13:46:30 -04002775 return fbInfo.fFBOID != 0;
Greg Daniel2a303902018-02-20 10:25:54 -05002776}
2777
Brian Salomonbdecacf2018-02-02 20:32:49 -05002778int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
2779 requestedCount = SkTMax(1, requestedCount);
Greg Daniel81e7bf82017-07-19 14:47:42 -04002780 int count = fConfigTable[config].fColorSampleCounts.count();
Brian Salomonbdecacf2018-02-02 20:32:49 -05002781 if (!count) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002782 return 0;
2783 }
2784
Brian Salomonbdecacf2018-02-02 20:32:49 -05002785 if (1 == requestedCount) {
2786 return fConfigTable[config].fColorSampleCounts[0] == 1 ? 1 : 0;
2787 }
2788
Greg Daniel81e7bf82017-07-19 14:47:42 -04002789 for (int i = 0; i < count; ++i) {
2790 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
Adrienne Walkerd7c79782018-05-15 11:41:24 -07002791 int count = fConfigTable[config].fColorSampleCounts[i];
2792 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2793 count = SkTMin(count, 4);
2794 }
2795 return count;
Greg Daniel81e7bf82017-07-19 14:47:42 -04002796 }
2797 }
Brian Salomonbdecacf2018-02-02 20:32:49 -05002798 return 0;
2799}
2800
2801int GrGLCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
2802 const auto& table = fConfigTable[config].fColorSampleCounts;
2803 if (!table.count()) {
2804 return 0;
2805 }
Adrienne Walker3a69c742018-05-21 11:05:48 -07002806 int count = table[table.count() - 1];
2807 if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
2808 count = SkTMin(count, 4);
2809 }
2810 return count;
Brian Salomond653cac2018-02-01 13:58:00 -05002811}
2812
Greg Danielfaa095e2017-12-19 13:15:02 -05002813bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* config,
2814 GrGLStandard standard) {
2815 *config = kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002816
2817 switch (ct) {
2818 case kUnknown_SkColorType:
2819 return false;
2820 case kAlpha_8_SkColorType:
2821 if (GR_GL_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002822 *config = kAlpha_8_as_Alpha_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002823 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002824 *config = kAlpha_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002825 }
2826 break;
2827 case kRGB_565_SkColorType:
2828 if (GR_GL_RGB565 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002829 *config = kRGB_565_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002830 }
2831 break;
2832 case kARGB_4444_SkColorType:
2833 if (GR_GL_RGBA4 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002834 *config = kRGBA_4444_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002835 }
2836 break;
2837 case kRGBA_8888_SkColorType:
2838 if (GR_GL_RGBA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002839 *config = kRGBA_8888_GrPixelConfig;
Greg Daniel7b219ac2017-12-18 14:49:04 -05002840 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002841 *config = kSRGBA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002842 }
2843 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002844 case kRGB_888x_SkColorType:
Brian Salomon5fba7ad2018-03-22 10:01:16 -04002845 if (GR_GL_RGB8 == format) {
2846 *config = kRGB_888_GrPixelConfig;
2847 }
2848 break;
Greg Danielf5d87582017-12-18 14:48:15 -05002849 case kBGRA_8888_SkColorType:
Greg Danielfaa095e2017-12-19 13:15:02 -05002850 if (GR_GL_RGBA8 == format) {
2851 if (kGL_GrGLStandard == standard) {
2852 *config = kBGRA_8888_GrPixelConfig;
2853 }
2854 } else if (GR_GL_BGRA8 == format) {
2855 if (kGLES_GrGLStandard == standard) {
2856 *config = kBGRA_8888_GrPixelConfig;
2857 }
Greg Daniel7b219ac2017-12-18 14:49:04 -05002858 } else if (GR_GL_SRGB8_ALPHA8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002859 *config = kSBGRA_8888_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002860 }
2861 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002862 case kRGBA_1010102_SkColorType:
Brian Osman10fc6fd2018-03-02 11:01:10 -05002863 if (GR_GL_RGB10_A2 == format) {
2864 *config = kRGBA_1010102_GrPixelConfig;
2865 }
2866 break;
Brian Salomone41e1762018-01-25 14:07:47 -05002867 case kRGB_101010x_SkColorType:
2868 return false;
Greg Danielf5d87582017-12-18 14:48:15 -05002869 case kGray_8_SkColorType:
2870 if (GR_GL_LUMINANCE8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002871 *config = kGray_8_as_Lum_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002872 } else if (GR_GL_R8 == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002873 *config = kGray_8_as_Red_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002874 }
2875 break;
2876 case kRGBA_F16_SkColorType:
2877 if (GR_GL_RGBA16F == format) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002878 *config = kRGBA_half_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -05002879 }
2880 break;
2881 }
2882
Greg Danielfaa095e2017-12-19 13:15:02 -05002883 return kUnknown_GrPixelConfig != *config;
2884}
2885
2886bool GrGLCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
2887 GrPixelConfig* config) const {
Greg Daniel52e16d92018-04-10 09:34:07 -04002888 GrGLTextureInfo texInfo;
2889 if (!tex.getGLTextureInfo(&texInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002890 return false;
2891 }
Greg Daniel52e16d92018-04-10 09:34:07 -04002892 return validate_sized_format(texInfo.fFormat, ct, config, fStandard);
Greg Danielfaa095e2017-12-19 13:15:02 -05002893}
2894
2895bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
2896 GrPixelConfig* config) const {
Greg Daniel323fbcf2018-04-10 13:46:30 -04002897 GrGLFramebufferInfo fbInfo;
2898 if (!rt.getGLFramebufferInfo(&fbInfo)) {
Greg Danielfaa095e2017-12-19 13:15:02 -05002899 return false;
2900 }
Greg Daniel323fbcf2018-04-10 13:46:30 -04002901 return validate_sized_format(fbInfo.fFormat, ct, config, fStandard);
Greg Danielf5d87582017-12-18 14:48:15 -05002902}
2903
Robert Phillipsfc711a22018-02-13 17:03:00 -05002904bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
2905 GrPixelConfig* config) const {
2906 const GrGLenum* glFormat = format.getGLFormat();
2907 if (!glFormat) {
2908 return false;
2909 }
2910 return validate_sized_format(*glFormat, ct, config, fStandard);
2911}
Ravi Mistry35b40ce2018-05-30 20:54:40 +00002912
2913