blob: 48bcb28c4dfa21db368dbc6124126f1aaddea835 [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; }
cdalton0edea2c2015-05-21 08:27:44 -070065 bool mixedSamplesSupport() const { return fMixedSamplesSupport; }
jvanverthe9c0fc62015-04-29 11:18:05 -070066
67 /**
68 * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a
69 * given shader type. If the shader type is not supported or the precision level is not
70 * supported in that shader type then the returned struct will report false when supported() is
71 * called.
72 */
73 const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
74 GrSLPrecision precision) const {
75 return fFloatPrecisions[shaderType][precision];
76 };
77
78 /**
79 * Is there any difference between the float shader variable precision types? If this is true
80 * then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would
81 * report the same info for all precisions in all shader types.
82 */
83 bool floatPrecisionVaries() const { return fShaderPrecisionVaries; }
84
85protected:
cdalton4cd67132015-06-10 19:23:46 -070086 /** Subclasses must call this after initialization in order to apply caps overrides requested by
87 the client. Note that overrides will only reduce the caps never expand them. */
bsalomon4ee6bd82015-05-27 13:23:23 -070088 void applyOptionsOverrides(const GrContextOptions& options);
89
jvanverthe9c0fc62015-04-29 11:18:05 -070090 bool fShaderDerivativeSupport : 1;
91 bool fGeometryShaderSupport : 1;
92 bool fPathRenderingSupport : 1;
93 bool fDstReadInShaderSupport : 1;
94 bool fDualSourceBlendingSupport : 1;
cdalton0edea2c2015-05-21 08:27:44 -070095 bool fMixedSamplesSupport : 1;
jvanverthe9c0fc62015-04-29 11:18:05 -070096
97 bool fShaderPrecisionVaries;
98 PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
99
100private:
101 typedef SkRefCnt INHERITED;
102};
103
104/**
bsalomon4b91f762015-05-19 09:29:46 -0700105 * Represents the capabilities of a GrContext.
jvanverthe9c0fc62015-04-29 11:18:05 -0700106 */
bsalomon4b91f762015-05-19 09:29:46 -0700107class GrCaps : public SkRefCnt {
jvanverthe9c0fc62015-04-29 11:18:05 -0700108public:
bsalomon682c2692015-05-22 14:01:46 -0700109 GrCaps(const GrContextOptions&);
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000110
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000111 virtual SkString dump() const;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000112
jvanverthe9c0fc62015-04-29 11:18:05 -0700113 GrShaderCaps* shaderCaps() const { return fShaderCaps; }
114
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000115 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000116 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
117 only for POT textures) */
118 bool mipMapSupport() const { return fMipMapSupport; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000119 bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
120 bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000121 bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
egdanielbdad9c32015-03-05 12:19:17 -0800122#if GR_FORCE_GPU_TRACE_DEBUGGING
123 bool gpuTracingSupport() const { return true; }
124#else
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000125 bool gpuTracingSupport() const { return fGpuTracingSupport; }
egdanielbdad9c32015-03-05 12:19:17 -0800126#endif
krajcevski786978162014-07-30 11:25:44 -0700127 bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
bsalomond08ea5f2015-02-20 06:58:13 -0800128 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
cdaltonfd4167d2015-04-21 11:45:56 -0700129 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000130
bsalomon63b21962014-11-05 07:05:34 -0800131 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
joshualitt83bc2292015-06-18 14:18:02 -0700132 bool useDrawInsteadOfPartialRenderTargetWrite() const {
133 return fUseDrawInsteadOfPartialRenderTargetWrite;
134 }
bsalomon63b21962014-11-05 07:05:34 -0800135
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000136 /**
cdalton8917d622015-05-06 13:40:21 -0700137 * Indicates the capabilities of the fixed function blend unit.
138 */
139 enum BlendEquationSupport {
140 kBasic_BlendEquationSupport, //<! Support to select the operator that
141 // combines src and dst terms.
142 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
143 // SVG/PDF blend modes. Requires blend barriers.
144 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
145 // require blend barriers, and permits overlap.
146
147 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
148 };
149
150 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
151
152 bool advancedBlendEquationSupport() const {
153 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
154 }
155
156 bool advancedCoherentBlendEquationSupport() const {
157 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
158 }
159
cdalton1dd05422015-06-12 09:01:18 -0700160 bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
161 SkASSERT(GrBlendEquationIsAdvanced(equation));
162 return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
163 }
164
cdalton8917d622015-05-06 13:40:21 -0700165 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000166 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
167 * textures allows partial mappings or full mappings.
168 */
169 enum MapFlags {
170 kNone_MapFlags = 0x0, //<! Cannot map the resource.
171
172 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
173 // the other flags to have meaning.k
174 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
175 };
176
177 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
178
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000179 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000180 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000181 // recycled in the texture cache. This is to prevent ghosting by drivers
182 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000183 bool reuseScratchTextures() const { return fReuseScratchTextures; }
robertphillips1b8e1b52015-06-24 06:54:10 -0700184 bool reuseScratchBuffers() const { return fReuseScratchBuffers; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000185
186 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
187 int maxTextureSize() const { return fMaxTextureSize; }
bsalomonc59a1df2015-06-01 07:13:42 -0700188 /** 0 unless GPU has problems with small textures */
189 int minTextureSize() const { return fMinTextureSize; }
190
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000191 // Will be 0 if MSAA is not supported
192 int maxSampleCount() const { return fMaxSampleCount; }
193
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000194 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000195 SkASSERT(kGrPixelConfigCnt > config);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000196 return fConfigRenderSupport[config][withMSAA];
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000197 }
198
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000199 bool isConfigTexturable(GrPixelConfig config) const {
200 SkASSERT(kGrPixelConfigCnt > config);
201 return fConfigTextureSupport[config];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000202 }
203
bsalomon682c2692015-05-22 14:01:46 -0700204 bool suppressPrints() const { return fSupressPrints; }
205
206 bool drawPathMasksToCompressedTexturesSupport() const {
joshualitt7224c862015-05-29 06:46:47 -0700207 return fDrawPathMasksToCompressedTextureSupport;
208 }
209
210 size_t geometryBufferMapThreshold() const {
joshualitte5b74c62015-06-01 14:17:47 -0700211 SkASSERT(fGeometryBufferMapThreshold >= 0);
joshualitt7224c862015-05-29 06:46:47 -0700212 return fGeometryBufferMapThreshold;
213 }
bsalomon682c2692015-05-22 14:01:46 -0700214
joshualitt58001552015-06-26 12:46:36 -0700215 bool supportsInstancedDraws() const {
216 return fSupportsInstancedDraws;
217 }
218
egdaniel51c8d402015-08-06 10:54:13 -0700219 bool fullClearIsFree() const { return fFullClearIsFree; }
220
bsalomon7dea7b72015-08-19 08:26:51 -0700221 /** True in environments that will issue errors if memory uploaded to buffers
222 is not initialized (even if not read by draw calls). */
223 bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
224
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000225protected:
bsalomon4ee6bd82015-05-27 13:23:23 -0700226 /** Subclasses must call this at the end of their constructors in order to apply caps
227 overrides requested by the client. Note that overrides will only reduce the caps never
228 expand them. */
229 void applyOptionsOverrides(const GrContextOptions& options);
230
jvanverthe9c0fc62015-04-29 11:18:05 -0700231 SkAutoTUnref<GrShaderCaps> fShaderCaps;
232
joshualitt83bc2292015-06-18 14:18:02 -0700233 bool fNPOTTextureTileSupport : 1;
234 bool fMipMapSupport : 1;
235 bool fTwoSidedStencilSupport : 1;
236 bool fStencilWrapOpsSupport : 1;
237 bool fDiscardRenderTargetSupport : 1;
238 bool fReuseScratchTextures : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700239 bool fReuseScratchBuffers : 1;
joshualitt83bc2292015-06-18 14:18:02 -0700240 bool fGpuTracingSupport : 1;
241 bool fCompressedTexSubImageSupport : 1;
242 bool fOversizedStencilSupport : 1;
243 bool fTextureBarrierSupport : 1;
joshualitt58001552015-06-26 12:46:36 -0700244 bool fSupportsInstancedDraws : 1;
egdaniel51c8d402015-08-06 10:54:13 -0700245 bool fFullClearIsFree : 1;
bsalomon7dea7b72015-08-19 08:26:51 -0700246 bool fMustClearUploadedBufferData : 1;
robertphillips1b8e1b52015-06-24 06:54:10 -0700247
bsalomon63b21962014-11-05 07:05:34 -0800248 // Driver workaround
joshualitt83bc2292015-06-18 14:18:02 -0700249 bool fUseDrawInsteadOfClear : 1;
250 bool fUseDrawInsteadOfPartialRenderTargetWrite : 1;
bsalomon63b21962014-11-05 07:05:34 -0800251
cdalton8917d622015-05-06 13:40:21 -0700252 BlendEquationSupport fBlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -0700253 uint32_t fAdvBlendEqBlacklist;
254 GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
255
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000256 uint32_t fMapBufferFlags;
joshualitte5b74c62015-06-01 14:17:47 -0700257 int fGeometryBufferMapThreshold;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000258
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000259 int fMaxRenderTargetSize;
260 int fMaxTextureSize;
bsalomonc59a1df2015-06-01 07:13:42 -0700261 int fMinTextureSize;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000262 int fMaxSampleCount;
263
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000264 // The first entry for each config is without msaa and the second is with.
265 bool fConfigRenderSupport[kGrPixelConfigCnt][2];
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000266 bool fConfigTextureSupport[kGrPixelConfigCnt];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000267
egdanielbc127a32014-09-19 12:07:43 -0700268private:
bsalomon682c2692015-05-22 14:01:46 -0700269 bool fSupressPrints : 1;
270 bool fDrawPathMasksToCompressedTextureSupport : 1;
271
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000272 typedef SkRefCnt INHERITED;
273};
274
275#endif