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