blob: 6c0ee19584c22775817176b4eb871261c7f62ec7 [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"
jvanverthcba99b82015-06-24 06:59:57 -070013#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000014#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000015#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000016
bsalomon682c2692015-05-22 14:01:46 -070017GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
18 const GrGLContextInfo& ctxInfo,
19 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000020 fVerifiedColorConfigs.reset();
21 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000022 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000023 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070024 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000025 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080026 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000027 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000028 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000029 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fBGRAIsInternalFormat = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032 fUnpackRowLengthSupport = false;
33 fUnpackFlipYSupport = false;
34 fPackRowLengthSupport = false;
35 fPackFlipYSupport = false;
36 fTextureUsageSupport = false;
37 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000038 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000039 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000040 fTwoFormatLimit = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000041 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070042 fInstancedDrawingSupport = false;
43 fDirectStateAccessSupport = false;
44 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080045 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080046 fMultisampleDisableSupport = 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;
bsalomon16921ec2015-07-30 15:34:56 -070051 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070052 fRGBA8888PixelsOpsAreSlow = false;
53 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070054
55 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070056
halcanary385fe4d2015-08-26 13:07:48 -070057 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070058
cdalton4cd67132015-06-10 19:23:46 -070059 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060}
61
cdalton4cd67132015-06-10 19:23:46 -070062void GrGLCaps::init(const GrContextOptions& contextOptions,
63 const GrGLContextInfo& ctxInfo,
64 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000065 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000066 GrGLVersion version = ctxInfo.version();
67
bsalomon@google.combcce8922013-03-25 15:38:39 +000068 /**************************************************************************
69 * Caps specific to GrGLCaps
70 **************************************************************************/
71
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000072 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000073 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
74 &fMaxFragmentUniformVectors);
75 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000076 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000077 GrGLint max;
78 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
79 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000080 if (version >= GR_GL_VER(3, 2)) {
81 GrGLint profileMask;
82 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
83 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
84 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000085 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000086 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000087 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000089 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090 fRGBA8RenderbufferSupport = true;
91 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +000092 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
93 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094 ctxInfo.hasExtension("GL_ARM_rgba8");
95 }
96
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000097 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000098 fUnpackRowLengthSupport = true;
99 fUnpackFlipYSupport = false;
100 fPackRowLengthSupport = true;
101 fPackFlipYSupport = false;
102 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000103 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
104 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000105 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000106 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
107 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 fPackFlipYSupport =
109 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
110 }
111
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000112 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000113 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
114
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000115 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000116 // The EXT version can apply to either GL or GLES.
117 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
118 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
119 ctxInfo.hasExtension("GL_EXT_texture_storage");
120 } else {
121 // Qualcomm Adreno drivers appear to have issues with texture storage.
122 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
123 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
124 ctxInfo.hasExtension("GL_EXT_texture_storage");
125 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000126
cdaltonfd4167d2015-04-21 11:45:56 -0700127 if (kGL_GrGLStandard == standard) {
128 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
129 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
130 ctxInfo.hasExtension("GL_NV_texture_barrier");
131 } else {
132 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
133 }
134
hendrikwa0d5ad72014-12-02 07:30:30 -0800135 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
136 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700137 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800138 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000139 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
140 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800141 } else {
142 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
143 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000144 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000145 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000146 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000147 ctxInfo.hasExtension("GL_ARB_imaging");
148
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000149 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
150 // ReadPixels. The other format has to checked at run-time since it
151 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000152 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000153
bsalomon16921ec2015-07-30 15:34:56 -0700154 // We only enable srgb support if both textures and FBOs support srgb.
155 bool srgbSupport = false;
156 if (kGL_GrGLStandard == standard) {
157 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
158 srgbSupport = true;
159 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
160 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
161 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
162 srgbSupport = true;
163 }
164 }
165 // All the above srgb extensions support toggling srgb writes
166 fSRGBWriteControl = srgbSupport;
167 } else {
halcanary6950de62015-11-07 05:29:00 -0800168 // See https://bug.skia.org/4148 for PowerVR issue.
bsalomon58b43952015-07-30 16:27:50 -0700169 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
170 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
bsalomon16921ec2015-07-30 15:34:56 -0700171 // ES through 3.1 requires EXT_srgb_write_control to support toggling
172 // sRGB writing for destinations.
173 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
174 }
175
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000176 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
177 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
178 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
179 // limit this decision to specific GPU families rather than basing it on the vendor alone.
180 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700181 (kARM_GrGLVendor == ctxInfo.vendor() ||
182 kImagination_GrGLVendor == ctxInfo.vendor() ||
183 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000184 fUseNonVBOVertexAndIndexDynamicData = true;
185 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000186
egdaniel9250d242015-05-18 13:04:26 -0700187 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
188 // Thus we are blacklisting this extension for now on Adreno4xx devices.
189 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
190 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
191 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
192 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000193 fDiscardRenderTargetSupport = true;
194 fInvalidateFBType = kInvalidate_InvalidateFBType;
195 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
196 fDiscardRenderTargetSupport = true;
197 fInvalidateFBType = kDiscard_InvalidateFBType;
198 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000199
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000200 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
201 fFullClearIsFree = true;
202 }
203
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000204 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000205 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800206 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
207 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000208 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000209 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
210 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000211 }
212
cdalton626e1ff2015-06-12 13:56:46 -0700213 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
214 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
215 fInstancedDrawingSupport = true;
216 } else {
217 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
218 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
219 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
220 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
221 }
222
223 if (kGL_GrGLStandard == standard) {
224 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
225 } else {
226 fDirectStateAccessSupport = false;
227 }
228
229 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
230 fDebugSupport = true;
231 } else {
232 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
233 }
234
jvanverth3f801cb2014-12-16 09:49:38 -0800235 if (kGL_GrGLStandard == standard) {
236 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
237 }
238 else {
239 fES2CompatibilitySupport = true;
240 }
241
cdalton0edea2c2015-05-21 08:27:44 -0700242 if (kGL_GrGLStandard == standard) {
243 fMultisampleDisableSupport = true;
244 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700245 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700246 }
247
kkinnunend94708e2015-07-30 22:47:04 -0700248 if (kGL_GrGLStandard == standard) {
249 if (version >= GR_GL_VER(3, 0)) {
250 fBindFragDataLocationSupport = true;
251 }
252 } else {
253 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
254 fBindFragDataLocationSupport = true;
255 }
joshualittc1f56b52015-06-22 12:31:31 -0700256 }
257
halcanary6950de62015-11-07 05:29:00 -0800258#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700259 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
kkinnunen177519e2015-10-28 06:18:35 -0700260#else
261 fBindUniformLocationSupport = false;
262#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700263
bsalomon7ea33f52015-11-22 14:51:00 -0800264 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
265 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
266 fExternalTextureSupport = true;
267 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
268 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
269 // At least one driver has been found that has this extension without the "GL_" prefix.
270 fExternalTextureSupport = true;
271 }
272 }
273
bsalomon88c7b982015-07-31 11:20:16 -0700274#ifdef SK_BUILD_FOR_WIN
275 // We're assuming that on Windows Chromium we're using ANGLE.
276 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
277 kChromium_GrGLDriver == ctxInfo.driver();
278 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
279 fRGBA8888PixelsOpsAreSlow = isANGLE;
280 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
281 // check DX11 ANGLE.
282 fPartialFBOReadIsSlow = isANGLE;
283#endif
284
cdalton4cd67132015-06-10 19:23:46 -0700285 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700286 * GrShaderCaps fields
287 **************************************************************************/
288
egdaniel0a482332015-10-26 08:59:10 -0700289 // This must be called after fCoreProfile is set on the GrGLCaps
290 this->initGLSL(ctxInfo);
291 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
292
egdaniel05ded892015-10-26 07:38:05 -0700293 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
294
295 // For now these two are equivalent but we could have dst read in shader via some other method.
296 // Before setting this, initGLSL() must have been called.
297 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
298
299 // Enable supported shader-related caps
300 if (kGL_GrGLStandard == standard) {
301 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
302 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
303 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
304 glslCaps->fShaderDerivativeSupport = true;
305 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
306 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
307 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
308 }
309 else {
310 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
311
312 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
313 ctxInfo.hasExtension("GL_OES_standard_derivatives");
314 }
315
egdaniel05ded892015-10-26 07:38:05 -0700316 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700317 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000318 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700319
cdalton63f6c1f2015-11-06 07:09:43 -0800320 // We need dual source blending and the ability to disable multisample in order to support mixed
321 // samples in every corner case.
322 if (fMultisampleDisableSupport && glslCaps->dualSourceBlendingSupport()) {
323 fMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples");
324 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
325 if (fMixedSamplesSupport && kNVIDIA_GrGLDriver == ctxInfo.driver()) {
326 fDiscardRenderTargetSupport = false;
327 fInvalidateFBType = kNone_InvalidateFBType;
328 }
329 }
330
331 // fPathRenderingSupport and fMixedSamplesSupport must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700332 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700333 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700334 this->initStencilFormats(ctxInfo);
335
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000336 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000337 // we could also look for GL_ATI_separate_stencil extension or
338 // GL_EXT_stencil_two_side but they use different function signatures
339 // than GL2.0+ (and than each other).
340 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
341 // supported on GL 1.4 and higher or by extension
342 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
343 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
344 } else {
345 // ES 2 has two sided stencil and stencil wrap
346 fTwoSidedStencilSupport = true;
347 fStencilWrapOpsSupport = true;
348 }
349
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000350 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000351 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
352 // extension includes glMapBuffer.
353 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
354 fMapBufferFlags |= kSubset_MapFlag;
355 fMapBufferType = kMapBufferRange_MapBufferType;
356 } else {
357 fMapBufferType = kMapBuffer_MapBufferType;
358 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000359 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000360 // Unextended GLES2 doesn't have any buffer mapping.
361 fMapBufferFlags = kNone_MapBufferType;
362 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
363 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
364 fMapBufferType = kChromium_MapBufferType;
365 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
366 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
367 fMapBufferType = kMapBufferRange_MapBufferType;
368 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
369 fMapBufferFlags = kCanMap_MapFlag;
370 fMapBufferType = kMapBuffer_MapBufferType;
371 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000372 }
373
jvanverthd7a2c1f2015-12-07 07:36:44 -0800374 if (kGL_GrGLStandard == standard) {
375 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
376 fTransferBufferType = kPBO_TransferBufferType;
377 }
378 } else {
379 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
380 fTransferBufferType = kPBO_TransferBufferType;
381 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
382 fTransferBufferType = kChromium_TransferBufferType;
383 }
384 }
385
joshualitte5b74c62015-06-01 14:17:47 -0700386 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
387 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
388 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700389 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
390 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
391 // a small subset.
392#if 0
cdalton1acea862015-06-02 13:05:52 -0700393 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700394#else
395 fGeometryBufferMapThreshold = SK_MaxS32;
396#endif
joshualitte5b74c62015-06-01 14:17:47 -0700397 }
398
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000399 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000400 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
401 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
402 fNPOTTextureTileSupport = true;
403 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000404 } else {
405 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000406 // ES3 has no limitations.
407 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
408 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000409 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
410 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
411 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
412 // to alllow arbitrary wrap modes, however.
413 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000414 }
415
bsalomone72bd022015-10-26 07:33:03 -0700416 // Using MIPs on this GPU seems to be a source of trouble.
417 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
418 fMipMapSupport = false;
419 }
420
bsalomon@google.combcce8922013-03-25 15:38:39 +0000421 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
422 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
423 // Our render targets are always created with textures as the color
424 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000425 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000426
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000427 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
428
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000429 // Disable scratch texture reuse on Mali and Adreno devices
430 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
431 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000432
robertphillips1b8e1b52015-06-24 06:54:10 -0700433#if 0
434 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
435 kQualcomm_GrGLVendor != ctxInfo.vendor();
436#endif
437
egdaniel05ded892015-10-26 07:38:05 -0700438 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000439 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000440 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
441 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
442 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
443 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000444
bsalomon63b21962014-11-05 07:05:34 -0800445 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800446 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800447 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800448 fUseDrawInsteadOfClear = true;
449 }
450
joshualitt83bc2292015-06-18 14:18:02 -0700451 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
452 fUseDrawInsteadOfPartialRenderTargetWrite = true;
453 }
454
robertphillips63926682015-08-20 09:39:02 -0700455#ifdef SK_BUILD_FOR_WIN
456 // On ANGLE deferring flushes can lead to GPU starvation
457 fPreferVRAMUseOverFlushes = !isANGLE;
458#endif
459
bsalomon7dea7b72015-08-19 08:26:51 -0700460 if (kChromium_GrGLDriver == ctxInfo.driver()) {
461 fMustClearUploadedBufferData = true;
462 }
463
bsalomond08ea5f2015-02-20 06:58:13 -0800464 if (kGL_GrGLStandard == standard) {
465 // ARB allows mixed size FBO attachments, EXT does not.
466 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
467 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
468 fOversizedStencilSupport = true;
469 } else {
470 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
471 }
472 } else {
473 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
474 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
475 }
476
joshualitt58001552015-06-26 12:46:36 -0700477 if (kGL_GrGLStandard == standard) {
478 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
479 // instanced arrays, but we could make this more granular if we wanted
480 fSupportsInstancedDraws =
481 version >= GR_GL_VER(3, 2) ||
482 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
483 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
484 } else {
485 fSupportsInstancedDraws =
486 version >= GR_GL_VER(3, 0) ||
487 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
488 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
489 }
490
bsalomon16921ec2015-07-30 15:34:56 -0700491 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
492 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700493 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
egdanielb7e7d572015-11-04 04:23:53 -0800494 // Requires fTexutreSwizzleSupport and fTextureRedSupport to be set before this point.
495 this->initConfigSwizzleTable(ctxInfo, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700496
497 this->applyOptionsOverrides(contextOptions);
498 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000499}
500
egdaniel472d44e2015-10-22 08:20:00 -0700501const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
502 bool isCoreProfile) {
503 switch (generation) {
504 case k110_GrGLSLGeneration:
505 if (kGLES_GrGLStandard == standard) {
506 // ES2s shader language is based on version 1.20 but is version
507 // 1.00 of the ES language.
508 return "#version 100\n";
509 } else {
510 SkASSERT(kGL_GrGLStandard == standard);
511 return "#version 110\n";
512 }
513 case k130_GrGLSLGeneration:
514 SkASSERT(kGL_GrGLStandard == standard);
515 return "#version 130\n";
516 case k140_GrGLSLGeneration:
517 SkASSERT(kGL_GrGLStandard == standard);
518 return "#version 140\n";
519 case k150_GrGLSLGeneration:
520 SkASSERT(kGL_GrGLStandard == standard);
521 if (isCoreProfile) {
522 return "#version 150\n";
523 } else {
524 return "#version 150 compatibility\n";
525 }
526 case k330_GrGLSLGeneration:
527 if (kGLES_GrGLStandard == standard) {
528 return "#version 300 es\n";
529 } else {
530 SkASSERT(kGL_GrGLStandard == standard);
531 if (isCoreProfile) {
532 return "#version 330\n";
533 } else {
534 return "#version 330 compatibility\n";
535 }
536 }
537 case k310es_GrGLSLGeneration:
538 SkASSERT(kGLES_GrGLStandard == standard);
539 return "#version 310 es\n";
540 }
541 return "<no version>";
542}
543
egdaniel05ded892015-10-26 07:38:05 -0700544void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700545 GrGLStandard standard = ctxInfo.standard();
546 GrGLVersion version = ctxInfo.version();
547
548 /**************************************************************************
549 * Caps specific to GrGLSLCaps
550 **************************************************************************/
551
552 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
553 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
554
555 if (kGLES_GrGLStandard == standard) {
556 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
557 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
558 glslCaps->fFBFetchSupport = true;
559 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
560 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
561 }
562 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
563 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
564 glslCaps->fFBFetchNeedsCustomOutput = false;
565 glslCaps->fFBFetchSupport = true;
566 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
567 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
568 }
569 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
570 // The arm extension also requires an additional flag which we will set onResetContext
571 glslCaps->fFBFetchNeedsCustomOutput = false;
572 glslCaps->fFBFetchSupport = true;
573 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
574 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
575 }
576 glslCaps->fUsesPrecisionModifiers = true;
577 }
578
579 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
580
581 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
582 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
583
584 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
585 // function that may require a gradient calculation inside a conditional block may return
586 // undefined results". This appears to be an issue with the 'any' call since even the simple
587 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
588 // from our GrTextureDomain processor.
589 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
590
egdanielcae00852015-10-22 11:08:08 -0700591 glslCaps->fForceHighPrecisionNDSTransform = kARM_GrGLVendor == ctxInfo.vendor() ||
592 kPowerVR54x_GrGLRenderer == ctxInfo.renderer();
egdaniel472d44e2015-10-22 08:20:00 -0700593
594 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
595 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800596
597 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
598 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
599 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800600
601 // Frag Coords Convention support is not part of ES
602 // Known issue on at least some Intel platforms:
603 // http://code.google.com/p/skia/issues/detail?id=946
604 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
605 kGLES_GrGLStandard != standard &&
606 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
607 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
608 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
609 }
610
611 if (kGLES_GrGLStandard == standard) {
612 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
613 }
614
bsalomon7ea33f52015-11-22 14:51:00 -0800615 if (fExternalTextureSupport) {
616 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
617 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
618 } else {
619 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
620 }
621 }
622
egdaniel8dcdedc2015-11-11 06:27:20 -0800623 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
624 // the abs first in a separate expression.
625 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
626 glslCaps->fCanUseMinAndAbsTogether = false;
627 }
628
bsalomon7ea33f52015-11-22 14:51:00 -0800629 // 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 -0800630 // thus must us -1.0 * %s.x to work correctly
631 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
632 glslCaps->fMustForceNegatedAtanParamToFloat = true;
633 }
egdaniel472d44e2015-10-22 08:20:00 -0700634}
635
kkinnunencfe62e32015-07-01 02:58:50 -0700636bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700637 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
638
639 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700640 return false;
641 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700642
kkinnunencfe62e32015-07-01 02:58:50 -0700643 if (kGL_GrGLStandard == ctxInfo.standard()) {
644 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
645 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
646 return false;
647 }
648 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700649 if (!hasChromiumPathRendering &&
650 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700651 return false;
652 }
653 }
654 // We only support v1.3+ of GL_NV_path_rendering which allows us to
655 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
656 // additions are detected by checking the existence of the function.
657 // We also use *Then* functions that not all drivers might have. Check
658 // them for consistency.
halcanary96fcdcc2015-08-27 07:41:13 -0700659 if (nullptr == gli->fFunctions.fStencilThenCoverFillPath ||
660 nullptr == gli->fFunctions.fStencilThenCoverStrokePath ||
661 nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
662 nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
663 nullptr == gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700664 return false;
665 }
666 return true;
667}
668
bsalomon16921ec2015-07-30 15:34:56 -0700669void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000670 // OpenGL < 3.0
671 // no support for render targets unless the GL_ARB_framebuffer_object
672 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
673 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
674 // probably don't get R8 in this case.
675
676 // OpenGL 3.0
677 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
678 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
679
680 // >= OpenGL 3.1
681 // base color renderable: RED, RG, RGB, and RGBA
682 // sized derivatives: R8, RGBA4, RGBA8
683 // if the GL_ARB_compatibility extension is supported then we get back
684 // support for GL_ALPHA and ALPHA8
685
686 // GL_EXT_bgra adds BGRA render targets to any version
687
688 // ES 2.0
689 // color renderable: RGBA4, RGB5_A1, RGB565
690 // GL_EXT_texture_rg adds support for R8 as a color render target
691 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
692 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
693
694 // ES 3.0
695 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
696 // below already account for this).
697
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000698 GrGLStandard standard = ctxInfo.standard();
699
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000700 enum {
701 kNo_MSAA = 0,
702 kYes_MSAA = 1,
703 };
704
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000705 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000706 // Post 3.0 we will get R8
707 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
708 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
709 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000710 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
711 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000712 }
713 } else {
714 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000715 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
716 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000717 }
718
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000719 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000720 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000721 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
722 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000723 }
724
725 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000726 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
727 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000728
729 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000730 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000731 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000732 }
733
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000734 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000735 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
736 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
737 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000738 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000739 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000740 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
741 } else {
742 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
743 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
744 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000745 }
746
bsalomon16921ec2015-07-30 15:34:56 -0700747 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
748 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
749 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
jvanverthfa1e8a72014-12-22 08:31:49 -0800750 }
751
joshualittee5da552014-07-16 13:32:56 -0700752 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800753 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800754 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800755 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
756 } else {
joshualitt55999962015-06-18 13:47:10 -0700757 // for now we only enable this on desktop, because on ES we'd have to solve many
758 // precision issues and no clients actually want this yet
759 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800760 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
761 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
762 } else {
763 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
764 }
765 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700766 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
767 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700768 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800769 }
joshualittee5da552014-07-16 13:32:56 -0700770 }
771
jvanverth28f9c602014-12-05 13:06:35 -0800772 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800773 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800774 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800775 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800776 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
777 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
778 // for now we don't support floating point MSAA on ES
779 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800780 } else {
jvanverth1334c212014-12-18 05:44:55 -0800781 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
782 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
783 } else {
784 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
785 }
786 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800787 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
788 }
789 }
790
jvanverthfb5df432015-05-21 08:12:27 -0700791 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
792 if (kGL_GrGLStandard == standard) {
793 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
794 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
795 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
796 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
797 // for now we don't support floating point MSAA on ES
798 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
799 } else {
800 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
801 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
802 } else {
803 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
804 }
805 // for now we don't support floating point MSAA on ES
806 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
807 }
808 }
809
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000810 // If we don't support MSAA then undo any places above where we set a config as renderable with
811 // msaa.
812 if (kNone_MSFBOType == fMSFBOType) {
813 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
814 fConfigRenderSupport[i][kYes_MSAA] = false;
815 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000816 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000817}
818
bsalomon16921ec2015-07-30 15:34:56 -0700819void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
820 bool srgbSupport) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000821 GrGLStandard standard = ctxInfo.standard();
822 GrGLVersion version = ctxInfo.version();
823
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000824 // Base texture support
825 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
826 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
827 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
828 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
829
halcanary6950de62015-11-07 05:29:00 -0800830 // Disable this for now, while we investigate https://bug.skia.org/4333
reed56f38fb2015-09-14 09:09:00 -0700831 if (false) {
832 // Check for 8-bit palette..
833 GrGLint numFormats;
834 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
835 if (numFormats) {
836 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
837 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
838 for (int i = 0; i < numFormats; ++i) {
839 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
840 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
841 break;
842 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000843 }
844 }
845 }
846
847 // Check for BGRA
848 if (kGL_GrGLStandard == standard) {
849 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
850 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
851 } else {
852 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
853 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
854 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
855 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
856 fBGRAIsInternalFormat = true;
857 }
858 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
859 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
860 }
861
bsalomon16921ec2015-07-30 15:34:56 -0700862 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
jvanverthfa1e8a72014-12-22 08:31:49 -0800863
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000864 // Compressed texture support
865
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000866 // glCompressedTexImage2D is available on all OpenGL ES devices...
867 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000868 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000869
krajcevski786978162014-07-30 11:25:44 -0700870 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700871 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700872
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000873 // Check for ETC1
874 bool hasETC1 = false;
875
876 // First check version for support
877 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000878 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700879 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000880 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000881 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000882 hasETC1 = hasCompressTex2D &&
883 (version >= GR_GL_VER(3, 0) ||
884 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
885 // ETC2 is a superset of ETC1, so we can just check for that, too.
886 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
887 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000888 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000889 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000890
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000891 // Check for LATC under its various forms
892 LATCAlias alias = kLATC_LATCAlias;
893 bool hasLATC = hasCompressTex2D &&
894 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
895 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
896
897 // Check for RGTC
898 if (!hasLATC) {
899 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
900 if (kGL_GrGLStandard == standard) {
901 hasLATC = version >= GR_GL_VER(3, 0);
902 }
903
904 if (!hasLATC) {
905 hasLATC =
906 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
907 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
908 }
909
910 if (hasLATC) {
911 alias = kRGTC_LATCAlias;
912 }
913 }
914
915 // Check for 3DC
916 if (!hasLATC) {
917 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
918 if (hasLATC) {
919 alias = k3DC_LATCAlias;
920 }
921 }
922
923 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
924 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700925
krajcevskib3abe902014-07-30 13:08:11 -0700926 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
927 // cards default to decompressing the textures in the driver, and is
928 // generally slower.
929 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700930 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
931 }
joshualittee5da552014-07-16 13:32:56 -0700932
krajcevski7ef21622014-07-16 15:21:13 -0700933 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700934 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700935 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
936 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
937 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
938
joshualittee5da552014-07-16 13:32:56 -0700939 // Check for floating point texture support
940 // NOTE: We disallow floating point textures on ES devices if linear
941 // filtering modes are not supported. This is for simplicity, but a more
942 // granular approach is possible. Coincidentally, floating point textures became part of
943 // the standard in ES3.1 / OGL 3.1, hence the shorthand
944 bool hasFPTextures = version >= GR_GL_VER(3, 1);
945 if (!hasFPTextures) {
946 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800947 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700948 ctxInfo.hasExtension("GL_OES_texture_float"));
949 }
950 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800951
952 // Check for fp16 texture support
953 // NOTE: We disallow floating point textures on ES devices if linear
954 // filtering modes are not supported. This is for simplicity, but a more
955 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
956 // the standard in ES3.1 / OGL 3.1, hence the shorthand
957 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
958 if (!hasHalfFPTextures) {
959 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800960 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
961 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800962 }
jvanverth1334c212014-12-18 05:44:55 -0800963 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700964 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000965}
966
piotaixre4b23142014-10-02 10:57:53 -0700967bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
968 GrGLenum format,
969 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000970 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
971 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000972 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000973 }
974
975 if (!fTwoFormatLimit) {
976 // not limited by ES 2's constraints
977 return true;
978 }
979
bsalomon@google.com548a4332012-07-11 19:45:22 +0000980 GrGLint otherFormat = GR_GL_RGBA;
981 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000982
983 // The other supported format/type combo supported for ReadPixels
984 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000985 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000986 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
987 &otherFormat);
988
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000989 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000990 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
991 &otherType);
992
bsalomon@google.com548a4332012-07-11 19:45:22 +0000993 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000994}
995
piotaixre4b23142014-10-02 10:57:53 -0700996bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
997 GrGLenum format,
998 GrGLenum type,
999 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -08001000 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
1001 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
1002 return *supported;
piotaixre4b23142014-10-02 10:57:53 -07001003 }
mtklein2aa1f7e2015-02-20 12:35:32 -08001004 bool supported = this->doReadPixelsSupported(intf, format, type);
1005 fReadPixelsSupportedCache.set(key, supported);
1006 return supported;
piotaixre4b23142014-10-02 10:57:53 -07001007}
1008
robertphillips@google.com6177e692013-02-28 20:16:25 +00001009void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001010
1011 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001012 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001013 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
1014 // ES3 driver bugs on at least one device with a tiled GPU (N10).
1015 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
1016 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
1017 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
1018 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
cdalton63f6c1f2015-11-06 07:09:43 -08001019 } else if (fMixedSamplesSupport && fShaderCaps->pathRenderingSupport()) {
vbuzinovdded6962015-06-12 08:59:45 -07001020 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +00001021 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001022 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
1023 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
1024 // chrome's extension is equivalent to the EXT msaa
1025 // and fbo_blit extensions.
1026 fMSFBOType = kDesktop_EXT_MSFBOType;
1027 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
1028 fMSFBOType = kES_Apple_MSFBOType;
1029 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001030 } else {
cdalton63f6c1f2015-11-06 07:09:43 -08001031 if (fMixedSamplesSupport && fShaderCaps->pathRenderingSupport()) {
vbuzinovdded6962015-06-12 08:59:45 -07001032 fMSFBOType = kMixedSamples_MSFBOType;
1033 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001034 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001035 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001036 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1037 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001038 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001039 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001040 }
1041}
1042
cdalton1dd05422015-06-12 09:01:18 -07001043void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
1044 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
1045
1046 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
1047 // for now until its own blacklists can be updated.
1048 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
1049 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -07001050 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -07001051 return;
1052 }
1053
1054 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1055 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1056 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1057 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
1058 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1059 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1060 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1061 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
1062 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
1063 return;
1064 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1065 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1066 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1067 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
1068 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1069 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1070 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1071 // slow on a particular platform.
1072 } else {
1073 return; // No advanced blend support.
1074 }
1075
1076 SkASSERT(this->advancedBlendEquationSupport());
1077
1078 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
1079 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
1080 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
1081 (1 << kColorBurn_GrBlendEquation);
1082 }
joel.liang9764c402015-07-09 19:46:18 -07001083 if (kARM_GrGLVendor == ctxInfo.vendor()) {
1084 // Blacklist color-burn on ARM until the fix is released.
1085 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
1086 }
cdalton1dd05422015-06-12 09:01:18 -07001087}
1088
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001089namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001090const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001091}
1092
1093void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
1094
1095 // Build up list of legal stencil formats (though perhaps not supported on
1096 // the particular gpu/driver) from most preferred to least.
1097
1098 // these consts are in order of most preferred to least preferred
1099 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1100
1101 static const StencilFormat
1102 // internal Format stencil bits total bits packed?
1103 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1104 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1105 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1106 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001107 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001108 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1109
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001110 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001111 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001112 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001113 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1114 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1115
1116 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1117 // require FBO support we can expect these are legal formats and don't
1118 // check. These also all support the unsized GL_STENCIL_INDEX.
1119 fStencilFormats.push_back() = gS8;
1120 fStencilFormats.push_back() = gS16;
1121 if (supportsPackedDS) {
1122 fStencilFormats.push_back() = gD24S8;
1123 }
1124 fStencilFormats.push_back() = gS4;
1125 if (supportsPackedDS) {
1126 fStencilFormats.push_back() = gDS;
1127 }
1128 } else {
1129 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1130 // for other formats.
1131 // ES doesn't support using the unsized format.
1132
1133 fStencilFormats.push_back() = gS8;
1134 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001135 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1136 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001137 fStencilFormats.push_back() = gD24S8;
1138 }
1139 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1140 fStencilFormats.push_back() = gS4;
1141 }
1142 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001143}
1144
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001145SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001146
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001147 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001148
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001149 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001150 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001151 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001152 i,
1153 fStencilFormats[i].fStencilBits,
1154 fStencilFormats[i].fTotalBits);
1155 }
1156
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001157 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001158 "None",
1159 "ARB",
1160 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001161 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001162 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001163 "IMG MS To Texture",
1164 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001165 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001166 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001167 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1168 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1169 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001170 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1171 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1172 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1173 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001174 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001175 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001176
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001177 static const char* kInvalidateFBTypeStr[] = {
1178 "None",
1179 "Discard",
1180 "Invalidate",
1181 };
1182 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1183 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1184 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1185 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001186
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001187 static const char* kMapBufferTypeStr[] = {
1188 "None",
1189 "MapBuffer",
1190 "MapBufferRange",
1191 "Chromium",
1192 };
1193 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1194 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1195 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1196 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1197 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1198
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001199 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001200 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001201 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001202 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001203 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1204 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001205 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1206 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001207 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001208 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1209 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1210 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1211 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001212
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001213 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1214 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1215 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1216 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1217 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001218 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001219 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1220 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1221 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001222 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001223 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001224 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001225 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001226 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1227 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001228 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001229 return r;
1230}
1231
jvanverthe9c0fc62015-04-29 11:18:05 -07001232static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1233 switch (p) {
1234 case kLow_GrSLPrecision:
1235 return GR_GL_LOW_FLOAT;
1236 case kMedium_GrSLPrecision:
1237 return GR_GL_MEDIUM_FLOAT;
1238 case kHigh_GrSLPrecision:
1239 return GR_GL_HIGH_FLOAT;
1240 }
1241 SkFAIL("Unknown precision.");
1242 return -1;
1243}
1244
1245static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1246 switch (type) {
1247 case kVertex_GrShaderType:
1248 return GR_GL_VERTEX_SHADER;
1249 case kGeometry_GrShaderType:
1250 return GR_GL_GEOMETRY_SHADER;
1251 case kFragment_GrShaderType:
1252 return GR_GL_FRAGMENT_SHADER;
1253 }
1254 SkFAIL("Unknown shader type.");
1255 return -1;
1256}
1257
jvanverthcba99b82015-06-24 06:59:57 -07001258void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1259 const GrGLInterface* intf,
1260 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001261 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1262 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1263 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1264 if (kGeometry_GrShaderType != s) {
1265 GrShaderType shaderType = static_cast<GrShaderType>(s);
1266 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001267 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001268 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001269 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1270 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1271 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1272 GrGLint range[2];
1273 GrGLint bits;
1274 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1275 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001276 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1277 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1278 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001279 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001280 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001281 }
jvanverthcba99b82015-06-24 06:59:57 -07001282 else if (!glslCaps->fShaderPrecisionVaries) {
1283 glslCaps->fShaderPrecisionVaries =
1284 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001285 }
1286 }
1287 }
1288 }
1289 }
1290 }
1291 else {
1292 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001293 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001294 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1295 if (kGeometry_GrShaderType != s) {
1296 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001297 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1298 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1299 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001300 }
1301 }
1302 }
1303 }
1304 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1305 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1306 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1307 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001308 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001309 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001310 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1311 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001312 }
1313 }
1314}
1315
egdanielb7e7d572015-11-04 04:23:53 -08001316void GrGLCaps::initConfigSwizzleTable(const GrGLContextInfo& ctxInfo, GrGLSLCaps* glslCaps) {
1317 GrGLStandard standard = ctxInfo.standard();
1318 GrGLVersion version = ctxInfo.version();
jvanverthe9c0fc62015-04-29 11:18:05 -07001319
egdanielb7e7d572015-11-04 04:23:53 -08001320 glslCaps->fMustSwizzleInShader = true;
1321 if (kGL_GrGLStandard == standard) {
1322 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
1323 glslCaps->fMustSwizzleInShader = false;
1324 }
1325 } else {
1326 if (version >= GR_GL_VER(3,0)) {
1327 glslCaps->fMustSwizzleInShader = false;
1328 }
1329 }
1330
1331 glslCaps->fConfigSwizzle[kUnknown_GrPixelConfig] = nullptr;
1332 if (fTextureRedSupport) {
1333 glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "rrrr";
1334 glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "rrrr";
1335 } else {
1336 glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "aaaa";
1337 glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "aaaa";
1338 }
1339 glslCaps->fConfigSwizzle[kIndex_8_GrPixelConfig] = "rgba";
1340 glslCaps->fConfigSwizzle[kRGB_565_GrPixelConfig] = "rgba";
1341 glslCaps->fConfigSwizzle[kRGBA_4444_GrPixelConfig] = "rgba";
1342 glslCaps->fConfigSwizzle[kRGBA_8888_GrPixelConfig] = "rgba";
1343 glslCaps->fConfigSwizzle[kBGRA_8888_GrPixelConfig] = "rgba";
1344 glslCaps->fConfigSwizzle[kSRGBA_8888_GrPixelConfig] = "rgba";
1345 glslCaps->fConfigSwizzle[kETC1_GrPixelConfig] = "rgba";
1346 glslCaps->fConfigSwizzle[kLATC_GrPixelConfig] = "rrrr";
1347 glslCaps->fConfigSwizzle[kR11_EAC_GrPixelConfig] = "rrrr";
1348 glslCaps->fConfigSwizzle[kASTC_12x12_GrPixelConfig] = "rgba";
1349 glslCaps->fConfigSwizzle[kRGBA_float_GrPixelConfig] = "rgba";
1350 glslCaps->fConfigSwizzle[kRGBA_half_GrPixelConfig] = "rgba";
1351
1352}
1353
1354void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}
jvanverthe9c0fc62015-04-29 11:18:05 -07001355
1356