joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [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 GrPrimitiveProcessor_DEFINED |
| 9 | #define GrPrimitiveProcessor_DEFINED |
| 10 | |
| 11 | #include "GrColor.h" |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 12 | #include "GrNonAtomicRef.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 13 | #include "GrProcessor.h" |
Brian Salomon | ee78396 | 2018-08-01 09:55:10 -0400 | [diff] [blame] | 14 | #include "GrProxyRef.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 15 | #include "GrShaderVar.h" |
| 16 | |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 17 | class GrCoordTransform; |
| 18 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 19 | /* |
| 20 | * The GrPrimitiveProcessor represents some kind of geometric primitive. This includes the shape |
| 21 | * of the primitive and the inherent color of the primitive. The GrPrimitiveProcessor is |
| 22 | * responsible for providing a color and coverage input into the Ganesh rendering pipeline. Through |
| 23 | * optimization, Ganesh may decide a different color, no color, and / or no coverage are required |
| 24 | * from the GrPrimitiveProcessor, so the GrPrimitiveProcessor must be able to support this |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 25 | * functionality. |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 26 | * |
| 27 | * There are two feedback loops between the GrFragmentProcessors, the GrXferProcessor, and the |
Brian Salomon | cb30bb2 | 2017-02-12 09:28:54 -0500 | [diff] [blame] | 28 | * GrPrimitiveProcessor. These loops run on the CPU and to determine known properties of the final |
| 29 | * color and coverage inputs to the GrXferProcessor in order to perform optimizations that preserve |
| 30 | * correctness. The GrDrawOp seeds these loops with initial color and coverage, in its |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 31 | * getProcessorAnalysisInputs implementation. These seed values are processed by the |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 32 | * subsequent |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 33 | * stages of the rendering pipeline and the output is then fed back into the GrDrawOp in |
| 34 | * the applyPipelineOptimizations call, where the op can use the information to inform decisions |
| 35 | * about GrPrimitiveProcessor creation. |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 36 | */ |
| 37 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 38 | class GrGLSLPrimitiveProcessor; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 39 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 40 | /** |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 41 | * GrPrimitiveProcessor defines an interface which all subclasses must implement. All |
| 42 | * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh color / coverage |
| 43 | * pipelines, and they must provide some notion of equality |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 44 | * |
| 45 | * TODO: This class does not really need to be ref counted. Instances should be allocated using |
| 46 | * GrOpFlushState's arena and destroyed when the arena is torn down. |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 47 | */ |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 48 | class GrPrimitiveProcessor : public GrProcessor, public GrNonAtomicRef<GrPrimitiveProcessor> { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 49 | public: |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 50 | class TextureSampler; |
| 51 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 52 | /** Describes a vertex or instance attribute. */ |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 53 | class Attribute { |
| 54 | public: |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 55 | constexpr Attribute() = default; |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 56 | constexpr Attribute(const char* name, |
| 57 | GrVertexAttribType cpuType, |
| 58 | GrSLType gpuType) |
| 59 | : fName(name), fCPUType(cpuType), fGPUType(gpuType) {} |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 60 | constexpr Attribute(const Attribute&) = default; |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 61 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 62 | Attribute& operator=(const Attribute&) = default; |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 63 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 64 | constexpr bool isInitialized() const { return SkToBool(fName); } |
| 65 | |
| 66 | constexpr const char* name() const { return fName; } |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 67 | constexpr GrVertexAttribType cpuType() const { return fCPUType; } |
| 68 | constexpr GrSLType gpuType() const { return fGPUType; } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 69 | |
| 70 | inline constexpr size_t size() const; |
| 71 | constexpr size_t sizeAlign4() const { return SkAlign4(this->size()); } |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 72 | |
| 73 | GrShaderVar asShaderVar() const { |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 74 | return {fName, fGPUType, GrShaderVar::kIn_TypeModifier}; |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | private: |
| 78 | const char* fName = nullptr; |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 79 | GrVertexAttribType fCPUType = kFloat_GrVertexAttribType; |
| 80 | GrSLType fGPUType = kFloat_GrSLType; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 83 | class Iter { |
| 84 | public: |
| 85 | Iter() : fCurr(nullptr), fRemaining(0) {} |
| 86 | Iter(const Iter& iter) : fCurr(iter.fCurr), fRemaining(iter.fRemaining) {} |
| 87 | Iter& operator= (const Iter& iter) { |
| 88 | fCurr = iter.fCurr; |
| 89 | fRemaining = iter.fRemaining; |
| 90 | return *this; |
| 91 | } |
| 92 | Iter(const Attribute* attrs, int count) : fCurr(attrs), fRemaining(count) { |
| 93 | this->skipUninitialized(); |
| 94 | } |
| 95 | |
| 96 | bool operator!=(const Iter& that) const { return fCurr != that.fCurr; } |
| 97 | const Attribute& operator*() const { return *fCurr; } |
| 98 | void operator++() { |
| 99 | if (fRemaining) { |
| 100 | fRemaining--; |
| 101 | fCurr++; |
| 102 | this->skipUninitialized(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | void skipUninitialized() { |
| 108 | if (!fRemaining) { |
| 109 | fCurr = nullptr; |
| 110 | } else { |
| 111 | while (!fCurr->isInitialized()) { |
| 112 | ++fCurr; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | const Attribute* fCurr; |
| 118 | int fRemaining; |
| 119 | }; |
| 120 | |
| 121 | class AttributeSet { |
| 122 | public: |
| 123 | Iter begin() const { return Iter(fAttributes, fCount); } |
| 124 | Iter end() const { return Iter(); } |
| 125 | |
| 126 | private: |
| 127 | friend class GrPrimitiveProcessor; |
| 128 | |
| 129 | void init(const Attribute* attrs, int count) { |
| 130 | fAttributes = attrs; |
| 131 | fCount = 0; |
| 132 | fStride = 0; |
| 133 | for (int i = 0; i < count; ++i) { |
| 134 | if (attrs[i].isInitialized()) { |
| 135 | fCount++; |
| 136 | fStride += attrs[i].sizeAlign4(); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | const Attribute* fAttributes = nullptr; |
| 142 | int fCount = 0; |
| 143 | size_t fStride = 0; |
| 144 | }; |
| 145 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 146 | GrPrimitiveProcessor(ClassID); |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 147 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 148 | int numTextureSamplers() const { return fTextureSamplerCnt; } |
| 149 | const TextureSampler& textureSampler(int index) const; |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 150 | int numVertexAttributes() const { return fVertexAttributes.fCount; } |
| 151 | const AttributeSet& vertexAttributes() const { return fVertexAttributes; } |
| 152 | int numInstanceAttributes() const { return fInstanceAttributes.fCount; } |
| 153 | const AttributeSet& instanceAttributes() const { return fInstanceAttributes; } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 154 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 155 | bool hasVertexAttributes() const { return SkToBool(fVertexAttributes.fCount); } |
| 156 | bool hasInstanceAttributes() const { return SkToBool(fInstanceAttributes.fCount); } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 157 | |
| 158 | /** |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 159 | * A common practice is to populate the the vertex/instance's memory using an implicit array of |
| 160 | * structs. In this case, it is best to assert that: |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 161 | * stride == sizeof(struct) |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 162 | */ |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 163 | size_t vertexStride() const { return fVertexAttributes.fStride; } |
| 164 | size_t instanceStride() const { return fInstanceAttributes.fStride; } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 165 | |
| 166 | // Only the GrGeometryProcessor subclass actually has a geo shader or vertex attributes, but |
| 167 | // we put these calls on the base class to prevent having to cast |
| 168 | virtual bool willUseGeoShader() const = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 169 | |
| 170 | /** |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 171 | * Computes a transformKey from an array of coord transforms. Will only look at the first |
| 172 | * <numCoords> transforms in the array. |
| 173 | * |
| 174 | * TODO: A better name for this function would be "compute" instead of "get". |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 175 | */ |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 176 | uint32_t getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords, |
| 177 | int numCoords) const; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * Sets a unique key on the GrProcessorKeyBuilder that is directly associated with this geometry |
| 181 | * processor's GL backend implementation. |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 182 | * |
| 183 | * TODO: A better name for this function would be "compute" instead of "get". |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 184 | */ |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 185 | virtual void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 186 | |
| 187 | |
| 188 | /** Returns a new instance of the appropriate *GL* implementation class |
| 189 | for the given GrProcessor; caller is responsible for deleting |
| 190 | the object. */ |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 191 | virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 192 | |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 193 | virtual bool isPathRendering() const { return false; } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 194 | |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 195 | /** |
| 196 | * If non-null, overrides the dest color returned by GrGLSLFragmentShaderBuilder::dstColor(). |
| 197 | */ |
| 198 | virtual const char* getDestColorOverride() const { return nullptr; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 199 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 200 | virtual float getSampleShading() const { return 0.0; } |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 201 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 202 | protected: |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 203 | void setVertexAttributes(const Attribute* attrs, int attrCount) { |
| 204 | fVertexAttributes.init(attrs, attrCount); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 205 | } |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 206 | void setInstanceAttributes(const Attribute* attrs, int attrCount) { |
| 207 | SkASSERT(attrCount >= 0); |
| 208 | fInstanceAttributes.init(attrs, attrCount); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 209 | } |
| 210 | void setTextureSamplerCnt(int cnt) { |
| 211 | SkASSERT(cnt >= 0); |
| 212 | fTextureSamplerCnt = cnt; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Helper for implementing onTextureSampler(). E.g.: |
| 217 | * return IthTexureSampler(i, fMyFirstSampler, fMySecondSampler, fMyThirdSampler); |
| 218 | */ |
| 219 | template <typename... Args> |
| 220 | static const TextureSampler& IthTextureSampler(int i, const TextureSampler& samp0, |
| 221 | const Args&... samps) { |
| 222 | return (0 == i) ? samp0 : IthTextureSampler(i - 1, samps...); |
| 223 | } |
| 224 | inline static const TextureSampler& IthTextureSampler(int i); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 225 | |
| 226 | private: |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 227 | virtual const TextureSampler& onTextureSampler(int) const { return IthTextureSampler(0); } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 228 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 229 | AttributeSet fVertexAttributes; |
| 230 | AttributeSet fInstanceAttributes; |
| 231 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 232 | int fTextureSamplerCnt = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 233 | typedef GrProcessor INHERITED; |
| 234 | }; |
| 235 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 236 | ////////////////////////////////////////////////////////////////////////////// |
| 237 | |
| 238 | /** |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 239 | * Used to represent a texture that is required by a GrPrimitiveProcessor. It holds a GrTextureProxy |
| 240 | * along with an associated GrSamplerState. TextureSamplers don't perform any coord manipulation to |
| 241 | * account for texture origin. |
| 242 | */ |
| 243 | class GrPrimitiveProcessor::TextureSampler { |
| 244 | public: |
| 245 | TextureSampler() = default; |
| 246 | |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 247 | TextureSampler(GrTextureType, GrPixelConfig, const GrSamplerState&); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 248 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 249 | explicit TextureSampler(GrTextureType, GrPixelConfig, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 250 | GrSamplerState::Filter = GrSamplerState::Filter::kNearest, |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 251 | GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 252 | |
| 253 | TextureSampler(const TextureSampler&) = delete; |
| 254 | TextureSampler& operator=(const TextureSampler&) = delete; |
| 255 | |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 256 | void reset(GrTextureType, GrPixelConfig, const GrSamplerState&); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 257 | void reset(GrTextureType, GrPixelConfig, |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 258 | GrSamplerState::Filter = GrSamplerState::Filter::kNearest, |
Greg Daniel | 0f70be8 | 2018-10-08 17:35:08 +0000 | [diff] [blame] | 259 | GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 260 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 261 | GrTextureType textureType() const { return fTextureType; } |
| 262 | GrPixelConfig config() const { return fConfig; } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 263 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 264 | const GrSamplerState& samplerState() const { return fSamplerState; } |
| 265 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 266 | bool isInitialized() const { return fConfig != kUnknown_GrPixelConfig; } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 267 | |
| 268 | private: |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 269 | GrSamplerState fSamplerState; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 270 | GrTextureType fTextureType = GrTextureType::k2D; |
| 271 | GrPixelConfig fConfig = kUnknown_GrPixelConfig; |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::IthTextureSampler(int i) { |
| 275 | SK_ABORT("Illegal texture sampler index"); |
| 276 | static const TextureSampler kBogus; |
| 277 | return kBogus; |
| 278 | } |
| 279 | |
| 280 | ////////////////////////////////////////////////////////////////////////////// |
| 281 | |
| 282 | /** |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 283 | * Returns the size of the attrib type in bytes. |
| 284 | * This was moved from include/private/GrTypesPriv.h in service of Skia dependents that build |
| 285 | * with C++11. |
| 286 | */ |
| 287 | static constexpr inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
| 288 | switch (type) { |
| 289 | case kFloat_GrVertexAttribType: |
| 290 | return sizeof(float); |
| 291 | case kFloat2_GrVertexAttribType: |
| 292 | return 2 * sizeof(float); |
| 293 | case kFloat3_GrVertexAttribType: |
| 294 | return 3 * sizeof(float); |
| 295 | case kFloat4_GrVertexAttribType: |
| 296 | return 4 * sizeof(float); |
| 297 | case kHalf_GrVertexAttribType: |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 298 | return sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 299 | case kHalf2_GrVertexAttribType: |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 300 | return 2 * sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 301 | case kHalf3_GrVertexAttribType: |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 302 | return 3 * sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 303 | case kHalf4_GrVertexAttribType: |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 304 | return 4 * sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 305 | case kInt2_GrVertexAttribType: |
| 306 | return 2 * sizeof(int32_t); |
| 307 | case kInt3_GrVertexAttribType: |
| 308 | return 3 * sizeof(int32_t); |
| 309 | case kInt4_GrVertexAttribType: |
| 310 | return 4 * sizeof(int32_t); |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 311 | case kByte_GrVertexAttribType: |
| 312 | return 1 * sizeof(char); |
| 313 | case kByte2_GrVertexAttribType: |
| 314 | return 2 * sizeof(char); |
| 315 | case kByte3_GrVertexAttribType: |
| 316 | return 3 * sizeof(char); |
| 317 | case kByte4_GrVertexAttribType: |
| 318 | return 4 * sizeof(char); |
| 319 | case kUByte_GrVertexAttribType: |
| 320 | return 1 * sizeof(char); |
| 321 | case kUByte2_GrVertexAttribType: |
| 322 | return 2 * sizeof(char); |
| 323 | case kUByte3_GrVertexAttribType: |
| 324 | return 3 * sizeof(char); |
| 325 | case kUByte4_GrVertexAttribType: |
| 326 | return 4 * sizeof(char); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 327 | case kUByte_norm_GrVertexAttribType: |
| 328 | return 1 * sizeof(char); |
| 329 | case kUByte4_norm_GrVertexAttribType: |
| 330 | return 4 * sizeof(char); |
| 331 | case kShort2_GrVertexAttribType: |
| 332 | return 2 * sizeof(int16_t); |
Brian Osman | a5c578f | 2018-09-19 14:19:02 -0400 | [diff] [blame] | 333 | case kShort4_GrVertexAttribType: |
| 334 | return 4 * sizeof(int16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 335 | case kUShort2_GrVertexAttribType: // fall through |
| 336 | case kUShort2_norm_GrVertexAttribType: |
| 337 | return 2 * sizeof(uint16_t); |
| 338 | case kInt_GrVertexAttribType: |
| 339 | return sizeof(int32_t); |
| 340 | case kUint_GrVertexAttribType: |
| 341 | return sizeof(uint32_t); |
| 342 | } |
| 343 | // GCC fails because SK_ABORT evaluates to non constexpr. clang and cl.exe think this is |
| 344 | // unreachable and don't complain. |
| 345 | #if defined(__clang__) || !defined(__GNUC__) |
| 346 | SK_ABORT("Unsupported type conversion"); |
| 347 | #endif |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | constexpr size_t GrPrimitiveProcessor::Attribute::size() const { |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 352 | return GrVertexAttribTypeSize(fCPUType); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 353 | } |
| 354 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 355 | #endif |