blob: 40405fd55c1549660127ce6b6ffc4951177b0a03 [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
robertphillips@google.com6177e692013-02-28 20:16:25 +000011#include "GrGLContext.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000012#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000013#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000014
bsalomon682c2692015-05-22 14:01:46 -070015GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
16 const GrGLContextInfo& ctxInfo,
17 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000018 fVerifiedColorConfigs.reset();
19 fStencilFormats.reset();
20 fStencilVerifiedColorConfigs.reset();
21 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000022 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070023 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000024 fMapBufferType = kNone_MapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000025 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000026 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000027 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fBGRAIsInternalFormat = false;
30 fTextureSwizzleSupport = false;
31 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;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000039 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000040 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000041 fVertexArrayObjectSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080042 fES2CompatibilitySupport = false;
cdalton0edea2c2015-05-21 08:27:44 -070043 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000044 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000046 fFullClearIsFree = false;
piotaixre4b23142014-10-02 10:57:53 -070047
48 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070049
bsalomon4ee6bd82015-05-27 13:23:23 -070050 fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions,
51 ctxInfo, glInterface, *this)));
52
cdalton4cd67132015-06-10 19:23:46 -070053 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000054}
55
cdalton4cd67132015-06-10 19:23:46 -070056void GrGLCaps::init(const GrContextOptions& contextOptions,
57 const GrGLContextInfo& ctxInfo,
58 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000059 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060 GrGLVersion version = ctxInfo.version();
61
bsalomon@google.combcce8922013-03-25 15:38:39 +000062 /**************************************************************************
cdalton4cd67132015-06-10 19:23:46 -070063 * Caps specific to GrGLSLCaps
64 **************************************************************************/
65
66 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
67 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
68
69 if (kGLES_GrGLStandard == standard) {
70 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
71 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
72 glslCaps->fFBFetchSupport = true;
73 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
74 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
75 }
76 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
77 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
78 glslCaps->fFBFetchNeedsCustomOutput = false;
79 glslCaps->fFBFetchSupport = true;
80 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
81 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
82 }
83 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
84 // The arm extension also requires an additional flag which we will set onResetContext
85 glslCaps->fFBFetchNeedsCustomOutput = false;
86 glslCaps->fFBFetchSupport = true;
87 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
88 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
89 }
90 }
91
92 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
93 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
94
95 /**************************************************************************
bsalomon@google.combcce8922013-03-25 15:38:39 +000096 * Caps specific to GrGLCaps
97 **************************************************************************/
98
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000099 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000100 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
101 &fMaxFragmentUniformVectors);
102 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000103 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104 GrGLint max;
105 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
106 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000107 if (version >= GR_GL_VER(3, 2)) {
108 GrGLint profileMask;
109 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
110 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
111 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000113 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000114 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000115
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000116 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000117 fRGBA8RenderbufferSupport = true;
118 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000119 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
120 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000121 ctxInfo.hasExtension("GL_ARM_rgba8");
122 }
123
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000124 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000125 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
126 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
127 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000128 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000129 }
130
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000131 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000132 fUnpackRowLengthSupport = true;
133 fUnpackFlipYSupport = false;
134 fPackRowLengthSupport = true;
135 fPackFlipYSupport = false;
136 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000137 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
138 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000139 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000140 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
141 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000142 fPackFlipYSupport =
143 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
144 }
145
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000146 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000147 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
148
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000149 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000150 // The EXT version can apply to either GL or GLES.
151 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
152 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
153 ctxInfo.hasExtension("GL_EXT_texture_storage");
154 } else {
155 // Qualcomm Adreno drivers appear to have issues with texture storage.
156 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
157 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
158 ctxInfo.hasExtension("GL_EXT_texture_storage");
159 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000160
cdaltonfd4167d2015-04-21 11:45:56 -0700161 if (kGL_GrGLStandard == standard) {
162 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
163 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
164 ctxInfo.hasExtension("GL_NV_texture_barrier");
165 } else {
166 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
167 }
168
hendrikwa0d5ad72014-12-02 07:30:30 -0800169 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
170 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700171 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800172 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000173 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
174 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800175 } else {
176 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
177 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000178 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000179 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000180 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000181 ctxInfo.hasExtension("GL_ARB_imaging");
182
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000183 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
184 // ReadPixels. The other format has to checked at run-time since it
185 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000186 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000187
rmistry63a9f842014-10-17 06:07:08 -0700188 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000189 // Known issue on at least some Intel platforms:
190 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700191 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000192 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
193 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
194 }
195
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000196 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
197 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
198 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
199 // limit this decision to specific GPU families rather than basing it on the vendor alone.
200 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700201 (kARM_GrGLVendor == ctxInfo.vendor() ||
202 kImagination_GrGLVendor == ctxInfo.vendor() ||
203 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000204 fUseNonVBOVertexAndIndexDynamicData = true;
205 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000206
egdaniel9250d242015-05-18 13:04:26 -0700207 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
208 // Thus we are blacklisting this extension for now on Adreno4xx devices.
209 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
210 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
211 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
212 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000213 fDiscardRenderTargetSupport = true;
214 fInvalidateFBType = kInvalidate_InvalidateFBType;
215 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
216 fDiscardRenderTargetSupport = true;
217 fInvalidateFBType = kDiscard_InvalidateFBType;
218 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000219
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000220 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
221 fFullClearIsFree = true;
222 }
223
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000224 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000225 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800226 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
227 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000228 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000229 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
230 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000231 }
232
jvanverth3f801cb2014-12-16 09:49:38 -0800233 if (kGL_GrGLStandard == standard) {
234 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
235 }
236 else {
237 fES2CompatibilitySupport = true;
238 }
239
cdalton0edea2c2015-05-21 08:27:44 -0700240 if (kGL_GrGLStandard == standard) {
241 fMultisampleDisableSupport = true;
242 } else {
243 fMultisampleDisableSupport = false;
244 }
245
cdalton4cd67132015-06-10 19:23:46 -0700246 /**************************************************************************
247 * GrShaderCaps fields
248 **************************************************************************/
249
250 glslCaps->fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
251
252 if (glslCaps->fPathRenderingSupport) {
253 if (kGL_GrGLStandard == standard) {
254 // We only support v1.3+ of GL_NV_path_rendering which allows us to
255 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
256 // additions are detected by checking the existence of the function.
257 glslCaps->fPathRenderingSupport =
258 ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
259 ((ctxInfo.version() >= GR_GL_VER(4, 3) ||
260 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
261 gli->fFunctions.fProgramPathFragmentInputGen);
262 }
263 else {
264 glslCaps->fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3, 1);
265 }
266 }
267
268 // For now these two are equivalent but we could have dst read in shader via some other method
269 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
270
271 // Enable supported shader-related caps
272 if (kGL_GrGLStandard == standard) {
273 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
274 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
275 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
276 glslCaps->fShaderDerivativeSupport = true;
277 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
278 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
279 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
280 }
281 else {
282 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
283 ctxInfo.hasExtension("GL_OES_standard_derivatives");
284 }
285
286 // We need dual source blending and the ability to disable multisample in order to support mixed
287 // samples in every corner case.
288 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) {
289 // We understand "mixed samples" to mean the collective capability of 3 different extensions
290 glslCaps->fMixedSamplesSupport =
291 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
292 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
293 ctxInfo.hasExtension("GL_EXT_raster_multisample");
294 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000295
296 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700297 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000298 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700299
300 this->initFSAASupport(ctxInfo, gli);
301 this->initStencilFormats(ctxInfo);
302
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000303 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000304 // we could also look for GL_ATI_separate_stencil extension or
305 // GL_EXT_stencil_two_side but they use different function signatures
306 // than GL2.0+ (and than each other).
307 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
308 // supported on GL 1.4 and higher or by extension
309 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
310 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
311 } else {
312 // ES 2 has two sided stencil and stencil wrap
313 fTwoSidedStencilSupport = true;
314 fStencilWrapOpsSupport = true;
315 }
316
egdaniel28eee1a2015-05-08 14:42:43 -0700317// Disabling advanced blend until we can resolve various bugs
318#if 0
cdalton8917d622015-05-06 13:40:21 -0700319 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
cdalton4cd67132015-06-10 19:23:46 -0700320 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
cdalton8917d622015-05-06 13:40:21 -0700321 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
cdalton4cd67132015-06-10 19:23:46 -0700322 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
323 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
324 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
325 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
326 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
cdalton8917d622015-05-06 13:40:21 -0700327 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
cdalton4cd67132015-06-10 19:23:46 -0700328 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
329 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
330 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
331 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
cdalton8917d622015-05-06 13:40:21 -0700332 }
cdalton8917d622015-05-06 13:40:21 -0700333 }
egdaniel28eee1a2015-05-08 14:42:43 -0700334#endif
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000335 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000336 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
337 // extension includes glMapBuffer.
338 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
339 fMapBufferFlags |= kSubset_MapFlag;
340 fMapBufferType = kMapBufferRange_MapBufferType;
341 } else {
342 fMapBufferType = kMapBuffer_MapBufferType;
343 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000344 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000345 // Unextended GLES2 doesn't have any buffer mapping.
346 fMapBufferFlags = kNone_MapBufferType;
347 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
348 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
349 fMapBufferType = kChromium_MapBufferType;
350 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
351 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
352 fMapBufferType = kMapBufferRange_MapBufferType;
353 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
354 fMapBufferFlags = kCanMap_MapFlag;
355 fMapBufferType = kMapBuffer_MapBufferType;
356 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000357 }
358
joshualitte5b74c62015-06-01 14:17:47 -0700359 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
360 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
361 if (fGeometryBufferMapThreshold < 0) {
cdalton1acea862015-06-02 13:05:52 -0700362 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
joshualitte5b74c62015-06-01 14:17:47 -0700363 }
364
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000365 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000366 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
367 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
368 fNPOTTextureTileSupport = true;
369 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000370 } else {
371 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000372 // ES3 has no limitations.
373 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
374 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000375 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
376 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
377 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
378 // to alllow arbitrary wrap modes, however.
379 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000380 }
381
bsalomon@google.combcce8922013-03-25 15:38:39 +0000382 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
383 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
384 // Our render targets are always created with textures as the color
385 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000386 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000387
bsalomonc59a1df2015-06-01 07:13:42 -0700388 // This GPU seems to have problems when tiling small textures
389 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
390 fMinTextureSize = 16;
391 }
392
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000393 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
394
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000395 // Disable scratch texture reuse on Mali and Adreno devices
396 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
397 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000398
bsalomon@google.com347c3822013-05-01 20:10:01 +0000399 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000400 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
401 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
402 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
403 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000404
bsalomon63b21962014-11-05 07:05:34 -0800405 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800406 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800407 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800408 fUseDrawInsteadOfClear = true;
409 }
410
bsalomond08ea5f2015-02-20 06:58:13 -0800411 if (kGL_GrGLStandard == standard) {
412 // ARB allows mixed size FBO attachments, EXT does not.
413 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
414 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
415 fOversizedStencilSupport = true;
416 } else {
417 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
418 }
419 } else {
420 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
421 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
422 }
423
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000424 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000425 this->initConfigRenderableTable(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700426 glslCaps->initShaderPrecisionTable(ctxInfo, gli);
427
428 this->applyOptionsOverrides(contextOptions);
429 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000430}
431
432void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000433 // OpenGL < 3.0
434 // no support for render targets unless the GL_ARB_framebuffer_object
435 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
436 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
437 // probably don't get R8 in this case.
438
439 // OpenGL 3.0
440 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
441 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
442
443 // >= OpenGL 3.1
444 // base color renderable: RED, RG, RGB, and RGBA
445 // sized derivatives: R8, RGBA4, RGBA8
446 // if the GL_ARB_compatibility extension is supported then we get back
447 // support for GL_ALPHA and ALPHA8
448
449 // GL_EXT_bgra adds BGRA render targets to any version
450
451 // ES 2.0
452 // color renderable: RGBA4, RGB5_A1, RGB565
453 // GL_EXT_texture_rg adds support for R8 as a color render target
454 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
455 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
456
457 // ES 3.0
458 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
459 // below already account for this).
460
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000461 GrGLStandard standard = ctxInfo.standard();
462
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000463 enum {
464 kNo_MSAA = 0,
465 kYes_MSAA = 1,
466 };
467
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000468 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000469 // Post 3.0 we will get R8
470 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
471 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
472 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000473 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
474 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000475 }
476 } else {
477 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000478 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
479 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000480 }
481
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000482 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000483 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000484 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
485 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000486 }
487
488 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000489 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
490 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000491
492 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000493 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000494 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000495 }
496
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000497 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000498 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
499 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
500 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000501 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000502 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000503 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
504 } else {
505 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
506 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
507 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000508 }
509
jvanverthfa1e8a72014-12-22 08:31:49 -0800510 if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) {
511 if (kGL_GrGLStandard == standard) {
512 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
513 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
514 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
515 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
516 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
517 }
518 } else {
519 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
520 ctxInfo.hasExtension("GL_EXT_sRGB")) {
521 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
522 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
523 }
524 }
525 }
526
joshualittee5da552014-07-16 13:32:56 -0700527 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800528 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800529 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800530 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
531 } else {
jvanvertha60b2ea2014-12-12 05:58:06 -0800532 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
533 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
534 } else {
535 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
536 }
537 // for now we don't support floating point MSAA on ES
jvanverthfb5df432015-05-21 08:12:27 -0700538 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800539 }
joshualittee5da552014-07-16 13:32:56 -0700540 }
541
jvanverth28f9c602014-12-05 13:06:35 -0800542 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800543 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800544 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800545 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800546 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
547 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
548 // for now we don't support floating point MSAA on ES
549 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800550 } else {
jvanverth1334c212014-12-18 05:44:55 -0800551 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
552 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
553 } else {
554 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
555 }
556 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800557 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
558 }
559 }
560
jvanverthfb5df432015-05-21 08:12:27 -0700561 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
562 if (kGL_GrGLStandard == standard) {
563 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
564 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
565 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
566 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
567 // for now we don't support floating point MSAA on ES
568 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
569 } else {
570 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
571 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
572 } else {
573 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
574 }
575 // for now we don't support floating point MSAA on ES
576 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
577 }
578 }
579
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000580 // If we don't support MSAA then undo any places above where we set a config as renderable with
581 // msaa.
582 if (kNone_MSFBOType == fMSFBOType) {
583 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
584 fConfigRenderSupport[i][kYes_MSAA] = false;
585 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000586 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000587}
588
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000589void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000590 GrGLStandard standard = ctxInfo.standard();
591 GrGLVersion version = ctxInfo.version();
592
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000593 // Base texture support
594 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
595 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
596 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
597 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
598
599 // Check for 8-bit palette..
600 GrGLint numFormats;
601 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
602 if (numFormats) {
603 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
604 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
605 for (int i = 0; i < numFormats; ++i) {
606 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
607 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
608 break;
609 }
610 }
611 }
612
613 // Check for BGRA
614 if (kGL_GrGLStandard == standard) {
615 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
616 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
617 } else {
618 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
619 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
620 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
621 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
622 fBGRAIsInternalFormat = true;
623 }
624 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
625 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
626 }
627
jvanverthfa1e8a72014-12-22 08:31:49 -0800628 // Check for sRGBA
629 if (kGL_GrGLStandard == standard) {
630 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
631 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB"));
632 } else {
633 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
634 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
635 }
636
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000637 // Compressed texture support
638
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000639 // glCompressedTexImage2D is available on all OpenGL ES devices...
640 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000641 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000642
krajcevski786978162014-07-30 11:25:44 -0700643 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700644 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700645
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000646 // Check for ETC1
647 bool hasETC1 = false;
648
649 // First check version for support
650 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000651 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700652 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000653 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000654 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000655 hasETC1 = hasCompressTex2D &&
656 (version >= GR_GL_VER(3, 0) ||
657 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
658 // ETC2 is a superset of ETC1, so we can just check for that, too.
659 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
660 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000661 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000662 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000663
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000664 // Check for LATC under its various forms
665 LATCAlias alias = kLATC_LATCAlias;
666 bool hasLATC = hasCompressTex2D &&
667 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
668 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
669
670 // Check for RGTC
671 if (!hasLATC) {
672 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
673 if (kGL_GrGLStandard == standard) {
674 hasLATC = version >= GR_GL_VER(3, 0);
675 }
676
677 if (!hasLATC) {
678 hasLATC =
679 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
680 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
681 }
682
683 if (hasLATC) {
684 alias = kRGTC_LATCAlias;
685 }
686 }
687
688 // Check for 3DC
689 if (!hasLATC) {
690 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
691 if (hasLATC) {
692 alias = k3DC_LATCAlias;
693 }
694 }
695
696 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
697 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700698
krajcevskib3abe902014-07-30 13:08:11 -0700699 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
700 // cards default to decompressing the textures in the driver, and is
701 // generally slower.
702 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700703 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
704 }
joshualittee5da552014-07-16 13:32:56 -0700705
krajcevski7ef21622014-07-16 15:21:13 -0700706 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700707 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700708 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
709 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
710 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
711
joshualittee5da552014-07-16 13:32:56 -0700712 // Check for floating point texture support
713 // NOTE: We disallow floating point textures on ES devices if linear
714 // filtering modes are not supported. This is for simplicity, but a more
715 // granular approach is possible. Coincidentally, floating point textures became part of
716 // the standard in ES3.1 / OGL 3.1, hence the shorthand
717 bool hasFPTextures = version >= GR_GL_VER(3, 1);
718 if (!hasFPTextures) {
719 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800720 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700721 ctxInfo.hasExtension("GL_OES_texture_float"));
722 }
723 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800724
725 // Check for fp16 texture support
726 // NOTE: We disallow floating point textures on ES devices if linear
727 // filtering modes are not supported. This is for simplicity, but a more
728 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
729 // the standard in ES3.1 / OGL 3.1, hence the shorthand
730 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
731 if (!hasHalfFPTextures) {
732 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800733 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
734 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800735 }
jvanverth1334c212014-12-18 05:44:55 -0800736 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700737 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000738}
739
piotaixre4b23142014-10-02 10:57:53 -0700740bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
741 GrGLenum format,
742 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000743 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
744 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000745 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000746 }
747
748 if (!fTwoFormatLimit) {
749 // not limited by ES 2's constraints
750 return true;
751 }
752
bsalomon@google.com548a4332012-07-11 19:45:22 +0000753 GrGLint otherFormat = GR_GL_RGBA;
754 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000755
756 // The other supported format/type combo supported for ReadPixels
757 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000758 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000759 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
760 &otherFormat);
761
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000762 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000763 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
764 &otherType);
765
bsalomon@google.com548a4332012-07-11 19:45:22 +0000766 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000767}
768
piotaixre4b23142014-10-02 10:57:53 -0700769bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
770 GrGLenum format,
771 GrGLenum type,
772 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800773 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
774 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
775 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700776 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800777 bool supported = this->doReadPixelsSupported(intf, format, type);
778 fReadPixelsSupportedCache.set(key, supported);
779 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700780}
781
robertphillips@google.com6177e692013-02-28 20:16:25 +0000782void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000783
784 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000785 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000786 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
787 // ES3 driver bugs on at least one device with a tiled GPU (N10).
788 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
789 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
790 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
791 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000792 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000793 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
794 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
795 // chrome's extension is equivalent to the EXT msaa
796 // and fbo_blit extensions.
797 fMSFBOType = kDesktop_EXT_MSFBOType;
798 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
799 fMSFBOType = kES_Apple_MSFBOType;
800 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000801 } else {
802 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
803 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000804 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000805 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
806 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000807 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000808 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000809 }
810}
811
812namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700813const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000814}
815
816void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
817
818 // Build up list of legal stencil formats (though perhaps not supported on
819 // the particular gpu/driver) from most preferred to least.
820
821 // these consts are in order of most preferred to least preferred
822 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
823
824 static const StencilFormat
825 // internal Format stencil bits total bits packed?
826 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
827 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
828 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
829 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000830 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000831 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
832
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000833 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000834 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000835 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000836 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
837 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
838
839 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
840 // require FBO support we can expect these are legal formats and don't
841 // check. These also all support the unsized GL_STENCIL_INDEX.
842 fStencilFormats.push_back() = gS8;
843 fStencilFormats.push_back() = gS16;
844 if (supportsPackedDS) {
845 fStencilFormats.push_back() = gD24S8;
846 }
847 fStencilFormats.push_back() = gS4;
848 if (supportsPackedDS) {
849 fStencilFormats.push_back() = gDS;
850 }
851 } else {
852 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
853 // for other formats.
854 // ES doesn't support using the unsized format.
855
856 fStencilFormats.push_back() = gS8;
857 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000858 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
859 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000860 fStencilFormats.push_back() = gD24S8;
861 }
862 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
863 fStencilFormats.push_back() = gS4;
864 }
865 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000866 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000867 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
868}
869
870void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
871 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700872 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000873#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
874 return;
875#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000876 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
877 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000878 int count = fStencilFormats.count();
879 // we expect a really small number of possible formats so linear search
880 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000881 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000882 for (int i = 0; i < count; ++i) {
883 if (format.fInternalFormat ==
884 fStencilFormats[i].fInternalFormat) {
885 fStencilVerifiedColorConfigs[i].markVerified(config);
886 return;
887 }
888 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000889 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000890 "GrGLCaps doesn't know about.");
891}
892
893bool GrGLCaps::isColorConfigAndStencilFormatVerified(
894 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700895 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000896#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
897 return false;
898#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000899 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000900 int count = fStencilFormats.count();
901 // we expect a really small number of possible formats so linear search
902 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000903 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000904 for (int i = 0; i < count; ++i) {
905 if (format.fInternalFormat ==
906 fStencilFormats[i].fInternalFormat) {
907 return fStencilVerifiedColorConfigs[i].isVerified(config);
908 }
909 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000910 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000911 "GLCaps doesn't know about.");
912 return false;
913}
914
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000915SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000916
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000917 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000918
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000919 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000920 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000921 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000922 i,
923 fStencilFormats[i].fStencilBits,
924 fStencilFormats[i].fTotalBits);
925 }
926
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000927 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000928 "None",
929 "ARB",
930 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000931 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000932 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000933 "IMG MS To Texture",
934 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000935 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000936 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
937 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
938 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000939 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
940 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
941 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
942 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000943 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000944
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000945 static const char* kInvalidateFBTypeStr[] = {
946 "None",
947 "Discard",
948 "Invalidate",
949 };
950 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
951 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
952 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
953 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000954
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000955 static const char* kMapBufferTypeStr[] = {
956 "None",
957 "MapBuffer",
958 "MapBufferRange",
959 "Chromium",
960 };
961 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
962 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
963 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
964 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
965 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
966
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000967 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000968 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000969 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000970 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000971 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
972 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000973 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
974 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000975 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
976 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
977 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
978 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
979 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
980 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000981
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000982 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
983 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
984 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
985 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
986 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
987 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000988 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000989 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -0700990 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000991 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000992 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000993 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -0700994 return r;
995}
996
997////////////////////////////////////////////////////////////////////////////////////////////
998
bsalomon4ee6bd82015-05-27 13:23:23 -0700999GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options,
1000 const GrGLContextInfo& ctxInfo,
bsalomon424cc262015-05-22 10:37:30 -07001001 const GrGLInterface* gli,
1002 const GrGLCaps& glCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001003 fDropsTileOnZeroDivide = false;
1004 fFBFetchSupport = false;
1005 fFBFetchNeedsCustomOutput = false;
cdalton8917d622015-05-06 13:40:21 -07001006 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
jvanverthe9c0fc62015-04-29 11:18:05 -07001007 fFBFetchColorName = NULL;
1008 fFBFetchExtensionString = NULL;
jvanverthe9c0fc62015-04-29 11:18:05 -07001009}
1010
1011SkString GrGLSLCaps::dump() const {
1012 SkString r = INHERITED::dump();
1013
cdalton8917d622015-05-06 13:40:21 -07001014 static const char* kAdvBlendEqInteractionStr[] = {
1015 "Not Supported",
1016 "Automatic",
1017 "General Enable",
1018 "Specific Enables",
1019 };
1020 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
1021 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
1022 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
1023 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
1024 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
1025
jvanverthe9c0fc62015-04-29 11:18:05 -07001026 r.appendf("--- GLSL-Specific ---\n");
1027
1028 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +00001029 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
cdalton8917d622015-05-06 13:40:21 -07001030 r.appendf("Advanced blend equation interaction: %s\n",
1031 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001032 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001033}
jvanverthe9c0fc62015-04-29 11:18:05 -07001034
1035static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1036 switch (p) {
1037 case kLow_GrSLPrecision:
1038 return GR_GL_LOW_FLOAT;
1039 case kMedium_GrSLPrecision:
1040 return GR_GL_MEDIUM_FLOAT;
1041 case kHigh_GrSLPrecision:
1042 return GR_GL_HIGH_FLOAT;
1043 }
1044 SkFAIL("Unknown precision.");
1045 return -1;
1046}
1047
1048static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1049 switch (type) {
1050 case kVertex_GrShaderType:
1051 return GR_GL_VERTEX_SHADER;
1052 case kGeometry_GrShaderType:
1053 return GR_GL_GEOMETRY_SHADER;
1054 case kFragment_GrShaderType:
1055 return GR_GL_FRAGMENT_SHADER;
1056 }
1057 SkFAIL("Unknown shader type.");
1058 return -1;
1059}
1060
1061void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1062 const GrGLInterface* intf) {
1063 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1064 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1065 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1066 if (kGeometry_GrShaderType != s) {
1067 GrShaderType shaderType = static_cast<GrShaderType>(s);
1068 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
1069 PrecisionInfo* first = NULL;
1070 fShaderPrecisionVaries = false;
1071 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1072 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1073 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1074 GrGLint range[2];
1075 GrGLint bits;
1076 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1077 if (bits) {
1078 fFloatPrecisions[s][p].fLogRangeLow = range[0];
1079 fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1080 fFloatPrecisions[s][p].fBits = bits;
1081 if (!first) {
1082 first = &fFloatPrecisions[s][p];
1083 }
1084 else if (!fShaderPrecisionVaries) {
1085 fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]);
1086 }
1087 }
1088 }
1089 }
1090 }
1091 }
1092 else {
1093 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
1094 fShaderPrecisionVaries = false;
1095 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1096 if (kGeometry_GrShaderType != s) {
1097 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1098 fFloatPrecisions[s][p].fLogRangeLow = 127;
1099 fFloatPrecisions[s][p].fLogRangeHigh = 127;
1100 fFloatPrecisions[s][p].fBits = 23;
1101 }
1102 }
1103 }
1104 }
1105 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1106 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1107 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1108 // are recommended against.
1109 if (fGeometryShaderSupport) {
1110 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1111 fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p];
1112 }
1113 }
1114}
1115
1116
1117
1118