| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
| joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 8 | #ifndef GrProcessor_DEFINED |
| 9 | #define GrProcessor_DEFINED |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 10 | |
| Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 11 | #include "../private/SkAtomics.h" |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 12 | #include "GrBuffer.h" |
| Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 13 | #include "GrColor.h" |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 14 | #include "GrGpuResourceRef.h" |
| joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 15 | #include "GrProcessorUnitTest.h" |
| bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 16 | #include "GrProgramElement.h" |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 17 | #include "GrSamplerState.h" |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 18 | #include "GrShaderVar.h" |
| Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 19 | #include "GrSurfaceProxyPriv.h" |
| Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 20 | #include "GrTextureProxy.h" |
| egdaniel | 9e4d6d1 | 2014-10-15 13:49:02 -0700 | [diff] [blame] | 21 | #include "SkMath.h" |
| robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 22 | #include "SkString.h" |
| tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 23 | |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 24 | class GrContext; |
| bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 25 | class GrCoordTransform; |
| egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 26 | class GrInvariantOutput; |
| Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 27 | class GrResourceProvider; |
| bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 28 | |
| joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Used by processors to build their keys. It incorporates each per-processor key into a larger |
| 31 | * shader key. |
| 32 | */ |
| 33 | class GrProcessorKeyBuilder { |
| 34 | public: |
| 35 | GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) { |
| 36 | SkASSERT(0 == fData->count() % sizeof(uint32_t)); |
| 37 | } |
| 38 | |
| 39 | void add32(uint32_t v) { |
| 40 | ++fCount; |
| 41 | fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v)); |
| 42 | } |
| 43 | |
| 44 | /** Inserts count uint32_ts into the key. The returned pointer is only valid until the next |
| 45 | add*() call. */ |
| 46 | uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) { |
| 47 | SkASSERT(count > 0); |
| 48 | fCount += count; |
| 49 | return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count)); |
| 50 | } |
| 51 | |
| 52 | size_t size() const { return sizeof(uint32_t) * fCount; } |
| 53 | |
| 54 | private: |
| 55 | SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key. |
| 56 | int fCount; // number of uint32_ts added to fData by the processor. |
| 57 | }; |
| 58 | |
| bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 59 | /** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be |
| 60 | immutable: after being constructed, their fields may not change. |
| bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 61 | |
| joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 62 | Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an |
| mdempsky | 38f1f6f | 2015-08-27 12:57:01 -0700 | [diff] [blame] | 63 | processor must reach 0 before the thread terminates and the pool is destroyed. |
| bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 64 | */ |
| Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 65 | class GrProcessor { |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 66 | public: |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 67 | enum ClassID { |
| 68 | kAARectEffect_ClassID, |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 69 | kBigKeyProcessor_ClassID, |
| 70 | kBlockInputFragmentProcessor_ClassID, |
| 71 | kCircleGeometryProcessor_ClassID, |
| 72 | kCircleInside2PtConicalEffect_ClassID, |
| 73 | kCircleOutside2PtConicalEffect_ClassID, |
| 74 | kCircularRRectEffect_ClassID, |
| 75 | kColorMatrixEffect_ClassID, |
| 76 | kColorTableEffect_ClassID, |
| 77 | kComposeOneFragmentProcessor_ClassID, |
| 78 | kComposeTwoFragmentProcessor_ClassID, |
| 79 | kCoverageSetOpXP_ClassID, |
| 80 | kCustomXP_ClassID, |
| 81 | kDashingCircleEffect_ClassID, |
| 82 | kDashingLineEffect_ClassID, |
| 83 | kDefaultGeoProc_ClassID, |
| 84 | kDIEllipseGeometryProcessor_ClassID, |
| 85 | kDisableColorXP_ClassID, |
| 86 | kEdge2PtConicalEffect_ClassID, |
| 87 | kEllipseGeometryProcessor_ClassID, |
| 88 | kEllipticalRRectEffect_ClassID, |
| 89 | kFocalInside2PtConicalEffect_ClassID, |
| 90 | kFocalOutside2PtConicalEffect_ClassID, |
| 91 | kGP_ClassID, |
| 92 | kGrAlphaThresholdFragmentProcessor_ClassID, |
| Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 93 | kGrArithmeticFP_ClassID, |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 94 | kGrBicubicEffect_ClassID, |
| 95 | kGrBitmapTextGeoProc_ClassID, |
| 96 | kGrBlurredEdgeFragmentProcessor_ClassID, |
| 97 | kGrCCPRCoverageProcessor_ClassID, |
| 98 | kGrCCPRPathProcessor_ClassID, |
| 99 | kGrCircleBlurFragmentProcessor_ClassID, |
| 100 | kGrCircleEffect_ClassID, |
| Brian Osman | c4f93ca | 2017-10-17 17:15:52 -0400 | [diff] [blame] | 101 | kGrColorSpaceXformEffect_ClassID, |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 102 | kGrConfigConversionEffect_ClassID, |
| 103 | kGrConicEffect_ClassID, |
| 104 | kGrConstColorProcessor_ClassID, |
| 105 | kGrConvexPolyEffect_ClassID, |
| 106 | kGrCubicEffect_ClassID, |
| 107 | kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID, |
| 108 | kGrDiffuseLightingEffect_ClassID, |
| 109 | kGrDisplacementMapEffect_ClassID, |
| 110 | kGrDistanceFieldA8TextGeoProc_ClassID, |
| 111 | kGrDistanceFieldLCDTextGeoProc_ClassID, |
| 112 | kGrDistanceFieldPathGeoProc_ClassID, |
| 113 | kGrDitherEffect_ClassID, |
| 114 | kGrEllipseEffect_ClassID, |
| 115 | kGrGaussianConvolutionFragmentProcessor_ClassID, |
| 116 | kGrImprovedPerlinNoiseEffect_ClassID, |
| 117 | kGrLightingEffect_ClassID, |
| 118 | kGrLinearGradient_ClassID, |
| Ethan Nicholas | 14efcbf | 2017-11-07 09:23:38 -0500 | [diff] [blame] | 119 | kGrLumaColorFilterEffect_ClassID, |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 120 | kGrMagnifierEffect_ClassID, |
| 121 | kGrMatrixConvolutionEffect_ClassID, |
| 122 | kGrMeshTestProcessor_ClassID, |
| 123 | kGrMorphologyEffect_ClassID, |
| 124 | kGrNonlinearColorSpaceXformEffect_ClassID, |
| Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 125 | kGrOverdrawFragmentProcessor_ClassID, |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 126 | kGrPathProcessor_ClassID, |
| 127 | kGrPerlinNoise2Effect_ClassID, |
| 128 | kGrPipelineDynamicStateTestProcessor_ClassID, |
| 129 | kGrQuadEffect_ClassID, |
| 130 | kGrRadialGradient_ClassID, |
| 131 | kGrRectBlurEffect_ClassID, |
| 132 | kGrRRectBlurEffect_ClassID, |
| 133 | kGrRRectShadowGeoProc_ClassID, |
| 134 | kGrSimpleTextureEffect_ClassID, |
| 135 | kGrSpecularLightingEffect_ClassID, |
| 136 | kGrSRGBEffect_ClassID, |
| 137 | kGrSweepGradient_ClassID, |
| 138 | kGrTextureDomainEffect_ClassID, |
| 139 | kHighContrastFilterEffect_ClassID, |
| 140 | kInstanceProcessor_ClassID, |
| 141 | kLumaColorFilterEffect_ClassID, |
| 142 | kMSAAQuadProcessor_ClassID, |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 143 | kPDLCDXferProcessor_ClassID, |
| 144 | kPorterDuffXferProcessor_ClassID, |
| 145 | kPremulFragmentProcessor_ClassID, |
| 146 | kPremulInputFragmentProcessor_ClassID, |
| 147 | kQuadEdgeEffect_ClassID, |
| 148 | kReplaceInputFragmentProcessor_ClassID, |
| 149 | kRRectsGaussianEdgeFP_ClassID, |
| 150 | kSeriesFragmentProcessor_ClassID, |
| 151 | kShaderPDXferProcessor_ClassID, |
| 152 | kSwizzleFragmentProcessor_ClassID, |
| 153 | kTestFP_ClassID, |
| 154 | kTextureGeometryProcessor_ClassID, |
| 155 | kUnpremulInputFragmentProcessor_ClassID, |
| 156 | kYUVtoRGBEffect_ClassID |
| 157 | }; |
| 158 | |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 159 | virtual ~GrProcessor() = default; |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 160 | |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 161 | /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader |
| 162 | code. */ |
| joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 163 | virtual const char* name() const = 0; |
| bsalomon@google.com | 289efe0 | 2012-05-21 20:57:59 +0000 | [diff] [blame] | 164 | |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 165 | /** Human-readable dump of all information */ |
| robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 166 | virtual SkString dumpInfo() const { |
| 167 | SkString str; |
| 168 | str.appendf("Missing data"); |
| 169 | return str; |
| 170 | } |
| 171 | |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 172 | /** |
| 173 | * Platform specific built-in features that a processor can request for the fragment shader. |
| 174 | */ |
| cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 175 | enum RequiredFeatures { |
| 176 | kNone_RequiredFeatures = 0, |
| Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 177 | kSampleLocations_RequiredFeature = 1 << 0 |
| cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures); |
| 181 | |
| 182 | RequiredFeatures requiredFeatures() const { return fRequiredFeatures; } |
| commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 183 | |
| tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 184 | void* operator new(size_t size); |
| 185 | void operator delete(void* target); |
| 186 | |
| bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 187 | void* operator new(size_t size, void* placement) { |
| 188 | return ::operator new(size, placement); |
| 189 | } |
| 190 | void operator delete(void* target, void* placement) { |
| 191 | ::operator delete(target, placement); |
| 192 | } |
| 193 | |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 194 | /** Helper for down-casting to a GrProcessor subclass */ |
| joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 195 | template <typename T> const T& cast() const { return *static_cast<const T*>(this); } |
| 196 | |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 197 | ClassID classID() const { return fClassID; } |
| joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 198 | |
| bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 199 | protected: |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 200 | GrProcessor(ClassID classID) |
| 201 | : fClassID(classID) |
| 202 | , fRequiredFeatures(kNone_RequiredFeatures) {} |
| bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 203 | |
| bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 204 | /** |
| cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 205 | * If the prcoessor will generate code that uses platform specific built-in features, then it |
| 206 | * must call these methods from its constructor. Otherwise, requests to use these features will |
| 207 | * be denied. |
| commit-bot@chromium.org | 8d47ddc | 2013-05-09 14:55:46 +0000 | [diff] [blame] | 208 | */ |
| cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 209 | void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_RequiredFeature; } |
| cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 210 | |
| 211 | void combineRequiredFeatures(const GrProcessor& other) { |
| 212 | fRequiredFeatures |= other.fRequiredFeatures; |
| 213 | } |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 214 | |
| bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 215 | private: |
| Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 216 | GrProcessor(const GrProcessor&) = delete; |
| 217 | GrProcessor& operator=(const GrProcessor&) = delete; |
| 218 | |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 219 | ClassID fClassID; |
| 220 | RequiredFeatures fRequiredFeatures; |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
| cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 223 | GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures); |
| 224 | |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 225 | /** A GrProcessor with the ability to access textures, buffers, and image storages. */ |
| 226 | class GrResourceIOProcessor : public GrProcessor { |
| 227 | public: |
| 228 | class TextureSampler; |
| 229 | class BufferAccess; |
| 230 | class ImageStorageAccess; |
| 231 | |
| 232 | int numTextureSamplers() const { return fTextureSamplers.count(); } |
| 233 | |
| 234 | /** Returns the access pattern for the texture at index. index must be valid according to |
| 235 | numTextureSamplers(). */ |
| 236 | const TextureSampler& textureSampler(int index) const { return *fTextureSamplers[index]; } |
| 237 | |
| 238 | int numBuffers() const { return fBufferAccesses.count(); } |
| 239 | |
| 240 | /** Returns the access pattern for the buffer at index. index must be valid according to |
| 241 | numBuffers(). */ |
| 242 | const BufferAccess& bufferAccess(int index) const { return *fBufferAccesses[index]; } |
| 243 | |
| 244 | int numImageStorages() const { return fImageStorageAccesses.count(); } |
| 245 | |
| 246 | /** Returns the access object for the image at index. index must be valid according to |
| 247 | numImages(). */ |
| 248 | const ImageStorageAccess& imageStorageAccess(int index) const { |
| 249 | return *fImageStorageAccesses[index]; |
| 250 | } |
| 251 | |
| Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 252 | bool instantiate(GrResourceProvider* resourceProvider) const; |
| Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 253 | |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 254 | protected: |
| Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 255 | GrResourceIOProcessor(ClassID classID) |
| 256 | : INHERITED(classID) {} |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * Subclasses call these from their constructor to register sampler/image sources. The processor |
| 260 | * subclass manages the lifetime of the objects (these functions only store pointers). The |
| 261 | * TextureSampler and/or BufferAccess instances are typically member fields of the GrProcessor |
| 262 | * subclass. These must only be called from the constructor because GrProcessors are immutable. |
| 263 | */ |
| 264 | void addTextureSampler(const TextureSampler*); |
| 265 | void addBufferAccess(const BufferAccess*); |
| Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 266 | void addImageStorageAccess(const ImageStorageAccess*); |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 267 | |
| 268 | bool hasSameSamplersAndAccesses(const GrResourceIOProcessor&) const; |
| 269 | |
| Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 270 | // These methods can be used by derived classes that also derive from GrProgramElement. |
| 271 | void addPendingIOs() const; |
| 272 | void removeRefs() const; |
| 273 | void pendingIOComplete() const; |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 274 | |
| Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 275 | private: |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 276 | SkSTArray<4, const TextureSampler*, true> fTextureSamplers; |
| 277 | SkSTArray<1, const BufferAccess*, true> fBufferAccesses; |
| 278 | SkSTArray<1, const ImageStorageAccess*, true> fImageStorageAccesses; |
| 279 | |
| 280 | typedef GrProcessor INHERITED; |
| 281 | }; |
| 282 | |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 283 | /** |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 284 | * Used to represent a texture that is required by a GrResourceIOProcessor. It holds a GrTexture |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 285 | * along with an associated GrSamplerState. TextureSamplers don't perform any coord manipulation to |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 286 | * account for texture origin. |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 287 | */ |
| Brian Salomon | ffc2ec4 | 2017-07-25 14:59:03 -0400 | [diff] [blame] | 288 | class GrResourceIOProcessor::TextureSampler { |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 289 | public: |
| 290 | /** |
| 291 | * Must be initialized before adding to a GrProcessor's texture access list. |
| 292 | */ |
| 293 | TextureSampler(); |
| Brian Salomon | ffc2ec4 | 2017-07-25 14:59:03 -0400 | [diff] [blame] | 294 | /** |
| 295 | * This copy constructor is used by GrFragmentProcessor::clone() implementations. The copy |
| 296 | * always takes a new ref on the texture proxy as the new fragment processor will not yet be |
| 297 | * in pending execution state. |
| 298 | */ |
| 299 | explicit TextureSampler(const TextureSampler& that) |
| 300 | : fProxyRef(sk_ref_sp(that.fProxyRef.get()), that.fProxyRef.ioType()) |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 301 | , fSamplerState(that.fSamplerState) |
| Brian Salomon | ffc2ec4 | 2017-07-25 14:59:03 -0400 | [diff] [blame] | 302 | , fVisibility(that.fVisibility) {} |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 303 | |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 304 | TextureSampler(sk_sp<GrTextureProxy>, const GrSamplerState&); |
| Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 305 | |
| Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 306 | explicit TextureSampler(sk_sp<GrTextureProxy>, |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 307 | GrSamplerState::Filter = GrSamplerState::Filter::kNearest, |
| 308 | GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp, |
| Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 309 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 310 | |
| 311 | TextureSampler& operator=(const TextureSampler&) = delete; |
| 312 | |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 313 | void reset(sk_sp<GrTextureProxy>, const GrSamplerState&, |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 314 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 315 | void reset(sk_sp<GrTextureProxy>, |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 316 | GrSamplerState::Filter = GrSamplerState::Filter::kNearest, |
| 317 | GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp, |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 318 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 319 | |
| 320 | bool operator==(const TextureSampler& that) const { |
| Robert Phillips | 159e3c6 | 2017-06-19 12:02:00 -0400 | [diff] [blame] | 321 | return this->proxy()->underlyingUniqueID() == that.proxy()->underlyingUniqueID() && |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 322 | fSamplerState == that.fSamplerState && fVisibility == that.fVisibility; |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | bool operator!=(const TextureSampler& other) const { return !(*this == other); } |
| 326 | |
| Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 327 | // 'instantiate' should only ever be called at flush time. |
| 328 | bool instantiate(GrResourceProvider* resourceProvider) const { |
| Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 329 | return SkToBool(fProxyRef.get()->instantiate(resourceProvider)); |
| Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // 'peekTexture' should only ever be called after a successful 'instantiate' call |
| 333 | GrTexture* peekTexture() const { |
| Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 334 | SkASSERT(fProxyRef.get()->priv().peekTexture()); |
| 335 | return fProxyRef.get()->priv().peekTexture(); |
| Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 336 | } |
| 337 | |
| Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 338 | GrTextureProxy* proxy() const { return fProxyRef.get()->asTextureProxy(); } |
| Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 339 | GrShaderFlags visibility() const { return fVisibility; } |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 340 | const GrSamplerState& samplerState() const { return fSamplerState; } |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 341 | |
| Brian Salomon | 06e547c | 2017-06-09 16:11:32 -0400 | [diff] [blame] | 342 | bool isInitialized() const { return SkToBool(fProxyRef.get()); } |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 343 | /** |
| 344 | * For internal use by GrProcessor. |
| 345 | */ |
| Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 346 | const GrSurfaceProxyRef* programProxy() const { return &fProxyRef; } |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 347 | |
| 348 | private: |
| Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 349 | GrSurfaceProxyRef fProxyRef; |
| 350 | GrSamplerState fSamplerState; |
| 351 | GrShaderFlags fVisibility; |
| Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 352 | }; |
| 353 | |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 354 | /** |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 355 | * Used to represent a texel buffer that will be read in a GrResourceIOProcessor. It holds a |
| 356 | * GrBuffer along with an associated offset and texel config. |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 357 | */ |
| Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 358 | class GrResourceIOProcessor::BufferAccess { |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 359 | public: |
| Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 360 | BufferAccess() = default; |
| 361 | BufferAccess(GrPixelConfig texelConfig, GrBuffer* buffer, |
| 362 | GrShaderFlags visibility = kFragment_GrShaderFlag) { |
| 363 | this->reset(texelConfig, buffer, visibility); |
| 364 | } |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 365 | /** |
| Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 366 | * This copy constructor is used by GrFragmentProcessor::clone() implementations. The copy |
| 367 | * always takes a new ref on the buffer proxy as the new fragment processor will not yet be |
| 368 | * in pending execution state. |
| 369 | */ |
| 370 | explicit BufferAccess(const BufferAccess& that) { |
| 371 | this->reset(that.fTexelConfig, that.fBuffer.get(), that.fVisibility); |
| 372 | } |
| 373 | |
| 374 | BufferAccess& operator=(const BufferAccess&) = delete; |
| 375 | |
| 376 | /** |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 377 | * Must be initialized before adding to a GrProcessor's buffer access list. |
| 378 | */ |
| 379 | void reset(GrPixelConfig texelConfig, GrBuffer* buffer, |
| 380 | GrShaderFlags visibility = kFragment_GrShaderFlag) { |
| 381 | fTexelConfig = texelConfig; |
| 382 | fBuffer.set(SkRef(buffer), kRead_GrIOType); |
| 383 | fVisibility = visibility; |
| 384 | } |
| 385 | |
| 386 | bool operator==(const BufferAccess& that) const { |
| 387 | return fTexelConfig == that.fTexelConfig && |
| 388 | this->buffer() == that.buffer() && |
| 389 | fVisibility == that.fVisibility; |
| 390 | } |
| 391 | |
| 392 | bool operator!=(const BufferAccess& that) const { return !(*this == that); } |
| 393 | |
| 394 | GrPixelConfig texelConfig() const { return fTexelConfig; } |
| 395 | GrBuffer* buffer() const { return fBuffer.get(); } |
| 396 | GrShaderFlags visibility() const { return fVisibility; } |
| 397 | |
| 398 | /** |
| 399 | * For internal use by GrProcessor. |
| 400 | */ |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 401 | const GrGpuResourceRef* programBuffer() const { return &fBuffer;} |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 402 | |
| 403 | private: |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 404 | GrPixelConfig fTexelConfig; |
| 405 | GrTGpuResourceRef<GrBuffer> fBuffer; |
| 406 | GrShaderFlags fVisibility; |
| Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 407 | |
| 408 | typedef SkNoncopyable INHERITED; |
| 409 | }; |
| 410 | |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 411 | /** |
| 412 | * This is used by a GrProcessor to access a texture using image load/store in its shader code. |
| 413 | * ImageStorageAccesses don't perform any coord manipulation to account for texture origin. |
| 414 | * Currently the format of the load/store data in the shader is inferred from the texture config, |
| 415 | * though it could be made explicit. |
| 416 | */ |
| Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 417 | class GrResourceIOProcessor::ImageStorageAccess { |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 418 | public: |
| Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 419 | ImageStorageAccess(sk_sp<GrTextureProxy>, GrIOType, GrSLMemoryModel, GrSLRestrict, |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 420 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 421 | /** |
| 422 | * This copy constructor is used by GrFragmentProcessor::clone() implementations. The copy |
| 423 | * always takes a new ref on the surface proxy as the new fragment processor will not yet be |
| 424 | * in pending execution state. |
| 425 | */ |
| 426 | explicit ImageStorageAccess(const ImageStorageAccess& that) |
| 427 | : fProxyRef(sk_ref_sp(that.fProxyRef.get()), that.fProxyRef.ioType()) |
| 428 | , fVisibility(that.fVisibility) |
| 429 | , fFormat(that.fFormat) |
| 430 | , fMemoryModel(that.fMemoryModel) |
| 431 | , fRestrict(that.fRestrict) {} |
| 432 | |
| 433 | ImageStorageAccess& operator=(const ImageStorageAccess&) = delete; |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 434 | |
| 435 | bool operator==(const ImageStorageAccess& that) const { |
| Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 436 | return this->proxy() == that.proxy() && fVisibility == that.fVisibility; |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | bool operator!=(const ImageStorageAccess& that) const { return !(*this == that); } |
| 440 | |
| Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 441 | GrTextureProxy* proxy() const { return fProxyRef.get()->asTextureProxy(); } |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 442 | GrShaderFlags visibility() const { return fVisibility; } |
| Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 443 | GrIOType ioType() const { return fProxyRef.ioType(); } |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 444 | GrImageStorageFormat format() const { return fFormat; } |
| 445 | GrSLMemoryModel memoryModel() const { return fMemoryModel; } |
| 446 | GrSLRestrict restrict() const { return fRestrict; } |
| 447 | |
| Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 448 | // 'instantiate' should only ever be called at flush time. |
| 449 | bool instantiate(GrResourceProvider* resourceProvider) const { |
| Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 450 | return SkToBool(fProxyRef.get()->instantiate(resourceProvider)); |
| Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 451 | } |
| 452 | // 'peekTexture' should only ever be called after a successful 'instantiate' call |
| 453 | GrTexture* peekTexture() const { |
| Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 454 | SkASSERT(fProxyRef.get()->priv().peekTexture()); |
| 455 | return fProxyRef.get()->priv().peekTexture(); |
| Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 456 | } |
| 457 | |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 458 | /** |
| 459 | * For internal use by GrProcessor. |
| 460 | */ |
| Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 461 | const GrSurfaceProxyRef* programProxy() const { return &fProxyRef; } |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 462 | |
| 463 | private: |
| Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 464 | GrSurfaceProxyRef fProxyRef; |
| 465 | GrShaderFlags fVisibility; |
| Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 466 | GrImageStorageFormat fFormat; |
| Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 467 | GrSLMemoryModel fMemoryModel; |
| 468 | GrSLRestrict fRestrict; |
| Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 469 | typedef SkNoncopyable INHERITED; |
| 470 | }; |
| 471 | |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 472 | #endif |