blob: 1d25a2ca2f47eba5fcf1d4362387f9467983b1c4 [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 /**************************************************************************
68 * Caps specific to GrGLCaps
69 **************************************************************************/
70
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000071 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
73 &fMaxFragmentUniformVectors);
74 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000075 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000076 GrGLint max;
77 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
78 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000079 if (version >= GR_GL_VER(3, 2)) {
80 GrGLint profileMask;
81 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
82 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
83 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000084 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000085 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000086 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000087
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000088 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089 fRGBA8RenderbufferSupport = true;
90 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +000091 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
92 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000093 ctxInfo.hasExtension("GL_ARM_rgba8");
94 }
95
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000096 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
98 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
99 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000100 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101 }
102
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000103 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104 fUnpackRowLengthSupport = true;
105 fUnpackFlipYSupport = false;
106 fPackRowLengthSupport = true;
107 fPackFlipYSupport = false;
108 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000109 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
110 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000112 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
113 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000114 fPackFlipYSupport =
115 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
116 }
117
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000118 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000119 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
120
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000121 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000122 // The EXT version can apply to either GL or GLES.
123 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
124 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
125 ctxInfo.hasExtension("GL_EXT_texture_storage");
126 } else {
127 // Qualcomm Adreno drivers appear to have issues with texture storage.
128 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
129 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
130 ctxInfo.hasExtension("GL_EXT_texture_storage");
131 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000132
cdaltonfd4167d2015-04-21 11:45:56 -0700133 if (kGL_GrGLStandard == standard) {
134 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
135 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
136 ctxInfo.hasExtension("GL_NV_texture_barrier");
137 } else {
138 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
139 }
140
hendrikwa0d5ad72014-12-02 07:30:30 -0800141 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
142 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700143 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800144 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000145 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
146 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800147 } else {
148 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
149 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000150 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000151 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000152 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000153 ctxInfo.hasExtension("GL_ARB_imaging");
154
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000155 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
156 // ReadPixels. The other format has to checked at run-time since it
157 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000158 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000159
bsalomon16921ec2015-07-30 15:34:56 -0700160 // We only enable srgb support if both textures and FBOs support srgb.
161 bool srgbSupport = false;
162 if (kGL_GrGLStandard == standard) {
163 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
164 srgbSupport = true;
165 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
166 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
167 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
168 srgbSupport = true;
169 }
170 }
171 // All the above srgb extensions support toggling srgb writes
172 fSRGBWriteControl = srgbSupport;
173 } else {
bsalomon58b43952015-07-30 16:27:50 -0700174 // See http://skbug.com/4148 for PowerVR issue.
175 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
176 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
bsalomon16921ec2015-07-30 15:34:56 -0700177 // ES through 3.1 requires EXT_srgb_write_control to support toggling
178 // sRGB writing for destinations.
179 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
180 }
181
rmistry63a9f842014-10-17 06:07:08 -0700182 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000183 // Known issue on at least some Intel platforms:
184 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700185 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000186 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
187 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
188 }
189
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000190 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
191 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
192 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
193 // limit this decision to specific GPU families rather than basing it on the vendor alone.
194 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700195 (kARM_GrGLVendor == ctxInfo.vendor() ||
196 kImagination_GrGLVendor == ctxInfo.vendor() ||
197 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000198 fUseNonVBOVertexAndIndexDynamicData = true;
199 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000200
egdaniel9250d242015-05-18 13:04:26 -0700201 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
202 // Thus we are blacklisting this extension for now on Adreno4xx devices.
203 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
204 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
205 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
206 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000207 fDiscardRenderTargetSupport = true;
208 fInvalidateFBType = kInvalidate_InvalidateFBType;
209 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
210 fDiscardRenderTargetSupport = true;
211 fInvalidateFBType = kDiscard_InvalidateFBType;
212 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000213
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000214 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
215 fFullClearIsFree = true;
216 }
217
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000218 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000219 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800220 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
221 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000222 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000223 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
224 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000225 }
226
cdalton626e1ff2015-06-12 13:56:46 -0700227 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
228 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
229 fInstancedDrawingSupport = true;
230 } else {
231 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
232 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
233 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
234 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
235 }
236
237 if (kGL_GrGLStandard == standard) {
238 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
239 } else {
240 fDirectStateAccessSupport = false;
241 }
242
243 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
244 fDebugSupport = true;
245 } else {
246 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
247 }
248
jvanverth3f801cb2014-12-16 09:49:38 -0800249 if (kGL_GrGLStandard == standard) {
250 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
251 }
252 else {
253 fES2CompatibilitySupport = true;
254 }
255
cdalton0edea2c2015-05-21 08:27:44 -0700256 if (kGL_GrGLStandard == standard) {
257 fMultisampleDisableSupport = true;
258 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700259 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700260 }
261
kkinnunend94708e2015-07-30 22:47:04 -0700262 if (kGL_GrGLStandard == standard) {
263 if (version >= GR_GL_VER(3, 0)) {
264 fBindFragDataLocationSupport = true;
265 }
266 } else {
267 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
268 fBindFragDataLocationSupport = true;
269 }
joshualittc1f56b52015-06-22 12:31:31 -0700270 }
271
kkinnunen177519e2015-10-28 06:18:35 -0700272#if 0 // Disabled due to http://skbug.com/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700273 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
kkinnunen177519e2015-10-28 06:18:35 -0700274#else
275 fBindUniformLocationSupport = false;
276#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700277
bsalomon88c7b982015-07-31 11:20:16 -0700278#ifdef SK_BUILD_FOR_WIN
279 // We're assuming that on Windows Chromium we're using ANGLE.
280 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
281 kChromium_GrGLDriver == ctxInfo.driver();
282 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
283 fRGBA8888PixelsOpsAreSlow = isANGLE;
284 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
285 // check DX11 ANGLE.
286 fPartialFBOReadIsSlow = isANGLE;
287#endif
288
cdalton4cd67132015-06-10 19:23:46 -0700289 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700290 * GrShaderCaps fields
291 **************************************************************************/
292
egdaniel0a482332015-10-26 08:59:10 -0700293 // This must be called after fCoreProfile is set on the GrGLCaps
294 this->initGLSL(ctxInfo);
295 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
296
egdaniel05ded892015-10-26 07:38:05 -0700297 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
298
299 // For now these two are equivalent but we could have dst read in shader via some other method.
300 // Before setting this, initGLSL() must have been called.
301 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
302
303 // Enable supported shader-related caps
304 if (kGL_GrGLStandard == standard) {
305 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
306 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
307 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
308 glslCaps->fShaderDerivativeSupport = true;
309 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
310 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
311 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
312 }
313 else {
314 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
315
316 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
317 ctxInfo.hasExtension("GL_OES_standard_derivatives");
318 }
319
320 // We need dual source blending and the ability to disable multisample in order to support mixed
321 // samples in every corner case.
322 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) {
323 // We understand "mixed samples" to mean the collective capability of 3 different extensions
324 glslCaps->fMixedSamplesSupport =
325 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
326 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
327 ctxInfo.hasExtension("GL_EXT_raster_multisample");
328 }
329 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
330 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSupport()) {
331 fDiscardRenderTargetSupport = false;
332 fInvalidateFBType = kNone_InvalidateFBType;
333 }
334 glslCaps->fProgrammableSampleLocationsSupport =
335 ctxInfo.hasExtension("GL_NV_sample_locations") ||
336 ctxInfo.hasExtension("GL_ARB_sample_locations");
337
338 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700339 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000340 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700341
egdaniel05ded892015-10-26 07:38:05 -0700342 // fPathRenderingSupport and fMixedSampleSupport must be set before calling initFSAASupport.
343 // Both of these are set in the GrShaderCaps.
cdalton4cd67132015-06-10 19:23:46 -0700344 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700345 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700346 this->initStencilFormats(ctxInfo);
347
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000348 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000349 // we could also look for GL_ATI_separate_stencil extension or
350 // GL_EXT_stencil_two_side but they use different function signatures
351 // than GL2.0+ (and than each other).
352 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
353 // supported on GL 1.4 and higher or by extension
354 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
355 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
356 } else {
357 // ES 2 has two sided stencil and stencil wrap
358 fTwoSidedStencilSupport = true;
359 fStencilWrapOpsSupport = true;
360 }
361
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000362 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000363 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
364 // extension includes glMapBuffer.
365 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
366 fMapBufferFlags |= kSubset_MapFlag;
367 fMapBufferType = kMapBufferRange_MapBufferType;
368 } else {
369 fMapBufferType = kMapBuffer_MapBufferType;
370 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000371 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000372 // Unextended GLES2 doesn't have any buffer mapping.
373 fMapBufferFlags = kNone_MapBufferType;
374 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
375 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
376 fMapBufferType = kChromium_MapBufferType;
377 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
378 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
379 fMapBufferType = kMapBufferRange_MapBufferType;
380 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
381 fMapBufferFlags = kCanMap_MapFlag;
382 fMapBufferType = kMapBuffer_MapBufferType;
383 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000384 }
385
joshualitte5b74c62015-06-01 14:17:47 -0700386 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
387 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
388 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700389 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
390 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
391 // a small subset.
392#if 0
cdalton1acea862015-06-02 13:05:52 -0700393 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700394#else
395 fGeometryBufferMapThreshold = SK_MaxS32;
396#endif
joshualitte5b74c62015-06-01 14:17:47 -0700397 }
398
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000399 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000400 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
401 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
402 fNPOTTextureTileSupport = true;
403 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000404 } else {
405 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000406 // ES3 has no limitations.
407 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
408 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000409 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
410 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
411 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
412 // to alllow arbitrary wrap modes, however.
413 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000414 }
415
bsalomone72bd022015-10-26 07:33:03 -0700416 // Using MIPs on this GPU seems to be a source of trouble.
417 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
418 fMipMapSupport = false;
419 }
420
bsalomon@google.combcce8922013-03-25 15:38:39 +0000421 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
422 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
423 // Our render targets are always created with textures as the color
424 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000425 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000426
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000427 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
428
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000429 // Disable scratch texture reuse on Mali and Adreno devices
430 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
431 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000432
robertphillips1b8e1b52015-06-24 06:54:10 -0700433#if 0
434 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
435 kQualcomm_GrGLVendor != ctxInfo.vendor();
436#endif
437
egdaniel05ded892015-10-26 07:38:05 -0700438 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000439 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000440 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
441 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
442 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
443 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000444
bsalomon63b21962014-11-05 07:05:34 -0800445 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800446 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800447 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800448 fUseDrawInsteadOfClear = true;
449 }
450
joshualitt83bc2292015-06-18 14:18:02 -0700451 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
452 fUseDrawInsteadOfPartialRenderTargetWrite = true;
453 }
454
robertphillips63926682015-08-20 09:39:02 -0700455#ifdef SK_BUILD_FOR_WIN
456 // On ANGLE deferring flushes can lead to GPU starvation
457 fPreferVRAMUseOverFlushes = !isANGLE;
458#endif
459
bsalomon7dea7b72015-08-19 08:26:51 -0700460 if (kChromium_GrGLDriver == ctxInfo.driver()) {
461 fMustClearUploadedBufferData = true;
462 }
463
bsalomond08ea5f2015-02-20 06:58:13 -0800464 if (kGL_GrGLStandard == standard) {
465 // ARB allows mixed size FBO attachments, EXT does not.
466 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
467 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
468 fOversizedStencilSupport = true;
469 } else {
470 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
471 }
472 } else {
473 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
474 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
475 }
476
joshualitt58001552015-06-26 12:46:36 -0700477 if (kGL_GrGLStandard == standard) {
478 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
479 // instanced arrays, but we could make this more granular if we wanted
480 fSupportsInstancedDraws =
481 version >= GR_GL_VER(3, 2) ||
482 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
483 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
484 } else {
485 fSupportsInstancedDraws =
486 version >= GR_GL_VER(3, 0) ||
487 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
488 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
489 }
490
bsalomon16921ec2015-07-30 15:34:56 -0700491 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
492 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700493 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700494
495 this->applyOptionsOverrides(contextOptions);
496 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000497}
498
egdaniel472d44e2015-10-22 08:20:00 -0700499const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
500 bool isCoreProfile) {
501 switch (generation) {
502 case k110_GrGLSLGeneration:
503 if (kGLES_GrGLStandard == standard) {
504 // ES2s shader language is based on version 1.20 but is version
505 // 1.00 of the ES language.
506 return "#version 100\n";
507 } else {
508 SkASSERT(kGL_GrGLStandard == standard);
509 return "#version 110\n";
510 }
511 case k130_GrGLSLGeneration:
512 SkASSERT(kGL_GrGLStandard == standard);
513 return "#version 130\n";
514 case k140_GrGLSLGeneration:
515 SkASSERT(kGL_GrGLStandard == standard);
516 return "#version 140\n";
517 case k150_GrGLSLGeneration:
518 SkASSERT(kGL_GrGLStandard == standard);
519 if (isCoreProfile) {
520 return "#version 150\n";
521 } else {
522 return "#version 150 compatibility\n";
523 }
524 case k330_GrGLSLGeneration:
525 if (kGLES_GrGLStandard == standard) {
526 return "#version 300 es\n";
527 } else {
528 SkASSERT(kGL_GrGLStandard == standard);
529 if (isCoreProfile) {
530 return "#version 330\n";
531 } else {
532 return "#version 330 compatibility\n";
533 }
534 }
535 case k310es_GrGLSLGeneration:
536 SkASSERT(kGLES_GrGLStandard == standard);
537 return "#version 310 es\n";
538 }
539 return "<no version>";
540}
541
egdaniel05ded892015-10-26 07:38:05 -0700542void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700543 GrGLStandard standard = ctxInfo.standard();
544 GrGLVersion version = ctxInfo.version();
545
546 /**************************************************************************
547 * Caps specific to GrGLSLCaps
548 **************************************************************************/
549
550 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
551 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
552
553 if (kGLES_GrGLStandard == standard) {
554 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
555 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
556 glslCaps->fFBFetchSupport = true;
557 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
558 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
559 }
560 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
561 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
562 glslCaps->fFBFetchNeedsCustomOutput = false;
563 glslCaps->fFBFetchSupport = true;
564 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
565 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
566 }
567 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
568 // The arm extension also requires an additional flag which we will set onResetContext
569 glslCaps->fFBFetchNeedsCustomOutput = false;
570 glslCaps->fFBFetchSupport = true;
571 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
572 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
573 }
574 glslCaps->fUsesPrecisionModifiers = true;
575 }
576
577 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
578
579 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
580 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
581
582 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
583 // function that may require a gradient calculation inside a conditional block may return
584 // undefined results". This appears to be an issue with the 'any' call since even the simple
585 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
586 // from our GrTextureDomain processor.
587 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
588
egdanielcae00852015-10-22 11:08:08 -0700589 glslCaps->fForceHighPrecisionNDSTransform = kARM_GrGLVendor == ctxInfo.vendor() ||
590 kPowerVR54x_GrGLRenderer == ctxInfo.renderer();
egdaniel472d44e2015-10-22 08:20:00 -0700591
592 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
593 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800594
595 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
596 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
597 }
egdaniel472d44e2015-10-22 08:20:00 -0700598}
599
kkinnunencfe62e32015-07-01 02:58:50 -0700600bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700601 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
602
603 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700604 return false;
605 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700606
kkinnunencfe62e32015-07-01 02:58:50 -0700607 if (kGL_GrGLStandard == ctxInfo.standard()) {
608 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
609 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
610 return false;
611 }
612 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700613 if (!hasChromiumPathRendering &&
614 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700615 return false;
616 }
617 }
618 // We only support v1.3+ of GL_NV_path_rendering which allows us to
619 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
620 // additions are detected by checking the existence of the function.
621 // We also use *Then* functions that not all drivers might have. Check
622 // them for consistency.
halcanary96fcdcc2015-08-27 07:41:13 -0700623 if (nullptr == gli->fFunctions.fStencilThenCoverFillPath ||
624 nullptr == gli->fFunctions.fStencilThenCoverStrokePath ||
625 nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
626 nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
627 nullptr == gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700628 return false;
629 }
630 return true;
631}
632
bsalomon16921ec2015-07-30 15:34:56 -0700633void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000634 // OpenGL < 3.0
635 // no support for render targets unless the GL_ARB_framebuffer_object
636 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
637 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
638 // probably don't get R8 in this case.
639
640 // OpenGL 3.0
641 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
642 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
643
644 // >= OpenGL 3.1
645 // base color renderable: RED, RG, RGB, and RGBA
646 // sized derivatives: R8, RGBA4, RGBA8
647 // if the GL_ARB_compatibility extension is supported then we get back
648 // support for GL_ALPHA and ALPHA8
649
650 // GL_EXT_bgra adds BGRA render targets to any version
651
652 // ES 2.0
653 // color renderable: RGBA4, RGB5_A1, RGB565
654 // GL_EXT_texture_rg adds support for R8 as a color render target
655 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
656 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
657
658 // ES 3.0
659 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
660 // below already account for this).
661
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000662 GrGLStandard standard = ctxInfo.standard();
663
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000664 enum {
665 kNo_MSAA = 0,
666 kYes_MSAA = 1,
667 };
668
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000669 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000670 // Post 3.0 we will get R8
671 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
672 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
673 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000674 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
675 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000676 }
677 } else {
678 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000679 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
680 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000681 }
682
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000683 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000684 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000685 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
686 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000687 }
688
689 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000690 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
691 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000692
693 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000694 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000695 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000696 }
697
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000698 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000699 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
700 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
701 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000702 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000703 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000704 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
705 } else {
706 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
707 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
708 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000709 }
710
bsalomon16921ec2015-07-30 15:34:56 -0700711 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
712 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
713 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
jvanverthfa1e8a72014-12-22 08:31:49 -0800714 }
715
joshualittee5da552014-07-16 13:32:56 -0700716 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800717 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800718 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800719 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
720 } else {
joshualitt55999962015-06-18 13:47:10 -0700721 // for now we only enable this on desktop, because on ES we'd have to solve many
722 // precision issues and no clients actually want this yet
723 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800724 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
725 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
726 } else {
727 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
728 }
729 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700730 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
731 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700732 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800733 }
joshualittee5da552014-07-16 13:32:56 -0700734 }
735
jvanverth28f9c602014-12-05 13:06:35 -0800736 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800737 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800738 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800739 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800740 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
741 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
742 // for now we don't support floating point MSAA on ES
743 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800744 } else {
jvanverth1334c212014-12-18 05:44:55 -0800745 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
746 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
747 } else {
748 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
749 }
750 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800751 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
752 }
753 }
754
jvanverthfb5df432015-05-21 08:12:27 -0700755 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
756 if (kGL_GrGLStandard == standard) {
757 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
758 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
759 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
760 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
761 // for now we don't support floating point MSAA on ES
762 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
763 } else {
764 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
765 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
766 } else {
767 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
768 }
769 // for now we don't support floating point MSAA on ES
770 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
771 }
772 }
773
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000774 // If we don't support MSAA then undo any places above where we set a config as renderable with
775 // msaa.
776 if (kNone_MSFBOType == fMSFBOType) {
777 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
778 fConfigRenderSupport[i][kYes_MSAA] = false;
779 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000780 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000781}
782
bsalomon16921ec2015-07-30 15:34:56 -0700783void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
784 bool srgbSupport) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000785 GrGLStandard standard = ctxInfo.standard();
786 GrGLVersion version = ctxInfo.version();
787
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000788 // Base texture support
789 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
790 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
791 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
792 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
793
reed56f38fb2015-09-14 09:09:00 -0700794 // Disable this for now, while we investigate skbug.com/4333
795 if (false) {
796 // Check for 8-bit palette..
797 GrGLint numFormats;
798 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
799 if (numFormats) {
800 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
801 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
802 for (int i = 0; i < numFormats; ++i) {
803 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
804 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
805 break;
806 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000807 }
808 }
809 }
810
811 // Check for BGRA
812 if (kGL_GrGLStandard == standard) {
813 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
814 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
815 } else {
816 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
817 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
818 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
819 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
820 fBGRAIsInternalFormat = true;
821 }
822 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
823 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
824 }
825
bsalomon16921ec2015-07-30 15:34:56 -0700826 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
jvanverthfa1e8a72014-12-22 08:31:49 -0800827
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000828 // Compressed texture support
829
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000830 // glCompressedTexImage2D is available on all OpenGL ES devices...
831 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000832 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000833
krajcevski786978162014-07-30 11:25:44 -0700834 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700835 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700836
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000837 // Check for ETC1
838 bool hasETC1 = false;
839
840 // First check version for support
841 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000842 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700843 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000844 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000845 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000846 hasETC1 = hasCompressTex2D &&
847 (version >= GR_GL_VER(3, 0) ||
848 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
849 // ETC2 is a superset of ETC1, so we can just check for that, too.
850 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
851 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000852 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000853 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000854
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000855 // Check for LATC under its various forms
856 LATCAlias alias = kLATC_LATCAlias;
857 bool hasLATC = hasCompressTex2D &&
858 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
859 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
860
861 // Check for RGTC
862 if (!hasLATC) {
863 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
864 if (kGL_GrGLStandard == standard) {
865 hasLATC = version >= GR_GL_VER(3, 0);
866 }
867
868 if (!hasLATC) {
869 hasLATC =
870 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
871 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
872 }
873
874 if (hasLATC) {
875 alias = kRGTC_LATCAlias;
876 }
877 }
878
879 // Check for 3DC
880 if (!hasLATC) {
881 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
882 if (hasLATC) {
883 alias = k3DC_LATCAlias;
884 }
885 }
886
887 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
888 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700889
krajcevskib3abe902014-07-30 13:08:11 -0700890 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
891 // cards default to decompressing the textures in the driver, and is
892 // generally slower.
893 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700894 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
895 }
joshualittee5da552014-07-16 13:32:56 -0700896
krajcevski7ef21622014-07-16 15:21:13 -0700897 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700898 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700899 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
900 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
901 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
902
joshualittee5da552014-07-16 13:32:56 -0700903 // Check for floating point texture support
904 // NOTE: We disallow floating point textures on ES devices if linear
905 // filtering modes are not supported. This is for simplicity, but a more
906 // granular approach is possible. Coincidentally, floating point textures became part of
907 // the standard in ES3.1 / OGL 3.1, hence the shorthand
908 bool hasFPTextures = version >= GR_GL_VER(3, 1);
909 if (!hasFPTextures) {
910 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800911 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700912 ctxInfo.hasExtension("GL_OES_texture_float"));
913 }
914 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800915
916 // Check for fp16 texture support
917 // NOTE: We disallow floating point textures on ES devices if linear
918 // filtering modes are not supported. This is for simplicity, but a more
919 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
920 // the standard in ES3.1 / OGL 3.1, hence the shorthand
921 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
922 if (!hasHalfFPTextures) {
923 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800924 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
925 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800926 }
jvanverth1334c212014-12-18 05:44:55 -0800927 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700928 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000929}
930
piotaixre4b23142014-10-02 10:57:53 -0700931bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
932 GrGLenum format,
933 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000934 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
935 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000936 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000937 }
938
939 if (!fTwoFormatLimit) {
940 // not limited by ES 2's constraints
941 return true;
942 }
943
bsalomon@google.com548a4332012-07-11 19:45:22 +0000944 GrGLint otherFormat = GR_GL_RGBA;
945 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000946
947 // The other supported format/type combo supported for ReadPixels
948 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000949 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000950 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
951 &otherFormat);
952
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000953 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000954 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
955 &otherType);
956
bsalomon@google.com548a4332012-07-11 19:45:22 +0000957 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000958}
959
piotaixre4b23142014-10-02 10:57:53 -0700960bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
961 GrGLenum format,
962 GrGLenum type,
963 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800964 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
965 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
966 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700967 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800968 bool supported = this->doReadPixelsSupported(intf, format, type);
969 fReadPixelsSupportedCache.set(key, supported);
970 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700971}
972
robertphillips@google.com6177e692013-02-28 20:16:25 +0000973void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000974
975 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000976 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000977 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
978 // ES3 driver bugs on at least one device with a tiled GPU (N10).
979 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
980 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
981 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
982 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
vbuzinovdded6962015-06-12 08:59:45 -0700983 } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
984 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000985 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000986 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
987 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
988 // chrome's extension is equivalent to the EXT msaa
989 // and fbo_blit extensions.
990 fMSFBOType = kDesktop_EXT_MSFBOType;
991 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
992 fMSFBOType = kES_Apple_MSFBOType;
993 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000994 } else {
vbuzinovdded6962015-06-12 08:59:45 -0700995 if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
996 fMSFBOType = kMixedSamples_MSFBOType;
997 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000998 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000999 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001000 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1001 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001002 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001003 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001004 }
1005}
1006
cdalton1dd05422015-06-12 09:01:18 -07001007void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
1008 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
1009
1010 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
1011 // for now until its own blacklists can be updated.
1012 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
1013 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -07001014 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -07001015 return;
1016 }
1017
1018 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1019 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1020 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1021 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
1022 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1023 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1024 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1025 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
1026 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
1027 return;
1028 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1029 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1030 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1031 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
1032 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1033 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1034 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1035 // slow on a particular platform.
1036 } else {
1037 return; // No advanced blend support.
1038 }
1039
1040 SkASSERT(this->advancedBlendEquationSupport());
1041
1042 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
1043 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
1044 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
1045 (1 << kColorBurn_GrBlendEquation);
1046 }
joel.liang9764c402015-07-09 19:46:18 -07001047 if (kARM_GrGLVendor == ctxInfo.vendor()) {
1048 // Blacklist color-burn on ARM until the fix is released.
1049 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
1050 }
cdalton1dd05422015-06-12 09:01:18 -07001051}
1052
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001053namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001054const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001055}
1056
1057void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
1058
1059 // Build up list of legal stencil formats (though perhaps not supported on
1060 // the particular gpu/driver) from most preferred to least.
1061
1062 // these consts are in order of most preferred to least preferred
1063 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1064
1065 static const StencilFormat
1066 // internal Format stencil bits total bits packed?
1067 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1068 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1069 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1070 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001071 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001072 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1073
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001074 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001075 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001076 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001077 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1078 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1079
1080 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1081 // require FBO support we can expect these are legal formats and don't
1082 // check. These also all support the unsized GL_STENCIL_INDEX.
1083 fStencilFormats.push_back() = gS8;
1084 fStencilFormats.push_back() = gS16;
1085 if (supportsPackedDS) {
1086 fStencilFormats.push_back() = gD24S8;
1087 }
1088 fStencilFormats.push_back() = gS4;
1089 if (supportsPackedDS) {
1090 fStencilFormats.push_back() = gDS;
1091 }
1092 } else {
1093 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1094 // for other formats.
1095 // ES doesn't support using the unsized format.
1096
1097 fStencilFormats.push_back() = gS8;
1098 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001099 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1100 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001101 fStencilFormats.push_back() = gD24S8;
1102 }
1103 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1104 fStencilFormats.push_back() = gS4;
1105 }
1106 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001107}
1108
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001109SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001110
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001111 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001112
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001113 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001114 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001115 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001116 i,
1117 fStencilFormats[i].fStencilBits,
1118 fStencilFormats[i].fTotalBits);
1119 }
1120
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001121 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001122 "None",
1123 "ARB",
1124 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001125 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001126 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001127 "IMG MS To Texture",
1128 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001129 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001130 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001131 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1132 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1133 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001134 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1135 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1136 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1137 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001138 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001139 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001140
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001141 static const char* kInvalidateFBTypeStr[] = {
1142 "None",
1143 "Discard",
1144 "Invalidate",
1145 };
1146 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1147 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1148 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1149 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001150
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001151 static const char* kMapBufferTypeStr[] = {
1152 "None",
1153 "MapBuffer",
1154 "MapBufferRange",
1155 "Chromium",
1156 };
1157 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1158 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1159 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1160 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1161 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1162
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001163 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001164 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001165 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001166 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001167 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1168 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001169 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1170 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001171 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
1172 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
1173 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1174 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1175 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1176 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001177
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001178 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1179 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1180 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1181 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1182 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1183 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001184 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001185 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001186 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1187 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1188 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -07001189 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001190 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001191 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001192 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001193 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1194 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001195 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001196 return r;
1197}
1198
jvanverthe9c0fc62015-04-29 11:18:05 -07001199static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1200 switch (p) {
1201 case kLow_GrSLPrecision:
1202 return GR_GL_LOW_FLOAT;
1203 case kMedium_GrSLPrecision:
1204 return GR_GL_MEDIUM_FLOAT;
1205 case kHigh_GrSLPrecision:
1206 return GR_GL_HIGH_FLOAT;
1207 }
1208 SkFAIL("Unknown precision.");
1209 return -1;
1210}
1211
1212static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1213 switch (type) {
1214 case kVertex_GrShaderType:
1215 return GR_GL_VERTEX_SHADER;
1216 case kGeometry_GrShaderType:
1217 return GR_GL_GEOMETRY_SHADER;
1218 case kFragment_GrShaderType:
1219 return GR_GL_FRAGMENT_SHADER;
1220 }
1221 SkFAIL("Unknown shader type.");
1222 return -1;
1223}
1224
jvanverthcba99b82015-06-24 06:59:57 -07001225void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1226 const GrGLInterface* intf,
1227 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001228 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1229 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1230 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1231 if (kGeometry_GrShaderType != s) {
1232 GrShaderType shaderType = static_cast<GrShaderType>(s);
1233 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001234 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001235 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001236 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1237 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1238 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1239 GrGLint range[2];
1240 GrGLint bits;
1241 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1242 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001243 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1244 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1245 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001246 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001247 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001248 }
jvanverthcba99b82015-06-24 06:59:57 -07001249 else if (!glslCaps->fShaderPrecisionVaries) {
1250 glslCaps->fShaderPrecisionVaries =
1251 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001252 }
1253 }
1254 }
1255 }
1256 }
1257 }
1258 else {
1259 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001260 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001261 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1262 if (kGeometry_GrShaderType != s) {
1263 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001264 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1265 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1266 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001267 }
1268 }
1269 }
1270 }
1271 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1272 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1273 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1274 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001275 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001276 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001277 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1278 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001279 }
1280 }
1281}
1282
1283
1284
1285