blob: 13ba3863b1228efc806a0da20e7c0f0fee30604b [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
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000012#include "GrDrawTargetCaps.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070013#include "GrGLStencilAttachment.h"
piotaixre4b23142014-10-02 10:57:53 -070014#include "SkChecksum.h"
mtklein2aa1f7e2015-02-20 12:35:32 -080015#include "SkTHash.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000016#include "SkTArray.h"
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000017
18class GrGLContextInfo;
jvanverthe9c0fc62015-04-29 11:18:05 -070019class GrGLSLCaps;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000020
21/**
22 * Stores some capabilities of a GL context. Most are determined by the GL
23 * version and the extensions string. It also tracks formats that have passed
24 * the FBO completeness test.
25 */
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000026class GrGLCaps : public GrDrawTargetCaps {
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000027public:
bsalomon@google.combcce8922013-03-25 15:38:39 +000028 SK_DECLARE_INST_COUNT(GrGLCaps)
29
egdaniel8dc7c3a2015-04-16 11:22:42 -070030 typedef GrGLStencilAttachment::Format StencilFormat;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000031
32 /**
33 * The type of MSAA for FBOs supported. Different extensions have different
34 * semantics of how / when a resolve is performed.
35 */
36 enum MSFBOType {
37 /**
38 * no support for MSAA FBOs
39 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +000040 kNone_MSFBOType = 0,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000041 /**
skia.committer@gmail.com6fc1b492013-09-06 07:01:45 +000042 * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000043 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000044 kDesktop_ARB_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000045 /**
46 * earlier GL_EXT_framebuffer* extensions
47 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000048 kDesktop_EXT_MSFBOType,
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000049 /**
commit-bot@chromium.orga8e5a062013-09-05 23:44:09 +000050 * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
51 */
52 kES_3_0_MSFBOType,
53 /**
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000054 * GL_APPLE_framebuffer_multisample ES extension
55 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000056 kES_Apple_MSFBOType,
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000057 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +000058 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
59 * Instead the texture is multisampled when bound to the FBO and then resolved automatically
60 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
61 * GR_GL_MAX_SAMPLES_IMG).
bsalomon@google.comf3a60c02013-03-19 19:06:09 +000062 */
bsalomon@google.com347c3822013-05-01 20:10:01 +000063 kES_IMG_MsToTexture_MSFBOType,
64 /**
65 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
66 * GL_MAX_SAMPLES value.
67 */
68 kES_EXT_MsToTexture_MSFBOType,
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000069
skia.committer@gmail.comecc9d282013-05-04 07:01:15 +000070 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType
bsalomon@google.com6b0cf022013-05-03 13:35:14 +000071 };
72
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +000073 enum InvalidateFBType {
74 kNone_InvalidateFBType,
75 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer()
76 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer()
77
78 kLast_InvalidateFBType = kInvalidate_InvalidateFBType
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000079 };
80
commit-bot@chromium.org160b4782014-05-05 12:32:37 +000081 enum MapBufferType {
82 kNone_MapBufferType,
83 kMapBuffer_MapBufferType, // glMapBuffer()
84 kMapBufferRange_MapBufferType, // glMapBufferRange()
85 kChromium_MapBufferType, // GL_CHROMIUM_map_sub
86
87 kLast_MapBufferType = kChromium_MapBufferType,
88 };
89
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000090 /**
91 * Creates a GrGLCaps that advertises no support for any extensions,
92 * formats, etc. Call init to initialize from a GrGLContextInfo.
93 */
94 GrGLCaps();
95
96 GrGLCaps(const GrGLCaps& caps);
97
98 GrGLCaps& operator = (const GrGLCaps& caps);
99
100 /**
101 * Resets the caps such that nothing is supported.
102 */
mtklein36352bf2015-03-25 18:17:31 -0700103 void reset() override;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000104
105 /**
106 * Initializes the GrGLCaps to the set of features supported in the current
107 * OpenGL context accessible via ctxInfo.
108 */
george7c4c63a2014-06-25 12:14:30 -0700109 bool init(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000110
111 /**
112 * Call to note that a color config has been verified as a valid color
113 * attachment. This may save future calls to glCheckFramebufferStatus
114 * using isConfigVerifiedColorAttachment().
115 */
116 void markConfigAsValidColorAttachment(GrPixelConfig config) {
117 fVerifiedColorConfigs.markVerified(config);
118 }
119
120 /**
121 * Call to check whether a config has been verified as a valid color
122 * attachment.
123 */
124 bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
125 return fVerifiedColorConfigs.isVerified(config);
126 }
127
128 /**
129 * Call to note that a color config / stencil format pair passed
130 * FBO status check. We may skip calling glCheckFramebufferStatus for
131 * this combination in the future using
132 * isColorConfigAndStencilFormatVerified().
133 */
134 void markColorConfigAndStencilFormatAsVerified(
135 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700136 const GrGLStencilAttachment::Format& format);
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000137
138 /**
139 * Call to check whether color config / stencil format pair has already
140 * passed FBO status check.
141 */
142 bool isColorConfigAndStencilFormatVerified(
143 GrPixelConfig config,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700144 const GrGLStencilAttachment::Format& format) const;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000145
146 /**
147 * Reports the type of MSAA FBO support.
148 */
149 MSFBOType msFBOType() const { return fMSFBOType; }
150
151 /**
bsalomon@google.com347c3822013-05-01 20:10:01 +0000152 * Does the supported MSAA FBO extension have MSAA renderbuffers?
153 */
154 bool usesMSAARenderBuffers() const {
155 return kNone_MSFBOType != fMSFBOType &&
156 kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
157 kES_EXT_MsToTexture_MSFBOType != fMSFBOType;
158 }
159
160 /**
161 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
162 * then implicitly resolved when read.
163 */
164 bool usesImplicitMSAAResolve() const {
165 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
166 kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
167 }
168
vbuzinov08b4d292015-04-01 06:29:49 -0700169 bool fbMixedSamplesSupport() const { return fFBMixedSamplesSupport; }
170
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000171 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
172
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000173 /// What type of buffer mapping is supported?
174 MapBufferType mapBufferType() const { return fMapBufferType; }
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000175
176 /**
177 * Gets an array of legal stencil formats. These formats are not guaranteed
178 * to be supported by the driver but are legal GLenum names given the GL
179 * version and extensions supported.
180 */
181 const SkTArray<StencilFormat, true>& stencilFormats() const {
182 return fStencilFormats;
183 }
184
185 /// The maximum number of fragment uniform vectors (GLES has min. 16).
186 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
187
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000188 /// maximum number of attribute values per vertex
bsalomon@google.com60da4172012-06-01 19:25:00 +0000189 int maxVertexAttributes() const { return fMaxVertexAttributes; }
190
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000191 /// maximum number of texture units accessible in the fragment shader.
192 int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
193
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000194 /// ES requires an extension to support RGBA8 in RenderBufferStorage
195 bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
196
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000197 /**
198 * Depending on the ES extensions present the BGRA external format may
199 * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
200 * RGBA.
201 */
202 bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
203
204 /// GL_ARB_texture_swizzle support
205 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; }
206
207 /// Is there support for GL_UNPACK_ROW_LENGTH
208 bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
209
210 /// Is there support for GL_UNPACK_FLIP_Y
211 bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
212
213 /// Is there support for GL_PACK_ROW_LENGTH
214 bool packRowLengthSupport() const { return fPackRowLengthSupport; }
215
216 /// Is there support for GL_PACK_REVERSE_ROW_ORDER
217 bool packFlipYSupport() const { return fPackFlipYSupport; }
218
219 /// Is there support for texture parameter GL_TEXTURE_USAGE
220 bool textureUsageSupport() const { return fTextureUsageSupport; }
221
222 /// Is there support for glTexStorage
223 bool texStorageSupport() const { return fTexStorageSupport; }
224
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000225 /// Is there support for GL_RED and GL_R8
226 bool textureRedSupport() const { return fTextureRedSupport; }
227
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000228 /// Is GL_ARB_IMAGING supported
229 bool imagingSupport() const { return fImagingSupport; }
230
bsalomon@google.com706f6682012-10-23 14:53:55 +0000231 /// Is GL_ARB_fragment_coord_conventions supported?
232 bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
233
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000234 /// Is there support for Vertex Array Objects?
235 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
236
jvanverth3f801cb2014-12-16 09:49:38 -0800237 /// Is there support for ES2 compatability?
238 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
239
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000240 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bsalomon@google.com96966a52013-02-21 16:34:21 +0000241 bool useNonVBOVertexAndIndexDynamicData() const {
242 return fUseNonVBOVertexAndIndexDynamicData;
243 }
244
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000245 /// Does ReadPixels support the provided format/type combo?
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000246 bool readPixelsSupported(const GrGLInterface* intf,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000247 GrGLenum format,
piotaixre4b23142014-10-02 10:57:53 -0700248 GrGLenum type,
249 GrGLenum currFboFormat) const;
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000250
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000251 bool isCoreProfile() const { return fIsCoreProfile; }
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000252
commit-bot@chromium.org3628ad92013-08-30 19:43:47 +0000253
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000254 bool fullClearIsFree() const { return fFullClearIsFree; }
255
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000256 /**
257 * Returns a string containing the caps info.
258 */
mtklein36352bf2015-03-25 18:17:31 -0700259 SkString dump() const override;
commit-bot@chromium.orgbeb8b3a2014-04-15 15:37:51 +0000260
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000261 /**
262 * LATC can appear under one of three possible names. In order to know
263 * which GL internal format to use, we need to keep track of which name
264 * we found LATC under. The default is LATC.
265 */
266 enum LATCAlias {
267 kLATC_LATCAlias,
268 kRGTC_LATCAlias,
269 k3DC_LATCAlias
270 };
271
272 LATCAlias latcAlias() const { return fLATCAlias; }
273
jvanverthe9c0fc62015-04-29 11:18:05 -0700274 GrGLSLCaps* glslCaps() const { return reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get()); }
275
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000276private:
277 /**
278 * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
279 * performing glCheckFrameBufferStatus for the same config.
280 */
281 struct VerifiedColorConfigs {
282 VerifiedColorConfigs() {
283 this->reset();
284 }
285
286 void reset() {
287 for (int i = 0; i < kNumUints; ++i) {
288 fVerifiedColorConfigs[i] = 0;
289 }
290 }
291
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +0000292 static const int kNumUints = (kGrPixelConfigCnt + 31) / 32;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000293 uint32_t fVerifiedColorConfigs[kNumUints];
294
295 void markVerified(GrPixelConfig config) {
296#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
297 return;
298#endif
299 int u32Idx = config / 32;
300 int bitIdx = config % 32;
301 fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
302 }
303
304 bool isVerified(GrPixelConfig config) const {
305#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
306 return false;
307#endif
308 int u32Idx = config / 32;
309 int bitIdx = config % 32;
310 return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
311 }
312 };
313
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000314 void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
315 void initStencilFormats(const GrGLContextInfo&);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000316 // This must be called after initFSAASupport().
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000317 void initConfigRenderableTable(const GrGLContextInfo&);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000318 void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000319
bsalomon17168df2014-12-09 09:00:49 -0800320 bool doReadPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const;
piotaixre4b23142014-10-02 10:57:53 -0700321
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000322 // tracks configs that have been verified to pass the FBO completeness when
323 // used as a color attachment
324 VerifiedColorConfigs fVerifiedColorConfigs;
325
326 SkTArray<StencilFormat, true> fStencilFormats;
327 // tracks configs that have been verified to pass the FBO completeness when
328 // used as a color attachment when a particular stencil format is used
329 // as a stencil attachment.
330 SkTArray<VerifiedColorConfigs, true> fStencilVerifiedColorConfigs;
331
332 int fMaxFragmentUniformVectors;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000333 int fMaxVertexAttributes;
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000334 int fMaxFragmentTextureUnits;
bsalomon@google.com60da4172012-06-01 19:25:00 +0000335
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000336 MSFBOType fMSFBOType;
commit-bot@chromium.org52ffbf62014-04-02 16:19:33 +0000337 InvalidateFBType fInvalidateFBType;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000338 MapBufferType fMapBufferType;
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000339 LATCAlias fLATCAlias;
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000340
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000341 bool fRGBA8RenderbufferSupport : 1;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000342 bool fBGRAIsInternalFormat : 1;
343 bool fTextureSwizzleSupport : 1;
344 bool fUnpackRowLengthSupport : 1;
345 bool fUnpackFlipYSupport : 1;
346 bool fPackRowLengthSupport : 1;
347 bool fPackFlipYSupport : 1;
348 bool fTextureUsageSupport : 1;
349 bool fTexStorageSupport : 1;
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000350 bool fTextureRedSupport : 1;
bsalomon@google.come76b7cc2012-06-18 12:47:06 +0000351 bool fImagingSupport : 1;
robertphillips@google.com1d89c932012-06-27 19:31:41 +0000352 bool fTwoFormatLimit : 1;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000353 bool fFragCoordsConventionSupport : 1;
bsalomon@google.com07631cf2013-03-05 14:14:58 +0000354 bool fVertexArrayObjectSupport : 1;
jvanverth3f801cb2014-12-16 09:49:38 -0800355 bool fES2CompatibilitySupport : 1;
bsalomon@google.com96966a52013-02-21 16:34:21 +0000356 bool fUseNonVBOVertexAndIndexDynamicData : 1;
bsalomon@google.com2b1b8c02013-02-28 22:06:02 +0000357 bool fIsCoreProfile : 1;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000358 bool fFullClearIsFree : 1;
vbuzinov08b4d292015-04-01 06:29:49 -0700359 bool fFBMixedSamplesSupport : 1;
joshualitt58162332014-08-01 06:44:53 -0700360
mtklein2aa1f7e2015-02-20 12:35:32 -0800361 struct ReadPixelsSupportedFormat {
362 GrGLenum fFormat;
363 GrGLenum fType;
364 GrGLenum fFboFormat;
piotaixre4b23142014-10-02 10:57:53 -0700365
mtklein2aa1f7e2015-02-20 12:35:32 -0800366 bool operator==(const ReadPixelsSupportedFormat& rhs) const {
367 return fFormat == rhs.fFormat
368 && fType == rhs.fType
369 && fFboFormat == rhs.fFboFormat;
piotaixre4b23142014-10-02 10:57:53 -0700370 }
piotaixre4b23142014-10-02 10:57:53 -0700371 };
mtklein02f46cf2015-03-20 13:48:42 -0700372 mutable SkTHashMap<ReadPixelsSupportedFormat, bool> fReadPixelsSupportedCache;
piotaixre4b23142014-10-02 10:57:53 -0700373
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000374 typedef GrDrawTargetCaps INHERITED;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000375};
376
jvanverthe9c0fc62015-04-29 11:18:05 -0700377
378class GrGLSLCaps : public GrShaderCaps {
379public:
380 SK_DECLARE_INST_COUNT(GrGLSLCaps)
381
382 /**
383 * Creates a GrGLSLCaps that advertises no support for any extensions,
384 * formats, etc. Call init to initialize from a GrGLContextInfo.
385 */
386 GrGLSLCaps();
387 ~GrGLSLCaps() override {}
388
389 GrGLSLCaps(const GrGLSLCaps& caps);
390
391 GrGLSLCaps& operator = (const GrGLSLCaps& caps);
392
393 /**
394 * Resets the caps such that nothing is supported.
395 */
396 void reset() override;
397
398 /**
399 * Initializes the GrGLSLCaps to the set of features supported in the current
400 * OpenGL context accessible via ctxInfo.
401 */
402 bool init(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface);
403
404 /**
405 * Some helper functions for encapsulating various extensions to read FB Buffer on openglES
406 *
407 * TODO(joshualitt) On desktop opengl 4.2+ we can achieve something similar to this effect
408 */
409 bool fbFetchSupport() const { return fFBFetchSupport; }
410
411 bool fbFetchNeedsCustomOutput() const { return fFBFetchNeedsCustomOutput; }
412
413 const char* fbFetchColorName() const { return fFBFetchColorName; }
414
415 const char* fbFetchExtensionString() const { return fFBFetchExtensionString; }
416
417 bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; }
418
419 /**
420 * Returns a string containing the caps info.
421 */
422 SkString dump() const override;
423
424private:
425 // Must be called after fGeometryShaderSupport is initialized.
426 void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*);
427
428 bool fDropsTileOnZeroDivide : 1;
429 bool fFBFetchSupport : 1;
430 bool fFBFetchNeedsCustomOutput : 1;
431
432 const char* fFBFetchColorName;
433 const char* fFBFetchExtensionString;
434
435 typedef GrShaderCaps INHERITED;
436};
437
jvanverthcfc18862015-04-28 08:48:20 -0700438
bsalomon@google.comf7fa8062012-02-14 14:09:57 +0000439#endif