blob: f23a5b80bc62aca605c4590cd67a04a24e8acad3 [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) &&
117 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
118 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
hendrikwa0d5ad72014-12-02 07:30:30 -0800129 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
130 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700131 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800132 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000133 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
134 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800135 } else {
136 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
137 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000138 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000139 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000140 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000141 ctxInfo.hasExtension("GL_ARB_imaging");
142
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000143 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
144 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
145 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
146 // limit this decision to specific GPU families rather than basing it on the vendor alone.
147 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700148 (kARM_GrGLVendor == ctxInfo.vendor() ||
149 kImagination_GrGLVendor == ctxInfo.vendor() ||
150 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000151 fUseNonVBOVertexAndIndexDynamicData = true;
152 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000153
egdaniel9250d242015-05-18 13:04:26 -0700154 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
155 // Thus we are blacklisting this extension for now on Adreno4xx devices.
156 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
157 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
158 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
159 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000160 fDiscardRenderTargetSupport = true;
161 fInvalidateFBType = kInvalidate_InvalidateFBType;
162 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
163 fDiscardRenderTargetSupport = true;
164 fInvalidateFBType = kDiscard_InvalidateFBType;
165 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000166
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000167 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
168 fFullClearIsFree = true;
169 }
170
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000171 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000172 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800173 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
174 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000175 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000176 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
177 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000178 }
179
cdalton626e1ff2015-06-12 13:56:46 -0700180 if (kGL_GrGLStandard == standard) {
181 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
182 } else {
183 fDirectStateAccessSupport = false;
184 }
185
186 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
187 fDebugSupport = true;
188 } else {
189 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
190 }
191
jvanverth3f801cb2014-12-16 09:49:38 -0800192 if (kGL_GrGLStandard == standard) {
193 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
194 }
195 else {
196 fES2CompatibilitySupport = true;
197 }
198
cdalton0edea2c2015-05-21 08:27:44 -0700199 if (kGL_GrGLStandard == standard) {
200 fMultisampleDisableSupport = true;
201 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700202 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700203 }
204
kkinnunend94708e2015-07-30 22:47:04 -0700205 if (kGL_GrGLStandard == standard) {
206 if (version >= GR_GL_VER(3, 0)) {
207 fBindFragDataLocationSupport = true;
208 }
209 } else {
210 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
211 fBindFragDataLocationSupport = true;
212 }
joshualittc1f56b52015-06-22 12:31:31 -0700213 }
214
bsalomonb8909d32016-01-28 07:09:52 -0800215#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700216 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
bsalomonb8909d32016-01-28 07:09:52 -0800217#else
218 fBindUniformLocationSupport = false;
219#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700220
bsalomon7ea33f52015-11-22 14:51:00 -0800221 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
222 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
223 fExternalTextureSupport = true;
224 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
225 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
226 // At least one driver has been found that has this extension without the "GL_" prefix.
227 fExternalTextureSupport = true;
228 }
229 }
230
kkinnunene06ed252016-02-16 23:15:40 -0800231 if (kGL_GrGLStandard == standard) {
232 if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle")) {
233 // We also require textureSize() support for rectangle 2D samplers which was added in
234 // GLSL 1.40.
235 if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) {
236 fRectangleTextureSupport = true;
237 }
bsalomone179a912016-01-20 06:18:10 -0800238 }
kkinnunene06ed252016-02-16 23:15:40 -0800239 } else {
240 // Command buffer exposes this in GL ES context for Chromium reasons,
241 // but it should not be used. Also, at the time of writing command buffer
242 // lacks TexImage2D support and ANGLE lacks GL ES 3.0 support.
bsalomone5286e02016-01-14 09:24:09 -0800243 }
244
bsalomoncdee0092016-01-08 13:20:12 -0800245 if (kGL_GrGLStandard == standard) {
246 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
247 fTextureSwizzleSupport = true;
248 }
249 } else {
250 if (version >= GR_GL_VER(3,0)) {
251 fTextureSwizzleSupport = true;
252 }
253 }
254
bsalomon88c7b982015-07-31 11:20:16 -0700255#ifdef SK_BUILD_FOR_WIN
256 // We're assuming that on Windows Chromium we're using ANGLE.
257 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
258 kChromium_GrGLDriver == ctxInfo.driver();
259 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
260 fRGBA8888PixelsOpsAreSlow = isANGLE;
261 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
262 // check DX11 ANGLE.
263 fPartialFBOReadIsSlow = isANGLE;
264#endif
265
cdalton4cd67132015-06-10 19:23:46 -0700266 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700267 * GrShaderCaps fields
268 **************************************************************************/
269
egdaniel0a482332015-10-26 08:59:10 -0700270 // This must be called after fCoreProfile is set on the GrGLCaps
271 this->initGLSL(ctxInfo);
272 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
273
egdaniel05ded892015-10-26 07:38:05 -0700274 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
275
276 // For now these two are equivalent but we could have dst read in shader via some other method.
277 // Before setting this, initGLSL() must have been called.
278 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
279
280 // Enable supported shader-related caps
281 if (kGL_GrGLStandard == standard) {
282 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
283 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
284 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
285 glslCaps->fShaderDerivativeSupport = true;
286 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
287 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
288 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
cdalton793dc262016-02-08 10:11:47 -0800289 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
290 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
egdaniel05ded892015-10-26 07:38:05 -0700291 }
292 else {
293 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
294
295 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
296 ctxInfo.hasExtension("GL_OES_standard_derivatives");
cdalton793dc262016-02-08 10:11:47 -0800297
298 glslCaps->fIntegerSupport = ctxInfo.version() >= GR_GL_VER(3, 0) &&
299 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // We use this value for GLSL ES 3.0.
egdaniel05ded892015-10-26 07:38:05 -0700300 }
301
ethannicholas22793252016-01-30 09:59:10 -0800302 if (ctxInfo.hasExtension("GL_EXT_shader_pixel_local_storage")) {
303 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
304 GR_GL_GetIntegerv(gli, GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT,
305 &glslCaps->fPixelLocalStorageSize);
306 glslCaps->fPLSPathRenderingSupport = glslCaps->fFBFetchSupport;
307 }
308 else {
309 glslCaps->fPixelLocalStorageSize = 0;
310 glslCaps->fPLSPathRenderingSupport = false;
311 }
312
egdaniel05ded892015-10-26 07:38:05 -0700313 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700314 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000315 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700316
cdalton63f6c1f2015-11-06 07:09:43 -0800317 // We need dual source blending and the ability to disable multisample in order to support mixed
318 // samples in every corner case.
egdanieleed519e2016-01-15 11:36:18 -0800319 if (fMultisampleDisableSupport &&
320 glslCaps->dualSourceBlendingSupport() &&
321 fShaderCaps->pathRenderingSupport()) {
322 fUsesMixedSamples = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
kkinnunenea409432015-12-10 01:21:59 -0800323 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800324 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
kkinnunen9f63b442016-01-25 00:31:49 -0800325 if (fUsesMixedSamples && (kNVIDIA_GrGLDriver == ctxInfo.driver() ||
326 kChromium_GrGLDriver == ctxInfo.driver())) {
cdalton63f6c1f2015-11-06 07:09:43 -0800327 fDiscardRenderTargetSupport = false;
328 fInvalidateFBType = kNone_InvalidateFBType;
329 }
330 }
331
egdanieleed519e2016-01-15 11:36:18 -0800332 // fUsesMixedSamples must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700333 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700334 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700335 this->initStencilFormats(ctxInfo);
336
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000337 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000338 // we could also look for GL_ATI_separate_stencil extension or
339 // GL_EXT_stencil_two_side but they use different function signatures
340 // than GL2.0+ (and than each other).
341 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
342 // supported on GL 1.4 and higher or by extension
343 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
344 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
345 } else {
346 // ES 2 has two sided stencil and stencil wrap
347 fTwoSidedStencilSupport = true;
348 fStencilWrapOpsSupport = true;
349 }
350
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000351 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000352 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
353 // extension includes glMapBuffer.
354 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
355 fMapBufferFlags |= kSubset_MapFlag;
356 fMapBufferType = kMapBufferRange_MapBufferType;
357 } else {
358 fMapBufferType = kMapBuffer_MapBufferType;
359 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000360 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000361 // Unextended GLES2 doesn't have any buffer mapping.
362 fMapBufferFlags = kNone_MapBufferType;
363 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
364 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
365 fMapBufferType = kChromium_MapBufferType;
366 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
367 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
368 fMapBufferType = kMapBufferRange_MapBufferType;
369 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
370 fMapBufferFlags = kCanMap_MapFlag;
371 fMapBufferType = kMapBuffer_MapBufferType;
372 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000373 }
374
jvanverthd7a2c1f2015-12-07 07:36:44 -0800375 if (kGL_GrGLStandard == standard) {
376 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
377 fTransferBufferType = kPBO_TransferBufferType;
378 }
379 } else {
380 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
381 fTransferBufferType = kPBO_TransferBufferType;
382 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
383 fTransferBufferType = kChromium_TransferBufferType;
384 }
385 }
386
joshualitte5b74c62015-06-01 14:17:47 -0700387 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
388 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
389 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700390 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
391 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
392 // a small subset.
393#if 0
cdalton1acea862015-06-02 13:05:52 -0700394 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700395#else
396 fGeometryBufferMapThreshold = SK_MaxS32;
397#endif
joshualitte5b74c62015-06-01 14:17:47 -0700398 }
399
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000400 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000401 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
402 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
403 fNPOTTextureTileSupport = true;
404 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000405 } else {
406 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000407 // ES3 has no limitations.
408 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
409 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000410 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
411 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
412 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
413 // to alllow arbitrary wrap modes, however.
414 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000415 }
416
bsalomone72bd022015-10-26 07:33:03 -0700417 // Using MIPs on this GPU seems to be a source of trouble.
418 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
419 fMipMapSupport = false;
420 }
421
bsalomon@google.combcce8922013-03-25 15:38:39 +0000422 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
423 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
424 // Our render targets are always created with textures as the color
425 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000426 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000427
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000428 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
429
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000430 // Disable scratch texture reuse on Mali and Adreno devices
431 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
432 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000433
robertphillips1b8e1b52015-06-24 06:54:10 -0700434#if 0
435 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
436 kQualcomm_GrGLVendor != ctxInfo.vendor();
437#endif
438
egdaniel05ded892015-10-26 07:38:05 -0700439 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000440 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800441 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000442 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
cdaltonaf8bc7d2016-02-05 09:35:20 -0800443 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxStencilSampleCount);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000444 }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800445 // We only have a use for raster multisample if there is coverage modulation from mixed samples.
446 if (fUsesMixedSamples && ctxInfo.hasExtension("GL_EXT_raster_multisample")) {
447 GR_GL_GetIntegerv(gli, GR_GL_MAX_RASTER_SAMPLES, &fMaxRasterSamples);
448 // This is to guard against platforms that may not support as many samples for
449 // glRasterSamples as they do for framebuffers.
450 fMaxStencilSampleCount = SkTMin(fMaxStencilSampleCount, fMaxRasterSamples);
451 }
452 fMaxColorSampleCount = fMaxStencilSampleCount;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000453
bsalomon63b21962014-11-05 07:05:34 -0800454 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800455 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800456 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800457 fUseDrawInsteadOfClear = true;
458 }
459
joshualitt83bc2292015-06-18 14:18:02 -0700460 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
461 fUseDrawInsteadOfPartialRenderTargetWrite = true;
462 }
463
bsalomonbabafcc2016-02-16 11:36:47 -0800464 // Texture uploads sometimes seem to be ignored to textures bound to FBOS on Tegra3.
465 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
466 fUseDrawInsteadOfPartialRenderTargetWrite = true;
467 fUseDrawInsteadOfAllRenderTargetWrites = true;
468 }
469
robertphillips63926682015-08-20 09:39:02 -0700470#ifdef SK_BUILD_FOR_WIN
471 // On ANGLE deferring flushes can lead to GPU starvation
472 fPreferVRAMUseOverFlushes = !isANGLE;
473#endif
474
bsalomon7dea7b72015-08-19 08:26:51 -0700475 if (kChromium_GrGLDriver == ctxInfo.driver()) {
476 fMustClearUploadedBufferData = true;
477 }
478
bsalomond08ea5f2015-02-20 06:58:13 -0800479 if (kGL_GrGLStandard == standard) {
480 // ARB allows mixed size FBO attachments, EXT does not.
481 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
482 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
483 fOversizedStencilSupport = true;
484 } else {
485 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
486 }
487 } else {
488 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
489 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
490 }
491
joshualitt58001552015-06-26 12:46:36 -0700492 if (kGL_GrGLStandard == standard) {
493 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
494 // instanced arrays, but we could make this more granular if we wanted
495 fSupportsInstancedDraws =
496 version >= GR_GL_VER(3, 2) ||
497 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
498 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
499 } else {
500 fSupportsInstancedDraws =
501 version >= GR_GL_VER(3, 0) ||
502 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
503 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
504 }
505
cdalton06604b92016-02-05 10:09:51 -0800506 if (kGL_GrGLStandard == standard) {
507 // We don't use ARB_draw_indirect because it does not support a base instance.
508 // We don't use ARB_multi_draw_indirect because it does not support GL_DRAW_INDIRECT_BUFFER.
509 fDrawIndirectSupport =
510 fMultiDrawIndirectSupport = fBaseInstanceSupport = version >= GR_GL_VER(4,3);
511 } else {
512 fDrawIndirectSupport = version >= GR_GL_VER(3,1);
513 fMultiDrawIndirectSupport = ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
514 fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
515 }
516
jvanverthcba99b82015-06-24 06:59:57 -0700517 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
bsalomoncdee0092016-01-08 13:20:12 -0800518
519 if (contextOptions.fUseShaderSwizzling) {
520 fTextureSwizzleSupport = false;
521 }
522
523 // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
524 // already been detected.
525 this->initConfigTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700526
527 this->applyOptionsOverrides(contextOptions);
528 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000529}
530
egdaniel472d44e2015-10-22 08:20:00 -0700531const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
532 bool isCoreProfile) {
533 switch (generation) {
534 case k110_GrGLSLGeneration:
535 if (kGLES_GrGLStandard == standard) {
536 // ES2s shader language is based on version 1.20 but is version
537 // 1.00 of the ES language.
538 return "#version 100\n";
539 } else {
540 SkASSERT(kGL_GrGLStandard == standard);
541 return "#version 110\n";
542 }
543 case k130_GrGLSLGeneration:
544 SkASSERT(kGL_GrGLStandard == standard);
545 return "#version 130\n";
546 case k140_GrGLSLGeneration:
547 SkASSERT(kGL_GrGLStandard == standard);
548 return "#version 140\n";
549 case k150_GrGLSLGeneration:
550 SkASSERT(kGL_GrGLStandard == standard);
551 if (isCoreProfile) {
552 return "#version 150\n";
553 } else {
554 return "#version 150 compatibility\n";
555 }
556 case k330_GrGLSLGeneration:
557 if (kGLES_GrGLStandard == standard) {
558 return "#version 300 es\n";
559 } else {
560 SkASSERT(kGL_GrGLStandard == standard);
561 if (isCoreProfile) {
562 return "#version 330\n";
563 } else {
564 return "#version 330 compatibility\n";
565 }
566 }
567 case k310es_GrGLSLGeneration:
568 SkASSERT(kGLES_GrGLStandard == standard);
569 return "#version 310 es\n";
570 }
571 return "<no version>";
572}
573
egdaniel05ded892015-10-26 07:38:05 -0700574void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700575 GrGLStandard standard = ctxInfo.standard();
576 GrGLVersion version = ctxInfo.version();
577
578 /**************************************************************************
579 * Caps specific to GrGLSLCaps
580 **************************************************************************/
581
582 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
583 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700584 if (kGLES_GrGLStandard == standard) {
585 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
586 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
587 glslCaps->fFBFetchSupport = true;
588 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
589 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
590 }
591 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
592 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
593 glslCaps->fFBFetchNeedsCustomOutput = false;
594 glslCaps->fFBFetchSupport = true;
595 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
596 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
597 }
598 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
599 // The arm extension also requires an additional flag which we will set onResetContext
600 glslCaps->fFBFetchNeedsCustomOutput = false;
601 glslCaps->fFBFetchSupport = true;
602 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
603 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
604 }
605 glslCaps->fUsesPrecisionModifiers = true;
606 }
607
608 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
609
cdaltonc08f1962016-02-12 12:14:06 -0800610 if (kGL_GrGLStandard == standard) {
611 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
612 } else {
613 glslCaps->fFlatInterpolationSupport =
614 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
615 }
616
617 if (kGL_GrGLStandard == standard) {
618 glslCaps->fNoPerspectiveInterpolationSupport =
619 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
620 } else {
621 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
622 glslCaps->fNoPerspectiveInterpolationSupport = true;
623 glslCaps->fNoPerspectiveInterpolationExtensionString =
624 "GL_NV_shader_noperspective_interpolation";
625 }
626 }
627
egdaniel472d44e2015-10-22 08:20:00 -0700628 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
629 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
630
631 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
632 // function that may require a gradient calculation inside a conditional block may return
633 // undefined results". This appears to be an issue with the 'any' call since even the simple
634 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
635 // from our GrTextureDomain processor.
636 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
637
egdaniel472d44e2015-10-22 08:20:00 -0700638 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
639 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800640
641 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
642 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
643 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800644
645 // Frag Coords Convention support is not part of ES
646 // Known issue on at least some Intel platforms:
647 // http://code.google.com/p/skia/issues/detail?id=946
648 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
649 kGLES_GrGLStandard != standard &&
650 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
651 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
652 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
653 }
654
655 if (kGLES_GrGLStandard == standard) {
656 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
657 }
658
bsalomon7ea33f52015-11-22 14:51:00 -0800659 if (fExternalTextureSupport) {
660 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
661 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
662 } else {
663 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
664 }
665 }
666
egdaniel8dcdedc2015-11-11 06:27:20 -0800667 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
668 // the abs first in a separate expression.
669 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
670 glslCaps->fCanUseMinAndAbsTogether = false;
671 }
672
bsalomon7ea33f52015-11-22 14:51:00 -0800673 // 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 -0800674 // thus must us -1.0 * %s.x to work correctly
675 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
676 glslCaps->fMustForceNegatedAtanParamToFloat = true;
677 }
egdaniel472d44e2015-10-22 08:20:00 -0700678}
679
kkinnunencfe62e32015-07-01 02:58:50 -0700680bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700681 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
682
683 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700684 return false;
685 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700686
kkinnunencfe62e32015-07-01 02:58:50 -0700687 if (kGL_GrGLStandard == ctxInfo.standard()) {
688 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
689 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
690 return false;
691 }
692 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700693 if (!hasChromiumPathRendering &&
694 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700695 return false;
696 }
697 }
698 // We only support v1.3+ of GL_NV_path_rendering which allows us to
699 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
700 // additions are detected by checking the existence of the function.
701 // We also use *Then* functions that not all drivers might have. Check
702 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800703 if (!gli->fFunctions.fStencilThenCoverFillPath ||
704 !gli->fFunctions.fStencilThenCoverStrokePath ||
705 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
706 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
707 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700708 return false;
709 }
710 return true;
711}
bsalomon1aa20292016-01-22 08:16:09 -0800712
713bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800714 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800715 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
716 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800717 // If it's not possible to even have a render target of rtConfig then read pixels is
718 // not supported regardless of readConfig.
719 if (!this->isConfigRenderable(rtConfig, false)) {
720 return false;
721 }
bsalomon7928ef62016-01-05 10:26:39 -0800722
bsalomon76148af2016-01-12 11:13:47 -0800723 GrGLenum readFormat;
724 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800725 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800726 return false;
727 }
728
bsalomon1aa20292016-01-22 08:16:09 -0800729 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800730 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
731 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
732 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
733 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
734 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
735 readFormat != GR_GL_BGRA) {
736 return false;
737 }
738 // There is also a set of allowed types, but all the types we use are in the set:
739 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
740 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
741 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
742 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
743 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
744 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
745 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800746 return true;
piotaixre4b23142014-10-02 10:57:53 -0700747 }
bsalomon7928ef62016-01-05 10:26:39 -0800748
bsalomon76148af2016-01-12 11:13:47 -0800749 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800750
bsalomon1aa20292016-01-22 08:16:09 -0800751 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800752 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
753 return true;
754 }
755 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800756 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800757 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
758 return true;
759 }
760 }
761
bsalomon1aa20292016-01-22 08:16:09 -0800762 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800763 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800764 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800765 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800766 if (!bindRenderTarget()) {
767 return false;
768 }
769 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
770 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800771 rpFormat->fFormat = format;
772 rpFormat->fType = type;
773 }
774
bsalomon1aa20292016-01-22 08:16:09 -0800775 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
776 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700777}
778
robertphillips@google.com6177e692013-02-28 20:16:25 +0000779void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000780
781 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000782 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000783 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
784 // ES3 driver bugs on at least one device with a tiled GPU (N10).
785 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
786 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
787 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
788 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800789 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700790 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000791 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000792 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
793 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
794 // chrome's extension is equivalent to the EXT msaa
795 // and fbo_blit extensions.
796 fMSFBOType = kDesktop_EXT_MSFBOType;
797 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
798 fMSFBOType = kES_Apple_MSFBOType;
799 }
bsalomon083617b2016-02-12 12:10:14 -0800800
801 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
802 // is available.
803 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
804 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
805 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
806 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
807 // limitations.
808 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
809 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000810 } else {
egdanieleed519e2016-01-15 11:36:18 -0800811 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700812 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800813 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700814 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000815 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000816 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800817 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000818 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
819 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000820 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800821 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000822 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000823 }
824}
825
cdalton1dd05422015-06-12 09:01:18 -0700826void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
827 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
828
829 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
830 // for now until its own blacklists can be updated.
831 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
832 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700833 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700834 return;
835 }
836
837 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
838 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
839 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
840 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
841 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
842 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
843 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
844 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
845 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
846 return;
847 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
848 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
849 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
850 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
851 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
852 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
853 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
854 // slow on a particular platform.
855 } else {
856 return; // No advanced blend support.
857 }
858
859 SkASSERT(this->advancedBlendEquationSupport());
860
861 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
862 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
863 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
864 (1 << kColorBurn_GrBlendEquation);
865 }
joel.liang9764c402015-07-09 19:46:18 -0700866 if (kARM_GrGLVendor == ctxInfo.vendor()) {
867 // Blacklist color-burn on ARM until the fix is released.
868 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
869 }
cdalton1dd05422015-06-12 09:01:18 -0700870}
871
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000872namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700873const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000874}
875
876void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
877
878 // Build up list of legal stencil formats (though perhaps not supported on
879 // the particular gpu/driver) from most preferred to least.
880
881 // these consts are in order of most preferred to least preferred
882 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
883
884 static const StencilFormat
885 // internal Format stencil bits total bits packed?
886 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
887 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
888 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
889 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000890 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000891 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
892
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000893 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000894 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000895 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000896 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
897 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
898
899 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
900 // require FBO support we can expect these are legal formats and don't
901 // check. These also all support the unsized GL_STENCIL_INDEX.
902 fStencilFormats.push_back() = gS8;
903 fStencilFormats.push_back() = gS16;
904 if (supportsPackedDS) {
905 fStencilFormats.push_back() = gD24S8;
906 }
907 fStencilFormats.push_back() = gS4;
908 if (supportsPackedDS) {
909 fStencilFormats.push_back() = gDS;
910 }
911 } else {
912 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
913 // for other formats.
914 // ES doesn't support using the unsized format.
915
916 fStencilFormats.push_back() = gS8;
917 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000918 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
919 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000920 fStencilFormats.push_back() = gD24S8;
921 }
922 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
923 fStencilFormats.push_back() = gS4;
924 }
925 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000926}
927
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000928SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000929
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000930 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000931
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000932 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000933 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000934 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000935 i,
936 fStencilFormats[i].fStencilBits,
937 fStencilFormats[i].fTotalBits);
938 }
939
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000940 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000941 "None",
942 "ARB",
943 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000944 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000945 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000946 "IMG MS To Texture",
947 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -0700948 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000949 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000950 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
951 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
952 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000953 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
954 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
955 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
956 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -0700957 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000958 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000959
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000960 static const char* kInvalidateFBTypeStr[] = {
961 "None",
962 "Discard",
963 "Invalidate",
964 };
965 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
966 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
967 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
968 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000969
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000970 static const char* kMapBufferTypeStr[] = {
971 "None",
972 "MapBuffer",
973 "MapBufferRange",
974 "Chromium",
975 };
976 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
977 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
978 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
979 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
980 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
981
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000982 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000983 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000984 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000985 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000986 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
987 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000988 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000989 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
990 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
991 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
992 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000993
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000994 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
995 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
996 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
997 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000998 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -0700999 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1000 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001001 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001002 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1003 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1004 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001005 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001006 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001007 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001008 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1009 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001010 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001011 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001012 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001013 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001014
1015 r.append("Configs\n-------\n");
1016 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1017 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001018 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1019 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001020 i,
1021 fConfigTable[i].fFlags,
1022 fConfigTable[i].fFormats.fBaseInternalFormat,
1023 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001024 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1025 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001026 fConfigTable[i].fFormats.fExternalType,
1027 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001028 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001029 }
1030
jvanverthe9c0fc62015-04-29 11:18:05 -07001031 return r;
1032}
1033
jvanverthe9c0fc62015-04-29 11:18:05 -07001034static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1035 switch (p) {
1036 case kLow_GrSLPrecision:
1037 return GR_GL_LOW_FLOAT;
1038 case kMedium_GrSLPrecision:
1039 return GR_GL_MEDIUM_FLOAT;
1040 case kHigh_GrSLPrecision:
1041 return GR_GL_HIGH_FLOAT;
1042 }
1043 SkFAIL("Unknown precision.");
1044 return -1;
1045}
1046
1047static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1048 switch (type) {
1049 case kVertex_GrShaderType:
1050 return GR_GL_VERTEX_SHADER;
1051 case kGeometry_GrShaderType:
1052 return GR_GL_GEOMETRY_SHADER;
1053 case kFragment_GrShaderType:
1054 return GR_GL_FRAGMENT_SHADER;
1055 }
1056 SkFAIL("Unknown shader type.");
1057 return -1;
1058}
1059
jvanverthcba99b82015-06-24 06:59:57 -07001060void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1061 const GrGLInterface* intf,
1062 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001063 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1064 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1065 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1066 if (kGeometry_GrShaderType != s) {
1067 GrShaderType shaderType = static_cast<GrShaderType>(s);
1068 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001069 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001070 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001071 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1072 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1073 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1074 GrGLint range[2];
1075 GrGLint bits;
1076 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1077 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001078 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1079 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1080 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001081 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001082 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001083 }
jvanverthcba99b82015-06-24 06:59:57 -07001084 else if (!glslCaps->fShaderPrecisionVaries) {
1085 glslCaps->fShaderPrecisionVaries =
1086 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001087 }
1088 }
1089 }
1090 }
1091 }
1092 }
1093 else {
1094 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001095 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001096 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1097 if (kGeometry_GrShaderType != s) {
1098 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001099 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1100 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1101 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001102 }
1103 }
1104 }
1105 }
1106 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1107 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1108 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1109 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001110 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001111 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001112 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1113 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001114 }
1115 }
1116}
1117
bsalomon41e4384e2016-01-08 09:12:44 -08001118bool GrGLCaps::bgraIsInternalFormat() const {
1119 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1120}
1121
bsalomon76148af2016-01-12 11:13:47 -08001122bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1123 GrGLenum* internalFormat, GrGLenum* externalFormat,
1124 GrGLenum* externalType) const {
1125 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1126 externalFormat, externalType)) {
1127 return false;
1128 }
1129 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1130 return true;
1131}
1132
1133bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1134 GrGLenum* internalFormat) const {
1135 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1136 return false;
1137 }
1138 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1139 return true;
1140}
1141
1142bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1143 GrGLenum* externalFormat, GrGLenum* externalType) const {
1144 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1145 externalFormat, externalType)) {
1146 return false;
1147 }
1148 return true;
1149}
1150
1151bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1152 if (GrPixelConfigIsCompressed(config)) {
1153 return false;
1154 }
1155 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1156 return true;
1157}
1158
1159bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1160 ExternalFormatUsage usage, GrGLenum* externalFormat,
1161 GrGLenum* externalType) const {
1162 SkASSERT(externalFormat && externalType);
1163 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1164 return false;
1165 }
1166
1167 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1168 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1169
1170 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1171 // made to work in many cases using glPixelStore and what not but is not needed currently.
1172 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1173 return false;
1174 }
1175
1176 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1177 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1178
bsalomone9573312016-01-25 14:33:25 -08001179 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1180 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1181 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1182 // texture, not the red component.
1183 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1184 if (this->textureRedSupport()) {
1185 SkASSERT(GR_GL_RED == *externalFormat);
1186 *externalFormat = GR_GL_ALPHA;
1187 }
1188 }
1189
bsalomon76148af2016-01-12 11:13:47 -08001190 return true;
1191}
1192
bsalomoncdee0092016-01-08 13:20:12 -08001193void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1194 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001195 /*
1196 Comments on renderability of configs on various GL versions.
1197 OpenGL < 3.0:
1198 no built in support for render targets.
1199 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1200 format RGB, RGBA and NV float formats we don't use.
1201 This is the following:
1202 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1203 RGB10_A2, RGBA12,RGBA16
1204 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1205 since they aren't required by later standards and the driver can simply return
1206 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1207 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1208 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1209 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1210 This adds a lot of additional renderable sized formats, including ALPHA8.
1211 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1212 16F, 32I, 32UI, and 32F variants).
1213 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1214
1215 For both the above extensions we limit ourselves to those that are also required by
1216 OpenGL 3.0.
1217
1218 OpenGL 3.0:
1219 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1220 but are not required to be supported as renderable textures/renderbuffer.
1221 Required renderable color formats:
1222 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1223 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1224 RGB10_A2.
1225 - R11F_G11F_B10F.
1226 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1227 and RG8UI.
1228 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1229 - ALPHA8
1230
1231 OpenGL 3.1, 3.2, 3.3
1232 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1233 OpengGL 3.3, 4.0, 4.1
1234 Adds RGB10_A2UI.
1235 OpengGL 4.2
1236 Adds
1237 - RGB5_A1, RGBA4
1238 - RGB565
1239 OpenGL 4.4
1240 Does away with the separate list and adds a column to the sized internal color format
1241 table. However, no new formats become required color renderable.
1242
1243 ES 2.0
1244 color renderable: RGBA4, RGB5_A1, RGB565
1245 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1246 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1247 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1248 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1249 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1250 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1251
1252 ES 3.0
1253 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1254 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1255 RGB5_A1.
1256 - RGB8 and RGB565.
1257 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1258 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1259 ES 3.1
1260 Adds RGB10_A2, RGB10_A2UI,
1261 ES 3.2
1262 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1263 */
1264 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1265 if (kNone_MSFBOType != fMSFBOType) {
1266 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1267 }
1268
1269 GrGLStandard standard = ctxInfo.standard();
1270 GrGLVersion version = ctxInfo.version();
1271
bsalomon30447372015-12-21 09:03:05 -08001272 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1273 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001274 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001275 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001276 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001277 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001278
1279 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1280 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001281 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1282 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001283 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001284 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001285 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1286 if (kGL_GrGLStandard == standard) {
1287 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1288 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001289 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001290 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1291 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1292 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1293 }
egdaniel4999df82016-01-07 17:06:04 -08001294 }
bsalomoncdee0092016-01-08 13:20:12 -08001295 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001296
bsalomon76148af2016-01-12 11:13:47 -08001297 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1298 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001299 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001300 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001301 if (kGL_GrGLStandard == standard) {
1302 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1303 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1304 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1305 // Since the internal format is RGBA8, it is also renderable.
1306 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1307 allRenderFlags;
1308 }
1309 } else {
1310 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1311 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1312 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1313 // The APPLE extension doesn't make this renderable.
1314 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1315 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1316 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1317 // Though, that seems to not be the case if the texture storage extension is
1318 // present. The specs don't exactly make that clear.
1319 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1320 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1321 }
1322 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1323 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1324 ConfigInfo::kRenderable_Flag;
1325 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001326 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001327 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1328 ConfigInfo::kRenderableWithMSAA_Flag;
1329 }
1330 }
1331 }
bsalomoncdee0092016-01-08 13:20:12 -08001332 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001333
bsalomon41e4384e2016-01-08 09:12:44 -08001334 // We only enable srgb support if both textures and FBOs support srgb.
1335 bool srgbSupport = false;
1336 if (kGL_GrGLStandard == standard) {
1337 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1338 srgbSupport = true;
1339 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1340 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1341 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1342 srgbSupport = true;
1343 }
1344 }
1345 // All the above srgb extensions support toggling srgb writes
1346 fSRGBWriteControl = srgbSupport;
1347 } else {
1348 // See https://bug.skia.org/4148 for PowerVR issue.
1349 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1350 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1351 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1352 // sRGB writing for destinations.
1353 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1354 }
bsalomon30447372015-12-21 09:03:05 -08001355 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1356 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1357 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1358 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001359 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1360 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001361 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001362 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001363 if (srgbSupport) {
1364 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1365 allRenderFlags;
1366 }
bsalomoncdee0092016-01-08 13:20:12 -08001367 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001368
1369 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1370 if (this->ES2CompatibilitySupport()) {
1371 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1372 } else {
1373 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1374 }
bsalomon76148af2016-01-12 11:13:47 -08001375 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1376 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001377 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001378 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001379 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1380 if (kGL_GrGLStandard == standard) {
1381 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1382 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1383 }
1384 } else {
1385 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1386 }
bsalomoncdee0092016-01-08 13:20:12 -08001387 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001388
1389 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1390 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001391 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1392 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001393 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001394 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001395 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1396 if (kGL_GrGLStandard == standard) {
1397 if (version >= GR_GL_VER(4, 2)) {
1398 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1399 }
1400 } else {
1401 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1402 }
bsalomoncdee0092016-01-08 13:20:12 -08001403 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001404
1405 if (this->textureRedSupport()) {
1406 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1407 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001408 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1409 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001410 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001411 } else {
1412 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1413 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001414 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1415 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001416 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001417 }
1418 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001419 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001420 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1421 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1422 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1423 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1424 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1425 }
1426
1427 // Check for [half] floating point texture support
1428 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1429 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1430 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1431 bool hasFPTextures = false;
1432 bool hasHalfFPTextures = false;
1433 // for now we don't support floating point MSAA on ES
1434 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1435 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1436
1437 if (kGL_GrGLStandard == standard) {
1438 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1439 hasFPTextures = true;
1440 hasHalfFPTextures = true;
1441 }
1442 } else {
1443 if (version >= GR_GL_VER(3, 1)) {
1444 hasFPTextures = true;
1445 hasHalfFPTextures = true;
1446 } else {
1447 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1448 ctxInfo.hasExtension("GL_OES_texture_float")) {
1449 hasFPTextures = true;
1450 }
1451 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1452 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1453 hasHalfFPTextures = true;
1454 }
1455 }
1456 }
bsalomon30447372015-12-21 09:03:05 -08001457
1458 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1459 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001460 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1461 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001462 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001463 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001464 if (hasFPTextures) {
1465 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1466 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1467 // many precision issues and no clients actually want this yet.
1468 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1469 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1470 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1471 }
1472 }
bsalomoncdee0092016-01-08 13:20:12 -08001473 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001474
1475 if (this->textureRedSupport()) {
1476 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1477 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001478 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1479 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001480 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001481 } else {
1482 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1483 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001484 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1485 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001486 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001487 }
1488 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1489 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1490 } else {
1491 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1492 }
bsalomon7928ef62016-01-05 10:26:39 -08001493 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001494 if (hasHalfFPTextures) {
1495 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1496 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1497 // GL_RED internal format.
1498 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1499 (this->textureRedSupport() &&
1500 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1501 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1502 }
1503 }
bsalomon30447372015-12-21 09:03:05 -08001504
1505 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1506 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001507 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1508 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001509 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1510 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1511 } else {
1512 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1513 }
bsalomon7928ef62016-01-05 10:26:39 -08001514 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001515 if (hasHalfFPTextures) {
1516 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1517 // ES requires 3.2 or EXT_color_buffer_half_float.
1518 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1519 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1520 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1521 }
1522 }
bsalomoncdee0092016-01-08 13:20:12 -08001523 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001524
1525 // Compressed texture support
1526
1527 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1528 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1529
1530 // TODO: Fix command buffer bindings and remove this.
1531 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001532
1533 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001534 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001535
1536 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1537 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001538 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001539 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001540 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001541 // Disable this for now, while we investigate https://bug.skia.org/4333
1542 if (false) {
1543 // Check for 8-bit palette..
1544 GrGLint numFormats;
1545 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1546 if (numFormats) {
1547 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1548 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1549 for (int i = 0; i < numFormats; ++i) {
1550 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1551 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1552 break;
1553 }
1554 }
1555 }
1556 }
bsalomoncdee0092016-01-08 13:20:12 -08001557 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001558
bsalomon41e4384e2016-01-08 09:12:44 -08001559 // May change the internal format based on extensions.
1560 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1561 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1562 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1563 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1564 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1565 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1566 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1567 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1568 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1569 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1570 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1571 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1572 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1573 GR_GL_COMPRESSED_RED_RGTC1;
1574 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1575 GR_GL_COMPRESSED_RED_RGTC1;
1576 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1577 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1578 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1579 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1580 GR_GL_COMPRESSED_3DC_X;
1581
bsalomon30447372015-12-21 09:03:05 -08001582 }
bsalomon76148af2016-01-12 11:13:47 -08001583 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001584 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001585 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001586 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001587
1588 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1589 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001590 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001591 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001592 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001593 if (kGL_GrGLStandard == standard) {
1594 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1595 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1596 }
1597 } else {
1598 if (version >= GR_GL_VER(3, 0) ||
1599 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1600 // ETC2 is a superset of ETC1, so we can just check for that, too.
1601 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1602 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1603 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1604 }
1605 }
bsalomoncdee0092016-01-08 13:20:12 -08001606 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001607
1608 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1609 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001610 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001611 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001612 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001613 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1614 // decompressing the textures in the driver, and is generally slower.
1615 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1616 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1617 }
bsalomoncdee0092016-01-08 13:20:12 -08001618 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001619
1620 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1621 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1622 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1623 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001624 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1625 0;
bsalomon30447372015-12-21 09:03:05 -08001626 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001627 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001628 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1629 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1630 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1631 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1632 }
bsalomoncdee0092016-01-08 13:20:12 -08001633 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001634
1635 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1636
1637 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001638 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1639 ctxInfo.version() >= GR_GL_VER(3,0));
1640 // All ES versions (thus far) require sized internal formats for render buffers.
1641 // TODO: Always use sized internal format?
1642 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1643
bsalomon30447372015-12-21 09:03:05 -08001644 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001645 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1646 // param to glTex[Sub]Image.
1647 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1648 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1649 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1650 fConfigTable[i].fFormats.fSizedInternalFormat :
1651 fConfigTable[i].fFormats.fBaseInternalFormat;
1652 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001653 fConfigTable[i].fFormats.fSizedInternalFormat :
1654 fConfigTable[i].fFormats.fBaseInternalFormat;
1655 }
1656 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1657 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1658 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1659 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1660 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001661 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001662 GR_GL_SRGB_ALPHA;
1663 }
1664
1665 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1666 // as a base format.
1667 // GL_EXT_texture_format_BGRA8888:
1668 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1669 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1670 // formats.
1671 // GL_APPLE_texture_format_BGRA8888:
1672 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1673 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1674 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001675 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001676 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1677 }
1678
bsalomoncdee0092016-01-08 13:20:12 -08001679 // If we don't have texture swizzle support then the shader generator must insert the
1680 // swizzle into shader code.
1681 if (!this->textureSwizzleSupport()) {
1682 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1683 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1684 }
1685 }
1686
bsalomon7f9b2e42016-01-12 13:29:26 -08001687 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1688 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1689 // gets written to the single component.
1690 if (this->textureRedSupport()) {
1691 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1692 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1693 if (GrPixelConfigIsAlphaOnly(config) &&
1694 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1695 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1696 }
1697 }
1698 }
1699
bsalomon30447372015-12-21 09:03:05 -08001700#ifdef SK_DEBUG
1701 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001702 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001703 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001704 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1705 fConfigTable[i].fFormats.fBaseInternalFormat);
1706 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001707 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001708 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1709 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1710 fConfigTable[i].fFormats.fExternalFormat[j]);
1711 }
1712 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001713 }
1714#endif
1715}
1716
egdanielb7e7d572015-11-04 04:23:53 -08001717void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}