blob: 6a34a30771fbb1ad0bf81fe7d56990527b837570 [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
8
9#include "GrGLCaps.h"
joshualittb4384b92014-10-21 12:53:15 -070010
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000012#include "GrGLContext.h"
bsalomon1aa20292016-01-22 08:16:09 -080013#include "GrGLRenderTarget.h"
jvanverthcba99b82015-06-24 06:59:57 -070014#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000015#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000016#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000017
bsalomon682c2692015-05-22 14:01:46 -070018GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
19 const GrGLContextInfo& ctxInfo,
20 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon1aa20292016-01-22 08:16:09 -080021 fStandard = ctxInfo.standard();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000024 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000025 fInvalidateFBType = kNone_InvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000026 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080027 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fMaxFragmentUniformVectors = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fUnpackRowLengthSupport = false;
30 fUnpackFlipYSupport = false;
31 fPackRowLengthSupport = false;
32 fPackFlipYSupport = false;
33 fTextureUsageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000034 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000035 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000036 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070037 fDirectStateAccessSupport = false;
38 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080039 fES2CompatibilitySupport = false;
cdalton06604b92016-02-05 10:09:51 -080040 fDrawIndirectSupport = false;
41 fMultiDrawIndirectSupport = false;
42 fBaseInstanceSupport = false;
csmartdaltonc411f2d2016-06-27 09:29:07 -070043 fCanDrawIndirectToFloat = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000044 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070045 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080046 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080047 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070048 fRGBA8888PixelsOpsAreSlow = false;
49 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080050 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080051 fRGBAToBGRAReadbackConversionsAreSlow = false;
brianosman09563ce2016-06-02 08:59:34 -070052 fDoManualMipmapping = false;
piotaixre4b23142014-10-02 10:57:53 -070053
bsalomon083617b2016-02-12 12:10:14 -080054 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
55
halcanary385fe4d2015-08-26 13:07:48 -070056 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070057
cdalton4cd67132015-06-10 19:23:46 -070058 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059}
60
cdalton4cd67132015-06-10 19:23:46 -070061void GrGLCaps::init(const GrContextOptions& contextOptions,
62 const GrGLContextInfo& ctxInfo,
63 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000064 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000065 GrGLVersion version = ctxInfo.version();
66
bsalomon@google.combcce8922013-03-25 15:38:39 +000067 /**************************************************************************
68 * Caps specific to GrGLCaps
69 **************************************************************************/
70
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000071 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
73 &fMaxFragmentUniformVectors);
74 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000075 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000076 GrGLint max;
77 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
78 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000079 if (version >= GR_GL_VER(3, 2)) {
80 GrGLint profileMask;
81 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
82 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
83 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000084 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000085 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000087 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088 fUnpackRowLengthSupport = true;
89 fUnpackFlipYSupport = false;
90 fPackRowLengthSupport = true;
91 fPackFlipYSupport = false;
92 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000093 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
94 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000096 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
97 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 fPackFlipYSupport =
99 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
100 }
101
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000102 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000103 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
104
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000105 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700106 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
107 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
108 ctxInfo.hasExtension("GL_NV_texture_barrier");
109 } else {
110 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
111 }
112
cdaltoneb79eea2016-02-26 10:39:34 -0800113 if (kGL_GrGLStandard == standard) {
114 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
115 ctxInfo.hasExtension("GL_ARB_texture_multisample");
116 } else {
117 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
118 }
119
halcanary9d524f22016-03-29 09:03:52 -0700120 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
hendrikwa0d5ad72014-12-02 07:30:30 -0800121 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700122 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800123 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000124 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
125 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800126 } else {
127 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
128 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000129 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000130 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000131 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000132 ctxInfo.hasExtension("GL_ARB_imaging");
133
egdaniel9250d242015-05-18 13:04:26 -0700134 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
135 // Thus we are blacklisting this extension for now on Adreno4xx devices.
136 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
137 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
138 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
139 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000140 fDiscardRenderTargetSupport = true;
141 fInvalidateFBType = kInvalidate_InvalidateFBType;
142 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
143 fDiscardRenderTargetSupport = true;
144 fInvalidateFBType = kDiscard_InvalidateFBType;
145 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000146
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000147 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
148 fFullClearIsFree = true;
149 }
150
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000151 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000152 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800153 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
154 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000155 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000156 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
157 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000158 }
159
cdalton626e1ff2015-06-12 13:56:46 -0700160 if (kGL_GrGLStandard == standard) {
161 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
162 } else {
163 fDirectStateAccessSupport = false;
164 }
165
166 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
167 fDebugSupport = true;
168 } else {
169 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
170 }
171
jvanverth3f801cb2014-12-16 09:49:38 -0800172 if (kGL_GrGLStandard == standard) {
173 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
174 }
175 else {
176 fES2CompatibilitySupport = true;
177 }
178
cdalton0edea2c2015-05-21 08:27:44 -0700179 if (kGL_GrGLStandard == standard) {
180 fMultisampleDisableSupport = true;
181 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700182 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700183 }
184
kkinnunend94708e2015-07-30 22:47:04 -0700185 if (kGL_GrGLStandard == standard) {
186 if (version >= GR_GL_VER(3, 0)) {
187 fBindFragDataLocationSupport = true;
188 }
189 } else {
190 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
191 fBindFragDataLocationSupport = true;
192 }
joshualittc1f56b52015-06-22 12:31:31 -0700193 }
194
bsalomonb8909d32016-01-28 07:09:52 -0800195#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700196 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800197#else
198 fBindUniformLocationSupport = false;
199#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700200
kkinnunene06ed252016-02-16 23:15:40 -0800201 if (kGL_GrGLStandard == standard) {
202 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
203 // We also require textureSize() support for rectangle 2D samplers which was added in
204 // GLSL 1.40.
205 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
206 fRectangleTextureSupport = true;
207 }
bsalomone179a912016-01-20 06:18:10 -0800208 }
kkinnunene06ed252016-02-16 23:15:40 -0800209 } else {
210 // Command buffer exposes this in GL ES context for Chromium reasons,
211 // but it should not be used. Also, at the time of writing command buffer
212 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800213 }
214
bsalomoncdee0092016-01-08 13:20:12 -0800215 if (kGL_GrGLStandard == standard) {
216 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
217 fTextureSwizzleSupport = true;
218 }
219 } else {
220 if (version >= GR_GL_VER(3,0)) {
221 fTextureSwizzleSupport = true;
222 }
223 }
224
cblume09bd2c02016-03-01 14:08:28 -0800225 if (kGL_GrGLStandard == standard) {
226 fMipMapLevelAndLodControlSupport = true;
227 } else if (kGLES_GrGLStandard == standard) {
228 if (version >= GR_GL_VER(3,0)) {
229 fMipMapLevelAndLodControlSupport = true;
230 }
231 }
232
bsalomon88c7b982015-07-31 11:20:16 -0700233#ifdef SK_BUILD_FOR_WIN
234 // We're assuming that on Windows Chromium we're using ANGLE.
235 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
236 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700237 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700238 fRGBA8888PixelsOpsAreSlow = isANGLE;
239 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
240 // check DX11 ANGLE.
241 fPartialFBOReadIsSlow = isANGLE;
242#endif
243
ericrkb4ecabd2016-03-11 15:18:20 -0800244 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
245 bool isMAC = false;
246#ifdef SK_BUILD_FOR_MAC
247 isMAC = true;
248#endif
249
250 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
251 // vis-versa.
252 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
253
cdalton4cd67132015-06-10 19:23:46 -0700254 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700255 * GrShaderCaps fields
256 **************************************************************************/
257
egdaniel0a482332015-10-26 08:59:10 -0700258 // This must be called after fCoreProfile is set on the GrGLCaps
259 this->initGLSL(ctxInfo);
260 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
261
egdaniel05ded892015-10-26 07:38:05 -0700262 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
263
264 // For now these two are equivalent but we could have dst read in shader via some other method.
265 // Before setting this, initGLSL() must have been called.
266 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
267
268 // Enable supported shader-related caps
269 if (kGL_GrGLStandard == standard) {
270 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
271 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
272 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
273 glslCaps->fShaderDerivativeSupport = true;
274 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
275 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
276 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800277 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
278 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700279 }
280 else {
281 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
282
283 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
284 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800285
286 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
287 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700288 }
289
ethannicholas22793252016-01-30 09:59:10 -0800290 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
291 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
halcanary9d524f22016-03-29 09:03:52 -0700292 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
ethannicholas22793252016-01-30 09:59:10 -0800293 &glslCaps->fPixelLocalStorageSize);
294 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
295 }
296 else {
297 glslCaps->fPixelLocalStorageSize = 0;
298 glslCaps->fPLSPathRenderingSupport = false;
299 }
300
cdalton9c3f1432016-03-11 10:07:37 -0800301 // Protect ourselves against tracking huge amounts of texture state.
302 static const uint8_t kMaxSaneSamplers = 32;
303 GrGLint maxSamplers;
304 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
305 glslCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
306 if (glslCaps->fGeometryShaderSupport) {
307 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
308 glslCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
309 }
310 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
311 glslCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
312 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
313 glslCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
314
egdaniel05ded892015-10-26 07:38:05 -0700315 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700316 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000317 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700318
cdalton63f6c1f2015-11-06 07:09:43 -0800319 // We need dual source blending and the ability to disable multisample in order to support mixed
320 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800321 if (fMultisampleDisableSupport &&
322 glslCaps->dualSourceBlendingSupport() &&
323 fShaderCaps->pathRenderingSupport()) {
324 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800325 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800326 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800327 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
328 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800329 fDiscardRenderTargetSupport = false;
330 fInvalidateFBType = kNone_InvalidateFBType;
331 }
332 }
333
csmartdalton485a1202016-07-13 10:16:32 -0700334 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
335 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
336 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
337 // limit this decision to specific GPU families rather than basing it on the vendor alone.
338 if (!GR_GL_MUST_USE_VBO &&
339 !fIsCoreProfile &&
340 (kARM_GrGLVendor == ctxInfo.vendor() ||
341 kImagination_GrGLVendor == ctxInfo.vendor() ||
342 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
343 fPreferClientSideDynamicBuffers = true;
344 }
345
egdanieleed519e2016-01-15 11:36:18 -0800346 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700347 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700348 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700349 this->initStencilFormats(ctxInfo);
350
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000351 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000352 // we could also look for GL_ATI_separate_stencil extension or
353 // GL_EXT_stencil_two_side but they use different function signatures
354 // than GL2.0+ (and than each other).
355 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
356 // supported on GL 1.4 and higher or by extension
357 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
358 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
359 } else {
360 // ES 2 has two sided stencil and stencil wrap
361 fTwoSidedStencilSupport = true;
362 fStencilWrapOpsSupport = true;
363 }
364
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000365 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000366 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
367 // extension includes glMapBuffer.
368 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
369 fMapBufferFlags |= kSubset_MapFlag;
370 fMapBufferType = kMapBufferRange_MapBufferType;
371 } else {
372 fMapBufferType = kMapBuffer_MapBufferType;
373 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000374 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000375 // Unextended GLES2 doesn't have any buffer mapping.
376 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800377 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800378 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
379 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800380 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
381 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
382 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000383 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
384 fMapBufferFlags = kCanMap_MapFlag;
385 fMapBufferType = kMapBuffer_MapBufferType;
386 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000387 }
388
jvanverthd7a2c1f2015-12-07 07:36:44 -0800389 if (kGL_GrGLStandard == standard) {
390 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
391 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700392 }
jvanverthd7a2c1f2015-12-07 07:36:44 -0800393 } else {
394 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
395 fTransferBufferType = kPBO_TransferBufferType;
jvanverthc3d706f2016-04-20 10:33:27 -0700396 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
397 fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800398 }
399 }
400
joshualitte5b74c62015-06-01 14:17:47 -0700401 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
402 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700403 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700404 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
405 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
406 // a small subset.
407#if 0
cdalton397536c2016-03-25 12:15:03 -0700408 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700409#else
cdalton397536c2016-03-25 12:15:03 -0700410 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700411#endif
joshualitte5b74c62015-06-01 14:17:47 -0700412 }
413
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000414 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000415 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
416 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
417 fNPOTTextureTileSupport = true;
418 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000419 } else {
420 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000421 // ES3 has no limitations.
422 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
423 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000424 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
425 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
426 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
427 // to alllow arbitrary wrap modes, however.
428 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000429 }
430
bsalomone72bd022015-10-26 07:33:03 -0700431 // Using MIPs on this GPU seems to be a source of trouble.
432 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
433 fMipMapSupport = false;
434 }
435
bsalomon@google.combcce8922013-03-25 15:38:39 +0000436 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
437 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
438 // Our render targets are always created with textures as the color
439 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000440 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000441
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000442 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
443
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000444 // Disable scratch texture reuse on Mali and Adreno devices
445 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
446 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000447
robertphillips1b8e1b52015-06-24 06:54:10 -0700448#if 0
449 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
450 kQualcomm_GrGLVendor != ctxInfo.vendor();
451#endif
452
egdaniel05ded892015-10-26 07:38:05 -0700453 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000454 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800455 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000456 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800457 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000458 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800459 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
460 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
461 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
462 // This is to guard against platforms that may not support as many samples for
463 // glRasterSamples as they do for framebuffers.
464 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
465 }
466 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000467
bsalomon63b21962014-11-05 07:05:34 -0800468 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800469 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800470 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800471 fUseDrawInsteadOfClear = true;
472 }
473
joshualitt83bc2292015-06-18 14:18:02 -0700474 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
475 fUseDrawInsteadOfPartialRenderTargetWrite = true;
476 }
477
bsalomonbabafcc2016-02-16 11:36:47 -0800478 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
479 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
480 fUseDrawInsteadOfPartialRenderTargetWrite = true;
481 fUseDrawInsteadOfAllRenderTargetWrites = true;
482 }
483
robertphillips63926682015-08-20 09:39:02 -0700484#ifdef SK_BUILD_FOR_WIN
485 // On ANGLE deferring flushes can lead to GPU starvation
486 fPreferVRAMUseOverFlushes = !isANGLE;
487#endif
488
bsalomon7dea7b72015-08-19 08:26:51 -0700489 if (kChromium_GrGLDriver == ctxInfo.driver()) {
490 fMustClearUploadedBufferData = true;
491 }
492
bsalomond08ea5f2015-02-20 06:58:13 -0800493 if (kGL_GrGLStandard == standard) {
494 // ARB allows mixed size FBO attachments, EXT does not.
495 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
496 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
497 fOversizedStencilSupport = true;
498 } else {
499 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
500 }
501 } else {
502 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
503 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
504 }
505
joshualitt58001552015-06-26 12:46:36 -0700506 if (kGL_GrGLStandard == standard) {
507 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
508 // instanced arrays, but we could make this more granular if we wanted
509 fSupportsInstancedDraws =
510 version >= GR_GL_VER(3, 2) ||
511 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
512 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
513 } else {
514 fSupportsInstancedDraws =
515 version >= GR_GL_VER(3, 0) ||
516 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
517 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
518 }
519
cdalton06604b92016-02-05 10:09:51 -0800520 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700521 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
522 ctxInfo.hasExtension("GL_ARB_draw_indirect");
523 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
524 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
525 (!fBaseInstanceSupport && // The ARB extension has no base inst.
526 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
cdalton06604b92016-02-05 10:09:51 -0800527 } else {
528 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
529 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
530 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
531 }
532
csmartdaltonc411f2d2016-06-27 09:29:07 -0700533 // OS X doesn't seem to write correctly to floating point textures when using glDraw*Indirect,
534 // regardless of the underlying GPU.
535#ifndef SK_BUILD_FOR_MAC
536 if (fDrawIndirectSupport) {
537 fCanDrawIndirectToFloat = true;
538 }
539#endif
540
jvanverthcba99b82015-06-24 06:59:57 -0700541 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800542
543 if (contextOptions.fUseShaderSwizzling) {
544 fTextureSwizzleSupport = false;
545 }
546
ethannicholas28ef4452016-03-25 09:26:03 -0700547 if (kGL_GrGLStandard == standard) {
ethannicholas6536ae52016-05-02 12:16:49 -0700548 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading")) &&
549 ctxInfo.vendor() != kIntel_GrGLVendor) {
ethannicholas28ef4452016-03-25 09:26:03 -0700550 fSampleShadingSupport = true;
551 }
552 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
553 fSampleShadingSupport = true;
554 }
555
brianosman131ff132016-06-07 14:22:44 -0700556 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
557 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
558 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
559 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
brianosman09563ce2016-06-02 08:59:34 -0700560 if (fMipMapLevelAndLodControlSupport &&
brianosman9a3fbf72016-06-09 13:11:08 -0700561 (contextOptions.fDoManualMipmapping ||
562 (kIntel_GrGLVendor == ctxInfo.vendor()) ||
brianosman131ff132016-06-07 14:22:44 -0700563 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
564 (kATI_GrGLVendor == ctxInfo.vendor()))) {
brianosman09563ce2016-06-02 08:59:34 -0700565 fDoManualMipmapping = true;
566 }
567
bsalomoncdee0092016-01-08 13:20:12 -0800568 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
569 // already been detected.
570 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700571
572 this->applyOptionsOverrides(contextOptions);
573 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000574}
575
egdaniel472d44e2015-10-22 08:20:00 -0700576const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
577 bool isCoreProfile) {
578 switch (generation) {
579 case k110_GrGLSLGeneration:
580 if (kGLES_GrGLStandard == standard) {
581 // ES2s shader language is based on version 1.20 but is version
582 // 1.00 of the ES language.
583 return "#version 100\n";
584 } else {
585 SkASSERT(kGL_GrGLStandard == standard);
586 return "#version 110\n";
587 }
588 case k130_GrGLSLGeneration:
589 SkASSERT(kGL_GrGLStandard == standard);
590 return "#version 130\n";
591 case k140_GrGLSLGeneration:
592 SkASSERT(kGL_GrGLStandard == standard);
593 return "#version 140\n";
594 case k150_GrGLSLGeneration:
595 SkASSERT(kGL_GrGLStandard == standard);
596 if (isCoreProfile) {
597 return "#version 150\n";
598 } else {
599 return "#version 150 compatibility\n";
600 }
601 case k330_GrGLSLGeneration:
602 if (kGLES_GrGLStandard == standard) {
603 return "#version 300 es\n";
604 } else {
605 SkASSERT(kGL_GrGLStandard == standard);
606 if (isCoreProfile) {
607 return "#version 330\n";
608 } else {
609 return "#version 330 compatibility\n";
610 }
611 }
cdalton33ad7012016-02-22 07:55:44 -0800612 case k400_GrGLSLGeneration:
613 SkASSERT(kGL_GrGLStandard == standard);
614 if (isCoreProfile) {
615 return "#version 400\n";
616 } else {
617 return "#version 400 compatibility\n";
618 }
egdaniel472d44e2015-10-22 08:20:00 -0700619 case k310es_GrGLSLGeneration:
620 SkASSERT(kGLES_GrGLStandard == standard);
621 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800622 case k320es_GrGLSLGeneration:
623 SkASSERT(kGLES_GrGLStandard == standard);
624 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700625 }
626 return "<no version>";
627}
628
egdaniel05ded892015-10-26 07:38:05 -0700629void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700630 GrGLStandard standard = ctxInfo.standard();
631 GrGLVersion version = ctxInfo.version();
632
633 /**************************************************************************
634 * Caps specific to GrGLSLCaps
635 **************************************************************************/
636
637 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
638 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700639 if (kGLES_GrGLStandard == standard) {
640 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
641 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
642 glslCaps->fFBFetchSupport = true;
643 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
644 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
645 }
646 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
647 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
648 glslCaps->fFBFetchNeedsCustomOutput = false;
649 glslCaps->fFBFetchSupport = true;
650 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
651 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
652 }
653 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
654 // The arm extension also requires an additional flag which we will set onResetContext
655 glslCaps->fFBFetchNeedsCustomOutput = false;
656 glslCaps->fFBFetchSupport = true;
657 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
658 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
659 }
660 glslCaps->fUsesPrecisionModifiers = true;
661 }
662
663 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
664
cdaltonc08f1962016-02-12 12:14:06 -0800665 if (kGL_GrGLStandard == standard) {
666 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
667 } else {
668 glslCaps->fFlatInterpolationSupport =
669 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
670 }
671
672 if (kGL_GrGLStandard == standard) {
673 glslCaps->fNoPerspectiveInterpolationSupport =
674 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
675 } else {
676 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
677 glslCaps->fNoPerspectiveInterpolationSupport = true;
678 glslCaps->fNoPerspectiveInterpolationExtensionString =
679 "GL_NV_shader_noperspective_interpolation";
680 }
681 }
682
cdalton33ad7012016-02-22 07:55:44 -0800683 if (kGL_GrGLStandard == standard) {
cdalton4a98cdb2016-03-01 12:12:20 -0800684 glslCaps->fMultisampleInterpolationSupport =
685 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
686 } else {
687 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
688 glslCaps->fMultisampleInterpolationSupport = true;
689 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
690 glslCaps->fMultisampleInterpolationSupport = true;
691 glslCaps->fMultisampleInterpolationExtensionString =
692 "GL_OES_shader_multisample_interpolation";
693 }
694 }
695
696 if (kGL_GrGLStandard == standard) {
cdalton33ad7012016-02-22 07:55:44 -0800697 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
698 } else {
699 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
700 glslCaps->fSampleVariablesSupport = true;
701 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
702 glslCaps->fSampleVariablesSupport = true;
703 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
704 }
705 }
706
csmartdaltonf848c9c2016-06-15 12:42:13 -0700707 if (glslCaps->fSampleVariablesSupport &&
708 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage")) {
709 // Pre-361 NVIDIA has a bug with NV_sample_mask_override_coverage.
cdalton33ad7012016-02-22 07:55:44 -0800710 glslCaps->fSampleMaskOverrideCoverageSupport =
csmartdaltonf848c9c2016-06-15 12:42:13 -0700711 kNVIDIA_GrGLDriver != ctxInfo.driver() ||
712 ctxInfo.driverVersion() >= GR_GL_DRIVER_VER(361,00);
cdalton33ad7012016-02-22 07:55:44 -0800713 }
714
egdaniel472d44e2015-10-22 08:20:00 -0700715 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
716 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
717
718 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
719 // function that may require a gradient calculation inside a conditional block may return
720 // undefined results". This appears to be an issue with the 'any' call since even the simple
721 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
722 // from our GrTextureDomain processor.
723 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
724
egdaniel472d44e2015-10-22 08:20:00 -0700725 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
726 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800727
728 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
729 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
730 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800731
732 // Frag Coords Convention support is not part of ES
733 // Known issue on at least some Intel platforms:
734 // http://code.google.com/p/skia/issues/detail?id=946
735 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
736 kGLES_GrGLStandard != standard &&
737 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
738 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
739 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
740 }
741
742 if (kGLES_GrGLStandard == standard) {
743 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
744 }
745
cdalton9c3f1432016-03-11 10:07:37 -0800746 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
747 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
748 glslCaps->fExternalTextureSupport = true;
749 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
750 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
751 // At least one driver has been found that has this extension without the "GL_" prefix.
752 glslCaps->fExternalTextureSupport = true;
753 }
754 }
755
756 if (glslCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800757 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
758 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
759 } else {
760 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
761 }
762 }
763
cdaltonc04ce672016-03-11 14:07:38 -0800764 if (kGL_GrGLStandard == standard) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700765 glslCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800766 } else {
cdaltonf8a6ce82016-04-11 13:02:05 -0700767 glslCaps->fTexelFetchSupport =
768 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
769 }
770
771 if (glslCaps->fTexelFetchSupport) {
772 if (kGL_GrGLStandard == standard) {
csmartdalton1897cfd2016-06-03 08:50:54 -0700773 glslCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
cdaltonf8a6ce82016-04-11 13:02:05 -0700774 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
775 } else {
776 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
777 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
778 glslCaps->fTexelBufferSupport = true;
779 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
780 glslCaps->fTexelBufferSupport = true;
781 glslCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
782 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
783 glslCaps->fTexelBufferSupport = true;
784 glslCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
785 }
cdaltonc04ce672016-03-11 14:07:38 -0800786 }
787 }
788
egdaniel8dcdedc2015-11-11 06:27:20 -0800789 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
790 // the abs first in a separate expression.
791 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
792 glslCaps->fCanUseMinAndAbsTogether = false;
793 }
794
bsalomon7ea33f52015-11-22 14:51:00 -0800795 // 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 -0800796 // thus must us -1.0 * %s.x to work correctly
797 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
798 glslCaps->fMustForceNegatedAtanParamToFloat = true;
799 }
egdaniel472d44e2015-10-22 08:20:00 -0700800}
801
kkinnunencfe62e32015-07-01 02:58:50 -0700802bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700803 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
804
805 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700806 return false;
807 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700808
kkinnunencfe62e32015-07-01 02:58:50 -0700809 if (kGL_GrGLStandard == ctxInfo.standard()) {
810 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
811 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
812 return false;
813 }
814 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700815 if (!hasChromiumPathRendering &&
816 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700817 return false;
818 }
819 }
820 // We only support v1.3+ of GL_NV_path_rendering which allows us to
821 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
822 // additions are detected by checking the existence of the function.
823 // We also use *Then* functions that not all drivers might have. Check
824 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800825 if (!gli->fFunctions.fStencilThenCoverFillPath ||
826 !gli->fFunctions.fStencilThenCoverStrokePath ||
827 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
828 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
829 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700830 return false;
831 }
832 return true;
833}
bsalomon1aa20292016-01-22 08:16:09 -0800834
835bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800836 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800837 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
838 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800839 // If it's not possible to even have a render target of rtConfig then read pixels is
840 // not supported regardless of readConfig.
841 if (!this->isConfigRenderable(rtConfig, false)) {
842 return false;
843 }
bsalomon7928ef62016-01-05 10:26:39 -0800844
bsalomon76148af2016-01-12 11:13:47 -0800845 GrGLenum readFormat;
846 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800847 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800848 return false;
849 }
850
bsalomon1aa20292016-01-22 08:16:09 -0800851 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800852 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
853 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
854 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
855 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
856 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
857 readFormat != GR_GL_BGRA) {
858 return false;
859 }
860 // There is also a set of allowed types, but all the types we use are in the set:
861 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
862 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
863 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
864 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
865 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
866 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
867 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800868 return true;
piotaixre4b23142014-10-02 10:57:53 -0700869 }
bsalomon7928ef62016-01-05 10:26:39 -0800870
bsalomon76148af2016-01-12 11:13:47 -0800871 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800872
bsalomon1aa20292016-01-22 08:16:09 -0800873 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800874 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
875 return true;
876 }
877 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800878 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800879 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
880 return true;
881 }
882 }
883
bsalomon1aa20292016-01-22 08:16:09 -0800884 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800885 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800886 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800887 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800888 if (!bindRenderTarget()) {
889 return false;
890 }
891 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
892 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800893 rpFormat->fFormat = format;
894 rpFormat->fType = type;
895 }
896
bsalomon1aa20292016-01-22 08:16:09 -0800897 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
898 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700899}
900
robertphillips@google.com6177e692013-02-28 20:16:25 +0000901void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000902
903 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000904 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000905 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
906 // ES3 driver bugs on at least one device with a tiled GPU (N10).
907 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
908 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
909 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
910 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800911 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700912 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000913 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000914 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
915 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
916 // chrome's extension is equivalent to the EXT msaa
917 // and fbo_blit extensions.
918 fMSFBOType = kDesktop_EXT_MSFBOType;
919 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
920 fMSFBOType = kES_Apple_MSFBOType;
921 }
bsalomon083617b2016-02-12 12:10:14 -0800922
923 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
924 // is available.
925 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
926 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
927 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
928 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
929 // limitations.
930 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
931 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000932 } else {
egdanieleed519e2016-01-15 11:36:18 -0800933 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700934 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800935 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700936 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000937 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000938 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800939 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000940 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
941 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000942 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800943 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000944 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000945 }
946}
947
cdalton1dd05422015-06-12 09:01:18 -0700948void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
949 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
950
951 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
952 // for now until its own blacklists can be updated.
953 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
954 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700955 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700956 return;
957 }
958
959 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
960 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
961 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
962 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
963 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
964 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
965 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
966 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
967 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
968 return;
969 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
970 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
971 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
972 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
973 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
974 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
975 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
976 // slow on a particular platform.
977 } else {
978 return; // No advanced blend support.
979 }
980
981 SkASSERT(this->advancedBlendEquationSupport());
982
983 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
984 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
985 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
986 (1 << kColorBurn_GrBlendEquation);
987 }
joel.liang9764c402015-07-09 19:46:18 -0700988 if (kARM_GrGLVendor == ctxInfo.vendor()) {
989 // Blacklist color-burn on ARM until the fix is released.
990 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
991 }
cdalton1dd05422015-06-12 09:01:18 -0700992}
993
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000994namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700995const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000996}
997
998void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
999
1000 // Build up list of legal stencil formats (though perhaps not supported on
1001 // the particular gpu/driver) from most preferred to least.
1002
1003 // these consts are in order of most preferred to least preferred
1004 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1005
1006 static const StencilFormat
1007 // internal Format stencil bits total bits packed?
1008 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1009 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1010 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1011 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001012 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001013 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1014
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001015 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001016 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001017 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001018 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1019 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1020
1021 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1022 // require FBO support we can expect these are legal formats and don't
1023 // check. These also all support the unsized GL_STENCIL_INDEX.
1024 fStencilFormats.push_back() = gS8;
1025 fStencilFormats.push_back() = gS16;
1026 if (supportsPackedDS) {
1027 fStencilFormats.push_back() = gD24S8;
1028 }
1029 fStencilFormats.push_back() = gS4;
1030 if (supportsPackedDS) {
1031 fStencilFormats.push_back() = gDS;
1032 }
1033 } else {
1034 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1035 // for other formats.
1036 // ES doesn't support using the unsized format.
1037
1038 fStencilFormats.push_back() = gS8;
1039 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001040 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1041 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001042 fStencilFormats.push_back() = gD24S8;
1043 }
1044 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1045 fStencilFormats.push_back() = gS4;
1046 }
1047 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001048}
1049
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001050SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001051
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001052 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001053
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001054 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001055 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001056 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001057 i,
1058 fStencilFormats[i].fStencilBits,
1059 fStencilFormats[i].fTotalBits);
1060 }
1061
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001062 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001063 "None",
1064 "ARB",
1065 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001066 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001067 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001068 "IMG MS To Texture",
1069 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001070 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001071 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001072 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1073 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1074 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001075 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1076 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1077 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1078 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001079 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001080 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001081
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001082 static const char* kInvalidateFBTypeStr[] = {
1083 "None",
1084 "Discard",
1085 "Invalidate",
1086 };
1087 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1088 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1089 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1090 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001091
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001092 static const char* kMapBufferTypeStr[] = {
1093 "None",
1094 "MapBuffer",
1095 "MapBufferRange",
1096 "Chromium",
1097 };
1098 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1099 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1100 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1101 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1102 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1103
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001104 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001105 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001106 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001107 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001108 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001109 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1110 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1111 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1112 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001113
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001114 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001115 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1116 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001117 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001118 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1119 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton06604b92016-02-05 10:09:51 -08001120 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1121 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1122 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
csmartdaltonc411f2d2016-06-27 09:29:07 -07001123 r.appendf("Can draw indirect to float: %s\n", (fCanDrawIndirectToFloat ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001124 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1125 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001126 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001127 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001128 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
halcanary9d524f22016-03-29 09:03:52 -07001129 r.appendf("BGRA to RGBA readback conversions are slow: %s\n",
ericrkb4ecabd2016-03-11 15:18:20 -08001130 (fRGBAToBGRAReadbackConversionsAreSlow ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001131
1132 r.append("Configs\n-------\n");
1133 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1134 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001135 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1136 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001137 i,
1138 fConfigTable[i].fFlags,
1139 fConfigTable[i].fFormats.fBaseInternalFormat,
1140 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001141 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1142 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001143 fConfigTable[i].fFormats.fExternalType,
1144 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001145 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001146 }
1147
jvanverthe9c0fc62015-04-29 11:18:05 -07001148 return r;
1149}
1150
jvanverthe9c0fc62015-04-29 11:18:05 -07001151static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1152 switch (p) {
1153 case kLow_GrSLPrecision:
1154 return GR_GL_LOW_FLOAT;
1155 case kMedium_GrSLPrecision:
1156 return GR_GL_MEDIUM_FLOAT;
1157 case kHigh_GrSLPrecision:
1158 return GR_GL_HIGH_FLOAT;
1159 }
1160 SkFAIL("Unknown precision.");
1161 return -1;
1162}
1163
1164static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1165 switch (type) {
1166 case kVertex_GrShaderType:
1167 return GR_GL_VERTEX_SHADER;
1168 case kGeometry_GrShaderType:
1169 return GR_GL_GEOMETRY_SHADER;
1170 case kFragment_GrShaderType:
1171 return GR_GL_FRAGMENT_SHADER;
1172 }
1173 SkFAIL("Unknown shader type.");
1174 return -1;
1175}
1176
jvanverthcba99b82015-06-24 06:59:57 -07001177void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
halcanary9d524f22016-03-29 09:03:52 -07001178 const GrGLInterface* intf,
jvanverthcba99b82015-06-24 06:59:57 -07001179 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001180 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1181 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1182 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1183 if (kGeometry_GrShaderType != s) {
1184 GrShaderType shaderType = static_cast<GrShaderType>(s);
1185 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001186 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001187 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001188 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1189 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1190 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1191 GrGLint range[2];
1192 GrGLint bits;
1193 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1194 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001195 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1196 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1197 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001198 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001199 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001200 }
jvanverthcba99b82015-06-24 06:59:57 -07001201 else if (!glslCaps->fShaderPrecisionVaries) {
halcanary9d524f22016-03-29 09:03:52 -07001202 glslCaps->fShaderPrecisionVaries =
jvanverthcba99b82015-06-24 06:59:57 -07001203 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001204 }
1205 }
1206 }
1207 }
1208 }
1209 }
1210 else {
1211 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001212 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001213 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1214 if (kGeometry_GrShaderType != s) {
1215 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001216 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1217 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1218 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001219 }
1220 }
1221 }
1222 }
1223 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1224 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1225 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1226 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001227 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001228 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
halcanary9d524f22016-03-29 09:03:52 -07001229 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
jvanverthcba99b82015-06-24 06:59:57 -07001230 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001231 }
1232 }
cdaltona6b92ad2016-04-11 12:03:08 -07001233 glslCaps->initSamplerPrecisionTable();
jvanverthe9c0fc62015-04-29 11:18:05 -07001234}
1235
bsalomon41e4384e2016-01-08 09:12:44 -08001236bool GrGLCaps::bgraIsInternalFormat() const {
1237 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1238}
1239
bsalomon76148af2016-01-12 11:13:47 -08001240bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1241 GrGLenum* internalFormat, GrGLenum* externalFormat,
1242 GrGLenum* externalType) const {
1243 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1244 externalFormat, externalType)) {
1245 return false;
1246 }
1247 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1248 return true;
1249}
1250
1251bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1252 GrGLenum* internalFormat) const {
1253 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1254 return false;
1255 }
1256 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1257 return true;
1258}
1259
1260bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1261 GrGLenum* externalFormat, GrGLenum* externalType) const {
1262 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1263 externalFormat, externalType)) {
1264 return false;
1265 }
1266 return true;
1267}
1268
1269bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1270 if (GrPixelConfigIsCompressed(config)) {
1271 return false;
1272 }
1273 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1274 return true;
1275}
1276
1277bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1278 ExternalFormatUsage usage, GrGLenum* externalFormat,
1279 GrGLenum* externalType) const {
1280 SkASSERT(externalFormat && externalType);
1281 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1282 return false;
1283 }
1284
1285 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1286 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1287
1288 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1289 // made to work in many cases using glPixelStore and what not but is not needed currently.
1290 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1291 return false;
1292 }
1293
1294 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1295 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1296
bsalomone9573312016-01-25 14:33:25 -08001297 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1298 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1299 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1300 // texture, not the red component.
1301 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1302 if (this->textureRedSupport()) {
1303 SkASSERT(GR_GL_RED == *externalFormat);
1304 *externalFormat = GR_GL_ALPHA;
1305 }
1306 }
1307
bsalomon76148af2016-01-12 11:13:47 -08001308 return true;
1309}
1310
bsalomoncdee0092016-01-08 13:20:12 -08001311void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1312 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001313 /*
1314 Comments on renderability of configs on various GL versions.
1315 OpenGL < 3.0:
1316 no built in support for render targets.
1317 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1318 format RGB, RGBA and NV float formats we don't use.
1319 This is the following:
1320 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1321 RGB10_A2, RGBA12,RGBA16
1322 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1323 since they aren't required by later standards and the driver can simply return
1324 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1325 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1326 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1327 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1328 This adds a lot of additional renderable sized formats, including ALPHA8.
1329 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1330 16F, 32I, 32UI, and 32F variants).
1331 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1332
1333 For both the above extensions we limit ourselves to those that are also required by
1334 OpenGL 3.0.
1335
1336 OpenGL 3.0:
1337 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1338 but are not required to be supported as renderable textures/renderbuffer.
1339 Required renderable color formats:
1340 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1341 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1342 RGB10_A2.
1343 - R11F_G11F_B10F.
1344 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1345 and RG8UI.
1346 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1347 - ALPHA8
1348
1349 OpenGL 3.1, 3.2, 3.3
1350 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1351 OpengGL 3.3, 4.0, 4.1
1352 Adds RGB10_A2UI.
1353 OpengGL 4.2
1354 Adds
1355 - RGB5_A1, RGBA4
1356 - RGB565
1357 OpenGL 4.4
1358 Does away with the separate list and adds a column to the sized internal color format
1359 table. However, no new formats become required color renderable.
1360
1361 ES 2.0
1362 color renderable: RGBA4, RGB5_A1, RGB565
1363 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1364 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1365 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1366 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1367 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1368 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1369
1370 ES 3.0
1371 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1372 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1373 RGB5_A1.
1374 - RGB8 and RGB565.
1375 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1376 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1377 ES 3.1
1378 Adds RGB10_A2, RGB10_A2UI,
1379 ES 3.2
1380 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1381 */
1382 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1383 if (kNone_MSFBOType != fMSFBOType) {
1384 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1385 }
1386
1387 GrGLStandard standard = ctxInfo.standard();
1388 GrGLVersion version = ctxInfo.version();
1389
cblume790d5132016-02-29 11:13:29 -08001390 bool texStorageSupported = false;
1391 if (kGL_GrGLStandard == standard) {
1392 // The EXT version can apply to either GL or GLES.
1393 texStorageSupported = version >= GR_GL_VER(4,2) ||
1394 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1395 ctxInfo.hasExtension("GL_EXT_texture_storage");
1396 } else {
1397 // Qualcomm Adreno drivers appear to have issues with texture storage.
1398 texStorageSupported = (version >= GR_GL_VER(3,0) &&
1399 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
1400 ctxInfo.hasExtension("GL_EXT_texture_storage");
1401 }
1402
1403 // TODO: remove after command buffer supports full ES 3.0
1404 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1405 kChromium_GrGLDriver == ctxInfo.driver()) {
1406 texStorageSupported = false;
1407 }
1408
cdalton74b8d322016-04-11 14:47:28 -07001409 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1410
bsalomon30447372015-12-21 09:03:05 -08001411 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1412 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001413 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001414 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001415 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001416 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001417
1418 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1419 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001420 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1421 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001422 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001423 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001424 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1425 if (kGL_GrGLStandard == standard) {
1426 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1427 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001428 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001429 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1430 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1431 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1432 }
egdaniel4999df82016-01-07 17:06:04 -08001433 }
cblume790d5132016-02-29 11:13:29 -08001434 if (texStorageSupported) {
1435 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1436 }
cdalton74b8d322016-04-11 14:47:28 -07001437 if (texelBufferSupport) {
1438 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1439 }
bsalomoncdee0092016-01-08 13:20:12 -08001440 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001441
bsalomon76148af2016-01-12 11:13:47 -08001442 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1443 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001444 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001445 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001446 if (kGL_GrGLStandard == standard) {
1447 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1448 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1449 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1450 // Since the internal format is RGBA8, it is also renderable.
1451 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1452 allRenderFlags;
1453 }
1454 } else {
1455 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1456 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1457 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1458 // The APPLE extension doesn't make this renderable.
1459 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1460 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1461 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1462 // Though, that seems to not be the case if the texture storage extension is
1463 // present. The specs don't exactly make that clear.
1464 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1465 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1466 }
1467 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1468 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1469 ConfigInfo::kRenderable_Flag;
1470 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001471 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001472 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1473 ConfigInfo::kRenderableWithMSAA_Flag;
1474 }
1475 }
1476 }
cblume790d5132016-02-29 11:13:29 -08001477 if (texStorageSupported) {
1478 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1479 }
bsalomoncdee0092016-01-08 13:20:12 -08001480 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001481
brianosmana6359362016-03-21 06:55:37 -07001482 // We only enable srgb support if both textures and FBOs support srgb,
brianosman35b784d2016-05-05 11:52:53 -07001483 // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
bsalomon41e4384e2016-01-08 09:12:44 -08001484 if (kGL_GrGLStandard == standard) {
1485 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001486 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001487 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1488 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1489 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001490 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001491 }
1492 }
1493 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001494 if (fSRGBSupport) {
1495 fSRGBWriteControl = true;
1496 }
bsalomon41e4384e2016-01-08 09:12:44 -08001497 } else {
1498 // See https://bug.skia.org/4148 for PowerVR issue.
brianosmana6359362016-03-21 06:55:37 -07001499 fSRGBSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
bsalomon41e4384e2016-01-08 09:12:44 -08001500 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1501 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1502 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001503 // See https://bug.skia.org/5329 for Adreno4xx issue.
1504 fSRGBWriteControl = kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
1505 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001506 }
brianosmana6359362016-03-21 06:55:37 -07001507 if (!ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode")) {
1508 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode:
1509 fSRGBSupport = false;
1510 }
bsalomon30447372015-12-21 09:03:05 -08001511 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1512 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1513 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1514 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001515 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1516 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001517 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001518 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001519 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001520 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1521 allRenderFlags;
1522 }
cblume790d5132016-02-29 11:13:29 -08001523 if (texStorageSupported) {
1524 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1525 }
bsalomoncdee0092016-01-08 13:20:12 -08001526 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001527
brianosmana6359362016-03-21 06:55:37 -07001528 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1529 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1530 // is in this format, for example).
1531 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1532 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1533 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1534 // external format is GL_BGRA.
1535 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1536 GR_GL_BGRA;
1537 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1538 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1539 if (fSRGBSupport) {
1540 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1541 allRenderFlags;
1542 }
1543 if (texStorageSupported) {
1544 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1545 }
1546 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1547
bsalomon30447372015-12-21 09:03:05 -08001548 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1549 if (this->ES2CompatibilitySupport()) {
1550 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1551 } else {
1552 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1553 }
bsalomon76148af2016-01-12 11:13:47 -08001554 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1555 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001556 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001557 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001558 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1559 if (kGL_GrGLStandard == standard) {
1560 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1561 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1562 }
1563 } else {
1564 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1565 }
cblume790d5132016-02-29 11:13:29 -08001566 // 565 is not a sized internal format on desktop GL. So on desktop with
1567 // 565 we always use an unsized internal format to let the system pick
1568 // the best sized format to convert the 565 data to. Since TexStorage
1569 // only allows sized internal formats we disallow it.
1570 //
1571 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1572 // update.
1573 if (texStorageSupported && kGL_GrGLStandard != standard) {
1574 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1575 }
bsalomoncdee0092016-01-08 13:20:12 -08001576 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001577
1578 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1579 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001580 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1581 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001582 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001583 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001584 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1585 if (kGL_GrGLStandard == standard) {
1586 if (version >= GR_GL_VER(4, 2)) {
1587 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1588 }
1589 } else {
1590 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1591 }
cblume790d5132016-02-29 11:13:29 -08001592 if (texStorageSupported) {
1593 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1594 }
bsalomoncdee0092016-01-08 13:20:12 -08001595 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001596
1597 if (this->textureRedSupport()) {
1598 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1599 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001600 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1601 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001602 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001603 if (texelBufferSupport) {
1604 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1605 }
bsalomon30447372015-12-21 09:03:05 -08001606 } else {
1607 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1608 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001609 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1610 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001611 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001612 }
1613 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001614 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001615 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
bsalomon40170072016-05-05 14:40:03 -07001616 if (this->textureRedSupport() ||
1617 (kDesktop_ARB_MSFBOType == this->msFBOType() &&
1618 ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001619 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
bsalomon40170072016-05-05 14:40:03 -07001620 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
bsalomon41e4384e2016-01-08 09:12:44 -08001621 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1622 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1623 }
cblume790d5132016-02-29 11:13:29 -08001624 if (texStorageSupported) {
1625 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1626 }
bsalomon41e4384e2016-01-08 09:12:44 -08001627
1628 // Check for [half] floating point texture support
1629 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1630 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1631 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1632 bool hasFPTextures = false;
1633 bool hasHalfFPTextures = false;
1634 // for now we don't support floating point MSAA on ES
1635 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1636 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1637
1638 if (kGL_GrGLStandard == standard) {
1639 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1640 hasFPTextures = true;
1641 hasHalfFPTextures = true;
1642 }
1643 } else {
1644 if (version >= GR_GL_VER(3, 1)) {
1645 hasFPTextures = true;
1646 hasHalfFPTextures = true;
1647 } else {
1648 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1649 ctxInfo.hasExtension("GL_OES_texture_float")) {
1650 hasFPTextures = true;
1651 }
1652 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1653 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1654 hasHalfFPTextures = true;
1655 }
1656 }
1657 }
bsalomon30447372015-12-21 09:03:05 -08001658
1659 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1660 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001661 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1662 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001663 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001664 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001665 if (hasFPTextures) {
1666 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1667 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1668 // many precision issues and no clients actually want this yet.
1669 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1670 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1671 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1672 }
1673 }
cblume790d5132016-02-29 11:13:29 -08001674 if (texStorageSupported) {
1675 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1676 }
cdalton74b8d322016-04-11 14:47:28 -07001677 if (texelBufferSupport) {
1678 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1679 }
bsalomoncdee0092016-01-08 13:20:12 -08001680 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001681
1682 if (this->textureRedSupport()) {
1683 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1684 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001685 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1686 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001687 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001688 if (texelBufferSupport) {
1689 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |=
1690 ConfigInfo::kCanUseWithTexelBuffer_Flag;
1691 }
bsalomon30447372015-12-21 09:03:05 -08001692 } else {
1693 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1694 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001695 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1696 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001697 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001698 }
1699 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1700 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1701 } else {
1702 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1703 }
bsalomon7928ef62016-01-05 10:26:39 -08001704 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001705 if (hasHalfFPTextures) {
1706 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1707 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1708 // GL_RED internal format.
1709 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1710 (this->textureRedSupport() &&
1711 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1712 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1713 }
1714 }
cblume790d5132016-02-29 11:13:29 -08001715 if (texStorageSupported) {
1716 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1717 }
bsalomon30447372015-12-21 09:03:05 -08001718
1719 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1720 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001721 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1722 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001723 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1724 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1725 } else {
1726 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1727 }
bsalomon7928ef62016-01-05 10:26:39 -08001728 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001729 if (hasHalfFPTextures) {
1730 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1731 // ES requires 3.2 or EXT_color_buffer_half_float.
1732 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1733 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1734 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1735 }
1736 }
cblume790d5132016-02-29 11:13:29 -08001737 if (texStorageSupported) {
1738 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1739 }
cdalton74b8d322016-04-11 14:47:28 -07001740 if (texelBufferSupport) {
1741 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1742 }
bsalomoncdee0092016-01-08 13:20:12 -08001743 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001744
1745 // Compressed texture support
1746
1747 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1748 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1749
1750 // TODO: Fix command buffer bindings and remove this.
1751 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001752
1753 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001754 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001755
1756 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1757 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001758 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001759 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001760 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001761 // Disable this for now, while we investigate https://bug.skia.org/4333
1762 if (false) {
1763 // Check for 8-bit palette..
1764 GrGLint numFormats;
1765 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1766 if (numFormats) {
1767 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1768 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1769 for (int i = 0; i < numFormats; ++i) {
1770 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1771 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1772 break;
1773 }
1774 }
1775 }
1776 }
bsalomoncdee0092016-01-08 13:20:12 -08001777 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001778
bsalomon41e4384e2016-01-08 09:12:44 -08001779 // May change the internal format based on extensions.
1780 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1781 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1782 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1783 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1784 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1785 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1786 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1787 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1788 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1789 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1790 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1791 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1792 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1793 GR_GL_COMPRESSED_RED_RGTC1;
1794 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1795 GR_GL_COMPRESSED_RED_RGTC1;
1796 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1797 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1798 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1799 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1800 GR_GL_COMPRESSED_3DC_X;
1801
bsalomon30447372015-12-21 09:03:05 -08001802 }
bsalomon76148af2016-01-12 11:13:47 -08001803 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001804 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001805 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001806 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001807
1808 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1809 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001810 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001811 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001812 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001813 if (kGL_GrGLStandard == standard) {
1814 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1815 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1816 }
1817 } else {
1818 if (version >= GR_GL_VER(3, 0) ||
1819 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1820 // ETC2 is a superset of ETC1, so we can just check for that, too.
1821 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1822 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1823 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1824 }
1825 }
bsalomoncdee0092016-01-08 13:20:12 -08001826 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001827
1828 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1829 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001830 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001831 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001832 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001833 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1834 // decompressing the textures in the driver, and is generally slower.
1835 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1836 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1837 }
bsalomoncdee0092016-01-08 13:20:12 -08001838 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001839
1840 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1841 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1842 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1843 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001844 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1845 0;
bsalomon30447372015-12-21 09:03:05 -08001846 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001847 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001848 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1849 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1850 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1851 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1852 }
bsalomoncdee0092016-01-08 13:20:12 -08001853 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001854
1855 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1856
1857 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001858 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1859 ctxInfo.version() >= GR_GL_VER(3,0));
1860 // All ES versions (thus far) require sized internal formats for render buffers.
1861 // TODO: Always use sized internal format?
1862 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1863
bsalomon30447372015-12-21 09:03:05 -08001864 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001865 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1866 // param to glTex[Sub]Image.
1867 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1868 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1869 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1870 fConfigTable[i].fFormats.fSizedInternalFormat :
1871 fConfigTable[i].fFormats.fBaseInternalFormat;
1872 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001873 fConfigTable[i].fFormats.fSizedInternalFormat :
1874 fConfigTable[i].fFormats.fBaseInternalFormat;
1875 }
1876 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1877 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1878 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1879 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1880 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001881 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001882 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001883
1884 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1885 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1886 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1887 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001888 }
1889
1890 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1891 // as a base format.
1892 // GL_EXT_texture_format_BGRA8888:
1893 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1894 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1895 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001896 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001897 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1898 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1899 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001900 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001901 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1902 }
1903
bsalomoncdee0092016-01-08 13:20:12 -08001904 // If we don't have texture swizzle support then the shader generator must insert the
1905 // swizzle into shader code.
1906 if (!this->textureSwizzleSupport()) {
1907 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1908 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1909 }
1910 }
1911
bsalomon7f9b2e42016-01-12 13:29:26 -08001912 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1913 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1914 // gets written to the single component.
1915 if (this->textureRedSupport()) {
1916 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1917 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1918 if (GrPixelConfigIsAlphaOnly(config) &&
1919 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1920 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1921 }
1922 }
1923 }
1924
bsalomon30447372015-12-21 09:03:05 -08001925#ifdef SK_DEBUG
1926 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001927 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001928 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001929 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1930 fConfigTable[i].fFormats.fBaseInternalFormat);
1931 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001932 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001933 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1934 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1935 fConfigTable[i].fFormats.fExternalFormat[j]);
1936 }
1937 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001938 }
1939#endif
1940}
1941
egdanielb7e7d572015-11-04 04:23:53 -08001942void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}