blob: 539212c3a516336f977ce64680cf1c2ba04d15c6 [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;
piotaixre4b23142014-10-02 10:57:53 -070052
53 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070054
jvanverthcba99b82015-06-24 06:59:57 -070055 fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions)));
bsalomon4ee6bd82015-05-27 13:23:23 -070056
cdalton4cd67132015-06-10 19:23:46 -070057 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000058}
59
cdalton4cd67132015-06-10 19:23:46 -070060void GrGLCaps::init(const GrContextOptions& contextOptions,
61 const GrGLContextInfo& ctxInfo,
62 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000063 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000064 GrGLVersion version = ctxInfo.version();
65
bsalomon@google.combcce8922013-03-25 15:38:39 +000066 /**************************************************************************
cdalton4cd67132015-06-10 19:23:46 -070067 * Caps specific to GrGLSLCaps
68 **************************************************************************/
69
70 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
71 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
72
73 if (kGLES_GrGLStandard == standard) {
74 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
75 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
76 glslCaps->fFBFetchSupport = true;
77 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
78 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
79 }
80 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
81 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
82 glslCaps->fFBFetchNeedsCustomOutput = false;
83 glslCaps->fFBFetchSupport = true;
84 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
85 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
86 }
87 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
88 // The arm extension also requires an additional flag which we will set onResetContext
89 glslCaps->fFBFetchNeedsCustomOutput = false;
90 glslCaps->fFBFetchSupport = true;
91 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
92 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
93 }
94 }
95
cdalton626e1ff2015-06-12 13:56:46 -070096 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
97
cdalton4cd67132015-06-10 19:23:46 -070098 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
99 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
100
101 /**************************************************************************
bsalomon@google.combcce8922013-03-25 15:38:39 +0000102 * Caps specific to GrGLCaps
103 **************************************************************************/
104
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000105 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000106 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
107 &fMaxFragmentUniformVectors);
108 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000109 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000110 GrGLint max;
111 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
112 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000113 if (version >= GR_GL_VER(3, 2)) {
114 GrGLint profileMask;
115 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
116 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
117 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000118 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000119 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000120 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000121
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000122 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000123 fRGBA8RenderbufferSupport = true;
124 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000125 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
126 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127 ctxInfo.hasExtension("GL_ARM_rgba8");
128 }
129
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000130 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000131 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
132 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
133 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000134 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000135 }
136
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000137 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000138 fUnpackRowLengthSupport = true;
139 fUnpackFlipYSupport = false;
140 fPackRowLengthSupport = true;
141 fPackFlipYSupport = false;
142 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000143 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
144 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000145 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000146 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
147 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000148 fPackFlipYSupport =
149 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
150 }
151
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000152 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000153 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
154
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000155 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000156 // The EXT version can apply to either GL or GLES.
157 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
158 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
159 ctxInfo.hasExtension("GL_EXT_texture_storage");
160 } else {
161 // Qualcomm Adreno drivers appear to have issues with texture storage.
162 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
163 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
164 ctxInfo.hasExtension("GL_EXT_texture_storage");
165 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000166
cdaltonfd4167d2015-04-21 11:45:56 -0700167 if (kGL_GrGLStandard == standard) {
168 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
169 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
170 ctxInfo.hasExtension("GL_NV_texture_barrier");
171 } else {
172 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
173 }
174
hendrikwa0d5ad72014-12-02 07:30:30 -0800175 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
176 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700177 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800178 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000179 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
180 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800181 } else {
182 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
183 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000184 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000185 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000186 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000187 ctxInfo.hasExtension("GL_ARB_imaging");
188
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000189 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
190 // ReadPixels. The other format has to checked at run-time since it
191 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000192 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000193
rmistry63a9f842014-10-17 06:07:08 -0700194 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000195 // Known issue on at least some Intel platforms:
196 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700197 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000198 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
199 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
200 }
201
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000202 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
203 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
204 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
205 // limit this decision to specific GPU families rather than basing it on the vendor alone.
206 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700207 (kARM_GrGLVendor == ctxInfo.vendor() ||
208 kImagination_GrGLVendor == ctxInfo.vendor() ||
209 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000210 fUseNonVBOVertexAndIndexDynamicData = true;
211 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000212
egdaniel9250d242015-05-18 13:04:26 -0700213 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
214 // Thus we are blacklisting this extension for now on Adreno4xx devices.
215 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
216 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
217 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
218 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000219 fDiscardRenderTargetSupport = true;
220 fInvalidateFBType = kInvalidate_InvalidateFBType;
221 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
222 fDiscardRenderTargetSupport = true;
223 fInvalidateFBType = kDiscard_InvalidateFBType;
224 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000225
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000226 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
227 fFullClearIsFree = true;
228 }
229
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000230 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000231 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800232 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
233 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000234 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000235 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
236 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000237 }
238
cdalton626e1ff2015-06-12 13:56:46 -0700239 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
240 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
241 fInstancedDrawingSupport = true;
242 } else {
243 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
244 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
245 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
246 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
247 }
248
249 if (kGL_GrGLStandard == standard) {
250 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
251 } else {
252 fDirectStateAccessSupport = false;
253 }
254
255 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
256 fDebugSupport = true;
257 } else {
258 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
259 }
260
jvanverth3f801cb2014-12-16 09:49:38 -0800261 if (kGL_GrGLStandard == standard) {
262 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
263 }
264 else {
265 fES2CompatibilitySupport = true;
266 }
267
cdalton0edea2c2015-05-21 08:27:44 -0700268 if (kGL_GrGLStandard == standard) {
269 fMultisampleDisableSupport = true;
270 } else {
271 fMultisampleDisableSupport = false;
272 }
273
joshualittc1f56b52015-06-22 12:31:31 -0700274 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(3, 0)) {
275 fBindFragDataLocationSupport = true;
276 }
277
cdalton4cd67132015-06-10 19:23:46 -0700278 /**************************************************************************
279 * GrShaderCaps fields
280 **************************************************************************/
281
kkinnunencfe62e32015-07-01 02:58:50 -0700282 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
cdalton4cd67132015-06-10 19:23:46 -0700283
284 // For now these two are equivalent but we could have dst read in shader via some other method
285 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
286
287 // Enable supported shader-related caps
288 if (kGL_GrGLStandard == standard) {
289 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
290 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
291 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
292 glslCaps->fShaderDerivativeSupport = true;
293 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
294 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
295 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
296 }
297 else {
298 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
299 ctxInfo.hasExtension("GL_OES_standard_derivatives");
300 }
301
302 // We need dual source blending and the ability to disable multisample in order to support mixed
303 // samples in every corner case.
304 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) {
305 // We understand "mixed samples" to mean the collective capability of 3 different extensions
306 glslCaps->fMixedSamplesSupport =
307 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
308 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
309 ctxInfo.hasExtension("GL_EXT_raster_multisample");
310 }
vbuzinovdded6962015-06-12 08:59:45 -0700311 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
312 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSupport()) {
313 fDiscardRenderTargetSupport = false;
314 fInvalidateFBType = kNone_InvalidateFBType;
315 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000316
317 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700318 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000319 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700320
321 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700322 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700323 this->initStencilFormats(ctxInfo);
324
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000325 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000326 // we could also look for GL_ATI_separate_stencil extension or
327 // GL_EXT_stencil_two_side but they use different function signatures
328 // than GL2.0+ (and than each other).
329 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
330 // supported on GL 1.4 and higher or by extension
331 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
332 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
333 } else {
334 // ES 2 has two sided stencil and stencil wrap
335 fTwoSidedStencilSupport = true;
336 fStencilWrapOpsSupport = true;
337 }
338
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000339 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000340 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
341 // extension includes glMapBuffer.
342 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
343 fMapBufferFlags |= kSubset_MapFlag;
344 fMapBufferType = kMapBufferRange_MapBufferType;
345 } else {
346 fMapBufferType = kMapBuffer_MapBufferType;
347 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000348 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000349 // Unextended GLES2 doesn't have any buffer mapping.
350 fMapBufferFlags = kNone_MapBufferType;
351 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
352 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
353 fMapBufferType = kChromium_MapBufferType;
354 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
355 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
356 fMapBufferType = kMapBufferRange_MapBufferType;
357 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
358 fMapBufferFlags = kCanMap_MapFlag;
359 fMapBufferType = kMapBuffer_MapBufferType;
360 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000361 }
362
joshualitte5b74c62015-06-01 14:17:47 -0700363 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
364 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
365 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700366 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
367 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
368 // a small subset.
369#if 0
cdalton1acea862015-06-02 13:05:52 -0700370 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700371#else
372 fGeometryBufferMapThreshold = SK_MaxS32;
373#endif
joshualitte5b74c62015-06-01 14:17:47 -0700374 }
375
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000376 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000377 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
378 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
379 fNPOTTextureTileSupport = true;
380 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000381 } else {
382 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000383 // ES3 has no limitations.
384 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
385 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000386 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
387 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
388 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
389 // to alllow arbitrary wrap modes, however.
390 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000391 }
392
bsalomon@google.combcce8922013-03-25 15:38:39 +0000393 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
394 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
395 // Our render targets are always created with textures as the color
396 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000397 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000398
bsalomonc59a1df2015-06-01 07:13:42 -0700399 // This GPU seems to have problems when tiling small textures
400 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
401 fMinTextureSize = 16;
402 }
403
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000404 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
405
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000406 // Disable scratch texture reuse on Mali and Adreno devices
407 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
408 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000409
robertphillips1b8e1b52015-06-24 06:54:10 -0700410#if 0
411 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
412 kQualcomm_GrGLVendor != ctxInfo.vendor();
413#endif
414
bsalomon@google.com347c3822013-05-01 20:10:01 +0000415 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000416 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
417 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
418 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
419 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000420
bsalomon63b21962014-11-05 07:05:34 -0800421 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800422 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800423 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800424 fUseDrawInsteadOfClear = true;
425 }
426
joshualitt83bc2292015-06-18 14:18:02 -0700427 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
428 fUseDrawInsteadOfPartialRenderTargetWrite = true;
429 }
430
bsalomond08ea5f2015-02-20 06:58:13 -0800431 if (kGL_GrGLStandard == standard) {
432 // ARB allows mixed size FBO attachments, EXT does not.
433 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
434 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
435 fOversizedStencilSupport = true;
436 } else {
437 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
438 }
439 } else {
440 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
441 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
442 }
443
joshualitt58001552015-06-26 12:46:36 -0700444 if (kGL_GrGLStandard == standard) {
445 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
446 // instanced arrays, but we could make this more granular if we wanted
447 fSupportsInstancedDraws =
448 version >= GR_GL_VER(3, 2) ||
449 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
450 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
451 } else {
452 fSupportsInstancedDraws =
453 version >= GR_GL_VER(3, 0) ||
454 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
455 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
456 }
457
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000458 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000459 this->initConfigRenderableTable(ctxInfo);
jvanverthcba99b82015-06-24 06:59:57 -0700460 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700461
462 this->applyOptionsOverrides(contextOptions);
463 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000464}
465
kkinnunencfe62e32015-07-01 02:58:50 -0700466bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
467 if (!ctxInfo.hasExtension("GL_NV_path_rendering")) {
468 return false;
469 }
470 if (kGL_GrGLStandard == ctxInfo.standard()) {
471 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
472 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
473 return false;
474 }
475 } else {
476 if (ctxInfo.version() < GR_GL_VER(3, 1)) {
477 return false;
478 }
479 }
480 // We only support v1.3+ of GL_NV_path_rendering which allows us to
481 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
482 // additions are detected by checking the existence of the function.
483 // We also use *Then* functions that not all drivers might have. Check
484 // them for consistency.
485 if (NULL == gli->fFunctions.fStencilThenCoverFillPath ||
486 NULL == gli->fFunctions.fStencilThenCoverStrokePath ||
487 NULL == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
488 NULL == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
489 NULL == gli->fFunctions.fProgramPathFragmentInputGen) {
490 return false;
491 }
492 return true;
493}
494
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000495void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000496 // OpenGL < 3.0
497 // no support for render targets unless the GL_ARB_framebuffer_object
498 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
499 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
500 // probably don't get R8 in this case.
501
502 // OpenGL 3.0
503 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
504 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
505
506 // >= OpenGL 3.1
507 // base color renderable: RED, RG, RGB, and RGBA
508 // sized derivatives: R8, RGBA4, RGBA8
509 // if the GL_ARB_compatibility extension is supported then we get back
510 // support for GL_ALPHA and ALPHA8
511
512 // GL_EXT_bgra adds BGRA render targets to any version
513
514 // ES 2.0
515 // color renderable: RGBA4, RGB5_A1, RGB565
516 // GL_EXT_texture_rg adds support for R8 as a color render target
517 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
518 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
519
520 // ES 3.0
521 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
522 // below already account for this).
523
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000524 GrGLStandard standard = ctxInfo.standard();
525
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000526 enum {
527 kNo_MSAA = 0,
528 kYes_MSAA = 1,
529 };
530
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000531 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000532 // Post 3.0 we will get R8
533 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
534 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
535 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000536 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
537 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000538 }
539 } else {
540 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000541 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
542 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000543 }
544
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000545 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000546 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000547 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
548 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000549 }
550
551 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000552 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
553 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000554
555 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000556 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000557 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000558 }
559
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000560 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000561 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
562 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
563 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000564 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000565 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000566 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
567 } else {
568 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
569 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
570 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000571 }
572
jvanverthfa1e8a72014-12-22 08:31:49 -0800573 if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) {
574 if (kGL_GrGLStandard == standard) {
575 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
576 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
577 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
578 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
579 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
580 }
581 } else {
582 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
583 ctxInfo.hasExtension("GL_EXT_sRGB")) {
584 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
585 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
586 }
587 }
588 }
589
joshualittee5da552014-07-16 13:32:56 -0700590 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800591 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800592 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800593 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
594 } else {
joshualitt55999962015-06-18 13:47:10 -0700595 // for now we only enable this on desktop, because on ES we'd have to solve many
596 // precision issues and no clients actually want this yet
597 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800598 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
599 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
600 } else {
601 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
602 }
603 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700604 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
605 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700606 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800607 }
joshualittee5da552014-07-16 13:32:56 -0700608 }
609
jvanverth28f9c602014-12-05 13:06:35 -0800610 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800611 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800612 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800613 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800614 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
615 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
616 // for now we don't support floating point MSAA on ES
617 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800618 } else {
jvanverth1334c212014-12-18 05:44:55 -0800619 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
620 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
621 } else {
622 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
623 }
624 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800625 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
626 }
627 }
628
jvanverthfb5df432015-05-21 08:12:27 -0700629 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
630 if (kGL_GrGLStandard == standard) {
631 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
632 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
633 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
634 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
635 // for now we don't support floating point MSAA on ES
636 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
637 } else {
638 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
639 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
640 } else {
641 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
642 }
643 // for now we don't support floating point MSAA on ES
644 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
645 }
646 }
647
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000648 // If we don't support MSAA then undo any places above where we set a config as renderable with
649 // msaa.
650 if (kNone_MSFBOType == fMSFBOType) {
651 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
652 fConfigRenderSupport[i][kYes_MSAA] = false;
653 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000654 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000655}
656
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000657void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000658 GrGLStandard standard = ctxInfo.standard();
659 GrGLVersion version = ctxInfo.version();
660
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000661 // Base texture support
662 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
663 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
664 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
665 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
666
667 // Check for 8-bit palette..
668 GrGLint numFormats;
669 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
670 if (numFormats) {
671 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
672 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
673 for (int i = 0; i < numFormats; ++i) {
674 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
675 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
676 break;
677 }
678 }
679 }
680
681 // Check for BGRA
682 if (kGL_GrGLStandard == standard) {
683 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
684 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
685 } else {
686 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
687 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
688 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
689 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
690 fBGRAIsInternalFormat = true;
691 }
692 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
693 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
694 }
695
jvanverthfa1e8a72014-12-22 08:31:49 -0800696 // Check for sRGBA
697 if (kGL_GrGLStandard == standard) {
698 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
699 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB"));
700 } else {
701 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
702 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
703 }
704
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000705 // Compressed texture support
706
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000707 // glCompressedTexImage2D is available on all OpenGL ES devices...
708 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000709 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000710
krajcevski786978162014-07-30 11:25:44 -0700711 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700712 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700713
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000714 // Check for ETC1
715 bool hasETC1 = false;
716
717 // First check version for support
718 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000719 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700720 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000721 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000722 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000723 hasETC1 = hasCompressTex2D &&
724 (version >= GR_GL_VER(3, 0) ||
725 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
726 // ETC2 is a superset of ETC1, so we can just check for that, too.
727 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
728 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000729 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000730 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000731
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000732 // Check for LATC under its various forms
733 LATCAlias alias = kLATC_LATCAlias;
734 bool hasLATC = hasCompressTex2D &&
735 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
736 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
737
738 // Check for RGTC
739 if (!hasLATC) {
740 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
741 if (kGL_GrGLStandard == standard) {
742 hasLATC = version >= GR_GL_VER(3, 0);
743 }
744
745 if (!hasLATC) {
746 hasLATC =
747 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
748 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
749 }
750
751 if (hasLATC) {
752 alias = kRGTC_LATCAlias;
753 }
754 }
755
756 // Check for 3DC
757 if (!hasLATC) {
758 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
759 if (hasLATC) {
760 alias = k3DC_LATCAlias;
761 }
762 }
763
764 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
765 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700766
krajcevskib3abe902014-07-30 13:08:11 -0700767 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
768 // cards default to decompressing the textures in the driver, and is
769 // generally slower.
770 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700771 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
772 }
joshualittee5da552014-07-16 13:32:56 -0700773
krajcevski7ef21622014-07-16 15:21:13 -0700774 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700775 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700776 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
777 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
778 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
779
joshualittee5da552014-07-16 13:32:56 -0700780 // Check for floating point texture support
781 // NOTE: We disallow floating point textures on ES devices if linear
782 // filtering modes are not supported. This is for simplicity, but a more
783 // granular approach is possible. Coincidentally, floating point textures became part of
784 // the standard in ES3.1 / OGL 3.1, hence the shorthand
785 bool hasFPTextures = version >= GR_GL_VER(3, 1);
786 if (!hasFPTextures) {
787 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800788 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700789 ctxInfo.hasExtension("GL_OES_texture_float"));
790 }
791 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800792
793 // Check for fp16 texture support
794 // NOTE: We disallow floating point textures on ES devices if linear
795 // filtering modes are not supported. This is for simplicity, but a more
796 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
797 // the standard in ES3.1 / OGL 3.1, hence the shorthand
798 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
799 if (!hasHalfFPTextures) {
800 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800801 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
802 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800803 }
jvanverth1334c212014-12-18 05:44:55 -0800804 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700805 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000806}
807
piotaixre4b23142014-10-02 10:57:53 -0700808bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
809 GrGLenum format,
810 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000811 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
812 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000813 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000814 }
815
816 if (!fTwoFormatLimit) {
817 // not limited by ES 2's constraints
818 return true;
819 }
820
bsalomon@google.com548a4332012-07-11 19:45:22 +0000821 GrGLint otherFormat = GR_GL_RGBA;
822 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000823
824 // The other supported format/type combo supported for ReadPixels
825 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000826 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000827 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
828 &otherFormat);
829
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000830 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000831 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
832 &otherType);
833
bsalomon@google.com548a4332012-07-11 19:45:22 +0000834 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000835}
836
piotaixre4b23142014-10-02 10:57:53 -0700837bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
838 GrGLenum format,
839 GrGLenum type,
840 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800841 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
842 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
843 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700844 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800845 bool supported = this->doReadPixelsSupported(intf, format, type);
846 fReadPixelsSupportedCache.set(key, supported);
847 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700848}
849
robertphillips@google.com6177e692013-02-28 20:16:25 +0000850void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000851
852 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000853 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000854 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
855 // ES3 driver bugs on at least one device with a tiled GPU (N10).
856 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
857 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
858 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
859 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
vbuzinovdded6962015-06-12 08:59:45 -0700860 } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
861 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000862 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000863 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
864 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
865 // chrome's extension is equivalent to the EXT msaa
866 // and fbo_blit extensions.
867 fMSFBOType = kDesktop_EXT_MSFBOType;
868 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
869 fMSFBOType = kES_Apple_MSFBOType;
870 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000871 } else {
vbuzinovdded6962015-06-12 08:59:45 -0700872 if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
873 fMSFBOType = kMixedSamples_MSFBOType;
874 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000875 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000876 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000877 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
878 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000879 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000880 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000881 }
882}
883
cdalton1dd05422015-06-12 09:01:18 -0700884void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
885 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
886
887 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
888 // for now until its own blacklists can be updated.
889 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
890 kIntel_GrGLDriver == ctxInfo.driver() ||
cdalton07a8fc82015-06-15 10:52:11 -0700891 kChromium_GrGLDriver == ctxInfo.driver() ||
892 kARM_GrGLVendor == ctxInfo.vendor()) {
cdalton1dd05422015-06-12 09:01:18 -0700893 return;
894 }
895
896 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
897 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
898 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
899 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
900 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
901 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
902 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
903 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
904 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
905 return;
906 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
907 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
908 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
909 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
910 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
911 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
912 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
913 // slow on a particular platform.
914 } else {
915 return; // No advanced blend support.
916 }
917
918 SkASSERT(this->advancedBlendEquationSupport());
919
920 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
921 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
922 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
923 (1 << kColorBurn_GrBlendEquation);
924 }
925}
926
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000927namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700928const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000929}
930
931void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
932
933 // Build up list of legal stencil formats (though perhaps not supported on
934 // the particular gpu/driver) from most preferred to least.
935
936 // these consts are in order of most preferred to least preferred
937 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
938
939 static const StencilFormat
940 // internal Format stencil bits total bits packed?
941 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
942 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
943 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
944 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000945 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000946 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
947
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000948 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000949 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000950 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000951 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
952 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
953
954 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
955 // require FBO support we can expect these are legal formats and don't
956 // check. These also all support the unsized GL_STENCIL_INDEX.
957 fStencilFormats.push_back() = gS8;
958 fStencilFormats.push_back() = gS16;
959 if (supportsPackedDS) {
960 fStencilFormats.push_back() = gD24S8;
961 }
962 fStencilFormats.push_back() = gS4;
963 if (supportsPackedDS) {
964 fStencilFormats.push_back() = gDS;
965 }
966 } else {
967 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
968 // for other formats.
969 // ES doesn't support using the unsized format.
970
971 fStencilFormats.push_back() = gS8;
972 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000973 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
974 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000975 fStencilFormats.push_back() = gD24S8;
976 }
977 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
978 fStencilFormats.push_back() = gS4;
979 }
980 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000981 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000982 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
983}
984
985void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
986 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700987 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000988#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
989 return;
990#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000991 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
992 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000993 int count = fStencilFormats.count();
994 // we expect a really small number of possible formats so linear search
995 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000996 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000997 for (int i = 0; i < count; ++i) {
998 if (format.fInternalFormat ==
999 fStencilFormats[i].fInternalFormat) {
1000 fStencilVerifiedColorConfigs[i].markVerified(config);
1001 return;
1002 }
1003 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001004 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001005 "GrGLCaps doesn't know about.");
1006}
1007
1008bool GrGLCaps::isColorConfigAndStencilFormatVerified(
1009 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -07001010 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001011#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
1012 return false;
1013#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001014 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001015 int count = fStencilFormats.count();
1016 // we expect a really small number of possible formats so linear search
1017 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +00001018 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001019 for (int i = 0; i < count; ++i) {
1020 if (format.fInternalFormat ==
1021 fStencilFormats[i].fInternalFormat) {
1022 return fStencilVerifiedColorConfigs[i].isVerified(config);
1023 }
1024 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +00001025 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001026 "GLCaps doesn't know about.");
1027 return false;
1028}
1029
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001030SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001031
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001032 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001033
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001034 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001035 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001036 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001037 i,
1038 fStencilFormats[i].fStencilBits,
1039 fStencilFormats[i].fTotalBits);
1040 }
1041
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001042 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001043 "None",
1044 "ARB",
1045 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001046 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001047 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001048 "IMG MS To Texture",
1049 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001050 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001051 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001052 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1053 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1054 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001055 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1056 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1057 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1058 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001059 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001060 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001061
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001062 static const char* kInvalidateFBTypeStr[] = {
1063 "None",
1064 "Discard",
1065 "Invalidate",
1066 };
1067 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1068 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1069 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1070 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001071
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001072 static const char* kMapBufferTypeStr[] = {
1073 "None",
1074 "MapBuffer",
1075 "MapBufferRange",
1076 "Chromium",
1077 };
1078 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1079 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1080 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1081 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1082 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1083
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001084 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001085 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001086 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001087 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001088 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1089 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001090 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1091 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001092 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
1093 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
1094 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1095 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1096 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1097 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001098
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001099 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1100 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1101 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1102 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1103 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1104 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001105 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001106 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001107 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1108 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1109 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -07001110 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001111 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001112 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001113 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001114 return r;
1115}
1116
jvanverthe9c0fc62015-04-29 11:18:05 -07001117static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1118 switch (p) {
1119 case kLow_GrSLPrecision:
1120 return GR_GL_LOW_FLOAT;
1121 case kMedium_GrSLPrecision:
1122 return GR_GL_MEDIUM_FLOAT;
1123 case kHigh_GrSLPrecision:
1124 return GR_GL_HIGH_FLOAT;
1125 }
1126 SkFAIL("Unknown precision.");
1127 return -1;
1128}
1129
1130static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1131 switch (type) {
1132 case kVertex_GrShaderType:
1133 return GR_GL_VERTEX_SHADER;
1134 case kGeometry_GrShaderType:
1135 return GR_GL_GEOMETRY_SHADER;
1136 case kFragment_GrShaderType:
1137 return GR_GL_FRAGMENT_SHADER;
1138 }
1139 SkFAIL("Unknown shader type.");
1140 return -1;
1141}
1142
jvanverthcba99b82015-06-24 06:59:57 -07001143void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1144 const GrGLInterface* intf,
1145 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001146 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1147 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1148 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1149 if (kGeometry_GrShaderType != s) {
1150 GrShaderType shaderType = static_cast<GrShaderType>(s);
1151 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
jvanverthcba99b82015-06-24 06:59:57 -07001152 GrShaderCaps::PrecisionInfo* first = NULL;
1153 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001154 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1155 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1156 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1157 GrGLint range[2];
1158 GrGLint bits;
1159 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1160 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001161 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1162 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1163 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001164 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001165 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001166 }
jvanverthcba99b82015-06-24 06:59:57 -07001167 else if (!glslCaps->fShaderPrecisionVaries) {
1168 glslCaps->fShaderPrecisionVaries =
1169 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001170 }
1171 }
1172 }
1173 }
1174 }
1175 }
1176 else {
1177 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001178 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001179 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1180 if (kGeometry_GrShaderType != s) {
1181 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001182 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1183 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1184 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001185 }
1186 }
1187 }
1188 }
1189 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1190 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1191 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1192 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001193 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001194 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001195 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1196 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001197 }
1198 }
1199}
1200
1201
1202
1203