blob: 9b8b2c9f5e135ce25c823082f2a0461e1a43f1f8 [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"
Brian Salomon94efbf52016-11-29 13:43:05 -050013#include "GrShaderCaps.h"
Robert Phillipsbf25d432017-04-07 10:08:53 -040014#include "GrSurfaceProxyPriv.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000015#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000016#include "SkTSort.h"
Brian Salomon467921e2017-03-06 16:17:12 -050017#include "instanced/GLInstancedRendering.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000018
bsalomon682c2692015-05-22 14:01:46 -070019GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
20 const GrGLContextInfo& ctxInfo,
21 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080022 fStandard = ctxInfo.standard();
23
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000025 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000026 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000027 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080028 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fUnpackRowLengthSupport = false;
31 fUnpackFlipYSupport = false;
32 fPackRowLengthSupport = false;
33 fPackFlipYSupport = false;
34 fTextureUsageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000035 fTextureRedSupport = false;
Robert Phillips5ab72762017-06-07 12:04:18 -040036 fAlpha8IsRenderable = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000037 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000038 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070039 fDirectStateAccessSupport = false;
40 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;
brianosman09563ce2016-06-02 08:59:34 -070053 fDoManualMipmapping = false;
brianosman20471892016-12-02 06:43:32 -080054 fSRGBDecodeDisableSupport = false;
brianosman851c2382016-12-07 10:03:25 -080055 fSRGBDecodeDisableAffectsMipmaps = false;
Eric Karlaeaf22b2017-05-18 15:08:09 -070056 fClearToBoundaryValuesIsBroken = false;
Brian Salomond17b4a62017-05-23 16:53:47 -040057 fClearTextureSupport = false;
Chris Dalton9926f4b2017-05-17 15:15:50 -060058 fDrawArraysBaseVertexIsBroken = false;
Mike Klein31550db2017-06-06 23:29:53 +000059 fUseDrawToClearStencilClip = false;
piotaixre4b23142014-10-02 10:57:53 -070060
Brian Salomone5e7eb12016-10-14 16:18:33 -040061 fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
bsalomon083617b2016-02-12 12:10:14 -080062
Brian Salomon94efbf52016-11-29 13:43:05 -050063 fShaderCaps.reset(new GrShaderCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070064
cdalton4cd67132015-06-10 19:23:46 -070065 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000066}
67
cdalton4cd67132015-06-10 19:23:46 -070068void GrGLCaps::init(const GrContextOptions& contextOptions,
69 const GrGLContextInfo& ctxInfo,
70 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000071 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 GrGLVersion version = ctxInfo.version();
73
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000074 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000075 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
76 &fMaxFragmentUniformVectors);
77 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000078 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079 GrGLint max;
80 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
81 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000082 if (version >= GR_GL_VER(3, 2)) {
83 GrGLint profileMask;
84 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
85 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
86 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000088 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000090 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000091 fUnpackRowLengthSupport = true;
92 fUnpackFlipYSupport = false;
93 fPackRowLengthSupport = true;
94 fPackFlipYSupport = false;
95 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000096 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
97 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000099 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
100 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 fPackFlipYSupport =
102 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
103 }
104
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000105 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000106 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
107
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000108 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700109 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
110 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
111 ctxInfo.hasExtension("GL_NV_texture_barrier");
112 } else {
113 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
114 }
115
cdaltoneb79eea2016-02-26 10:39:34 -0800116 if (kGL_GrGLStandard == standard) {
117 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
118 ctxInfo.hasExtension("GL_ARB_texture_multisample");
119 } else {
120 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
121 }
122
Brian Salomon0ee6f952017-01-19 15:52:24 -0500123 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
hendrikwa0d5ad72014-12-02 07:30:30 -0800124 // and GL_RG on FBO textures.
Brian Salomon0ee6f952017-01-19 15:52:24 -0500125 if (kOSMesa_GrGLRenderer != ctxInfo.renderer()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800126 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000127 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
128 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800129 } else {
130 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
131 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000132 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000133 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000134 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000135 ctxInfo.hasExtension("GL_ARB_imaging");
136
egdaniel9250d242015-05-18 13:04:26 -0700137 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
138 // Thus we are blacklisting this extension for now on Adreno4xx devices.
139 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
140 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
141 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
142 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000143 fDiscardRenderTargetSupport = true;
144 fInvalidateFBType = kInvalidate_InvalidateFBType;
145 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
146 fDiscardRenderTargetSupport = true;
147 fInvalidateFBType = kDiscard_InvalidateFBType;
148 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000149
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000150 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
151 fFullClearIsFree = true;
152 }
153
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000154 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000155 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800156 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
157 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000158 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000159 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
160 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000161 }
162
cdalton626e1ff2015-06-12 13:56:46 -0700163 if (kGL_GrGLStandard == standard) {
164 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
165 } else {
166 fDirectStateAccessSupport = false;
167 }
168
169 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
170 fDebugSupport = true;
171 } else {
172 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
173 }
174
jvanverth3f801cb2014-12-16 09:49:38 -0800175 if (kGL_GrGLStandard == standard) {
176 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
177 }
178 else {
179 fES2CompatibilitySupport = true;
180 }
181
cdalton0edea2c2015-05-21 08:27:44 -0700182 if (kGL_GrGLStandard == standard) {
183 fMultisampleDisableSupport = true;
184 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700185 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700186 }
187
kkinnunend94708e2015-07-30 22:47:04 -0700188 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600189 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
190 // instanced arrays, but we could make this more granular if we wanted
191 fInstanceAttribSupport =
192 version >= GR_GL_VER(3, 2) ||
193 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
194 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
195 } else {
196 fInstanceAttribSupport =
197 version >= GR_GL_VER(3, 0) ||
198 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
199 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
200 }
201
202 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700203 if (version >= GR_GL_VER(3, 0)) {
204 fBindFragDataLocationSupport = true;
205 }
206 } else {
207 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
208 fBindFragDataLocationSupport = true;
209 }
joshualittc1f56b52015-06-22 12:31:31 -0700210 }
211
joshualitt7bdd70a2015-10-01 06:28:11 -0700212 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
213
kkinnunene06ed252016-02-16 23:15:40 -0800214 if (kGL_GrGLStandard == standard) {
215 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
216 // We also require textureSize() support for rectangle 2D samplers which was added in
217 // GLSL 1.40.
218 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
219 fRectangleTextureSupport = true;
220 }
bsalomone179a912016-01-20 06:18:10 -0800221 }
kkinnunene06ed252016-02-16 23:15:40 -0800222 } else {
223 // Command buffer exposes this in GL ES context for Chromium reasons,
224 // but it should not be used. Also, at the time of writing command buffer
225 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800226 }
227
bsalomoncdee0092016-01-08 13:20:12 -0800228 if (kGL_GrGLStandard == standard) {
229 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
230 fTextureSwizzleSupport = true;
231 }
232 } else {
233 if (version >= GR_GL_VER(3,0)) {
234 fTextureSwizzleSupport = true;
235 }
236 }
237
cblume09bd2c02016-03-01 14:08:28 -0800238 if (kGL_GrGLStandard == standard) {
239 fMipMapLevelAndLodControlSupport = true;
240 } else if (kGLES_GrGLStandard == standard) {
241 if (version >= GR_GL_VER(3,0)) {
242 fMipMapLevelAndLodControlSupport = true;
243 }
244 }
245
bsalomon88c7b982015-07-31 11:20:16 -0700246#ifdef SK_BUILD_FOR_WIN
247 // We're assuming that on Windows Chromium we're using ANGLE.
248 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
249 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700250 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700251 fRGBA8888PixelsOpsAreSlow = isANGLE;
252 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
253 // check DX11 ANGLE.
254 fPartialFBOReadIsSlow = isANGLE;
255#endif
256
ericrkb4ecabd2016-03-11 15:18:20 -0800257 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
258 bool isMAC = false;
259#ifdef SK_BUILD_FOR_MAC
260 isMAC = true;
261#endif
262
263 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
264 // vis-versa.
265 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
266
Brian Salomond17b4a62017-05-23 16:53:47 -0400267 if (kGL_GrGLStandard == standard) {
268 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
269 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
270 // 340.96 and 367.57.
271 if (ctxInfo.driver() != kNVIDIA_GrGLDriver ||
272 ctxInfo.driverVersion() >= GR_GL_DRIVER_VER(367, 57)) {
273 fClearTextureSupport = true;
274 }
275 }
276 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
277 // Calling glClearTexImage crashes on the NexusPlayer.
278 if (kPowerVRRogue_GrGLRenderer != ctxInfo.renderer()) {
279 fClearTextureSupport = true;
280 }
281 }
282
cdalton4cd67132015-06-10 19:23:46 -0700283 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700284 * GrShaderCaps fields
285 **************************************************************************/
286
egdaniel0a482332015-10-26 08:59:10 -0700287 // This must be called after fCoreProfile is set on the GrGLCaps
288 this->initGLSL(ctxInfo);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500289 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700290
csmartdalton008b9d82017-02-22 12:00:42 -0700291 if (!contextOptions.fSuppressPathRendering) {
292 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
293 }
egdaniel05ded892015-10-26 07:38:05 -0700294
295 // For now these two are equivalent but we could have dst read in shader via some other method.
296 // Before setting this, initGLSL() must have been called.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500297 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
egdaniel05ded892015-10-26 07:38:05 -0700298
299 // Enable supported shader-related caps
300 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500301 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700302 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
303 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
Brian Salomon1edc5b92016-11-29 13:43:46 -0500304 shaderCaps->fShaderDerivativeSupport = true;
egdaniel05ded892015-10-26 07:38:05 -0700305 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500306 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700307 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Brian Salomon1edc5b92016-11-29 13:43:46 -0500308 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800309 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700310 }
311 else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500312 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700313
Brian Salomon1edc5b92016-11-29 13:43:46 -0500314 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700315 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800316
csmartdalton1d2aed02017-02-15 21:43:20 -0700317 shaderCaps->fGeometryShaderSupport = ctxInfo.hasExtension("GL_EXT_geometry_shader");
318
Brian Salomon1edc5b92016-11-29 13:43:46 -0500319 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800320 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700321 }
322
cdalton9c3f1432016-03-11 10:07:37 -0800323 // Protect ourselves against tracking huge amounts of texture state.
324 static const uint8_t kMaxSaneSamplers = 32;
325 GrGLint maxSamplers;
326 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500327 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
328 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800329 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500330 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800331 }
332 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500333 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800334 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500335 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800336
Brian Salomonf26f7a02016-11-15 14:05:01 -0500337 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500338 shaderCaps->fImageLoadStoreSupport = ctxInfo.version() >= GR_GL_VER(4, 2);
339 if (!shaderCaps->fImageLoadStoreSupport &&
Brian Salomonf26f7a02016-11-15 14:05:01 -0500340 ctxInfo.hasExtension("GL_ARB_shader_image_load_store")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500341 shaderCaps->fImageLoadStoreSupport = true;
342 shaderCaps->fImageLoadStoreExtensionString = "GL_ARB_shader_image_load_store";
Brian Salomonf26f7a02016-11-15 14:05:01 -0500343 }
344 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500345 shaderCaps->fImageLoadStoreSupport = ctxInfo.version() >= GR_GL_VER(3, 1);
Brian Salomonf26f7a02016-11-15 14:05:01 -0500346 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500347 if (shaderCaps->fImageLoadStoreSupport) {
Brian Salomonf26f7a02016-11-15 14:05:01 -0500348 // Protect ourselves against tracking huge amounts of image state.
349 static constexpr int kMaxSaneImages = 4;
350 GrGLint maxUnits;
351 GR_GL_GetIntegerv(gli, GR_GL_MAX_IMAGE_UNITS, &maxUnits);
Brian Salomonf9f45122016-11-29 11:59:17 -0500352 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_IMAGE_UNIFORMS,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500353 &shaderCaps->fMaxVertexImageStorages);
354 if (shaderCaps->fGeometryShaderSupport) {
Brian Salomonf9f45122016-11-29 11:59:17 -0500355 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_IMAGE_UNIFORMS,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500356 &shaderCaps->fMaxGeometryImageStorages);
Brian Salomonf9f45122016-11-29 11:59:17 -0500357 }
358 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_IMAGE_UNIFORMS,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500359 &shaderCaps->fMaxFragmentImageStorages);
Brian Salomonf9f45122016-11-29 11:59:17 -0500360 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_IMAGE_UNIFORMS,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500361 &shaderCaps->fMaxCombinedImageStorages);
Brian Salomonf26f7a02016-11-15 14:05:01 -0500362 // We use one unit for every image uniform
Brian Salomon1edc5b92016-11-29 13:43:46 -0500363 shaderCaps->fMaxCombinedImageStorages = SkTMin(SkTMin(shaderCaps->fMaxCombinedImageStorages,
364 maxUnits), kMaxSaneImages);
365 shaderCaps->fMaxVertexImageStorages = SkTMin(maxUnits,
366 shaderCaps->fMaxVertexImageStorages);
367 shaderCaps->fMaxGeometryImageStorages = SkTMin(maxUnits,
368 shaderCaps->fMaxGeometryImageStorages);
369 shaderCaps->fMaxFragmentImageStorages = SkTMin(maxUnits,
370 shaderCaps->fMaxFragmentImageStorages);
Brian Salomonf26f7a02016-11-15 14:05:01 -0500371 }
372
csmartdalton485a1202016-07-13 10:16:32 -0700373 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
374 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
375 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
376 // limit this decision to specific GPU families rather than basing it on the vendor alone.
377 if (!GR_GL_MUST_USE_VBO &&
378 !fIsCoreProfile &&
379 (kARM_GrGLVendor == ctxInfo.vendor() ||
380 kImagination_GrGLVendor == ctxInfo.vendor() ||
381 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
382 fPreferClientSideDynamicBuffers = true;
383 }
384
Eric Karl5c779752017-05-08 12:02:07 -0700385 if (!contextOptions.fAvoidStencilBuffers) {
386 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
387 this->initFSAASupport(contextOptions, ctxInfo, gli);
388 this->initStencilSupport(ctxInfo);
389 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400390
391 // Setup blit framebuffer
392 if (kGL_GrGLStandard != ctxInfo.standard()) {
393 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
394 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
395 kNoMSAADst_BlitFramebufferFlag |
396 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
397 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
398 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
399 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
400 // limitations.
401 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
402 kResolveMustBeFull_BlitFrambufferFlag |
403 kNoMSAADst_BlitFramebufferFlag |
404 kNoFormatConversion_BlitFramebufferFlag |
405 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
406 }
407 } else {
408 if (fUsesMixedSamples ||
409 ctxInfo.version() >= GR_GL_VER(3,0) ||
410 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
411 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
412 fBlitFramebufferFlags = 0;
413 }
414 }
415
cdalton1dd05422015-06-12 09:01:18 -0700416 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000417
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000418 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000419 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
420 // extension includes glMapBuffer.
421 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
422 fMapBufferFlags |= kSubset_MapFlag;
423 fMapBufferType = kMapBufferRange_MapBufferType;
424 } else {
425 fMapBufferType = kMapBuffer_MapBufferType;
426 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000427 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000428 // Unextended GLES2 doesn't have any buffer mapping.
429 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800430 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800431 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
432 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800433 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
434 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
435 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000436 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
437 fMapBufferFlags = kCanMap_MapFlag;
438 fMapBufferType = kMapBuffer_MapBufferType;
439 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000440 }
441
jvanverthd7a2c1f2015-12-07 07:36:44 -0800442 if (kGL_GrGLStandard == standard) {
443 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
444 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700445 }
jvanverthd7a2c1f2015-12-07 07:36:44 -0800446 } else {
447 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
448 fTransferBufferType = kPBO_TransferBufferType;
jvanverthc3d706f2016-04-20 10:33:27 -0700449 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
450 fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800451 }
452 }
453
joshualitte5b74c62015-06-01 14:17:47 -0700454 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
455 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700456 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700457#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500458 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
459 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
460 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700461 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700462#else
cdalton397536c2016-03-25 12:15:03 -0700463 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700464#endif
joshualitte5b74c62015-06-01 14:17:47 -0700465 }
466
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000467 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000468 fNPOTTextureTileSupport = true;
469 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000470 } else {
471 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000472 // ES3 has no limitations.
473 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
474 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000475 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
476 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
477 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
478 // to alllow arbitrary wrap modes, however.
479 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000480 }
481
bsalomone72bd022015-10-26 07:33:03 -0700482 // Using MIPs on this GPU seems to be a source of trouble.
483 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
484 fMipMapSupport = false;
485 }
486
bsalomon@google.combcce8922013-03-25 15:38:39 +0000487 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
488 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
489 // Our render targets are always created with textures as the color
490 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000491 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000492
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000493 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
494
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000495 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700496 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000497
robertphillips1b8e1b52015-06-24 06:54:10 -0700498#if 0
499 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
500 kQualcomm_GrGLVendor != ctxInfo.vendor();
501#endif
502
csmartdalton9bc11872016-08-09 12:42:47 -0700503 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
504 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700505 }
506
bsalomon63b21962014-11-05 07:05:34 -0800507 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800508 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon1b52df32017-03-24 18:49:09 -0400509 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
510 ctxInfo.driver() != kChromium_GrGLDriver)) {
bsalomon63b21962014-11-05 07:05:34 -0800511 fUseDrawInsteadOfClear = true;
512 }
513
joshualitt83bc2292015-06-18 14:18:02 -0700514 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomonfdd11702017-05-31 15:59:40 +0000515 fUseDrawInsteadOfPartialRenderTargetWrite = true;
Brian Salomonb52fa022017-06-07 09:42:52 -0400516 // This is known to be fixed sometime between driver 145.0 and 219.0
517 if (ctxInfo.driver() == kQualcomm_GrGLDriver &&
518 ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0)) {
519 fUseDrawToClearStencilClip = true;
520 }
joshualitt83bc2292015-06-18 14:18:02 -0700521 }
522
bsalomonbabafcc2016-02-16 11:36:47 -0800523 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
524 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomonfdd11702017-05-31 15:59:40 +0000525 fUseDrawInsteadOfPartialRenderTargetWrite = true;
bsalomonbabafcc2016-02-16 11:36:47 -0800526 fUseDrawInsteadOfAllRenderTargetWrites = true;
527 }
528
robertphillips63926682015-08-20 09:39:02 -0700529#ifdef SK_BUILD_FOR_WIN
530 // On ANGLE deferring flushes can lead to GPU starvation
531 fPreferVRAMUseOverFlushes = !isANGLE;
532#endif
533
bsalomon7dea7b72015-08-19 08:26:51 -0700534 if (kChromium_GrGLDriver == ctxInfo.driver()) {
535 fMustClearUploadedBufferData = true;
536 }
537
bsalomond08ea5f2015-02-20 06:58:13 -0800538 if (kGL_GrGLStandard == standard) {
539 // ARB allows mixed size FBO attachments, EXT does not.
540 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
541 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
542 fOversizedStencilSupport = true;
543 } else {
544 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
545 }
546 } else {
547 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
548 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
549 }
550
joshualitt58001552015-06-26 12:46:36 -0700551 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700552 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
553 ctxInfo.hasExtension("GL_ARB_draw_indirect");
554 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
555 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700556 (fDrawIndirectSupport &&
557 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700558 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700559 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800560 } else {
561 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700562 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
563 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
564 fBaseInstanceSupport = fDrawIndirectSupport &&
565 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700566 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800567 }
568
Brian Salomon1edc5b92016-11-29 13:43:46 -0500569 this->initShaderPrecisionTable(ctxInfo, gli, shaderCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800570
571 if (contextOptions.fUseShaderSwizzling) {
572 fTextureSwizzleSupport = false;
573 }
574
ethannicholas28ef4452016-03-25 09:26:03 -0700575 if (kGL_GrGLStandard == standard) {
ethannicholas6536ae52016-05-02 12:16:49 -0700576 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading")) &&
577 ctxInfo.vendor() != kIntel_GrGLVendor) {
ethannicholas28ef4452016-03-25 09:26:03 -0700578 fSampleShadingSupport = true;
579 }
580 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
581 fSampleShadingSupport = true;
582 }
583
jvanverth84741b32016-09-30 08:39:02 -0700584 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
585 if (kGL_GrGLStandard == standard) {
586 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
587 fFenceSyncSupport = true;
588 }
589 } else if (version >= GR_GL_VER(3, 0)) {
590 fFenceSyncSupport = true;
591 }
592
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400593 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500594 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500595
brianosman131ff132016-06-07 14:22:44 -0700596 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
597 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
598 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
599 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
brianosman09563ce2016-06-02 08:59:34 -0700600 if (fMipMapLevelAndLodControlSupport &&
brianosman9a3fbf72016-06-09 13:11:08 -0700601 (contextOptions.fDoManualMipmapping ||
602 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
brianosman131ff132016-06-07 14:22:44 -0700603 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
604 (kATI_GrGLVendor == ctxInfo.vendor()))) {
brianosman09563ce2016-06-02 08:59:34 -0700605 fDoManualMipmapping = true;
606 }
607
brianosman20471892016-12-02 06:43:32 -0800608 fSRGBDecodeDisableSupport = ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode");
brianosman851c2382016-12-07 10:03:25 -0800609 fSRGBDecodeDisableAffectsMipmaps = fSRGBDecodeDisableSupport &&
610 kChromium_GrGLDriver != ctxInfo.driver();
brianosman20471892016-12-02 06:43:32 -0800611
Brian Salomon028a9a52017-05-11 11:39:08 -0400612 // See http://crbug.com/710443
613#ifdef SK_BUILD_FOR_MAC
614 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
Eric Karlaeaf22b2017-05-18 15:08:09 -0700615 fClearToBoundaryValuesIsBroken = true;
Brian Salomon028a9a52017-05-11 11:39:08 -0400616 }
617#endif
Chris Dalton9926f4b2017-05-17 15:15:50 -0600618 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
619 fDrawArraysBaseVertexIsBroken = true;
620 }
Brian Salomon028a9a52017-05-11 11:39:08 -0400621
bsalomoncdee0092016-01-08 13:20:12 -0800622 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
623 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800624 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700625
626 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500627 shaderCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000628}
629
egdaniel472d44e2015-10-22 08:20:00 -0700630const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
631 bool isCoreProfile) {
632 switch (generation) {
633 case k110_GrGLSLGeneration:
634 if (kGLES_GrGLStandard == standard) {
635 // ES2s shader language is based on version 1.20 but is version
636 // 1.00 of the ES language.
637 return "#version 100\n";
638 } else {
639 SkASSERT(kGL_GrGLStandard == standard);
640 return "#version 110\n";
641 }
642 case k130_GrGLSLGeneration:
643 SkASSERT(kGL_GrGLStandard == standard);
644 return "#version 130\n";
645 case k140_GrGLSLGeneration:
646 SkASSERT(kGL_GrGLStandard == standard);
647 return "#version 140\n";
648 case k150_GrGLSLGeneration:
649 SkASSERT(kGL_GrGLStandard == standard);
650 if (isCoreProfile) {
651 return "#version 150\n";
652 } else {
653 return "#version 150 compatibility\n";
654 }
655 case k330_GrGLSLGeneration:
656 if (kGLES_GrGLStandard == standard) {
657 return "#version 300 es\n";
658 } else {
659 SkASSERT(kGL_GrGLStandard == standard);
660 if (isCoreProfile) {
661 return "#version 330\n";
662 } else {
663 return "#version 330 compatibility\n";
664 }
665 }
cdalton33ad7012016-02-22 07:55:44 -0800666 case k400_GrGLSLGeneration:
667 SkASSERT(kGL_GrGLStandard == standard);
668 if (isCoreProfile) {
669 return "#version 400\n";
670 } else {
671 return "#version 400 compatibility\n";
672 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500673 case k420_GrGLSLGeneration:
674 SkASSERT(kGL_GrGLStandard == standard);
675 if (isCoreProfile) {
676 return "#version 420\n";
677 }
678 else {
679 return "#version 420 compatibility\n";
680 }
egdaniel472d44e2015-10-22 08:20:00 -0700681 case k310es_GrGLSLGeneration:
682 SkASSERT(kGLES_GrGLStandard == standard);
683 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800684 case k320es_GrGLSLGeneration:
685 SkASSERT(kGLES_GrGLStandard == standard);
686 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700687 }
688 return "<no version>";
689}
690
egdaniel05ded892015-10-26 07:38:05 -0700691void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700692 GrGLStandard standard = ctxInfo.standard();
693 GrGLVersion version = ctxInfo.version();
694
695 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500696 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700697 **************************************************************************/
698
Brian Salomon1edc5b92016-11-29 13:43:46 -0500699 GrShaderCaps* shaderCaps = fShaderCaps.get();
700 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700701 if (kGLES_GrGLStandard == standard) {
702 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500703 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
704 shaderCaps->fFBFetchSupport = true;
705 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
706 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700707 }
708 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
709 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
Brian Salomon1edc5b92016-11-29 13:43:46 -0500710 shaderCaps->fFBFetchNeedsCustomOutput = false;
711 shaderCaps->fFBFetchSupport = true;
712 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
713 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700714 }
715 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
716 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500717 shaderCaps->fFBFetchNeedsCustomOutput = false;
718 shaderCaps->fFBFetchSupport = true;
719 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
720 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700721 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500722 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700723 }
724
egdaniel7517e452016-09-20 13:00:26 -0700725 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
726 // Galaxy S7.
727 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
728 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500729 shaderCaps->fFBFetchSupport = false;
egdaniel7517e452016-09-20 13:00:26 -0700730 }
731
Brian Salomon1edc5b92016-11-29 13:43:46 -0500732 shaderCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
egdaniel472d44e2015-10-22 08:20:00 -0700733
cdaltonc08f1962016-02-12 12:14:06 -0800734 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500735 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800736 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500737 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800738 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
739 }
740
741 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500742 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800743 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
744 } else {
745 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500746 shaderCaps->fNoPerspectiveInterpolationSupport = true;
747 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800748 "GL_NV_shader_noperspective_interpolation";
749 }
750 }
751
cdalton33ad7012016-02-22 07:55:44 -0800752 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500753 shaderCaps->fMultisampleInterpolationSupport =
cdalton4a98cdb2016-03-01 12:12:20 -0800754 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
755 } else {
756 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500757 shaderCaps->fMultisampleInterpolationSupport = true;
cdalton4a98cdb2016-03-01 12:12:20 -0800758 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500759 shaderCaps->fMultisampleInterpolationSupport = true;
760 shaderCaps->fMultisampleInterpolationExtensionString =
cdalton4a98cdb2016-03-01 12:12:20 -0800761 "GL_OES_shader_multisample_interpolation";
762 }
763 }
764
765 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500766 shaderCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
cdalton33ad7012016-02-22 07:55:44 -0800767 } else {
768 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500769 shaderCaps->fSampleVariablesSupport = true;
cdalton33ad7012016-02-22 07:55:44 -0800770 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500771 shaderCaps->fSampleVariablesSupport = true;
772 shaderCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
cdalton33ad7012016-02-22 07:55:44 -0800773 }
774 }
775
Brian Salomon1edc5b92016-11-29 13:43:46 -0500776 if (shaderCaps->fSampleVariablesSupport &&
csmartdaltonf848c9c2016-06-15 12:42:13 -0700777 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage")) {
778 // Pre-361 NVIDIA has a bug with NV_sample_mask_override_coverage.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500779 shaderCaps->fSampleMaskOverrideCoverageSupport =
csmartdaltonf848c9c2016-06-15 12:42:13 -0700780 kNVIDIA_GrGLDriver != ctxInfo.driver() ||
781 ctxInfo.driverVersion() >= GR_GL_DRIVER_VER(361,00);
cdalton33ad7012016-02-22 07:55:44 -0800782 }
783
egdaniel472d44e2015-10-22 08:20:00 -0700784 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
Brian Salomon1edc5b92016-11-29 13:43:46 -0500785 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
egdaniel472d44e2015-10-22 08:20:00 -0700786
787 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
788 // function that may require a gradient calculation inside a conditional block may return
789 // undefined results". This appears to be an issue with the 'any' call since even the simple
790 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
791 // from our GrTextureDomain processor.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500792 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
egdaniel472d44e2015-10-22 08:20:00 -0700793
Brian Salomon1edc5b92016-11-29 13:43:46 -0500794 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
795 shaderCaps->fGLSLGeneration,
796 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800797
Brian Salomon1edc5b92016-11-29 13:43:46 -0500798 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
799 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800800 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800801
802 // Frag Coords Convention support is not part of ES
803 // Known issue on at least some Intel platforms:
804 // http://code.google.com/p/skia/issues/detail?id=946
805 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
806 kGLES_GrGLStandard != standard &&
807 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
808 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500809 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800810 }
811
812 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500813 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800814 }
815
cdalton9c3f1432016-03-11 10:07:37 -0800816 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
817 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500818 shaderCaps->fExternalTextureSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800819 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
820 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
821 // At least one driver has been found that has this extension without the "GL_" prefix.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500822 shaderCaps->fExternalTextureSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800823 }
824 }
825
Brian Salomon1edc5b92016-11-29 13:43:46 -0500826 if (shaderCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800827 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500828 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
bsalomon7ea33f52015-11-22 14:51:00 -0800829 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500830 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800831 }
832 }
833
cdaltonc04ce672016-03-11 14:07:38 -0800834 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500835 shaderCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800836 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500837 shaderCaps->fTexelFetchSupport =
cdaltonf8a6ce82016-04-11 13:02:05 -0700838 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
839 }
840
Brian Salomon1edc5b92016-11-29 13:43:46 -0500841 if (shaderCaps->fTexelFetchSupport) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700842 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500843 shaderCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
cdaltonf8a6ce82016-04-11 13:02:05 -0700844 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
845 } else {
846 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
847 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500848 shaderCaps->fTexelBufferSupport = true;
cdaltonf8a6ce82016-04-11 13:02:05 -0700849 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500850 shaderCaps->fTexelBufferSupport = true;
851 shaderCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700852 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500853 shaderCaps->fTexelBufferSupport = true;
854 shaderCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700855 }
cdaltonc04ce672016-03-11 14:07:38 -0800856 }
857 }
858
Chris Dalton1d616352017-05-31 12:51:23 -0600859 if (kGL_GrGLStandard == standard) {
860 shaderCaps->fVertexIDSupport = true;
861 } else {
862 // Desktop GLSL 3.30 == ES GLSL 3.00.
863 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
864 }
865
egdaniel8dcdedc2015-11-11 06:27:20 -0800866 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
867 // the abs first in a separate expression.
868 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500869 shaderCaps->fCanUseMinAndAbsTogether = false;
egdaniel8dcdedc2015-11-11 06:27:20 -0800870 }
871
bsalomon7ea33f52015-11-22 14:51:00 -0800872 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
egdaniel8dcdedc2015-11-11 06:27:20 -0800873 // thus must us -1.0 * %s.x to work correctly
874 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500875 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
egdaniel8dcdedc2015-11-11 06:27:20 -0800876 }
egdaniel138c2632016-08-17 10:59:00 -0700877
878 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
879 // the original dst color when reading the outColor even after being written to. By using a
880 // local outColor we can work around this bug.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500881 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
882 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
egdaniel138c2632016-08-17 10:59:00 -0700883 }
csmartdalton2e777ea2017-02-15 10:41:27 -0700884
885#ifdef SK_BUILD_FOR_MAC
886 // On at least some MacBooks, geometry shaders fall apart if we use more than one invocation. To
887 // work around this, we always use a single invocation and wrap the shader in a loop. The long-
888 // term plan for this WAR is for it to eventually be baked into SkSL.
889 shaderCaps->fMustImplementGSInvocationsWithLoop = true;
890#endif
Brian Osmanac1e4962017-05-25 11:34:38 -0400891
892 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
893 // color, and that uniform contains an opaque color, and the output of the shader is only based
894 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
895 // that the shader always outputs opaque values. In that case, it appears to remove the shader
896 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
897 // insert an extra bit of math on the uniform that confuses the compiler just enough...
898 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
899 shaderCaps->fMustObfuscateUniformColor = true;
900 }
egdaniel472d44e2015-10-22 08:20:00 -0700901}
902
kkinnunencfe62e32015-07-01 02:58:50 -0700903bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700904 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
905
906 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700907 return false;
908 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700909
kkinnunencfe62e32015-07-01 02:58:50 -0700910 if (kGL_GrGLStandard == ctxInfo.standard()) {
911 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
912 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
913 return false;
914 }
915 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700916 if (!hasChromiumPathRendering &&
917 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700918 return false;
919 }
920 }
921 // We only support v1.3+ of GL_NV_path_rendering which allows us to
922 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
923 // additions are detected by checking the existence of the function.
924 // We also use *Then* functions that not all drivers might have. Check
925 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800926 if (!gli->fFunctions.fStencilThenCoverFillPath ||
927 !gli->fFunctions.fStencilThenCoverStrokePath ||
928 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
929 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
930 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700931 return false;
932 }
933 return true;
934}
bsalomon1aa20292016-01-22 08:16:09 -0800935
Brian Salomon71d9d842016-11-03 13:42:00 -0400936bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800937 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800938 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800939 std::function<bool ()> bindRenderTarget,
940 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400941 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800942 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400943 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800944 return false;
945 }
bsalomon7928ef62016-01-05 10:26:39 -0800946
Brian Salomonbf7b6202016-11-11 16:08:03 -0500947 if (GrPixelConfigIsSint(surfaceConfig) != GrPixelConfigIsSint(readConfig)) {
948 return false;
949 }
950
bsalomon76148af2016-01-12 11:13:47 -0800951 GrGLenum readFormat;
952 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400953 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800954 return false;
955 }
956
bsalomon1aa20292016-01-22 08:16:09 -0800957 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800958 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
959 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
960 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
961 // 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 -0500962 // The manual does not seem to fully match the spec as the spec allows integer formats
963 // when the bound color buffer is an integer buffer. It doesn't specify which integer
964 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500965 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
966 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
967 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800968 return false;
969 }
970 // There is also a set of allowed types, but all the types we use are in the set:
971 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
972 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
973 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
974 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
975 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
976 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
977 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800978 return true;
piotaixre4b23142014-10-02 10:57:53 -0700979 }
bsalomon7928ef62016-01-05 10:26:39 -0800980
bsalomon76148af2016-01-12 11:13:47 -0800981 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500982 switch (fConfigTable[surfaceConfig].fFormatType) {
983 case kNormalizedFixedPoint_FormatType:
984 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
985 return true;
986 }
987 break;
988 case kInteger_FormatType:
989 if (GR_GL_RGBA_INTEGER == readFormat && GR_GL_INT == readType) {
990 return true;
991 }
992 break;
993 case kFloat_FormatType:
994 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
995 return true;
996 }
997 break;
bsalomon7928ef62016-01-05 10:26:39 -0800998 }
999
Brian Salomon71d9d842016-11-03 13:42:00 -04001000 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -08001001 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -04001002 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -08001003 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -08001004 if (!bindRenderTarget()) {
1005 return false;
1006 }
1007 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
1008 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -08001009 rpFormat->fFormat = format;
1010 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -08001011 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -08001012 }
1013
Brian Salomon71d9d842016-11-03 13:42:00 -04001014 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
1015 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -07001016}
1017
Eric Karl5c779752017-05-08 12:02:07 -07001018void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
1019 const GrGLInterface* gli) {
1020 // We need dual source blending and the ability to disable multisample in order to support mixed
1021 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
1022 // renderer is available and enabled; no other path renderers support this feature.
1023 if (fMultisampleDisableSupport &&
1024 this->shaderCaps()->dualSourceBlendingSupport() &&
1025 this->shaderCaps()->pathRenderingSupport() &&
1026 (contextOptions.fGpuPathRenderers & GrContextOptions::GpuPathRenderers::kStencilAndCover)) {
1027 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -04001028 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -07001029 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
1030 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
1031 kChromium_GrGLDriver == ctxInfo.driver())) {
1032 fDiscardRenderTargetSupport = false;
1033 fInvalidateFBType = kNone_InvalidateFBType;
1034 }
1035 }
1036
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001037 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001038 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
1039 // ES3 driver bugs on at least one device with a tiled GPU (N10).
1040 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
1041 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
1042 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
1043 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -08001044 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -07001045 fMSFBOType = kMixedSamples_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -04001046 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1047 fMSFBOType = kStandard_MSFBOType;
1048 fAlpha8IsRenderable = true;
1049 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -04001050 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001051 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001052 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001053 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
1054 fMSFBOType = kES_Apple_MSFBOType;
1055 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001056 } else {
egdanieleed519e2016-01-15 11:36:18 -08001057 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -07001058 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -04001059 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1060 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001061
Brian Salomon00731b42016-10-14 11:30:51 -04001062 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -04001063 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
1064 // Core profile removes ALPHA8 support.
1065 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
1066 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
1067 // present.
1068 fAlpha8IsRenderable = true;
1069 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001070 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1071 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001072 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001073 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001074 }
Eric Karl5c779752017-05-08 12:02:07 -07001075
Robert Phillips3b3307f2017-05-24 07:44:02 -04001076 // We disable MSAA across the board for Intel GPUs
1077 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
1078 fMSFBOType = kNone_MSFBOType;
1079 }
1080
Eric Karl5c779752017-05-08 12:02:07 -07001081 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1082 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
1083 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1084 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
1085 }
1086 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
1087 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
1088 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
1089 // This is to guard against platforms that may not support as many samples for
1090 // glRasterSamples as they do for framebuffers.
1091 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
1092 }
1093 fMaxColorSampleCount = fMaxStencilSampleCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001094}
1095
cdalton1dd05422015-06-12 09:01:18 -07001096void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001097 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -07001098
1099 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
1100 // for now until its own blacklists can be updated.
1101 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
Greg Daniel0ea7d432016-10-27 16:55:52 -04001102 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
cdalton1dd05422015-06-12 09:01:18 -07001103 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -07001104 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -07001105 return;
1106 }
1107
1108 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1109 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001110 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001111 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
1112 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001113 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001114 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1115 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
1116 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
1117 return;
1118 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1119 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001120 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001121 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
1122 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001123 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001124 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1125 // slow on a particular platform.
1126 } else {
1127 return; // No advanced blend support.
1128 }
1129
1130 SkASSERT(this->advancedBlendEquationSupport());
1131
csmartdalton3b88a032016-08-04 14:43:49 -07001132 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1133 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355,00)) {
1134 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
cdalton1dd05422015-06-12 09:01:18 -07001135 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
1136 (1 << kColorBurn_GrBlendEquation);
1137 }
joel.liang9764c402015-07-09 19:46:18 -07001138 if (kARM_GrGLVendor == ctxInfo.vendor()) {
1139 // Blacklist color-burn on ARM until the fix is released.
1140 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
1141 }
cdalton1dd05422015-06-12 09:01:18 -07001142}
1143
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001144namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001145const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001146}
1147
Eric Karl5c779752017-05-08 12:02:07 -07001148void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001149
1150 // Build up list of legal stencil formats (though perhaps not supported on
1151 // the particular gpu/driver) from most preferred to least.
1152
1153 // these consts are in order of most preferred to least preferred
1154 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1155
1156 static const StencilFormat
1157 // internal Format stencil bits total bits packed?
1158 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1159 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1160 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1161 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001162 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001163 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1164
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001165 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001166 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001167 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001168 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1169 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1170
1171 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1172 // require FBO support we can expect these are legal formats and don't
1173 // check. These also all support the unsized GL_STENCIL_INDEX.
1174 fStencilFormats.push_back() = gS8;
1175 fStencilFormats.push_back() = gS16;
1176 if (supportsPackedDS) {
1177 fStencilFormats.push_back() = gD24S8;
1178 }
1179 fStencilFormats.push_back() = gS4;
1180 if (supportsPackedDS) {
1181 fStencilFormats.push_back() = gDS;
1182 }
1183 } else {
1184 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1185 // for other formats.
1186 // ES doesn't support using the unsized format.
1187
1188 fStencilFormats.push_back() = gS8;
1189 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001190 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1191 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001192 fStencilFormats.push_back() = gD24S8;
1193 }
1194 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1195 fStencilFormats.push_back() = gS4;
1196 }
1197 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001198}
1199
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001200SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001201
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001202 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001203
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001204 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001205 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001206 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001207 i,
1208 fStencilFormats[i].fStencilBits,
1209 fStencilFormats[i].fTotalBits);
1210 }
1211
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001212 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001213 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001214 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001215 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001216 "IMG MS To Texture",
1217 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001218 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001219 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001220 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001221 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1222 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1223 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1224 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1225 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001226 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001227
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001228 static const char* kInvalidateFBTypeStr[] = {
1229 "None",
1230 "Discard",
1231 "Invalidate",
1232 };
1233 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1234 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1235 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1236 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001237
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001238 static const char* kMapBufferTypeStr[] = {
1239 "None",
1240 "MapBuffer",
1241 "MapBufferRange",
1242 "Chromium",
1243 };
1244 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1245 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1246 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1247 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1248 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1249
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001250 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001251 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001252 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001253 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001254 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001255 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1256 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1257 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1258 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001259
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001260 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001261 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
Robert Phillips5ab72762017-06-07 12:04:18 -04001262 r.appendf("Alpha8 is renderable: %s\n", (fAlpha8IsRenderable ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001263 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001264 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001265 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1266 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton06604b92016-02-05 10:09:51 -08001267 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1268 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1269 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001270 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1271 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001272 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001273 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001274 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
halcanary9d524f22016-03-29 09:03:52 -07001275 r.appendf("BGRA to RGBA readback conversions are slow: %s\n",
ericrkb4ecabd2016-03-11 15:18:20 -08001276 (fRGBAToBGRAReadbackConversionsAreSlow ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001277
1278 r.append("Configs\n-------\n");
1279 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1280 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001281 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1282 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001283 i,
1284 fConfigTable[i].fFlags,
1285 fConfigTable[i].fFormats.fBaseInternalFormat,
1286 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001287 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1288 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001289 fConfigTable[i].fFormats.fExternalType,
1290 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001291 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001292 }
1293
jvanverthe9c0fc62015-04-29 11:18:05 -07001294 return r;
1295}
1296
jvanverthe9c0fc62015-04-29 11:18:05 -07001297static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1298 switch (p) {
1299 case kLow_GrSLPrecision:
1300 return GR_GL_LOW_FLOAT;
1301 case kMedium_GrSLPrecision:
1302 return GR_GL_MEDIUM_FLOAT;
1303 case kHigh_GrSLPrecision:
1304 return GR_GL_HIGH_FLOAT;
Brian Osman33aa2c72017-04-05 09:26:15 -04001305 default:
1306 SkFAIL("Unexpected precision type.");
1307 return -1;
jvanverthe9c0fc62015-04-29 11:18:05 -07001308 }
jvanverthe9c0fc62015-04-29 11:18:05 -07001309}
1310
1311static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1312 switch (type) {
1313 case kVertex_GrShaderType:
1314 return GR_GL_VERTEX_SHADER;
1315 case kGeometry_GrShaderType:
1316 return GR_GL_GEOMETRY_SHADER;
1317 case kFragment_GrShaderType:
1318 return GR_GL_FRAGMENT_SHADER;
1319 }
1320 SkFAIL("Unknown shader type.");
1321 return -1;
1322}
1323
jvanverthcba99b82015-06-24 06:59:57 -07001324void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
halcanary9d524f22016-03-29 09:03:52 -07001325 const GrGLInterface* intf,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001326 GrShaderCaps* shaderCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001327 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1328 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1329 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1330 if (kGeometry_GrShaderType != s) {
1331 GrShaderType shaderType = static_cast<GrShaderType>(s);
1332 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001333 GrShaderCaps::PrecisionInfo* first = nullptr;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001334 shaderCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001335 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1336 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1337 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1338 GrGLint range[2];
1339 GrGLint bits;
1340 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1341 if (bits) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001342 shaderCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1343 shaderCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1344 shaderCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001345 if (!first) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001346 first = &shaderCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001347 }
Brian Salomon1edc5b92016-11-29 13:43:46 -05001348 else if (!shaderCaps->fShaderPrecisionVaries) {
1349 shaderCaps->fShaderPrecisionVaries =
1350 (*first != shaderCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001351 }
1352 }
1353 }
1354 }
1355 }
1356 }
1357 else {
1358 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
Brian Salomon1edc5b92016-11-29 13:43:46 -05001359 shaderCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001360 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1361 if (kGeometry_GrShaderType != s) {
1362 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001363 shaderCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1364 shaderCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1365 shaderCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001366 }
1367 }
1368 }
1369 }
1370 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1371 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1372 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1373 // are recommended against.
Brian Salomon1edc5b92016-11-29 13:43:46 -05001374 if (shaderCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001375 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001376 shaderCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1377 shaderCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001378 }
1379 }
Brian Salomon1edc5b92016-11-29 13:43:46 -05001380 shaderCaps->initSamplerPrecisionTable();
jvanverthe9c0fc62015-04-29 11:18:05 -07001381}
1382
bsalomon41e4384e2016-01-08 09:12:44 -08001383bool GrGLCaps::bgraIsInternalFormat() const {
1384 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1385}
1386
bsalomon76148af2016-01-12 11:13:47 -08001387bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1388 GrGLenum* internalFormat, GrGLenum* externalFormat,
1389 GrGLenum* externalType) const {
1390 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1391 externalFormat, externalType)) {
1392 return false;
1393 }
1394 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1395 return true;
1396}
1397
bsalomon76148af2016-01-12 11:13:47 -08001398bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1399 GrGLenum* externalFormat, GrGLenum* externalType) const {
1400 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1401 externalFormat, externalType)) {
1402 return false;
1403 }
1404 return true;
1405}
1406
1407bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001408 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1409 return true;
1410}
1411
1412bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1413 ExternalFormatUsage usage, GrGLenum* externalFormat,
1414 GrGLenum* externalType) const {
1415 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001416
1417 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1418 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1419
1420 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1421 // made to work in many cases using glPixelStore and what not but is not needed currently.
1422 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1423 return false;
1424 }
1425
1426 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1427 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1428
bsalomone9573312016-01-25 14:33:25 -08001429 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1430 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1431 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1432 // texture, not the red component.
1433 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1434 if (this->textureRedSupport()) {
1435 SkASSERT(GR_GL_RED == *externalFormat);
1436 *externalFormat = GR_GL_ALPHA;
1437 }
1438 }
1439
bsalomon76148af2016-01-12 11:13:47 -08001440 return true;
1441}
1442
brianosman20471892016-12-02 06:43:32 -08001443void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1444 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001445 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001446 /*
1447 Comments on renderability of configs on various GL versions.
1448 OpenGL < 3.0:
1449 no built in support for render targets.
1450 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1451 format RGB, RGBA and NV float formats we don't use.
1452 This is the following:
1453 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1454 RGB10_A2, RGBA12,RGBA16
1455 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1456 since they aren't required by later standards and the driver can simply return
1457 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1458 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1459 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1460 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1461 This adds a lot of additional renderable sized formats, including ALPHA8.
1462 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1463 16F, 32I, 32UI, and 32F variants).
1464 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1465
1466 For both the above extensions we limit ourselves to those that are also required by
1467 OpenGL 3.0.
1468
1469 OpenGL 3.0:
1470 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1471 but are not required to be supported as renderable textures/renderbuffer.
1472 Required renderable color formats:
1473 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1474 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1475 RGB10_A2.
1476 - R11F_G11F_B10F.
1477 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1478 and RG8UI.
1479 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1480 - ALPHA8
1481
1482 OpenGL 3.1, 3.2, 3.3
1483 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1484 OpengGL 3.3, 4.0, 4.1
1485 Adds RGB10_A2UI.
1486 OpengGL 4.2
1487 Adds
1488 - RGB5_A1, RGBA4
1489 - RGB565
1490 OpenGL 4.4
1491 Does away with the separate list and adds a column to the sized internal color format
1492 table. However, no new formats become required color renderable.
1493
1494 ES 2.0
1495 color renderable: RGBA4, RGB5_A1, RGB565
1496 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1497 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1498 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1499 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1500 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1501 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1502
1503 ES 3.0
1504 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1505 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1506 RGB5_A1.
1507 - RGB8 and RGB565.
1508 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1509 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1510 ES 3.1
1511 Adds RGB10_A2, RGB10_A2UI,
1512 ES 3.2
1513 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1514 */
Brian Salomon71d9d842016-11-03 13:42:00 -04001515 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1516 ConfigInfo::kFBOColorAttachment_Flag;
1517 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001518 if (kNone_MSFBOType != fMSFBOType) {
1519 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1520 }
bsalomon41e4384e2016-01-08 09:12:44 -08001521 GrGLStandard standard = ctxInfo.standard();
1522 GrGLVersion version = ctxInfo.version();
1523
cblume790d5132016-02-29 11:13:29 -08001524 bool texStorageSupported = false;
1525 if (kGL_GrGLStandard == standard) {
1526 // The EXT version can apply to either GL or GLES.
1527 texStorageSupported = version >= GR_GL_VER(4,2) ||
1528 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1529 ctxInfo.hasExtension("GL_EXT_texture_storage");
1530 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001531 texStorageSupported = version >= GR_GL_VER(3,0) ||
1532 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001533 }
1534
1535 // TODO: remove after command buffer supports full ES 3.0
1536 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1537 kChromium_GrGLDriver == ctxInfo.driver()) {
1538 texStorageSupported = false;
1539 }
1540
cdalton74b8d322016-04-11 14:47:28 -07001541 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1542
bsalomon30447372015-12-21 09:03:05 -08001543 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1544 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001545 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001546 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001547 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001548 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001549
1550 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1551 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001552 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1553 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001554 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001555 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001556 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1557 if (kGL_GrGLStandard == standard) {
1558 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1559 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001560 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001561 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1562 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1563 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1564 }
egdaniel4999df82016-01-07 17:06:04 -08001565 }
cblume790d5132016-02-29 11:13:29 -08001566 if (texStorageSupported) {
1567 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1568 }
cdalton74b8d322016-04-11 14:47:28 -07001569 if (texelBufferSupport) {
1570 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1571 }
bsalomoncdee0092016-01-08 13:20:12 -08001572 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001573
bsalomon76148af2016-01-12 11:13:47 -08001574 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1575 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001576 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001577 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001578 if (kGL_GrGLStandard == standard) {
1579 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1580 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1581 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1582 // Since the internal format is RGBA8, it is also renderable.
1583 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1584 allRenderFlags;
1585 }
1586 } else {
1587 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1588 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1589 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001590 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1591 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1592 // driver remembers the external format when the texture is created (with TexImage).
1593 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1594 // We could work around this, but it adds even more state tracking to code that is
1595 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1596 // This also side-steps some ambiguous interactions with the texture storage extension.
1597 if (version >= GR_GL_VER(3,0)) {
1598 // The APPLE extension doesn't make this renderable.
1599 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
bsalomon41e4384e2016-01-08 09:12:44 -08001600 }
1601 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1602 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Salomon71d9d842016-11-03 13:42:00 -04001603 nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001604 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001605 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001606 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1607 ConfigInfo::kRenderableWithMSAA_Flag;
1608 }
1609 }
1610 }
Brian Osman48c99192017-06-02 08:45:06 -04001611
1612 bool isX86PowerVR = false;
1613#if defined(SK_CPU_X86)
1614 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1615 isX86PowerVR = true;
1616 }
1617#endif
1618
1619 // Adreno 3xx, 4xx, 5xx, and NexusPlayer all fail if we try to use TexStorage with BGRA
1620 if (texStorageSupported &&
1621 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
1622 kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
1623 kAdreno5xx_GrGLRenderer != ctxInfo.renderer() &&
1624 !isX86PowerVR) {
1625 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001626 }
bsalomoncdee0092016-01-08 13:20:12 -08001627 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001628
brianosmana6359362016-03-21 06:55:37 -07001629 // We only enable srgb support if both textures and FBOs support srgb,
brianosman35b784d2016-05-05 11:52:53 -07001630 // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
bsalomon41e4384e2016-01-08 09:12:44 -08001631 if (kGL_GrGLStandard == standard) {
1632 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001633 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001634 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1635 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1636 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001637 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001638 }
1639 }
1640 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001641 if (fSRGBSupport) {
1642 fSRGBWriteControl = true;
1643 }
bsalomon41e4384e2016-01-08 09:12:44 -08001644 } else {
brianosman20471892016-12-02 06:43:32 -08001645 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Osman48c99192017-06-02 08:45:06 -04001646 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1647 // blacklist that device (and any others that might be sharing the same driver).
1648 if (isX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001649 fSRGBSupport = false;
1650 }
bsalomon41e4384e2016-01-08 09:12:44 -08001651 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1652 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001653 // See https://bug.skia.org/5329 for Adreno4xx issue.
1654 fSRGBWriteControl = kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
1655 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001656 }
brianosman20471892016-12-02 06:43:32 -08001657 if (contextOptions.fRequireDecodeDisableForSRGB && !fSRGBDecodeDisableSupport) {
1658 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode. Clients
1659 // can opt-out of that requirement, if they intend to always do linear blending.
brianosmana6359362016-03-21 06:55:37 -07001660 fSRGBSupport = false;
1661 }
brianosman20471892016-12-02 06:43:32 -08001662
1663 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1664 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1665 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1666 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1667 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1668 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1669 // affects Windows.
1670 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1671 fSRGBSupport = false;
1672 }
1673
Brian Osman48c99192017-06-02 08:45:06 -04001674 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1675 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1676 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1677
Brian Osman67999392017-05-31 16:19:34 -04001678 uint32_t srgbRenderFlags = allRenderFlags;
1679 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers
1680#if defined(SK_BUILD_FOR_MAC)
1681 if (kATI_GrGLVendor == ctxInfo.vendor()) {
1682 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1683 }
1684#endif
1685
bsalomon30447372015-12-21 09:03:05 -08001686 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1687 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1688 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1689 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001690 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1691 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001692 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001693 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001694 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001695 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001696 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001697 }
Brian Osman48c99192017-06-02 08:45:06 -04001698 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1699 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001700 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1701 }
bsalomoncdee0092016-01-08 13:20:12 -08001702 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001703 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1704 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1705 // is in this format, for example).
1706 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1707 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1708 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1709 // external format is GL_BGRA.
1710 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1711 GR_GL_BGRA;
1712 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1713 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001714 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001715 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001716 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001717 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001718
brianosmana6359362016-03-21 06:55:37 -07001719 if (texStorageSupported) {
1720 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1721 }
1722 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1723
Brian Salomonbf7b6202016-11-11 16:08:03 -05001724 bool hasIntegerTextures;
1725 if (standard == kGL_GrGLStandard) {
1726 hasIntegerTextures = version >= GR_GL_VER(3, 0) ||
1727 ctxInfo.hasExtension("GL_EXT_texture_integer");
1728 } else {
1729 hasIntegerTextures = (version >= GR_GL_VER(3, 0));
1730 }
1731 // We may have limited GLSL to an earlier version that doesn't have integer sampler types.
1732 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
1733 hasIntegerTextures = false;
1734 }
1735 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA_INTEGER;
1736 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8I;
1737 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RGBA_INTEGER;
1738 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fExternalType = GR_GL_BYTE;
1739 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormatType = kInteger_FormatType;
1740 // We currently only support using integer textures as srcs, not for rendering (even though GL
1741 // allows it).
1742 if (hasIntegerTextures) {
1743 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1744 ConfigInfo::kFBOColorAttachment_Flag;
1745 if (texStorageSupported) {
1746 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags |=
1747 ConfigInfo::kCanUseTexStorage_Flag;
1748 }
1749 }
1750
bsalomon30447372015-12-21 09:03:05 -08001751 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1752 if (this->ES2CompatibilitySupport()) {
1753 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1754 } else {
1755 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1756 }
bsalomon76148af2016-01-12 11:13:47 -08001757 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1758 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001759 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001760 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001761 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1762 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001763 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001764 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1765 }
1766 } else {
1767 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1768 }
cblume790d5132016-02-29 11:13:29 -08001769 // 565 is not a sized internal format on desktop GL. So on desktop with
1770 // 565 we always use an unsized internal format to let the system pick
1771 // the best sized format to convert the 565 data to. Since TexStorage
1772 // only allows sized internal formats we disallow it.
1773 //
1774 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1775 // update.
1776 if (texStorageSupported && kGL_GrGLStandard != standard) {
1777 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1778 }
bsalomoncdee0092016-01-08 13:20:12 -08001779 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001780
1781 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1782 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001783 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1784 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001785 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001786 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001787 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1788 if (kGL_GrGLStandard == standard) {
1789 if (version >= GR_GL_VER(4, 2)) {
1790 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1791 }
1792 } else {
1793 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1794 }
cblume790d5132016-02-29 11:13:29 -08001795 if (texStorageSupported) {
1796 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1797 }
bsalomoncdee0092016-01-08 13:20:12 -08001798 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001799
Brian Osmanf4faccd2017-01-10 16:53:58 -05001800 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1801 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1802 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001803 if (this->textureRedSupport()) {
1804 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1805 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001806 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1807 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001808 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001809 if (texelBufferSupport) {
1810 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1811 }
Robert Phillips5ab72762017-06-07 12:04:18 -04001812 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
bsalomon30447372015-12-21 09:03:05 -08001813 } else {
1814 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1815 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001816 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1817 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001818 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
Robert Phillips5ab72762017-06-07 12:04:18 -04001819 if (fAlpha8IsRenderable) {
1820 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1821 }
bsalomon30447372015-12-21 09:03:05 -08001822 }
Robert Phillips5ab72762017-06-07 12:04:18 -04001823
Brian Osman48c99192017-06-02 08:45:06 -04001824 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1825 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001826 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1827 }
bsalomon41e4384e2016-01-08 09:12:44 -08001828
Brian Osmanf4faccd2017-01-10 16:53:58 -05001829 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1830 fConfigTable[kGray_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1831 fConfigTable[kGray_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001832 if (this->textureRedSupport()) {
1833 fConfigTable[kGray_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1834 fConfigTable[kGray_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
1835 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1836 GR_GL_RED;
1837 fConfigTable[kGray_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRA();
1838 if (texelBufferSupport) {
1839 fConfigTable[kGray_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1840 }
1841 } else {
1842 fConfigTable[kGray_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1843 fConfigTable[kGray_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
1844 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1845 GR_GL_LUMINANCE;
1846 fConfigTable[kGray_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1847 }
Brian Osman986563b2017-01-10 14:20:02 -05001848#if 0 // Leaving Gray8 as non-renderable, to keep things simple and match raster
1849 if (this->textureRedSupport() ||
1850 (kDesktop_ARB_MSFBOType == this->msFBOType() &&
1851 ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
1852 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1853 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1854 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
1855 fConfigTable[kGray_8_GrPixelConfig].fFlags |= allRenderFlags;
1856 }
1857#endif
Brian Osman48c99192017-06-02 08:45:06 -04001858 if (texStorageSupported && !isCommandBufferES2) {
Brian Osman986563b2017-01-10 14:20:02 -05001859 fConfigTable[kGray_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1860 }
1861
bsalomon41e4384e2016-01-08 09:12:44 -08001862 // Check for [half] floating point texture support
1863 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1864 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1865 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1866 bool hasFPTextures = false;
1867 bool hasHalfFPTextures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001868 bool rgIsTexturable = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001869 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001870 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001871
1872 if (kGL_GrGLStandard == standard) {
1873 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1874 hasFPTextures = true;
1875 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001876 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001877 }
1878 } else {
1879 if (version >= GR_GL_VER(3, 1)) {
1880 hasFPTextures = true;
1881 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001882 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001883 } else {
1884 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1885 ctxInfo.hasExtension("GL_OES_texture_float")) {
1886 hasFPTextures = true;
1887 }
1888 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1889 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1890 hasHalfFPTextures = true;
1891 }
1892 }
1893 }
bsalomon30447372015-12-21 09:03:05 -08001894
csmartdalton6aa0e112017-02-08 16:14:11 -05001895 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1896 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1897 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1898 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1899 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
1900 fConfigTable[fpconfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = format;
1901 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1902 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
1903 if (hasFPTextures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001904 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
csmartdalton6aa0e112017-02-08 16:14:11 -05001905 // For now we only enable rendering to float on desktop, because on ES we'd have to
1906 // solve many precision issues and no clients actually want this yet.
1907 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1908 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1909 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1910 }
bsalomon41e4384e2016-01-08 09:12:44 -08001911 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001912 if (texStorageSupported) {
1913 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1914 }
1915 if (texelBufferSupport) {
1916 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1917 }
1918 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001919 }
bsalomon30447372015-12-21 09:03:05 -08001920
1921 if (this->textureRedSupport()) {
1922 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1923 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001924 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1925 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001926 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001927 if (texelBufferSupport) {
1928 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |=
1929 ConfigInfo::kCanUseWithTexelBuffer_Flag;
1930 }
bsalomon30447372015-12-21 09:03:05 -08001931 } else {
1932 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1933 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001934 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1935 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001936 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001937 }
Brian Osman3a887252016-11-17 13:27:31 -05001938 // ANGLE always returns GL_HALF_FLOAT_OES for GL_IMPLEMENTATION_COLOR_READ_TYPE, even though
1939 // ES3 would typically return GL_HALF_FLOAT. The correct fix is for us to respect the value
1940 // returned when we query, but that turns into a bigger refactor, so just work around it.
1941 if (kGL_GrGLStandard == ctxInfo.standard() ||
1942 (ctxInfo.version() >= GR_GL_VER(3, 0) && kANGLE_GrGLDriver != ctxInfo.driver())) {
bsalomon30447372015-12-21 09:03:05 -08001943 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1944 } else {
1945 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1946 }
bsalomon7928ef62016-01-05 10:26:39 -08001947 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
cblume790d5132016-02-29 11:13:29 -08001948 if (texStorageSupported) {
1949 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1950 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001951 if (hasHalfFPTextures) {
1952 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1953 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1954 // GL_RED internal format.
1955 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
1956 (this->textureRedSupport() &&
1957 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1958 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1959 }
1960 }
bsalomon30447372015-12-21 09:03:05 -08001961
1962 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1963 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001964 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1965 GR_GL_RGBA;
Brian Osman3a887252016-11-17 13:27:31 -05001966 // See comment above, re: ANGLE and ES3.
1967 if (kGL_GrGLStandard == ctxInfo.standard() ||
1968 (ctxInfo.version() >= GR_GL_VER(3, 0) && kANGLE_GrGLDriver != ctxInfo.driver())) {
bsalomon30447372015-12-21 09:03:05 -08001969 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1970 } else {
1971 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1972 }
bsalomon7928ef62016-01-05 10:26:39 -08001973 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001974 if (hasHalfFPTextures) {
1975 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1976 // ES requires 3.2 or EXT_color_buffer_half_float.
1977 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1978 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1979 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1980 }
1981 }
cblume790d5132016-02-29 11:13:29 -08001982 if (texStorageSupported) {
1983 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1984 }
cdalton74b8d322016-04-11 14:47:28 -07001985 if (texelBufferSupport) {
1986 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1987 }
bsalomoncdee0092016-01-08 13:20:12 -08001988 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001989
bsalomon30447372015-12-21 09:03:05 -08001990 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1991
1992 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001993 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1994 ctxInfo.version() >= GR_GL_VER(3,0));
1995 // All ES versions (thus far) require sized internal formats for render buffers.
1996 // TODO: Always use sized internal format?
1997 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1998
bsalomon30447372015-12-21 09:03:05 -08001999 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08002000 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
2001 // param to glTex[Sub]Image.
2002 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
2003 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
2004 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
2005 fConfigTable[i].fFormats.fSizedInternalFormat :
2006 fConfigTable[i].fFormats.fBaseInternalFormat;
2007 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08002008 fConfigTable[i].fFormats.fSizedInternalFormat :
2009 fConfigTable[i].fFormats.fBaseInternalFormat;
2010 }
2011 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
2012 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
2013 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
2014 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
2015 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08002016 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08002017 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07002018
2019 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
2020 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
2021 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
2022 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08002023 }
2024
2025 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
2026 // as a base format.
2027 // GL_EXT_texture_format_BGRA8888:
2028 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
2029 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
2030 // formats.
halcanary9d524f22016-03-29 09:03:52 -07002031 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08002032 // ES 2.0: the extension makes BGRA an external format but not an internal format.
2033 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
2034 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08002035 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08002036 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
2037 }
2038
bsalomoncdee0092016-01-08 13:20:12 -08002039 // If we don't have texture swizzle support then the shader generator must insert the
2040 // swizzle into shader code.
2041 if (!this->textureSwizzleSupport()) {
2042 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05002043 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08002044 }
2045 }
2046
bsalomon7f9b2e42016-01-12 13:29:26 -08002047 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
2048 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
2049 // gets written to the single component.
2050 if (this->textureRedSupport()) {
2051 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
2052 GrPixelConfig config = static_cast<GrPixelConfig>(i);
2053 if (GrPixelConfigIsAlphaOnly(config) &&
2054 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05002055 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08002056 }
2057 }
2058 }
2059
Brian Salomonf9f45122016-11-29 11:59:17 -05002060 // We currently only support images on rgba textures formats. We could add additional formats
2061 // if desired. The shader builder would have to be updated to add swizzles where appropriate
2062 // (e.g. where we use GL_RED textures to implement alpha configs).
2063 if (this->shaderCaps()->imageLoadStoreSupport()) {
2064 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags |=
2065 ConfigInfo::kCanUseAsImageStorage_Flag;
2066 // In OpenGL ES a texture may only be used with BindImageTexture if it has been made
2067 // immutable via TexStorage. We create non-integer textures as mutable textures using
2068 // TexImage because we may lazily add MIP levels. Thus, on ES we currently disable image
2069 // storage support for non-integer textures.
2070 if (kGL_GrGLStandard == ctxInfo.standard()) {
2071 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseAsImageStorage_Flag;
2072 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |=
2073 ConfigInfo::kCanUseAsImageStorage_Flag;
2074 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseAsImageStorage_Flag;
2075 }
2076 }
2077
bsalomon30447372015-12-21 09:03:05 -08002078#ifdef SK_DEBUG
2079 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002080 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002081 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002082 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2083 // renderable.
2084 SkASSERT(!((ConfigInfo::kRenderable_Flag) && !(ConfigInfo::kFBOColorAttachment_Flag)));
2085 SkASSERT(!((ConfigInfo::kRenderableWithMSAA_Flag) && !(ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002086 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2087 fConfigTable[i].fFormats.fBaseInternalFormat);
2088 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002089 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002090 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2091 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2092 fConfigTable[i].fFormats.fExternalFormat[j]);
2093 }
2094 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002095 }
2096#endif
2097}
2098
Robert Phillipsbf25d432017-04-07 10:08:53 -04002099bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Eric Karl74480882017-04-03 14:49:05 -07002100 bool* rectsMustMatch, bool* disallowSubrect) const {
2101 // By default, we don't require rects to match.
2102 *rectsMustMatch = false;
2103
2104 // By default, we allow subrects.
2105 *disallowSubrect = false;
2106
Brian Salomon467921e2017-03-06 16:17:12 -05002107 // If the src is a texture, we can implement the blit as a draw assuming the config is
2108 // renderable.
Robert Phillipsbf25d432017-04-07 10:08:53 -04002109 if (src->asTextureProxy() && this->isConfigRenderable(src->config(), false)) {
2110 desc->fOrigin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002111 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2112 desc->fConfig = src->config();
2113 return true;
2114 }
2115
Robert Phillipsbf25d432017-04-07 10:08:53 -04002116 {
2117 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2118 // wrapped. In that case the proxy would already be instantiated.
2119 const GrTexture* srcTexture = src->priv().peekTexture();
2120 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2121 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2122 // Not supported for FBO blit or CopyTexSubImage
2123 return false;
2124 }
Brian Salomon467921e2017-03-06 16:17:12 -05002125 }
2126
2127 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2128 // possible and we return false to fallback to creating a render target dst for render-to-
2129 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2130 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002131 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002132 bool rectsMustMatchForBlitFramebuffer = false;
2133 bool disallowSubrectForBlitFramebuffer = false;
2134 if (src->numColorSamples() &&
2135 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2136 rectsMustMatchForBlitFramebuffer = true;
2137 disallowSubrectForBlitFramebuffer = true;
2138 // Mirroring causes rects to mismatch later, don't allow it.
2139 originForBlitFramebuffer = src->origin();
2140 } else if (src->numColorSamples() && (this->blitFramebufferSupportFlags() &
2141 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
2142 rectsMustMatchForBlitFramebuffer = true;
2143 // Mirroring causes rects to mismatch later, don't allow it.
2144 originForBlitFramebuffer = src->origin();
2145 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002146 originForBlitFramebuffer = src->origin();
2147 }
2148
2149 // Check for format issues with glCopyTexSubImage2D
2150 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2151 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2152 // then we set up for that, otherwise fail.
2153 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
2154 desc->fOrigin = originForBlitFramebuffer;
2155 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002156 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2157 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002158 return true;
2159 }
2160 return false;
2161 }
2162
Robert Phillipsbf25d432017-04-07 10:08:53 -04002163 {
Brian Salomon63e79732017-05-15 21:23:13 -04002164 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2165 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002166 if (srcIsMSAARenderbuffer) {
2167 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2168 // blit or fail.
2169 if (this->canConfigBeFBOColorAttachment(src->config())) {
2170 desc->fOrigin = originForBlitFramebuffer;
2171 desc->fConfig = src->config();
2172 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2173 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2174 return true;
2175 }
2176 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002177 }
Brian Salomon467921e2017-03-06 16:17:12 -05002178 }
2179
2180 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
2181 desc->fConfig = src->config();
2182 desc->fOrigin = src->origin();
2183 desc->fFlags = kNone_GrSurfaceFlags;
2184 return true;
2185}
2186
csmartdaltone0d36292016-07-29 08:14:20 -07002187void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
2188 if (options.fEnableInstancedRendering) {
2189 fInstancedSupport = gr_instanced::GLInstancedRendering::CheckSupport(*this);
2190#ifndef SK_BUILD_FOR_MAC
2191 // OS X doesn't seem to write correctly to floating point textures when using
2192 // glDraw*Indirect, regardless of the underlying GPU.
2193 fAvoidInstancedDrawsToFPTargets = true;
2194#endif
2195 }
2196}