blob: 0591f188a56b8ee028fa2ce89a6efba70025d49b [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
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000012#include "GrGLContext.h"
jvanverthcba99b82015-06-24 06:59:57 -070013#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000014#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000015#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000016
bsalomon682c2692015-05-22 14:01:46 -070017GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
18 const GrGLContextInfo& ctxInfo,
19 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000020 fVerifiedColorConfigs.reset();
21 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000022 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;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 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 fUnpackRowLengthSupport = true;
98 fUnpackFlipYSupport = false;
99 fPackRowLengthSupport = true;
100 fPackFlipYSupport = false;
101 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000102 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
103 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000105 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
106 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107 fPackFlipYSupport =
108 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
109 }
110
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000111 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000112 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
113
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000114 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000115 // The EXT version can apply to either GL or GLES.
116 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
117 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
118 ctxInfo.hasExtension("GL_EXT_texture_storage");
119 } else {
120 // Qualcomm Adreno drivers appear to have issues with texture storage.
121 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
122 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
123 ctxInfo.hasExtension("GL_EXT_texture_storage");
124 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000125
cdaltonfd4167d2015-04-21 11:45:56 -0700126 if (kGL_GrGLStandard == standard) {
127 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
128 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
129 ctxInfo.hasExtension("GL_NV_texture_barrier");
130 } else {
131 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
132 }
133
hendrikwa0d5ad72014-12-02 07:30:30 -0800134 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
135 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700136 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800137 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000138 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
139 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800140 } else {
141 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
142 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000143 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000144 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000145 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000146 ctxInfo.hasExtension("GL_ARB_imaging");
147
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000148 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
149 // ReadPixels. The other format has to checked at run-time since it
150 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000151 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000152
bsalomon16921ec2015-07-30 15:34:56 -0700153 // We only enable srgb support if both textures and FBOs support srgb.
154 bool srgbSupport = false;
155 if (kGL_GrGLStandard == standard) {
156 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
157 srgbSupport = true;
158 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
159 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
160 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
161 srgbSupport = true;
162 }
163 }
164 // All the above srgb extensions support toggling srgb writes
165 fSRGBWriteControl = srgbSupport;
166 } else {
bsalomon58b43952015-07-30 16:27:50 -0700167 // See http://skbug.com/4148 for PowerVR issue.
168 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
169 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
bsalomon16921ec2015-07-30 15:34:56 -0700170 // ES through 3.1 requires EXT_srgb_write_control to support toggling
171 // sRGB writing for destinations.
172 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
173 }
174
rmistry63a9f842014-10-17 06:07:08 -0700175 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000176 // Known issue on at least some Intel platforms:
177 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700178 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000179 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
180 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
181 }
182
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000183 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
184 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
185 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
186 // limit this decision to specific GPU families rather than basing it on the vendor alone.
187 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700188 (kARM_GrGLVendor == ctxInfo.vendor() ||
189 kImagination_GrGLVendor == ctxInfo.vendor() ||
190 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000191 fUseNonVBOVertexAndIndexDynamicData = true;
192 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000193
egdaniel9250d242015-05-18 13:04:26 -0700194 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
195 // Thus we are blacklisting this extension for now on Adreno4xx devices.
196 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
197 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
198 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
199 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000200 fDiscardRenderTargetSupport = true;
201 fInvalidateFBType = kInvalidate_InvalidateFBType;
202 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
203 fDiscardRenderTargetSupport = true;
204 fInvalidateFBType = kDiscard_InvalidateFBType;
205 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000206
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000207 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
208 fFullClearIsFree = true;
209 }
210
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000211 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000212 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800213 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
214 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000215 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000216 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
217 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000218 }
219
cdalton626e1ff2015-06-12 13:56:46 -0700220 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
221 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
222 fInstancedDrawingSupport = true;
223 } else {
224 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
225 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
226 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
227 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
228 }
229
230 if (kGL_GrGLStandard == standard) {
231 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
232 } else {
233 fDirectStateAccessSupport = false;
234 }
235
236 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
237 fDebugSupport = true;
238 } else {
239 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
240 }
241
jvanverth3f801cb2014-12-16 09:49:38 -0800242 if (kGL_GrGLStandard == standard) {
243 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
244 }
245 else {
246 fES2CompatibilitySupport = true;
247 }
248
cdalton0edea2c2015-05-21 08:27:44 -0700249 if (kGL_GrGLStandard == standard) {
250 fMultisampleDisableSupport = true;
251 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700252 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700253 }
254
kkinnunend94708e2015-07-30 22:47:04 -0700255 if (kGL_GrGLStandard == standard) {
256 if (version >= GR_GL_VER(3, 0)) {
257 fBindFragDataLocationSupport = true;
258 }
259 } else {
260 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
261 fBindFragDataLocationSupport = true;
262 }
joshualittc1f56b52015-06-22 12:31:31 -0700263 }
264
kkinnunen177519e2015-10-28 06:18:35 -0700265#if 0 // Disabled due to http://skbug.com/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700266 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
kkinnunen177519e2015-10-28 06:18:35 -0700267#else
268 fBindUniformLocationSupport = false;
269#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700270
bsalomon88c7b982015-07-31 11:20:16 -0700271#ifdef SK_BUILD_FOR_WIN
272 // We're assuming that on Windows Chromium we're using ANGLE.
273 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
274 kChromium_GrGLDriver == ctxInfo.driver();
275 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
276 fRGBA8888PixelsOpsAreSlow = isANGLE;
277 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
278 // check DX11 ANGLE.
279 fPartialFBOReadIsSlow = isANGLE;
280#endif
281
cdalton4cd67132015-06-10 19:23:46 -0700282 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700283 * GrShaderCaps fields
284 **************************************************************************/
285
egdaniel0a482332015-10-26 08:59:10 -0700286 // This must be called after fCoreProfile is set on the GrGLCaps
287 this->initGLSL(ctxInfo);
288 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
289
egdaniel05ded892015-10-26 07:38:05 -0700290 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
291
292 // For now these two are equivalent but we could have dst read in shader via some other method.
293 // Before setting this, initGLSL() must have been called.
294 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
295
296 // Enable supported shader-related caps
297 if (kGL_GrGLStandard == standard) {
298 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
299 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
300 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
301 glslCaps->fShaderDerivativeSupport = true;
302 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
303 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
304 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
305 }
306 else {
307 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
308
309 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
310 ctxInfo.hasExtension("GL_OES_standard_derivatives");
311 }
312
313 // We need dual source blending and the ability to disable multisample in order to support mixed
314 // samples in every corner case.
315 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) {
316 // We understand "mixed samples" to mean the collective capability of 3 different extensions
317 glslCaps->fMixedSamplesSupport =
318 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
319 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
320 ctxInfo.hasExtension("GL_EXT_raster_multisample");
321 }
322 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
323 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSupport()) {
324 fDiscardRenderTargetSupport = false;
325 fInvalidateFBType = kNone_InvalidateFBType;
326 }
cdalton98cad622015-11-03 09:33:21 -0800327
328 if (kGL_GrGLStandard == standard) {
329 glslCaps->fProgrammableSampleLocationsSupport =
330 ctxInfo.version() >= GR_GL_VER(4, 3) &&
331 (ctxInfo.hasExtension("GL_ARB_sample_locations") ||
332 ctxInfo.hasExtension("GL_NV_sample_locations"));
333 } else {
334 glslCaps->fProgrammableSampleLocationsSupport =
335 ctxInfo.version() >= GR_GL_VER(3, 1) &&
336 ctxInfo.hasExtension("GL_NV_sample_locations");
337 }
egdaniel05ded892015-10-26 07:38:05 -0700338
339 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700340 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000341 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700342
egdaniel05ded892015-10-26 07:38:05 -0700343 // fPathRenderingSupport and fMixedSampleSupport must be set before calling initFSAASupport.
344 // Both of these are set in the GrShaderCaps.
cdalton4cd67132015-06-10 19:23:46 -0700345 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700346 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700347 this->initStencilFormats(ctxInfo);
348
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000349 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000350 // we could also look for GL_ATI_separate_stencil extension or
351 // GL_EXT_stencil_two_side but they use different function signatures
352 // than GL2.0+ (and than each other).
353 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
354 // supported on GL 1.4 and higher or by extension
355 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
356 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
357 } else {
358 // ES 2 has two sided stencil and stencil wrap
359 fTwoSidedStencilSupport = true;
360 fStencilWrapOpsSupport = true;
361 }
362
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000363 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000364 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
365 // extension includes glMapBuffer.
366 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
367 fMapBufferFlags |= kSubset_MapFlag;
368 fMapBufferType = kMapBufferRange_MapBufferType;
369 } else {
370 fMapBufferType = kMapBuffer_MapBufferType;
371 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000372 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000373 // Unextended GLES2 doesn't have any buffer mapping.
374 fMapBufferFlags = kNone_MapBufferType;
375 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
376 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
377 fMapBufferType = kChromium_MapBufferType;
378 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
379 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
380 fMapBufferType = kMapBufferRange_MapBufferType;
381 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
382 fMapBufferFlags = kCanMap_MapFlag;
383 fMapBufferType = kMapBuffer_MapBufferType;
384 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000385 }
386
joshualitte5b74c62015-06-01 14:17:47 -0700387 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
388 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
389 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700390 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
391 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
392 // a small subset.
393#if 0
cdalton1acea862015-06-02 13:05:52 -0700394 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700395#else
396 fGeometryBufferMapThreshold = SK_MaxS32;
397#endif
joshualitte5b74c62015-06-01 14:17:47 -0700398 }
399
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000400 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000401 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
402 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
403 fNPOTTextureTileSupport = true;
404 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000405 } else {
406 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000407 // ES3 has no limitations.
408 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
409 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000410 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
411 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
412 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
413 // to alllow arbitrary wrap modes, however.
414 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000415 }
416
bsalomone72bd022015-10-26 07:33:03 -0700417 // Using MIPs on this GPU seems to be a source of trouble.
418 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
419 fMipMapSupport = false;
420 }
421
bsalomon@google.combcce8922013-03-25 15:38:39 +0000422 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
423 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
424 // Our render targets are always created with textures as the color
425 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000426 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000427
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000428 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
429
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000430 // Disable scratch texture reuse on Mali and Adreno devices
431 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
432 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000433
robertphillips1b8e1b52015-06-24 06:54:10 -0700434#if 0
435 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
436 kQualcomm_GrGLVendor != ctxInfo.vendor();
437#endif
438
egdaniel05ded892015-10-26 07:38:05 -0700439 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000440 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000441 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
442 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
443 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
444 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000445
bsalomon63b21962014-11-05 07:05:34 -0800446 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800447 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800448 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800449 fUseDrawInsteadOfClear = true;
450 }
451
joshualitt83bc2292015-06-18 14:18:02 -0700452 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
453 fUseDrawInsteadOfPartialRenderTargetWrite = true;
454 }
455
robertphillips63926682015-08-20 09:39:02 -0700456#ifdef SK_BUILD_FOR_WIN
457 // On ANGLE deferring flushes can lead to GPU starvation
458 fPreferVRAMUseOverFlushes = !isANGLE;
459#endif
460
bsalomon7dea7b72015-08-19 08:26:51 -0700461 if (kChromium_GrGLDriver == ctxInfo.driver()) {
462 fMustClearUploadedBufferData = true;
463 }
464
bsalomond08ea5f2015-02-20 06:58:13 -0800465 if (kGL_GrGLStandard == standard) {
466 // ARB allows mixed size FBO attachments, EXT does not.
467 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
468 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
469 fOversizedStencilSupport = true;
470 } else {
471 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
472 }
473 } else {
474 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
475 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
476 }
477
joshualitt58001552015-06-26 12:46:36 -0700478 if (kGL_GrGLStandard == standard) {
479 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
480 // instanced arrays, but we could make this more granular if we wanted
481 fSupportsInstancedDraws =
482 version >= GR_GL_VER(3, 2) ||
483 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
484 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
485 } else {
486 fSupportsInstancedDraws =
487 version >= GR_GL_VER(3, 0) ||
488 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
489 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
490 }
491
bsalomon16921ec2015-07-30 15:34:56 -0700492 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
493 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700494 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
egdanielb7e7d572015-11-04 04:23:53 -0800495 // Requires fTexutreSwizzleSupport and fTextureRedSupport to be set before this point.
496 this->initConfigSwizzleTable(ctxInfo, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700497
498 this->applyOptionsOverrides(contextOptions);
499 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000500}
501
egdaniel472d44e2015-10-22 08:20:00 -0700502const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
503 bool isCoreProfile) {
504 switch (generation) {
505 case k110_GrGLSLGeneration:
506 if (kGLES_GrGLStandard == standard) {
507 // ES2s shader language is based on version 1.20 but is version
508 // 1.00 of the ES language.
509 return "#version 100\n";
510 } else {
511 SkASSERT(kGL_GrGLStandard == standard);
512 return "#version 110\n";
513 }
514 case k130_GrGLSLGeneration:
515 SkASSERT(kGL_GrGLStandard == standard);
516 return "#version 130\n";
517 case k140_GrGLSLGeneration:
518 SkASSERT(kGL_GrGLStandard == standard);
519 return "#version 140\n";
520 case k150_GrGLSLGeneration:
521 SkASSERT(kGL_GrGLStandard == standard);
522 if (isCoreProfile) {
523 return "#version 150\n";
524 } else {
525 return "#version 150 compatibility\n";
526 }
527 case k330_GrGLSLGeneration:
528 if (kGLES_GrGLStandard == standard) {
529 return "#version 300 es\n";
530 } else {
531 SkASSERT(kGL_GrGLStandard == standard);
532 if (isCoreProfile) {
533 return "#version 330\n";
534 } else {
535 return "#version 330 compatibility\n";
536 }
537 }
538 case k310es_GrGLSLGeneration:
539 SkASSERT(kGLES_GrGLStandard == standard);
540 return "#version 310 es\n";
541 }
542 return "<no version>";
543}
544
egdaniel05ded892015-10-26 07:38:05 -0700545void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700546 GrGLStandard standard = ctxInfo.standard();
547 GrGLVersion version = ctxInfo.version();
548
549 /**************************************************************************
550 * Caps specific to GrGLSLCaps
551 **************************************************************************/
552
553 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
554 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
555
556 if (kGLES_GrGLStandard == standard) {
557 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
558 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
559 glslCaps->fFBFetchSupport = true;
560 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
561 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
562 }
563 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
564 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
565 glslCaps->fFBFetchNeedsCustomOutput = false;
566 glslCaps->fFBFetchSupport = true;
567 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
568 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
569 }
570 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
571 // The arm extension also requires an additional flag which we will set onResetContext
572 glslCaps->fFBFetchNeedsCustomOutput = false;
573 glslCaps->fFBFetchSupport = true;
574 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
575 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
576 }
577 glslCaps->fUsesPrecisionModifiers = true;
578 }
579
580 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
581
582 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
583 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
584
585 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
586 // function that may require a gradient calculation inside a conditional block may return
587 // undefined results". This appears to be an issue with the 'any' call since even the simple
588 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
589 // from our GrTextureDomain processor.
590 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
591
egdanielcae00852015-10-22 11:08:08 -0700592 glslCaps->fForceHighPrecisionNDSTransform = kARM_GrGLVendor == ctxInfo.vendor() ||
593 kPowerVR54x_GrGLRenderer == ctxInfo.renderer();
egdaniel472d44e2015-10-22 08:20:00 -0700594
595 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
596 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800597
598 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
599 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
600 }
egdaniel472d44e2015-10-22 08:20:00 -0700601}
602
kkinnunencfe62e32015-07-01 02:58:50 -0700603bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700604 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
605
606 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700607 return false;
608 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700609
kkinnunencfe62e32015-07-01 02:58:50 -0700610 if (kGL_GrGLStandard == ctxInfo.standard()) {
611 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
612 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
613 return false;
614 }
615 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700616 if (!hasChromiumPathRendering &&
617 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700618 return false;
619 }
620 }
621 // We only support v1.3+ of GL_NV_path_rendering which allows us to
622 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
623 // additions are detected by checking the existence of the function.
624 // We also use *Then* functions that not all drivers might have. Check
625 // them for consistency.
halcanary96fcdcc2015-08-27 07:41:13 -0700626 if (nullptr == gli->fFunctions.fStencilThenCoverFillPath ||
627 nullptr == gli->fFunctions.fStencilThenCoverStrokePath ||
628 nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
629 nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
630 nullptr == gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700631 return false;
632 }
633 return true;
634}
635
bsalomon16921ec2015-07-30 15:34:56 -0700636void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000637 // OpenGL < 3.0
638 // no support for render targets unless the GL_ARB_framebuffer_object
639 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
640 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
641 // probably don't get R8 in this case.
642
643 // OpenGL 3.0
644 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
645 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
646
647 // >= OpenGL 3.1
648 // base color renderable: RED, RG, RGB, and RGBA
649 // sized derivatives: R8, RGBA4, RGBA8
650 // if the GL_ARB_compatibility extension is supported then we get back
651 // support for GL_ALPHA and ALPHA8
652
653 // GL_EXT_bgra adds BGRA render targets to any version
654
655 // ES 2.0
656 // color renderable: RGBA4, RGB5_A1, RGB565
657 // GL_EXT_texture_rg adds support for R8 as a color render target
658 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
659 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
660
661 // ES 3.0
662 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
663 // below already account for this).
664
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000665 GrGLStandard standard = ctxInfo.standard();
666
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000667 enum {
668 kNo_MSAA = 0,
669 kYes_MSAA = 1,
670 };
671
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000672 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000673 // Post 3.0 we will get R8
674 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
675 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
676 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000677 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
678 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000679 }
680 } else {
681 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000682 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
683 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000684 }
685
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000686 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000687 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000688 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
689 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000690 }
691
692 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000693 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
694 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000695
696 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000697 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000698 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000699 }
700
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000701 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000702 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
703 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
704 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000705 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000706 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000707 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
708 } else {
709 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
710 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
711 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000712 }
713
bsalomon16921ec2015-07-30 15:34:56 -0700714 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
715 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
716 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
jvanverthfa1e8a72014-12-22 08:31:49 -0800717 }
718
joshualittee5da552014-07-16 13:32:56 -0700719 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800720 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800721 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800722 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
723 } else {
joshualitt55999962015-06-18 13:47:10 -0700724 // for now we only enable this on desktop, because on ES we'd have to solve many
725 // precision issues and no clients actually want this yet
726 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800727 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
728 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
729 } else {
730 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
731 }
732 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700733 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
734 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700735 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800736 }
joshualittee5da552014-07-16 13:32:56 -0700737 }
738
jvanverth28f9c602014-12-05 13:06:35 -0800739 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800740 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800741 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800742 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800743 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
744 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
745 // for now we don't support floating point MSAA on ES
746 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800747 } else {
jvanverth1334c212014-12-18 05:44:55 -0800748 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
749 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
750 } else {
751 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
752 }
753 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800754 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
755 }
756 }
757
jvanverthfb5df432015-05-21 08:12:27 -0700758 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
759 if (kGL_GrGLStandard == standard) {
760 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
761 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
762 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
763 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
764 // for now we don't support floating point MSAA on ES
765 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
766 } else {
767 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
768 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
769 } else {
770 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
771 }
772 // for now we don't support floating point MSAA on ES
773 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
774 }
775 }
776
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000777 // If we don't support MSAA then undo any places above where we set a config as renderable with
778 // msaa.
779 if (kNone_MSFBOType == fMSFBOType) {
780 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
781 fConfigRenderSupport[i][kYes_MSAA] = false;
782 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000783 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000784}
785
bsalomon16921ec2015-07-30 15:34:56 -0700786void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
787 bool srgbSupport) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000788 GrGLStandard standard = ctxInfo.standard();
789 GrGLVersion version = ctxInfo.version();
790
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000791 // Base texture support
792 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
793 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
794 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
795 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
796
reed56f38fb2015-09-14 09:09:00 -0700797 // Disable this for now, while we investigate skbug.com/4333
798 if (false) {
799 // Check for 8-bit palette..
800 GrGLint numFormats;
801 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
802 if (numFormats) {
803 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
804 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
805 for (int i = 0; i < numFormats; ++i) {
806 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
807 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
808 break;
809 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000810 }
811 }
812 }
813
814 // Check for BGRA
815 if (kGL_GrGLStandard == standard) {
816 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
817 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
818 } else {
819 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
820 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
821 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
822 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
823 fBGRAIsInternalFormat = true;
824 }
825 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
826 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
827 }
828
bsalomon16921ec2015-07-30 15:34:56 -0700829 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
jvanverthfa1e8a72014-12-22 08:31:49 -0800830
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000831 // Compressed texture support
832
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000833 // glCompressedTexImage2D is available on all OpenGL ES devices...
834 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000835 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000836
krajcevski786978162014-07-30 11:25:44 -0700837 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700838 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700839
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000840 // Check for ETC1
841 bool hasETC1 = false;
842
843 // First check version for support
844 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000845 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700846 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000847 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000848 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000849 hasETC1 = hasCompressTex2D &&
850 (version >= GR_GL_VER(3, 0) ||
851 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
852 // ETC2 is a superset of ETC1, so we can just check for that, too.
853 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
854 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000855 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000856 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000857
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000858 // Check for LATC under its various forms
859 LATCAlias alias = kLATC_LATCAlias;
860 bool hasLATC = hasCompressTex2D &&
861 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
862 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
863
864 // Check for RGTC
865 if (!hasLATC) {
866 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
867 if (kGL_GrGLStandard == standard) {
868 hasLATC = version >= GR_GL_VER(3, 0);
869 }
870
871 if (!hasLATC) {
872 hasLATC =
873 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
874 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
875 }
876
877 if (hasLATC) {
878 alias = kRGTC_LATCAlias;
879 }
880 }
881
882 // Check for 3DC
883 if (!hasLATC) {
884 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
885 if (hasLATC) {
886 alias = k3DC_LATCAlias;
887 }
888 }
889
890 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
891 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700892
krajcevskib3abe902014-07-30 13:08:11 -0700893 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
894 // cards default to decompressing the textures in the driver, and is
895 // generally slower.
896 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700897 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
898 }
joshualittee5da552014-07-16 13:32:56 -0700899
krajcevski7ef21622014-07-16 15:21:13 -0700900 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700901 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700902 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
903 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
904 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
905
joshualittee5da552014-07-16 13:32:56 -0700906 // Check for floating point texture support
907 // NOTE: We disallow floating point textures on ES devices if linear
908 // filtering modes are not supported. This is for simplicity, but a more
909 // granular approach is possible. Coincidentally, floating point textures became part of
910 // the standard in ES3.1 / OGL 3.1, hence the shorthand
911 bool hasFPTextures = version >= GR_GL_VER(3, 1);
912 if (!hasFPTextures) {
913 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800914 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700915 ctxInfo.hasExtension("GL_OES_texture_float"));
916 }
917 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800918
919 // Check for fp16 texture support
920 // NOTE: We disallow floating point textures on ES devices if linear
921 // filtering modes are not supported. This is for simplicity, but a more
922 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
923 // the standard in ES3.1 / OGL 3.1, hence the shorthand
924 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
925 if (!hasHalfFPTextures) {
926 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800927 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
928 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800929 }
jvanverth1334c212014-12-18 05:44:55 -0800930 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700931 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000932}
933
piotaixre4b23142014-10-02 10:57:53 -0700934bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
935 GrGLenum format,
936 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000937 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
938 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000939 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000940 }
941
942 if (!fTwoFormatLimit) {
943 // not limited by ES 2's constraints
944 return true;
945 }
946
bsalomon@google.com548a4332012-07-11 19:45:22 +0000947 GrGLint otherFormat = GR_GL_RGBA;
948 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000949
950 // The other supported format/type combo supported for ReadPixels
951 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000952 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000953 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
954 &otherFormat);
955
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000956 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000957 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
958 &otherType);
959
bsalomon@google.com548a4332012-07-11 19:45:22 +0000960 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000961}
962
piotaixre4b23142014-10-02 10:57:53 -0700963bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
964 GrGLenum format,
965 GrGLenum type,
966 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800967 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
968 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
969 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700970 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800971 bool supported = this->doReadPixelsSupported(intf, format, type);
972 fReadPixelsSupportedCache.set(key, supported);
973 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700974}
975
robertphillips@google.com6177e692013-02-28 20:16:25 +0000976void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000977
978 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000979 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000980 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
981 // ES3 driver bugs on at least one device with a tiled GPU (N10).
982 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
983 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
984 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
985 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
vbuzinovdded6962015-06-12 08:59:45 -0700986 } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
987 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000988 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000989 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
990 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
991 // chrome's extension is equivalent to the EXT msaa
992 // and fbo_blit extensions.
993 fMSFBOType = kDesktop_EXT_MSFBOType;
994 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
995 fMSFBOType = kES_Apple_MSFBOType;
996 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000997 } else {
vbuzinovdded6962015-06-12 08:59:45 -0700998 if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
999 fMSFBOType = kMixedSamples_MSFBOType;
1000 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001001 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001002 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001003 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1004 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001005 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001006 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001007 }
1008}
1009
cdalton1dd05422015-06-12 09:01:18 -07001010void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
1011 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
1012
1013 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
1014 // for now until its own blacklists can be updated.
1015 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
1016 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -07001017 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -07001018 return;
1019 }
1020
1021 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1022 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1023 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1024 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
1025 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1026 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1027 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1028 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
1029 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
1030 return;
1031 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1032 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1033 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1034 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
1035 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1036 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1037 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1038 // slow on a particular platform.
1039 } else {
1040 return; // No advanced blend support.
1041 }
1042
1043 SkASSERT(this->advancedBlendEquationSupport());
1044
1045 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
1046 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
1047 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
1048 (1 << kColorBurn_GrBlendEquation);
1049 }
joel.liang9764c402015-07-09 19:46:18 -07001050 if (kARM_GrGLVendor == ctxInfo.vendor()) {
1051 // Blacklist color-burn on ARM until the fix is released.
1052 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
1053 }
cdalton1dd05422015-06-12 09:01:18 -07001054}
1055
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001056namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001057const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001058}
1059
1060void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
1061
1062 // Build up list of legal stencil formats (though perhaps not supported on
1063 // the particular gpu/driver) from most preferred to least.
1064
1065 // these consts are in order of most preferred to least preferred
1066 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1067
1068 static const StencilFormat
1069 // internal Format stencil bits total bits packed?
1070 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1071 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1072 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1073 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001074 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001075 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1076
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001077 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001078 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001079 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001080 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1081 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1082
1083 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1084 // require FBO support we can expect these are legal formats and don't
1085 // check. These also all support the unsized GL_STENCIL_INDEX.
1086 fStencilFormats.push_back() = gS8;
1087 fStencilFormats.push_back() = gS16;
1088 if (supportsPackedDS) {
1089 fStencilFormats.push_back() = gD24S8;
1090 }
1091 fStencilFormats.push_back() = gS4;
1092 if (supportsPackedDS) {
1093 fStencilFormats.push_back() = gDS;
1094 }
1095 } else {
1096 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1097 // for other formats.
1098 // ES doesn't support using the unsized format.
1099
1100 fStencilFormats.push_back() = gS8;
1101 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001102 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1103 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001104 fStencilFormats.push_back() = gD24S8;
1105 }
1106 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1107 fStencilFormats.push_back() = gS4;
1108 }
1109 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001110}
1111
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001112SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001113
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001114 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001115
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001116 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001117 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001118 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001119 i,
1120 fStencilFormats[i].fStencilBits,
1121 fStencilFormats[i].fTotalBits);
1122 }
1123
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001124 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001125 "None",
1126 "ARB",
1127 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001128 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001129 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001130 "IMG MS To Texture",
1131 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001132 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001133 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001134 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1135 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1136 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001137 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1138 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1139 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1140 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001141 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001142 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001143
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001144 static const char* kInvalidateFBTypeStr[] = {
1145 "None",
1146 "Discard",
1147 "Invalidate",
1148 };
1149 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1150 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1151 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1152 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001153
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001154 static const char* kMapBufferTypeStr[] = {
1155 "None",
1156 "MapBuffer",
1157 "MapBufferRange",
1158 "Chromium",
1159 };
1160 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1161 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1162 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1163 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1164 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1165
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001166 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001167 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001168 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001169 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001170 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1171 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001172 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1173 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001174 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001175 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1176 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1177 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1178 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001179
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001180 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1181 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1182 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1183 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1184 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1185 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001186 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001187 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001188 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1189 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1190 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -07001191 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001192 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001193 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001194 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001195 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1196 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001197 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001198 return r;
1199}
1200
jvanverthe9c0fc62015-04-29 11:18:05 -07001201static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1202 switch (p) {
1203 case kLow_GrSLPrecision:
1204 return GR_GL_LOW_FLOAT;
1205 case kMedium_GrSLPrecision:
1206 return GR_GL_MEDIUM_FLOAT;
1207 case kHigh_GrSLPrecision:
1208 return GR_GL_HIGH_FLOAT;
1209 }
1210 SkFAIL("Unknown precision.");
1211 return -1;
1212}
1213
1214static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1215 switch (type) {
1216 case kVertex_GrShaderType:
1217 return GR_GL_VERTEX_SHADER;
1218 case kGeometry_GrShaderType:
1219 return GR_GL_GEOMETRY_SHADER;
1220 case kFragment_GrShaderType:
1221 return GR_GL_FRAGMENT_SHADER;
1222 }
1223 SkFAIL("Unknown shader type.");
1224 return -1;
1225}
1226
jvanverthcba99b82015-06-24 06:59:57 -07001227void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1228 const GrGLInterface* intf,
1229 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001230 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1231 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1232 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1233 if (kGeometry_GrShaderType != s) {
1234 GrShaderType shaderType = static_cast<GrShaderType>(s);
1235 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001236 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001237 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001238 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1239 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1240 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1241 GrGLint range[2];
1242 GrGLint bits;
1243 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1244 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001245 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1246 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1247 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001248 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001249 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001250 }
jvanverthcba99b82015-06-24 06:59:57 -07001251 else if (!glslCaps->fShaderPrecisionVaries) {
1252 glslCaps->fShaderPrecisionVaries =
1253 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001254 }
1255 }
1256 }
1257 }
1258 }
1259 }
1260 else {
1261 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001262 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001263 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1264 if (kGeometry_GrShaderType != s) {
1265 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001266 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1267 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1268 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001269 }
1270 }
1271 }
1272 }
1273 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1274 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1275 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1276 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001277 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001278 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001279 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1280 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001281 }
1282 }
1283}
1284
egdanielb7e7d572015-11-04 04:23:53 -08001285void GrGLCaps::initConfigSwizzleTable(const GrGLContextInfo& ctxInfo, GrGLSLCaps* glslCaps) {
1286 GrGLStandard standard = ctxInfo.standard();
1287 GrGLVersion version = ctxInfo.version();
jvanverthe9c0fc62015-04-29 11:18:05 -07001288
egdanielb7e7d572015-11-04 04:23:53 -08001289 glslCaps->fMustSwizzleInShader = true;
1290 if (kGL_GrGLStandard == standard) {
1291 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
1292 glslCaps->fMustSwizzleInShader = false;
1293 }
1294 } else {
1295 if (version >= GR_GL_VER(3,0)) {
1296 glslCaps->fMustSwizzleInShader = false;
1297 }
1298 }
1299
1300 glslCaps->fConfigSwizzle[kUnknown_GrPixelConfig] = nullptr;
1301 if (fTextureRedSupport) {
1302 glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "rrrr";
1303 glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "rrrr";
1304 } else {
1305 glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "aaaa";
1306 glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "aaaa";
1307 }
1308 glslCaps->fConfigSwizzle[kIndex_8_GrPixelConfig] = "rgba";
1309 glslCaps->fConfigSwizzle[kRGB_565_GrPixelConfig] = "rgba";
1310 glslCaps->fConfigSwizzle[kRGBA_4444_GrPixelConfig] = "rgba";
1311 glslCaps->fConfigSwizzle[kRGBA_8888_GrPixelConfig] = "rgba";
1312 glslCaps->fConfigSwizzle[kBGRA_8888_GrPixelConfig] = "rgba";
1313 glslCaps->fConfigSwizzle[kSRGBA_8888_GrPixelConfig] = "rgba";
1314 glslCaps->fConfigSwizzle[kETC1_GrPixelConfig] = "rgba";
1315 glslCaps->fConfigSwizzle[kLATC_GrPixelConfig] = "rrrr";
1316 glslCaps->fConfigSwizzle[kR11_EAC_GrPixelConfig] = "rrrr";
1317 glslCaps->fConfigSwizzle[kASTC_12x12_GrPixelConfig] = "rgba";
1318 glslCaps->fConfigSwizzle[kRGBA_float_GrPixelConfig] = "rgba";
1319 glslCaps->fConfigSwizzle[kRGBA_half_GrPixelConfig] = "rgba";
1320
1321}
1322
1323void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}
jvanverthe9c0fc62015-04-29 11:18:05 -07001324
1325