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