blob: 35e2c2ca302657a744cbb90af50afe8e08d66320 [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; }
cdalton793dc262016-02-08 10:11:47 -080065 bool integerSupport() const { return fIntegerSupport; }
cdaltonf8a6ce82016-04-11 13:02:05 -070066 bool texelBufferSupport() const { return fTexelBufferSupport; }
jvanverthe9c0fc62015-04-29 11:18:05 -070067
68 /**
69 * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a
70 * given shader type. If the shader type is not supported or the precision level is not
71 * supported in that shader type then the returned struct will report false when supported() is
72 * called.
73 */
74 const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
robertphillips2eb10092015-12-11 04:59:36 -080075 GrSLPrecision precision) const {
jvanverthe9c0fc62015-04-29 11:18:05 -070076 return fFloatPrecisions[shaderType][precision];
77 };
78
79 /**
80 * Is there any difference between the float shader variable precision types? If this is true
81 * then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would
82 * report the same info for all precisions in all shader types.
83 */
84 bool floatPrecisionVaries() const { return fShaderPrecisionVaries; }
85
ethannicholas22793252016-01-30 09:59:10 -080086 /**
87 * PLS storage size in bytes (0 when not supported). The PLS spec defines a minimum size of 16
88 * bytes whenever PLS is supported.
89 */
90 int pixelLocalStorageSize() const { return fPixelLocalStorageSize; }
91
92 /**
93 * True if this context supports the necessary extensions and features to enable the PLS path
94 * renderer.
95 */
96 bool plsPathRenderingSupport() const {
97#if GR_ENABLE_PLS_PATH_RENDERING
98 return fPLSPathRenderingSupport;
99#else
100 return false;
101#endif
102 }
103
jvanverthe9c0fc62015-04-29 11:18:05 -0700104protected:
cdalton4cd67132015-06-10 19:23:46 -0700105 /** Subclasses must call this after initialization in order to apply caps overrides requested by
106 the client. Note that overrides will only reduce the caps never expand them. */
bsalomon4ee6bd82015-05-27 13:23:23 -0700107 void applyOptionsOverrides(const GrContextOptions& options);
108
jvanverthe9c0fc62015-04-29 11:18:05 -0700109 bool fShaderDerivativeSupport : 1;
110 bool fGeometryShaderSupport : 1;
111 bool fPathRenderingSupport : 1;
112 bool fDstReadInShaderSupport : 1;
113 bool fDualSourceBlendingSupport : 1;
cdalton793dc262016-02-08 10:11:47 -0800114 bool fIntegerSupport : 1;
cdaltonf8a6ce82016-04-11 13:02:05 -0700115 bool fTexelBufferSupport : 1;
jvanverthe9c0fc62015-04-29 11:18:05 -0700116
117 bool fShaderPrecisionVaries;
118 PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
ethannicholas22793252016-01-30 09:59:10 -0800119 int fPixelLocalStorageSize;
120 bool fPLSPathRenderingSupport;
jvanverthe9c0fc62015-04-29 11:18:05 -0700121
122private:
egdanielb7e7d572015-11-04 04:23:53 -0800123 virtual void onApplyOptionsOverrides(const GrContextOptions&) {};
jvanverthe9c0fc62015-04-29 11:18:05 -0700124 typedef SkRefCnt INHERITED;
125};
126
127/**
bsalomon4b91f762015-05-19 09:29:46 -0700128 * Represents the capabilities of a GrContext.
jvanverthe9c0fc62015-04-29 11:18:05 -0700129 */
bsalomon4b91f762015-05-19 09:29:46 -0700130class GrCaps : public SkRefCnt {
jvanverthe9c0fc62015-04-29 11:18:05 -0700131public:
bsalomon682c2692015-05-22 14:01:46 -0700132 GrCaps(const GrContextOptions&);
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000133
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000134 virtual SkString dump() const;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000135
jvanverthe9c0fc62015-04-29 11:18:05 -0700136 GrShaderCaps* shaderCaps() const { return fShaderCaps; }
137
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000138 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000139 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
140 only for POT textures) */
141 bool mipMapSupport() const { return fMipMapSupport; }
brianosman64d094d2016-03-25 06:01:59 -0700142
143 /**
144 * Skia convention is that a device only has sRGB support if it supports sRGB formats for both
145 * textures and framebuffers. In addition:
146 * Decoding to linear of an sRGB texture can be disabled.
brianosman64d094d2016-03-25 06:01:59 -0700147 */
brianosmana6359362016-03-21 06:55:37 -0700148 bool srgbSupport() const { return fSRGBSupport; }
brianosman35b784d2016-05-05 11:52:53 -0700149 /**
150 * Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers?
151 */
152 bool srgbWriteControl() const { return fSRGBWriteControl; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000153 bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
154 bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000155 bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000156 bool gpuTracingSupport() const { return fGpuTracingSupport; }
krajcevski786978162014-07-30 11:25:44 -0700157 bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
bsalomond08ea5f2015-02-20 06:58:13 -0800158 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
cdaltonfd4167d2015-04-21 11:45:56 -0700159 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
cdaltoneb79eea2016-02-26 10:39:34 -0800160 bool sampleLocationsSupport() const { return fSampleLocationsSupport; }
csmartdalton2b5f2cb2016-06-10 14:06:32 -0700161 bool multisampleDisableSupport() const { return fMultisampleDisableSupport; }
egdanieleed519e2016-01-15 11:36:18 -0800162 bool usesMixedSamples() const { return fUsesMixedSamples; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000163
bsalomon63b21962014-11-05 07:05:34 -0800164 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
joshualitt83bc2292015-06-18 14:18:02 -0700165 bool useDrawInsteadOfPartialRenderTargetWrite() const {
166 return fUseDrawInsteadOfPartialRenderTargetWrite;
167 }
bsalomon63b21962014-11-05 07:05:34 -0800168
bsalomonbabafcc2016-02-16 11:36:47 -0800169 bool useDrawInsteadOfAllRenderTargetWrites() const {
170 return fUseDrawInsteadOfAllRenderTargetWrites;
171 }
172
robertphillips63926682015-08-20 09:39:02 -0700173 bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; }
174
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000175 /**
cdalton8917d622015-05-06 13:40:21 -0700176 * Indicates the capabilities of the fixed function blend unit.
177 */
178 enum BlendEquationSupport {
179 kBasic_BlendEquationSupport, //<! Support to select the operator that
180 // combines src and dst terms.
181 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
182 // SVG/PDF blend modes. Requires blend barriers.
183 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
184 // require blend barriers, and permits overlap.
185
186 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
187 };
188
189 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
190
191 bool advancedBlendEquationSupport() const {
192 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
193 }
194
195 bool advancedCoherentBlendEquationSupport() const {
196 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
197 }
198
cdalton1dd05422015-06-12 09:01:18 -0700199 bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
200 SkASSERT(GrBlendEquationIsAdvanced(equation));
201 return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
202 }
203
cdalton8917d622015-05-06 13:40:21 -0700204 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000205 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
206 * textures allows partial mappings or full mappings.
207 */
208 enum MapFlags {
209 kNone_MapFlags = 0x0, //<! Cannot map the resource.
210
211 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
212 // the other flags to have meaning.k
213 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
214 };
215
216 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
217
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000218 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000219 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000220 // recycled in the texture cache. This is to prevent ghosting by drivers
221 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000222 bool reuseScratchTextures() const { return fReuseScratchTextures; }
robertphillips1b8e1b52015-06-24 06:54:10 -0700223 bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000224
bsalomon7dbd45d2016-03-23 10:40:53 -0700225 /// maximum number of attribute values per vertex
226 int maxVertexAttributes() const { return fMaxVertexAttributes; }
227
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000228 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
229 int maxTextureSize() const { return fMaxTextureSize; }
bsalomon8c07b7a2015-11-02 11:36:52 -0800230 /** This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps.
231 It is usually the max texture size, unless we're overriding it for testing. */
232 int maxTileSize() const { SkASSERT(fMaxTileSize <= fMaxTextureSize); return fMaxTileSize; }
bsalomonc59a1df2015-06-01 07:13:42 -0700233
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000234 // Will be 0 if MSAA is not supported
egdanieleed519e2016-01-15 11:36:18 -0800235 int maxColorSampleCount() const { return fMaxColorSampleCount; }
236 // Will be 0 if MSAA is not supported
237 int maxStencilSampleCount() const { return fMaxStencilSampleCount; }
cdaltonaf8bc7d2016-02-05 09:35:20 -0800238 // Will be 0 if raster multisample is not supported. Raster multisample is a special HW mode
239 // where the rasterizer runs with more samples than are in the target framebuffer.
240 int maxRasterSamples() const { return fMaxRasterSamples; }
egdanieleed519e2016-01-15 11:36:18 -0800241 // We require the sample count to be less than maxColorSampleCount and maxStencilSampleCount.
242 // If we are using mixed samples, we only care about stencil.
243 int maxSampleCount() const {
244 if (this->usesMixedSamples()) {
245 return this->maxStencilSampleCount();
246 } else {
247 return SkTMin(this->maxColorSampleCount(), this->maxStencilSampleCount());
248 }
249 }
250
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000251
bsalomon41e4384e2016-01-08 09:12:44 -0800252 virtual bool isConfigTexturable(GrPixelConfig config) const = 0;
253 virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0;
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000254
robertphillipscaef3452015-11-11 13:18:11 -0800255 bool suppressPrints() const { return fSuppressPrints; }
256
257 bool immediateFlush() const { return fImmediateFlush; }
bsalomon682c2692015-05-22 14:01:46 -0700258
cdalton397536c2016-03-25 12:15:03 -0700259 size_t bufferMapThreshold() const {
260 SkASSERT(fBufferMapThreshold >= 0);
261 return fBufferMapThreshold;
joshualitt7224c862015-05-29 06:46:47 -0700262 }
bsalomon682c2692015-05-22 14:01:46 -0700263
joshualitt58001552015-06-26 12:46:36 -0700264 bool supportsInstancedDraws() const {
265 return fSupportsInstancedDraws;
266 }
267
egdaniel51c8d402015-08-06 10:54:13 -0700268 bool fullClearIsFree() const { return fFullClearIsFree; }
269
bsalomon7dea7b72015-08-19 08:26:51 -0700270 /** True in environments that will issue errors if memory uploaded to buffers
271 is not initialized (even if not read by draw calls). */
272 bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
273
ethannicholas28ef4452016-03-25 09:26:03 -0700274 bool sampleShadingSupport() const { return fSampleShadingSupport; }
275
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000276protected:
bsalomon4ee6bd82015-05-27 13:23:23 -0700277 /** Subclasses must call this at the end of their constructors in order to apply caps
278 overrides requested by the client. Note that overrides will only reduce the caps never
279 expand them. */
280 void applyOptionsOverrides(const GrContextOptions& options);
281
jvanverthe9c0fc62015-04-29 11:18:05 -0700282 SkAutoTUnref<GrShaderCaps> fShaderCaps;
283
joshualitt83bc2292015-06-18 14:18:02 -0700284 bool fNPOTTextureTileSupport : 1;
285 bool fMipMapSupport : 1;
brianosmana6359362016-03-21 06:55:37 -0700286 bool fSRGBSupport : 1;
brianosman35b784d2016-05-05 11:52:53 -0700287 bool fSRGBWriteControl : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700288 bool fTwoSidedStencilSupport : 1;
289 bool fStencilWrapOpsSupport : 1;
290 bool fDiscardRenderTargetSupport : 1;
291 bool fReuseScratchTextures : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700292 bool fReuseScratchBuffers : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700293 bool fGpuTracingSupport : 1;
294 bool fCompressedTexSubImageSupport : 1;
295 bool fOversizedStencilSupport : 1;
296 bool fTextureBarrierSupport : 1;
cdaltoneb79eea2016-02-26 10:39:34 -0800297 bool fSampleLocationsSupport : 1;
csmartdalton2b5f2cb2016-06-10 14:06:32 -0700298 bool fMultisampleDisableSupport : 1;
egdanieleed519e2016-01-15 11:36:18 -0800299 bool fUsesMixedSamples : 1;
joshualitt58001552015-06-26 12:46:36 -0700300 bool fSupportsInstancedDraws : 1;
egdaniel51c8d402015-08-06 10:54:13 -0700301 bool fFullClearIsFree : 1;
bsalomon7dea7b72015-08-19 08:26:51 -0700302 bool fMustClearUploadedBufferData : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700303
bsalomon63b21962014-11-05 07:05:34 -0800304 // Driver workaround
joshualitt83bc2292015-06-18 14:18:02 -0700305 bool fUseDrawInsteadOfClear : 1;
306 bool fUseDrawInsteadOfPartialRenderTargetWrite : 1;
bsalomonbabafcc2016-02-16 11:36:47 -0800307 bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
bsalomon63b21962014-11-05 07:05:34 -0800308
robertphillips63926682015-08-20 09:39:02 -0700309 // ANGLE workaround
310 bool fPreferVRAMUseOverFlushes : 1;
311
ethannicholas28ef4452016-03-25 09:26:03 -0700312 bool fSampleShadingSupport : 1;
313
cdalton8917d622015-05-06 13:40:21 -0700314 BlendEquationSupport fBlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -0700315 uint32_t fAdvBlendEqBlacklist;
316 GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
317
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000318 uint32_t fMapBufferFlags;
cdalton397536c2016-03-25 12:15:03 -0700319 int fBufferMapThreshold;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000320
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000321 int fMaxRenderTargetSize;
bsalomon7dbd45d2016-03-23 10:40:53 -0700322 int fMaxVertexAttributes;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000323 int fMaxTextureSize;
bsalomon8c07b7a2015-11-02 11:36:52 -0800324 int fMaxTileSize;
egdanieleed519e2016-01-15 11:36:18 -0800325 int fMaxColorSampleCount;
326 int fMaxStencilSampleCount;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800327 int fMaxRasterSamples;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000328
egdanielbc127a32014-09-19 12:07:43 -0700329private:
egdanielb7e7d572015-11-04 04:23:53 -0800330 virtual void onApplyOptionsOverrides(const GrContextOptions&) {};
331
robertphillipscaef3452015-11-11 13:18:11 -0800332 bool fSuppressPrints : 1;
333 bool fImmediateFlush: 1;
bsalomon682c2692015-05-22 14:01:46 -0700334
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000335 typedef SkRefCnt INHERITED;
336};
337
338#endif