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, |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 106 | kFragmentPosition_RequiredFeature = 1 << 0, |
| 107 | kSampleLocations_RequiredFeature = 1 << 1 |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures); |
| 111 | |
| 112 | RequiredFeatures requiredFeatures() const { return fRequiredFeatures; } |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 113 | |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 114 | void* operator new(size_t size); |
| 115 | void operator delete(void* target); |
| 116 | |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 117 | void* operator new(size_t size, void* placement) { |
| 118 | return ::operator new(size, placement); |
| 119 | } |
| 120 | void operator delete(void* target, void* placement) { |
| 121 | ::operator delete(target, placement); |
| 122 | } |
| 123 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 124 | /** Helper for down-casting to a GrProcessor subclass */ |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 125 | template <typename T> const T& cast() const { return *static_cast<const T*>(this); } |
| 126 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 127 | uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); return fClassID; } |
| 128 | |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 129 | protected: |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 130 | GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_RequiredFeatures) {} |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 131 | |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 132 | /** |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 133 | * Subclasses call these from their constructor to register sampler/image sources. The processor |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 134 | * 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] | 135 | * TextureSampler and/or BufferAccess instances are typically member fields of the GrProcessor |
| 136 | * 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] | 137 | */ |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 138 | void addTextureSampler(const TextureSampler*); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 139 | void addBufferAccess(const BufferAccess*); |
| 140 | void addImageStorageAccess(const ImageStorageAccess*); |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 141 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 142 | bool hasSameSamplersAndAccesses(const GrProcessor &) const; |
commit-bot@chromium.org | 8d47ddc | 2013-05-09 14:55:46 +0000 | [diff] [blame] | 143 | |
| 144 | /** |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 145 | * If the prcoessor will generate code that uses platform specific built-in features, then it |
| 146 | * must call these methods from its constructor. Otherwise, requests to use these features will |
| 147 | * be denied. |
commit-bot@chromium.org | 8d47ddc | 2013-05-09 14:55:46 +0000 | [diff] [blame] | 148 | */ |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 149 | void setWillReadFragmentPosition() { fRequiredFeatures |= kFragmentPosition_RequiredFeature; } |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 150 | void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_RequiredFeature; } |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 151 | |
| 152 | void combineRequiredFeatures(const GrProcessor& other) { |
| 153 | fRequiredFeatures |= other.fRequiredFeatures; |
| 154 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 155 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 156 | template <typename PROC_SUBCLASS> void initClassID() { |
| 157 | static uint32_t kClassID = GenClassID(); |
| 158 | fClassID = kClassID; |
| 159 | } |
| 160 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 161 | private: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 162 | static uint32_t GenClassID() { |
| 163 | // fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The |
| 164 | // atomic inc returns the old value not the incremented value. So we add |
| 165 | // 1 to the returned value. |
| 166 | uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID)) + 1; |
| 167 | if (!id) { |
| 168 | SkFAIL("This should never wrap as it should only be called once for each GrProcessor " |
| 169 | "subclass."); |
| 170 | } |
| 171 | return id; |
| 172 | } |
| 173 | |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 174 | friend class GrProgramElement<GrProcessor>; |
| 175 | void addPendingIOs() const; |
| 176 | void removeRefs() const; |
| 177 | void pendingIOComplete() const; |
| 178 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 179 | enum { |
| 180 | kIllegalProcessorClassID = 0, |
| 181 | }; |
| 182 | static int32_t gCurrProcessorClassID; |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 183 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 184 | uint32_t fClassID; |
| 185 | RequiredFeatures fRequiredFeatures; |
| 186 | SkSTArray<4, const TextureSampler*, true> fTextureSamplers; |
| 187 | SkSTArray<1, const BufferAccess*, true> fBufferAccesses; |
| 188 | SkSTArray<1, const ImageStorageAccess*, true> fImageStorageAccesses; |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 189 | |
bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 190 | typedef GrProgramElement INHERITED; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 193 | GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures); |
| 194 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 195 | /** |
| 196 | * 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] | 197 | * an associated GrSamplerParams. TextureSamplers don't perform any coord manipulation to account |
| 198 | * for texture origin. |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 199 | */ |
| 200 | class GrProcessor::TextureSampler : public SkNoncopyable { |
| 201 | public: |
| 202 | /** |
| 203 | * Must be initialized before adding to a GrProcessor's texture access list. |
| 204 | */ |
| 205 | TextureSampler(); |
| 206 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 207 | TextureSampler(GrTexture*, const GrSamplerParams&); |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 208 | |
| 209 | explicit TextureSampler(GrTexture*, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 210 | GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 211 | SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode, |
| 212 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 213 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 214 | void reset(GrTexture*, const GrSamplerParams&, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 215 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 216 | void reset(GrTexture*, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 217 | GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 218 | SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode, |
| 219 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 220 | |
| 221 | bool operator==(const TextureSampler& that) const { |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 222 | return this->texture() == that.texture() && |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 223 | fParams == that.fParams && |
| 224 | fVisibility == that.fVisibility; |
| 225 | } |
| 226 | |
| 227 | bool operator!=(const TextureSampler& other) const { return !(*this == other); } |
| 228 | |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 229 | GrTexture* texture() const { return fTexture.get(); } |
| 230 | GrShaderFlags visibility() const { return fVisibility; } |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 231 | const GrSamplerParams& params() const { return fParams; } |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * For internal use by GrProcessor. |
| 235 | */ |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 236 | const GrGpuResourceRef* programTexture() const { return &fTexture; } |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 237 | |
| 238 | private: |
| 239 | |
| 240 | typedef GrTGpuResourceRef<GrTexture> ProgramTexture; |
| 241 | |
| 242 | ProgramTexture fTexture; |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 243 | GrSamplerParams fParams; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 244 | GrShaderFlags fVisibility; |
| 245 | |
| 246 | typedef SkNoncopyable INHERITED; |
| 247 | }; |
| 248 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 249 | /** |
| 250 | * Used to represent a texel buffer that will be read in a GrProcessor. It holds a GrBuffer along |
| 251 | * with an associated offset and texel config. |
| 252 | */ |
| 253 | class GrProcessor::BufferAccess : public SkNoncopyable { |
| 254 | public: |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame^] | 255 | BufferAccess() = default; |
| 256 | BufferAccess(GrPixelConfig texelConfig, GrBuffer* buffer, |
| 257 | GrShaderFlags visibility = kFragment_GrShaderFlag) { |
| 258 | this->reset(texelConfig, buffer, visibility); |
| 259 | } |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 260 | /** |
| 261 | * Must be initialized before adding to a GrProcessor's buffer access list. |
| 262 | */ |
| 263 | void reset(GrPixelConfig texelConfig, GrBuffer* buffer, |
| 264 | GrShaderFlags visibility = kFragment_GrShaderFlag) { |
| 265 | fTexelConfig = texelConfig; |
| 266 | fBuffer.set(SkRef(buffer), kRead_GrIOType); |
| 267 | fVisibility = visibility; |
| 268 | } |
| 269 | |
| 270 | bool operator==(const BufferAccess& that) const { |
| 271 | return fTexelConfig == that.fTexelConfig && |
| 272 | this->buffer() == that.buffer() && |
| 273 | fVisibility == that.fVisibility; |
| 274 | } |
| 275 | |
| 276 | bool operator!=(const BufferAccess& that) const { return !(*this == that); } |
| 277 | |
| 278 | GrPixelConfig texelConfig() const { return fTexelConfig; } |
| 279 | GrBuffer* buffer() const { return fBuffer.get(); } |
| 280 | GrShaderFlags visibility() const { return fVisibility; } |
| 281 | |
| 282 | /** |
| 283 | * For internal use by GrProcessor. |
| 284 | */ |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 285 | const GrGpuResourceRef* programBuffer() const { return &fBuffer;} |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 286 | |
| 287 | private: |
| 288 | GrPixelConfig fTexelConfig; |
| 289 | GrTGpuResourceRef<GrBuffer> fBuffer; |
| 290 | GrShaderFlags fVisibility; |
| 291 | |
| 292 | typedef SkNoncopyable INHERITED; |
| 293 | }; |
| 294 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 295 | /** |
| 296 | * This is used by a GrProcessor to access a texture using image load/store in its shader code. |
| 297 | * ImageStorageAccesses don't perform any coord manipulation to account for texture origin. |
| 298 | * Currently the format of the load/store data in the shader is inferred from the texture config, |
| 299 | * though it could be made explicit. |
| 300 | */ |
| 301 | class GrProcessor::ImageStorageAccess : public SkNoncopyable { |
| 302 | public: |
| 303 | ImageStorageAccess(sk_sp<GrTexture> texture, GrIOType ioType, GrSLMemoryModel, GrSLRestrict, |
| 304 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 305 | |
| 306 | bool operator==(const ImageStorageAccess& that) const { |
| 307 | return this->texture() == that.texture() && fVisibility == that.fVisibility; |
| 308 | } |
| 309 | |
| 310 | bool operator!=(const ImageStorageAccess& that) const { return !(*this == that); } |
| 311 | |
| 312 | GrTexture* texture() const { return fTexture.get(); } |
| 313 | GrShaderFlags visibility() const { return fVisibility; } |
| 314 | GrIOType ioType() const { return fTexture.ioType(); } |
| 315 | GrImageStorageFormat format() const { return fFormat; } |
| 316 | GrSLMemoryModel memoryModel() const { return fMemoryModel; } |
| 317 | GrSLRestrict restrict() const { return fRestrict; } |
| 318 | |
| 319 | /** |
| 320 | * For internal use by GrProcessor. |
| 321 | */ |
| 322 | const GrGpuResourceRef* programTexture() const { return &fTexture; } |
| 323 | |
| 324 | private: |
| 325 | GrTGpuResourceRef<GrTexture> fTexture; |
| 326 | GrShaderFlags fVisibility; |
| 327 | GrImageStorageFormat fFormat; |
| 328 | GrSLMemoryModel fMemoryModel; |
| 329 | GrSLRestrict fRestrict; |
| 330 | typedef SkNoncopyable INHERITED; |
| 331 | }; |
| 332 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 333 | #endif |