blob: 546b0bf692a57b621d28ae7dd7e7a1b34b688ed5 [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 }
cdalton33ad7012016-02-22 07:55:44 -0800567 case k400_GrGLSLGeneration:
568 SkASSERT(kGL_GrGLStandard == standard);
569 if (isCoreProfile) {
570 return "#version 400\n";
571 } else {
572 return "#version 400 compatibility\n";
573 }
egdaniel472d44e2015-10-22 08:20:00 -0700574 case k310es_GrGLSLGeneration:
575 SkASSERT(kGLES_GrGLStandard == standard);
576 return "#version 310 es\n";
cdalton33ad7012016-02-22 07:55:44 -0800577 case k320es_GrGLSLGeneration:
578 SkASSERT(kGLES_GrGLStandard == standard);
579 return "#version 320 es\n";
egdaniel472d44e2015-10-22 08:20:00 -0700580 }
581 return "<no version>";
582}
583
egdaniel05ded892015-10-26 07:38:05 -0700584void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700585 GrGLStandard standard = ctxInfo.standard();
586 GrGLVersion version = ctxInfo.version();
587
588 /**************************************************************************
589 * Caps specific to GrGLSLCaps
590 **************************************************************************/
591
592 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
593 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
egdaniel472d44e2015-10-22 08:20:00 -0700594 if (kGLES_GrGLStandard == standard) {
595 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
596 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
597 glslCaps->fFBFetchSupport = true;
598 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
599 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
600 }
601 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
602 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
603 glslCaps->fFBFetchNeedsCustomOutput = false;
604 glslCaps->fFBFetchSupport = true;
605 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
606 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
607 }
608 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
609 // The arm extension also requires an additional flag which we will set onResetContext
610 glslCaps->fFBFetchNeedsCustomOutput = false;
611 glslCaps->fFBFetchSupport = true;
612 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
613 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
614 }
615 glslCaps->fUsesPrecisionModifiers = true;
616 }
617
618 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
619
cdaltonc08f1962016-02-12 12:14:06 -0800620 if (kGL_GrGLStandard == standard) {
621 glslCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
622 } else {
623 glslCaps->fFlatInterpolationSupport =
624 ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; // This is the value for GLSL ES 3.0.
625 }
626
627 if (kGL_GrGLStandard == standard) {
628 glslCaps->fNoPerspectiveInterpolationSupport =
629 ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
630 } else {
631 if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation")) {
632 glslCaps->fNoPerspectiveInterpolationSupport = true;
633 glslCaps->fNoPerspectiveInterpolationExtensionString =
634 "GL_NV_shader_noperspective_interpolation";
635 }
636 }
637
cdalton33ad7012016-02-22 07:55:44 -0800638 if (kGL_GrGLStandard == standard) {
639 glslCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
640 } else {
641 if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
642 glslCaps->fSampleVariablesSupport = true;
643 } else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
644 glslCaps->fSampleVariablesSupport = true;
645 glslCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
646 }
647 }
648
649 if (glslCaps->fSampleVariablesSupport) {
650 glslCaps->fSampleMaskOverrideCoverageSupport =
651 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage");
652 }
653
egdaniel472d44e2015-10-22 08:20:00 -0700654 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
655 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
656
657 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
658 // function that may require a gradient calculation inside a conditional block may return
659 // undefined results". This appears to be an issue with the 'any' call since even the simple
660 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
661 // from our GrTextureDomain processor.
662 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
663
egdaniel472d44e2015-10-22 08:20:00 -0700664 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
665 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800666
667 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
668 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
669 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800670
671 // Frag Coords Convention support is not part of ES
672 // Known issue on at least some Intel platforms:
673 // http://code.google.com/p/skia/issues/detail?id=946
674 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
675 kGLES_GrGLStandard != standard &&
676 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
677 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
678 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
679 }
680
681 if (kGLES_GrGLStandard == standard) {
682 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
683 }
684
bsalomon7ea33f52015-11-22 14:51:00 -0800685 if (fExternalTextureSupport) {
686 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
687 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
688 } else {
689 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
690 }
691 }
692
egdaniel8dcdedc2015-11-11 06:27:20 -0800693 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
694 // the abs first in a separate expression.
695 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
696 glslCaps->fCanUseMinAndAbsTogether = false;
697 }
698
bsalomon7ea33f52015-11-22 14:51:00 -0800699 // 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 -0800700 // thus must us -1.0 * %s.x to work correctly
701 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
702 glslCaps->fMustForceNegatedAtanParamToFloat = true;
703 }
egdaniel472d44e2015-10-22 08:20:00 -0700704}
705
kkinnunencfe62e32015-07-01 02:58:50 -0700706bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700707 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
708
709 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700710 return false;
711 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700712
kkinnunencfe62e32015-07-01 02:58:50 -0700713 if (kGL_GrGLStandard == ctxInfo.standard()) {
714 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
715 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
716 return false;
717 }
718 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700719 if (!hasChromiumPathRendering &&
720 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700721 return false;
722 }
723 }
724 // We only support v1.3+ of GL_NV_path_rendering which allows us to
725 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
726 // additions are detected by checking the existence of the function.
727 // We also use *Then* functions that not all drivers might have. Check
728 // them for consistency.
bsalomon9f2dc272016-02-08 07:22:17 -0800729 if (!gli->fFunctions.fStencilThenCoverFillPath ||
730 !gli->fFunctions.fStencilThenCoverStrokePath ||
731 !gli->fFunctions.fStencilThenCoverFillPathInstanced ||
732 !gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
733 !gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700734 return false;
735 }
736 return true;
737}
bsalomon1aa20292016-01-22 08:16:09 -0800738
739bool GrGLCaps::readPixelsSupported(GrPixelConfig rtConfig,
bsalomon7928ef62016-01-05 10:26:39 -0800740 GrPixelConfig readConfig,
bsalomon1aa20292016-01-22 08:16:09 -0800741 std::function<void (GrGLenum, GrGLint*)> getIntegerv,
742 std::function<bool ()> bindRenderTarget) const {
bsalomone9573312016-01-25 14:33:25 -0800743 // If it's not possible to even have a render target of rtConfig then read pixels is
744 // not supported regardless of readConfig.
745 if (!this->isConfigRenderable(rtConfig, false)) {
746 return false;
747 }
bsalomon7928ef62016-01-05 10:26:39 -0800748
bsalomon76148af2016-01-12 11:13:47 -0800749 GrGLenum readFormat;
750 GrGLenum readType;
bsalomon1aa20292016-01-22 08:16:09 -0800751 if (!this->getReadPixelsFormat(rtConfig, readConfig, &readFormat, &readType)) {
bsalomon76148af2016-01-12 11:13:47 -0800752 return false;
753 }
754
bsalomon1aa20292016-01-22 08:16:09 -0800755 if (kGL_GrGLStandard == fStandard) {
bsalomone9573312016-01-25 14:33:25 -0800756 // Some OpenGL implementations allow GL_ALPHA as a format to glReadPixels. However,
757 // the manual (https://www.opengl.org/sdk/docs/man/) says only these formats are allowed:
758 // GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_RED, GL_GREEN, GL_BLUE,
759 // GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA. We check for the subset that we would use.
760 if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA &&
761 readFormat != GR_GL_BGRA) {
762 return false;
763 }
764 // There is also a set of allowed types, but all the types we use are in the set:
765 // GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT,
766 // GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
767 // GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
768 // GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
769 // GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2,
770 // GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
771 // GL_UNSIGNED_INT_5_9_9_9_REV, or GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
bsalomon7928ef62016-01-05 10:26:39 -0800772 return true;
piotaixre4b23142014-10-02 10:57:53 -0700773 }
bsalomon7928ef62016-01-05 10:26:39 -0800774
bsalomon76148af2016-01-12 11:13:47 -0800775 // See Section 16.1.2 in the ES 3.2 specification.
bsalomon7928ef62016-01-05 10:26:39 -0800776
bsalomon1aa20292016-01-22 08:16:09 -0800777 if (kNormalizedFixedPoint_FormatType == fConfigTable[rtConfig].fFormatType) {
bsalomon7928ef62016-01-05 10:26:39 -0800778 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
779 return true;
780 }
781 } else {
bsalomon1aa20292016-01-22 08:16:09 -0800782 SkASSERT(kFloat_FormatType == fConfigTable[rtConfig].fFormatType);
bsalomon7928ef62016-01-05 10:26:39 -0800783 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
784 return true;
785 }
786 }
787
bsalomon1aa20292016-01-22 08:16:09 -0800788 if (0 == fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat) {
bsalomon7928ef62016-01-05 10:26:39 -0800789 ReadPixelsFormat* rpFormat =
bsalomon1aa20292016-01-22 08:16:09 -0800790 const_cast<ReadPixelsFormat*>(&fConfigTable[rtConfig].fSecondReadPixelsFormat);
bsalomon7928ef62016-01-05 10:26:39 -0800791 GrGLint format = 0, type = 0;
bsalomon1aa20292016-01-22 08:16:09 -0800792 if (!bindRenderTarget()) {
793 return false;
794 }
795 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
796 getIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
bsalomon7928ef62016-01-05 10:26:39 -0800797 rpFormat->fFormat = format;
798 rpFormat->fType = type;
799 }
800
bsalomon1aa20292016-01-22 08:16:09 -0800801 return fConfigTable[rtConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
802 fConfigTable[rtConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700803}
804
robertphillips@google.com6177e692013-02-28 20:16:25 +0000805void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000806
807 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000808 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000809 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
810 // ES3 driver bugs on at least one device with a tiled GPU (N10).
811 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
812 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
813 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
814 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
egdanieleed519e2016-01-15 11:36:18 -0800815 } else if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700816 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000817 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000818 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
819 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
820 // chrome's extension is equivalent to the EXT msaa
821 // and fbo_blit extensions.
822 fMSFBOType = kDesktop_EXT_MSFBOType;
823 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
824 fMSFBOType = kES_Apple_MSFBOType;
825 }
bsalomon083617b2016-02-12 12:10:14 -0800826
827 // Above determined the preferred MSAA approach, now decide whether glBlitFramebuffer
828 // is available.
829 if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
830 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
831 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
832 // The CHROMIUM extension uses the ANGLE version of glBlitFramebuffer and includes its
833 // limitations.
834 fBlitFramebufferSupport = kNoScalingNoMirroring_BlitFramebufferSupport;
835 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000836 } else {
egdanieleed519e2016-01-15 11:36:18 -0800837 if (fUsesMixedSamples) {
vbuzinovdded6962015-06-12 08:59:45 -0700838 fMSFBOType = kMixedSamples_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800839 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
vbuzinovdded6962015-06-12 08:59:45 -0700840 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000841 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000842 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800843 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000844 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
845 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000846 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon083617b2016-02-12 12:10:14 -0800847 fBlitFramebufferSupport = kFull_BlitFramebufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000848 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000849 }
850}
851
cdalton1dd05422015-06-12 09:01:18 -0700852void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
853 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
854
855 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
856 // for now until its own blacklists can be updated.
857 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
858 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700859 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700860 return;
861 }
862
863 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
864 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
865 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
866 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
867 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
868 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
869 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
870 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
871 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
872 return;
873 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
874 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
875 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
876 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
877 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
878 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
879 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
880 // slow on a particular platform.
881 } else {
882 return; // No advanced blend support.
883 }
884
885 SkASSERT(this->advancedBlendEquationSupport());
886
887 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
888 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
889 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
890 (1 << kColorBurn_GrBlendEquation);
891 }
joel.liang9764c402015-07-09 19:46:18 -0700892 if (kARM_GrGLVendor == ctxInfo.vendor()) {
893 // Blacklist color-burn on ARM until the fix is released.
894 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
895 }
cdalton1dd05422015-06-12 09:01:18 -0700896}
897
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000898namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700899const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000900}
901
902void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
903
904 // Build up list of legal stencil formats (though perhaps not supported on
905 // the particular gpu/driver) from most preferred to least.
906
907 // these consts are in order of most preferred to least preferred
908 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
909
910 static const StencilFormat
911 // internal Format stencil bits total bits packed?
912 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
913 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
914 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
915 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000916 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000917 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
918
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000919 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000920 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000921 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000922 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
923 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
924
925 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
926 // require FBO support we can expect these are legal formats and don't
927 // check. These also all support the unsized GL_STENCIL_INDEX.
928 fStencilFormats.push_back() = gS8;
929 fStencilFormats.push_back() = gS16;
930 if (supportsPackedDS) {
931 fStencilFormats.push_back() = gD24S8;
932 }
933 fStencilFormats.push_back() = gS4;
934 if (supportsPackedDS) {
935 fStencilFormats.push_back() = gDS;
936 }
937 } else {
938 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
939 // for other formats.
940 // ES doesn't support using the unsized format.
941
942 fStencilFormats.push_back() = gS8;
943 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000944 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
945 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000946 fStencilFormats.push_back() = gD24S8;
947 }
948 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
949 fStencilFormats.push_back() = gS4;
950 }
951 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000952}
953
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000954SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000955
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000956 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000957
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000958 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000959 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000960 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000961 i,
962 fStencilFormats[i].fStencilBits,
963 fStencilFormats[i].fTotalBits);
964 }
965
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000966 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000967 "None",
968 "ARB",
969 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000970 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000971 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000972 "IMG MS To Texture",
973 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -0700974 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000975 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000976 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
977 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
978 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000979 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
980 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
981 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
982 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -0700983 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000984 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000985
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000986 static const char* kInvalidateFBTypeStr[] = {
987 "None",
988 "Discard",
989 "Invalidate",
990 };
991 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
992 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
993 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
994 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000995
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000996 static const char* kMapBufferTypeStr[] = {
997 "None",
998 "MapBuffer",
999 "MapBufferRange",
1000 "Chromium",
1001 };
1002 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1003 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1004 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1005 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1006 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1007
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001008 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001009 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001010 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001011 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001012 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1013 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001014 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001015 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1016 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1017 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1018 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001019
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001020 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1021 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1022 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1023 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001024 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001025 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1026 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001027 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
cdalton06604b92016-02-05 10:09:51 -08001028 r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
1029 r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
1030 r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001031 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001032 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001033 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001034 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1035 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001036 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001037 r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO"));
bsalomone5286e02016-01-14 09:24:09 -08001038 r.appendf("Rectangle texture support: %s\n", (fRectangleTextureSupport? "YES" : "NO"));
bsalomoncdee0092016-01-08 13:20:12 -08001039 r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO"));
bsalomon41e4384e2016-01-08 09:12:44 -08001040
1041 r.append("Configs\n-------\n");
1042 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1043 r.appendf(" cfg: %d flags: 0x%04x, b_internal: 0x%08x s_internal: 0x%08x, e_format: "
bsalomon76148af2016-01-12 11:13:47 -08001044 "0x%08x, e_format_teximage: 0x%08x, e_type: 0x%08x, i_for_teximage: 0x%08x, "
1045 "i_for_renderbuffer: 0x%08x\n",
bsalomon41e4384e2016-01-08 09:12:44 -08001046 i,
1047 fConfigTable[i].fFlags,
1048 fConfigTable[i].fFormats.fBaseInternalFormat,
1049 fConfigTable[i].fFormats.fSizedInternalFormat,
bsalomon76148af2016-01-12 11:13:47 -08001050 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage],
1051 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage],
bsalomon41e4384e2016-01-08 09:12:44 -08001052 fConfigTable[i].fFormats.fExternalType,
1053 fConfigTable[i].fFormats.fInternalFormatTexImage,
bsalomon76148af2016-01-12 11:13:47 -08001054 fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
bsalomon41e4384e2016-01-08 09:12:44 -08001055 }
1056
jvanverthe9c0fc62015-04-29 11:18:05 -07001057 return r;
1058}
1059
jvanverthe9c0fc62015-04-29 11:18:05 -07001060static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1061 switch (p) {
1062 case kLow_GrSLPrecision:
1063 return GR_GL_LOW_FLOAT;
1064 case kMedium_GrSLPrecision:
1065 return GR_GL_MEDIUM_FLOAT;
1066 case kHigh_GrSLPrecision:
1067 return GR_GL_HIGH_FLOAT;
1068 }
1069 SkFAIL("Unknown precision.");
1070 return -1;
1071}
1072
1073static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1074 switch (type) {
1075 case kVertex_GrShaderType:
1076 return GR_GL_VERTEX_SHADER;
1077 case kGeometry_GrShaderType:
1078 return GR_GL_GEOMETRY_SHADER;
1079 case kFragment_GrShaderType:
1080 return GR_GL_FRAGMENT_SHADER;
1081 }
1082 SkFAIL("Unknown shader type.");
1083 return -1;
1084}
1085
jvanverthcba99b82015-06-24 06:59:57 -07001086void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1087 const GrGLInterface* intf,
1088 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001089 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1090 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1091 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1092 if (kGeometry_GrShaderType != s) {
1093 GrShaderType shaderType = static_cast<GrShaderType>(s);
1094 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001095 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001096 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001097 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1098 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1099 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1100 GrGLint range[2];
1101 GrGLint bits;
1102 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1103 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001104 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1105 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1106 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001107 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001108 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001109 }
jvanverthcba99b82015-06-24 06:59:57 -07001110 else if (!glslCaps->fShaderPrecisionVaries) {
1111 glslCaps->fShaderPrecisionVaries =
1112 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001113 }
1114 }
1115 }
1116 }
1117 }
1118 }
1119 else {
1120 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001121 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001122 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1123 if (kGeometry_GrShaderType != s) {
1124 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001125 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1126 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1127 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001128 }
1129 }
1130 }
1131 }
1132 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1133 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1134 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1135 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001136 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001137 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001138 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1139 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001140 }
1141 }
1142}
1143
bsalomon41e4384e2016-01-08 09:12:44 -08001144bool GrGLCaps::bgraIsInternalFormat() const {
1145 return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
1146}
1147
bsalomon76148af2016-01-12 11:13:47 -08001148bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1149 GrGLenum* internalFormat, GrGLenum* externalFormat,
1150 GrGLenum* externalType) const {
1151 if (!this->getExternalFormat(surfaceConfig, externalConfig, kTexImage_ExternalFormatUsage,
1152 externalFormat, externalType)) {
1153 return false;
1154 }
1155 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1156 return true;
1157}
1158
1159bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
1160 GrGLenum* internalFormat) const {
1161 if (!GrPixelConfigIsCompressed(surfaceConfig)) {
1162 return false;
1163 }
1164 *internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
1165 return true;
1166}
1167
1168bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
1169 GrGLenum* externalFormat, GrGLenum* externalType) const {
1170 if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage,
1171 externalFormat, externalType)) {
1172 return false;
1173 }
1174 return true;
1175}
1176
1177bool GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
1178 if (GrPixelConfigIsCompressed(config)) {
1179 return false;
1180 }
1181 *internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
1182 return true;
1183}
1184
1185bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
1186 ExternalFormatUsage usage, GrGLenum* externalFormat,
1187 GrGLenum* externalType) const {
1188 SkASSERT(externalFormat && externalType);
1189 if (GrPixelConfigIsCompressed(memoryConfig) || GrPixelConfigIsCompressed(memoryConfig)) {
1190 return false;
1191 }
1192
1193 bool surfaceIsAlphaOnly = GrPixelConfigIsAlphaOnly(surfaceConfig);
1194 bool memoryIsAlphaOnly = GrPixelConfigIsAlphaOnly(memoryConfig);
1195
1196 // We don't currently support moving RGBA data into and out of ALPHA surfaces. It could be
1197 // made to work in many cases using glPixelStore and what not but is not needed currently.
1198 if (surfaceIsAlphaOnly && !memoryIsAlphaOnly) {
1199 return false;
1200 }
1201
1202 *externalFormat = fConfigTable[memoryConfig].fFormats.fExternalFormat[usage];
1203 *externalType = fConfigTable[memoryConfig].fFormats.fExternalType;
1204
bsalomone9573312016-01-25 14:33:25 -08001205 // When GL_RED is supported as a texture format, our alpha-only textures are stored using
1206 // GL_RED and we swizzle in order to map all components to 'r'. However, in this case the
1207 // surface is not alpha-only and we want alpha to really mean the alpha component of the
1208 // texture, not the red component.
1209 if (memoryIsAlphaOnly && !surfaceIsAlphaOnly) {
1210 if (this->textureRedSupport()) {
1211 SkASSERT(GR_GL_RED == *externalFormat);
1212 *externalFormat = GR_GL_ALPHA;
1213 }
1214 }
1215
bsalomon76148af2016-01-12 11:13:47 -08001216 return true;
1217}
1218
bsalomoncdee0092016-01-08 13:20:12 -08001219void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
1220 GrGLSLCaps* glslCaps) {
bsalomon41e4384e2016-01-08 09:12:44 -08001221 /*
1222 Comments on renderability of configs on various GL versions.
1223 OpenGL < 3.0:
1224 no built in support for render targets.
1225 GL_EXT_framebuffer_object adds possible support for any sized format with base internal
1226 format RGB, RGBA and NV float formats we don't use.
1227 This is the following:
1228 R3_G3_B2, RGB4, RGB5, RGB8, RGB10, RGB12, RGB16, RGBA2, RGBA4, RGB5_A1, RGBA8
1229 RGB10_A2, RGBA12,RGBA16
1230 Though, it is hard to believe the more obscure formats such as RGBA12 would work
1231 since they aren't required by later standards and the driver can simply return
1232 FRAMEBUFFER_UNSUPPORTED for anything it doesn't allow.
1233 GL_ARB_framebuffer_object adds everything added by the EXT extension and additionally
1234 any sized internal format with a base internal format of ALPHA, LUMINANCE,
1235 LUMINANCE_ALPHA, INTENSITY, RED, and RG.
1236 This adds a lot of additional renderable sized formats, including ALPHA8.
1237 The GL_ARB_texture_rg brings in the RED and RG formats (8, 8I, 8UI, 16, 16I, 16UI,
1238 16F, 32I, 32UI, and 32F variants).
1239 Again, the driver has an escape hatch via FRAMEBUFFER_UNSUPPORTED.
1240
1241 For both the above extensions we limit ourselves to those that are also required by
1242 OpenGL 3.0.
1243
1244 OpenGL 3.0:
1245 Any format with base internal format ALPHA, RED, RG, RGB or RGBA is "color-renderable"
1246 but are not required to be supported as renderable textures/renderbuffer.
1247 Required renderable color formats:
1248 - RGBA32F, RGBA32I, RGBA32UI, RGBA16, RGBA16F, RGBA16I,
1249 RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, and
1250 RGB10_A2.
1251 - R11F_G11F_B10F.
1252 - RG32F, RG32I, RG32UI, RG16, RG16F, RG16I, RG16UI, RG8, RG8I,
1253 and RG8UI.
1254 - R32F, R32I, R32UI, R16F, R16I, R16UI, R16, R8, R8I, and R8UI.
1255 - ALPHA8
1256
1257 OpenGL 3.1, 3.2, 3.3
1258 Same as 3.0 except ALPHA8 requires GL_ARB_compatibility/compatibility profile.
1259 OpengGL 3.3, 4.0, 4.1
1260 Adds RGB10_A2UI.
1261 OpengGL 4.2
1262 Adds
1263 - RGB5_A1, RGBA4
1264 - RGB565
1265 OpenGL 4.4
1266 Does away with the separate list and adds a column to the sized internal color format
1267 table. However, no new formats become required color renderable.
1268
1269 ES 2.0
1270 color renderable: RGBA4, RGB5_A1, RGB565
1271 GL_EXT_texture_rg adds support for R8, RG5 as a color render target
1272 GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8
1273 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8)
1274 GL_EXT_texture_format_BGRA8888 does not add renderbuffer support
1275 GL_CHROMIUM_renderbuffer_format_BGRA8888 adds BGRA8 as color-renderable
1276 GL_APPLE_texture_format_BGRA8888 does not add renderbuffer support
1277
1278 ES 3.0
1279 - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I,
1280 RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and
1281 RGB5_A1.
1282 - RGB8 and RGB565.
1283 - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI.
1284 - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI
1285 ES 3.1
1286 Adds RGB10_A2, RGB10_A2UI,
1287 ES 3.2
1288 Adds R16F, RG16F, RGBA16F, R32F, RG32F, RGBA32F, R11F_G11F_B10F.
1289 */
1290 uint32_t allRenderFlags = ConfigInfo::kRenderable_Flag;
1291 if (kNone_MSFBOType != fMSFBOType) {
1292 allRenderFlags |= ConfigInfo::kRenderableWithMSAA_Flag;
1293 }
1294
1295 GrGLStandard standard = ctxInfo.standard();
1296 GrGLVersion version = ctxInfo.version();
1297
bsalomon30447372015-12-21 09:03:05 -08001298 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1299 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
bsalomon76148af2016-01-12 11:13:47 -08001300 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001301 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001302 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001303 fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001304
1305 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1306 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001307 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1308 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001309 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001310 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001311 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1312 if (kGL_GrGLStandard == standard) {
1313 // We require some form of FBO support and all GLs with FBO support can render to RGBA8
1314 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
egdaniel4999df82016-01-07 17:06:04 -08001315 } else {
bsalomon41e4384e2016-01-08 09:12:44 -08001316 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
1317 ctxInfo.hasExtension("GL_ARM_rgba8")) {
1318 fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
1319 }
egdaniel4999df82016-01-07 17:06:04 -08001320 }
bsalomoncdee0092016-01-08 13:20:12 -08001321 fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001322
bsalomon76148af2016-01-12 11:13:47 -08001323 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1324 GR_GL_BGRA;
bsalomon30447372015-12-21 09:03:05 -08001325 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001326 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001327 if (kGL_GrGLStandard == standard) {
1328 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1329 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1330 if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
1331 // Since the internal format is RGBA8, it is also renderable.
1332 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1333 allRenderFlags;
1334 }
1335 } else {
1336 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1337 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1338 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
1339 // The APPLE extension doesn't make this renderable.
1340 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1341 if (version < GR_GL_VER(3,0) && !ctxInfo.hasExtension("GL_EXT_texture_storage")) {
1342 // On ES2 the internal format of a BGRA texture is RGBA with the APPLE extension.
1343 // Though, that seems to not be the case if the texture storage extension is
1344 // present. The specs don't exactly make that clear.
1345 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1346 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1347 }
1348 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
1349 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1350 ConfigInfo::kRenderable_Flag;
1351 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888") &&
kkinnunen9f63b442016-01-25 00:31:49 -08001352 (this->usesMSAARenderBuffers() || this->fMSFBOType == kMixedSamples_MSFBOType)) {
bsalomon41e4384e2016-01-08 09:12:44 -08001353 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1354 ConfigInfo::kRenderableWithMSAA_Flag;
1355 }
1356 }
1357 }
bsalomoncdee0092016-01-08 13:20:12 -08001358 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001359
bsalomon41e4384e2016-01-08 09:12:44 -08001360 // We only enable srgb support if both textures and FBOs support srgb.
1361 bool srgbSupport = false;
1362 if (kGL_GrGLStandard == standard) {
1363 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1364 srgbSupport = true;
1365 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1366 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1367 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1368 srgbSupport = true;
1369 }
1370 }
1371 // All the above srgb extensions support toggling srgb writes
1372 fSRGBWriteControl = srgbSupport;
1373 } else {
1374 // See https://bug.skia.org/4148 for PowerVR issue.
1375 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1376 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
1377 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1378 // sRGB writing for destinations.
1379 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1380 }
bsalomon30447372015-12-21 09:03:05 -08001381 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1382 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1383 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1384 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
bsalomon76148af2016-01-12 11:13:47 -08001385 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1386 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001387 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001388 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001389 if (srgbSupport) {
1390 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
1391 allRenderFlags;
1392 }
bsalomoncdee0092016-01-08 13:20:12 -08001393 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001394
1395 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1396 if (this->ES2CompatibilitySupport()) {
1397 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1398 } else {
1399 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1400 }
bsalomon76148af2016-01-12 11:13:47 -08001401 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1402 GR_GL_RGB;
bsalomon30447372015-12-21 09:03:05 -08001403 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001404 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001405 fConfigTable[kRGB_565_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1406 if (kGL_GrGLStandard == standard) {
1407 if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ES2_compatibility")) {
1408 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1409 }
1410 } else {
1411 fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
1412 }
bsalomoncdee0092016-01-08 13:20:12 -08001413 fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001414
1415 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1416 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
bsalomon76148af2016-01-12 11:13:47 -08001417 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1418 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001419 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001420 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001421 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1422 if (kGL_GrGLStandard == standard) {
1423 if (version >= GR_GL_VER(4, 2)) {
1424 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1425 }
1426 } else {
1427 fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
1428 }
bsalomoncdee0092016-01-08 13:20:12 -08001429 fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001430
1431 if (this->textureRedSupport()) {
1432 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1433 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
bsalomon76148af2016-01-12 11:13:47 -08001434 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1435 GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001436 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001437 } else {
1438 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1439 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
bsalomon76148af2016-01-12 11:13:47 -08001440 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1441 GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001442 fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001443 }
1444 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001445 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001446 fConfigTable[kAlpha_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1447 if (this->textureRedSupport() || kDesktop_ARB_MSFBOType == this->msFBOType()) {
1448 // desktop ARB extension/3.0+ supports ALPHA8 as renderable.
1449 // Core profile removes ALPHA8 support, but we should have chosen R8 in that case.
1450 fConfigTable[kAlpha_8_GrPixelConfig].fFlags |= allRenderFlags;
1451 }
1452
1453 // Check for [half] floating point texture support
1454 // NOTE: We disallow floating point textures on ES devices if linear filtering modes are not
1455 // supported. This is for simplicity, but a more granular approach is possible. Coincidentally,
1456 // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0.
1457 bool hasFPTextures = false;
1458 bool hasHalfFPTextures = false;
1459 // for now we don't support floating point MSAA on ES
1460 uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ?
1461 allRenderFlags : (uint32_t)ConfigInfo::kRenderable_Flag;
1462
1463 if (kGL_GrGLStandard == standard) {
1464 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) {
1465 hasFPTextures = true;
1466 hasHalfFPTextures = true;
1467 }
1468 } else {
1469 if (version >= GR_GL_VER(3, 1)) {
1470 hasFPTextures = true;
1471 hasHalfFPTextures = true;
1472 } else {
1473 if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
1474 ctxInfo.hasExtension("GL_OES_texture_float")) {
1475 hasFPTextures = true;
1476 }
1477 if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
1478 ctxInfo.hasExtension("GL_OES_texture_half_float")) {
1479 hasHalfFPTextures = true;
1480 }
1481 }
1482 }
bsalomon30447372015-12-21 09:03:05 -08001483
1484 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1485 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
bsalomon76148af2016-01-12 11:13:47 -08001486 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1487 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001488 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001489 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001490 if (hasFPTextures) {
1491 fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1492 // For now we only enable rendering to float on desktop, because on ES we'd have to solve
1493 // many precision issues and no clients actually want this yet.
1494 if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) ||
1495 ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) {
1496 fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags;
1497 }
1498 }
bsalomoncdee0092016-01-08 13:20:12 -08001499 fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001500
1501 if (this->textureRedSupport()) {
1502 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1503 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
bsalomon76148af2016-01-12 11:13:47 -08001504 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1505 = GR_GL_RED;
bsalomoncdee0092016-01-08 13:20:12 -08001506 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001507 } else {
1508 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1509 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
bsalomon76148af2016-01-12 11:13:47 -08001510 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage]
1511 = GR_GL_ALPHA;
bsalomoncdee0092016-01-08 13:20:12 -08001512 fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA();
bsalomon30447372015-12-21 09:03:05 -08001513 }
1514 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1515 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1516 } else {
1517 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1518 }
bsalomon7928ef62016-01-05 10:26:39 -08001519 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001520 if (hasHalfFPTextures) {
1521 fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1522 // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for
1523 // GL_RED internal format.
1524 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1525 (this->textureRedSupport() &&
1526 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) {
1527 fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags;
1528 }
1529 }
bsalomon30447372015-12-21 09:03:05 -08001530
1531 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1532 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
bsalomon76148af2016-01-12 11:13:47 -08001533 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1534 GR_GL_RGBA;
bsalomon30447372015-12-21 09:03:05 -08001535 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1536 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1537 } else {
1538 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1539 }
bsalomon7928ef62016-01-05 10:26:39 -08001540 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001541 if (hasHalfFPTextures) {
1542 fConfigTable[kRGBA_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1543 // ES requires 3.2 or EXT_color_buffer_half_float.
1544 if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3,2) ||
1545 ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
1546 fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags;
1547 }
1548 }
bsalomoncdee0092016-01-08 13:20:12 -08001549 fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon41e4384e2016-01-08 09:12:44 -08001550
1551 // Compressed texture support
1552
1553 // glCompressedTexImage2D is available on all OpenGL ES devices. It is available on standard
1554 // OpenGL after version 1.3. We'll assume at least that level of OpenGL support.
1555
1556 // TODO: Fix command buffer bindings and remove this.
1557 fCompressedTexSubImageSupport = SkToBool(gli->fFunctions.fCompressedTexSubImage2D);
bsalomon30447372015-12-21 09:03:05 -08001558
1559 // No sized/unsized internal format distinction for compressed formats, no external format.
bsalomon41e4384e2016-01-08 09:12:44 -08001560 // Below we set the external formats and types to 0.
bsalomon30447372015-12-21 09:03:05 -08001561
1562 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1563 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
bsalomon76148af2016-01-12 11:13:47 -08001564 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001565 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001566 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001567 // Disable this for now, while we investigate https://bug.skia.org/4333
1568 if (false) {
1569 // Check for 8-bit palette..
1570 GrGLint numFormats;
1571 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
1572 if (numFormats) {
1573 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
1574 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
1575 for (int i = 0; i < numFormats; ++i) {
1576 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
1577 fConfigTable[kIndex_8_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1578 break;
1579 }
1580 }
1581 }
1582 }
bsalomoncdee0092016-01-08 13:20:12 -08001583 fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001584
bsalomon41e4384e2016-01-08 09:12:44 -08001585 // May change the internal format based on extensions.
1586 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1587 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1588 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1589 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1590 if (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
1591 ctxInfo.hasExtension("GL_NV_texture_compression_latc")) {
1592 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1593 } else if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) ||
1594 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
1595 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc")) {
1596 // RGTC is identical and available on OpenGL 3.0+ as well as with extensions
1597 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1598 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1599 GR_GL_COMPRESSED_RED_RGTC1;
1600 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1601 GR_GL_COMPRESSED_RED_RGTC1;
1602 } else if (ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture")) {
1603 fConfigTable[kLATC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1604 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1605 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1606 GR_GL_COMPRESSED_3DC_X;
1607
bsalomon30447372015-12-21 09:03:05 -08001608 }
bsalomon76148af2016-01-12 11:13:47 -08001609 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001610 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001611 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomoncdee0092016-01-08 13:20:12 -08001612 fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001613
1614 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1615 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
bsalomon76148af2016-01-12 11:13:47 -08001616 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001617 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001618 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001619 if (kGL_GrGLStandard == standard) {
1620 if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
1621 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1622 }
1623 } else {
1624 if (version >= GR_GL_VER(3, 0) ||
1625 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
1626 // ETC2 is a superset of ETC1, so we can just check for that, too.
1627 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
1628 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture"))) {
1629 fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1630 }
1631 }
bsalomoncdee0092016-01-08 13:20:12 -08001632 fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001633
1634 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1635 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
bsalomon76148af2016-01-12 11:13:47 -08001636 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0;
bsalomon30447372015-12-21 09:03:05 -08001637 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001638 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001639 // Check for R11_EAC. We don't support R11_EAC on desktop, as most cards default to
1640 // decompressing the textures in the driver, and is generally slower.
1641 if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) {
1642 fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1643 }
bsalomoncdee0092016-01-08 13:20:12 -08001644 fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR();
bsalomon30447372015-12-21 09:03:05 -08001645
1646 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1647 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1648 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1649 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
bsalomon76148af2016-01-12 11:13:47 -08001650 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] =
1651 0;
bsalomon30447372015-12-21 09:03:05 -08001652 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001653 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon41e4384e2016-01-08 09:12:44 -08001654 if (ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
1655 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
1656 ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
1657 fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag;
1658 }
bsalomoncdee0092016-01-08 13:20:12 -08001659 fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
bsalomon30447372015-12-21 09:03:05 -08001660
1661 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1662
1663 // ES 2.0 requires that the internal/external formats match.
bsalomon76148af2016-01-12 11:13:47 -08001664 bool useSizedTexFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1665 ctxInfo.version() >= GR_GL_VER(3,0));
1666 // All ES versions (thus far) require sized internal formats for render buffers.
1667 // TODO: Always use sized internal format?
1668 bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard();
1669
bsalomon30447372015-12-21 09:03:05 -08001670 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001671 // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format>
1672 // param to glTex[Sub]Image.
1673 fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
1674 fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage];
1675 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
1676 fConfigTable[i].fFormats.fSizedInternalFormat :
1677 fConfigTable[i].fFormats.fBaseInternalFormat;
1678 fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
bsalomon30447372015-12-21 09:03:05 -08001679 fConfigTable[i].fFormats.fSizedInternalFormat :
1680 fConfigTable[i].fFormats.fBaseInternalFormat;
1681 }
1682 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1683 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1684 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1685 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1686 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
bsalomon76148af2016-01-12 11:13:47 -08001687 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
bsalomon30447372015-12-21 09:03:05 -08001688 GR_GL_SRGB_ALPHA;
1689 }
1690
1691 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1692 // as a base format.
1693 // GL_EXT_texture_format_BGRA8888:
1694 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1695 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1696 // formats.
1697 // GL_APPLE_texture_format_BGRA8888:
1698 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1699 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1700 // glTexImage (just for glTexStorage).
bsalomon76148af2016-01-12 11:13:47 -08001701 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
bsalomon30447372015-12-21 09:03:05 -08001702 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1703 }
1704
bsalomoncdee0092016-01-08 13:20:12 -08001705 // If we don't have texture swizzle support then the shader generator must insert the
1706 // swizzle into shader code.
1707 if (!this->textureSwizzleSupport()) {
1708 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1709 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1710 }
1711 }
1712
bsalomon7f9b2e42016-01-12 13:29:26 -08001713 // Shader output swizzles will default to RGBA. When we've use GL_RED instead of GL_ALPHA to
1714 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
1715 // gets written to the single component.
1716 if (this->textureRedSupport()) {
1717 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1718 GrPixelConfig config = static_cast<GrPixelConfig>(i);
1719 if (GrPixelConfigIsAlphaOnly(config) &&
1720 fConfigTable[i].fFormats.fBaseInternalFormat == GR_GL_RED) {
1721 glslCaps->fConfigOutputSwizzle[i] = GrSwizzle::AAAA();
1722 }
1723 }
1724 }
1725
bsalomon30447372015-12-21 09:03:05 -08001726#ifdef SK_DEBUG
1727 // Make sure we initialized everything.
bsalomon76148af2016-01-12 11:13:47 -08001728 ConfigInfo defaultEntry;
bsalomon30447372015-12-21 09:03:05 -08001729 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
bsalomon76148af2016-01-12 11:13:47 -08001730 SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
1731 fConfigTable[i].fFormats.fBaseInternalFormat);
1732 SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
bsalomon30447372015-12-21 09:03:05 -08001733 fConfigTable[i].fFormats.fSizedInternalFormat);
bsalomon76148af2016-01-12 11:13:47 -08001734 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1735 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1736 fConfigTable[i].fFormats.fExternalFormat[j]);
1737 }
1738 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats.fExternalType);
bsalomon30447372015-12-21 09:03:05 -08001739 }
1740#endif
1741}
1742
egdanielb7e7d572015-11-04 04:23:53 -08001743void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}