blob: 84679096227535e329c91c511484f532ea719e9b [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
Brian Salomone03a7292017-06-08 11:00:50 -0400442 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
443 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
444 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
445 // unclear whether this really affects a wide range of devices.
446 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer && ctxInfo.driver() == kQualcomm_GrGLDriver &&
447 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0)) {
448 fMapBufferType = kNone_MapBufferType;
449 fMapBufferFlags = kNone_MapFlags;
450 }
451
jvanverthd7a2c1f2015-12-07 07:36:44 -0800452 if (kGL_GrGLStandard == standard) {
453 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
454 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700455 }
jvanverthd7a2c1f2015-12-07 07:36:44 -0800456 } else {
457 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
458 fTransferBufferType = kPBO_TransferBufferType;
jvanverthc3d706f2016-04-20 10:33:27 -0700459 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
460 fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800461 }
462 }
463
joshualitte5b74c62015-06-01 14:17:47 -0700464 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
465 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700466 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700467#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500468 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
469 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
470 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700471 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700472#else
cdalton397536c2016-03-25 12:15:03 -0700473 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700474#endif
joshualitte5b74c62015-06-01 14:17:47 -0700475 }
476
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000477 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000478 fNPOTTextureTileSupport = true;
479 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000480 } else {
481 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000482 // ES3 has no limitations.
483 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
484 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000485 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
486 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
487 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
488 // to alllow arbitrary wrap modes, however.
489 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000490 }
491
bsalomone72bd022015-10-26 07:33:03 -0700492 // Using MIPs on this GPU seems to be a source of trouble.
493 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
494 fMipMapSupport = false;
495 }
496
bsalomon@google.combcce8922013-03-25 15:38:39 +0000497 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
498 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
499 // Our render targets are always created with textures as the color
500 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000501 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000502
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000503 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
504
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000505 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700506 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000507
robertphillips1b8e1b52015-06-24 06:54:10 -0700508#if 0
509 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
510 kQualcomm_GrGLVendor != ctxInfo.vendor();
511#endif
512
csmartdalton9bc11872016-08-09 12:42:47 -0700513 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
514 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700515 }
516
bsalomon63b21962014-11-05 07:05:34 -0800517 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800518 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon1b52df32017-03-24 18:49:09 -0400519 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
520 ctxInfo.driver() != kChromium_GrGLDriver)) {
bsalomon63b21962014-11-05 07:05:34 -0800521 fUseDrawInsteadOfClear = true;
522 }
523
joshualitt83bc2292015-06-18 14:18:02 -0700524 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomonfdd11702017-05-31 15:59:40 +0000525 fUseDrawInsteadOfPartialRenderTargetWrite = true;
Brian Salomonb52fa022017-06-07 09:42:52 -0400526 // This is known to be fixed sometime between driver 145.0 and 219.0
527 if (ctxInfo.driver() == kQualcomm_GrGLDriver &&
528 ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0)) {
529 fUseDrawToClearStencilClip = true;
530 }
joshualitt83bc2292015-06-18 14:18:02 -0700531 }
532
bsalomonbabafcc2016-02-16 11:36:47 -0800533 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
534 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomonfdd11702017-05-31 15:59:40 +0000535 fUseDrawInsteadOfPartialRenderTargetWrite = true;
bsalomonbabafcc2016-02-16 11:36:47 -0800536 fUseDrawInsteadOfAllRenderTargetWrites = true;
537 }
538
robertphillips63926682015-08-20 09:39:02 -0700539#ifdef SK_BUILD_FOR_WIN
540 // On ANGLE deferring flushes can lead to GPU starvation
541 fPreferVRAMUseOverFlushes = !isANGLE;
542#endif
543
bsalomon7dea7b72015-08-19 08:26:51 -0700544 if (kChromium_GrGLDriver == ctxInfo.driver()) {
545 fMustClearUploadedBufferData = true;
546 }
547
bsalomond08ea5f2015-02-20 06:58:13 -0800548 if (kGL_GrGLStandard == standard) {
549 // ARB allows mixed size FBO attachments, EXT does not.
550 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
551 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
552 fOversizedStencilSupport = true;
553 } else {
554 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
555 }
556 } else {
557 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
558 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
559 }
560
joshualitt58001552015-06-26 12:46:36 -0700561 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700562 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
563 ctxInfo.hasExtension("GL_ARB_draw_indirect");
564 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
565 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700566 (fDrawIndirectSupport &&
567 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700568 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700569 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800570 } else {
571 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700572 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
573 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
574 fBaseInstanceSupport = fDrawIndirectSupport &&
575 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700576 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800577 }
578
Brian Salomon1edc5b92016-11-29 13:43:46 -0500579 this->initShaderPrecisionTable(ctxInfo, gli, shaderCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800580
581 if (contextOptions.fUseShaderSwizzling) {
582 fTextureSwizzleSupport = false;
583 }
584
ethannicholas28ef4452016-03-25 09:26:03 -0700585 if (kGL_GrGLStandard == standard) {
ethannicholas6536ae52016-05-02 12:16:49 -0700586 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading")) &&
587 ctxInfo.vendor() != kIntel_GrGLVendor) {
ethannicholas28ef4452016-03-25 09:26:03 -0700588 fSampleShadingSupport = true;
589 }
590 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
591 fSampleShadingSupport = true;
592 }
593
jvanverth84741b32016-09-30 08:39:02 -0700594 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
595 if (kGL_GrGLStandard == standard) {
596 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
597 fFenceSyncSupport = true;
598 }
599 } else if (version >= GR_GL_VER(3, 0)) {
600 fFenceSyncSupport = true;
601 }
602
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400603 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500604 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500605
brianosman131ff132016-06-07 14:22:44 -0700606 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
607 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
608 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
609 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
brianosman09563ce2016-06-02 08:59:34 -0700610 if (fMipMapLevelAndLodControlSupport &&
brianosman9a3fbf72016-06-09 13:11:08 -0700611 (contextOptions.fDoManualMipmapping ||
612 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
brianosman131ff132016-06-07 14:22:44 -0700613 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
614 (kATI_GrGLVendor == ctxInfo.vendor()))) {
brianosman09563ce2016-06-02 08:59:34 -0700615 fDoManualMipmapping = true;
616 }
617
brianosman20471892016-12-02 06:43:32 -0800618 fSRGBDecodeDisableSupport = ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode");
brianosman851c2382016-12-07 10:03:25 -0800619 fSRGBDecodeDisableAffectsMipmaps = fSRGBDecodeDisableSupport &&
620 kChromium_GrGLDriver != ctxInfo.driver();
brianosman20471892016-12-02 06:43:32 -0800621
Brian Salomon028a9a52017-05-11 11:39:08 -0400622 // See http://crbug.com/710443
623#ifdef SK_BUILD_FOR_MAC
624 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
Eric Karlaeaf22b2017-05-18 15:08:09 -0700625 fClearToBoundaryValuesIsBroken = true;
Brian Salomon028a9a52017-05-11 11:39:08 -0400626 }
627#endif
Chris Dalton9926f4b2017-05-17 15:15:50 -0600628 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
629 fDrawArraysBaseVertexIsBroken = true;
630 }
Brian Salomon028a9a52017-05-11 11:39:08 -0400631
bsalomoncdee0092016-01-08 13:20:12 -0800632 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
633 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800634 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700635
636 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500637 shaderCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000638}
639
egdaniel472d44e2015-10-22 08:20:00 -0700640const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
641 bool isCoreProfile) {
642 switch (generation) {
643 case k110_GrGLSLGeneration:
644 if (kGLES_GrGLStandard == standard) {
645 // ES2s shader language is based on version 1.20 but is version
646 // 1.00 of the ES language.
647 return "#version 100\n";
648 } else {
649 SkASSERT(kGL_GrGLStandard == standard);
650 return "#version 110\n";
651 }
652 case k130_GrGLSLGeneration:
653 SkASSERT(kGL_GrGLStandard == standard);
654 return "#version 130\n";
655 case k140_GrGLSLGeneration:
656 SkASSERT(kGL_GrGLStandard == standard);
657 return "#version 140\n";
658 case k150_GrGLSLGeneration:
659 SkASSERT(kGL_GrGLStandard == standard);
660 if (isCoreProfile) {
661 return "#version 150\n";
662 } else {
663 return "#version 150 compatibility\n";
664 }
665 case k330_GrGLSLGeneration:
666 if (kGLES_GrGLStandard == standard) {
667 return "#version 300 es\n";
668 } else {
669 SkASSERT(kGL_GrGLStandard == standard);
670 if (isCoreProfile) {
671 return "#version 330\n";
672 } else {
673 return "#version 330 compatibility\n";
674 }
675 }
cdalton33ad7012016-02-22 07:55:44 -0800676 case k400_GrGLSLGeneration:
677 SkASSERT(kGL_GrGLStandard == standard);
678 if (isCoreProfile) {
679 return "#version 400\n";
680 } else {
681 return "#version 400 compatibility\n";
682 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500683 case k420_GrGLSLGeneration:
684 SkASSERT(kGL_GrGLStandard == standard);
685 if (isCoreProfile) {
686 return "#version 420\n";
687 }
688 else {
689 return "#version 420 compatibility\n";
690 }
egdaniel472d44e2015-10-22 08:20:00 -0700691 case k310es_GrGLSLGeneration:
692 SkASSERT(kGLES_GrGLStandard == standard);
693 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800694 case k320es_GrGLSLGeneration:
695 SkASSERT(kGLES_GrGLStandard == standard);
696 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700697 }
698 return "<no version>";
699}
700
egdaniel05ded892015-10-26 07:38:05 -0700701void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700702 GrGLStandard standard = ctxInfo.standard();
703 GrGLVersion version = ctxInfo.version();
704
705 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500706 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700707 **************************************************************************/
708
Brian Salomon1edc5b92016-11-29 13:43:46 -0500709 GrShaderCaps* shaderCaps = fShaderCaps.get();
710 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700711 if (kGLES_GrGLStandard == standard) {
712 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500713 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
714 shaderCaps->fFBFetchSupport = true;
715 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
716 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700717 }
718 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
719 // 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 -0500720 shaderCaps->fFBFetchNeedsCustomOutput = false;
721 shaderCaps->fFBFetchSupport = true;
722 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
723 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700724 }
725 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
726 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500727 shaderCaps->fFBFetchNeedsCustomOutput = false;
728 shaderCaps->fFBFetchSupport = true;
729 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
730 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700731 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500732 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700733 }
734
egdaniel7517e452016-09-20 13:00:26 -0700735 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
736 // Galaxy S7.
737 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
738 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500739 shaderCaps->fFBFetchSupport = false;
egdaniel7517e452016-09-20 13:00:26 -0700740 }
741
Brian Salomon1edc5b92016-11-29 13:43:46 -0500742 shaderCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
egdaniel472d44e2015-10-22 08:20:00 -0700743
cdaltonc08f1962016-02-12 12:14:06 -0800744 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500745 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800746 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500747 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800748 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
749 }
750
751 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500752 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800753 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
754 } else {
755 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500756 shaderCaps->fNoPerspectiveInterpolationSupport = true;
757 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800758 "GL_NV_shader_noperspective_interpolation";
759 }
760 }
761
cdalton33ad7012016-02-22 07:55:44 -0800762 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500763 shaderCaps->fMultisampleInterpolationSupport =
cdalton4a98cdb2016-03-01 12:12:20 -0800764 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
765 } else {
766 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500767 shaderCaps->fMultisampleInterpolationSupport = true;
cdalton4a98cdb2016-03-01 12:12:20 -0800768 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500769 shaderCaps->fMultisampleInterpolationSupport = true;
770 shaderCaps->fMultisampleInterpolationExtensionString =
cdalton4a98cdb2016-03-01 12:12:20 -0800771 "GL_OES_shader_multisample_interpolation";
772 }
773 }
774
775 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500776 shaderCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
cdalton33ad7012016-02-22 07:55:44 -0800777 } else {
778 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500779 shaderCaps->fSampleVariablesSupport = true;
cdalton33ad7012016-02-22 07:55:44 -0800780 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500781 shaderCaps->fSampleVariablesSupport = true;
782 shaderCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
cdalton33ad7012016-02-22 07:55:44 -0800783 }
784 }
785
Brian Salomon1edc5b92016-11-29 13:43:46 -0500786 if (shaderCaps->fSampleVariablesSupport &&
csmartdaltonf848c9c2016-06-15 12:42:13 -0700787 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage")) {
788 // Pre-361 NVIDIA has a bug with NV_sample_mask_override_coverage.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500789 shaderCaps->fSampleMaskOverrideCoverageSupport =
csmartdaltonf848c9c2016-06-15 12:42:13 -0700790 kNVIDIA_GrGLDriver != ctxInfo.driver() ||
791 ctxInfo.driverVersion() >= GR_GL_DRIVER_VER(361,00);
cdalton33ad7012016-02-22 07:55:44 -0800792 }
793
egdaniel472d44e2015-10-22 08:20:00 -0700794 // 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 -0500795 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
egdaniel472d44e2015-10-22 08:20:00 -0700796
797 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
798 // function that may require a gradient calculation inside a conditional block may return
799 // undefined results". This appears to be an issue with the 'any' call since even the simple
800 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
801 // from our GrTextureDomain processor.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500802 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
egdaniel472d44e2015-10-22 08:20:00 -0700803
Brian Salomon1edc5b92016-11-29 13:43:46 -0500804 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
805 shaderCaps->fGLSLGeneration,
806 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800807
Brian Salomon1edc5b92016-11-29 13:43:46 -0500808 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
809 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800810 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800811
812 // Frag Coords Convention support is not part of ES
813 // Known issue on at least some Intel platforms:
814 // http://code.google.com/p/skia/issues/detail?id=946
815 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
816 kGLES_GrGLStandard != standard &&
817 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
818 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500819 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800820 }
821
822 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500823 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800824 }
825
cdalton9c3f1432016-03-11 10:07:37 -0800826 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
827 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500828 shaderCaps->fExternalTextureSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800829 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
830 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
831 // At least one driver has been found that has this extension without the "GL_" prefix.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500832 shaderCaps->fExternalTextureSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800833 }
834 }
835
Brian Salomon1edc5b92016-11-29 13:43:46 -0500836 if (shaderCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800837 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500838 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
bsalomon7ea33f52015-11-22 14:51:00 -0800839 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500840 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800841 }
842 }
843
cdaltonc04ce672016-03-11 14:07:38 -0800844 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500845 shaderCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800846 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500847 shaderCaps->fTexelFetchSupport =
cdaltonf8a6ce82016-04-11 13:02:05 -0700848 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
849 }
850
Brian Salomon1edc5b92016-11-29 13:43:46 -0500851 if (shaderCaps->fTexelFetchSupport) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700852 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500853 shaderCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
cdaltonf8a6ce82016-04-11 13:02:05 -0700854 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
855 } else {
856 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
857 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500858 shaderCaps->fTexelBufferSupport = true;
cdaltonf8a6ce82016-04-11 13:02:05 -0700859 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500860 shaderCaps->fTexelBufferSupport = true;
861 shaderCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700862 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500863 shaderCaps->fTexelBufferSupport = true;
864 shaderCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700865 }
cdaltonc04ce672016-03-11 14:07:38 -0800866 }
867 }
868
Chris Dalton1d616352017-05-31 12:51:23 -0600869 if (kGL_GrGLStandard == standard) {
870 shaderCaps->fVertexIDSupport = true;
871 } else {
872 // Desktop GLSL 3.30 == ES GLSL 3.00.
873 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
874 }
875
egdaniel8dcdedc2015-11-11 06:27:20 -0800876 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
877 // the abs first in a separate expression.
878 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500879 shaderCaps->fCanUseMinAndAbsTogether = false;
egdaniel8dcdedc2015-11-11 06:27:20 -0800880 }
881
bsalomon7ea33f52015-11-22 14:51:00 -0800882 // 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 -0800883 // thus must us -1.0 * %s.x to work correctly
884 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500885 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
egdaniel8dcdedc2015-11-11 06:27:20 -0800886 }
egdaniel138c2632016-08-17 10:59:00 -0700887
888 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
889 // the original dst color when reading the outColor even after being written to. By using a
890 // local outColor we can work around this bug.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500891 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
892 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
egdaniel138c2632016-08-17 10:59:00 -0700893 }
csmartdalton2e777ea2017-02-15 10:41:27 -0700894
895#ifdef SK_BUILD_FOR_MAC
896 // On at least some MacBooks, geometry shaders fall apart if we use more than one invocation. To
897 // work around this, we always use a single invocation and wrap the shader in a loop. The long-
898 // term plan for this WAR is for it to eventually be baked into SkSL.
899 shaderCaps->fMustImplementGSInvocationsWithLoop = true;
900#endif
Brian Osmanac1e4962017-05-25 11:34:38 -0400901
902 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
903 // color, and that uniform contains an opaque color, and the output of the shader is only based
904 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
905 // that the shader always outputs opaque values. In that case, it appears to remove the shader
906 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
907 // insert an extra bit of math on the uniform that confuses the compiler just enough...
908 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
909 shaderCaps->fMustObfuscateUniformColor = true;
910 }
egdaniel472d44e2015-10-22 08:20:00 -0700911}
912
kkinnunencfe62e32015-07-01 02:58:50 -0700913bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700914 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
915
916 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700917 return false;
918 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700919
kkinnunencfe62e32015-07-01 02:58:50 -0700920 if (kGL_GrGLStandard == ctxInfo.standard()) {
921 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
922 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
923 return false;
924 }
925 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700926 if (!hasChromiumPathRendering &&
927 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700928 return false;
929 }
930 }
931 // We only support v1.3+ of GL_NV_path_rendering which allows us to
932 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
933 // additions are detected by checking the existence of the function.
934 // We also use *Then* functions that not all drivers might have. Check
935 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800936 if (!gli->fFunctions.fStencilThenCoverFillPath ||
937 !gli->fFunctions.fStencilThenCoverStrokePath ||
938 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
939 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
940 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700941 return false;
942 }
943 return true;
944}
bsalomon1aa20292016-01-22 08:16:09 -0800945
Brian Salomon71d9d842016-11-03 13:42:00 -0400946bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800947 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800948 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -0800949 std::function<bool ()> bindRenderTarget,
950 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -0400951 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -0800952 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -0400953 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -0800954 return false;
955 }
bsalomon7928ef62016-01-05 10:26:39 -0800956
Brian Salomonbf7b6202016-11-11 16:08:03 -0500957 if (GrPixelConfigIsSint(surfaceConfig) != GrPixelConfigIsSint(readConfig)) {
958 return false;
959 }
960
bsalomon76148af2016-01-12 11:13:47 -0800961 GrGLenum readFormat;
962 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -0400963 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800964 return false;
965 }
966
bsalomon1aa20292016-01-22 08:16:09 -0800967 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800968 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
969 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
970 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
971 // 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 -0500972 // The manual does not seem to fully match the spec as the spec allows integer formats
973 // when the bound color buffer is an integer buffer. It doesn't specify which integer
974 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -0500975 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
976 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
977 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -0800978 return false;
979 }
980 // There is also a set of allowed types, but all the types we use are in the set:
981 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
982 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
983 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
984 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
985 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
986 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
987 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800988 return true;
piotaixre4b23142014-10-02 10:57:53 -0700989 }
bsalomon7928ef62016-01-05 10:26:39 -0800990
bsalomon76148af2016-01-12 11:13:47 -0800991 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -0500992 switch (fConfigTable[surfaceConfig].fFormatType) {
993 case kNormalizedFixedPoint_FormatType:
994 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
995 return true;
996 }
997 break;
998 case kInteger_FormatType:
999 if (GR_GL_RGBA_INTEGER == readFormat && GR_GL_INT == readType) {
1000 return true;
1001 }
1002 break;
1003 case kFloat_FormatType:
1004 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
1005 return true;
1006 }
1007 break;
bsalomon7928ef62016-01-05 10:26:39 -08001008 }
1009
Brian Salomon71d9d842016-11-03 13:42:00 -04001010 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -08001011 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -04001012 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -08001013 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -08001014 if (!bindRenderTarget()) {
1015 return false;
1016 }
1017 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
1018 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -08001019 rpFormat->fFormat = format;
1020 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -08001021 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -08001022 }
1023
Brian Salomon71d9d842016-11-03 13:42:00 -04001024 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
1025 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -07001026}
1027
Eric Karl5c779752017-05-08 12:02:07 -07001028void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
1029 const GrGLInterface* gli) {
1030 // We need dual source blending and the ability to disable multisample in order to support mixed
1031 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
1032 // renderer is available and enabled; no other path renderers support this feature.
1033 if (fMultisampleDisableSupport &&
1034 this->shaderCaps()->dualSourceBlendingSupport() &&
1035 this->shaderCaps()->pathRenderingSupport() &&
1036 (contextOptions.fGpuPathRenderers & GrContextOptions::GpuPathRenderers::kStencilAndCover)) {
1037 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -04001038 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -07001039 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
1040 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
1041 kChromium_GrGLDriver == ctxInfo.driver())) {
1042 fDiscardRenderTargetSupport = false;
1043 fInvalidateFBType = kNone_InvalidateFBType;
1044 }
1045 }
1046
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001047 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001048 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
1049 // ES3 driver bugs on at least one device with a tiled GPU (N10).
1050 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
1051 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
1052 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
1053 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -08001054 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -07001055 fMSFBOType = kMixedSamples_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -04001056 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1057 fMSFBOType = kStandard_MSFBOType;
1058 fAlpha8IsRenderable = true;
1059 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -04001060 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001061 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001062 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001063 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
1064 fMSFBOType = kES_Apple_MSFBOType;
1065 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001066 } else {
egdanieleed519e2016-01-15 11:36:18 -08001067 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -07001068 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -04001069 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1070 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001071
Brian Salomon00731b42016-10-14 11:30:51 -04001072 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -04001073 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
1074 // Core profile removes ALPHA8 support.
1075 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
1076 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
1077 // present.
1078 fAlpha8IsRenderable = true;
1079 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001080 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1081 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001082 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001083 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001084 }
Eric Karl5c779752017-05-08 12:02:07 -07001085
Robert Phillips3b3307f2017-05-24 07:44:02 -04001086 // We disable MSAA across the board for Intel GPUs
1087 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
1088 fMSFBOType = kNone_MSFBOType;
1089 }
1090
Eric Karl5c779752017-05-08 12:02:07 -07001091 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1092 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
1093 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1094 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
1095 }
1096 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
1097 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
1098 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
1099 // This is to guard against platforms that may not support as many samples for
1100 // glRasterSamples as they do for framebuffers.
1101 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
1102 }
1103 fMaxColorSampleCount = fMaxStencilSampleCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001104}
1105
cdalton1dd05422015-06-12 09:01:18 -07001106void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001107 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -07001108
1109 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
1110 // for now until its own blacklists can be updated.
1111 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
Greg Daniel0ea7d432016-10-27 16:55:52 -04001112 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
cdalton1dd05422015-06-12 09:01:18 -07001113 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -07001114 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -07001115 return;
1116 }
1117
1118 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1119 fBlendEquationSupport = kAdvancedCoherent_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_coherent")) {
1122 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001123 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001124 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1125 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
1126 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
1127 return;
1128 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1129 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001130 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001131 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
1132 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001133 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001134 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1135 // slow on a particular platform.
1136 } else {
1137 return; // No advanced blend support.
1138 }
1139
1140 SkASSERT(this->advancedBlendEquationSupport());
1141
csmartdalton3b88a032016-08-04 14:43:49 -07001142 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1143 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355,00)) {
1144 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
cdalton1dd05422015-06-12 09:01:18 -07001145 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
1146 (1 << kColorBurn_GrBlendEquation);
1147 }
joel.liang9764c402015-07-09 19:46:18 -07001148 if (kARM_GrGLVendor == ctxInfo.vendor()) {
1149 // Blacklist color-burn on ARM until the fix is released.
1150 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
1151 }
cdalton1dd05422015-06-12 09:01:18 -07001152}
1153
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001154namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001155const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001156}
1157
Eric Karl5c779752017-05-08 12:02:07 -07001158void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001159
1160 // Build up list of legal stencil formats (though perhaps not supported on
1161 // the particular gpu/driver) from most preferred to least.
1162
1163 // these consts are in order of most preferred to least preferred
1164 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1165
1166 static const StencilFormat
1167 // internal Format stencil bits total bits packed?
1168 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1169 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1170 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1171 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001172 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001173 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1174
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001175 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001176 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001177 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001178 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1179 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1180
1181 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1182 // require FBO support we can expect these are legal formats and don't
1183 // check. These also all support the unsized GL_STENCIL_INDEX.
1184 fStencilFormats.push_back() = gS8;
1185 fStencilFormats.push_back() = gS16;
1186 if (supportsPackedDS) {
1187 fStencilFormats.push_back() = gD24S8;
1188 }
1189 fStencilFormats.push_back() = gS4;
1190 if (supportsPackedDS) {
1191 fStencilFormats.push_back() = gDS;
1192 }
1193 } else {
1194 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1195 // for other formats.
1196 // ES doesn't support using the unsized format.
1197
1198 fStencilFormats.push_back() = gS8;
1199 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001200 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1201 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001202 fStencilFormats.push_back() = gD24S8;
1203 }
1204 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1205 fStencilFormats.push_back() = gS4;
1206 }
1207 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001208}
1209
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001210SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001211
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001212 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001213
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001214 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001215 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001216 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001217 i,
1218 fStencilFormats[i].fStencilBits,
1219 fStencilFormats[i].fTotalBits);
1220 }
1221
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001222 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001223 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001224 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001225 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001226 "IMG MS To Texture",
1227 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001228 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001229 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001230 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001231 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1232 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1233 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1234 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1235 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001236 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001237
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001238 static const char* kInvalidateFBTypeStr[] = {
1239 "None",
1240 "Discard",
1241 "Invalidate",
1242 };
1243 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1244 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1245 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1246 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001247
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001248 static const char* kMapBufferTypeStr[] = {
1249 "None",
1250 "MapBuffer",
1251 "MapBufferRange",
1252 "Chromium",
1253 };
1254 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1255 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1256 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1257 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1258 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1259
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001260 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001261 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001262 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001263 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001264 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001265 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1266 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1267 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1268 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001269
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001270 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001271 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
Robert Phillips5ab72762017-06-07 12:04:18 -04001272 r.appendf("Alpha8 is renderable: %s\n", (fAlpha8IsRenderable ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001273 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001274 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001275 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1276 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton06604b92016-02-05 10:09:51 -08001277 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1278 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1279 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001280 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1281 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001282 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001283 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001284 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
halcanary9d524f22016-03-29 09:03:52 -07001285 r.appendf("BGRA to RGBA readback conversions are slow: %s\n",
ericrkb4ecabd2016-03-11 15:18:20 -08001286 (fRGBAToBGRAReadbackConversionsAreSlow ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001287
1288 r.append("Configs\n-------\n");
1289 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1290 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001291 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1292 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001293 i,
1294 fConfigTable[i].fFlags,
1295 fConfigTable[i].fFormats.fBaseInternalFormat,
1296 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001297 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1298 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001299 fConfigTable[i].fFormats.fExternalType,
1300 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001301 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001302 }
1303
jvanverthe9c0fc62015-04-29 11:18:05 -07001304 return r;
1305}
1306
jvanverthe9c0fc62015-04-29 11:18:05 -07001307static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1308 switch (p) {
1309 case kLow_GrSLPrecision:
1310 return GR_GL_LOW_FLOAT;
1311 case kMedium_GrSLPrecision:
1312 return GR_GL_MEDIUM_FLOAT;
1313 case kHigh_GrSLPrecision:
1314 return GR_GL_HIGH_FLOAT;
Brian Osman33aa2c72017-04-05 09:26:15 -04001315 default:
1316 SkFAIL("Unexpected precision type.");
1317 return -1;
jvanverthe9c0fc62015-04-29 11:18:05 -07001318 }
jvanverthe9c0fc62015-04-29 11:18:05 -07001319}
1320
1321static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1322 switch (type) {
1323 case kVertex_GrShaderType:
1324 return GR_GL_VERTEX_SHADER;
1325 case kGeometry_GrShaderType:
1326 return GR_GL_GEOMETRY_SHADER;
1327 case kFragment_GrShaderType:
1328 return GR_GL_FRAGMENT_SHADER;
1329 }
1330 SkFAIL("Unknown shader type.");
1331 return -1;
1332}
1333
jvanverthcba99b82015-06-24 06:59:57 -07001334void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
halcanary9d524f22016-03-29 09:03:52 -07001335 const GrGLInterface* intf,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001336 GrShaderCaps* shaderCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001337 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1338 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1339 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1340 if (kGeometry_GrShaderType != s) {
1341 GrShaderType shaderType = static_cast<GrShaderType>(s);
1342 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001343 GrShaderCaps::PrecisionInfo* first = nullptr;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001344 shaderCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001345 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1346 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1347 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1348 GrGLint range[2];
1349 GrGLint bits;
1350 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1351 if (bits) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001352 shaderCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1353 shaderCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1354 shaderCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001355 if (!first) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001356 first = &shaderCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001357 }
Brian Salomon1edc5b92016-11-29 13:43:46 -05001358 else if (!shaderCaps->fShaderPrecisionVaries) {
1359 shaderCaps->fShaderPrecisionVaries =
1360 (*first != shaderCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001361 }
1362 }
1363 }
1364 }
1365 }
1366 }
1367 else {
1368 // 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 -05001369 shaderCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001370 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1371 if (kGeometry_GrShaderType != s) {
1372 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001373 shaderCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1374 shaderCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1375 shaderCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001376 }
1377 }
1378 }
1379 }
1380 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1381 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1382 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1383 // are recommended against.
Brian Salomon1edc5b92016-11-29 13:43:46 -05001384 if (shaderCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001385 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001386 shaderCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1387 shaderCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001388 }
1389 }
Brian Salomon1edc5b92016-11-29 13:43:46 -05001390 shaderCaps->initSamplerPrecisionTable();
jvanverthe9c0fc62015-04-29 11:18:05 -07001391}
1392
bsalomon41e4384e2016-01-08 09:12:44 -08001393bool GrGLCaps::bgraIsInternalFormat() const {
1394 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1395}
1396
bsalomon76148af2016-01-12 11:13:47 -08001397bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1398 GrGLenum* internalFormat, GrGLenum* externalFormat,
1399 GrGLenum* externalType) const {
1400 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1401 externalFormat, externalType)) {
1402 return false;
1403 }
1404 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1405 return true;
1406}
1407
bsalomon76148af2016-01-12 11:13:47 -08001408bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1409 GrGLenum* externalFormat, GrGLenum* externalType) const {
1410 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1411 externalFormat, externalType)) {
1412 return false;
1413 }
1414 return true;
1415}
1416
1417bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001418 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1419 return true;
1420}
1421
1422bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1423 ExternalFormatUsage usage, GrGLenum* externalFormat,
1424 GrGLenum* externalType) const {
1425 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001426
1427 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1428 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1429
1430 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1431 // made to work in many cases using glPixelStore and what not but is not needed currently.
1432 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1433 return false;
1434 }
1435
1436 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1437 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1438
bsalomone9573312016-01-25 14:33:25 -08001439 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1440 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1441 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1442 // texture, not the red component.
1443 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1444 if (this->textureRedSupport()) {
1445 SkASSERT(GR_GL_RED == *externalFormat);
1446 *externalFormat = GR_GL_ALPHA;
1447 }
1448 }
1449
bsalomon76148af2016-01-12 11:13:47 -08001450 return true;
1451}
1452
brianosman20471892016-12-02 06:43:32 -08001453void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1454 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001455 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001456 /*
1457 Comments on renderability of configs on various GL versions.
1458 OpenGL < 3.0:
1459 no built in support for render targets.
1460 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1461 format RGB, RGBA and NV float formats we don't use.
1462 This is the following:
1463 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1464 RGB10_A2, RGBA12,RGBA16
1465 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1466 since they aren't required by later standards and the driver can simply return
1467 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1468 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1469 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1470 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1471 This adds a lot of additional renderable sized formats, including ALPHA8.
1472 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1473 16F, 32I, 32UI, and 32F variants).
1474 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1475
1476 For both the above extensions we limit ourselves to those that are also required by
1477 OpenGL 3.0.
1478
1479 OpenGL 3.0:
1480 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1481 but are not required to be supported as renderable textures/renderbuffer.
1482 Required renderable color formats:
1483 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1484 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1485 RGB10_A2.
1486 - R11F_G11F_B10F.
1487 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1488 and RG8UI.
1489 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1490 - ALPHA8
1491
1492 OpenGL 3.1, 3.2, 3.3
1493 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1494 OpengGL 3.3, 4.0, 4.1
1495 Adds RGB10_A2UI.
1496 OpengGL 4.2
1497 Adds
1498 - RGB5_A1, RGBA4
1499 - RGB565
1500 OpenGL 4.4
1501 Does away with the separate list and adds a column to the sized internal color format
1502 table. However, no new formats become required color renderable.
1503
1504 ES 2.0
1505 color renderable: RGBA4, RGB5_A1, RGB565
1506 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1507 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1508 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1509 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1510 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1511 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1512
1513 ES 3.0
1514 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1515 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1516 RGB5_A1.
1517 - RGB8 and RGB565.
1518 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1519 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1520 ES 3.1
1521 Adds RGB10_A2, RGB10_A2UI,
1522 ES 3.2
1523 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1524 */
Brian Salomon71d9d842016-11-03 13:42:00 -04001525 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1526 ConfigInfo::kFBOColorAttachment_Flag;
1527 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001528 if (kNone_MSFBOType != fMSFBOType) {
1529 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1530 }
bsalomon41e4384e2016-01-08 09:12:44 -08001531 GrGLStandard standard = ctxInfo.standard();
1532 GrGLVersion version = ctxInfo.version();
1533
cblume790d5132016-02-29 11:13:29 -08001534 bool texStorageSupported = false;
1535 if (kGL_GrGLStandard == standard) {
1536 // The EXT version can apply to either GL or GLES.
1537 texStorageSupported = version >= GR_GL_VER(4,2) ||
1538 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1539 ctxInfo.hasExtension("GL_EXT_texture_storage");
1540 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001541 texStorageSupported = version >= GR_GL_VER(3,0) ||
1542 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001543 }
1544
1545 // TODO: remove after command buffer supports full ES 3.0
1546 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1547 kChromium_GrGLDriver == ctxInfo.driver()) {
1548 texStorageSupported = false;
1549 }
1550
cdalton74b8d322016-04-11 14:47:28 -07001551 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1552
bsalomon30447372015-12-21 09:03:05 -08001553 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1554 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001555 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001556 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001557 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001558 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001559
1560 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1561 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001562 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1563 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001564 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001565 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001566 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1567 if (kGL_GrGLStandard == standard) {
1568 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1569 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001570 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001571 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1572 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1573 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1574 }
egdaniel4999df82016-01-07 17:06:04 -08001575 }
cblume790d5132016-02-29 11:13:29 -08001576 if (texStorageSupported) {
1577 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1578 }
cdalton74b8d322016-04-11 14:47:28 -07001579 if (texelBufferSupport) {
1580 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1581 }
bsalomoncdee0092016-01-08 13:20:12 -08001582 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001583
bsalomon76148af2016-01-12 11:13:47 -08001584 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1585 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001586 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001587 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001588 if (kGL_GrGLStandard == standard) {
1589 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1590 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1591 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1592 // Since the internal format is RGBA8, it is also renderable.
1593 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1594 allRenderFlags;
1595 }
1596 } else {
1597 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1598 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1599 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001600 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1601 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1602 // driver remembers the external format when the texture is created (with TexImage).
1603 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1604 // We could work around this, but it adds even more state tracking to code that is
1605 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1606 // This also side-steps some ambiguous interactions with the texture storage extension.
1607 if (version >= GR_GL_VER(3,0)) {
1608 // The APPLE extension doesn't make this renderable.
1609 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
bsalomon41e4384e2016-01-08 09:12:44 -08001610 }
1611 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1612 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Salomon71d9d842016-11-03 13:42:00 -04001613 nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001614 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001615 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001616 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1617 ConfigInfo::kRenderableWithMSAA_Flag;
1618 }
1619 }
1620 }
Brian Osman48c99192017-06-02 08:45:06 -04001621
1622 bool isX86PowerVR = false;
1623#if defined(SK_CPU_X86)
1624 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1625 isX86PowerVR = true;
1626 }
1627#endif
1628
1629 // Adreno 3xx, 4xx, 5xx, and NexusPlayer all fail if we try to use TexStorage with BGRA
1630 if (texStorageSupported &&
1631 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
1632 kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
1633 kAdreno5xx_GrGLRenderer != ctxInfo.renderer() &&
1634 !isX86PowerVR) {
1635 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001636 }
bsalomoncdee0092016-01-08 13:20:12 -08001637 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001638
brianosmana6359362016-03-21 06:55:37 -07001639 // We only enable srgb support if both textures and FBOs support srgb,
brianosman35b784d2016-05-05 11:52:53 -07001640 // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
bsalomon41e4384e2016-01-08 09:12:44 -08001641 if (kGL_GrGLStandard == standard) {
1642 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001643 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001644 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1645 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1646 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001647 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001648 }
1649 }
1650 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001651 if (fSRGBSupport) {
1652 fSRGBWriteControl = true;
1653 }
bsalomon41e4384e2016-01-08 09:12:44 -08001654 } else {
brianosman20471892016-12-02 06:43:32 -08001655 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Osman48c99192017-06-02 08:45:06 -04001656 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1657 // blacklist that device (and any others that might be sharing the same driver).
1658 if (isX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001659 fSRGBSupport = false;
1660 }
bsalomon41e4384e2016-01-08 09:12:44 -08001661 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1662 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001663 // See https://bug.skia.org/5329 for Adreno4xx issue.
1664 fSRGBWriteControl = kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
1665 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001666 }
brianosman20471892016-12-02 06:43:32 -08001667 if (contextOptions.fRequireDecodeDisableForSRGB && !fSRGBDecodeDisableSupport) {
1668 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode. Clients
1669 // can opt-out of that requirement, if they intend to always do linear blending.
brianosmana6359362016-03-21 06:55:37 -07001670 fSRGBSupport = false;
1671 }
brianosman20471892016-12-02 06:43:32 -08001672
1673 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1674 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1675 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1676 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1677 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1678 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1679 // affects Windows.
1680 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1681 fSRGBSupport = false;
1682 }
1683
Brian Osman48c99192017-06-02 08:45:06 -04001684 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1685 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1686 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1687
Brian Osman67999392017-05-31 16:19:34 -04001688 uint32_t srgbRenderFlags = allRenderFlags;
1689 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers
1690#if defined(SK_BUILD_FOR_MAC)
1691 if (kATI_GrGLVendor == ctxInfo.vendor()) {
1692 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1693 }
1694#endif
1695
bsalomon30447372015-12-21 09:03:05 -08001696 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1697 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1698 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1699 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001700 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1701 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001702 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001703 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001704 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001705 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001706 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001707 }
Brian Osman48c99192017-06-02 08:45:06 -04001708 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1709 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001710 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1711 }
bsalomoncdee0092016-01-08 13:20:12 -08001712 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001713 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1714 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1715 // is in this format, for example).
1716 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1717 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1718 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1719 // external format is GL_BGRA.
1720 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1721 GR_GL_BGRA;
1722 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1723 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001724 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001725 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001726 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001727 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001728
brianosmana6359362016-03-21 06:55:37 -07001729 if (texStorageSupported) {
1730 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1731 }
1732 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1733
Brian Salomonbf7b6202016-11-11 16:08:03 -05001734 bool hasIntegerTextures;
1735 if (standard == kGL_GrGLStandard) {
1736 hasIntegerTextures = version >= GR_GL_VER(3, 0) ||
1737 ctxInfo.hasExtension("GL_EXT_texture_integer");
1738 } else {
1739 hasIntegerTextures = (version >= GR_GL_VER(3, 0));
1740 }
1741 // We may have limited GLSL to an earlier version that doesn't have integer sampler types.
1742 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
1743 hasIntegerTextures = false;
1744 }
1745 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA_INTEGER;
1746 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8I;
1747 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RGBA_INTEGER;
1748 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fExternalType = GR_GL_BYTE;
1749 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormatType = kInteger_FormatType;
1750 // We currently only support using integer textures as srcs, not for rendering (even though GL
1751 // allows it).
1752 if (hasIntegerTextures) {
1753 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1754 ConfigInfo::kFBOColorAttachment_Flag;
1755 if (texStorageSupported) {
1756 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags |=
1757 ConfigInfo::kCanUseTexStorage_Flag;
1758 }
1759 }
1760
bsalomon30447372015-12-21 09:03:05 -08001761 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1762 if (this->ES2CompatibilitySupport()) {
1763 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1764 } else {
1765 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1766 }
bsalomon76148af2016-01-12 11:13:47 -08001767 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1768 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001769 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001770 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001771 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1772 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001773 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001774 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1775 }
1776 } else {
1777 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1778 }
cblume790d5132016-02-29 11:13:29 -08001779 // 565 is not a sized internal format on desktop GL. So on desktop with
1780 // 565 we always use an unsized internal format to let the system pick
1781 // the best sized format to convert the 565 data to. Since TexStorage
1782 // only allows sized internal formats we disallow it.
1783 //
1784 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1785 // update.
1786 if (texStorageSupported && kGL_GrGLStandard != standard) {
1787 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1788 }
bsalomoncdee0092016-01-08 13:20:12 -08001789 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001790
1791 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1792 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001793 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1794 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001795 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001796 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001797 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1798 if (kGL_GrGLStandard == standard) {
1799 if (version >= GR_GL_VER(4, 2)) {
1800 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1801 }
1802 } else {
1803 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1804 }
cblume790d5132016-02-29 11:13:29 -08001805 if (texStorageSupported) {
1806 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1807 }
bsalomoncdee0092016-01-08 13:20:12 -08001808 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001809
Brian Osmanf4faccd2017-01-10 16:53:58 -05001810 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1811 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1812 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001813 if (this->textureRedSupport()) {
1814 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1815 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001816 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1817 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001818 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001819 if (texelBufferSupport) {
1820 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1821 }
Robert Phillips5ab72762017-06-07 12:04:18 -04001822 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
bsalomon30447372015-12-21 09:03:05 -08001823 } else {
1824 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1825 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001826 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1827 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001828 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
Robert Phillips5ab72762017-06-07 12:04:18 -04001829 if (fAlpha8IsRenderable) {
1830 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1831 }
bsalomon30447372015-12-21 09:03:05 -08001832 }
Robert Phillips5ab72762017-06-07 12:04:18 -04001833
Brian Osman48c99192017-06-02 08:45:06 -04001834 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1835 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001836 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1837 }
bsalomon41e4384e2016-01-08 09:12:44 -08001838
Brian Osmanf4faccd2017-01-10 16:53:58 -05001839 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1840 fConfigTable[kGray_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1841 fConfigTable[kGray_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001842 if (this->textureRedSupport()) {
1843 fConfigTable[kGray_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1844 fConfigTable[kGray_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
1845 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1846 GR_GL_RED;
1847 fConfigTable[kGray_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRA();
1848 if (texelBufferSupport) {
1849 fConfigTable[kGray_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1850 }
1851 } else {
1852 fConfigTable[kGray_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1853 fConfigTable[kGray_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
1854 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1855 GR_GL_LUMINANCE;
1856 fConfigTable[kGray_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1857 }
Brian Osman986563b2017-01-10 14:20:02 -05001858#if 0 // Leaving Gray8 as non-renderable, to keep things simple and match raster
1859 if (this->textureRedSupport() ||
1860 (kDesktop_ARB_MSFBOType == this->msFBOType() &&
1861 ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
1862 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1863 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1864 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
1865 fConfigTable[kGray_8_GrPixelConfig].fFlags |= allRenderFlags;
1866 }
1867#endif
Brian Osman48c99192017-06-02 08:45:06 -04001868 if (texStorageSupported && !isCommandBufferES2) {
Brian Osman986563b2017-01-10 14:20:02 -05001869 fConfigTable[kGray_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1870 }
1871
bsalomon41e4384e2016-01-08 09:12:44 -08001872 // Check for [half] floating point texture support
1873 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1874 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1875 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1876 bool hasFPTextures = false;
1877 bool hasHalfFPTextures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001878 bool rgIsTexturable = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001879 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001880 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001881
1882 if (kGL_GrGLStandard == standard) {
1883 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1884 hasFPTextures = true;
1885 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001886 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001887 }
1888 } else {
1889 if (version >= GR_GL_VER(3, 1)) {
1890 hasFPTextures = true;
1891 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001892 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001893 } else {
1894 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1895 ctxInfo.hasExtension("GL_OES_texture_float")) {
1896 hasFPTextures = true;
1897 }
1898 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1899 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1900 hasHalfFPTextures = true;
1901 }
1902 }
1903 }
bsalomon30447372015-12-21 09:03:05 -08001904
csmartdalton6aa0e112017-02-08 16:14:11 -05001905 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
1906 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
1907 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
1908 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
1909 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
1910 fConfigTable[fpconfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = format;
1911 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
1912 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
1913 if (hasFPTextures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001914 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
csmartdalton6aa0e112017-02-08 16:14:11 -05001915 // For now we only enable rendering to float on desktop, because on ES we'd have to
1916 // solve many precision issues and no clients actually want this yet.
1917 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1918 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1919 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
1920 }
bsalomon41e4384e2016-01-08 09:12:44 -08001921 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001922 if (texStorageSupported) {
1923 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1924 }
1925 if (texelBufferSupport) {
1926 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1927 }
1928 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001929 }
bsalomon30447372015-12-21 09:03:05 -08001930
1931 if (this->textureRedSupport()) {
1932 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1933 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001934 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1935 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001936 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001937 if (texelBufferSupport) {
1938 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |=
1939 ConfigInfo::kCanUseWithTexelBuffer_Flag;
1940 }
bsalomon30447372015-12-21 09:03:05 -08001941 } else {
1942 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1943 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001944 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1945 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001946 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001947 }
Brian Osman3a887252016-11-17 13:27:31 -05001948 // ANGLE always returns GL_HALF_FLOAT_OES for GL_IMPLEMENTATION_COLOR_READ_TYPE, even though
1949 // ES3 would typically return GL_HALF_FLOAT. The correct fix is for us to respect the value
1950 // returned when we query, but that turns into a bigger refactor, so just work around it.
1951 if (kGL_GrGLStandard == ctxInfo.standard() ||
1952 (ctxInfo.version() >= GR_GL_VER(3, 0) && kANGLE_GrGLDriver != ctxInfo.driver())) {
bsalomon30447372015-12-21 09:03:05 -08001953 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1954 } else {
1955 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1956 }
bsalomon7928ef62016-01-05 10:26:39 -08001957 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
cblume790d5132016-02-29 11:13:29 -08001958 if (texStorageSupported) {
1959 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1960 }
csmartdalton6aa0e112017-02-08 16:14:11 -05001961 if (hasHalfFPTextures) {
1962 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1963 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1964 // GL_RED internal format.
1965 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
1966 (this->textureRedSupport() &&
1967 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1968 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1969 }
1970 }
bsalomon30447372015-12-21 09:03:05 -08001971
1972 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1973 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001974 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1975 GR_GL_RGBA;
Brian Osman3a887252016-11-17 13:27:31 -05001976 // See comment above, re: ANGLE and ES3.
1977 if (kGL_GrGLStandard == ctxInfo.standard() ||
1978 (ctxInfo.version() >= GR_GL_VER(3, 0) && kANGLE_GrGLDriver != ctxInfo.driver())) {
bsalomon30447372015-12-21 09:03:05 -08001979 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1980 } else {
1981 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1982 }
bsalomon7928ef62016-01-05 10:26:39 -08001983 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001984 if (hasHalfFPTextures) {
1985 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1986 // ES requires 3.2 or EXT_color_buffer_half_float.
1987 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1988 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1989 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1990 }
1991 }
cblume790d5132016-02-29 11:13:29 -08001992 if (texStorageSupported) {
1993 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1994 }
cdalton74b8d322016-04-11 14:47:28 -07001995 if (texelBufferSupport) {
1996 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1997 }
bsalomoncdee0092016-01-08 13:20:12 -08001998 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001999
bsalomon30447372015-12-21 09:03:05 -08002000 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
2001
2002 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08002003 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
2004 ctxInfo.version() >= GR_GL_VER(3,0));
2005 // All ES versions (thus far) require sized internal formats for render buffers.
2006 // TODO: Always use sized internal format?
2007 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
2008
bsalomon30447372015-12-21 09:03:05 -08002009 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08002010 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
2011 // param to glTex[Sub]Image.
2012 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
2013 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
2014 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
2015 fConfigTable[i].fFormats.fSizedInternalFormat :
2016 fConfigTable[i].fFormats.fBaseInternalFormat;
2017 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08002018 fConfigTable[i].fFormats.fSizedInternalFormat :
2019 fConfigTable[i].fFormats.fBaseInternalFormat;
2020 }
2021 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
2022 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
2023 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
2024 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
2025 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08002026 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08002027 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07002028
2029 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
2030 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
2031 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
2032 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08002033 }
2034
2035 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
2036 // as a base format.
2037 // GL_EXT_texture_format_BGRA8888:
2038 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
2039 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
2040 // formats.
halcanary9d524f22016-03-29 09:03:52 -07002041 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08002042 // ES 2.0: the extension makes BGRA an external format but not an internal format.
2043 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
2044 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08002045 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08002046 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
2047 }
2048
bsalomoncdee0092016-01-08 13:20:12 -08002049 // If we don't have texture swizzle support then the shader generator must insert the
2050 // swizzle into shader code.
2051 if (!this->textureSwizzleSupport()) {
2052 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05002053 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08002054 }
2055 }
2056
bsalomon7f9b2e42016-01-12 13:29:26 -08002057 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
2058 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
2059 // gets written to the single component.
2060 if (this->textureRedSupport()) {
2061 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
2062 GrPixelConfig config = static_cast<GrPixelConfig>(i);
2063 if (GrPixelConfigIsAlphaOnly(config) &&
2064 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05002065 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08002066 }
2067 }
2068 }
2069
Brian Salomonf9f45122016-11-29 11:59:17 -05002070 // We currently only support images on rgba textures formats. We could add additional formats
2071 // if desired. The shader builder would have to be updated to add swizzles where appropriate
2072 // (e.g. where we use GL_RED textures to implement alpha configs).
2073 if (this->shaderCaps()->imageLoadStoreSupport()) {
2074 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags |=
2075 ConfigInfo::kCanUseAsImageStorage_Flag;
2076 // In OpenGL ES a texture may only be used with BindImageTexture if it has been made
2077 // immutable via TexStorage. We create non-integer textures as mutable textures using
2078 // TexImage because we may lazily add MIP levels. Thus, on ES we currently disable image
2079 // storage support for non-integer textures.
2080 if (kGL_GrGLStandard == ctxInfo.standard()) {
2081 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseAsImageStorage_Flag;
2082 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |=
2083 ConfigInfo::kCanUseAsImageStorage_Flag;
2084 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseAsImageStorage_Flag;
2085 }
2086 }
2087
bsalomon30447372015-12-21 09:03:05 -08002088#ifdef SK_DEBUG
2089 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002090 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002091 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002092 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2093 // renderable.
2094 SkASSERT(!((ConfigInfo::kRenderable_Flag) && !(ConfigInfo::kFBOColorAttachment_Flag)));
2095 SkASSERT(!((ConfigInfo::kRenderableWithMSAA_Flag) && !(ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002096 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2097 fConfigTable[i].fFormats.fBaseInternalFormat);
2098 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002099 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002100 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2101 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2102 fConfigTable[i].fFormats.fExternalFormat[j]);
2103 }
2104 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002105 }
2106#endif
2107}
2108
Robert Phillipsbf25d432017-04-07 10:08:53 -04002109bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Eric Karl74480882017-04-03 14:49:05 -07002110 bool* rectsMustMatch, bool* disallowSubrect) const {
2111 // By default, we don't require rects to match.
2112 *rectsMustMatch = false;
2113
2114 // By default, we allow subrects.
2115 *disallowSubrect = false;
2116
Brian Salomon467921e2017-03-06 16:17:12 -05002117 // If the src is a texture, we can implement the blit as a draw assuming the config is
2118 // renderable.
Robert Phillipsbf25d432017-04-07 10:08:53 -04002119 if (src->asTextureProxy() && this->isConfigRenderable(src->config(), false)) {
2120 desc->fOrigin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002121 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2122 desc->fConfig = src->config();
2123 return true;
2124 }
2125
Robert Phillipsbf25d432017-04-07 10:08:53 -04002126 {
2127 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2128 // wrapped. In that case the proxy would already be instantiated.
2129 const GrTexture* srcTexture = src->priv().peekTexture();
2130 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2131 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2132 // Not supported for FBO blit or CopyTexSubImage
2133 return false;
2134 }
Brian Salomon467921e2017-03-06 16:17:12 -05002135 }
2136
2137 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2138 // possible and we return false to fallback to creating a render target dst for render-to-
2139 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2140 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002141 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002142 bool rectsMustMatchForBlitFramebuffer = false;
2143 bool disallowSubrectForBlitFramebuffer = false;
2144 if (src->numColorSamples() &&
2145 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2146 rectsMustMatchForBlitFramebuffer = true;
2147 disallowSubrectForBlitFramebuffer = true;
2148 // Mirroring causes rects to mismatch later, don't allow it.
2149 originForBlitFramebuffer = src->origin();
2150 } else if (src->numColorSamples() && (this->blitFramebufferSupportFlags() &
2151 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
2152 rectsMustMatchForBlitFramebuffer = true;
2153 // Mirroring causes rects to mismatch later, don't allow it.
2154 originForBlitFramebuffer = src->origin();
2155 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002156 originForBlitFramebuffer = src->origin();
2157 }
2158
2159 // Check for format issues with glCopyTexSubImage2D
2160 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2161 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2162 // then we set up for that, otherwise fail.
2163 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
2164 desc->fOrigin = originForBlitFramebuffer;
2165 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002166 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2167 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002168 return true;
2169 }
2170 return false;
2171 }
2172
Robert Phillipsbf25d432017-04-07 10:08:53 -04002173 {
Brian Salomon63e79732017-05-15 21:23:13 -04002174 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2175 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002176 if (srcIsMSAARenderbuffer) {
2177 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2178 // blit or fail.
2179 if (this->canConfigBeFBOColorAttachment(src->config())) {
2180 desc->fOrigin = originForBlitFramebuffer;
2181 desc->fConfig = src->config();
2182 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2183 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2184 return true;
2185 }
2186 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002187 }
Brian Salomon467921e2017-03-06 16:17:12 -05002188 }
2189
2190 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
2191 desc->fConfig = src->config();
2192 desc->fOrigin = src->origin();
2193 desc->fFlags = kNone_GrSurfaceFlags;
2194 return true;
2195}
2196
csmartdaltone0d36292016-07-29 08:14:20 -07002197void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
2198 if (options.fEnableInstancedRendering) {
2199 fInstancedSupport = gr_instanced::GLInstancedRendering::CheckSupport(*this);
2200#ifndef SK_BUILD_FOR_MAC
2201 // OS X doesn't seem to write correctly to floating point textures when using
2202 // glDraw*Indirect, regardless of the underlying GPU.
2203 fAvoidInstancedDrawsToFPTargets = true;
2204#endif
2205 }
2206}