blob: 8b296e360bfd5f5c61dc7b2b82e17d3b8bb7b899 [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;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fRGBA8RenderbufferSupport = false;
32 fBGRAFormatSupport = false;
33 fBGRAIsInternalFormat = false;
34 fTextureSwizzleSupport = false;
35 fUnpackRowLengthSupport = false;
36 fUnpackFlipYSupport = false;
37 fPackRowLengthSupport = false;
38 fPackFlipYSupport = false;
39 fTextureUsageSupport = false;
40 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000041 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000042 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000043 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000044 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000045 fVertexArrayObjectSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000046 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000047 fIsCoreProfile = false;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000048 fDiscardFBSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000049}
50
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000051GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000052 *this = caps;
53}
54
55GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000056 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000057 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
58 fStencilFormats = caps.fStencilFormats;
59 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
60 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000061 fMaxVertexAttributes = caps.fMaxVertexAttributes;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000062 fMSFBOType = caps.fMSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000063 fCoverageAAType = caps.fCoverageAAType;
64 fMSAACoverageModes = caps.fMSAACoverageModes;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000065 fFBFetchType = caps.fFBFetchType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000066 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
67 fBGRAFormatSupport = caps.fBGRAFormatSupport;
68 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
69 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
70 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
71 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
72 fPackRowLengthSupport = caps.fPackRowLengthSupport;
73 fPackFlipYSupport = caps.fPackFlipYSupport;
74 fTextureUsageSupport = caps.fTextureUsageSupport;
75 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000076 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000077 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000078 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000079 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000080 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000081 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000082 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.coma6ffb582013-04-29 16:50:17 +000083 fDiscardFBSupport = caps.fDiscardFBSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000084
85 return *this;
86}
87
robertphillips@google.com6177e692013-02-28 20:16:25 +000088void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089
90 this->reset();
91 if (!ctxInfo.isInitialized()) {
92 return;
93 }
94
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000095 GrGLBinding binding = ctxInfo.binding();
96 GrGLVersion version = ctxInfo.version();
97
bsalomon@google.combcce8922013-03-25 15:38:39 +000098 /**************************************************************************
99 * Caps specific to GrGLCaps
100 **************************************************************************/
101
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000102 if (kES2_GrGLBinding == binding) {
103 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
104 &fMaxFragmentUniformVectors);
105 } else {
106 GrAssert(kDesktop_GrGLBinding == binding);
107 GrGLint max;
108 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
109 fMaxFragmentUniformVectors = max / 4;
110 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000111 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112
113 if (kDesktop_GrGLBinding == binding) {
114 fRGBA8RenderbufferSupport = true;
115 } else {
116 fRGBA8RenderbufferSupport = ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
117 ctxInfo.hasExtension("GL_ARM_rgba8");
118 }
119
120 if (kDesktop_GrGLBinding == binding) {
121 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
122 ctxInfo.hasExtension("GL_EXT_bgra");
123 } else {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
125 fBGRAFormatSupport = true;
126 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
127 fBGRAFormatSupport = true;
128 fBGRAIsInternalFormat = true;
129 }
130 GrAssert(fBGRAFormatSupport ||
bsalomon@google.com0342a852012-08-20 19:22:38 +0000131 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000132 }
133
134 if (kDesktop_GrGLBinding == binding) {
135 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
136 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
137 } else {
138 fTextureSwizzleSupport = false;
139 }
140
141 if (kDesktop_GrGLBinding == binding) {
142 fUnpackRowLengthSupport = true;
143 fUnpackFlipYSupport = false;
144 fPackRowLengthSupport = true;
145 fPackFlipYSupport = false;
146 } else {
147 fUnpackRowLengthSupport =ctxInfo.hasExtension("GL_EXT_unpack_subimage");
148 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
149 // no extension for pack row length
150 fPackRowLengthSupport = false;
151 fPackFlipYSupport =
152 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
153 }
154
155 fTextureUsageSupport = (kES2_GrGLBinding == binding) &&
156 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
157
158 // Tex storage is in desktop 4.2 and can be an extension to desktop or ES.
159 fTexStorageSupport = (kDesktop_GrGLBinding == binding &&
160 version >= GR_GL_VER(4,2)) ||
161 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
162 ctxInfo.hasExtension("GL_EXT_texture_storage");
163
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000164 // ARB_texture_rg is part of OpenGL 3.0
165 if (kDesktop_GrGLBinding == binding) {
166 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
167 ctxInfo.hasExtension("GL_ARB_texture_rg");
168 } else {
169 fTextureRedSupport = ctxInfo.hasExtension("GL_EXT_texture_rg");
170 }
171
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000172 fImagingSupport = kDesktop_GrGLBinding == binding &&
173 ctxInfo.hasExtension("GL_ARB_imaging");
174
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000175 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
176 // ReadPixels. The other format has to checked at run-time since it
177 // can change based on which render target is bound
178 fTwoFormatLimit = kES2_GrGLBinding == binding;
179
bsalomon@google.com706f6682012-10-23 14:53:55 +0000180 // Known issue on at least some Intel platforms:
181 // http://code.google.com/p/skia/issues/detail?id=946
182 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
183 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
184 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
185 }
186
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000187 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
188 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
189 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
190 // limit this decision to specific GPU families rather than basing it on the vendor alone.
191 if (!GR_GL_MUST_USE_VBO &&
192 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000193 fUseNonVBOVertexAndIndexDynamicData = true;
194 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000195
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000196 if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) {
197 GrGLint profileMask;
198 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
199 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
200 }
bsalomon@google.com96966a52013-02-21 16:34:21 +0000201
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000202 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
203
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000204 if (kDesktop_GrGLBinding == binding) {
205 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
206 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
207 } else {
208 fVertexArrayObjectSupport = ctxInfo.hasExtension("GL_OES_vertex_array_object");
209 }
210
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000211 if (kES2_GrGLBinding == binding) {
212 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
213 fFBFetchType = kEXT_FBFetchType;
214 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
215 fFBFetchType = kNV_FBFetchType;
216 }
217 }
218
robertphillips@google.com6177e692013-02-28 20:16:25 +0000219 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000220 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000221
222 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000223 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000224 **************************************************************************/
225 GrGLint maxTextureUnits;
226 // check FS and fixed-function texture unit limits
227 // we only use textures in the fragment stage currently.
228 // checks are > to make sure we have a spare unit.
229 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000230
231 GrGLint numFormats;
232 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
bungeman@google.com71033442013-05-01 14:21:20 +0000233 if (numFormats) {
234 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
235 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
236 for (int i = 0; i < numFormats; ++i) {
237 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
238 f8BitPaletteSupport = true;
239 break;
240 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000241 }
242 }
243
244 if (kDesktop_GrGLBinding == binding) {
245 // we could also look for GL_ATI_separate_stencil extension or
246 // GL_EXT_stencil_two_side but they use different function signatures
247 // than GL2.0+ (and than each other).
248 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
249 // supported on GL 1.4 and higher or by extension
250 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
251 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
252 } else {
253 // ES 2 has two sided stencil and stencil wrap
254 fTwoSidedStencilSupport = true;
255 fStencilWrapOpsSupport = true;
256 }
257
258 if (kDesktop_GrGLBinding == binding) {
259 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
260 // glMapBuffer.
261 } else {
262 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
263 }
264
265 if (kDesktop_GrGLBinding == binding) {
266 if (ctxInfo.version() >= GR_GL_VER(2,0) ||
267 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
268 fNPOTTextureTileSupport = true;
269 } else {
270 fNPOTTextureTileSupport = false;
271 }
272 } else {
273 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
274 fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot");
275 }
276
277 fHWAALineSupport = (kDesktop_GrGLBinding == binding);
278
279 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
280 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
281 // Our render targets are always created with textures as the color
282 // attachment, hence this min:
283 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
284
285 fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
286 ctxInfo.hasExtension("GL_NV_path_rendering");
287
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000288 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
289
bsalomon@google.combcce8922013-03-25 15:38:39 +0000290 // Enable supported shader-related caps
291 if (kDesktop_GrGLBinding == binding) {
292 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
293 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
294 fShaderDerivativeSupport = true;
295 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
296 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
297 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
298 } else {
299 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
300 }
301
bsalomon@google.com347c3822013-05-01 20:10:01 +0000302 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000303 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
304 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
305 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
306 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000307}
308
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000309bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000310 GrGLenum format,
311 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000312 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
313 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000314 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000315 }
316
317 if (!fTwoFormatLimit) {
318 // not limited by ES 2's constraints
319 return true;
320 }
321
bsalomon@google.com548a4332012-07-11 19:45:22 +0000322 GrGLint otherFormat = GR_GL_RGBA;
323 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000324
325 // The other supported format/type combo supported for ReadPixels
326 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000327 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000328 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
329 &otherFormat);
330
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000331 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000332 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
333 &otherType);
334
bsalomon@google.com548a4332012-07-11 19:45:22 +0000335 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000336}
337
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000338namespace {
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000339bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left,
340 const GrGLCaps::MSAACoverageMode& right) {
341 if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) {
342 return true;
343 } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) {
344 return false;
345 } else if (left.fColorSampleCnt < right.fColorSampleCnt) {
346 return true;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000347 }
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000348 return false;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000349}
350}
351
robertphillips@google.com6177e692013-02-28 20:16:25 +0000352void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000353
354 fMSFBOType = kNone_MSFBOType;
355 if (kDesktop_GrGLBinding != ctxInfo.binding()) {
356 if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
357 // chrome's extension is equivalent to the EXT msaa
358 // and fbo_blit extensions.
bsalomon@google.com347c3822013-05-01 20:10:01 +0000359 fMSFBOType = kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000360 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000361 fMSFBOType = kES_Apple_MSFBOType;
362 } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
363 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
bsalomon@google.comf3a60c02013-03-19 19:06:09 +0000364 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000365 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000366 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000367 } else {
368 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
369 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000370 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000371 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
372 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000373 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000374 }
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000375 // TODO: We could populate fMSAACoverageModes using GetInternalformativ
376 // on GL 4.2+. It's format-specific, though. See also
377 // http://code.google.com/p/skia/issues/detail?id=470 about using actual
378 // rather than requested sample counts in cache key.
379 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
380 fCoverageAAType = kNVDesktop_CoverageAAType;
381 GrGLint count;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000382 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000383 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
384 &count);
385 fMSAACoverageModes.setCount(count);
robertphillips@google.com6177e692013-02-28 20:16:25 +0000386 GR_GL_GetIntegerv(gli,
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000387 GR_GL_MULTISAMPLE_COVERAGE_MODES,
388 (int*)&fMSAACoverageModes[0]);
389 // The NV driver seems to return the modes already sorted but the
390 // spec doesn't require this. So we sort.
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000391 typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_less> SortFunctor;
392 SortFunctor sortFunctor;
393 SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(),
394 fMSAACoverageModes.end() - 1,
395 sortFunctor);
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000396 }
397 }
398}
399
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000400const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000401 static const MSAACoverageMode kNoneMode = {0, 0};
402 if (0 == fMSAACoverageModes.count()) {
403 return kNoneMode;
404 } else {
405 GrAssert(kNone_CoverageAAType != fCoverageAAType);
406 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
407 desiredSampleCount = GrMin(desiredSampleCount, max);
408 MSAACoverageMode desiredMode = {desiredSampleCount, 0};
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000409 int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverageModes[0],
410 fMSAACoverageModes.count(),
411 desiredMode,
412 sizeof(MSAACoverageMode));
bsalomon@google.comc9668ec2012-04-11 18:16:41 +0000413 if (idx < 0) {
414 idx = ~idx;
415 }
416 GrAssert(idx >= 0 && idx < fMSAACoverageModes.count());
417 return fMSAACoverageModes[idx];
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000418 }
419}
420
421namespace {
422const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
423}
424
425void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
426
427 // Build up list of legal stencil formats (though perhaps not supported on
428 // the particular gpu/driver) from most preferred to least.
429
430 // these consts are in order of most preferred to least preferred
431 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
432
433 static const StencilFormat
434 // internal Format stencil bits total bits packed?
435 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
436 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
437 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
438 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000439 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000440 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
441
442 if (kDesktop_GrGLBinding == ctxInfo.binding()) {
443 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000444 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000445 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
446 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
447
448 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
449 // require FBO support we can expect these are legal formats and don't
450 // check. These also all support the unsized GL_STENCIL_INDEX.
451 fStencilFormats.push_back() = gS8;
452 fStencilFormats.push_back() = gS16;
453 if (supportsPackedDS) {
454 fStencilFormats.push_back() = gD24S8;
455 }
456 fStencilFormats.push_back() = gS4;
457 if (supportsPackedDS) {
458 fStencilFormats.push_back() = gDS;
459 }
460 } else {
461 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
462 // for other formats.
463 // ES doesn't support using the unsized format.
464
465 fStencilFormats.push_back() = gS8;
466 //fStencilFormats.push_back() = gS16;
467 if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
468 fStencilFormats.push_back() = gD24S8;
469 }
470 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
471 fStencilFormats.push_back() = gS4;
472 }
473 }
474 GrAssert(0 == fStencilVerifiedColorConfigs.count());
475 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
476}
477
478void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
479 GrPixelConfig config,
480 const GrGLStencilBuffer::Format& format) {
481#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
482 return;
483#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000484 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000485 GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
486 int count = fStencilFormats.count();
487 // we expect a really small number of possible formats so linear search
488 // should be OK
489 GrAssert(count < 16);
490 for (int i = 0; i < count; ++i) {
491 if (format.fInternalFormat ==
492 fStencilFormats[i].fInternalFormat) {
493 fStencilVerifiedColorConfigs[i].markVerified(config);
494 return;
495 }
496 }
497 GrCrash("Why are we seeing a stencil format that "
498 "GrGLCaps doesn't know about.");
499}
500
501bool GrGLCaps::isColorConfigAndStencilFormatVerified(
502 GrPixelConfig config,
503 const GrGLStencilBuffer::Format& format) const {
504#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
505 return false;
506#endif
bsalomon@google.comb6b72e52013-03-28 15:11:14 +0000507 GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000508 int count = fStencilFormats.count();
509 // we expect a really small number of possible formats so linear search
510 // should be OK
511 GrAssert(count < 16);
512 for (int i = 0; i < count; ++i) {
513 if (format.fInternalFormat ==
514 fStencilFormats[i].fInternalFormat) {
515 return fStencilVerifiedColorConfigs[i].isVerified(config);
516 }
517 }
518 GrCrash("Why are we seeing a stencil format that "
519 "GLCaps doesn't know about.");
520 return false;
521}
522
523void GrGLCaps::print() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000524
525 INHERITED::print();
526
527 GrPrintf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000528 for (int i = 0; i < fStencilFormats.count(); ++i) {
529 GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
530 i,
531 fStencilFormats[i].fStencilBits,
532 fStencilFormats[i].fTotalBits);
533 }
534
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000535 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000536 "None",
537 "ARB",
538 "EXT",
539 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000540 "IMG MS To Texture",
541 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000542 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000543 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
544 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
545 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
546 GR_STATIC_ASSERT(3 == kES_Apple_MSFBOType);
547 GR_STATIC_ASSERT(4 == kES_IMG_MsToTexture_MSFBOType);
548 GR_STATIC_ASSERT(5 == kES_EXT_MsToTexture_MSFBOType);
549 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
550
551 static const char* kFBFetchTypeStr[] = {
552 "None",
553 "EXT",
554 "NV",
555 };
556 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
557 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
558 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
559 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
560
561
562 GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
563 GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000564 GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000565 GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
566 GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
567 GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
568 GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
569 GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
570 GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
571 GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
572 GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
573 GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
574
575 GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
576 GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
577 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
578 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000579 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000580 GrPrintf("Fragment coord conventions support: %s\n",
581 (fFragCoordsConventionSupport ? "YES": "NO"));
582 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
583 GrPrintf("Use non-VBO for dynamic data: %s\n",
584 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
585 GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000586 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000587}