blob: e2e59c30a4c7701b1f85e3174262982c6f006484 [file] [log] [blame]
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001
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 */
bsalomon4b91f762015-05-19 09:29:46 -07008#ifndef GrCaps_DEFINED
9#define GrCaps_DEFINED
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000010
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000011#include "GrTypes.h"
bsalomon17168df2014-12-09 09:00:49 -080012#include "GrTypesPriv.h"
cdalton1dd05422015-06-12 09:01:18 -070013#include "GrBlend.h"
bsalomon17168df2014-12-09 09:00:49 -080014#include "GrShaderVar.h"
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000015#include "SkRefCnt.h"
16#include "SkString.h"
17
bsalomon682c2692015-05-22 14:01:46 -070018struct GrContextOptions;
19
jvanverthe9c0fc62015-04-29 11:18:05 -070020class GrShaderCaps : public SkRefCnt {
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000021public:
bsalomon17168df2014-12-09 09:00:49 -080022 /** Info about shader variable precision within a given shader stage. That is, this info
bsalomonc0bd6482014-12-09 10:04:14 -080023 is relevant to a float (or vecNf) variable declared with a GrSLPrecision
bsalomon17168df2014-12-09 09:00:49 -080024 in a given GrShaderType. The info here is hoisted from the OpenGL spec. */
25 struct PrecisionInfo {
26 PrecisionInfo() {
27 fLogRangeLow = 0;
28 fLogRangeHigh = 0;
29 fBits = 0;
30 }
31
32 /** Is this precision level allowed in the shader stage? */
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
41 /** floor(log2(|min_value|)) */
42 int fLogRangeLow;
43 /** floor(log2(|max_value|)) */
44 int fLogRangeHigh;
jvanverthe9c0fc62015-04-29 11:18:05 -070045 /** Number of bits of precision. As defined in OpenGL (with names modified to reflect this
bsalomon17168df2014-12-09 09:00:49 -080046 struct) :
47 """
jvanverthe9c0fc62015-04-29 11:18:05 -070048 If the smallest representable value greater than 1 is 1 + e, then fBits will
49 contain floor(log2(e)), and every value in the range [2^fLogRangeLow,
50 2^fLogRangeHigh] can be represented to at least one part in 2^fBits.
51 """
bsalomon17168df2014-12-09 09:00:49 -080052 */
53 int fBits;
54 };
55
bsalomon424cc262015-05-22 10:37:30 -070056 GrShaderCaps();
jvanverthe9c0fc62015-04-29 11:18:05 -070057
jvanverthe9c0fc62015-04-29 11:18:05 -070058 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
66 /**
67 * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a
68 * given shader type. If the shader type is not supported or the precision level is not
69 * supported in that shader type then the returned struct will report false when supported() is
70 * called.
71 */
72 const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
robertphillips2eb10092015-12-11 04:59:36 -080073 GrSLPrecision precision) const {
jvanverthe9c0fc62015-04-29 11:18:05 -070074 return fFloatPrecisions[shaderType][precision];
75 };
76
77 /**
78 * Is there any difference between the float shader variable precision types? If this is true
79 * then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would
80 * report the same info for all precisions in all shader types.
81 */
82 bool floatPrecisionVaries() const { return fShaderPrecisionVaries; }
83
84protected:
cdalton4cd67132015-06-10 19:23:46 -070085 /** Subclasses must call this after initialization in order to apply caps overrides requested by
86 the client. Note that overrides will only reduce the caps never expand them. */
bsalomon4ee6bd82015-05-27 13:23:23 -070087 void applyOptionsOverrides(const GrContextOptions& options);
88
jvanverthe9c0fc62015-04-29 11:18:05 -070089 bool fShaderDerivativeSupport : 1;
90 bool fGeometryShaderSupport : 1;
91 bool fPathRenderingSupport : 1;
92 bool fDstReadInShaderSupport : 1;
93 bool fDualSourceBlendingSupport : 1;
94
95 bool fShaderPrecisionVaries;
96 PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
97
98private:
egdanielb7e7d572015-11-04 04:23:53 -080099 virtual void onApplyOptionsOverrides(const GrContextOptions&) {};
jvanverthe9c0fc62015-04-29 11:18:05 -0700100 typedef SkRefCnt INHERITED;
101};
102
103/**
bsalomon4b91f762015-05-19 09:29:46 -0700104 * Represents the capabilities of a GrContext.
jvanverthe9c0fc62015-04-29 11:18:05 -0700105 */
bsalomon4b91f762015-05-19 09:29:46 -0700106class GrCaps : public SkRefCnt {
jvanverthe9c0fc62015-04-29 11:18:05 -0700107public:
bsalomon682c2692015-05-22 14:01:46 -0700108 GrCaps(const GrContextOptions&);
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000109
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000110 virtual SkString dump() const;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000111
jvanverthe9c0fc62015-04-29 11:18:05 -0700112 GrShaderCaps* shaderCaps() const { return fShaderCaps; }
113
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000114 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000115 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
116 only for POT textures) */
117 bool mipMapSupport() const { return fMipMapSupport; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000118 bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
119 bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000120 bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000121 bool gpuTracingSupport() const { return fGpuTracingSupport; }
krajcevski786978162014-07-30 11:25:44 -0700122 bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
bsalomond08ea5f2015-02-20 06:58:13 -0800123 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
cdaltonfd4167d2015-04-21 11:45:56 -0700124 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
egdanieleed519e2016-01-15 11:36:18 -0800125 bool usesMixedSamples() const { return fUsesMixedSamples; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000126
bsalomon63b21962014-11-05 07:05:34 -0800127 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
joshualitt83bc2292015-06-18 14:18:02 -0700128 bool useDrawInsteadOfPartialRenderTargetWrite() const {
129 return fUseDrawInsteadOfPartialRenderTargetWrite;
130 }
bsalomon63b21962014-11-05 07:05:34 -0800131
robertphillips63926682015-08-20 09:39:02 -0700132 bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
133
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000134 /**
cdalton8917d622015-05-06 13:40:21 -0700135 * Indicates the capabilities of the fixed function blend unit.
136 */
137 enum BlendEquationSupport {
138 kBasic_BlendEquationSupport, //<! Support to select the operator that
139 // combines src and dst terms.
140 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
141 // SVG/PDF blend modes. Requires blend barriers.
142 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
143 // require blend barriers, and permits overlap.
144
145 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
146 };
147
148 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
149
150 bool advancedBlendEquationSupport() const {
151 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
152 }
153
154 bool advancedCoherentBlendEquationSupport() const {
155 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
156 }
157
cdalton1dd05422015-06-12 09:01:18 -0700158 bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
159 SkASSERT(GrBlendEquationIsAdvanced(equation));
160 return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
161 }
162
cdalton8917d622015-05-06 13:40:21 -0700163 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000164 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
165 * textures allows partial mappings or full mappings.
166 */
167 enum MapFlags {
168 kNone_MapFlags = 0x0, //<! Cannot map the resource.
169
170 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
171 // the other flags to have meaning.k
172 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
173 };
174
175 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
176
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000177 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000178 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000179 // recycled in the texture cache. This is to prevent ghosting by drivers
180 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000181 bool reuseScratchTextures() const { return fReuseScratchTextures; }
robertphillips1b8e1b52015-06-24 06:54:10 -0700182 bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000183
184 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
185 int maxTextureSize() const { return fMaxTextureSize; }
bsalomon8c07b7a2015-11-02 11:36:52 -0800186 /** This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps.
187 It is usually the max texture size, unless we're overriding it for testing. */
188 int maxTileSize() const { SkASSERT(fMaxTileSize <= fMaxTextureSize); return fMaxTileSize; }
bsalomonc59a1df2015-06-01 07:13:42 -0700189
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000190 // Will be 0 if MSAA is not supported
egdanieleed519e2016-01-15 11:36:18 -0800191 int maxColorSampleCount() const { return fMaxColorSampleCount; }
192 // Will be 0 if MSAA is not supported
193 int maxStencilSampleCount() const { return fMaxStencilSampleCount; }
194 // We require the sample count to be less than maxColorSampleCount and maxStencilSampleCount.
195 // If we are using mixed samples, we only care about stencil.
196 int maxSampleCount() const {
197 if (this->usesMixedSamples()) {
198 return this->maxStencilSampleCount();
199 } else {
200 return SkTMin(this->maxColorSampleCount(), this->maxStencilSampleCount());
201 }
202 }
203
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000204
bsalomon41e4384e2016-01-08 09:12:44 -0800205 virtual bool isConfigTexturable(GrPixelConfig config) const = 0;
206 virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000207
robertphillipscaef3452015-11-11 13:18:11 -0800208 bool suppressPrints() const { return fSuppressPrints; }
209
210 bool immediateFlush() const { return fImmediateFlush; }
bsalomon682c2692015-05-22 14:01:46 -0700211
212 bool drawPathMasksToCompressedTexturesSupport() const {
joshualitt7224c862015-05-29 06:46:47 -0700213 return fDrawPathMasksToCompressedTextureSupport;
214 }
215
216 size_t geometryBufferMapThreshold() const {
joshualitte5b74c62015-06-01 14:17:47 -0700217 SkASSERT(fGeometryBufferMapThreshold >= 0);
joshualitt7224c862015-05-29 06:46:47 -0700218 return fGeometryBufferMapThreshold;
219 }
bsalomon682c2692015-05-22 14:01:46 -0700220
joshualitt58001552015-06-26 12:46:36 -0700221 bool supportsInstancedDraws() const {
222 return fSupportsInstancedDraws;
223 }
224
egdaniel51c8d402015-08-06 10:54:13 -0700225 bool fullClearIsFree() const { return fFullClearIsFree; }
226
bsalomon7dea7b72015-08-19 08:26:51 -0700227 /** True in environments that will issue errors if memory uploaded to buffers
228 is not initialized (even if not read by draw calls). */
229 bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
230
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000231protected:
bsalomon4ee6bd82015-05-27 13:23:23 -0700232 /** Subclasses must call this at the end of their constructors in order to apply caps
233 overrides requested by the client. Note that overrides will only reduce the caps never
234 expand them. */
235 void applyOptionsOverrides(const GrContextOptions& options);
236
jvanverthe9c0fc62015-04-29 11:18:05 -0700237 SkAutoTUnref<GrShaderCaps> fShaderCaps;
238
joshualitt83bc2292015-06-18 14:18:02 -0700239 bool fNPOTTextureTileSupport : 1;
240 bool fMipMapSupport : 1;
241 bool fTwoSidedStencilSupport : 1;
242 bool fStencilWrapOpsSupport : 1;
243 bool fDiscardRenderTargetSupport : 1;
244 bool fReuseScratchTextures : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700245 bool fReuseScratchBuffers : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700246 bool fGpuTracingSupport : 1;
247 bool fCompressedTexSubImageSupport : 1;
248 bool fOversizedStencilSupport : 1;
249 bool fTextureBarrierSupport : 1;
egdanieleed519e2016-01-15 11:36:18 -0800250 bool fUsesMixedSamples : 1;
joshualitt58001552015-06-26 12:46:36 -0700251 bool fSupportsInstancedDraws : 1;
egdaniel51c8d402015-08-06 10:54:13 -0700252 bool fFullClearIsFree : 1;
bsalomon7dea7b72015-08-19 08:26:51 -0700253 bool fMustClearUploadedBufferData : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700254
bsalomon63b21962014-11-05 07:05:34 -0800255 // Driver workaround
joshualitt83bc2292015-06-18 14:18:02 -0700256 bool fUseDrawInsteadOfClear : 1;
257 bool fUseDrawInsteadOfPartialRenderTargetWrite : 1;
bsalomon63b21962014-11-05 07:05:34 -0800258
robertphillips63926682015-08-20 09:39:02 -0700259 // ANGLE workaround
260 bool fPreferVRAMUseOverFlushes : 1;
261
cdalton8917d622015-05-06 13:40:21 -0700262 BlendEquationSupport fBlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -0700263 uint32_t fAdvBlendEqBlacklist;
264 GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
265
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000266 uint32_t fMapBufferFlags;
joshualitte5b74c62015-06-01 14:17:47 -0700267 int fGeometryBufferMapThreshold;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000268
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000269 int fMaxRenderTargetSize;
270 int fMaxTextureSize;
bsalomon8c07b7a2015-11-02 11:36:52 -0800271 int fMaxTileSize;
egdanieleed519e2016-01-15 11:36:18 -0800272 int fMaxColorSampleCount;
273 int fMaxStencilSampleCount;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000274
egdanielbc127a32014-09-19 12:07:43 -0700275private:
egdanielb7e7d572015-11-04 04:23:53 -0800276 virtual void onApplyOptionsOverrides(const GrContextOptions&) {};
277
robertphillipscaef3452015-11-11 13:18:11 -0800278 bool fSuppressPrints : 1;
279 bool fImmediateFlush: 1;
bsalomon682c2692015-05-22 14:01:46 -0700280 bool fDrawPathMasksToCompressedTextureSupport : 1;
281
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000282 typedef SkRefCnt INHERITED;
283};
284
285#endif