blob: c9703b16f83b442dc1c10ebf0edba2a3a2970669 [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();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000021 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000022 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070023 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000024 fMapBufferType = kNone_MapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000025 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000026 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000027 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fBGRAIsInternalFormat = false;
30 fTextureSwizzleSupport = false;
31 fUnpackRowLengthSupport = false;
32 fUnpackFlipYSupport = false;
33 fPackRowLengthSupport = false;
34 fPackFlipYSupport = false;
35 fTextureUsageSupport = false;
36 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000037 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000039 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000040 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000041 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070042 fInstancedDrawingSupport = false;
43 fDirectStateAccessSupport = false;
44 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080045 fES2CompatibilitySupport = false;
cdalton0edea2c2015-05-21 08:27:44 -070046 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000047 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000048 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070049 fBindFragDataLocationSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070050 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070051 fRGBA8888PixelsOpsAreSlow = false;
52 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070053
54 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070055
halcanary385fe4d2015-08-26 13:07:48 -070056 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070057
cdalton4cd67132015-06-10 19:23:46 -070058 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059}
60
cdalton4cd67132015-06-10 19:23:46 -070061void GrGLCaps::init(const GrContextOptions& contextOptions,
62 const GrGLContextInfo& ctxInfo,
63 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000064 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000065 GrGLVersion version = ctxInfo.version();
66
bsalomon@google.combcce8922013-03-25 15:38:39 +000067 /**************************************************************************
cdalton4cd67132015-06-10 19:23:46 -070068 * Caps specific to GrGLSLCaps
69 **************************************************************************/
70
71 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
72 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
73
74 if (kGLES_GrGLStandard == standard) {
75 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
76 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
77 glslCaps->fFBFetchSupport = true;
78 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
79 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
80 }
81 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
82 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
83 glslCaps->fFBFetchNeedsCustomOutput = false;
84 glslCaps->fFBFetchSupport = true;
85 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
86 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
87 }
88 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
89 // The arm extension also requires an additional flag which we will set onResetContext
90 glslCaps->fFBFetchNeedsCustomOutput = false;
91 glslCaps->fFBFetchSupport = true;
92 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
93 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
94 }
95 }
96
cdalton626e1ff2015-06-12 13:56:46 -070097 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
98
cdalton4cd67132015-06-10 19:23:46 -070099 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
100 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
101
102 /**************************************************************************
bsalomon@google.combcce8922013-03-25 15:38:39 +0000103 * Caps specific to GrGLCaps
104 **************************************************************************/
105
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000106 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
108 &fMaxFragmentUniformVectors);
109 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000110 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 GrGLint max;
112 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
113 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000114 if (version >= GR_GL_VER(3, 2)) {
115 GrGLint profileMask;
116 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
117 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
118 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000119 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000120 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000121 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000122
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000123 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124 fRGBA8RenderbufferSupport = true;
125 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000126 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
127 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000128 ctxInfo.hasExtension("GL_ARM_rgba8");
129 }
130
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000131 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000132 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
133 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
134 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000135 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000136 }
137
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000138 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000139 fUnpackRowLengthSupport = true;
140 fUnpackFlipYSupport = false;
141 fPackRowLengthSupport = true;
142 fPackFlipYSupport = false;
143 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000144 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
145 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000146 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000147 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
148 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000149 fPackFlipYSupport =
150 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
151 }
152
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000153 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000154 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
155
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000156 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000157 // The EXT version can apply to either GL or GLES.
158 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
159 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
160 ctxInfo.hasExtension("GL_EXT_texture_storage");
161 } else {
162 // Qualcomm Adreno drivers appear to have issues with texture storage.
163 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
164 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
165 ctxInfo.hasExtension("GL_EXT_texture_storage");
166 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000167
cdaltonfd4167d2015-04-21 11:45:56 -0700168 if (kGL_GrGLStandard == standard) {
169 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
170 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
171 ctxInfo.hasExtension("GL_NV_texture_barrier");
172 } else {
173 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
174 }
175
hendrikwa0d5ad72014-12-02 07:30:30 -0800176 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
177 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700178 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800179 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000180 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
181 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800182 } else {
183 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
184 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000185 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000186 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000187 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000188 ctxInfo.hasExtension("GL_ARB_imaging");
189
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000190 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
191 // ReadPixels. The other format has to checked at run-time since it
192 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000193 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000194
bsalomon16921ec2015-07-30 15:34:56 -0700195 // We only enable srgb support if both textures and FBOs support srgb.
196 bool srgbSupport = false;
197 if (kGL_GrGLStandard == standard) {
198 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
199 srgbSupport = true;
200 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
201 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
202 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
203 srgbSupport = true;
204 }
205 }
206 // All the above srgb extensions support toggling srgb writes
207 fSRGBWriteControl = srgbSupport;
208 } else {
bsalomon58b43952015-07-30 16:27:50 -0700209 // See http://skbug.com/4148 for PowerVR issue.
210 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
211 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
bsalomon16921ec2015-07-30 15:34:56 -0700212 // ES through 3.1 requires EXT_srgb_write_control to support toggling
213 // sRGB writing for destinations.
214 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
215 }
216
rmistry63a9f842014-10-17 06:07:08 -0700217 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000218 // Known issue on at least some Intel platforms:
219 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700220 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000221 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
222 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
223 }
224
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000225 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
226 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
227 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
228 // limit this decision to specific GPU families rather than basing it on the vendor alone.
229 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700230 (kARM_GrGLVendor == ctxInfo.vendor() ||
231 kImagination_GrGLVendor == ctxInfo.vendor() ||
232 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000233 fUseNonVBOVertexAndIndexDynamicData = true;
234 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000235
egdaniel9250d242015-05-18 13:04:26 -0700236 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
237 // Thus we are blacklisting this extension for now on Adreno4xx devices.
238 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
239 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
240 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
241 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000242 fDiscardRenderTargetSupport = true;
243 fInvalidateFBType = kInvalidate_InvalidateFBType;
244 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
245 fDiscardRenderTargetSupport = true;
246 fInvalidateFBType = kDiscard_InvalidateFBType;
247 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000248
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000249 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
250 fFullClearIsFree = true;
251 }
252
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000253 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000254 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800255 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
256 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000257 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000258 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
259 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000260 }
261
cdalton626e1ff2015-06-12 13:56:46 -0700262 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
263 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
264 fInstancedDrawingSupport = true;
265 } else {
266 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
267 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
268 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
269 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
270 }
271
272 if (kGL_GrGLStandard == standard) {
273 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
274 } else {
275 fDirectStateAccessSupport = false;
276 }
277
278 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
279 fDebugSupport = true;
280 } else {
281 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
282 }
283
jvanverth3f801cb2014-12-16 09:49:38 -0800284 if (kGL_GrGLStandard == standard) {
285 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
286 }
287 else {
288 fES2CompatibilitySupport = true;
289 }
290
cdalton0edea2c2015-05-21 08:27:44 -0700291 if (kGL_GrGLStandard == standard) {
292 fMultisampleDisableSupport = true;
293 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700294 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700295 }
296
kkinnunend94708e2015-07-30 22:47:04 -0700297 if (kGL_GrGLStandard == standard) {
298 if (version >= GR_GL_VER(3, 0)) {
299 fBindFragDataLocationSupport = true;
300 }
301 } else {
302 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
303 fBindFragDataLocationSupport = true;
304 }
joshualittc1f56b52015-06-22 12:31:31 -0700305 }
306
joshualitt7bdd70a2015-10-01 06:28:11 -0700307 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
308
bsalomon88c7b982015-07-31 11:20:16 -0700309#ifdef SK_BUILD_FOR_WIN
310 // We're assuming that on Windows Chromium we're using ANGLE.
311 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
312 kChromium_GrGLDriver == ctxInfo.driver();
313 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
314 fRGBA8888PixelsOpsAreSlow = isANGLE;
315 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
316 // check DX11 ANGLE.
317 fPartialFBOReadIsSlow = isANGLE;
318#endif
319
cdalton4cd67132015-06-10 19:23:46 -0700320 /**************************************************************************
321 * GrShaderCaps fields
322 **************************************************************************/
323
kkinnunencfe62e32015-07-01 02:58:50 -0700324 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
cdalton4cd67132015-06-10 19:23:46 -0700325
326 // For now these two are equivalent but we could have dst read in shader via some other method
327 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
328
329 // Enable supported shader-related caps
330 if (kGL_GrGLStandard == standard) {
331 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
332 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
333 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
334 glslCaps->fShaderDerivativeSupport = true;
335 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
336 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
337 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
338 }
339 else {
kkinnunend94708e2015-07-30 22:47:04 -0700340 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
341
cdalton4cd67132015-06-10 19:23:46 -0700342 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
343 ctxInfo.hasExtension("GL_OES_standard_derivatives");
344 }
345
346 // We need dual source blending and the ability to disable multisample in order to support mixed
347 // samples in every corner case.
348 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) {
349 // We understand "mixed samples" to mean the collective capability of 3 different extensions
350 glslCaps->fMixedSamplesSupport =
351 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
352 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
353 ctxInfo.hasExtension("GL_EXT_raster_multisample");
354 }
vbuzinovdded6962015-06-12 08:59:45 -0700355 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
356 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSupport()) {
357 fDiscardRenderTargetSupport = false;
358 fInvalidateFBType = kNone_InvalidateFBType;
359 }
vbuzinov3e77ba92015-09-30 23:02:06 -0700360 glslCaps->fProgrammableSampleLocationsSupport =
361 ctxInfo.hasExtension("GL_NV_sample_locations") ||
362 ctxInfo.hasExtension("GL_ARB_sample_locations");
363
bsalomon@google.combcce8922013-03-25 15:38:39 +0000364
365 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700366 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000367 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700368
369 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700370 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700371 this->initStencilFormats(ctxInfo);
372
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000373 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000374 // we could also look for GL_ATI_separate_stencil extension or
375 // GL_EXT_stencil_two_side but they use different function signatures
376 // than GL2.0+ (and than each other).
377 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
378 // supported on GL 1.4 and higher or by extension
379 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
380 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
381 } else {
382 // ES 2 has two sided stencil and stencil wrap
383 fTwoSidedStencilSupport = true;
384 fStencilWrapOpsSupport = true;
385 }
386
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000387 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000388 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
389 // extension includes glMapBuffer.
390 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
391 fMapBufferFlags |= kSubset_MapFlag;
392 fMapBufferType = kMapBufferRange_MapBufferType;
393 } else {
394 fMapBufferType = kMapBuffer_MapBufferType;
395 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000396 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000397 // Unextended GLES2 doesn't have any buffer mapping.
398 fMapBufferFlags = kNone_MapBufferType;
399 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
400 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
401 fMapBufferType = kChromium_MapBufferType;
402 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
403 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
404 fMapBufferType = kMapBufferRange_MapBufferType;
405 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
406 fMapBufferFlags = kCanMap_MapFlag;
407 fMapBufferType = kMapBuffer_MapBufferType;
408 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000409 }
410
joshualitte5b74c62015-06-01 14:17:47 -0700411 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
412 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
413 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700414 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
415 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
416 // a small subset.
417#if 0
cdalton1acea862015-06-02 13:05:52 -0700418 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700419#else
420 fGeometryBufferMapThreshold = SK_MaxS32;
421#endif
joshualitte5b74c62015-06-01 14:17:47 -0700422 }
423
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000424 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000425 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
426 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
427 fNPOTTextureTileSupport = true;
428 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000429 } else {
430 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000431 // ES3 has no limitations.
432 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
433 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000434 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
435 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
436 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
437 // to alllow arbitrary wrap modes, however.
438 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000439 }
440
bsalomon@google.combcce8922013-03-25 15:38:39 +0000441 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
442 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
443 // Our render targets are always created with textures as the color
444 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000445 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000446
bsalomonc59a1df2015-06-01 07:13:42 -0700447 // This GPU seems to have problems when tiling small textures
448 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
449 fMinTextureSize = 16;
450 }
451
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000452 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
453
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000454 // Disable scratch texture reuse on Mali and Adreno devices
455 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
456 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000457
robertphillips1b8e1b52015-06-24 06:54:10 -0700458#if 0
459 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
460 kQualcomm_GrGLVendor != ctxInfo.vendor();
461#endif
462
bsalomon@google.com347c3822013-05-01 20:10:01 +0000463 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000464 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
465 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
466 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
467 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000468
bsalomon63b21962014-11-05 07:05:34 -0800469 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800470 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800471 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800472 fUseDrawInsteadOfClear = true;
473 }
474
joshualitt83bc2292015-06-18 14:18:02 -0700475 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
476 fUseDrawInsteadOfPartialRenderTargetWrite = true;
477 }
478
robertphillips63926682015-08-20 09:39:02 -0700479#ifdef SK_BUILD_FOR_WIN
480 // On ANGLE deferring flushes can lead to GPU starvation
481 fPreferVRAMUseOverFlushes = !isANGLE;
482#endif
483
bsalomon7dea7b72015-08-19 08:26:51 -0700484 if (kChromium_GrGLDriver == ctxInfo.driver()) {
485 fMustClearUploadedBufferData = true;
486 }
487
bsalomond08ea5f2015-02-20 06:58:13 -0800488 if (kGL_GrGLStandard == standard) {
489 // ARB allows mixed size FBO attachments, EXT does not.
490 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
491 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
492 fOversizedStencilSupport = true;
493 } else {
494 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
495 }
496 } else {
497 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
498 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
499 }
500
joshualitt58001552015-06-26 12:46:36 -0700501 if (kGL_GrGLStandard == standard) {
502 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
503 // instanced arrays, but we could make this more granular if we wanted
504 fSupportsInstancedDraws =
505 version >= GR_GL_VER(3, 2) ||
506 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
507 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
508 } else {
509 fSupportsInstancedDraws =
510 version >= GR_GL_VER(3, 0) ||
511 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
512 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
513 }
514
bsalomon16921ec2015-07-30 15:34:56 -0700515 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
516 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700517 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700518
519 this->applyOptionsOverrides(contextOptions);
520 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000521}
522
kkinnunencfe62e32015-07-01 02:58:50 -0700523bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700524 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
525
526 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700527 return false;
528 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700529
kkinnunencfe62e32015-07-01 02:58:50 -0700530 if (kGL_GrGLStandard == ctxInfo.standard()) {
531 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
532 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
533 return false;
534 }
535 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700536 if (!hasChromiumPathRendering &&
537 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700538 return false;
539 }
540 }
541 // We only support v1.3+ of GL_NV_path_rendering which allows us to
542 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
543 // additions are detected by checking the existence of the function.
544 // We also use *Then* functions that not all drivers might have. Check
545 // them for consistency.
halcanary96fcdcc2015-08-27 07:41:13 -0700546 if (nullptr == gli->fFunctions.fStencilThenCoverFillPath ||
547 nullptr == gli->fFunctions.fStencilThenCoverStrokePath ||
548 nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
549 nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
550 nullptr == gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700551 return false;
552 }
553 return true;
554}
555
bsalomon16921ec2015-07-30 15:34:56 -0700556void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000557 // OpenGL < 3.0
558 // no support for render targets unless the GL_ARB_framebuffer_object
559 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
560 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
561 // probably don't get R8 in this case.
562
563 // OpenGL 3.0
564 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
565 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
566
567 // >= OpenGL 3.1
568 // base color renderable: RED, RG, RGB, and RGBA
569 // sized derivatives: R8, RGBA4, RGBA8
570 // if the GL_ARB_compatibility extension is supported then we get back
571 // support for GL_ALPHA and ALPHA8
572
573 // GL_EXT_bgra adds BGRA render targets to any version
574
575 // ES 2.0
576 // color renderable: RGBA4, RGB5_A1, RGB565
577 // GL_EXT_texture_rg adds support for R8 as a color render target
578 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
579 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
580
581 // ES 3.0
582 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
583 // below already account for this).
584
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000585 GrGLStandard standard = ctxInfo.standard();
586
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000587 enum {
588 kNo_MSAA = 0,
589 kYes_MSAA = 1,
590 };
591
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000592 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000593 // Post 3.0 we will get R8
594 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
595 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
596 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000597 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
598 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000599 }
600 } else {
601 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000602 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
603 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000604 }
605
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000606 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000607 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000608 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
609 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000610 }
611
612 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000613 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
614 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000615
616 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000617 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000618 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000619 }
620
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000621 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000622 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
623 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
624 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000625 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000626 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000627 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
628 } else {
629 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
630 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
631 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000632 }
633
bsalomon16921ec2015-07-30 15:34:56 -0700634 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
635 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
636 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
jvanverthfa1e8a72014-12-22 08:31:49 -0800637 }
638
joshualittee5da552014-07-16 13:32:56 -0700639 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800640 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800641 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800642 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
643 } else {
joshualitt55999962015-06-18 13:47:10 -0700644 // for now we only enable this on desktop, because on ES we'd have to solve many
645 // precision issues and no clients actually want this yet
646 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800647 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
648 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
649 } else {
650 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
651 }
652 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700653 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
654 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700655 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800656 }
joshualittee5da552014-07-16 13:32:56 -0700657 }
658
jvanverth28f9c602014-12-05 13:06:35 -0800659 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800660 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800661 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800662 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800663 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
664 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
665 // for now we don't support floating point MSAA on ES
666 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800667 } else {
jvanverth1334c212014-12-18 05:44:55 -0800668 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
669 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
670 } else {
671 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
672 }
673 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800674 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
675 }
676 }
677
jvanverthfb5df432015-05-21 08:12:27 -0700678 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
679 if (kGL_GrGLStandard == standard) {
680 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
681 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
682 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
683 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
684 // for now we don't support floating point MSAA on ES
685 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
686 } else {
687 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
688 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
689 } else {
690 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
691 }
692 // for now we don't support floating point MSAA on ES
693 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
694 }
695 }
696
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000697 // If we don't support MSAA then undo any places above where we set a config as renderable with
698 // msaa.
699 if (kNone_MSFBOType == fMSFBOType) {
700 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
701 fConfigRenderSupport[i][kYes_MSAA] = false;
702 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000703 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000704}
705
bsalomon16921ec2015-07-30 15:34:56 -0700706void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
707 bool srgbSupport) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000708 GrGLStandard standard = ctxInfo.standard();
709 GrGLVersion version = ctxInfo.version();
710
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000711 // Base texture support
712 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
713 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
714 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
715 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
716
reed56f38fb2015-09-14 09:09:00 -0700717 // Disable this for now, while we investigate skbug.com/4333
718 if (false) {
719 // Check for 8-bit palette..
720 GrGLint numFormats;
721 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
722 if (numFormats) {
723 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
724 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
725 for (int i = 0; i < numFormats; ++i) {
726 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
727 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
728 break;
729 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000730 }
731 }
732 }
733
734 // Check for BGRA
735 if (kGL_GrGLStandard == standard) {
736 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
737 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
738 } else {
739 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
740 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
741 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
742 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
743 fBGRAIsInternalFormat = true;
744 }
745 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
746 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
747 }
748
bsalomon16921ec2015-07-30 15:34:56 -0700749 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
jvanverthfa1e8a72014-12-22 08:31:49 -0800750
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000751 // Compressed texture support
752
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000753 // glCompressedTexImage2D is available on all OpenGL ES devices...
754 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000755 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000756
krajcevski786978162014-07-30 11:25:44 -0700757 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700758 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700759
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000760 // Check for ETC1
761 bool hasETC1 = false;
762
763 // First check version for support
764 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000765 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700766 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000767 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000768 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000769 hasETC1 = hasCompressTex2D &&
770 (version >= GR_GL_VER(3, 0) ||
771 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
772 // ETC2 is a superset of ETC1, so we can just check for that, too.
773 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
774 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000775 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000776 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000777
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000778 // Check for LATC under its various forms
779 LATCAlias alias = kLATC_LATCAlias;
780 bool hasLATC = hasCompressTex2D &&
781 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
782 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
783
784 // Check for RGTC
785 if (!hasLATC) {
786 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
787 if (kGL_GrGLStandard == standard) {
788 hasLATC = version >= GR_GL_VER(3, 0);
789 }
790
791 if (!hasLATC) {
792 hasLATC =
793 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
794 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
795 }
796
797 if (hasLATC) {
798 alias = kRGTC_LATCAlias;
799 }
800 }
801
802 // Check for 3DC
803 if (!hasLATC) {
804 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
805 if (hasLATC) {
806 alias = k3DC_LATCAlias;
807 }
808 }
809
810 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
811 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700812
krajcevskib3abe902014-07-30 13:08:11 -0700813 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
814 // cards default to decompressing the textures in the driver, and is
815 // generally slower.
816 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700817 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
818 }
joshualittee5da552014-07-16 13:32:56 -0700819
krajcevski7ef21622014-07-16 15:21:13 -0700820 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700821 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700822 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
823 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
824 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
825
joshualittee5da552014-07-16 13:32:56 -0700826 // Check for floating point 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, floating point textures became part of
830 // the standard in ES3.1 / OGL 3.1, hence the shorthand
831 bool hasFPTextures = version >= GR_GL_VER(3, 1);
832 if (!hasFPTextures) {
833 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800834 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700835 ctxInfo.hasExtension("GL_OES_texture_float"));
836 }
837 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800838
839 // Check for fp16 texture support
840 // NOTE: We disallow floating point textures on ES devices if linear
841 // filtering modes are not supported. This is for simplicity, but a more
842 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
843 // the standard in ES3.1 / OGL 3.1, hence the shorthand
844 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
845 if (!hasHalfFPTextures) {
846 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800847 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
848 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800849 }
jvanverth1334c212014-12-18 05:44:55 -0800850 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700851 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000852}
853
piotaixre4b23142014-10-02 10:57:53 -0700854bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
855 GrGLenum format,
856 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000857 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
858 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000859 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000860 }
861
862 if (!fTwoFormatLimit) {
863 // not limited by ES 2's constraints
864 return true;
865 }
866
bsalomon@google.com548a4332012-07-11 19:45:22 +0000867 GrGLint otherFormat = GR_GL_RGBA;
868 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000869
870 // The other supported format/type combo supported for ReadPixels
871 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000872 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000873 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
874 &otherFormat);
875
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000876 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000877 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
878 &otherType);
879
bsalomon@google.com548a4332012-07-11 19:45:22 +0000880 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000881}
882
piotaixre4b23142014-10-02 10:57:53 -0700883bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
884 GrGLenum format,
885 GrGLenum type,
886 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800887 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
888 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
889 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700890 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800891 bool supported = this->doReadPixelsSupported(intf, format, type);
892 fReadPixelsSupportedCache.set(key, supported);
893 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700894}
895
robertphillips@google.com6177e692013-02-28 20:16:25 +0000896void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000897
898 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000899 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000900 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
901 // ES3 driver bugs on at least one device with a tiled GPU (N10).
902 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
903 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
904 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
905 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
vbuzinovdded6962015-06-12 08:59:45 -0700906 } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
907 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000908 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000909 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
910 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
911 // chrome's extension is equivalent to the EXT msaa
912 // and fbo_blit extensions.
913 fMSFBOType = kDesktop_EXT_MSFBOType;
914 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
915 fMSFBOType = kES_Apple_MSFBOType;
916 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000917 } else {
vbuzinovdded6962015-06-12 08:59:45 -0700918 if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
919 fMSFBOType = kMixedSamples_MSFBOType;
920 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000921 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000922 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000923 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
924 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000925 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000926 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000927 }
928}
929
cdalton1dd05422015-06-12 09:01:18 -0700930void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
931 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
932
933 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
934 // for now until its own blacklists can be updated.
935 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
936 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700937 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700938 return;
939 }
940
941 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
942 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
943 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
944 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
945 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
946 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
947 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
948 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
949 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
950 return;
951 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
952 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
953 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
954 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
955 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
956 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
957 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
958 // slow on a particular platform.
959 } else {
960 return; // No advanced blend support.
961 }
962
963 SkASSERT(this->advancedBlendEquationSupport());
964
965 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
966 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
967 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
968 (1 << kColorBurn_GrBlendEquation);
969 }
joel.liang9764c402015-07-09 19:46:18 -0700970 if (kARM_GrGLVendor == ctxInfo.vendor()) {
971 // Blacklist color-burn on ARM until the fix is released.
972 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
973 }
cdalton1dd05422015-06-12 09:01:18 -0700974}
975
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000976namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700977const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000978}
979
980void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
981
982 // Build up list of legal stencil formats (though perhaps not supported on
983 // the particular gpu/driver) from most preferred to least.
984
985 // these consts are in order of most preferred to least preferred
986 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
987
988 static const StencilFormat
989 // internal Format stencil bits total bits packed?
990 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
991 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
992 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
993 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000994 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000995 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
996
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000997 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000998 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000999 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001000 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1001 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1002
1003 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1004 // require FBO support we can expect these are legal formats and don't
1005 // check. These also all support the unsized GL_STENCIL_INDEX.
1006 fStencilFormats.push_back() = gS8;
1007 fStencilFormats.push_back() = gS16;
1008 if (supportsPackedDS) {
1009 fStencilFormats.push_back() = gD24S8;
1010 }
1011 fStencilFormats.push_back() = gS4;
1012 if (supportsPackedDS) {
1013 fStencilFormats.push_back() = gDS;
1014 }
1015 } else {
1016 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1017 // for other formats.
1018 // ES doesn't support using the unsized format.
1019
1020 fStencilFormats.push_back() = gS8;
1021 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001022 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1023 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001024 fStencilFormats.push_back() = gD24S8;
1025 }
1026 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1027 fStencilFormats.push_back() = gS4;
1028 }
1029 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001030}
1031
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001032SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001033
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001034 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001035
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001036 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001037 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001038 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001039 i,
1040 fStencilFormats[i].fStencilBits,
1041 fStencilFormats[i].fTotalBits);
1042 }
1043
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001044 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001045 "None",
1046 "ARB",
1047 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001048 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001049 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001050 "IMG MS To Texture",
1051 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001052 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001053 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001054 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1055 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1056 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001057 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1058 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1059 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1060 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001061 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001062 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001063
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001064 static const char* kInvalidateFBTypeStr[] = {
1065 "None",
1066 "Discard",
1067 "Invalidate",
1068 };
1069 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1070 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1071 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1072 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001073
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001074 static const char* kMapBufferTypeStr[] = {
1075 "None",
1076 "MapBuffer",
1077 "MapBufferRange",
1078 "Chromium",
1079 };
1080 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1081 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1082 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1083 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1084 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1085
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001086 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001087 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001088 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001089 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001090 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1091 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001092 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1093 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001094 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
1095 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
1096 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1097 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1098 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1099 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001100
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001101 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1102 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1103 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1104 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1105 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1106 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001107 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001108 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001109 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1110 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1111 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -07001112 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001113 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001114 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001115 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001116 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1117 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001118 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001119 return r;
1120}
1121
jvanverthe9c0fc62015-04-29 11:18:05 -07001122static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1123 switch (p) {
1124 case kLow_GrSLPrecision:
1125 return GR_GL_LOW_FLOAT;
1126 case kMedium_GrSLPrecision:
1127 return GR_GL_MEDIUM_FLOAT;
1128 case kHigh_GrSLPrecision:
1129 return GR_GL_HIGH_FLOAT;
1130 }
1131 SkFAIL("Unknown precision.");
1132 return -1;
1133}
1134
1135static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1136 switch (type) {
1137 case kVertex_GrShaderType:
1138 return GR_GL_VERTEX_SHADER;
1139 case kGeometry_GrShaderType:
1140 return GR_GL_GEOMETRY_SHADER;
1141 case kFragment_GrShaderType:
1142 return GR_GL_FRAGMENT_SHADER;
1143 }
1144 SkFAIL("Unknown shader type.");
1145 return -1;
1146}
1147
jvanverthcba99b82015-06-24 06:59:57 -07001148void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1149 const GrGLInterface* intf,
1150 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001151 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1152 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1153 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1154 if (kGeometry_GrShaderType != s) {
1155 GrShaderType shaderType = static_cast<GrShaderType>(s);
1156 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001157 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001158 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001159 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1160 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1161 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1162 GrGLint range[2];
1163 GrGLint bits;
1164 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1165 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001166 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1167 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1168 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001169 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001170 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001171 }
jvanverthcba99b82015-06-24 06:59:57 -07001172 else if (!glslCaps->fShaderPrecisionVaries) {
1173 glslCaps->fShaderPrecisionVaries =
1174 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001175 }
1176 }
1177 }
1178 }
1179 }
1180 }
1181 else {
1182 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001183 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001184 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1185 if (kGeometry_GrShaderType != s) {
1186 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001187 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1188 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1189 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001190 }
1191 }
1192 }
1193 }
1194 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1195 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1196 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1197 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001198 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001199 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001200 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1201 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001202 }
1203 }
1204}
1205
1206
1207
1208