commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrTypesPriv_DEFINED |
| 9 | #define GrTypesPriv_DEFINED |
| 10 | |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 11 | #include <chrono> |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 12 | #include "GrTypes.h" |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 13 | #include "SkRefCnt.h" |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 14 | |
Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame^] | 15 | class GrCaps; |
| 16 | |
Brian Salomon | 5e15085 | 2017-03-22 14:53:13 -0400 | [diff] [blame] | 17 | // The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might |
| 18 | // not actually be monotonic, depending on how libstdc++ was built. However, this is only currently |
| 19 | // used for idle resource purging so it shouldn't cause a correctness problem. |
| 20 | #if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000) |
| 21 | using GrStdSteadyClock = std::chrono::monotonic_clock; |
| 22 | #else |
| 23 | using GrStdSteadyClock = std::chrono::steady_clock; |
| 24 | #endif |
| 25 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 26 | /** This enum indicates the type of antialiasing to be performed. */ |
Brian Salomon | af9847e | 2017-03-01 11:28:27 -0500 | [diff] [blame] | 27 | enum class GrAAType : unsigned { |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 28 | /** No antialiasing */ |
| 29 | kNone, |
| 30 | /** Use fragment shader code to compute a fractional pixel coverage. */ |
| 31 | kCoverage, |
| 32 | /** Use normal MSAA. */ |
| 33 | kMSAA, |
| 34 | /** |
| 35 | * Use "mixed samples" MSAA such that the stencil buffer is multisampled but the color buffer is |
| 36 | * not. |
| 37 | */ |
| 38 | kMixedSamples |
| 39 | }; |
| 40 | |
Brian Salomon | 0abc8b4 | 2016-12-13 10:22:54 -0500 | [diff] [blame] | 41 | static inline bool GrAATypeIsHW(GrAAType type) { |
| 42 | switch (type) { |
| 43 | case GrAAType::kNone: |
| 44 | return false; |
| 45 | case GrAAType::kCoverage: |
| 46 | return false; |
| 47 | case GrAAType::kMSAA: |
| 48 | return true; |
| 49 | case GrAAType::kMixedSamples: |
| 50 | return true; |
| 51 | } |
| 52 | SkFAIL("Unknown AA Type"); |
| 53 | return false; |
| 54 | } |
| 55 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 56 | /** The type of full scene antialiasing supported by a render target. */ |
| 57 | enum class GrFSAAType { |
| 58 | /** No FSAA */ |
| 59 | kNone, |
| 60 | /** Regular MSAA where each attachment has the same sample count. */ |
| 61 | kUnifiedMSAA, |
| 62 | /** One color sample, N stencil samples. */ |
| 63 | kMixedSamples, |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * Not all drawing code paths support using mixed samples when available and instead use |
| 68 | * coverage-based aa. |
| 69 | */ |
| 70 | enum class GrAllowMixedSamples { kNo, kYes }; |
| 71 | |
Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame^] | 72 | GrAAType GrChooseAAType(GrAA, GrFSAAType, GrAllowMixedSamples, const GrCaps&); |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 73 | |
Brian Salomon | 0abc8b4 | 2016-12-13 10:22:54 -0500 | [diff] [blame] | 74 | /** |
| 75 | * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars, |
| 76 | * but should be applicable to other shader languages.) |
| 77 | */ |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 78 | enum GrSLType { |
| 79 | kVoid_GrSLType, |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 80 | kBool_GrSLType, |
| 81 | kInt_GrSLType, |
| 82 | kUint_GrSLType, |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 83 | kFloat_GrSLType, |
| 84 | kVec2f_GrSLType, |
| 85 | kVec3f_GrSLType, |
| 86 | kVec4f_GrSLType, |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 87 | kVec2i_GrSLType, |
| 88 | kVec3i_GrSLType, |
| 89 | kVec4i_GrSLType, |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 90 | kMat22f_GrSLType, |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 91 | kMat33f_GrSLType, |
| 92 | kMat44f_GrSLType, |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 93 | kTexture2DSampler_GrSLType, |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 94 | kITexture2DSampler_GrSLType, |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 95 | kTextureExternalSampler_GrSLType, |
| 96 | kTexture2DRectSampler_GrSLType, |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame] | 97 | kBufferSampler_GrSLType, |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 98 | kTexture2D_GrSLType, |
| 99 | kSampler_GrSLType, |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 100 | kImageStorage2D_GrSLType, |
| 101 | kIImageStorage2D_GrSLType, |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 104 | enum GrShaderType { |
| 105 | kVertex_GrShaderType, |
| 106 | kGeometry_GrShaderType, |
| 107 | kFragment_GrShaderType, |
| 108 | |
| 109 | kLastkFragment_GrShaderType = kFragment_GrShaderType |
| 110 | }; |
| 111 | static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1; |
| 112 | |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 113 | enum GrShaderFlags { |
| 114 | kNone_GrShaderFlags = 0, |
| 115 | kVertex_GrShaderFlag = 1 << kVertex_GrShaderType, |
| 116 | kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType, |
| 117 | kFragment_GrShaderFlag = 1 << kFragment_GrShaderType |
| 118 | }; |
| 119 | GR_MAKE_BITFIELD_OPS(GrShaderFlags); |
| 120 | |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 121 | /** |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 122 | * Precisions of shader language variables. Not all shading languages support precisions or actually |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 123 | * vary the internal precision based on the qualifiers. These currently only apply to float types ( |
| 124 | * including float vectors and matrices). |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 125 | */ |
| 126 | enum GrSLPrecision { |
| 127 | kLow_GrSLPrecision, |
| 128 | kMedium_GrSLPrecision, |
| 129 | kHigh_GrSLPrecision, |
| 130 | |
Brian Osman | 33aa2c7 | 2017-04-05 09:26:15 -0400 | [diff] [blame] | 131 | // Default precision is a special tag that means "whatever the default for the program/type |
| 132 | // combination is". In other words, it maps to the empty string in shader code. There are some |
| 133 | // scenarios where kDefault is not allowed (as the default precision for a program, or for |
| 134 | // varyings, for example). |
| 135 | kDefault_GrSLPrecision, |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 136 | |
Brian Osman | 33aa2c7 | 2017-04-05 09:26:15 -0400 | [diff] [blame] | 137 | // We only consider the "real" precisions here |
| 138 | kLast_GrSLPrecision = kHigh_GrSLPrecision, |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; |
| 142 | |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 143 | /** Is the shading language type float (including vectors/matrices)? */ |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 144 | static inline bool GrSLTypeIsFloatType(GrSLType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 145 | switch (type) { |
| 146 | case kFloat_GrSLType: |
| 147 | case kVec2f_GrSLType: |
| 148 | case kVec3f_GrSLType: |
| 149 | case kVec4f_GrSLType: |
| 150 | case kMat22f_GrSLType: |
| 151 | case kMat33f_GrSLType: |
| 152 | case kMat44f_GrSLType: |
| 153 | return true; |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 154 | |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 155 | case kVoid_GrSLType: |
| 156 | case kTexture2DSampler_GrSLType: |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 157 | case kITexture2DSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 158 | case kTextureExternalSampler_GrSLType: |
| 159 | case kTexture2DRectSampler_GrSLType: |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame] | 160 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 161 | case kBool_GrSLType: |
| 162 | case kInt_GrSLType: |
| 163 | case kUint_GrSLType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 164 | case kVec2i_GrSLType: |
| 165 | case kVec3i_GrSLType: |
| 166 | case kVec4i_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 167 | case kTexture2D_GrSLType: |
| 168 | case kSampler_GrSLType: |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 169 | case kImageStorage2D_GrSLType: |
| 170 | case kIImageStorage2D_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 171 | return false; |
| 172 | } |
| 173 | SkFAIL("Unexpected type"); |
| 174 | return false; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 175 | } |
| 176 | |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 177 | static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 178 | switch (type) { |
| 179 | case kTexture2DSampler_GrSLType: |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 180 | case kITexture2DSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 181 | case kTextureExternalSampler_GrSLType: |
| 182 | case kTexture2DRectSampler_GrSLType: |
| 183 | return true; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 184 | |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 185 | case kVoid_GrSLType: |
| 186 | case kFloat_GrSLType: |
| 187 | case kVec2f_GrSLType: |
| 188 | case kVec3f_GrSLType: |
| 189 | case kVec4f_GrSLType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 190 | case kVec2i_GrSLType: |
| 191 | case kVec3i_GrSLType: |
| 192 | case kVec4i_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 193 | case kMat22f_GrSLType: |
| 194 | case kMat33f_GrSLType: |
| 195 | case kMat44f_GrSLType: |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame] | 196 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 197 | case kInt_GrSLType: |
| 198 | case kUint_GrSLType: |
| 199 | case kBool_GrSLType: |
| 200 | case kTexture2D_GrSLType: |
| 201 | case kSampler_GrSLType: |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 202 | case kImageStorage2D_GrSLType: |
| 203 | case kIImageStorage2D_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | SkFAIL("Unexpected type"); |
| 207 | return false; |
egdaniel | fa89632 | 2016-01-13 12:19:30 -0800 | [diff] [blame] | 208 | } |
| 209 | |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 210 | static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 211 | switch (type) { |
| 212 | case kTexture2DSampler_GrSLType: |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 213 | case kITexture2DSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 214 | case kTextureExternalSampler_GrSLType: |
| 215 | case kTexture2DRectSampler_GrSLType: |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame] | 216 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 217 | return true; |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 218 | |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 219 | case kVoid_GrSLType: |
| 220 | case kFloat_GrSLType: |
| 221 | case kVec2f_GrSLType: |
| 222 | case kVec3f_GrSLType: |
| 223 | case kVec4f_GrSLType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 224 | case kVec2i_GrSLType: |
| 225 | case kVec3i_GrSLType: |
| 226 | case kVec4i_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 227 | case kMat22f_GrSLType: |
| 228 | case kMat33f_GrSLType: |
| 229 | case kMat44f_GrSLType: |
| 230 | case kInt_GrSLType: |
| 231 | case kUint_GrSLType: |
| 232 | case kBool_GrSLType: |
| 233 | case kTexture2D_GrSLType: |
| 234 | case kSampler_GrSLType: |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 235 | case kImageStorage2D_GrSLType: |
| 236 | case kIImageStorage2D_GrSLType: |
| 237 | return false; |
| 238 | } |
| 239 | SkFAIL("Unexpected type"); |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | static inline bool GrSLTypeIsImageStorage(GrSLType type) { |
| 244 | switch (type) { |
| 245 | case kImageStorage2D_GrSLType: |
| 246 | case kIImageStorage2D_GrSLType: |
| 247 | return true; |
| 248 | |
| 249 | case kVoid_GrSLType: |
| 250 | case kFloat_GrSLType: |
| 251 | case kVec2f_GrSLType: |
| 252 | case kVec3f_GrSLType: |
| 253 | case kVec4f_GrSLType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 254 | case kVec2i_GrSLType: |
| 255 | case kVec3i_GrSLType: |
| 256 | case kVec4i_GrSLType: |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 257 | case kMat22f_GrSLType: |
| 258 | case kMat33f_GrSLType: |
| 259 | case kMat44f_GrSLType: |
| 260 | case kInt_GrSLType: |
| 261 | case kUint_GrSLType: |
| 262 | case kBool_GrSLType: |
| 263 | case kTexture2D_GrSLType: |
| 264 | case kSampler_GrSLType: |
| 265 | case kTexture2DSampler_GrSLType: |
| 266 | case kITexture2DSampler_GrSLType: |
| 267 | case kTextureExternalSampler_GrSLType: |
| 268 | case kTexture2DRectSampler_GrSLType: |
| 269 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 270 | return false; |
| 271 | } |
| 272 | SkFAIL("Unexpected type"); |
| 273 | return false; |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 274 | } |
| 275 | |
cdalton | 5f2d8e2 | 2016-03-11 13:34:32 -0800 | [diff] [blame] | 276 | static inline bool GrSLTypeAcceptsPrecision(GrSLType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 277 | switch (type) { |
| 278 | case kInt_GrSLType: |
| 279 | case kUint_GrSLType: |
| 280 | case kFloat_GrSLType: |
| 281 | case kVec2f_GrSLType: |
| 282 | case kVec3f_GrSLType: |
| 283 | case kVec4f_GrSLType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 284 | case kVec2i_GrSLType: |
| 285 | case kVec3i_GrSLType: |
| 286 | case kVec4i_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 287 | case kMat22f_GrSLType: |
| 288 | case kMat33f_GrSLType: |
| 289 | case kMat44f_GrSLType: |
| 290 | case kTexture2DSampler_GrSLType: |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 291 | case kITexture2DSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 292 | case kTextureExternalSampler_GrSLType: |
| 293 | case kTexture2DRectSampler_GrSLType: |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame] | 294 | case kBufferSampler_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 295 | case kTexture2D_GrSLType: |
| 296 | case kSampler_GrSLType: |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 297 | case kImageStorage2D_GrSLType: |
| 298 | case kIImageStorage2D_GrSLType: |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 299 | return true; |
| 300 | |
| 301 | case kVoid_GrSLType: |
| 302 | case kBool_GrSLType: |
| 303 | return false; |
| 304 | } |
| 305 | SkFAIL("Unexpected type"); |
| 306 | return false; |
cdalton | 5f2d8e2 | 2016-03-11 13:34:32 -0800 | [diff] [blame] | 307 | } |
| 308 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 309 | ////////////////////////////////////////////////////////////////////////////// |
| 310 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 311 | /** |
| 312 | * Types used to describe format of vertices in arrays. |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 313 | */ |
| 314 | enum GrVertexAttribType { |
| 315 | kFloat_GrVertexAttribType = 0, |
| 316 | kVec2f_GrVertexAttribType, |
| 317 | kVec3f_GrVertexAttribType, |
| 318 | kVec4f_GrVertexAttribType, |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 319 | |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 320 | kVec2i_GrVertexAttribType, // vector of 2 32-bit ints |
| 321 | kVec3i_GrVertexAttribType, // vector of 3 32-bit ints |
| 322 | kVec4i_GrVertexAttribType, // vector of 4 32-bit ints |
| 323 | |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 324 | kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage |
jvanverth | 5a105ff | 2015-02-18 11:36:35 -0800 | [diff] [blame] | 325 | kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 326 | |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 327 | kVec2us_GrVertexAttribType, // vector of 2 shorts, e.g. texture coordinates |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 328 | |
| 329 | kInt_GrVertexAttribType, |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 330 | kUint_GrVertexAttribType, |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 331 | |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 332 | kLast_GrVertexAttribType = kUint_GrVertexAttribType |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 333 | }; |
| 334 | static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; |
| 335 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * Returns the size of the attrib type in bytes. |
| 339 | */ |
| 340 | static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 341 | switch (type) { |
| 342 | case kFloat_GrVertexAttribType: |
| 343 | return sizeof(float); |
| 344 | case kVec2f_GrVertexAttribType: |
| 345 | return 2*sizeof(float); |
| 346 | case kVec3f_GrVertexAttribType: |
| 347 | return 3*sizeof(float); |
| 348 | case kVec4f_GrVertexAttribType: |
| 349 | return 4*sizeof(float); |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 350 | case kVec2i_GrVertexAttribType: |
| 351 | return 2*sizeof(int32_t); |
| 352 | case kVec3i_GrVertexAttribType: |
| 353 | return 3*sizeof(int32_t); |
| 354 | case kVec4i_GrVertexAttribType: |
| 355 | return 4*sizeof(int32_t); |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 356 | case kUByte_GrVertexAttribType: |
| 357 | return 1*sizeof(char); |
| 358 | case kVec4ub_GrVertexAttribType: |
| 359 | return 4*sizeof(char); |
| 360 | case kVec2us_GrVertexAttribType: |
| 361 | return 2*sizeof(int16_t); |
| 362 | case kInt_GrVertexAttribType: |
| 363 | return sizeof(int32_t); |
| 364 | case kUint_GrVertexAttribType: |
| 365 | return sizeof(uint32_t); |
| 366 | } |
| 367 | SkFAIL("Unexpected attribute type"); |
| 368 | return 0; |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /** |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 372 | * Is the attrib type integral? |
| 373 | */ |
| 374 | static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) { |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 375 | switch (type) { |
| 376 | case kFloat_GrVertexAttribType: |
| 377 | return false; |
| 378 | case kVec2f_GrVertexAttribType: |
| 379 | return false; |
| 380 | case kVec3f_GrVertexAttribType: |
| 381 | return false; |
| 382 | case kVec4f_GrVertexAttribType: |
| 383 | return false; |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 384 | case kVec2i_GrVertexAttribType: |
| 385 | return true; |
| 386 | case kVec3i_GrVertexAttribType: |
| 387 | return true; |
| 388 | case kVec4i_GrVertexAttribType: |
| 389 | return true; |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 390 | case kUByte_GrVertexAttribType: |
| 391 | return false; |
| 392 | case kVec4ub_GrVertexAttribType: |
| 393 | return false; |
| 394 | case kVec2us_GrVertexAttribType: |
| 395 | return false; |
| 396 | case kInt_GrVertexAttribType: |
| 397 | return true; |
| 398 | case kUint_GrVertexAttribType: |
| 399 | return true; |
| 400 | } |
| 401 | SkFAIL("Unexpected attribute type"); |
| 402 | return false; |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /** |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 406 | * converts a GrVertexAttribType to a GrSLType |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 407 | */ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 408 | static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { |
| 409 | switch (type) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 410 | case kUByte_GrVertexAttribType: |
| 411 | case kFloat_GrVertexAttribType: |
| 412 | return kFloat_GrSLType; |
jvanverth | 7023a00 | 2016-02-22 11:25:32 -0800 | [diff] [blame] | 413 | case kVec2us_GrVertexAttribType: |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 414 | case kVec2f_GrVertexAttribType: |
| 415 | return kVec2f_GrSLType; |
| 416 | case kVec3f_GrVertexAttribType: |
| 417 | return kVec3f_GrSLType; |
| 418 | case kVec4ub_GrVertexAttribType: |
| 419 | case kVec4f_GrVertexAttribType: |
| 420 | return kVec4f_GrSLType; |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 421 | case kVec2i_GrVertexAttribType: |
| 422 | return kVec2i_GrSLType; |
| 423 | case kVec3i_GrVertexAttribType: |
| 424 | return kVec3i_GrSLType; |
| 425 | case kVec4i_GrVertexAttribType: |
| 426 | return kVec4i_GrSLType; |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 427 | case kInt_GrVertexAttribType: |
| 428 | return kInt_GrSLType; |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 429 | case kUint_GrVertexAttribType: |
| 430 | return kUint_GrSLType; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 431 | } |
Brian Salomon | fa26e66 | 2016-11-14 11:27:00 -0500 | [diff] [blame] | 432 | SkFAIL("Unsupported type conversion"); |
| 433 | return kVoid_GrSLType; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 434 | } |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 435 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 436 | ////////////////////////////////////////////////////////////////////////////// |
| 437 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 438 | enum class GrImageStorageFormat { |
| 439 | kRGBA8, |
| 440 | kRGBA8i, |
| 441 | kRGBA16f, |
| 442 | kRGBA32f, |
| 443 | }; |
| 444 | |
| 445 | /** |
| 446 | * Describes types of caching and compiler optimizations allowed for certain variable types |
| 447 | * (currently only image storages). |
| 448 | **/ |
| 449 | enum class GrSLMemoryModel { |
| 450 | /** No special restrctions on memory accesses or compiler optimizations */ |
| 451 | kNone, |
| 452 | /** Cache coherent across shader invocations */ |
| 453 | kCoherent, |
| 454 | /** |
| 455 | * Disallows compiler from eliding loads or stores that appear redundant in a single |
| 456 | * invocation. Implies coherent. |
| 457 | */ |
| 458 | kVolatile |
| 459 | }; |
| 460 | |
| 461 | /** |
| 462 | * If kYes then the memory backing the varialble is only accessed via the variable. This is |
| 463 | * currently only used with image storages. |
| 464 | */ |
| 465 | enum class GrSLRestrict { |
| 466 | kYes, |
| 467 | kNo, |
| 468 | }; |
| 469 | |
| 470 | ////////////////////////////////////////////////////////////////////////////// |
| 471 | |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 472 | /** |
| 473 | * We have coverage effects that clip rendering to the edge of some geometric primitive. |
skia.committer@gmail.com | 06acb58 | 2014-03-06 03:02:32 +0000 | [diff] [blame] | 474 | * This enum specifies how that clipping is performed. Not all factories that take a |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 475 | * GrProcessorEdgeType will succeed with all values and it is up to the caller to check for |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 476 | * a NULL return. |
| 477 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 478 | enum GrPrimitiveEdgeType { |
| 479 | kFillBW_GrProcessorEdgeType, |
| 480 | kFillAA_GrProcessorEdgeType, |
| 481 | kInverseFillBW_GrProcessorEdgeType, |
| 482 | kInverseFillAA_GrProcessorEdgeType, |
| 483 | kHairlineAA_GrProcessorEdgeType, |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 484 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 485 | kLast_GrProcessorEdgeType = kHairlineAA_GrProcessorEdgeType |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 486 | }; |
| 487 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 488 | static const int kGrProcessorEdgeTypeCnt = kLast_GrProcessorEdgeType + 1; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 489 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 490 | static inline bool GrProcessorEdgeTypeIsFill(const GrPrimitiveEdgeType edgeType) { |
| 491 | return (kFillAA_GrProcessorEdgeType == edgeType || kFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 492 | } |
| 493 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 494 | static inline bool GrProcessorEdgeTypeIsInverseFill(const GrPrimitiveEdgeType edgeType) { |
| 495 | return (kInverseFillAA_GrProcessorEdgeType == edgeType || |
| 496 | kInverseFillBW_GrProcessorEdgeType == edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 497 | } |
| 498 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 499 | static inline bool GrProcessorEdgeTypeIsAA(const GrPrimitiveEdgeType edgeType) { |
| 500 | return (kFillBW_GrProcessorEdgeType != edgeType && kInverseFillBW_GrProcessorEdgeType != edgeType); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 501 | } |
| 502 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 503 | static inline GrPrimitiveEdgeType GrInvertProcessorEdgeType(const GrPrimitiveEdgeType edgeType) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 504 | switch (edgeType) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 505 | case kFillBW_GrProcessorEdgeType: |
| 506 | return kInverseFillBW_GrProcessorEdgeType; |
| 507 | case kFillAA_GrProcessorEdgeType: |
| 508 | return kInverseFillAA_GrProcessorEdgeType; |
| 509 | case kInverseFillBW_GrProcessorEdgeType: |
| 510 | return kFillBW_GrProcessorEdgeType; |
| 511 | case kInverseFillAA_GrProcessorEdgeType: |
| 512 | return kFillAA_GrProcessorEdgeType; |
| 513 | case kHairlineAA_GrProcessorEdgeType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 514 | SkFAIL("Hairline fill isn't invertible."); |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 515 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 516 | return kFillAA_GrProcessorEdgeType; // suppress warning. |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 517 | } |
| 518 | |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 519 | /** |
| 520 | * Indicates the type of pending IO operations that can be recorded for gpu resources. |
| 521 | */ |
| 522 | enum GrIOType { |
| 523 | kRead_GrIOType, |
| 524 | kWrite_GrIOType, |
| 525 | kRW_GrIOType |
| 526 | }; |
| 527 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 528 | /** |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 529 | * Indicates the type of data that a GPU buffer will be used for. |
| 530 | */ |
| 531 | enum GrBufferType { |
| 532 | kVertex_GrBufferType, |
| 533 | kIndex_GrBufferType, |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 534 | kTexel_GrBufferType, |
| 535 | kDrawIndirect_GrBufferType, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 536 | kXferCpuToGpu_GrBufferType, |
| 537 | kXferGpuToCpu_GrBufferType, |
| 538 | |
| 539 | kLast_GrBufferType = kXferGpuToCpu_GrBufferType |
| 540 | }; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 541 | static const int kGrBufferTypeCount = kLast_GrBufferType + 1; |
| 542 | |
| 543 | static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) { |
| 544 | SkASSERT(type >= 0 && type < kGrBufferTypeCount); |
| 545 | return type <= kIndex_GrBufferType; |
| 546 | |
| 547 | GR_STATIC_ASSERT(0 == kVertex_GrBufferType); |
| 548 | GR_STATIC_ASSERT(1 == kIndex_GrBufferType); |
| 549 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 550 | |
| 551 | /** |
| 552 | * Provides a performance hint regarding the frequency at which a data store will be accessed. |
| 553 | */ |
| 554 | enum GrAccessPattern { |
| 555 | /** Data store will be respecified repeatedly and used many times. */ |
| 556 | kDynamic_GrAccessPattern, |
| 557 | /** Data store will be specified once and used many times. (Thus disqualified from caching.) */ |
| 558 | kStatic_GrAccessPattern, |
| 559 | /** Data store will be specified once and used at most a few times. (Also can't be cached.) */ |
| 560 | kStream_GrAccessPattern, |
| 561 | |
| 562 | kLast_GrAccessPattern = kStream_GrAccessPattern |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 563 | }; |
| 564 | |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 565 | // Flags shared between GrRenderTarget and GrRenderTargetProxy |
| 566 | enum class GrRenderTargetFlags { |
| 567 | kNone = 0, |
| 568 | |
| 569 | // For internal resources: |
| 570 | // this is enabled whenever MSAA is enabled and GrCaps reports mixed samples are supported |
| 571 | // For wrapped resources: |
| 572 | // this is disabled for FBO0 |
| 573 | // but, otherwise, is enabled whenever MSAA is enabled and GrCaps reports mixed samples |
| 574 | // are supported |
| 575 | kMixedSampled = 1 << 0, |
| 576 | |
| 577 | // For internal resources: |
| 578 | // this is enabled whenever GrCaps reports window rect support |
| 579 | // For wrapped resources1 |
| 580 | // this is disabled for FBO0 |
| 581 | // but, otherwise, is enabled whenever GrCaps reports window rect support |
| 582 | kWindowRectsSupport = 1 << 1 |
| 583 | }; |
| 584 | GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTargetFlags) |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 585 | |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 586 | #ifdef SK_DEBUG |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 587 | // Takes a pointer to a GrCaps, and will suppress prints if required |
| 588 | #define GrCapsDebugf(caps, ...) \ |
Brian Salomon | eb62829 | 2017-02-15 14:12:26 -0500 | [diff] [blame] | 589 | if (!(caps)->suppressPrints()) { \ |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 590 | SkDebugf(__VA_ARGS__); \ |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 591 | } |
| 592 | #else |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 593 | #define GrCapsDebugf(caps, ...) |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 594 | #endif |
| 595 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 596 | /** |
| 597 | * Specifies if the holder owns the backend, OpenGL or Vulkan, object. |
| 598 | */ |
| 599 | enum class GrBackendObjectOwnership : bool { |
| 600 | /** Holder does not destroy the backend object. */ |
| 601 | kBorrowed = false, |
| 602 | /** Holder destroys the backend object. */ |
| 603 | kOwned = true |
| 604 | }; |
| 605 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 606 | template <typename T> T * const * sk_sp_address_as_pointer_address(sk_sp<T> const * sp) { |
| 607 | static_assert(sizeof(T*) == sizeof(sk_sp<T>), "sk_sp not expected size."); |
| 608 | return reinterpret_cast<T * const *>(sp); |
| 609 | } |
| 610 | |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 611 | /* |
| 612 | * Object for CPU-GPU synchronization |
| 613 | */ |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 614 | typedef uint64_t GrFence; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 615 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 616 | #endif |