blob: cd11ac4ac2599462d4e74a7a560e8182a21fecea [file] [log] [blame]
tomhudson@google.com168e6342012-04-18 17:49:20 +00001/*
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
joshualittb0a8a372014-09-23 09:50:21 -07008#ifndef GrProcessor_DEFINED
9#define GrProcessor_DEFINED
tomhudson@google.com168e6342012-04-18 17:49:20 +000010
Brian Salomon0c26a9d2017-07-06 10:09:38 -040011#include "../private/SkAtomics.h"
Brian Salomonb014cca2016-11-18 11:39:15 -050012#include "GrBuffer.h"
Brian Salomon0c26a9d2017-07-06 10:09:38 -040013#include "GrColor.h"
Brian Salomonb014cca2016-11-18 11:39:15 -050014#include "GrGpuResourceRef.h"
joshualittb0a8a372014-09-23 09:50:21 -070015#include "GrProcessorUnitTest.h"
bsalomon95740982014-09-04 13:12:37 -070016#include "GrProgramElement.h"
Brian Salomon2bbdcc42017-09-07 12:36:34 -040017#include "GrSamplerState.h"
Brian Salomonf9f45122016-11-29 11:59:17 -050018#include "GrShaderVar.h"
Robert Phillips8a02f652017-05-12 14:49:16 -040019#include "GrSurfaceProxyPriv.h"
Brian Salomon0c26a9d2017-07-06 10:09:38 -040020#include "GrTextureProxy.h"
egdaniel9e4d6d12014-10-15 13:49:02 -070021#include "SkMath.h"
robertphillipse004bfc2015-11-16 09:06:59 -080022#include "SkString.h"
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000023
tomhudson@google.com168e6342012-04-18 17:49:20 +000024class GrContext;
bsalomon@google.com77af6802013-10-02 13:04:56 +000025class GrCoordTransform;
egdaniel605dd0f2014-11-12 08:35:25 -080026class GrInvariantOutput;
Brian Osman32342f02017-03-04 08:12:46 -050027class GrResourceProvider;
bsalomon95740982014-09-04 13:12:37 -070028
joshualitteb2a6762014-12-04 11:35:33 -080029/**
30 * Used by processors to build their keys. It incorporates each per-processor key into a larger
31 * shader key.
32 */
33class GrProcessorKeyBuilder {
34public:
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
54private:
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
bsalomon98b33eb2014-10-15 11:05:26 -070059/** 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.com0ac6af42013-01-16 15:16:18 +000061
joshualittb0a8a372014-09-23 09:50:21 -070062 Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
mdempsky38f1f6f2015-08-27 12:57:01 -070063 processor must reach 0 before the thread terminates and the pool is destroyed.
bsalomon98b33eb2014-10-15 11:05:26 -070064 */
Brian Salomond61c9d92017-04-10 10:54:25 -040065class GrProcessor {
tomhudson@google.com168e6342012-04-18 17:49:20 +000066public:
Ethan Nicholasabff9562017-10-09 10:54:08 -040067 enum ClassID {
68 kAARectEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040069 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 Nicholasc9472af2017-10-10 16:30:21 -040093 kGrArithmeticFP_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040094 kGrBicubicEffect_ClassID,
95 kGrBitmapTextGeoProc_ClassID,
96 kGrBlurredEdgeFragmentProcessor_ClassID,
97 kGrCCPRCoverageProcessor_ClassID,
98 kGrCCPRPathProcessor_ClassID,
99 kGrCircleBlurFragmentProcessor_ClassID,
100 kGrCircleEffect_ClassID,
Brian Osmanc4f93ca2017-10-17 17:15:52 -0400101 kGrColorSpaceXformEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400102 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 Nicholas14efcbf2017-11-07 09:23:38 -0500119 kGrLumaColorFilterEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400120 kGrMagnifierEffect_ClassID,
121 kGrMatrixConvolutionEffect_ClassID,
122 kGrMeshTestProcessor_ClassID,
123 kGrMorphologyEffect_ClassID,
124 kGrNonlinearColorSpaceXformEffect_ClassID,
Ethan Nicholasd608c092017-10-26 09:30:08 -0400125 kGrOverdrawFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400126 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 Nicholasabff9562017-10-09 10:54:08 -0400143 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 Salomonab015ef2017-04-04 10:15:51 -0400159 virtual ~GrProcessor() = default;
tomhudson@google.com168e6342012-04-18 17:49:20 +0000160
Brian Salomonb014cca2016-11-18 11:39:15 -0500161 /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader
162 code. */
joshualitteb2a6762014-12-04 11:35:33 -0800163 virtual const char* name() const = 0;
bsalomon@google.com289efe02012-05-21 20:57:59 +0000164
Brian Salomonb014cca2016-11-18 11:39:15 -0500165 /** Human-readable dump of all information */
robertphillipse004bfc2015-11-16 09:06:59 -0800166 virtual SkString dumpInfo() const {
167 SkString str;
168 str.appendf("Missing data");
169 return str;
170 }
171
Brian Salomonf9f45122016-11-29 11:59:17 -0500172 /**
173 * Platform specific built-in features that a processor can request for the fragment shader.
174 */
cdalton87332102016-02-26 12:22:02 -0800175 enum RequiredFeatures {
176 kNone_RequiredFeatures = 0,
Ethan Nicholas38657112017-02-09 17:01:22 -0500177 kSampleLocations_RequiredFeature = 1 << 0
cdalton87332102016-02-26 12:22:02 -0800178 };
179
180 GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures);
181
182 RequiredFeatures requiredFeatures() const { return fRequiredFeatures; }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000183
tomhudson@google.comdcba4c22012-07-24 21:36:16 +0000184 void* operator new(size_t size);
185 void operator delete(void* target);
186
bsalomon@google.comd42aca32013-04-23 15:37:27 +0000187 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 Salomonb014cca2016-11-18 11:39:15 -0500194 /** Helper for down-casting to a GrProcessor subclass */
joshualitt49586be2014-09-16 08:21:41 -0700195 template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
196
Ethan Nicholasabff9562017-10-09 10:54:08 -0400197 ClassID classID() const { return fClassID; }
joshualitteb2a6762014-12-04 11:35:33 -0800198
bsalomon@google.com50db75c2013-01-11 13:54:30 +0000199protected:
Ethan Nicholasabff9562017-10-09 10:54:08 -0400200 GrProcessor(ClassID classID)
201 : fClassID(classID)
202 , fRequiredFeatures(kNone_RequiredFeatures) {}
bsalomon420d7e92014-10-16 09:18:09 -0700203
bsalomon@google.com50db75c2013-01-11 13:54:30 +0000204 /**
cdalton28f45b92016-03-07 13:58:26 -0800205 * 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.org8d47ddc2013-05-09 14:55:46 +0000208 */
cdalton28f45b92016-03-07 13:58:26 -0800209 void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_RequiredFeature; }
cdalton87332102016-02-26 12:22:02 -0800210
211 void combineRequiredFeatures(const GrProcessor& other) {
212 fRequiredFeatures |= other.fRequiredFeatures;
213 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000214
bsalomon0e08fc12014-10-15 08:19:04 -0700215private:
Brian Salomond61c9d92017-04-10 10:54:25 -0400216 GrProcessor(const GrProcessor&) = delete;
217 GrProcessor& operator=(const GrProcessor&) = delete;
218
Ethan Nicholasabff9562017-10-09 10:54:08 -0400219 ClassID fClassID;
220 RequiredFeatures fRequiredFeatures;
tomhudson@google.com168e6342012-04-18 17:49:20 +0000221};
222
cdalton87332102016-02-26 12:22:02 -0800223GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures);
224
Brian Salomonab015ef2017-04-04 10:15:51 -0400225/** A GrProcessor with the ability to access textures, buffers, and image storages. */
226class GrResourceIOProcessor : public GrProcessor {
227public:
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 Phillips9bee2e52017-05-29 12:37:20 -0400252 bool instantiate(GrResourceProvider* resourceProvider) const;
Robert Phillipsa91e0b72017-05-01 13:12:20 -0400253
Brian Salomonab015ef2017-04-04 10:15:51 -0400254protected:
Ethan Nicholasabff9562017-10-09 10:54:08 -0400255 GrResourceIOProcessor(ClassID classID)
256 : INHERITED(classID) {}
Brian Salomonab015ef2017-04-04 10:15:51 -0400257
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 Phillipsfbcef6e2017-06-15 12:07:18 -0400266 void addImageStorageAccess(const ImageStorageAccess*);
Brian Salomonab015ef2017-04-04 10:15:51 -0400267
268 bool hasSameSamplersAndAccesses(const GrResourceIOProcessor&) const;
269
Brian Salomond61c9d92017-04-10 10:54:25 -0400270 // 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 Salomonab015ef2017-04-04 10:15:51 -0400274
Brian Salomond61c9d92017-04-10 10:54:25 -0400275private:
Brian Salomonab015ef2017-04-04 10:15:51 -0400276 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 Salomon0bbecb22016-11-17 11:38:22 -0500283/**
Brian Salomonab015ef2017-04-04 10:15:51 -0400284 * Used to represent a texture that is required by a GrResourceIOProcessor. It holds a GrTexture
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400285 * along with an associated GrSamplerState. TextureSamplers don't perform any coord manipulation to
Brian Salomonab015ef2017-04-04 10:15:51 -0400286 * account for texture origin.
Brian Salomon0bbecb22016-11-17 11:38:22 -0500287 */
Brian Salomonffc2ec42017-07-25 14:59:03 -0400288class GrResourceIOProcessor::TextureSampler {
Brian Salomon0bbecb22016-11-17 11:38:22 -0500289public:
290 /**
291 * Must be initialized before adding to a GrProcessor's texture access list.
292 */
293 TextureSampler();
Brian Salomonffc2ec42017-07-25 14:59:03 -0400294 /**
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 Salomon2bbdcc42017-09-07 12:36:34 -0400301 , fSamplerState(that.fSamplerState)
Brian Salomonffc2ec42017-07-25 14:59:03 -0400302 , fVisibility(that.fVisibility) {}
Brian Salomon0bbecb22016-11-17 11:38:22 -0500303
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400304 TextureSampler(sk_sp<GrTextureProxy>, const GrSamplerState&);
Brian Salomonb17e6392017-07-28 13:41:51 -0400305
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400306 explicit TextureSampler(sk_sp<GrTextureProxy>,
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400307 GrSamplerState::Filter = GrSamplerState::Filter::kNearest,
308 GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp,
Robert Phillipsbc7a4fb2017-01-23 15:30:35 -0500309 GrShaderFlags visibility = kFragment_GrShaderFlag);
Brian Salomonb17e6392017-07-28 13:41:51 -0400310
311 TextureSampler& operator=(const TextureSampler&) = delete;
312
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400313 void reset(sk_sp<GrTextureProxy>, const GrSamplerState&,
Brian Salomon0bbecb22016-11-17 11:38:22 -0500314 GrShaderFlags visibility = kFragment_GrShaderFlag);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400315 void reset(sk_sp<GrTextureProxy>,
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400316 GrSamplerState::Filter = GrSamplerState::Filter::kNearest,
317 GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp,
Brian Salomon0bbecb22016-11-17 11:38:22 -0500318 GrShaderFlags visibility = kFragment_GrShaderFlag);
319
320 bool operator==(const TextureSampler& that) const {
Robert Phillips159e3c62017-06-19 12:02:00 -0400321 return this->proxy()->underlyingUniqueID() == that.proxy()->underlyingUniqueID() &&
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400322 fSamplerState == that.fSamplerState && fVisibility == that.fVisibility;
Brian Salomon0bbecb22016-11-17 11:38:22 -0500323 }
324
325 bool operator!=(const TextureSampler& other) const { return !(*this == other); }
326
Robert Phillips9bee2e52017-05-29 12:37:20 -0400327 // 'instantiate' should only ever be called at flush time.
328 bool instantiate(GrResourceProvider* resourceProvider) const {
Robert Phillips18166ee2017-06-01 12:55:44 -0400329 return SkToBool(fProxyRef.get()->instantiate(resourceProvider));
Robert Phillips9bee2e52017-05-29 12:37:20 -0400330 }
331
332 // 'peekTexture' should only ever be called after a successful 'instantiate' call
333 GrTexture* peekTexture() const {
Robert Phillips18166ee2017-06-01 12:55:44 -0400334 SkASSERT(fProxyRef.get()->priv().peekTexture());
335 return fProxyRef.get()->priv().peekTexture();
Robert Phillips9bee2e52017-05-29 12:37:20 -0400336 }
337
Robert Phillips18166ee2017-06-01 12:55:44 -0400338 GrTextureProxy* proxy() const { return fProxyRef.get()->asTextureProxy(); }
Brian Salomondb4183d2016-11-17 12:48:40 -0500339 GrShaderFlags visibility() const { return fVisibility; }
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400340 const GrSamplerState& samplerState() const { return fSamplerState; }
Brian Salomon0bbecb22016-11-17 11:38:22 -0500341
Brian Salomon06e547c2017-06-09 16:11:32 -0400342 bool isInitialized() const { return SkToBool(fProxyRef.get()); }
Brian Salomon0bbecb22016-11-17 11:38:22 -0500343 /**
344 * For internal use by GrProcessor.
345 */
Robert Phillips18166ee2017-06-01 12:55:44 -0400346 const GrSurfaceProxyRef* programProxy() const { return &fProxyRef; }
Brian Salomon0bbecb22016-11-17 11:38:22 -0500347
348private:
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400349 GrSurfaceProxyRef fProxyRef;
350 GrSamplerState fSamplerState;
351 GrShaderFlags fVisibility;
Brian Salomon0bbecb22016-11-17 11:38:22 -0500352};
353
Brian Salomonb014cca2016-11-18 11:39:15 -0500354/**
Brian Salomonab015ef2017-04-04 10:15:51 -0400355 * 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 Salomonb014cca2016-11-18 11:39:15 -0500357 */
Brian Salomonb17e6392017-07-28 13:41:51 -0400358class GrResourceIOProcessor::BufferAccess {
Brian Salomonb014cca2016-11-18 11:39:15 -0500359public:
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500360 BufferAccess() = default;
361 BufferAccess(GrPixelConfig texelConfig, GrBuffer* buffer,
362 GrShaderFlags visibility = kFragment_GrShaderFlag) {
363 this->reset(texelConfig, buffer, visibility);
364 }
Brian Salomonb014cca2016-11-18 11:39:15 -0500365 /**
Brian Salomonb17e6392017-07-28 13:41:51 -0400366 * 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 Salomonb014cca2016-11-18 11:39:15 -0500377 * 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 Salomonf9f45122016-11-29 11:59:17 -0500401 const GrGpuResourceRef* programBuffer() const { return &fBuffer;}
Brian Salomonb014cca2016-11-18 11:39:15 -0500402
403private:
Brian Salomonab015ef2017-04-04 10:15:51 -0400404 GrPixelConfig fTexelConfig;
405 GrTGpuResourceRef<GrBuffer> fBuffer;
406 GrShaderFlags fVisibility;
Brian Salomonb014cca2016-11-18 11:39:15 -0500407
408 typedef SkNoncopyable INHERITED;
409};
410
Brian Salomonf9f45122016-11-29 11:59:17 -0500411/**
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 Salomonb17e6392017-07-28 13:41:51 -0400417class GrResourceIOProcessor::ImageStorageAccess {
Brian Salomonf9f45122016-11-29 11:59:17 -0500418public:
Robert Phillips8a02f652017-05-12 14:49:16 -0400419 ImageStorageAccess(sk_sp<GrTextureProxy>, GrIOType, GrSLMemoryModel, GrSLRestrict,
Brian Salomonf9f45122016-11-29 11:59:17 -0500420 GrShaderFlags visibility = kFragment_GrShaderFlag);
Brian Salomonb17e6392017-07-28 13:41:51 -0400421 /**
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 Salomonf9f45122016-11-29 11:59:17 -0500434
435 bool operator==(const ImageStorageAccess& that) const {
Robert Phillips8a02f652017-05-12 14:49:16 -0400436 return this->proxy() == that.proxy() && fVisibility == that.fVisibility;
Brian Salomonf9f45122016-11-29 11:59:17 -0500437 }
438
439 bool operator!=(const ImageStorageAccess& that) const { return !(*this == that); }
440
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400441 GrTextureProxy* proxy() const { return fProxyRef.get()->asTextureProxy(); }
Brian Salomonf9f45122016-11-29 11:59:17 -0500442 GrShaderFlags visibility() const { return fVisibility; }
Robert Phillips8a02f652017-05-12 14:49:16 -0400443 GrIOType ioType() const { return fProxyRef.ioType(); }
Brian Salomonf9f45122016-11-29 11:59:17 -0500444 GrImageStorageFormat format() const { return fFormat; }
445 GrSLMemoryModel memoryModel() const { return fMemoryModel; }
446 GrSLRestrict restrict() const { return fRestrict; }
447
Robert Phillips9bee2e52017-05-29 12:37:20 -0400448 // 'instantiate' should only ever be called at flush time.
449 bool instantiate(GrResourceProvider* resourceProvider) const {
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400450 return SkToBool(fProxyRef.get()->instantiate(resourceProvider));
Robert Phillips9bee2e52017-05-29 12:37:20 -0400451 }
452 // 'peekTexture' should only ever be called after a successful 'instantiate' call
453 GrTexture* peekTexture() const {
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400454 SkASSERT(fProxyRef.get()->priv().peekTexture());
455 return fProxyRef.get()->priv().peekTexture();
Robert Phillips8a02f652017-05-12 14:49:16 -0400456 }
457
Brian Salomonf9f45122016-11-29 11:59:17 -0500458 /**
459 * For internal use by GrProcessor.
460 */
Robert Phillips8a02f652017-05-12 14:49:16 -0400461 const GrSurfaceProxyRef* programProxy() const { return &fProxyRef; }
Brian Salomonf9f45122016-11-29 11:59:17 -0500462
463private:
Robert Phillips8a02f652017-05-12 14:49:16 -0400464 GrSurfaceProxyRef fProxyRef;
465 GrShaderFlags fVisibility;
Brian Salomonab015ef2017-04-04 10:15:51 -0400466 GrImageStorageFormat fFormat;
Robert Phillips8a02f652017-05-12 14:49:16 -0400467 GrSLMemoryModel fMemoryModel;
468 GrSLRestrict fRestrict;
Brian Salomonf9f45122016-11-29 11:59:17 -0500469 typedef SkNoncopyable INHERITED;
470};
471
tomhudson@google.com168e6342012-04-18 17:49:20 +0000472#endif