blob: 54969c59333f3ad0c8e5816dde3fa72cd336f7b8 [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:
jvanverthe9c0fc62015-04-29 11:18:05 -070022 SK_DECLARE_INST_COUNT(GrShaderCaps)
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000023
bsalomon17168df2014-12-09 09:00:49 -080024 /** Info about shader variable precision within a given shader stage. That is, this info
bsalomonc0bd6482014-12-09 10:04:14 -080025 is relevant to a float (or vecNf) variable declared with a GrSLPrecision
bsalomon17168df2014-12-09 09:00:49 -080026 in a given GrShaderType. The info here is hoisted from the OpenGL spec. */
27 struct PrecisionInfo {
28 PrecisionInfo() {
29 fLogRangeLow = 0;
30 fLogRangeHigh = 0;
31 fBits = 0;
32 }
33
34 /** Is this precision level allowed in the shader stage? */
35 bool supported() const { return 0 != fBits; }
36
37 bool operator==(const PrecisionInfo& that) const {
38 return fLogRangeLow == that.fLogRangeLow && fLogRangeHigh == that.fLogRangeHigh &&
39 fBits == that.fBits;
40 }
41 bool operator!=(const PrecisionInfo& that) const { return !(*this == that); }
42
43 /** floor(log2(|min_value|)) */
44 int fLogRangeLow;
45 /** floor(log2(|max_value|)) */
46 int fLogRangeHigh;
jvanverthe9c0fc62015-04-29 11:18:05 -070047 /** Number of bits of precision. As defined in OpenGL (with names modified to reflect this
bsalomon17168df2014-12-09 09:00:49 -080048 struct) :
49 """
jvanverthe9c0fc62015-04-29 11:18:05 -070050 If the smallest representable value greater than 1 is 1 + e, then fBits will
51 contain floor(log2(e)), and every value in the range [2^fLogRangeLow,
52 2^fLogRangeHigh] can be represented to at least one part in 2^fBits.
53 """
bsalomon17168df2014-12-09 09:00:49 -080054 */
55 int fBits;
56 };
57
bsalomon424cc262015-05-22 10:37:30 -070058 GrShaderCaps();
jvanverthe9c0fc62015-04-29 11:18:05 -070059
jvanverthe9c0fc62015-04-29 11:18:05 -070060 virtual SkString dump() const;
61
62 bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
63 bool geometryShaderSupport() const { return fGeometryShaderSupport; }
64 bool pathRenderingSupport() const { return fPathRenderingSupport; }
65 bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
66 bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
cdalton0edea2c2015-05-21 08:27:44 -070067 bool mixedSamplesSupport() const { return fMixedSamplesSupport; }
jvanverthe9c0fc62015-04-29 11:18:05 -070068
69 /**
70 * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a
71 * given shader type. If the shader type is not supported or the precision level is not
72 * supported in that shader type then the returned struct will report false when supported() is
73 * called.
74 */
75 const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType,
76 GrSLPrecision precision) const {
77 return fFloatPrecisions[shaderType][precision];
78 };
79
80 /**
81 * Is there any difference between the float shader variable precision types? If this is true
82 * then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would
83 * report the same info for all precisions in all shader types.
84 */
85 bool floatPrecisionVaries() const { return fShaderPrecisionVaries; }
86
87protected:
cdalton4cd67132015-06-10 19:23:46 -070088 /** Subclasses must call this after initialization in order to apply caps overrides requested by
89 the client. Note that overrides will only reduce the caps never expand them. */
bsalomon4ee6bd82015-05-27 13:23:23 -070090 void applyOptionsOverrides(const GrContextOptions& options);
91
jvanverthe9c0fc62015-04-29 11:18:05 -070092 bool fShaderDerivativeSupport : 1;
93 bool fGeometryShaderSupport : 1;
94 bool fPathRenderingSupport : 1;
95 bool fDstReadInShaderSupport : 1;
96 bool fDualSourceBlendingSupport : 1;
cdalton0edea2c2015-05-21 08:27:44 -070097 bool fMixedSamplesSupport : 1;
jvanverthe9c0fc62015-04-29 11:18:05 -070098
99 bool fShaderPrecisionVaries;
100 PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
101
102private:
103 typedef SkRefCnt INHERITED;
104};
105
106/**
bsalomon4b91f762015-05-19 09:29:46 -0700107 * Represents the capabilities of a GrContext.
jvanverthe9c0fc62015-04-29 11:18:05 -0700108 */
bsalomon4b91f762015-05-19 09:29:46 -0700109class GrCaps : public SkRefCnt {
jvanverthe9c0fc62015-04-29 11:18:05 -0700110public:
bsalomon4b91f762015-05-19 09:29:46 -0700111 SK_DECLARE_INST_COUNT(GrCaps)
bsalomon17168df2014-12-09 09:00:49 -0800112
bsalomon682c2692015-05-22 14:01:46 -0700113 GrCaps(const GrContextOptions&);
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000114
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000115 virtual SkString dump() const;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000116
jvanverthe9c0fc62015-04-29 11:18:05 -0700117 GrShaderCaps* shaderCaps() const { return fShaderCaps; }
118
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000119 bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; }
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000120 /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g.
121 only for POT textures) */
122 bool mipMapSupport() const { return fMipMapSupport; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000123 bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; }
124 bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; }
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000125 bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; }
egdanielbdad9c32015-03-05 12:19:17 -0800126#if GR_FORCE_GPU_TRACE_DEBUGGING
127 bool gpuTracingSupport() const { return true; }
128#else
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000129 bool gpuTracingSupport() const { return fGpuTracingSupport; }
egdanielbdad9c32015-03-05 12:19:17 -0800130#endif
krajcevski786978162014-07-30 11:25:44 -0700131 bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
bsalomond08ea5f2015-02-20 06:58:13 -0800132 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
cdaltonfd4167d2015-04-21 11:45:56 -0700133 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000134
bsalomon63b21962014-11-05 07:05:34 -0800135 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
136
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000137 /**
cdalton8917d622015-05-06 13:40:21 -0700138 * Indicates the capabilities of the fixed function blend unit.
139 */
140 enum BlendEquationSupport {
141 kBasic_BlendEquationSupport, //<! Support to select the operator that
142 // combines src and dst terms.
143 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
144 // SVG/PDF blend modes. Requires blend barriers.
145 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
146 // require blend barriers, and permits overlap.
147
148 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
149 };
150
151 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
152
153 bool advancedBlendEquationSupport() const {
154 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
155 }
156
157 bool advancedCoherentBlendEquationSupport() const {
158 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
159 }
160
cdalton1dd05422015-06-12 09:01:18 -0700161 bool canUseAdvancedBlendEquation(GrBlendEquation equation) const {
162 SkASSERT(GrBlendEquationIsAdvanced(equation));
163 return SkToBool(fAdvBlendEqBlacklist & (1 << equation));
164 }
165
cdalton8917d622015-05-06 13:40:21 -0700166 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000167 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
168 * textures allows partial mappings or full mappings.
169 */
170 enum MapFlags {
171 kNone_MapFlags = 0x0, //<! Cannot map the resource.
172
173 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
174 // the other flags to have meaning.k
175 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
176 };
177
178 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
179
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000180 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000181 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000182 // recycled in the texture cache. This is to prevent ghosting by drivers
183 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000184 bool reuseScratchTextures() const { return fReuseScratchTextures; }
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
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000215protected:
bsalomon4ee6bd82015-05-27 13:23:23 -0700216 /** Subclasses must call this at the end of their constructors in order to apply caps
217 overrides requested by the client. Note that overrides will only reduce the caps never
218 expand them. */
219 void applyOptionsOverrides(const GrContextOptions& options);
220
jvanverthe9c0fc62015-04-29 11:18:05 -0700221 SkAutoTUnref<GrShaderCaps> fShaderCaps;
222
bsalomond08ea5f2015-02-20 06:58:13 -0800223 bool fNPOTTextureTileSupport : 1;
224 bool fMipMapSupport : 1;
225 bool fTwoSidedStencilSupport : 1;
226 bool fStencilWrapOpsSupport : 1;
bsalomond08ea5f2015-02-20 06:58:13 -0800227 bool fDiscardRenderTargetSupport : 1;
228 bool fReuseScratchTextures : 1;
229 bool fGpuTracingSupport : 1;
230 bool fCompressedTexSubImageSupport : 1;
231 bool fOversizedStencilSupport : 1;
cdaltonfd4167d2015-04-21 11:45:56 -0700232 bool fTextureBarrierSupport : 1;
bsalomon63b21962014-11-05 07:05:34 -0800233 // Driver workaround
bsalomond08ea5f2015-02-20 06:58:13 -0800234 bool fUseDrawInsteadOfClear : 1;
bsalomon63b21962014-11-05 07:05:34 -0800235
cdalton8917d622015-05-06 13:40:21 -0700236 BlendEquationSupport fBlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -0700237 uint32_t fAdvBlendEqBlacklist;
238 GR_STATIC_ASSERT(kLast_GrBlendEquation < 32);
239
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000240 uint32_t fMapBufferFlags;
joshualitte5b74c62015-06-01 14:17:47 -0700241 int fGeometryBufferMapThreshold;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000242
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000243 int fMaxRenderTargetSize;
244 int fMaxTextureSize;
bsalomonc59a1df2015-06-01 07:13:42 -0700245 int fMinTextureSize;
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000246 int fMaxSampleCount;
247
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000248 // The first entry for each config is without msaa and the second is with.
249 bool fConfigRenderSupport[kGrPixelConfigCnt][2];
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000250 bool fConfigTextureSupport[kGrPixelConfigCnt];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000251
egdanielbc127a32014-09-19 12:07:43 -0700252private:
bsalomon682c2692015-05-22 14:01:46 -0700253 bool fSupressPrints : 1;
254 bool fDrawPathMasksToCompressedTextureSupport : 1;
255
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000256 typedef SkRefCnt INHERITED;
257};
258
259#endif