blob: 8ca88c14aa1a73141290c7c656884495b6d17be3 [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"
robertphillips@google.com6177e692013-02-28 20:16:25 +000010#include "GrGLContext.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000011#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000012#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000013
bsalomon@google.combcce8922013-03-25 15:38:39 +000014SK_DEFINE_INST_COUNT(GrGLCaps)
15
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000016GrGLCaps::GrGLCaps() {
17 this->reset();
18}
19
20void GrGLCaps::reset() {
bsalomon@google.combcce8922013-03-25 15:38:39 +000021 INHERITED::reset();
22
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000023 fVerifiedColorConfigs.reset();
24 fStencilFormats.reset();
25 fStencilVerifiedColorConfigs.reset();
26 fMSFBOType = kNone_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000027 fCoverageAAType = kNone_CoverageAAType;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000028 fFBFetchType = kNone_FBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000030 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000031 fMaxFragmentTextureUnits = 0;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000032 fMaxFixedFunctionTextureCoords = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000033 fRGBA8RenderbufferSupport = false;
34 fBGRAFormatSupport = false;
35 fBGRAIsInternalFormat = false;
36 fTextureSwizzleSupport = false;
37 fUnpackRowLengthSupport = false;
38 fUnpackFlipYSupport = false;
39 fPackRowLengthSupport = false;
40 fPackFlipYSupport = false;
41 fTextureUsageSupport = false;
42 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000043 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000044 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000045 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000046 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000047 fVertexArrayObjectSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000048 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000049 fIsCoreProfile = false;
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +000050 fFixedFunctionSupport = false;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000051 fDiscardFBSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000052}
53
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000054GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000055 *this = caps;
56}
57
58GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000059 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
61 fStencilFormats = caps.fStencilFormats;
62 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
63 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000064 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000065 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000066 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000067 fMSFBOType = caps.fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000068 fCoverageAAType = caps.fCoverageAAType;
69 fMSAACoverageModes = caps.fMSAACoverageModes;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000070 fFBFetchType = caps.fFBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000071 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
72 fBGRAFormatSupport = caps.fBGRAFormatSupport;
73 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
74 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
75 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
76 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
77 fPackRowLengthSupport = caps.fPackRowLengthSupport;
78 fPackFlipYSupport = caps.fPackFlipYSupport;
79 fTextureUsageSupport = caps.fTextureUsageSupport;
80 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000081 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000082 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000083 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000084 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000085 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000086 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000087 fIsCoreProfile = caps.fIsCoreProfile;
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +000088 fFixedFunctionSupport = caps.fFixedFunctionSupport;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000089 fDiscardFBSupport = caps.fDiscardFBSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090
91 return *this;
92}
93
robertphillips@google.com6177e692013-02-28 20:16:25 +000094void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095
96 this->reset();
97 if (!ctxInfo.isInitialized()) {
98 return;
99 }
100
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 GrGLBinding binding = ctxInfo.binding();
102 GrGLVersion version = ctxInfo.version();
103
bsalomon@google.combcce8922013-03-25 15:38:39 +0000104 /**************************************************************************
105 * Caps specific to GrGLCaps
106 **************************************************************************/
107
bsalomon@google.com791816a2013-08-15 18:54:39 +0000108 if (kES_GrGLBinding == binding) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
110 &fMaxFragmentUniformVectors);
111 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000112 SkASSERT(kDesktop_GrGLBinding == binding);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000113 GrGLint max;
114 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
115 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000116 if (version >= GR_GL_VER(3, 2)) {
117 GrGLint profileMask;
118 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
119 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
120 }
121 if (!fIsCoreProfile) {
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000122 fFixedFunctionSupport = true;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000123 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
124 // Sanity check
125 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
126 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000128 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000129 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000130
131 if (kDesktop_GrGLBinding == binding) {
132 fRGBA8RenderbufferSupport = true;
133 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000134 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
135 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000136 ctxInfo.hasExtension("GL_ARM_rgba8");
137 }
138
139 if (kDesktop_GrGLBinding == binding) {
140 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
141 ctxInfo.hasExtension("GL_EXT_bgra");
142 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000143 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
144 fBGRAFormatSupport = true;
145 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
146 fBGRAFormatSupport = true;
147 fBGRAIsInternalFormat = true;
148 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000149 SkASSERT(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000150 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000151 }
152
153 if (kDesktop_GrGLBinding == binding) {
154 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
155 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
156 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000157 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000158 }
159
160 if (kDesktop_GrGLBinding == binding) {
161 fUnpackRowLengthSupport = true;
162 fUnpackFlipYSupport = false;
163 fPackRowLengthSupport = true;
164 fPackFlipYSupport = false;
165 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000166 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
167 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000168 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000169 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
170 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000171 fPackFlipYSupport =
172 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
173 }
174
bsalomon@google.com791816a2013-08-15 18:54:39 +0000175 fTextureUsageSupport = (kES_GrGLBinding == binding) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000176 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
177
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000178 if (kDesktop_GrGLBinding == binding) {
179 // The EXT version can apply to either GL or GLES.
180 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
181 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
182 ctxInfo.hasExtension("GL_EXT_texture_storage");
183 } else {
184 // Qualcomm Adreno drivers appear to have issues with texture storage.
185 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
186 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
187 ctxInfo.hasExtension("GL_EXT_texture_storage");
188 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000189
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000190 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
191 // it doesn't have ARB_texture_rg extension.
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000192 if (kDesktop_GrGLBinding == binding) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000193 if (ctxInfo.isMesa()) {
194 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
195 } else {
196 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
197 ctxInfo.hasExtension("GL_ARB_texture_rg");
198 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000199 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000200 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
201 ctxInfo.hasExtension("GL_EXT_texture_rg");
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000202 }
203
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000204 fImagingSupport = kDesktop_GrGLBinding == binding &&
205 ctxInfo.hasExtension("GL_ARB_imaging");
206
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000207 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
208 // ReadPixels. The other format has to checked at run-time since it
209 // can change based on which render target is bound
bsalomon@google.com791816a2013-08-15 18:54:39 +0000210 fTwoFormatLimit = kES_GrGLBinding == binding;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000211
bsalomon@google.com706f6682012-10-23 14:53:55 +0000212 // Known issue on at least some Intel platforms:
213 // http://code.google.com/p/skia/issues/detail?id=946
214 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
215 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
216 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
217 }
218
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000219 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
220 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
221 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
222 // limit this decision to specific GPU families rather than basing it on the vendor alone.
223 if (!GR_GL_MUST_USE_VBO &&
224 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000225 fUseNonVBOVertexAndIndexDynamicData = true;
226 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000227
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000228 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
229
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000230 if (kDesktop_GrGLBinding == binding) {
231 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
232 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
233 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000234 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
235 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000236 }
237
bsalomon@google.com791816a2013-08-15 18:54:39 +0000238 if (kES_GrGLBinding == binding) {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000239 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
240 fFBFetchType = kEXT_FBFetchType;
241 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
242 fFBFetchType = kNV_FBFetchType;
243 }
244 }
245
robertphillips@google.com6177e692013-02-28 20:16:25 +0000246 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000247 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000248
249 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000250 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000251 **************************************************************************/
bsalomon@google.combcce8922013-03-25 15:38:39 +0000252 GrGLint numFormats;
253 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
bungeman@google.com71033442013-05-01 14:21:20 +0000254 if (numFormats) {
255 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
256 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
257 for (int i = 0; i < numFormats; ++i) {
258 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
259 f8BitPaletteSupport = true;
260 break;
261 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000262 }
263 }
264
265 if (kDesktop_GrGLBinding == binding) {
266 // we could also look for GL_ATI_separate_stencil extension or
267 // GL_EXT_stencil_two_side but they use different function signatures
268 // than GL2.0+ (and than each other).
269 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
270 // supported on GL 1.4 and higher or by extension
271 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
272 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
273 } else {
274 // ES 2 has two sided stencil and stencil wrap
275 fTwoSidedStencilSupport = true;
276 fStencilWrapOpsSupport = true;
277 }
278
279 if (kDesktop_GrGLBinding == binding) {
280 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
281 // glMapBuffer.
282 } else {
283 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
284 }
285
286 if (kDesktop_GrGLBinding == binding) {
287 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
288 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
289 fNPOTTextureTileSupport = true;
290 } else {
291 fNPOTTextureTileSupport = false;
292 }
293 } else {
294 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000295 // ES3 has no limitations.
296 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
297 ctxInfo.hasExtension("GL_OES_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000298 }
299
300 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
301
302 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
303 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
304 // Our render targets are always created with textures as the color
305 // attachment, hence this min:
306 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
307
308 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
309 ctxInfo.hasExtension("GL_NV_path_rendering");
310
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000311 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
312
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000313#if 0
314 // This has to be temporarily disabled. On Android it causes the texture
315 // usage to become front loaded and the OS kills the process. It can
316 // be re-enabled once the more dynamic (ref-driven) cache clearing
317 // system is in place.
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000318 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000319#else
320 fReuseScratchTextures = true;
321#endif
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000322
bsalomon@google.combcce8922013-03-25 15:38:39 +0000323 // Enable supported shader-related caps
324 if (kDesktop_GrGLBinding == binding) {
325 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
326 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
327 fShaderDerivativeSupport = true;
328 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
329 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
330 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
331 } else {
332 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
333 }
334
bsalomon@google.com347c3822013-05-01 20:10:01 +0000335 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000336 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
337 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
338 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
339 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000340}
341
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000342bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000343 GrGLenum format,
344 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000345 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
346 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000347 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000348 }
349
350 if (!fTwoFormatLimit) {
351 // not limited by ES 2's constraints
352 return true;
353 }
354
bsalomon@google.com548a4332012-07-11 19:45:22 +0000355 GrGLint otherFormat = GR_GL_RGBA;
356 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000357
358 // The other supported format/type combo supported for ReadPixels
359 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000360 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000361 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
362 &otherFormat);
363
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000364 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000365 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
366 &otherType);
367
bsalomon@google.com548a4332012-07-11 19:45:22 +0000368 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000369}
370
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000371namespace {
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000372bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left,
373 const GrGLCaps::MSAACoverageMode& right) {
374 if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) {
375 return true;
376 } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) {
377 return false;
378 } else if (left.fColorSampleCnt < right.fColorSampleCnt) {
379 return true;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000380 }
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000381 return false;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000382}
383}
384
robertphillips@google.com6177e692013-02-28 20:16:25 +0000385void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000386
387 fMSFBOType = kNone_MSFBOType;
388 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000389 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
390 // ES3 driver bugs on at least one device with a tiled GPU (N10).
391 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
392 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
393 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
394 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
395 } else if (!GR_GL_IGNORE_ES3_MSAA && ctxInfo.version() >= GR_GL_VER(3,0)) {
396 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
397 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
398 // chrome's extension is equivalent to the EXT msaa
399 // and fbo_blit extensions.
400 fMSFBOType = kDesktop_EXT_MSFBOType;
401 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
402 fMSFBOType = kES_Apple_MSFBOType;
403 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000404 } else {
405 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
406 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000407 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000408 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
409 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000410 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000411 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000412 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
413 // on GL 4.2+. It's format-specific, though. See also
414 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
415 // rather than requested sample counts in cache key.
416 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
417 fCoverageAAType = kNVDesktop_CoverageAAType;
418 GrGLint count;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000419 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000420 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
421 &count);
422 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000423 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000424 GR_GL_MULTISAMPLE_COVERAGE_MODES,
425 (int*)&fMSAACoverageModes[0]);
426 // The NV driver seems to return the modes already sorted but the
427 // spec doesn't require this. So we sort.
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000428 typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_less> SortFunctor;
429 SortFunctor sortFunctor;
430 SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(),
431 fMSAACoverageModes.end() - 1,
432 sortFunctor);
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000433 }
434 }
435}
436
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000437const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000438 static const MSAACoverageMode kNoneMode = {0, 0};
439 if (0 == fMSAACoverageModes.count()) {
440 return kNoneMode;
441 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000442 SkASSERT(kNone_CoverageAAType != fCoverageAAType);
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000443 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
444 desiredSampleCount = GrMin(desiredSampleCount, max);
445 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000446 int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverageModes[0],
447 fMSAACoverageModes.count(),
448 desiredMode,
449 sizeof(MSAACoverageMode));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000450 if (idx < 0) {
451 idx = ~idx;
452 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000453 SkASSERT(idx >= 0 && idx < fMSAACoverageModes.count());
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000454 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000455 }
456}
457
458namespace {
459const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
460}
461
462void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
463
464 // Build up list of legal stencil formats (though perhaps not supported on
465 // the particular gpu/driver) from most preferred to least.
466
467 // these consts are in order of most preferred to least preferred
468 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
469
470 static const StencilFormat
471 // internal Format stencil bits total bits packed?
472 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
473 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
474 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
475 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000476 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000477 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
478
479 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
480 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000481 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000482 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
483 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
484
485 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
486 // require FBO support we can expect these are legal formats and don't
487 // check. These also all support the unsized GL_STENCIL_INDEX.
488 fStencilFormats.push_back() = gS8;
489 fStencilFormats.push_back() = gS16;
490 if (supportsPackedDS) {
491 fStencilFormats.push_back() = gD24S8;
492 }
493 fStencilFormats.push_back() = gS4;
494 if (supportsPackedDS) {
495 fStencilFormats.push_back() = gDS;
496 }
497 } else {
498 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
499 // for other formats.
500 // ES doesn't support using the unsized format.
501
502 fStencilFormats.push_back() = gS8;
503 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000504 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
505 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000506 fStencilFormats.push_back() = gD24S8;
507 }
508 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
509 fStencilFormats.push_back() = gS4;
510 }
511 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000512 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000513 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
514}
515
516void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
517 GrPixelConfig config,
518 const GrGLStencilBuffer::Format& format) {
519#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
520 return;
521#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000522 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
523 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000524 int count = fStencilFormats.count();
525 // we expect a really small number of possible formats so linear search
526 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000527 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000528 for (int i = 0; i < count; ++i) {
529 if (format.fInternalFormat ==
530 fStencilFormats[i].fInternalFormat) {
531 fStencilVerifiedColorConfigs[i].markVerified(config);
532 return;
533 }
534 }
535 GrCrash("Why are we seeing a stencil format that "
536 "GrGLCaps doesn't know about.");
537}
538
539bool GrGLCaps::isColorConfigAndStencilFormatVerified(
540 GrPixelConfig config,
541 const GrGLStencilBuffer::Format& format) const {
542#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
543 return false;
544#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000545 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000546 int count = fStencilFormats.count();
547 // we expect a really small number of possible formats so linear search
548 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000549 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000550 for (int i = 0; i < count; ++i) {
551 if (format.fInternalFormat ==
552 fStencilFormats[i].fInternalFormat) {
553 return fStencilVerifiedColorConfigs[i].isVerified(config);
554 }
555 }
556 GrCrash("Why are we seeing a stencil format that "
557 "GLCaps doesn't know about.");
558 return false;
559}
560
561void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000562
563 INHERITED::print();
564
565 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000566 for (int i = 0; i < fStencilFormats.count(); ++i) {
567 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
568 i,
569 fStencilFormats[i].fStencilBits,
570 fStencilFormats[i].fTotalBits);
571 }
572
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000573 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000574 "None",
575 "ARB",
576 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000577 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000578 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000579 "IMG MS To Texture",
580 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000581 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000582 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
583 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
584 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000585 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
586 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
587 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
588 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000589 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
590
591 static const char* kFBFetchTypeStr[] = {
592 "None",
593 "EXT",
594 "NV",
595 };
596 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
597 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
598 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
599 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
600
601
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000602 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
603 GrPrintf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO"));
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000604 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
605 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000606 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000607 GrPrintf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
608 if (fFixedFunctionSupport) {
609 GrPrintf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
610 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000611 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
612 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
613 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
614 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
615 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
616 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
617 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
618 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
619 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
620
621 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
622 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
623 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
624 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000625 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000626 GrPrintf("Fragment coord conventions support: %s\n",
627 (fFragCoordsConventionSupport ? "YES": "NO"));
628 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
629 GrPrintf("Use non-VBO for dynamic data: %s\n",
630 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000631 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000632}