blob: 368e5366e42c6cf690ece1d646a945f2719f27ab [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
15GrGLCaps::GrGLCaps() {
16 this->reset();
17}
18
19void GrGLCaps::reset() {
bsalomon@google.combcce8922013-03-25 15:38:39 +000020 INHERITED::reset();
21
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000022 fVerifiedColorConfigs.reset();
23 fStencilFormats.reset();
24 fStencilVerifiedColorConfigs.reset();
25 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000026 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070027 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000028 fMapBufferType = kNone_MapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000030 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000031 fMaxFragmentTextureUnits = 0;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000032 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000033 fBGRAIsInternalFormat = false;
34 fTextureSwizzleSupport = false;
35 fUnpackRowLengthSupport = false;
36 fUnpackFlipYSupport = false;
37 fPackRowLengthSupport = false;
38 fPackFlipYSupport = false;
39 fTextureUsageSupport = false;
40 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000041 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000042 fImagingSupport = false;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000043 fTwoFormatLimit = false;
bsalomon@google.com706f6682012-10-23 14:53:55 +000044 fFragCoordsConventionSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000045 fVertexArrayObjectSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080046 fES2CompatibilitySupport = 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;
vbuzinov08b4d292015-04-01 06:29:49 -070050 fFBMixedSamplesSupport = false;
piotaixre4b23142014-10-02 10:57:53 -070051
52 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070053
54 fShaderCaps.reset(SkNEW(GrGLSLCaps));
55
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000056}
57
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000058GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000059 *this = caps;
60}
61
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +000062GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) {
bsalomon@google.combcce8922013-03-25 15:38:39 +000063 INHERITED::operator=(caps);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000064 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
65 fStencilFormats = caps.fStencilFormats;
66 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
krajcevski3217c4a2014-06-09 09:10:04 -070067 fLATCAlias = caps.fLATCAlias;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000068 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +000069 fMaxVertexAttributes = caps.fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000070 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000071 fMSFBOType = caps.fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000072 fInvalidateFBType = caps.fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000073 fMapBufferType = caps.fMapBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000074 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000075 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
76 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
77 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
78 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
79 fPackRowLengthSupport = caps.fPackRowLengthSupport;
80 fPackFlipYSupport = caps.fPackFlipYSupport;
81 fTextureUsageSupport = caps.fTextureUsageSupport;
82 fTexStorageSupport = caps.fTexStorageSupport;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000083 fTextureRedSupport = caps.fTextureRedSupport;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000084 fImagingSupport = caps.fImagingSupport;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000085 fTwoFormatLimit = caps.fTwoFormatLimit;
bsalomon@google.com706f6682012-10-23 14:53:55 +000086 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000087 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
jvanverth3f801cb2014-12-16 09:49:38 -080088 fES2CompatibilitySupport = caps.fES2CompatibilitySupport;
bsalomon@google.com96966a52013-02-21 16:34:21 +000089 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000090 fIsCoreProfile = caps.fIsCoreProfile;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +000091 fFullClearIsFree = caps.fFullClearIsFree;
vbuzinov08b4d292015-04-01 06:29:49 -070092 fFBMixedSamplesSupport = caps.fFBMixedSamplesSupport;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000093
jvanverthe9c0fc62015-04-29 11:18:05 -070094 *(reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get())) =
95 *(reinterpret_cast<GrGLSLCaps*>(caps.fShaderCaps.get()));
96
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000097 return *this;
98}
99
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000100bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000101
102 this->reset();
103 if (!ctxInfo.isInitialized()) {
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000104 return false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000105 }
106
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000107 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 GrGLVersion version = ctxInfo.version();
109
bsalomon@google.combcce8922013-03-25 15:38:39 +0000110 /**************************************************************************
111 * Caps specific to GrGLCaps
112 **************************************************************************/
113
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000114 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000115 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
116 &fMaxFragmentUniformVectors);
117 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000118 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000119 GrGLint max;
120 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
121 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +0000122 if (version >= GR_GL_VER(3, 2)) {
123 GrGLint profileMask;
124 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
125 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
126 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000127 }
bsalomon@google.com60da4172012-06-01 19:25:00 +0000128 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000129 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000130
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000131 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000132 fRGBA8RenderbufferSupport = true;
133 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +0000134 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
135 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000136 ctxInfo.hasExtension("GL_ARM_rgba8");
137 }
138
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000139 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000140 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
141 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
142 } else {
commit-bot@chromium.org6364b5e2013-08-20 20:22:52 +0000143 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000144 }
145
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000146 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000147 fUnpackRowLengthSupport = true;
148 fUnpackFlipYSupport = false;
149 fPackRowLengthSupport = true;
150 fPackFlipYSupport = false;
151 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000152 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
153 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000154 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000155 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
156 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000157 fPackFlipYSupport =
158 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
159 }
160
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000161 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000162 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
163
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000164 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000165 // The EXT version can apply to either GL or GLES.
166 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
167 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
168 ctxInfo.hasExtension("GL_EXT_texture_storage");
169 } else {
170 // Qualcomm Adreno drivers appear to have issues with texture storage.
171 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
172 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
173 ctxInfo.hasExtension("GL_EXT_texture_storage");
174 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000175
cdaltonfd4167d2015-04-21 11:45:56 -0700176 if (kGL_GrGLStandard == standard) {
177 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
178 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
179 ctxInfo.hasExtension("GL_NV_texture_barrier");
180 } else {
181 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
182 }
183
hendrikwa0d5ad72014-12-02 07:30:30 -0800184 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
185 // and GL_RG on FBO textures.
186 if (!ctxInfo.isMesa()) {
187 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000188 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
189 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800190 } else {
191 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
192 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000193 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000194 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000195 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000196 ctxInfo.hasExtension("GL_ARB_imaging");
197
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000198 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
199 // ReadPixels. The other format has to checked at run-time since it
200 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000201 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000202
rmistry63a9f842014-10-17 06:07:08 -0700203 // Frag Coords Convention support is not part of ES
bsalomon@google.com706f6682012-10-23 14:53:55 +0000204 // Known issue on at least some Intel platforms:
205 // http://code.google.com/p/skia/issues/detail?id=946
rmistry63a9f842014-10-17 06:07:08 -0700206 if (kIntel_GrGLVendor != ctxInfo.vendor() && kGLES_GrGLStandard != standard) {
bsalomon@google.com706f6682012-10-23 14:53:55 +0000207 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
208 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
209 }
210
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000211 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
212 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
213 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
214 // limit this decision to specific GPU families rather than basing it on the vendor alone.
215 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700216 (kARM_GrGLVendor == ctxInfo.vendor() ||
217 kImagination_GrGLVendor == ctxInfo.vendor() ||
218 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000219 fUseNonVBOVertexAndIndexDynamicData = true;
220 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000221
egdaniel9250d242015-05-18 13:04:26 -0700222 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
223 // Thus we are blacklisting this extension for now on Adreno4xx devices.
224 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
225 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
226 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
227 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000228 fDiscardRenderTargetSupport = true;
229 fInvalidateFBType = kInvalidate_InvalidateFBType;
230 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
231 fDiscardRenderTargetSupport = true;
232 fInvalidateFBType = kDiscard_InvalidateFBType;
233 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000234
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000235 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
236 fFullClearIsFree = true;
237 }
238
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000239 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000240 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800241 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
242 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000243 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000244 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
245 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000246 }
247
jvanverth3f801cb2014-12-16 09:49:38 -0800248 if (kGL_GrGLStandard == standard) {
249 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
250 }
251 else {
252 fES2CompatibilitySupport = true;
253 }
254
robertphillips@google.com6177e692013-02-28 20:16:25 +0000255 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000256 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000257
258 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000259 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000260 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000261 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000262 // we could also look for GL_ATI_separate_stencil extension or
263 // GL_EXT_stencil_two_side but they use different function signatures
264 // than GL2.0+ (and than each other).
265 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
266 // supported on GL 1.4 and higher or by extension
267 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
268 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
269 } else {
270 // ES 2 has two sided stencil and stencil wrap
271 fTwoSidedStencilSupport = true;
272 fStencilWrapOpsSupport = true;
273 }
274
egdaniel28eee1a2015-05-08 14:42:43 -0700275// Disabling advanced blend until we can resolve various bugs
276#if 0
cdalton8917d622015-05-06 13:40:21 -0700277 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
278 if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") ||
279 ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
280 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
281 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") ||
282 ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
283 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
284 } else {
285 fBlendEquationSupport = kBasic_BlendEquationSupport;
286 }
287 } else {
288 // On Intel platforms, KHR_blend_equation_advanced is not conformant.
289 fBlendEquationSupport = kBasic_BlendEquationSupport;
290 }
egdaniel28eee1a2015-05-08 14:42:43 -0700291#endif
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000292 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000293 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
294 // extension includes glMapBuffer.
295 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
296 fMapBufferFlags |= kSubset_MapFlag;
297 fMapBufferType = kMapBufferRange_MapBufferType;
298 } else {
299 fMapBufferType = kMapBuffer_MapBufferType;
300 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000301 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000302 // Unextended GLES2 doesn't have any buffer mapping.
303 fMapBufferFlags = kNone_MapBufferType;
304 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
305 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
306 fMapBufferType = kChromium_MapBufferType;
307 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
308 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
309 fMapBufferType = kMapBufferRange_MapBufferType;
310 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
311 fMapBufferFlags = kCanMap_MapFlag;
312 fMapBufferType = kMapBuffer_MapBufferType;
313 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000314 }
315
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000316 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000317 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
318 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
319 fNPOTTextureTileSupport = true;
320 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000321 } else {
322 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000323 // ES3 has no limitations.
324 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
325 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000326 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
327 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
328 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
329 // to alllow arbitrary wrap modes, however.
330 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000331 }
332
bsalomon@google.combcce8922013-03-25 15:38:39 +0000333 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
334 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
335 // Our render targets are always created with textures as the color
336 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000337 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000338
vbuzinov08b4d292015-04-01 06:29:49 -0700339 fFBMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples");
340
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000341 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
342
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000343 // Disable scratch texture reuse on Mali and Adreno devices
344 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
345 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000346
bsalomon@google.com347c3822013-05-01 20:10:01 +0000347 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000348 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
349 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
350 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
351 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000352
bsalomon63b21962014-11-05 07:05:34 -0800353 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800354 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800355 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800356 fUseDrawInsteadOfClear = true;
357 }
358
bsalomond08ea5f2015-02-20 06:58:13 -0800359 if (kGL_GrGLStandard == standard) {
360 // ARB allows mixed size FBO attachments, EXT does not.
361 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
362 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
363 fOversizedStencilSupport = true;
364 } else {
365 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
366 }
367 } else {
368 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
369 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
370 }
371
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000372 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000373 this->initConfigRenderableTable(ctxInfo);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000374
cdalton8917d622015-05-06 13:40:21 -0700375 reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get())->init(ctxInfo, gli, *this);
bsalomon17168df2014-12-09 09:00:49 -0800376
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000377 return true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000378}
379
380void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000381 // OpenGL < 3.0
382 // no support for render targets unless the GL_ARB_framebuffer_object
383 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
384 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
385 // probably don't get R8 in this case.
386
387 // OpenGL 3.0
388 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
389 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
390
391 // >= OpenGL 3.1
392 // base color renderable: RED, RG, RGB, and RGBA
393 // sized derivatives: R8, RGBA4, RGBA8
394 // if the GL_ARB_compatibility extension is supported then we get back
395 // support for GL_ALPHA and ALPHA8
396
397 // GL_EXT_bgra adds BGRA render targets to any version
398
399 // ES 2.0
400 // color renderable: RGBA4, RGB5_A1, RGB565
401 // GL_EXT_texture_rg adds support for R8 as a color render target
402 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
403 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
404
405 // ES 3.0
406 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
407 // below already account for this).
408
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000409 GrGLStandard standard = ctxInfo.standard();
410
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000411 enum {
412 kNo_MSAA = 0,
413 kYes_MSAA = 1,
414 };
415
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000416 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000417 // Post 3.0 we will get R8
418 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
419 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
420 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000421 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
422 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000423 }
424 } else {
425 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000426 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
427 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000428 }
429
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000430 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000431 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000432 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
433 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000434 }
435
436 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000437 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
438 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000439
440 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000441 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000442 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000443 }
444
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000445 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000446 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
447 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
448 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000449 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000450 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000451 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
452 } else {
453 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
454 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
455 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000456 }
457
jvanverthfa1e8a72014-12-22 08:31:49 -0800458 if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) {
459 if (kGL_GrGLStandard == standard) {
460 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
461 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
462 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
463 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
464 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
465 }
466 } else {
467 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
468 ctxInfo.hasExtension("GL_EXT_sRGB")) {
469 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
470 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
471 }
472 }
473 }
474
joshualittee5da552014-07-16 13:32:56 -0700475 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800476 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800477 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800478 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
479 } else {
jvanvertha60b2ea2014-12-12 05:58:06 -0800480 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
481 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
482 } else {
483 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
484 }
485 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800486 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
487 }
joshualittee5da552014-07-16 13:32:56 -0700488 }
489
jvanverth28f9c602014-12-05 13:06:35 -0800490 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800491 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800492 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800493 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800494 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
495 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
496 // for now we don't support floating point MSAA on ES
497 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800498 } else {
jvanverth1334c212014-12-18 05:44:55 -0800499 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
500 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
501 } else {
502 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
503 }
504 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800505 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
506 }
507 }
508
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000509 // If we don't support MSAA then undo any places above where we set a config as renderable with
510 // msaa.
511 if (kNone_MSFBOType == fMSFBOType) {
512 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
513 fConfigRenderSupport[i][kYes_MSAA] = false;
514 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000515 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000516}
517
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000518void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000519 GrGLStandard standard = ctxInfo.standard();
520 GrGLVersion version = ctxInfo.version();
521
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000522 // Base texture support
523 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
524 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
525 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
526 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
527
528 // Check for 8-bit palette..
529 GrGLint numFormats;
530 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
531 if (numFormats) {
532 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
533 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
534 for (int i = 0; i < numFormats; ++i) {
535 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
536 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
537 break;
538 }
539 }
540 }
541
542 // Check for BGRA
543 if (kGL_GrGLStandard == standard) {
544 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
545 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
546 } else {
547 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
548 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
549 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
550 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
551 fBGRAIsInternalFormat = true;
552 }
553 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
554 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
555 }
556
jvanverthfa1e8a72014-12-22 08:31:49 -0800557 // Check for sRGBA
558 if (kGL_GrGLStandard == standard) {
559 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
560 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB"));
561 } else {
562 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
563 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
564 }
565
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000566 // Compressed texture support
567
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000568 // glCompressedTexImage2D is available on all OpenGL ES devices...
569 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000570 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000571
krajcevski786978162014-07-30 11:25:44 -0700572 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700573 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700574
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000575 // Check for ETC1
576 bool hasETC1 = false;
577
578 // First check version for support
579 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000580 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700581 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000582 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000583 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000584 hasETC1 = hasCompressTex2D &&
585 (version >= GR_GL_VER(3, 0) ||
586 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
587 // ETC2 is a superset of ETC1, so we can just check for that, too.
588 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
589 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000590 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000591 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000592
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000593 // Check for LATC under its various forms
594 LATCAlias alias = kLATC_LATCAlias;
595 bool hasLATC = hasCompressTex2D &&
596 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
597 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
598
599 // Check for RGTC
600 if (!hasLATC) {
601 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
602 if (kGL_GrGLStandard == standard) {
603 hasLATC = version >= GR_GL_VER(3, 0);
604 }
605
606 if (!hasLATC) {
607 hasLATC =
608 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
609 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
610 }
611
612 if (hasLATC) {
613 alias = kRGTC_LATCAlias;
614 }
615 }
616
617 // Check for 3DC
618 if (!hasLATC) {
619 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
620 if (hasLATC) {
621 alias = k3DC_LATCAlias;
622 }
623 }
624
625 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
626 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700627
krajcevskib3abe902014-07-30 13:08:11 -0700628 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
629 // cards default to decompressing the textures in the driver, and is
630 // generally slower.
631 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700632 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
633 }
joshualittee5da552014-07-16 13:32:56 -0700634
krajcevski7ef21622014-07-16 15:21:13 -0700635 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700636 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700637 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
638 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
639 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
640
joshualittee5da552014-07-16 13:32:56 -0700641 // Check for floating point texture support
642 // NOTE: We disallow floating point textures on ES devices if linear
643 // filtering modes are not supported. This is for simplicity, but a more
644 // granular approach is possible. Coincidentally, floating point textures became part of
645 // the standard in ES3.1 / OGL 3.1, hence the shorthand
646 bool hasFPTextures = version >= GR_GL_VER(3, 1);
647 if (!hasFPTextures) {
648 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800649 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700650 ctxInfo.hasExtension("GL_OES_texture_float"));
651 }
652 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800653
654 // Check for fp16 texture support
655 // NOTE: We disallow floating point textures on ES devices if linear
656 // filtering modes are not supported. This is for simplicity, but a more
657 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
658 // the standard in ES3.1 / OGL 3.1, hence the shorthand
659 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
660 if (!hasHalfFPTextures) {
661 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800662 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
663 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800664 }
jvanverth1334c212014-12-18 05:44:55 -0800665 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000666}
667
piotaixre4b23142014-10-02 10:57:53 -0700668bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
669 GrGLenum format,
670 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000671 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
672 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000673 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000674 }
675
676 if (!fTwoFormatLimit) {
677 // not limited by ES 2's constraints
678 return true;
679 }
680
bsalomon@google.com548a4332012-07-11 19:45:22 +0000681 GrGLint otherFormat = GR_GL_RGBA;
682 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000683
684 // The other supported format/type combo supported for ReadPixels
685 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000686 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000687 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
688 &otherFormat);
689
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000690 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000691 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
692 &otherType);
693
bsalomon@google.com548a4332012-07-11 19:45:22 +0000694 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000695}
696
piotaixre4b23142014-10-02 10:57:53 -0700697bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
698 GrGLenum format,
699 GrGLenum type,
700 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800701 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
702 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
703 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700704 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800705 bool supported = this->doReadPixelsSupported(intf, format, type);
706 fReadPixelsSupportedCache.set(key, supported);
707 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700708}
709
robertphillips@google.com6177e692013-02-28 20:16:25 +0000710void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000711
712 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000713 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000714 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
715 // ES3 driver bugs on at least one device with a tiled GPU (N10).
716 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
717 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
718 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
719 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000720 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000721 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
722 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
723 // chrome's extension is equivalent to the EXT msaa
724 // and fbo_blit extensions.
725 fMSFBOType = kDesktop_EXT_MSFBOType;
726 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
727 fMSFBOType = kES_Apple_MSFBOType;
728 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000729 } else {
730 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
731 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000732 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000733 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
734 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000735 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000736 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000737 }
738}
739
740namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700741const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000742}
743
744void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
745
746 // Build up list of legal stencil formats (though perhaps not supported on
747 // the particular gpu/driver) from most preferred to least.
748
749 // these consts are in order of most preferred to least preferred
750 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
751
752 static const StencilFormat
753 // internal Format stencil bits total bits packed?
754 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
755 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
756 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
757 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000758 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000759 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
760
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000761 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000762 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000763 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000764 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
765 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
766
767 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
768 // require FBO support we can expect these are legal formats and don't
769 // check. These also all support the unsized GL_STENCIL_INDEX.
770 fStencilFormats.push_back() = gS8;
771 fStencilFormats.push_back() = gS16;
772 if (supportsPackedDS) {
773 fStencilFormats.push_back() = gD24S8;
774 }
775 fStencilFormats.push_back() = gS4;
776 if (supportsPackedDS) {
777 fStencilFormats.push_back() = gDS;
778 }
779 } else {
780 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
781 // for other formats.
782 // ES doesn't support using the unsized format.
783
784 fStencilFormats.push_back() = gS8;
785 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000786 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
787 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000788 fStencilFormats.push_back() = gD24S8;
789 }
790 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
791 fStencilFormats.push_back() = gS4;
792 }
793 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000794 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000795 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
796}
797
798void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
799 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700800 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000801#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
802 return;
803#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000804 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
805 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000806 int count = fStencilFormats.count();
807 // we expect a really small number of possible formats so linear search
808 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000809 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000810 for (int i = 0; i < count; ++i) {
811 if (format.fInternalFormat ==
812 fStencilFormats[i].fInternalFormat) {
813 fStencilVerifiedColorConfigs[i].markVerified(config);
814 return;
815 }
816 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000817 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000818 "GrGLCaps doesn't know about.");
819}
820
821bool GrGLCaps::isColorConfigAndStencilFormatVerified(
822 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700823 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000824#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
825 return false;
826#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000827 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000828 int count = fStencilFormats.count();
829 // we expect a really small number of possible formats so linear search
830 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000831 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000832 for (int i = 0; i < count; ++i) {
833 if (format.fInternalFormat ==
834 fStencilFormats[i].fInternalFormat) {
835 return fStencilVerifiedColorConfigs[i].isVerified(config);
836 }
837 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000838 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000839 "GLCaps doesn't know about.");
840 return false;
841}
842
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000843SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000844
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000845 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000846
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000847 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000848 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000849 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000850 i,
851 fStencilFormats[i].fStencilBits,
852 fStencilFormats[i].fTotalBits);
853 }
854
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000855 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000856 "None",
857 "ARB",
858 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000859 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000860 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000861 "IMG MS To Texture",
862 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000863 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000864 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
865 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
866 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000867 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
868 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
869 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
870 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000871 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000872
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000873 static const char* kInvalidateFBTypeStr[] = {
874 "None",
875 "Discard",
876 "Invalidate",
877 };
878 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
879 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
880 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
881 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000882
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000883 static const char* kMapBufferTypeStr[] = {
884 "None",
885 "MapBuffer",
886 "MapBufferRange",
887 "Chromium",
888 };
889 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
890 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
891 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
892 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
893 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
894
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000895 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000896 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000897 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000898 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000899 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
900 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000901 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
902 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000903 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
904 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
905 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
906 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
907 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
908 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000909
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000910 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
911 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
912 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
913 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
914 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
915 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000916 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000917 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
918 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000919 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000920 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -0700921 return r;
922}
923
924////////////////////////////////////////////////////////////////////////////////////////////
925
926GrGLSLCaps::GrGLSLCaps() {
927 this->reset();
928}
929
930
931void GrGLSLCaps::reset() {
932 INHERITED::reset();
933
934 fDropsTileOnZeroDivide = false;
935 fFBFetchSupport = false;
936 fFBFetchNeedsCustomOutput = false;
cdalton8917d622015-05-06 13:40:21 -0700937 fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction;
jvanverthe9c0fc62015-04-29 11:18:05 -0700938 fFBFetchColorName = NULL;
939 fFBFetchExtensionString = NULL;
940}
941
942GrGLSLCaps::GrGLSLCaps(const GrGLSLCaps& caps) : GrShaderCaps() {
943 *this = caps;
944}
945
946GrGLSLCaps& GrGLSLCaps::operator= (const GrGLSLCaps& caps) {
947 INHERITED::operator=(caps);
948 fDropsTileOnZeroDivide = caps.fDropsTileOnZeroDivide;
949 fFBFetchSupport = caps.fFBFetchSupport;
950 fFBFetchNeedsCustomOutput = caps.fFBFetchNeedsCustomOutput;
cdalton8917d622015-05-06 13:40:21 -0700951 fAdvBlendEqInteraction = caps.fAdvBlendEqInteraction;
jvanverthe9c0fc62015-04-29 11:18:05 -0700952 fFBFetchColorName = caps.fFBFetchColorName;
953 fFBFetchExtensionString = caps.fFBFetchExtensionString;
954
955 return *this;
956}
957
cdalton8917d622015-05-06 13:40:21 -0700958bool GrGLSLCaps::init(const GrGLContextInfo& ctxInfo,
959 const GrGLInterface* gli,
960 const GrGLCaps& glCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -0700961 this->reset();
962 if (!ctxInfo.isInitialized()) {
963 return false;
964 }
965
966 GrGLStandard standard = ctxInfo.standard();
967 GrGLVersion version = ctxInfo.version();
968
969 /**************************************************************************
970 * Caps specific to GrGLSLCaps
971 **************************************************************************/
972
973 if (kGLES_GrGLStandard == standard) {
974 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
975 fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
976 fFBFetchSupport = true;
977 fFBFetchColorName = "gl_LastFragData[0]";
978 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
979 }
980 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
981 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
982 fFBFetchNeedsCustomOutput = false;
983 fFBFetchSupport = true;
984 fFBFetchColorName = "gl_LastFragData[0]";
985 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
986 }
987 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
988 // The arm extension also requires an additional flag which we will set onResetContext
989 fFBFetchNeedsCustomOutput = false;
990 fFBFetchSupport = true;
991 fFBFetchColorName = "gl_LastFragColorARM";
992 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
993 }
994 }
995
996 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
997 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
998
999 /**************************************************************************
1000 * GrShaderCaps fields
1001 **************************************************************************/
1002
1003 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
1004
1005 if (fPathRenderingSupport) {
1006 if (kGL_GrGLStandard == standard) {
1007 // We only support v1.3+ of GL_NV_path_rendering which allows us to
1008 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
1009 // additions are detected by checking the existence of the function.
1010 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
1011 ((ctxInfo.version() >= GR_GL_VER(4, 3) ||
1012 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
1013 gli->fFunctions.fProgramPathFragmentInputGen);
1014 }
1015 else {
1016 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3, 1);
1017 }
1018 }
1019
1020 // For now these two are equivalent but we could have dst read in shader via some other method
1021 fDstReadInShaderSupport = fFBFetchSupport;
1022
1023 // Enable supported shader-related caps
1024 if (kGL_GrGLStandard == standard) {
1025 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3, 3) ||
1026 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
1027 fShaderDerivativeSupport = true;
1028 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
1029 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
1030 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
1031 }
1032 else {
1033 fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
1034 ctxInfo.hasExtension("GL_OES_standard_derivatives");
1035 }
1036
cdalton8917d622015-05-06 13:40:21 -07001037 if (glCaps.advancedBlendEquationSupport()) {
1038 bool coherent = glCaps.advancedCoherentBlendEquationSupport();
1039 if (ctxInfo.hasExtension(coherent ? "GL_NV_blend_equation_advanced_coherent"
1040 : "GL_NV_blend_equation_advanced")) {
1041 fAdvBlendEqInteraction = kAutomatic_AdvBlendEqInteraction;
1042 } else {
1043 fAdvBlendEqInteraction = kGeneralEnable_AdvBlendEqInteraction;
1044 // TODO: Use the following on any platform where "blend_support_all_equations" is slow.
1045 //fAdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction;
1046 }
1047 }
1048
jvanverthe9c0fc62015-04-29 11:18:05 -07001049 this->initShaderPrecisionTable(ctxInfo, gli);
1050
1051 return true;
1052}
1053
1054SkString GrGLSLCaps::dump() const {
1055 SkString r = INHERITED::dump();
1056
cdalton8917d622015-05-06 13:40:21 -07001057 static const char* kAdvBlendEqInteractionStr[] = {
1058 "Not Supported",
1059 "Automatic",
1060 "General Enable",
1061 "Specific Enables",
1062 };
1063 GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction);
1064 GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction);
1065 GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction);
1066 GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction);
1067 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1);
1068
jvanverthe9c0fc62015-04-29 11:18:05 -07001069 r.appendf("--- GLSL-Specific ---\n");
1070
1071 r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO"));
commit-bot@chromium.org4362a382014-03-26 19:49:03 +00001072 r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO"));
cdalton8917d622015-05-06 13:40:21 -07001073 r.appendf("Advanced blend equation interaction: %s\n",
1074 kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001075 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001076}
jvanverthe9c0fc62015-04-29 11:18:05 -07001077
1078static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1079 switch (p) {
1080 case kLow_GrSLPrecision:
1081 return GR_GL_LOW_FLOAT;
1082 case kMedium_GrSLPrecision:
1083 return GR_GL_MEDIUM_FLOAT;
1084 case kHigh_GrSLPrecision:
1085 return GR_GL_HIGH_FLOAT;
1086 }
1087 SkFAIL("Unknown precision.");
1088 return -1;
1089}
1090
1091static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1092 switch (type) {
1093 case kVertex_GrShaderType:
1094 return GR_GL_VERTEX_SHADER;
1095 case kGeometry_GrShaderType:
1096 return GR_GL_GEOMETRY_SHADER;
1097 case kFragment_GrShaderType:
1098 return GR_GL_FRAGMENT_SHADER;
1099 }
1100 SkFAIL("Unknown shader type.");
1101 return -1;
1102}
1103
1104void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1105 const GrGLInterface* intf) {
1106 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1107 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1108 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1109 if (kGeometry_GrShaderType != s) {
1110 GrShaderType shaderType = static_cast<GrShaderType>(s);
1111 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
1112 PrecisionInfo* first = NULL;
1113 fShaderPrecisionVaries = false;
1114 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1115 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1116 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1117 GrGLint range[2];
1118 GrGLint bits;
1119 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1120 if (bits) {
1121 fFloatPrecisions[s][p].fLogRangeLow = range[0];
1122 fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1123 fFloatPrecisions[s][p].fBits = bits;
1124 if (!first) {
1125 first = &fFloatPrecisions[s][p];
1126 }
1127 else if (!fShaderPrecisionVaries) {
1128 fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]);
1129 }
1130 }
1131 }
1132 }
1133 }
1134 }
1135 else {
1136 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
1137 fShaderPrecisionVaries = false;
1138 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1139 if (kGeometry_GrShaderType != s) {
1140 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1141 fFloatPrecisions[s][p].fLogRangeLow = 127;
1142 fFloatPrecisions[s][p].fLogRangeHigh = 127;
1143 fFloatPrecisions[s][p].fBits = 23;
1144 }
1145 }
1146 }
1147 }
1148 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1149 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1150 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1151 // are recommended against.
1152 if (fGeometryShaderSupport) {
1153 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1154 fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p];
1155 }
1156 }
1157}
1158
1159
1160
1161