aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-04-04 10:15:51 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-04 15:27:44 +0000
commitab015efc48c462ffdffebb45c02cd19efb254983 (patch)
tree0b120fe0e4238f89f7e4bb73a88a00301ecf1378 /include
parent19aff5dd5cd83141f12c234c4255a35f63e564cd (diff)
Move the ability to access textures, buffers, and image storages out from GrProcessor.
GrXferProcessor can no longer use this functionality so it is moved to a new intermediate class inherited by GrFragmentProcessor and GrPrimitiveProcessor. Change-Id: I4f30c89bdceb2d77b602bf0646107e0780881c26 Reviewed-on: https://skia-review.googlesource.com/11202 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrFragmentProcessor.h8
-rw-r--r--include/gpu/GrGpuResourceRef.h2
-rw-r--r--include/gpu/GrProcessor.h134
3 files changed, 80 insertions, 64 deletions
diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h
index c95c5e5956..acbc63ea77 100644
--- a/include/gpu/GrFragmentProcessor.h
+++ b/include/gpu/GrFragmentProcessor.h
@@ -23,7 +23,7 @@ class GrSwizzle;
GrCoordTransforms to receive a transformation of the local coordinates that map from local space
to the fragment being processed.
*/
-class GrFragmentProcessor : public GrProcessor {
+class GrFragmentProcessor : public GrResourceIOProcessor {
public:
/**
* In many instances (e.g. SkShader::asFragmentProcessor() implementations) it is desirable to
@@ -228,9 +228,9 @@ public:
&GrFragmentProcessor::coordTransform>;
using TextureAccessIter = FPItemIter<TextureSampler,
- GrProcessor,
- &GrProcessor::numTextureSamplers,
- &GrProcessor::textureSampler>;
+ GrResourceIOProcessor,
+ &GrResourceIOProcessor::numTextureSamplers,
+ &GrResourceIOProcessor::textureSampler>;
protected:
enum OptimizationFlags : uint32_t {
diff --git a/include/gpu/GrGpuResourceRef.h b/include/gpu/GrGpuResourceRef.h
index d6da1d21e9..d6ef6c13a9 100644
--- a/include/gpu/GrGpuResourceRef.h
+++ b/include/gpu/GrGpuResourceRef.h
@@ -79,7 +79,7 @@ private:
called. */
void pendingIOComplete() const;
- friend class GrProcessor;
+ friend class GrResourceIOProcessor;
GrGpuResource* fResource;
mutable bool fOwnRef;
diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h
index 8caec8e531..54691812e1 100644
--- a/include/gpu/GrProcessor.h
+++ b/include/gpu/GrProcessor.h
@@ -63,11 +63,7 @@ private:
*/
class GrProcessor : public GrProgramElement<GrProcessor> {
public:
- class TextureSampler;
- class BufferAccess;
- class ImageStorageAccess;
-
- virtual ~GrProcessor();
+ virtual ~GrProcessor() = default;
/** Human-meaningful string to identify this prcoessor; may be embedded in generated shader
code. */
@@ -80,26 +76,6 @@ public:
return str;
}
- int numTextureSamplers() const { return fTextureSamplers.count(); }
-
- /** Returns the access pattern for the texture at index. index must be valid according to
- numTextureSamplers(). */
- const TextureSampler& textureSampler(int index) const { return *fTextureSamplers[index]; }
-
- int numBuffers() const { return fBufferAccesses.count(); }
-
- /** Returns the access pattern for the buffer at index. index must be valid according to
- numBuffers(). */
- const BufferAccess& bufferAccess(int index) const { return *fBufferAccesses[index]; }
-
- int numImageStorages() const { return fImageStorageAccesses.count(); }
-
- /** Returns the access object for the image at index. index must be valid according to
- numImages(). */
- const ImageStorageAccess& imageStorageAccess(int index) const {
- return *fImageStorageAccesses[index];
- }
-
/**
* Platform specific built-in features that a processor can request for the fragment shader.
*/
@@ -131,18 +107,6 @@ protected:
GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_RequiredFeatures) {}
/**
- * Subclasses call these from their constructor to register sampler/image sources. The processor
- * subclass manages the lifetime of the objects (these functions only store pointers). The
- * TextureSampler and/or BufferAccess instances are typically member fields of the GrProcessor
- * subclass. These must only be called from the constructor because GrProcessors are immutable.
- */
- void addTextureSampler(const TextureSampler*);
- void addBufferAccess(const BufferAccess*);
- void addImageStorageAccess(const ImageStorageAccess*);
-
- bool hasSameSamplersAndAccesses(const GrProcessor &) const;
-
- /**
* If the prcoessor will generate code that uses platform specific built-in features, then it
* must call these methods from its constructor. Otherwise, requests to use these features will
* be denied.
@@ -172,9 +136,9 @@ private:
}
friend class GrProgramElement<GrProcessor>;
- void addPendingIOs() const;
- void removeRefs() const;
- void pendingIOComplete() const;
+ virtual void addPendingIOs() const {}
+ virtual void removeRefs() const {}
+ virtual void pendingIOComplete() const {}
enum {
kIllegalProcessorClassID = 0,
@@ -183,21 +147,73 @@ private:
uint32_t fClassID;
RequiredFeatures fRequiredFeatures;
- SkSTArray<4, const TextureSampler*, true> fTextureSamplers;
- SkSTArray<1, const BufferAccess*, true> fBufferAccesses;
- SkSTArray<1, const ImageStorageAccess*, true> fImageStorageAccesses;
typedef GrProgramElement INHERITED;
};
GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures);
+/** A GrProcessor with the ability to access textures, buffers, and image storages. */
+class GrResourceIOProcessor : public GrProcessor {
+public:
+ class TextureSampler;
+ class BufferAccess;
+ class ImageStorageAccess;
+
+ int numTextureSamplers() const { return fTextureSamplers.count(); }
+
+ /** Returns the access pattern for the texture at index. index must be valid according to
+ numTextureSamplers(). */
+ const TextureSampler& textureSampler(int index) const { return *fTextureSamplers[index]; }
+
+ int numBuffers() const { return fBufferAccesses.count(); }
+
+ /** Returns the access pattern for the buffer at index. index must be valid according to
+ numBuffers(). */
+ const BufferAccess& bufferAccess(int index) const { return *fBufferAccesses[index]; }
+
+ int numImageStorages() const { return fImageStorageAccesses.count(); }
+
+ /** Returns the access object for the image at index. index must be valid according to
+ numImages(). */
+ const ImageStorageAccess& imageStorageAccess(int index) const {
+ return *fImageStorageAccesses[index];
+ }
+
+protected:
+ GrResourceIOProcessor() = default;
+
+ /**
+ * Subclasses call these from their constructor to register sampler/image sources. The processor
+ * subclass manages the lifetime of the objects (these functions only store pointers). The
+ * TextureSampler and/or BufferAccess instances are typically member fields of the GrProcessor
+ * subclass. These must only be called from the constructor because GrProcessors are immutable.
+ */
+ void addTextureSampler(const TextureSampler*);
+ void addBufferAccess(const BufferAccess*);
+ void addImageStorageAccess(const ImageStorageAccess*);
+
+ bool hasSameSamplersAndAccesses(const GrResourceIOProcessor&) const;
+
+private:
+ friend class GrProgramElement<GrProcessor>;
+ void addPendingIOs() const override;
+ void removeRefs() const override;
+ void pendingIOComplete() const override;
+
+ SkSTArray<4, const TextureSampler*, true> fTextureSamplers;
+ SkSTArray<1, const BufferAccess*, true> fBufferAccesses;
+ SkSTArray<1, const ImageStorageAccess*, true> fImageStorageAccesses;
+
+ typedef GrProcessor INHERITED;
+};
+
/**
- * Used to represent a texture that is required by a GrProcessor. It holds a GrTexture along with
- * an associated GrSamplerParams. TextureSamplers don't perform any coord manipulation to account
- * for texture origin.
+ * Used to represent a texture that is required by a GrResourceIOProcessor. It holds a GrTexture
+ * along with an associated GrSamplerParams. TextureSamplers don't perform any coord manipulation to
+ * account for texture origin.
*/
-class GrProcessor::TextureSampler : public SkNoncopyable {
+class GrResourceIOProcessor::TextureSampler : public SkNoncopyable {
public:
/**
* Must be initialized before adding to a GrProcessor's texture access list.
@@ -258,10 +274,10 @@ private:
};
/**
- * Used to represent a texel buffer that will be read in a GrProcessor. It holds a GrBuffer along
- * with an associated offset and texel config.
+ * Used to represent a texel buffer that will be read in a GrResourceIOProcessor. It holds a
+ * GrBuffer along with an associated offset and texel config.
*/
-class GrProcessor::BufferAccess : public SkNoncopyable {
+class GrResourceIOProcessor::BufferAccess : public SkNoncopyable {
public:
BufferAccess() = default;
BufferAccess(GrPixelConfig texelConfig, GrBuffer* buffer,
@@ -296,9 +312,9 @@ public:
const GrGpuResourceRef* programBuffer() const { return &fBuffer;}
private:
- GrPixelConfig fTexelConfig;
- GrTGpuResourceRef<GrBuffer> fBuffer;
- GrShaderFlags fVisibility;
+ GrPixelConfig fTexelConfig;
+ GrTGpuResourceRef<GrBuffer> fBuffer;
+ GrShaderFlags fVisibility;
typedef SkNoncopyable INHERITED;
};
@@ -309,7 +325,7 @@ private:
* Currently the format of the load/store data in the shader is inferred from the texture config,
* though it could be made explicit.
*/
-class GrProcessor::ImageStorageAccess : public SkNoncopyable {
+class GrResourceIOProcessor::ImageStorageAccess : public SkNoncopyable {
public:
ImageStorageAccess(sk_sp<GrTexture> texture, GrIOType ioType, GrSLMemoryModel, GrSLRestrict,
GrShaderFlags visibility = kFragment_GrShaderFlag);
@@ -333,11 +349,11 @@ public:
const GrGpuResourceRef* programTexture() const { return &fTexture; }
private:
- GrTGpuResourceRef<GrTexture> fTexture;
- GrShaderFlags fVisibility;
- GrImageStorageFormat fFormat;
- GrSLMemoryModel fMemoryModel;
- GrSLRestrict fRestrict;
+ GrTGpuResourceRef<GrTexture> fTexture;
+ GrShaderFlags fVisibility;
+ GrImageStorageFormat fFormat;
+ GrSLMemoryModel fMemoryModel;
+ GrSLRestrict fRestrict;
typedef SkNoncopyable INHERITED;
};