blob: 989c799a37c4edbf641322c88677b99a3278b8a2 [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;
36 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000037 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDirectStateAccessSupport = false;
41 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080042 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080043 fMultisampleDisableSupport = false;
cdalton06604b92016-02-05 10:09:51 -080044 fDrawIndirectSupport = false;
45 fMultiDrawIndirectSupport = false;
46 fBaseInstanceSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000047 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000048 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070049 fBindFragDataLocationSupport = false;
bsalomon7ea33f52015-11-22 14:51:00 -080050 fExternalTextureSupport = false;
bsalomone5286e02016-01-14 09:24:09 -080051 fRectangleTextureSupport = false;
bsalomoncdee0092016-01-08 13:20:12 -080052 fTextureSwizzleSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070053 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070054 fRGBA8888PixelsOpsAreSlow = false;
55 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070056
bsalomon083617b2016-02-12 12:10:14 -080057 fBlitFramebufferSupport = kNone_BlitFramebufferSupport;
58
halcanary385fe4d2015-08-26 13:07:48 -070059 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070060
cdalton4cd67132015-06-10 19:23:46 -070061 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000062}
63
cdalton4cd67132015-06-10 19:23:46 -070064void GrGLCaps::init(const GrContextOptions& contextOptions,
65 const GrGLContextInfo& ctxInfo,
66 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000067 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000068 GrGLVersion version = ctxInfo.version();
69
bsalomon@google.combcce8922013-03-25 15:38:39 +000070 /**************************************************************************
71 * Caps specific to GrGLCaps
72 **************************************************************************/
73
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000074 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000075 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
76 &fMaxFragmentUniformVectors);
77 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000078 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079 GrGLint max;
80 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
81 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000082 if (version >= GR_GL_VER(3, 2)) {
83 GrGLint profileMask;
84 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
85 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
86 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000088 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000089 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000091 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000092 fUnpackRowLengthSupport = true;
93 fUnpackFlipYSupport = false;
94 fPackRowLengthSupport = true;
95 fPackFlipYSupport = false;
96 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000097 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
98 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000100 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
101 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000102 fPackFlipYSupport =
103 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
104 }
105
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000106 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
108
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000109 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000110 // The EXT version can apply to either GL or GLES.
111 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
112 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
113 ctxInfo.hasExtension("GL_EXT_texture_storage");
114 } else {
115 // Qualcomm Adreno drivers appear to have issues with texture storage.
116 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
kkinnunen45c2c812016-02-25 02:03:43 -0800117 kQualcomm_GrGLVendor != ctxInfo.vendor()) &&
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000118 ctxInfo.hasExtension("GL_EXT_texture_storage");
119 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000120
cdaltonfd4167d2015-04-21 11:45:56 -0700121 if (kGL_GrGLStandard == standard) {
122 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
123 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
124 ctxInfo.hasExtension("GL_NV_texture_barrier");
125 } else {
126 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
127 }
128
cdaltoneb79eea2016-02-26 10:39:34 -0800129 if (kGL_GrGLStandard == standard) {
130 fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
131 ctxInfo.hasExtension("GL_ARB_texture_multisample");
132 } else {
133 fSampleLocationsSupport = version >= GR_GL_VER(3,1);
134 }
135
hendrikwa0d5ad72014-12-02 07:30:30 -0800136 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
137 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700138 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800139 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000140 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
141 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800142 } else {
143 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
144 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000145 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000146 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000147 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000148 ctxInfo.hasExtension("GL_ARB_imaging");
149
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000150 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
151 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
152 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
153 // limit this decision to specific GPU families rather than basing it on the vendor alone.
154 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700155 (kARM_GrGLVendor == ctxInfo.vendor() ||
156 kImagination_GrGLVendor == ctxInfo.vendor() ||
157 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000158 fUseNonVBOVertexAndIndexDynamicData = true;
159 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000160
egdaniel9250d242015-05-18 13:04:26 -0700161 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
162 // Thus we are blacklisting this extension for now on Adreno4xx devices.
163 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
164 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
165 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
166 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000167 fDiscardRenderTargetSupport = true;
168 fInvalidateFBType = kInvalidate_InvalidateFBType;
169 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
170 fDiscardRenderTargetSupport = true;
171 fInvalidateFBType = kDiscard_InvalidateFBType;
172 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000173
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000174 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
175 fFullClearIsFree = true;
176 }
177
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000178 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000179 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800180 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
181 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000182 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000183 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
184 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000185 }
186
cdalton626e1ff2015-06-12 13:56:46 -0700187 if (kGL_GrGLStandard == standard) {
188 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
189 } else {
190 fDirectStateAccessSupport = false;
191 }
192
193 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
194 fDebugSupport = true;
195 } else {
196 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
197 }
198
jvanverth3f801cb2014-12-16 09:49:38 -0800199 if (kGL_GrGLStandard == standard) {
200 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
201 }
202 else {
203 fES2CompatibilitySupport = true;
204 }
205
cdalton0edea2c2015-05-21 08:27:44 -0700206 if (kGL_GrGLStandard == standard) {
207 fMultisampleDisableSupport = true;
208 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700209 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700210 }
211
kkinnunend94708e2015-07-30 22:47:04 -0700212 if (kGL_GrGLStandard == standard) {
213 if (version >= GR_GL_VER(3, 0)) {
214 fBindFragDataLocationSupport = true;
215 }
216 } else {
217 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
218 fBindFragDataLocationSupport = true;
219 }
joshualittc1f56b52015-06-22 12:31:31 -0700220 }
221
bsalomonb8909d32016-01-28 07:09:52 -0800222#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700223 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800224#else
225 fBindUniformLocationSupport = false;
226#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700227
bsalomon7ea33f52015-11-22 14:51:00 -0800228 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
229 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
230 fExternalTextureSupport = true;
231 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
232 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
233 // At least one driver has been found that has this extension without the "GL_" prefix.
234 fExternalTextureSupport = true;
235 }
236 }
237
kkinnunene06ed252016-02-16 23:15:40 -0800238 if (kGL_GrGLStandard == standard) {
239 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
240 // We also require textureSize() support for rectangle 2D samplers which was added in
241 // GLSL 1.40.
242 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
243 fRectangleTextureSupport = true;
244 }
bsalomone179a912016-01-20 06:18:10 -0800245 }
kkinnunene06ed252016-02-16 23:15:40 -0800246 } else {
247 // Command buffer exposes this in GL ES context for Chromium reasons,
248 // but it should not be used. Also, at the time of writing command buffer
249 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800250 }
251
bsalomoncdee0092016-01-08 13:20:12 -0800252 if (kGL_GrGLStandard == standard) {
253 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
254 fTextureSwizzleSupport = true;
255 }
256 } else {
257 if (version >= GR_GL_VER(3,0)) {
258 fTextureSwizzleSupport = true;
259 }
260 }
261
bsalomon88c7b982015-07-31 11:20:16 -0700262#ifdef SK_BUILD_FOR_WIN
263 // We're assuming that on Windows Chromium we're using ANGLE.
264 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
265 kChromium_GrGLDriver == ctxInfo.driver();
266 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
267 fRGBA8888PixelsOpsAreSlow = isANGLE;
268 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
269 // check DX11 ANGLE.
270 fPartialFBOReadIsSlow = isANGLE;
271#endif
272
cdalton4cd67132015-06-10 19:23:46 -0700273 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700274 * GrShaderCaps fields
275 **************************************************************************/
276
egdaniel0a482332015-10-26 08:59:10 -0700277 // This must be called after fCoreProfile is set on the GrGLCaps
278 this->initGLSL(ctxInfo);
279 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
280
egdaniel05ded892015-10-26 07:38:05 -0700281 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
282
283 // For now these two are equivalent but we could have dst read in shader via some other method.
284 // Before setting this, initGLSL() must have been called.
285 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
286
287 // Enable supported shader-related caps
288 if (kGL_GrGLStandard == standard) {
289 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
290 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
291 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
292 glslCaps->fShaderDerivativeSupport = true;
293 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
294 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
295 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800296 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
297 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700298 }
299 else {
300 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
301
302 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
303 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800304
305 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
306 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700307 }
308
ethannicholas22793252016-01-30 09:59:10 -0800309 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
310 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
311 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
312 &glslCaps->fPixelLocalStorageSize);
313 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
314 }
315 else {
316 glslCaps->fPixelLocalStorageSize = 0;
317 glslCaps->fPLSPathRenderingSupport = false;
318 }
319
egdaniel05ded892015-10-26 07:38:05 -0700320 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700321 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000322 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700323
cdalton63f6c1f2015-11-06 07:09:43 -0800324 // We need dual source blending and the ability to disable multisample in order to support mixed
325 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800326 if (fMultisampleDisableSupport &&
327 glslCaps->dualSourceBlendingSupport() &&
328 fShaderCaps->pathRenderingSupport()) {
329 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800330 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800331 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800332 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
333 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800334 fDiscardRenderTargetSupport = false;
335 fInvalidateFBType = kNone_InvalidateFBType;
336 }
337 }
338
egdanieleed519e2016-01-15 11:36:18 -0800339 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700340 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700341 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700342 this->initStencilFormats(ctxInfo);
343
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000344 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000345 // we could also look for GL_ATI_separate_stencil extension or
346 // GL_EXT_stencil_two_side but they use different function signatures
347 // than GL2.0+ (and than each other).
348 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
349 // supported on GL 1.4 and higher or by extension
350 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
351 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
352 } else {
353 // ES 2 has two sided stencil and stencil wrap
354 fTwoSidedStencilSupport = true;
355 fStencilWrapOpsSupport = true;
356 }
357
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000358 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000359 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
360 // extension includes glMapBuffer.
361 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
362 fMapBufferFlags |= kSubset_MapFlag;
363 fMapBufferType = kMapBufferRange_MapBufferType;
364 } else {
365 fMapBufferType = kMapBuffer_MapBufferType;
366 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000367 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000368 // Unextended GLES2 doesn't have any buffer mapping.
369 fMapBufferFlags = kNone_MapBufferType;
kkinnunen45c2c812016-02-25 02:03:43 -0800370 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000371 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
372 fMapBufferType = kMapBufferRange_MapBufferType;
kkinnunen45c2c812016-02-25 02:03:43 -0800373 } else if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
374 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
375 fMapBufferType = kChromium_MapBufferType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000376 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
377 fMapBufferFlags = kCanMap_MapFlag;
378 fMapBufferType = kMapBuffer_MapBufferType;
379 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000380 }
381
jvanverthd7a2c1f2015-12-07 07:36:44 -0800382 if (kGL_GrGLStandard == standard) {
383 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
384 fTransferBufferType = kPBO_TransferBufferType;
385 }
386 } else {
387 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
388 fTransferBufferType = kPBO_TransferBufferType;
389 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
390 fTransferBufferType = kChromium_TransferBufferType;
391 }
392 }
393
joshualitte5b74c62015-06-01 14:17:47 -0700394 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
395 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
396 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700397 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
398 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
399 // a small subset.
400#if 0
cdalton1acea862015-06-02 13:05:52 -0700401 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700402#else
403 fGeometryBufferMapThreshold = SK_MaxS32;
404#endif
joshualitte5b74c62015-06-01 14:17:47 -0700405 }
406
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000407 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000408 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
409 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
410 fNPOTTextureTileSupport = true;
411 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000412 } else {
413 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000414 // ES3 has no limitations.
415 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
416 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000417 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
418 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
419 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
420 // to alllow arbitrary wrap modes, however.
421 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000422 }
423
bsalomone72bd022015-10-26 07:33:03 -0700424 // Using MIPs on this GPU seems to be a source of trouble.
425 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
426 fMipMapSupport = false;
427 }
428
bsalomon@google.combcce8922013-03-25 15:38:39 +0000429 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
430 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
431 // Our render targets are always created with textures as the color
432 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000433 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000434
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000435 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
436
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000437 // Disable scratch texture reuse on Mali and Adreno devices
438 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
439 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000440
robertphillips1b8e1b52015-06-24 06:54:10 -0700441#if 0
442 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
443 kQualcomm_GrGLVendor != ctxInfo.vendor();
444#endif
445
egdaniel05ded892015-10-26 07:38:05 -0700446 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000447 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800448 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000449 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800450 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000451 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800452 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
453 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
454 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
455 // This is to guard against platforms that may not support as many samples for
456 // glRasterSamples as they do for framebuffers.
457 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
458 }
459 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000460
bsalomon63b21962014-11-05 07:05:34 -0800461 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800462 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800463 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800464 fUseDrawInsteadOfClear = true;
465 }
466
joshualitt83bc2292015-06-18 14:18:02 -0700467 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
468 fUseDrawInsteadOfPartialRenderTargetWrite = true;
469 }
470
bsalomonbabafcc2016-02-16 11:36:47 -0800471 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
472 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
473 fUseDrawInsteadOfPartialRenderTargetWrite = true;
474 fUseDrawInsteadOfAllRenderTargetWrites = true;
475 }
476
robertphillips63926682015-08-20 09:39:02 -0700477#ifdef SK_BUILD_FOR_WIN
478 // On ANGLE deferring flushes can lead to GPU starvation
479 fPreferVRAMUseOverFlushes = !isANGLE;
480#endif
481
bsalomon7dea7b72015-08-19 08:26:51 -0700482 if (kChromium_GrGLDriver == ctxInfo.driver()) {
483 fMustClearUploadedBufferData = true;
484 }
485
bsalomond08ea5f2015-02-20 06:58:13 -0800486 if (kGL_GrGLStandard == standard) {
487 // ARB allows mixed size FBO attachments, EXT does not.
488 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
489 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
490 fOversizedStencilSupport = true;
491 } else {
492 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
493 }
494 } else {
495 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
496 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
497 }
498
joshualitt58001552015-06-26 12:46:36 -0700499 if (kGL_GrGLStandard == standard) {
500 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
501 // instanced arrays, but we could make this more granular if we wanted
502 fSupportsInstancedDraws =
503 version >= GR_GL_VER(3, 2) ||
504 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
505 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
506 } else {
507 fSupportsInstancedDraws =
508 version >= GR_GL_VER(3, 0) ||
509 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
510 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
511 }
512
cdalton06604b92016-02-05 10:09:51 -0800513 if (kGL_GrGLStandard == standard) {
514 // We don't use ARB_draw_indirect because it does not support a base instance.
515 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
516 fDrawIndirectSupport =
517 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
518 } else {
519 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
520 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
521 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
522 }
523
jvanverthcba99b82015-06-24 06:59:57 -0700524 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800525
526 if (contextOptions.fUseShaderSwizzling) {
527 fTextureSwizzleSupport = false;
528 }
529
kkinnunen45c2c812016-02-25 02:03:43 -0800530 // TODO: remove after command buffer supports full ES 3.0.
531 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3, 0) &&
532 kChromium_GrGLDriver == ctxInfo.driver()) {
533 fTexStorageSupport = false;
534 fSupportsInstancedDraws = false;
535 fTextureSwizzleSupport = false;
536 SkASSERT(ctxInfo.hasExtension("GL_CHROMIUM_map_sub"));
537 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
538 fMapBufferType = kChromium_MapBufferType;
539 }
540
bsalomoncdee0092016-01-08 13:20:12 -0800541 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
542 // already been detected.
543 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700544
545 this->applyOptionsOverrides(contextOptions);
546 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000547}
548
egdaniel472d44e2015-10-22 08:20:00 -0700549const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
550 bool isCoreProfile) {
551 switch (generation) {
552 case k110_GrGLSLGeneration:
553 if (kGLES_GrGLStandard == standard) {
554 // ES2s shader language is based on version 1.20 but is version
555 // 1.00 of the ES language.
556 return "#version 100\n";
557 } else {
558 SkASSERT(kGL_GrGLStandard == standard);
559 return "#version 110\n";
560 }
561 case k130_GrGLSLGeneration:
562 SkASSERT(kGL_GrGLStandard == standard);
563 return "#version 130\n";
564 case k140_GrGLSLGeneration:
565 SkASSERT(kGL_GrGLStandard == standard);
566 return "#version 140\n";
567 case k150_GrGLSLGeneration:
568 SkASSERT(kGL_GrGLStandard == standard);
569 if (isCoreProfile) {
570 return "#version 150\n";
571 } else {
572 return "#version 150 compatibility\n";
573 }
574 case k330_GrGLSLGeneration:
575 if (kGLES_GrGLStandard == standard) {
576 return "#version 300 es\n";
577 } else {
578 SkASSERT(kGL_GrGLStandard == standard);
579 if (isCoreProfile) {
580 return "#version 330\n";
581 } else {
582 return "#version 330 compatibility\n";
583 }
584 }
cdalton33ad7012016-02-22 07:55:44 -0800585 case k400_GrGLSLGeneration:
586 SkASSERT(kGL_GrGLStandard == standard);
587 if (isCoreProfile) {
588 return "#version 400\n";
589 } else {
590 return "#version 400 compatibility\n";
591 }
egdaniel472d44e2015-10-22 08:20:00 -0700592 case k310es_GrGLSLGeneration:
593 SkASSERT(kGLES_GrGLStandard == standard);
594 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800595 case k320es_GrGLSLGeneration:
596 SkASSERT(kGLES_GrGLStandard == standard);
597 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700598 }
599 return "<no version>";
600}
601
egdaniel05ded892015-10-26 07:38:05 -0700602void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700603 GrGLStandard standard = ctxInfo.standard();
604 GrGLVersion version = ctxInfo.version();
605
606 /**************************************************************************
607 * Caps specific to GrGLSLCaps
608 **************************************************************************/
609
610 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
611 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700612 if (kGLES_GrGLStandard == standard) {
613 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
614 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
615 glslCaps->fFBFetchSupport = true;
616 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
617 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
618 }
619 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
620 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
621 glslCaps->fFBFetchNeedsCustomOutput = false;
622 glslCaps->fFBFetchSupport = true;
623 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
624 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
625 }
626 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
627 // The arm extension also requires an additional flag which we will set onResetContext
628 glslCaps->fFBFetchNeedsCustomOutput = false;
629 glslCaps->fFBFetchSupport = true;
630 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
631 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
632 }
633 glslCaps->fUsesPrecisionModifiers = true;
634 }
635
636 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
637
cdaltonc08f1962016-02-12 12:14:06 -0800638 if (kGL_GrGLStandard == standard) {
639 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
640 } else {
641 glslCaps->fFlatInterpolationSupport =
642 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
643 }
644
645 if (kGL_GrGLStandard == standard) {
646 glslCaps->fNoPerspectiveInterpolationSupport =
647 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
648 } else {
649 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
650 glslCaps->fNoPerspectiveInterpolationSupport = true;
651 glslCaps->fNoPerspectiveInterpolationExtensionString =
652 "GL_NV_shader_noperspective_interpolation";
653 }
654 }
655
cdalton33ad7012016-02-22 07:55:44 -0800656 if (kGL_GrGLStandard == standard) {
657 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
658 } else {
659 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
660 glslCaps->fSampleVariablesSupport = true;
661 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
662 glslCaps->fSampleVariablesSupport = true;
663 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
664 }
665 }
666
667 if (glslCaps->fSampleVariablesSupport) {
668 glslCaps->fSampleMaskOverrideCoverageSupport =
669 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
670 }
671
egdaniel472d44e2015-10-22 08:20:00 -0700672 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
673 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
674
675 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
676 // function that may require a gradient calculation inside a conditional block may return
677 // undefined results". This appears to be an issue with the 'any' call since even the simple
678 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
679 // from our GrTextureDomain processor.
680 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
681
egdaniel472d44e2015-10-22 08:20:00 -0700682 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
683 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800684
685 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
686 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
687 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800688
689 // Frag Coords Convention support is not part of ES
690 // Known issue on at least some Intel platforms:
691 // http://code.google.com/p/skia/issues/detail?id=946
692 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
693 kGLES_GrGLStandard != standard &&
694 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
695 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
696 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
697 }
698
699 if (kGLES_GrGLStandard == standard) {
700 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
701 }
702
bsalomon7ea33f52015-11-22 14:51:00 -0800703 if (fExternalTextureSupport) {
704 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
705 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
706 } else {
707 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
708 }
709 }
710
egdaniel8dcdedc2015-11-11 06:27:20 -0800711 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
712 // the abs first in a separate expression.
713 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
714 glslCaps->fCanUseMinAndAbsTogether = false;
715 }
716
bsalomon7ea33f52015-11-22 14:51:00 -0800717 // 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 -0800718 // thus must us -1.0 * %s.x to work correctly
719 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
720 glslCaps->fMustForceNegatedAtanParamToFloat = true;
721 }
egdaniel472d44e2015-10-22 08:20:00 -0700722}
723
kkinnunencfe62e32015-07-01 02:58:50 -0700724bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700725 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
726
727 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700728 return false;
729 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700730
kkinnunencfe62e32015-07-01 02:58:50 -0700731 if (kGL_GrGLStandard == ctxInfo.standard()) {
732 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
733 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
734 return false;
735 }
736 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700737 if (!hasChromiumPathRendering &&
738 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700739 return false;
740 }
741 }
742 // We only support v1.3+ of GL_NV_path_rendering which allows us to
743 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
744 // additions are detected by checking the existence of the function.
745 // We also use *Then* functions that not all drivers might have. Check
746 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800747 if (!gli->fFunctions.fStencilThenCoverFillPath ||
748 !gli->fFunctions.fStencilThenCoverStrokePath ||
749 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
750 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
751 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700752 return false;
753 }
754 return true;
755}
bsalomon1aa20292016-01-22 08:16:09 -0800756
757bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800758 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800759 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
760 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800761 // If it's not possible to even have a render target of rtConfig then read pixels is
762 // not supported regardless of readConfig.
763 if (!this->isConfigRenderable(rtConfig, false)) {
764 return false;
765 }
bsalomon7928ef62016-01-05 10:26:39 -0800766
bsalomon76148af2016-01-12 11:13:47 -0800767 GrGLenum readFormat;
768 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800769 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800770 return false;
771 }
772
bsalomon1aa20292016-01-22 08:16:09 -0800773 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800774 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
775 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
776 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
777 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
778 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
779 readFormat != GR_GL_BGRA) {
780 return false;
781 }
782 // There is also a set of allowed types, but all the types we use are in the set:
783 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
784 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
785 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
786 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
787 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
788 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
789 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800790 return true;
piotaixre4b23142014-10-02 10:57:53 -0700791 }
bsalomon7928ef62016-01-05 10:26:39 -0800792
bsalomon76148af2016-01-12 11:13:47 -0800793 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800794
bsalomon1aa20292016-01-22 08:16:09 -0800795 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800796 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
797 return true;
798 }
799 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800800 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800801 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
802 return true;
803 }
804 }
805
bsalomon1aa20292016-01-22 08:16:09 -0800806 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800807 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800808 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800809 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800810 if (!bindRenderTarget()) {
811 return false;
812 }
813 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
814 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800815 rpFormat->fFormat = format;
816 rpFormat->fType = type;
817 }
818
bsalomon1aa20292016-01-22 08:16:09 -0800819 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
820 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700821}
822
robertphillips@google.com6177e692013-02-28 20:16:25 +0000823void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000824
825 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000826 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000827 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
828 // ES3 driver bugs on at least one device with a tiled GPU (N10).
829 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
830 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
831 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
832 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800833 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700834 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000835 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000836 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
837 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
838 // chrome's extension is equivalent to the EXT msaa
839 // and fbo_blit extensions.
840 fMSFBOType = kDesktop_EXT_MSFBOType;
841 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
842 fMSFBOType = kES_Apple_MSFBOType;
843 }
bsalomon083617b2016-02-12 12:10:14 -0800844
845 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
846 // is available.
847 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
848 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
849 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
850 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
851 // limitations.
852 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
853 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000854 } else {
egdanieleed519e2016-01-15 11:36:18 -0800855 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700856 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800857 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700858 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000859 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000860 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800861 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000862 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
863 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000864 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800865 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000866 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000867 }
868}
869
cdalton1dd05422015-06-12 09:01:18 -0700870void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
871 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
872
873 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
874 // for now until its own blacklists can be updated.
875 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
876 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700877 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700878 return;
879 }
880
881 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
882 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
883 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
884 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
885 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
886 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
887 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
888 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
889 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
890 return;
891 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
892 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
893 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
894 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
895 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
896 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
897 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
898 // slow on a particular platform.
899 } else {
900 return; // No advanced blend support.
901 }
902
903 SkASSERT(this->advancedBlendEquationSupport());
904
905 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
906 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
907 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
908 (1 << kColorBurn_GrBlendEquation);
909 }
joel.liang9764c402015-07-09 19:46:18 -0700910 if (kARM_GrGLVendor == ctxInfo.vendor()) {
911 // Blacklist color-burn on ARM until the fix is released.
912 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
913 }
cdalton1dd05422015-06-12 09:01:18 -0700914}
915
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000916namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700917const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000918}
919
920void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
921
922 // Build up list of legal stencil formats (though perhaps not supported on
923 // the particular gpu/driver) from most preferred to least.
924
925 // these consts are in order of most preferred to least preferred
926 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
927
928 static const StencilFormat
929 // internal Format stencil bits total bits packed?
930 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
931 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
932 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
933 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000934 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000935 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
936
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000937 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000938 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000939 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000940 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
941 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
942
943 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
944 // require FBO support we can expect these are legal formats and don't
945 // check. These also all support the unsized GL_STENCIL_INDEX.
946 fStencilFormats.push_back() = gS8;
947 fStencilFormats.push_back() = gS16;
948 if (supportsPackedDS) {
949 fStencilFormats.push_back() = gD24S8;
950 }
951 fStencilFormats.push_back() = gS4;
952 if (supportsPackedDS) {
953 fStencilFormats.push_back() = gDS;
954 }
955 } else {
956 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
957 // for other formats.
958 // ES doesn't support using the unsized format.
959
960 fStencilFormats.push_back() = gS8;
961 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000962 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
963 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000964 fStencilFormats.push_back() = gD24S8;
965 }
966 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
967 fStencilFormats.push_back() = gS4;
968 }
969 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000970}
971
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000972SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000973
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000974 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000975
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000976 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000977 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000978 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000979 i,
980 fStencilFormats[i].fStencilBits,
981 fStencilFormats[i].fTotalBits);
982 }
983
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000984 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000985 "None",
986 "ARB",
987 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000988 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000989 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000990 "IMG MS To Texture",
991 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -0700992 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000993 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000994 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
995 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
996 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000997 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
998 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
999 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1000 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001001 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001002 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001003
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001004 static const char* kInvalidateFBTypeStr[] = {
1005 "None",
1006 "Discard",
1007 "Invalidate",
1008 };
1009 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1010 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1011 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1012 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001013
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001014 static const char* kMapBufferTypeStr[] = {
1015 "None",
1016 "MapBuffer",
1017 "MapBufferRange",
1018 "Chromium",
1019 };
1020 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1021 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1022 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1023 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1024 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1025
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001026 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001027 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001028 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001029 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001030 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1031 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001032 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001033 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1034 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1035 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1036 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001037
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001038 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1039 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1040 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1041 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001042 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001043 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1044 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001045 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001046 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1047 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1048 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001049 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001050 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001051 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001052 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1053 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001054 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001055 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001056 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001057 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001058
1059 r.append("Configs\n-------\n");
1060 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1061 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001062 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1063 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001064 i,
1065 fConfigTable[i].fFlags,
1066 fConfigTable[i].fFormats.fBaseInternalFormat,
1067 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001068 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1069 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001070 fConfigTable[i].fFormats.fExternalType,
1071 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001072 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001073 }
1074
jvanverthe9c0fc62015-04-29 11:18:05 -07001075 return r;
1076}
1077
jvanverthe9c0fc62015-04-29 11:18:05 -07001078static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1079 switch (p) {
1080 case kLow_GrSLPrecision:
1081 return GR_GL_LOW_FLOAT;
1082 case kMedium_GrSLPrecision:
1083 return GR_GL_MEDIUM_FLOAT;
1084 case kHigh_GrSLPrecision:
1085 return GR_GL_HIGH_FLOAT;
1086 }
1087 SkFAIL("Unknown precision.");
1088 return -1;
1089}
1090
1091static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1092 switch (type) {
1093 case kVertex_GrShaderType:
1094 return GR_GL_VERTEX_SHADER;
1095 case kGeometry_GrShaderType:
1096 return GR_GL_GEOMETRY_SHADER;
1097 case kFragment_GrShaderType:
1098 return GR_GL_FRAGMENT_SHADER;
1099 }
1100 SkFAIL("Unknown shader type.");
1101 return -1;
1102}
1103
jvanverthcba99b82015-06-24 06:59:57 -07001104void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1105 const GrGLInterface* intf,
1106 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001107 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1108 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1109 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1110 if (kGeometry_GrShaderType != s) {
1111 GrShaderType shaderType = static_cast<GrShaderType>(s);
1112 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001113 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001114 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001115 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1116 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1117 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1118 GrGLint range[2];
1119 GrGLint bits;
1120 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1121 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001122 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1123 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1124 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001125 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001126 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001127 }
jvanverthcba99b82015-06-24 06:59:57 -07001128 else if (!glslCaps->fShaderPrecisionVaries) {
1129 glslCaps->fShaderPrecisionVaries =
1130 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001131 }
1132 }
1133 }
1134 }
1135 }
1136 }
1137 else {
1138 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001139 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001140 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1141 if (kGeometry_GrShaderType != s) {
1142 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001143 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1144 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1145 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001146 }
1147 }
1148 }
1149 }
1150 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1151 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1152 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1153 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001154 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001155 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001156 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1157 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001158 }
1159 }
1160}
1161
bsalomon41e4384e2016-01-08 09:12:44 -08001162bool GrGLCaps::bgraIsInternalFormat() const {
1163 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1164}
1165
bsalomon76148af2016-01-12 11:13:47 -08001166bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1167 GrGLenum* internalFormat, GrGLenum* externalFormat,
1168 GrGLenum* externalType) const {
1169 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1170 externalFormat, externalType)) {
1171 return false;
1172 }
1173 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1174 return true;
1175}
1176
1177bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1178 GrGLenum* internalFormat) const {
1179 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1180 return false;
1181 }
1182 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1183 return true;
1184}
1185
1186bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1187 GrGLenum* externalFormat, GrGLenum* externalType) const {
1188 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1189 externalFormat, externalType)) {
1190 return false;
1191 }
1192 return true;
1193}
1194
1195bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1196 if (GrPixelConfigIsCompressed(config)) {
1197 return false;
1198 }
1199 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1200 return true;
1201}
1202
1203bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1204 ExternalFormatUsage usage, GrGLenum* externalFormat,
1205 GrGLenum* externalType) const {
1206 SkASSERT(externalFormat && externalType);
1207 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1208 return false;
1209 }
1210
1211 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1212 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1213
1214 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1215 // made to work in many cases using glPixelStore and what not but is not needed currently.
1216 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1217 return false;
1218 }
1219
1220 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1221 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1222
bsalomone9573312016-01-25 14:33:25 -08001223 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1224 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1225 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1226 // texture, not the red component.
1227 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1228 if (this->textureRedSupport()) {
1229 SkASSERT(GR_GL_RED == *externalFormat);
1230 *externalFormat = GR_GL_ALPHA;
1231 }
1232 }
1233
bsalomon76148af2016-01-12 11:13:47 -08001234 return true;
1235}
1236
bsalomoncdee0092016-01-08 13:20:12 -08001237void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1238 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001239 /*
1240 Comments on renderability of configs on various GL versions.
1241 OpenGL < 3.0:
1242 no built in support for render targets.
1243 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1244 format RGB, RGBA and NV float formats we don't use.
1245 This is the following:
1246 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1247 RGB10_A2, RGBA12,RGBA16
1248 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1249 since they aren't required by later standards and the driver can simply return
1250 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1251 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1252 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1253 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1254 This adds a lot of additional renderable sized formats, including ALPHA8.
1255 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1256 16F, 32I, 32UI, and 32F variants).
1257 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1258
1259 For both the above extensions we limit ourselves to those that are also required by
1260 OpenGL 3.0.
1261
1262 OpenGL 3.0:
1263 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1264 but are not required to be supported as renderable textures/renderbuffer.
1265 Required renderable color formats:
1266 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1267 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1268 RGB10_A2.
1269 - R11F_G11F_B10F.
1270 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1271 and RG8UI.
1272 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1273 - ALPHA8
1274
1275 OpenGL 3.1, 3.2, 3.3
1276 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1277 OpengGL 3.3, 4.0, 4.1
1278 Adds RGB10_A2UI.
1279 OpengGL 4.2
1280 Adds
1281 - RGB5_A1, RGBA4
1282 - RGB565
1283 OpenGL 4.4
1284 Does away with the separate list and adds a column to the sized internal color format
1285 table. However, no new formats become required color renderable.
1286
1287 ES 2.0
1288 color renderable: RGBA4, RGB5_A1, RGB565
1289 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1290 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1291 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1292 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1293 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1294 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1295
1296 ES 3.0
1297 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1298 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1299 RGB5_A1.
1300 - RGB8 and RGB565.
1301 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1302 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1303 ES 3.1
1304 Adds RGB10_A2, RGB10_A2UI,
1305 ES 3.2
1306 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1307 */
1308 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1309 if (kNone_MSFBOType != fMSFBOType) {
1310 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1311 }
1312
1313 GrGLStandard standard = ctxInfo.standard();
1314 GrGLVersion version = ctxInfo.version();
1315
bsalomon30447372015-12-21 09:03:05 -08001316 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1317 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001318 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001319 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001320 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001321 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001322
1323 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1324 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001325 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1326 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001327 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001328 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001329 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1330 if (kGL_GrGLStandard == standard) {
1331 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1332 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001333 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001334 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1335 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1336 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1337 }
egdaniel4999df82016-01-07 17:06:04 -08001338 }
bsalomoncdee0092016-01-08 13:20:12 -08001339 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001340
bsalomon76148af2016-01-12 11:13:47 -08001341 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1342 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001343 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001344 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001345 if (kGL_GrGLStandard == standard) {
1346 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1347 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1348 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1349 // Since the internal format is RGBA8, it is also renderable.
1350 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1351 allRenderFlags;
1352 }
1353 } else {
1354 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1355 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1356 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1357 // The APPLE extension doesn't make this renderable.
1358 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1359 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1360 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1361 // Though, that seems to not be the case if the texture storage extension is
1362 // present. The specs don't exactly make that clear.
1363 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1364 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1365 }
1366 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1367 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1368 ConfigInfo::kRenderable_Flag;
1369 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001370 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001371 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1372 ConfigInfo::kRenderableWithMSAA_Flag;
1373 }
1374 }
1375 }
bsalomoncdee0092016-01-08 13:20:12 -08001376 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001377
bsalomon41e4384e2016-01-08 09:12:44 -08001378 // We only enable srgb support if both textures and FBOs support srgb.
1379 bool srgbSupport = false;
1380 if (kGL_GrGLStandard == standard) {
1381 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1382 srgbSupport = true;
1383 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1384 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1385 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1386 srgbSupport = true;
1387 }
1388 }
1389 // All the above srgb extensions support toggling srgb writes
1390 fSRGBWriteControl = srgbSupport;
1391 } else {
1392 // See https://bug.skia.org/4148 for PowerVR issue.
1393 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1394 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1395 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1396 // sRGB writing for destinations.
1397 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1398 }
bsalomon30447372015-12-21 09:03:05 -08001399 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1400 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1401 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1402 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001403 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1404 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001405 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001406 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001407 if (srgbSupport) {
1408 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1409 allRenderFlags;
1410 }
bsalomoncdee0092016-01-08 13:20:12 -08001411 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001412
1413 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1414 if (this->ES2CompatibilitySupport()) {
1415 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1416 } else {
1417 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1418 }
bsalomon76148af2016-01-12 11:13:47 -08001419 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1420 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001421 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001422 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001423 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1424 if (kGL_GrGLStandard == standard) {
1425 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1426 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1427 }
1428 } else {
1429 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1430 }
bsalomoncdee0092016-01-08 13:20:12 -08001431 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001432
1433 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1434 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001435 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1436 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001437 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001438 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001439 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1440 if (kGL_GrGLStandard == standard) {
1441 if (version >= GR_GL_VER(4, 2)) {
1442 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1443 }
1444 } else {
1445 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1446 }
bsalomoncdee0092016-01-08 13:20:12 -08001447 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001448
1449 if (this->textureRedSupport()) {
1450 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1451 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001452 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1453 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001454 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001455 } else {
1456 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1457 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001458 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1459 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001460 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001461 }
1462 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001463 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001464 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1465 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1466 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1467 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1468 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1469 }
1470
1471 // Check for [half] floating point texture support
1472 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1473 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1474 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1475 bool hasFPTextures = false;
1476 bool hasHalfFPTextures = false;
1477 // for now we don't support floating point MSAA on ES
1478 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1479 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1480
1481 if (kGL_GrGLStandard == standard) {
1482 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1483 hasFPTextures = true;
1484 hasHalfFPTextures = true;
1485 }
1486 } else {
1487 if (version >= GR_GL_VER(3, 1)) {
1488 hasFPTextures = true;
1489 hasHalfFPTextures = true;
1490 } else {
1491 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1492 ctxInfo.hasExtension("GL_OES_texture_float")) {
1493 hasFPTextures = true;
1494 }
1495 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1496 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1497 hasHalfFPTextures = true;
1498 }
1499 }
1500 }
bsalomon30447372015-12-21 09:03:05 -08001501
1502 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1503 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001504 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1505 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001506 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001507 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001508 if (hasFPTextures) {
1509 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1510 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1511 // many precision issues and no clients actually want this yet.
1512 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1513 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1514 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1515 }
1516 }
bsalomoncdee0092016-01-08 13:20:12 -08001517 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001518
1519 if (this->textureRedSupport()) {
1520 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1521 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001522 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1523 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001524 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001525 } else {
1526 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1527 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001528 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1529 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001530 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001531 }
1532 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1533 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1534 } else {
1535 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1536 }
bsalomon7928ef62016-01-05 10:26:39 -08001537 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001538 if (hasHalfFPTextures) {
1539 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1540 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1541 // GL_RED internal format.
1542 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1543 (this->textureRedSupport() &&
1544 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1545 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1546 }
1547 }
bsalomon30447372015-12-21 09:03:05 -08001548
1549 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1550 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001551 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1552 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001553 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1554 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1555 } else {
1556 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1557 }
bsalomon7928ef62016-01-05 10:26:39 -08001558 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001559 if (hasHalfFPTextures) {
1560 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1561 // ES requires 3.2 or EXT_color_buffer_half_float.
1562 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1563 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1564 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1565 }
1566 }
bsalomoncdee0092016-01-08 13:20:12 -08001567 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001568
1569 // Compressed texture support
1570
1571 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1572 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1573
1574 // TODO: Fix command buffer bindings and remove this.
1575 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001576
1577 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001578 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001579
1580 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1581 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001582 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001583 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001584 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001585 // Disable this for now, while we investigate https://bug.skia.org/4333
1586 if (false) {
1587 // Check for 8-bit palette..
1588 GrGLint numFormats;
1589 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1590 if (numFormats) {
1591 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1592 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1593 for (int i = 0; i < numFormats; ++i) {
1594 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1595 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1596 break;
1597 }
1598 }
1599 }
1600 }
bsalomoncdee0092016-01-08 13:20:12 -08001601 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001602
bsalomon41e4384e2016-01-08 09:12:44 -08001603 // May change the internal format based on extensions.
1604 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1605 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1606 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1607 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1608 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1609 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1610 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1611 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1612 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1613 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1614 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1615 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1616 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1617 GR_GL_COMPRESSED_RED_RGTC1;
1618 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1619 GR_GL_COMPRESSED_RED_RGTC1;
1620 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1621 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1622 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1623 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1624 GR_GL_COMPRESSED_3DC_X;
1625
bsalomon30447372015-12-21 09:03:05 -08001626 }
bsalomon76148af2016-01-12 11:13:47 -08001627 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001628 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001629 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001630 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001631
1632 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1633 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001634 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001635 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001636 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001637 if (kGL_GrGLStandard == standard) {
1638 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1639 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1640 }
1641 } else {
1642 if (version >= GR_GL_VER(3, 0) ||
1643 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1644 // ETC2 is a superset of ETC1, so we can just check for that, too.
1645 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1646 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1647 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1648 }
1649 }
bsalomoncdee0092016-01-08 13:20:12 -08001650 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001651
1652 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1653 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001654 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001655 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001656 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001657 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1658 // decompressing the textures in the driver, and is generally slower.
1659 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1660 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1661 }
bsalomoncdee0092016-01-08 13:20:12 -08001662 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001663
1664 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1665 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1666 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1667 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001668 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1669 0;
bsalomon30447372015-12-21 09:03:05 -08001670 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001671 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001672 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1673 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1674 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1675 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1676 }
bsalomoncdee0092016-01-08 13:20:12 -08001677 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001678
1679 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1680
1681 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001682 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1683 ctxInfo.version() >= GR_GL_VER(3,0));
1684 // All ES versions (thus far) require sized internal formats for render buffers.
1685 // TODO: Always use sized internal format?
1686 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1687
bsalomon30447372015-12-21 09:03:05 -08001688 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001689 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1690 // param to glTex[Sub]Image.
1691 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1692 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1693 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1694 fConfigTable[i].fFormats.fSizedInternalFormat :
1695 fConfigTable[i].fFormats.fBaseInternalFormat;
1696 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001697 fConfigTable[i].fFormats.fSizedInternalFormat :
1698 fConfigTable[i].fFormats.fBaseInternalFormat;
1699 }
1700 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1701 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1702 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1703 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1704 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001705 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001706 GR_GL_SRGB_ALPHA;
1707 }
1708
1709 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1710 // as a base format.
1711 // GL_EXT_texture_format_BGRA8888:
1712 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1713 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1714 // formats.
1715 // GL_APPLE_texture_format_BGRA8888:
1716 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1717 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1718 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001719 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001720 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1721 }
1722
bsalomoncdee0092016-01-08 13:20:12 -08001723 // If we don't have texture swizzle support then the shader generator must insert the
1724 // swizzle into shader code.
1725 if (!this->textureSwizzleSupport()) {
1726 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1727 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1728 }
1729 }
1730
bsalomon7f9b2e42016-01-12 13:29:26 -08001731 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1732 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1733 // gets written to the single component.
1734 if (this->textureRedSupport()) {
1735 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1736 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1737 if (GrPixelConfigIsAlphaOnly(config) &&
1738 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1739 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1740 }
1741 }
1742 }
1743
bsalomon30447372015-12-21 09:03:05 -08001744#ifdef SK_DEBUG
1745 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001746 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001747 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001748 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1749 fConfigTable[i].fFormats.fBaseInternalFormat);
1750 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001751 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001752 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1753 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1754 fConfigTable[i].fFormats.fExternalFormat[j]);
1755 }
1756 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001757 }
1758#endif
1759}
1760
egdanielb7e7d572015-11-04 04:23:53 -08001761void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}