blob: a4a5b68ade8fec072e54937e4f02a72f4e9f3b42 [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;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000050 fFullClearIsFree = false;
joshualittc1f56b52015-06-22 12:31:31 -070051 fBindFragDataLocationSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070052 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070053 fRGBA8888PixelsOpsAreSlow = false;
54 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070055
56 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070057
jvanverthcba99b82015-06-24 06:59:57 -070058 fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions)));
bsalomon4ee6bd82015-05-27 13:23:23 -070059
cdalton4cd67132015-06-10 19:23:46 -070060 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000061}
62
cdalton4cd67132015-06-10 19:23:46 -070063void GrGLCaps::init(const GrContextOptions& contextOptions,
64 const GrGLContextInfo& ctxInfo,
65 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000066 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000067 GrGLVersion version = ctxInfo.version();
68
bsalomon@google.combcce8922013-03-25 15:38:39 +000069 /**************************************************************************
cdalton4cd67132015-06-10 19:23:46 -070070 * Caps specific to GrGLSLCaps
71 **************************************************************************/
72
73 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
74 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
75
76 if (kGLES_GrGLStandard == standard) {
77 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
78 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
79 glslCaps->fFBFetchSupport = true;
80 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
81 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
82 }
83 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
84 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
85 glslCaps->fFBFetchNeedsCustomOutput = false;
86 glslCaps->fFBFetchSupport = true;
87 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
88 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
89 }
90 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
91 // The arm extension also requires an additional flag which we will set onResetContext
92 glslCaps->fFBFetchNeedsCustomOutput = false;
93 glslCaps->fFBFetchSupport = true;
94 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
95 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
96 }
97 }
98
cdalton626e1ff2015-06-12 13:56:46 -070099 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
100
cdalton4cd67132015-06-10 19:23:46 -0700101 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
102 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
103
104 /**************************************************************************
bsalomon@google.combcce8922013-03-25 15:38:39 +0000105 * Caps specific to GrGLCaps
106 **************************************************************************/
107
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000108 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000109 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
110 &fMaxFragmentUniformVectors);
111 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000112 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000113 GrGLint max;
114 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
115 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000116 if (version >= GR_GL_VER(3, 2)) {
117 GrGLint profileMask;
118 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
119 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
120 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000121 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000122 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000123 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000125 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000126 fRGBA8RenderbufferSupport = true;
127 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000128 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
129 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000130 ctxInfo.hasExtension("GL_ARM_rgba8");
131 }
132
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000133 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000134 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
135 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
136 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000137 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000138 }
139
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000140 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000141 fUnpackRowLengthSupport = true;
142 fUnpackFlipYSupport = false;
143 fPackRowLengthSupport = true;
144 fPackFlipYSupport = false;
145 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000146 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
147 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000148 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000149 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
150 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000151 fPackFlipYSupport =
152 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
153 }
154
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000155 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000156 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
157
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000158 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000159 // The EXT version can apply to either GL or GLES.
160 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
161 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
162 ctxInfo.hasExtension("GL_EXT_texture_storage");
163 } else {
164 // Qualcomm Adreno drivers appear to have issues with texture storage.
165 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
166 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
167 ctxInfo.hasExtension("GL_EXT_texture_storage");
168 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000169
cdaltonfd4167d2015-04-21 11:45:56 -0700170 if (kGL_GrGLStandard == standard) {
171 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
172 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
173 ctxInfo.hasExtension("GL_NV_texture_barrier");
174 } else {
175 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
176 }
177
hendrikwa0d5ad72014-12-02 07:30:30 -0800178 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
179 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700180 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800181 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000182 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
183 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800184 } else {
185 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
186 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000187 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000188 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000189 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000190 ctxInfo.hasExtension("GL_ARB_imaging");
191
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000192 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
193 // ReadPixels. The other format has to checked at run-time since it
194 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000195 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000196
bsalomon16921ec2015-07-30 15:34:56 -0700197 // We only enable srgb support if both textures and FBOs support srgb.
198 bool srgbSupport = false;
199 if (kGL_GrGLStandard == standard) {
200 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
201 srgbSupport = true;
202 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
203 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
204 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
205 srgbSupport = true;
206 }
207 }
208 // All the above srgb extensions support toggling srgb writes
209 fSRGBWriteControl = srgbSupport;
210 } else {
bsalomon58b43952015-07-30 16:27:50 -0700211 // See http://skbug.com/4148 for PowerVR issue.
212 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
213 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
bsalomon16921ec2015-07-30 15:34:56 -0700214 // ES through 3.1 requires EXT_srgb_write_control to support toggling
215 // sRGB writing for destinations.
216 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
217 }
218
rmistry63a9f842014-10-17 06:07:08 -0700219 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000220 // Known issue on at least some Intel platforms:
221 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700222 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000223 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
224 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
225 }
226
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000227 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
228 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
229 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
230 // limit this decision to specific GPU families rather than basing it on the vendor alone.
231 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700232 (kARM_GrGLVendor == ctxInfo.vendor() ||
233 kImagination_GrGLVendor == ctxInfo.vendor() ||
234 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000235 fUseNonVBOVertexAndIndexDynamicData = true;
236 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000237
egdaniel9250d242015-05-18 13:04:26 -0700238 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
239 // Thus we are blacklisting this extension for now on Adreno4xx devices.
240 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
241 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
242 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
243 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000244 fDiscardRenderTargetSupport = true;
245 fInvalidateFBType = kInvalidate_InvalidateFBType;
246 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
247 fDiscardRenderTargetSupport = true;
248 fInvalidateFBType = kDiscard_InvalidateFBType;
249 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000250
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000251 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
252 fFullClearIsFree = true;
253 }
254
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000255 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000256 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800257 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
258 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000259 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000260 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
261 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000262 }
263
cdalton626e1ff2015-06-12 13:56:46 -0700264 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
265 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
266 fInstancedDrawingSupport = true;
267 } else {
268 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
269 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
270 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
271 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
272 }
273
274 if (kGL_GrGLStandard == standard) {
275 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
276 } else {
277 fDirectStateAccessSupport = false;
278 }
279
280 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
281 fDebugSupport = true;
282 } else {
283 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
284 }
285
jvanverth3f801cb2014-12-16 09:49:38 -0800286 if (kGL_GrGLStandard == standard) {
287 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
288 }
289 else {
290 fES2CompatibilitySupport = true;
291 }
292
cdalton0edea2c2015-05-21 08:27:44 -0700293 if (kGL_GrGLStandard == standard) {
294 fMultisampleDisableSupport = true;
295 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700296 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700297 }
298
kkinnunend94708e2015-07-30 22:47:04 -0700299 if (kGL_GrGLStandard == standard) {
300 if (version >= GR_GL_VER(3, 0)) {
301 fBindFragDataLocationSupport = true;
302 }
303 } else {
304 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
305 fBindFragDataLocationSupport = true;
306 }
joshualittc1f56b52015-06-22 12:31:31 -0700307 }
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 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000360
361 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700362 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000363 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700364
365 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700366 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700367 this->initStencilFormats(ctxInfo);
368
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000369 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000370 // we could also look for GL_ATI_separate_stencil extension or
371 // GL_EXT_stencil_two_side but they use different function signatures
372 // than GL2.0+ (and than each other).
373 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
374 // supported on GL 1.4 and higher or by extension
375 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
376 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
377 } else {
378 // ES 2 has two sided stencil and stencil wrap
379 fTwoSidedStencilSupport = true;
380 fStencilWrapOpsSupport = true;
381 }
382
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000383 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000384 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
385 // extension includes glMapBuffer.
386 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
387 fMapBufferFlags |= kSubset_MapFlag;
388 fMapBufferType = kMapBufferRange_MapBufferType;
389 } else {
390 fMapBufferType = kMapBuffer_MapBufferType;
391 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000392 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000393 // Unextended GLES2 doesn't have any buffer mapping.
394 fMapBufferFlags = kNone_MapBufferType;
395 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
396 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
397 fMapBufferType = kChromium_MapBufferType;
398 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
399 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
400 fMapBufferType = kMapBufferRange_MapBufferType;
401 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
402 fMapBufferFlags = kCanMap_MapFlag;
403 fMapBufferType = kMapBuffer_MapBufferType;
404 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000405 }
406
joshualitte5b74c62015-06-01 14:17:47 -0700407 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
408 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
409 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700410 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
411 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
412 // a small subset.
413#if 0
cdalton1acea862015-06-02 13:05:52 -0700414 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700415#else
416 fGeometryBufferMapThreshold = SK_MaxS32;
417#endif
joshualitte5b74c62015-06-01 14:17:47 -0700418 }
419
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000420 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000421 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
422 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
423 fNPOTTextureTileSupport = true;
424 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000425 } else {
426 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000427 // ES3 has no limitations.
428 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
429 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000430 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
431 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
432 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
433 // to alllow arbitrary wrap modes, however.
434 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000435 }
436
bsalomon@google.combcce8922013-03-25 15:38:39 +0000437 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
438 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
439 // Our render targets are always created with textures as the color
440 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000441 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000442
bsalomonc59a1df2015-06-01 07:13:42 -0700443 // This GPU seems to have problems when tiling small textures
444 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
445 fMinTextureSize = 16;
446 }
447
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000448 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
449
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000450 // Disable scratch texture reuse on Mali and Adreno devices
451 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
452 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000453
robertphillips1b8e1b52015-06-24 06:54:10 -0700454#if 0
455 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
456 kQualcomm_GrGLVendor != ctxInfo.vendor();
457#endif
458
bsalomon@google.com347c3822013-05-01 20:10:01 +0000459 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000460 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
461 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
462 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
463 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000464
bsalomon63b21962014-11-05 07:05:34 -0800465 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800466 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800467 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800468 fUseDrawInsteadOfClear = true;
469 }
470
joshualitt83bc2292015-06-18 14:18:02 -0700471 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
472 fUseDrawInsteadOfPartialRenderTargetWrite = true;
473 }
474
bsalomond08ea5f2015-02-20 06:58:13 -0800475 if (kGL_GrGLStandard == standard) {
476 // ARB allows mixed size FBO attachments, EXT does not.
477 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
478 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
479 fOversizedStencilSupport = true;
480 } else {
481 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
482 }
483 } else {
484 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
485 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
486 }
487
joshualitt58001552015-06-26 12:46:36 -0700488 if (kGL_GrGLStandard == standard) {
489 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
490 // instanced arrays, but we could make this more granular if we wanted
491 fSupportsInstancedDraws =
492 version >= GR_GL_VER(3, 2) ||
493 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
494 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
495 } else {
496 fSupportsInstancedDraws =
497 version >= GR_GL_VER(3, 0) ||
498 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
499 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
500 }
501
bsalomon16921ec2015-07-30 15:34:56 -0700502 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
503 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700504 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700505
506 this->applyOptionsOverrides(contextOptions);
507 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000508}
509
kkinnunencfe62e32015-07-01 02:58:50 -0700510bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700511 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
512
513 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700514 return false;
515 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700516
kkinnunencfe62e32015-07-01 02:58:50 -0700517 if (kGL_GrGLStandard == ctxInfo.standard()) {
518 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
519 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
520 return false;
521 }
522 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700523 if (!hasChromiumPathRendering &&
524 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700525 return false;
526 }
527 }
528 // We only support v1.3+ of GL_NV_path_rendering which allows us to
529 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
530 // additions are detected by checking the existence of the function.
531 // We also use *Then* functions that not all drivers might have. Check
532 // them for consistency.
533 if (NULL == gli->fFunctions.fStencilThenCoverFillPath ||
534 NULL == gli->fFunctions.fStencilThenCoverStrokePath ||
535 NULL == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
536 NULL == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
537 NULL == gli->fFunctions.fProgramPathFragmentInputGen) {
538 return false;
539 }
540 return true;
541}
542
bsalomon16921ec2015-07-30 15:34:56 -0700543void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000544 // OpenGL < 3.0
545 // no support for render targets unless the GL_ARB_framebuffer_object
546 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
547 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
548 // probably don't get R8 in this case.
549
550 // OpenGL 3.0
551 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
552 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
553
554 // >= OpenGL 3.1
555 // base color renderable: RED, RG, RGB, and RGBA
556 // sized derivatives: R8, RGBA4, RGBA8
557 // if the GL_ARB_compatibility extension is supported then we get back
558 // support for GL_ALPHA and ALPHA8
559
560 // GL_EXT_bgra adds BGRA render targets to any version
561
562 // ES 2.0
563 // color renderable: RGBA4, RGB5_A1, RGB565
564 // GL_EXT_texture_rg adds support for R8 as a color render target
565 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
566 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
567
568 // ES 3.0
569 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
570 // below already account for this).
571
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000572 GrGLStandard standard = ctxInfo.standard();
573
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000574 enum {
575 kNo_MSAA = 0,
576 kYes_MSAA = 1,
577 };
578
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000579 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000580 // Post 3.0 we will get R8
581 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
582 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
583 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000584 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
585 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000586 }
587 } else {
588 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000589 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
590 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000591 }
592
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000593 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000594 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000595 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
596 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000597 }
598
599 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000600 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
601 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000602
603 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000604 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000605 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000606 }
607
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000608 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000609 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
610 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
611 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000612 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000613 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000614 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
615 } else {
616 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
617 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
618 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000619 }
620
bsalomon16921ec2015-07-30 15:34:56 -0700621 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
622 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
623 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
jvanverthfa1e8a72014-12-22 08:31:49 -0800624 }
625
joshualittee5da552014-07-16 13:32:56 -0700626 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800627 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800628 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800629 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
630 } else {
joshualitt55999962015-06-18 13:47:10 -0700631 // for now we only enable this on desktop, because on ES we'd have to solve many
632 // precision issues and no clients actually want this yet
633 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800634 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
635 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
636 } else {
637 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
638 }
639 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700640 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
641 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700642 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800643 }
joshualittee5da552014-07-16 13:32:56 -0700644 }
645
jvanverth28f9c602014-12-05 13:06:35 -0800646 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800647 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800648 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800649 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800650 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
651 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
652 // for now we don't support floating point MSAA on ES
653 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800654 } else {
jvanverth1334c212014-12-18 05:44:55 -0800655 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
656 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
657 } else {
658 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
659 }
660 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800661 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
662 }
663 }
664
jvanverthfb5df432015-05-21 08:12:27 -0700665 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
666 if (kGL_GrGLStandard == standard) {
667 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
668 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
669 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
670 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
671 // for now we don't support floating point MSAA on ES
672 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
673 } else {
674 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
675 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
676 } else {
677 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
678 }
679 // for now we don't support floating point MSAA on ES
680 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
681 }
682 }
683
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000684 // If we don't support MSAA then undo any places above where we set a config as renderable with
685 // msaa.
686 if (kNone_MSFBOType == fMSFBOType) {
687 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
688 fConfigRenderSupport[i][kYes_MSAA] = false;
689 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000690 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000691}
692
bsalomon16921ec2015-07-30 15:34:56 -0700693void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
694 bool srgbSupport) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000695 GrGLStandard standard = ctxInfo.standard();
696 GrGLVersion version = ctxInfo.version();
697
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000698 // Base texture support
699 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
700 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
701 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
702 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
703
704 // Check for 8-bit palette..
705 GrGLint numFormats;
706 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
707 if (numFormats) {
708 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
709 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
710 for (int i = 0; i < numFormats; ++i) {
711 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
712 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
713 break;
714 }
715 }
716 }
717
718 // Check for BGRA
719 if (kGL_GrGLStandard == standard) {
720 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
721 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
722 } else {
723 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
724 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
725 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
726 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
727 fBGRAIsInternalFormat = true;
728 }
729 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
730 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
731 }
732
bsalomon16921ec2015-07-30 15:34:56 -0700733 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
jvanverthfa1e8a72014-12-22 08:31:49 -0800734
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000735 // Compressed texture support
736
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000737 // glCompressedTexImage2D is available on all OpenGL ES devices...
738 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000739 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000740
krajcevski786978162014-07-30 11:25:44 -0700741 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700742 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700743
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000744 // Check for ETC1
745 bool hasETC1 = false;
746
747 // First check version for support
748 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000749 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700750 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000751 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000752 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000753 hasETC1 = hasCompressTex2D &&
754 (version >= GR_GL_VER(3, 0) ||
755 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
756 // ETC2 is a superset of ETC1, so we can just check for that, too.
757 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
758 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000759 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000760 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000761
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000762 // Check for LATC under its various forms
763 LATCAlias alias = kLATC_LATCAlias;
764 bool hasLATC = hasCompressTex2D &&
765 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
766 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
767
768 // Check for RGTC
769 if (!hasLATC) {
770 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
771 if (kGL_GrGLStandard == standard) {
772 hasLATC = version >= GR_GL_VER(3, 0);
773 }
774
775 if (!hasLATC) {
776 hasLATC =
777 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
778 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
779 }
780
781 if (hasLATC) {
782 alias = kRGTC_LATCAlias;
783 }
784 }
785
786 // Check for 3DC
787 if (!hasLATC) {
788 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
789 if (hasLATC) {
790 alias = k3DC_LATCAlias;
791 }
792 }
793
794 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
795 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700796
krajcevskib3abe902014-07-30 13:08:11 -0700797 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
798 // cards default to decompressing the textures in the driver, and is
799 // generally slower.
800 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700801 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
802 }
joshualittee5da552014-07-16 13:32:56 -0700803
krajcevski7ef21622014-07-16 15:21:13 -0700804 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700805 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700806 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
807 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
808 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
809
joshualittee5da552014-07-16 13:32:56 -0700810 // Check for floating point texture support
811 // NOTE: We disallow floating point textures on ES devices if linear
812 // filtering modes are not supported. This is for simplicity, but a more
813 // granular approach is possible. Coincidentally, floating point textures became part of
814 // the standard in ES3.1 / OGL 3.1, hence the shorthand
815 bool hasFPTextures = version >= GR_GL_VER(3, 1);
816 if (!hasFPTextures) {
817 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800818 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700819 ctxInfo.hasExtension("GL_OES_texture_float"));
820 }
821 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800822
823 // Check for fp16 texture support
824 // NOTE: We disallow floating point textures on ES devices if linear
825 // filtering modes are not supported. This is for simplicity, but a more
826 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
827 // the standard in ES3.1 / OGL 3.1, hence the shorthand
828 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
829 if (!hasHalfFPTextures) {
830 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800831 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
832 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800833 }
jvanverth1334c212014-12-18 05:44:55 -0800834 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700835 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000836}
837
piotaixre4b23142014-10-02 10:57:53 -0700838bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
839 GrGLenum format,
840 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000841 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
842 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000843 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000844 }
845
846 if (!fTwoFormatLimit) {
847 // not limited by ES 2's constraints
848 return true;
849 }
850
bsalomon@google.com548a4332012-07-11 19:45:22 +0000851 GrGLint otherFormat = GR_GL_RGBA;
852 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000853
854 // The other supported format/type combo supported for ReadPixels
855 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000856 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000857 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
858 &otherFormat);
859
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000860 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000861 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
862 &otherType);
863
bsalomon@google.com548a4332012-07-11 19:45:22 +0000864 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000865}
866
piotaixre4b23142014-10-02 10:57:53 -0700867bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
868 GrGLenum format,
869 GrGLenum type,
870 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800871 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
872 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
873 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700874 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800875 bool supported = this->doReadPixelsSupported(intf, format, type);
876 fReadPixelsSupportedCache.set(key, supported);
877 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700878}
879
robertphillips@google.com6177e692013-02-28 20:16:25 +0000880void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000881
882 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000883 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000884 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
885 // ES3 driver bugs on at least one device with a tiled GPU (N10).
886 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
887 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
888 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
889 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
vbuzinovdded6962015-06-12 08:59:45 -0700890 } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
891 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000892 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000893 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
894 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
895 // chrome's extension is equivalent to the EXT msaa
896 // and fbo_blit extensions.
897 fMSFBOType = kDesktop_EXT_MSFBOType;
898 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
899 fMSFBOType = kES_Apple_MSFBOType;
900 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000901 } else {
vbuzinovdded6962015-06-12 08:59:45 -0700902 if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
903 fMSFBOType = kMixedSamples_MSFBOType;
904 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000905 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000906 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000907 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
908 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000909 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000910 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000911 }
912}
913
cdalton1dd05422015-06-12 09:01:18 -0700914void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
915 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
916
917 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
918 // for now until its own blacklists can be updated.
919 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
920 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700921 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700922 return;
923 }
924
925 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
926 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
927 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
928 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
929 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
930 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
931 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
932 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
933 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
934 return;
935 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
936 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
937 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
938 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
939 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
940 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
941 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
942 // slow on a particular platform.
943 } else {
944 return; // No advanced blend support.
945 }
946
947 SkASSERT(this->advancedBlendEquationSupport());
948
949 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
950 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
951 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
952 (1 << kColorBurn_GrBlendEquation);
953 }
joel.liang9764c402015-07-09 19:46:18 -0700954 if (kARM_GrGLVendor == ctxInfo.vendor()) {
955 // Blacklist color-burn on ARM until the fix is released.
956 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
957 }
cdalton1dd05422015-06-12 09:01:18 -0700958}
959
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000960namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700961const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000962}
963
964void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
965
966 // Build up list of legal stencil formats (though perhaps not supported on
967 // the particular gpu/driver) from most preferred to least.
968
969 // these consts are in order of most preferred to least preferred
970 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
971
972 static const StencilFormat
973 // internal Format stencil bits total bits packed?
974 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
975 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
976 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
977 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000978 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000979 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
980
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000981 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000982 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000983 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000984 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
985 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
986
987 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
988 // require FBO support we can expect these are legal formats and don't
989 // check. These also all support the unsized GL_STENCIL_INDEX.
990 fStencilFormats.push_back() = gS8;
991 fStencilFormats.push_back() = gS16;
992 if (supportsPackedDS) {
993 fStencilFormats.push_back() = gD24S8;
994 }
995 fStencilFormats.push_back() = gS4;
996 if (supportsPackedDS) {
997 fStencilFormats.push_back() = gDS;
998 }
999 } else {
1000 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1001 // for other formats.
1002 // ES doesn't support using the unsized format.
1003
1004 fStencilFormats.push_back() = gS8;
1005 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001006 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1007 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001008 fStencilFormats.push_back() = gD24S8;
1009 }
1010 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1011 fStencilFormats.push_back() = gS4;
1012 }
1013 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001014 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001015 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
1016}
1017
1018void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
1019 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -07001020 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001021#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
1022 return;
1023#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001024 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
1025 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001026 int count = fStencilFormats.count();
1027 // we expect a really small number of possible formats so linear search
1028 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001029 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001030 for (int i = 0; i < count; ++i) {
1031 if (format.fInternalFormat ==
1032 fStencilFormats[i].fInternalFormat) {
1033 fStencilVerifiedColorConfigs[i].markVerified(config);
1034 return;
1035 }
1036 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001037 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001038 "GrGLCaps doesn't know about.");
1039}
1040
1041bool GrGLCaps::isColorConfigAndStencilFormatVerified(
1042 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -07001043 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001044#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
1045 return false;
1046#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001047 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001048 int count = fStencilFormats.count();
1049 // we expect a really small number of possible formats so linear search
1050 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001051 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001052 for (int i = 0; i < count; ++i) {
1053 if (format.fInternalFormat ==
1054 fStencilFormats[i].fInternalFormat) {
1055 return fStencilVerifiedColorConfigs[i].isVerified(config);
1056 }
1057 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001058 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001059 "GLCaps doesn't know about.");
1060 return false;
1061}
1062
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001063SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001064
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001065 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001066
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001067 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001068 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001069 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001070 i,
1071 fStencilFormats[i].fStencilBits,
1072 fStencilFormats[i].fTotalBits);
1073 }
1074
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001075 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001076 "None",
1077 "ARB",
1078 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001079 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001080 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001081 "IMG MS To Texture",
1082 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001083 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001084 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001085 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1086 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1087 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001088 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1089 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1090 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1091 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001092 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001093 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001094
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001095 static const char* kInvalidateFBTypeStr[] = {
1096 "None",
1097 "Discard",
1098 "Invalidate",
1099 };
1100 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1101 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1102 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1103 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001104
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001105 static const char* kMapBufferTypeStr[] = {
1106 "None",
1107 "MapBuffer",
1108 "MapBufferRange",
1109 "Chromium",
1110 };
1111 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1112 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1113 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1114 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1115 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1116
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001117 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001118 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001119 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001120 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001121 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1122 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001123 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1124 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001125 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
1126 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
1127 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1128 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1129 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1130 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001131
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001132 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1133 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1134 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1135 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1136 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1137 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001138 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001139 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001140 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1141 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1142 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -07001143 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001144 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001145 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001146 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001147 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
bsalomon88c7b982015-07-31 11:20:16 -07001148 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow? "YES" : "NO"));
1149 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001150 return r;
1151}
1152
jvanverthe9c0fc62015-04-29 11:18:05 -07001153static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1154 switch (p) {
1155 case kLow_GrSLPrecision:
1156 return GR_GL_LOW_FLOAT;
1157 case kMedium_GrSLPrecision:
1158 return GR_GL_MEDIUM_FLOAT;
1159 case kHigh_GrSLPrecision:
1160 return GR_GL_HIGH_FLOAT;
1161 }
1162 SkFAIL("Unknown precision.");
1163 return -1;
1164}
1165
1166static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1167 switch (type) {
1168 case kVertex_GrShaderType:
1169 return GR_GL_VERTEX_SHADER;
1170 case kGeometry_GrShaderType:
1171 return GR_GL_GEOMETRY_SHADER;
1172 case kFragment_GrShaderType:
1173 return GR_GL_FRAGMENT_SHADER;
1174 }
1175 SkFAIL("Unknown shader type.");
1176 return -1;
1177}
1178
jvanverthcba99b82015-06-24 06:59:57 -07001179void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1180 const GrGLInterface* intf,
1181 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001182 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1183 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1184 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1185 if (kGeometry_GrShaderType != s) {
1186 GrShaderType shaderType = static_cast<GrShaderType>(s);
1187 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
jvanverthcba99b82015-06-24 06:59:57 -07001188 GrShaderCaps::PrecisionInfo* first = NULL;
1189 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001190 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1191 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1192 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1193 GrGLint range[2];
1194 GrGLint bits;
1195 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1196 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001197 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1198 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1199 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001200 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001201 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001202 }
jvanverthcba99b82015-06-24 06:59:57 -07001203 else if (!glslCaps->fShaderPrecisionVaries) {
1204 glslCaps->fShaderPrecisionVaries =
1205 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001206 }
1207 }
1208 }
1209 }
1210 }
1211 }
1212 else {
1213 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001214 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001215 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1216 if (kGeometry_GrShaderType != s) {
1217 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001218 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1219 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1220 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001221 }
1222 }
1223 }
1224 }
1225 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1226 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1227 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1228 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001229 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001230 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001231 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1232 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001233 }
1234 }
1235}
1236
1237
1238
1239