diff options
author | Brian Salomon <bsalomon@google.com> | 2016-11-29 13:43:05 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-29 19:32:31 +0000 |
commit | 94efbf51f5a88d9e8aa961d3fbe38c5e335d6108 (patch) | |
tree | 2723f6ec5bfc291d4a52adf961165e3e74a098ca /src/gpu/glsl | |
parent | e11b614795bbe707d131ad599ead5be452e7c06f (diff) |
Merge GrGLSLCaps into GrShaderCaps
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5121
Change-Id: If8d13638f80f42161cbc766a2666c5789e5772c8
Reviewed-on: https://skia-review.googlesource.com/5121
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r-- | src/gpu/glsl/GrGLSL.cpp | 6 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSL.h | 374 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLCaps.cpp | 164 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLCaps.h | 260 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLFragmentProcessor.h | 7 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp | 22 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLPrimitiveProcessor.h | 6 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.cpp | 30 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.h | 5 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLShaderBuilder.cpp | 16 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLVarying.cpp | 8 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLXferProcessor.cpp | 2 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLXferProcessor.h | 6 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSL_impl.h | 175 |
14 files changed, 55 insertions, 1026 deletions
diff --git a/src/gpu/glsl/GrGLSL.cpp b/src/gpu/glsl/GrGLSL.cpp index 69f046cb82..2f69a3c5a2 100644 --- a/src/gpu/glsl/GrGLSL.cpp +++ b/src/gpu/glsl/GrGLSL.cpp @@ -5,9 +5,9 @@ * found in the LICENSE file. */ -#include "GrGLSL.h" -#include "GrGLSLCaps.h" +#include "GrShaderCaps.h" #include "SkString.h" +#include "../private/GrGLSL.h" bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) { switch (gen) { @@ -27,7 +27,7 @@ bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) { } void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, - const GrGLSLCaps& glslCaps, + const GrShaderCaps& glslCaps, SkString* out) { if (glslCaps.usesPrecisionModifiers()) { switch (p) { diff --git a/src/gpu/glsl/GrGLSL.h b/src/gpu/glsl/GrGLSL.h deleted file mode 100644 index 417f6d78d2..0000000000 --- a/src/gpu/glsl/GrGLSL.h +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrGLSL_DEFINED -#define GrGLSL_DEFINED - -#include "GrTypesPriv.h" -#include "SkString.h" - -class GrGLSLCaps; - -// Limited set of GLSL versions we build shaders for. Caller should round -// down the GLSL version to one of these enums. -enum GrGLSLGeneration { - /** - * Desktop GLSL 1.10 and ES2 shading language (based on desktop GLSL 1.20) - */ - k110_GrGLSLGeneration, - /** - * Desktop GLSL 1.30 - */ - k130_GrGLSLGeneration, - /** - * Desktop GLSL 1.40 - */ - k140_GrGLSLGeneration, - /** - * Desktop GLSL 1.50 - */ - k150_GrGLSLGeneration, - /** - * Desktop GLSL 3.30, and ES GLSL 3.00 - */ - k330_GrGLSLGeneration, - /** - * Desktop GLSL 4.00 - */ - k400_GrGLSLGeneration, - /** - * Desktop GLSL 4.20 - */ - k420_GrGLSLGeneration, - /** - * ES GLSL 3.10 only TODO Make GLSLCap objects to make this more granular - */ - k310es_GrGLSLGeneration, - /** - * ES GLSL 3.20 - */ - k320es_GrGLSLGeneration, -}; - -bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration); - -/** - * Adds a line of GLSL code to declare the default precision for float types. - */ -void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision, - const GrGLSLCaps& glslCaps, - SkString* out); - -/** - * Converts a GrSLPrecision to its corresponding GLSL precision qualifier. - */ -static inline const char* GrGLSLPrecisionString(GrSLPrecision p) { - switch (p) { - case kLow_GrSLPrecision: - return "lowp"; - case kMedium_GrSLPrecision: - return "mediump"; - case kHigh_GrSLPrecision: - return "highp"; - default: - SkFAIL("Unexpected precision type."); - return ""; - } -} - -/** - * Converts a GrSLType to a string containing the name of the equivalent GLSL type. - */ -static inline const char* GrGLSLTypeString(GrSLType t) { - switch (t) { - case kVoid_GrSLType: - return "void"; - case kFloat_GrSLType: - return "float"; - case kVec2f_GrSLType: - return "vec2"; - case kVec3f_GrSLType: - return "vec3"; - case kVec4f_GrSLType: - return "vec4"; - case kMat22f_GrSLType: - return "mat2"; - case kMat33f_GrSLType: - return "mat3"; - case kMat44f_GrSLType: - return "mat4"; - case kTexture2DSampler_GrSLType: - return "sampler2D"; - case kITexture2DSampler_GrSLType: - return "isampler2D"; - case kTextureExternalSampler_GrSLType: - return "samplerExternalOES"; - case kTexture2DRectSampler_GrSLType: - return "sampler2DRect"; - case kBufferSampler_GrSLType: - return "samplerBuffer"; - case kBool_GrSLType: - return "bool"; - case kInt_GrSLType: - return "int"; - case kUint_GrSLType: - return "uint"; - case kTexture2D_GrSLType: - return "texture2D"; - case kSampler_GrSLType: - return "sampler"; - case kImageStorage2D_GrSLType: - return "image2D"; - case kIImageStorage2D_GrSLType: - return "iimage2D"; - } - SkFAIL("Unknown shader var type."); - return ""; // suppress warning -} - -/** A generic base-class representing a GLSL expression. - * The instance can be a variable name, expression or vecN(0) or vecN(1). Does simple constant - * folding with help of 1 and 0. - * - * Clients should not use this class, rather the specific instantiations defined - * later, for example GrGLSLExpr4. - */ -template <typename Self> -class GrGLSLExpr { -public: - bool isOnes() const { return kOnes_ExprType == fType; } - bool isZeros() const { return kZeros_ExprType == fType; } - - const char* c_str() const { - if (kZeros_ExprType == fType) { - return Self::ZerosStr(); - } else if (kOnes_ExprType == fType) { - return Self::OnesStr(); - } - SkASSERT(!fExpr.isEmpty()); // Empty expressions should not be used. - return fExpr.c_str(); - } - - bool isValid() const { - return kFullExpr_ExprType != fType || !fExpr.isEmpty(); - } - -protected: - /** Constructs an invalid expression. - * Useful only as a return value from functions that never actually return - * this and instances that will be assigned to later. */ - GrGLSLExpr() - : fType(kFullExpr_ExprType) { - // The only constructor that is allowed to build an empty expression. - SkASSERT(!this->isValid()); - } - - /** Constructs an expression with all components as value v */ - explicit GrGLSLExpr(int v) { - if (v == 0) { - fType = kZeros_ExprType; - } else if (v == 1) { - fType = kOnes_ExprType; - } else { - fType = kFullExpr_ExprType; - fExpr.appendf(Self::CastIntStr(), v); - } - } - - /** Constructs an expression from a string. - * Argument expr is a simple expression or a parenthesized expression. */ - // TODO: make explicit once effects input Exprs. - GrGLSLExpr(const char expr[]) { - if (nullptr == expr) { // TODO: remove this once effects input Exprs. - fType = kOnes_ExprType; - } else { - fType = kFullExpr_ExprType; - fExpr = expr; - } - SkASSERT(this->isValid()); - } - - /** Constructs an expression from a string. - * Argument expr is a simple expression or a parenthesized expression. */ - // TODO: make explicit once effects input Exprs. - GrGLSLExpr(const SkString& expr) { - if (expr.isEmpty()) { // TODO: remove this once effects input Exprs. - fType = kOnes_ExprType; - } else { - fType = kFullExpr_ExprType; - fExpr = expr; - } - SkASSERT(this->isValid()); - } - - /** Constructs an expression from a string with one substitution. */ - GrGLSLExpr(const char format[], const char in0[]) - : fType(kFullExpr_ExprType) { - fExpr.appendf(format, in0); - } - - /** Constructs an expression from a string with two substitutions. */ - GrGLSLExpr(const char format[], const char in0[], const char in1[]) - : fType(kFullExpr_ExprType) { - fExpr.appendf(format, in0, in1); - } - - /** Returns expression casted to another type. - * Generic implementation that is called for non-trivial cases of casts. */ - template <typename T> - static Self VectorCastImpl(const T& other); - - /** Returns a GLSL multiplication: component-wise or component-by-scalar. - * The multiplication will be component-wise or multiply each component by a scalar. - * - * The returned expression will compute the value of: - * vecN(in0.x * in1.x, ...) if dim(T0) == dim(T1) (component-wise) - * vecN(in0.x * in1, ...) if dim(T1) == 1 (vector by scalar) - * vecN(in0 * in1.x, ...) if dim(T0) == 1 (scalar by vector) - */ - template <typename T0, typename T1> - static Self Mul(T0 in0, T1 in1); - - /** Returns a GLSL addition: component-wise or add a scalar to each component. - * Return value computes: - * vecN(in0.x + in1.x, ...) or vecN(in0.x + in1, ...) or vecN(in0 + in1.x, ...). - */ - template <typename T0, typename T1> - static Self Add(T0 in0, T1 in1); - - /** Returns a GLSL subtraction: component-wise or subtract compoments by a scalar. - * Return value computes - * vecN(in0.x - in1.x, ...) or vecN(in0.x - in1, ...) or vecN(in0 - in1.x, ...). - */ - template <typename T0, typename T1> - static Self Sub(T0 in0, T1 in1); - - /** Returns expression that accesses component(s) of the expression. - * format should be the form "%s.x" where 'x' is the component(s) to access. - * Caller is responsible for making sure the amount of components in the - * format string is equal to dim(T). - */ - template <typename T> - T extractComponents(const char format[]) const; - -private: - enum ExprType { - kZeros_ExprType, - kOnes_ExprType, - kFullExpr_ExprType, - }; - ExprType fType; - SkString fExpr; -}; - -class GrGLSLExpr1; -class GrGLSLExpr4; - -/** Class representing a float GLSL expression. */ -class GrGLSLExpr1 : public GrGLSLExpr<GrGLSLExpr1> { -public: - GrGLSLExpr1() - : INHERITED() { - } - explicit GrGLSLExpr1(int v) - : INHERITED(v) { - } - GrGLSLExpr1(const char* expr) - : INHERITED(expr) { - } - GrGLSLExpr1(const SkString& expr) - : INHERITED(expr) { - } - - static GrGLSLExpr1 VectorCast(const GrGLSLExpr1& expr); - -private: - GrGLSLExpr1(const char format[], const char in0[]) - : INHERITED(format, in0) { - } - GrGLSLExpr1(const char format[], const char in0[], const char in1[]) - : INHERITED(format, in0, in1) { - } - - static const char* ZerosStr(); - static const char* OnesStr(); - static const char* CastStr(); - static const char* CastIntStr(); - - friend GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); - friend GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); - friend GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); - - friend class GrGLSLExpr<GrGLSLExpr1>; - friend class GrGLSLExpr<GrGLSLExpr4>; - - typedef GrGLSLExpr<GrGLSLExpr1> INHERITED; -}; - -/** Class representing a float vector (vec4) GLSL expression. */ -class GrGLSLExpr4 : public GrGLSLExpr<GrGLSLExpr4> { -public: - GrGLSLExpr4() - : INHERITED() { - } - explicit GrGLSLExpr4(int v) - : INHERITED(v) { - } - GrGLSLExpr4(const char* expr) - : INHERITED(expr) { - } - GrGLSLExpr4(const SkString& expr) - : INHERITED(expr) { - } - - typedef GrGLSLExpr1 AExpr; - AExpr a() const; - - /** GLSL vec4 cast / constructor, eg vec4(floatv) -> vec4(floatv, floatv, floatv, floatv) */ - static GrGLSLExpr4 VectorCast(const GrGLSLExpr1& expr); - static GrGLSLExpr4 VectorCast(const GrGLSLExpr4& expr); - -private: - GrGLSLExpr4(const char format[], const char in0[]) - : INHERITED(format, in0) { - } - GrGLSLExpr4(const char format[], const char in0[], const char in1[]) - : INHERITED(format, in0, in1) { - } - - static const char* ZerosStr(); - static const char* OnesStr(); - static const char* CastStr(); - static const char* CastIntStr(); - - // The vector-by-scalar and scalar-by-vector binary operations. - friend GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1); - friend GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1); - friend GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1); - friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); - friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); - friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); - - // The vector-by-vector, i.e. component-wise, binary operations. - friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); - friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); - friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); - - friend class GrGLSLExpr<GrGLSLExpr4>; - - typedef GrGLSLExpr<GrGLSLExpr4> INHERITED; -}; - -/** - * Does an inplace mul, *=, of vec4VarName by mulFactor. - * A semicolon is added after the assignment. - */ -void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor); - -#include "GrGLSL_impl.h" - -#endif diff --git a/src/gpu/glsl/GrGLSLCaps.cpp b/src/gpu/glsl/GrGLSLCaps.cpp deleted file mode 100644 index 57e5a0c04e..0000000000 --- a/src/gpu/glsl/GrGLSLCaps.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#include "GrGLSLCaps.h" - -#include "GrContextOptions.h" - -//////////////////////////////////////////////////////////////////////////////////////////// - -GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options) { - fGLSLGeneration = k330_GrGLSLGeneration; - - fDropsTileOnZeroDivide = false; - fFBFetchSupport = false; - fFBFetchNeedsCustomOutput = false; - fBindlessTextureSupport = false; - fUsesPrecisionModifiers = false; - fCanUseAnyFunctionInShader = true; - fCanUseMinAndAbsTogether = true; - fMustForceNegatedAtanParamToFloat = false; - fRequiresLocalOutputColorForFBFetch = false; - fFlatInterpolationSupport = false; - fNoPerspectiveInterpolationSupport = false; - fMultisampleInterpolationSupport = false; - fSampleVariablesSupport = false; - fSampleMaskOverrideCoverageSupport = false; - fExternalTextureSupport = false; - fTexelFetchSupport = false; - fVersionDeclString = nullptr; - fShaderDerivativeExtensionString = nullptr; - fFragCoordConventionsExtensionString = nullptr; - fSecondaryOutputExtensionString = nullptr; - fExternalTextureExtensionString = nullptr; - fTexelBufferExtensionString = nullptr; - fNoPerspectiveInterpolationExtensionString = nullptr; - fMultisampleInterpolationExtensionString = nullptr; - fSampleVariablesExtensionString = nullptr; - fFBFetchColorName = nullptr; - fFBFetchExtensionString = nullptr; - fImageLoadStoreExtensionString = nullptr; - fMaxVertexSamplers = 0; - fMaxGeometrySamplers = 0; - fMaxFragmentSamplers = 0; - fMaxCombinedSamplers = 0; - fMaxVertexImageStorages = 0; - fMaxGeometryImageStorages = 0; - fMaxFragmentImageStorages = 0; - fMaxCombinedImageStorages = 0; - fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; -} - -SkString GrGLSLCaps::dump() const { - SkString r = INHERITED::dump(); - - static const char* kAdvBlendEqInteractionStr[] = { - "Not Supported", - "Automatic", - "General Enable", - "Specific Enables", - }; - GR_STATIC_ASSERT(0 == kNotSupported_AdvBlendEqInteraction); - GR_STATIC_ASSERT(1 == kAutomatic_AdvBlendEqInteraction); - GR_STATIC_ASSERT(2 == kGeneralEnable_AdvBlendEqInteraction); - GR_STATIC_ASSERT(3 == kSpecificEnables_AdvBlendEqInteraction); - GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAdvBlendEqInteractionStr) == kLast_AdvBlendEqInteraction + 1); - - r.appendf("--- GLSL-Specific ---\n"); - - r.appendf("FB Fetch Support: %s\n", (fFBFetchSupport ? "YES" : "NO")); - r.appendf("Drops tile on zero divide: %s\n", (fDropsTileOnZeroDivide ? "YES" : "NO")); - r.appendf("Bindless texture support: %s\n", (fBindlessTextureSupport ? "YES" : "NO")); - r.appendf("Uses precision modifiers: %s\n", (fUsesPrecisionModifiers ? "YES" : "NO")); - r.appendf("Can use any() function: %s\n", (fCanUseAnyFunctionInShader ? "YES" : "NO")); - r.appendf("Can use min() and abs() together: %s\n", (fCanUseMinAndAbsTogether ? "YES" : "NO")); - r.appendf("Must force negated atan param to float: %s\n", (fMustForceNegatedAtanParamToFloat ? - "YES" : "NO")); - r.appendf("Must use local out color for FBFetch: %s\n", (fRequiresLocalOutputColorForFBFetch ? - "YES" : "NO")); - r.appendf("Flat interpolation support: %s\n", (fFlatInterpolationSupport ? "YES" : "NO")); - r.appendf("No perspective interpolation support: %s\n", (fNoPerspectiveInterpolationSupport ? - "YES" : "NO")); - r.appendf("Multisample interpolation support: %s\n", (fMultisampleInterpolationSupport ? - "YES" : "NO")); - r.appendf("Sample variables support: %s\n", (fSampleVariablesSupport ? "YES" : "NO")); - r.appendf("Sample mask override coverage support: %s\n", (fSampleMaskOverrideCoverageSupport ? - "YES" : "NO")); - r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO")); - r.appendf("texelFetch support: %s\n", (fTexelFetchSupport ? "YES" : "NO")); - r.appendf("Max VS Samplers: %d\n", fMaxVertexSamplers); - r.appendf("Max GS Samplers: %d\n", fMaxGeometrySamplers); - r.appendf("Max FS Samplers: %d\n", fMaxFragmentSamplers); - r.appendf("Max Combined Samplers: %d\n", fMaxFragmentSamplers); - r.appendf("Max VS Image Storages: %d\n", fMaxVertexImageStorages); - r.appendf("Max GS Image Storages: %d\n", fMaxGeometryImageStorages); - r.appendf("Max FS Image Storages: %d\n", fMaxFragmentImageStorages); - r.appendf("Max Combined Image Storages: %d\n", fMaxFragmentImageStorages); - r.appendf("Advanced blend equation interaction: %s\n", - kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); - return r; -} - -void GrGLSLCaps::initSamplerPrecisionTable() { - // Determine the largest precision qualifiers that are effectively the same as lowp/mediump. - // e.g. if lowp == mediump, then use mediump instead of lowp. - GrSLPrecision effectiveMediumP[kGrShaderTypeCount]; - GrSLPrecision effectiveLowP[kGrShaderTypeCount]; - for (int s = 0; s < kGrShaderTypeCount; ++s) { - const PrecisionInfo* info = fFloatPrecisions[s]; - effectiveMediumP[s] = info[kHigh_GrSLPrecision] == info[kMedium_GrSLPrecision] ? - kHigh_GrSLPrecision : kMedium_GrSLPrecision; - effectiveLowP[s] = info[kMedium_GrSLPrecision] == info[kLow_GrSLPrecision] ? - effectiveMediumP[s] : kLow_GrSLPrecision; - } - - // Determine which precision qualifiers should be used with samplers. - for (int visibility = 0; visibility < (1 << kGrShaderTypeCount); ++visibility) { - GrSLPrecision mediump = kHigh_GrSLPrecision; - GrSLPrecision lowp = kHigh_GrSLPrecision; - for (int s = 0; s < kGrShaderTypeCount; ++s) { - if (visibility & (1 << s)) { - mediump = SkTMin(mediump, effectiveMediumP[s]); - lowp = SkTMin(lowp, effectiveLowP[s]); - } - - GR_STATIC_ASSERT(0 == kLow_GrSLPrecision); - GR_STATIC_ASSERT(1 == kMedium_GrSLPrecision); - GR_STATIC_ASSERT(2 == kHigh_GrSLPrecision); - - GR_STATIC_ASSERT((1 << kVertex_GrShaderType) == kVertex_GrShaderFlag); - GR_STATIC_ASSERT((1 << kGeometry_GrShaderType) == kGeometry_GrShaderFlag); - GR_STATIC_ASSERT((1 << kFragment_GrShaderType) == kFragment_GrShaderFlag); - GR_STATIC_ASSERT(3 == kGrShaderTypeCount); - } - - uint8_t* table = fSamplerPrecisions[visibility]; - table[kUnknown_GrPixelConfig] = kDefault_GrSLPrecision; - table[kAlpha_8_GrPixelConfig] = lowp; - table[kIndex_8_GrPixelConfig] = lowp; - table[kRGB_565_GrPixelConfig] = lowp; - table[kRGBA_4444_GrPixelConfig] = lowp; - table[kRGBA_8888_GrPixelConfig] = lowp; - table[kBGRA_8888_GrPixelConfig] = lowp; - table[kSRGBA_8888_GrPixelConfig] = lowp; - table[kSBGRA_8888_GrPixelConfig] = lowp; - table[kRGBA_8888_sint_GrPixelConfig] = lowp; - table[kETC1_GrPixelConfig] = lowp; - table[kLATC_GrPixelConfig] = lowp; - table[kR11_EAC_GrPixelConfig] = lowp; - table[kASTC_12x12_GrPixelConfig] = lowp; - table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision; - table[kAlpha_half_GrPixelConfig] = mediump; - table[kRGBA_half_GrPixelConfig] = mediump; - - GR_STATIC_ASSERT(17 == kGrPixelConfigCnt); - } -} - -void GrGLSLCaps::onApplyOptionsOverrides(const GrContextOptions& options) { -} diff --git a/src/gpu/glsl/GrGLSLCaps.h b/src/gpu/glsl/GrGLSLCaps.h deleted file mode 100644 index 11ce754527..0000000000 --- a/src/gpu/glsl/GrGLSLCaps.h +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#ifndef GrGLSLCaps_DEFINED -#define GrGLSLCaps_DEFINED - -#include "GrCaps.h" -#include "GrGLSL.h" -#include "GrSwizzle.h" - -namespace SkSL { - class GLSLCapsFactory; -} - -class GrGLSLCaps : public GrShaderCaps { -public: - /** - * Indicates how GLSL must interact with advanced blend equations. The KHR extension requires - * special layout qualifiers in the fragment shader. - */ - enum AdvBlendEqInteraction { - kNotSupported_AdvBlendEqInteraction, //<! No _blend_equation_advanced extension - kAutomatic_AdvBlendEqInteraction, //<! No interaction required - kGeneralEnable_AdvBlendEqInteraction, //<! layout(blend_support_all_equations) out - kSpecificEnables_AdvBlendEqInteraction, //<! Specific layout qualifiers per equation - - kLast_AdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction - }; - - /** - * Initializes the GrGLSLCaps to a default set of features - */ - GrGLSLCaps(const GrContextOptions&); - - /** - * Some helper functions for encapsulating various extensions to read FB Buffer on openglES - * - * TODO(joshualitt) On desktop opengl 4.2+ we can achieve something similar to this effect - */ - bool fbFetchSupport() const { return fFBFetchSupport; } - - bool fbFetchNeedsCustomOutput() const { return fFBFetchNeedsCustomOutput; } - - bool bindlessTextureSupport() const { return fBindlessTextureSupport; } - - const char* versionDeclString() const { return fVersionDeclString; } - - const char* fbFetchColorName() const { return fFBFetchColorName; } - - const char* fbFetchExtensionString() const { return fFBFetchExtensionString; } - - bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; } - - bool flatInterpolationSupport() const { return fFlatInterpolationSupport; } - - bool noperspectiveInterpolationSupport() const { return fNoPerspectiveInterpolationSupport; } - - bool multisampleInterpolationSupport() const { return fMultisampleInterpolationSupport; } - - bool sampleVariablesSupport() const { return fSampleVariablesSupport; } - - bool sampleMaskOverrideCoverageSupport() const { return fSampleMaskOverrideCoverageSupport; } - - bool externalTextureSupport() const { return fExternalTextureSupport; } - - bool texelFetchSupport() const { return fTexelFetchSupport; } - - AdvBlendEqInteraction advBlendEqInteraction() const { return fAdvBlendEqInteraction; } - - bool mustEnableAdvBlendEqs() const { - return fAdvBlendEqInteraction >= kGeneralEnable_AdvBlendEqInteraction; - } - - bool mustEnableSpecificAdvBlendEqs() const { - return fAdvBlendEqInteraction == kSpecificEnables_AdvBlendEqInteraction; - } - - bool mustDeclareFragmentShaderOutput() const { - return fGLSLGeneration > k110_GrGLSLGeneration; - } - - bool usesPrecisionModifiers() const { return fUsesPrecisionModifiers; } - - // Returns whether we can use the glsl funciton any() in our shader code. - bool canUseAnyFunctionInShader() const { return fCanUseAnyFunctionInShader; } - - bool canUseMinAndAbsTogether() const { return fCanUseMinAndAbsTogether; } - - bool mustForceNegatedAtanParamToFloat() const { return fMustForceNegatedAtanParamToFloat; } - - bool requiresLocalOutputColorForFBFetch() const { return fRequiresLocalOutputColorForFBFetch; } - - // Returns the string of an extension that must be enabled in the shader to support - // derivatives. If nullptr is returned then no extension needs to be enabled. Before calling - // this function, the caller should check that shaderDerivativeSupport exists. - const char* shaderDerivativeExtensionString() const { - SkASSERT(this->shaderDerivativeSupport()); - return fShaderDerivativeExtensionString; - } - - // Returns the string of an extension that will do all necessary coord transfomations needed - // when reading the fragment position. If such an extension does not exisits, this function - // returns a nullptr, and all transforms of the frag position must be done manually in the - // shader. - const char* fragCoordConventionsExtensionString() const { - return fFragCoordConventionsExtensionString; - } - - // This returns the name of an extension that must be enabled in the shader, if such a thing is - // required in order to use a secondary output in the shader. This returns a nullptr if no such - // extension is required. However, the return value of this function does not say whether dual - // source blending is supported. - const char* secondaryOutputExtensionString() const { - return fSecondaryOutputExtensionString; - } - - const char* externalTextureExtensionString() const { - SkASSERT(this->externalTextureSupport()); - return fExternalTextureExtensionString; - } - - const char* texelBufferExtensionString() const { - SkASSERT(this->texelBufferSupport()); - return fTexelBufferExtensionString; - } - - const char* noperspectiveInterpolationExtensionString() const { - SkASSERT(this->noperspectiveInterpolationSupport()); - return fNoPerspectiveInterpolationExtensionString; - } - - const char* multisampleInterpolationExtensionString() const { - SkASSERT(this->multisampleInterpolationSupport()); - return fMultisampleInterpolationExtensionString; - } - - const char* sampleVariablesExtensionString() const { - SkASSERT(this->sampleVariablesSupport()); - return fSampleVariablesExtensionString; - } - - const char* imageLoadStoreExtensionString() const { - SkASSERT(this->imageLoadStoreSupport()); - return fImageLoadStoreExtensionString; - } - - int maxVertexSamplers() const { return fMaxVertexSamplers; } - - int maxGeometrySamplers() const { return fMaxGeometrySamplers; } - - int maxFragmentSamplers() const { return fMaxFragmentSamplers; } - - int maxCombinedSamplers() const { return fMaxCombinedSamplers; } - - int maxVertexImageStorages() const { return fMaxVertexImageStorages; } - - int maxGeometryImageStorages() const { return fMaxGeometryImageStorages; } - - int maxFragmentImageStorages() const { return fMaxFragmentImageStorages; } - - int maxCombinedImageStorages() const { return fMaxCombinedImageStorages; } - - /** - * Given a texture's config, this determines what swizzle must be appended to accesses to the - * texture in generated shader code. Swizzling may be implemented in texture parameters or a - * sampler rather than in the shader. In this case the returned swizzle will always be "rgba". - */ - const GrSwizzle& configTextureSwizzle(GrPixelConfig config) const { - return fConfigTextureSwizzle[config]; - } - - /** Swizzle that should occur on the fragment shader outputs for a given config. */ - const GrSwizzle& configOutputSwizzle(GrPixelConfig config) const { - return fConfigOutputSwizzle[config]; - } - - /** Precision qualifier that should be used with a sampler, given its config and visibility. */ - GrSLPrecision samplerPrecision(GrPixelConfig config, GrShaderFlags visibility) const { - return static_cast<GrSLPrecision>(fSamplerPrecisions[visibility][config]); - } - - GrGLSLGeneration generation() const { return fGLSLGeneration; } - - /** - * Returns a string containing the caps info. - */ - SkString dump() const override; - -private: - /** GrCaps subclasses must call this after filling in the shader precision table. */ - void initSamplerPrecisionTable(); - - void onApplyOptionsOverrides(const GrContextOptions& options) override; - - GrGLSLGeneration fGLSLGeneration; - - bool fDropsTileOnZeroDivide : 1; - bool fFBFetchSupport : 1; - bool fFBFetchNeedsCustomOutput : 1; - bool fBindlessTextureSupport : 1; - bool fUsesPrecisionModifiers : 1; - bool fCanUseAnyFunctionInShader : 1; - bool fFlatInterpolationSupport : 1; - bool fNoPerspectiveInterpolationSupport : 1; - bool fMultisampleInterpolationSupport : 1; - bool fSampleVariablesSupport : 1; - bool fSampleMaskOverrideCoverageSupport : 1; - bool fExternalTextureSupport : 1; - bool fTexelFetchSupport : 1; - - // Used for specific driver bug work arounds - bool fCanUseMinAndAbsTogether : 1; - bool fMustForceNegatedAtanParamToFloat : 1; - bool fRequiresLocalOutputColorForFBFetch : 1; - - const char* fVersionDeclString; - - const char* fShaderDerivativeExtensionString; - const char* fFragCoordConventionsExtensionString; - const char* fSecondaryOutputExtensionString; - const char* fExternalTextureExtensionString; - const char* fTexelBufferExtensionString; - const char* fNoPerspectiveInterpolationExtensionString; - const char* fMultisampleInterpolationExtensionString; - const char* fSampleVariablesExtensionString; - const char* fImageLoadStoreExtensionString; - - const char* fFBFetchColorName; - const char* fFBFetchExtensionString; - - int fMaxVertexSamplers; - int fMaxGeometrySamplers; - int fMaxFragmentSamplers; - int fMaxCombinedSamplers; - - int fMaxVertexImageStorages; - int fMaxGeometryImageStorages; - int fMaxFragmentImageStorages; - int fMaxCombinedImageStorages; - - AdvBlendEqInteraction fAdvBlendEqInteraction; - - GrSwizzle fConfigTextureSwizzle[kGrPixelConfigCnt]; - GrSwizzle fConfigOutputSwizzle[kGrPixelConfigCnt]; - - uint8_t fSamplerPrecisions[(1 << kGrShaderTypeCount)][kGrPixelConfigCnt]; - - friend class GrGLCaps; // For initialization. - friend class GrVkCaps; - friend class SkSL::GLSLCapsFactory; - - typedef GrShaderCaps INHERITED; -}; - -#endif diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h index c8154231b5..c9230e4c92 100644 --- a/src/gpu/glsl/GrGLSLFragmentProcessor.h +++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h @@ -15,7 +15,6 @@ class GrProcessor; class GrProcessorKeyBuilder; -class GrGLSLCaps; class GrGLSLFPBuilder; class GrGLSLFPFragmentBuilder; @@ -112,7 +111,7 @@ public: struct EmitArgs { EmitArgs(GrGLSLFPFragmentBuilder* fragBuilder, GrGLSLUniformHandler* uniformHandler, - const GrGLSLCaps* caps, + const GrShaderCaps* caps, const GrFragmentProcessor& fp, const char* outputColor, const char* inputColor, @@ -134,7 +133,7 @@ public: , fGpImplementsDistanceVector(gpImplementsDistanceVector) {} GrGLSLFPFragmentBuilder* fFragBuilder; GrGLSLUniformHandler* fUniformHandler; - const GrGLSLCaps* fGLSLCaps; + const GrShaderCaps* fGLSLCaps; const GrFragmentProcessor& fFp; const char* fOutputColor; const char* fInputColor; @@ -149,7 +148,7 @@ public: void setData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& processor); - static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*) {} + static void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*) {} int numChildProcessors() const { return fChildProcessors.count(); } diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp index f6e1ad81d7..3d9802a720 100644 --- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp @@ -8,12 +8,12 @@ #include "GrGLSLFragmentShaderBuilder.h" #include "GrRenderTarget.h" #include "GrRenderTargetPriv.h" +#include "GrShaderCaps.h" #include "gl/GrGLGpu.h" -#include "glsl/GrGLSL.h" -#include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLProgramBuilder.h" #include "glsl/GrGLSLUniformHandler.h" #include "glsl/GrGLSLVarying.h" +#include "../private/GrGLSL.h" const char* GrGLSLFragmentShaderBuilder::kDstColorName = "_dstColor"; @@ -94,7 +94,7 @@ GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* p } bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { - const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps(); + const GrShaderCaps& glslCaps = *fProgramBuilder->shaderCaps(); switch (feature) { case kPixelLocalStorage_GLSLFeature: if (glslCaps.pixelLocalStorageSize() <= 0) { @@ -133,7 +133,7 @@ SkString GrGLSLFragmentShaderBuilder::ensureCoords2D(const GrShaderVar& coords) const char* GrGLSLFragmentShaderBuilder::fragmentPosition() { SkDEBUGCODE(fUsedProcessorFeatures |= GrProcessor::kFragmentPosition_RequiredFeature;) - const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); + const GrShaderCaps* glslCaps = fProgramBuilder->shaderCaps(); // We only declare "gl_FragCoord" when we're in the case where we want to use layout qualifiers // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier appears in the // declaration varies in earlier GLSL specs. So it is simpler to omit it. @@ -193,7 +193,7 @@ void GrGLSLFragmentShaderBuilder::appendOffsetToSample(const char* sampleIdx, Co } void GrGLSLFragmentShaderBuilder::maskSampleCoverage(const char* mask, bool invert) { - const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps(); + const GrShaderCaps& glslCaps = *fProgramBuilder->shaderCaps(); if (!glslCaps.sampleVariablesSupport()) { SkDEBUGFAIL("Attempted to mask sample coverage without support."); return; @@ -213,7 +213,7 @@ void GrGLSLFragmentShaderBuilder::maskSampleCoverage(const char* mask, bool inve } void GrGLSLFragmentShaderBuilder::overrideSampleCoverage(const char* mask) { - const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps(); + const GrShaderCaps& glslCaps = *fProgramBuilder->shaderCaps(); if (!glslCaps.sampleMaskOverrideCoverageSupport()) { SkDEBUGFAIL("Attempted to override sample coverage without support."); return; @@ -240,7 +240,7 @@ const char* GrGLSLFragmentShaderBuilder::dstColor() { return override; } - const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps(); + const GrShaderCaps* glslCaps = fProgramBuilder->shaderCaps(); if (glslCaps->fbFetchSupport()) { this->addFeature(1 << kFramebufferFetch_GLSLPrivateFeature, glslCaps->fbFetchExtensionString()); @@ -263,7 +263,7 @@ const char* GrGLSLFragmentShaderBuilder::dstColor() { void GrGLSLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquation equation) { SkASSERT(GrBlendEquationIsAdvanced(equation)); - const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); + const GrShaderCaps& caps = *fProgramBuilder->shaderCaps(); if (!caps.mustEnableAdvBlendEqs()) { return; } @@ -290,7 +290,7 @@ void GrGLSLFragmentShaderBuilder::enableCustomOutput() { void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() { SkASSERT(!fHasSecondaryOutput); fHasSecondaryOutput = true; - const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); + const GrShaderCaps& caps = *fProgramBuilder->shaderCaps(); if (const char* extension = caps.secondaryOutputExtensionString()) { this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension); } @@ -318,7 +318,7 @@ void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) { } const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const { - const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); + const GrShaderCaps& caps = *fProgramBuilder->shaderCaps(); return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutputName() : "gl_SecondaryFragColorEXT"; } @@ -334,7 +334,7 @@ GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const { void GrGLSLFragmentShaderBuilder::onFinalize() { fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outputs()); GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, - *fProgramBuilder->glslCaps(), + *fProgramBuilder->shaderCaps(), &this->precisionQualifier()); if (fUsedSampleOffsetArrays & (1 << kSkiaDevice_Coordinates)) { this->defineSampleOffsetArray(sample_offset_array_name(kSkiaDevice_Coordinates), diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h index b398cfd5c7..6c3d3a8963 100644 --- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h +++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h @@ -15,12 +15,12 @@ class GrBatchTracker; class GrPrimitiveProcessor; -class GrGLSLCaps; class GrGLSLPPFragmentBuilder; class GrGLSLGeometryBuilder; class GrGLSLGPBuilder; class GrGLSLVaryingHandler; class GrGLSLVertexBuilder; +class GrShaderCaps; class GrGLSLPrimitiveProcessor { public: @@ -71,7 +71,7 @@ public: GrGLSLPPFragmentBuilder* fragBuilder, GrGLSLVaryingHandler* varyingHandler, GrGLSLUniformHandler* uniformHandler, - const GrGLSLCaps* caps, + const GrShaderCaps* caps, const GrPrimitiveProcessor& gp, const char* outputColor, const char* outputCoverage, @@ -99,7 +99,7 @@ public: GrGLSLPPFragmentBuilder* fFragBuilder; GrGLSLVaryingHandler* fVaryingHandler; GrGLSLUniformHandler* fUniformHandler; - const GrGLSLCaps* fGLSLCaps; + const GrShaderCaps* fGLSLCaps; const GrPrimitiveProcessor& fGP; const char* fOutputColor; const char* fOutputCoverage; diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp index 0c1661d3b7..40e5a43ded 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp +++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp @@ -7,9 +7,10 @@ #include "glsl/GrGLSLProgramBuilder.h" +#include "GrCaps.h" #include "GrPipeline.h" +#include "GrShaderCaps.h" #include "GrTexturePriv.h" -#include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLGeometryProcessor.h" #include "glsl/GrGLSLVarying.h" @@ -98,7 +99,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr fVS.codeAppendf("// Primitive Processor %s\n", proc.name()); SkASSERT(!fGeometryProcessor); - fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps()); + fGeometryProcessor = proc.createGLSLInstance(*this->shaderCaps()); SkSTArray<4, SamplerHandle> texSamplers(proc.numTextureSamplers()); SkSTArray<2, SamplerHandle> bufferSamplers(proc.numBuffers()); @@ -112,7 +113,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr &fFS, this->varyingHandler(), this->uniformHandler(), - this->glslCaps(), + this->shaderCaps(), proc, outputColor->c_str(), outputCoverage->c_str(), @@ -182,7 +183,7 @@ void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp, GrGLSLFragmentProcessor::ImageStorages imageStorages(&fp, imageStorageArray.begin()); GrGLSLFragmentProcessor::EmitArgs args(&fFS, this->uniformHandler(), - this->glslCaps(), + this->shaderCaps(), fp, output->c_str(), input.isOnes() ? nullptr : input.c_str(), @@ -218,7 +219,7 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, fFS.enableSecondaryOutput(); } - if (this->glslCaps()->mustDeclareFragmentShaderOutput()) { + if (this->shaderCaps()->mustDeclareFragmentShaderOutput()) { fFS.enableCustomOutput(); } @@ -234,7 +235,7 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp, bool usePLSDstRead = (plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState); GrGLSLXferProcessor::EmitArgs args(&fFS, this->uniformHandler(), - this->glslCaps(), + this->shaderCaps(), xp, colorIn.c_str(), ignoresCoverage ? nullptr : coverageIn.c_str(), fFS.getPrimaryColorOutputName(), @@ -263,7 +264,8 @@ void GrGLSLProgramBuilder::emitSamplersAndImageStorages( name.printf("TextureSampler_%d", outTexSamplerHandles->count()); GrSLType samplerType = sampler.texture()->texturePriv().samplerType(); if (kTextureExternalSampler_GrSLType == samplerType) { - const char* externalFeatureString = this->glslCaps()->externalTextureExtensionString(); + const char* externalFeatureString = + this->shaderCaps()->externalTextureExtensionString(); // We shouldn't ever create a GrGLTexture that requires external sampler type SkASSERT(externalFeatureString); this->addFeature(sampler.visibility(), @@ -276,7 +278,7 @@ void GrGLSLProgramBuilder::emitSamplersAndImageStorages( } if (int numBuffers = processor.numBuffers()) { - SkASSERT(this->glslCaps()->texelBufferSupport()); + SkASSERT(this->shaderCaps()->texelBufferSupport()); GrShaderFlags texelBufferVisibility = kNone_GrShaderFlags; for (int b = 0; b < numBuffers; ++b) { @@ -287,7 +289,7 @@ void GrGLSLProgramBuilder::emitSamplersAndImageStorages( texelBufferVisibility |= access.visibility(); } - if (const char* extension = this->glslCaps()->texelBufferExtensionString()) { + if (const char* extension = this->shaderCaps()->texelBufferExtensionString()) { this->addFeature(texelBufferVisibility, 1 << GrGLSLShaderBuilder::kTexelBuffer_GLSLPrivateFeature, extension); @@ -316,8 +318,8 @@ void GrGLSLProgramBuilder::emitSampler(GrSLType samplerType, if (visibility & kFragment_GrShaderFlag) { ++fNumFragmentSamplers; } - GrSLPrecision precision = this->glslCaps()->samplerPrecision(config, visibility); - GrSwizzle swizzle = this->glslCaps()->configTextureSwizzle(config); + GrSLPrecision precision = this->shaderCaps()->samplerPrecision(config, visibility); + GrSwizzle swizzle = this->shaderCaps()->configTextureSwizzle(config); outSamplerHandles->emplace_back(this->uniformHandler()->addSampler(visibility, swizzle, samplerType, @@ -362,7 +364,7 @@ void GrGLSLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) { } bool GrGLSLProgramBuilder::checkSamplerCounts() { - const GrGLSLCaps& glslCaps = *this->glslCaps(); + const GrShaderCaps& glslCaps = *this->shaderCaps(); if (fNumVertexSamplers > glslCaps.maxVertexSamplers()) { GrCapsDebugf(this->caps(), "Program would use too many vertex samplers\n"); return false; @@ -385,7 +387,7 @@ bool GrGLSLProgramBuilder::checkSamplerCounts() { } bool GrGLSLProgramBuilder::checkImageStorageCounts() { - const GrGLSLCaps& glslCaps = *this->glslCaps(); + const GrShaderCaps& glslCaps = *this->shaderCaps(); if (fNumVertexImageStorages > glslCaps.maxVertexImageStorages()) { GrCapsDebugf(this->caps(), "Program would use too many vertex images\n"); return false; @@ -487,7 +489,7 @@ void GrGLSLProgramBuilder::finalizeShaders() { this->varyingHandler()->finalize(); fVS.finalize(kVertex_GrShaderFlag); if (this->primitiveProcessor().willUseGeoShader()) { - SkASSERT(this->glslCaps()->geometryShaderSupport()); + SkASSERT(this->shaderCaps()->geometryShaderSupport()); fGS.finalize(kGeometry_GrShaderFlag); } fFS.finalize(kFragment_GrShaderFlag); diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h index 5543537d19..fdb6e11c14 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.h +++ b/src/gpu/glsl/GrGLSLProgramBuilder.h @@ -8,6 +8,7 @@ #ifndef GrGLSLProgramBuilder_DEFINED #define GrGLSLProgramBuilder_DEFINED +#include "GrCaps.h" #include "GrGeometryProcessor.h" #include "GrGpu.h" #include "glsl/GrGLSLFragmentProcessor.h" @@ -19,10 +20,10 @@ #include "glsl/GrGLSLVertexShaderBuilder.h" #include "glsl/GrGLSLXferProcessor.h" -class GrGLSLCaps; class GrShaderVar; class GrGLSLVaryingHandler; class GrGLSLExpr4; +class GrShaderCaps; typedef SkSTArray<8, GrGLSLFragmentProcessor*, true> GrGLSLFragProcs; @@ -35,7 +36,7 @@ public: virtual ~GrGLSLProgramBuilder() {} virtual const GrCaps* caps() const = 0; - virtual const GrGLSLCaps* glslCaps() const = 0; + const GrShaderCaps* shaderCaps() const { return this->caps()->shaderCaps(); } const GrPrimitiveProcessor& primitiveProcessor() const { return fPrimProc; } const GrPipeline& pipeline() const { return fPipeline; } diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp index 79e977c5be..e2cbdee3ff 100644 --- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp @@ -6,9 +6,9 @@ */ #include "GrShaderVar.h" +#include "GrShaderCaps.h" #include "GrSwizzle.h" #include "glsl/GrGLSLShaderBuilder.h" -#include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLProgramBuilder.h" @@ -31,7 +31,7 @@ GrGLSLShaderBuilder::GrGLSLShaderBuilder(GrGLSLProgramBuilder* program) void GrGLSLShaderBuilder::declAppend(const GrShaderVar& var) { SkString tempDecl; - var.appendDecl(fProgramBuilder->glslCaps(), &tempDecl); + var.appendDecl(fProgramBuilder->shaderCaps(), &tempDecl); this->codeAppendf("%s;", tempDecl.c_str()); } @@ -46,7 +46,7 @@ void GrGLSLShaderBuilder::emitFunction(GrSLType returnType, this->functions().appendf(" %s", outName->c_str()); this->functions().append("("); for (int i = 0; i < argCnt; ++i) { - args[i].appendDecl(fProgramBuilder->glslCaps(), &this->functions()); + args[i].appendDecl(fProgramBuilder->shaderCaps(), &this->functions()); if (i < argCnt - 1) { this->functions().append(", "); } @@ -150,7 +150,7 @@ void GrGLSLShaderBuilder::appendTexelFetch(SkString* out, SamplerHandle samplerHandle, const char* coordExpr) const { const GrShaderVar& sampler = fProgramBuilder->samplerVariable(samplerHandle); - SkASSERT(fProgramBuilder->glslCaps()->texelFetchSupport()); + SkASSERT(fProgramBuilder->shaderCaps()->texelFetchSupport()); SkASSERT(GrSLTypeIsCombinedSamplerType(sampler.getType())); out->appendf("texelFetch(%s, %s)", sampler.c_str(), coordExpr); @@ -183,14 +183,14 @@ bool GrGLSLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionN void GrGLSLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { for (int i = 0; i < vars.count(); ++i) { - vars[i].appendDecl(fProgramBuilder->glslCaps(), out); + vars[i].appendDecl(fProgramBuilder->shaderCaps(), out); out->append(";\n"); } } void GrGLSLShaderBuilder::addLayoutQualifier(const char* param, InterfaceQualifier interface) { - SkASSERT(fProgramBuilder->glslCaps()->generation() >= k330_GrGLSLGeneration || - fProgramBuilder->glslCaps()->mustEnableAdvBlendEqs()); + SkASSERT(fProgramBuilder->shaderCaps()->generation() >= k330_GrGLSLGeneration || + fProgramBuilder->shaderCaps()->mustEnableAdvBlendEqs()); fLayoutParams[interface].push_back() = param; } @@ -219,7 +219,7 @@ void GrGLSLShaderBuilder::compileAndAppendLayoutQualifiers() { void GrGLSLShaderBuilder::finalize(uint32_t visibility) { SkASSERT(!fFinalized); - this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString(); + this->versionDecl() = fProgramBuilder->shaderCaps()->versionDeclString(); this->compileAndAppendLayoutQualifiers(); SkASSERT(visibility); fProgramBuilder->appendUniformDecls((GrShaderFlags) visibility, &this->uniforms()); diff --git a/src/gpu/glsl/GrGLSLVarying.cpp b/src/gpu/glsl/GrGLSLVarying.cpp index f264fc0921..7d841f5417 100644 --- a/src/gpu/glsl/GrGLSLVarying.cpp +++ b/src/gpu/glsl/GrGLSLVarying.cpp @@ -5,8 +5,8 @@ * found in the LICENSE file. */ +#include "GrShaderCaps.h" #include "glsl/GrGLSLVarying.h" -#include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLProgramBuilder.h" void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::Attribute* input, @@ -87,7 +87,7 @@ void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) { } void GrGLSLVaryingHandler::setNoPerspective() { - const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); + const GrShaderCaps& caps = *fProgramBuilder->shaderCaps(); if (!caps.noperspectiveInterpolationSupport()) { return; } @@ -131,7 +131,7 @@ void GrGLSLVaryingHandler::finalize() { void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) const { for (int i = 0; i < vars.count(); ++i) { - vars[i].appendDecl(fProgramBuilder->glslCaps(), out); + vars[i].appendDecl(fProgramBuilder->shaderCaps(), out); out->append(";"); } } @@ -148,7 +148,7 @@ void GrGLSLVaryingHandler::getGeomDecls(SkString* inputDecls, SkString* outputDe void GrGLSLVaryingHandler::getFragDecls(SkString* inputDecls, SkString* outputDecls) const { // We should not have any outputs in the fragment shader when using version 1.10 - SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() || + SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->shaderCaps()->generation() || fFragOutputs.empty()); this->appendDecls(fFragInputs, inputDecls); this->appendDecls(fFragOutputs, outputDecls); diff --git a/src/gpu/glsl/GrGLSLXferProcessor.cpp b/src/gpu/glsl/GrGLSLXferProcessor.cpp index 1f6db4ca20..0588513040 100644 --- a/src/gpu/glsl/GrGLSLXferProcessor.cpp +++ b/src/gpu/glsl/GrGLSLXferProcessor.cpp @@ -7,8 +7,8 @@ #include "glsl/GrGLSLXferProcessor.h" +#include "GrShaderCaps.h" #include "GrXferProcessor.h" -#include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLUniformHandler.h" diff --git a/src/gpu/glsl/GrGLSLXferProcessor.h b/src/gpu/glsl/GrGLSLXferProcessor.h index 69e00723a8..f3a1c688da 100644 --- a/src/gpu/glsl/GrGLSLXferProcessor.h +++ b/src/gpu/glsl/GrGLSLXferProcessor.h @@ -12,9 +12,9 @@ #include "glsl/GrGLSLUniformHandler.h" class GrXferProcessor; -class GrGLSLCaps; class GrGLSLXPBuilder; class GrGLSLXPFragmentBuilder; +class GrShaderCaps; class GrGLSLXferProcessor { public: @@ -27,7 +27,7 @@ public: struct EmitArgs { EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder, GrGLSLUniformHandler* uniformHandler, - const GrGLSLCaps* caps, + const GrShaderCaps* caps, const GrXferProcessor& xp, const char* inputColor, const char* inputCoverage, @@ -52,7 +52,7 @@ public: GrGLSLXPFragmentBuilder* fXPFragBuilder; GrGLSLUniformHandler* fUniformHandler; - const GrGLSLCaps* fGLSLCaps; + const GrShaderCaps* fGLSLCaps; const GrXferProcessor& fXP; const char* fInputColor; const char* fInputCoverage; diff --git a/src/gpu/glsl/GrGLSL_impl.h b/src/gpu/glsl/GrGLSL_impl.h deleted file mode 100644 index bdd69cc76b..0000000000 --- a/src/gpu/glsl/GrGLSL_impl.h +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrGLSL_impl_DEFINED -#define GrGLSL_impl_DEFINED - -template<typename Self> -template<typename T> -inline Self GrGLSLExpr<Self>::VectorCastImpl(const T& expr) { - if (expr.isZeros()) { - return Self(0); - } - if (expr.isOnes()) { - return Self(1); - } - return Self(Self::CastStr(), expr.c_str()); -} - -template<typename Self> -template<typename T0, typename T1> -inline Self GrGLSLExpr<Self>::Mul(T0 in0, T1 in1) { - if (in0.isZeros() || in1.isZeros()) { - return Self(0); - } - if (in0.isOnes()) { - return Self::VectorCast(in1); - } - if (in1.isOnes()) { - return Self::VectorCast(in0); - } - return Self("(%s * %s)", in0.c_str(), in1.c_str()); -} - -template<typename Self> -template<typename T0, typename T1> -inline Self GrGLSLExpr<Self>::Add(T0 in0, T1 in1) { - if (in1.isZeros()) { - return Self::VectorCast(in0); - } - if (in0.isZeros()) { - return Self::VectorCast(in1); - } - if (in0.isOnes() && in1.isOnes()) { - return Self(2); - } - return Self("(%s + %s)", in0.c_str(), in1.c_str()); -} - -template<typename Self> -template<typename T0, typename T1> -inline Self GrGLSLExpr<Self>::Sub(T0 in0, T1 in1) { - if (in1.isZeros()) { - return Self::VectorCast(in0); - } - if (in1.isOnes()) { - if (in0.isOnes()) { - return Self(0); - } - } - - return Self("(%s - %s)", in0.c_str(), in1.c_str()); -} - -template <typename Self> -template <typename T> -T GrGLSLExpr<Self>::extractComponents(const char format[]) const { - if (this->isZeros()) { - return T(0); - } - if (this->isOnes()) { - return T(1); - } - return T(format, this->c_str()); -} - -inline GrGLSLExpr1 GrGLSLExpr1::VectorCast(const GrGLSLExpr1& expr) { - return expr; -} - -inline const char* GrGLSLExpr1::ZerosStr() { - return "0"; -} - -inline const char* GrGLSLExpr1::OnesStr() { - return "1.0"; -} - -// GrGLSLExpr1::CastStr() is unimplemented because using them is likely an -// error. This is now caught compile-time. - -inline const char* GrGLSLExpr1::CastIntStr() { - return "%d"; -} - -inline GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) { - return GrGLSLExpr1::Mul(in0, in1); -} - -inline GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) { - return GrGLSLExpr1::Add(in0, in1); -} - -inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) { - return GrGLSLExpr1::Sub(in0, in1); -} - -inline const char* GrGLSLExpr4::ZerosStr() { - return "vec4(0)"; -} - -inline const char* GrGLSLExpr4::OnesStr() { - return "vec4(1)"; -} - -inline const char* GrGLSLExpr4::CastStr() { - return "vec4(%s)"; -} - -inline const char* GrGLSLExpr4::CastIntStr() { - return "vec4(%d)"; -} - -inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr1& expr) { - return INHERITED::VectorCastImpl(expr); -} - -inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) { - return expr; -} - -inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const { - return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a"); -} - -inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) { - return GrGLSLExpr4::Mul(in0, in1); -} - -inline GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) { - return GrGLSLExpr4::Add(in0, in1); -} - -inline GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) { - return GrGLSLExpr4::Sub(in0, in1); -} - -inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) { - return GrGLSLExpr4::Mul(in0, in1); -} - -inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) { - return GrGLSLExpr4::Add(in0, in1); -} - -inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) { - return GrGLSLExpr4::Sub(in0, in1); -} - -inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) { - return GrGLSLExpr4::Mul(in0, in1); -} - -inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) { - return GrGLSLExpr4::Add(in0, in1); -} - -inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) { - return GrGLSLExpr4::Sub(in0, in1); -} - -#endif |