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