blob: 260521187a657e7da93a66aa93d25b707842f1ef [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;
cdaltond4727922015-11-10 12:49:06 -080040 fMultisampleDisableSupport = false;
cdalton06604b92016-02-05 10:09:51 -080041 fDrawIndirectSupport = false;
42 fMultiDrawIndirectSupport = false;
43 fBaseInstanceSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000044 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080047 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080048 fTextureSwizzleSupport = false;
bsalomon88c7b982015-07-31 11:20:16 -070049 fRGBA8888PixelsOpsAreSlow = false;
50 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080051 fMipMapLevelAndLodControlSupport = false;
ericrkb4ecabd2016-03-11 15:18:20 -080052 fRGBAToBGRAReadbackConversionsAreSlow = false;
brianosman09563ce2016-06-02 08:59:34 -070053 fDoManualMipmapping = false;
piotaixre4b23142014-10-02 10:57:53 -070054
bsalomon083617b2016-02-12 12:10:14 -080055 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
56
halcanary385fe4d2015-08-26 13:07:48 -070057 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070058
cdalton4cd67132015-06-10 19:23:46 -070059 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060}
61
cdalton4cd67132015-06-10 19:23:46 -070062void GrGLCaps::init(const GrContextOptions& contextOptions,
63 const GrGLContextInfo& ctxInfo,
64 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000065 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000066 GrGLVersion version = ctxInfo.version();
67
bsalomon@google.combcce8922013-03-25 15:38:39 +000068 /**************************************************************************
69 * Caps specific to GrGLCaps
70 **************************************************************************/
71
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000072 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
74 &fMaxFragmentUniformVectors);
75 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000076 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000077 GrGLint max;
78 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
79 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000080 if (version >= GR_GL_VER(3, 2)) {
81 GrGLint profileMask;
82 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
83 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
84 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000085 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000086 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000088 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089 fUnpackRowLengthSupport = true;
90 fUnpackFlipYSupport = false;
91 fPackRowLengthSupport = true;
92 fPackFlipYSupport = false;
93 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000094 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
95 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000097 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
98 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099 fPackFlipYSupport =
100 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
101 }
102
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000103 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
105
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000106 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700107 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
108 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
109 ctxInfo.hasExtension("GL_NV_texture_barrier");
110 } else {
111 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
112 }
113
cdaltoneb79eea2016-02-26 10:39:34 -0800114 if (kGL_GrGLStandard == standard) {
115 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
116 ctxInfo.hasExtension("GL_ARB_texture_multisample");
117 } else {
118 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
119 }
120
halcanary9d524f22016-03-29 09:03:52 -0700121 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
hendrikwa0d5ad72014-12-02 07:30:30 -0800122 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700123 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800124 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000125 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
126 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800127 } else {
128 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
129 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000130 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000131 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000132 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000133 ctxInfo.hasExtension("GL_ARB_imaging");
134
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000135 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
136 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
137 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
138 // limit this decision to specific GPU families rather than basing it on the vendor alone.
139 if (!GR_GL_MUST_USE_VBO &&
cdaltone2e71c22016-04-07 18:13:29 -0700140 !fIsCoreProfile &&
bsalomoned82c4e2014-09-02 07:54:47 -0700141 (kARM_GrGLVendor == ctxInfo.vendor() ||
142 kImagination_GrGLVendor == ctxInfo.vendor() ||
143 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000144 fUseNonVBOVertexAndIndexDynamicData = true;
145 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000146
egdaniel9250d242015-05-18 13:04:26 -0700147 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
148 // Thus we are blacklisting this extension for now on Adreno4xx devices.
149 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
150 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
151 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
152 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000153 fDiscardRenderTargetSupport = true;
154 fInvalidateFBType = kInvalidate_InvalidateFBType;
155 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
156 fDiscardRenderTargetSupport = true;
157 fInvalidateFBType = kDiscard_InvalidateFBType;
158 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000159
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000160 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
161 fFullClearIsFree = true;
162 }
163
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000164 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000165 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800166 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
167 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000168 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000169 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
170 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000171 }
172
cdalton626e1ff2015-06-12 13:56:46 -0700173 if (kGL_GrGLStandard == standard) {
174 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
175 } else {
176 fDirectStateAccessSupport = false;
177 }
178
179 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
180 fDebugSupport = true;
181 } else {
182 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
183 }
184
jvanverth3f801cb2014-12-16 09:49:38 -0800185 if (kGL_GrGLStandard == standard) {
186 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
187 }
188 else {
189 fES2CompatibilitySupport = true;
190 }
191
cdalton0edea2c2015-05-21 08:27:44 -0700192 if (kGL_GrGLStandard == standard) {
193 fMultisampleDisableSupport = true;
194 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700195 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700196 }
197
kkinnunend94708e2015-07-30 22:47:04 -0700198 if (kGL_GrGLStandard == standard) {
199 if (version >= GR_GL_VER(3, 0)) {
200 fBindFragDataLocationSupport = true;
201 }
202 } else {
203 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
204 fBindFragDataLocationSupport = true;
205 }
joshualittc1f56b52015-06-22 12:31:31 -0700206 }
207
bsalomonb8909d32016-01-28 07:09:52 -0800208#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700209 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800210#else
211 fBindUniformLocationSupport = false;
212#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700213
kkinnunene06ed252016-02-16 23:15:40 -0800214 if (kGL_GrGLStandard == standard) {
215 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
216 // We also require textureSize() support for rectangle 2D samplers which was added in
217 // GLSL 1.40.
218 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
219 fRectangleTextureSupport = true;
220 }
bsalomone179a912016-01-20 06:18:10 -0800221 }
kkinnunene06ed252016-02-16 23:15:40 -0800222 } else {
223 // Command buffer exposes this in GL ES context for Chromium reasons,
224 // but it should not be used. Also, at the time of writing command buffer
225 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800226 }
227
bsalomoncdee0092016-01-08 13:20:12 -0800228 if (kGL_GrGLStandard == standard) {
229 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
230 fTextureSwizzleSupport = true;
231 }
232 } else {
233 if (version >= GR_GL_VER(3,0)) {
234 fTextureSwizzleSupport = true;
235 }
236 }
237
cblume09bd2c02016-03-01 14:08:28 -0800238 if (kGL_GrGLStandard == standard) {
239 fMipMapLevelAndLodControlSupport = true;
240 } else if (kGLES_GrGLStandard == standard) {
241 if (version >= GR_GL_VER(3,0)) {
242 fMipMapLevelAndLodControlSupport = true;
243 }
244 }
245
bsalomon88c7b982015-07-31 11:20:16 -0700246#ifdef SK_BUILD_FOR_WIN
247 // We're assuming that on Windows Chromium we're using ANGLE.
248 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
249 kChromium_GrGLDriver == ctxInfo.driver();
halcanary9d524f22016-03-29 09:03:52 -0700250 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
bsalomon88c7b982015-07-31 11:20:16 -0700251 fRGBA8888PixelsOpsAreSlow = isANGLE;
252 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
253 // check DX11 ANGLE.
254 fPartialFBOReadIsSlow = isANGLE;
255#endif
256
ericrkb4ecabd2016-03-11 15:18:20 -0800257 bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
258 bool isMAC = false;
259#ifdef SK_BUILD_FOR_MAC
260 isMAC = true;
261#endif
262
263 // Both mesa and mac have reduced performance if reading back an RGBA framebuffer as BGRA or
264 // vis-versa.
265 fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
266
cdalton4cd67132015-06-10 19:23:46 -0700267 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700268 * GrShaderCaps fields
269 **************************************************************************/
270
egdaniel0a482332015-10-26 08:59:10 -0700271 // This must be called after fCoreProfile is set on the GrGLCaps
272 this->initGLSL(ctxInfo);
273 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
274
egdaniel05ded892015-10-26 07:38:05 -0700275 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
276
277 // For now these two are equivalent but we could have dst read in shader via some other method.
278 // Before setting this, initGLSL() must have been called.
279 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
280
281 // Enable supported shader-related caps
282 if (kGL_GrGLStandard == standard) {
283 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
284 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
285 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
286 glslCaps->fShaderDerivativeSupport = true;
287 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
288 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
289 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800290 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
291 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700292 }
293 else {
294 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
295
296 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
297 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800298
299 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
300 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700301 }
302
ethannicholas22793252016-01-30 09:59:10 -0800303 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
304 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
halcanary9d524f22016-03-29 09:03:52 -0700305 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
ethannicholas22793252016-01-30 09:59:10 -0800306 &glslCaps->fPixelLocalStorageSize);
307 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
308 }
309 else {
310 glslCaps->fPixelLocalStorageSize = 0;
311 glslCaps->fPLSPathRenderingSupport = false;
312 }
313
cdalton9c3f1432016-03-11 10:07:37 -0800314 // Protect ourselves against tracking huge amounts of texture state.
315 static const uint8_t kMaxSaneSamplers = 32;
316 GrGLint maxSamplers;
317 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxSamplers);
318 glslCaps->fMaxVertexSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
319 if (glslCaps->fGeometryShaderSupport) {
320 GR_GL_GetIntegerv(gli, GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxSamplers);
321 glslCaps->fMaxGeometrySamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
322 }
323 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
324 glslCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
325 GR_GL_GetIntegerv(gli, GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxSamplers);
326 glslCaps->fMaxCombinedSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
327
egdaniel05ded892015-10-26 07:38:05 -0700328 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700329 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000330 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700331
cdalton63f6c1f2015-11-06 07:09:43 -0800332 // We need dual source blending and the ability to disable multisample in order to support mixed
333 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800334 if (fMultisampleDisableSupport &&
335 glslCaps->dualSourceBlendingSupport() &&
336 fShaderCaps->pathRenderingSupport()) {
337 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800338 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800339 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800340 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
341 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800342 fDiscardRenderTargetSupport = false;
343 fInvalidateFBType = kNone_InvalidateFBType;
344 }
345 }
346
egdanieleed519e2016-01-15 11:36:18 -0800347 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700348 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700349 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700350 this->initStencilFormats(ctxInfo);
351
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000352 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000353 // we could also look for GL_ATI_separate_stencil extension or
354 // GL_EXT_stencil_two_side but they use different function signatures
355 // than GL2.0+ (and than each other).
356 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
357 // supported on GL 1.4 and higher or by extension
358 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
359 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
360 } else {
361 // ES 2 has two sided stencil and stencil wrap
362 fTwoSidedStencilSupport = true;
363 fStencilWrapOpsSupport = true;
364 }
365
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000366 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000367 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
368 // extension includes glMapBuffer.
369 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
370 fMapBufferFlags |= kSubset_MapFlag;
371 fMapBufferType = kMapBufferRange_MapBufferType;
372 } else {
373 fMapBufferType = kMapBuffer_MapBufferType;
374 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000375 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000376 // Unextended GLES2 doesn't have any buffer mapping.
377 fMapBufferFlags = kNone_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800378 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
kkinnunen45c2c812016-02-25 02:03:43 -0800379 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
380 fMapBufferType = kChromium_MapBufferType;
kkinnunenf655e932016-03-03 07:39:48 -0800381 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
382 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
383 fMapBufferType = kMapBufferRange_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000384 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
385 fMapBufferFlags = kCanMap_MapFlag;
386 fMapBufferType = kMapBuffer_MapBufferType;
387 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000388 }
389
jvanverthd7a2c1f2015-12-07 07:36:44 -0800390 if (kGL_GrGLStandard == standard) {
391 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
392 fTransferBufferType = kPBO_TransferBufferType;
halcanary9d524f22016-03-29 09:03:52 -0700393 }
jvanverthd7a2c1f2015-12-07 07:36:44 -0800394 } else {
395 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
396 fTransferBufferType = kPBO_TransferBufferType;
jvanverthc3d706f2016-04-20 10:33:27 -0700397 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
398 fTransferBufferType = kChromium_TransferBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -0800399 }
400 }
401
joshualitte5b74c62015-06-01 14:17:47 -0700402 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
403 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
cdalton397536c2016-03-25 12:15:03 -0700404 if (fBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700405 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
406 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
407 // a small subset.
408#if 0
cdalton397536c2016-03-25 12:15:03 -0700409 fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700410#else
cdalton397536c2016-03-25 12:15:03 -0700411 fBufferMapThreshold = SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700412#endif
joshualitte5b74c62015-06-01 14:17:47 -0700413 }
414
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000415 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000416 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
417 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
418 fNPOTTextureTileSupport = true;
419 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000420 } else {
421 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000422 // ES3 has no limitations.
423 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
424 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000425 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
426 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
427 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
428 // to alllow arbitrary wrap modes, however.
429 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000430 }
431
bsalomone72bd022015-10-26 07:33:03 -0700432 // Using MIPs on this GPU seems to be a source of trouble.
433 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
434 fMipMapSupport = false;
435 }
436
bsalomon@google.combcce8922013-03-25 15:38:39 +0000437 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
438 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
439 // Our render targets are always created with textures as the color
440 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000441 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000442
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000443 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
444
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000445 // Disable scratch texture reuse on Mali and Adreno devices
446 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
447 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000448
robertphillips1b8e1b52015-06-24 06:54:10 -0700449#if 0
450 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
451 kQualcomm_GrGLVendor != ctxInfo.vendor();
452#endif
453
egdaniel05ded892015-10-26 07:38:05 -0700454 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000455 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800456 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000457 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800458 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000459 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800460 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
461 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
462 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
463 // This is to guard against platforms that may not support as many samples for
464 // glRasterSamples as they do for framebuffers.
465 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
466 }
467 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000468
bsalomon63b21962014-11-05 07:05:34 -0800469 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800470 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800471 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800472 fUseDrawInsteadOfClear = true;
473 }
474
joshualitt83bc2292015-06-18 14:18:02 -0700475 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
476 fUseDrawInsteadOfPartialRenderTargetWrite = true;
477 }
478
bsalomonbabafcc2016-02-16 11:36:47 -0800479 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
480 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
481 fUseDrawInsteadOfPartialRenderTargetWrite = true;
482 fUseDrawInsteadOfAllRenderTargetWrites = true;
483 }
484
robertphillips63926682015-08-20 09:39:02 -0700485#ifdef SK_BUILD_FOR_WIN
486 // On ANGLE deferring flushes can lead to GPU starvation
487 fPreferVRAMUseOverFlushes = !isANGLE;
488#endif
489
bsalomon7dea7b72015-08-19 08:26:51 -0700490 if (kChromium_GrGLDriver == ctxInfo.driver()) {
491 fMustClearUploadedBufferData = true;
492 }
493
bsalomond08ea5f2015-02-20 06:58:13 -0800494 if (kGL_GrGLStandard == standard) {
495 // ARB allows mixed size FBO attachments, EXT does not.
496 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
497 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
498 fOversizedStencilSupport = true;
499 } else {
500 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
501 }
502 } else {
503 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
504 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
505 }
506
joshualitt58001552015-06-26 12:46:36 -0700507 if (kGL_GrGLStandard == standard) {
508 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
509 // instanced arrays, but we could make this more granular if we wanted
510 fSupportsInstancedDraws =
511 version >= GR_GL_VER(3, 2) ||
512 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
513 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
514 } else {
515 fSupportsInstancedDraws =
516 version >= GR_GL_VER(3, 0) ||
517 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
518 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
519 }
520
cdalton06604b92016-02-05 10:09:51 -0800521 if (kGL_GrGLStandard == standard) {
csmartdalton5cebf8c2016-06-03 08:28:47 -0700522 fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
523 ctxInfo.hasExtension("GL_ARB_draw_indirect");
524 fBaseInstanceSupport = version >= GR_GL_VER(4,2);
525 fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
526 (!fBaseInstanceSupport && // The ARB extension has no base inst.
527 ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
cdalton06604b92016-02-05 10:09:51 -0800528 } else {
529 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
530 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
531 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
532 }
533
jvanverthcba99b82015-06-24 06:59:57 -0700534 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800535
536 if (contextOptions.fUseShaderSwizzling) {
537 fTextureSwizzleSupport = false;
538 }
539
ethannicholas28ef4452016-03-25 09:26:03 -0700540 if (kGL_GrGLStandard == standard) {
ethannicholas6536ae52016-05-02 12:16:49 -0700541 if ((version >= GR_GL_VER(4, 0) || ctxInfo.hasExtension("GL_ARB_sample_shading")) &&
542 ctxInfo.vendor() != kIntel_GrGLVendor) {
ethannicholas28ef4452016-03-25 09:26:03 -0700543 fSampleShadingSupport = true;
544 }
545 } else if (ctxInfo.hasExtension("GL_OES_sample_shading")) {
546 fSampleShadingSupport = true;
547 }
548
brianosman131ff132016-06-07 14:22:44 -0700549 // We support manual mip-map generation (via iterative downsampling draw calls). This fixes
550 // bugs on some cards/drivers that produce incorrect mip-maps for sRGB textures when using
551 // glGenerateMipmap. Our implementation requires mip-level sampling control. Additionally,
552 // it can be much slower (especially on mobile GPUs), so we opt-in only when necessary:
brianosman09563ce2016-06-02 08:59:34 -0700553 if (fMipMapLevelAndLodControlSupport &&
brianosman131ff132016-06-07 14:22:44 -0700554 ((kIntel_GrGLVendor == ctxInfo.vendor()) ||
555 (kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
556 (kATI_GrGLVendor == ctxInfo.vendor()))) {
brianosman09563ce2016-06-02 08:59:34 -0700557 fDoManualMipmapping = true;
558 }
559
bsalomoncdee0092016-01-08 13:20:12 -0800560 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
561 // already been detected.
562 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700563
564 this->applyOptionsOverrides(contextOptions);
565 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000566}
567
egdaniel472d44e2015-10-22 08:20:00 -0700568const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
569 bool isCoreProfile) {
570 switch (generation) {
571 case k110_GrGLSLGeneration:
572 if (kGLES_GrGLStandard == standard) {
573 // ES2s shader language is based on version 1.20 but is version
574 // 1.00 of the ES language.
575 return "#version 100\n";
576 } else {
577 SkASSERT(kGL_GrGLStandard == standard);
578 return "#version 110\n";
579 }
580 case k130_GrGLSLGeneration:
581 SkASSERT(kGL_GrGLStandard == standard);
582 return "#version 130\n";
583 case k140_GrGLSLGeneration:
584 SkASSERT(kGL_GrGLStandard == standard);
585 return "#version 140\n";
586 case k150_GrGLSLGeneration:
587 SkASSERT(kGL_GrGLStandard == standard);
588 if (isCoreProfile) {
589 return "#version 150\n";
590 } else {
591 return "#version 150 compatibility\n";
592 }
593 case k330_GrGLSLGeneration:
594 if (kGLES_GrGLStandard == standard) {
595 return "#version 300 es\n";
596 } else {
597 SkASSERT(kGL_GrGLStandard == standard);
598 if (isCoreProfile) {
599 return "#version 330\n";
600 } else {
601 return "#version 330 compatibility\n";
602 }
603 }
cdalton33ad7012016-02-22 07:55:44 -0800604 case k400_GrGLSLGeneration:
605 SkASSERT(kGL_GrGLStandard == standard);
606 if (isCoreProfile) {
607 return "#version 400\n";
608 } else {
609 return "#version 400 compatibility\n";
610 }
egdaniel472d44e2015-10-22 08:20:00 -0700611 case k310es_GrGLSLGeneration:
612 SkASSERT(kGLES_GrGLStandard == standard);
613 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800614 case k320es_GrGLSLGeneration:
615 SkASSERT(kGLES_GrGLStandard == standard);
616 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700617 }
618 return "<no version>";
619}
620
egdaniel05ded892015-10-26 07:38:05 -0700621void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700622 GrGLStandard standard = ctxInfo.standard();
623 GrGLVersion version = ctxInfo.version();
624
625 /**************************************************************************
626 * Caps specific to GrGLSLCaps
627 **************************************************************************/
628
629 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
630 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700631 if (kGLES_GrGLStandard == standard) {
632 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
633 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
634 glslCaps->fFBFetchSupport = true;
635 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
636 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
637 }
638 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
639 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
640 glslCaps->fFBFetchNeedsCustomOutput = false;
641 glslCaps->fFBFetchSupport = true;
642 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
643 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
644 }
645 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
646 // The arm extension also requires an additional flag which we will set onResetContext
647 glslCaps->fFBFetchNeedsCustomOutput = false;
648 glslCaps->fFBFetchSupport = true;
649 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
650 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
651 }
652 glslCaps->fUsesPrecisionModifiers = true;
653 }
654
655 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
656
cdaltonc08f1962016-02-12 12:14:06 -0800657 if (kGL_GrGLStandard == standard) {
658 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
659 } else {
660 glslCaps->fFlatInterpolationSupport =
661 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
662 }
663
664 if (kGL_GrGLStandard == standard) {
665 glslCaps->fNoPerspectiveInterpolationSupport =
666 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
667 } else {
668 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
669 glslCaps->fNoPerspectiveInterpolationSupport = true;
670 glslCaps->fNoPerspectiveInterpolationExtensionString =
671 "GL_NV_shader_noperspective_interpolation";
672 }
673 }
674
cdalton33ad7012016-02-22 07:55:44 -0800675 if (kGL_GrGLStandard == standard) {
cdalton4a98cdb2016-03-01 12:12:20 -0800676 glslCaps->fMultisampleInterpolationSupport =
677 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
678 } else {
679 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
680 glslCaps->fMultisampleInterpolationSupport = true;
681 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
682 glslCaps->fMultisampleInterpolationSupport = true;
683 glslCaps->fMultisampleInterpolationExtensionString =
684 "GL_OES_shader_multisample_interpolation";
685 }
686 }
687
688 if (kGL_GrGLStandard == standard) {
cdalton33ad7012016-02-22 07:55:44 -0800689 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
690 } else {
691 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
692 glslCaps->fSampleVariablesSupport = true;
693 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
694 glslCaps->fSampleVariablesSupport = true;
695 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
696 }
697 }
698
699 if (glslCaps->fSampleVariablesSupport) {
700 glslCaps->fSampleMaskOverrideCoverageSupport =
701 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
702 }
703
egdaniel472d44e2015-10-22 08:20:00 -0700704 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
705 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
706
707 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
708 // function that may require a gradient calculation inside a conditional block may return
709 // undefined results". This appears to be an issue with the 'any' call since even the simple
710 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
711 // from our GrTextureDomain processor.
712 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
713
egdaniel472d44e2015-10-22 08:20:00 -0700714 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
715 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800716
717 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
718 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
719 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800720
721 // Frag Coords Convention support is not part of ES
722 // Known issue on at least some Intel platforms:
723 // http://code.google.com/p/skia/issues/detail?id=946
724 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
725 kGLES_GrGLStandard != standard &&
726 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
727 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
728 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
729 }
730
731 if (kGLES_GrGLStandard == standard) {
732 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
733 }
734
cdalton9c3f1432016-03-11 10:07:37 -0800735 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
736 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
737 glslCaps->fExternalTextureSupport = true;
738 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
739 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
740 // At least one driver has been found that has this extension without the "GL_" prefix.
741 glslCaps->fExternalTextureSupport = true;
742 }
743 }
744
745 if (glslCaps->fExternalTextureSupport) {
bsalomon7ea33f52015-11-22 14:51:00 -0800746 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
747 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
748 } else {
749 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
750 }
751 }
752
cdaltonc04ce672016-03-11 14:07:38 -0800753 if (kGL_GrGLStandard == standard) {
cdaltonf8a6ce82016-04-11 13:02:05 -0700754 glslCaps->fTexelFetchSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
cdaltonc04ce672016-03-11 14:07:38 -0800755 } else {
cdaltonf8a6ce82016-04-11 13:02:05 -0700756 glslCaps->fTexelFetchSupport =
757 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
758 }
759
760 if (glslCaps->fTexelFetchSupport) {
761 if (kGL_GrGLStandard == standard) {
csmartdalton1897cfd2016-06-03 08:50:54 -0700762 glslCaps->fTexelBufferSupport = ctxInfo.version() >= GR_GL_VER(3, 1) &&
cdaltonf8a6ce82016-04-11 13:02:05 -0700763 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
764 } else {
765 if (ctxInfo.version() >= GR_GL_VER(3, 2) &&
766 ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
767 glslCaps->fTexelBufferSupport = true;
768 } else if (ctxInfo.hasExtension("GL_OES_texture_buffer")) {
769 glslCaps->fTexelBufferSupport = true;
770 glslCaps->fTexelBufferExtensionString = "GL_OES_texture_buffer";
771 } else if (ctxInfo.hasExtension("GL_EXT_texture_buffer")) {
772 glslCaps->fTexelBufferSupport = true;
773 glslCaps->fTexelBufferExtensionString = "GL_EXT_texture_buffer";
774 }
cdaltonc04ce672016-03-11 14:07:38 -0800775 }
776 }
777
egdaniel8dcdedc2015-11-11 06:27:20 -0800778 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
779 // the abs first in a separate expression.
780 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
781 glslCaps->fCanUseMinAndAbsTogether = false;
782 }
783
bsalomon7ea33f52015-11-22 14:51:00 -0800784 // 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 -0800785 // thus must us -1.0 * %s.x to work correctly
786 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
787 glslCaps->fMustForceNegatedAtanParamToFloat = true;
788 }
egdaniel472d44e2015-10-22 08:20:00 -0700789}
790
kkinnunencfe62e32015-07-01 02:58:50 -0700791bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700792 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
793
794 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700795 return false;
796 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700797
kkinnunencfe62e32015-07-01 02:58:50 -0700798 if (kGL_GrGLStandard == ctxInfo.standard()) {
799 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
800 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
801 return false;
802 }
803 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700804 if (!hasChromiumPathRendering &&
805 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700806 return false;
807 }
808 }
809 // We only support v1.3+ of GL_NV_path_rendering which allows us to
810 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
811 // additions are detected by checking the existence of the function.
812 // We also use *Then* functions that not all drivers might have. Check
813 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800814 if (!gli->fFunctions.fStencilThenCoverFillPath ||
815 !gli->fFunctions.fStencilThenCoverStrokePath ||
816 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
817 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
818 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700819 return false;
820 }
821 return true;
822}
bsalomon1aa20292016-01-22 08:16:09 -0800823
824bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800825 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800826 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
827 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800828 // If it's not possible to even have a render target of rtConfig then read pixels is
829 // not supported regardless of readConfig.
830 if (!this->isConfigRenderable(rtConfig, false)) {
831 return false;
832 }
bsalomon7928ef62016-01-05 10:26:39 -0800833
bsalomon76148af2016-01-12 11:13:47 -0800834 GrGLenum readFormat;
835 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800836 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800837 return false;
838 }
839
bsalomon1aa20292016-01-22 08:16:09 -0800840 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800841 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
842 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
843 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
844 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
845 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
846 readFormat != GR_GL_BGRA) {
847 return false;
848 }
849 // There is also a set of allowed types, but all the types we use are in the set:
850 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
851 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
852 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
853 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
854 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
855 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
856 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800857 return true;
piotaixre4b23142014-10-02 10:57:53 -0700858 }
bsalomon7928ef62016-01-05 10:26:39 -0800859
bsalomon76148af2016-01-12 11:13:47 -0800860 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800861
bsalomon1aa20292016-01-22 08:16:09 -0800862 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800863 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
864 return true;
865 }
866 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800867 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800868 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
869 return true;
870 }
871 }
872
bsalomon1aa20292016-01-22 08:16:09 -0800873 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800874 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800875 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800876 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800877 if (!bindRenderTarget()) {
878 return false;
879 }
880 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
881 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800882 rpFormat->fFormat = format;
883 rpFormat->fType = type;
884 }
885
bsalomon1aa20292016-01-22 08:16:09 -0800886 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
887 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700888}
889
robertphillips@google.com6177e692013-02-28 20:16:25 +0000890void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000891
892 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000893 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000894 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
895 // ES3 driver bugs on at least one device with a tiled GPU (N10).
896 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
897 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
898 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
899 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800900 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700901 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000902 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000903 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
904 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
905 // chrome's extension is equivalent to the EXT msaa
906 // and fbo_blit extensions.
907 fMSFBOType = kDesktop_EXT_MSFBOType;
908 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
909 fMSFBOType = kES_Apple_MSFBOType;
910 }
bsalomon083617b2016-02-12 12:10:14 -0800911
912 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
913 // is available.
914 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
915 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
916 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
917 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
918 // limitations.
919 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
920 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000921 } else {
egdanieleed519e2016-01-15 11:36:18 -0800922 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700923 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800924 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700925 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000926 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000927 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800928 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000929 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
930 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000931 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800932 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000933 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000934 }
935}
936
cdalton1dd05422015-06-12 09:01:18 -0700937void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
938 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
939
940 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
941 // for now until its own blacklists can be updated.
942 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
943 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700944 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700945 return;
946 }
947
948 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
949 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
950 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
951 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
952 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
953 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
954 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
955 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
956 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
957 return;
958 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
959 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
960 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
961 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
962 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
963 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
964 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
965 // slow on a particular platform.
966 } else {
967 return; // No advanced blend support.
968 }
969
970 SkASSERT(this->advancedBlendEquationSupport());
971
972 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
973 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
974 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
975 (1 << kColorBurn_GrBlendEquation);
976 }
joel.liang9764c402015-07-09 19:46:18 -0700977 if (kARM_GrGLVendor == ctxInfo.vendor()) {
978 // Blacklist color-burn on ARM until the fix is released.
979 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
980 }
cdalton1dd05422015-06-12 09:01:18 -0700981}
982
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000983namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700984const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000985}
986
987void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
988
989 // Build up list of legal stencil formats (though perhaps not supported on
990 // the particular gpu/driver) from most preferred to least.
991
992 // these consts are in order of most preferred to least preferred
993 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
994
995 static const StencilFormat
996 // internal Format stencil bits total bits packed?
997 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
998 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
999 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1000 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001001 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001002 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1003
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001004 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001005 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001006 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001007 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1008 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1009
1010 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1011 // require FBO support we can expect these are legal formats and don't
1012 // check. These also all support the unsized GL_STENCIL_INDEX.
1013 fStencilFormats.push_back() = gS8;
1014 fStencilFormats.push_back() = gS16;
1015 if (supportsPackedDS) {
1016 fStencilFormats.push_back() = gD24S8;
1017 }
1018 fStencilFormats.push_back() = gS4;
1019 if (supportsPackedDS) {
1020 fStencilFormats.push_back() = gDS;
1021 }
1022 } else {
1023 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1024 // for other formats.
1025 // ES doesn't support using the unsized format.
1026
1027 fStencilFormats.push_back() = gS8;
1028 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001029 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1030 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001031 fStencilFormats.push_back() = gD24S8;
1032 }
1033 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1034 fStencilFormats.push_back() = gS4;
1035 }
1036 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001037}
1038
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001039SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001040
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001041 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001042
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001043 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001044 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001045 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001046 i,
1047 fStencilFormats[i].fStencilBits,
1048 fStencilFormats[i].fTotalBits);
1049 }
1050
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001051 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001052 "None",
1053 "ARB",
1054 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001055 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001056 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001057 "IMG MS To Texture",
1058 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001059 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001060 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001061 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1062 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1063 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001064 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1065 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1066 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1067 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001068 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001069 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001070
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001071 static const char* kInvalidateFBTypeStr[] = {
1072 "None",
1073 "Discard",
1074 "Invalidate",
1075 };
1076 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1077 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1078 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1079 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001080
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001081 static const char* kMapBufferTypeStr[] = {
1082 "None",
1083 "MapBuffer",
1084 "MapBufferRange",
1085 "Chromium",
1086 };
1087 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1088 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1089 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1090 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1091 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1092
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001093 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001094 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001095 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001096 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001097 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001098 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1099 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1100 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1101 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001102
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001103 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001104 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1105 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001106 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001107 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1108 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001109 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001110 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1111 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1112 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001113 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001114 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001115 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1116 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001117 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001118 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001119 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
halcanary9d524f22016-03-29 09:03:52 -07001120 r.appendf("BGRA to RGBA readback conversions are slow: %s\n",
ericrkb4ecabd2016-03-11 15:18:20 -08001121 (fRGBAToBGRAReadbackConversionsAreSlow ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001122
1123 r.append("Configs\n-------\n");
1124 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1125 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001126 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1127 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001128 i,
1129 fConfigTable[i].fFlags,
1130 fConfigTable[i].fFormats.fBaseInternalFormat,
1131 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001132 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1133 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001134 fConfigTable[i].fFormats.fExternalType,
1135 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001136 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001137 }
1138
jvanverthe9c0fc62015-04-29 11:18:05 -07001139 return r;
1140}
1141
jvanverthe9c0fc62015-04-29 11:18:05 -07001142static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1143 switch (p) {
1144 case kLow_GrSLPrecision:
1145 return GR_GL_LOW_FLOAT;
1146 case kMedium_GrSLPrecision:
1147 return GR_GL_MEDIUM_FLOAT;
1148 case kHigh_GrSLPrecision:
1149 return GR_GL_HIGH_FLOAT;
1150 }
1151 SkFAIL("Unknown precision.");
1152 return -1;
1153}
1154
1155static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1156 switch (type) {
1157 case kVertex_GrShaderType:
1158 return GR_GL_VERTEX_SHADER;
1159 case kGeometry_GrShaderType:
1160 return GR_GL_GEOMETRY_SHADER;
1161 case kFragment_GrShaderType:
1162 return GR_GL_FRAGMENT_SHADER;
1163 }
1164 SkFAIL("Unknown shader type.");
1165 return -1;
1166}
1167
jvanverthcba99b82015-06-24 06:59:57 -07001168void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
halcanary9d524f22016-03-29 09:03:52 -07001169 const GrGLInterface* intf,
jvanverthcba99b82015-06-24 06:59:57 -07001170 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001171 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1172 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1173 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1174 if (kGeometry_GrShaderType != s) {
1175 GrShaderType shaderType = static_cast<GrShaderType>(s);
1176 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001177 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001178 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001179 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1180 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1181 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1182 GrGLint range[2];
1183 GrGLint bits;
1184 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1185 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001186 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1187 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1188 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001189 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001190 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001191 }
jvanverthcba99b82015-06-24 06:59:57 -07001192 else if (!glslCaps->fShaderPrecisionVaries) {
halcanary9d524f22016-03-29 09:03:52 -07001193 glslCaps->fShaderPrecisionVaries =
jvanverthcba99b82015-06-24 06:59:57 -07001194 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001195 }
1196 }
1197 }
1198 }
1199 }
1200 }
1201 else {
1202 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001203 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001204 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1205 if (kGeometry_GrShaderType != s) {
1206 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001207 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1208 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1209 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001210 }
1211 }
1212 }
1213 }
1214 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1215 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1216 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1217 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001218 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001219 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
halcanary9d524f22016-03-29 09:03:52 -07001220 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
jvanverthcba99b82015-06-24 06:59:57 -07001221 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001222 }
1223 }
cdaltona6b92ad2016-04-11 12:03:08 -07001224 glslCaps->initSamplerPrecisionTable();
jvanverthe9c0fc62015-04-29 11:18:05 -07001225}
1226
bsalomon41e4384e2016-01-08 09:12:44 -08001227bool GrGLCaps::bgraIsInternalFormat() const {
1228 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1229}
1230
bsalomon76148af2016-01-12 11:13:47 -08001231bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1232 GrGLenum* internalFormat, GrGLenum* externalFormat,
1233 GrGLenum* externalType) const {
1234 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1235 externalFormat, externalType)) {
1236 return false;
1237 }
1238 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1239 return true;
1240}
1241
1242bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1243 GrGLenum* internalFormat) const {
1244 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1245 return false;
1246 }
1247 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1248 return true;
1249}
1250
1251bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1252 GrGLenum* externalFormat, GrGLenum* externalType) const {
1253 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1254 externalFormat, externalType)) {
1255 return false;
1256 }
1257 return true;
1258}
1259
1260bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1261 if (GrPixelConfigIsCompressed(config)) {
1262 return false;
1263 }
1264 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1265 return true;
1266}
1267
1268bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1269 ExternalFormatUsage usage, GrGLenum* externalFormat,
1270 GrGLenum* externalType) const {
1271 SkASSERT(externalFormat && externalType);
1272 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1273 return false;
1274 }
1275
1276 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1277 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1278
1279 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1280 // made to work in many cases using glPixelStore and what not but is not needed currently.
1281 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1282 return false;
1283 }
1284
1285 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1286 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1287
bsalomone9573312016-01-25 14:33:25 -08001288 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1289 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1290 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1291 // texture, not the red component.
1292 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1293 if (this->textureRedSupport()) {
1294 SkASSERT(GR_GL_RED == *externalFormat);
1295 *externalFormat = GR_GL_ALPHA;
1296 }
1297 }
1298
bsalomon76148af2016-01-12 11:13:47 -08001299 return true;
1300}
1301
bsalomoncdee0092016-01-08 13:20:12 -08001302void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1303 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001304 /*
1305 Comments on renderability of configs on various GL versions.
1306 OpenGL < 3.0:
1307 no built in support for render targets.
1308 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1309 format RGB, RGBA and NV float formats we don't use.
1310 This is the following:
1311 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1312 RGB10_A2, RGBA12,RGBA16
1313 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1314 since they aren't required by later standards and the driver can simply return
1315 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1316 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1317 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1318 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1319 This adds a lot of additional renderable sized formats, including ALPHA8.
1320 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1321 16F, 32I, 32UI, and 32F variants).
1322 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1323
1324 For both the above extensions we limit ourselves to those that are also required by
1325 OpenGL 3.0.
1326
1327 OpenGL 3.0:
1328 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1329 but are not required to be supported as renderable textures/renderbuffer.
1330 Required renderable color formats:
1331 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1332 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1333 RGB10_A2.
1334 - R11F_G11F_B10F.
1335 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1336 and RG8UI.
1337 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1338 - ALPHA8
1339
1340 OpenGL 3.1, 3.2, 3.3
1341 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1342 OpengGL 3.3, 4.0, 4.1
1343 Adds RGB10_A2UI.
1344 OpengGL 4.2
1345 Adds
1346 - RGB5_A1, RGBA4
1347 - RGB565
1348 OpenGL 4.4
1349 Does away with the separate list and adds a column to the sized internal color format
1350 table. However, no new formats become required color renderable.
1351
1352 ES 2.0
1353 color renderable: RGBA4, RGB5_A1, RGB565
1354 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1355 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1356 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1357 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1358 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1359 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1360
1361 ES 3.0
1362 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1363 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1364 RGB5_A1.
1365 - RGB8 and RGB565.
1366 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1367 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1368 ES 3.1
1369 Adds RGB10_A2, RGB10_A2UI,
1370 ES 3.2
1371 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1372 */
1373 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1374 if (kNone_MSFBOType != fMSFBOType) {
1375 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1376 }
1377
1378 GrGLStandard standard = ctxInfo.standard();
1379 GrGLVersion version = ctxInfo.version();
1380
cblume790d5132016-02-29 11:13:29 -08001381 bool texStorageSupported = false;
1382 if (kGL_GrGLStandard == standard) {
1383 // The EXT version can apply to either GL or GLES.
1384 texStorageSupported = version >= GR_GL_VER(4,2) ||
1385 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1386 ctxInfo.hasExtension("GL_EXT_texture_storage");
1387 } else {
1388 // Qualcomm Adreno drivers appear to have issues with texture storage.
1389 texStorageSupported = (version >= GR_GL_VER(3,0) &&
1390 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
1391 ctxInfo.hasExtension("GL_EXT_texture_storage");
1392 }
1393
1394 // TODO: remove after command buffer supports full ES 3.0
1395 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1396 kChromium_GrGLDriver == ctxInfo.driver()) {
1397 texStorageSupported = false;
1398 }
1399
cdalton74b8d322016-04-11 14:47:28 -07001400 bool texelBufferSupport = this->shaderCaps()->texelBufferSupport();
1401
bsalomon30447372015-12-21 09:03:05 -08001402 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1403 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001404 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001405 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001406 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001407 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001408
1409 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1410 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001411 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1412 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001413 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001414 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001415 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1416 if (kGL_GrGLStandard == standard) {
1417 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1418 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001419 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001420 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1421 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1422 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1423 }
egdaniel4999df82016-01-07 17:06:04 -08001424 }
cblume790d5132016-02-29 11:13:29 -08001425 if (texStorageSupported) {
1426 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1427 }
cdalton74b8d322016-04-11 14:47:28 -07001428 if (texelBufferSupport) {
1429 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1430 }
bsalomoncdee0092016-01-08 13:20:12 -08001431 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001432
bsalomon76148af2016-01-12 11:13:47 -08001433 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1434 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001435 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001436 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001437 if (kGL_GrGLStandard == standard) {
1438 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1439 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1440 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1441 // Since the internal format is RGBA8, it is also renderable.
1442 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1443 allRenderFlags;
1444 }
1445 } else {
1446 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1447 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1448 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1449 // The APPLE extension doesn't make this renderable.
1450 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1451 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1452 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1453 // Though, that seems to not be the case if the texture storage extension is
1454 // present. The specs don't exactly make that clear.
1455 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1456 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1457 }
1458 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1459 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1460 ConfigInfo::kRenderable_Flag;
1461 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001462 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001463 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1464 ConfigInfo::kRenderableWithMSAA_Flag;
1465 }
1466 }
1467 }
cblume790d5132016-02-29 11:13:29 -08001468 if (texStorageSupported) {
1469 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1470 }
bsalomoncdee0092016-01-08 13:20:12 -08001471 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001472
brianosmana6359362016-03-21 06:55:37 -07001473 // We only enable srgb support if both textures and FBOs support srgb,
brianosman35b784d2016-05-05 11:52:53 -07001474 // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
bsalomon41e4384e2016-01-08 09:12:44 -08001475 if (kGL_GrGLStandard == standard) {
1476 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
brianosmana6359362016-03-21 06:55:37 -07001477 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001478 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1479 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1480 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
brianosmana6359362016-03-21 06:55:37 -07001481 fSRGBSupport = true;
bsalomon41e4384e2016-01-08 09:12:44 -08001482 }
1483 }
1484 // All the above srgb extensions support toggling srgb writes
bsalomon44d427e2016-05-10 09:05:06 -07001485 if (fSRGBSupport) {
1486 fSRGBWriteControl = true;
1487 }
bsalomon41e4384e2016-01-08 09:12:44 -08001488 } else {
1489 // See https://bug.skia.org/4148 for PowerVR issue.
brianosmana6359362016-03-21 06:55:37 -07001490 fSRGBSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
bsalomon41e4384e2016-01-08 09:12:44 -08001491 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1492 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1493 // sRGB writing for destinations.
brianosmanc9986b62016-05-23 06:23:27 -07001494 // See https://bug.skia.org/5329 for Adreno4xx issue.
1495 fSRGBWriteControl = kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
1496 ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
bsalomon41e4384e2016-01-08 09:12:44 -08001497 }
brianosmana6359362016-03-21 06:55:37 -07001498 if (!ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode")) {
1499 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode:
1500 fSRGBSupport = false;
1501 }
bsalomon30447372015-12-21 09:03:05 -08001502 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1503 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1504 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1505 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001506 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1507 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001508 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001509 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
brianosmana6359362016-03-21 06:55:37 -07001510 if (fSRGBSupport) {
bsalomon41e4384e2016-01-08 09:12:44 -08001511 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1512 allRenderFlags;
1513 }
cblume790d5132016-02-29 11:13:29 -08001514 if (texStorageSupported) {
1515 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1516 }
bsalomoncdee0092016-01-08 13:20:12 -08001517 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001518
brianosmana6359362016-03-21 06:55:37 -07001519 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
1520 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1521 // is in this format, for example).
1522 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1523 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1524 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1525 // external format is GL_BGRA.
1526 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1527 GR_GL_BGRA;
1528 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
1529 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
1530 if (fSRGBSupport) {
1531 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1532 allRenderFlags;
1533 }
1534 if (texStorageSupported) {
1535 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1536 }
1537 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1538
bsalomon30447372015-12-21 09:03:05 -08001539 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1540 if (this->ES2CompatibilitySupport()) {
1541 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1542 } else {
1543 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1544 }
bsalomon76148af2016-01-12 11:13:47 -08001545 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1546 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001547 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001548 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001549 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1550 if (kGL_GrGLStandard == standard) {
1551 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1552 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1553 }
1554 } else {
1555 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1556 }
cblume790d5132016-02-29 11:13:29 -08001557 // 565 is not a sized internal format on desktop GL. So on desktop with
1558 // 565 we always use an unsized internal format to let the system pick
1559 // the best sized format to convert the 565 data to. Since TexStorage
1560 // only allows sized internal formats we disallow it.
1561 //
1562 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1563 // update.
1564 if (texStorageSupported && kGL_GrGLStandard != standard) {
1565 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1566 }
bsalomoncdee0092016-01-08 13:20:12 -08001567 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001568
1569 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1570 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001571 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1572 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001573 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001574 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001575 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1576 if (kGL_GrGLStandard == standard) {
1577 if (version >= GR_GL_VER(4, 2)) {
1578 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1579 }
1580 } else {
1581 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1582 }
cblume790d5132016-02-29 11:13:29 -08001583 if (texStorageSupported) {
1584 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1585 }
bsalomoncdee0092016-01-08 13:20:12 -08001586 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001587
1588 if (this->textureRedSupport()) {
1589 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1590 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001591 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1592 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001593 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001594 if (texelBufferSupport) {
1595 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1596 }
bsalomon30447372015-12-21 09:03:05 -08001597 } else {
1598 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1599 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001600 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1601 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001602 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001603 }
1604 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001605 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001606 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
bsalomon40170072016-05-05 14:40:03 -07001607 if (this->textureRedSupport() ||
1608 (kDesktop_ARB_MSFBOType == this->msFBOType() &&
1609 ctxInfo.renderer() != kOSMesa_GrGLRenderer)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001610 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
bsalomon40170072016-05-05 14:40:03 -07001611 // However, osmesa fails if it used even when GL_ARB_framebuffer_object is present.
bsalomon41e4384e2016-01-08 09:12:44 -08001612 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1613 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1614 }
cblume790d5132016-02-29 11:13:29 -08001615 if (texStorageSupported) {
1616 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1617 }
bsalomon41e4384e2016-01-08 09:12:44 -08001618
1619 // Check for [half] floating point texture support
1620 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1621 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1622 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1623 bool hasFPTextures = false;
1624 bool hasHalfFPTextures = false;
1625 // for now we don't support floating point MSAA on ES
1626 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1627 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1628
1629 if (kGL_GrGLStandard == standard) {
1630 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1631 hasFPTextures = true;
1632 hasHalfFPTextures = true;
1633 }
1634 } else {
1635 if (version >= GR_GL_VER(3, 1)) {
1636 hasFPTextures = true;
1637 hasHalfFPTextures = true;
1638 } else {
1639 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1640 ctxInfo.hasExtension("GL_OES_texture_float")) {
1641 hasFPTextures = true;
1642 }
1643 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1644 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1645 hasHalfFPTextures = true;
1646 }
1647 }
1648 }
bsalomon30447372015-12-21 09:03:05 -08001649
1650 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1651 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001652 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1653 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001654 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001655 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001656 if (hasFPTextures) {
1657 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1658 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1659 // many precision issues and no clients actually want this yet.
1660 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1661 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1662 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1663 }
1664 }
cblume790d5132016-02-29 11:13:29 -08001665 if (texStorageSupported) {
1666 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1667 }
cdalton74b8d322016-04-11 14:47:28 -07001668 if (texelBufferSupport) {
1669 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1670 }
bsalomoncdee0092016-01-08 13:20:12 -08001671 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001672
1673 if (this->textureRedSupport()) {
1674 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1675 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001676 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1677 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001678 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
cdalton74b8d322016-04-11 14:47:28 -07001679 if (texelBufferSupport) {
1680 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |=
1681 ConfigInfo::kCanUseWithTexelBuffer_Flag;
1682 }
bsalomon30447372015-12-21 09:03:05 -08001683 } else {
1684 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1685 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001686 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1687 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001688 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001689 }
1690 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1691 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1692 } else {
1693 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1694 }
bsalomon7928ef62016-01-05 10:26:39 -08001695 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001696 if (hasHalfFPTextures) {
1697 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1698 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1699 // GL_RED internal format.
1700 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1701 (this->textureRedSupport() &&
1702 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1703 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1704 }
1705 }
cblume790d5132016-02-29 11:13:29 -08001706 if (texStorageSupported) {
1707 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1708 }
bsalomon30447372015-12-21 09:03:05 -08001709
1710 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1711 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001712 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1713 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001714 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1715 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1716 } else {
1717 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1718 }
bsalomon7928ef62016-01-05 10:26:39 -08001719 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001720 if (hasHalfFPTextures) {
1721 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1722 // ES requires 3.2 or EXT_color_buffer_half_float.
1723 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1724 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1725 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1726 }
1727 }
cblume790d5132016-02-29 11:13:29 -08001728 if (texStorageSupported) {
1729 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1730 }
cdalton74b8d322016-04-11 14:47:28 -07001731 if (texelBufferSupport) {
1732 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag;
1733 }
bsalomoncdee0092016-01-08 13:20:12 -08001734 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001735
1736 // Compressed texture support
1737
1738 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1739 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1740
1741 // TODO: Fix command buffer bindings and remove this.
1742 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001743
1744 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001745 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001746
1747 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1748 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001749 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001750 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001751 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001752 // Disable this for now, while we investigate https://bug.skia.org/4333
1753 if (false) {
1754 // Check for 8-bit palette..
1755 GrGLint numFormats;
1756 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1757 if (numFormats) {
1758 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1759 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1760 for (int i = 0; i < numFormats; ++i) {
1761 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1762 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1763 break;
1764 }
1765 }
1766 }
1767 }
bsalomoncdee0092016-01-08 13:20:12 -08001768 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001769
bsalomon41e4384e2016-01-08 09:12:44 -08001770 // May change the internal format based on extensions.
1771 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1772 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1773 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1774 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1775 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1776 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1777 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1778 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1779 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1780 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1781 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1782 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1783 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1784 GR_GL_COMPRESSED_RED_RGTC1;
1785 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1786 GR_GL_COMPRESSED_RED_RGTC1;
1787 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1788 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1789 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1790 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1791 GR_GL_COMPRESSED_3DC_X;
1792
bsalomon30447372015-12-21 09:03:05 -08001793 }
bsalomon76148af2016-01-12 11:13:47 -08001794 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001795 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001796 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001797 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001798
1799 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1800 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001801 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001802 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001803 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001804 if (kGL_GrGLStandard == standard) {
1805 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1806 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1807 }
1808 } else {
1809 if (version >= GR_GL_VER(3, 0) ||
1810 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1811 // ETC2 is a superset of ETC1, so we can just check for that, too.
1812 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1813 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1814 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1815 }
1816 }
bsalomoncdee0092016-01-08 13:20:12 -08001817 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001818
1819 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1820 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001821 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001822 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001823 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001824 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1825 // decompressing the textures in the driver, and is generally slower.
1826 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1827 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1828 }
bsalomoncdee0092016-01-08 13:20:12 -08001829 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001830
1831 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1832 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1833 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1834 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001835 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1836 0;
bsalomon30447372015-12-21 09:03:05 -08001837 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001838 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001839 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1840 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1841 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1842 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1843 }
bsalomoncdee0092016-01-08 13:20:12 -08001844 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001845
1846 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1847
1848 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001849 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1850 ctxInfo.version() >= GR_GL_VER(3,0));
1851 // All ES versions (thus far) require sized internal formats for render buffers.
1852 // TODO: Always use sized internal format?
1853 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1854
bsalomon30447372015-12-21 09:03:05 -08001855 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001856 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1857 // param to glTex[Sub]Image.
1858 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1859 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1860 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1861 fConfigTable[i].fFormats.fSizedInternalFormat :
1862 fConfigTable[i].fFormats.fBaseInternalFormat;
1863 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001864 fConfigTable[i].fFormats.fSizedInternalFormat :
1865 fConfigTable[i].fFormats.fBaseInternalFormat;
1866 }
1867 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1868 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1869 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1870 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1871 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001872 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001873 GR_GL_SRGB_ALPHA;
brianosmana6359362016-03-21 06:55:37 -07001874
1875 // Additionally, because we had to "invent" sBGRA, there is no way to make it work
1876 // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
1877 // unsupported. (If we have no sRGB support at all, this will get overwritten below).
1878 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
bsalomon30447372015-12-21 09:03:05 -08001879 }
1880
1881 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1882 // as a base format.
1883 // GL_EXT_texture_format_BGRA8888:
1884 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1885 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1886 // formats.
halcanary9d524f22016-03-29 09:03:52 -07001887 // GL_APPLE_texture_format_BGRA8888:
bsalomon30447372015-12-21 09:03:05 -08001888 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1889 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1890 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001891 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001892 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1893 }
1894
bsalomoncdee0092016-01-08 13:20:12 -08001895 // If we don't have texture swizzle support then the shader generator must insert the
1896 // swizzle into shader code.
1897 if (!this->textureSwizzleSupport()) {
1898 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1899 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1900 }
1901 }
1902
bsalomon7f9b2e42016-01-12 13:29:26 -08001903 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1904 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1905 // gets written to the single component.
1906 if (this->textureRedSupport()) {
1907 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1908 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1909 if (GrPixelConfigIsAlphaOnly(config) &&
1910 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1911 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1912 }
1913 }
1914 }
1915
bsalomon30447372015-12-21 09:03:05 -08001916#ifdef SK_DEBUG
1917 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001918 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001919 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001920 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1921 fConfigTable[i].fFormats.fBaseInternalFormat);
1922 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001923 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001924 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1925 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1926 fConfigTable[i].fFormats.fExternalFormat[j]);
1927 }
1928 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001929 }
1930#endif
1931}
1932
egdanielb7e7d572015-11-04 04:23:53 -08001933void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}