blob: 792f3ed5ba63555bb4305c247531ba6790a571e3 [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;
piotaixre4b23142014-10-02 10:57:53 -070055
bsalomon083617b2016-02-12 12:10:14 -080056 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
57
halcanary385fe4d2015-08-26 13:07:48 -070058 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070059
cdalton4cd67132015-06-10 19:23:46 -070060 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000061}
62
cdalton4cd67132015-06-10 19:23:46 -070063void GrGLCaps::init(const GrContextOptions& contextOptions,
64 const GrGLContextInfo& ctxInfo,
65 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000066 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000067 GrGLVersion version = ctxInfo.version();
68
bsalomon@google.combcce8922013-03-25 15:38:39 +000069 /**************************************************************************
70 * Caps specific to GrGLCaps
71 **************************************************************************/
72
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000073 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000074 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
75 &fMaxFragmentUniformVectors);
76 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000077 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000078 GrGLint max;
79 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
80 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000081 if (version >= GR_GL_VER(3, 2)) {
82 GrGLint profileMask;
83 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
84 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
85 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000087 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000088 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000090 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000091 fUnpackRowLengthSupport = true;
92 fUnpackFlipYSupport = false;
93 fPackRowLengthSupport = true;
94 fPackFlipYSupport = false;
95 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000096 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
97 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000099 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
100 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 fPackFlipYSupport =
102 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
103 }
104
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000105 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000106 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
107
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000108 if (kGL_GrGLStandard == standard) {
cdaltonfd4167d2015-04-21 11:45:56 -0700109 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
110 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
111 ctxInfo.hasExtension("GL_NV_texture_barrier");
112 } else {
113 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
114 }
115
cdaltoneb79eea2016-02-26 10:39:34 -0800116 if (kGL_GrGLStandard == standard) {
117 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
118 ctxInfo.hasExtension("GL_ARB_texture_multisample");
119 } else {
120 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
121 }
122
hendrikwa0d5ad72014-12-02 07:30:30 -0800123 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
124 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700125 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800126 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000127 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
128 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800129 } else {
130 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
131 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000132 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000133 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000134 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000135 ctxInfo.hasExtension("GL_ARB_imaging");
136
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000137 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
138 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
139 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
140 // limit this decision to specific GPU families rather than basing it on the vendor alone.
141 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700142 (kARM_GrGLVendor == ctxInfo.vendor() ||
143 kImagination_GrGLVendor == ctxInfo.vendor() ||
144 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000145 fUseNonVBOVertexAndIndexDynamicData = true;
146 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000147
egdaniel9250d242015-05-18 13:04:26 -0700148 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
149 // Thus we are blacklisting this extension for now on Adreno4xx devices.
150 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
151 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
152 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
153 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000154 fDiscardRenderTargetSupport = true;
155 fInvalidateFBType = kInvalidate_InvalidateFBType;
156 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
157 fDiscardRenderTargetSupport = true;
158 fInvalidateFBType = kDiscard_InvalidateFBType;
159 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000160
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000161 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
162 fFullClearIsFree = true;
163 }
164
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000165 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000166 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800167 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
168 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000169 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000170 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
171 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000172 }
173
cdalton626e1ff2015-06-12 13:56:46 -0700174 if (kGL_GrGLStandard == standard) {
175 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
176 } else {
177 fDirectStateAccessSupport = false;
178 }
179
180 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
181 fDebugSupport = true;
182 } else {
183 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
184 }
185
jvanverth3f801cb2014-12-16 09:49:38 -0800186 if (kGL_GrGLStandard == standard) {
187 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
188 }
189 else {
190 fES2CompatibilitySupport = true;
191 }
192
cdalton0edea2c2015-05-21 08:27:44 -0700193 if (kGL_GrGLStandard == standard) {
194 fMultisampleDisableSupport = true;
195 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700196 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700197 }
198
kkinnunend94708e2015-07-30 22:47:04 -0700199 if (kGL_GrGLStandard == standard) {
200 if (version >= GR_GL_VER(3, 0)) {
201 fBindFragDataLocationSupport = true;
202 }
203 } else {
204 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
205 fBindFragDataLocationSupport = true;
206 }
joshualittc1f56b52015-06-22 12:31:31 -0700207 }
208
bsalomonb8909d32016-01-28 07:09:52 -0800209#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700210 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800211#else
212 fBindUniformLocationSupport = false;
213#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700214
bsalomon7ea33f52015-11-22 14:51:00 -0800215 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
216 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
217 fExternalTextureSupport = true;
218 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
219 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
220 // At least one driver has been found that has this extension without the "GL_" prefix.
221 fExternalTextureSupport = true;
222 }
223 }
224
kkinnunene06ed252016-02-16 23:15:40 -0800225 if (kGL_GrGLStandard == standard) {
226 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
227 // We also require textureSize() support for rectangle 2D samplers which was added in
228 // GLSL 1.40.
229 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
230 fRectangleTextureSupport = true;
231 }
bsalomone179a912016-01-20 06:18:10 -0800232 }
kkinnunene06ed252016-02-16 23:15:40 -0800233 } else {
234 // Command buffer exposes this in GL ES context for Chromium reasons,
235 // but it should not be used. Also, at the time of writing command buffer
236 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800237 }
238
bsalomoncdee0092016-01-08 13:20:12 -0800239 if (kGL_GrGLStandard == standard) {
240 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
241 fTextureSwizzleSupport = true;
242 }
243 } else {
244 if (version >= GR_GL_VER(3,0)) {
245 fTextureSwizzleSupport = true;
246 }
247 }
248
bsalomon88c7b982015-07-31 11:20:16 -0700249#ifdef SK_BUILD_FOR_WIN
250 // We're assuming that on Windows Chromium we're using ANGLE.
251 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
252 kChromium_GrGLDriver == ctxInfo.driver();
253 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
254 fRGBA8888PixelsOpsAreSlow = isANGLE;
255 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
256 // check DX11 ANGLE.
257 fPartialFBOReadIsSlow = isANGLE;
258#endif
259
cdalton4cd67132015-06-10 19:23:46 -0700260 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700261 * GrShaderCaps fields
262 **************************************************************************/
263
egdaniel0a482332015-10-26 08:59:10 -0700264 // This must be called after fCoreProfile is set on the GrGLCaps
265 this->initGLSL(ctxInfo);
266 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
267
egdaniel05ded892015-10-26 07:38:05 -0700268 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
269
270 // For now these two are equivalent but we could have dst read in shader via some other method.
271 // Before setting this, initGLSL() must have been called.
272 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
273
274 // Enable supported shader-related caps
275 if (kGL_GrGLStandard == standard) {
276 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
277 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
278 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
279 glslCaps->fShaderDerivativeSupport = true;
280 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
281 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
282 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800283 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
284 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700285 }
286 else {
287 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
288
289 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
290 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800291
292 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
293 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700294 }
295
ethannicholas22793252016-01-30 09:59:10 -0800296 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
297 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
298 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
299 &glslCaps->fPixelLocalStorageSize);
300 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
301 }
302 else {
303 glslCaps->fPixelLocalStorageSize = 0;
304 glslCaps->fPLSPathRenderingSupport = false;
305 }
306
egdaniel05ded892015-10-26 07:38:05 -0700307 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700308 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000309 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700310
cdalton63f6c1f2015-11-06 07:09:43 -0800311 // We need dual source blending and the ability to disable multisample in order to support mixed
312 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800313 if (fMultisampleDisableSupport &&
314 glslCaps->dualSourceBlendingSupport() &&
315 fShaderCaps->pathRenderingSupport()) {
316 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800317 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800318 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800319 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
320 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800321 fDiscardRenderTargetSupport = false;
322 fInvalidateFBType = kNone_InvalidateFBType;
323 }
324 }
325
egdanieleed519e2016-01-15 11:36:18 -0800326 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700327 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700328 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700329 this->initStencilFormats(ctxInfo);
330
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000331 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000332 // we could also look for GL_ATI_separate_stencil extension or
333 // GL_EXT_stencil_two_side but they use different function signatures
334 // than GL2.0+ (and than each other).
335 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
336 // supported on GL 1.4 and higher or by extension
337 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
338 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
339 } else {
340 // ES 2 has two sided stencil and stencil wrap
341 fTwoSidedStencilSupport = true;
342 fStencilWrapOpsSupport = true;
343 }
344
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000345 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000346 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
347 // extension includes glMapBuffer.
348 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
349 fMapBufferFlags |= kSubset_MapFlag;
350 fMapBufferType = kMapBufferRange_MapBufferType;
351 } else {
352 fMapBufferType = kMapBuffer_MapBufferType;
353 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000354 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000355 // Unextended GLES2 doesn't have any buffer mapping.
356 fMapBufferFlags = kNone_MapBufferType;
kkinnunen45c2c812016-02-25 02:03:43 -0800357 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000358 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
359 fMapBufferType = kMapBufferRange_MapBufferType;
kkinnunen45c2c812016-02-25 02:03:43 -0800360 } else if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
361 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
362 fMapBufferType = kChromium_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000363 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
364 fMapBufferFlags = kCanMap_MapFlag;
365 fMapBufferType = kMapBuffer_MapBufferType;
366 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000367 }
368
jvanverthd7a2c1f2015-12-07 07:36:44 -0800369 if (kGL_GrGLStandard == standard) {
370 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
371 fTransferBufferType = kPBO_TransferBufferType;
372 }
373 } else {
374 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
375 fTransferBufferType = kPBO_TransferBufferType;
376 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
377 fTransferBufferType = kChromium_TransferBufferType;
378 }
379 }
380
joshualitte5b74c62015-06-01 14:17:47 -0700381 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
382 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
383 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700384 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
385 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
386 // a small subset.
387#if 0
cdalton1acea862015-06-02 13:05:52 -0700388 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700389#else
390 fGeometryBufferMapThreshold = SK_MaxS32;
391#endif
joshualitte5b74c62015-06-01 14:17:47 -0700392 }
393
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000394 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000395 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
396 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
397 fNPOTTextureTileSupport = true;
398 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000399 } else {
400 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000401 // ES3 has no limitations.
402 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
403 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000404 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
405 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
406 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
407 // to alllow arbitrary wrap modes, however.
408 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000409 }
410
bsalomone72bd022015-10-26 07:33:03 -0700411 // Using MIPs on this GPU seems to be a source of trouble.
412 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
413 fMipMapSupport = false;
414 }
415
bsalomon@google.combcce8922013-03-25 15:38:39 +0000416 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
417 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
418 // Our render targets are always created with textures as the color
419 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000420 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000421
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000422 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
423
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000424 // Disable scratch texture reuse on Mali and Adreno devices
425 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
426 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000427
robertphillips1b8e1b52015-06-24 06:54:10 -0700428#if 0
429 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
430 kQualcomm_GrGLVendor != ctxInfo.vendor();
431#endif
432
egdaniel05ded892015-10-26 07:38:05 -0700433 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000434 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800435 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000436 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800437 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000438 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800439 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
440 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
441 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
442 // This is to guard against platforms that may not support as many samples for
443 // glRasterSamples as they do for framebuffers.
444 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
445 }
446 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000447
bsalomon63b21962014-11-05 07:05:34 -0800448 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800449 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800450 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800451 fUseDrawInsteadOfClear = true;
452 }
453
joshualitt83bc2292015-06-18 14:18:02 -0700454 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
455 fUseDrawInsteadOfPartialRenderTargetWrite = true;
456 }
457
bsalomonbabafcc2016-02-16 11:36:47 -0800458 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
459 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
460 fUseDrawInsteadOfPartialRenderTargetWrite = true;
461 fUseDrawInsteadOfAllRenderTargetWrites = true;
462 }
463
robertphillips63926682015-08-20 09:39:02 -0700464#ifdef SK_BUILD_FOR_WIN
465 // On ANGLE deferring flushes can lead to GPU starvation
466 fPreferVRAMUseOverFlushes = !isANGLE;
467#endif
468
bsalomon7dea7b72015-08-19 08:26:51 -0700469 if (kChromium_GrGLDriver == ctxInfo.driver()) {
470 fMustClearUploadedBufferData = true;
471 }
472
bsalomond08ea5f2015-02-20 06:58:13 -0800473 if (kGL_GrGLStandard == standard) {
474 // ARB allows mixed size FBO attachments, EXT does not.
475 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
476 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
477 fOversizedStencilSupport = true;
478 } else {
479 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
480 }
481 } else {
482 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
483 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
484 }
485
joshualitt58001552015-06-26 12:46:36 -0700486 if (kGL_GrGLStandard == standard) {
487 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
488 // instanced arrays, but we could make this more granular if we wanted
489 fSupportsInstancedDraws =
490 version >= GR_GL_VER(3, 2) ||
491 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
492 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
493 } else {
494 fSupportsInstancedDraws =
495 version >= GR_GL_VER(3, 0) ||
496 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
497 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
498 }
499
cdalton06604b92016-02-05 10:09:51 -0800500 if (kGL_GrGLStandard == standard) {
501 // We don't use ARB_draw_indirect because it does not support a base instance.
502 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
503 fDrawIndirectSupport =
504 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
505 } else {
506 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
507 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
508 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
509 }
510
jvanverthcba99b82015-06-24 06:59:57 -0700511 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800512
513 if (contextOptions.fUseShaderSwizzling) {
514 fTextureSwizzleSupport = false;
515 }
516
kkinnunen45c2c812016-02-25 02:03:43 -0800517 // TODO: remove after command buffer supports full ES 3.0.
518 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3, 0) &&
519 kChromium_GrGLDriver == ctxInfo.driver()) {
kkinnunen45c2c812016-02-25 02:03:43 -0800520 fSupportsInstancedDraws = false;
521 fTextureSwizzleSupport = false;
522 SkASSERT(ctxInfo.hasExtension("GL_CHROMIUM_map_sub"));
523 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
524 fMapBufferType = kChromium_MapBufferType;
525 }
526
bsalomoncdee0092016-01-08 13:20:12 -0800527 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
528 // already been detected.
529 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700530
531 this->applyOptionsOverrides(contextOptions);
532 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000533}
534
egdaniel472d44e2015-10-22 08:20:00 -0700535const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
536 bool isCoreProfile) {
537 switch (generation) {
538 case k110_GrGLSLGeneration:
539 if (kGLES_GrGLStandard == standard) {
540 // ES2s shader language is based on version 1.20 but is version
541 // 1.00 of the ES language.
542 return "#version 100\n";
543 } else {
544 SkASSERT(kGL_GrGLStandard == standard);
545 return "#version 110\n";
546 }
547 case k130_GrGLSLGeneration:
548 SkASSERT(kGL_GrGLStandard == standard);
549 return "#version 130\n";
550 case k140_GrGLSLGeneration:
551 SkASSERT(kGL_GrGLStandard == standard);
552 return "#version 140\n";
553 case k150_GrGLSLGeneration:
554 SkASSERT(kGL_GrGLStandard == standard);
555 if (isCoreProfile) {
556 return "#version 150\n";
557 } else {
558 return "#version 150 compatibility\n";
559 }
560 case k330_GrGLSLGeneration:
561 if (kGLES_GrGLStandard == standard) {
562 return "#version 300 es\n";
563 } else {
564 SkASSERT(kGL_GrGLStandard == standard);
565 if (isCoreProfile) {
566 return "#version 330\n";
567 } else {
568 return "#version 330 compatibility\n";
569 }
570 }
cdalton33ad7012016-02-22 07:55:44 -0800571 case k400_GrGLSLGeneration:
572 SkASSERT(kGL_GrGLStandard == standard);
573 if (isCoreProfile) {
574 return "#version 400\n";
575 } else {
576 return "#version 400 compatibility\n";
577 }
egdaniel472d44e2015-10-22 08:20:00 -0700578 case k310es_GrGLSLGeneration:
579 SkASSERT(kGLES_GrGLStandard == standard);
580 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800581 case k320es_GrGLSLGeneration:
582 SkASSERT(kGLES_GrGLStandard == standard);
583 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700584 }
585 return "<no version>";
586}
587
egdaniel05ded892015-10-26 07:38:05 -0700588void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700589 GrGLStandard standard = ctxInfo.standard();
590 GrGLVersion version = ctxInfo.version();
591
592 /**************************************************************************
593 * Caps specific to GrGLSLCaps
594 **************************************************************************/
595
596 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
597 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700598 if (kGLES_GrGLStandard == standard) {
599 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
600 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
601 glslCaps->fFBFetchSupport = true;
602 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
603 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
604 }
605 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
606 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
607 glslCaps->fFBFetchNeedsCustomOutput = false;
608 glslCaps->fFBFetchSupport = true;
609 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
610 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
611 }
612 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
613 // The arm extension also requires an additional flag which we will set onResetContext
614 glslCaps->fFBFetchNeedsCustomOutput = false;
615 glslCaps->fFBFetchSupport = true;
616 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
617 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
618 }
619 glslCaps->fUsesPrecisionModifiers = true;
620 }
621
622 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
623
cdaltonc08f1962016-02-12 12:14:06 -0800624 if (kGL_GrGLStandard == standard) {
625 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
626 } else {
627 glslCaps->fFlatInterpolationSupport =
628 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
629 }
630
631 if (kGL_GrGLStandard == standard) {
632 glslCaps->fNoPerspectiveInterpolationSupport =
633 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
634 } else {
635 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
636 glslCaps->fNoPerspectiveInterpolationSupport = true;
637 glslCaps->fNoPerspectiveInterpolationExtensionString =
638 "GL_NV_shader_noperspective_interpolation";
639 }
640 }
641
cdalton33ad7012016-02-22 07:55:44 -0800642 if (kGL_GrGLStandard == standard) {
643 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
644 } else {
645 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
646 glslCaps->fSampleVariablesSupport = true;
647 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
648 glslCaps->fSampleVariablesSupport = true;
649 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
650 }
651 }
652
653 if (glslCaps->fSampleVariablesSupport) {
654 glslCaps->fSampleMaskOverrideCoverageSupport =
655 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
656 }
657
egdaniel472d44e2015-10-22 08:20:00 -0700658 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
659 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
660
661 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
662 // function that may require a gradient calculation inside a conditional block may return
663 // undefined results". This appears to be an issue with the 'any' call since even the simple
664 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
665 // from our GrTextureDomain processor.
666 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
667
egdaniel472d44e2015-10-22 08:20:00 -0700668 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
669 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800670
671 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
672 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
673 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800674
675 // Frag Coords Convention support is not part of ES
676 // Known issue on at least some Intel platforms:
677 // http://code.google.com/p/skia/issues/detail?id=946
678 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
679 kGLES_GrGLStandard != standard &&
680 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
681 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
682 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
683 }
684
685 if (kGLES_GrGLStandard == standard) {
686 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
687 }
688
bsalomon7ea33f52015-11-22 14:51:00 -0800689 if (fExternalTextureSupport) {
690 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
691 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
692 } else {
693 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
694 }
695 }
696
egdaniel8dcdedc2015-11-11 06:27:20 -0800697 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
698 // the abs first in a separate expression.
699 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
700 glslCaps->fCanUseMinAndAbsTogether = false;
701 }
702
bsalomon7ea33f52015-11-22 14:51:00 -0800703 // 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 -0800704 // thus must us -1.0 * %s.x to work correctly
705 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
706 glslCaps->fMustForceNegatedAtanParamToFloat = true;
707 }
egdaniel472d44e2015-10-22 08:20:00 -0700708}
709
kkinnunencfe62e32015-07-01 02:58:50 -0700710bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700711 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
712
713 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700714 return false;
715 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700716
kkinnunencfe62e32015-07-01 02:58:50 -0700717 if (kGL_GrGLStandard == ctxInfo.standard()) {
718 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
719 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
720 return false;
721 }
722 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700723 if (!hasChromiumPathRendering &&
724 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700725 return false;
726 }
727 }
728 // We only support v1.3+ of GL_NV_path_rendering which allows us to
729 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
730 // additions are detected by checking the existence of the function.
731 // We also use *Then* functions that not all drivers might have. Check
732 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800733 if (!gli->fFunctions.fStencilThenCoverFillPath ||
734 !gli->fFunctions.fStencilThenCoverStrokePath ||
735 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
736 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
737 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700738 return false;
739 }
740 return true;
741}
bsalomon1aa20292016-01-22 08:16:09 -0800742
743bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800744 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800745 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
746 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800747 // If it's not possible to even have a render target of rtConfig then read pixels is
748 // not supported regardless of readConfig.
749 if (!this->isConfigRenderable(rtConfig, false)) {
750 return false;
751 }
bsalomon7928ef62016-01-05 10:26:39 -0800752
bsalomon76148af2016-01-12 11:13:47 -0800753 GrGLenum readFormat;
754 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800755 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800756 return false;
757 }
758
bsalomon1aa20292016-01-22 08:16:09 -0800759 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800760 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
761 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
762 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
763 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
764 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
765 readFormat != GR_GL_BGRA) {
766 return false;
767 }
768 // There is also a set of allowed types, but all the types we use are in the set:
769 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
770 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
771 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
772 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
773 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
774 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
775 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800776 return true;
piotaixre4b23142014-10-02 10:57:53 -0700777 }
bsalomon7928ef62016-01-05 10:26:39 -0800778
bsalomon76148af2016-01-12 11:13:47 -0800779 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800780
bsalomon1aa20292016-01-22 08:16:09 -0800781 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800782 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
783 return true;
784 }
785 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800786 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800787 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
788 return true;
789 }
790 }
791
bsalomon1aa20292016-01-22 08:16:09 -0800792 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800793 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800794 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800795 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800796 if (!bindRenderTarget()) {
797 return false;
798 }
799 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
800 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800801 rpFormat->fFormat = format;
802 rpFormat->fType = type;
803 }
804
bsalomon1aa20292016-01-22 08:16:09 -0800805 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
806 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700807}
808
robertphillips@google.com6177e692013-02-28 20:16:25 +0000809void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000810
811 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000812 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000813 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
814 // ES3 driver bugs on at least one device with a tiled GPU (N10).
815 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
816 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
817 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
818 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800819 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700820 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000821 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000822 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
823 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
824 // chrome's extension is equivalent to the EXT msaa
825 // and fbo_blit extensions.
826 fMSFBOType = kDesktop_EXT_MSFBOType;
827 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
828 fMSFBOType = kES_Apple_MSFBOType;
829 }
bsalomon083617b2016-02-12 12:10:14 -0800830
831 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
832 // is available.
833 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
834 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
835 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
836 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
837 // limitations.
838 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
839 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000840 } else {
egdanieleed519e2016-01-15 11:36:18 -0800841 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700842 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800843 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700844 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000845 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000846 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800847 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000848 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
849 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000850 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800851 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000852 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000853 }
854}
855
cdalton1dd05422015-06-12 09:01:18 -0700856void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
857 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
858
859 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
860 // for now until its own blacklists can be updated.
861 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
862 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700863 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700864 return;
865 }
866
867 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
868 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
869 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
870 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
871 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
872 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
873 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
874 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
875 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
876 return;
877 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
878 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
879 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
880 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
881 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
882 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
883 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
884 // slow on a particular platform.
885 } else {
886 return; // No advanced blend support.
887 }
888
889 SkASSERT(this->advancedBlendEquationSupport());
890
891 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
892 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
893 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
894 (1 << kColorBurn_GrBlendEquation);
895 }
joel.liang9764c402015-07-09 19:46:18 -0700896 if (kARM_GrGLVendor == ctxInfo.vendor()) {
897 // Blacklist color-burn on ARM until the fix is released.
898 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
899 }
cdalton1dd05422015-06-12 09:01:18 -0700900}
901
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000902namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700903const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000904}
905
906void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
907
908 // Build up list of legal stencil formats (though perhaps not supported on
909 // the particular gpu/driver) from most preferred to least.
910
911 // these consts are in order of most preferred to least preferred
912 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
913
914 static const StencilFormat
915 // internal Format stencil bits total bits packed?
916 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
917 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
918 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
919 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000920 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000921 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
922
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000923 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000924 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000925 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000926 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
927 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
928
929 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
930 // require FBO support we can expect these are legal formats and don't
931 // check. These also all support the unsized GL_STENCIL_INDEX.
932 fStencilFormats.push_back() = gS8;
933 fStencilFormats.push_back() = gS16;
934 if (supportsPackedDS) {
935 fStencilFormats.push_back() = gD24S8;
936 }
937 fStencilFormats.push_back() = gS4;
938 if (supportsPackedDS) {
939 fStencilFormats.push_back() = gDS;
940 }
941 } else {
942 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
943 // for other formats.
944 // ES doesn't support using the unsized format.
945
946 fStencilFormats.push_back() = gS8;
947 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000948 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
949 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000950 fStencilFormats.push_back() = gD24S8;
951 }
952 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
953 fStencilFormats.push_back() = gS4;
954 }
955 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000956}
957
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000958SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000959
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000960 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000961
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000962 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000963 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000964 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000965 i,
966 fStencilFormats[i].fStencilBits,
967 fStencilFormats[i].fTotalBits);
968 }
969
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000970 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000971 "None",
972 "ARB",
973 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000974 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000975 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000976 "IMG MS To Texture",
977 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -0700978 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000979 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000980 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
981 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
982 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000983 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
984 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
985 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
986 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -0700987 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000988 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000989
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000990 static const char* kInvalidateFBTypeStr[] = {
991 "None",
992 "Discard",
993 "Invalidate",
994 };
995 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
996 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
997 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
998 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000999
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001000 static const char* kMapBufferTypeStr[] = {
1001 "None",
1002 "MapBuffer",
1003 "MapBufferRange",
1004 "Chromium",
1005 };
1006 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1007 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1008 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1009 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1010 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1011
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001012 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001013 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001014 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001015 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001016 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1017 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001018 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001019 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1020 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1021 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1022 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001023
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001024 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001025 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1026 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001027 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001028 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1029 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001030 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001031 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1032 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1033 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001034 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001035 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001036 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001037 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1038 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001039 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001040 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001041 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001042 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001043
1044 r.append("Configs\n-------\n");
1045 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1046 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001047 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1048 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001049 i,
1050 fConfigTable[i].fFlags,
1051 fConfigTable[i].fFormats.fBaseInternalFormat,
1052 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001053 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1054 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001055 fConfigTable[i].fFormats.fExternalType,
1056 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001057 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001058 }
1059
jvanverthe9c0fc62015-04-29 11:18:05 -07001060 return r;
1061}
1062
jvanverthe9c0fc62015-04-29 11:18:05 -07001063static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1064 switch (p) {
1065 case kLow_GrSLPrecision:
1066 return GR_GL_LOW_FLOAT;
1067 case kMedium_GrSLPrecision:
1068 return GR_GL_MEDIUM_FLOAT;
1069 case kHigh_GrSLPrecision:
1070 return GR_GL_HIGH_FLOAT;
1071 }
1072 SkFAIL("Unknown precision.");
1073 return -1;
1074}
1075
1076static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1077 switch (type) {
1078 case kVertex_GrShaderType:
1079 return GR_GL_VERTEX_SHADER;
1080 case kGeometry_GrShaderType:
1081 return GR_GL_GEOMETRY_SHADER;
1082 case kFragment_GrShaderType:
1083 return GR_GL_FRAGMENT_SHADER;
1084 }
1085 SkFAIL("Unknown shader type.");
1086 return -1;
1087}
1088
jvanverthcba99b82015-06-24 06:59:57 -07001089void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1090 const GrGLInterface* intf,
1091 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001092 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1093 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1094 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1095 if (kGeometry_GrShaderType != s) {
1096 GrShaderType shaderType = static_cast<GrShaderType>(s);
1097 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001098 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001099 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001100 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1101 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1102 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1103 GrGLint range[2];
1104 GrGLint bits;
1105 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1106 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001107 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1108 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1109 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001110 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001111 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001112 }
jvanverthcba99b82015-06-24 06:59:57 -07001113 else if (!glslCaps->fShaderPrecisionVaries) {
1114 glslCaps->fShaderPrecisionVaries =
1115 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001116 }
1117 }
1118 }
1119 }
1120 }
1121 }
1122 else {
1123 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001124 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001125 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1126 if (kGeometry_GrShaderType != s) {
1127 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001128 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1129 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1130 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001131 }
1132 }
1133 }
1134 }
1135 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1136 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1137 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1138 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001139 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001140 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001141 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1142 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001143 }
1144 }
1145}
1146
bsalomon41e4384e2016-01-08 09:12:44 -08001147bool GrGLCaps::bgraIsInternalFormat() const {
1148 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1149}
1150
bsalomon76148af2016-01-12 11:13:47 -08001151bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1152 GrGLenum* internalFormat, GrGLenum* externalFormat,
1153 GrGLenum* externalType) const {
1154 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1155 externalFormat, externalType)) {
1156 return false;
1157 }
1158 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1159 return true;
1160}
1161
1162bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1163 GrGLenum* internalFormat) const {
1164 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1165 return false;
1166 }
1167 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1168 return true;
1169}
1170
1171bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1172 GrGLenum* externalFormat, GrGLenum* externalType) const {
1173 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1174 externalFormat, externalType)) {
1175 return false;
1176 }
1177 return true;
1178}
1179
1180bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1181 if (GrPixelConfigIsCompressed(config)) {
1182 return false;
1183 }
1184 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1185 return true;
1186}
1187
1188bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1189 ExternalFormatUsage usage, GrGLenum* externalFormat,
1190 GrGLenum* externalType) const {
1191 SkASSERT(externalFormat && externalType);
1192 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1193 return false;
1194 }
1195
1196 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1197 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1198
1199 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1200 // made to work in many cases using glPixelStore and what not but is not needed currently.
1201 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1202 return false;
1203 }
1204
1205 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1206 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1207
bsalomone9573312016-01-25 14:33:25 -08001208 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1209 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1210 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1211 // texture, not the red component.
1212 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1213 if (this->textureRedSupport()) {
1214 SkASSERT(GR_GL_RED == *externalFormat);
1215 *externalFormat = GR_GL_ALPHA;
1216 }
1217 }
1218
bsalomon76148af2016-01-12 11:13:47 -08001219 return true;
1220}
1221
bsalomoncdee0092016-01-08 13:20:12 -08001222void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1223 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001224 /*
1225 Comments on renderability of configs on various GL versions.
1226 OpenGL < 3.0:
1227 no built in support for render targets.
1228 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1229 format RGB, RGBA and NV float formats we don't use.
1230 This is the following:
1231 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1232 RGB10_A2, RGBA12,RGBA16
1233 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1234 since they aren't required by later standards and the driver can simply return
1235 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1236 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1237 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1238 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1239 This adds a lot of additional renderable sized formats, including ALPHA8.
1240 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1241 16F, 32I, 32UI, and 32F variants).
1242 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1243
1244 For both the above extensions we limit ourselves to those that are also required by
1245 OpenGL 3.0.
1246
1247 OpenGL 3.0:
1248 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1249 but are not required to be supported as renderable textures/renderbuffer.
1250 Required renderable color formats:
1251 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1252 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1253 RGB10_A2.
1254 - R11F_G11F_B10F.
1255 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1256 and RG8UI.
1257 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1258 - ALPHA8
1259
1260 OpenGL 3.1, 3.2, 3.3
1261 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1262 OpengGL 3.3, 4.0, 4.1
1263 Adds RGB10_A2UI.
1264 OpengGL 4.2
1265 Adds
1266 - RGB5_A1, RGBA4
1267 - RGB565
1268 OpenGL 4.4
1269 Does away with the separate list and adds a column to the sized internal color format
1270 table. However, no new formats become required color renderable.
1271
1272 ES 2.0
1273 color renderable: RGBA4, RGB5_A1, RGB565
1274 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1275 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1276 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1277 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1278 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1279 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1280
1281 ES 3.0
1282 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1283 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1284 RGB5_A1.
1285 - RGB8 and RGB565.
1286 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1287 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1288 ES 3.1
1289 Adds RGB10_A2, RGB10_A2UI,
1290 ES 3.2
1291 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1292 */
1293 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1294 if (kNone_MSFBOType != fMSFBOType) {
1295 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1296 }
1297
1298 GrGLStandard standard = ctxInfo.standard();
1299 GrGLVersion version = ctxInfo.version();
1300
cblume790d5132016-02-29 11:13:29 -08001301 bool texStorageSupported = false;
1302 if (kGL_GrGLStandard == standard) {
1303 // The EXT version can apply to either GL or GLES.
1304 texStorageSupported = version >= GR_GL_VER(4,2) ||
1305 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
1306 ctxInfo.hasExtension("GL_EXT_texture_storage");
1307 } else {
1308 // Qualcomm Adreno drivers appear to have issues with texture storage.
1309 texStorageSupported = (version >= GR_GL_VER(3,0) &&
1310 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
1311 ctxInfo.hasExtension("GL_EXT_texture_storage");
1312 }
1313
1314 // TODO: remove after command buffer supports full ES 3.0
1315 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0) &&
1316 kChromium_GrGLDriver == ctxInfo.driver()) {
1317 texStorageSupported = false;
1318 }
1319
bsalomon30447372015-12-21 09:03:05 -08001320 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1321 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001322 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001323 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001324 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001325 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001326
1327 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1328 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001329 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1330 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001331 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001332 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001333 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1334 if (kGL_GrGLStandard == standard) {
1335 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1336 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001337 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001338 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1339 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1340 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1341 }
egdaniel4999df82016-01-07 17:06:04 -08001342 }
cblume790d5132016-02-29 11:13:29 -08001343 if (texStorageSupported) {
1344 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1345 }
bsalomoncdee0092016-01-08 13:20:12 -08001346 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001347
bsalomon76148af2016-01-12 11:13:47 -08001348 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1349 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001350 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001351 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001352 if (kGL_GrGLStandard == standard) {
1353 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1354 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1355 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1356 // Since the internal format is RGBA8, it is also renderable.
1357 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1358 allRenderFlags;
1359 }
1360 } else {
1361 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1362 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1363 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1364 // The APPLE extension doesn't make this renderable.
1365 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1366 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1367 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1368 // Though, that seems to not be the case if the texture storage extension is
1369 // present. The specs don't exactly make that clear.
1370 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1371 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1372 }
1373 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1374 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1375 ConfigInfo::kRenderable_Flag;
1376 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001377 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001378 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1379 ConfigInfo::kRenderableWithMSAA_Flag;
1380 }
1381 }
1382 }
cblume790d5132016-02-29 11:13:29 -08001383 if (texStorageSupported) {
1384 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1385 }
bsalomoncdee0092016-01-08 13:20:12 -08001386 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001387
bsalomon41e4384e2016-01-08 09:12:44 -08001388 // We only enable srgb support if both textures and FBOs support srgb.
1389 bool srgbSupport = false;
1390 if (kGL_GrGLStandard == standard) {
1391 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1392 srgbSupport = true;
1393 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1394 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1395 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1396 srgbSupport = true;
1397 }
1398 }
1399 // All the above srgb extensions support toggling srgb writes
1400 fSRGBWriteControl = srgbSupport;
1401 } else {
1402 // See https://bug.skia.org/4148 for PowerVR issue.
1403 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1404 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1405 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1406 // sRGB writing for destinations.
1407 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1408 }
bsalomon30447372015-12-21 09:03:05 -08001409 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1410 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1411 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1412 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001413 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1414 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001415 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001416 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001417 if (srgbSupport) {
1418 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1419 allRenderFlags;
1420 }
cblume790d5132016-02-29 11:13:29 -08001421 if (texStorageSupported) {
1422 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1423 }
bsalomoncdee0092016-01-08 13:20:12 -08001424 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001425
1426 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1427 if (this->ES2CompatibilitySupport()) {
1428 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1429 } else {
1430 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1431 }
bsalomon76148af2016-01-12 11:13:47 -08001432 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1433 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001434 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001435 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001436 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1437 if (kGL_GrGLStandard == standard) {
1438 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1439 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1440 }
1441 } else {
1442 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1443 }
cblume790d5132016-02-29 11:13:29 -08001444 // 565 is not a sized internal format on desktop GL. So on desktop with
1445 // 565 we always use an unsized internal format to let the system pick
1446 // the best sized format to convert the 565 data to. Since TexStorage
1447 // only allows sized internal formats we disallow it.
1448 //
1449 // TODO: As of 4.2, regular GL supports 565. This logic is due for an
1450 // update.
1451 if (texStorageSupported && kGL_GrGLStandard != standard) {
1452 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1453 }
bsalomoncdee0092016-01-08 13:20:12 -08001454 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001455
1456 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1457 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001458 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1459 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001460 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001461 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001462 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1463 if (kGL_GrGLStandard == standard) {
1464 if (version >= GR_GL_VER(4, 2)) {
1465 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1466 }
1467 } else {
1468 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1469 }
cblume790d5132016-02-29 11:13:29 -08001470 if (texStorageSupported) {
1471 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1472 }
bsalomoncdee0092016-01-08 13:20:12 -08001473 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001474
1475 if (this->textureRedSupport()) {
1476 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1477 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001478 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1479 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001480 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001481 } else {
1482 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1483 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001484 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1485 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001486 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001487 }
1488 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001489 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001490 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1491 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1492 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1493 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1494 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1495 }
cblume790d5132016-02-29 11:13:29 -08001496 if (texStorageSupported) {
1497 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1498 }
bsalomon41e4384e2016-01-08 09:12:44 -08001499
1500 // Check for [half] floating point texture support
1501 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1502 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1503 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1504 bool hasFPTextures = false;
1505 bool hasHalfFPTextures = false;
1506 // for now we don't support floating point MSAA on ES
1507 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1508 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1509
1510 if (kGL_GrGLStandard == standard) {
1511 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1512 hasFPTextures = true;
1513 hasHalfFPTextures = true;
1514 }
1515 } else {
1516 if (version >= GR_GL_VER(3, 1)) {
1517 hasFPTextures = true;
1518 hasHalfFPTextures = true;
1519 } else {
1520 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1521 ctxInfo.hasExtension("GL_OES_texture_float")) {
1522 hasFPTextures = true;
1523 }
1524 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1525 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1526 hasHalfFPTextures = true;
1527 }
1528 }
1529 }
bsalomon30447372015-12-21 09:03:05 -08001530
1531 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1532 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001533 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1534 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001535 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001536 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001537 if (hasFPTextures) {
1538 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1539 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1540 // many precision issues and no clients actually want this yet.
1541 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1542 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1543 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1544 }
1545 }
cblume790d5132016-02-29 11:13:29 -08001546 if (texStorageSupported) {
1547 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1548 }
bsalomoncdee0092016-01-08 13:20:12 -08001549 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001550
1551 if (this->textureRedSupport()) {
1552 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1553 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001554 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1555 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001556 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001557 } else {
1558 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1559 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001560 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1561 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001562 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001563 }
1564 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1565 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1566 } else {
1567 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1568 }
bsalomon7928ef62016-01-05 10:26:39 -08001569 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001570 if (hasHalfFPTextures) {
1571 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1572 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1573 // GL_RED internal format.
1574 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1575 (this->textureRedSupport() &&
1576 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1577 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1578 }
1579 }
cblume790d5132016-02-29 11:13:29 -08001580 if (texStorageSupported) {
1581 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1582 }
bsalomon30447372015-12-21 09:03:05 -08001583
1584 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1585 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001586 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1587 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001588 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1589 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1590 } else {
1591 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1592 }
bsalomon7928ef62016-01-05 10:26:39 -08001593 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001594 if (hasHalfFPTextures) {
1595 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1596 // ES requires 3.2 or EXT_color_buffer_half_float.
1597 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1598 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1599 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1600 }
1601 }
cblume790d5132016-02-29 11:13:29 -08001602 if (texStorageSupported) {
1603 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
1604 }
bsalomoncdee0092016-01-08 13:20:12 -08001605 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001606
1607 // Compressed texture support
1608
1609 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1610 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1611
1612 // TODO: Fix command buffer bindings and remove this.
1613 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001614
1615 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001616 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001617
1618 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1619 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001620 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001621 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001622 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001623 // Disable this for now, while we investigate https://bug.skia.org/4333
1624 if (false) {
1625 // Check for 8-bit palette..
1626 GrGLint numFormats;
1627 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1628 if (numFormats) {
1629 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1630 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1631 for (int i = 0; i < numFormats; ++i) {
1632 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1633 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1634 break;
1635 }
1636 }
1637 }
1638 }
bsalomoncdee0092016-01-08 13:20:12 -08001639 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001640
bsalomon41e4384e2016-01-08 09:12:44 -08001641 // May change the internal format based on extensions.
1642 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1643 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1644 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1645 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1646 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1647 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1648 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1649 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1650 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1651 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1652 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1653 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1654 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1655 GR_GL_COMPRESSED_RED_RGTC1;
1656 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1657 GR_GL_COMPRESSED_RED_RGTC1;
1658 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1659 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1660 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1661 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1662 GR_GL_COMPRESSED_3DC_X;
1663
bsalomon30447372015-12-21 09:03:05 -08001664 }
bsalomon76148af2016-01-12 11:13:47 -08001665 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001666 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001667 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001668 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001669
1670 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1671 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001672 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001673 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001674 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001675 if (kGL_GrGLStandard == standard) {
1676 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1677 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1678 }
1679 } else {
1680 if (version >= GR_GL_VER(3, 0) ||
1681 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1682 // ETC2 is a superset of ETC1, so we can just check for that, too.
1683 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1684 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1685 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1686 }
1687 }
bsalomoncdee0092016-01-08 13:20:12 -08001688 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001689
1690 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1691 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001692 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001693 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001694 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001695 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1696 // decompressing the textures in the driver, and is generally slower.
1697 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1698 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1699 }
bsalomoncdee0092016-01-08 13:20:12 -08001700 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001701
1702 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1703 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1704 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1705 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001706 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1707 0;
bsalomon30447372015-12-21 09:03:05 -08001708 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001709 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001710 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1711 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1712 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1713 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1714 }
bsalomoncdee0092016-01-08 13:20:12 -08001715 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001716
1717 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1718
1719 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001720 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1721 ctxInfo.version() >= GR_GL_VER(3,0));
1722 // All ES versions (thus far) require sized internal formats for render buffers.
1723 // TODO: Always use sized internal format?
1724 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1725
bsalomon30447372015-12-21 09:03:05 -08001726 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001727 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1728 // param to glTex[Sub]Image.
1729 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1730 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1731 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1732 fConfigTable[i].fFormats.fSizedInternalFormat :
1733 fConfigTable[i].fFormats.fBaseInternalFormat;
1734 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001735 fConfigTable[i].fFormats.fSizedInternalFormat :
1736 fConfigTable[i].fFormats.fBaseInternalFormat;
1737 }
1738 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1739 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1740 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1741 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1742 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001743 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001744 GR_GL_SRGB_ALPHA;
1745 }
1746
1747 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1748 // as a base format.
1749 // GL_EXT_texture_format_BGRA8888:
1750 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1751 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1752 // formats.
1753 // GL_APPLE_texture_format_BGRA8888:
1754 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1755 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1756 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001757 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001758 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1759 }
1760
bsalomoncdee0092016-01-08 13:20:12 -08001761 // If we don't have texture swizzle support then the shader generator must insert the
1762 // swizzle into shader code.
1763 if (!this->textureSwizzleSupport()) {
1764 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1765 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1766 }
1767 }
1768
bsalomon7f9b2e42016-01-12 13:29:26 -08001769 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1770 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1771 // gets written to the single component.
1772 if (this->textureRedSupport()) {
1773 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1774 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1775 if (GrPixelConfigIsAlphaOnly(config) &&
1776 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1777 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1778 }
1779 }
1780 }
1781
bsalomon30447372015-12-21 09:03:05 -08001782#ifdef SK_DEBUG
1783 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001784 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001785 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001786 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1787 fConfigTable[i].fFormats.fBaseInternalFormat);
1788 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001789 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001790 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1791 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1792 fConfigTable[i].fFormats.fExternalFormat[j]);
1793 }
1794 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001795 }
1796#endif
1797}
1798
egdanielb7e7d572015-11-04 04:23:53 -08001799void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}