blob: 21d3d9374e297828f7fad0eda3d724056e79fd8b [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"
jvanverthcba99b82015-06-24 06:59:57 -070012#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000013#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000014#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000015
bsalomon682c2692015-05-22 14:01:46 -070016GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
17 const GrGLContextInfo& ctxInfo,
18 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000019 fVerifiedColorConfigs.reset();
20 fStencilFormats.reset();
21 fStencilVerifiedColorConfigs.reset();
22 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000023 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070024 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000025 fMapBufferType = kNone_MapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000027 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000028 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fBGRAIsInternalFormat = false;
31 fTextureSwizzleSupport = false;
32 fUnpackRowLengthSupport = false;
33 fUnpackFlipYSupport = false;
34 fPackRowLengthSupport = false;
35 fPackFlipYSupport = false;
36 fTextureUsageSupport = false;
37 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000038 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000039 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000040 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000041 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000042 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070043 fInstancedDrawingSupport = false;
44 fDirectStateAccessSupport = false;
45 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080046 fES2CompatibilitySupport = false;
cdalton0edea2c2015-05-21 08:27:44 -070047 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000048 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000049 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070050 fBindFragDataLocationSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070051 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070052 fRGBA8888PixelsOpsAreSlow = false;
53 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070054
55 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070056
jvanverthcba99b82015-06-24 06:59:57 -070057 fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions)));
bsalomon4ee6bd82015-05-27 13:23:23 -070058
cdalton4cd67132015-06-10 19:23:46 -070059 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000060}
61
cdalton4cd67132015-06-10 19:23:46 -070062void GrGLCaps::init(const GrContextOptions& contextOptions,
63 const GrGLContextInfo& ctxInfo,
64 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000065 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000066 GrGLVersion version = ctxInfo.version();
67
bsalomon@google.combcce8922013-03-25 15:38:39 +000068 /**************************************************************************
cdalton4cd67132015-06-10 19:23:46 -070069 * Caps specific to GrGLSLCaps
70 **************************************************************************/
71
72 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
73 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
74
75 if (kGLES_GrGLStandard == standard) {
76 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
77 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
78 glslCaps->fFBFetchSupport = true;
79 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
80 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
81 }
82 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
83 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
84 glslCaps->fFBFetchNeedsCustomOutput = false;
85 glslCaps->fFBFetchSupport = true;
86 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
87 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
88 }
89 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
90 // The arm extension also requires an additional flag which we will set onResetContext
91 glslCaps->fFBFetchNeedsCustomOutput = false;
92 glslCaps->fFBFetchSupport = true;
93 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
94 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
95 }
96 }
97
cdalton626e1ff2015-06-12 13:56:46 -070098 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
99
cdalton4cd67132015-06-10 19:23:46 -0700100 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
101 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
102
103 /**************************************************************************
bsalomon@google.combcce8922013-03-25 15:38:39 +0000104 * Caps specific to GrGLCaps
105 **************************************************************************/
106
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000107 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
109 &fMaxFragmentUniformVectors);
110 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000111 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112 GrGLint max;
113 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
114 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000115 if (version >= GR_GL_VER(3, 2)) {
116 GrGLint profileMask;
117 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
118 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
119 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000120 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000121 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000122 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000123
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000124 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000125 fRGBA8RenderbufferSupport = true;
126 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000127 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
128 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000129 ctxInfo.hasExtension("GL_ARM_rgba8");
130 }
131
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000132 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000133 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
134 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
135 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000136 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000137 }
138
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000139 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000140 fUnpackRowLengthSupport = true;
141 fUnpackFlipYSupport = false;
142 fPackRowLengthSupport = true;
143 fPackFlipYSupport = false;
144 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000145 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
146 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000147 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000148 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
149 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000150 fPackFlipYSupport =
151 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
152 }
153
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000154 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000155 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
156
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000157 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000158 // The EXT version can apply to either GL or GLES.
159 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
160 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
161 ctxInfo.hasExtension("GL_EXT_texture_storage");
162 } else {
163 // Qualcomm Adreno drivers appear to have issues with texture storage.
164 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
165 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
166 ctxInfo.hasExtension("GL_EXT_texture_storage");
167 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000168
cdaltonfd4167d2015-04-21 11:45:56 -0700169 if (kGL_GrGLStandard == standard) {
170 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
171 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
172 ctxInfo.hasExtension("GL_NV_texture_barrier");
173 } else {
174 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
175 }
176
hendrikwa0d5ad72014-12-02 07:30:30 -0800177 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
178 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700179 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800180 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000181 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
182 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800183 } else {
184 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
185 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000186 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000187 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000188 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000189 ctxInfo.hasExtension("GL_ARB_imaging");
190
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000191 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
192 // ReadPixels. The other format has to checked at run-time since it
193 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000194 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000195
bsalomon16921ec2015-07-30 15:34:56 -0700196 // We only enable srgb support if both textures and FBOs support srgb.
197 bool srgbSupport = false;
198 if (kGL_GrGLStandard == standard) {
199 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
200 srgbSupport = true;
201 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
202 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
203 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
204 srgbSupport = true;
205 }
206 }
207 // All the above srgb extensions support toggling srgb writes
208 fSRGBWriteControl = srgbSupport;
209 } else {
bsalomon58b43952015-07-30 16:27:50 -0700210 // See http://skbug.com/4148 for PowerVR issue.
211 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
212 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
bsalomon16921ec2015-07-30 15:34:56 -0700213 // ES through 3.1 requires EXT_srgb_write_control to support toggling
214 // sRGB writing for destinations.
215 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
216 }
217
rmistry63a9f842014-10-17 06:07:08 -0700218 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000219 // Known issue on at least some Intel platforms:
220 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700221 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000222 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
223 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
224 }
225
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000226 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
227 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
228 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
229 // limit this decision to specific GPU families rather than basing it on the vendor alone.
230 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700231 (kARM_GrGLVendor == ctxInfo.vendor() ||
232 kImagination_GrGLVendor == ctxInfo.vendor() ||
233 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000234 fUseNonVBOVertexAndIndexDynamicData = true;
235 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000236
egdaniel9250d242015-05-18 13:04:26 -0700237 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
238 // Thus we are blacklisting this extension for now on Adreno4xx devices.
239 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
240 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
241 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
242 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000243 fDiscardRenderTargetSupport = true;
244 fInvalidateFBType = kInvalidate_InvalidateFBType;
245 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
246 fDiscardRenderTargetSupport = true;
247 fInvalidateFBType = kDiscard_InvalidateFBType;
248 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000249
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000250 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
251 fFullClearIsFree = true;
252 }
253
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000254 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000255 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800256 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
257 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000258 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000259 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
260 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000261 }
262
cdalton626e1ff2015-06-12 13:56:46 -0700263 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
264 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
265 fInstancedDrawingSupport = true;
266 } else {
267 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
268 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
269 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
270 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
271 }
272
273 if (kGL_GrGLStandard == standard) {
274 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
275 } else {
276 fDirectStateAccessSupport = false;
277 }
278
279 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
280 fDebugSupport = true;
281 } else {
282 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
283 }
284
jvanverth3f801cb2014-12-16 09:49:38 -0800285 if (kGL_GrGLStandard == standard) {
286 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
287 }
288 else {
289 fES2CompatibilitySupport = true;
290 }
291
cdalton0edea2c2015-05-21 08:27:44 -0700292 if (kGL_GrGLStandard == standard) {
293 fMultisampleDisableSupport = true;
294 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700295 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700296 }
297
kkinnunend94708e2015-07-30 22:47:04 -0700298 if (kGL_GrGLStandard == standard) {
299 if (version >= GR_GL_VER(3, 0)) {
300 fBindFragDataLocationSupport = true;
301 }
302 } else {
303 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
304 fBindFragDataLocationSupport = true;
305 }
joshualittc1f56b52015-06-22 12:31:31 -0700306 }
307
bsalomon88c7b982015-07-31 11:20:16 -0700308#ifdef SK_BUILD_FOR_WIN
309 // We're assuming that on Windows Chromium we're using ANGLE.
310 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
311 kChromium_GrGLDriver == ctxInfo.driver();
312 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
313 fRGBA8888PixelsOpsAreSlow = isANGLE;
314 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
315 // check DX11 ANGLE.
316 fPartialFBOReadIsSlow = isANGLE;
317#endif
318
cdalton4cd67132015-06-10 19:23:46 -0700319 /**************************************************************************
320 * GrShaderCaps fields
321 **************************************************************************/
322
kkinnunencfe62e32015-07-01 02:58:50 -0700323 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
cdalton4cd67132015-06-10 19:23:46 -0700324
325 // For now these two are equivalent but we could have dst read in shader via some other method
326 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
327
328 // Enable supported shader-related caps
329 if (kGL_GrGLStandard == standard) {
330 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
331 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
332 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
333 glslCaps->fShaderDerivativeSupport = true;
334 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
335 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
336 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
337 }
338 else {
kkinnunend94708e2015-07-30 22:47:04 -0700339 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
340
cdalton4cd67132015-06-10 19:23:46 -0700341 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
342 ctxInfo.hasExtension("GL_OES_standard_derivatives");
343 }
344
345 // We need dual source blending and the ability to disable multisample in order to support mixed
346 // samples in every corner case.
347 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) {
348 // We understand "mixed samples" to mean the collective capability of 3 different extensions
349 glslCaps->fMixedSamplesSupport =
350 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
351 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
352 ctxInfo.hasExtension("GL_EXT_raster_multisample");
353 }
vbuzinovdded6962015-06-12 08:59:45 -0700354 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
355 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSupport()) {
356 fDiscardRenderTargetSupport = false;
357 fInvalidateFBType = kNone_InvalidateFBType;
358 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000359
360 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700361 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000362 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700363
364 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700365 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700366 this->initStencilFormats(ctxInfo);
367
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000368 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000369 // we could also look for GL_ATI_separate_stencil extension or
370 // GL_EXT_stencil_two_side but they use different function signatures
371 // than GL2.0+ (and than each other).
372 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
373 // supported on GL 1.4 and higher or by extension
374 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
375 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
376 } else {
377 // ES 2 has two sided stencil and stencil wrap
378 fTwoSidedStencilSupport = true;
379 fStencilWrapOpsSupport = true;
380 }
381
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000382 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000383 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
384 // extension includes glMapBuffer.
385 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
386 fMapBufferFlags |= kSubset_MapFlag;
387 fMapBufferType = kMapBufferRange_MapBufferType;
388 } else {
389 fMapBufferType = kMapBuffer_MapBufferType;
390 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000391 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000392 // Unextended GLES2 doesn't have any buffer mapping.
393 fMapBufferFlags = kNone_MapBufferType;
394 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
395 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
396 fMapBufferType = kChromium_MapBufferType;
397 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
398 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
399 fMapBufferType = kMapBufferRange_MapBufferType;
400 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
401 fMapBufferFlags = kCanMap_MapFlag;
402 fMapBufferType = kMapBuffer_MapBufferType;
403 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000404 }
405
joshualitte5b74c62015-06-01 14:17:47 -0700406 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
407 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
408 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700409 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
410 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
411 // a small subset.
412#if 0
cdalton1acea862015-06-02 13:05:52 -0700413 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700414#else
415 fGeometryBufferMapThreshold = SK_MaxS32;
416#endif
joshualitte5b74c62015-06-01 14:17:47 -0700417 }
418
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000419 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000420 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
421 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
422 fNPOTTextureTileSupport = true;
423 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000424 } else {
425 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000426 // ES3 has no limitations.
427 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
428 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000429 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
430 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
431 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
432 // to alllow arbitrary wrap modes, however.
433 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000434 }
435
bsalomon@google.combcce8922013-03-25 15:38:39 +0000436 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
437 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
438 // Our render targets are always created with textures as the color
439 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000440 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000441
bsalomonc59a1df2015-06-01 07:13:42 -0700442 // This GPU seems to have problems when tiling small textures
443 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
444 fMinTextureSize = 16;
445 }
446
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000447 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
448
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000449 // Disable scratch texture reuse on Mali and Adreno devices
450 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
451 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000452
robertphillips1b8e1b52015-06-24 06:54:10 -0700453#if 0
454 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
455 kQualcomm_GrGLVendor != ctxInfo.vendor();
456#endif
457
bsalomon@google.com347c3822013-05-01 20:10:01 +0000458 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000459 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
460 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
461 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
462 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000463
bsalomon63b21962014-11-05 07:05:34 -0800464 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800465 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800466 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800467 fUseDrawInsteadOfClear = true;
468 }
469
joshualitt83bc2292015-06-18 14:18:02 -0700470 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
471 fUseDrawInsteadOfPartialRenderTargetWrite = true;
472 }
473
bsalomon7dea7b72015-08-19 08:26:51 -0700474 if (kChromium_GrGLDriver == ctxInfo.driver()) {
475 fMustClearUploadedBufferData = true;
476 }
477
bsalomond08ea5f2015-02-20 06:58:13 -0800478 if (kGL_GrGLStandard == standard) {
479 // ARB allows mixed size FBO attachments, EXT does not.
480 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
481 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
482 fOversizedStencilSupport = true;
483 } else {
484 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
485 }
486 } else {
487 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
488 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
489 }
490
joshualitt58001552015-06-26 12:46:36 -0700491 if (kGL_GrGLStandard == standard) {
492 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
493 // instanced arrays, but we could make this more granular if we wanted
494 fSupportsInstancedDraws =
495 version >= GR_GL_VER(3, 2) ||
496 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
497 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
498 } else {
499 fSupportsInstancedDraws =
500 version >= GR_GL_VER(3, 0) ||
501 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
502 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
503 }
504
bsalomon16921ec2015-07-30 15:34:56 -0700505 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
506 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700507 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700508
509 this->applyOptionsOverrides(contextOptions);
510 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000511}
512
kkinnunencfe62e32015-07-01 02:58:50 -0700513bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700514 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
515
516 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700517 return false;
518 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700519
kkinnunencfe62e32015-07-01 02:58:50 -0700520 if (kGL_GrGLStandard == ctxInfo.standard()) {
521 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
522 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
523 return false;
524 }
525 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700526 if (!hasChromiumPathRendering &&
527 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700528 return false;
529 }
530 }
531 // We only support v1.3+ of GL_NV_path_rendering which allows us to
532 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
533 // additions are detected by checking the existence of the function.
534 // We also use *Then* functions that not all drivers might have. Check
535 // them for consistency.
536 if (NULL == gli->fFunctions.fStencilThenCoverFillPath ||
537 NULL == gli->fFunctions.fStencilThenCoverStrokePath ||
538 NULL == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
539 NULL == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
540 NULL == gli->fFunctions.fProgramPathFragmentInputGen) {
541 return false;
542 }
543 return true;
544}
545
bsalomon16921ec2015-07-30 15:34:56 -0700546void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000547 // OpenGL < 3.0
548 // no support for render targets unless the GL_ARB_framebuffer_object
549 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
550 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
551 // probably don't get R8 in this case.
552
553 // OpenGL 3.0
554 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
555 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
556
557 // >= OpenGL 3.1
558 // base color renderable: RED, RG, RGB, and RGBA
559 // sized derivatives: R8, RGBA4, RGBA8
560 // if the GL_ARB_compatibility extension is supported then we get back
561 // support for GL_ALPHA and ALPHA8
562
563 // GL_EXT_bgra adds BGRA render targets to any version
564
565 // ES 2.0
566 // color renderable: RGBA4, RGB5_A1, RGB565
567 // GL_EXT_texture_rg adds support for R8 as a color render target
568 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
569 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
570
571 // ES 3.0
572 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
573 // below already account for this).
574
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000575 GrGLStandard standard = ctxInfo.standard();
576
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000577 enum {
578 kNo_MSAA = 0,
579 kYes_MSAA = 1,
580 };
581
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000582 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000583 // Post 3.0 we will get R8
584 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
585 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
586 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000587 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
588 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000589 }
590 } else {
591 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000592 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
593 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000594 }
595
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000596 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000597 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000598 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
599 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000600 }
601
602 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000603 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
604 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000605
606 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000607 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000608 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000609 }
610
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000611 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000612 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
613 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
614 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000615 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000616 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000617 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
618 } else {
619 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
620 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
621 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000622 }
623
bsalomon16921ec2015-07-30 15:34:56 -0700624 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
625 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
626 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
jvanverthfa1e8a72014-12-22 08:31:49 -0800627 }
628
joshualittee5da552014-07-16 13:32:56 -0700629 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800630 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800631 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800632 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
633 } else {
joshualitt55999962015-06-18 13:47:10 -0700634 // for now we only enable this on desktop, because on ES we'd have to solve many
635 // precision issues and no clients actually want this yet
636 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800637 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
638 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
639 } else {
640 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
641 }
642 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700643 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
644 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700645 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800646 }
joshualittee5da552014-07-16 13:32:56 -0700647 }
648
jvanverth28f9c602014-12-05 13:06:35 -0800649 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800650 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800651 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800652 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800653 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
654 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
655 // for now we don't support floating point MSAA on ES
656 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800657 } else {
jvanverth1334c212014-12-18 05:44:55 -0800658 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
659 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
660 } else {
661 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
662 }
663 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800664 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
665 }
666 }
667
jvanverthfb5df432015-05-21 08:12:27 -0700668 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
669 if (kGL_GrGLStandard == standard) {
670 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
671 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
672 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
673 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
674 // for now we don't support floating point MSAA on ES
675 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
676 } else {
677 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
678 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
679 } else {
680 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
681 }
682 // for now we don't support floating point MSAA on ES
683 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
684 }
685 }
686
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000687 // If we don't support MSAA then undo any places above where we set a config as renderable with
688 // msaa.
689 if (kNone_MSFBOType == fMSFBOType) {
690 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
691 fConfigRenderSupport[i][kYes_MSAA] = false;
692 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000693 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000694}
695
bsalomon16921ec2015-07-30 15:34:56 -0700696void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
697 bool srgbSupport) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000698 GrGLStandard standard = ctxInfo.standard();
699 GrGLVersion version = ctxInfo.version();
700
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000701 // Base texture support
702 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
703 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
704 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
705 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
706
707 // Check for 8-bit palette..
708 GrGLint numFormats;
709 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
710 if (numFormats) {
711 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
712 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
713 for (int i = 0; i < numFormats; ++i) {
714 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
715 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
716 break;
717 }
718 }
719 }
720
721 // Check for BGRA
722 if (kGL_GrGLStandard == standard) {
723 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
724 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
725 } else {
726 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
727 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
728 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
729 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
730 fBGRAIsInternalFormat = true;
731 }
732 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
733 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
734 }
735
bsalomon16921ec2015-07-30 15:34:56 -0700736 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
jvanverthfa1e8a72014-12-22 08:31:49 -0800737
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000738 // Compressed texture support
739
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000740 // glCompressedTexImage2D is available on all OpenGL ES devices...
741 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000742 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000743
krajcevski786978162014-07-30 11:25:44 -0700744 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700745 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700746
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000747 // Check for ETC1
748 bool hasETC1 = false;
749
750 // First check version for support
751 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000752 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700753 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000754 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000755 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000756 hasETC1 = hasCompressTex2D &&
757 (version >= GR_GL_VER(3, 0) ||
758 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
759 // ETC2 is a superset of ETC1, so we can just check for that, too.
760 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
761 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000762 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000763 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000764
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000765 // Check for LATC under its various forms
766 LATCAlias alias = kLATC_LATCAlias;
767 bool hasLATC = hasCompressTex2D &&
768 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
769 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
770
771 // Check for RGTC
772 if (!hasLATC) {
773 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
774 if (kGL_GrGLStandard == standard) {
775 hasLATC = version >= GR_GL_VER(3, 0);
776 }
777
778 if (!hasLATC) {
779 hasLATC =
780 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
781 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
782 }
783
784 if (hasLATC) {
785 alias = kRGTC_LATCAlias;
786 }
787 }
788
789 // Check for 3DC
790 if (!hasLATC) {
791 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
792 if (hasLATC) {
793 alias = k3DC_LATCAlias;
794 }
795 }
796
797 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
798 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700799
krajcevskib3abe902014-07-30 13:08:11 -0700800 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
801 // cards default to decompressing the textures in the driver, and is
802 // generally slower.
803 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700804 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
805 }
joshualittee5da552014-07-16 13:32:56 -0700806
krajcevski7ef21622014-07-16 15:21:13 -0700807 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700808 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700809 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
810 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
811 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
812
joshualittee5da552014-07-16 13:32:56 -0700813 // Check for floating point texture support
814 // NOTE: We disallow floating point textures on ES devices if linear
815 // filtering modes are not supported. This is for simplicity, but a more
816 // granular approach is possible. Coincidentally, floating point textures became part of
817 // the standard in ES3.1 / OGL 3.1, hence the shorthand
818 bool hasFPTextures = version >= GR_GL_VER(3, 1);
819 if (!hasFPTextures) {
820 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800821 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700822 ctxInfo.hasExtension("GL_OES_texture_float"));
823 }
824 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800825
826 // Check for fp16 texture support
827 // NOTE: We disallow floating point textures on ES devices if linear
828 // filtering modes are not supported. This is for simplicity, but a more
829 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
830 // the standard in ES3.1 / OGL 3.1, hence the shorthand
831 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
832 if (!hasHalfFPTextures) {
833 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800834 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
835 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800836 }
jvanverth1334c212014-12-18 05:44:55 -0800837 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700838 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000839}
840
piotaixre4b23142014-10-02 10:57:53 -0700841bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
842 GrGLenum format,
843 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000844 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
845 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000846 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000847 }
848
849 if (!fTwoFormatLimit) {
850 // not limited by ES 2's constraints
851 return true;
852 }
853
bsalomon@google.com548a4332012-07-11 19:45:22 +0000854 GrGLint otherFormat = GR_GL_RGBA;
855 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000856
857 // The other supported format/type combo supported for ReadPixels
858 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000859 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000860 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
861 &otherFormat);
862
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000863 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000864 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
865 &otherType);
866
bsalomon@google.com548a4332012-07-11 19:45:22 +0000867 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000868}
869
piotaixre4b23142014-10-02 10:57:53 -0700870bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
871 GrGLenum format,
872 GrGLenum type,
873 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800874 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
875 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
876 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700877 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800878 bool supported = this->doReadPixelsSupported(intf, format, type);
879 fReadPixelsSupportedCache.set(key, supported);
880 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700881}
882
robertphillips@google.com6177e692013-02-28 20:16:25 +0000883void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000884
885 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000886 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000887 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
888 // ES3 driver bugs on at least one device with a tiled GPU (N10).
889 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
890 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
891 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
892 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
vbuzinovdded6962015-06-12 08:59:45 -0700893 } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
894 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000895 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000896 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
897 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
898 // chrome's extension is equivalent to the EXT msaa
899 // and fbo_blit extensions.
900 fMSFBOType = kDesktop_EXT_MSFBOType;
901 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
902 fMSFBOType = kES_Apple_MSFBOType;
903 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000904 } else {
vbuzinovdded6962015-06-12 08:59:45 -0700905 if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
906 fMSFBOType = kMixedSamples_MSFBOType;
907 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000908 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000909 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000910 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
911 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000912 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000913 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000914 }
915}
916
cdalton1dd05422015-06-12 09:01:18 -0700917void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
918 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
919
920 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
921 // for now until its own blacklists can be updated.
922 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
923 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700924 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700925 return;
926 }
927
928 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
929 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
930 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
931 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
932 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
933 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
934 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
935 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
936 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
937 return;
938 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
939 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
940 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
941 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
942 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
943 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
944 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
945 // slow on a particular platform.
946 } else {
947 return; // No advanced blend support.
948 }
949
950 SkASSERT(this->advancedBlendEquationSupport());
951
952 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
953 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
954 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
955 (1 << kColorBurn_GrBlendEquation);
956 }
joel.liang9764c402015-07-09 19:46:18 -0700957 if (kARM_GrGLVendor == ctxInfo.vendor()) {
958 // Blacklist color-burn on ARM until the fix is released.
959 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
960 }
cdalton1dd05422015-06-12 09:01:18 -0700961}
962
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000963namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700964const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000965}
966
967void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
968
969 // Build up list of legal stencil formats (though perhaps not supported on
970 // the particular gpu/driver) from most preferred to least.
971
972 // these consts are in order of most preferred to least preferred
973 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
974
975 static const StencilFormat
976 // internal Format stencil bits total bits packed?
977 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
978 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
979 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
980 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000981 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000982 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
983
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000984 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000985 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000986 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000987 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
988 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
989
990 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
991 // require FBO support we can expect these are legal formats and don't
992 // check. These also all support the unsized GL_STENCIL_INDEX.
993 fStencilFormats.push_back() = gS8;
994 fStencilFormats.push_back() = gS16;
995 if (supportsPackedDS) {
996 fStencilFormats.push_back() = gD24S8;
997 }
998 fStencilFormats.push_back() = gS4;
999 if (supportsPackedDS) {
1000 fStencilFormats.push_back() = gDS;
1001 }
1002 } else {
1003 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1004 // for other formats.
1005 // ES doesn't support using the unsized format.
1006
1007 fStencilFormats.push_back() = gS8;
1008 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001009 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1010 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001011 fStencilFormats.push_back() = gD24S8;
1012 }
1013 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1014 fStencilFormats.push_back() = gS4;
1015 }
1016 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001017 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001018 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
1019}
1020
1021void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
1022 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -07001023 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001024#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
1025 return;
1026#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001027 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
1028 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001029 int count = fStencilFormats.count();
1030 // we expect a really small number of possible formats so linear search
1031 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001032 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001033 for (int i = 0; i < count; ++i) {
1034 if (format.fInternalFormat ==
1035 fStencilFormats[i].fInternalFormat) {
1036 fStencilVerifiedColorConfigs[i].markVerified(config);
1037 return;
1038 }
1039 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001040 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001041 "GrGLCaps doesn't know about.");
1042}
1043
1044bool GrGLCaps::isColorConfigAndStencilFormatVerified(
1045 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -07001046 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001047#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
1048 return false;
1049#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001050 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001051 int count = fStencilFormats.count();
1052 // we expect a really small number of possible formats so linear search
1053 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001054 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001055 for (int i = 0; i < count; ++i) {
1056 if (format.fInternalFormat ==
1057 fStencilFormats[i].fInternalFormat) {
1058 return fStencilVerifiedColorConfigs[i].isVerified(config);
1059 }
1060 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001061 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001062 "GLCaps doesn't know about.");
1063 return false;
1064}
1065
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001066SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001067
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001068 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001069
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001070 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001071 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001072 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001073 i,
1074 fStencilFormats[i].fStencilBits,
1075 fStencilFormats[i].fTotalBits);
1076 }
1077
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001078 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001079 "None",
1080 "ARB",
1081 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001082 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001083 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001084 "IMG MS To Texture",
1085 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001086 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001087 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001088 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1089 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1090 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001091 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1092 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1093 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1094 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001095 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001096 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001097
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001098 static const char* kInvalidateFBTypeStr[] = {
1099 "None",
1100 "Discard",
1101 "Invalidate",
1102 };
1103 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1104 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1105 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1106 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001107
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001108 static const char* kMapBufferTypeStr[] = {
1109 "None",
1110 "MapBuffer",
1111 "MapBufferRange",
1112 "Chromium",
1113 };
1114 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1115 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1116 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1117 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1118 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1119
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001120 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001121 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001122 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001123 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001124 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1125 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001126 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1127 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001128 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
1129 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
1130 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1131 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1132 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1133 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001134
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001135 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1136 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1137 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1138 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1139 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1140 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001141 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001142 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001143 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1144 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1145 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -07001146 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001147 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001148 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001149 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
bsalomon88c7b982015-07-31 11:20:16 -07001150 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow? "YES" : "NO"));
1151 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001152 return r;
1153}
1154
jvanverthe9c0fc62015-04-29 11:18:05 -07001155static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1156 switch (p) {
1157 case kLow_GrSLPrecision:
1158 return GR_GL_LOW_FLOAT;
1159 case kMedium_GrSLPrecision:
1160 return GR_GL_MEDIUM_FLOAT;
1161 case kHigh_GrSLPrecision:
1162 return GR_GL_HIGH_FLOAT;
1163 }
1164 SkFAIL("Unknown precision.");
1165 return -1;
1166}
1167
1168static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1169 switch (type) {
1170 case kVertex_GrShaderType:
1171 return GR_GL_VERTEX_SHADER;
1172 case kGeometry_GrShaderType:
1173 return GR_GL_GEOMETRY_SHADER;
1174 case kFragment_GrShaderType:
1175 return GR_GL_FRAGMENT_SHADER;
1176 }
1177 SkFAIL("Unknown shader type.");
1178 return -1;
1179}
1180
jvanverthcba99b82015-06-24 06:59:57 -07001181void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1182 const GrGLInterface* intf,
1183 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001184 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1185 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1186 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1187 if (kGeometry_GrShaderType != s) {
1188 GrShaderType shaderType = static_cast<GrShaderType>(s);
1189 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
jvanverthcba99b82015-06-24 06:59:57 -07001190 GrShaderCaps::PrecisionInfo* first = NULL;
1191 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001192 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1193 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1194 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1195 GrGLint range[2];
1196 GrGLint bits;
1197 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1198 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001199 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1200 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1201 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001202 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001203 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001204 }
jvanverthcba99b82015-06-24 06:59:57 -07001205 else if (!glslCaps->fShaderPrecisionVaries) {
1206 glslCaps->fShaderPrecisionVaries =
1207 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001208 }
1209 }
1210 }
1211 }
1212 }
1213 }
1214 else {
1215 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001216 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001217 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1218 if (kGeometry_GrShaderType != s) {
1219 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001220 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1221 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1222 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001223 }
1224 }
1225 }
1226 }
1227 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1228 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1229 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1230 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001231 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001232 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001233 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1234 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001235 }
1236 }
1237}
1238
1239
1240
1241