blob: 3b401e65a1b24efd566297476ccec455b981bc19 [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"
Brian Osman71a18892017-08-10 10:23:25 -040015#include "SkJSONWriter.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000016#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000017#include "SkTSort.h"
Brian Salomon467921e2017-03-06 16:17:12 -050018#include "instanced/GLInstancedRendering.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000019
bsalomon682c2692015-05-22 14:01:46 -070020GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
21 const GrGLContextInfo& ctxInfo,
22 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080023 fStandard = ctxInfo.standard();
24
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000025 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000027 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000028 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080029 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fUnpackRowLengthSupport = false;
32 fUnpackFlipYSupport = false;
33 fPackRowLengthSupport = false;
34 fPackFlipYSupport = false;
35 fTextureUsageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000036 fTextureRedSupport = false;
Robert Phillips5ab72762017-06-07 12:04:18 -040037 fAlpha8IsRenderable = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDirectStateAccessSupport = false;
41 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080042 fES2CompatibilitySupport = false;
cdalton06604b92016-02-05 10:09:51 -080043 fDrawIndirectSupport = false;
44 fMultiDrawIndirectSupport = false;
45 fBaseInstanceSupport = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000046 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070047 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080048 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080049 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070050 fRGBA8888PixelsOpsAreSlow = false;
51 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080052 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080053 fRGBAToBGRAReadbackConversionsAreSlow = false;
brianosman09563ce2016-06-02 08:59:34 -070054 fDoManualMipmapping = false;
brianosman851c2382016-12-07 10:03:25 -080055 fSRGBDecodeDisableAffectsMipmaps = false;
Eric Karlaeaf22b2017-05-18 15:08:09 -070056 fClearToBoundaryValuesIsBroken = false;
Brian Salomond17b4a62017-05-23 16:53:47 -040057 fClearTextureSupport = false;
Chris Dalton9926f4b2017-05-17 15:15:50 -060058 fDrawArraysBaseVertexIsBroken = false;
Mike Klein31550db2017-06-06 23:29:53 +000059 fUseDrawToClearStencilClip = false;
Brian Salomon9bada542017-06-12 12:09:30 -040060 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
61 fUseDrawInsteadOfAllRenderTargetWrites = false;
Brian Salomon6d9c88b2017-06-12 10:24:42 -040062 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
piotaixre4b23142014-10-02 10:57:53 -070063
Brian Salomone5e7eb12016-10-14 16:18:33 -040064 fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
bsalomon083617b2016-02-12 12:10:14 -080065
Brian Salomon94efbf52016-11-29 13:43:05 -050066 fShaderCaps.reset(new GrShaderCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070067
cdalton4cd67132015-06-10 19:23:46 -070068 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000069}
70
cdalton4cd67132015-06-10 19:23:46 -070071void GrGLCaps::init(const GrContextOptions& contextOptions,
72 const GrGLContextInfo& ctxInfo,
73 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000074 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000075 GrGLVersion version = ctxInfo.version();
76
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000077 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000078 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
79 &fMaxFragmentUniformVectors);
80 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000081 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000082 GrGLint max;
83 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
84 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000085 if (version >= GR_GL_VER(3, 2)) {
86 GrGLint profileMask;
87 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
88 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
89 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000091 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000092
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000093 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094 fUnpackRowLengthSupport = true;
95 fUnpackFlipYSupport = false;
96 fPackRowLengthSupport = true;
97 fPackFlipYSupport = false;
98 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000099 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
100 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000102 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
103 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104 fPackFlipYSupport =
105 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
106 }
107
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000108 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
110
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000111 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700112 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
113 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
114 ctxInfo.hasExtension("GL_NV_texture_barrier");
115 } else {
116 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
117 }
118
cdaltoneb79eea2016-02-26 10:39:34 -0800119 if (kGL_GrGLStandard == standard) {
120 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
121 ctxInfo.hasExtension("GL_ARB_texture_multisample");
122 } else {
123 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
124 }
125
Brian Salomon0ee6f952017-01-19 15:52:24 -0500126 // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED
hendrikwa0d5ad72014-12-02 07:30:30 -0800127 // and GL_RG on FBO textures.
Brian Salomon0ee6f952017-01-19 15:52:24 -0500128 if (kOSMesa_GrGLRenderer != ctxInfo.renderer()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800129 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000130 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
131 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800132 } else {
133 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
134 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000135 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000136 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000137 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000138 ctxInfo.hasExtension("GL_ARB_imaging");
139
egdaniel9250d242015-05-18 13:04:26 -0700140 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
141 // Thus we are blacklisting this extension for now on Adreno4xx devices.
142 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
143 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
144 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
145 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000146 fDiscardRenderTargetSupport = true;
147 fInvalidateFBType = kInvalidate_InvalidateFBType;
148 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
149 fDiscardRenderTargetSupport = true;
150 fInvalidateFBType = kDiscard_InvalidateFBType;
151 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000152
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000153 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
154 fFullClearIsFree = true;
155 }
156
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000157 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000158 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800159 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
160 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000161 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000162 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
163 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000164 }
165
cdalton626e1ff2015-06-12 13:56:46 -0700166 if (kGL_GrGLStandard == standard) {
167 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
168 } else {
169 fDirectStateAccessSupport = false;
170 }
171
172 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
173 fDebugSupport = true;
174 } else {
175 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
176 }
177
jvanverth3f801cb2014-12-16 09:49:38 -0800178 if (kGL_GrGLStandard == standard) {
179 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
180 }
181 else {
182 fES2CompatibilitySupport = true;
183 }
184
cdalton0edea2c2015-05-21 08:27:44 -0700185 if (kGL_GrGLStandard == standard) {
186 fMultisampleDisableSupport = true;
187 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700188 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700189 }
190
kkinnunend94708e2015-07-30 22:47:04 -0700191 if (kGL_GrGLStandard == standard) {
Chris Dalton1d616352017-05-31 12:51:23 -0600192 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
193 // instanced arrays, but we could make this more granular if we wanted
194 fInstanceAttribSupport =
195 version >= GR_GL_VER(3, 2) ||
196 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
197 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
198 } else {
199 fInstanceAttribSupport =
200 version >= GR_GL_VER(3, 0) ||
201 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
202 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
203 }
204
205 if (kGL_GrGLStandard == standard) {
kkinnunend94708e2015-07-30 22:47:04 -0700206 if (version >= GR_GL_VER(3, 0)) {
207 fBindFragDataLocationSupport = true;
208 }
209 } else {
210 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
211 fBindFragDataLocationSupport = true;
212 }
joshualittc1f56b52015-06-22 12:31:31 -0700213 }
214
joshualitt7bdd70a2015-10-01 06:28:11 -0700215 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
216
kkinnunene06ed252016-02-16 23:15:40 -0800217 if (kGL_GrGLStandard == standard) {
218 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
219 // We also require textureSize() support for rectangle 2D samplers which was added in
220 // GLSL 1.40.
221 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
222 fRectangleTextureSupport = true;
223 }
bsalomone179a912016-01-20 06:18:10 -0800224 }
kkinnunene06ed252016-02-16 23:15:40 -0800225 } else {
226 // Command buffer exposes this in GL ES context for Chromium reasons,
227 // but it should not be used. Also, at the time of writing command buffer
228 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800229 }
230
bsalomoncdee0092016-01-08 13:20:12 -0800231 if (kGL_GrGLStandard == standard) {
232 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
233 fTextureSwizzleSupport = true;
234 }
235 } else {
236 if (version >= GR_GL_VER(3,0)) {
237 fTextureSwizzleSupport = true;
238 }
239 }
240
cblume09bd2c02016-03-01 14:08:28 -0800241 if (kGL_GrGLStandard == standard) {
242 fMipMapLevelAndLodControlSupport = true;
243 } else if (kGLES_GrGLStandard == standard) {
244 if (version >= GR_GL_VER(3,0)) {
245 fMipMapLevelAndLodControlSupport = true;
246 }
247 }
248
bsalomon88c7b982015-07-31 11:20:16 -0700249#ifdef SK_BUILD_FOR_WIN
250 // We're assuming that on Windows Chromium we're using ANGLE.
251 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
252 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700253 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700254 fRGBA8888PixelsOpsAreSlow = isANGLE;
255 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
256 // check DX11 ANGLE.
257 fPartialFBOReadIsSlow = isANGLE;
258#endif
259
ericrkb4ecabd2016-03-11 15:18:20 -0800260 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
261 bool isMAC = false;
262#ifdef SK_BUILD_FOR_MAC
263 isMAC = true;
264#endif
265
266 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
267 // vis-versa.
268 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
269
Brian Salomond17b4a62017-05-23 16:53:47 -0400270 if (kGL_GrGLStandard == standard) {
271 if (version >= GR_GL_VER(4,4) || ctxInfo.hasExtension("GL_ARB_clear_texture")) {
272 // glClearTexImage seems to have a bug in NVIDIA drivers that was fixed sometime between
273 // 340.96 and 367.57.
274 if (ctxInfo.driver() != kNVIDIA_GrGLDriver ||
275 ctxInfo.driverVersion() >= GR_GL_DRIVER_VER(367, 57)) {
276 fClearTextureSupport = true;
277 }
278 }
279 } else if (ctxInfo.hasExtension("GL_EXT_clear_texture")) {
280 // Calling glClearTexImage crashes on the NexusPlayer.
281 if (kPowerVRRogue_GrGLRenderer != ctxInfo.renderer()) {
282 fClearTextureSupport = true;
283 }
284 }
285
cdalton4cd67132015-06-10 19:23:46 -0700286 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700287 * GrShaderCaps fields
288 **************************************************************************/
289
egdaniel0a482332015-10-26 08:59:10 -0700290 // This must be called after fCoreProfile is set on the GrGLCaps
291 this->initGLSL(ctxInfo);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500292 GrShaderCaps* shaderCaps = fShaderCaps.get();
egdaniel0a482332015-10-26 08:59:10 -0700293
Brian Osman195c05b2017-08-30 15:14:04 -0400294 shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
295#if GR_TEST_UTILS
296 if (contextOptions.fSuppressPathRendering) {
297 shaderCaps->fPathRenderingSupport = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700298 }
Brian Osman195c05b2017-08-30 15:14:04 -0400299#endif
egdaniel05ded892015-10-26 07:38:05 -0700300
301 // For now these two are equivalent but we could have dst read in shader via some other method.
302 // Before setting this, initGLSL() must have been called.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500303 shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
egdaniel05ded892015-10-26 07:38:05 -0700304
305 // Enable supported shader-related caps
306 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500307 shaderCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
egdaniel05ded892015-10-26 07:38:05 -0700308 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
309 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600310
Brian Salomon1edc5b92016-11-29 13:43:46 -0500311 shaderCaps->fShaderDerivativeSupport = true;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600312
egdaniel05ded892015-10-26 07:38:05 -0700313 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
Brian Salomon1edc5b92016-11-29 13:43:46 -0500314 shaderCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
egdaniel05ded892015-10-26 07:38:05 -0700315 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600316 if (shaderCaps->fGeometryShaderSupport) {
317 // On at least some MacBooks, GLSL 4.0 geometry shaders break if we use invocations.
318#ifndef SK_BUILD_FOR_MAC
319 if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
320 shaderCaps->fGSInvocationsSupport = true;
321 } else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
322 shaderCaps->fGSInvocationsSupport = true;
323 shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
324 }
325#endif
326 }
327
Brian Salomon1edc5b92016-11-29 13:43:46 -0500328 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800329 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700330 }
331 else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500332 shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
egdaniel05ded892015-10-26 07:38:05 -0700333
Brian Salomon1edc5b92016-11-29 13:43:46 -0500334 shaderCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
egdaniel05ded892015-10-26 07:38:05 -0700335 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800336
csmartdalton1d2aed02017-02-15 21:43:20 -0700337 shaderCaps->fGeometryShaderSupport = ctxInfo.hasExtension("GL_EXT_geometry_shader");
Chris Daltonf1b47bb2017-10-06 11:57:51 -0600338 shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
csmartdalton1d2aed02017-02-15 21:43:20 -0700339
Brian Salomon1edc5b92016-11-29 13:43:46 -0500340 shaderCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
cdalton793dc262016-02-08 10:11:47 -0800341 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700342 }
343
cdalton9c3f1432016-03-11 10:07:37 -0800344 // Protect ourselves against tracking huge amounts of texture state.
345 static const uint8_t kMaxSaneSamplers = 32;
346 GrGLint maxSamplers;
347 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500348 shaderCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
349 if (shaderCaps->fGeometryShaderSupport) {
cdalton9c3f1432016-03-11 10:07:37 -0800350 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500351 shaderCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800352 }
353 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500354 shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800355 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500356 shaderCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
cdalton9c3f1432016-03-11 10:07:37 -0800357
Brian Salomonf26f7a02016-11-15 14:05:01 -0500358 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500359 shaderCaps->fImageLoadStoreSupport = ctxInfo.version() >= GR_GL_VER(4, 2);
360 if (!shaderCaps->fImageLoadStoreSupport &&
Brian Salomonf26f7a02016-11-15 14:05:01 -0500361 ctxInfo.hasExtension("GL_ARB_shader_image_load_store")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500362 shaderCaps->fImageLoadStoreSupport = true;
363 shaderCaps->fImageLoadStoreExtensionString = "GL_ARB_shader_image_load_store";
Brian Salomonf26f7a02016-11-15 14:05:01 -0500364 }
365 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500366 shaderCaps->fImageLoadStoreSupport = ctxInfo.version() >= GR_GL_VER(3, 1);
Brian Salomonf26f7a02016-11-15 14:05:01 -0500367 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500368 if (shaderCaps->fImageLoadStoreSupport) {
Brian Salomonf26f7a02016-11-15 14:05:01 -0500369 // Protect ourselves against tracking huge amounts of image state.
370 static constexpr int kMaxSaneImages = 4;
371 GrGLint maxUnits;
372 GR_GL_GetIntegerv(gli, GR_GL_MAX_IMAGE_UNITS, &maxUnits);
Brian Salomonf9f45122016-11-29 11:59:17 -0500373 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_IMAGE_UNIFORMS,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500374 &shaderCaps->fMaxVertexImageStorages);
375 if (shaderCaps->fGeometryShaderSupport) {
Brian Salomonf9f45122016-11-29 11:59:17 -0500376 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_IMAGE_UNIFORMS,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500377 &shaderCaps->fMaxGeometryImageStorages);
Brian Salomonf9f45122016-11-29 11:59:17 -0500378 }
379 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_IMAGE_UNIFORMS,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500380 &shaderCaps->fMaxFragmentImageStorages);
Brian Salomonf9f45122016-11-29 11:59:17 -0500381 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_IMAGE_UNIFORMS,
Brian Salomon1edc5b92016-11-29 13:43:46 -0500382 &shaderCaps->fMaxCombinedImageStorages);
Brian Salomonf26f7a02016-11-15 14:05:01 -0500383 // We use one unit for every image uniform
Brian Salomon1edc5b92016-11-29 13:43:46 -0500384 shaderCaps->fMaxCombinedImageStorages = SkTMin(SkTMin(shaderCaps->fMaxCombinedImageStorages,
385 maxUnits), kMaxSaneImages);
386 shaderCaps->fMaxVertexImageStorages = SkTMin(maxUnits,
387 shaderCaps->fMaxVertexImageStorages);
388 shaderCaps->fMaxGeometryImageStorages = SkTMin(maxUnits,
389 shaderCaps->fMaxGeometryImageStorages);
390 shaderCaps->fMaxFragmentImageStorages = SkTMin(maxUnits,
391 shaderCaps->fMaxFragmentImageStorages);
Brian Salomonf26f7a02016-11-15 14:05:01 -0500392 }
393
csmartdalton485a1202016-07-13 10:16:32 -0700394 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
395 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
396 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
397 // limit this decision to specific GPU families rather than basing it on the vendor alone.
398 if (!GR_GL_MUST_USE_VBO &&
399 !fIsCoreProfile &&
400 (kARM_GrGLVendor == ctxInfo.vendor() ||
401 kImagination_GrGLVendor == ctxInfo.vendor() ||
402 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
403 fPreferClientSideDynamicBuffers = true;
404 }
405
Chris Daltone4679fa2017-09-29 13:58:26 -0600406 // Mali GPUs have serious issues with CCPR. Blacklisting until we can look into workarounds.
407 if (kARM_GrGLVendor == ctxInfo.vendor()) {
408 fBlacklistCoverageCounting = true;
409 }
410
Chris Dalton4a6a7322017-10-06 14:28:11 -0600411 if (kIntel_GrGLDriver == ctxInfo.driver()) {
412 // Intel HD4400, HD4600, and Iris6100 crash on the bots.
413 fBlacklistCoverageCounting = kIntel4xxx_GrGLRenderer == ctxInfo.renderer() ||
414 kIntel6xxx_GrGLRenderer == ctxInfo.renderer();
415 }
416
Eric Karl5c779752017-05-08 12:02:07 -0700417 if (!contextOptions.fAvoidStencilBuffers) {
418 // To reduce surface area, if we avoid stencil buffers, we also disable MSAA.
419 this->initFSAASupport(contextOptions, ctxInfo, gli);
420 this->initStencilSupport(ctxInfo);
421 }
Greg Danielcd2f5122017-05-25 10:50:40 -0400422
423 // Setup blit framebuffer
424 if (kGL_GrGLStandard != ctxInfo.standard()) {
425 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
426 fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
427 kNoMSAADst_BlitFramebufferFlag |
428 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
429 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
430 ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
431 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
432 // limitations.
433 fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
434 kResolveMustBeFull_BlitFrambufferFlag |
435 kNoMSAADst_BlitFramebufferFlag |
436 kNoFormatConversion_BlitFramebufferFlag |
437 kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
438 }
439 } else {
440 if (fUsesMixedSamples ||
441 ctxInfo.version() >= GR_GL_VER(3,0) ||
442 ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
443 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
444 fBlitFramebufferFlags = 0;
445 }
446 }
447
cdalton1dd05422015-06-12 09:01:18 -0700448 this->initBlendEqationSupport(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000449
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000450 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000451 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
452 // extension includes glMapBuffer.
453 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
454 fMapBufferFlags |= kSubset_MapFlag;
455 fMapBufferType = kMapBufferRange_MapBufferType;
456 } else {
457 fMapBufferType = kMapBuffer_MapBufferType;
458 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000459 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000460 // Unextended GLES2 doesn't have any buffer mapping.
461 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800462 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800463 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
464 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800465 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
466 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
467 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000468 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
469 fMapBufferFlags = kCanMap_MapFlag;
470 fMapBufferType = kMapBuffer_MapBufferType;
471 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000472 }
473
Brian Salomone03a7292017-06-08 11:00:50 -0400474 // We found that the Galaxy J5 with an Adreno 306 running 6.0.1 has a bug where
475 // GL_INVALID_OPERATION thrown by glDrawArrays when using a buffer that was mapped. The same bug
476 // did not reproduce on a Nexus7 2013 with a 320 running Android M with driver 127.0. It's
477 // unclear whether this really affects a wide range of devices.
478 if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer && ctxInfo.driver() == kQualcomm_GrGLDriver &&
479 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0)) {
480 fMapBufferType = kNone_MapBufferType;
481 fMapBufferFlags = kNone_MapFlags;
482 }
483
jvanverthd7a2c1f2015-12-07 07:36:44 -0800484 if (kGL_GrGLStandard == standard) {
485 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
486 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700487 }
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400488 } else if (kANGLE_GrGLDriver != ctxInfo.driver()) { // TODO: re-enable for ANGLE
489 if (version >= GR_GL_VER(3, 0) ||
490 (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
491 // GL_EXT_unpack_subimage needed to support subtexture rectangles
492 ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
jvanverthd7a2c1f2015-12-07 07:36:44 -0800493 fTransferBufferType = kPBO_TransferBufferType;
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400494// TODO: get transfer buffers working in Chrome
495// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
496// fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800497 }
498 }
499
joshualitte5b74c62015-06-01 14:17:47 -0700500 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
501 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700502 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700503#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500504 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
505 // we will use for all GrMeshDrawOps. Right now we might wind up mapping a large buffer and
506 // using a small subset.
cdalton397536c2016-03-25 12:15:03 -0700507 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700508#else
cdalton397536c2016-03-25 12:15:03 -0700509 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700510#endif
joshualitte5b74c62015-06-01 14:17:47 -0700511 }
512
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000513 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000514 fNPOTTextureTileSupport = true;
515 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000516 } else {
517 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000518 // ES3 has no limitations.
519 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
520 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000521 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
522 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
523 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
524 // to alllow arbitrary wrap modes, however.
525 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000526 }
527
bsalomone72bd022015-10-26 07:33:03 -0700528 // Using MIPs on this GPU seems to be a source of trouble.
529 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
530 fMipMapSupport = false;
531 }
532
bsalomon@google.combcce8922013-03-25 15:38:39 +0000533 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
534 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
535 // Our render targets are always created with textures as the color
536 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000537 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000538
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000539 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
540
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000541 // Disable scratch texture reuse on Mali and Adreno devices
brianosman5702c862016-08-09 14:02:13 -0700542 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000543
robertphillips1b8e1b52015-06-24 06:54:10 -0700544#if 0
545 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
546 kQualcomm_GrGLVendor != ctxInfo.vendor();
547#endif
548
csmartdalton9bc11872016-08-09 12:42:47 -0700549 if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
550 GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
csmartdalton9bc11872016-08-09 12:42:47 -0700551 }
552
bsalomon63b21962014-11-05 07:05:34 -0800553 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800554 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
Brian Salomon1b52df32017-03-24 18:49:09 -0400555 (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
556 ctxInfo.driver() != kChromium_GrGLDriver)) {
bsalomon63b21962014-11-05 07:05:34 -0800557 fUseDrawInsteadOfClear = true;
558 }
Robert Phillipsa2fd62a2017-10-05 12:46:21 -0400559
560#ifdef SK_BUILD_FOR_MAC
561 // crbug.com/768134 - On MacBook Pros, the Intel Iris Pro doesn't always perform
562 // full screen clears
563 if (kIntelIrisPro_GrGLRenderer == ctxInfo.renderer()) {
564 fUseDrawInsteadOfClear = true;
565 }
566#endif
567
Brian Salomon266ef6d2017-09-22 11:27:42 -0400568 // See crbug.com/755871. This could probably be narrowed to just partial clears as the driver
569 // bugs seems to involve clearing too much and not skipping the clear.
Robert Phillips3a930532017-10-04 18:03:24 -0400570 // See crbug.com/768134. This is also needed for full clears and was seen on an nVidia K620
571 // but only for D3D11 ANGLE.
572 if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
Brian Salomon266ef6d2017-09-22 11:27:42 -0400573 fUseDrawInsteadOfClear = true;
574 }
bsalomon63b21962014-11-05 07:05:34 -0800575
joshualitt83bc2292015-06-18 14:18:02 -0700576 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomonb52fa022017-06-07 09:42:52 -0400577 // This is known to be fixed sometime between driver 145.0 and 219.0
578 if (ctxInfo.driver() == kQualcomm_GrGLDriver &&
579 ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0)) {
580 fUseDrawToClearStencilClip = true;
581 }
Brian Salomon9bada542017-06-12 12:09:30 -0400582 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
joshualitt83bc2292015-06-18 14:18:02 -0700583 }
584
Brian Salomonaf971de2017-06-08 16:11:33 -0400585 // This was reproduced on the following configurations:
586 // - A Galaxy J5 (Adreno 306) running Android 6 with driver 140.0
587 // - A Nexus 7 2013 (Adreno 320) running Android 5 with driver 104.0
588 // - A Nexus 7 2013 (Adreno 320) running Android 6 with driver 127.0
Brian Salomon6d9c88b2017-06-12 10:24:42 -0400589 // - A Nexus 5 (Adreno 330) running Android 6 with driver 127.0
Brian Salomonaf971de2017-06-08 16:11:33 -0400590 // and not produced on:
591 // - A Nexus 7 2013 (Adreno 320) running Android 4 with driver 53.0
Brian Salomon6d9c88b2017-06-12 10:24:42 -0400592 // The particular lines that get dropped from test images varies across different devices.
Brian Salomonaf971de2017-06-08 16:11:33 -0400593 if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() && kQualcomm_GrGLDriver == ctxInfo.driver() &&
594 ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0)) {
Brian Salomon6d9c88b2017-06-12 10:24:42 -0400595 fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
Brian Salomonaf971de2017-06-08 16:11:33 -0400596 }
597
bsalomonbabafcc2016-02-16 11:36:47 -0800598 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
599 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon9bada542017-06-12 12:09:30 -0400600 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
bsalomonbabafcc2016-02-16 11:36:47 -0800601 fUseDrawInsteadOfAllRenderTargetWrites = true;
602 }
603
robertphillips63926682015-08-20 09:39:02 -0700604#ifdef SK_BUILD_FOR_WIN
605 // On ANGLE deferring flushes can lead to GPU starvation
606 fPreferVRAMUseOverFlushes = !isANGLE;
607#endif
608
bsalomon7dea7b72015-08-19 08:26:51 -0700609 if (kChromium_GrGLDriver == ctxInfo.driver()) {
610 fMustClearUploadedBufferData = true;
611 }
612
bsalomond08ea5f2015-02-20 06:58:13 -0800613 if (kGL_GrGLStandard == standard) {
614 // ARB allows mixed size FBO attachments, EXT does not.
615 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
616 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
617 fOversizedStencilSupport = true;
618 } else {
619 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
620 }
621 } else {
622 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
623 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
624 }
625
joshualitt58001552015-06-26 12:46:36 -0700626 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700627 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
628 ctxInfo.hasExtension("GL_ARB_draw_indirect");
629 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
630 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
csmartdalton4c18b622016-07-29 12:19:28 -0700631 (fDrawIndirectSupport &&
632 !fBaseInstanceSupport && // The ARB extension has no base inst.
csmartdalton5cebf8c2016-06-03 08:28:47 -0700633 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
bsalomonfc9527a2016-08-29 09:18:39 -0700634 fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
cdalton06604b92016-02-05 10:09:51 -0800635 } else {
636 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
csmartdalton4c18b622016-07-29 12:19:28 -0700637 fMultiDrawIndirectSupport = fDrawIndirectSupport &&
638 ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
639 fBaseInstanceSupport = fDrawIndirectSupport &&
640 ctxInfo.hasExtension("GL_EXT_base_instance");
bsalomonfc9527a2016-08-29 09:18:39 -0700641 fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
cdalton06604b92016-02-05 10:09:51 -0800642 }
643
Brian Salomon1edc5b92016-11-29 13:43:46 -0500644 this->initShaderPrecisionTable(ctxInfo, gli, shaderCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800645
ethannicholas28ef4452016-03-25 09:26:03 -0700646 if (kGL_GrGLStandard == standard) {
Greg Daniela5cb7812017-06-16 09:45:32 -0400647 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading")) &&
ethannicholas6536ae52016-05-02 12:16:49 -0700648 ctxInfo.vendor() != kIntel_GrGLVendor) {
ethannicholas28ef4452016-03-25 09:26:03 -0700649 fSampleShadingSupport = true;
650 }
651 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
652 fSampleShadingSupport = true;
653 }
654
jvanverth84741b32016-09-30 08:39:02 -0700655 // TODO: support CHROMIUM_sync_point and maybe KHR_fence_sync
656 if (kGL_GrGLStandard == standard) {
657 if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync")) {
658 fFenceSyncSupport = true;
659 }
Brian Osman93a23462017-06-21 15:13:39 -0400660 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync")) {
jvanverth84741b32016-09-30 08:39:02 -0700661 fFenceSyncSupport = true;
662 }
663
Brian Osman0eb4ecb2017-05-16 13:30:11 -0400664 // Safely moving textures between contexts requires fences.
Brian Osman2c2bc112017-02-28 10:02:49 -0500665 fCrossContextTextureSupport = fFenceSyncSupport;
Brian Osman2c2bc112017-02-28 10:02:49 -0500666
brianosman131ff132016-06-07 14:22:44 -0700667 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
668 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
669 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
670 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
brianosman09563ce2016-06-02 08:59:34 -0700671 if (fMipMapLevelAndLodControlSupport &&
brianosman9a3fbf72016-06-09 13:11:08 -0700672 (contextOptions.fDoManualMipmapping ||
673 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
brianosman131ff132016-06-07 14:22:44 -0700674 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
675 (kATI_GrGLVendor == ctxInfo.vendor()))) {
brianosman09563ce2016-06-02 08:59:34 -0700676 fDoManualMipmapping = true;
677 }
678
brianosman20471892016-12-02 06:43:32 -0800679 fSRGBDecodeDisableSupport = ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode");
brianosman851c2382016-12-07 10:03:25 -0800680 fSRGBDecodeDisableAffectsMipmaps = fSRGBDecodeDisableSupport &&
681 kChromium_GrGLDriver != ctxInfo.driver();
brianosman20471892016-12-02 06:43:32 -0800682
Brian Salomon028a9a52017-05-11 11:39:08 -0400683 // See http://crbug.com/710443
684#ifdef SK_BUILD_FOR_MAC
685 if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
Eric Karlaeaf22b2017-05-18 15:08:09 -0700686 fClearToBoundaryValuesIsBroken = true;
Brian Salomon028a9a52017-05-11 11:39:08 -0400687 }
688#endif
Chris Dalton9926f4b2017-05-17 15:15:50 -0600689 if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
690 fDrawArraysBaseVertexIsBroken = true;
691 }
Brian Salomon028a9a52017-05-11 11:39:08 -0400692
bsalomoncdee0092016-01-08 13:20:12 -0800693 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
694 // already been detected.
brianosman20471892016-12-02 06:43:32 -0800695 this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
cdalton4cd67132015-06-10 19:23:46 -0700696
697 this->applyOptionsOverrides(contextOptions);
Brian Salomon1edc5b92016-11-29 13:43:46 -0500698 shaderCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000699}
700
egdaniel472d44e2015-10-22 08:20:00 -0700701const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
702 bool isCoreProfile) {
703 switch (generation) {
704 case k110_GrGLSLGeneration:
705 if (kGLES_GrGLStandard == standard) {
706 // ES2s shader language is based on version 1.20 but is version
707 // 1.00 of the ES language.
708 return "#version 100\n";
709 } else {
710 SkASSERT(kGL_GrGLStandard == standard);
711 return "#version 110\n";
712 }
713 case k130_GrGLSLGeneration:
714 SkASSERT(kGL_GrGLStandard == standard);
715 return "#version 130\n";
716 case k140_GrGLSLGeneration:
717 SkASSERT(kGL_GrGLStandard == standard);
718 return "#version 140\n";
719 case k150_GrGLSLGeneration:
720 SkASSERT(kGL_GrGLStandard == standard);
721 if (isCoreProfile) {
722 return "#version 150\n";
723 } else {
724 return "#version 150 compatibility\n";
725 }
726 case k330_GrGLSLGeneration:
727 if (kGLES_GrGLStandard == standard) {
728 return "#version 300 es\n";
729 } else {
730 SkASSERT(kGL_GrGLStandard == standard);
731 if (isCoreProfile) {
732 return "#version 330\n";
733 } else {
734 return "#version 330 compatibility\n";
735 }
736 }
cdalton33ad7012016-02-22 07:55:44 -0800737 case k400_GrGLSLGeneration:
738 SkASSERT(kGL_GrGLStandard == standard);
739 if (isCoreProfile) {
740 return "#version 400\n";
741 } else {
742 return "#version 400 compatibility\n";
743 }
Brian Salomond327e8c2016-11-15 13:26:08 -0500744 case k420_GrGLSLGeneration:
745 SkASSERT(kGL_GrGLStandard == standard);
746 if (isCoreProfile) {
747 return "#version 420\n";
748 }
749 else {
750 return "#version 420 compatibility\n";
751 }
egdaniel472d44e2015-10-22 08:20:00 -0700752 case k310es_GrGLSLGeneration:
753 SkASSERT(kGLES_GrGLStandard == standard);
754 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800755 case k320es_GrGLSLGeneration:
756 SkASSERT(kGLES_GrGLStandard == standard);
757 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700758 }
759 return "<no version>";
760}
761
egdaniel05ded892015-10-26 07:38:05 -0700762void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700763 GrGLStandard standard = ctxInfo.standard();
764 GrGLVersion version = ctxInfo.version();
765
766 /**************************************************************************
Brian Salomon1edc5b92016-11-29 13:43:46 -0500767 * Caps specific to GrShaderCaps
egdaniel472d44e2015-10-22 08:20:00 -0700768 **************************************************************************/
769
Brian Salomon1edc5b92016-11-29 13:43:46 -0500770 GrShaderCaps* shaderCaps = fShaderCaps.get();
771 shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700772 if (kGLES_GrGLStandard == standard) {
773 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500774 shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
775 shaderCaps->fFBFetchSupport = true;
776 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
777 shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700778 }
779 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
780 // 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 -0500781 shaderCaps->fFBFetchNeedsCustomOutput = false;
782 shaderCaps->fFBFetchSupport = true;
783 shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
784 shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700785 }
786 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
787 // The arm extension also requires an additional flag which we will set onResetContext
Brian Salomon1edc5b92016-11-29 13:43:46 -0500788 shaderCaps->fFBFetchNeedsCustomOutput = false;
789 shaderCaps->fFBFetchSupport = true;
790 shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
791 shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
egdaniel472d44e2015-10-22 08:20:00 -0700792 }
Brian Salomon1edc5b92016-11-29 13:43:46 -0500793 shaderCaps->fUsesPrecisionModifiers = true;
egdaniel472d44e2015-10-22 08:20:00 -0700794 }
795
egdaniel7517e452016-09-20 13:00:26 -0700796 // Currently the extension is advertised but fb fetch is broken on 500 series Adrenos like the
797 // Galaxy S7.
798 // TODO: Once this is fixed we can update the check here to look at a driver version number too.
799 if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500800 shaderCaps->fFBFetchSupport = false;
egdaniel7517e452016-09-20 13:00:26 -0700801 }
802
Brian Salomon1edc5b92016-11-29 13:43:46 -0500803 shaderCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
egdaniel472d44e2015-10-22 08:20:00 -0700804
cdaltonc08f1962016-02-12 12:14:06 -0800805 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500806 shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc08f1962016-02-12 12:14:06 -0800807 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500808 shaderCaps->fFlatInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800809 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
810 }
Brian Salomon41274562017-09-15 09:40:03 -0700811 // Flat interpolation appears to be slow on Qualcomm GPUs (tested Adreno 405 and 530).
812 shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
813 kQualcomm_GrGLVendor != ctxInfo.vendor();
cdaltonc08f1962016-02-12 12:14:06 -0800814 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500815 shaderCaps->fNoPerspectiveInterpolationSupport =
cdaltonc08f1962016-02-12 12:14:06 -0800816 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
817 } else {
818 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500819 shaderCaps->fNoPerspectiveInterpolationSupport = true;
820 shaderCaps->fNoPerspectiveInterpolationExtensionString =
cdaltonc08f1962016-02-12 12:14:06 -0800821 "GL_NV_shader_noperspective_interpolation";
822 }
823 }
824
cdalton33ad7012016-02-22 07:55:44 -0800825 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500826 shaderCaps->fMultisampleInterpolationSupport =
cdalton4a98cdb2016-03-01 12:12:20 -0800827 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
828 } else {
829 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500830 shaderCaps->fMultisampleInterpolationSupport = true;
cdalton4a98cdb2016-03-01 12:12:20 -0800831 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500832 shaderCaps->fMultisampleInterpolationSupport = true;
833 shaderCaps->fMultisampleInterpolationExtensionString =
cdalton4a98cdb2016-03-01 12:12:20 -0800834 "GL_OES_shader_multisample_interpolation";
835 }
836 }
837
838 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500839 shaderCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
cdalton33ad7012016-02-22 07:55:44 -0800840 } else {
841 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500842 shaderCaps->fSampleVariablesSupport = true;
cdalton33ad7012016-02-22 07:55:44 -0800843 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500844 shaderCaps->fSampleVariablesSupport = true;
845 shaderCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
cdalton33ad7012016-02-22 07:55:44 -0800846 }
847 }
848
Brian Salomon1edc5b92016-11-29 13:43:46 -0500849 if (shaderCaps->fSampleVariablesSupport &&
csmartdaltonf848c9c2016-06-15 12:42:13 -0700850 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage")) {
851 // Pre-361 NVIDIA has a bug with NV_sample_mask_override_coverage.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500852 shaderCaps->fSampleMaskOverrideCoverageSupport =
csmartdaltonf848c9c2016-06-15 12:42:13 -0700853 kNVIDIA_GrGLDriver != ctxInfo.driver() ||
854 ctxInfo.driverVersion() >= GR_GL_DRIVER_VER(361,00);
cdalton33ad7012016-02-22 07:55:44 -0800855 }
856
egdaniel472d44e2015-10-22 08:20:00 -0700857 // 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 -0500858 shaderCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
egdaniel472d44e2015-10-22 08:20:00 -0700859
860 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
861 // function that may require a gradient calculation inside a conditional block may return
862 // undefined results". This appears to be an issue with the 'any' call since even the simple
863 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
864 // from our GrTextureDomain processor.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500865 shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
egdaniel472d44e2015-10-22 08:20:00 -0700866
Brian Salomon1edc5b92016-11-29 13:43:46 -0500867 shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
868 shaderCaps->fGLSLGeneration,
869 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800870
Brian Salomon1edc5b92016-11-29 13:43:46 -0500871 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
872 shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
egdaniel574a4c12015-11-02 06:22:44 -0800873 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800874
875 // Frag Coords Convention support is not part of ES
876 // Known issue on at least some Intel platforms:
877 // http://code.google.com/p/skia/issues/detail?id=946
878 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
879 kGLES_GrGLStandard != standard &&
880 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
881 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500882 shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
egdaniel8dcdedc2015-11-11 06:27:20 -0800883 }
884
885 if (kGLES_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500886 shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
egdaniel8dcdedc2015-11-11 06:27:20 -0800887 }
888
cdalton9c3f1432016-03-11 10:07:37 -0800889 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
890 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500891 shaderCaps->fExternalTextureSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800892 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
893 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
894 // At least one driver has been found that has this extension without the "GL_" prefix.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500895 shaderCaps->fExternalTextureSupport = true;
cdalton9c3f1432016-03-11 10:07:37 -0800896 }
897 }
898
Brian Salomon1edc5b92016-11-29 13:43:46 -0500899 if (shaderCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800900 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500901 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
bsalomon7ea33f52015-11-22 14:51:00 -0800902 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500903 shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
bsalomon7ea33f52015-11-22 14:51:00 -0800904 }
905 }
906
cdaltonc04ce672016-03-11 14:07:38 -0800907 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500908 shaderCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800909 } else {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500910 shaderCaps->fTexelFetchSupport =
cdaltonf8a6ce82016-04-11 13:02:05 -0700911 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
912 }
913
Brian Salomon1edc5b92016-11-29 13:43:46 -0500914 if (shaderCaps->fTexelFetchSupport) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700915 if (kGL_GrGLStandard == standard) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500916 shaderCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
cdaltonf8a6ce82016-04-11 13:02:05 -0700917 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
918 } else {
919 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
920 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500921 shaderCaps->fTexelBufferSupport = true;
cdaltonf8a6ce82016-04-11 13:02:05 -0700922 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500923 shaderCaps->fTexelBufferSupport = true;
924 shaderCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700925 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500926 shaderCaps->fTexelBufferSupport = true;
927 shaderCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
cdaltonf8a6ce82016-04-11 13:02:05 -0700928 }
cdaltonc04ce672016-03-11 14:07:38 -0800929 }
930 }
931
Chris Dalton1d616352017-05-31 12:51:23 -0600932 if (kGL_GrGLStandard == standard) {
933 shaderCaps->fVertexIDSupport = true;
934 } else {
935 // Desktop GLSL 3.30 == ES GLSL 3.00.
936 shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
937 }
938
egdaniel8dcdedc2015-11-11 06:27:20 -0800939 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
Florin Malita8a0044f2017-08-07 14:38:22 -0400940 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0),
941 // so we must do the abs first in a separate expression.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500942 shaderCaps->fCanUseMinAndAbsTogether = false;
Florin Malita8a0044f2017-08-07 14:38:22 -0400943
944 // Tegra3 fract() seems to trigger undefined behavior for negative values, so we
945 // must avoid this condition.
946 shaderCaps->fCanUseFractForNegativeValues = false;
egdaniel8dcdedc2015-11-11 06:27:20 -0800947 }
948
bsalomon7ea33f52015-11-22 14:51:00 -0800949 // 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 -0800950 // thus must us -1.0 * %s.x to work correctly
951 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
Brian Salomon1edc5b92016-11-29 13:43:46 -0500952 shaderCaps->fMustForceNegatedAtanParamToFloat = true;
egdaniel8dcdedc2015-11-11 06:27:20 -0800953 }
egdaniel138c2632016-08-17 10:59:00 -0700954
955 // On Adreno devices with framebuffer fetch support, there is a bug where they always return
956 // the original dst color when reading the outColor even after being written to. By using a
957 // local outColor we can work around this bug.
Brian Salomon1edc5b92016-11-29 13:43:46 -0500958 if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
959 shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
egdaniel138c2632016-08-17 10:59:00 -0700960 }
csmartdalton2e777ea2017-02-15 10:41:27 -0700961
Brian Osmanac1e4962017-05-25 11:34:38 -0400962 // Newer Mali GPUs do incorrect static analysis in specific situations: If there is uniform
963 // color, and that uniform contains an opaque color, and the output of the shader is only based
964 // on that uniform plus soemthing un-trackable (like a texture read), the compiler will deduce
965 // that the shader always outputs opaque values. In that case, it appears to remove the shader
966 // based blending code it normally injects, turning SrcOver into Src. To fix this, we always
967 // insert an extra bit of math on the uniform that confuses the compiler just enough...
968 if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
969 shaderCaps->fMustObfuscateUniformColor = true;
970 }
Brian Osmandff5d432017-08-01 14:46:18 -0400971
972#ifdef SK_BUILD_FOR_WIN
973 // Check for ANGLE on Windows, so we can workaround a bug in D3D itself (anglebug.com/2098).
974 //
975 // Basically, if a shader has a construct like:
976 //
977 // float x = someCondition ? someValue : 0;
978 // float2 result = (0 == x) ? float2(x, x)
979 // : float2(2 * x / x, 0);
980 //
981 // ... the compiler will produce an error 'NaN and infinity literals not allowed', even though
982 // we've explicitly guarded the division with a check against zero. This manifests in much
983 // more complex ways in some of our shaders, so we use this caps bit to add an epsilon value
984 // to the denominator of divisions, even when we've added checks that the denominator isn't 0.
985 if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
986 shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
987 }
988#endif
egdaniel472d44e2015-10-22 08:20:00 -0700989}
990
kkinnunencfe62e32015-07-01 02:58:50 -0700991bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700992 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
993
994 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700995 return false;
996 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700997
kkinnunencfe62e32015-07-01 02:58:50 -0700998 if (kGL_GrGLStandard == ctxInfo.standard()) {
999 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
1000 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
1001 return false;
1002 }
1003 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -07001004 if (!hasChromiumPathRendering &&
1005 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -07001006 return false;
1007 }
1008 }
1009 // We only support v1.3+ of GL_NV_path_rendering which allows us to
1010 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
1011 // additions are detected by checking the existence of the function.
1012 // We also use *Then* functions that not all drivers might have. Check
1013 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -08001014 if (!gli->fFunctions.fStencilThenCoverFillPath ||
1015 !gli->fFunctions.fStencilThenCoverStrokePath ||
1016 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
1017 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
1018 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -07001019 return false;
1020 }
1021 return true;
1022}
bsalomon1aa20292016-01-22 08:16:09 -08001023
Brian Salomon71d9d842016-11-03 13:42:00 -04001024bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig,
bsalomon7928ef62016-01-05 10:26:39 -08001025 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -08001026 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
bsalomon2c3db322016-11-08 13:26:24 -08001027 std::function<bool ()> bindRenderTarget,
1028 std::function<void ()> unbindRenderTarget) const {
Brian Salomon71d9d842016-11-03 13:42:00 -04001029 // If it's not possible to even have a color attachment of surfaceConfig then read pixels is
bsalomone9573312016-01-25 14:33:25 -08001030 // not supported regardless of readConfig.
Brian Salomon71d9d842016-11-03 13:42:00 -04001031 if (!this->canConfigBeFBOColorAttachment(surfaceConfig)) {
bsalomone9573312016-01-25 14:33:25 -08001032 return false;
1033 }
bsalomon7928ef62016-01-05 10:26:39 -08001034
Brian Salomonbf7b6202016-11-11 16:08:03 -05001035 if (GrPixelConfigIsSint(surfaceConfig) != GrPixelConfigIsSint(readConfig)) {
1036 return false;
1037 }
1038
bsalomon76148af2016-01-12 11:13:47 -08001039 GrGLenum readFormat;
1040 GrGLenum readType;
Brian Salomon71d9d842016-11-03 13:42:00 -04001041 if (!this->getReadPixelsFormat(surfaceConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -08001042 return false;
1043 }
1044
bsalomon1aa20292016-01-22 08:16:09 -08001045 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -08001046 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
1047 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
1048 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
1049 // 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 -05001050 // The manual does not seem to fully match the spec as the spec allows integer formats
1051 // when the bound color buffer is an integer buffer. It doesn't specify which integer
1052 // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently.
csmartdalton6aa0e112017-02-08 16:14:11 -05001053 if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB &&
1054 readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA &&
1055 readFormat != GR_GL_RGBA_INTEGER) {
bsalomone9573312016-01-25 14:33:25 -08001056 return false;
1057 }
1058 // There is also a set of allowed types, but all the types we use are in the set:
1059 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
1060 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
1061 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
1062 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
1063 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
1064 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
1065 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -08001066 return true;
piotaixre4b23142014-10-02 10:57:53 -07001067 }
bsalomon7928ef62016-01-05 10:26:39 -08001068
bsalomon76148af2016-01-12 11:13:47 -08001069 // See Section 16.1.2 in the ES 3.2 specification.
Brian Salomonbf7b6202016-11-11 16:08:03 -05001070 switch (fConfigTable[surfaceConfig].fFormatType) {
1071 case kNormalizedFixedPoint_FormatType:
1072 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
1073 return true;
1074 }
1075 break;
1076 case kInteger_FormatType:
1077 if (GR_GL_RGBA_INTEGER == readFormat && GR_GL_INT == readType) {
1078 return true;
1079 }
1080 break;
1081 case kFloat_FormatType:
1082 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
1083 return true;
1084 }
1085 break;
bsalomon7928ef62016-01-05 10:26:39 -08001086 }
1087
Brian Salomon71d9d842016-11-03 13:42:00 -04001088 if (0 == fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -08001089 ReadPixelsFormat* rpFormat =
Brian Salomon71d9d842016-11-03 13:42:00 -04001090 const_cast<ReadPixelsFormat*>(&fConfigTable[surfaceConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -08001091 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -08001092 if (!bindRenderTarget()) {
1093 return false;
1094 }
1095 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
1096 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -08001097 rpFormat->fFormat = format;
1098 rpFormat->fType = type;
bsalomon2c3db322016-11-08 13:26:24 -08001099 unbindRenderTarget();
bsalomon7928ef62016-01-05 10:26:39 -08001100 }
1101
Brian Salomon71d9d842016-11-03 13:42:00 -04001102 return fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
1103 fConfigTable[surfaceConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -07001104}
1105
Eric Karl5c779752017-05-08 12:02:07 -07001106void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
1107 const GrGLInterface* gli) {
1108 // We need dual source blending and the ability to disable multisample in order to support mixed
1109 // samples in every corner case. We only use mixed samples if the stencil-and-cover path
1110 // renderer is available and enabled; no other path renderers support this feature.
1111 if (fMultisampleDisableSupport &&
1112 this->shaderCaps()->dualSourceBlendingSupport() &&
Brian Osman195c05b2017-08-30 15:14:04 -04001113 this->shaderCaps()->pathRenderingSupport()
1114#if GR_TEST_UTILS
1115 && (contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover)
1116#endif
1117 ) {
Eric Karl5c779752017-05-08 12:02:07 -07001118 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
Robert Phillips3b3307f2017-05-24 07:44:02 -04001119 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
Eric Karl5c779752017-05-08 12:02:07 -07001120 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
1121 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
1122 kChromium_GrGLDriver == ctxInfo.driver())) {
1123 fDiscardRenderTargetSupport = false;
1124 fInvalidateFBType = kNone_InvalidateFBType;
1125 }
1126 }
1127
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001128 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001129 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
1130 // ES3 driver bugs on at least one device with a tiled GPU (N10).
1131 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
1132 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
1133 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
1134 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -08001135 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -07001136 fMSFBOType = kMixedSamples_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -04001137 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1138 fMSFBOType = kStandard_MSFBOType;
1139 fAlpha8IsRenderable = true;
1140 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
Brian Salomon00731b42016-10-14 11:30:51 -04001141 fMSFBOType = kStandard_MSFBOType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001142 } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001143 fMSFBOType = kStandard_MSFBOType;
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001144 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
1145 fMSFBOType = kES_Apple_MSFBOType;
1146 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001147 } else {
egdanieleed519e2016-01-15 11:36:18 -08001148 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -07001149 fMSFBOType = kMixedSamples_MSFBOType;
Brian Salomon00731b42016-10-14 11:30:51 -04001150 } else if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1151 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001152
Brian Salomon00731b42016-10-14 11:30:51 -04001153 fMSFBOType = kStandard_MSFBOType;
Robert Phillips5ab72762017-06-07 12:04:18 -04001154 if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
1155 // Core profile removes ALPHA8 support.
1156 // OpenGL 3.0+ (and GL_ARB_framebuffer_object) supports ALPHA8 as renderable.
1157 // However, osmesa fails if it is used even when GL_ARB_framebuffer_object is
1158 // present.
1159 fAlpha8IsRenderable = true;
1160 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001161 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1162 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
Robert Phillips5ab72762017-06-07 12:04:18 -04001163 fMSFBOType = kStandard_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001164 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001165 }
Eric Karl5c779752017-05-08 12:02:07 -07001166
Robert Phillips3b3307f2017-05-24 07:44:02 -04001167 // We disable MSAA across the board for Intel GPUs
1168 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
1169 fMSFBOType = kNone_MSFBOType;
1170 }
1171
Eric Karl5c779752017-05-08 12:02:07 -07001172 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
1173 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
1174 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
1175 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
1176 }
1177 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
1178 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
1179 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
1180 // This is to guard against platforms that may not support as many samples for
1181 // glRasterSamples as they do for framebuffers.
1182 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
1183 }
1184 fMaxColorSampleCount = fMaxStencilSampleCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001185}
1186
cdalton1dd05422015-06-12 09:01:18 -07001187void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001188 GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
cdalton1dd05422015-06-12 09:01:18 -07001189
1190 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
1191 // for now until its own blacklists can be updated.
1192 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
Greg Daniel0ea7d432016-10-27 16:55:52 -04001193 kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
cdalton1dd05422015-06-12 09:01:18 -07001194 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -07001195 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -07001196 return;
1197 }
1198
1199 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1200 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001201 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001202 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
1203 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001204 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001205 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1206 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
1207 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
1208 return;
1209 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1210 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001211 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001212 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
1213 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001214 shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton1dd05422015-06-12 09:01:18 -07001215 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1216 // slow on a particular platform.
1217 } else {
1218 return; // No advanced blend support.
1219 }
1220
1221 SkASSERT(this->advancedBlendEquationSupport());
1222
csmartdalton3b88a032016-08-04 14:43:49 -07001223 if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1224 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355,00)) {
1225 // Blacklist color-dodge and color-burn on pre-355.00 NVIDIA.
cdalton1dd05422015-06-12 09:01:18 -07001226 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
1227 (1 << kColorBurn_GrBlendEquation);
1228 }
joel.liang9764c402015-07-09 19:46:18 -07001229 if (kARM_GrGLVendor == ctxInfo.vendor()) {
1230 // Blacklist color-burn on ARM until the fix is released.
1231 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
1232 }
cdalton1dd05422015-06-12 09:01:18 -07001233}
1234
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001235namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001236const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001237}
1238
Eric Karl5c779752017-05-08 12:02:07 -07001239void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001240
1241 // Build up list of legal stencil formats (though perhaps not supported on
1242 // the particular gpu/driver) from most preferred to least.
1243
1244 // these consts are in order of most preferred to least preferred
1245 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1246
1247 static const StencilFormat
1248 // internal Format stencil bits total bits packed?
1249 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1250 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1251 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1252 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001253 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001254 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1255
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001256 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001257 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001258 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001259 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1260 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1261
1262 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1263 // require FBO support we can expect these are legal formats and don't
1264 // check. These also all support the unsized GL_STENCIL_INDEX.
1265 fStencilFormats.push_back() = gS8;
1266 fStencilFormats.push_back() = gS16;
1267 if (supportsPackedDS) {
1268 fStencilFormats.push_back() = gD24S8;
1269 }
1270 fStencilFormats.push_back() = gS4;
1271 if (supportsPackedDS) {
1272 fStencilFormats.push_back() = gDS;
1273 }
1274 } else {
1275 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1276 // for other formats.
1277 // ES doesn't support using the unsized format.
1278
1279 fStencilFormats.push_back() = gS8;
1280 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001281 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1282 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001283 fStencilFormats.push_back() = gD24S8;
1284 }
1285 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1286 fStencilFormats.push_back() = gS4;
1287 }
1288 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001289}
1290
Brian Osman71a18892017-08-10 10:23:25 -04001291void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001292
Brian Osman71a18892017-08-10 10:23:25 -04001293 // We are called by the base class, which has already called beginObject(). We choose to nest
1294 // all of our caps information in a named sub-object.
1295 writer->beginObject("GL caps");
bsalomon@google.combcce8922013-03-25 15:38:39 +00001296
Brian Osman71a18892017-08-10 10:23:25 -04001297 writer->beginArray("Stencil Formats");
1298
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001299 for (int i = 0; i < fStencilFormats.count(); ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001300 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001301 writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
1302 writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
1303 writer->endObject();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001304 }
1305
Brian Osman71a18892017-08-10 10:23:25 -04001306 writer->endArray();
1307
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001308 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001309 "None",
Brian Salomon00731b42016-10-14 11:30:51 -04001310 "Standard",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001311 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001312 "IMG MS To Texture",
1313 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001314 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001315 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001316 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
Robert Phillips5ab72762017-06-07 12:04:18 -04001317 GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
1318 GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
1319 GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
1320 GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
1321 GR_STATIC_ASSERT(5 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001322 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001323
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001324 static const char* kInvalidateFBTypeStr[] = {
1325 "None",
1326 "Discard",
1327 "Invalidate",
1328 };
1329 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1330 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1331 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1332 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001333
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001334 static const char* kMapBufferTypeStr[] = {
1335 "None",
1336 "MapBuffer",
1337 "MapBufferRange",
1338 "Chromium",
1339 };
1340 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1341 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1342 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1343 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1344 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1345
Brian Osman71a18892017-08-10 10:23:25 -04001346 writer->appendBool("Core Profile", fIsCoreProfile);
1347 writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
1348 writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
1349 writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
1350 writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
1351 writer->appendBool("Unpack Row length support", fUnpackRowLengthSupport);
1352 writer->appendBool("Unpack Flip Y support", fUnpackFlipYSupport);
1353 writer->appendBool("Pack Row length support", fPackRowLengthSupport);
1354 writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
bsalomon@google.combcce8922013-03-25 15:38:39 +00001355
Brian Osman71a18892017-08-10 10:23:25 -04001356 writer->appendBool("Texture Usage support", fTextureUsageSupport);
1357 writer->appendBool("GL_R support", fTextureRedSupport);
1358 writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
1359 writer->appendBool("GL_ARB_imaging support", fImagingSupport);
1360 writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
1361 writer->appendBool("Direct state access support", fDirectStateAccessSupport);
1362 writer->appendBool("Debug support", fDebugSupport);
1363 writer->appendBool("Draw indirect support", fDrawIndirectSupport);
1364 writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
1365 writer->appendBool("Base instance support", fBaseInstanceSupport);
1366 writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
1367 writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
1368 writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
1369 writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
1370 writer->appendBool("Texture swizzle support", fTextureSwizzleSupport);
1371 writer->appendBool("BGRA to RGBA readback conversions are slow",
1372 fRGBAToBGRAReadbackConversionsAreSlow);
1373 writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
1374 fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
1375 writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
1376 fUseDrawInsteadOfAllRenderTargetWrites);
bsalomon41e4384e2016-01-08 09:12:44 -08001377
Brian Osman71a18892017-08-10 10:23:25 -04001378 writer->beginArray("configs");
1379
bsalomon41e4384e2016-01-08 09:12:44 -08001380 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Osman80488222017-08-10 13:29:30 -04001381 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -04001382 writer->appendHexU32("flags", fConfigTable[i].fFlags);
1383 writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
1384 writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
1385 writer->appendHexU32("e_format",
1386 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage]);
1387 writer->appendHexU32(
1388 "e_format_teximage",
1389 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
1390 writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
1391 writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
1392 writer->appendHexU32("i_for_renderbuffer",
1393 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
1394 writer->endObject();
bsalomon41e4384e2016-01-08 09:12:44 -08001395 }
1396
Brian Osman71a18892017-08-10 10:23:25 -04001397 writer->endArray();
1398 writer->endObject();
jvanverthe9c0fc62015-04-29 11:18:05 -07001399}
1400
jvanverthe9c0fc62015-04-29 11:18:05 -07001401static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1402 switch (p) {
1403 case kLow_GrSLPrecision:
1404 return GR_GL_LOW_FLOAT;
1405 case kMedium_GrSLPrecision:
1406 return GR_GL_MEDIUM_FLOAT;
1407 case kHigh_GrSLPrecision:
1408 return GR_GL_HIGH_FLOAT;
Brian Osman33aa2c72017-04-05 09:26:15 -04001409 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -04001410 SK_ABORT("Unexpected precision type.");
Brian Osman33aa2c72017-04-05 09:26:15 -04001411 return -1;
jvanverthe9c0fc62015-04-29 11:18:05 -07001412 }
jvanverthe9c0fc62015-04-29 11:18:05 -07001413}
1414
1415static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1416 switch (type) {
1417 case kVertex_GrShaderType:
1418 return GR_GL_VERTEX_SHADER;
1419 case kGeometry_GrShaderType:
1420 return GR_GL_GEOMETRY_SHADER;
1421 case kFragment_GrShaderType:
1422 return GR_GL_FRAGMENT_SHADER;
1423 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -04001424 SK_ABORT("Unknown shader type.");
jvanverthe9c0fc62015-04-29 11:18:05 -07001425 return -1;
1426}
1427
jvanverthcba99b82015-06-24 06:59:57 -07001428void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
halcanary9d524f22016-03-29 09:03:52 -07001429 const GrGLInterface* intf,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001430 GrShaderCaps* shaderCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001431 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1432 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1433 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1434 if (kGeometry_GrShaderType != s) {
1435 GrShaderType shaderType = static_cast<GrShaderType>(s);
1436 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001437 GrShaderCaps::PrecisionInfo* first = nullptr;
Brian Salomon1edc5b92016-11-29 13:43:46 -05001438 shaderCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001439 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1440 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1441 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1442 GrGLint range[2];
1443 GrGLint bits;
1444 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1445 if (bits) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001446 shaderCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1447 shaderCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1448 shaderCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001449 if (!first) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001450 first = &shaderCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001451 }
Brian Salomon1edc5b92016-11-29 13:43:46 -05001452 else if (!shaderCaps->fShaderPrecisionVaries) {
1453 shaderCaps->fShaderPrecisionVaries =
1454 (*first != shaderCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001455 }
1456 }
1457 }
1458 }
1459 }
1460 }
1461 else {
1462 // 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 -05001463 shaderCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001464 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1465 if (kGeometry_GrShaderType != s) {
1466 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001467 shaderCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1468 shaderCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1469 shaderCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001470 }
1471 }
1472 }
1473 }
1474 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1475 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1476 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1477 // are recommended against.
Brian Salomon1edc5b92016-11-29 13:43:46 -05001478 if (shaderCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001479 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05001480 shaderCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1481 shaderCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001482 }
1483 }
Brian Salomon1edc5b92016-11-29 13:43:46 -05001484 shaderCaps->initSamplerPrecisionTable();
jvanverthe9c0fc62015-04-29 11:18:05 -07001485}
1486
bsalomon41e4384e2016-01-08 09:12:44 -08001487bool GrGLCaps::bgraIsInternalFormat() const {
1488 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1489}
1490
bsalomon76148af2016-01-12 11:13:47 -08001491bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1492 GrGLenum* internalFormat, GrGLenum* externalFormat,
1493 GrGLenum* externalType) const {
1494 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1495 externalFormat, externalType)) {
1496 return false;
1497 }
1498 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1499 return true;
1500}
1501
bsalomon76148af2016-01-12 11:13:47 -08001502bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1503 GrGLenum* externalFormat, GrGLenum* externalType) const {
1504 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1505 externalFormat, externalType)) {
1506 return false;
1507 }
1508 return true;
1509}
1510
1511bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
bsalomon76148af2016-01-12 11:13:47 -08001512 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1513 return true;
1514}
1515
1516bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1517 ExternalFormatUsage usage, GrGLenum* externalFormat,
1518 GrGLenum* externalType) const {
1519 SkASSERT(externalFormat && externalType);
bsalomon76148af2016-01-12 11:13:47 -08001520
1521 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1522 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1523
1524 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1525 // made to work in many cases using glPixelStore and what not but is not needed currently.
1526 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1527 return false;
1528 }
1529
1530 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1531 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1532
bsalomone9573312016-01-25 14:33:25 -08001533 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1534 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1535 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1536 // texture, not the red component.
1537 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1538 if (this->textureRedSupport()) {
1539 SkASSERT(GR_GL_RED == *externalFormat);
1540 *externalFormat = GR_GL_ALPHA;
1541 }
1542 }
1543
bsalomon76148af2016-01-12 11:13:47 -08001544 return true;
1545}
1546
brianosman20471892016-12-02 06:43:32 -08001547void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
1548 const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
Brian Salomon1edc5b92016-11-29 13:43:46 -05001549 GrShaderCaps* shaderCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001550 /*
1551 Comments on renderability of configs on various GL versions.
1552 OpenGL < 3.0:
1553 no built in support for render targets.
1554 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1555 format RGB, RGBA and NV float formats we don't use.
1556 This is the following:
1557 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1558 RGB10_A2, RGBA12,RGBA16
1559 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1560 since they aren't required by later standards and the driver can simply return
1561 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1562 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1563 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1564 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1565 This adds a lot of additional renderable sized formats, including ALPHA8.
1566 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1567 16F, 32I, 32UI, and 32F variants).
1568 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1569
1570 For both the above extensions we limit ourselves to those that are also required by
1571 OpenGL 3.0.
1572
1573 OpenGL 3.0:
1574 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1575 but are not required to be supported as renderable textures/renderbuffer.
1576 Required renderable color formats:
1577 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1578 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1579 RGB10_A2.
1580 - R11F_G11F_B10F.
1581 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1582 and RG8UI.
1583 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1584 - ALPHA8
1585
1586 OpenGL 3.1, 3.2, 3.3
1587 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1588 OpengGL 3.3, 4.0, 4.1
1589 Adds RGB10_A2UI.
1590 OpengGL 4.2
1591 Adds
1592 - RGB5_A1, RGBA4
1593 - RGB565
1594 OpenGL 4.4
1595 Does away with the separate list and adds a column to the sized internal color format
1596 table. However, no new formats become required color renderable.
1597
1598 ES 2.0
1599 color renderable: RGBA4, RGB5_A1, RGB565
1600 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1601 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1602 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1603 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1604 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1605 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1606
1607 ES 3.0
1608 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1609 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1610 RGB5_A1.
1611 - RGB8 and RGB565.
1612 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1613 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1614 ES 3.1
1615 Adds RGB10_A2, RGB10_A2UI,
1616 ES 3.2
1617 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1618 */
Brian Salomon71d9d842016-11-03 13:42:00 -04001619 uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag |
1620 ConfigInfo::kFBOColorAttachment_Flag;
1621 uint32_t allRenderFlags = nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001622 if (kNone_MSFBOType != fMSFBOType) {
1623 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1624 }
bsalomon41e4384e2016-01-08 09:12:44 -08001625 GrGLStandard standard = ctxInfo.standard();
1626 GrGLVersion version = ctxInfo.version();
1627
cblume790d5132016-02-29 11:13:29 -08001628 bool texStorageSupported = false;
1629 if (kGL_GrGLStandard == standard) {
1630 // The EXT version can apply to either GL or GLES.
1631 texStorageSupported = version >= GR_GL_VER(4,2) ||
1632 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1633 ctxInfo.hasExtension("GL_EXT_texture_storage");
1634 } else {
Brian Salomon3ab83e22016-11-28 13:14:00 -05001635 texStorageSupported = version >= GR_GL_VER(3,0) ||
1636 ctxInfo.hasExtension("GL_EXT_texture_storage");
cblume790d5132016-02-29 11:13:29 -08001637 }
1638
1639 // TODO: remove after command buffer supports full ES 3.0
1640 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1641 kChromium_GrGLDriver == ctxInfo.driver()) {
1642 texStorageSupported = false;
1643 }
1644
cdalton74b8d322016-04-11 14:47:28 -07001645 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1646
bsalomon30447372015-12-21 09:03:05 -08001647 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1648 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001649 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001650 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001651 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001652 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001653
1654 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1655 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001656 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1657 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001658 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001659 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001660 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1661 if (kGL_GrGLStandard == standard) {
1662 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1663 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001664 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001665 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1666 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1667 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1668 }
egdaniel4999df82016-01-07 17:06:04 -08001669 }
cblume790d5132016-02-29 11:13:29 -08001670 if (texStorageSupported) {
1671 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1672 }
cdalton74b8d322016-04-11 14:47:28 -07001673 if (texelBufferSupport) {
1674 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1675 }
bsalomoncdee0092016-01-08 13:20:12 -08001676 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001677
bsalomon76148af2016-01-12 11:13:47 -08001678 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1679 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001680 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001681 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001682 if (kGL_GrGLStandard == standard) {
1683 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1684 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1685 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1686 // Since the internal format is RGBA8, it is also renderable.
1687 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1688 allRenderFlags;
1689 }
1690 } else {
1691 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1692 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1693 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
Brian Osman48c99192017-06-02 08:45:06 -04001694 // This APPLE extension introduces complexity on ES2. It leaves the internal format
1695 // as RGBA, but allows BGRA as the external format. From testing, it appears that the
1696 // driver remembers the external format when the texture is created (with TexImage).
1697 // If you then try to upload data in the other swizzle (with TexSubImage), it fails.
1698 // We could work around this, but it adds even more state tracking to code that is
1699 // already too tricky. Instead, we opt not to support BGRA on ES2 with this extension.
1700 // This also side-steps some ambiguous interactions with the texture storage extension.
1701 if (version >= GR_GL_VER(3,0)) {
1702 // The APPLE extension doesn't make this renderable.
1703 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
bsalomon41e4384e2016-01-08 09:12:44 -08001704 }
1705 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1706 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Salomon71d9d842016-11-03 13:42:00 -04001707 nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001708 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001709 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001710 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1711 ConfigInfo::kRenderableWithMSAA_Flag;
1712 }
1713 }
1714 }
Brian Osman48c99192017-06-02 08:45:06 -04001715
1716 bool isX86PowerVR = false;
1717#if defined(SK_CPU_X86)
1718 if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
1719 isX86PowerVR = true;
1720 }
1721#endif
1722
1723 // Adreno 3xx, 4xx, 5xx, and NexusPlayer all fail if we try to use TexStorage with BGRA
1724 if (texStorageSupported &&
1725 kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
1726 kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
1727 kAdreno5xx_GrGLRenderer != ctxInfo.renderer() &&
1728 !isX86PowerVR) {
1729 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
cblume790d5132016-02-29 11:13:29 -08001730 }
bsalomoncdee0092016-01-08 13:20:12 -08001731 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001732
brianosmana6359362016-03-21 06:55:37 -07001733 // We only enable srgb support if both textures and FBOs support srgb,
brianosman35b784d2016-05-05 11:52:53 -07001734 // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
bsalomon41e4384e2016-01-08 09:12:44 -08001735 if (kGL_GrGLStandard == standard) {
1736 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001737 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001738 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1739 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1740 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001741 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001742 }
1743 }
1744 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001745 if (fSRGBSupport) {
1746 fSRGBWriteControl = true;
1747 }
bsalomon41e4384e2016-01-08 09:12:44 -08001748 } else {
brianosman20471892016-12-02 06:43:32 -08001749 fSRGBSupport = ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
Brian Osman48c99192017-06-02 08:45:06 -04001750 // NexusPlayer has strange bugs with sRGB (skbug.com/4148). This is a targeted fix to
1751 // blacklist that device (and any others that might be sharing the same driver).
1752 if (isX86PowerVR) {
brianosman20471892016-12-02 06:43:32 -08001753 fSRGBSupport = false;
1754 }
bsalomon41e4384e2016-01-08 09:12:44 -08001755 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1756 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001757 // See https://bug.skia.org/5329 for Adreno4xx issue.
1758 fSRGBWriteControl = kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
1759 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001760 }
brianosman20471892016-12-02 06:43:32 -08001761 if (contextOptions.fRequireDecodeDisableForSRGB && !fSRGBDecodeDisableSupport) {
1762 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode. Clients
1763 // can opt-out of that requirement, if they intend to always do linear blending.
brianosmana6359362016-03-21 06:55:37 -07001764 fSRGBSupport = false;
1765 }
brianosman20471892016-12-02 06:43:32 -08001766
1767 // This is very conservative, if we're on a platform where N32 is BGRA, and using ES, disable
1768 // all sRGB support. Too much code relies on creating surfaces with N32 + sRGB colorspace,
1769 // and sBGRA is basically impossible to support on any version of ES (with our current code).
1770 // In particular, ES2 doesn't support sBGRA at all, and even in ES3, there is no valid pair
1771 // of formats that can be used for TexImage calls to upload BGRA data to sRGBA (which is what
1772 // we *have* to use as the internal format, because sBGRA doesn't exist). This primarily
1773 // affects Windows.
1774 if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig && kGLES_GrGLStandard == standard) {
1775 fSRGBSupport = false;
1776 }
1777
Brian Osman48c99192017-06-02 08:45:06 -04001778 // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format
1779 // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions.
1780 bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0);
1781
Brian Osman67999392017-05-31 16:19:34 -04001782 uint32_t srgbRenderFlags = allRenderFlags;
1783 // MacPro devices with AMD cards fail to create MSAA sRGB render buffers
1784#if defined(SK_BUILD_FOR_MAC)
1785 if (kATI_GrGLVendor == ctxInfo.vendor()) {
1786 srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
1787 }
1788#endif
1789
bsalomon30447372015-12-21 09:03:05 -08001790 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1791 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1792 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1793 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001794 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1795 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001796 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001797 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001798 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001799 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001800 srgbRenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001801 }
Brian Osman48c99192017-06-02 08:45:06 -04001802 // ES2 Command Buffer does not allow TexStorage with SRGB8_ALPHA8_EXT
1803 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001804 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1805 }
bsalomoncdee0092016-01-08 13:20:12 -08001806 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
brianosmana6359362016-03-21 06:55:37 -07001807 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1808 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1809 // is in this format, for example).
1810 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1811 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1812 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1813 // external format is GL_BGRA.
1814 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1815 GR_GL_BGRA;
1816 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1817 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001818 if (fSRGBSupport && kGL_GrGLStandard == standard) {
brianosmana6359362016-03-21 06:55:37 -07001819 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
Brian Osman67999392017-05-31 16:19:34 -04001820 srgbRenderFlags;
brianosmana6359362016-03-21 06:55:37 -07001821 }
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001822
brianosmana6359362016-03-21 06:55:37 -07001823 if (texStorageSupported) {
1824 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1825 }
1826 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1827
Brian Salomonbf7b6202016-11-11 16:08:03 -05001828 bool hasIntegerTextures;
1829 if (standard == kGL_GrGLStandard) {
1830 hasIntegerTextures = version >= GR_GL_VER(3, 0) ||
1831 ctxInfo.hasExtension("GL_EXT_texture_integer");
1832 } else {
1833 hasIntegerTextures = (version >= GR_GL_VER(3, 0));
1834 }
1835 // We may have limited GLSL to an earlier version that doesn't have integer sampler types.
1836 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
1837 hasIntegerTextures = false;
1838 }
1839 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA_INTEGER;
1840 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8I;
1841 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RGBA_INTEGER;
1842 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormats.fExternalType = GR_GL_BYTE;
1843 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFormatType = kInteger_FormatType;
1844 // We currently only support using integer textures as srcs, not for rendering (even though GL
1845 // allows it).
1846 if (hasIntegerTextures) {
1847 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1848 ConfigInfo::kFBOColorAttachment_Flag;
1849 if (texStorageSupported) {
1850 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags |=
1851 ConfigInfo::kCanUseTexStorage_Flag;
1852 }
1853 }
1854
bsalomon30447372015-12-21 09:03:05 -08001855 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1856 if (this->ES2CompatibilitySupport()) {
1857 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1858 } else {
1859 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1860 }
bsalomon76148af2016-01-12 11:13:47 -08001861 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1862 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001863 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001864 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001865 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1866 if (kGL_GrGLStandard == standard) {
elementala6759102016-11-18 23:11:29 +01001867 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
bsalomon41e4384e2016-01-08 09:12:44 -08001868 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1869 }
1870 } else {
1871 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1872 }
cblume790d5132016-02-29 11:13:29 -08001873 // 565 is not a sized internal format on desktop GL. So on desktop with
1874 // 565 we always use an unsized internal format to let the system pick
1875 // the best sized format to convert the 565 data to. Since TexStorage
1876 // only allows sized internal formats we disallow it.
1877 //
1878 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1879 // update.
1880 if (texStorageSupported && kGL_GrGLStandard != standard) {
1881 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1882 }
bsalomoncdee0092016-01-08 13:20:12 -08001883 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001884
1885 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1886 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001887 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1888 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001889 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001890 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001891 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1892 if (kGL_GrGLStandard == standard) {
1893 if (version >= GR_GL_VER(4, 2)) {
1894 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1895 }
1896 } else {
1897 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1898 }
cblume790d5132016-02-29 11:13:29 -08001899 if (texStorageSupported) {
1900 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1901 }
bsalomoncdee0092016-01-08 13:20:12 -08001902 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001903
Brian Osmanf4faccd2017-01-10 16:53:58 -05001904 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1905 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1906 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
bsalomon30447372015-12-21 09:03:05 -08001907 if (this->textureRedSupport()) {
1908 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1909 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001910 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1911 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001912 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001913 if (texelBufferSupport) {
1914 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1915 }
Robert Phillips5ab72762017-06-07 12:04:18 -04001916 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
bsalomon30447372015-12-21 09:03:05 -08001917 } else {
1918 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1919 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001920 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1921 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001922 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
Robert Phillips5ab72762017-06-07 12:04:18 -04001923 if (fAlpha8IsRenderable) {
1924 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1925 }
bsalomon30447372015-12-21 09:03:05 -08001926 }
Robert Phillips5ab72762017-06-07 12:04:18 -04001927
Brian Osman48c99192017-06-02 08:45:06 -04001928 // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8)
1929 if (texStorageSupported && !isCommandBufferES2) {
cblume790d5132016-02-29 11:13:29 -08001930 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1931 }
bsalomon41e4384e2016-01-08 09:12:44 -08001932
Brian Osmanf4faccd2017-01-10 16:53:58 -05001933 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1934 fConfigTable[kGray_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1935 fConfigTable[kGray_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
Brian Osman986563b2017-01-10 14:20:02 -05001936 if (this->textureRedSupport()) {
1937 fConfigTable[kGray_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1938 fConfigTable[kGray_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
1939 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1940 GR_GL_RED;
1941 fConfigTable[kGray_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRA();
1942 if (texelBufferSupport) {
1943 fConfigTable[kGray_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1944 }
1945 } else {
1946 fConfigTable[kGray_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
1947 fConfigTable[kGray_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
1948 fConfigTable[kGray_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1949 GR_GL_LUMINANCE;
1950 fConfigTable[kGray_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1951 }
Brian Osman986563b2017-01-10 14:20:02 -05001952#if 0 // Leaving Gray8 as non-renderable, to keep things simple and match raster
1953 if (this->textureRedSupport() ||
1954 (kDesktop_ARB_MSFBOType == this->msFBOType() &&
1955 ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
1956 // desktop ARB extension/3.0+ supports LUMINANCE8 as renderable.
1957 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
1958 // Core profile removes LUMINANCE8 support, but we should have chosen R8 in that case.
1959 fConfigTable[kGray_8_GrPixelConfig].fFlags |= allRenderFlags;
1960 }
1961#endif
Brian Osman48c99192017-06-02 08:45:06 -04001962 if (texStorageSupported && !isCommandBufferES2) {
Brian Osman986563b2017-01-10 14:20:02 -05001963 fConfigTable[kGray_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1964 }
1965
bsalomon41e4384e2016-01-08 09:12:44 -08001966 // Check for [half] floating point texture support
1967 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1968 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1969 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1970 bool hasFPTextures = false;
1971 bool hasHalfFPTextures = false;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001972 bool rgIsTexturable = false;
bsalomon41e4384e2016-01-08 09:12:44 -08001973 // for now we don't support floating point MSAA on ES
Brian Salomon71d9d842016-11-03 13:42:00 -04001974 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags;
bsalomon41e4384e2016-01-08 09:12:44 -08001975
1976 if (kGL_GrGLStandard == standard) {
1977 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1978 hasFPTextures = true;
1979 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001980 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001981 }
1982 } else {
1983 if (version >= GR_GL_VER(3, 1)) {
1984 hasFPTextures = true;
1985 hasHalfFPTextures = true;
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04001986 rgIsTexturable = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001987 } else {
1988 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1989 ctxInfo.hasExtension("GL_OES_texture_float")) {
1990 hasFPTextures = true;
1991 }
1992 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1993 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1994 hasHalfFPTextures = true;
1995 }
1996 }
1997 }
bsalomon30447372015-12-21 09:03:05 -08001998
csmartdalton6aa0e112017-02-08 16:14:11 -05001999 for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
2000 const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
2001 fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
2002 fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
2003 kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
2004 fConfigTable[fpconfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = format;
2005 fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
2006 fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
2007 if (hasFPTextures) {
Robert Phillipsb7b7e5f2017-05-22 13:23:19 -04002008 fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0;
csmartdalton6aa0e112017-02-08 16:14:11 -05002009 // For now we only enable rendering to float on desktop, because on ES we'd have to
2010 // solve many precision issues and no clients actually want this yet.
2011 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
2012 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
2013 fConfigTable[fpconfig].fFlags |= fpRenderFlags;
2014 }
bsalomon41e4384e2016-01-08 09:12:44 -08002015 }
csmartdalton6aa0e112017-02-08 16:14:11 -05002016 if (texStorageSupported) {
2017 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
2018 }
2019 if (texelBufferSupport) {
2020 fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
2021 }
2022 fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08002023 }
bsalomon30447372015-12-21 09:03:05 -08002024
2025 if (this->textureRedSupport()) {
2026 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
2027 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08002028 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
2029 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08002030 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07002031 if (texelBufferSupport) {
2032 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |=
2033 ConfigInfo::kCanUseWithTexelBuffer_Flag;
2034 }
bsalomon30447372015-12-21 09:03:05 -08002035 } else {
2036 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
2037 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08002038 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
2039 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08002040 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08002041 }
Geoff Lang4b050002017-09-28 15:16:50 -04002042
2043 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08002044 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
2045 } else {
2046 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
2047 }
bsalomon7928ef62016-01-05 10:26:39 -08002048 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
cblume790d5132016-02-29 11:13:29 -08002049 if (texStorageSupported) {
2050 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
2051 }
csmartdalton6aa0e112017-02-08 16:14:11 -05002052 if (hasHalfFPTextures) {
2053 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
2054 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
2055 // GL_RED internal format.
2056 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) ||
2057 (this->textureRedSupport() &&
2058 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
2059 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
2060 }
2061 }
bsalomon30447372015-12-21 09:03:05 -08002062
2063 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
2064 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08002065 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
2066 GR_GL_RGBA;
Geoff Lang4b050002017-09-28 15:16:50 -04002067 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
bsalomon30447372015-12-21 09:03:05 -08002068 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
2069 } else {
2070 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
2071 }
bsalomon7928ef62016-01-05 10:26:39 -08002072 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08002073 if (hasHalfFPTextures) {
2074 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
2075 // ES requires 3.2 or EXT_color_buffer_half_float.
2076 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
2077 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
2078 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
2079 }
2080 }
cblume790d5132016-02-29 11:13:29 -08002081 if (texStorageSupported) {
2082 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
2083 }
cdalton74b8d322016-04-11 14:47:28 -07002084 if (texelBufferSupport) {
2085 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
2086 }
bsalomoncdee0092016-01-08 13:20:12 -08002087 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08002088
bsalomon30447372015-12-21 09:03:05 -08002089 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
2090
2091 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08002092 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
2093 ctxInfo.version() >= GR_GL_VER(3,0));
2094 // All ES versions (thus far) require sized internal formats for render buffers.
2095 // TODO: Always use sized internal format?
2096 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
2097
bsalomon30447372015-12-21 09:03:05 -08002098 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08002099 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
2100 // param to glTex[Sub]Image.
2101 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
2102 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
2103 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
2104 fConfigTable[i].fFormats.fSizedInternalFormat :
2105 fConfigTable[i].fFormats.fBaseInternalFormat;
2106 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08002107 fConfigTable[i].fFormats.fSizedInternalFormat :
2108 fConfigTable[i].fFormats.fBaseInternalFormat;
2109 }
2110 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
2111 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
2112 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
2113 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
2114 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08002115 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08002116 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07002117
2118 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
2119 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
2120 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
2121 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08002122 }
2123
2124 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
2125 // as a base format.
2126 // GL_EXT_texture_format_BGRA8888:
2127 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
2128 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
2129 // formats.
halcanary9d524f22016-03-29 09:03:52 -07002130 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08002131 // ES 2.0: the extension makes BGRA an external format but not an internal format.
2132 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
2133 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08002134 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08002135 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
2136 }
2137
bsalomoncdee0092016-01-08 13:20:12 -08002138 // If we don't have texture swizzle support then the shader generator must insert the
2139 // swizzle into shader code.
2140 if (!this->textureSwizzleSupport()) {
2141 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05002142 shaderCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
bsalomoncdee0092016-01-08 13:20:12 -08002143 }
2144 }
2145
bsalomon7f9b2e42016-01-12 13:29:26 -08002146 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
2147 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
2148 // gets written to the single component.
2149 if (this->textureRedSupport()) {
2150 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
2151 GrPixelConfig config = static_cast<GrPixelConfig>(i);
2152 if (GrPixelConfigIsAlphaOnly(config) &&
2153 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
Brian Salomon1edc5b92016-11-29 13:43:46 -05002154 shaderCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
bsalomon7f9b2e42016-01-12 13:29:26 -08002155 }
2156 }
2157 }
2158
Brian Salomonf9f45122016-11-29 11:59:17 -05002159 // We currently only support images on rgba textures formats. We could add additional formats
2160 // if desired. The shader builder would have to be updated to add swizzles where appropriate
2161 // (e.g. where we use GL_RED textures to implement alpha configs).
2162 if (this->shaderCaps()->imageLoadStoreSupport()) {
2163 fConfigTable[kRGBA_8888_sint_GrPixelConfig].fFlags |=
2164 ConfigInfo::kCanUseAsImageStorage_Flag;
2165 // In OpenGL ES a texture may only be used with BindImageTexture if it has been made
2166 // immutable via TexStorage. We create non-integer textures as mutable textures using
2167 // TexImage because we may lazily add MIP levels. Thus, on ES we currently disable image
2168 // storage support for non-integer textures.
2169 if (kGL_GrGLStandard == ctxInfo.standard()) {
2170 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseAsImageStorage_Flag;
2171 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |=
2172 ConfigInfo::kCanUseAsImageStorage_Flag;
2173 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseAsImageStorage_Flag;
2174 }
2175 }
2176
Greg Daniel81e7bf82017-07-19 14:47:42 -04002177 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
2178 if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
Greg Daniel6bd729d2017-07-31 09:38:23 -04002179 if ((kGL_GrGLStandard == ctxInfo.standard() &&
Greg Daniel81e7bf82017-07-19 14:47:42 -04002180 (ctxInfo.version() >= GR_GL_VER(4,2) ||
2181 ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
Greg Daniel6bd729d2017-07-31 09:38:23 -04002182 (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3,0))) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002183 int count;
2184 GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
2185 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
2186 1, &count);
2187 if (count) {
2188 int* temp = new int[count];
2189 GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_SAMPLES, count,
2190 temp);
2191 fConfigTable[i].fColorSampleCounts.setCount(count+1);
2192 // We initialize our supported values with 0 (no msaa) and reverse the order
2193 // returned by GL so that the array is ascending.
2194 fConfigTable[i].fColorSampleCounts[0] = 0;
2195 for (int j = 0; j < count; ++j) {
2196 fConfigTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
2197 }
2198 delete[] temp;
2199 }
2200 } else {
2201 static const int kDefaultSamples[] = {0,1,2,4,8};
2202 int count = SK_ARRAY_COUNT(kDefaultSamples);
2203 for (; count > 0; --count) {
Greg Daniel2bb6ecc2017-07-20 13:11:14 +00002204 if (kDefaultSamples[count-1] <= fMaxColorSampleCount) {
Greg Daniel81e7bf82017-07-19 14:47:42 -04002205 break;
2206 }
2207 }
2208 if (count > 0) {
2209 fConfigTable[i].fColorSampleCounts.append(count, kDefaultSamples);
2210 }
2211 }
2212 }
2213 }
2214
bsalomon30447372015-12-21 09:03:05 -08002215#ifdef SK_DEBUG
2216 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08002217 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08002218 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
Brian Salomon71d9d842016-11-03 13:42:00 -04002219 // Make sure we didn't set renderable and not blittable or renderable with msaa and not
2220 // renderable.
2221 SkASSERT(!((ConfigInfo::kRenderable_Flag) && !(ConfigInfo::kFBOColorAttachment_Flag)));
2222 SkASSERT(!((ConfigInfo::kRenderableWithMSAA_Flag) && !(ConfigInfo::kRenderable_Flag)));
bsalomon76148af2016-01-12 11:13:47 -08002223 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
2224 fConfigTable[i].fFormats.fBaseInternalFormat);
2225 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08002226 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08002227 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
2228 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
2229 fConfigTable[i].fFormats.fExternalFormat[j]);
2230 }
2231 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08002232 }
2233#endif
2234}
2235
Robert Phillipsbf25d432017-04-07 10:08:53 -04002236bool GrGLCaps::initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Eric Karl74480882017-04-03 14:49:05 -07002237 bool* rectsMustMatch, bool* disallowSubrect) const {
2238 // By default, we don't require rects to match.
2239 *rectsMustMatch = false;
2240
2241 // By default, we allow subrects.
2242 *disallowSubrect = false;
2243
Brian Salomon467921e2017-03-06 16:17:12 -05002244 // If the src is a texture, we can implement the blit as a draw assuming the config is
2245 // renderable.
Robert Phillipsbf25d432017-04-07 10:08:53 -04002246 if (src->asTextureProxy() && this->isConfigRenderable(src->config(), false)) {
2247 desc->fOrigin = kBottomLeft_GrSurfaceOrigin;
Brian Salomon467921e2017-03-06 16:17:12 -05002248 desc->fFlags = kRenderTarget_GrSurfaceFlag;
2249 desc->fConfig = src->config();
2250 return true;
2251 }
2252
Robert Phillipsbf25d432017-04-07 10:08:53 -04002253 {
2254 // The only way we could see a non-GR_GL_TEXTURE_2D texture would be if it were
2255 // wrapped. In that case the proxy would already be instantiated.
2256 const GrTexture* srcTexture = src->priv().peekTexture();
2257 const GrGLTexture* glSrcTexture = static_cast<const GrGLTexture*>(srcTexture);
2258 if (glSrcTexture && glSrcTexture->target() != GR_GL_TEXTURE_2D) {
2259 // Not supported for FBO blit or CopyTexSubImage
2260 return false;
2261 }
Brian Salomon467921e2017-03-06 16:17:12 -05002262 }
2263
2264 // We look for opportunities to use CopyTexSubImage, or fbo blit. If neither are
2265 // possible and we return false to fallback to creating a render target dst for render-to-
2266 // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo
2267 // creation. It isn't clear that avoiding temporary fbo creation is actually optimal.
Robert Phillipsbb581ce2017-05-29 15:05:15 -04002268 GrSurfaceOrigin originForBlitFramebuffer = kTopLeft_GrSurfaceOrigin;
Eric Karl74480882017-04-03 14:49:05 -07002269 bool rectsMustMatchForBlitFramebuffer = false;
2270 bool disallowSubrectForBlitFramebuffer = false;
2271 if (src->numColorSamples() &&
2272 (this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
2273 rectsMustMatchForBlitFramebuffer = true;
2274 disallowSubrectForBlitFramebuffer = true;
2275 // Mirroring causes rects to mismatch later, don't allow it.
2276 originForBlitFramebuffer = src->origin();
2277 } else if (src->numColorSamples() && (this->blitFramebufferSupportFlags() &
2278 kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
2279 rectsMustMatchForBlitFramebuffer = true;
2280 // Mirroring causes rects to mismatch later, don't allow it.
2281 originForBlitFramebuffer = src->origin();
2282 } else if (this->blitFramebufferSupportFlags() & kNoScalingOrMirroring_BlitFramebufferFlag) {
Brian Salomon467921e2017-03-06 16:17:12 -05002283 originForBlitFramebuffer = src->origin();
2284 }
2285
2286 // Check for format issues with glCopyTexSubImage2D
2287 if (this->bgraIsInternalFormat() && kBGRA_8888_GrPixelConfig == src->config()) {
2288 // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit
2289 // then we set up for that, otherwise fail.
2290 if (this->canConfigBeFBOColorAttachment(kBGRA_8888_GrPixelConfig)) {
2291 desc->fOrigin = originForBlitFramebuffer;
2292 desc->fConfig = kBGRA_8888_GrPixelConfig;
Eric Karl74480882017-04-03 14:49:05 -07002293 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2294 *disallowSubrect = disallowSubrectForBlitFramebuffer;
Brian Salomon467921e2017-03-06 16:17:12 -05002295 return true;
2296 }
2297 return false;
2298 }
2299
Robert Phillipsbf25d432017-04-07 10:08:53 -04002300 {
Brian Salomon63e79732017-05-15 21:23:13 -04002301 bool srcIsMSAARenderbuffer = GrFSAAType::kUnifiedMSAA == src->fsaaType() &&
2302 this->usesMSAARenderBuffers();
Robert Phillipsbf25d432017-04-07 10:08:53 -04002303 if (srcIsMSAARenderbuffer) {
2304 // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO
2305 // blit or fail.
2306 if (this->canConfigBeFBOColorAttachment(src->config())) {
2307 desc->fOrigin = originForBlitFramebuffer;
2308 desc->fConfig = src->config();
2309 *rectsMustMatch = rectsMustMatchForBlitFramebuffer;
2310 *disallowSubrect = disallowSubrectForBlitFramebuffer;
2311 return true;
2312 }
2313 return false;
Brian Salomon467921e2017-03-06 16:17:12 -05002314 }
Brian Salomon467921e2017-03-06 16:17:12 -05002315 }
2316
2317 // We'll do a CopyTexSubImage. Make the dst a plain old texture.
2318 desc->fConfig = src->config();
2319 desc->fOrigin = src->origin();
2320 desc->fFlags = kNone_GrSurfaceFlags;
2321 return true;
2322}
2323
csmartdaltone0d36292016-07-29 08:14:20 -07002324void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
2325 if (options.fEnableInstancedRendering) {
2326 fInstancedSupport = gr_instanced::GLInstancedRendering::CheckSupport(*this);
2327#ifndef SK_BUILD_FOR_MAC
2328 // OS X doesn't seem to write correctly to floating point textures when using
2329 // glDraw*Indirect, regardless of the underlying GPU.
2330 fAvoidInstancedDrawsToFPTargets = true;
2331#endif
2332 }
Brian Salomon9bada542017-06-12 12:09:30 -04002333 if (options.fUseDrawInsteadOfPartialRenderTargetWrite) {
2334 fUseDrawInsteadOfAllRenderTargetWrites = true;
2335 }
csmartdaltone0d36292016-07-29 08:14:20 -07002336}
Greg Daniel81e7bf82017-07-19 14:47:42 -04002337
2338int GrGLCaps::getSampleCount(int requestedCount, GrPixelConfig config) const {
2339 int count = fConfigTable[config].fColorSampleCounts.count();
2340 if (!count || !this->isConfigRenderable(config, true)) {
2341 return 0;
2342 }
2343
2344 for (int i = 0; i < count; ++i) {
2345 if (fConfigTable[config].fColorSampleCounts[i] >= requestedCount) {
2346 return fConfigTable[config].fColorSampleCounts[i];
2347 }
2348 }
2349 return fConfigTable[config].fColorSampleCounts[count-1];
2350}
2351