blob: be62d8a851972a8cd1182852e34a430696264a46 [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"
13#include "GrShaderVar.h"
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +000014#include "SkRefCnt.h"
15#include "SkString.h"
16
bsalomon682c2692015-05-22 14:01:46 -070017struct GrContextOptions;
18
jvanverthe9c0fc62015-04-29 11:18:05 -070019class GrShaderCaps : public SkRefCnt {
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000020public:
jvanverthe9c0fc62015-04-29 11:18:05 -070021 SK_DECLARE_INST_COUNT(GrShaderCaps)
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000022
bsalomon17168df2014-12-09 09:00:49 -080023 /** Info about shader variable precision within a given shader stage. That is, this info
bsalomonc0bd6482014-12-09 10:04:14 -080024 is relevant to a float (or vecNf) variable declared with a GrSLPrecision
bsalomon17168df2014-12-09 09:00:49 -080025 in a given GrShaderType. The info here is hoisted from the OpenGL spec. */
26 struct PrecisionInfo {
27 PrecisionInfo() {
28 fLogRangeLow = 0;
29 fLogRangeHigh = 0;
30 fBits = 0;
31 }
32
33 /** Is this precision level allowed in the shader stage? */
34 bool supported() const { return 0 != fBits; }
35
36 bool operator==(const PrecisionInfo& that) const {
37 return fLogRangeLow == that.fLogRangeLow && fLogRangeHigh == that.fLogRangeHigh &&
38 fBits == that.fBits;
39 }
40 bool operator!=(const PrecisionInfo& that) const { return !(*this == that); }
41
42 /** floor(log2(|min_value|)) */
43 int fLogRangeLow;
44 /** floor(log2(|max_value|)) */
45 int fLogRangeHigh;
jvanverthe9c0fc62015-04-29 11:18:05 -070046 /** Number of bits of precision. As defined in OpenGL (with names modified to reflect this
bsalomon17168df2014-12-09 09:00:49 -080047 struct) :
48 """
jvanverthe9c0fc62015-04-29 11:18:05 -070049 If the smallest representable value greater than 1 is 1 + e, then fBits will
50 contain floor(log2(e)), and every value in the range [2^fLogRangeLow,
51 2^fLogRangeHigh] can be represented to at least one part in 2^fBits.
52 """
bsalomon17168df2014-12-09 09:00:49 -080053 */
54 int fBits;
55 };
56
bsalomon424cc262015-05-22 10:37:30 -070057 GrShaderCaps();
jvanverthe9c0fc62015-04-29 11:18:05 -070058
jvanverthe9c0fc62015-04-29 11:18:05 -070059 virtual SkString dump() const;
60
61 bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
62 bool geometryShaderSupport() const { return fGeometryShaderSupport; }
63 bool pathRenderingSupport() const { return fPathRenderingSupport; }
64 bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; }
65 bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; }
cdalton0edea2c2015-05-21 08:27:44 -070066 bool mixedSamplesSupport() const { return fMixedSamplesSupport; }
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,
75 GrSLPrecision precision) const {
76 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
86protected:
87 bool fShaderDerivativeSupport : 1;
88 bool fGeometryShaderSupport : 1;
89 bool fPathRenderingSupport : 1;
90 bool fDstReadInShaderSupport : 1;
91 bool fDualSourceBlendingSupport : 1;
cdalton0edea2c2015-05-21 08:27:44 -070092 bool fMixedSamplesSupport : 1;
jvanverthe9c0fc62015-04-29 11:18:05 -070093
94 bool fShaderPrecisionVaries;
95 PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount];
96
97private:
98 typedef SkRefCnt INHERITED;
99};
100
101/**
bsalomon4b91f762015-05-19 09:29:46 -0700102 * Represents the capabilities of a GrContext.
jvanverthe9c0fc62015-04-29 11:18:05 -0700103 */
bsalomon4b91f762015-05-19 09:29:46 -0700104class GrCaps : public SkRefCnt {
jvanverthe9c0fc62015-04-29 11:18:05 -0700105public:
bsalomon4b91f762015-05-19 09:29:46 -0700106 SK_DECLARE_INST_COUNT(GrCaps)
bsalomon17168df2014-12-09 09:00:49 -0800107
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; }
egdanielbdad9c32015-03-05 12:19:17 -0800121#if GR_FORCE_GPU_TRACE_DEBUGGING
122 bool gpuTracingSupport() const { return true; }
123#else
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000124 bool gpuTracingSupport() const { return fGpuTracingSupport; }
egdanielbdad9c32015-03-05 12:19:17 -0800125#endif
krajcevski786978162014-07-30 11:25:44 -0700126 bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; }
bsalomond08ea5f2015-02-20 06:58:13 -0800127 bool oversizedStencilSupport() const { return fOversizedStencilSupport; }
cdaltonfd4167d2015-04-21 11:45:56 -0700128 bool textureBarrierSupport() const { return fTextureBarrierSupport; }
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000129
bsalomon63b21962014-11-05 07:05:34 -0800130 bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; }
131
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000132 /**
cdalton8917d622015-05-06 13:40:21 -0700133 * Indicates the capabilities of the fixed function blend unit.
134 */
135 enum BlendEquationSupport {
136 kBasic_BlendEquationSupport, //<! Support to select the operator that
137 // combines src and dst terms.
138 kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific
139 // SVG/PDF blend modes. Requires blend barriers.
140 kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not
141 // require blend barriers, and permits overlap.
142
143 kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport
144 };
145
146 BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; }
147
148 bool advancedBlendEquationSupport() const {
149 return fBlendEquationSupport >= kAdvanced_BlendEquationSupport;
150 }
151
152 bool advancedCoherentBlendEquationSupport() const {
153 return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport;
154 }
155
156 /**
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000157 * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and
158 * textures allows partial mappings or full mappings.
159 */
160 enum MapFlags {
161 kNone_MapFlags = 0x0, //<! Cannot map the resource.
162
163 kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of
164 // the other flags to have meaning.k
165 kSubset_MapFlag = 0x2, //<! The resource can be partially mapped.
166 };
167
168 uint32_t mapBufferFlags() const { return fMapBufferFlags; }
169
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000170 // Scratch textures not being reused means that those scratch textures
skia.committer@gmail.com7ed98df2013-10-31 07:01:53 +0000171 // that we upload to (i.e., don't have a render target) will not be
robertphillips@google.com2d2e5c42013-10-30 21:30:43 +0000172 // recycled in the texture cache. This is to prevent ghosting by drivers
173 // (in particular for deferred architectures).
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000174 bool reuseScratchTextures() const { return fReuseScratchTextures; }
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000175
176 int maxRenderTargetSize() const { return fMaxRenderTargetSize; }
177 int maxTextureSize() const { return fMaxTextureSize; }
178 // Will be 0 if MSAA is not supported
179 int maxSampleCount() const { return fMaxSampleCount; }
180
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000181 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const {
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000182 SkASSERT(kGrPixelConfigCnt > config);
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000183 return fConfigRenderSupport[config][withMSAA];
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000184 }
185
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000186 bool isConfigTexturable(GrPixelConfig config) const {
187 SkASSERT(kGrPixelConfigCnt > config);
188 return fConfigTextureSupport[config];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000189 }
190
bsalomon682c2692015-05-22 14:01:46 -0700191 bool suppressPrints() const { return fSupressPrints; }
192
193 bool drawPathMasksToCompressedTexturesSupport() const {
194 return fDrawPathMasksToCompressedTextureSupport; }
195
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000196protected:
jvanverthe9c0fc62015-04-29 11:18:05 -0700197 SkAutoTUnref<GrShaderCaps> fShaderCaps;
198
bsalomond08ea5f2015-02-20 06:58:13 -0800199 bool fNPOTTextureTileSupport : 1;
200 bool fMipMapSupport : 1;
201 bool fTwoSidedStencilSupport : 1;
202 bool fStencilWrapOpsSupport : 1;
bsalomond08ea5f2015-02-20 06:58:13 -0800203 bool fDiscardRenderTargetSupport : 1;
204 bool fReuseScratchTextures : 1;
205 bool fGpuTracingSupport : 1;
206 bool fCompressedTexSubImageSupport : 1;
207 bool fOversizedStencilSupport : 1;
cdaltonfd4167d2015-04-21 11:45:56 -0700208 bool fTextureBarrierSupport : 1;
bsalomon63b21962014-11-05 07:05:34 -0800209 // Driver workaround
bsalomond08ea5f2015-02-20 06:58:13 -0800210 bool fUseDrawInsteadOfClear : 1;
bsalomon63b21962014-11-05 07:05:34 -0800211
cdalton8917d622015-05-06 13:40:21 -0700212 BlendEquationSupport fBlendEquationSupport;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000213 uint32_t fMapBufferFlags;
214
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000215 int fMaxRenderTargetSize;
216 int fMaxTextureSize;
217 int fMaxSampleCount;
218
commit-bot@chromium.org6b7938f2013-10-15 14:18:16 +0000219 // The first entry for each config is without msaa and the second is with.
220 bool fConfigRenderSupport[kGrPixelConfigCnt][2];
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000221 bool fConfigTextureSupport[kGrPixelConfigCnt];
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000222
egdanielbc127a32014-09-19 12:07:43 -0700223private:
bsalomon682c2692015-05-22 14:01:46 -0700224 bool fSupressPrints : 1;
225 bool fDrawPathMasksToCompressedTextureSupport : 1;
226
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000227 typedef SkRefCnt INHERITED;
228};
229
230#endif