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 | |
bsalomon@google.com | 371e105 | 2013-01-11 21:08:55 +0000 | [diff] [blame] | 11 | #include "GrColor.h" |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 12 | #include "GrBuffer.h" |
| 13 | #include "GrGpuResourceRef.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 14 | #include "GrProcessorUnitTest.h" |
bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 15 | #include "GrProgramElement.h" |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 16 | #include "GrSamplerParams.h" |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 17 | #include "GrShaderVar.h" |
egdaniel | 9e4d6d1 | 2014-10-15 13:49:02 -0700 | [diff] [blame] | 18 | #include "SkMath.h" |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 19 | #include "SkString.h" |
mtklein | 59c12e3 | 2016-05-02 07:19:41 -0700 | [diff] [blame] | 20 | #include "../private/SkAtomics.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 21 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 22 | class GrContext; |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 23 | class GrCoordTransform; |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 24 | class GrInvariantOutput; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 25 | class GrResourceProvider; |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 26 | class GrTextureProxy; |
bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 27 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 28 | /** |
| 29 | * Used by processors to build their keys. It incorporates each per-processor key into a larger |
| 30 | * shader key. |
| 31 | */ |
| 32 | class GrProcessorKeyBuilder { |
| 33 | public: |
| 34 | GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) { |
| 35 | SkASSERT(0 == fData->count() % sizeof(uint32_t)); |
| 36 | } |
| 37 | |
| 38 | void add32(uint32_t v) { |
| 39 | ++fCount; |
| 40 | fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v)); |
| 41 | } |
| 42 | |
| 43 | /** Inserts count uint32_ts into the key. The returned pointer is only valid until the next |
| 44 | add*() call. */ |
| 45 | uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) { |
| 46 | SkASSERT(count > 0); |
| 47 | fCount += count; |
| 48 | return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count)); |
| 49 | } |
| 50 | |
| 51 | size_t size() const { return sizeof(uint32_t) * fCount; } |
| 52 | |
| 53 | private: |
| 54 | SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key. |
| 55 | int fCount; // number of uint32_ts added to fData by the processor. |
| 56 | }; |
| 57 | |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 58 | /** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be |
| 59 | immutable: after being constructed, their fields may not change. |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 60 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 61 | 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] | 62 | processor must reach 0 before the thread terminates and the pool is destroyed. |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 63 | */ |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 64 | class GrProcessor : public GrProgramElement<GrProcessor> { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 65 | public: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 66 | virtual ~GrProcessor() = default; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 67 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 68 | /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader |
| 69 | code. */ |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 70 | virtual const char* name() const = 0; |
bsalomon@google.com | 289efe0 | 2012-05-21 20:57:59 +0000 | [diff] [blame] | 71 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 72 | /** Human-readable dump of all information */ |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 73 | virtual SkString dumpInfo() const { |
| 74 | SkString str; |
| 75 | str.appendf("Missing data"); |
| 76 | return str; |
| 77 | } |
| 78 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 79 | /** |
| 80 | * Platform specific built-in features that a processor can request for the fragment shader. |
| 81 | */ |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 82 | enum RequiredFeatures { |
| 83 | kNone_RequiredFeatures = 0, |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 84 | kSampleLocations_RequiredFeature = 1 << 0 |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures); |
| 88 | |
| 89 | RequiredFeatures requiredFeatures() const { return fRequiredFeatures; } |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 90 | |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 91 | void* operator new(size_t size); |
| 92 | void operator delete(void* target); |
| 93 | |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 94 | void* operator new(size_t size, void* placement) { |
| 95 | return ::operator new(size, placement); |
| 96 | } |
| 97 | void operator delete(void* target, void* placement) { |
| 98 | ::operator delete(target, placement); |
| 99 | } |
| 100 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 101 | /** Helper for down-casting to a GrProcessor subclass */ |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 102 | template <typename T> const T& cast() const { return *static_cast<const T*>(this); } |
| 103 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 104 | uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); return fClassID; } |
| 105 | |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 106 | protected: |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 107 | GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_RequiredFeatures) {} |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 108 | |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 109 | /** |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 110 | * If the prcoessor will generate code that uses platform specific built-in features, then it |
| 111 | * must call these methods from its constructor. Otherwise, requests to use these features will |
| 112 | * be denied. |
commit-bot@chromium.org | 8d47ddc | 2013-05-09 14:55:46 +0000 | [diff] [blame] | 113 | */ |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 114 | void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_RequiredFeature; } |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 115 | |
| 116 | void combineRequiredFeatures(const GrProcessor& other) { |
| 117 | fRequiredFeatures |= other.fRequiredFeatures; |
| 118 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 119 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 120 | template <typename PROC_SUBCLASS> void initClassID() { |
| 121 | static uint32_t kClassID = GenClassID(); |
| 122 | fClassID = kClassID; |
| 123 | } |
| 124 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 125 | private: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 126 | static uint32_t GenClassID() { |
| 127 | // fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The |
| 128 | // atomic inc returns the old value not the incremented value. So we add |
| 129 | // 1 to the returned value. |
| 130 | uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID)) + 1; |
| 131 | if (!id) { |
| 132 | SkFAIL("This should never wrap as it should only be called once for each GrProcessor " |
| 133 | "subclass."); |
| 134 | } |
| 135 | return id; |
| 136 | } |
| 137 | |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 138 | friend class GrProgramElement<GrProcessor>; |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 139 | virtual void addPendingIOs() const {} |
| 140 | virtual void removeRefs() const {} |
| 141 | virtual void pendingIOComplete() const {} |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 142 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 143 | enum { |
| 144 | kIllegalProcessorClassID = 0, |
| 145 | }; |
| 146 | static int32_t gCurrProcessorClassID; |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 147 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 148 | uint32_t fClassID; |
| 149 | RequiredFeatures fRequiredFeatures; |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 150 | |
bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 151 | typedef GrProgramElement INHERITED; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 154 | GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures); |
| 155 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 156 | /** A GrProcessor with the ability to access textures, buffers, and image storages. */ |
| 157 | class GrResourceIOProcessor : public GrProcessor { |
| 158 | public: |
| 159 | class TextureSampler; |
| 160 | class BufferAccess; |
| 161 | class ImageStorageAccess; |
| 162 | |
| 163 | int numTextureSamplers() const { return fTextureSamplers.count(); } |
| 164 | |
| 165 | /** Returns the access pattern for the texture at index. index must be valid according to |
| 166 | numTextureSamplers(). */ |
| 167 | const TextureSampler& textureSampler(int index) const { return *fTextureSamplers[index]; } |
| 168 | |
| 169 | int numBuffers() const { return fBufferAccesses.count(); } |
| 170 | |
| 171 | /** Returns the access pattern for the buffer at index. index must be valid according to |
| 172 | numBuffers(). */ |
| 173 | const BufferAccess& bufferAccess(int index) const { return *fBufferAccesses[index]; } |
| 174 | |
| 175 | int numImageStorages() const { return fImageStorageAccesses.count(); } |
| 176 | |
| 177 | /** Returns the access object for the image at index. index must be valid according to |
| 178 | numImages(). */ |
| 179 | const ImageStorageAccess& imageStorageAccess(int index) const { |
| 180 | return *fImageStorageAccesses[index]; |
| 181 | } |
| 182 | |
| 183 | protected: |
| 184 | GrResourceIOProcessor() = default; |
| 185 | |
| 186 | /** |
| 187 | * Subclasses call these from their constructor to register sampler/image sources. The processor |
| 188 | * subclass manages the lifetime of the objects (these functions only store pointers). The |
| 189 | * TextureSampler and/or BufferAccess instances are typically member fields of the GrProcessor |
| 190 | * subclass. These must only be called from the constructor because GrProcessors are immutable. |
| 191 | */ |
| 192 | void addTextureSampler(const TextureSampler*); |
| 193 | void addBufferAccess(const BufferAccess*); |
| 194 | void addImageStorageAccess(const ImageStorageAccess*); |
| 195 | |
| 196 | bool hasSameSamplersAndAccesses(const GrResourceIOProcessor&) const; |
| 197 | |
| 198 | private: |
| 199 | friend class GrProgramElement<GrProcessor>; |
| 200 | void addPendingIOs() const override; |
| 201 | void removeRefs() const override; |
| 202 | void pendingIOComplete() const override; |
| 203 | |
| 204 | SkSTArray<4, const TextureSampler*, true> fTextureSamplers; |
| 205 | SkSTArray<1, const BufferAccess*, true> fBufferAccesses; |
| 206 | SkSTArray<1, const ImageStorageAccess*, true> fImageStorageAccesses; |
| 207 | |
| 208 | typedef GrProcessor INHERITED; |
| 209 | }; |
| 210 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 211 | /** |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 212 | * Used to represent a texture that is required by a GrResourceIOProcessor. It holds a GrTexture |
| 213 | * along with an associated GrSamplerParams. TextureSamplers don't perform any coord manipulation to |
| 214 | * account for texture origin. |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 215 | */ |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 216 | class GrResourceIOProcessor::TextureSampler : public SkNoncopyable { |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 217 | public: |
| 218 | /** |
| 219 | * Must be initialized before adding to a GrProcessor's texture access list. |
| 220 | */ |
| 221 | TextureSampler(); |
| 222 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 223 | TextureSampler(GrTexture*, const GrSamplerParams&); |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 224 | explicit TextureSampler(GrTexture*, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 225 | GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 226 | SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode, |
| 227 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 228 | void reset(GrTexture*, const GrSamplerParams&, |
| 229 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 230 | void reset(GrTexture*, |
| 231 | GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode, |
| 232 | SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode, |
| 233 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 234 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 235 | // MDB TODO: ultimately we shouldn't need the resource provider parameter |
| 236 | TextureSampler(GrResourceProvider*, sk_sp<GrTextureProxy>, const GrSamplerParams&); |
| 237 | explicit TextureSampler(GrResourceProvider*, sk_sp<GrTextureProxy>, |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 238 | GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode, |
| 239 | SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode, |
| 240 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 241 | void reset(GrResourceProvider*, sk_sp<GrTextureProxy>, const GrSamplerParams&, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 242 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 243 | void reset(GrResourceProvider*, sk_sp<GrTextureProxy>, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 244 | GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 245 | SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode, |
| 246 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 247 | |
| 248 | bool operator==(const TextureSampler& that) const { |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 249 | return this->texture() == that.texture() && |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 250 | fParams == that.fParams && |
| 251 | fVisibility == that.fVisibility; |
| 252 | } |
| 253 | |
| 254 | bool operator!=(const TextureSampler& other) const { return !(*this == other); } |
| 255 | |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 256 | GrTexture* texture() const { return fTexture.get(); } |
| 257 | GrShaderFlags visibility() const { return fVisibility; } |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 258 | const GrSamplerParams& params() const { return fParams; } |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 259 | |
| 260 | /** |
| 261 | * For internal use by GrProcessor. |
| 262 | */ |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 263 | const GrGpuResourceRef* programTexture() const { return &fTexture; } |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 264 | |
| 265 | private: |
| 266 | |
| 267 | typedef GrTGpuResourceRef<GrTexture> ProgramTexture; |
| 268 | |
| 269 | ProgramTexture fTexture; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 270 | GrSamplerParams fParams; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 271 | GrShaderFlags fVisibility; |
| 272 | |
| 273 | typedef SkNoncopyable INHERITED; |
| 274 | }; |
| 275 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 276 | /** |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 277 | * Used to represent a texel buffer that will be read in a GrResourceIOProcessor. It holds a |
| 278 | * GrBuffer along with an associated offset and texel config. |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 279 | */ |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 280 | class GrResourceIOProcessor::BufferAccess : public SkNoncopyable { |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 281 | public: |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 282 | BufferAccess() = default; |
| 283 | BufferAccess(GrPixelConfig texelConfig, GrBuffer* buffer, |
| 284 | GrShaderFlags visibility = kFragment_GrShaderFlag) { |
| 285 | this->reset(texelConfig, buffer, visibility); |
| 286 | } |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 287 | /** |
| 288 | * Must be initialized before adding to a GrProcessor's buffer access list. |
| 289 | */ |
| 290 | void reset(GrPixelConfig texelConfig, GrBuffer* buffer, |
| 291 | GrShaderFlags visibility = kFragment_GrShaderFlag) { |
| 292 | fTexelConfig = texelConfig; |
| 293 | fBuffer.set(SkRef(buffer), kRead_GrIOType); |
| 294 | fVisibility = visibility; |
| 295 | } |
| 296 | |
| 297 | bool operator==(const BufferAccess& that) const { |
| 298 | return fTexelConfig == that.fTexelConfig && |
| 299 | this->buffer() == that.buffer() && |
| 300 | fVisibility == that.fVisibility; |
| 301 | } |
| 302 | |
| 303 | bool operator!=(const BufferAccess& that) const { return !(*this == that); } |
| 304 | |
| 305 | GrPixelConfig texelConfig() const { return fTexelConfig; } |
| 306 | GrBuffer* buffer() const { return fBuffer.get(); } |
| 307 | GrShaderFlags visibility() const { return fVisibility; } |
| 308 | |
| 309 | /** |
| 310 | * For internal use by GrProcessor. |
| 311 | */ |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 312 | const GrGpuResourceRef* programBuffer() const { return &fBuffer;} |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 313 | |
| 314 | private: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 315 | GrPixelConfig fTexelConfig; |
| 316 | GrTGpuResourceRef<GrBuffer> fBuffer; |
| 317 | GrShaderFlags fVisibility; |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 318 | |
| 319 | typedef SkNoncopyable INHERITED; |
| 320 | }; |
| 321 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 322 | /** |
| 323 | * This is used by a GrProcessor to access a texture using image load/store in its shader code. |
| 324 | * ImageStorageAccesses don't perform any coord manipulation to account for texture origin. |
| 325 | * Currently the format of the load/store data in the shader is inferred from the texture config, |
| 326 | * though it could be made explicit. |
| 327 | */ |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 328 | class GrResourceIOProcessor::ImageStorageAccess : public SkNoncopyable { |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 329 | public: |
| 330 | ImageStorageAccess(sk_sp<GrTexture> texture, GrIOType ioType, GrSLMemoryModel, GrSLRestrict, |
| 331 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 332 | |
| 333 | bool operator==(const ImageStorageAccess& that) const { |
| 334 | return this->texture() == that.texture() && fVisibility == that.fVisibility; |
| 335 | } |
| 336 | |
| 337 | bool operator!=(const ImageStorageAccess& that) const { return !(*this == that); } |
| 338 | |
| 339 | GrTexture* texture() const { return fTexture.get(); } |
| 340 | GrShaderFlags visibility() const { return fVisibility; } |
| 341 | GrIOType ioType() const { return fTexture.ioType(); } |
| 342 | GrImageStorageFormat format() const { return fFormat; } |
| 343 | GrSLMemoryModel memoryModel() const { return fMemoryModel; } |
| 344 | GrSLRestrict restrict() const { return fRestrict; } |
| 345 | |
| 346 | /** |
| 347 | * For internal use by GrProcessor. |
| 348 | */ |
| 349 | const GrGpuResourceRef* programTexture() const { return &fTexture; } |
| 350 | |
| 351 | private: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 352 | GrTGpuResourceRef<GrTexture> fTexture; |
| 353 | GrShaderFlags fVisibility; |
| 354 | GrImageStorageFormat fFormat; |
| 355 | GrSLMemoryModel fMemoryModel; |
| 356 | GrSLRestrict fRestrict; |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 357 | typedef SkNoncopyable INHERITED; |
| 358 | }; |
| 359 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 360 | #endif |