blob: 2b19f1314d6c4592394d237e1fa74968a8949178 [file] [log] [blame]
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#include "GrGLCaps.h"
joshualittb4384b92014-10-21 12:53:15 -070010
robertphillips@google.com6177e692013-02-28 20:16:25 +000011#include "GrGLContext.h"
jvanverthcba99b82015-06-24 06:59:57 -070012#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000013#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000014#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000015
bsalomon682c2692015-05-22 14:01:46 -070016GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
17 const GrGLContextInfo& ctxInfo,
18 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000019 fVerifiedColorConfigs.reset();
20 fStencilFormats.reset();
21 fStencilVerifiedColorConfigs.reset();
22 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000023 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070024 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000025 fMapBufferType = kNone_MapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000027 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000028 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 fBGRAIsInternalFormat = false;
31 fTextureSwizzleSupport = false;
32 fUnpackRowLengthSupport = false;
33 fUnpackFlipYSupport = false;
34 fPackRowLengthSupport = false;
35 fPackFlipYSupport = false;
36 fTextureUsageSupport = false;
37 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000038 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000039 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000040 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000041 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000042 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070043 fInstancedDrawingSupport = false;
44 fDirectStateAccessSupport = false;
45 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080046 fES2CompatibilitySupport = false;
cdalton0edea2c2015-05-21 08:27:44 -070047 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000048 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000049 fIsCoreProfile = false;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000050 fFullClearIsFree = false;
joshualittc1f56b52015-06-22 12:31:31 -070051 fBindFragDataLocationSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070052 fSRGBWriteControl = false;
piotaixre4b23142014-10-02 10:57:53 -070053
54 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070055
jvanverthcba99b82015-06-24 06:59:57 -070056 fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions)));
bsalomon4ee6bd82015-05-27 13:23:23 -070057
cdalton4cd67132015-06-10 19:23:46 -070058 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059}
60
cdalton4cd67132015-06-10 19:23:46 -070061void GrGLCaps::init(const GrContextOptions& contextOptions,
62 const GrGLContextInfo& ctxInfo,
63 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000064 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000065 GrGLVersion version = ctxInfo.version();
66
bsalomon@google.combcce8922013-03-25 15:38:39 +000067 /**************************************************************************
cdalton4cd67132015-06-10 19:23:46 -070068 * Caps specific to GrGLSLCaps
69 **************************************************************************/
70
71 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
72 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
73
74 if (kGLES_GrGLStandard == standard) {
75 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
76 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
77 glslCaps->fFBFetchSupport = true;
78 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
79 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
80 }
81 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
82 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
83 glslCaps->fFBFetchNeedsCustomOutput = false;
84 glslCaps->fFBFetchSupport = true;
85 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
86 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
87 }
88 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
89 // The arm extension also requires an additional flag which we will set onResetContext
90 glslCaps->fFBFetchNeedsCustomOutput = false;
91 glslCaps->fFBFetchSupport = true;
92 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
93 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
94 }
95 }
96
cdalton626e1ff2015-06-12 13:56:46 -070097 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
98
cdalton4cd67132015-06-10 19:23:46 -070099 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
100 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
101
102 /**************************************************************************
bsalomon@google.combcce8922013-03-25 15:38:39 +0000103 * Caps specific to GrGLCaps
104 **************************************************************************/
105
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000106 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000107 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
108 &fMaxFragmentUniformVectors);
109 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000110 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 GrGLint max;
112 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
113 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000114 if (version >= GR_GL_VER(3, 2)) {
115 GrGLint profileMask;
116 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
117 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
118 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000119 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000120 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000121 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000122
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000123 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124 fRGBA8RenderbufferSupport = true;
125 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000126 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
127 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000128 ctxInfo.hasExtension("GL_ARM_rgba8");
129 }
130
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000131 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000132 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
133 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
134 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000135 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000136 }
137
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000138 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000139 fUnpackRowLengthSupport = true;
140 fUnpackFlipYSupport = false;
141 fPackRowLengthSupport = true;
142 fPackFlipYSupport = false;
143 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000144 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
145 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000146 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000147 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
148 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000149 fPackFlipYSupport =
150 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
151 }
152
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000153 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000154 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
155
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000156 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000157 // The EXT version can apply to either GL or GLES.
158 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
159 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
160 ctxInfo.hasExtension("GL_EXT_texture_storage");
161 } else {
162 // Qualcomm Adreno drivers appear to have issues with texture storage.
163 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
164 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
165 ctxInfo.hasExtension("GL_EXT_texture_storage");
166 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000167
cdaltonfd4167d2015-04-21 11:45:56 -0700168 if (kGL_GrGLStandard == standard) {
169 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
170 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
171 ctxInfo.hasExtension("GL_NV_texture_barrier");
172 } else {
173 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
174 }
175
hendrikwa0d5ad72014-12-02 07:30:30 -0800176 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
177 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700178 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800179 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000180 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
181 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800182 } else {
183 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
184 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000185 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000186 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000187 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000188 ctxInfo.hasExtension("GL_ARB_imaging");
189
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000190 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
191 // ReadPixels. The other format has to checked at run-time since it
192 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000193 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000194
bsalomon16921ec2015-07-30 15:34:56 -0700195 // We only enable srgb support if both textures and FBOs support srgb.
196 bool srgbSupport = false;
197 if (kGL_GrGLStandard == standard) {
198 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
199 srgbSupport = true;
200 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
201 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
202 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
203 srgbSupport = true;
204 }
205 }
206 // All the above srgb extensions support toggling srgb writes
207 fSRGBWriteControl = srgbSupport;
208 } else {
bsalomon58b43952015-07-30 16:27:50 -0700209 // See http://skbug.com/4148 for PowerVR issue.
210 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
211 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
bsalomon16921ec2015-07-30 15:34:56 -0700212 // ES through 3.1 requires EXT_srgb_write_control to support toggling
213 // sRGB writing for destinations.
214 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
215 }
216
rmistry63a9f842014-10-17 06:07:08 -0700217 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000218 // Known issue on at least some Intel platforms:
219 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700220 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000221 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
222 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
223 }
224
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000225 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
226 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
227 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
228 // limit this decision to specific GPU families rather than basing it on the vendor alone.
229 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700230 (kARM_GrGLVendor == ctxInfo.vendor() ||
231 kImagination_GrGLVendor == ctxInfo.vendor() ||
232 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000233 fUseNonVBOVertexAndIndexDynamicData = true;
234 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000235
egdaniel9250d242015-05-18 13:04:26 -0700236 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
237 // Thus we are blacklisting this extension for now on Adreno4xx devices.
238 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
239 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
240 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
241 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000242 fDiscardRenderTargetSupport = true;
243 fInvalidateFBType = kInvalidate_InvalidateFBType;
244 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
245 fDiscardRenderTargetSupport = true;
246 fInvalidateFBType = kDiscard_InvalidateFBType;
247 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000248
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000249 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
250 fFullClearIsFree = true;
251 }
252
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000253 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000254 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800255 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
256 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000257 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000258 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
259 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000260 }
261
cdalton626e1ff2015-06-12 13:56:46 -0700262 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
263 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
264 fInstancedDrawingSupport = true;
265 } else {
266 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
267 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
268 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
269 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
270 }
271
272 if (kGL_GrGLStandard == standard) {
273 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
274 } else {
275 fDirectStateAccessSupport = false;
276 }
277
278 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
279 fDebugSupport = true;
280 } else {
281 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
282 }
283
jvanverth3f801cb2014-12-16 09:49:38 -0800284 if (kGL_GrGLStandard == standard) {
285 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
286 }
287 else {
288 fES2CompatibilitySupport = true;
289 }
290
cdalton0edea2c2015-05-21 08:27:44 -0700291 if (kGL_GrGLStandard == standard) {
292 fMultisampleDisableSupport = true;
293 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700294 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700295 }
296
kkinnunend94708e2015-07-30 22:47:04 -0700297 if (kGL_GrGLStandard == standard) {
298 if (version >= GR_GL_VER(3, 0)) {
299 fBindFragDataLocationSupport = true;
300 }
301 } else {
302 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
303 fBindFragDataLocationSupport = true;
304 }
joshualittc1f56b52015-06-22 12:31:31 -0700305 }
306
cdalton4cd67132015-06-10 19:23:46 -0700307 /**************************************************************************
308 * GrShaderCaps fields
309 **************************************************************************/
310
kkinnunencfe62e32015-07-01 02:58:50 -0700311 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
cdalton4cd67132015-06-10 19:23:46 -0700312
313 // For now these two are equivalent but we could have dst read in shader via some other method
314 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
315
316 // Enable supported shader-related caps
317 if (kGL_GrGLStandard == standard) {
318 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
319 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
320 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
321 glslCaps->fShaderDerivativeSupport = true;
322 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
323 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
324 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
325 }
326 else {
kkinnunend94708e2015-07-30 22:47:04 -0700327 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
328
cdalton4cd67132015-06-10 19:23:46 -0700329 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
330 ctxInfo.hasExtension("GL_OES_standard_derivatives");
331 }
332
333 // We need dual source blending and the ability to disable multisample in order to support mixed
334 // samples in every corner case.
335 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) {
336 // We understand "mixed samples" to mean the collective capability of 3 different extensions
337 glslCaps->fMixedSamplesSupport =
338 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
339 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
340 ctxInfo.hasExtension("GL_EXT_raster_multisample");
341 }
vbuzinovdded6962015-06-12 08:59:45 -0700342 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
343 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSupport()) {
344 fDiscardRenderTargetSupport = false;
345 fInvalidateFBType = kNone_InvalidateFBType;
346 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000347
348 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700349 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000350 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700351
352 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700353 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700354 this->initStencilFormats(ctxInfo);
355
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000356 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000357 // we could also look for GL_ATI_separate_stencil extension or
358 // GL_EXT_stencil_two_side but they use different function signatures
359 // than GL2.0+ (and than each other).
360 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
361 // supported on GL 1.4 and higher or by extension
362 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
363 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
364 } else {
365 // ES 2 has two sided stencil and stencil wrap
366 fTwoSidedStencilSupport = true;
367 fStencilWrapOpsSupport = true;
368 }
369
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000370 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000371 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
372 // extension includes glMapBuffer.
373 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
374 fMapBufferFlags |= kSubset_MapFlag;
375 fMapBufferType = kMapBufferRange_MapBufferType;
376 } else {
377 fMapBufferType = kMapBuffer_MapBufferType;
378 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000379 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000380 // Unextended GLES2 doesn't have any buffer mapping.
381 fMapBufferFlags = kNone_MapBufferType;
382 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
383 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
384 fMapBufferType = kChromium_MapBufferType;
385 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
386 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
387 fMapBufferType = kMapBufferRange_MapBufferType;
388 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
389 fMapBufferFlags = kCanMap_MapFlag;
390 fMapBufferType = kMapBuffer_MapBufferType;
391 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000392 }
393
joshualitte5b74c62015-06-01 14:17:47 -0700394 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
395 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
396 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700397 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
398 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
399 // a small subset.
400#if 0
cdalton1acea862015-06-02 13:05:52 -0700401 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700402#else
403 fGeometryBufferMapThreshold = SK_MaxS32;
404#endif
joshualitte5b74c62015-06-01 14:17:47 -0700405 }
406
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000407 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000408 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
409 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
410 fNPOTTextureTileSupport = true;
411 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000412 } else {
413 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000414 // ES3 has no limitations.
415 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
416 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000417 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
418 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
419 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
420 // to alllow arbitrary wrap modes, however.
421 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000422 }
423
bsalomon@google.combcce8922013-03-25 15:38:39 +0000424 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
425 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
426 // Our render targets are always created with textures as the color
427 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000428 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000429
bsalomonc59a1df2015-06-01 07:13:42 -0700430 // This GPU seems to have problems when tiling small textures
431 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
432 fMinTextureSize = 16;
433 }
434
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000435 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
436
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000437 // Disable scratch texture reuse on Mali and Adreno devices
438 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
439 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000440
robertphillips1b8e1b52015-06-24 06:54:10 -0700441#if 0
442 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
443 kQualcomm_GrGLVendor != ctxInfo.vendor();
444#endif
445
bsalomon@google.com347c3822013-05-01 20:10:01 +0000446 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000447 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
448 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
449 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
450 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000451
bsalomon63b21962014-11-05 07:05:34 -0800452 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800453 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800454 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800455 fUseDrawInsteadOfClear = true;
456 }
457
joshualitt83bc2292015-06-18 14:18:02 -0700458 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
459 fUseDrawInsteadOfPartialRenderTargetWrite = true;
460 }
461
bsalomond08ea5f2015-02-20 06:58:13 -0800462 if (kGL_GrGLStandard == standard) {
463 // ARB allows mixed size FBO attachments, EXT does not.
464 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
465 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
466 fOversizedStencilSupport = true;
467 } else {
468 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
469 }
470 } else {
471 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
472 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
473 }
474
joshualitt58001552015-06-26 12:46:36 -0700475 if (kGL_GrGLStandard == standard) {
476 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
477 // instanced arrays, but we could make this more granular if we wanted
478 fSupportsInstancedDraws =
479 version >= GR_GL_VER(3, 2) ||
480 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
481 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
482 } else {
483 fSupportsInstancedDraws =
484 version >= GR_GL_VER(3, 0) ||
485 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
486 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
487 }
488
bsalomon16921ec2015-07-30 15:34:56 -0700489 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
490 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700491 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700492
493 this->applyOptionsOverrides(contextOptions);
494 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000495}
496
kkinnunencfe62e32015-07-01 02:58:50 -0700497bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700498 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
499
500 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700501 return false;
502 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700503
kkinnunencfe62e32015-07-01 02:58:50 -0700504 if (kGL_GrGLStandard == ctxInfo.standard()) {
505 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
506 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
507 return false;
508 }
509 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700510 if (!hasChromiumPathRendering &&
511 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700512 return false;
513 }
514 }
515 // We only support v1.3+ of GL_NV_path_rendering which allows us to
516 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
517 // additions are detected by checking the existence of the function.
518 // We also use *Then* functions that not all drivers might have. Check
519 // them for consistency.
520 if (NULL == gli->fFunctions.fStencilThenCoverFillPath ||
521 NULL == gli->fFunctions.fStencilThenCoverStrokePath ||
522 NULL == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
523 NULL == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
524 NULL == gli->fFunctions.fProgramPathFragmentInputGen) {
525 return false;
526 }
527 return true;
528}
529
bsalomon16921ec2015-07-30 15:34:56 -0700530void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000531 // OpenGL < 3.0
532 // no support for render targets unless the GL_ARB_framebuffer_object
533 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
534 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
535 // probably don't get R8 in this case.
536
537 // OpenGL 3.0
538 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
539 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
540
541 // >= OpenGL 3.1
542 // base color renderable: RED, RG, RGB, and RGBA
543 // sized derivatives: R8, RGBA4, RGBA8
544 // if the GL_ARB_compatibility extension is supported then we get back
545 // support for GL_ALPHA and ALPHA8
546
547 // GL_EXT_bgra adds BGRA render targets to any version
548
549 // ES 2.0
550 // color renderable: RGBA4, RGB5_A1, RGB565
551 // GL_EXT_texture_rg adds support for R8 as a color render target
552 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
553 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
554
555 // ES 3.0
556 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
557 // below already account for this).
558
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000559 GrGLStandard standard = ctxInfo.standard();
560
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000561 enum {
562 kNo_MSAA = 0,
563 kYes_MSAA = 1,
564 };
565
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000566 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000567 // Post 3.0 we will get R8
568 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
569 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
570 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000571 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
572 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000573 }
574 } else {
575 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000576 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
577 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000578 }
579
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000580 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000581 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000582 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
583 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000584 }
585
586 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000587 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
588 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000589
590 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000591 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000592 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000593 }
594
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000595 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000596 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
597 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
598 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000599 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000600 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000601 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
602 } else {
603 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
604 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
605 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000606 }
607
bsalomon16921ec2015-07-30 15:34:56 -0700608 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
609 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
610 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
jvanverthfa1e8a72014-12-22 08:31:49 -0800611 }
612
joshualittee5da552014-07-16 13:32:56 -0700613 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800614 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800615 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800616 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
617 } else {
joshualitt55999962015-06-18 13:47:10 -0700618 // for now we only enable this on desktop, because on ES we'd have to solve many
619 // precision issues and no clients actually want this yet
620 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800621 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
622 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
623 } else {
624 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
625 }
626 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700627 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
628 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700629 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800630 }
joshualittee5da552014-07-16 13:32:56 -0700631 }
632
jvanverth28f9c602014-12-05 13:06:35 -0800633 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800634 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800635 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800636 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800637 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
638 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
639 // for now we don't support floating point MSAA on ES
640 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800641 } else {
jvanverth1334c212014-12-18 05:44:55 -0800642 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
643 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
644 } else {
645 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
646 }
647 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800648 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
649 }
650 }
651
jvanverthfb5df432015-05-21 08:12:27 -0700652 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
653 if (kGL_GrGLStandard == standard) {
654 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
655 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
656 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
657 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
658 // for now we don't support floating point MSAA on ES
659 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
660 } else {
661 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
662 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
663 } else {
664 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
665 }
666 // for now we don't support floating point MSAA on ES
667 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
668 }
669 }
670
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000671 // If we don't support MSAA then undo any places above where we set a config as renderable with
672 // msaa.
673 if (kNone_MSFBOType == fMSFBOType) {
674 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
675 fConfigRenderSupport[i][kYes_MSAA] = false;
676 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000677 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000678}
679
bsalomon16921ec2015-07-30 15:34:56 -0700680void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
681 bool srgbSupport) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000682 GrGLStandard standard = ctxInfo.standard();
683 GrGLVersion version = ctxInfo.version();
684
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000685 // Base texture support
686 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
687 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
688 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
689 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
690
691 // Check for 8-bit palette..
692 GrGLint numFormats;
693 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
694 if (numFormats) {
695 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
696 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
697 for (int i = 0; i < numFormats; ++i) {
698 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
699 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
700 break;
701 }
702 }
703 }
704
705 // Check for BGRA
706 if (kGL_GrGLStandard == standard) {
707 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
708 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
709 } else {
710 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
711 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
712 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
713 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
714 fBGRAIsInternalFormat = true;
715 }
716 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
717 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
718 }
719
bsalomon16921ec2015-07-30 15:34:56 -0700720 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
jvanverthfa1e8a72014-12-22 08:31:49 -0800721
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000722 // Compressed texture support
723
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000724 // glCompressedTexImage2D is available on all OpenGL ES devices...
725 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000726 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000727
krajcevski786978162014-07-30 11:25:44 -0700728 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700729 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700730
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000731 // Check for ETC1
732 bool hasETC1 = false;
733
734 // First check version for support
735 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000736 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700737 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000738 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000739 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000740 hasETC1 = hasCompressTex2D &&
741 (version >= GR_GL_VER(3, 0) ||
742 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
743 // ETC2 is a superset of ETC1, so we can just check for that, too.
744 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
745 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000746 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000747 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000748
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000749 // Check for LATC under its various forms
750 LATCAlias alias = kLATC_LATCAlias;
751 bool hasLATC = hasCompressTex2D &&
752 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
753 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
754
755 // Check for RGTC
756 if (!hasLATC) {
757 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
758 if (kGL_GrGLStandard == standard) {
759 hasLATC = version >= GR_GL_VER(3, 0);
760 }
761
762 if (!hasLATC) {
763 hasLATC =
764 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
765 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
766 }
767
768 if (hasLATC) {
769 alias = kRGTC_LATCAlias;
770 }
771 }
772
773 // Check for 3DC
774 if (!hasLATC) {
775 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
776 if (hasLATC) {
777 alias = k3DC_LATCAlias;
778 }
779 }
780
781 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
782 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700783
krajcevskib3abe902014-07-30 13:08:11 -0700784 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
785 // cards default to decompressing the textures in the driver, and is
786 // generally slower.
787 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700788 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
789 }
joshualittee5da552014-07-16 13:32:56 -0700790
krajcevski7ef21622014-07-16 15:21:13 -0700791 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700792 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700793 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
794 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
795 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
796
joshualittee5da552014-07-16 13:32:56 -0700797 // Check for floating point texture support
798 // NOTE: We disallow floating point textures on ES devices if linear
799 // filtering modes are not supported. This is for simplicity, but a more
800 // granular approach is possible. Coincidentally, floating point textures became part of
801 // the standard in ES3.1 / OGL 3.1, hence the shorthand
802 bool hasFPTextures = version >= GR_GL_VER(3, 1);
803 if (!hasFPTextures) {
804 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800805 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700806 ctxInfo.hasExtension("GL_OES_texture_float"));
807 }
808 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800809
810 // Check for fp16 texture support
811 // NOTE: We disallow floating point textures on ES devices if linear
812 // filtering modes are not supported. This is for simplicity, but a more
813 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
814 // the standard in ES3.1 / OGL 3.1, hence the shorthand
815 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
816 if (!hasHalfFPTextures) {
817 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800818 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
819 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800820 }
jvanverth1334c212014-12-18 05:44:55 -0800821 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700822 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000823}
824
piotaixre4b23142014-10-02 10:57:53 -0700825bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
826 GrGLenum format,
827 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000828 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
829 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000830 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000831 }
832
833 if (!fTwoFormatLimit) {
834 // not limited by ES 2's constraints
835 return true;
836 }
837
bsalomon@google.com548a4332012-07-11 19:45:22 +0000838 GrGLint otherFormat = GR_GL_RGBA;
839 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000840
841 // The other supported format/type combo supported for ReadPixels
842 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000843 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000844 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
845 &otherFormat);
846
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000847 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000848 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
849 &otherType);
850
bsalomon@google.com548a4332012-07-11 19:45:22 +0000851 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000852}
853
piotaixre4b23142014-10-02 10:57:53 -0700854bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
855 GrGLenum format,
856 GrGLenum type,
857 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800858 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
859 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
860 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700861 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800862 bool supported = this->doReadPixelsSupported(intf, format, type);
863 fReadPixelsSupportedCache.set(key, supported);
864 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700865}
866
robertphillips@google.com6177e692013-02-28 20:16:25 +0000867void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000868
869 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000870 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000871 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
872 // ES3 driver bugs on at least one device with a tiled GPU (N10).
873 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
874 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
875 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
876 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
vbuzinovdded6962015-06-12 08:59:45 -0700877 } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
878 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000879 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000880 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
881 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
882 // chrome's extension is equivalent to the EXT msaa
883 // and fbo_blit extensions.
884 fMSFBOType = kDesktop_EXT_MSFBOType;
885 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
886 fMSFBOType = kES_Apple_MSFBOType;
887 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000888 } else {
vbuzinovdded6962015-06-12 08:59:45 -0700889 if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
890 fMSFBOType = kMixedSamples_MSFBOType;
891 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000892 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000893 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000894 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
895 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000896 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000897 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000898 }
899}
900
cdalton1dd05422015-06-12 09:01:18 -0700901void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
902 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
903
904 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
905 // for now until its own blacklists can be updated.
906 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
907 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -0700908 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -0700909 return;
910 }
911
912 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
913 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
914 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
915 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
916 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
917 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
918 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
919 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
920 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
921 return;
922 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
923 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
924 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
925 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
926 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
927 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
928 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
929 // slow on a particular platform.
930 } else {
931 return; // No advanced blend support.
932 }
933
934 SkASSERT(this->advancedBlendEquationSupport());
935
936 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
937 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
938 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
939 (1 << kColorBurn_GrBlendEquation);
940 }
joel.liang9764c402015-07-09 19:46:18 -0700941 if (kARM_GrGLVendor == ctxInfo.vendor()) {
942 // Blacklist color-burn on ARM until the fix is released.
943 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
944 }
cdalton1dd05422015-06-12 09:01:18 -0700945}
946
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000947namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700948const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000949}
950
951void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
952
953 // Build up list of legal stencil formats (though perhaps not supported on
954 // the particular gpu/driver) from most preferred to least.
955
956 // these consts are in order of most preferred to least preferred
957 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
958
959 static const StencilFormat
960 // internal Format stencil bits total bits packed?
961 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
962 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
963 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
964 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000965 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000966 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
967
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000968 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000969 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000970 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000971 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
972 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
973
974 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
975 // require FBO support we can expect these are legal formats and don't
976 // check. These also all support the unsized GL_STENCIL_INDEX.
977 fStencilFormats.push_back() = gS8;
978 fStencilFormats.push_back() = gS16;
979 if (supportsPackedDS) {
980 fStencilFormats.push_back() = gD24S8;
981 }
982 fStencilFormats.push_back() = gS4;
983 if (supportsPackedDS) {
984 fStencilFormats.push_back() = gDS;
985 }
986 } else {
987 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
988 // for other formats.
989 // ES doesn't support using the unsized format.
990
991 fStencilFormats.push_back() = gS8;
992 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000993 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
994 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000995 fStencilFormats.push_back() = gD24S8;
996 }
997 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
998 fStencilFormats.push_back() = gS4;
999 }
1000 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001001 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001002 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
1003}
1004
1005void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
1006 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -07001007 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001008#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
1009 return;
1010#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001011 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
1012 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001013 int count = fStencilFormats.count();
1014 // we expect a really small number of possible formats so linear search
1015 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001016 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001017 for (int i = 0; i < count; ++i) {
1018 if (format.fInternalFormat ==
1019 fStencilFormats[i].fInternalFormat) {
1020 fStencilVerifiedColorConfigs[i].markVerified(config);
1021 return;
1022 }
1023 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001024 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001025 "GrGLCaps doesn't know about.");
1026}
1027
1028bool GrGLCaps::isColorConfigAndStencilFormatVerified(
1029 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -07001030 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001031#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
1032 return false;
1033#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001034 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001035 int count = fStencilFormats.count();
1036 // we expect a really small number of possible formats so linear search
1037 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001038 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001039 for (int i = 0; i < count; ++i) {
1040 if (format.fInternalFormat ==
1041 fStencilFormats[i].fInternalFormat) {
1042 return fStencilVerifiedColorConfigs[i].isVerified(config);
1043 }
1044 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001045 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001046 "GLCaps doesn't know about.");
1047 return false;
1048}
1049
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001050SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001051
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001052 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001053
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001054 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001055 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001056 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001057 i,
1058 fStencilFormats[i].fStencilBits,
1059 fStencilFormats[i].fTotalBits);
1060 }
1061
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001062 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001063 "None",
1064 "ARB",
1065 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001066 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001067 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001068 "IMG MS To Texture",
1069 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001070 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001071 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001072 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1073 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1074 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001075 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1076 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1077 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1078 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001079 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001080 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001081
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001082 static const char* kInvalidateFBTypeStr[] = {
1083 "None",
1084 "Discard",
1085 "Invalidate",
1086 };
1087 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1088 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1089 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1090 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001091
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001092 static const char* kMapBufferTypeStr[] = {
1093 "None",
1094 "MapBuffer",
1095 "MapBufferRange",
1096 "Chromium",
1097 };
1098 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1099 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1100 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1101 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1102 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1103
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001104 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001105 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001106 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001107 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001108 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1109 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001110 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1111 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001112 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
1113 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
1114 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1115 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1116 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1117 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001118
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001119 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1120 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1121 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1122 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1123 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1124 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001125 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001126 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001127 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1128 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1129 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -07001130 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001131 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001132 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001133 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001134 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001135 return r;
1136}
1137
jvanverthe9c0fc62015-04-29 11:18:05 -07001138static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1139 switch (p) {
1140 case kLow_GrSLPrecision:
1141 return GR_GL_LOW_FLOAT;
1142 case kMedium_GrSLPrecision:
1143 return GR_GL_MEDIUM_FLOAT;
1144 case kHigh_GrSLPrecision:
1145 return GR_GL_HIGH_FLOAT;
1146 }
1147 SkFAIL("Unknown precision.");
1148 return -1;
1149}
1150
1151static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1152 switch (type) {
1153 case kVertex_GrShaderType:
1154 return GR_GL_VERTEX_SHADER;
1155 case kGeometry_GrShaderType:
1156 return GR_GL_GEOMETRY_SHADER;
1157 case kFragment_GrShaderType:
1158 return GR_GL_FRAGMENT_SHADER;
1159 }
1160 SkFAIL("Unknown shader type.");
1161 return -1;
1162}
1163
jvanverthcba99b82015-06-24 06:59:57 -07001164void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1165 const GrGLInterface* intf,
1166 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001167 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1168 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1169 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1170 if (kGeometry_GrShaderType != s) {
1171 GrShaderType shaderType = static_cast<GrShaderType>(s);
1172 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
jvanverthcba99b82015-06-24 06:59:57 -07001173 GrShaderCaps::PrecisionInfo* first = NULL;
1174 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001175 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1176 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1177 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1178 GrGLint range[2];
1179 GrGLint bits;
1180 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1181 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001182 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1183 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1184 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001185 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001186 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001187 }
jvanverthcba99b82015-06-24 06:59:57 -07001188 else if (!glslCaps->fShaderPrecisionVaries) {
1189 glslCaps->fShaderPrecisionVaries =
1190 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001191 }
1192 }
1193 }
1194 }
1195 }
1196 }
1197 else {
1198 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001199 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001200 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1201 if (kGeometry_GrShaderType != s) {
1202 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001203 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1204 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1205 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001206 }
1207 }
1208 }
1209 }
1210 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1211 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1212 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1213 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001214 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001215 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001216 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1217 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001218 }
1219 }
1220}
1221
1222
1223
1224