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 | |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrNonAtomicRef.h" |
| 13 | #include "src/gpu/GrProcessor.h" |
| 14 | #include "src/gpu/GrShaderVar.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 15 | |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 16 | class GrCoordTransform; |
| 17 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 18 | /* |
| 19 | * The GrPrimitiveProcessor represents some kind of geometric primitive. This includes the shape |
| 20 | * of the primitive and the inherent color of the primitive. The GrPrimitiveProcessor is |
| 21 | * responsible for providing a color and coverage input into the Ganesh rendering pipeline. Through |
| 22 | * optimization, Ganesh may decide a different color, no color, and / or no coverage are required |
| 23 | * from the GrPrimitiveProcessor, so the GrPrimitiveProcessor must be able to support this |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 24 | * functionality. |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 25 | * |
| 26 | * There are two feedback loops between the GrFragmentProcessors, the GrXferProcessor, and the |
Brian Salomon | cb30bb2 | 2017-02-12 09:28:54 -0500 | [diff] [blame] | 27 | * GrPrimitiveProcessor. These loops run on the CPU and to determine known properties of the final |
| 28 | * color and coverage inputs to the GrXferProcessor in order to perform optimizations that preserve |
| 29 | * 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] | 30 | * getProcessorAnalysisInputs implementation. These seed values are processed by the |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 31 | * subsequent |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 32 | * stages of the rendering pipeline and the output is then fed back into the GrDrawOp in |
| 33 | * the applyPipelineOptimizations call, where the op can use the information to inform decisions |
| 34 | * about GrPrimitiveProcessor creation. |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 35 | */ |
| 36 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 37 | class GrGLSLPrimitiveProcessor; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 38 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 39 | /** |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 40 | * GrPrimitiveProcessor defines an interface which all subclasses must implement. All |
| 41 | * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh color / coverage |
| 42 | * pipelines, and they must provide some notion of equality |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 43 | * |
| 44 | * TODO: This class does not really need to be ref counted. Instances should be allocated using |
| 45 | * GrOpFlushState's arena and destroyed when the arena is torn down. |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 46 | */ |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 47 | class GrPrimitiveProcessor : public GrProcessor, public GrNonAtomicRef<GrPrimitiveProcessor> { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 48 | public: |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 49 | class TextureSampler; |
| 50 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 51 | /** Describes a vertex or instance attribute. */ |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 52 | class Attribute { |
| 53 | public: |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 54 | constexpr Attribute() = default; |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 55 | constexpr Attribute(const char* name, |
| 56 | GrVertexAttribType cpuType, |
| 57 | GrSLType gpuType) |
| 58 | : fName(name), fCPUType(cpuType), fGPUType(gpuType) {} |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 59 | constexpr Attribute(const Attribute&) = default; |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 60 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 61 | Attribute& operator=(const Attribute&) = default; |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 62 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 63 | constexpr bool isInitialized() const { return SkToBool(fName); } |
| 64 | |
| 65 | constexpr const char* name() const { return fName; } |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 66 | constexpr GrVertexAttribType cpuType() const { return fCPUType; } |
| 67 | constexpr GrSLType gpuType() const { return fGPUType; } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 68 | |
| 69 | inline constexpr size_t size() const; |
| 70 | constexpr size_t sizeAlign4() const { return SkAlign4(this->size()); } |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 71 | |
| 72 | GrShaderVar asShaderVar() const { |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 73 | return {fName, fGPUType, GrShaderVar::kIn_TypeModifier}; |
Brian Salomon | 70132d0 | 2018-05-29 15:33:06 -0400 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | private: |
| 77 | const char* fName = nullptr; |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 78 | GrVertexAttribType fCPUType = kFloat_GrVertexAttribType; |
| 79 | GrSLType fGPUType = kFloat_GrSLType; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 82 | class Iter { |
| 83 | public: |
| 84 | Iter() : fCurr(nullptr), fRemaining(0) {} |
| 85 | Iter(const Iter& iter) : fCurr(iter.fCurr), fRemaining(iter.fRemaining) {} |
| 86 | Iter& operator= (const Iter& iter) { |
| 87 | fCurr = iter.fCurr; |
| 88 | fRemaining = iter.fRemaining; |
| 89 | return *this; |
| 90 | } |
| 91 | Iter(const Attribute* attrs, int count) : fCurr(attrs), fRemaining(count) { |
| 92 | this->skipUninitialized(); |
| 93 | } |
| 94 | |
| 95 | bool operator!=(const Iter& that) const { return fCurr != that.fCurr; } |
| 96 | const Attribute& operator*() const { return *fCurr; } |
| 97 | void operator++() { |
| 98 | if (fRemaining) { |
| 99 | fRemaining--; |
| 100 | fCurr++; |
| 101 | this->skipUninitialized(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | void skipUninitialized() { |
| 107 | if (!fRemaining) { |
| 108 | fCurr = nullptr; |
| 109 | } else { |
| 110 | while (!fCurr->isInitialized()) { |
| 111 | ++fCurr; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | const Attribute* fCurr; |
| 117 | int fRemaining; |
| 118 | }; |
| 119 | |
| 120 | class AttributeSet { |
| 121 | public: |
| 122 | Iter begin() const { return Iter(fAttributes, fCount); } |
| 123 | Iter end() const { return Iter(); } |
| 124 | |
| 125 | private: |
| 126 | friend class GrPrimitiveProcessor; |
| 127 | |
| 128 | void init(const Attribute* attrs, int count) { |
| 129 | fAttributes = attrs; |
Brian Osman | d3e7130 | 2018-12-06 11:17:35 -0500 | [diff] [blame] | 130 | fRawCount = count; |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 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; |
Brian Osman | d3e7130 | 2018-12-06 11:17:35 -0500 | [diff] [blame] | 142 | int fRawCount = 0; |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 143 | int fCount = 0; |
| 144 | size_t fStride = 0; |
| 145 | }; |
| 146 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 147 | GrPrimitiveProcessor(ClassID); |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 148 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 149 | int numTextureSamplers() const { return fTextureSamplerCnt; } |
| 150 | const TextureSampler& textureSampler(int index) const; |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 151 | int numVertexAttributes() const { return fVertexAttributes.fCount; } |
| 152 | const AttributeSet& vertexAttributes() const { return fVertexAttributes; } |
| 153 | int numInstanceAttributes() const { return fInstanceAttributes.fCount; } |
| 154 | const AttributeSet& instanceAttributes() const { return fInstanceAttributes; } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 155 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 156 | bool hasVertexAttributes() const { return SkToBool(fVertexAttributes.fCount); } |
| 157 | bool hasInstanceAttributes() const { return SkToBool(fInstanceAttributes.fCount); } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 158 | |
| 159 | /** |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 160 | * A common practice is to populate the the vertex/instance's memory using an implicit array of |
| 161 | * structs. In this case, it is best to assert that: |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 162 | * stride == sizeof(struct) |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 163 | */ |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 164 | size_t vertexStride() const { return fVertexAttributes.fStride; } |
| 165 | size_t instanceStride() const { return fInstanceAttributes.fStride; } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 166 | |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 167 | bool willUseTessellationShaders() const { |
| 168 | return fShaders & (kTessControl_GrShaderFlag | kTessEvaluation_GrShaderFlag); |
| 169 | } |
| 170 | |
| 171 | bool willUseGeoShader() const { |
| 172 | return fShaders & kGeometry_GrShaderFlag; |
| 173 | } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 174 | |
| 175 | /** |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 176 | * Computes a key for the transforms owned by an FP based on the shader code that will be |
| 177 | * emitted by the primitive processor to implement them. |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 178 | */ |
Brian Salomon | 7eabfe8 | 2019-12-02 14:20:20 -0500 | [diff] [blame] | 179 | uint32_t computeCoordTransformsKey(const GrFragmentProcessor& fp) const; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 180 | |
| 181 | /** |
| 182 | * Sets a unique key on the GrProcessorKeyBuilder that is directly associated with this geometry |
| 183 | * processor's GL backend implementation. |
wangyix | a7f4c43 | 2015-08-20 07:25:02 -0700 | [diff] [blame] | 184 | * |
| 185 | * TODO: A better name for this function would be "compute" instead of "get". |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 186 | */ |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 187 | virtual void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 188 | |
| 189 | |
Brian Osman | d3e7130 | 2018-12-06 11:17:35 -0500 | [diff] [blame] | 190 | void getAttributeKey(GrProcessorKeyBuilder* b) const { |
| 191 | // Ensure that our CPU and GPU type fields fit together in a 32-bit value, and we never |
| 192 | // collide with the "uninitialized" value. |
| 193 | static_assert(kGrVertexAttribTypeCount < (1 << 8), ""); |
| 194 | static_assert(kGrSLTypeCount < (1 << 8), ""); |
| 195 | |
| 196 | auto add_attributes = [=](const Attribute* attrs, int attrCount) { |
| 197 | for (int i = 0; i < attrCount; ++i) { |
| 198 | b->add32(attrs[i].isInitialized() ? (attrs[i].cpuType() << 16) | attrs[i].gpuType() |
| 199 | : ~0); |
| 200 | } |
| 201 | }; |
| 202 | add_attributes(fVertexAttributes.fAttributes, fVertexAttributes.fRawCount); |
| 203 | add_attributes(fInstanceAttributes.fAttributes, fInstanceAttributes.fRawCount); |
| 204 | } |
| 205 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 206 | /** Returns a new instance of the appropriate *GL* implementation class |
| 207 | for the given GrProcessor; caller is responsible for deleting |
| 208 | the object. */ |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 209 | virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 210 | |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 211 | virtual bool isPathRendering() const { return false; } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 212 | |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 213 | // We use these methods as a temporary back door to inject OpenGL tessellation code. Once |
| 214 | // tessellation is supported by SkSL we can remove these. |
| 215 | virtual SkString getTessControlShaderGLSL(const char* versionAndExtensionDecls, |
| 216 | const GrShaderCaps&) const { |
| 217 | SK_ABORT("Not implemented."); |
| 218 | } |
| 219 | virtual SkString getTessEvaluationShaderGLSL(const char* versionAndExtensionDecls, |
| 220 | const GrShaderCaps&) const { |
| 221 | SK_ABORT("Not implemented."); |
| 222 | } |
| 223 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 224 | protected: |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 225 | void setVertexAttributes(const Attribute* attrs, int attrCount) { |
| 226 | fVertexAttributes.init(attrs, attrCount); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 227 | } |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 228 | void setInstanceAttributes(const Attribute* attrs, int attrCount) { |
| 229 | SkASSERT(attrCount >= 0); |
| 230 | fInstanceAttributes.init(attrs, attrCount); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 231 | } |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 232 | void setWillUseTessellationShaders() { |
| 233 | fShaders |= kTessControl_GrShaderFlag | kTessEvaluation_GrShaderFlag; |
| 234 | } |
| 235 | void setWillUseGeoShader() { fShaders |= kGeometry_GrShaderFlag; } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 236 | void setTextureSamplerCnt(int cnt) { |
| 237 | SkASSERT(cnt >= 0); |
| 238 | fTextureSamplerCnt = cnt; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Helper for implementing onTextureSampler(). E.g.: |
| 243 | * return IthTexureSampler(i, fMyFirstSampler, fMySecondSampler, fMyThirdSampler); |
| 244 | */ |
| 245 | template <typename... Args> |
| 246 | static const TextureSampler& IthTextureSampler(int i, const TextureSampler& samp0, |
| 247 | const Args&... samps) { |
| 248 | return (0 == i) ? samp0 : IthTextureSampler(i - 1, samps...); |
| 249 | } |
| 250 | inline static const TextureSampler& IthTextureSampler(int i); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 251 | |
| 252 | private: |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 253 | virtual const TextureSampler& onTextureSampler(int) const { return IthTextureSampler(0); } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 254 | |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 255 | GrShaderFlags fShaders = kVertex_GrShaderFlag | kFragment_GrShaderFlag; |
| 256 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 257 | AttributeSet fVertexAttributes; |
| 258 | AttributeSet fInstanceAttributes; |
| 259 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 260 | int fTextureSamplerCnt = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 261 | typedef GrProcessor INHERITED; |
| 262 | }; |
| 263 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 264 | ////////////////////////////////////////////////////////////////////////////// |
| 265 | |
| 266 | /** |
Robert Phillips | 7d7aaf4 | 2019-10-14 11:34:16 -0400 | [diff] [blame] | 267 | * Used to capture the properties of the GrTextureProxies required/expected by a primitiveProcessor |
| 268 | * along with an associated GrSamplerState. The actual proxies used are stored in either the |
| 269 | * fixed or dynamic state arrays. TextureSamplers don't perform any coord manipulation to account |
| 270 | * for texture origin. |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 271 | */ |
| 272 | class GrPrimitiveProcessor::TextureSampler { |
| 273 | public: |
| 274 | TextureSampler() = default; |
| 275 | |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 276 | TextureSampler(GrSamplerState, const GrBackendFormat&, const GrSwizzle&); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 277 | |
| 278 | TextureSampler(const TextureSampler&) = delete; |
| 279 | TextureSampler& operator=(const TextureSampler&) = delete; |
| 280 | |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 281 | void reset(GrSamplerState, const GrBackendFormat&, const GrSwizzle&); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 282 | |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 283 | const GrBackendFormat& backendFormat() const { return fBackendFormat; } |
| 284 | GrTextureType textureType() const { return fBackendFormat.textureType(); } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 285 | |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 286 | GrSamplerState samplerState() const { return fSamplerState; } |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 287 | const GrSwizzle& swizzle() const { return fSwizzle; } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 288 | |
Brian Salomon | 67529b2 | 2019-08-13 15:31:04 -0400 | [diff] [blame] | 289 | bool isInitialized() const { return fIsInitialized; } |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 290 | |
| 291 | private: |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 292 | GrSamplerState fSamplerState; |
| 293 | GrBackendFormat fBackendFormat; |
| 294 | GrSwizzle fSwizzle; |
Robert Phillips | f272bea | 2019-10-17 08:56:16 -0400 | [diff] [blame] | 295 | bool fIsInitialized = false; |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::IthTextureSampler(int i) { |
| 299 | SK_ABORT("Illegal texture sampler index"); |
| 300 | static const TextureSampler kBogus; |
| 301 | return kBogus; |
| 302 | } |
| 303 | |
| 304 | ////////////////////////////////////////////////////////////////////////////// |
| 305 | |
| 306 | /** |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 307 | * Returns the size of the attrib type in bytes. |
| 308 | * This was moved from include/private/GrTypesPriv.h in service of Skia dependents that build |
| 309 | * with C++11. |
| 310 | */ |
| 311 | static constexpr inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
| 312 | switch (type) { |
| 313 | case kFloat_GrVertexAttribType: |
| 314 | return sizeof(float); |
| 315 | case kFloat2_GrVertexAttribType: |
| 316 | return 2 * sizeof(float); |
| 317 | case kFloat3_GrVertexAttribType: |
| 318 | return 3 * sizeof(float); |
| 319 | case kFloat4_GrVertexAttribType: |
| 320 | return 4 * sizeof(float); |
| 321 | case kHalf_GrVertexAttribType: |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 322 | return sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 323 | case kHalf2_GrVertexAttribType: |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 324 | return 2 * sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 325 | case kHalf3_GrVertexAttribType: |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 326 | return 3 * sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 327 | case kHalf4_GrVertexAttribType: |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 328 | return 4 * sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 329 | case kInt2_GrVertexAttribType: |
| 330 | return 2 * sizeof(int32_t); |
| 331 | case kInt3_GrVertexAttribType: |
| 332 | return 3 * sizeof(int32_t); |
| 333 | case kInt4_GrVertexAttribType: |
| 334 | return 4 * sizeof(int32_t); |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 335 | case kByte_GrVertexAttribType: |
| 336 | return 1 * sizeof(char); |
| 337 | case kByte2_GrVertexAttribType: |
| 338 | return 2 * sizeof(char); |
| 339 | case kByte3_GrVertexAttribType: |
| 340 | return 3 * sizeof(char); |
| 341 | case kByte4_GrVertexAttribType: |
| 342 | return 4 * sizeof(char); |
| 343 | case kUByte_GrVertexAttribType: |
| 344 | return 1 * sizeof(char); |
| 345 | case kUByte2_GrVertexAttribType: |
| 346 | return 2 * sizeof(char); |
| 347 | case kUByte3_GrVertexAttribType: |
| 348 | return 3 * sizeof(char); |
| 349 | case kUByte4_GrVertexAttribType: |
| 350 | return 4 * sizeof(char); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 351 | case kUByte_norm_GrVertexAttribType: |
| 352 | return 1 * sizeof(char); |
| 353 | case kUByte4_norm_GrVertexAttribType: |
| 354 | return 4 * sizeof(char); |
| 355 | case kShort2_GrVertexAttribType: |
| 356 | return 2 * sizeof(int16_t); |
Brian Osman | a5c578f | 2018-09-19 14:19:02 -0400 | [diff] [blame] | 357 | case kShort4_GrVertexAttribType: |
| 358 | return 4 * sizeof(int16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 359 | case kUShort2_GrVertexAttribType: // fall through |
| 360 | case kUShort2_norm_GrVertexAttribType: |
| 361 | return 2 * sizeof(uint16_t); |
| 362 | case kInt_GrVertexAttribType: |
| 363 | return sizeof(int32_t); |
| 364 | case kUint_GrVertexAttribType: |
| 365 | return sizeof(uint32_t); |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 366 | case kUShort_norm_GrVertexAttribType: |
| 367 | return sizeof(uint16_t); |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 368 | case kUShort4_norm_GrVertexAttribType: |
| 369 | return 4 * sizeof(uint16_t); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 370 | } |
| 371 | // GCC fails because SK_ABORT evaluates to non constexpr. clang and cl.exe think this is |
| 372 | // unreachable and don't complain. |
| 373 | #if defined(__clang__) || !defined(__GNUC__) |
| 374 | SK_ABORT("Unsupported type conversion"); |
| 375 | #endif |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | constexpr size_t GrPrimitiveProcessor::Attribute::size() const { |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 380 | return GrVertexAttribTypeSize(fCPUType); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 381 | } |
| 382 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 383 | #endif |