diff options
author | Brian Salomon <bsalomon@google.com> | 2016-11-29 11:59:17 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-29 17:42:53 +0000 |
commit | f9f451213a3951d8a61568998de2ddbd643f6693 (patch) | |
tree | ba11ab458cbe8c654337bc704c52f4ca73f6b44a /include | |
parent | e18c97b73a0392b2eee57a111122dd5b637e36e6 (diff) |
Reland image storage with fixes.
Revert "Revert "Initial OpenGL Image support.""
This reverts commit 59dc41175d99d0a31c046aec0c26c4d82a3a3574.
BUG=skia:
Change-Id: Ibe3c87ce7f746f065fdbcc5a518388cc291112f5
Reviewed-on: https://skia-review.googlesource.com/5131
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrCaps.h | 1 | ||||
-rw-r--r-- | include/gpu/GrGpuResourceRef.h | 4 | ||||
-rw-r--r-- | include/gpu/GrProcessor.h | 73 | ||||
-rw-r--r-- | include/gpu/GrShaderVar.h | 25 | ||||
-rw-r--r-- | include/gpu/GrTypesPriv.h | 74 |
5 files changed, 150 insertions, 27 deletions
diff --git a/include/gpu/GrCaps.h b/include/gpu/GrCaps.h index c44f6c10d7..60d0c70543 100644 --- a/include/gpu/GrCaps.h +++ b/include/gpu/GrCaps.h @@ -269,6 +269,7 @@ public: virtual bool isConfigTexturable(GrPixelConfig config) const = 0; virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0; + virtual bool canConfigBeImageStorage(GrPixelConfig config) const = 0; bool suppressPrints() const { return fSuppressPrints; } diff --git a/include/gpu/GrGpuResourceRef.h b/include/gpu/GrGpuResourceRef.h index a91dcfeed5..a51d8148e7 100644 --- a/include/gpu/GrGpuResourceRef.h +++ b/include/gpu/GrGpuResourceRef.h @@ -43,6 +43,10 @@ public: /** Does this object own a pending read or write on the resource it is wrapping. */ bool ownsPendingIO() const { return fPendingIO; } + /** What type of IO does this represent? This is independent of whether a normal ref or a + pending IO is currently held. */ + GrIOType ioType() const { return fIOType; } + /** Shortcut for calling setResource() with NULL. It cannot be called after markingPendingIO is called. */ void reset(); diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h index e4f59ea5ed..95a669e64c 100644 --- a/include/gpu/GrProcessor.h +++ b/include/gpu/GrProcessor.h @@ -14,6 +14,7 @@ #include "GrProcessorUnitTest.h" #include "GrProgramElement.h" #include "GrSamplerParams.h" +#include "GrShaderVar.h" #include "SkMath.h" #include "SkString.h" #include "../private/SkAtomics.h" @@ -62,6 +63,7 @@ class GrProcessor : public GrProgramElement { public: class TextureSampler; class BufferAccess; + class ImageStorageAccess; virtual ~GrProcessor(); @@ -88,7 +90,17 @@ public: numBuffers(). */ const BufferAccess& bufferAccess(int index) const { return *fBufferAccesses[index]; } - /** Platform specific built-in features that a processor can request for the fragment shader. */ + 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. + */ enum RequiredFeatures { kNone_RequiredFeatures = 0, kFragmentPosition_RequiredFeature = 1 << 0, @@ -118,15 +130,16 @@ protected: GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_RequiredFeatures) {} /** - * Subclasses call these from their constructor to register sampler sources. The processor + * 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* bufferAccess); + void addBufferAccess(const BufferAccess*); + void addImageStorageAccess(const ImageStorageAccess*); - bool hasSameSamplers(const GrProcessor&) const; + bool hasSameSamplersAndAccesses(const GrProcessor &) const; /** * If the prcoessor will generate code that uses platform specific built-in features, then it @@ -145,7 +158,6 @@ protected: fClassID = kClassID; } - uint32_t fClassID; private: static uint32_t GenClassID() { // fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The @@ -164,9 +176,11 @@ private: }; static int32_t gCurrProcessorClassID; - RequiredFeatures fRequiredFeatures; - SkSTArray<4, const TextureSampler*, true> fTextureSamplers; - SkSTArray<2, const BufferAccess*, true> fBufferAccesses; + 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; }; @@ -175,7 +189,8 @@ GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures); /** * Used to represent a texture that is required by a GrProcessor. It holds a GrTexture along with - * an associated GrSamplerParams + * an associated GrSamplerParams. TextureSamplers don't perform any coord manipulation to account + * for texture origin. */ class GrProcessor::TextureSampler : public SkNoncopyable { public: @@ -257,7 +272,7 @@ public: /** * For internal use by GrProcessor. */ - const GrGpuResourceRef* getProgramBuffer() const { return &fBuffer;} + const GrGpuResourceRef* programBuffer() const { return &fBuffer;} private: GrPixelConfig fTexelConfig; @@ -267,4 +282,42 @@ private: typedef SkNoncopyable INHERITED; }; +/** + * This is used by a GrProcessor to access a texture using image load/store in its shader code. + * ImageStorageAccesses don't perform any coord manipulation to account for texture origin. + * 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 { +public: + ImageStorageAccess(sk_sp<GrTexture> texture, GrIOType ioType, GrSLMemoryModel, GrSLRestrict, + GrShaderFlags visibility = kFragment_GrShaderFlag); + + bool operator==(const ImageStorageAccess& that) const { + return this->texture() == that.texture() && fVisibility == that.fVisibility; + } + + bool operator!=(const ImageStorageAccess& that) const { return !(*this == that); } + + GrTexture* texture() const { return fTexture.get(); } + GrShaderFlags visibility() const { return fVisibility; } + GrIOType ioType() const { return fTexture.ioType(); } + GrImageStorageFormat format() const { return fFormat; } + GrSLMemoryModel memoryModel() const { return fMemoryModel; } + GrSLRestrict restrict() const { return fRestrict; } + + /** + * For internal use by GrProcessor. + */ + const GrGpuResourceRef* programTexture() const { return &fTexture; } + +private: + GrTGpuResourceRef<GrTexture> fTexture; + GrShaderFlags fVisibility; + GrImageStorageFormat fFormat; + GrSLMemoryModel fMemoryModel; + GrSLRestrict fRestrict; + typedef SkNoncopyable INHERITED; +}; + #endif diff --git a/include/gpu/GrShaderVar.h b/include/gpu/GrShaderVar.h index aaae107c19..1149f84cce 100644 --- a/include/gpu/GrShaderVar.h +++ b/include/gpu/GrShaderVar.h @@ -284,6 +284,14 @@ public: } } + void setImageStorageFormat(GrImageStorageFormat format); + + void setMemoryModel(GrSLMemoryModel); + + void setRestrict(GrSLRestrict); + + void setIOType(GrIOType); + void addModifier(const char* modifier) { if (modifier) { fExtraModifiers.appendf("%s ", modifier); @@ -310,23 +318,6 @@ public: } private: - static const char* TypeModifierString(TypeModifier t) { - switch (t) { - case kNone_TypeModifier: - return ""; - case kIn_TypeModifier: - return "in"; - case kInOut_TypeModifier: - return "inout"; - case kOut_TypeModifier: - return "out"; - case kUniform_TypeModifier: - return "uniform"; - } - SkFAIL("Unknown shader variable type modifier."); - return ""; // suppress warning - } - GrSLType fType; TypeModifier fTypeModifier; int fCount; diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h index 4ecab9cc01..51dccc5f7d 100644 --- a/include/gpu/GrTypesPriv.h +++ b/include/gpu/GrTypesPriv.h @@ -34,6 +34,8 @@ enum GrSLType { kBufferSampler_GrSLType, kTexture2D_GrSLType, kSampler_GrSLType, + kImageStorage2D_GrSLType, + kIImageStorage2D_GrSLType, }; enum GrShaderType { @@ -103,6 +105,8 @@ static inline bool GrSLTypeIsFloatType(GrSLType type) { case kUint_GrSLType: case kTexture2D_GrSLType: case kSampler_GrSLType: + case kImageStorage2D_GrSLType: + case kIImageStorage2D_GrSLType: return false; } SkFAIL("Unexpected type"); @@ -131,6 +135,8 @@ static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) { case kBool_GrSLType: case kTexture2D_GrSLType: case kSampler_GrSLType: + case kImageStorage2D_GrSLType: + case kIImageStorage2D_GrSLType: return false; } SkFAIL("Unexpected type"); @@ -159,6 +165,38 @@ static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) { case kBool_GrSLType: case kTexture2D_GrSLType: case kSampler_GrSLType: + case kImageStorage2D_GrSLType: + case kIImageStorage2D_GrSLType: + return false; + } + SkFAIL("Unexpected type"); + return false; +} + +static inline bool GrSLTypeIsImageStorage(GrSLType type) { + switch (type) { + case kImageStorage2D_GrSLType: + case kIImageStorage2D_GrSLType: + return true; + + case kVoid_GrSLType: + case kFloat_GrSLType: + case kVec2f_GrSLType: + case kVec3f_GrSLType: + case kVec4f_GrSLType: + case kMat22f_GrSLType: + case kMat33f_GrSLType: + case kMat44f_GrSLType: + case kInt_GrSLType: + case kUint_GrSLType: + case kBool_GrSLType: + case kTexture2D_GrSLType: + case kSampler_GrSLType: + case kTexture2DSampler_GrSLType: + case kITexture2DSampler_GrSLType: + case kTextureExternalSampler_GrSLType: + case kTexture2DRectSampler_GrSLType: + case kBufferSampler_GrSLType: return false; } SkFAIL("Unexpected type"); @@ -183,6 +221,8 @@ static inline bool GrSLTypeAcceptsPrecision(GrSLType type) { case kBufferSampler_GrSLType: case kTexture2D_GrSLType: case kSampler_GrSLType: + case kImageStorage2D_GrSLType: + case kIImageStorage2D_GrSLType: return true; case kVoid_GrSLType: @@ -300,6 +340,40 @@ static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { ////////////////////////////////////////////////////////////////////////////// +enum class GrImageStorageFormat { + kRGBA8, + kRGBA8i, + kRGBA16f, + kRGBA32f, +}; + +/** + * Describes types of caching and compiler optimizations allowed for certain variable types + * (currently only image storages). + **/ +enum class GrSLMemoryModel { + /** No special restrctions on memory accesses or compiler optimizations */ + kNone, + /** Cache coherent across shader invocations */ + kCoherent, + /** + * Disallows compiler from eliding loads or stores that appear redundant in a single + * invocation. Implies coherent. + */ + kVolatile +}; + +/** + * If kYes then the memory backing the varialble is only accessed via the variable. This is + * currently only used with image storages. + */ +enum class GrSLRestrict { + kYes, + kNo, +}; + +////////////////////////////////////////////////////////////////////////////// + /** * We have coverage effects that clip rendering to the edge of some geometric primitive. * This enum specifies how that clipping is performed. Not all factories that take a |