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