blob: 9489e216436fadb97710483f8e083b1fbe90d25e [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
bsalomon424cc262015-05-22 10:37:30 -070050 this->init(ctxInfo, glInterface);
jvanverthe9c0fc62015-04-29 11:18:05 -070051
bsalomon4ee6bd82015-05-27 13:23:23 -070052 fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions,
53 ctxInfo, glInterface, *this)));
54
55 this->applyOptionsOverrides(contextOptions);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000056}
57
bsalomon424cc262015-05-22 10:37:30 -070058void GrGLCaps::init(const GrGLContextInfo& ctxInfo, 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 /**************************************************************************
63 * Caps specific to GrGLCaps
64 **************************************************************************/
65
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000066 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000067 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
68 &fMaxFragmentUniformVectors);
69 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000070 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000071 GrGLint max;
72 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
73 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000074 if (version >= GR_GL_VER(3, 2)) {
75 GrGLint profileMask;
76 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
77 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
78 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000080 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000081 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000082
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000083 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000084 fRGBA8RenderbufferSupport = true;
85 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +000086 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
87 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088 ctxInfo.hasExtension("GL_ARM_rgba8");
89 }
90
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000091 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000092 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
93 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
94 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +000095 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096 }
97
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000098 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099 fUnpackRowLengthSupport = true;
100 fUnpackFlipYSupport = false;
101 fPackRowLengthSupport = true;
102 fPackFlipYSupport = false;
103 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000104 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
105 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000106 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000107 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
108 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 fPackFlipYSupport =
110 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
111 }
112
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000113 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000114 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
115
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000116 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000117 // The EXT version can apply to either GL or GLES.
118 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
119 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
120 ctxInfo.hasExtension("GL_EXT_texture_storage");
121 } else {
122 // Qualcomm Adreno drivers appear to have issues with texture storage.
123 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
124 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
125 ctxInfo.hasExtension("GL_EXT_texture_storage");
126 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127
cdaltonfd4167d2015-04-21 11:45:56 -0700128 if (kGL_GrGLStandard == standard) {
129 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
130 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
131 ctxInfo.hasExtension("GL_NV_texture_barrier");
132 } else {
133 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
134 }
135
hendrikwa0d5ad72014-12-02 07:30:30 -0800136 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
137 // and GL_RG on FBO textures.
138 if (!ctxInfo.isMesa()) {
139 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000140 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
141 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800142 } else {
143 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
144 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000145 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000146 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000147 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000148 ctxInfo.hasExtension("GL_ARB_imaging");
149
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000150 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
151 // ReadPixels. The other format has to checked at run-time since it
152 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000153 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000154
rmistry63a9f842014-10-17 06:07:08 -0700155 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000156 // Known issue on at least some Intel platforms:
157 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700158 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000159 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
160 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
161 }
162
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000163 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
164 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
165 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
166 // limit this decision to specific GPU families rather than basing it on the vendor alone.
167 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700168 (kARM_GrGLVendor == ctxInfo.vendor() ||
169 kImagination_GrGLVendor == ctxInfo.vendor() ||
170 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000171 fUseNonVBOVertexAndIndexDynamicData = true;
172 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000173
egdaniel9250d242015-05-18 13:04:26 -0700174 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
175 // Thus we are blacklisting this extension for now on Adreno4xx devices.
176 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
177 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
178 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
179 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000180 fDiscardRenderTargetSupport = true;
181 fInvalidateFBType = kInvalidate_InvalidateFBType;
182 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
183 fDiscardRenderTargetSupport = true;
184 fInvalidateFBType = kDiscard_InvalidateFBType;
185 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000186
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000187 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
188 fFullClearIsFree = true;
189 }
190
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000191 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000192 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800193 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
194 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000195 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000196 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
197 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000198 }
199
jvanverth3f801cb2014-12-16 09:49:38 -0800200 if (kGL_GrGLStandard == standard) {
201 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
202 }
203 else {
204 fES2CompatibilitySupport = true;
205 }
206
cdalton0edea2c2015-05-21 08:27:44 -0700207 if (kGL_GrGLStandard == standard) {
208 fMultisampleDisableSupport = true;
209 } else {
210 fMultisampleDisableSupport = false;
211 }
212
robertphillips@google.com6177e692013-02-28 20:16:25 +0000213 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000214 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000215
216 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700217 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000218 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000219 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000220 // we could also look for GL_ATI_separate_stencil extension or
221 // GL_EXT_stencil_two_side but they use different function signatures
222 // than GL2.0+ (and than each other).
223 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
224 // supported on GL 1.4 and higher or by extension
225 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
226 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
227 } else {
228 // ES 2 has two sided stencil and stencil wrap
229 fTwoSidedStencilSupport = true;
230 fStencilWrapOpsSupport = true;
231 }
232
egdaniel28eee1a2015-05-08 14:42:43 -0700233// Disabling advanced blend until we can resolve various bugs
234#if 0
cdalton8917d622015-05-06 13:40:21 -0700235 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
236 if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") ||
237 ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
238 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
239 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") ||
240 ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
241 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
242 } else {
243 fBlendEquationSupport = kBasic_BlendEquationSupport;
244 }
245 } else {
246 // On Intel platforms, KHR_blend_equation_advanced is not conformant.
247 fBlendEquationSupport = kBasic_BlendEquationSupport;
248 }
egdaniel28eee1a2015-05-08 14:42:43 -0700249#endif
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000250 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000251 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
252 // extension includes glMapBuffer.
253 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
254 fMapBufferFlags |= kSubset_MapFlag;
255 fMapBufferType = kMapBufferRange_MapBufferType;
256 } else {
257 fMapBufferType = kMapBuffer_MapBufferType;
258 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000259 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000260 // Unextended GLES2 doesn't have any buffer mapping.
261 fMapBufferFlags = kNone_MapBufferType;
262 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
263 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
264 fMapBufferType = kChromium_MapBufferType;
265 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
266 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
267 fMapBufferType = kMapBufferRange_MapBufferType;
268 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
269 fMapBufferFlags = kCanMap_MapFlag;
270 fMapBufferType = kMapBuffer_MapBufferType;
271 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000272 }
273
joshualitte5b74c62015-06-01 14:17:47 -0700274 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
275 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
276 if (fGeometryBufferMapThreshold < 0) {
277 fGeometryBufferMapThreshold = ctxInfo.isChromium() ? 0 : SK_MaxS32;
278 }
279
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000280 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000281 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
282 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
283 fNPOTTextureTileSupport = true;
284 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000285 } else {
286 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000287 // ES3 has no limitations.
288 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
289 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000290 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
291 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
292 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
293 // to alllow arbitrary wrap modes, however.
294 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000295 }
296
bsalomon@google.combcce8922013-03-25 15:38:39 +0000297 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
298 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
299 // Our render targets are always created with textures as the color
300 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000301 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000302
bsalomonc59a1df2015-06-01 07:13:42 -0700303 // This GPU seems to have problems when tiling small textures
304 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
305 fMinTextureSize = 16;
306 }
307
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000308 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
309
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000310 // Disable scratch texture reuse on Mali and Adreno devices
311 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
312 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000313
bsalomon@google.com347c3822013-05-01 20:10:01 +0000314 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000315 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
316 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
317 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
318 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000319
bsalomon63b21962014-11-05 07:05:34 -0800320 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800321 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800322 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800323 fUseDrawInsteadOfClear = true;
324 }
325
bsalomond08ea5f2015-02-20 06:58:13 -0800326 if (kGL_GrGLStandard == standard) {
327 // ARB allows mixed size FBO attachments, EXT does not.
328 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
329 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
330 fOversizedStencilSupport = true;
331 } else {
332 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
333 }
334 } else {
335 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
336 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
337 }
338
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000339 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000340 this->initConfigRenderableTable(ctxInfo);
341}
342
343void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000344 // OpenGL < 3.0
345 // no support for render targets unless the GL_ARB_framebuffer_object
346 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
347 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
348 // probably don't get R8 in this case.
349
350 // OpenGL 3.0
351 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
352 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
353
354 // >= OpenGL 3.1
355 // base color renderable: RED, RG, RGB, and RGBA
356 // sized derivatives: R8, RGBA4, RGBA8
357 // if the GL_ARB_compatibility extension is supported then we get back
358 // support for GL_ALPHA and ALPHA8
359
360 // GL_EXT_bgra adds BGRA render targets to any version
361
362 // ES 2.0
363 // color renderable: RGBA4, RGB5_A1, RGB565
364 // GL_EXT_texture_rg adds support for R8 as a color render target
365 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
366 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
367
368 // ES 3.0
369 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
370 // below already account for this).
371
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000372 GrGLStandard standard = ctxInfo.standard();
373
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000374 enum {
375 kNo_MSAA = 0,
376 kYes_MSAA = 1,
377 };
378
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000379 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000380 // Post 3.0 we will get R8
381 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
382 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
383 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000384 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
385 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000386 }
387 } else {
388 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000389 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
390 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000391 }
392
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000393 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000394 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000395 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
396 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000397 }
398
399 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000400 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
401 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000402
403 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000404 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000405 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000406 }
407
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000408 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000409 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
410 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
411 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000412 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000413 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000414 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
415 } else {
416 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
417 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
418 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000419 }
420
jvanverthfa1e8a72014-12-22 08:31:49 -0800421 if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) {
422 if (kGL_GrGLStandard == standard) {
423 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
424 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
425 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
426 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
427 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
428 }
429 } else {
430 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
431 ctxInfo.hasExtension("GL_EXT_sRGB")) {
432 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
433 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
434 }
435 }
436 }
437
joshualittee5da552014-07-16 13:32:56 -0700438 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800439 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800440 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800441 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
442 } else {
jvanvertha60b2ea2014-12-12 05:58:06 -0800443 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
444 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
445 } else {
446 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
447 }
448 // for now we don't support floating point MSAA on ES
jvanverthfb5df432015-05-21 08:12:27 -0700449 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800450 }
joshualittee5da552014-07-16 13:32:56 -0700451 }
452
jvanverth28f9c602014-12-05 13:06:35 -0800453 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800454 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800455 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800456 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800457 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
458 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
459 // for now we don't support floating point MSAA on ES
460 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800461 } else {
jvanverth1334c212014-12-18 05:44:55 -0800462 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
463 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
464 } else {
465 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
466 }
467 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800468 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
469 }
470 }
471
jvanverthfb5df432015-05-21 08:12:27 -0700472 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
473 if (kGL_GrGLStandard == standard) {
474 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
475 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
476 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
477 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
478 // for now we don't support floating point MSAA on ES
479 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
480 } else {
481 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
482 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
483 } else {
484 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
485 }
486 // for now we don't support floating point MSAA on ES
487 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
488 }
489 }
490
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000491 // If we don't support MSAA then undo any places above where we set a config as renderable with
492 // msaa.
493 if (kNone_MSFBOType == fMSFBOType) {
494 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
495 fConfigRenderSupport[i][kYes_MSAA] = false;
496 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000497 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000498}
499
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000500void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000501 GrGLStandard standard = ctxInfo.standard();
502 GrGLVersion version = ctxInfo.version();
503
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000504 // Base texture support
505 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
506 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
507 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
508 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
509
510 // Check for 8-bit palette..
511 GrGLint numFormats;
512 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
513 if (numFormats) {
514 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
515 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
516 for (int i = 0; i < numFormats; ++i) {
517 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
518 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
519 break;
520 }
521 }
522 }
523
524 // Check for BGRA
525 if (kGL_GrGLStandard == standard) {
526 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
527 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
528 } else {
529 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
530 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
531 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
532 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
533 fBGRAIsInternalFormat = true;
534 }
535 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
536 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
537 }
538
jvanverthfa1e8a72014-12-22 08:31:49 -0800539 // Check for sRGBA
540 if (kGL_GrGLStandard == standard) {
541 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
542 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB"));
543 } else {
544 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
545 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
546 }
547
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000548 // Compressed texture support
549
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000550 // glCompressedTexImage2D is available on all OpenGL ES devices...
551 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000552 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000553
krajcevski786978162014-07-30 11:25:44 -0700554 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700555 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700556
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000557 // Check for ETC1
558 bool hasETC1 = false;
559
560 // First check version for support
561 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000562 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700563 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000564 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000565 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000566 hasETC1 = hasCompressTex2D &&
567 (version >= GR_GL_VER(3, 0) ||
568 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
569 // ETC2 is a superset of ETC1, so we can just check for that, too.
570 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
571 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000572 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000573 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000574
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000575 // Check for LATC under its various forms
576 LATCAlias alias = kLATC_LATCAlias;
577 bool hasLATC = hasCompressTex2D &&
578 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
579 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
580
581 // Check for RGTC
582 if (!hasLATC) {
583 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
584 if (kGL_GrGLStandard == standard) {
585 hasLATC = version >= GR_GL_VER(3, 0);
586 }
587
588 if (!hasLATC) {
589 hasLATC =
590 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
591 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
592 }
593
594 if (hasLATC) {
595 alias = kRGTC_LATCAlias;
596 }
597 }
598
599 // Check for 3DC
600 if (!hasLATC) {
601 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
602 if (hasLATC) {
603 alias = k3DC_LATCAlias;
604 }
605 }
606
607 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
608 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700609
krajcevskib3abe902014-07-30 13:08:11 -0700610 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
611 // cards default to decompressing the textures in the driver, and is
612 // generally slower.
613 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700614 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
615 }
joshualittee5da552014-07-16 13:32:56 -0700616
krajcevski7ef21622014-07-16 15:21:13 -0700617 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700618 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700619 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
620 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
621 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
622
joshualittee5da552014-07-16 13:32:56 -0700623 // Check for floating point texture support
624 // NOTE: We disallow floating point textures on ES devices if linear
625 // filtering modes are not supported. This is for simplicity, but a more
626 // granular approach is possible. Coincidentally, floating point textures became part of
627 // the standard in ES3.1 / OGL 3.1, hence the shorthand
628 bool hasFPTextures = version >= GR_GL_VER(3, 1);
629 if (!hasFPTextures) {
630 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800631 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700632 ctxInfo.hasExtension("GL_OES_texture_float"));
633 }
634 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800635
636 // Check for fp16 texture support
637 // NOTE: We disallow floating point textures on ES devices if linear
638 // filtering modes are not supported. This is for simplicity, but a more
639 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
640 // the standard in ES3.1 / OGL 3.1, hence the shorthand
641 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
642 if (!hasHalfFPTextures) {
643 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800644 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
645 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800646 }
jvanverth1334c212014-12-18 05:44:55 -0800647 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700648 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000649}
650
piotaixre4b23142014-10-02 10:57:53 -0700651bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
652 GrGLenum format,
653 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000654 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
655 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000656 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000657 }
658
659 if (!fTwoFormatLimit) {
660 // not limited by ES 2's constraints
661 return true;
662 }
663
bsalomon@google.com548a4332012-07-11 19:45:22 +0000664 GrGLint otherFormat = GR_GL_RGBA;
665 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000666
667 // The other supported format/type combo supported for ReadPixels
668 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000669 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000670 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
671 &otherFormat);
672
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000673 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000674 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
675 &otherType);
676
bsalomon@google.com548a4332012-07-11 19:45:22 +0000677 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000678}
679
piotaixre4b23142014-10-02 10:57:53 -0700680bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
681 GrGLenum format,
682 GrGLenum type,
683 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800684 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
685 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
686 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700687 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800688 bool supported = this->doReadPixelsSupported(intf, format, type);
689 fReadPixelsSupportedCache.set(key, supported);
690 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700691}
692
robertphillips@google.com6177e692013-02-28 20:16:25 +0000693void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000694
695 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000696 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000697 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
698 // ES3 driver bugs on at least one device with a tiled GPU (N10).
699 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
700 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
701 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
702 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000703 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000704 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
705 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
706 // chrome's extension is equivalent to the EXT msaa
707 // and fbo_blit extensions.
708 fMSFBOType = kDesktop_EXT_MSFBOType;
709 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
710 fMSFBOType = kES_Apple_MSFBOType;
711 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000712 } else {
713 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
714 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000715 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000716 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
717 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000718 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000719 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000720 }
721}
722
723namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700724const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000725}
726
727void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
728
729 // Build up list of legal stencil formats (though perhaps not supported on
730 // the particular gpu/driver) from most preferred to least.
731
732 // these consts are in order of most preferred to least preferred
733 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
734
735 static const StencilFormat
736 // internal Format stencil bits total bits packed?
737 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
738 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
739 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
740 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000741 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000742 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
743
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000744 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000745 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000746 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000747 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
748 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
749
750 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
751 // require FBO support we can expect these are legal formats and don't
752 // check. These also all support the unsized GL_STENCIL_INDEX.
753 fStencilFormats.push_back() = gS8;
754 fStencilFormats.push_back() = gS16;
755 if (supportsPackedDS) {
756 fStencilFormats.push_back() = gD24S8;
757 }
758 fStencilFormats.push_back() = gS4;
759 if (supportsPackedDS) {
760 fStencilFormats.push_back() = gDS;
761 }
762 } else {
763 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
764 // for other formats.
765 // ES doesn't support using the unsized format.
766
767 fStencilFormats.push_back() = gS8;
768 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000769 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
770 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000771 fStencilFormats.push_back() = gD24S8;
772 }
773 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
774 fStencilFormats.push_back() = gS4;
775 }
776 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000777 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000778 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
779}
780
781void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
782 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700783 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000784#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
785 return;
786#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000787 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
788 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000789 int count = fStencilFormats.count();
790 // we expect a really small number of possible formats so linear search
791 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000792 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000793 for (int i = 0; i < count; ++i) {
794 if (format.fInternalFormat ==
795 fStencilFormats[i].fInternalFormat) {
796 fStencilVerifiedColorConfigs[i].markVerified(config);
797 return;
798 }
799 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000800 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000801 "GrGLCaps doesn't know about.");
802}
803
804bool GrGLCaps::isColorConfigAndStencilFormatVerified(
805 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700806 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000807#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
808 return false;
809#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000810 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000811 int count = fStencilFormats.count();
812 // we expect a really small number of possible formats so linear search
813 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000814 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000815 for (int i = 0; i < count; ++i) {
816 if (format.fInternalFormat ==
817 fStencilFormats[i].fInternalFormat) {
818 return fStencilVerifiedColorConfigs[i].isVerified(config);
819 }
820 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000821 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000822 "GLCaps doesn't know about.");
823 return false;
824}
825
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000826SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000827
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000828 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000829
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000830 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000831 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000832 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000833 i,
834 fStencilFormats[i].fStencilBits,
835 fStencilFormats[i].fTotalBits);
836 }
837
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000838 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000839 "None",
840 "ARB",
841 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000842 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000843 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000844 "IMG MS To Texture",
845 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000846 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000847 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
848 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
849 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000850 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
851 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
852 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
853 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000854 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000855
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000856 static const char* kInvalidateFBTypeStr[] = {
857 "None",
858 "Discard",
859 "Invalidate",
860 };
861 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
862 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
863 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
864 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000865
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000866 static const char* kMapBufferTypeStr[] = {
867 "None",
868 "MapBuffer",
869 "MapBufferRange",
870 "Chromium",
871 };
872 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
873 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
874 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
875 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
876 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
877
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000878 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000879 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000880 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000881 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000882 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
883 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000884 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
885 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000886 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
887 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
888 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
889 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
890 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
891 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000892
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000893 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
894 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
895 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
896 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
897 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
898 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000899 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000900 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -0700901 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000902 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000903 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000904 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -0700905 return r;
906}
907
908////////////////////////////////////////////////////////////////////////////////////////////
909
bsalomon4ee6bd82015-05-27 13:23:23 -0700910GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options,
911 const GrGLContextInfo& ctxInfo,
bsalomon424cc262015-05-22 10:37:30 -0700912 const GrGLInterface* gli,
913 const GrGLCaps& glCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -0700914 fDropsTileOnZeroDivide = false;
915 fFBFetchSupport = false;
916 fFBFetchNeedsCustomOutput = false;
cdalton8917d622015-05-06 13:40:21 -0700917 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
jvanverthe9c0fc62015-04-29 11:18:05 -0700918 fFBFetchColorName = NULL;
919 fFBFetchExtensionString = NULL;
bsalomon424cc262015-05-22 10:37:30 -0700920 this->init(ctxInfo, gli, glCaps);
bsalomon4ee6bd82015-05-27 13:23:23 -0700921 this->applyOptionsOverrides(options);
jvanverthe9c0fc62015-04-29 11:18:05 -0700922}
923
bsalomon424cc262015-05-22 10:37:30 -0700924void GrGLSLCaps::init(const GrGLContextInfo& ctxInfo,
cdalton8917d622015-05-06 13:40:21 -0700925 const GrGLInterface* gli,
926 const GrGLCaps& glCaps) {
bsalomon6df86402015-06-01 10:41:49 -0700927 fGLSLGeneration = ctxInfo.glslGeneration();
jvanverthe9c0fc62015-04-29 11:18:05 -0700928 GrGLStandard standard = ctxInfo.standard();
929 GrGLVersion version = ctxInfo.version();
930
931 /**************************************************************************
932 * Caps specific to GrGLSLCaps
933 **************************************************************************/
934
935 if (kGLES_GrGLStandard == standard) {
936 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
937 fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
938 fFBFetchSupport = true;
939 fFBFetchColorName = "gl_LastFragData[0]";
940 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
941 }
942 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
943 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
944 fFBFetchNeedsCustomOutput = false;
945 fFBFetchSupport = true;
946 fFBFetchColorName = "gl_LastFragData[0]";
947 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
948 }
949 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
950 // The arm extension also requires an additional flag which we will set onResetContext
951 fFBFetchNeedsCustomOutput = false;
952 fFBFetchSupport = true;
953 fFBFetchColorName = "gl_LastFragColorARM";
954 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
955 }
956 }
957
958 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
959 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
960
961 /**************************************************************************
962 * GrShaderCaps fields
963 **************************************************************************/
964
965 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
966
967 if (fPathRenderingSupport) {
968 if (kGL_GrGLStandard == standard) {
969 // We only support v1.3+ of GL_NV_path_rendering which allows us to
970 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
971 // additions are detected by checking the existence of the function.
972 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
973 ((ctxInfo.version() >= GR_GL_VER(4, 3) ||
974 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
975 gli->fFunctions.fProgramPathFragmentInputGen);
976 }
977 else {
978 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3, 1);
979 }
980 }
981
982 // For now these two are equivalent but we could have dst read in shader via some other method
983 fDstReadInShaderSupport = fFBFetchSupport;
984
985 // Enable supported shader-related caps
986 if (kGL_GrGLStandard == standard) {
987 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3, 3) ||
988 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
989 fShaderDerivativeSupport = true;
990 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
991 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
992 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
993 }
994 else {
995 fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
996 ctxInfo.hasExtension("GL_OES_standard_derivatives");
997 }
998
cdalton0edea2c2015-05-21 08:27:44 -0700999 // We need dual source blending and the ability to disable multisample in order to support mixed
1000 // samples in every corner case.
1001 if (fDualSourceBlendingSupport && glCaps.multisampleDisableSupport()) {
1002 // We understand "mixed samples" to mean the collective capability of 3 different extensions
1003 fMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
1004 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
1005 ctxInfo.hasExtension("GL_EXT_raster_multisample");
1006 }
1007
cdalton8917d622015-05-06 13:40:21 -07001008 if (glCaps.advancedBlendEquationSupport()) {
1009 bool coherent = glCaps.advancedCoherentBlendEquationSupport();
1010 if (ctxInfo.hasExtension(coherent ? "GL_NV_blend_equation_advanced_coherent"
1011 : "GL_NV_blend_equation_advanced")) {
1012 fAdvBlendEqInteraction = kAutomatic_AdvBlendEqInteraction;
1013 } else {
1014 fAdvBlendEqInteraction = kGeneralEnable_AdvBlendEqInteraction;
1015 // TODO: Use the following on any platform where "blend_support_all_equations" is slow.
1016 //fAdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction;
1017 }
1018 }
1019
jvanverthe9c0fc62015-04-29 11:18:05 -07001020 this->initShaderPrecisionTable(ctxInfo, gli);
jvanverthe9c0fc62015-04-29 11:18:05 -07001021}
1022
1023SkString GrGLSLCaps::dump() const {
1024 SkString r = INHERITED::dump();
1025
cdalton8917d622015-05-06 13:40:21 -07001026 static const char* kAdvBlendEqInteractionStr[] = {
1027 "Not Supported",
1028 "Automatic",
1029 "General Enable",
1030 "Specific Enables",
1031 };
1032 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
1033 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
1034 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
1035 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
1036 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
1037
jvanverthe9c0fc62015-04-29 11:18:05 -07001038 r.appendf("--- GLSL-Specific ---\n");
1039
1040 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +00001041 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
cdalton8917d622015-05-06 13:40:21 -07001042 r.appendf("Advanced blend equation interaction: %s\n",
1043 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001044 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001045}
jvanverthe9c0fc62015-04-29 11:18:05 -07001046
1047static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1048 switch (p) {
1049 case kLow_GrSLPrecision:
1050 return GR_GL_LOW_FLOAT;
1051 case kMedium_GrSLPrecision:
1052 return GR_GL_MEDIUM_FLOAT;
1053 case kHigh_GrSLPrecision:
1054 return GR_GL_HIGH_FLOAT;
1055 }
1056 SkFAIL("Unknown precision.");
1057 return -1;
1058}
1059
1060static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1061 switch (type) {
1062 case kVertex_GrShaderType:
1063 return GR_GL_VERTEX_SHADER;
1064 case kGeometry_GrShaderType:
1065 return GR_GL_GEOMETRY_SHADER;
1066 case kFragment_GrShaderType:
1067 return GR_GL_FRAGMENT_SHADER;
1068 }
1069 SkFAIL("Unknown shader type.");
1070 return -1;
1071}
1072
1073void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1074 const GrGLInterface* intf) {
1075 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1076 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1077 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1078 if (kGeometry_GrShaderType != s) {
1079 GrShaderType shaderType = static_cast<GrShaderType>(s);
1080 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
1081 PrecisionInfo* first = NULL;
1082 fShaderPrecisionVaries = false;
1083 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1084 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1085 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1086 GrGLint range[2];
1087 GrGLint bits;
1088 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1089 if (bits) {
1090 fFloatPrecisions[s][p].fLogRangeLow = range[0];
1091 fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1092 fFloatPrecisions[s][p].fBits = bits;
1093 if (!first) {
1094 first = &fFloatPrecisions[s][p];
1095 }
1096 else if (!fShaderPrecisionVaries) {
1097 fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]);
1098 }
1099 }
1100 }
1101 }
1102 }
1103 }
1104 else {
1105 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
1106 fShaderPrecisionVaries = false;
1107 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1108 if (kGeometry_GrShaderType != s) {
1109 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1110 fFloatPrecisions[s][p].fLogRangeLow = 127;
1111 fFloatPrecisions[s][p].fLogRangeHigh = 127;
1112 fFloatPrecisions[s][p].fBits = 23;
1113 }
1114 }
1115 }
1116 }
1117 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1118 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1119 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1120 // are recommended against.
1121 if (fGeometryShaderSupport) {
1122 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1123 fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p];
1124 }
1125 }
1126}
1127
1128
1129
1130