blob: 22aa13f0ab4f7268d66f68560925e657011336fd [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.com60da4172012-06-01 19:25:00 +000029 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000030 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fUnpackRowLengthSupport = false;
32 fUnpackFlipYSupport = false;
33 fPackRowLengthSupport = false;
34 fPackFlipYSupport = false;
35 fTextureUsageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000036 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000037 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000038 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070039 fDirectStateAccessSupport = false;
40 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080041 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080042 fMultisampleDisableSupport = false;
cdalton06604b92016-02-05 10:09:51 -080043 fDrawIndirectSupport = false;
44 fMultiDrawIndirectSupport = false;
45 fBaseInstanceSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000046 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000047 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070048 fBindFragDataLocationSupport = false;
bsalomon7ea33f52015-11-22 14:51:00 -080049 fExternalTextureSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080050 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080051 fTextureSwizzleSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070052 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070053 fRGBA8888PixelsOpsAreSlow = false;
54 fPartialFBOReadIsSlow = false;
cblume09bd2c02016-03-01 14:08:28 -080055 fMipMapLevelAndLodControlSupport = false;
piotaixre4b23142014-10-02 10:57:53 -070056
bsalomon083617b2016-02-12 12:10:14 -080057 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
58
halcanary385fe4d2015-08-26 13:07:48 -070059 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070060
cdalton4cd67132015-06-10 19:23:46 -070061 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000062}
63
cdalton4cd67132015-06-10 19:23:46 -070064void GrGLCaps::init(const GrContextOptions& contextOptions,
65 const GrGLContextInfo& ctxInfo,
66 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000067 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000068 GrGLVersion version = ctxInfo.version();
69
bsalomon@google.combcce8922013-03-25 15:38:39 +000070 /**************************************************************************
71 * Caps specific to GrGLCaps
72 **************************************************************************/
73
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000074 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000075 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
76 &fMaxFragmentUniformVectors);
77 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000078 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079 GrGLint max;
80 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
81 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000082 if (version >= GR_GL_VER(3, 2)) {
83 GrGLint profileMask;
84 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
85 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
86 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000088 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000089 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000091 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000092 fUnpackRowLengthSupport = true;
93 fUnpackFlipYSupport = false;
94 fPackRowLengthSupport = true;
95 fPackFlipYSupport = false;
96 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000097 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
98 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000100 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
101 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000102 fPackFlipYSupport =
103 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
104 }
105
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000106 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
108
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000109 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700110 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
111 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
112 ctxInfo.hasExtension("GL_NV_texture_barrier");
113 } else {
114 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
115 }
116
cdaltoneb79eea2016-02-26 10:39:34 -0800117 if (kGL_GrGLStandard == standard) {
118 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
119 ctxInfo.hasExtension("GL_ARB_texture_multisample");
120 } else {
121 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
122 }
123
hendrikwa0d5ad72014-12-02 07:30:30 -0800124 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
125 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700126 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800127 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000128 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
129 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800130 } else {
131 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
132 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000133 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000134 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000135 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000136 ctxInfo.hasExtension("GL_ARB_imaging");
137
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000138 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
139 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
140 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
141 // limit this decision to specific GPU families rather than basing it on the vendor alone.
142 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700143 (kARM_GrGLVendor == ctxInfo.vendor() ||
144 kImagination_GrGLVendor == ctxInfo.vendor() ||
145 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000146 fUseNonVBOVertexAndIndexDynamicData = true;
147 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000148
egdaniel9250d242015-05-18 13:04:26 -0700149 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
150 // Thus we are blacklisting this extension for now on Adreno4xx devices.
151 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
152 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
153 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
154 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000155 fDiscardRenderTargetSupport = true;
156 fInvalidateFBType = kInvalidate_InvalidateFBType;
157 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
158 fDiscardRenderTargetSupport = true;
159 fInvalidateFBType = kDiscard_InvalidateFBType;
160 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000161
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000162 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
163 fFullClearIsFree = true;
164 }
165
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000166 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000167 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800168 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
169 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000170 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000171 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
172 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000173 }
174
cdalton626e1ff2015-06-12 13:56:46 -0700175 if (kGL_GrGLStandard == standard) {
176 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
177 } else {
178 fDirectStateAccessSupport = false;
179 }
180
181 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
182 fDebugSupport = true;
183 } else {
184 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
185 }
186
jvanverth3f801cb2014-12-16 09:49:38 -0800187 if (kGL_GrGLStandard == standard) {
188 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
189 }
190 else {
191 fES2CompatibilitySupport = true;
192 }
193
cdalton0edea2c2015-05-21 08:27:44 -0700194 if (kGL_GrGLStandard == standard) {
195 fMultisampleDisableSupport = true;
196 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700197 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700198 }
199
kkinnunend94708e2015-07-30 22:47:04 -0700200 if (kGL_GrGLStandard == standard) {
201 if (version >= GR_GL_VER(3, 0)) {
202 fBindFragDataLocationSupport = true;
203 }
204 } else {
205 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
206 fBindFragDataLocationSupport = true;
207 }
joshualittc1f56b52015-06-22 12:31:31 -0700208 }
209
bsalomonb8909d32016-01-28 07:09:52 -0800210#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700211 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800212#else
213 fBindUniformLocationSupport = false;
214#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700215
bsalomon7ea33f52015-11-22 14:51:00 -0800216 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
217 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
218 fExternalTextureSupport = true;
219 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
220 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
221 // At least one driver has been found that has this extension without the "GL_" prefix.
222 fExternalTextureSupport = true;
223 }
224 }
225
kkinnunene06ed252016-02-16 23:15:40 -0800226 if (kGL_GrGLStandard == standard) {
227 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
228 // We also require textureSize() support for rectangle 2D samplers which was added in
229 // GLSL 1.40.
230 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
231 fRectangleTextureSupport = true;
232 }
bsalomone179a912016-01-20 06:18:10 -0800233 }
kkinnunene06ed252016-02-16 23:15:40 -0800234 } else {
235 // Command buffer exposes this in GL ES context for Chromium reasons,
236 // but it should not be used. Also, at the time of writing command buffer
237 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800238 }
239
bsalomoncdee0092016-01-08 13:20:12 -0800240 if (kGL_GrGLStandard == standard) {
241 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
242 fTextureSwizzleSupport = true;
243 }
244 } else {
245 if (version >= GR_GL_VER(3,0)) {
246 fTextureSwizzleSupport = true;
247 }
248 }
249
cblume09bd2c02016-03-01 14:08:28 -0800250 if (kGL_GrGLStandard == standard) {
251 fMipMapLevelAndLodControlSupport = true;
252 } else if (kGLES_GrGLStandard == standard) {
253 if (version >= GR_GL_VER(3,0)) {
254 fMipMapLevelAndLodControlSupport = true;
255 }
256 }
257
bsalomon88c7b982015-07-31 11:20:16 -0700258#ifdef SK_BUILD_FOR_WIN
259 // We're assuming that on Windows Chromium we're using ANGLE.
260 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
261 kChromium_GrGLDriver == ctxInfo.driver();
262 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
263 fRGBA8888PixelsOpsAreSlow = isANGLE;
264 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
265 // check DX11 ANGLE.
266 fPartialFBOReadIsSlow = isANGLE;
267#endif
268
cdalton4cd67132015-06-10 19:23:46 -0700269 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700270 * GrShaderCaps fields
271 **************************************************************************/
272
egdaniel0a482332015-10-26 08:59:10 -0700273 // This must be called after fCoreProfile is set on the GrGLCaps
274 this->initGLSL(ctxInfo);
275 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
276
egdaniel05ded892015-10-26 07:38:05 -0700277 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
278
279 // For now these two are equivalent but we could have dst read in shader via some other method.
280 // Before setting this, initGLSL() must have been called.
281 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
282
283 // Enable supported shader-related caps
284 if (kGL_GrGLStandard == standard) {
285 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
286 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
287 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
288 glslCaps->fShaderDerivativeSupport = true;
289 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
290 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
291 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800292 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
293 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700294 }
295 else {
296 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
297
298 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
299 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800300
301 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
302 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700303 }
304
ethannicholas22793252016-01-30 09:59:10 -0800305 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
306 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
307 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
308 &glslCaps->fPixelLocalStorageSize);
309 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
310 }
311 else {
312 glslCaps->fPixelLocalStorageSize = 0;
313 glslCaps->fPLSPathRenderingSupport = false;
314 }
315
egdaniel05ded892015-10-26 07:38:05 -0700316 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700317 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000318 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700319
cdalton63f6c1f2015-11-06 07:09:43 -0800320 // We need dual source blending and the ability to disable multisample in order to support mixed
321 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800322 if (fMultisampleDisableSupport &&
323 glslCaps->dualSourceBlendingSupport() &&
324 fShaderCaps->pathRenderingSupport()) {
325 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800326 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800327 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800328 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
329 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800330 fDiscardRenderTargetSupport = false;
331 fInvalidateFBType = kNone_InvalidateFBType;
332 }
333 }
334
egdanieleed519e2016-01-15 11:36:18 -0800335 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700336 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700337 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700338 this->initStencilFormats(ctxInfo);
339
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000340 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000341 // we could also look for GL_ATI_separate_stencil extension or
342 // GL_EXT_stencil_two_side but they use different function signatures
343 // than GL2.0+ (and than each other).
344 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
345 // supported on GL 1.4 and higher or by extension
346 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
347 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
348 } else {
349 // ES 2 has two sided stencil and stencil wrap
350 fTwoSidedStencilSupport = true;
351 fStencilWrapOpsSupport = true;
352 }
353
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000354 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000355 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
356 // extension includes glMapBuffer.
357 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
358 fMapBufferFlags |= kSubset_MapFlag;
359 fMapBufferType = kMapBufferRange_MapBufferType;
360 } else {
361 fMapBufferType = kMapBuffer_MapBufferType;
362 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000363 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000364 // Unextended GLES2 doesn't have any buffer mapping.
365 fMapBufferFlags = kNone_MapBufferType;
kkinnunen45c2c812016-02-25 02:03:43 -0800366 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000367 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
368 fMapBufferType = kMapBufferRange_MapBufferType;
kkinnunen45c2c812016-02-25 02:03:43 -0800369 } else if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
370 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
371 fMapBufferType = kChromium_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000372 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
373 fMapBufferFlags = kCanMap_MapFlag;
374 fMapBufferType = kMapBuffer_MapBufferType;
375 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000376 }
377
jvanverthd7a2c1f2015-12-07 07:36:44 -0800378 if (kGL_GrGLStandard == standard) {
379 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
380 fTransferBufferType = kPBO_TransferBufferType;
381 }
382 } else {
383 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
384 fTransferBufferType = kPBO_TransferBufferType;
385 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
386 fTransferBufferType = kChromium_TransferBufferType;
387 }
388 }
389
joshualitte5b74c62015-06-01 14:17:47 -0700390 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
391 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
392 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700393 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
394 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
395 // a small subset.
396#if 0
cdalton1acea862015-06-02 13:05:52 -0700397 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700398#else
399 fGeometryBufferMapThreshold = SK_MaxS32;
400#endif
joshualitte5b74c62015-06-01 14:17:47 -0700401 }
402
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000403 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000404 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
405 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
406 fNPOTTextureTileSupport = true;
407 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000408 } else {
409 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000410 // ES3 has no limitations.
411 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
412 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000413 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
414 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
415 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
416 // to alllow arbitrary wrap modes, however.
417 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000418 }
419
bsalomone72bd022015-10-26 07:33:03 -0700420 // Using MIPs on this GPU seems to be a source of trouble.
421 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
422 fMipMapSupport = false;
423 }
424
bsalomon@google.combcce8922013-03-25 15:38:39 +0000425 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
426 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
427 // Our render targets are always created with textures as the color
428 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000429 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000430
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000431 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
432
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000433 // Disable scratch texture reuse on Mali and Adreno devices
434 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
435 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000436
robertphillips1b8e1b52015-06-24 06:54:10 -0700437#if 0
438 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
439 kQualcomm_GrGLVendor != ctxInfo.vendor();
440#endif
441
egdaniel05ded892015-10-26 07:38:05 -0700442 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000443 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800444 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000445 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800446 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000447 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800448 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
449 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
450 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
451 // This is to guard against platforms that may not support as many samples for
452 // glRasterSamples as they do for framebuffers.
453 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
454 }
455 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000456
bsalomon63b21962014-11-05 07:05:34 -0800457 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800458 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800459 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800460 fUseDrawInsteadOfClear = true;
461 }
462
joshualitt83bc2292015-06-18 14:18:02 -0700463 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
464 fUseDrawInsteadOfPartialRenderTargetWrite = true;
465 }
466
bsalomonbabafcc2016-02-16 11:36:47 -0800467 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
468 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
469 fUseDrawInsteadOfPartialRenderTargetWrite = true;
470 fUseDrawInsteadOfAllRenderTargetWrites = true;
471 }
472
robertphillips63926682015-08-20 09:39:02 -0700473#ifdef SK_BUILD_FOR_WIN
474 // On ANGLE deferring flushes can lead to GPU starvation
475 fPreferVRAMUseOverFlushes = !isANGLE;
476#endif
477
bsalomon7dea7b72015-08-19 08:26:51 -0700478 if (kChromium_GrGLDriver == ctxInfo.driver()) {
479 fMustClearUploadedBufferData = true;
480 }
481
bsalomond08ea5f2015-02-20 06:58:13 -0800482 if (kGL_GrGLStandard == standard) {
483 // ARB allows mixed size FBO attachments, EXT does not.
484 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
485 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
486 fOversizedStencilSupport = true;
487 } else {
488 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
489 }
490 } else {
491 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
492 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
493 }
494
joshualitt58001552015-06-26 12:46:36 -0700495 if (kGL_GrGLStandard == standard) {
496 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
497 // instanced arrays, but we could make this more granular if we wanted
498 fSupportsInstancedDraws =
499 version >= GR_GL_VER(3, 2) ||
500 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
501 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
502 } else {
503 fSupportsInstancedDraws =
504 version >= GR_GL_VER(3, 0) ||
505 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
506 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
507 }
508
cdalton06604b92016-02-05 10:09:51 -0800509 if (kGL_GrGLStandard == standard) {
510 // We don't use ARB_draw_indirect because it does not support a base instance.
511 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
512 fDrawIndirectSupport =
513 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
514 } else {
515 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
516 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
517 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
518 }
519
jvanverthcba99b82015-06-24 06:59:57 -0700520 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800521
522 if (contextOptions.fUseShaderSwizzling) {
523 fTextureSwizzleSupport = false;
524 }
525
kkinnunen45c2c812016-02-25 02:03:43 -0800526 // TODO: remove after command buffer supports full ES 3.0.
527 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3, 0) &&
528 kChromium_GrGLDriver == ctxInfo.driver()) {
kkinnunen45c2c812016-02-25 02:03:43 -0800529 fSupportsInstancedDraws = false;
530 fTextureSwizzleSupport = false;
531 SkASSERT(ctxInfo.hasExtension("GL_CHROMIUM_map_sub"));
532 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
533 fMapBufferType = kChromium_MapBufferType;
534 }
535
bsalomoncdee0092016-01-08 13:20:12 -0800536 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
537 // already been detected.
538 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700539
540 this->applyOptionsOverrides(contextOptions);
541 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000542}
543
egdaniel472d44e2015-10-22 08:20:00 -0700544const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
545 bool isCoreProfile) {
546 switch (generation) {
547 case k110_GrGLSLGeneration:
548 if (kGLES_GrGLStandard == standard) {
549 // ES2s shader language is based on version 1.20 but is version
550 // 1.00 of the ES language.
551 return "#version 100\n";
552 } else {
553 SkASSERT(kGL_GrGLStandard == standard);
554 return "#version 110\n";
555 }
556 case k130_GrGLSLGeneration:
557 SkASSERT(kGL_GrGLStandard == standard);
558 return "#version 130\n";
559 case k140_GrGLSLGeneration:
560 SkASSERT(kGL_GrGLStandard == standard);
561 return "#version 140\n";
562 case k150_GrGLSLGeneration:
563 SkASSERT(kGL_GrGLStandard == standard);
564 if (isCoreProfile) {
565 return "#version 150\n";
566 } else {
567 return "#version 150 compatibility\n";
568 }
569 case k330_GrGLSLGeneration:
570 if (kGLES_GrGLStandard == standard) {
571 return "#version 300 es\n";
572 } else {
573 SkASSERT(kGL_GrGLStandard == standard);
574 if (isCoreProfile) {
575 return "#version 330\n";
576 } else {
577 return "#version 330 compatibility\n";
578 }
579 }
cdalton33ad7012016-02-22 07:55:44 -0800580 case k400_GrGLSLGeneration:
581 SkASSERT(kGL_GrGLStandard == standard);
582 if (isCoreProfile) {
583 return "#version 400\n";
584 } else {
585 return "#version 400 compatibility\n";
586 }
egdaniel472d44e2015-10-22 08:20:00 -0700587 case k310es_GrGLSLGeneration:
588 SkASSERT(kGLES_GrGLStandard == standard);
589 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800590 case k320es_GrGLSLGeneration:
591 SkASSERT(kGLES_GrGLStandard == standard);
592 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700593 }
594 return "<no version>";
595}
596
egdaniel05ded892015-10-26 07:38:05 -0700597void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700598 GrGLStandard standard = ctxInfo.standard();
599 GrGLVersion version = ctxInfo.version();
600
601 /**************************************************************************
602 * Caps specific to GrGLSLCaps
603 **************************************************************************/
604
605 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
606 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700607 if (kGLES_GrGLStandard == standard) {
608 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
609 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
610 glslCaps->fFBFetchSupport = true;
611 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
612 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
613 }
614 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
615 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
616 glslCaps->fFBFetchNeedsCustomOutput = false;
617 glslCaps->fFBFetchSupport = true;
618 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
619 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
620 }
621 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
622 // The arm extension also requires an additional flag which we will set onResetContext
623 glslCaps->fFBFetchNeedsCustomOutput = false;
624 glslCaps->fFBFetchSupport = true;
625 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
626 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
627 }
628 glslCaps->fUsesPrecisionModifiers = true;
629 }
630
631 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
632
cdaltonc08f1962016-02-12 12:14:06 -0800633 if (kGL_GrGLStandard == standard) {
634 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
635 } else {
636 glslCaps->fFlatInterpolationSupport =
637 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
638 }
639
640 if (kGL_GrGLStandard == standard) {
641 glslCaps->fNoPerspectiveInterpolationSupport =
642 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
643 } else {
644 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
645 glslCaps->fNoPerspectiveInterpolationSupport = true;
646 glslCaps->fNoPerspectiveInterpolationExtensionString =
647 "GL_NV_shader_noperspective_interpolation";
648 }
649 }
650
cdalton33ad7012016-02-22 07:55:44 -0800651 if (kGL_GrGLStandard == standard) {
cdalton4a98cdb2016-03-01 12:12:20 -0800652 glslCaps->fMultisampleInterpolationSupport =
653 ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
654 } else {
655 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
656 glslCaps->fMultisampleInterpolationSupport = true;
657 } else if (ctxInfo.hasExtension("GL_OES_shader_multisample_interpolation")) {
658 glslCaps->fMultisampleInterpolationSupport = true;
659 glslCaps->fMultisampleInterpolationExtensionString =
660 "GL_OES_shader_multisample_interpolation";
661 }
662 }
663
664 if (kGL_GrGLStandard == standard) {
cdalton33ad7012016-02-22 07:55:44 -0800665 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
666 } else {
667 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
668 glslCaps->fSampleVariablesSupport = true;
669 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
670 glslCaps->fSampleVariablesSupport = true;
671 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
672 }
673 }
674
675 if (glslCaps->fSampleVariablesSupport) {
676 glslCaps->fSampleMaskOverrideCoverageSupport =
677 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
678 }
679
egdaniel472d44e2015-10-22 08:20:00 -0700680 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
681 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
682
683 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
684 // function that may require a gradient calculation inside a conditional block may return
685 // undefined results". This appears to be an issue with the 'any' call since even the simple
686 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
687 // from our GrTextureDomain processor.
688 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
689
egdaniel472d44e2015-10-22 08:20:00 -0700690 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
691 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800692
693 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
694 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
695 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800696
697 // Frag Coords Convention support is not part of ES
698 // Known issue on at least some Intel platforms:
699 // http://code.google.com/p/skia/issues/detail?id=946
700 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
701 kGLES_GrGLStandard != standard &&
702 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
703 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
704 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
705 }
706
707 if (kGLES_GrGLStandard == standard) {
708 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
709 }
710
bsalomon7ea33f52015-11-22 14:51:00 -0800711 if (fExternalTextureSupport) {
712 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
713 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
714 } else {
715 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
716 }
717 }
718
egdaniel8dcdedc2015-11-11 06:27:20 -0800719 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
720 // the abs first in a separate expression.
721 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
722 glslCaps->fCanUseMinAndAbsTogether = false;
723 }
724
bsalomon7ea33f52015-11-22 14:51:00 -0800725 // 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 -0800726 // thus must us -1.0 * %s.x to work correctly
727 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
728 glslCaps->fMustForceNegatedAtanParamToFloat = true;
729 }
egdaniel472d44e2015-10-22 08:20:00 -0700730}
731
kkinnunencfe62e32015-07-01 02:58:50 -0700732bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700733 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
734
735 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700736 return false;
737 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700738
kkinnunencfe62e32015-07-01 02:58:50 -0700739 if (kGL_GrGLStandard == ctxInfo.standard()) {
740 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
741 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
742 return false;
743 }
744 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700745 if (!hasChromiumPathRendering &&
746 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700747 return false;
748 }
749 }
750 // We only support v1.3+ of GL_NV_path_rendering which allows us to
751 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
752 // additions are detected by checking the existence of the function.
753 // We also use *Then* functions that not all drivers might have. Check
754 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800755 if (!gli->fFunctions.fStencilThenCoverFillPath ||
756 !gli->fFunctions.fStencilThenCoverStrokePath ||
757 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
758 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
759 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700760 return false;
761 }
762 return true;
763}
bsalomon1aa20292016-01-22 08:16:09 -0800764
765bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800766 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800767 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
768 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800769 // If it's not possible to even have a render target of rtConfig then read pixels is
770 // not supported regardless of readConfig.
771 if (!this->isConfigRenderable(rtConfig, false)) {
772 return false;
773 }
bsalomon7928ef62016-01-05 10:26:39 -0800774
bsalomon76148af2016-01-12 11:13:47 -0800775 GrGLenum readFormat;
776 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800777 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800778 return false;
779 }
780
bsalomon1aa20292016-01-22 08:16:09 -0800781 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800782 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
783 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
784 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
785 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
786 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
787 readFormat != GR_GL_BGRA) {
788 return false;
789 }
790 // There is also a set of allowed types, but all the types we use are in the set:
791 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
792 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
793 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
794 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
795 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
796 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
797 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800798 return true;
piotaixre4b23142014-10-02 10:57:53 -0700799 }
bsalomon7928ef62016-01-05 10:26:39 -0800800
bsalomon76148af2016-01-12 11:13:47 -0800801 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800802
bsalomon1aa20292016-01-22 08:16:09 -0800803 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800804 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
805 return true;
806 }
807 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800808 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800809 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
810 return true;
811 }
812 }
813
bsalomon1aa20292016-01-22 08:16:09 -0800814 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800815 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800816 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800817 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800818 if (!bindRenderTarget()) {
819 return false;
820 }
821 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
822 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800823 rpFormat->fFormat = format;
824 rpFormat->fType = type;
825 }
826
bsalomon1aa20292016-01-22 08:16:09 -0800827 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
828 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700829}
830
robertphillips@google.com6177e692013-02-28 20:16:25 +0000831void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000832
833 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000834 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000835 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
836 // ES3 driver bugs on at least one device with a tiled GPU (N10).
837 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
838 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
839 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
840 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800841 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700842 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000843 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000844 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
845 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
846 // chrome's extension is equivalent to the EXT msaa
847 // and fbo_blit extensions.
848 fMSFBOType = kDesktop_EXT_MSFBOType;
849 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
850 fMSFBOType = kES_Apple_MSFBOType;
851 }
bsalomon083617b2016-02-12 12:10:14 -0800852
853 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
854 // is available.
855 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
856 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
857 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
858 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
859 // limitations.
860 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
861 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000862 } else {
egdanieleed519e2016-01-15 11:36:18 -0800863 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700864 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800865 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700866 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000867 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000868 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800869 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000870 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
871 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000872 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800873 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000874 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000875 }
876}
877
cdalton1dd05422015-06-12 09:01:18 -0700878void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
879 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
880
881 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
882 // for now until its own blacklists can be updated.
883 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
884 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700885 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700886 return;
887 }
888
889 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
890 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
891 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
892 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
893 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
894 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
895 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
896 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
897 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
898 return;
899 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
900 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
901 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
902 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
903 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
904 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
905 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
906 // slow on a particular platform.
907 } else {
908 return; // No advanced blend support.
909 }
910
911 SkASSERT(this->advancedBlendEquationSupport());
912
913 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
914 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
915 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
916 (1 << kColorBurn_GrBlendEquation);
917 }
joel.liang9764c402015-07-09 19:46:18 -0700918 if (kARM_GrGLVendor == ctxInfo.vendor()) {
919 // Blacklist color-burn on ARM until the fix is released.
920 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
921 }
cdalton1dd05422015-06-12 09:01:18 -0700922}
923
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000924namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700925const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000926}
927
928void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
929
930 // Build up list of legal stencil formats (though perhaps not supported on
931 // the particular gpu/driver) from most preferred to least.
932
933 // these consts are in order of most preferred to least preferred
934 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
935
936 static const StencilFormat
937 // internal Format stencil bits total bits packed?
938 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
939 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
940 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
941 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000942 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000943 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
944
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000945 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000946 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000947 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000948 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
949 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
950
951 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
952 // require FBO support we can expect these are legal formats and don't
953 // check. These also all support the unsized GL_STENCIL_INDEX.
954 fStencilFormats.push_back() = gS8;
955 fStencilFormats.push_back() = gS16;
956 if (supportsPackedDS) {
957 fStencilFormats.push_back() = gD24S8;
958 }
959 fStencilFormats.push_back() = gS4;
960 if (supportsPackedDS) {
961 fStencilFormats.push_back() = gDS;
962 }
963 } else {
964 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
965 // for other formats.
966 // ES doesn't support using the unsized format.
967
968 fStencilFormats.push_back() = gS8;
969 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000970 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
971 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000972 fStencilFormats.push_back() = gD24S8;
973 }
974 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
975 fStencilFormats.push_back() = gS4;
976 }
977 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000978}
979
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000980SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000981
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000982 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000983
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000984 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000985 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000986 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000987 i,
988 fStencilFormats[i].fStencilBits,
989 fStencilFormats[i].fTotalBits);
990 }
991
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000992 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000993 "None",
994 "ARB",
995 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000996 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000997 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000998 "IMG MS To Texture",
999 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001000 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001001 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001002 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1003 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1004 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001005 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1006 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1007 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1008 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001009 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001010 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001011
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001012 static const char* kInvalidateFBTypeStr[] = {
1013 "None",
1014 "Discard",
1015 "Invalidate",
1016 };
1017 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1018 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1019 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1020 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001021
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001022 static const char* kMapBufferTypeStr[] = {
1023 "None",
1024 "MapBuffer",
1025 "MapBufferRange",
1026 "Chromium",
1027 };
1028 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1029 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1030 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1031 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1032 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1033
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001034 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001035 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001036 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001037 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001038 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1039 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001040 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001041 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1042 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1043 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1044 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001045
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001046 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001047 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1048 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001049 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001050 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1051 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001052 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001053 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1054 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1055 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001056 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001057 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001058 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001059 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1060 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001061 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001062 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001063 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001064 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001065
1066 r.append("Configs\n-------\n");
1067 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1068 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001069 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1070 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001071 i,
1072 fConfigTable[i].fFlags,
1073 fConfigTable[i].fFormats.fBaseInternalFormat,
1074 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001075 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1076 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001077 fConfigTable[i].fFormats.fExternalType,
1078 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001079 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001080 }
1081
jvanverthe9c0fc62015-04-29 11:18:05 -07001082 return r;
1083}
1084
jvanverthe9c0fc62015-04-29 11:18:05 -07001085static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1086 switch (p) {
1087 case kLow_GrSLPrecision:
1088 return GR_GL_LOW_FLOAT;
1089 case kMedium_GrSLPrecision:
1090 return GR_GL_MEDIUM_FLOAT;
1091 case kHigh_GrSLPrecision:
1092 return GR_GL_HIGH_FLOAT;
1093 }
1094 SkFAIL("Unknown precision.");
1095 return -1;
1096}
1097
1098static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1099 switch (type) {
1100 case kVertex_GrShaderType:
1101 return GR_GL_VERTEX_SHADER;
1102 case kGeometry_GrShaderType:
1103 return GR_GL_GEOMETRY_SHADER;
1104 case kFragment_GrShaderType:
1105 return GR_GL_FRAGMENT_SHADER;
1106 }
1107 SkFAIL("Unknown shader type.");
1108 return -1;
1109}
1110
jvanverthcba99b82015-06-24 06:59:57 -07001111void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1112 const GrGLInterface* intf,
1113 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001114 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1115 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1116 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1117 if (kGeometry_GrShaderType != s) {
1118 GrShaderType shaderType = static_cast<GrShaderType>(s);
1119 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001120 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001121 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001122 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1123 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1124 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1125 GrGLint range[2];
1126 GrGLint bits;
1127 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1128 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001129 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1130 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1131 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001132 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001133 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001134 }
jvanverthcba99b82015-06-24 06:59:57 -07001135 else if (!glslCaps->fShaderPrecisionVaries) {
1136 glslCaps->fShaderPrecisionVaries =
1137 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001138 }
1139 }
1140 }
1141 }
1142 }
1143 }
1144 else {
1145 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001146 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001147 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1148 if (kGeometry_GrShaderType != s) {
1149 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001150 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1151 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1152 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001153 }
1154 }
1155 }
1156 }
1157 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1158 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1159 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1160 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001161 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001162 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001163 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1164 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001165 }
1166 }
1167}
1168
bsalomon41e4384e2016-01-08 09:12:44 -08001169bool GrGLCaps::bgraIsInternalFormat() const {
1170 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1171}
1172
bsalomon76148af2016-01-12 11:13:47 -08001173bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1174 GrGLenum* internalFormat, GrGLenum* externalFormat,
1175 GrGLenum* externalType) const {
1176 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1177 externalFormat, externalType)) {
1178 return false;
1179 }
1180 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1181 return true;
1182}
1183
1184bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1185 GrGLenum* internalFormat) const {
1186 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1187 return false;
1188 }
1189 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1190 return true;
1191}
1192
1193bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1194 GrGLenum* externalFormat, GrGLenum* externalType) const {
1195 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1196 externalFormat, externalType)) {
1197 return false;
1198 }
1199 return true;
1200}
1201
1202bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1203 if (GrPixelConfigIsCompressed(config)) {
1204 return false;
1205 }
1206 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1207 return true;
1208}
1209
1210bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1211 ExternalFormatUsage usage, GrGLenum* externalFormat,
1212 GrGLenum* externalType) const {
1213 SkASSERT(externalFormat && externalType);
1214 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1215 return false;
1216 }
1217
1218 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1219 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1220
1221 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1222 // made to work in many cases using glPixelStore and what not but is not needed currently.
1223 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1224 return false;
1225 }
1226
1227 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1228 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1229
bsalomone9573312016-01-25 14:33:25 -08001230 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1231 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1232 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1233 // texture, not the red component.
1234 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1235 if (this->textureRedSupport()) {
1236 SkASSERT(GR_GL_RED == *externalFormat);
1237 *externalFormat = GR_GL_ALPHA;
1238 }
1239 }
1240
bsalomon76148af2016-01-12 11:13:47 -08001241 return true;
1242}
1243
bsalomoncdee0092016-01-08 13:20:12 -08001244void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1245 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001246 /*
1247 Comments on renderability of configs on various GL versions.
1248 OpenGL < 3.0:
1249 no built in support for render targets.
1250 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1251 format RGB, RGBA and NV float formats we don't use.
1252 This is the following:
1253 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1254 RGB10_A2, RGBA12,RGBA16
1255 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1256 since they aren't required by later standards and the driver can simply return
1257 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1258 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1259 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1260 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1261 This adds a lot of additional renderable sized formats, including ALPHA8.
1262 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1263 16F, 32I, 32UI, and 32F variants).
1264 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1265
1266 For both the above extensions we limit ourselves to those that are also required by
1267 OpenGL 3.0.
1268
1269 OpenGL 3.0:
1270 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1271 but are not required to be supported as renderable textures/renderbuffer.
1272 Required renderable color formats:
1273 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1274 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1275 RGB10_A2.
1276 - R11F_G11F_B10F.
1277 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1278 and RG8UI.
1279 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1280 - ALPHA8
1281
1282 OpenGL 3.1, 3.2, 3.3
1283 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1284 OpengGL 3.3, 4.0, 4.1
1285 Adds RGB10_A2UI.
1286 OpengGL 4.2
1287 Adds
1288 - RGB5_A1, RGBA4
1289 - RGB565
1290 OpenGL 4.4
1291 Does away with the separate list and adds a column to the sized internal color format
1292 table. However, no new formats become required color renderable.
1293
1294 ES 2.0
1295 color renderable: RGBA4, RGB5_A1, RGB565
1296 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1297 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1298 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1299 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1300 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1301 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1302
1303 ES 3.0
1304 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1305 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1306 RGB5_A1.
1307 - RGB8 and RGB565.
1308 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1309 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1310 ES 3.1
1311 Adds RGB10_A2, RGB10_A2UI,
1312 ES 3.2
1313 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1314 */
1315 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1316 if (kNone_MSFBOType != fMSFBOType) {
1317 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1318 }
1319
1320 GrGLStandard standard = ctxInfo.standard();
1321 GrGLVersion version = ctxInfo.version();
1322
cblume790d5132016-02-29 11:13:29 -08001323 bool texStorageSupported = false;
1324 if (kGL_GrGLStandard == standard) {
1325 // The EXT version can apply to either GL or GLES.
1326 texStorageSupported = version >= GR_GL_VER(4,2) ||
1327 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1328 ctxInfo.hasExtension("GL_EXT_texture_storage");
1329 } else {
1330 // Qualcomm Adreno drivers appear to have issues with texture storage.
1331 texStorageSupported = (version >= GR_GL_VER(3,0) &&
1332 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
1333 ctxInfo.hasExtension("GL_EXT_texture_storage");
1334 }
1335
1336 // TODO: remove after command buffer supports full ES 3.0
1337 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1338 kChromium_GrGLDriver == ctxInfo.driver()) {
1339 texStorageSupported = false;
1340 }
1341
bsalomon30447372015-12-21 09:03:05 -08001342 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1343 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001344 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001345 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001346 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001347 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001348
1349 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1350 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001351 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1352 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001353 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001354 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001355 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1356 if (kGL_GrGLStandard == standard) {
1357 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1358 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001359 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001360 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1361 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1362 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1363 }
egdaniel4999df82016-01-07 17:06:04 -08001364 }
cblume790d5132016-02-29 11:13:29 -08001365 if (texStorageSupported) {
1366 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1367 }
bsalomoncdee0092016-01-08 13:20:12 -08001368 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001369
bsalomon76148af2016-01-12 11:13:47 -08001370 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1371 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001372 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001373 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001374 if (kGL_GrGLStandard == standard) {
1375 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1376 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1377 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1378 // Since the internal format is RGBA8, it is also renderable.
1379 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1380 allRenderFlags;
1381 }
1382 } else {
1383 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1384 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1385 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1386 // The APPLE extension doesn't make this renderable.
1387 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1388 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1389 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1390 // Though, that seems to not be the case if the texture storage extension is
1391 // present. The specs don't exactly make that clear.
1392 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1393 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1394 }
1395 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1396 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1397 ConfigInfo::kRenderable_Flag;
1398 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001399 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001400 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1401 ConfigInfo::kRenderableWithMSAA_Flag;
1402 }
1403 }
1404 }
cblume790d5132016-02-29 11:13:29 -08001405 if (texStorageSupported) {
1406 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1407 }
bsalomoncdee0092016-01-08 13:20:12 -08001408 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001409
bsalomon41e4384e2016-01-08 09:12:44 -08001410 // We only enable srgb support if both textures and FBOs support srgb.
1411 bool srgbSupport = false;
1412 if (kGL_GrGLStandard == standard) {
1413 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1414 srgbSupport = true;
1415 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1416 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1417 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1418 srgbSupport = true;
1419 }
1420 }
1421 // All the above srgb extensions support toggling srgb writes
1422 fSRGBWriteControl = srgbSupport;
1423 } else {
1424 // See https://bug.skia.org/4148 for PowerVR issue.
1425 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1426 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1427 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1428 // sRGB writing for destinations.
1429 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1430 }
bsalomon30447372015-12-21 09:03:05 -08001431 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1432 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1433 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1434 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001435 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1436 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001437 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001438 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001439 if (srgbSupport) {
1440 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1441 allRenderFlags;
1442 }
cblume790d5132016-02-29 11:13:29 -08001443 if (texStorageSupported) {
1444 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1445 }
bsalomoncdee0092016-01-08 13:20:12 -08001446 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001447
1448 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1449 if (this->ES2CompatibilitySupport()) {
1450 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1451 } else {
1452 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1453 }
bsalomon76148af2016-01-12 11:13:47 -08001454 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1455 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001456 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001457 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001458 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1459 if (kGL_GrGLStandard == standard) {
1460 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1461 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1462 }
1463 } else {
1464 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1465 }
cblume790d5132016-02-29 11:13:29 -08001466 // 565 is not a sized internal format on desktop GL. So on desktop with
1467 // 565 we always use an unsized internal format to let the system pick
1468 // the best sized format to convert the 565 data to. Since TexStorage
1469 // only allows sized internal formats we disallow it.
1470 //
1471 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1472 // update.
1473 if (texStorageSupported && kGL_GrGLStandard != standard) {
1474 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1475 }
bsalomoncdee0092016-01-08 13:20:12 -08001476 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001477
1478 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1479 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001480 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1481 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001482 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001483 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001484 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1485 if (kGL_GrGLStandard == standard) {
1486 if (version >= GR_GL_VER(4, 2)) {
1487 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1488 }
1489 } else {
1490 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1491 }
cblume790d5132016-02-29 11:13:29 -08001492 if (texStorageSupported) {
1493 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1494 }
bsalomoncdee0092016-01-08 13:20:12 -08001495 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001496
1497 if (this->textureRedSupport()) {
1498 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1499 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001500 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1501 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001502 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001503 } else {
1504 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1505 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001506 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1507 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001508 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001509 }
1510 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001511 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001512 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1513 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1514 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1515 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1516 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1517 }
cblume790d5132016-02-29 11:13:29 -08001518 if (texStorageSupported) {
1519 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1520 }
bsalomon41e4384e2016-01-08 09:12:44 -08001521
1522 // Check for [half] floating point texture support
1523 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1524 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1525 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1526 bool hasFPTextures = false;
1527 bool hasHalfFPTextures = false;
1528 // for now we don't support floating point MSAA on ES
1529 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1530 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1531
1532 if (kGL_GrGLStandard == standard) {
1533 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1534 hasFPTextures = true;
1535 hasHalfFPTextures = true;
1536 }
1537 } else {
1538 if (version >= GR_GL_VER(3, 1)) {
1539 hasFPTextures = true;
1540 hasHalfFPTextures = true;
1541 } else {
1542 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1543 ctxInfo.hasExtension("GL_OES_texture_float")) {
1544 hasFPTextures = true;
1545 }
1546 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1547 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1548 hasHalfFPTextures = true;
1549 }
1550 }
1551 }
bsalomon30447372015-12-21 09:03:05 -08001552
1553 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1554 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001555 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1556 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001557 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001558 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001559 if (hasFPTextures) {
1560 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1561 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1562 // many precision issues and no clients actually want this yet.
1563 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1564 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1565 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1566 }
1567 }
cblume790d5132016-02-29 11:13:29 -08001568 if (texStorageSupported) {
1569 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1570 }
bsalomoncdee0092016-01-08 13:20:12 -08001571 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001572
1573 if (this->textureRedSupport()) {
1574 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1575 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001576 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1577 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001578 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001579 } else {
1580 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1581 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001582 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1583 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001584 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001585 }
1586 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1587 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1588 } else {
1589 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1590 }
bsalomon7928ef62016-01-05 10:26:39 -08001591 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001592 if (hasHalfFPTextures) {
1593 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1594 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1595 // GL_RED internal format.
1596 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1597 (this->textureRedSupport() &&
1598 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1599 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1600 }
1601 }
cblume790d5132016-02-29 11:13:29 -08001602 if (texStorageSupported) {
1603 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1604 }
bsalomon30447372015-12-21 09:03:05 -08001605
1606 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1607 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001608 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1609 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001610 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1611 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1612 } else {
1613 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1614 }
bsalomon7928ef62016-01-05 10:26:39 -08001615 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001616 if (hasHalfFPTextures) {
1617 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1618 // ES requires 3.2 or EXT_color_buffer_half_float.
1619 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1620 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1621 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1622 }
1623 }
cblume790d5132016-02-29 11:13:29 -08001624 if (texStorageSupported) {
1625 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1626 }
bsalomoncdee0092016-01-08 13:20:12 -08001627 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001628
1629 // Compressed texture support
1630
1631 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1632 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1633
1634 // TODO: Fix command buffer bindings and remove this.
1635 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001636
1637 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001638 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001639
1640 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1641 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001642 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001643 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001644 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001645 // Disable this for now, while we investigate https://bug.skia.org/4333
1646 if (false) {
1647 // Check for 8-bit palette..
1648 GrGLint numFormats;
1649 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1650 if (numFormats) {
1651 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1652 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1653 for (int i = 0; i < numFormats; ++i) {
1654 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1655 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1656 break;
1657 }
1658 }
1659 }
1660 }
bsalomoncdee0092016-01-08 13:20:12 -08001661 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001662
bsalomon41e4384e2016-01-08 09:12:44 -08001663 // May change the internal format based on extensions.
1664 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1665 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1666 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1667 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1668 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1669 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1670 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1671 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1672 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1673 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1674 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1675 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1676 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1677 GR_GL_COMPRESSED_RED_RGTC1;
1678 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1679 GR_GL_COMPRESSED_RED_RGTC1;
1680 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1681 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1682 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1683 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1684 GR_GL_COMPRESSED_3DC_X;
1685
bsalomon30447372015-12-21 09:03:05 -08001686 }
bsalomon76148af2016-01-12 11:13:47 -08001687 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001688 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001689 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001690 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001691
1692 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1693 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001694 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001695 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001696 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001697 if (kGL_GrGLStandard == standard) {
1698 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1699 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1700 }
1701 } else {
1702 if (version >= GR_GL_VER(3, 0) ||
1703 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1704 // ETC2 is a superset of ETC1, so we can just check for that, too.
1705 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1706 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1707 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1708 }
1709 }
bsalomoncdee0092016-01-08 13:20:12 -08001710 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001711
1712 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1713 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001714 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001715 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001716 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001717 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1718 // decompressing the textures in the driver, and is generally slower.
1719 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1720 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1721 }
bsalomoncdee0092016-01-08 13:20:12 -08001722 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001723
1724 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1725 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1726 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1727 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001728 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1729 0;
bsalomon30447372015-12-21 09:03:05 -08001730 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001731 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001732 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1733 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1734 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1735 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1736 }
bsalomoncdee0092016-01-08 13:20:12 -08001737 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001738
1739 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1740
1741 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001742 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1743 ctxInfo.version() >= GR_GL_VER(3,0));
1744 // All ES versions (thus far) require sized internal formats for render buffers.
1745 // TODO: Always use sized internal format?
1746 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1747
bsalomon30447372015-12-21 09:03:05 -08001748 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001749 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1750 // param to glTex[Sub]Image.
1751 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1752 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1753 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1754 fConfigTable[i].fFormats.fSizedInternalFormat :
1755 fConfigTable[i].fFormats.fBaseInternalFormat;
1756 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001757 fConfigTable[i].fFormats.fSizedInternalFormat :
1758 fConfigTable[i].fFormats.fBaseInternalFormat;
1759 }
1760 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1761 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1762 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1763 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1764 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001765 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001766 GR_GL_SRGB_ALPHA;
1767 }
1768
1769 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1770 // as a base format.
1771 // GL_EXT_texture_format_BGRA8888:
1772 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1773 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1774 // formats.
1775 // GL_APPLE_texture_format_BGRA8888:
1776 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1777 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1778 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001779 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001780 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1781 }
1782
bsalomoncdee0092016-01-08 13:20:12 -08001783 // If we don't have texture swizzle support then the shader generator must insert the
1784 // swizzle into shader code.
1785 if (!this->textureSwizzleSupport()) {
1786 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1787 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1788 }
1789 }
1790
bsalomon7f9b2e42016-01-12 13:29:26 -08001791 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1792 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1793 // gets written to the single component.
1794 if (this->textureRedSupport()) {
1795 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1796 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1797 if (GrPixelConfigIsAlphaOnly(config) &&
1798 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1799 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1800 }
1801 }
1802 }
1803
bsalomon30447372015-12-21 09:03:05 -08001804#ifdef SK_DEBUG
1805 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001806 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001807 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001808 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1809 fConfigTable[i].fFormats.fBaseInternalFormat);
1810 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001811 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001812 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1813 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1814 fConfigTable[i].fFormats.fExternalFormat[j]);
1815 }
1816 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001817 }
1818#endif
1819}
1820
egdanielb7e7d572015-11-04 04:23:53 -08001821void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}