blob: b02f387afe71663a74e14d07d5d07ff13f503c8b [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 fVerifiedColorConfigs.reset();
21 fStencilFormats.reset();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000022 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000023 fInvalidateFBType = kNone_InvalidateFBType;
krajcevski3217c4a2014-06-09 09:10:04 -070024 fLATCAlias = kLATC_LATCAlias;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000025 fMapBufferType = kNone_MapBufferType;
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;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000029 fRGBA8RenderbufferSupport = false;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030 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;
robertphillips@google.com1d89c932012-06-27 19:31:41 +000039 fTwoFormatLimit = false;
bsalomon@google.com07631cf2013-03-05 14:14:58 +000040 fVertexArrayObjectSupport = false;
cdalton626e1ff2015-06-12 13:56:46 -070041 fInstancedDrawingSupport = false;
42 fDirectStateAccessSupport = false;
43 fDebugSupport = false;
jvanverth3f801cb2014-12-16 09:49:38 -080044 fES2CompatibilitySupport = false;
cdaltond4727922015-11-10 12:49:06 -080045 fMultisampleDisableSupport = false;
bsalomon@google.com96966a52013-02-21 16:34:21 +000046 fUseNonVBOVertexAndIndexDynamicData = false;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +000047 fIsCoreProfile = false;
joshualittc1f56b52015-06-22 12:31:31 -070048 fBindFragDataLocationSupport = false;
bsalomon16921ec2015-07-30 15:34:56 -070049 fSRGBWriteControl = false;
bsalomon88c7b982015-07-31 11:20:16 -070050 fRGBA8888PixelsOpsAreSlow = false;
51 fPartialFBOReadIsSlow = false;
piotaixre4b23142014-10-02 10:57:53 -070052
53 fReadPixelsSupportedCache.reset();
jvanverthe9c0fc62015-04-29 11:18:05 -070054
halcanary385fe4d2015-08-26 13:07:48 -070055 fShaderCaps.reset(new GrGLSLCaps(contextOptions));
bsalomon4ee6bd82015-05-27 13:23:23 -070056
cdalton4cd67132015-06-10 19:23:46 -070057 this->init(contextOptions, ctxInfo, glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000058}
59
cdalton4cd67132015-06-10 19:23:46 -070060void GrGLCaps::init(const GrContextOptions& contextOptions,
61 const GrGLContextInfo& ctxInfo,
62 const GrGLInterface* gli) {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000063 GrGLStandard standard = ctxInfo.standard();
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000064 GrGLVersion version = ctxInfo.version();
65
bsalomon@google.combcce8922013-03-25 15:38:39 +000066 /**************************************************************************
67 * Caps specific to GrGLCaps
68 **************************************************************************/
69
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000070 if (kGLES_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000071 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
72 &fMaxFragmentUniformVectors);
73 } else {
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000074 SkASSERT(kGL_GrGLStandard == standard);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000075 GrGLint max;
76 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
77 fMaxFragmentUniformVectors = max / 4;
commit-bot@chromium.org46fbfe02013-08-30 15:52:12 +000078 if (version >= GR_GL_VER(3, 2)) {
79 GrGLint profileMask;
80 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
81 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
82 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000083 }
bsalomon@google.com60da4172012-06-01 19:25:00 +000084 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +000085 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000086
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000087 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000088 fRGBA8RenderbufferSupport = true;
89 } else {
commit-bot@chromium.orgc5dffe42013-08-20 15:25:21 +000090 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
91 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000092 ctxInfo.hasExtension("GL_ARM_rgba8");
93 }
94
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000095 if (kGL_GrGLStandard == standard) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000096 fUnpackRowLengthSupport = true;
97 fUnpackFlipYSupport = false;
98 fPackRowLengthSupport = true;
99 fPackFlipYSupport = false;
100 } else {
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000101 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
102 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000103 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
commit-bot@chromium.orgdc3134c2013-08-16 16:12:23 +0000104 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
105 ctxInfo.hasExtension("GL_NV_pack_subimage");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000106 fPackFlipYSupport =
107 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
108 }
109
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000110 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000111 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
112
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000113 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org7a434a22013-08-21 14:01:56 +0000114 // The EXT version can apply to either GL or GLES.
115 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
116 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
117 ctxInfo.hasExtension("GL_EXT_texture_storage");
118 } else {
119 // Qualcomm Adreno drivers appear to have issues with texture storage.
120 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
121 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
122 ctxInfo.hasExtension("GL_EXT_texture_storage");
123 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000124
cdaltonfd4167d2015-04-21 11:45:56 -0700125 if (kGL_GrGLStandard == standard) {
126 fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
127 ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
128 ctxInfo.hasExtension("GL_NV_texture_barrier");
129 } else {
130 fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
131 }
132
hendrikwa0d5ad72014-12-02 07:30:30 -0800133 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support GL_RED
134 // and GL_RG on FBO textures.
cdalton1acea862015-06-02 13:05:52 -0700135 if (kMesa_GrGLDriver != ctxInfo.driver()) {
hendrikwa0d5ad72014-12-02 07:30:30 -0800136 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000137 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
138 ctxInfo.hasExtension("GL_ARB_texture_rg");
hendrikwa0d5ad72014-12-02 07:30:30 -0800139 } else {
140 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
141 ctxInfo.hasExtension("GL_EXT_texture_rg");
commit-bot@chromium.org459104c2013-06-14 14:42:56 +0000142 }
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000143 }
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000144 fImagingSupport = kGL_GrGLStandard == standard &&
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000145 ctxInfo.hasExtension("GL_ARB_imaging");
146
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000147 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
148 // ReadPixels. The other format has to checked at run-time since it
149 // can change based on which render target is bound
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000150 fTwoFormatLimit = kGLES_GrGLStandard == standard;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000151
bsalomon16921ec2015-07-30 15:34:56 -0700152 // We only enable srgb support if both textures and FBOs support srgb.
153 bool srgbSupport = false;
154 if (kGL_GrGLStandard == standard) {
155 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
156 srgbSupport = true;
157 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
158 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
159 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
160 srgbSupport = true;
161 }
162 }
163 // All the above srgb extensions support toggling srgb writes
164 fSRGBWriteControl = srgbSupport;
165 } else {
halcanary6950de62015-11-07 05:29:00 -0800166 // See https://bug.skia.org/4148 for PowerVR issue.
bsalomon58b43952015-07-30 16:27:50 -0700167 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
168 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
bsalomon16921ec2015-07-30 15:34:56 -0700169 // ES through 3.1 requires EXT_srgb_write_control to support toggling
170 // sRGB writing for destinations.
171 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
172 }
173
bsalomon@google.com3012ded2013-02-22 16:44:04 +0000174 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
175 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
176 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
177 // limit this decision to specific GPU families rather than basing it on the vendor alone.
178 if (!GR_GL_MUST_USE_VBO &&
bsalomoned82c4e2014-09-02 07:54:47 -0700179 (kARM_GrGLVendor == ctxInfo.vendor() ||
180 kImagination_GrGLVendor == ctxInfo.vendor() ||
181 kQualcomm_GrGLVendor == ctxInfo.vendor())) {
bsalomon@google.com96966a52013-02-21 16:34:21 +0000182 fUseNonVBOVertexAndIndexDynamicData = true;
183 }
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000184
egdaniel9250d242015-05-18 13:04:26 -0700185 // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
186 // Thus we are blacklisting this extension for now on Adreno4xx devices.
187 if (kAdreno4xx_GrGLRenderer != ctxInfo.renderer() &&
188 ((kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) ||
189 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) ||
190 ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000191 fDiscardRenderTargetSupport = true;
192 fInvalidateFBType = kInvalidate_InvalidateFBType;
193 } else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
194 fDiscardRenderTargetSupport = true;
195 fInvalidateFBType = kDiscard_InvalidateFBType;
196 }
robertphillips@google.coma6ffb582013-04-29 16:50:17 +0000197
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000198 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
199 fFullClearIsFree = true;
200 }
201
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000202 if (kGL_GrGLStandard == standard) {
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000203 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
tomhudson612e9262014-11-24 11:22:36 -0800204 ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
205 ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000206 } else {
commit-bot@chromium.org2276c012013-08-16 15:53:33 +0000207 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
208 ctxInfo.hasExtension("GL_OES_vertex_array_object");
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000209 }
210
cdalton626e1ff2015-06-12 13:56:46 -0700211 if ((kGL_GrGLStandard == standard && version >= GR_GL_VER(3,2)) ||
212 (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0))) {
213 fInstancedDrawingSupport = true;
214 } else {
215 fInstancedDrawingSupport = (ctxInfo.hasExtension("GL_ARB_draw_instanced") ||
216 ctxInfo.hasExtension("GL_EXT_draw_instanced")) &&
217 (ctxInfo.hasExtension("GL_ARB_instanced_arrays") ||
218 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
219 }
220
221 if (kGL_GrGLStandard == standard) {
222 fDirectStateAccessSupport = ctxInfo.hasExtension("GL_EXT_direct_state_access");
223 } else {
224 fDirectStateAccessSupport = false;
225 }
226
227 if (kGL_GrGLStandard == standard && version >= GR_GL_VER(4,3)) {
228 fDebugSupport = true;
229 } else {
230 fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
231 }
232
jvanverth3f801cb2014-12-16 09:49:38 -0800233 if (kGL_GrGLStandard == standard) {
234 fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
235 }
236 else {
237 fES2CompatibilitySupport = true;
238 }
239
cdalton0edea2c2015-05-21 08:27:44 -0700240 if (kGL_GrGLStandard == standard) {
241 fMultisampleDisableSupport = true;
242 } else {
kkinnunenbf49e462015-07-30 22:43:52 -0700243 fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
cdalton0edea2c2015-05-21 08:27:44 -0700244 }
245
kkinnunend94708e2015-07-30 22:47:04 -0700246 if (kGL_GrGLStandard == standard) {
247 if (version >= GR_GL_VER(3, 0)) {
248 fBindFragDataLocationSupport = true;
249 }
250 } else {
251 if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
252 fBindFragDataLocationSupport = true;
253 }
joshualittc1f56b52015-06-22 12:31:31 -0700254 }
255
halcanary6950de62015-11-07 05:29:00 -0800256#if 0 // Disabled due to https://bug.skia.org/4454
joshualitt7bdd70a2015-10-01 06:28:11 -0700257 fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
kkinnunen177519e2015-10-28 06:18:35 -0700258#else
259 fBindUniformLocationSupport = false;
260#endif
joshualitt7bdd70a2015-10-01 06:28:11 -0700261
bsalomon88c7b982015-07-31 11:20:16 -0700262#ifdef SK_BUILD_FOR_WIN
263 // We're assuming that on Windows Chromium we're using ANGLE.
264 bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
265 kChromium_GrGLDriver == ctxInfo.driver();
266 // Angle has slow read/write pixel paths for 32bit RGBA (but fast for BGRA).
267 fRGBA8888PixelsOpsAreSlow = isANGLE;
268 // On DX9 ANGLE reading a partial FBO is slow. TODO: Check whether this is still true and
269 // check DX11 ANGLE.
270 fPartialFBOReadIsSlow = isANGLE;
271#endif
272
cdalton4cd67132015-06-10 19:23:46 -0700273 /**************************************************************************
egdaniel05ded892015-10-26 07:38:05 -0700274 * GrShaderCaps fields
275 **************************************************************************/
276
egdaniel0a482332015-10-26 08:59:10 -0700277 // This must be called after fCoreProfile is set on the GrGLCaps
278 this->initGLSL(ctxInfo);
279 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
280
egdaniel05ded892015-10-26 07:38:05 -0700281 glslCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
282
283 // For now these two are equivalent but we could have dst read in shader via some other method.
284 // Before setting this, initGLSL() must have been called.
285 glslCaps->fDstReadInShaderSupport = glslCaps->fFBFetchSupport;
286
287 // Enable supported shader-related caps
288 if (kGL_GrGLStandard == standard) {
289 glslCaps->fDualSourceBlendingSupport = (ctxInfo.version() >= GR_GL_VER(3, 3) ||
290 ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
291 GrGLSLSupportsNamedFragmentShaderOutputs(ctxInfo.glslGeneration());
292 glslCaps->fShaderDerivativeSupport = true;
293 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
294 glslCaps->fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3, 2) &&
295 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
296 }
297 else {
298 glslCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
299
300 glslCaps->fShaderDerivativeSupport = ctxInfo.version() >= GR_GL_VER(3, 0) ||
301 ctxInfo.hasExtension("GL_OES_standard_derivatives");
302 }
303
cdaltond4727922015-11-10 12:49:06 -0800304 if (kGL_GrGLStandard == standard) {
305 glslCaps->fProgrammableSampleLocationsSupport =
306 ctxInfo.version() >= GR_GL_VER(4, 3) &&
307 (ctxInfo.hasExtension("GL_ARB_sample_locations") ||
308 ctxInfo.hasExtension("GL_NV_sample_locations"));
309 } else {
310 glslCaps->fProgrammableSampleLocationsSupport =
311 ctxInfo.version() >= GR_GL_VER(3, 1) &&
312 ctxInfo.hasExtension("GL_NV_sample_locations");
313 }
314
egdaniel05ded892015-10-26 07:38:05 -0700315 /**************************************************************************
bsalomon4b91f762015-05-19 09:29:46 -0700316 * GrCaps fields
bsalomon@google.combcce8922013-03-25 15:38:39 +0000317 **************************************************************************/
cdalton4cd67132015-06-10 19:23:46 -0700318
cdalton63f6c1f2015-11-06 07:09:43 -0800319 // We need dual source blending and the ability to disable multisample in order to support mixed
320 // samples in every corner case.
321 if (fMultisampleDisableSupport && glslCaps->dualSourceBlendingSupport()) {
322 fMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples");
323 // Workaround NVIDIA bug related to glInvalidateFramebuffer and mixed samples.
324 if (fMixedSamplesSupport && kNVIDIA_GrGLDriver == ctxInfo.driver()) {
325 fDiscardRenderTargetSupport = false;
326 fInvalidateFBType = kNone_InvalidateFBType;
327 }
328 }
329
330 // fPathRenderingSupport and fMixedSamplesSupport must be set before calling initFSAASupport.
cdalton4cd67132015-06-10 19:23:46 -0700331 this->initFSAASupport(ctxInfo, gli);
cdalton1dd05422015-06-12 09:01:18 -0700332 this->initBlendEqationSupport(ctxInfo);
cdalton4cd67132015-06-10 19:23:46 -0700333 this->initStencilFormats(ctxInfo);
334
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000335 if (kGL_GrGLStandard == standard) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000336 // we could also look for GL_ATI_separate_stencil extension or
337 // GL_EXT_stencil_two_side but they use different function signatures
338 // than GL2.0+ (and than each other).
339 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
340 // supported on GL 1.4 and higher or by extension
341 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
342 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
343 } else {
344 // ES 2 has two sided stencil and stencil wrap
345 fTwoSidedStencilSupport = true;
346 fStencilWrapOpsSupport = true;
347 }
348
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000349 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000350 fMapBufferFlags = kCanMap_MapFlag; // we require VBO support and the desktop VBO
351 // extension includes glMapBuffer.
352 if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
353 fMapBufferFlags |= kSubset_MapFlag;
354 fMapBufferType = kMapBufferRange_MapBufferType;
355 } else {
356 fMapBufferType = kMapBuffer_MapBufferType;
357 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000358 } else {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000359 // Unextended GLES2 doesn't have any buffer mapping.
360 fMapBufferFlags = kNone_MapBufferType;
361 if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
362 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
363 fMapBufferType = kChromium_MapBufferType;
364 } else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
365 fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
366 fMapBufferType = kMapBufferRange_MapBufferType;
367 } else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
368 fMapBufferFlags = kCanMap_MapFlag;
369 fMapBufferType = kMapBuffer_MapBufferType;
370 }
bsalomon@google.combcce8922013-03-25 15:38:39 +0000371 }
372
joshualitte5b74c62015-06-01 14:17:47 -0700373 // On many GPUs, map memory is very expensive, so we effectively disable it here by setting the
374 // threshold to the maximum unless the client gives us a hint that map memory is cheap.
375 if (fGeometryBufferMapThreshold < 0) {
bsalomonbc233752015-06-26 11:38:25 -0700376 // We think mapping on Chromium will be cheaper once we know ahead of time how much space
377 // we will use for all GrBatchs. Right now we might wind up mapping a large buffer and using
378 // a small subset.
379#if 0
cdalton1acea862015-06-02 13:05:52 -0700380 fGeometryBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
bsalomonbc233752015-06-26 11:38:25 -0700381#else
382 fGeometryBufferMapThreshold = SK_MaxS32;
383#endif
joshualitte5b74c62015-06-01 14:17:47 -0700384 }
385
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000386 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000387 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
388 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
389 fNPOTTextureTileSupport = true;
390 fMipMapSupport = true;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000391 } else {
392 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
commit-bot@chromium.org22dd6b92013-08-16 18:13:48 +0000393 // ES3 has no limitations.
394 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
395 ctxInfo.hasExtension("GL_OES_texture_npot");
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000396 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
397 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
398 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
399 // to alllow arbitrary wrap modes, however.
400 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
bsalomon@google.combcce8922013-03-25 15:38:39 +0000401 }
402
bsalomone72bd022015-10-26 07:33:03 -0700403 // Using MIPs on this GPU seems to be a source of trouble.
404 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
405 fMipMapSupport = false;
406 }
407
bsalomon@google.combcce8922013-03-25 15:38:39 +0000408 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
409 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
410 // Our render targets are always created with textures as the color
411 // attachment, hence this min:
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000412 fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
bsalomon@google.combcce8922013-03-25 15:38:39 +0000413
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000414 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
415
robertphillips@google.com8995b7b2013-11-01 15:03:34 +0000416 // Disable scratch texture reuse on Mali and Adreno devices
417 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
418 kQualcomm_GrGLVendor != ctxInfo.vendor();
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000419
robertphillips1b8e1b52015-06-24 06:54:10 -0700420#if 0
421 fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
422 kQualcomm_GrGLVendor != ctxInfo.vendor();
423#endif
424
egdaniel05ded892015-10-26 07:38:05 -0700425 // initFSAASupport() must have been called before this point
bsalomon@google.com347c3822013-05-01 20:10:01 +0000426 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
bsalomon@google.combcce8922013-03-25 15:38:39 +0000427 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
428 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
429 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
430 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000431
bsalomon63b21962014-11-05 07:05:34 -0800432 if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
bsalomone702d972015-01-29 10:07:32 -0800433 kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
bsalomona8fcea02015-02-13 09:00:39 -0800434 kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
bsalomon63b21962014-11-05 07:05:34 -0800435 fUseDrawInsteadOfClear = true;
436 }
437
joshualitt83bc2292015-06-18 14:18:02 -0700438 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer()) {
439 fUseDrawInsteadOfPartialRenderTargetWrite = true;
440 }
441
robertphillips63926682015-08-20 09:39:02 -0700442#ifdef SK_BUILD_FOR_WIN
443 // On ANGLE deferring flushes can lead to GPU starvation
444 fPreferVRAMUseOverFlushes = !isANGLE;
445#endif
446
bsalomon7dea7b72015-08-19 08:26:51 -0700447 if (kChromium_GrGLDriver == ctxInfo.driver()) {
448 fMustClearUploadedBufferData = true;
449 }
450
bsalomond08ea5f2015-02-20 06:58:13 -0800451 if (kGL_GrGLStandard == standard) {
452 // ARB allows mixed size FBO attachments, EXT does not.
453 if (ctxInfo.version() >= GR_GL_VER(3, 0) ||
454 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
455 fOversizedStencilSupport = true;
456 } else {
457 SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
458 }
459 } else {
460 // ES 3.0 supports mixed size FBO attachments, 2.0 does not.
461 fOversizedStencilSupport = ctxInfo.version() >= GR_GL_VER(3, 0);
462 }
463
joshualitt58001552015-06-26 12:46:36 -0700464 if (kGL_GrGLStandard == standard) {
465 // 3.1 has draw_instanced but not instanced_arrays, for the time being we only care about
466 // instanced arrays, but we could make this more granular if we wanted
467 fSupportsInstancedDraws =
468 version >= GR_GL_VER(3, 2) ||
469 (ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
470 ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
471 } else {
472 fSupportsInstancedDraws =
473 version >= GR_GL_VER(3, 0) ||
474 (ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
475 ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
476 }
477
bsalomon16921ec2015-07-30 15:34:56 -0700478 this->initConfigTexturableTable(ctxInfo, gli, srgbSupport);
479 this->initConfigRenderableTable(ctxInfo, srgbSupport);
jvanverthcba99b82015-06-24 06:59:57 -0700480 this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
egdanielb7e7d572015-11-04 04:23:53 -0800481 // Requires fTexutreSwizzleSupport and fTextureRedSupport to be set before this point.
482 this->initConfigSwizzleTable(ctxInfo, glslCaps);
cdalton4cd67132015-06-10 19:23:46 -0700483
484 this->applyOptionsOverrides(contextOptions);
485 glslCaps->applyOptionsOverrides(contextOptions);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000486}
487
egdaniel472d44e2015-10-22 08:20:00 -0700488const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
489 bool isCoreProfile) {
490 switch (generation) {
491 case k110_GrGLSLGeneration:
492 if (kGLES_GrGLStandard == standard) {
493 // ES2s shader language is based on version 1.20 but is version
494 // 1.00 of the ES language.
495 return "#version 100\n";
496 } else {
497 SkASSERT(kGL_GrGLStandard == standard);
498 return "#version 110\n";
499 }
500 case k130_GrGLSLGeneration:
501 SkASSERT(kGL_GrGLStandard == standard);
502 return "#version 130\n";
503 case k140_GrGLSLGeneration:
504 SkASSERT(kGL_GrGLStandard == standard);
505 return "#version 140\n";
506 case k150_GrGLSLGeneration:
507 SkASSERT(kGL_GrGLStandard == standard);
508 if (isCoreProfile) {
509 return "#version 150\n";
510 } else {
511 return "#version 150 compatibility\n";
512 }
513 case k330_GrGLSLGeneration:
514 if (kGLES_GrGLStandard == standard) {
515 return "#version 300 es\n";
516 } else {
517 SkASSERT(kGL_GrGLStandard == standard);
518 if (isCoreProfile) {
519 return "#version 330\n";
520 } else {
521 return "#version 330 compatibility\n";
522 }
523 }
524 case k310es_GrGLSLGeneration:
525 SkASSERT(kGLES_GrGLStandard == standard);
526 return "#version 310 es\n";
527 }
528 return "<no version>";
529}
530
egdaniel05ded892015-10-26 07:38:05 -0700531void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo) {
egdaniel472d44e2015-10-22 08:20:00 -0700532 GrGLStandard standard = ctxInfo.standard();
533 GrGLVersion version = ctxInfo.version();
534
535 /**************************************************************************
536 * Caps specific to GrGLSLCaps
537 **************************************************************************/
538
539 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
540 glslCaps->fGLSLGeneration = ctxInfo.glslGeneration();
541
542 if (kGLES_GrGLStandard == standard) {
543 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
544 glslCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
545 glslCaps->fFBFetchSupport = true;
546 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
547 glslCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
548 }
549 else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
550 // Actually, we haven't seen an ES3.0 device with this extension yet, so we don't know
551 glslCaps->fFBFetchNeedsCustomOutput = false;
552 glslCaps->fFBFetchSupport = true;
553 glslCaps->fFBFetchColorName = "gl_LastFragData[0]";
554 glslCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
555 }
556 else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
557 // The arm extension also requires an additional flag which we will set onResetContext
558 glslCaps->fFBFetchNeedsCustomOutput = false;
559 glslCaps->fFBFetchSupport = true;
560 glslCaps->fFBFetchColorName = "gl_LastFragColorARM";
561 glslCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
562 }
563 glslCaps->fUsesPrecisionModifiers = true;
564 }
565
566 glslCaps->fBindlessTextureSupport = ctxInfo.hasExtension("GL_NV_bindless_texture");
567
568 // Adreno GPUs have a tendency to drop tiles when there is a divide-by-zero in a shader
569 glslCaps->fDropsTileOnZeroDivide = kQualcomm_GrGLVendor == ctxInfo.vendor();
570
571 // On the NexusS and GalaxyNexus, the use of 'any' causes the compilation error "Calls to any
572 // function that may require a gradient calculation inside a conditional block may return
573 // undefined results". This appears to be an issue with the 'any' call since even the simple
574 // "result=black; if (any()) result=white;" code fails to compile. This issue comes into play
575 // from our GrTextureDomain processor.
576 glslCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
577
egdanielcae00852015-10-22 11:08:08 -0700578 glslCaps->fForceHighPrecisionNDSTransform = kARM_GrGLVendor == ctxInfo.vendor() ||
579 kPowerVR54x_GrGLRenderer == ctxInfo.renderer();
egdaniel472d44e2015-10-22 08:20:00 -0700580
581 glslCaps->fVersionDeclString = get_glsl_version_decl_string(standard, glslCaps->fGLSLGeneration,
582 fIsCoreProfile);
egdaniel574a4c12015-11-02 06:22:44 -0800583
584 if (kGLES_GrGLStandard == standard && k110_GrGLSLGeneration == glslCaps->fGLSLGeneration) {
585 glslCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
586 }
egdaniel8dcdedc2015-11-11 06:27:20 -0800587
588 // Frag Coords Convention support is not part of ES
589 // Known issue on at least some Intel platforms:
590 // http://code.google.com/p/skia/issues/detail?id=946
591 if (kIntel_GrGLVendor != ctxInfo.vendor() &&
592 kGLES_GrGLStandard != standard &&
593 (ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
594 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
595 glslCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
596 }
597
598 if (kGLES_GrGLStandard == standard) {
599 glslCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
600 }
601
602 // The Tegra3 compiler will sometimes never return if we have min(abs(x), 1.0), so we must do
603 // the abs first in a separate expression.
604 if (kTegra3_GrGLRenderer == ctxInfo.renderer()) {
605 glslCaps->fCanUseMinAndAbsTogether = false;
606 }
607
608 // On Intel GPU there is an issue where it reads the second arguement to atan "- %s.x" as an int
609 // thus must us -1.0 * %s.x to work correctly
610 if (kIntel_GrGLVendor == ctxInfo.vendor()) {
611 glslCaps->fMustForceNegatedAtanParamToFloat = true;
612 }
egdaniel472d44e2015-10-22 08:20:00 -0700613}
614
kkinnunencfe62e32015-07-01 02:58:50 -0700615bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
kkinnunen6bb6d402015-07-14 10:59:23 -0700616 bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
617
618 if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700619 return false;
620 }
kkinnunen6bb6d402015-07-14 10:59:23 -0700621
kkinnunencfe62e32015-07-01 02:58:50 -0700622 if (kGL_GrGLStandard == ctxInfo.standard()) {
623 if (ctxInfo.version() < GR_GL_VER(4, 3) &&
624 !ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
625 return false;
626 }
627 } else {
kkinnunen6bb6d402015-07-14 10:59:23 -0700628 if (!hasChromiumPathRendering &&
629 ctxInfo.version() < GR_GL_VER(3, 1)) {
kkinnunencfe62e32015-07-01 02:58:50 -0700630 return false;
631 }
632 }
633 // We only support v1.3+ of GL_NV_path_rendering which allows us to
634 // set individual fragment inputs with ProgramPathFragmentInputGen. The API
635 // additions are detected by checking the existence of the function.
636 // We also use *Then* functions that not all drivers might have. Check
637 // them for consistency.
halcanary96fcdcc2015-08-27 07:41:13 -0700638 if (nullptr == gli->fFunctions.fStencilThenCoverFillPath ||
639 nullptr == gli->fFunctions.fStencilThenCoverStrokePath ||
640 nullptr == gli->fFunctions.fStencilThenCoverFillPathInstanced ||
641 nullptr == gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
642 nullptr == gli->fFunctions.fProgramPathFragmentInputGen) {
kkinnunencfe62e32015-07-01 02:58:50 -0700643 return false;
644 }
645 return true;
646}
647
bsalomon16921ec2015-07-30 15:34:56 -0700648void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo, bool srgbSupport) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000649 // OpenGL < 3.0
650 // no support for render targets unless the GL_ARB_framebuffer_object
651 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
652 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
653 // probably don't get R8 in this case.
654
655 // OpenGL 3.0
656 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
657 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
658
659 // >= OpenGL 3.1
660 // base color renderable: RED, RG, RGB, and RGBA
661 // sized derivatives: R8, RGBA4, RGBA8
662 // if the GL_ARB_compatibility extension is supported then we get back
663 // support for GL_ALPHA and ALPHA8
664
665 // GL_EXT_bgra adds BGRA render targets to any version
666
667 // ES 2.0
668 // color renderable: RGBA4, RGB5_A1, RGB565
669 // GL_EXT_texture_rg adds support for R8 as a color render target
670 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
671 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
672
673 // ES 3.0
674 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
675 // below already account for this).
676
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000677 GrGLStandard standard = ctxInfo.standard();
678
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000679 enum {
680 kNo_MSAA = 0,
681 kYes_MSAA = 1,
682 };
683
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000684 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000685 // Post 3.0 we will get R8
686 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
687 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
688 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000689 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
690 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000691 }
692 } else {
693 // On ES we can only hope for R8
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000694 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
695 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000696 }
697
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000698 if (kGL_GrGLStandard != standard) {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000699 // only available in ES
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000700 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
701 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000702 }
703
704 // we no longer support 444 as a render target
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000705 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
706 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000707
708 if (this->fRGBA8RenderbufferSupport) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000709 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
commit-bot@chromium.orgda3d69c2013-10-28 15:09:13 +0000710 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000711 }
712
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000713 if (this->isConfigTexturable(kBGRA_8888_GrPixelConfig)) {
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000714 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
715 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
716 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000717 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +0000718 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
commit-bot@chromium.org4256d242013-10-17 16:29:41 +0000719 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
720 } else {
721 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
722 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
723 }
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000724 }
725
bsalomon16921ec2015-07-30 15:34:56 -0700726 if (this->fRGBA8RenderbufferSupport && srgbSupport) {
727 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
728 fConfigRenderSupport[kSRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
jvanverthfa1e8a72014-12-22 08:31:49 -0800729 }
730
joshualittee5da552014-07-16 13:32:56 -0700731 if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800732 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800733 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800734 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = true;
735 } else {
joshualitt55999962015-06-18 13:47:10 -0700736 // for now we only enable this on desktop, because on ES we'd have to solve many
737 // precision issues and no clients actually want this yet
738 /*
jvanvertha60b2ea2014-12-12 05:58:06 -0800739 if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
740 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
741 } else {
742 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
743 }
744 // for now we don't support floating point MSAA on ES
joshualitt55999962015-06-18 13:47:10 -0700745 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;*/
746 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = false;
jvanverthfb5df432015-05-21 08:12:27 -0700747 fConfigRenderSupport[kRGBA_float_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800748 }
joshualittee5da552014-07-16 13:32:56 -0700749 }
750
jvanverth28f9c602014-12-05 13:06:35 -0800751 if (this->isConfigTexturable(kAlpha_half_GrPixelConfig)) {
jvanverth28f9c602014-12-05 13:06:35 -0800752 if (kGL_GrGLStandard == standard) {
jvanvertha60b2ea2014-12-12 05:58:06 -0800753 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
jvanverth28f9c602014-12-05 13:06:35 -0800754 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = true;
jvanverth1334c212014-12-18 05:44:55 -0800755 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
756 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
757 // for now we don't support floating point MSAA on ES
758 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
jvanverth28f9c602014-12-05 13:06:35 -0800759 } else {
jvanverth1334c212014-12-18 05:44:55 -0800760 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") && fTextureRedSupport) {
761 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = true;
762 } else {
763 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kNo_MSAA] = false;
764 }
765 // for now we don't support floating point MSAA on ES
jvanverth28f9c602014-12-05 13:06:35 -0800766 fConfigRenderSupport[kAlpha_half_GrPixelConfig][kYes_MSAA] = false;
767 }
768 }
769
jvanverthfb5df432015-05-21 08:12:27 -0700770 if (this->isConfigTexturable(kRGBA_half_GrPixelConfig)) {
771 if (kGL_GrGLStandard == standard) {
772 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
773 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = true;
774 } else if (ctxInfo.version() >= GR_GL_VER(3, 0)) {
775 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
776 // for now we don't support floating point MSAA on ES
777 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
778 } else {
779 if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
780 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = true;
781 } else {
782 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kNo_MSAA] = false;
783 }
784 // for now we don't support floating point MSAA on ES
785 fConfigRenderSupport[kRGBA_half_GrPixelConfig][kYes_MSAA] = false;
786 }
787 }
788
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000789 // If we don't support MSAA then undo any places above where we set a config as renderable with
790 // msaa.
791 if (kNone_MSFBOType == fMSFBOType) {
792 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
793 fConfigRenderSupport[i][kYes_MSAA] = false;
794 }
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000795 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000796}
797
bsalomon16921ec2015-07-30 15:34:56 -0700798void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
799 bool srgbSupport) {
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000800 GrGLStandard standard = ctxInfo.standard();
801 GrGLVersion version = ctxInfo.version();
802
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000803 // Base texture support
804 fConfigTextureSupport[kAlpha_8_GrPixelConfig] = true;
805 fConfigTextureSupport[kRGB_565_GrPixelConfig] = true;
806 fConfigTextureSupport[kRGBA_4444_GrPixelConfig] = true;
807 fConfigTextureSupport[kRGBA_8888_GrPixelConfig] = true;
808
halcanary6950de62015-11-07 05:29:00 -0800809 // Disable this for now, while we investigate https://bug.skia.org/4333
reed56f38fb2015-09-14 09:09:00 -0700810 if (false) {
811 // Check for 8-bit palette..
812 GrGLint numFormats;
813 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
814 if (numFormats) {
815 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
816 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
817 for (int i = 0; i < numFormats; ++i) {
818 if (GR_GL_PALETTE8_RGBA8 == formats[i]) {
819 fConfigTextureSupport[kIndex_8_GrPixelConfig] = true;
820 break;
821 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000822 }
823 }
824 }
825
826 // Check for BGRA
827 if (kGL_GrGLStandard == standard) {
828 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] =
829 version >= GR_GL_VER(1,2) || ctxInfo.hasExtension("GL_EXT_bgra");
830 } else {
831 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
832 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
833 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
834 fConfigTextureSupport[kBGRA_8888_GrPixelConfig] = true;
835 fBGRAIsInternalFormat = true;
836 }
837 SkASSERT(fConfigTextureSupport[kBGRA_8888_GrPixelConfig] ||
838 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
839 }
840
bsalomon16921ec2015-07-30 15:34:56 -0700841 fConfigTextureSupport[kSRGBA_8888_GrPixelConfig] = srgbSupport;
jvanverthfa1e8a72014-12-22 08:31:49 -0800842
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000843 // Compressed texture support
844
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000845 // glCompressedTexImage2D is available on all OpenGL ES devices...
846 // however, it is only available on standard OpenGL after version 1.3
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000847 bool hasCompressTex2D = (kGL_GrGLStandard != standard || version >= GR_GL_VER(1, 3));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000848
krajcevski786978162014-07-30 11:25:44 -0700849 fCompressedTexSubImageSupport =
bsalomon49f085d2014-09-05 13:34:00 -0700850 hasCompressTex2D && (gli->fFunctions.fCompressedTexSubImage2D);
krajcevski786978162014-07-30 11:25:44 -0700851
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000852 // Check for ETC1
853 bool hasETC1 = false;
854
855 // First check version for support
856 if (kGL_GrGLStandard == standard) {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000857 hasETC1 = hasCompressTex2D &&
joshualittee5da552014-07-16 13:32:56 -0700858 (version >= GR_GL_VER(4, 3) ||
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000859 ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000860 } else {
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000861 hasETC1 = hasCompressTex2D &&
862 (version >= GR_GL_VER(3, 0) ||
863 ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture") ||
864 // ETC2 is a superset of ETC1, so we can just check for that, too.
865 (ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture") &&
866 ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGBA8_texture")));
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000867 }
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000868 fConfigTextureSupport[kETC1_GrPixelConfig] = hasETC1;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000869
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000870 // Check for LATC under its various forms
871 LATCAlias alias = kLATC_LATCAlias;
872 bool hasLATC = hasCompressTex2D &&
873 (ctxInfo.hasExtension("GL_EXT_texture_compression_latc") ||
874 ctxInfo.hasExtension("GL_NV_texture_compression_latc"));
875
876 // Check for RGTC
877 if (!hasLATC) {
878 // If we're using OpenGL 3.0 or later, then we have RGTC, an identical compression format.
879 if (kGL_GrGLStandard == standard) {
880 hasLATC = version >= GR_GL_VER(3, 0);
881 }
882
883 if (!hasLATC) {
884 hasLATC =
885 ctxInfo.hasExtension("GL_EXT_texture_compression_rgtc") ||
886 ctxInfo.hasExtension("GL_ARB_texture_compression_rgtc");
887 }
888
889 if (hasLATC) {
890 alias = kRGTC_LATCAlias;
891 }
892 }
893
894 // Check for 3DC
895 if (!hasLATC) {
896 hasLATC = ctxInfo.hasExtension("GL_AMD_compressed_3DC_texture");
897 if (hasLATC) {
898 alias = k3DC_LATCAlias;
899 }
900 }
901
902 fConfigTextureSupport[kLATC_GrPixelConfig] = hasLATC;
903 fLATCAlias = alias;
krajcevski238b4562014-06-30 09:09:22 -0700904
krajcevskib3abe902014-07-30 13:08:11 -0700905 // Check for R11_EAC ... We don't support R11_EAC on desktop, as most
906 // cards default to decompressing the textures in the driver, and is
907 // generally slower.
908 if (kGL_GrGLStandard != standard) {
krajcevski238b4562014-06-30 09:09:22 -0700909 fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
910 }
joshualittee5da552014-07-16 13:32:56 -0700911
krajcevski7ef21622014-07-16 15:21:13 -0700912 // Check for ASTC
piotaixre4b23142014-10-02 10:57:53 -0700913 fConfigTextureSupport[kASTC_12x12_GrPixelConfig] =
krajcevski7ef21622014-07-16 15:21:13 -0700914 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_hdr") ||
915 ctxInfo.hasExtension("GL_KHR_texture_compression_astc_ldr") ||
916 ctxInfo.hasExtension("GL_OES_texture_compression_astc");
917
joshualittee5da552014-07-16 13:32:56 -0700918 // Check for floating point texture support
919 // NOTE: We disallow floating point textures on ES devices if linear
920 // filtering modes are not supported. This is for simplicity, but a more
921 // granular approach is possible. Coincidentally, floating point textures became part of
922 // the standard in ES3.1 / OGL 3.1, hence the shorthand
923 bool hasFPTextures = version >= GR_GL_VER(3, 1);
924 if (!hasFPTextures) {
925 hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanvertha60b2ea2014-12-12 05:58:06 -0800926 (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
joshualittee5da552014-07-16 13:32:56 -0700927 ctxInfo.hasExtension("GL_OES_texture_float"));
928 }
929 fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
jvanverth28f9c602014-12-05 13:06:35 -0800930
931 // Check for fp16 texture support
932 // NOTE: We disallow floating point textures on ES devices if linear
933 // filtering modes are not supported. This is for simplicity, but a more
934 // granular approach is possible. Coincidentally, 16-bit floating point textures became part of
935 // the standard in ES3.1 / OGL 3.1, hence the shorthand
936 bool hasHalfFPTextures = version >= GR_GL_VER(3, 1);
937 if (!hasHalfFPTextures) {
938 hasHalfFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
jvanverth1334c212014-12-18 05:44:55 -0800939 (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
940 ctxInfo.hasExtension("GL_OES_texture_half_float"));
jvanverth28f9c602014-12-05 13:06:35 -0800941 }
jvanverth1334c212014-12-18 05:44:55 -0800942 fConfigTextureSupport[kAlpha_half_GrPixelConfig] = hasHalfFPTextures;
jvanverthfb5df432015-05-21 08:12:27 -0700943 fConfigTextureSupport[kRGBA_half_GrPixelConfig] = hasHalfFPTextures;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000944}
945
piotaixre4b23142014-10-02 10:57:53 -0700946bool GrGLCaps::doReadPixelsSupported(const GrGLInterface* intf,
947 GrGLenum format,
948 GrGLenum type) const {
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000949 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
950 // ES 2 guarantees this format is supported
robertphillips@google.comeca2dfb2012-06-27 20:13:49 +0000951 return true;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000952 }
953
954 if (!fTwoFormatLimit) {
955 // not limited by ES 2's constraints
956 return true;
957 }
958
bsalomon@google.com548a4332012-07-11 19:45:22 +0000959 GrGLint otherFormat = GR_GL_RGBA;
960 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000961
962 // The other supported format/type combo supported for ReadPixels
963 // can change based on which render target is bound
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000964 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000965 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
966 &otherFormat);
967
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000968 GR_GL_GetIntegerv(intf,
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000969 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
970 &otherType);
971
bsalomon@google.com548a4332012-07-11 19:45:22 +0000972 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000973}
974
piotaixre4b23142014-10-02 10:57:53 -0700975bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
976 GrGLenum format,
977 GrGLenum type,
978 GrGLenum currFboFormat) const {
mtklein2aa1f7e2015-02-20 12:35:32 -0800979 ReadPixelsSupportedFormat key = {format, type, currFboFormat};
980 if (const bool* supported = fReadPixelsSupportedCache.find(key)) {
981 return *supported;
piotaixre4b23142014-10-02 10:57:53 -0700982 }
mtklein2aa1f7e2015-02-20 12:35:32 -0800983 bool supported = this->doReadPixelsSupported(intf, format, type);
984 fReadPixelsSupportedCache.set(key, supported);
985 return supported;
piotaixre4b23142014-10-02 10:57:53 -0700986}
987
robertphillips@google.com6177e692013-02-28 20:16:25 +0000988void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000989
990 fMSFBOType = kNone_MSFBOType;
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +0000991 if (kGL_GrGLStandard != ctxInfo.standard()) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +0000992 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
993 // ES3 driver bugs on at least one device with a tiled GPU (N10).
994 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
995 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
996 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
997 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
cdalton63f6c1f2015-11-06 07:09:43 -0800998 } else if (fMixedSamplesSupport && fShaderCaps->pathRenderingSupport()) {
vbuzinovdded6962015-06-12 08:59:45 -0700999 fMSFBOType = kMixedSamples_MSFBOType;
commit-bot@chromium.org92b78842014-01-16 20:49:46 +00001000 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001001 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
1002 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
1003 // chrome's extension is equivalent to the EXT msaa
1004 // and fbo_blit extensions.
1005 fMSFBOType = kDesktop_EXT_MSFBOType;
1006 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
1007 fMSFBOType = kES_Apple_MSFBOType;
1008 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001009 } else {
cdalton63f6c1f2015-11-06 07:09:43 -08001010 if (fMixedSamplesSupport && fShaderCaps->pathRenderingSupport()) {
vbuzinovdded6962015-06-12 08:59:45 -07001011 fMSFBOType = kMixedSamples_MSFBOType;
1012 } else if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001013 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001014 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001015 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
1016 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
bsalomon@google.com347c3822013-05-01 20:10:01 +00001017 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001018 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001019 }
1020}
1021
cdalton1dd05422015-06-12 09:01:18 -07001022void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
1023 GrGLSLCaps* glslCaps = static_cast<GrGLSLCaps*>(fShaderCaps.get());
1024
1025 // Disabling advanced blend on various platforms with major known issues. We also block Chrome
1026 // for now until its own blacklists can be updated.
1027 if (kAdreno4xx_GrGLRenderer == ctxInfo.renderer() ||
1028 kIntel_GrGLDriver == ctxInfo.driver() ||
joel.liang9764c402015-07-09 19:46:18 -07001029 kChromium_GrGLDriver == ctxInfo.driver()) {
cdalton1dd05422015-06-12 09:01:18 -07001030 return;
1031 }
1032
1033 if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
1034 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1035 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1036 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent")) {
1037 fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
1038 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1039 } else if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
1040 ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337,00)) {
1041 // Non-coherent advanced blend has an issue on NVIDIA pre 337.00.
1042 return;
1043 } else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
1044 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1045 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kAutomatic_AdvBlendEqInteraction;
1046 } else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced")) {
1047 fBlendEquationSupport = kAdvanced_BlendEquationSupport;
1048 glslCaps->fAdvBlendEqInteraction = GrGLSLCaps::kGeneralEnable_AdvBlendEqInteraction;
1049 // TODO: Use kSpecificEnables_AdvBlendEqInteraction if "blend_support_all_equations" is
1050 // slow on a particular platform.
1051 } else {
1052 return; // No advanced blend support.
1053 }
1054
1055 SkASSERT(this->advancedBlendEquationSupport());
1056
1057 if (kNVIDIA_GrGLDriver == ctxInfo.driver()) {
1058 // Blacklist color-dodge and color-burn on NVIDIA until the fix is released.
1059 fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
1060 (1 << kColorBurn_GrBlendEquation);
1061 }
joel.liang9764c402015-07-09 19:46:18 -07001062 if (kARM_GrGLVendor == ctxInfo.vendor()) {
1063 // Blacklist color-burn on ARM until the fix is released.
1064 fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
1065 }
cdalton1dd05422015-06-12 09:01:18 -07001066}
1067
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001068namespace {
egdaniel8dc7c3a2015-04-16 11:22:42 -07001069const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001070}
1071
1072void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
1073
1074 // Build up list of legal stencil formats (though perhaps not supported on
1075 // the particular gpu/driver) from most preferred to least.
1076
1077 // these consts are in order of most preferred to least preferred
1078 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
1079
1080 static const StencilFormat
1081 // internal Format stencil bits total bits packed?
1082 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
1083 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
1084 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
1085 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
caryclark@google.comcf6285b2012-06-06 12:09:01 +00001086 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001087 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
1088
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +00001089 if (kGL_GrGLStandard == ctxInfo.standard()) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001090 bool supportsPackedDS =
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001091 ctxInfo.version() >= GR_GL_VER(3,0) ||
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001092 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
1093 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
1094
1095 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
1096 // require FBO support we can expect these are legal formats and don't
1097 // check. These also all support the unsized GL_STENCIL_INDEX.
1098 fStencilFormats.push_back() = gS8;
1099 fStencilFormats.push_back() = gS16;
1100 if (supportsPackedDS) {
1101 fStencilFormats.push_back() = gD24S8;
1102 }
1103 fStencilFormats.push_back() = gS4;
1104 if (supportsPackedDS) {
1105 fStencilFormats.push_back() = gDS;
1106 }
1107 } else {
1108 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
1109 // for other formats.
1110 // ES doesn't support using the unsized format.
1111
1112 fStencilFormats.push_back() = gS8;
1113 //fStencilFormats.push_back() = gS16;
commit-bot@chromium.org04c500f2013-09-06 15:28:01 +00001114 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
1115 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001116 fStencilFormats.push_back() = gD24S8;
1117 }
1118 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
1119 fStencilFormats.push_back() = gS4;
1120 }
1121 }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001122}
1123
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001124SkString GrGLCaps::dump() const {
bsalomon@google.combcce8922013-03-25 15:38:39 +00001125
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001126 SkString r = INHERITED::dump();
bsalomon@google.combcce8922013-03-25 15:38:39 +00001127
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001128 r.appendf("--- GL-Specific ---\n");
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001129 for (int i = 0; i < fStencilFormats.count(); ++i) {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001130 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001131 i,
1132 fStencilFormats[i].fStencilBits,
1133 fStencilFormats[i].fTotalBits);
1134 }
1135
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001136 static const char* kMSFBOExtStr[] = {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001137 "None",
1138 "ARB",
1139 "EXT",
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001140 "ES 3.0",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001141 "Apple",
bsalomon@google.com347c3822013-05-01 20:10:01 +00001142 "IMG MS To Texture",
1143 "EXT MS To Texture",
vbuzinovdded6962015-06-12 08:59:45 -07001144 "MixedSamples",
bsalomon@google.comf7fa8062012-02-14 14:09:57 +00001145 };
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001146 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
1147 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
1148 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +00001149 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
1150 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
1151 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
1152 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
vbuzinovdded6962015-06-12 08:59:45 -07001153 GR_STATIC_ASSERT(7 == kMixedSamples_MSFBOType);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +00001154 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001155
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001156 static const char* kInvalidateFBTypeStr[] = {
1157 "None",
1158 "Discard",
1159 "Invalidate",
1160 };
1161 GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
1162 GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
1163 GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
1164 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
bsalomon@google.com6b0cf022013-05-03 13:35:14 +00001165
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001166 static const char* kMapBufferTypeStr[] = {
1167 "None",
1168 "MapBuffer",
1169 "MapBufferRange",
1170 "Chromium",
1171 };
1172 GR_STATIC_ASSERT(0 == kNone_MapBufferType);
1173 GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
1174 GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
1175 GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
1176 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
1177
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001178 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001179 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +00001180 r.appendf("Invalidate FB Type: %s\n", kInvalidateFBTypeStr[fInvalidateFBType]);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001181 r.appendf("Map Buffer Type: %s\n", kMapBufferTypeStr[fMapBufferType]);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001182 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
1183 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001184 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
1185 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001186 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001187 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
1188 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
1189 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
1190 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001191
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001192 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
1193 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
1194 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
1195 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
1196 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001197 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
cdalton626e1ff2015-06-12 13:56:46 -07001198 r.appendf("Instanced drawing support: %s\n", (fInstancedDrawingSupport ? "YES": "NO"));
1199 r.appendf("Direct state access support: %s\n", (fDirectStateAccessSupport ? "YES": "NO"));
1200 r.appendf("Debug support: %s\n", (fDebugSupport ? "YES": "NO"));
cdaltond4727922015-11-10 12:49:06 -08001201 r.appendf("Multisample disable support: %s\n", (fMultisampleDisableSupport ? "YES" : "NO"));
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001202 r.appendf("Use non-VBO for dynamic data: %s\n",
bsalomon@google.combcce8922013-03-25 15:38:39 +00001203 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
bsalomon16921ec2015-07-30 15:34:56 -07001204 r.appendf("SRGB write contol: %s\n", (fSRGBWriteControl ? "YES" : "NO"));
robertphillips63926682015-08-20 09:39:02 -07001205 r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
1206 r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
joshualitt7bdd70a2015-10-01 06:28:11 -07001207 r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
jvanverthe9c0fc62015-04-29 11:18:05 -07001208 return r;
1209}
1210
jvanverthe9c0fc62015-04-29 11:18:05 -07001211static GrGLenum precision_to_gl_float_type(GrSLPrecision p) {
1212 switch (p) {
1213 case kLow_GrSLPrecision:
1214 return GR_GL_LOW_FLOAT;
1215 case kMedium_GrSLPrecision:
1216 return GR_GL_MEDIUM_FLOAT;
1217 case kHigh_GrSLPrecision:
1218 return GR_GL_HIGH_FLOAT;
1219 }
1220 SkFAIL("Unknown precision.");
1221 return -1;
1222}
1223
1224static GrGLenum shader_type_to_gl_shader(GrShaderType type) {
1225 switch (type) {
1226 case kVertex_GrShaderType:
1227 return GR_GL_VERTEX_SHADER;
1228 case kGeometry_GrShaderType:
1229 return GR_GL_GEOMETRY_SHADER;
1230 case kFragment_GrShaderType:
1231 return GR_GL_FRAGMENT_SHADER;
1232 }
1233 SkFAIL("Unknown shader type.");
1234 return -1;
1235}
1236
jvanverthcba99b82015-06-24 06:59:57 -07001237void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
1238 const GrGLInterface* intf,
1239 GrGLSLCaps* glslCaps) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001240 if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) ||
1241 ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
1242 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1243 if (kGeometry_GrShaderType != s) {
1244 GrShaderType shaderType = static_cast<GrShaderType>(s);
1245 GrGLenum glShader = shader_type_to_gl_shader(shaderType);
halcanary96fcdcc2015-08-27 07:41:13 -07001246 GrShaderCaps::PrecisionInfo* first = nullptr;
jvanverthcba99b82015-06-24 06:59:57 -07001247 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001248 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
1249 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
1250 GrGLenum glPrecision = precision_to_gl_float_type(precision);
1251 GrGLint range[2];
1252 GrGLint bits;
1253 GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits);
1254 if (bits) {
jvanverthcba99b82015-06-24 06:59:57 -07001255 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0];
1256 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1];
1257 glslCaps->fFloatPrecisions[s][p].fBits = bits;
jvanverthe9c0fc62015-04-29 11:18:05 -07001258 if (!first) {
jvanverthcba99b82015-06-24 06:59:57 -07001259 first = &glslCaps->fFloatPrecisions[s][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001260 }
jvanverthcba99b82015-06-24 06:59:57 -07001261 else if (!glslCaps->fShaderPrecisionVaries) {
1262 glslCaps->fShaderPrecisionVaries =
1263 (*first != glslCaps->fFloatPrecisions[s][p]);
jvanverthe9c0fc62015-04-29 11:18:05 -07001264 }
1265 }
1266 }
1267 }
1268 }
1269 }
1270 else {
1271 // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float.
jvanverthcba99b82015-06-24 06:59:57 -07001272 glslCaps->fShaderPrecisionVaries = false;
jvanverthe9c0fc62015-04-29 11:18:05 -07001273 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1274 if (kGeometry_GrShaderType != s) {
1275 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001276 glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127;
1277 glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127;
1278 glslCaps->fFloatPrecisions[s][p].fBits = 23;
jvanverthe9c0fc62015-04-29 11:18:05 -07001279 }
1280 }
1281 }
1282 }
1283 // GetShaderPrecisionFormat doesn't accept GL_GEOMETRY_SHADER as a shader type. Assume they're
1284 // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for
1285 // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that
1286 // are recommended against.
jvanverthcba99b82015-06-24 06:59:57 -07001287 if (glslCaps->fGeometryShaderSupport) {
jvanverthe9c0fc62015-04-29 11:18:05 -07001288 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
jvanverthcba99b82015-06-24 06:59:57 -07001289 glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] =
1290 glslCaps->fFloatPrecisions[kVertex_GrShaderType][p];
jvanverthe9c0fc62015-04-29 11:18:05 -07001291 }
1292 }
1293}
1294
egdanielb7e7d572015-11-04 04:23:53 -08001295void GrGLCaps::initConfigSwizzleTable(const GrGLContextInfo& ctxInfo, GrGLSLCaps* glslCaps) {
1296 GrGLStandard standard = ctxInfo.standard();
1297 GrGLVersion version = ctxInfo.version();
jvanverthe9c0fc62015-04-29 11:18:05 -07001298
egdanielb7e7d572015-11-04 04:23:53 -08001299 glslCaps->fMustSwizzleInShader = true;
1300 if (kGL_GrGLStandard == standard) {
1301 if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
1302 glslCaps->fMustSwizzleInShader = false;
1303 }
1304 } else {
1305 if (version >= GR_GL_VER(3,0)) {
1306 glslCaps->fMustSwizzleInShader = false;
1307 }
1308 }
1309
1310 glslCaps->fConfigSwizzle[kUnknown_GrPixelConfig] = nullptr;
1311 if (fTextureRedSupport) {
1312 glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "rrrr";
1313 glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "rrrr";
1314 } else {
1315 glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "aaaa";
1316 glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "aaaa";
1317 }
1318 glslCaps->fConfigSwizzle[kIndex_8_GrPixelConfig] = "rgba";
1319 glslCaps->fConfigSwizzle[kRGB_565_GrPixelConfig] = "rgba";
1320 glslCaps->fConfigSwizzle[kRGBA_4444_GrPixelConfig] = "rgba";
1321 glslCaps->fConfigSwizzle[kRGBA_8888_GrPixelConfig] = "rgba";
1322 glslCaps->fConfigSwizzle[kBGRA_8888_GrPixelConfig] = "rgba";
1323 glslCaps->fConfigSwizzle[kSRGBA_8888_GrPixelConfig] = "rgba";
1324 glslCaps->fConfigSwizzle[kETC1_GrPixelConfig] = "rgba";
1325 glslCaps->fConfigSwizzle[kLATC_GrPixelConfig] = "rrrr";
1326 glslCaps->fConfigSwizzle[kR11_EAC_GrPixelConfig] = "rrrr";
1327 glslCaps->fConfigSwizzle[kASTC_12x12_GrPixelConfig] = "rgba";
1328 glslCaps->fConfigSwizzle[kRGBA_float_GrPixelConfig] = "rgba";
1329 glslCaps->fConfigSwizzle[kRGBA_half_GrPixelConfig] = "rgba";
1330
1331}
1332
1333void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}
jvanverthe9c0fc62015-04-29 11:18:05 -07001334
1335