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