blob: c568646db6b37e189ca25777b5ab015bdef4601e [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
egdanielb7e7d572015-11-04 04:23:53 -080011#include "GrContextOptions.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000012#include "GrGLContext.h"
jvanverthcba99b82015-06-24 06:59:57 -070013#include "glsl/GrGLSLCaps.h"
bsalomon@google.comc9668ec2012-04-11 18:16:41 +000014#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000015#include "SkTSort.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000016
bsalomon682c2692015-05-22 14:01:46 -070017GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
18 const GrGLContextInfo& ctxInfo,
19 const GrGLInterface* glInterface) : INHERITED(contextOptions) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000020 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000021 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000022 fInvalidateFBType = kNone_InvalidateFBType;
egdaniel4999df82016-01-07 17:06:04 -080023 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000024 fMapBufferType = kNone_MapBufferType;
jvanverthd7a2c1f2015-12-07 07:36:44 -080025 fTransferBufferType = kNone_TransferBufferType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000026 fMaxFragmentUniformVectors = 0;
bsalomon@google.com60da4172012-06-01 19:25:00 +000027 fMaxVertexAttributes = 0;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000028 fMaxFragmentTextureUnits = 0;
egdaniel4999df82016-01-07 17:06:04 -080029 fRGBA8RenderbufferSupport = false;
30 fBGRAIsInternalFormat = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031 fUnpackRowLengthSupport = false;
32 fUnpackFlipYSupport = false;
33 fPackRowLengthSupport = false;
34 fPackFlipYSupport = false;
35 fTextureUsageSupport = false;
36 fTexStorageSupport = false;
robertphillips@google.com443e5a52012-04-30 20:01:21 +000037 fTextureRedSupport = false;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +000038 fImagingSupport = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000039 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070040 fDirectStateAccessSupport = false;
41 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080042 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080043 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000044 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000045 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070046 fBindFragDataLocationSupport = false;
bsalomon7ea33f52015-11-22 14:51:00 -080047 fExternalTextureSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070048 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070049 fRGBA8888PixelsOpsAreSlow = false;
50 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070051
halcanary385fe4d2015-08-26 13:07:48 -070052 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070053
cdalton4cd67132015-06-10 19:23:46 -070054 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000055}
56
cdalton4cd67132015-06-10 19:23:46 -070057void GrGLCaps::init(const GrContextOptions& contextOptions,
58 const GrGLContextInfo& ctxInfo,
59 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000060 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000061 GrGLVersion version = ctxInfo.version();
62
bsalomon@google.combcce8922013-03-25 15:38:39 +000063 /**************************************************************************
64 * Caps specific to GrGLCaps
65 **************************************************************************/
66
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000067 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000068 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
69 &fMaxFragmentUniformVectors);
70 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000071 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000072 GrGLint max;
73 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
74 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000075 if (version >= GR_GL_VER(3, 2)) {
76 GrGLint profileMask;
77 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
78 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
79 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000080 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000081 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000082 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000083
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000084 if (kGL_GrGLStandard == standard) {
egdaniel4999df82016-01-07 17:06:04 -080085 fRGBA8RenderbufferSupport = true;
86 } else {
87 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
88 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
89 ctxInfo.hasExtension("GL_ARM_rgba8");
90 }
91
92 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000093 fUnpackRowLengthSupport = true;
94 fUnpackFlipYSupport = false;
95 fPackRowLengthSupport = true;
96 fPackFlipYSupport = false;
97 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +000098 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
99 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000100 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000101 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
102 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000103 fPackFlipYSupport =
104 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
105 }
106
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000107 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000108 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
109
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000110 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000111 // The EXT version can apply to either GL or GLES.
112 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
113 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
114 ctxInfo.hasExtension("GL_EXT_texture_storage");
115 } else {
116 // Qualcomm Adreno drivers appear to have issues with texture storage.
117 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
118 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
119 ctxInfo.hasExtension("GL_EXT_texture_storage");
120 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000121
cdaltonfd4167d2015-04-21 11:45:56 -0700122 if (kGL_GrGLStandard == standard) {
123 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
124 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
125 ctxInfo.hasExtension("GL_NV_texture_barrier");
126 } else {
127 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
128 }
129
hendrikwa0d5ad72014-12-02 07:30:30 -0800130 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
131 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700132 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800133 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000134 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
135 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800136 } else {
137 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
138 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000139 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000140 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000141 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000142 ctxInfo.hasExtension("GL_ARB_imaging");
143
egdaniel4999df82016-01-07 17:06:04 -0800144 // We only enable srgb support if both textures and FBOs support srgb.
145 bool srgbSupport = false;
146 if (kGL_GrGLStandard == standard) {
147 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
148 srgbSupport = true;
149 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
150 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
151 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
152 srgbSupport = true;
153 }
154 }
155 // All the above srgb extensions support toggling srgb writes
156 fSRGBWriteControl = srgbSupport;
157 } else {
158 // See https://bug.skia.org/4148 for PowerVR issue.
159 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
160 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
161 // ES through 3.1 requires EXT_srgb_write_control to support toggling
162 // sRGB writing for destinations.
163 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
164 }
165
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000166 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
167 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
168 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
169 // limit this decision to specific GPU families rather than basing it on the vendor alone.
170 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700171 (kARM_GrGLVendor == ctxInfo.vendor() ||
172 kImagination_GrGLVendor == ctxInfo.vendor() ||
173 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000174 fUseNonVBOVertexAndIndexDynamicData = true;
175 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000176
egdaniel9250d242015-05-18 13:04:26 -0700177 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
178 // Thus we are blacklisting this extension for now on Adreno4xx devices.
179 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
180 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
181 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
182 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000183 fDiscardRenderTargetSupport = true;
184 fInvalidateFBType = kInvalidate_InvalidateFBType;
185 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
186 fDiscardRenderTargetSupport = true;
187 fInvalidateFBType = kDiscard_InvalidateFBType;
188 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000189
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000190 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
191 fFullClearIsFree = true;
192 }
193
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000194 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000195 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800196 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
197 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000198 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000199 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
200 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000201 }
202
cdalton626e1ff2015-06-12 13:56:46 -0700203 if (kGL_GrGLStandard == standard) {
204 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
205 } else {
206 fDirectStateAccessSupport = false;
207 }
208
209 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
210 fDebugSupport = true;
211 } else {
212 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
213 }
214
jvanverth3f801cb2014-12-16 09:49:38 -0800215 if (kGL_GrGLStandard == standard) {
216 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
217 }
218 else {
219 fES2CompatibilitySupport = true;
220 }
221
cdalton0edea2c2015-05-21 08:27:44 -0700222 if (kGL_GrGLStandard == standard) {
223 fMultisampleDisableSupport = true;
224 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700225 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700226 }
227
kkinnunend94708e2015-07-30 22:47:04 -0700228 if (kGL_GrGLStandard == standard) {
229 if (version >= GR_GL_VER(3, 0)) {
230 fBindFragDataLocationSupport = true;
231 }
232 } else {
233 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
234 fBindFragDataLocationSupport = true;
235 }
joshualittc1f56b52015-06-22 12:31:31 -0700236 }
237
halcanary6950de62015-11-07 05:29:00 -0800238#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700239 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
kkinnunen177519e2015-10-28 06:18:35 -0700240#else
241 fBindUniformLocationSupport = false;
242#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700243
bsalomon7ea33f52015-11-22 14:51:00 -0800244 if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
245 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
246 fExternalTextureSupport = true;
247 } else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
248 ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
249 // At least one driver has been found that has this extension without the "GL_" prefix.
250 fExternalTextureSupport = true;
251 }
252 }
253
bsalomon88c7b982015-07-31 11:20:16 -0700254#ifdef SK_BUILD_FOR_WIN
255 // We're assuming that on Windows Chromium we're using ANGLE.
256 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
257 kChromium_GrGLDriver == ctxInfo.driver();
258 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
259 fRGBA8888PixelsOpsAreSlow = isANGLE;
260 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
261 // check DX11 ANGLE.
262 fPartialFBOReadIsSlow = isANGLE;
263#endif
264
cdalton4cd67132015-06-10 19:23:46 -0700265 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700266 * GrShaderCaps fields
267 **************************************************************************/
268
egdaniel0a482332015-10-26 08:59:10 -0700269 // This must be called after fCoreProfile is set on the GrGLCaps
270 this->initGLSL(ctxInfo);
271 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
272
egdaniel05ded892015-10-26 07:38:05 -0700273 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
274
275 // For now these two are equivalent but we could have dst read in shader via some other method.
276 // Before setting this, initGLSL() must have been called.
277 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
278
279 // Enable supported shader-related caps
280 if (kGL_GrGLStandard == standard) {
281 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
282 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
283 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
284 glslCaps->fShaderDerivativeSupport = true;
285 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
286 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
287 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
288 }
289 else {
290 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
291
292 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
293 ctxInfo.hasExtension("GL_OES_standard_derivatives");
294 }
295
egdaniel05ded892015-10-26 07:38:05 -0700296 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700297 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000298 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700299
cdalton63f6c1f2015-11-06 07:09:43 -0800300 // We need dual source blending and the ability to disable multisample in order to support mixed
301 // samples in every corner case.
302 if (fMultisampleDisableSupport && glslCaps->dualSourceBlendingSupport()) {
kkinnunenea409432015-12-10 01:21:59 -0800303 fMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
304 ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
cdalton63f6c1f2015-11-06 07:09:43 -0800305 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
306 if (fMixedSamplesSupport && kNVIDIA_GrGLDriver == ctxInfo.driver()) {
307 fDiscardRenderTargetSupport = false;
308 fInvalidateFBType = kNone_InvalidateFBType;
309 }
310 }
311
312 // fPathRenderingSupport and fMixedSamplesSupport must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700313 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700314 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700315 this->initStencilFormats(ctxInfo);
316
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000317 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000318 // we could also look for GL_ATI_separate_stencil extension or
319 // GL_EXT_stencil_two_side but they use different function signatures
320 // than GL2.0+ (and than each other).
321 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
322 // supported on GL 1.4 and higher or by extension
323 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
324 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
325 } else {
326 // ES 2 has two sided stencil and stencil wrap
327 fTwoSidedStencilSupport = true;
328 fStencilWrapOpsSupport = true;
329 }
330
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000331 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000332 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
333 // extension includes glMapBuffer.
334 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
335 fMapBufferFlags |= kSubset_MapFlag;
336 fMapBufferType = kMapBufferRange_MapBufferType;
337 } else {
338 fMapBufferType = kMapBuffer_MapBufferType;
339 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000340 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000341 // Unextended GLES2 doesn't have any buffer mapping.
342 fMapBufferFlags = kNone_MapBufferType;
343 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
344 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
345 fMapBufferType = kChromium_MapBufferType;
346 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
347 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
348 fMapBufferType = kMapBufferRange_MapBufferType;
349 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
350 fMapBufferFlags = kCanMap_MapFlag;
351 fMapBufferType = kMapBuffer_MapBufferType;
352 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000353 }
354
jvanverthd7a2c1f2015-12-07 07:36:44 -0800355 if (kGL_GrGLStandard == standard) {
356 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object")) {
357 fTransferBufferType = kPBO_TransferBufferType;
358 }
359 } else {
360 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pixel_buffer_object")) {
361 fTransferBufferType = kPBO_TransferBufferType;
362 } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
363 fTransferBufferType = kChromium_TransferBufferType;
364 }
365 }
366
joshualitte5b74c62015-06-01 14:17:47 -0700367 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
368 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
369 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700370 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
371 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
372 // a small subset.
373#if 0
cdalton1acea862015-06-02 13:05:52 -0700374 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700375#else
376 fGeometryBufferMapThreshold = SK_MaxS32;
377#endif
joshualitte5b74c62015-06-01 14:17:47 -0700378 }
379
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000380 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000381 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
382 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
383 fNPOTTextureTileSupport = true;
384 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000385 } else {
386 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000387 // ES3 has no limitations.
388 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
389 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000390 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
391 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
392 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
393 // to alllow arbitrary wrap modes, however.
394 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000395 }
396
bsalomone72bd022015-10-26 07:33:03 -0700397 // Using MIPs on this GPU seems to be a source of trouble.
398 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
399 fMipMapSupport = false;
400 }
401
bsalomon@google.combcce8922013-03-25 15:38:39 +0000402 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
403 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
404 // Our render targets are always created with textures as the color
405 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000406 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000407
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000408 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
409
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000410 // Disable scratch texture reuse on Mali and Adreno devices
411 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
412 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000413
robertphillips1b8e1b52015-06-24 06:54:10 -0700414#if 0
415 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
416 kQualcomm_GrGLVendor != ctxInfo.vendor();
417#endif
418
egdaniel05ded892015-10-26 07:38:05 -0700419 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000420 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000421 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
422 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
423 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
424 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000425
bsalomon63b21962014-11-05 07:05:34 -0800426 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800427 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800428 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800429 fUseDrawInsteadOfClear = true;
430 }
431
joshualitt83bc2292015-06-18 14:18:02 -0700432 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
433 fUseDrawInsteadOfPartialRenderTargetWrite = true;
434 }
435
robertphillips63926682015-08-20 09:39:02 -0700436#ifdef SK_BUILD_FOR_WIN
437 // On ANGLE deferring flushes can lead to GPU starvation
438 fPreferVRAMUseOverFlushes = !isANGLE;
439#endif
440
bsalomon7dea7b72015-08-19 08:26:51 -0700441 if (kChromium_GrGLDriver == ctxInfo.driver()) {
442 fMustClearUploadedBufferData = true;
443 }
444
bsalomond08ea5f2015-02-20 06:58:13 -0800445 if (kGL_GrGLStandard == standard) {
446 // ARB allows mixed size FBO attachments, EXT does not.
447 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
448 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
449 fOversizedStencilSupport = true;
450 } else {
451 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
452 }
453 } else {
454 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
455 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
456 }
457
joshualitt58001552015-06-26 12:46:36 -0700458 if (kGL_GrGLStandard == standard) {
459 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
460 // instanced arrays, but we could make this more granular if we wanted
461 fSupportsInstancedDraws =
462 version >= GR_GL_VER(3, 2) ||
463 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
464 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
465 } else {
466 fSupportsInstancedDraws =
467 version >= GR_GL_VER(3, 0) ||
468 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
469 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
470 }
471
egdaniel4999df82016-01-07 17:06:04 -0800472 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
473 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700474 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
egdanielb7e7d572015-11-04 04:23:53 -0800475 // Requires fTexutreSwizzleSupport and fTextureRedSupport to be set before this point.
476 this->initConfigSwizzleTable(ctxInfo, glslCaps);
egdaniel4999df82016-01-07 17:06:04 -0800477 // Requires various members are already correctly initialized (e.g. fTextureRedSupport).
478 this->initConfigTable(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700479
480 this->applyOptionsOverrides(contextOptions);
481 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000482}
483
egdaniel472d44e2015-10-22 08:20:00 -0700484const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
485 bool isCoreProfile) {
486 switch (generation) {
487 case k110_GrGLSLGeneration:
488 if (kGLES_GrGLStandard == standard) {
489 // ES2s shader language is based on version 1.20 but is version
490 // 1.00 of the ES language.
491 return "#version 100\n";
492 } else {
493 SkASSERT(kGL_GrGLStandard == standard);
494 return "#version 110\n";
495 }
496 case k130_GrGLSLGeneration:
497 SkASSERT(kGL_GrGLStandard == standard);
498 return "#version 130\n";
499 case k140_GrGLSLGeneration:
500 SkASSERT(kGL_GrGLStandard == standard);
501 return "#version 140\n";
502 case k150_GrGLSLGeneration:
503 SkASSERT(kGL_GrGLStandard == standard);
504 if (isCoreProfile) {
505 return "#version 150\n";
506 } else {
507 return "#version 150 compatibility\n";
508 }
509 case k330_GrGLSLGeneration:
510 if (kGLES_GrGLStandard == standard) {
511 return "#version 300 es\n";
512 } else {
513 SkASSERT(kGL_GrGLStandard == standard);
514 if (isCoreProfile) {
515 return "#version 330\n";
516 } else {
517 return "#version 330 compatibility\n";
518 }
519 }
520 case k310es_GrGLSLGeneration:
521 SkASSERT(kGLES_GrGLStandard == standard);
522 return "#version 310 es\n";
523 }
524 return "<no version>";
525}
526
egdaniel05ded892015-10-26 07:38:05 -0700527void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700528 GrGLStandard standard = ctxInfo.standard();
529 GrGLVersion version = ctxInfo.version();
530
531 /**************************************************************************
532 * Caps specific to GrGLSLCaps
533 **************************************************************************/
534
535 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
536 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
537
538 if (kGLES_GrGLStandard == standard) {
539 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
540 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
541 glslCaps->fFBFetchSupport = true;
542 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
543 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
544 }
545 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
546 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
547 glslCaps->fFBFetchNeedsCustomOutput = false;
548 glslCaps->fFBFetchSupport = true;
549 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
550 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
551 }
552 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
553 // The arm extension also requires an additional flag which we will set onResetContext
554 glslCaps->fFBFetchNeedsCustomOutput = false;
555 glslCaps->fFBFetchSupport = true;
556 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
557 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
558 }
559 glslCaps->fUsesPrecisionModifiers = true;
560 }
561
562 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
563
564 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
565 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
566
567 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
568 // function that may require a gradient calculation inside a conditional block may return
569 // undefined results". This appears to be an issue with the 'any' call since even the simple
570 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
571 // from our GrTextureDomain processor.
572 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
573
egdaniel472d44e2015-10-22 08:20:00 -0700574 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
575 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800576
577 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
578 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
579 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800580
581 // Frag Coords Convention support is not part of ES
582 // Known issue on at least some Intel platforms:
583 // http://code.google.com/p/skia/issues/detail?id=946
584 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
585 kGLES_GrGLStandard != standard &&
586 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
587 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
588 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
589 }
590
591 if (kGLES_GrGLStandard == standard) {
592 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
593 }
594
bsalomon7ea33f52015-11-22 14:51:00 -0800595 if (fExternalTextureSupport) {
596 if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
597 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
598 } else {
599 glslCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
600 }
601 }
602
egdaniel8dcdedc2015-11-11 06:27:20 -0800603 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
604 // the abs first in a separate expression.
605 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
606 glslCaps->fCanUseMinAndAbsTogether = false;
607 }
608
bsalomon7ea33f52015-11-22 14:51:00 -0800609 // On Intel GPU there is an issue where it reads the second argument to atan "- %s.x" as an int
egdaniel8dcdedc2015-11-11 06:27:20 -0800610 // thus must us -1.0 * %s.x to work correctly
611 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
612 glslCaps->fMustForceNegatedAtanParamToFloat = true;
613 }
egdaniel472d44e2015-10-22 08:20:00 -0700614}
615
kkinnunencfe62e32015-07-01 02:58:50 -0700616bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700617 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
618
619 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700620 return false;
621 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700622
kkinnunencfe62e32015-07-01 02:58:50 -0700623 if (kGL_GrGLStandard == ctxInfo.standard()) {
624 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
625 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
626 return false;
627 }
628 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700629 if (!hasChromiumPathRendering &&
630 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700631 return false;
632 }
633 }
634 // We only support v1.3+ of GL_NV_path_rendering which allows us to
635 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
636 // additions are detected by checking the existence of the function.
637 // We also use *Then* functions that not all drivers might have. Check
638 // them for consistency.
halcanary96fcdcc2015-08-27 07:41:13 -0700639 if (nullptr == gli->fFunctions.fStencilThenCoverFillPath ||
640 nullptr == gli->fFunctions.fStencilThenCoverStrokePath ||
641 nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
642 nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
643 nullptr == gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700644 return false;
645 }
646 return true;
647}
egdaniel4999df82016-01-07 17:06:04 -0800648
649void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
650 // OpenGL < 3.0
651 // no support for render targets unless the GL_ARB_framebuffer_object
652 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
653 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
654 // probably don't get R8 in this case.
655
656 // OpenGL 3.0
657 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
658 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
659
660 // >= OpenGL 3.1
661 // base color renderable: RED, RG, RGB, and RGBA
662 // sized derivatives: R8, RGBA4, RGBA8
663 // if the GL_ARB_compatibility extension is supported then we get back
664 // support for GL_ALPHA and ALPHA8
665
666 // GL_EXT_bgra adds BGRA render targets to any version
667
668 // ES 2.0
669 // color renderable: RGBA4, RGB5_A1, RGB565
670 // GL_EXT_texture_rg adds support for R8 as a color render target
671 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
672 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
673
674 // ES 3.0
675 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
676 // below already account for this).
677
678 GrGLStandard standard = ctxInfo.standard();
679
680 enum {
681 kNo_MSAA = 0,
682 kYes_MSAA = 1,
683 };
684
685 if (kGL_GrGLStandard == standard) {
686 // Post 3.0 we will get R8
687 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
688 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
689 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
690 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
691 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
692 }
693 } else {
694 // On ES we can only hope for R8
695 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
696 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
697 }
698
699 if (kGL_GrGLStandard != standard) {
700 // only available in ES
701 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
702 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
703 }
704
705 // we no longer support 444 as a render target
706 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
707 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
708
709 if (this->fRGBA8RenderbufferSupport) {
710 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
711 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
712 }
713
714 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
715 // On iOS, BGRA is not supported as a renderable target on ES 3.0+
716 if (!ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888") ||
717 ctxInfo.version() < GR_GL_VER(3,0)) {
718 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
719 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
720 // configs that are color-renderable and can be passed to
721 // glRenderBufferStorageMultisample. Chromium may have an extension to allow BGRA
722 // renderbuffers to work on desktop platforms.
723 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
724 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
725 } else {
726 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
727 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
728 }
729 }
730 }
731
732 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
733 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
734 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
735 }
736
737 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
738 if (kGL_GrGLStandard == standard) {
739 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
740 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
741 } else {
742 // for now we only enable this on desktop, because on ES we'd have to solve many
743 // precision issues and no clients actually want this yet
744 /*
745 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
746 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
747 } else {
748 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
749 }
750 // for now we don't support floating point MSAA on ES
751 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
752 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
753 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
754 }
755 }
756
757 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
758 if (kGL_GrGLStandard == standard) {
759 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
760 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
761 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
762 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
763 // for now we don't support floating point MSAA on ES
764 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
765 } else {
766 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
767 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
768 } else {
769 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
770 }
771 // for now we don't support floating point MSAA on ES
772 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
773 }
774 }
775
776 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
777 if (kGL_GrGLStandard == standard) {
778 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
779 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
780 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
781 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
782 // for now we don't support floating point MSAA on ES
783 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
784 } else {
785 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
786 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
787 } else {
788 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
789 }
790 // for now we don't support floating point MSAA on ES
791 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
792 }
793 }
794
795 // If we don't support MSAA then undo any places above where we set a config as renderable with
796 // msaa.
797 if (kNone_MSFBOType == fMSFBOType) {
798 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
799 fConfigRenderSupport[i][kYes_MSAA] = false;
800 }
801 }
802}
803
804void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
805 bool srgbSupport) {
806 GrGLStandard standard = ctxInfo.standard();
807 GrGLVersion version = ctxInfo.version();
808
809 // Base texture support
810 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
811 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
812 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
813 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
814
815 // Disable this for now, while we investigate https://bug.skia.org/4333
816 if (false) {
817 // Check for 8-bit palette..
818 GrGLint numFormats;
819 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
820 if (numFormats) {
821 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
822 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
823 for (int i = 0; i < numFormats; ++i) {
824 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
825 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
826 break;
827 }
828 }
829 }
830 }
831
832 // Check for BGRA
833 if (kGL_GrGLStandard == standard) {
834 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
835 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
836 } else {
837 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
838 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
839 if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_texture_storage")) {
840 fBGRAIsInternalFormat = true;
841 }
842 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
843 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
844 fBGRAIsInternalFormat = true;
845 }
846 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
847 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
848 }
849
850 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
851
852 // Compressed texture support
853
854 // glCompressedTexImage2D is available on all OpenGL ES devices...
855 // however, it is only available on standard OpenGL after version 1.3
856 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
857
858 fCompressedTexSubImageSupport =
859 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
860
861 // Check for ETC1
862 bool hasETC1 = false;
863
864 // First check version for support
865 if (kGL_GrGLStandard == standard) {
866 hasETC1 = hasCompressTex2D &&
867 (version >= GR_GL_VER(4, 3) ||
868 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
869 } else {
870 hasETC1 = hasCompressTex2D &&
871 (version >= GR_GL_VER(3, 0) ||
872 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
873 // ETC2 is a superset of ETC1, so we can just check for that, too.
874 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
875 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
876 }
877 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
878
879 // Check for LATC under its various forms
880 LATCAlias alias = kLATC_LATCAlias;
881 bool hasLATC = hasCompressTex2D &&
882 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
883 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
884
885 // Check for RGTC
886 if (!hasLATC) {
887 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
888 if (kGL_GrGLStandard == standard) {
889 hasLATC = version >= GR_GL_VER(3, 0);
890 }
891
892 if (!hasLATC) {
893 hasLATC =
894 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
895 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
896 }
897
898 if (hasLATC) {
899 alias = kRGTC_LATCAlias;
900 }
901 }
902
903 // Check for 3DC
904 if (!hasLATC) {
905 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
906 if (hasLATC) {
907 alias = k3DC_LATCAlias;
908 }
909 }
910
911 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
912 fLATCAlias = alias;
913
914 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
915 // cards default to decompressing the textures in the driver, and is
916 // generally slower.
917 if (kGL_GrGLStandard != standard) {
918 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
919 }
920
921 // Check for ASTC
922 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
923 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
924 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
925 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
926
927 // Check for floating point texture support
928 // NOTE: We disallow floating point textures on ES devices if linear
929 // filtering modes are not supported. This is for simplicity, but a more
930 // granular approach is possible. Coincidentally, floating point textures became part of
931 // the standard in ES3.1 / OGL 3.1, hence the shorthand
932 bool hasFPTextures = version >= GR_GL_VER(3, 1);
933 if (!hasFPTextures) {
934 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
935 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
936 ctxInfo.hasExtension("GL_OES_texture_float"));
937 }
938 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
939
940 // Check for fp16 texture support
941 // NOTE: We disallow floating point textures on ES devices if linear
942 // filtering modes are not supported. This is for simplicity, but a more
943 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
944 // the standard in ES3.1 / OGL 3.1, hence the shorthand
945 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
946 if (!hasHalfFPTextures) {
947 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
948 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
949 ctxInfo.hasExtension("GL_OES_texture_half_float"));
950 }
951 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
952 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
953}
954
piotaixre4b23142014-10-02 10:57:53 -0700955bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
bsalomon7928ef62016-01-05 10:26:39 -0800956 GrPixelConfig readConfig,
957 GrPixelConfig currFBOConfig) const {
958 SkASSERT(this->isConfigRenderable(currFBOConfig, false));
959
960 if (kGL_GrGLStandard == intf->fStandard) {
961 // All of our renderable configs can be converted to each other by glReadPixels in OpenGL.
962 return true;
piotaixre4b23142014-10-02 10:57:53 -0700963 }
bsalomon7928ef62016-01-05 10:26:39 -0800964 // See Section 16.1.2 in the ES 3.2 specification.
965
966 GrGLenum readFormat = fConfigTable[readConfig].fFormats.fExternalFormat;
967 GrGLenum readType = fConfigTable[readConfig].fFormats.fExternalType;
968
969 if (kNormalizedFixedPoint_FormatType == fConfigTable[currFBOConfig].fFormatType) {
970 if (GR_GL_RGBA == readFormat && GR_GL_UNSIGNED_BYTE == readType) {
971 return true;
972 }
973 } else {
974 SkASSERT(kFloat_FormatType == fConfigTable[currFBOConfig].fFormatType);
975 if (GR_GL_RGBA == readFormat && GR_GL_FLOAT == readType) {
976 return true;
977 }
978 }
979
980 if (0 == fConfigTable[currFBOConfig].fSecondReadPixelsFormat.fFormat) {
981 ReadPixelsFormat* rpFormat =
982 const_cast<ReadPixelsFormat*>(&fConfigTable[currFBOConfig].fSecondReadPixelsFormat);
983 GrGLint format = 0, type = 0;
984 GR_GL_GetIntegerv(intf, GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &format);
985 GR_GL_GetIntegerv(intf, GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &type);
986 rpFormat->fFormat = format;
987 rpFormat->fType = type;
988 }
989
990 return fConfigTable[currFBOConfig].fSecondReadPixelsFormat.fFormat == readFormat &&
991 fConfigTable[currFBOConfig].fSecondReadPixelsFormat.fType == readType;
piotaixre4b23142014-10-02 10:57:53 -0700992}
993
robertphillips@google.com6177e692013-02-28 20:16:25 +0000994void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000995
996 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000997 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000998 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
999 // ES3 driver bugs on at least one device with a tiled GPU (N10).
1000 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
1001 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
1002 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
1003 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
cdalton63f6c1f2015-11-06 07:09:43 -08001004 } else if (fMixedSamplesSupport && fShaderCaps->pathRenderingSupport()) {
vbuzinovdded6962015-06-12 08:59:45 -07001005 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +00001006 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001007 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
1008 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
1009 // chrome's extension is equivalent to the EXT msaa
1010 // and fbo_blit extensions.
1011 fMSFBOType = kDesktop_EXT_MSFBOType;
1012 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
1013 fMSFBOType = kES_Apple_MSFBOType;
1014 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001015 } else {
cdalton63f6c1f2015-11-06 07:09:43 -08001016 if (fMixedSamplesSupport && fShaderCaps->pathRenderingSupport()) {
vbuzinovdded6962015-06-12 08:59:45 -07001017 fMSFBOType = kMixedSamples_MSFBOType;
1018 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001019 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001020 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001021 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1022 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001023 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001024 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001025 }
1026}
1027
cdalton1dd05422015-06-12 09:01:18 -07001028void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
1029 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
1030
1031 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
1032 // for now until its own blacklists can be updated.
1033 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
1034 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -07001035 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -07001036 return;
1037 }
1038
1039 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1040 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1041 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1042 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
1043 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1044 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1045 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1046 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
1047 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
1048 return;
1049 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1050 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1051 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1052 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
1053 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1054 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1055 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1056 // slow on a particular platform.
1057 } else {
1058 return; // No advanced blend support.
1059 }
1060
1061 SkASSERT(this->advancedBlendEquationSupport());
1062
1063 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
1064 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
1065 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
1066 (1 << kColorBurn_GrBlendEquation);
1067 }
joel.liang9764c402015-07-09 19:46:18 -07001068 if (kARM_GrGLVendor == ctxInfo.vendor()) {
1069 // Blacklist color-burn on ARM until the fix is released.
1070 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
1071 }
cdalton1dd05422015-06-12 09:01:18 -07001072}
1073
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001074namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001075const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001076}
1077
1078void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
1079
1080 // Build up list of legal stencil formats (though perhaps not supported on
1081 // the particular gpu/driver) from most preferred to least.
1082
1083 // these consts are in order of most preferred to least preferred
1084 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1085
1086 static const StencilFormat
1087 // internal Format stencil bits total bits packed?
1088 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1089 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1090 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1091 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001092 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001093 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1094
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001095 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001096 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001097 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001098 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1099 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1100
1101 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1102 // require FBO support we can expect these are legal formats and don't
1103 // check. These also all support the unsized GL_STENCIL_INDEX.
1104 fStencilFormats.push_back() = gS8;
1105 fStencilFormats.push_back() = gS16;
1106 if (supportsPackedDS) {
1107 fStencilFormats.push_back() = gD24S8;
1108 }
1109 fStencilFormats.push_back() = gS4;
1110 if (supportsPackedDS) {
1111 fStencilFormats.push_back() = gDS;
1112 }
1113 } else {
1114 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1115 // for other formats.
1116 // ES doesn't support using the unsized format.
1117
1118 fStencilFormats.push_back() = gS8;
1119 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001120 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1121 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001122 fStencilFormats.push_back() = gD24S8;
1123 }
1124 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1125 fStencilFormats.push_back() = gS4;
1126 }
1127 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001128}
1129
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001130SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001131
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001132 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001133
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001134 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001135 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001136 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001137 i,
1138 fStencilFormats[i].fStencilBits,
1139 fStencilFormats[i].fTotalBits);
1140 }
1141
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001142 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001143 "None",
1144 "ARB",
1145 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001146 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001147 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001148 "IMG MS To Texture",
1149 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001150 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001151 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001152 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1153 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1154 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001155 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1156 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1157 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1158 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001159 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001160 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001161
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001162 static const char* kInvalidateFBTypeStr[] = {
1163 "None",
1164 "Discard",
1165 "Invalidate",
1166 };
1167 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1168 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1169 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1170 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001171
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001172 static const char* kMapBufferTypeStr[] = {
1173 "None",
1174 "MapBuffer",
1175 "MapBufferRange",
1176 "Chromium",
1177 };
1178 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1179 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1180 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1181 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1182 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1183
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001184 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001185 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001186 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001187 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001188 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1189 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001190 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
egdaniel4999df82016-01-07 17:06:04 -08001191 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
1192 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001193 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1194 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1195 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1196 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001197
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001198 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1199 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1200 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1201 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001202 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001203 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1204 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001205 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001206 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001207 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001208 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001209 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1210 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001211 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001212 return r;
1213}
1214
jvanverthe9c0fc62015-04-29 11:18:05 -07001215static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1216 switch (p) {
1217 case kLow_GrSLPrecision:
1218 return GR_GL_LOW_FLOAT;
1219 case kMedium_GrSLPrecision:
1220 return GR_GL_MEDIUM_FLOAT;
1221 case kHigh_GrSLPrecision:
1222 return GR_GL_HIGH_FLOAT;
1223 }
1224 SkFAIL("Unknown precision.");
1225 return -1;
1226}
1227
1228static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1229 switch (type) {
1230 case kVertex_GrShaderType:
1231 return GR_GL_VERTEX_SHADER;
1232 case kGeometry_GrShaderType:
1233 return GR_GL_GEOMETRY_SHADER;
1234 case kFragment_GrShaderType:
1235 return GR_GL_FRAGMENT_SHADER;
1236 }
1237 SkFAIL("Unknown shader type.");
1238 return -1;
1239}
1240
jvanverthcba99b82015-06-24 06:59:57 -07001241void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1242 const GrGLInterface* intf,
1243 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001244 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1245 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1246 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1247 if (kGeometry_GrShaderType != s) {
1248 GrShaderType shaderType = static_cast<GrShaderType>(s);
1249 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001250 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001251 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001252 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1253 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1254 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1255 GrGLint range[2];
1256 GrGLint bits;
1257 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1258 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001259 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1260 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1261 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001262 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001263 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001264 }
jvanverthcba99b82015-06-24 06:59:57 -07001265 else if (!glslCaps->fShaderPrecisionVaries) {
1266 glslCaps->fShaderPrecisionVaries =
1267 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001268 }
1269 }
1270 }
1271 }
1272 }
1273 }
1274 else {
1275 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001276 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001277 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1278 if (kGeometry_GrShaderType != s) {
1279 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001280 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1281 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1282 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001283 }
1284 }
1285 }
1286 }
1287 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1288 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1289 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1290 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001291 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001292 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001293 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1294 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001295 }
1296 }
1297}
1298
egdanielb7e7d572015-11-04 04:23:53 -08001299void GrGLCaps::initConfigSwizzleTable(const GrGLContextInfo& ctxInfo, GrGLSLCaps* glslCaps) {
1300 GrGLStandard standard = ctxInfo.standard();
1301 GrGLVersion version = ctxInfo.version();
jvanverthe9c0fc62015-04-29 11:18:05 -07001302
egdanielb7e7d572015-11-04 04:23:53 -08001303 glslCaps->fMustSwizzleInShader = true;
1304 if (kGL_GrGLStandard == standard) {
1305 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
1306 glslCaps->fMustSwizzleInShader = false;
1307 }
1308 } else {
1309 if (version >= GR_GL_VER(3,0)) {
1310 glslCaps->fMustSwizzleInShader = false;
1311 }
1312 }
1313
1314 glslCaps->fConfigSwizzle[kUnknown_GrPixelConfig] = nullptr;
1315 if (fTextureRedSupport) {
1316 glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "rrrr";
1317 glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "rrrr";
1318 } else {
1319 glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "aaaa";
1320 glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "aaaa";
1321 }
1322 glslCaps->fConfigSwizzle[kIndex_8_GrPixelConfig] = "rgba";
1323 glslCaps->fConfigSwizzle[kRGB_565_GrPixelConfig] = "rgba";
1324 glslCaps->fConfigSwizzle[kRGBA_4444_GrPixelConfig] = "rgba";
1325 glslCaps->fConfigSwizzle[kRGBA_8888_GrPixelConfig] = "rgba";
1326 glslCaps->fConfigSwizzle[kBGRA_8888_GrPixelConfig] = "rgba";
1327 glslCaps->fConfigSwizzle[kSRGBA_8888_GrPixelConfig] = "rgba";
1328 glslCaps->fConfigSwizzle[kETC1_GrPixelConfig] = "rgba";
1329 glslCaps->fConfigSwizzle[kLATC_GrPixelConfig] = "rrrr";
1330 glslCaps->fConfigSwizzle[kR11_EAC_GrPixelConfig] = "rrrr";
1331 glslCaps->fConfigSwizzle[kASTC_12x12_GrPixelConfig] = "rgba";
1332 glslCaps->fConfigSwizzle[kRGBA_float_GrPixelConfig] = "rgba";
1333 glslCaps->fConfigSwizzle[kRGBA_half_GrPixelConfig] = "rgba";
1334
1335}
1336
egdaniel4999df82016-01-07 17:06:04 -08001337void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo) {
bsalomon30447372015-12-21 09:03:05 -08001338 fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
1339 fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
1340 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat = 0;
1341 fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001342 fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001343
1344 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1345 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1346 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGBA;
1347 fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001348 fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon32a3cd22016-01-07 13:00:11 -08001349
egdaniel4999df82016-01-07 17:06:04 -08001350 if (this->bgraIsInternalFormat()) {
1351 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
1352 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
1353 } else {
1354 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1355 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
1356 }
bsalomon30447372015-12-21 09:03:05 -08001357 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat= GR_GL_BGRA;
1358 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001359 fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001360
egdaniel4999df82016-01-07 17:06:04 -08001361
bsalomon30447372015-12-21 09:03:05 -08001362 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
1363 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
1364 // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the
1365 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image.
1366 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGBA;
1367 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001368 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001369
1370 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
1371 if (this->ES2CompatibilitySupport()) {
1372 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
1373 } else {
1374 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
1375 }
1376 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGB;
1377 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
bsalomon7928ef62016-01-05 10:26:39 -08001378 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001379
1380 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1381 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
1382 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGBA;
1383 fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
bsalomon7928ef62016-01-05 10:26:39 -08001384 fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
egdaniel4999df82016-01-07 17:06:04 -08001385
bsalomon30447372015-12-21 09:03:05 -08001386
1387 if (this->textureRedSupport()) {
1388 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1389 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8;
1390 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RED;
1391 } else {
1392 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1393 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
1394 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat = GR_GL_ALPHA;
1395 }
1396 fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
bsalomon7928ef62016-01-05 10:26:39 -08001397 fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001398
1399 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1400 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F;
1401 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGBA;
1402 fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT;
bsalomon7928ef62016-01-05 10:26:39 -08001403 fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001404
1405 if (this->textureRedSupport()) {
1406 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED;
1407 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F;
1408 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RED;
1409 } else {
1410 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA;
1411 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F;
1412 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat = GR_GL_ALPHA;
1413 }
1414 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1415 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1416 } else {
1417 fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1418 }
bsalomon7928ef62016-01-05 10:26:39 -08001419 fConfigTable[kAlpha_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001420
1421 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
1422 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
1423 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RGBA;
1424 if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) {
1425 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT;
1426 } else {
1427 fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
1428 }
bsalomon7928ef62016-01-05 10:26:39 -08001429 fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001430
1431 // No sized/unsized internal format distinction for compressed formats, no external format.
1432
1433 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_PALETTE8_RGBA8;
1434 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_PALETTE8_RGBA8;
1435 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalFormat = 0;
1436 fConfigTable[kIndex_8_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001437 fConfigTable[kIndex_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001438
egdaniel4999df82016-01-07 17:06:04 -08001439 switch(this->latcAlias()) {
1440 case GrGLCaps::kLATC_LATCAlias:
1441 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1442 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1443 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1444 GR_GL_COMPRESSED_LUMINANCE_LATC1;
1445 break;
1446 case GrGLCaps::kRGTC_LATCAlias:
1447 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat =
1448 GR_GL_COMPRESSED_RED_RGTC1;
1449 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1450 GR_GL_COMPRESSED_RED_RGTC1;
1451 break;
1452 case GrGLCaps::k3DC_LATCAlias:
1453 fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_3DC_X;
1454 fConfigTable[kLATC_GrPixelConfig].fFormats.fSizedInternalFormat =
1455 GR_GL_COMPRESSED_3DC_X;
1456 break;
bsalomon30447372015-12-21 09:03:05 -08001457 }
1458 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat = 0;
1459 fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001460 fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001461
1462 fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1463 fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
1464 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalFormat = 0;
1465 fConfigTable[kETC1_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001466 fConfigTable[kETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001467
1468 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1469 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC;
1470 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalFormat = 0;
1471 fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001472 fConfigTable[kR11_EAC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001473
1474 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat =
1475 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1476 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fSizedInternalFormat =
1477 GR_GL_COMPRESSED_RGBA_ASTC_12x12;
1478 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalFormat = 0;
1479 fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fExternalType = 0;
bsalomon7928ef62016-01-05 10:26:39 -08001480 fConfigTable[kASTC_12x12_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
bsalomon30447372015-12-21 09:03:05 -08001481
1482 // Bulk populate the texture internal/external formats here and then deal with exceptions below.
1483
1484 // ES 2.0 requires that the internal/external formats match.
1485 bool useSizedFormats = (kGL_GrGLStandard == ctxInfo.standard() ||
1486 ctxInfo.version() >= GR_GL_VER(3,0));
1487 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1488 // Almost always we want to pass fExternalFormat as the <format> param to glTex[Sub]Image.
1489 fConfigTable[i].fFormats.fExternalFormatForTexImage =
1490 fConfigTable[i].fFormats.fExternalFormat;
1491 fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedFormats ?
1492 fConfigTable[i].fFormats.fSizedInternalFormat :
1493 fConfigTable[i].fFormats.fBaseInternalFormat;
1494 }
1495 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
1496 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1497 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1498 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1499 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
1500 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormatForTexImage =
1501 GR_GL_SRGB_ALPHA;
1502 }
1503
1504 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1505 // as a base format.
1506 // GL_EXT_texture_format_BGRA8888:
1507 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1508 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1509 // formats.
1510 // GL_APPLE_texture_format_BGRA8888:
1511 // ES 2.0: the extension makes BGRA an external format but not an internal format.
1512 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
1513 // glTexImage (just for glTexStorage).
1514 if (useSizedFormats && this->bgraIsInternalFormat()) {
1515 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1516 }
1517
1518#ifdef SK_DEBUG
1519 // Make sure we initialized everything.
1520 ConfigFormats defaultEntry;
1521 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1522 SkASSERT(defaultEntry.fBaseInternalFormat != fConfigTable[i].fFormats.fBaseInternalFormat);
1523 SkASSERT(defaultEntry.fSizedInternalFormat !=
1524 fConfigTable[i].fFormats.fSizedInternalFormat);
1525 SkASSERT(defaultEntry.fExternalFormat != fConfigTable[i].fFormats.fExternalFormat);
1526 SkASSERT(defaultEntry.fExternalType != fConfigTable[i].fFormats.fExternalType);
1527 }
1528#endif
1529}
1530
egdanielb7e7d572015-11-04 04:23:53 -08001531void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}
jvanverthe9c0fc62015-04-29 11:18:05 -07001532
1533