bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 1 | |
| 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 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame^] | 8 | #ifndef GrCaps_DEFINED |
| 9 | #define GrCaps_DEFINED |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 10 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 11 | #include "GrTypes.h" |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 12 | #include "GrTypesPriv.h" |
| 13 | #include "GrShaderVar.h" |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 14 | #include "SkRefCnt.h" |
| 15 | #include "SkString.h" |
| 16 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 17 | class GrShaderCaps : public SkRefCnt { |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 18 | public: |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 19 | SK_DECLARE_INST_COUNT(GrShaderCaps) |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 20 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 21 | /** Info about shader variable precision within a given shader stage. That is, this info |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 22 | is relevant to a float (or vecNf) variable declared with a GrSLPrecision |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 23 | in a given GrShaderType. The info here is hoisted from the OpenGL spec. */ |
| 24 | struct PrecisionInfo { |
| 25 | PrecisionInfo() { |
| 26 | fLogRangeLow = 0; |
| 27 | fLogRangeHigh = 0; |
| 28 | fBits = 0; |
| 29 | } |
| 30 | |
| 31 | /** Is this precision level allowed in the shader stage? */ |
| 32 | bool supported() const { return 0 != fBits; } |
| 33 | |
| 34 | bool operator==(const PrecisionInfo& that) const { |
| 35 | return fLogRangeLow == that.fLogRangeLow && fLogRangeHigh == that.fLogRangeHigh && |
| 36 | fBits == that.fBits; |
| 37 | } |
| 38 | bool operator!=(const PrecisionInfo& that) const { return !(*this == that); } |
| 39 | |
| 40 | /** floor(log2(|min_value|)) */ |
| 41 | int fLogRangeLow; |
| 42 | /** floor(log2(|max_value|)) */ |
| 43 | int fLogRangeHigh; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 44 | /** Number of bits of precision. As defined in OpenGL (with names modified to reflect this |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 45 | struct) : |
| 46 | """ |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 47 | If the smallest representable value greater than 1 is 1 + e, then fBits will |
| 48 | contain floor(log2(e)), and every value in the range [2^fLogRangeLow, |
| 49 | 2^fLogRangeHigh] can be represented to at least one part in 2^fBits. |
| 50 | """ |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 51 | */ |
| 52 | int fBits; |
| 53 | }; |
| 54 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 55 | GrShaderCaps() { |
| 56 | this->reset(); |
| 57 | } |
| 58 | virtual ~GrShaderCaps() {} |
| 59 | GrShaderCaps(const GrShaderCaps& other) : INHERITED() { |
| 60 | *this = other; |
| 61 | } |
| 62 | GrShaderCaps& operator= (const GrShaderCaps&); |
| 63 | |
| 64 | virtual void reset(); |
| 65 | virtual SkString dump() const; |
| 66 | |
| 67 | bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; } |
| 68 | bool geometryShaderSupport() const { return fGeometryShaderSupport; } |
| 69 | bool pathRenderingSupport() const { return fPathRenderingSupport; } |
| 70 | bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; } |
| 71 | bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; } |
| 72 | |
| 73 | /** |
| 74 | * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a |
| 75 | * given shader type. If the shader type is not supported or the precision level is not |
| 76 | * supported in that shader type then the returned struct will report false when supported() is |
| 77 | * called. |
| 78 | */ |
| 79 | const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType, |
| 80 | GrSLPrecision precision) const { |
| 81 | return fFloatPrecisions[shaderType][precision]; |
| 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * Is there any difference between the float shader variable precision types? If this is true |
| 86 | * then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would |
| 87 | * report the same info for all precisions in all shader types. |
| 88 | */ |
| 89 | bool floatPrecisionVaries() const { return fShaderPrecisionVaries; } |
| 90 | |
| 91 | protected: |
| 92 | bool fShaderDerivativeSupport : 1; |
| 93 | bool fGeometryShaderSupport : 1; |
| 94 | bool fPathRenderingSupport : 1; |
| 95 | bool fDstReadInShaderSupport : 1; |
| 96 | bool fDualSourceBlendingSupport : 1; |
| 97 | |
| 98 | bool fShaderPrecisionVaries; |
| 99 | PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount]; |
| 100 | |
| 101 | private: |
| 102 | typedef SkRefCnt INHERITED; |
| 103 | }; |
| 104 | |
| 105 | /** |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame^] | 106 | * Represents the capabilities of a GrContext. |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 107 | */ |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame^] | 108 | class GrCaps : public SkRefCnt { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 109 | public: |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame^] | 110 | SK_DECLARE_INST_COUNT(GrCaps) |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 111 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame^] | 112 | GrCaps() { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 113 | fShaderCaps.reset(NULL); |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 114 | this->reset(); |
| 115 | } |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame^] | 116 | GrCaps(const GrCaps& other) : INHERITED() { |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 117 | *this = other; |
| 118 | } |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame^] | 119 | virtual ~GrCaps() {} |
| 120 | GrCaps& operator= (const GrCaps&); |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 121 | |
| 122 | virtual void reset(); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 123 | virtual SkString dump() const; |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 124 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 125 | GrShaderCaps* shaderCaps() const { return fShaderCaps; } |
| 126 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 127 | bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; } |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 128 | /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g. |
| 129 | only for POT textures) */ |
| 130 | bool mipMapSupport() const { return fMipMapSupport; } |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 131 | bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; } |
| 132 | bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; } |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 133 | bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; } |
egdaniel | bdad9c3 | 2015-03-05 12:19:17 -0800 | [diff] [blame] | 134 | #if GR_FORCE_GPU_TRACE_DEBUGGING |
| 135 | bool gpuTracingSupport() const { return true; } |
| 136 | #else |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 137 | bool gpuTracingSupport() const { return fGpuTracingSupport; } |
egdaniel | bdad9c3 | 2015-03-05 12:19:17 -0800 | [diff] [blame] | 138 | #endif |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 139 | bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; } |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 140 | bool oversizedStencilSupport() const { return fOversizedStencilSupport; } |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 141 | bool textureBarrierSupport() const { return fTextureBarrierSupport; } |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 142 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 143 | bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; } |
| 144 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 145 | /** |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 146 | * Indicates the capabilities of the fixed function blend unit. |
| 147 | */ |
| 148 | enum BlendEquationSupport { |
| 149 | kBasic_BlendEquationSupport, //<! Support to select the operator that |
| 150 | // combines src and dst terms. |
| 151 | kAdvanced_BlendEquationSupport, //<! Additional fixed function support for specific |
| 152 | // SVG/PDF blend modes. Requires blend barriers. |
| 153 | kAdvancedCoherent_BlendEquationSupport, //<! Advanced blend equation support that does not |
| 154 | // require blend barriers, and permits overlap. |
| 155 | |
| 156 | kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport |
| 157 | }; |
| 158 | |
| 159 | BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; } |
| 160 | |
| 161 | bool advancedBlendEquationSupport() const { |
| 162 | return fBlendEquationSupport >= kAdvanced_BlendEquationSupport; |
| 163 | } |
| 164 | |
| 165 | bool advancedCoherentBlendEquationSupport() const { |
| 166 | return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport; |
| 167 | } |
| 168 | |
| 169 | /** |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 170 | * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and |
| 171 | * textures allows partial mappings or full mappings. |
| 172 | */ |
| 173 | enum MapFlags { |
| 174 | kNone_MapFlags = 0x0, //<! Cannot map the resource. |
| 175 | |
| 176 | kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of |
| 177 | // the other flags to have meaning.k |
| 178 | kSubset_MapFlag = 0x2, //<! The resource can be partially mapped. |
| 179 | }; |
| 180 | |
| 181 | uint32_t mapBufferFlags() const { return fMapBufferFlags; } |
| 182 | |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 183 | // Scratch textures not being reused means that those scratch textures |
skia.committer@gmail.com | 7ed98df | 2013-10-31 07:01:53 +0000 | [diff] [blame] | 184 | // that we upload to (i.e., don't have a render target) will not be |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 185 | // recycled in the texture cache. This is to prevent ghosting by drivers |
| 186 | // (in particular for deferred architectures). |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 187 | bool reuseScratchTextures() const { return fReuseScratchTextures; } |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 188 | |
| 189 | int maxRenderTargetSize() const { return fMaxRenderTargetSize; } |
| 190 | int maxTextureSize() const { return fMaxTextureSize; } |
| 191 | // Will be 0 if MSAA is not supported |
| 192 | int maxSampleCount() const { return fMaxSampleCount; } |
| 193 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 194 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 195 | SkASSERT(kGrPixelConfigCnt > config); |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 196 | return fConfigRenderSupport[config][withMSAA]; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 197 | } |
| 198 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 199 | bool isConfigTexturable(GrPixelConfig config) const { |
| 200 | SkASSERT(kGrPixelConfigCnt > config); |
| 201 | return fConfigTextureSupport[config]; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 202 | } |
| 203 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 204 | protected: |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 205 | SkAutoTUnref<GrShaderCaps> fShaderCaps; |
| 206 | |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 207 | bool fNPOTTextureTileSupport : 1; |
| 208 | bool fMipMapSupport : 1; |
| 209 | bool fTwoSidedStencilSupport : 1; |
| 210 | bool fStencilWrapOpsSupport : 1; |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 211 | bool fDiscardRenderTargetSupport : 1; |
| 212 | bool fReuseScratchTextures : 1; |
| 213 | bool fGpuTracingSupport : 1; |
| 214 | bool fCompressedTexSubImageSupport : 1; |
| 215 | bool fOversizedStencilSupport : 1; |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 216 | bool fTextureBarrierSupport : 1; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 217 | // Driver workaround |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 218 | bool fUseDrawInsteadOfClear : 1; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 219 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 220 | BlendEquationSupport fBlendEquationSupport; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 221 | uint32_t fMapBufferFlags; |
| 222 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 223 | int fMaxRenderTargetSize; |
| 224 | int fMaxTextureSize; |
| 225 | int fMaxSampleCount; |
| 226 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 227 | // The first entry for each config is without msaa and the second is with. |
| 228 | bool fConfigRenderSupport[kGrPixelConfigCnt][2]; |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 229 | bool fConfigTextureSupport[kGrPixelConfigCnt]; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 230 | |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 231 | private: |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 232 | typedef SkRefCnt INHERITED; |
| 233 | }; |
| 234 | |
| 235 | #endif |