Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrCaps.h
1 
2 /*
3  * Copyright 2013 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 #ifndef GrCaps_DEFINED
9 #define GrCaps_DEFINED
10 
11 #include "GrTypes.h"
12 #include "GrTypesPriv.h"
13 #include "GrBlend.h"
14 #include "GrShaderVar.h"
15 #include "SkRefCnt.h"
16 #include "SkString.h"
17 
18 struct GrContextOptions;
19 
20 class GrShaderCaps : public SkRefCnt {
21 public:
25  struct PrecisionInfo {
26  PrecisionInfo() {
27  fLogRangeLow = 0;
28  fLogRangeHigh = 0;
29  fBits = 0;
30  }
31 
33  bool supported() const { return 0 != fBits; }
34 
35  bool operator==(const PrecisionInfo& that) const {
36  return fLogRangeLow == that.fLogRangeLow && fLogRangeHigh == that.fLogRangeHigh &&
37  fBits == that.fBits;
38  }
39  bool operator!=(const PrecisionInfo& that) const { return !(*this == that); }
40 
53  int fBits;
54  };
55 
56  GrShaderCaps();
57 
58  virtual SkString dump() const;
59 
60  bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
61  bool geometryShaderSupport() const { return fGeometryShaderSupport; }
62  bool pathRenderingSupport() const { return fPathRenderingSupport; }
63  bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
64  bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
65  bool integerSupport() const { return fIntegerSupport; }
66  bool texelBufferSupport() const { return fTexelBufferSupport; }
67 
74  const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
75  GrSLPrecision precision) const {
76  return fFloatPrecisions[shaderType][precision];
77  };
78 
84  bool floatPrecisionVaries() const { return fShaderPrecisionVaries; }
85 
90  int pixelLocalStorageSize() const { return fPixelLocalStorageSize; }
91 
96  bool plsPathRenderingSupport() const {
97 #if GR_ENABLE_PLS_PATH_RENDERING
98  return fPLSPathRenderingSupport;
99 #else
100  return false;
101 #endif
102  }
103 
104 protected:
107  void applyOptionsOverrides(const GrContextOptions& options);
108 
109  bool fShaderDerivativeSupport : 1;
110  bool fGeometryShaderSupport : 1;
111  bool fPathRenderingSupport : 1;
112  bool fDstReadInShaderSupport : 1;
113  bool fDualSourceBlendingSupport : 1;
114  bool fIntegerSupport : 1;
115  bool fTexelBufferSupport : 1;
116 
117  bool fShaderPrecisionVaries;
118  PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
119  int fPixelLocalStorageSize;
120  bool fPLSPathRenderingSupport;
121 
122 private:
123  virtual void onApplyOptionsOverrides(const GrContextOptions&) {};
124  typedef SkRefCnt INHERITED;
125 };
126 
130 class GrCaps : public SkRefCnt {
131 public:
132  GrCaps(const GrContextOptions&);
133 
134  virtual SkString dump() const;
135 
136  GrShaderCaps* shaderCaps() const { return fShaderCaps; }
137 
138  bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
141  bool mipMapSupport() const { return fMipMapSupport; }
142 
148  bool srgbSupport() const { return fSRGBSupport; }
152  bool srgbWriteControl() const { return fSRGBWriteControl; }
153  bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
154  bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
155  bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
156  bool gpuTracingSupport() const { return fGpuTracingSupport; }
157  bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
158  bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
159  bool textureBarrierSupport() const { return fTextureBarrierSupport; }
160  bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
161  bool multisampleDisableSupport() const { return fMultisampleDisableSupport; }
162  bool usesMixedSamples() const { return fUsesMixedSamples; }
163  bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
164 
165  bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
166  bool useDrawInsteadOfPartialRenderTargetWrite() const {
167  return fUseDrawInsteadOfPartialRenderTargetWrite;
168  }
169 
170  bool useDrawInsteadOfAllRenderTargetWrites() const {
171  return fUseDrawInsteadOfAllRenderTargetWrites;
172  }
173 
174  bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
175 
180  enum class InstancedSupport {
181  kNone,
182  kBasic,
183  kMultisampled,
184  kMixedSampled
185  };
186 
187  InstancedSupport instancedSupport() const { return fInstancedSupport; }
188 
189  bool avoidInstancedDrawsToFPTargets() const { return fAvoidInstancedDrawsToFPTargets; }
190 
195  kBasic_BlendEquationSupport, //<! Support to select the operator that
196  // combines src and dst terms.
197  kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
198  // SVG/PDF blend modes. Requires blend barriers.
199  kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
200  // require blend barriers, and permits overlap.
201 
202  kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
203  };
204 
205  BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
206 
207  bool advancedBlendEquationSupport() const {
208  return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
209  }
210 
211  bool advancedCoherentBlendEquationSupport() const {
212  return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
213  }
214 
215  bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
216  SkASSERT(GrBlendEquationIsAdvanced(equation));
217  return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
218  }
219 
224  enum MapFlags {
225  kNone_MapFlags = 0x0, //<! Cannot map the resource.
226 
227  kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
228  // the other flags to have meaning.k
229  kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
230  };
231 
232  uint32_t mapBufferFlags() const { return fMapBufferFlags; }
233 
234  // Scratch textures not being reused means that those scratch textures
235  // that we upload to (i.e., don't have a render target) will not be
236  // recycled in the texture cache. This is to prevent ghosting by drivers
237  // (in particular for deferred architectures).
238  bool reuseScratchTextures() const { return fReuseScratchTextures; }
239  bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
240 
242  int maxVertexAttributes() const { return fMaxVertexAttributes; }
243 
244  int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
245  int maxTextureSize() const { return fMaxTextureSize; }
248  int maxTileSize() const { SkASSERT(fMaxTileSize <= fMaxTextureSize); return fMaxTileSize; }
249 
250  // Will be 0 if MSAA is not supported
251  int maxColorSampleCount() const { return fMaxColorSampleCount; }
252  // Will be 0 if MSAA is not supported
253  int maxStencilSampleCount() const { return fMaxStencilSampleCount; }
254  // Will be 0 if raster multisample is not supported. Raster multisample is a special HW mode
255  // where the rasterizer runs with more samples than are in the target framebuffer.
256  int maxRasterSamples() const { return fMaxRasterSamples; }
257  // We require the sample count to be less than maxColorSampleCount and maxStencilSampleCount.
258  // If we are using mixed samples, we only care about stencil.
259  int maxSampleCount() const {
260  if (this->usesMixedSamples()) {
261  return this->maxStencilSampleCount();
262  } else {
263  return SkTMin(this->maxColorSampleCount(), this->maxStencilSampleCount());
264  }
265  }
266 
267  int maxWindowRectangles() const { return fMaxWindowRectangles; }
268 
269  virtual bool isConfigTexturable(GrPixelConfig config) const = 0;
270  virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0;
271 
272  bool suppressPrints() const { return fSuppressPrints; }
273 
274  bool immediateFlush() const { return fImmediateFlush; }
275 
276  size_t bufferMapThreshold() const {
277  SkASSERT(fBufferMapThreshold >= 0);
278  return fBufferMapThreshold;
279  }
280 
281  bool fullClearIsFree() const { return fFullClearIsFree; }
282 
285  bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
286 
287  bool sampleShadingSupport() const { return fSampleShadingSupport; }
288 
289 protected:
293  void applyOptionsOverrides(const GrContextOptions& options);
294 
295  SkAutoTUnref<GrShaderCaps> fShaderCaps;
296 
297  bool fNPOTTextureTileSupport : 1;
298  bool fMipMapSupport : 1;
299  bool fSRGBSupport : 1;
300  bool fSRGBWriteControl : 1;
301  bool fTwoSidedStencilSupport : 1;
302  bool fStencilWrapOpsSupport : 1;
303  bool fDiscardRenderTargetSupport : 1;
304  bool fReuseScratchTextures : 1;
305  bool fReuseScratchBuffers : 1;
306  bool fGpuTracingSupport : 1;
307  bool fCompressedTexSubImageSupport : 1;
308  bool fOversizedStencilSupport : 1;
309  bool fTextureBarrierSupport : 1;
310  bool fSampleLocationsSupport : 1;
311  bool fMultisampleDisableSupport : 1;
312  bool fUsesMixedSamples : 1;
313  bool fPreferClientSideDynamicBuffers : 1;
314  bool fFullClearIsFree : 1;
315  bool fMustClearUploadedBufferData : 1;
316 
317  // Driver workaround
318  bool fUseDrawInsteadOfClear : 1;
319  bool fUseDrawInsteadOfPartialRenderTargetWrite : 1;
320  bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
321  bool fAvoidInstancedDrawsToFPTargets : 1;
322 
323  // ANGLE workaround
324  bool fPreferVRAMUseOverFlushes : 1;
325 
326  bool fSampleShadingSupport : 1;
327 
328  InstancedSupport fInstancedSupport;
329 
330  BlendEquationSupport fBlendEquationSupport;
331  uint32_t fAdvBlendEqBlacklist;
332  GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
333 
334  uint32_t fMapBufferFlags;
335  int fBufferMapThreshold;
336 
337  int fMaxRenderTargetSize;
338  int fMaxVertexAttributes;
339  int fMaxTextureSize;
340  int fMaxTileSize;
341  int fMaxColorSampleCount;
342  int fMaxStencilSampleCount;
343  int fMaxRasterSamples;
344  int fMaxWindowRectangles;
345 
346 private:
347  virtual void onApplyOptionsOverrides(const GrContextOptions&) {};
348 
349  bool fSuppressPrints : 1;
350  bool fImmediateFlush: 1;
351 
352  typedef SkRefCnt INHERITED;
353 };
354 
355 #endif
Definition: GrContextOptions.h:13
Info about shader variable precision within a given shader stage.
Definition: GrCaps.h:25
bool supported() const
Is this precision level allowed in the shader stage?
Definition: GrCaps.h:33
int pixelLocalStorageSize() const
PLS storage size in bytes (0 when not supported).
Definition: GrCaps.h:90
Represents the capabilities of a GrContext.
Definition: GrCaps.h:130
bool srgbWriteControl() const
Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers?
Definition: GrCaps.h:152
bool plsPathRenderingSupport() const
True if this context supports the necessary extensions and features to enable the PLS path renderer...
Definition: GrCaps.h:96
void applyOptionsOverrides(const GrContextOptions &options)
Subclasses must call this after initialization in order to apply caps overrides requested by the clie...
int fLogRangeLow
floor(log2(|min_value|))
Definition: GrCaps.h:42
MapFlags
Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and textures allow...
Definition: GrCaps.h:224
InstancedSupport
Indicates the level of support for gr_instanced::* functionality.
Definition: GrCaps.h:180
Definition: SkRefCnt.h:135
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
int fBits
Number of bits of precision.
Definition: GrCaps.h:53
bool floatPrecisionVaries() const
Is there any difference between the float shader variable precision types? If this is true then unles...
Definition: GrCaps.h:84
int maxVertexAttributes() const
maximum number of attribute values per vertex
Definition: GrCaps.h:242
bool mipMapSupport() const
To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e...
Definition: GrCaps.h:141
int fLogRangeHigh
floor(log2(|max_value|))
Definition: GrCaps.h:44
BlendEquationSupport
Indicates the capabilities of the fixed function blend unit.
Definition: GrCaps.h:194
void applyOptionsOverrides(const GrContextOptions &options)
Subclasses must call this at the end of their constructors in order to apply caps overrides requested...
Definition: GrCaps.h:20
const PrecisionInfo & getFloatShaderPrecisionInfo(GrShaderType shaderType, GrSLPrecision precision) const
Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a given shader...
Definition: GrCaps.h:74
bool srgbSupport() const
Skia convention is that a device only has sRGB support if it supports sRGB formats for both textures ...
Definition: GrCaps.h:148
bool mustClearUploadedBufferData() const
True in environments that will issue errors if memory uploaded to buffers is not initialized (even if...
Definition: GrCaps.h:285
Light weight class for managing strings.
Definition: SkString.h:121
int maxTileSize() const
This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps.
Definition: GrCaps.h:248