blob: 6f272b7b8e2d19d7ed610100dcf40d97f3d26dff [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;
jvanverth3f801cb2014-12-16 09:49:38 -080042 fES2CompatibilitySupport = false;
cdalton0edea2c2015-05-21 08:27:44 -070043 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000044 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000046 fFullClearIsFree = false;
piotaixre4b23142014-10-02 10:57:53 -070047
48 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070049
bsalomon424cc262015-05-22 10:37:30 -070050 this->init(ctxInfo, glInterface);
jvanverthe9c0fc62015-04-29 11:18:05 -070051
bsalomon424cc262015-05-22 10:37:30 -070052 fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (ctxInfo, glInterface, *this)));
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000053}
54
bsalomon424cc262015-05-22 10:37:30 -070055void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000056 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000057 GrGLVersion version = ctxInfo.version();
58
bsalomon@google.combcce8922013-03-25 15:38:39 +000059 /**************************************************************************
60 * Caps specific to GrGLCaps
61 **************************************************************************/
62
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000063 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000064 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
65 &fMaxFragmentUniformVectors);
66 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000067 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000068 GrGLint max;
69 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
70 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000071 if (version >= GR_GL_VER(3, 2)) {
72 GrGLint profileMask;
73 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
74 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
75 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000076 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000077 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000078 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000080 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000081 fRGBA8RenderbufferSupport = true;
82 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +000083 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
84 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000085 ctxInfo.hasExtension("GL_ARM_rgba8");
86 }
87
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000088 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000089 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
90 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
91 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +000092 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000093 }
94
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000095 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096 fUnpackRowLengthSupport = true;
97 fUnpackFlipYSupport = false;
98 fPackRowLengthSupport = true;
99 fPackFlipYSupport = false;
100 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000101 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
102 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000103 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000104 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
105 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000106 fPackFlipYSupport =
107 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
108 }
109
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000110 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
112
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000113 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000114 // The EXT version can apply to either GL or GLES.
115 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
116 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
117 ctxInfo.hasExtension("GL_EXT_texture_storage");
118 } else {
119 // Qualcomm Adreno drivers appear to have issues with texture storage.
120 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
121 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
122 ctxInfo.hasExtension("GL_EXT_texture_storage");
123 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124
cdaltonfd4167d2015-04-21 11:45:56 -0700125 if (kGL_GrGLStandard == standard) {
126 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
127 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
128 ctxInfo.hasExtension("GL_NV_texture_barrier");
129 } else {
130 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
131 }
132
hendrikwa0d5ad72014-12-02 07:30:30 -0800133 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
134 // and GL_RG on FBO textures.
135 if (!ctxInfo.isMesa()) {
136 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000137 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
138 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800139 } else {
140 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
141 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000142 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000143 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000144 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000145 ctxInfo.hasExtension("GL_ARB_imaging");
146
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000147 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
148 // ReadPixels. The other format has to checked at run-time since it
149 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000150 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000151
rmistry63a9f842014-10-17 06:07:08 -0700152 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000153 // Known issue on at least some Intel platforms:
154 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700155 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000156 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
157 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
158 }
159
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000160 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
161 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
162 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
163 // limit this decision to specific GPU families rather than basing it on the vendor alone.
164 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700165 (kARM_GrGLVendor == ctxInfo.vendor() ||
166 kImagination_GrGLVendor == ctxInfo.vendor() ||
167 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000168 fUseNonVBOVertexAndIndexDynamicData = true;
169 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000170
egdaniel9250d242015-05-18 13:04:26 -0700171 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
172 // Thus we are blacklisting this extension for now on Adreno4xx devices.
173 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
174 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
175 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
176 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000177 fDiscardRenderTargetSupport = true;
178 fInvalidateFBType = kInvalidate_InvalidateFBType;
179 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
180 fDiscardRenderTargetSupport = true;
181 fInvalidateFBType = kDiscard_InvalidateFBType;
182 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000183
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000184 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
185 fFullClearIsFree = true;
186 }
187
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000188 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000189 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800190 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
191 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000192 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000193 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
194 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000195 }
196
jvanverth3f801cb2014-12-16 09:49:38 -0800197 if (kGL_GrGLStandard == standard) {
198 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
199 }
200 else {
201 fES2CompatibilitySupport = true;
202 }
203
cdalton0edea2c2015-05-21 08:27:44 -0700204 if (kGL_GrGLStandard == standard) {
205 fMultisampleDisableSupport = true;
206 } else {
207 fMultisampleDisableSupport = false;
208 }
209
robertphillips@google.com6177e692013-02-28 20:16:25 +0000210 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000211 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000212
213 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700214 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000215 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000216 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000217 // we could also look for GL_ATI_separate_stencil extension or
218 // GL_EXT_stencil_two_side but they use different function signatures
219 // than GL2.0+ (and than each other).
220 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
221 // supported on GL 1.4 and higher or by extension
222 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
223 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
224 } else {
225 // ES 2 has two sided stencil and stencil wrap
226 fTwoSidedStencilSupport = true;
227 fStencilWrapOpsSupport = true;
228 }
229
egdaniel28eee1a2015-05-08 14:42:43 -0700230// Disabling advanced blend until we can resolve various bugs
231#if 0
cdalton8917d622015-05-06 13:40:21 -0700232 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
233 if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") ||
234 ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
235 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
236 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") ||
237 ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
238 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
239 } else {
240 fBlendEquationSupport = kBasic_BlendEquationSupport;
241 }
242 } else {
243 // On Intel platforms, KHR_blend_equation_advanced is not conformant.
244 fBlendEquationSupport = kBasic_BlendEquationSupport;
245 }
egdaniel28eee1a2015-05-08 14:42:43 -0700246#endif
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000247 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000248 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
249 // extension includes glMapBuffer.
250 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
251 fMapBufferFlags |= kSubset_MapFlag;
252 fMapBufferType = kMapBufferRange_MapBufferType;
253 } else {
254 fMapBufferType = kMapBuffer_MapBufferType;
255 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000256 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000257 // Unextended GLES2 doesn't have any buffer mapping.
258 fMapBufferFlags = kNone_MapBufferType;
259 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
260 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
261 fMapBufferType = kChromium_MapBufferType;
262 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
263 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
264 fMapBufferType = kMapBufferRange_MapBufferType;
265 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
266 fMapBufferFlags = kCanMap_MapFlag;
267 fMapBufferType = kMapBuffer_MapBufferType;
268 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000269 }
270
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000271 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000272 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
273 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
274 fNPOTTextureTileSupport = true;
275 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000276 } else {
277 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000278 // ES3 has no limitations.
279 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
280 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000281 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
282 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
283 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
284 // to alllow arbitrary wrap modes, however.
285 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000286 }
287
bsalomon@google.combcce8922013-03-25 15:38:39 +0000288 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
289 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
290 // Our render targets are always created with textures as the color
291 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000292 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000293
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000294 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
295
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000296 // Disable scratch texture reuse on Mali and Adreno devices
297 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
298 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000299
bsalomon@google.com347c3822013-05-01 20:10:01 +0000300 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000301 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
302 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
303 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
304 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000305
bsalomon63b21962014-11-05 07:05:34 -0800306 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800307 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800308 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800309 fUseDrawInsteadOfClear = true;
310 }
311
bsalomond08ea5f2015-02-20 06:58:13 -0800312 if (kGL_GrGLStandard == standard) {
313 // ARB allows mixed size FBO attachments, EXT does not.
314 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
315 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
316 fOversizedStencilSupport = true;
317 } else {
318 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
319 }
320 } else {
321 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
322 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
323 }
324
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000325 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000326 this->initConfigRenderableTable(ctxInfo);
327}
328
329void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000330 // OpenGL < 3.0
331 // no support for render targets unless the GL_ARB_framebuffer_object
332 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
333 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
334 // probably don't get R8 in this case.
335
336 // OpenGL 3.0
337 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
338 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
339
340 // >= OpenGL 3.1
341 // base color renderable: RED, RG, RGB, and RGBA
342 // sized derivatives: R8, RGBA4, RGBA8
343 // if the GL_ARB_compatibility extension is supported then we get back
344 // support for GL_ALPHA and ALPHA8
345
346 // GL_EXT_bgra adds BGRA render targets to any version
347
348 // ES 2.0
349 // color renderable: RGBA4, RGB5_A1, RGB565
350 // GL_EXT_texture_rg adds support for R8 as a color render target
351 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
352 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
353
354 // ES 3.0
355 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
356 // below already account for this).
357
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000358 GrGLStandard standard = ctxInfo.standard();
359
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000360 enum {
361 kNo_MSAA = 0,
362 kYes_MSAA = 1,
363 };
364
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000365 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000366 // Post 3.0 we will get R8
367 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
368 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
369 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000370 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
371 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000372 }
373 } else {
374 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000375 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
376 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000377 }
378
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000379 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000380 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000381 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
382 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000383 }
384
385 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000386 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
387 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000388
389 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000390 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000391 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000392 }
393
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000394 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000395 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
396 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
397 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000398 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000399 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000400 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
401 } else {
402 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
403 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
404 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000405 }
406
jvanverthfa1e8a72014-12-22 08:31:49 -0800407 if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) {
408 if (kGL_GrGLStandard == standard) {
409 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
410 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
411 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
412 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
413 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
414 }
415 } else {
416 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
417 ctxInfo.hasExtension("GL_EXT_sRGB")) {
418 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
419 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
420 }
421 }
422 }
423
joshualittee5da552014-07-16 13:32:56 -0700424 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800425 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800426 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800427 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
428 } else {
jvanvertha60b2ea2014-12-12 05:58:06 -0800429 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
430 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
431 } else {
432 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
433 }
434 // for now we don't support floating point MSAA on ES
jvanverthfb5df432015-05-21 08:12:27 -0700435 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800436 }
joshualittee5da552014-07-16 13:32:56 -0700437 }
438
jvanverth28f9c602014-12-05 13:06:35 -0800439 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800440 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800441 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800442 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800443 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
444 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
445 // for now we don't support floating point MSAA on ES
446 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800447 } else {
jvanverth1334c212014-12-18 05:44:55 -0800448 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
449 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
450 } else {
451 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
452 }
453 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800454 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
455 }
456 }
457
jvanverthfb5df432015-05-21 08:12:27 -0700458 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
459 if (kGL_GrGLStandard == standard) {
460 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
461 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
462 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
463 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
464 // for now we don't support floating point MSAA on ES
465 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
466 } else {
467 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
468 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
469 } else {
470 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
471 }
472 // for now we don't support floating point MSAA on ES
473 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
474 }
475 }
476
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000477 // If we don't support MSAA then undo any places above where we set a config as renderable with
478 // msaa.
479 if (kNone_MSFBOType == fMSFBOType) {
480 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
481 fConfigRenderSupport[i][kYes_MSAA] = false;
482 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000483 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000484}
485
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000486void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000487 GrGLStandard standard = ctxInfo.standard();
488 GrGLVersion version = ctxInfo.version();
489
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000490 // Base texture support
491 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
492 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
493 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
494 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
495
496 // Check for 8-bit palette..
497 GrGLint numFormats;
498 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
499 if (numFormats) {
500 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
501 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
502 for (int i = 0; i < numFormats; ++i) {
503 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
504 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
505 break;
506 }
507 }
508 }
509
510 // Check for BGRA
511 if (kGL_GrGLStandard == standard) {
512 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
513 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
514 } else {
515 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
516 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
517 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
518 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
519 fBGRAIsInternalFormat = true;
520 }
521 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
522 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
523 }
524
jvanverthfa1e8a72014-12-22 08:31:49 -0800525 // Check for sRGBA
526 if (kGL_GrGLStandard == standard) {
527 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
528 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB"));
529 } else {
530 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
531 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
532 }
533
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000534 // Compressed texture support
535
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000536 // glCompressedTexImage2D is available on all OpenGL ES devices...
537 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000538 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000539
krajcevski786978162014-07-30 11:25:44 -0700540 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700541 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700542
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000543 // Check for ETC1
544 bool hasETC1 = false;
545
546 // First check version for support
547 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000548 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700549 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000550 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000551 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000552 hasETC1 = hasCompressTex2D &&
553 (version >= GR_GL_VER(3, 0) ||
554 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
555 // ETC2 is a superset of ETC1, so we can just check for that, too.
556 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
557 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000558 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000559 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000560
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000561 // Check for LATC under its various forms
562 LATCAlias alias = kLATC_LATCAlias;
563 bool hasLATC = hasCompressTex2D &&
564 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
565 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
566
567 // Check for RGTC
568 if (!hasLATC) {
569 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
570 if (kGL_GrGLStandard == standard) {
571 hasLATC = version >= GR_GL_VER(3, 0);
572 }
573
574 if (!hasLATC) {
575 hasLATC =
576 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
577 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
578 }
579
580 if (hasLATC) {
581 alias = kRGTC_LATCAlias;
582 }
583 }
584
585 // Check for 3DC
586 if (!hasLATC) {
587 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
588 if (hasLATC) {
589 alias = k3DC_LATCAlias;
590 }
591 }
592
593 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
594 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700595
krajcevskib3abe902014-07-30 13:08:11 -0700596 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
597 // cards default to decompressing the textures in the driver, and is
598 // generally slower.
599 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700600 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
601 }
joshualittee5da552014-07-16 13:32:56 -0700602
krajcevski7ef21622014-07-16 15:21:13 -0700603 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700604 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700605 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
606 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
607 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
608
joshualittee5da552014-07-16 13:32:56 -0700609 // Check for floating point texture support
610 // NOTE: We disallow floating point textures on ES devices if linear
611 // filtering modes are not supported. This is for simplicity, but a more
612 // granular approach is possible. Coincidentally, floating point textures became part of
613 // the standard in ES3.1 / OGL 3.1, hence the shorthand
614 bool hasFPTextures = version >= GR_GL_VER(3, 1);
615 if (!hasFPTextures) {
616 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800617 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700618 ctxInfo.hasExtension("GL_OES_texture_float"));
619 }
620 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800621
622 // Check for fp16 texture support
623 // NOTE: We disallow floating point textures on ES devices if linear
624 // filtering modes are not supported. This is for simplicity, but a more
625 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
626 // the standard in ES3.1 / OGL 3.1, hence the shorthand
627 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
628 if (!hasHalfFPTextures) {
629 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800630 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
631 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800632 }
jvanverth1334c212014-12-18 05:44:55 -0800633 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700634 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000635}
636
piotaixre4b23142014-10-02 10:57:53 -0700637bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
638 GrGLenum format,
639 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000640 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
641 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000642 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000643 }
644
645 if (!fTwoFormatLimit) {
646 // not limited by ES 2's constraints
647 return true;
648 }
649
bsalomon@google.com548a4332012-07-11 19:45:22 +0000650 GrGLint otherFormat = GR_GL_RGBA;
651 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000652
653 // The other supported format/type combo supported for ReadPixels
654 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000655 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000656 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
657 &otherFormat);
658
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000659 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000660 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
661 &otherType);
662
bsalomon@google.com548a4332012-07-11 19:45:22 +0000663 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000664}
665
piotaixre4b23142014-10-02 10:57:53 -0700666bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
667 GrGLenum format,
668 GrGLenum type,
669 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800670 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
671 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
672 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700673 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800674 bool supported = this->doReadPixelsSupported(intf, format, type);
675 fReadPixelsSupportedCache.set(key, supported);
676 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700677}
678
robertphillips@google.com6177e692013-02-28 20:16:25 +0000679void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000680
681 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000682 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000683 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
684 // ES3 driver bugs on at least one device with a tiled GPU (N10).
685 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
686 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
687 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
688 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000689 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000690 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
691 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
692 // chrome's extension is equivalent to the EXT msaa
693 // and fbo_blit extensions.
694 fMSFBOType = kDesktop_EXT_MSFBOType;
695 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
696 fMSFBOType = kES_Apple_MSFBOType;
697 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000698 } else {
699 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
700 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000701 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000702 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
703 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000704 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000705 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000706 }
707}
708
709namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700710const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000711}
712
713void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
714
715 // Build up list of legal stencil formats (though perhaps not supported on
716 // the particular gpu/driver) from most preferred to least.
717
718 // these consts are in order of most preferred to least preferred
719 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
720
721 static const StencilFormat
722 // internal Format stencil bits total bits packed?
723 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
724 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
725 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
726 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000727 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000728 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
729
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000730 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000731 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000732 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000733 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
734 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
735
736 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
737 // require FBO support we can expect these are legal formats and don't
738 // check. These also all support the unsized GL_STENCIL_INDEX.
739 fStencilFormats.push_back() = gS8;
740 fStencilFormats.push_back() = gS16;
741 if (supportsPackedDS) {
742 fStencilFormats.push_back() = gD24S8;
743 }
744 fStencilFormats.push_back() = gS4;
745 if (supportsPackedDS) {
746 fStencilFormats.push_back() = gDS;
747 }
748 } else {
749 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
750 // for other formats.
751 // ES doesn't support using the unsized format.
752
753 fStencilFormats.push_back() = gS8;
754 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000755 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
756 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000757 fStencilFormats.push_back() = gD24S8;
758 }
759 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
760 fStencilFormats.push_back() = gS4;
761 }
762 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000763 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000764 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
765}
766
767void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
768 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700769 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000770#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
771 return;
772#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000773 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
774 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000775 int count = fStencilFormats.count();
776 // we expect a really small number of possible formats so linear search
777 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000778 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000779 for (int i = 0; i < count; ++i) {
780 if (format.fInternalFormat ==
781 fStencilFormats[i].fInternalFormat) {
782 fStencilVerifiedColorConfigs[i].markVerified(config);
783 return;
784 }
785 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000786 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000787 "GrGLCaps doesn't know about.");
788}
789
790bool GrGLCaps::isColorConfigAndStencilFormatVerified(
791 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700792 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000793#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
794 return false;
795#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000796 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000797 int count = fStencilFormats.count();
798 // we expect a really small number of possible formats so linear search
799 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000800 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000801 for (int i = 0; i < count; ++i) {
802 if (format.fInternalFormat ==
803 fStencilFormats[i].fInternalFormat) {
804 return fStencilVerifiedColorConfigs[i].isVerified(config);
805 }
806 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000807 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000808 "GLCaps doesn't know about.");
809 return false;
810}
811
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000812SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000813
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000814 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000815
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000816 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000817 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000818 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000819 i,
820 fStencilFormats[i].fStencilBits,
821 fStencilFormats[i].fTotalBits);
822 }
823
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000824 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000825 "None",
826 "ARB",
827 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000828 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000829 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000830 "IMG MS To Texture",
831 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000832 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000833 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
834 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
835 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000836 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
837 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
838 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
839 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000840 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000841
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000842 static const char* kInvalidateFBTypeStr[] = {
843 "None",
844 "Discard",
845 "Invalidate",
846 };
847 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
848 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
849 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
850 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000851
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000852 static const char* kMapBufferTypeStr[] = {
853 "None",
854 "MapBuffer",
855 "MapBufferRange",
856 "Chromium",
857 };
858 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
859 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
860 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
861 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
862 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
863
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000864 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000865 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000866 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000867 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000868 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
869 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000870 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
871 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000872 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
873 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
874 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
875 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
876 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
877 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000878
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000879 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
880 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
881 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
882 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
883 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
884 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000885 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000886 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton0edea2c2015-05-21 08:27:44 -0700887 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000888 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000889 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000890 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -0700891 return r;
892}
893
894////////////////////////////////////////////////////////////////////////////////////////////
895
bsalomon424cc262015-05-22 10:37:30 -0700896GrGLSLCaps::GrGLSLCaps(const GrGLContextInfo& ctxInfo,
897 const GrGLInterface* gli,
898 const GrGLCaps& glCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -0700899 fDropsTileOnZeroDivide = false;
900 fFBFetchSupport = false;
901 fFBFetchNeedsCustomOutput = false;
cdalton8917d622015-05-06 13:40:21 -0700902 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
jvanverthe9c0fc62015-04-29 11:18:05 -0700903 fFBFetchColorName = NULL;
904 fFBFetchExtensionString = NULL;
bsalomon424cc262015-05-22 10:37:30 -0700905 this->init(ctxInfo, gli, glCaps);
jvanverthe9c0fc62015-04-29 11:18:05 -0700906}
907
bsalomon424cc262015-05-22 10:37:30 -0700908void GrGLSLCaps::init(const GrGLContextInfo& ctxInfo,
cdalton8917d622015-05-06 13:40:21 -0700909 const GrGLInterface* gli,
910 const GrGLCaps& glCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -0700911 GrGLStandard standard = ctxInfo.standard();
912 GrGLVersion version = ctxInfo.version();
913
914 /**************************************************************************
915 * Caps specific to GrGLSLCaps
916 **************************************************************************/
917
918 if (kGLES_GrGLStandard == standard) {
919 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
920 fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
921 fFBFetchSupport = true;
922 fFBFetchColorName = "gl_LastFragData[0]";
923 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
924 }
925 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
926 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
927 fFBFetchNeedsCustomOutput = false;
928 fFBFetchSupport = true;
929 fFBFetchColorName = "gl_LastFragData[0]";
930 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
931 }
932 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
933 // The arm extension also requires an additional flag which we will set onResetContext
934 fFBFetchNeedsCustomOutput = false;
935 fFBFetchSupport = true;
936 fFBFetchColorName = "gl_LastFragColorARM";
937 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
938 }
939 }
940
941 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
942 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
943
944 /**************************************************************************
945 * GrShaderCaps fields
946 **************************************************************************/
947
948 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
949
950 if (fPathRenderingSupport) {
951 if (kGL_GrGLStandard == standard) {
952 // We only support v1.3+ of GL_NV_path_rendering which allows us to
953 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
954 // additions are detected by checking the existence of the function.
955 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
956 ((ctxInfo.version() >= GR_GL_VER(4, 3) ||
957 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
958 gli->fFunctions.fProgramPathFragmentInputGen);
959 }
960 else {
961 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3, 1);
962 }
963 }
964
965 // For now these two are equivalent but we could have dst read in shader via some other method
966 fDstReadInShaderSupport = fFBFetchSupport;
967
968 // Enable supported shader-related caps
969 if (kGL_GrGLStandard == standard) {
970 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3, 3) ||
971 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
972 fShaderDerivativeSupport = true;
973 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
974 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
975 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
976 }
977 else {
978 fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
979 ctxInfo.hasExtension("GL_OES_standard_derivatives");
980 }
981
cdalton0edea2c2015-05-21 08:27:44 -0700982 // We need dual source blending and the ability to disable multisample in order to support mixed
983 // samples in every corner case.
984 if (fDualSourceBlendingSupport && glCaps.multisampleDisableSupport()) {
985 // We understand "mixed samples" to mean the collective capability of 3 different extensions
986 fMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") &&
987 ctxInfo.hasExtension("GL_NV_sample_mask_override_coverage") &&
988 ctxInfo.hasExtension("GL_EXT_raster_multisample");
989 }
990
cdalton8917d622015-05-06 13:40:21 -0700991 if (glCaps.advancedBlendEquationSupport()) {
992 bool coherent = glCaps.advancedCoherentBlendEquationSupport();
993 if (ctxInfo.hasExtension(coherent ? "GL_NV_blend_equation_advanced_coherent"
994 : "GL_NV_blend_equation_advanced")) {
995 fAdvBlendEqInteraction = kAutomatic_AdvBlendEqInteraction;
996 } else {
997 fAdvBlendEqInteraction = kGeneralEnable_AdvBlendEqInteraction;
998 // TODO: Use the following on any platform where "blend_support_all_equations" is slow.
999 //fAdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction;
1000 }
1001 }
1002
jvanverthe9c0fc62015-04-29 11:18:05 -07001003 this->initShaderPrecisionTable(ctxInfo, gli);
jvanverthe9c0fc62015-04-29 11:18:05 -07001004}
1005
1006SkString GrGLSLCaps::dump() const {
1007 SkString r = INHERITED::dump();
1008
cdalton8917d622015-05-06 13:40:21 -07001009 static const char* kAdvBlendEqInteractionStr[] = {
1010 "Not Supported",
1011 "Automatic",
1012 "General Enable",
1013 "Specific Enables",
1014 };
1015 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
1016 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
1017 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
1018 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
1019 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
1020
jvanverthe9c0fc62015-04-29 11:18:05 -07001021 r.appendf("--- GLSL-Specific ---\n");
1022
1023 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +00001024 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
cdalton8917d622015-05-06 13:40:21 -07001025 r.appendf("Advanced blend equation interaction: %s\n",
1026 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001027 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001028}
jvanverthe9c0fc62015-04-29 11:18:05 -07001029
1030static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1031 switch (p) {
1032 case kLow_GrSLPrecision:
1033 return GR_GL_LOW_FLOAT;
1034 case kMedium_GrSLPrecision:
1035 return GR_GL_MEDIUM_FLOAT;
1036 case kHigh_GrSLPrecision:
1037 return GR_GL_HIGH_FLOAT;
1038 }
1039 SkFAIL("Unknown precision.");
1040 return -1;
1041}
1042
1043static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1044 switch (type) {
1045 case kVertex_GrShaderType:
1046 return GR_GL_VERTEX_SHADER;
1047 case kGeometry_GrShaderType:
1048 return GR_GL_GEOMETRY_SHADER;
1049 case kFragment_GrShaderType:
1050 return GR_GL_FRAGMENT_SHADER;
1051 }
1052 SkFAIL("Unknown shader type.");
1053 return -1;
1054}
1055
1056void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1057 const GrGLInterface* intf) {
1058 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1059 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1060 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1061 if (kGeometry_GrShaderType != s) {
1062 GrShaderType shaderType = static_cast<GrShaderType>(s);
1063 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
1064 PrecisionInfo* first = NULL;
1065 fShaderPrecisionVaries = false;
1066 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1067 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1068 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1069 GrGLint range[2];
1070 GrGLint bits;
1071 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1072 if (bits) {
1073 fFloatPrecisions[s][p].fLogRangeLow = range[0];
1074 fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1075 fFloatPrecisions[s][p].fBits = bits;
1076 if (!first) {
1077 first = &fFloatPrecisions[s][p];
1078 }
1079 else if (!fShaderPrecisionVaries) {
1080 fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]);
1081 }
1082 }
1083 }
1084 }
1085 }
1086 }
1087 else {
1088 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
1089 fShaderPrecisionVaries = false;
1090 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1091 if (kGeometry_GrShaderType != s) {
1092 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1093 fFloatPrecisions[s][p].fLogRangeLow = 127;
1094 fFloatPrecisions[s][p].fLogRangeHigh = 127;
1095 fFloatPrecisions[s][p].fBits = 23;
1096 }
1097 }
1098 }
1099 }
1100 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1101 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1102 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1103 // are recommended against.
1104 if (fGeometryShaderSupport) {
1105 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1106 fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p];
1107 }
1108 }
1109}
1110
1111
1112
1113