blob: 2edf1d0219ac6e3ad4f4f7a1eabb8acfc5955bfa [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
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000222 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
skia.committer@gmail.coma9157722014-04-03 03:04:26 +0000223 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000224 ctxInfo.hasExtension("GL_ARB_invalidate_subdata")) {
225 fDiscardRenderTargetSupport = true;
226 fInvalidateFBType = kInvalidate_InvalidateFBType;
227 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
228 fDiscardRenderTargetSupport = true;
229 fInvalidateFBType = kDiscard_InvalidateFBType;
230 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000231
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000232 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
233 fFullClearIsFree = true;
234 }
235
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000236 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000237 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800238 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
239 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000240 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000241 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
242 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000243 }
244
jvanverth3f801cb2014-12-16 09:49:38 -0800245 if (kGL_GrGLStandard == standard) {
246 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
247 }
248 else {
249 fES2CompatibilitySupport = true;
250 }
251
robertphillips@google.com6177e692013-02-28 20:16:25 +0000252 this->initFSAASupport(ctxInfo, gli);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000253 this->initStencilFormats(ctxInfo);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000254
255 /**************************************************************************
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000256 * GrDrawTargetCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000257 **************************************************************************/
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000258 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000259 // we could also look for GL_ATI_separate_stencil extension or
260 // GL_EXT_stencil_two_side but they use different function signatures
261 // than GL2.0+ (and than each other).
262 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
263 // supported on GL 1.4 and higher or by extension
264 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
265 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
266 } else {
267 // ES 2 has two sided stencil and stencil wrap
268 fTwoSidedStencilSupport = true;
269 fStencilWrapOpsSupport = true;
270 }
271
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000272 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000273 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
274 // extension includes glMapBuffer.
275 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
276 fMapBufferFlags |= kSubset_MapFlag;
277 fMapBufferType = kMapBufferRange_MapBufferType;
278 } else {
279 fMapBufferType = kMapBuffer_MapBufferType;
280 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000281 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000282 // Unextended GLES2 doesn't have any buffer mapping.
283 fMapBufferFlags = kNone_MapBufferType;
284 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
285 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
286 fMapBufferType = kChromium_MapBufferType;
287 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
288 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
289 fMapBufferType = kMapBufferRange_MapBufferType;
290 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
291 fMapBufferFlags = kCanMap_MapFlag;
292 fMapBufferType = kMapBuffer_MapBufferType;
293 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000294 }
295
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000296 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000297 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
298 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
299 fNPOTTextureTileSupport = true;
300 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000301 } else {
302 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000303 // ES3 has no limitations.
304 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
305 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000306 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
307 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
308 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
309 // to alllow arbitrary wrap modes, however.
310 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000311 }
312
bsalomon@google.combcce8922013-03-25 15:38:39 +0000313 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
314 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
315 // Our render targets are always created with textures as the color
316 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000317 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000318
vbuzinov08b4d292015-04-01 06:29:49 -0700319 fFBMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples");
320
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000321 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
322
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000323 // Disable scratch texture reuse on Mali and Adreno devices
324 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
325 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000326
bsalomon@google.com347c3822013-05-01 20:10:01 +0000327 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000328 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
329 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
330 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
331 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000332
bsalomon63b21962014-11-05 07:05:34 -0800333 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800334 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800335 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800336 fUseDrawInsteadOfClear = true;
337 }
338
bsalomond08ea5f2015-02-20 06:58:13 -0800339 if (kGL_GrGLStandard == standard) {
340 // ARB allows mixed size FBO attachments, EXT does not.
341 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
342 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
343 fOversizedStencilSupport = true;
344 } else {
345 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
346 }
347 } else {
348 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
349 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
350 }
351
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000352 this->initConfigTexturableTable(ctxInfo, gli);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000353 this->initConfigRenderableTable(ctxInfo);
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000354
jvanverthe9c0fc62015-04-29 11:18:05 -0700355 reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get())->init(ctxInfo, gli);
bsalomon17168df2014-12-09 09:00:49 -0800356
commit-bot@chromium.orgf4e67e32014-04-30 01:26:04 +0000357 return true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000358}
359
360void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000361 // OpenGL < 3.0
362 // no support for render targets unless the GL_ARB_framebuffer_object
363 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
364 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
365 // probably don't get R8 in this case.
366
367 // OpenGL 3.0
368 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
369 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
370
371 // >= OpenGL 3.1
372 // base color renderable: RED, RG, RGB, and RGBA
373 // sized derivatives: R8, RGBA4, RGBA8
374 // if the GL_ARB_compatibility extension is supported then we get back
375 // support for GL_ALPHA and ALPHA8
376
377 // GL_EXT_bgra adds BGRA render targets to any version
378
379 // ES 2.0
380 // color renderable: RGBA4, RGB5_A1, RGB565
381 // GL_EXT_texture_rg adds support for R8 as a color render target
382 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
383 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
384
385 // ES 3.0
386 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
387 // below already account for this).
388
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000389 GrGLStandard standard = ctxInfo.standard();
390
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000391 enum {
392 kNo_MSAA = 0,
393 kYes_MSAA = 1,
394 };
395
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000396 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000397 // Post 3.0 we will get R8
398 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
399 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
400 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000401 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
402 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000403 }
404 } else {
405 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000406 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
407 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000408 }
409
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000410 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000411 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000412 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
413 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000414 }
415
416 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000417 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
418 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000419
420 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000421 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000422 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000423 }
424
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000425 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000426 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
427 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
428 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000429 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000430 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000431 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
432 } else {
433 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
434 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
435 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000436 }
437
jvanverthfa1e8a72014-12-22 08:31:49 -0800438 if (this->fRGBA8RenderbufferSupport && this->isConfigTexturable(kSRGBA_8888_GrPixelConfig)) {
439 if (kGL_GrGLStandard == standard) {
440 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
441 ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
442 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
443 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
444 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
445 }
446 } else {
447 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
448 ctxInfo.hasExtension("GL_EXT_sRGB")) {
449 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
450 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
451 }
452 }
453 }
454
joshualittee5da552014-07-16 13:32:56 -0700455 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800456 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800457 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800458 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
459 } else {
jvanvertha60b2ea2014-12-12 05:58:06 -0800460 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
461 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
462 } else {
463 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
464 }
465 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800466 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
467 }
joshualittee5da552014-07-16 13:32:56 -0700468 }
469
jvanverth28f9c602014-12-05 13:06:35 -0800470 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800471 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800472 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800473 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800474 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
475 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
476 // for now we don't support floating point MSAA on ES
477 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800478 } else {
jvanverth1334c212014-12-18 05:44:55 -0800479 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
480 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
481 } else {
482 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
483 }
484 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800485 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
486 }
487 }
488
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000489 // If we don't support MSAA then undo any places above where we set a config as renderable with
490 // msaa.
491 if (kNone_MSFBOType == fMSFBOType) {
492 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
493 fConfigRenderSupport[i][kYes_MSAA] = false;
494 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000495 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000496}
497
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000498void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000499 GrGLStandard standard = ctxInfo.standard();
500 GrGLVersion version = ctxInfo.version();
501
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000502 // Base texture support
503 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
504 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
505 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
506 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
507
508 // Check for 8-bit palette..
509 GrGLint numFormats;
510 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
511 if (numFormats) {
512 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
513 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
514 for (int i = 0; i < numFormats; ++i) {
515 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
516 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
517 break;
518 }
519 }
520 }
521
522 // Check for BGRA
523 if (kGL_GrGLStandard == standard) {
524 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
525 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
526 } else {
527 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
528 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
529 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
530 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
531 fBGRAIsInternalFormat = true;
532 }
533 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
534 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
535 }
536
jvanverthfa1e8a72014-12-22 08:31:49 -0800537 // Check for sRGBA
538 if (kGL_GrGLStandard == standard) {
539 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
540 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_sRGB"));
541 } else {
542 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] =
543 (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
544 }
545
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000546 // Compressed texture support
547
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000548 // glCompressedTexImage2D is available on all OpenGL ES devices...
549 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000550 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000551
krajcevski786978162014-07-30 11:25:44 -0700552 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700553 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700554
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000555 // Check for ETC1
556 bool hasETC1 = false;
557
558 // First check version for support
559 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000560 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700561 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000562 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000563 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000564 hasETC1 = hasCompressTex2D &&
565 (version >= GR_GL_VER(3, 0) ||
566 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
567 // ETC2 is a superset of ETC1, so we can just check for that, too.
568 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
569 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000570 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000571 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000572
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000573 // Check for LATC under its various forms
574 LATCAlias alias = kLATC_LATCAlias;
575 bool hasLATC = hasCompressTex2D &&
576 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
577 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
578
579 // Check for RGTC
580 if (!hasLATC) {
581 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
582 if (kGL_GrGLStandard == standard) {
583 hasLATC = version >= GR_GL_VER(3, 0);
584 }
585
586 if (!hasLATC) {
587 hasLATC =
588 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
589 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
590 }
591
592 if (hasLATC) {
593 alias = kRGTC_LATCAlias;
594 }
595 }
596
597 // Check for 3DC
598 if (!hasLATC) {
599 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
600 if (hasLATC) {
601 alias = k3DC_LATCAlias;
602 }
603 }
604
605 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
606 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700607
krajcevskib3abe902014-07-30 13:08:11 -0700608 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
609 // cards default to decompressing the textures in the driver, and is
610 // generally slower.
611 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700612 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
613 }
joshualittee5da552014-07-16 13:32:56 -0700614
krajcevski7ef21622014-07-16 15:21:13 -0700615 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700616 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700617 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
618 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
619 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
620
joshualittee5da552014-07-16 13:32:56 -0700621 // Check for floating point texture support
622 // NOTE: We disallow floating point textures on ES devices if linear
623 // filtering modes are not supported. This is for simplicity, but a more
624 // granular approach is possible. Coincidentally, floating point textures became part of
625 // the standard in ES3.1 / OGL 3.1, hence the shorthand
626 bool hasFPTextures = version >= GR_GL_VER(3, 1);
627 if (!hasFPTextures) {
628 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800629 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700630 ctxInfo.hasExtension("GL_OES_texture_float"));
631 }
632 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800633
634 // Check for fp16 texture support
635 // NOTE: We disallow floating point textures on ES devices if linear
636 // filtering modes are not supported. This is for simplicity, but a more
637 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
638 // the standard in ES3.1 / OGL 3.1, hence the shorthand
639 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
640 if (!hasHalfFPTextures) {
641 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800642 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
643 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800644 }
jvanverth1334c212014-12-18 05:44:55 -0800645 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000646}
647
piotaixre4b23142014-10-02 10:57:53 -0700648bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
649 GrGLenum format,
650 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000651 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
652 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000653 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000654 }
655
656 if (!fTwoFormatLimit) {
657 // not limited by ES 2's constraints
658 return true;
659 }
660
bsalomon@google.com548a4332012-07-11 19:45:22 +0000661 GrGLint otherFormat = GR_GL_RGBA;
662 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000663
664 // The other supported format/type combo supported for ReadPixels
665 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000666 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000667 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
668 &otherFormat);
669
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000670 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000671 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
672 &otherType);
673
bsalomon@google.com548a4332012-07-11 19:45:22 +0000674 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000675}
676
piotaixre4b23142014-10-02 10:57:53 -0700677bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
678 GrGLenum format,
679 GrGLenum type,
680 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800681 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
682 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
683 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700684 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800685 bool supported = this->doReadPixelsSupported(intf, format, type);
686 fReadPixelsSupportedCache.set(key, supported);
687 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700688}
689
robertphillips@google.com6177e692013-02-28 20:16:25 +0000690void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000691
692 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000693 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000694 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
695 // ES3 driver bugs on at least one device with a tiled GPU (N10).
696 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
697 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
698 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
699 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +0000700 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000701 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
702 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
703 // chrome's extension is equivalent to the EXT msaa
704 // and fbo_blit extensions.
705 fMSFBOType = kDesktop_EXT_MSFBOType;
706 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
707 fMSFBOType = kES_Apple_MSFBOType;
708 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000709 } else {
710 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
711 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000712 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000713 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
714 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +0000715 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000716 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000717 }
718}
719
720namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -0700721const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000722}
723
724void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
725
726 // Build up list of legal stencil formats (though perhaps not supported on
727 // the particular gpu/driver) from most preferred to least.
728
729 // these consts are in order of most preferred to least preferred
730 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
731
732 static const StencilFormat
733 // internal Format stencil bits total bits packed?
734 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
735 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
736 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
737 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000738 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000739 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
740
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000741 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000742 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000743 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000744 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
745 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
746
747 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
748 // require FBO support we can expect these are legal formats and don't
749 // check. These also all support the unsized GL_STENCIL_INDEX.
750 fStencilFormats.push_back() = gS8;
751 fStencilFormats.push_back() = gS16;
752 if (supportsPackedDS) {
753 fStencilFormats.push_back() = gD24S8;
754 }
755 fStencilFormats.push_back() = gS4;
756 if (supportsPackedDS) {
757 fStencilFormats.push_back() = gDS;
758 }
759 } else {
760 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
761 // for other formats.
762 // ES doesn't support using the unsized format.
763
764 fStencilFormats.push_back() = gS8;
765 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +0000766 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
767 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000768 fStencilFormats.push_back() = gD24S8;
769 }
770 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
771 fStencilFormats.push_back() = gS4;
772 }
773 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000774 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000775 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
776}
777
778void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
779 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700780 const GrGLStencilAttachment::Format& format) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000781#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
782 return;
783#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000784 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
785 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000786 int count = fStencilFormats.count();
787 // we expect a really small number of possible formats so linear search
788 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000789 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000790 for (int i = 0; i < count; ++i) {
791 if (format.fInternalFormat ==
792 fStencilFormats[i].fInternalFormat) {
793 fStencilVerifiedColorConfigs[i].markVerified(config);
794 return;
795 }
796 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000797 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000798 "GrGLCaps doesn't know about.");
799}
800
801bool GrGLCaps::isColorConfigAndStencilFormatVerified(
802 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700803 const GrGLStencilAttachment::Format& format) const {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000804#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
805 return false;
806#endif
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000807 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000808 int count = fStencilFormats.count();
809 // we expect a really small number of possible formats so linear search
810 // should be OK
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000811 SkASSERT(count < 16);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000812 for (int i = 0; i < count; ++i) {
813 if (format.fInternalFormat ==
814 fStencilFormats[i].fInternalFormat) {
815 return fStencilVerifiedColorConfigs[i].isVerified(config);
816 }
817 }
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000818 SkFAIL("Why are we seeing a stencil format that "
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000819 "GLCaps doesn't know about.");
820 return false;
821}
822
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000823SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000824
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000825 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +0000826
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000827 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000828 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000829 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000830 i,
831 fStencilFormats[i].fStencilBits,
832 fStencilFormats[i].fTotalBits);
833 }
834
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000835 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000836 "None",
837 "ARB",
838 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000839 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000840 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +0000841 "IMG MS To Texture",
842 "EXT MS To Texture",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000843 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000844 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
845 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
846 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000847 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
848 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
849 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
850 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000851 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000852
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000853 static const char* kInvalidateFBTypeStr[] = {
854 "None",
855 "Discard",
856 "Invalidate",
857 };
858 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
859 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
860 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
861 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000862
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000863 static const char* kMapBufferTypeStr[] = {
864 "None",
865 "MapBuffer",
866 "MapBufferRange",
867 "Chromium",
868 };
869 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
870 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
871 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
872 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
873 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
874
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000875 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000876 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000877 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000878 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000879 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
880 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000881 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
882 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000883 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
884 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
885 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
886 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
887 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
888 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000889
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000890 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
891 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
892 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
893 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
894 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
895 r.appendf("Fragment coord conventions support: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000896 (fFragCoordsConventionSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000897 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
898 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +0000899 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000900 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -0700901 return r;
902}
903
904////////////////////////////////////////////////////////////////////////////////////////////
905
906GrGLSLCaps::GrGLSLCaps() {
907 this->reset();
908}
909
910
911void GrGLSLCaps::reset() {
912 INHERITED::reset();
913
914 fDropsTileOnZeroDivide = false;
915 fFBFetchSupport = false;
916 fFBFetchNeedsCustomOutput = false;
917 fFBFetchColorName = NULL;
918 fFBFetchExtensionString = NULL;
919}
920
921GrGLSLCaps::GrGLSLCaps(const GrGLSLCaps& caps) : GrShaderCaps() {
922 *this = caps;
923}
924
925GrGLSLCaps& GrGLSLCaps::operator= (const GrGLSLCaps& caps) {
926 INHERITED::operator=(caps);
927 fDropsTileOnZeroDivide = caps.fDropsTileOnZeroDivide;
928 fFBFetchSupport = caps.fFBFetchSupport;
929 fFBFetchNeedsCustomOutput = caps.fFBFetchNeedsCustomOutput;
930 fFBFetchColorName = caps.fFBFetchColorName;
931 fFBFetchExtensionString = caps.fFBFetchExtensionString;
932
933 return *this;
934}
935
936bool GrGLSLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
937 this->reset();
938 if (!ctxInfo.isInitialized()) {
939 return false;
940 }
941
942 GrGLStandard standard = ctxInfo.standard();
943 GrGLVersion version = ctxInfo.version();
944
945 /**************************************************************************
946 * Caps specific to GrGLSLCaps
947 **************************************************************************/
948
949 if (kGLES_GrGLStandard == standard) {
950 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
951 fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
952 fFBFetchSupport = true;
953 fFBFetchColorName = "gl_LastFragData[0]";
954 fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
955 }
956 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
957 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
958 fFBFetchNeedsCustomOutput = false;
959 fFBFetchSupport = true;
960 fFBFetchColorName = "gl_LastFragData[0]";
961 fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
962 }
963 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
964 // The arm extension also requires an additional flag which we will set onResetContext
965 fFBFetchNeedsCustomOutput = false;
966 fFBFetchSupport = true;
967 fFBFetchColorName = "gl_LastFragColorARM";
968 fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
969 }
970 }
971
972 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
973 fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
974
975 /**************************************************************************
976 * GrShaderCaps fields
977 **************************************************************************/
978
979 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
980
981 if (fPathRenderingSupport) {
982 if (kGL_GrGLStandard == standard) {
983 // We only support v1.3+ of GL_NV_path_rendering which allows us to
984 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
985 // additions are detected by checking the existence of the function.
986 fPathRenderingSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access") &&
987 ((ctxInfo.version() >= GR_GL_VER(4, 3) ||
988 ctxInfo.hasExtension("GL_ARB_program_interface_query")) &&
989 gli->fFunctions.fProgramPathFragmentInputGen);
990 }
991 else {
992 fPathRenderingSupport = ctxInfo.version() >= GR_GL_VER(3, 1);
993 }
994 }
995
996 // For now these two are equivalent but we could have dst read in shader via some other method
997 fDstReadInShaderSupport = fFBFetchSupport;
998
999 // Enable supported shader-related caps
1000 if (kGL_GrGLStandard == standard) {
1001 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3, 3) ||
1002 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
1003 fShaderDerivativeSupport = true;
1004 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
1005 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
1006 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
1007 }
1008 else {
1009 fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
1010 ctxInfo.hasExtension("GL_OES_standard_derivatives");
1011 }
1012
1013 this->initShaderPrecisionTable(ctxInfo, gli);
1014
1015 return true;
1016}
1017
1018SkString GrGLSLCaps::dump() const {
1019 SkString r = INHERITED::dump();
1020
1021 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"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001025 return r;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001026}
jvanverthe9c0fc62015-04-29 11:18:05 -07001027
1028static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1029 switch (p) {
1030 case kLow_GrSLPrecision:
1031 return GR_GL_LOW_FLOAT;
1032 case kMedium_GrSLPrecision:
1033 return GR_GL_MEDIUM_FLOAT;
1034 case kHigh_GrSLPrecision:
1035 return GR_GL_HIGH_FLOAT;
1036 }
1037 SkFAIL("Unknown precision.");
1038 return -1;
1039}
1040
1041static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1042 switch (type) {
1043 case kVertex_GrShaderType:
1044 return GR_GL_VERTEX_SHADER;
1045 case kGeometry_GrShaderType:
1046 return GR_GL_GEOMETRY_SHADER;
1047 case kFragment_GrShaderType:
1048 return GR_GL_FRAGMENT_SHADER;
1049 }
1050 SkFAIL("Unknown shader type.");
1051 return -1;
1052}
1053
1054void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1055 const GrGLInterface* intf) {
1056 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1057 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1058 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1059 if (kGeometry_GrShaderType != s) {
1060 GrShaderType shaderType = static_cast<GrShaderType>(s);
1061 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
1062 PrecisionInfo* first = NULL;
1063 fShaderPrecisionVaries = false;
1064 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1065 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1066 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1067 GrGLint range[2];
1068 GrGLint bits;
1069 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1070 if (bits) {
1071 fFloatPrecisions[s][p].fLogRangeLow = range[0];
1072 fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1073 fFloatPrecisions[s][p].fBits = bits;
1074 if (!first) {
1075 first = &fFloatPrecisions[s][p];
1076 }
1077 else if (!fShaderPrecisionVaries) {
1078 fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]);
1079 }
1080 }
1081 }
1082 }
1083 }
1084 }
1085 else {
1086 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
1087 fShaderPrecisionVaries = false;
1088 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1089 if (kGeometry_GrShaderType != s) {
1090 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1091 fFloatPrecisions[s][p].fLogRangeLow = 127;
1092 fFloatPrecisions[s][p].fLogRangeHigh = 127;
1093 fFloatPrecisions[s][p].fBits = 23;
1094 }
1095 }
1096 }
1097 }
1098 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1099 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1100 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1101 // are recommended against.
1102 if (fGeometryShaderSupport) {
1103 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1104 fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p];
1105 }
1106 }
1107}
1108
1109
1110
1111