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@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 8 | #ifndef GrDrawTargetCaps_DEFINED |
| 9 | #define GrDrawTargetCaps_DEFINED |
| 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 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 17 | /** |
| 18 | * Represents the draw target capabilities. |
| 19 | */ |
| 20 | class GrDrawTargetCaps : public SkRefCnt { |
| 21 | public: |
bungeman | d6aeb6d | 2014-07-25 11:52:47 -0700 | [diff] [blame] | 22 | SK_DECLARE_INST_COUNT(GrDrawTargetCaps) |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 23 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 24 | /** 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] | 25 | is relevant to a float (or vecNf) variable declared with a GrSLPrecision |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 26 | 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; |
| 47 | /** Number of bits of precision. As defined in OpenGL (with names modified to reflect this |
| 48 | struct) : |
| 49 | """ |
| 50 | 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 | """ |
| 54 | */ |
| 55 | int fBits; |
| 56 | }; |
| 57 | |
| 58 | |
egdaniel | 9665eee | 2015-03-26 10:13:05 -0700 | [diff] [blame] | 59 | GrDrawTargetCaps() { |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 60 | this->reset(); |
| 61 | } |
egdaniel | 9665eee | 2015-03-26 10:13:05 -0700 | [diff] [blame] | 62 | GrDrawTargetCaps(const GrDrawTargetCaps& other) : INHERITED() { |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 63 | *this = other; |
| 64 | } |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 65 | GrDrawTargetCaps& operator= (const GrDrawTargetCaps&); |
| 66 | |
| 67 | virtual void reset(); |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 68 | virtual SkString dump() const; |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 69 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 70 | bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; } |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 71 | /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g. |
| 72 | only for POT textures) */ |
| 73 | bool mipMapSupport() const { return fMipMapSupport; } |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 74 | bool twoSidedStencilSupport() const { return fTwoSidedStencilSupport; } |
| 75 | bool stencilWrapOpsSupport() const { return fStencilWrapOpsSupport; } |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 76 | bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; } |
| 77 | bool geometryShaderSupport() const { return fGeometryShaderSupport; } |
| 78 | bool dualSourceBlendingSupport() const { return fDualSourceBlendingSupport; } |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 79 | bool pathRenderingSupport() const { return fPathRenderingSupport; } |
bsalomon@google.com | 6b0cf02 | 2013-05-03 13:35:14 +0000 | [diff] [blame] | 80 | bool dstReadInShaderSupport() const { return fDstReadInShaderSupport; } |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 81 | bool discardRenderTargetSupport() const { return fDiscardRenderTargetSupport; } |
egdaniel | bdad9c3 | 2015-03-05 12:19:17 -0800 | [diff] [blame] | 82 | #if GR_FORCE_GPU_TRACE_DEBUGGING |
| 83 | bool gpuTracingSupport() const { return true; } |
| 84 | #else |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 85 | bool gpuTracingSupport() const { return fGpuTracingSupport; } |
egdaniel | bdad9c3 | 2015-03-05 12:19:17 -0800 | [diff] [blame] | 86 | #endif |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 87 | bool compressedTexSubImageSupport() const { return fCompressedTexSubImageSupport; } |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 88 | bool oversizedStencilSupport() const { return fOversizedStencilSupport; } |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 89 | bool textureBarrierSupport() const { return fTextureBarrierSupport; } |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 90 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 91 | bool useDrawInsteadOfClear() const { return fUseDrawInsteadOfClear; } |
| 92 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 93 | /** |
| 94 | * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and |
| 95 | * textures allows partial mappings or full mappings. |
| 96 | */ |
| 97 | enum MapFlags { |
| 98 | kNone_MapFlags = 0x0, //<! Cannot map the resource. |
| 99 | |
| 100 | kCanMap_MapFlag = 0x1, //<! The resource can be mapped. Must be set for any of |
| 101 | // the other flags to have meaning.k |
| 102 | kSubset_MapFlag = 0x2, //<! The resource can be partially mapped. |
| 103 | }; |
| 104 | |
| 105 | uint32_t mapBufferFlags() const { return fMapBufferFlags; } |
| 106 | |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 107 | // Scratch textures not being reused means that those scratch textures |
skia.committer@gmail.com | 7ed98df | 2013-10-31 07:01:53 +0000 | [diff] [blame] | 108 | // 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] | 109 | // recycled in the texture cache. This is to prevent ghosting by drivers |
| 110 | // (in particular for deferred architectures). |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 111 | bool reuseScratchTextures() const { return fReuseScratchTextures; } |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 112 | |
| 113 | int maxRenderTargetSize() const { return fMaxRenderTargetSize; } |
| 114 | int maxTextureSize() const { return fMaxTextureSize; } |
| 115 | // Will be 0 if MSAA is not supported |
| 116 | int maxSampleCount() const { return fMaxSampleCount; } |
| 117 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 118 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const { |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 119 | SkASSERT(kGrPixelConfigCnt > config); |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 120 | return fConfigRenderSupport[config][withMSAA]; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 121 | } |
| 122 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 123 | bool isConfigTexturable(GrPixelConfig config) const { |
| 124 | SkASSERT(kGrPixelConfigCnt > config); |
| 125 | return fConfigTextureSupport[config]; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 126 | } |
| 127 | |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 128 | /** |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 129 | * Get the precision info for a variable of type kFloat_GrSLType, kVec2f_GrSLType, etc in a |
| 130 | * given shader type. If the shader type is not supported or the precision level is not |
| 131 | * supported in that shader type then the returned struct will report false when supported() is |
| 132 | * called. |
| 133 | */ |
| 134 | const PrecisionInfo& getFloatShaderPrecisionInfo(GrShaderType shaderType, |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 135 | GrSLPrecision precision) const { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 136 | return fFloatPrecisions[shaderType][precision]; |
| 137 | }; |
| 138 | |
| 139 | /** |
| 140 | * Is there any difference between the float shader variable precision types? If this is true |
| 141 | * then unless the shader type is not supported, any call to getFloatShaderPrecisionInfo() would |
| 142 | * report the same info for all precisions in all shader types. |
| 143 | */ |
| 144 | bool floatPrecisionVaries() const { return fShaderPrecisionVaries; } |
| 145 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 146 | protected: |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 147 | bool fNPOTTextureTileSupport : 1; |
| 148 | bool fMipMapSupport : 1; |
| 149 | bool fTwoSidedStencilSupport : 1; |
| 150 | bool fStencilWrapOpsSupport : 1; |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 151 | bool fShaderDerivativeSupport : 1; |
| 152 | bool fGeometryShaderSupport : 1; |
| 153 | bool fDualSourceBlendingSupport : 1; |
| 154 | bool fPathRenderingSupport : 1; |
| 155 | bool fDstReadInShaderSupport : 1; |
| 156 | bool fDiscardRenderTargetSupport : 1; |
| 157 | bool fReuseScratchTextures : 1; |
| 158 | bool fGpuTracingSupport : 1; |
| 159 | bool fCompressedTexSubImageSupport : 1; |
| 160 | bool fOversizedStencilSupport : 1; |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 161 | bool fTextureBarrierSupport : 1; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 162 | // Driver workaround |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 163 | bool fUseDrawInsteadOfClear : 1; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 164 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 165 | uint32_t fMapBufferFlags; |
| 166 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 167 | int fMaxRenderTargetSize; |
| 168 | int fMaxTextureSize; |
| 169 | int fMaxSampleCount; |
| 170 | |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 171 | // The first entry for each config is without msaa and the second is with. |
| 172 | bool fConfigRenderSupport[kGrPixelConfigCnt][2]; |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 173 | bool fConfigTextureSupport[kGrPixelConfigCnt]; |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 174 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 175 | bool fShaderPrecisionVaries; |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 176 | PrecisionInfo fFloatPrecisions[kGrShaderTypeCount][kGrSLPrecisionCount]; |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 177 | |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 178 | private: |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 179 | typedef SkRefCnt INHERITED; |
| 180 | }; |
| 181 | |
| 182 | #endif |