blob: b23619d8b6d600677431f14f5145867d48b45098 [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"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000012#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000013#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000014
bsalomon682c2692015-05-22 14:01:46 -070015GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
16 const GrGLContextInfo& ctxInfo,
17 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000018 fVerifiedColorConfigs.reset();
19 fStencilFormats.reset();
20 fStencilVerifiedColorConfigs.reset();
21 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000022 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070023 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000024 fMapBufferType = kNone_MapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000025 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000026 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000027 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fBGRAIsInternalFormat = false;
30 fTextureSwizzleSupport = false;
31 fUnpackRowLengthSupport = false;
32 fUnpackFlipYSupport = false;
33 fPackRowLengthSupport = false;
34 fPackFlipYSupport = false;
35 fTextureUsageSupport = false;
36 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000037 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000039 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000040 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000041 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070042 fInstancedDrawingSupport = false;
43 fDirectStateAccessSupport = false;
44 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080045 fES2CompatibilitySupport = false;
cdalton0edea2c2015-05-21 08:27:44 -070046 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000047 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000048 fIsCoreProfile = false;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000049 fFullClearIsFree = false;
joshualittc1f56b52015-06-22 12:31:31 -070050 fBindFragDataLocationSupport = false;
piotaixre4b23142014-10-02 10:57:53 -070051
52 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070053
bsalomon4ee6bd82015-05-27 13:23:23 -070054 fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions,
55 ctxInfo, glInterface, *this)));
56
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
282 glslCaps->fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
283
284 if (glslCaps->fPathRenderingSupport) {
285 if (kGL_GrGLStandard == standard) {
286 // We only support v1.3+ of GL_NV_path_rendering which allows us to
287 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
288 // additions are detected by checking the existence of the function.
cdalton626e1ff2015-06-12 13:56:46 -0700289 glslCaps->fPathRenderingSupport = ((ctxInfo.version() >= GR_GL_VER(4, 3) ||
cdalton4cd67132015-06-10 19:23:46 -0700290 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
291 gli->fFunctions.fProgramPathFragmentInputGen);
292 }
293 else {
294 glslCaps->fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3, 1);
295 }
296 }
297
298 // For now these two are equivalent but we could have dst read in shader via some other method
299 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
300
301 // Enable supported shader-related caps
302 if (kGL_GrGLStandard == standard) {
303 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
304 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
305 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
306 glslCaps->fShaderDerivativeSupport = true;
307 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
308 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
309 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
310 }
311 else {
312 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
313 ctxInfo.hasExtension("GL_OES_standard_derivatives");
314 }
315
316 // We need dual source blending and the ability to disable multisample in order to support mixed
317 // samples in every corner case.
318 if (fMultisampleDisableSupport && glslCaps->fDualSourceBlendingSupport) {
319 // We understand "mixed samples" to mean the collective capability of 3 different extensions
320 glslCaps->fMixedSamplesSupport =
321 ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
322 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
323 ctxInfo.hasExtension("GL_EXT_raster_multisample");
324 }
vbuzinovdded6962015-06-12 08:59:45 -0700325 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
326 if (kNVIDIA_GrGLDriver == ctxInfo.driver() && fShaderCaps->mixedSamplesSupport()) {
327 fDiscardRenderTargetSupport = false;
328 fInvalidateFBType = kNone_InvalidateFBType;
329 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000330
331 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700332 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000333 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700334
335 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700336 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700337 this->initStencilFormats(ctxInfo);
338
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000339 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000340 // we could also look for GL_ATI_separate_stencil extension or
341 // GL_EXT_stencil_two_side but they use different function signatures
342 // than GL2.0+ (and than each other).
343 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
344 // supported on GL 1.4 and higher or by extension
345 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
346 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
347 } else {
348 // ES 2 has two sided stencil and stencil wrap
349 fTwoSidedStencilSupport = true;
350 fStencilWrapOpsSupport = true;
351 }
352
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000353 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000354 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
355 // extension includes glMapBuffer.
356 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
357 fMapBufferFlags |= kSubset_MapFlag;
358 fMapBufferType = kMapBufferRange_MapBufferType;
359 } else {
360 fMapBufferType = kMapBuffer_MapBufferType;
361 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000362 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000363 // Unextended GLES2 doesn't have any buffer mapping.
364 fMapBufferFlags = kNone_MapBufferType;
365 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
366 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
367 fMapBufferType = kChromium_MapBufferType;
368 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
369 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
370 fMapBufferType = kMapBufferRange_MapBufferType;
371 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
372 fMapBufferFlags = kCanMap_MapFlag;
373 fMapBufferType = kMapBuffer_MapBufferType;
374 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000375 }
376
joshualitte5b74c62015-06-01 14:17:47 -0700377 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
378 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
379 if (fGeometryBufferMapThreshold < 0) {
cdalton1acea862015-06-02 13:05:52 -0700380 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
joshualitte5b74c62015-06-01 14:17:47 -0700381 }
382
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000383 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000384 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
385 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
386 fNPOTTextureTileSupport = true;
387 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000388 } else {
389 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000390 // ES3 has no limitations.
391 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
392 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000393 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
394 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
395 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
396 // to alllow arbitrary wrap modes, however.
397 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000398 }
399
bsalomon@google.combcce8922013-03-25 15:38:39 +0000400 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
401 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
402 // Our render targets are always created with textures as the color
403 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000404 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000405
bsalomonc59a1df2015-06-01 07:13:42 -0700406 // This GPU seems to have problems when tiling small textures
407 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
408 fMinTextureSize = 16;
409 }
410
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000411 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
412
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000413 // Disable scratch texture reuse on Mali and Adreno devices
414 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
415 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000416
bsalomon@google.com347c3822013-05-01 20:10:01 +0000417 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000418 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
419 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
420 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
421 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000422
bsalomon63b21962014-11-05 07:05:34 -0800423 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800424 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800425 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800426 fUseDrawInsteadOfClear = true;
427 }
428
joshualitt83bc2292015-06-18 14:18:02 -0700429 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
430 fUseDrawInsteadOfPartialRenderTargetWrite = true;
431 }
432
bsalomond08ea5f2015-02-20 06:58:13 -0800433 if (kGL_GrGLStandard == standard) {
434 // ARB allows mixed size FBO attachments, EXT does not.
435 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
436 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
437 fOversizedStencilSupport = true;
438 } else {
439 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
440 }
441 } else {
442 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
443 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
444 }
445
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000446 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000447 this->initConfigRenderableTable(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700448 glslCaps->initShaderPrecisionTable(ctxInfo, gli);
449
450 this->applyOptionsOverrides(contextOptions);
451 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000452}
453
454void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000455 // OpenGL < 3.0
456 // no support for render targets unless the GL_ARB_framebuffer_object
457 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
458 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
459 // probably don't get R8 in this case.
460
461 // OpenGL 3.0
462 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
463 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
464
465 // >= OpenGL 3.1
466 // base color renderable: RED, RG, RGB, and RGBA
467 // sized derivatives: R8, RGBA4, RGBA8
468 // if the GL_ARB_compatibility extension is supported then we get back
469 // support for GL_ALPHA and ALPHA8
470
471 // GL_EXT_bgra adds BGRA render targets to any version
472
473 // ES 2.0
474 // color renderable: RGBA4, RGB5_A1, RGB565
475 // GL_EXT_texture_rg adds support for R8 as a color render target
476 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
477 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
478
479 // ES 3.0
480 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
481 // below already account for this).
482
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000483 GrGLStandard standard = ctxInfo.standard();
484
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000485 enum {
486 kNo_MSAA = 0,
487 kYes_MSAA = 1,
488 };
489
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000490 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000491 // Post 3.0 we will get R8
492 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
493 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
494 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000495 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
496 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000497 }
498 } else {
499 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000500 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
501 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000502 }
503
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000504 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000505 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000506 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
507 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000508 }
509
510 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000511 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
512 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000513
514 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000515 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000516 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000517 }
518
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000519 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000520 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
521 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
522 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000523 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000524 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000525 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
526 } else {
527 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
528 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
529 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000530 }
531
jvanverthfa1e8a72014-12-22 08:31:49 -0800532 if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) {
533 if (kGL_GrGLStandard == standard) {
534 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
535 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
536 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
537 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
538 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
539 }
540 } else {
541 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
542 ctxInfo.hasExtension("GL_EXT_sRGB")) {
543 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
544 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
545 }
546 }
547 }
548
joshualittee5da552014-07-16 13:32:56 -0700549 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800550 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800551 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800552 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
553 } else {
joshualitt55999962015-06-18 13:47:10 -0700554 // for now we only enable this on desktop, because on ES we'd have to solve many
555 // precision issues and no clients actually want this yet
556 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800557 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
558 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
559 } else {
560 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
561 }
562 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700563 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
564 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700565 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800566 }
joshualittee5da552014-07-16 13:32:56 -0700567 }
568
jvanverth28f9c602014-12-05 13:06:35 -0800569 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800570 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800571 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800572 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800573 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
574 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
575 // for now we don't support floating point MSAA on ES
576 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800577 } else {
jvanverth1334c212014-12-18 05:44:55 -0800578 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
579 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
580 } else {
581 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
582 }
583 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800584 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
585 }
586 }
587
jvanverthfb5df432015-05-21 08:12:27 -0700588 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
589 if (kGL_GrGLStandard == standard) {
590 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
591 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
592 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
593 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
594 // for now we don't support floating point MSAA on ES
595 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
596 } else {
597 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
598 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
599 } else {
600 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
601 }
602 // for now we don't support floating point MSAA on ES
603 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
604 }
605 }
606
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000607 // If we don't support MSAA then undo any places above where we set a config as renderable with
608 // msaa.
609 if (kNone_MSFBOType == fMSFBOType) {
610 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
611 fConfigRenderSupport[i][kYes_MSAA] = false;
612 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000613 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000614}
615
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000616void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000617 GrGLStandard standard = ctxInfo.standard();
618 GrGLVersion version = ctxInfo.version();
619
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000620 // Base texture support
621 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
622 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
623 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
624 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
625
626 // Check for 8-bit palette..
627 GrGLint numFormats;
628 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
629 if (numFormats) {
630 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
631 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
632 for (int i = 0; i < numFormats; ++i) {
633 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
634 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
635 break;
636 }
637 }
638 }
639
640 // Check for BGRA
641 if (kGL_GrGLStandard == standard) {
642 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
643 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
644 } else {
645 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
646 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
647 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
648 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
649 fBGRAIsInternalFormat = true;
650 }
651 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
652 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
653 }
654
jvanverthfa1e8a72014-12-22 08:31:49 -0800655 // Check for sRGBA
656 if (kGL_GrGLStandard == standard) {
657 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
658 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB"));
659 } else {
660 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
661 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
662 }
663
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000664 // Compressed texture support
665
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000666 // glCompressedTexImage2D is available on all OpenGL ES devices...
667 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000668 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000669
krajcevski786978162014-07-30 11:25:44 -0700670 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700671 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700672
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000673 // Check for ETC1
674 bool hasETC1 = false;
675
676 // First check version for support
677 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000678 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700679 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000680 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000681 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000682 hasETC1 = hasCompressTex2D &&
683 (version >= GR_GL_VER(3, 0) ||
684 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
685 // ETC2 is a superset of ETC1, so we can just check for that, too.
686 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
687 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000688 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000689 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000690
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000691 // Check for LATC under its various forms
692 LATCAlias alias = kLATC_LATCAlias;
693 bool hasLATC = hasCompressTex2D &&
694 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
695 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
696
697 // Check for RGTC
698 if (!hasLATC) {
699 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
700 if (kGL_GrGLStandard == standard) {
701 hasLATC = version >= GR_GL_VER(3, 0);
702 }
703
704 if (!hasLATC) {
705 hasLATC =
706 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
707 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
708 }
709
710 if (hasLATC) {
711 alias = kRGTC_LATCAlias;
712 }
713 }
714
715 // Check for 3DC
716 if (!hasLATC) {
717 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
718 if (hasLATC) {
719 alias = k3DC_LATCAlias;
720 }
721 }
722
723 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
724 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700725
krajcevskib3abe902014-07-30 13:08:11 -0700726 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
727 // cards default to decompressing the textures in the driver, and is
728 // generally slower.
729 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700730 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
731 }
joshualittee5da552014-07-16 13:32:56 -0700732
krajcevski7ef21622014-07-16 15:21:13 -0700733 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700734 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700735 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
736 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
737 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
738
joshualittee5da552014-07-16 13:32:56 -0700739 // Check for floating point texture support
740 // NOTE: We disallow floating point textures on ES devices if linear
741 // filtering modes are not supported. This is for simplicity, but a more
742 // granular approach is possible. Coincidentally, floating point textures became part of
743 // the standard in ES3.1 / OGL 3.1, hence the shorthand
744 bool hasFPTextures = version >= GR_GL_VER(3, 1);
745 if (!hasFPTextures) {
746 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800747 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700748 ctxInfo.hasExtension("GL_OES_texture_float"));
749 }
750 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800751
752 // Check for fp16 texture support
753 // NOTE: We disallow floating point textures on ES devices if linear
754 // filtering modes are not supported. This is for simplicity, but a more
755 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
756 // the standard in ES3.1 / OGL 3.1, hence the shorthand
757 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
758 if (!hasHalfFPTextures) {
759 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800760 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
761 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800762 }
jvanverth1334c212014-12-18 05:44:55 -0800763 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700764 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000765}
766
piotaixre4b23142014-10-02 10:57:53 -0700767bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
768 GrGLenum format,
769 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000770 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
771 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000772 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000773 }
774
775 if (!fTwoFormatLimit) {
776 // not limited by ES 2's constraints
777 return true;
778 }
779
bsalomon@google.com548a4332012-07-11 19:45:22 +0000780 GrGLint otherFormat = GR_GL_RGBA;
781 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000782
783 // The other supported format/type combo supported for ReadPixels
784 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000785 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000786 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
787 &otherFormat);
788
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000789 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000790 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
791 &otherType);
792
bsalomon@google.com548a4332012-07-11 19:45:22 +0000793 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000794}
795
piotaixre4b23142014-10-02 10:57:53 -0700796bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
797 GrGLenum format,
798 GrGLenum type,
799 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800800 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
801 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
802 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700803 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800804 bool supported = this->doReadPixelsSupported(intf, format, type);
805 fReadPixelsSupportedCache.set(key, supported);
806 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700807}
808
robertphillips@google.com6177e692013-02-28 20:16:25 +0000809void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000810
811 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000812 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000813 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
814 // ES3 driver bugs on at least one device with a tiled GPU (N10).
815 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
816 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
817 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
818 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
vbuzinovdded6962015-06-12 08:59:45 -0700819 } else if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
820 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000821 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000822 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
823 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
824 // chrome's extension is equivalent to the EXT msaa
825 // and fbo_blit extensions.
826 fMSFBOType = kDesktop_EXT_MSFBOType;
827 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
828 fMSFBOType = kES_Apple_MSFBOType;
829 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000830 } else {
vbuzinovdded6962015-06-12 08:59:45 -0700831 if (fShaderCaps->mixedSamplesSupport() && fShaderCaps->pathRenderingSupport()) {
832 fMSFBOType = kMixedSamples_MSFBOType;
833 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000834 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000835 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000836 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
837 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000838 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000839 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000840 }
841}
842
cdalton1dd05422015-06-12 09:01:18 -0700843void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
844 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
845
846 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
847 // for now until its own blacklists can be updated.
848 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
849 kIntel_GrGLDriver == ctxInfo.driver() ||
cdalton07a8fc82015-06-15 10:52:11 -0700850 kChromium_GrGLDriver == ctxInfo.driver() ||
851 kARM_GrGLVendor == ctxInfo.vendor()) {
cdalton1dd05422015-06-12 09:01:18 -0700852 return;
853 }
854
855 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
856 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
857 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
858 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
859 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
860 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
861 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
862 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
863 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
864 return;
865 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
866 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
867 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
868 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
869 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
870 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
871 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
872 // slow on a particular platform.
873 } else {
874 return; // No advanced blend support.
875 }
876
877 SkASSERT(this->advancedBlendEquationSupport());
878
879 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
880 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
881 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
882 (1 << kColorBurn_GrBlendEquation);
883 }
884}
885
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000886namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700887const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000888}
889
890void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
891
892 // Build up list of legal stencil formats (though perhaps not supported on
893 // the particular gpu/driver) from most preferred to least.
894
895 // these consts are in order of most preferred to least preferred
896 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
897
898 static const StencilFormat
899 // internal Format stencil bits total bits packed?
900 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
901 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
902 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
903 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000904 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000905 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
906
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000907 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000908 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000909 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000910 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
911 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
912
913 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
914 // require FBO support we can expect these are legal formats and don't
915 // check. These also all support the unsized GL_STENCIL_INDEX.
916 fStencilFormats.push_back() = gS8;
917 fStencilFormats.push_back() = gS16;
918 if (supportsPackedDS) {
919 fStencilFormats.push_back() = gD24S8;
920 }
921 fStencilFormats.push_back() = gS4;
922 if (supportsPackedDS) {
923 fStencilFormats.push_back() = gDS;
924 }
925 } else {
926 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
927 // for other formats.
928 // ES doesn't support using the unsized format.
929
930 fStencilFormats.push_back() = gS8;
931 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000932 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
933 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000934 fStencilFormats.push_back() = gD24S8;
935 }
936 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
937 fStencilFormats.push_back() = gS4;
938 }
939 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000940 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000941 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
942}
943
944void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
945 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700946 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000947#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
948 return;
949#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000950 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
951 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000952 int count = fStencilFormats.count();
953 // we expect a really small number of possible formats so linear search
954 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000955 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000956 for (int i = 0; i < count; ++i) {
957 if (format.fInternalFormat ==
958 fStencilFormats[i].fInternalFormat) {
959 fStencilVerifiedColorConfigs[i].markVerified(config);
960 return;
961 }
962 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000963 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000964 "GrGLCaps doesn't know about.");
965}
966
967bool GrGLCaps::isColorConfigAndStencilFormatVerified(
968 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700969 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000970#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
971 return false;
972#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000973 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000974 int count = fStencilFormats.count();
975 // we expect a really small number of possible formats so linear search
976 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000977 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000978 for (int i = 0; i < count; ++i) {
979 if (format.fInternalFormat ==
980 fStencilFormats[i].fInternalFormat) {
981 return fStencilVerifiedColorConfigs[i].isVerified(config);
982 }
983 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000984 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000985 "GLCaps doesn't know about.");
986 return false;
987}
988
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000989SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000990
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000991 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000992
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000993 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000994 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000995 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000996 i,
997 fStencilFormats[i].fStencilBits,
998 fStencilFormats[i].fTotalBits);
999 }
1000
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001001 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001002 "None",
1003 "ARB",
1004 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001005 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001006 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001007 "IMG MS To Texture",
1008 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001009 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001010 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001011 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1012 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1013 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001014 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1015 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1016 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1017 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001018 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001019 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001020
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001021 static const char* kInvalidateFBTypeStr[] = {
1022 "None",
1023 "Discard",
1024 "Invalidate",
1025 };
1026 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1027 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1028 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1029 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001030
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001031 static const char* kMapBufferTypeStr[] = {
1032 "None",
1033 "MapBuffer",
1034 "MapBufferRange",
1035 "Chromium",
1036 };
1037 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1038 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1039 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1040 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1041 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1042
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001043 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001044 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001045 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001046 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001047 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1048 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001049 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1050 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001051 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
1052 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
1053 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1054 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1055 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1056 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001057
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001058 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1059 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1060 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1061 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1062 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
1063 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001064 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001065 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001066 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1067 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1068 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -07001069 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001070 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001071 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001072 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001073 return r;
1074}
1075
1076////////////////////////////////////////////////////////////////////////////////////////////
1077
bsalomon4ee6bd82015-05-27 13:23:23 -07001078GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options,
1079 const GrGLContextInfo& ctxInfo,
bsalomon424cc262015-05-22 10:37:30 -07001080 const GrGLInterface* gli,
1081 const GrGLCaps& glCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001082 fDropsTileOnZeroDivide = false;
1083 fFBFetchSupport = false;
1084 fFBFetchNeedsCustomOutput = false;
cdalton626e1ff2015-06-12 13:56:46 -07001085 fBindlessTextureSupport = false;
cdalton8917d622015-05-06 13:40:21 -07001086 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
jvanverthe9c0fc62015-04-29 11:18:05 -07001087 fFBFetchColorName = NULL;
1088 fFBFetchExtensionString = NULL;
jvanverthe9c0fc62015-04-29 11:18:05 -07001089}
1090
1091SkString GrGLSLCaps::dump() const {
1092 SkString r = INHERITED::dump();
1093
cdalton8917d622015-05-06 13:40:21 -07001094 static const char* kAdvBlendEqInteractionStr[] = {
1095 "Not Supported",
1096 "Automatic",
1097 "General Enable",
1098 "Specific Enables",
1099 };
1100 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
1101 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
1102 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
1103 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
1104 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
1105
jvanverthe9c0fc62015-04-29 11:18:05 -07001106 r.appendf("--- GLSL-Specific ---\n");
1107
1108 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +00001109 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001110 r.appendf("Bindless texture support: %s\n", (fBindlessTextureSupport ? "YES" : "NO"));
cdalton8917d622015-05-06 13:40:21 -07001111 r.appendf("Advanced blend equation interaction: %s\n",
1112 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001113 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001114}
jvanverthe9c0fc62015-04-29 11:18:05 -07001115
1116static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1117 switch (p) {
1118 case kLow_GrSLPrecision:
1119 return GR_GL_LOW_FLOAT;
1120 case kMedium_GrSLPrecision:
1121 return GR_GL_MEDIUM_FLOAT;
1122 case kHigh_GrSLPrecision:
1123 return GR_GL_HIGH_FLOAT;
1124 }
1125 SkFAIL("Unknown precision.");
1126 return -1;
1127}
1128
1129static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1130 switch (type) {
1131 case kVertex_GrShaderType:
1132 return GR_GL_VERTEX_SHADER;
1133 case kGeometry_GrShaderType:
1134 return GR_GL_GEOMETRY_SHADER;
1135 case kFragment_GrShaderType:
1136 return GR_GL_FRAGMENT_SHADER;
1137 }
1138 SkFAIL("Unknown shader type.");
1139 return -1;
1140}
1141
1142void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1143 const GrGLInterface* intf) {
1144 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1145 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1146 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1147 if (kGeometry_GrShaderType != s) {
1148 GrShaderType shaderType = static_cast<GrShaderType>(s);
1149 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
1150 PrecisionInfo* first = NULL;
1151 fShaderPrecisionVaries = false;
1152 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1153 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1154 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1155 GrGLint range[2];
1156 GrGLint bits;
1157 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1158 if (bits) {
1159 fFloatPrecisions[s][p].fLogRangeLow = range[0];
1160 fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1161 fFloatPrecisions[s][p].fBits = bits;
1162 if (!first) {
1163 first = &fFloatPrecisions[s][p];
1164 }
1165 else if (!fShaderPrecisionVaries) {
1166 fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]);
1167 }
1168 }
1169 }
1170 }
1171 }
1172 }
1173 else {
1174 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
1175 fShaderPrecisionVaries = false;
1176 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1177 if (kGeometry_GrShaderType != s) {
1178 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1179 fFloatPrecisions[s][p].fLogRangeLow = 127;
1180 fFloatPrecisions[s][p].fLogRangeHigh = 127;
1181 fFloatPrecisions[s][p].fBits = 23;
1182 }
1183 }
1184 }
1185 }
1186 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1187 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1188 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1189 // are recommended against.
1190 if (fGeometryShaderSupport) {
1191 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1192 fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p];
1193 }
1194 }
1195}
1196
1197
1198
1199