blob: 0622e68edcb2409e4ff9cc6636d03487855bdc35 [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#ifndef GrGLCaps_DEFINED
10#define GrGLCaps_DEFINED
11
bsalomoneb1cb5c2015-05-22 08:01:09 -070012#include "GrCaps.h"
jvanverthcba99b82015-06-24 06:59:57 -070013#include "glsl/GrGLSL.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070014#include "GrGLStencilAttachment.h"
piotaixre4b23142014-10-02 10:57:53 -070015#include "SkChecksum.h"
mtklein2aa1f7e2015-02-20 12:35:32 -080016#include "SkTHash.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000017#include "SkTArray.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000018
19class GrGLContextInfo;
jvanverthe9c0fc62015-04-29 11:18:05 -070020class GrGLSLCaps;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000021
22/**
23 * Stores some capabilities of a GL context. Most are determined by the GL
24 * version and the extensions string. It also tracks formats that have passed
25 * the FBO completeness test.
26 */
bsalomon4b91f762015-05-19 09:29:46 -070027class GrGLCaps : public GrCaps {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000028public:
egdaniel8dc7c3a2015-04-16 11:22:42 -070029 typedef GrGLStencilAttachment::Format StencilFormat;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000030
31 /**
32 * The type of MSAA for FBOs supported. Different extensions have different
33 * semantics of how / when a resolve is performed.
34 */
35 enum MSFBOType {
36 /**
37 * no support for MSAA FBOs
38 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000039 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000040 /**
skia.committer@gmail.com6fc1b492013-09-06 07:01:45 +000041 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000042 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000043 kDesktop_ARB_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000044 /**
45 * earlier GL_EXT_framebuffer* extensions
46 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000047 kDesktop_EXT_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000048 /**
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000049 * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
50 */
51 kES_3_0_MSFBOType,
52 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000053 * GL_APPLE_framebuffer_multisample ES extension
54 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000055 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000056 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000057 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
58 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
59 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
60 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000061 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000062 kES_IMG_MsToTexture_MSFBOType,
63 /**
64 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
65 * GL_MAX_SAMPLES value.
66 */
67 kES_EXT_MsToTexture_MSFBOType,
vbuzinovdded6962015-06-12 08:59:45 -070068 /**
69 * GL_NV_framebuffer_mixed_samples.
70 */
71 kMixedSamples_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000072
vbuzinovdded6962015-06-12 08:59:45 -070073 kLast_MSFBOType = kMixedSamples_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000074 };
75
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000076 enum InvalidateFBType {
77 kNone_InvalidateFBType,
78 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
79 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
80
81 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000082 };
83
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000084 enum MapBufferType {
85 kNone_MapBufferType,
86 kMapBuffer_MapBufferType, // glMapBuffer()
87 kMapBufferRange_MapBufferType, // glMapBufferRange()
88 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
89
90 kLast_MapBufferType = kChromium_MapBufferType,
91 };
92
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000093 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000094 * Initializes the GrGLCaps to the set of features supported in the current
95 * OpenGL context accessible via ctxInfo.
96 */
bsalomon682c2692015-05-22 14:01:46 -070097 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
98 const GrGLInterface* glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000099
100 /**
101 * Call to note that a color config has been verified as a valid color
102 * attachment. This may save future calls to glCheckFramebufferStatus
103 * using isConfigVerifiedColorAttachment().
104 */
105 void markConfigAsValidColorAttachment(GrPixelConfig config) {
106 fVerifiedColorConfigs.markVerified(config);
107 }
108
109 /**
110 * Call to check whether a config has been verified as a valid color
111 * attachment.
112 */
113 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
114 return fVerifiedColorConfigs.isVerified(config);
115 }
116
117 /**
118 * Call to note that a color config / stencil format pair passed
119 * FBO status check. We may skip calling glCheckFramebufferStatus for
120 * this combination in the future using
121 * isColorConfigAndStencilFormatVerified().
122 */
123 void markColorConfigAndStencilFormatAsVerified(
124 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700125 const GrGLStencilAttachment::Format& format);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000126
127 /**
128 * Call to check whether color config / stencil format pair has already
129 * passed FBO status check.
130 */
131 bool isColorConfigAndStencilFormatVerified(
132 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700133 const GrGLStencilAttachment::Format& format) const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000134
135 /**
136 * Reports the type of MSAA FBO support.
137 */
138 MSFBOType msFBOType() const { return fMSFBOType; }
139
140 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000141 * Does the supported MSAA FBO extension have MSAA renderbuffers?
142 */
143 bool usesMSAARenderBuffers() const {
144 return kNone_MSFBOType != fMSFBOType &&
145 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
vbuzinovdded6962015-06-12 08:59:45 -0700146 kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
147 kMixedSamples_MSFBOType != fMSFBOType;
bsalomon@google.com347c3822013-05-01 20:10:01 +0000148 }
149
150 /**
151 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
152 * then implicitly resolved when read.
153 */
154 bool usesImplicitMSAAResolve() const {
155 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
156 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
157 }
158
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000159 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
160
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000161 /// What type of buffer mapping is supported?
162 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000163
164 /**
165 * Gets an array of legal stencil formats. These formats are not guaranteed
166 * to be supported by the driver but are legal GLenum names given the GL
167 * version and extensions supported.
168 */
169 const SkTArray<StencilFormat, true>& stencilFormats() const {
170 return fStencilFormats;
171 }
172
173 /// The maximum number of fragment uniform vectors (GLES has min. 16).
174 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
175
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000176 /// maximum number of attribute values per vertex
bsalomon@google.com60da4172012-06-01 19:25:00 +0000177 int maxVertexAttributes() const { return fMaxVertexAttributes; }
178
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000179 /// maximum number of texture units accessible in the fragment shader.
180 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
181
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000182 /// ES requires an extension to support RGBA8 in RenderBufferStorage
183 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
184
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000185 /**
186 * Depending on the ES extensions present the BGRA external format may
187 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
188 * RGBA.
189 */
190 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
191
192 /// GL_ARB_texture_swizzle support
193 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
194
195 /// Is there support for GL_UNPACK_ROW_LENGTH
196 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
197
198 /// Is there support for GL_UNPACK_FLIP_Y
199 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
200
201 /// Is there support for GL_PACK_ROW_LENGTH
202 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
203
204 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
205 bool packFlipYSupport() const { return fPackFlipYSupport; }
206
207 /// Is there support for texture parameter GL_TEXTURE_USAGE
208 bool textureUsageSupport() const { return fTextureUsageSupport; }
209
210 /// Is there support for glTexStorage
211 bool texStorageSupport() const { return fTexStorageSupport; }
212
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000213 /// Is there support for GL_RED and GL_R8
214 bool textureRedSupport() const { return fTextureRedSupport; }
215
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000216 /// Is GL_ARB_IMAGING supported
217 bool imagingSupport() const { return fImagingSupport; }
218
bsalomon@google.com706f6682012-10-23 14:53:55 +0000219 /// Is GL_ARB_fragment_coord_conventions supported?
220 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
221
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000222 /// Is there support for Vertex Array Objects?
223 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
224
cdalton626e1ff2015-06-12 13:56:46 -0700225 /// Is there support for glDraw*Instanced and glVertexAttribDivisor?
226 bool instancedDrawingSupport() const { return fInstancedDrawingSupport; }
227
228 /// Is there support for GL_EXT_direct_state_access?
229 bool directStateAccessSupport() const { return fDirectStateAccessSupport; }
230
231 /// Is there support for GL_KHR_debug?
232 bool debugSupport() const { return fDebugSupport; }
233
jvanverth3f801cb2014-12-16 09:49:38 -0800234 /// Is there support for ES2 compatability?
235 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
236
cdalton0edea2c2015-05-21 08:27:44 -0700237 /// Can we call glDisable(GL_MULTISAMPLE)?
vbuzinovdded6962015-06-12 08:59:45 -0700238 bool multisampleDisableSupport() const {
239 return fMultisampleDisableSupport;
240 }
cdalton0edea2c2015-05-21 08:27:44 -0700241
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000242 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000243 bool useNonVBOVertexAndIndexDynamicData() const {
244 return fUseNonVBOVertexAndIndexDynamicData;
245 }
246
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000247 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000248 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000249 GrGLenum format,
piotaixre4b23142014-10-02 10:57:53 -0700250 GrGLenum type,
251 GrGLenum currFboFormat) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000252
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000253 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000254
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000255 bool fullClearIsFree() const { return fFullClearIsFree; }
256
joshualittc1f56b52015-06-22 12:31:31 -0700257 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
258
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000259 /**
bsalomon16921ec2015-07-30 15:34:56 -0700260 * Is there support for enabling/disabling sRGB writes for sRGB-capable color attachments?
261 * If false this does not mean sRGB is not supported but rather that if it is supported
262 * it cannot be turned off for configs that support it.
263 */
264 bool srgbWriteControl() const { return fSRGBWriteControl; }
265
266 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000267 * Returns a string containing the caps info.
268 */
mtklein36352bf2015-03-25 18:17:31 -0700269 SkString dump() const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000270
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000271 /**
272 * LATC can appear under one of three possible names. In order to know
273 * which GL internal format to use, we need to keep track of which name
274 * we found LATC under. The default is LATC.
275 */
276 enum LATCAlias {
277 kLATC_LATCAlias,
278 kRGTC_LATCAlias,
279 k3DC_LATCAlias
280 };
281
282 LATCAlias latcAlias() const { return fLATCAlias; }
283
jvanverthe9c0fc62015-04-29 11:18:05 -0700284 GrGLSLCaps* glslCaps() const { return reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get()); }
285
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000286private:
cdalton4cd67132015-06-10 19:23:46 -0700287 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
kkinnunencfe62e32015-07-01 02:58:50 -0700288 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
bsalomon424cc262015-05-22 10:37:30 -0700289
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000290 /**
291 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
292 * performing glCheckFrameBufferStatus for the same config.
293 */
294 struct VerifiedColorConfigs {
295 VerifiedColorConfigs() {
296 this->reset();
297 }
298
299 void reset() {
300 for (int i = 0; i < kNumUints; ++i) {
301 fVerifiedColorConfigs[i] = 0;
302 }
303 }
304
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +0000305 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000306 uint32_t fVerifiedColorConfigs[kNumUints];
307
308 void markVerified(GrPixelConfig config) {
309#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
310 return;
311#endif
312 int u32Idx = config / 32;
313 int bitIdx = config % 32;
314 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
315 }
316
317 bool isVerified(GrPixelConfig config) const {
318#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
319 return false;
320#endif
321 int u32Idx = config / 32;
322 int bitIdx = config % 32;
323 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
324 }
325 };
326
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000327 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
cdalton1dd05422015-06-12 09:01:18 -0700328 void initBlendEqationSupport(const GrGLContextInfo&);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000329 void initStencilFormats(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000330 // This must be called after initFSAASupport().
bsalomon16921ec2015-07-30 15:34:56 -0700331 void initConfigRenderableTable(const GrGLContextInfo&, bool srgbSupport);
332 void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*, bool srgbSupport);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000333
bsalomon17168df2014-12-09 09:00:49 -0800334 bool doReadPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const;
piotaixre4b23142014-10-02 10:57:53 -0700335
jvanverthcba99b82015-06-24 06:59:57 -0700336 void initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
337 const GrGLInterface* intf,
338 GrGLSLCaps* glslCaps);
339
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000340 // tracks configs that have been verified to pass the FBO completeness when
341 // used as a color attachment
342 VerifiedColorConfigs fVerifiedColorConfigs;
343
344 SkTArray<StencilFormat, true> fStencilFormats;
345 // tracks configs that have been verified to pass the FBO completeness when
346 // used as a color attachment when a particular stencil format is used
347 // as a stencil attachment.
348 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
349
350 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000351 int fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000352 int fMaxFragmentTextureUnits;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000353
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000354 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000355 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000356 MapBufferType fMapBufferType;
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000357 LATCAlias fLATCAlias;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000358
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000359 bool fRGBA8RenderbufferSupport : 1;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000360 bool fBGRAIsInternalFormat : 1;
361 bool fTextureSwizzleSupport : 1;
362 bool fUnpackRowLengthSupport : 1;
363 bool fUnpackFlipYSupport : 1;
364 bool fPackRowLengthSupport : 1;
365 bool fPackFlipYSupport : 1;
366 bool fTextureUsageSupport : 1;
367 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000368 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000369 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000370 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000371 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000372 bool fVertexArrayObjectSupport : 1;
cdalton626e1ff2015-06-12 13:56:46 -0700373 bool fInstancedDrawingSupport : 1;
374 bool fDirectStateAccessSupport : 1;
375 bool fDebugSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800376 bool fES2CompatibilitySupport : 1;
cdalton0edea2c2015-05-21 08:27:44 -0700377 bool fMultisampleDisableSupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000378 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000379 bool fIsCoreProfile : 1;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000380 bool fFullClearIsFree : 1;
joshualittc1f56b52015-06-22 12:31:31 -0700381 bool fBindFragDataLocationSupport : 1;
bsalomon16921ec2015-07-30 15:34:56 -0700382 bool fSRGBWriteControl : 1;
joshualitt58162332014-08-01 06:44:53 -0700383
mtklein2aa1f7e2015-02-20 12:35:32 -0800384 struct ReadPixelsSupportedFormat {
385 GrGLenum fFormat;
386 GrGLenum fType;
387 GrGLenum fFboFormat;
piotaixre4b23142014-10-02 10:57:53 -0700388
mtklein2aa1f7e2015-02-20 12:35:32 -0800389 bool operator==(const ReadPixelsSupportedFormat& rhs) const {
390 return fFormat == rhs.fFormat
391 && fType == rhs.fType
392 && fFboFormat == rhs.fFboFormat;
piotaixre4b23142014-10-02 10:57:53 -0700393 }
piotaixre4b23142014-10-02 10:57:53 -0700394 };
mtklein02f46cf2015-03-20 13:48:42 -0700395 mutable SkTHashMap<ReadPixelsSupportedFormat, bool> fReadPixelsSupportedCache;
piotaixre4b23142014-10-02 10:57:53 -0700396
bsalomon4b91f762015-05-19 09:29:46 -0700397 typedef GrCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000398};
399
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000400#endif