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