diff options
author | jvanverth <jvanverth@google.com> | 2015-06-24 06:59:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-24 06:59:57 -0700 |
commit | cba99b88fd5fb39def7a094dc32c0745c7a1cfea (patch) | |
tree | c2574908e1a63570bbd0eef0689efd7b783ff6a9 /src/gpu | |
parent | 1b8e1b5c499e31a671232c8ccb10e778e0d8b154 (diff) |
Move GLSL-specific routines/classes to separate glsl directory
The purpose is to begin separating our GLSL-specific code from
our GL-specific code, so it can be used with the GL45 platform
Review URL: https://codereview.chromium.org/1202293002
Diffstat (limited to 'src/gpu')
37 files changed, 264 insertions, 225 deletions
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index 45a4ca3783..4e3d859e0b 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -26,7 +26,6 @@ #include "SkString.h" #include "SkTraceEvent.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/GrAALinearizingConvexPathRenderer.cpp index e03df81def..5ded4d4b43 100644 --- a/src/gpu/GrAALinearizingConvexPathRenderer.cpp +++ b/src/gpu/GrAALinearizingConvexPathRenderer.cpp @@ -24,7 +24,6 @@ #include "SkString.h" #include "SkTraceEvent.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index e5e742c993..a429caba11 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -22,7 +22,6 @@ #include "SkTLazy.h" #include "effects/GrRRectEffect.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/GrPathProcessor.cpp b/src/gpu/GrPathProcessor.cpp index 4660aa080f..b47fa6a973 100644 --- a/src/gpu/GrPathProcessor.cpp +++ b/src/gpu/GrPathProcessor.cpp @@ -10,6 +10,8 @@ #include "gl/GrGLPathProcessor.h" #include "gl/GrGLGpu.h" +#include "glsl/GrGLSLCaps.h" + GrPathProcessor::GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& localMatrix) diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp index 078bc00306..cdea9d01ff 100644 --- a/src/gpu/effects/GrBezierEffect.cpp +++ b/src/gpu/effects/GrBezierEffect.cpp @@ -8,7 +8,6 @@ #include "GrBezierEffect.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp index 2e09dd3fcb..2871f86ced 100644 --- a/src/gpu/effects/GrBitmapTextGeoProc.cpp +++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp @@ -10,7 +10,6 @@ #include "GrInvariantOutput.h" #include "GrTexture.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/effects/GrConstColorProcessor.cpp b/src/gpu/effects/GrConstColorProcessor.cpp index 5f8ad383c5..67dc84156f 100644 --- a/src/gpu/effects/GrConstColorProcessor.cpp +++ b/src/gpu/effects/GrConstColorProcessor.cpp @@ -7,7 +7,6 @@ #include "effects/GrConstColorProcessor.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/builders/GrGLProgramBuilder.h" class GLConstColorProcessor : public GrGLFragmentProcessor { diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp index 0048279044..c42ac5326c 100644 --- a/src/gpu/effects/GrConvexPolyEffect.cpp +++ b/src/gpu/effects/GrConvexPolyEffect.cpp @@ -9,7 +9,6 @@ #include "GrInvariantOutput.h" #include "SkPathPriv.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/builders/GrGLProgramBuilder.h" ////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index 4124d5b97d..72640824d2 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -7,7 +7,6 @@ #include "GrConvolutionEffect.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp index 794e55efdc..e50268173f 100644 --- a/src/gpu/effects/GrCustomXfermode.cpp +++ b/src/gpu/effects/GrCustomXfermode.cpp @@ -21,6 +21,7 @@ #include "gl/GrGLProcessor.h" #include "gl/GrGLProgramDataManager.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLCaps.h" bool GrCustomXfermode::IsSupportedMode(SkXfermode::Mode mode) { return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMode; diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index 186cc417ee..8ebb31f9fe 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -23,7 +23,6 @@ #include "SkGr.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/builders/GrGLProgramBuilder.h" /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp index 2bb929b6a1..fa05275a32 100755 --- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp +++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp @@ -13,7 +13,6 @@ #include "SkDistanceFieldGen.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/effects/GrDitherEffect.cpp b/src/gpu/effects/GrDitherEffect.cpp index 2589c3bb1e..0c252321ac 100644 --- a/src/gpu/effects/GrDitherEffect.cpp +++ b/src/gpu/effects/GrDitherEffect.cpp @@ -10,7 +10,6 @@ #include "GrInvariantOutput.h" #include "SkRect.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/builders/GrGLProgramBuilder.h" ////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp index bb75d54b1a..93876adafa 100644 --- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp +++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp @@ -6,7 +6,6 @@ */ #include "GrMatrixConvolutionEffect.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/effects/GrOvalEffect.cpp b/src/gpu/effects/GrOvalEffect.cpp index 5370611ba0..7b9fd0a7c8 100644 --- a/src/gpu/effects/GrOvalEffect.cpp +++ b/src/gpu/effects/GrOvalEffect.cpp @@ -11,7 +11,6 @@ #include "GrInvariantOutput.h" #include "SkRect.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/builders/GrGLProgramBuilder.h" ////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp index bf297fd7e3..0db9c13e38 100644 --- a/src/gpu/effects/GrRRectEffect.cpp +++ b/src/gpu/effects/GrRRectEffect.cpp @@ -13,7 +13,6 @@ #include "GrOvalEffect.h" #include "SkRRect.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/builders/GrGLProgramBuilder.h" // The effects defined here only handle rrect radii >= kRadiusMin. diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp index 9a5b3a7abb..370b2ce9a9 100644 --- a/src/gpu/effects/GrSimpleTextureEffect.cpp +++ b/src/gpu/effects/GrSimpleTextureEffect.cpp @@ -10,7 +10,6 @@ #include "GrTexture.h" #include "gl/GrGLCaps.h" #include "gl/GrGLProcessor.h" -#include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" #include "gl/builders/GrGLProgramBuilder.h" diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 0c53006bd2..22fd053c1d 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -9,6 +9,7 @@ #include "GrGLCaps.h" #include "GrGLContext.h" +#include "glsl/GrGLSLCaps.h" #include "SkTSearch.h" #include "SkTSort.h" @@ -51,8 +52,7 @@ GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions, fReadPixelsSupportedCache.reset(); - fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions, - ctxInfo, glInterface, *this))); + fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (contextOptions))); this->init(contextOptions, ctxInfo, glInterface); } @@ -450,7 +450,7 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, this->initConfigTexturableTable(ctxInfo, gli); this->initConfigRenderableTable(ctxInfo); - glslCaps->initShaderPrecisionTable(ctxInfo, gli); + this->initShaderPrecisionTable(ctxInfo, gli, glslCaps); this->applyOptionsOverrides(contextOptions); glslCaps->applyOptionsOverrides(contextOptions); @@ -1078,46 +1078,6 @@ SkString GrGLCaps::dump() const { return r; } -//////////////////////////////////////////////////////////////////////////////////////////// - -GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options, - const GrGLContextInfo& ctxInfo, - const GrGLInterface* gli, - const GrGLCaps& glCaps) { - fDropsTileOnZeroDivide = false; - fFBFetchSupport = false; - fFBFetchNeedsCustomOutput = false; - fBindlessTextureSupport = false; - fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; - fFBFetchColorName = NULL; - fFBFetchExtensionString = NULL; -} - -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("Advanced blend equation interaction: %s\n", - kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); - return r; -} - static GrGLenum precision_to_gl_float_type(GrSLPrecision p) { switch (p) { case kLow_GrSLPrecision: @@ -1144,16 +1104,17 @@ static GrGLenum shader_type_to_gl_shader(GrShaderType type) { return -1; } -void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, - const GrGLInterface* intf) { +void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, + const GrGLInterface* intf, + GrGLSLCaps* glslCaps) { if (kGLES_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(4, 1) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) { for (int s = 0; s < kGrShaderTypeCount; ++s) { if (kGeometry_GrShaderType != s) { GrShaderType shaderType = static_cast<GrShaderType>(s); GrGLenum glShader = shader_type_to_gl_shader(shaderType); - PrecisionInfo* first = NULL; - fShaderPrecisionVaries = false; + GrShaderCaps::PrecisionInfo* first = NULL; + glslCaps->fShaderPrecisionVaries = false; for (int p = 0; p < kGrSLPrecisionCount; ++p) { GrSLPrecision precision = static_cast<GrSLPrecision>(p); GrGLenum glPrecision = precision_to_gl_float_type(precision); @@ -1161,14 +1122,15 @@ void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, GrGLint bits; GR_GL_GetShaderPrecisionFormat(intf, glShader, glPrecision, range, &bits); if (bits) { - fFloatPrecisions[s][p].fLogRangeLow = range[0]; - fFloatPrecisions[s][p].fLogRangeHigh = range[1]; - fFloatPrecisions[s][p].fBits = bits; + glslCaps->fFloatPrecisions[s][p].fLogRangeLow = range[0]; + glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = range[1]; + glslCaps->fFloatPrecisions[s][p].fBits = bits; if (!first) { - first = &fFloatPrecisions[s][p]; + first = &glslCaps->fFloatPrecisions[s][p]; } - else if (!fShaderPrecisionVaries) { - fShaderPrecisionVaries = (*first != fFloatPrecisions[s][p]); + else if (!glslCaps->fShaderPrecisionVaries) { + glslCaps->fShaderPrecisionVaries = + (*first != glslCaps->fFloatPrecisions[s][p]); } } } @@ -1177,13 +1139,13 @@ void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, } else { // We're on a desktop GL that doesn't have precision info. Assume they're all 32bit float. - fShaderPrecisionVaries = false; + glslCaps->fShaderPrecisionVaries = false; for (int s = 0; s < kGrShaderTypeCount; ++s) { if (kGeometry_GrShaderType != s) { for (int p = 0; p < kGrSLPrecisionCount; ++p) { - fFloatPrecisions[s][p].fLogRangeLow = 127; - fFloatPrecisions[s][p].fLogRangeHigh = 127; - fFloatPrecisions[s][p].fBits = 23; + glslCaps->fFloatPrecisions[s][p].fLogRangeLow = 127; + glslCaps->fFloatPrecisions[s][p].fLogRangeHigh = 127; + glslCaps->fFloatPrecisions[s][p].fBits = 23; } } } @@ -1192,9 +1154,10 @@ void GrGLSLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, // the same as the vertex shader. Only fragment shaders were ever allowed to omit support for // highp. GS was added after GetShaderPrecisionFormat was added to the list of features that // are recommended against. - if (fGeometryShaderSupport) { + if (glslCaps->fGeometryShaderSupport) { for (int p = 0; p < kGrSLPrecisionCount; ++p) { - fFloatPrecisions[kGeometry_GrShaderType][p] = fFloatPrecisions[kVertex_GrShaderType][p]; + glslCaps->fFloatPrecisions[kGeometry_GrShaderType][p] = + glslCaps->fFloatPrecisions[kVertex_GrShaderType][p]; } } } diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index 3d3319968f..fd03da5e46 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -10,7 +10,7 @@ #define GrGLCaps_DEFINED #include "GrCaps.h" -#include "GrGLSL.h" +#include "glsl/GrGLSL.h" #include "GrGLStencilAttachment.h" #include "SkChecksum.h" #include "SkTHash.h" @@ -328,6 +328,10 @@ private: bool doReadPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const; + void initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, + const GrGLInterface* intf, + GrGLSLCaps* glslCaps); + // tracks configs that have been verified to pass the FBO completeness when // used as a color attachment VerifiedColorConfigs fVerifiedColorConfigs; @@ -387,88 +391,4 @@ private: typedef GrCaps INHERITED; }; -class GrGLSLCaps : public GrShaderCaps { -public: - SK_DECLARE_INST_COUNT(GrGLSLCaps) - - /** - * 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 the set of features supported in the current - * OpenGL context accessible via ctxInfo. - */ - GrGLSLCaps(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*, - const GrGLCaps&); - - /** - * 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* fbFetchColorName() const { return fFBFetchColorName; } - - const char* fbFetchExtensionString() const { return fFBFetchExtensionString; } - - bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; } - - 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; - } - - GrGLSLGeneration generation() const { return fGLSLGeneration; } - - /** - * Returns a string containing the caps info. - */ - SkString dump() const override; - -private: - // Must be called after fGeometryShaderSupport is initialized. - void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*); - - GrGLSLGeneration fGLSLGeneration; - - bool fDropsTileOnZeroDivide : 1; - bool fFBFetchSupport : 1; - bool fFBFetchNeedsCustomOutput : 1; - bool fBindlessTextureSupport : 1; - - const char* fFBFetchColorName; - const char* fFBFetchExtensionString; - - AdvBlendEqInteraction fAdvBlendEqInteraction; - - friend class GrGLCaps; // For initialization. - - typedef GrShaderCaps INHERITED; -}; - - #endif diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp index adbc5d9e86..ee840b3aab 100644 --- a/src/gpu/gl/GrGLContext.cpp +++ b/src/gpu/gl/GrGLContext.cpp @@ -6,6 +6,7 @@ */ #include "GrGLContext.h" +#include "GrGLGLSL.h" //////////////////////////////////////////////////////////////////////////////// @@ -34,7 +35,7 @@ GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContext return NULL; } - if (!GrGetGLSLGeneration(interface, &args.fGLSLGeneration)) { + if (!GrGLGetGLSLGeneration(interface, &args.fGLSLGeneration)) { return NULL; } diff --git a/src/gpu/gl/GrGLContext.h b/src/gpu/gl/GrGLContext.h index 8a4289471c..f86007a217 100644 --- a/src/gpu/gl/GrGLContext.h +++ b/src/gpu/gl/GrGLContext.h @@ -12,7 +12,6 @@ #include "gl/GrGLExtensions.h" #include "gl/GrGLInterface.h" #include "GrGLCaps.h" -#include "GrGLSL.h" #include "GrGLUtil.h" struct GrContextOptions; diff --git a/src/gpu/gl/GrGLSL.cpp b/src/gpu/gl/GrGLGLSL.cpp index 20e6e20938..ea65842c91 100644..100755 --- a/src/gpu/gl/GrGLSL.cpp +++ b/src/gpu/gl/GrGLGLSL.cpp @@ -5,11 +5,11 @@ * found in the LICENSE file. */ -#include "GrGLSL.h" +#include "GrGLGLSL.h" #include "GrGLShaderVar.h" #include "SkString.h" -bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) { +bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) { SkASSERT(generation); GrGLSLVersion ver = GrGLGetGLSLVersion(gl); if (GR_GLSL_INVALID_VER == ver) { @@ -47,7 +47,7 @@ bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) } } -const char* GrGetGLSLVersionDecl(const GrGLContextInfo& info) { +const char* GrGLGetGLSLVersionDecl(const GrGLContextInfo& info) { switch (info.glslGeneration()) { case k110_GrGLSLGeneration: if (kGLES_GrGLStandard == info.standard()) { @@ -89,21 +89,7 @@ const char* GrGetGLSLVersionDecl(const GrGLContextInfo& info) { return "<no version>"; } -bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) { - switch (gen) { - case k110_GrGLSLGeneration: - return false; - case k130_GrGLSLGeneration: - case k140_GrGLSLGeneration: - case k150_GrGLSLGeneration: - case k330_GrGLSLGeneration: - case k310es_GrGLSLGeneration: - return true; - } - return false; -} - -void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandard s, SkString* out) { +void GrGLAppendGLSLDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandard s, SkString* out) { // Desktop GLSL has added precision qualifiers but they don't do anything. if (kGLES_GrGLStandard == s) { switch (p) { @@ -121,15 +107,3 @@ void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, GrGLStandard } } } - -void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor) { - if (mulFactor.isOnes()) { - *outAppend = SkString(); - } - - if (mulFactor.isZeros()) { - outAppend->appendf("%s = vec4(0);", vec4VarName); - } else { - outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str()); - } -} diff --git a/src/gpu/gl/GrGLGLSL.h b/src/gpu/gl/GrGLGLSL.h new file mode 100755 index 0000000000..724765f1a8 --- /dev/null +++ b/src/gpu/gl/GrGLGLSL.h @@ -0,0 +1,36 @@ +/* + * 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 GrGLInitGLSL_DEFINED +#define GrGLInitGLSL_DEFINED + +#include "gl/GrGLInterface.h" +#include "glsl/GrGLSL.h" +#include "GrColor.h" +#include "GrTypesPriv.h" +#include "SkString.h" + +class GrGLContextInfo; + +/** + * Gets the most recent GLSL Generation compatible with the OpenGL context. + */ +bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation); + +/** + * Returns a string to include at the beginning of a shader to declare the GLSL + * version. + */ +const char* GrGLGetGLSLVersionDecl(const GrGLContextInfo&); + +/** + * Adds a line of GLSL code to declare the default precision for float types. + */ +void GrGLAppendGLSLDefaultFloatPrecisionDeclaration(GrSLPrecision, GrGLStandard, SkString* out); + + +#endif diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index b3bcdbe79c..20669b8e78 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -7,6 +7,7 @@ #include "GrGLGpu.h" +#include "GrGLGLSL.h" #include "GrGLStencilAttachment.h" #include "GrGLTextureRenderTarget.h" #include "GrGpuResourcePriv.h" @@ -18,6 +19,7 @@ #include "GrTypes.h" #include "GrVertices.h" #include "builders/GrGLShaderStringBuilder.h" +#include "glsl/GrGLSLCaps.h" #include "SkStrokeRec.h" #include "SkTemplates.h" @@ -2737,7 +2739,7 @@ bool GrGLGpu::copySurface(GrSurface* dst, void GrGLGpu::createCopyProgram() { - const char* version = GrGetGLSLVersionDecl(this->ctxInfo()); + const char* version = GrGLGetGLSLVersionDecl(this->ctxInfo()); GrGLShaderVar aVertex("a_vertex", kVec2f_GrSLType, GrShaderVar::kAttribute_TypeModifier); GrGLShaderVar uTexCoordXform("u_texCoordXform", kVec4f_GrSLType, @@ -2767,8 +2769,8 @@ void GrGLGpu::createCopyProgram() { ); SkString fshaderTxt(version); - GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, this->glStandard(), - &fshaderTxt); + GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, this->glStandard(), + &fshaderTxt); vTexCoord.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); vTexCoord.appendDecl(this->ctxInfo(), &fshaderTxt); fshaderTxt.append(";"); diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 679e3ba4ca..7a6c5974d8 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -15,7 +15,6 @@ #include "GrGLPathProcessor.h" #include "GrGLPathRendering.h" #include "GrGLShaderVar.h" -#include "GrGLSL.h" #include "GrGLXferProcessor.h" #include "GrPathProcessor.h" #include "GrPipeline.h" diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 22afefb011..086fb7ac2a 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -12,7 +12,6 @@ #include "builders/GrGLProgramBuilder.h" #include "GrGLContext.h" #include "GrGLProgramDesc.h" -#include "GrGLSL.h" #include "GrGLTexture.h" #include "GrGLProgramDataManager.h" diff --git a/src/gpu/gl/GrGLProgramDataManager.h b/src/gpu/gl/GrGLProgramDataManager.h index 21ee9b5931..644ba951c4 100644 --- a/src/gpu/gl/GrGLProgramDataManager.h +++ b/src/gpu/gl/GrGLProgramDataManager.h @@ -9,7 +9,6 @@ #define GrGLProgramDataManager_DEFINED #include "gl/GrGLShaderVar.h" -#include "gl/GrGLSL.h" #include "GrAllocator.h" #include "SkTArray.h" diff --git a/src/gpu/gl/GrGLShaderVar.h b/src/gpu/gl/GrGLShaderVar.h index e32683ab4f..77d46a507d 100644 --- a/src/gpu/gl/GrGLShaderVar.h +++ b/src/gpu/gl/GrGLShaderVar.h @@ -9,7 +9,6 @@ #define GrGLShaderVar_DEFINED #include "GrGLContext.h" -#include "GrGLSL.h" #include "GrShaderVar.h" #define USE_UNIFORM_FLOAT_ARRAYS true diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp index 557cdbfa58..c2eb09d85a 100644 --- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp @@ -7,7 +7,9 @@ #include "GrGLFragmentShaderBuilder.h" #include "GrGLProgramBuilder.h" -#include "../GrGLGpu.h" +#include "gl/GrGLGpu.h" +#include "gl/GrGLGLSL.h" +#include "glsl/GrGLSLCaps.h" #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(), R, X) @@ -249,10 +251,10 @@ const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) { GrGLGpu* gpu = fProgramBuilder->gpu(); - this->versionDecl() = GrGetGLSLVersionDecl(gpu->ctxInfo()); - GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, - gpu->glStandard(), - &this->precisionQualifier()); + this->versionDecl() = GrGLGetGLSLVersionDecl(gpu->ctxInfo()); + GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, + gpu->glStandard(), + &this->precisionQualifier()); this->compileAndAppendLayoutQualifiers(); fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility, &this->uniforms()); diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index 25d9716403..e253ab233b 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -14,6 +14,7 @@ #include "gl/GrGLSLPrettyPrint.h" #include "gl/GrGLUniformHandle.h" #include "gl/GrGLXferProcessor.h" +#include "glsl/GrGLSLCaps.h" #include "GrAutoLocaleSetter.h" #include "GrCoordTransform.h" #include "GrGLProgramBuilder.h" diff --git a/src/gpu/gl/builders/GrGLShaderBuilder.cpp b/src/gpu/gl/builders/GrGLShaderBuilder.cpp index 984233dd77..f0408afe21 100644 --- a/src/gpu/gl/builders/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLShaderBuilder.cpp @@ -10,6 +10,7 @@ #include "GrGLShaderStringBuilder.h" #include "../GrGLGpu.h" #include "../GrGLShaderVar.h" +#include "glsl/GrGLSLCaps.h" namespace { void append_texture_lookup(SkString* out, diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp index 6d5d344088..983de21021 100644 --- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp @@ -7,6 +7,7 @@ #include "GrGLVertexShaderBuilder.h" #include "GrGLProgramBuilder.h" +#include "../GrGLGLSL.h" #include "../GrGLGpu.h" #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) @@ -85,7 +86,7 @@ void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { bool GrGLVertexBuilder::compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) { - this->versionDecl() = GrGetGLSLVersionDecl(fProgramBuilder->ctxInfo()); + this->versionDecl() = GrGLGetGLSLVersionDecl(fProgramBuilder->ctxInfo()); this->compileAndAppendLayoutQualifiers(); fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility, &this->uniforms()); this->appendDecls(fInputs, &this->inputs()); diff --git a/src/gpu/glsl/GrGLSL.cpp b/src/gpu/glsl/GrGLSL.cpp new file mode 100644 index 0000000000..c77b7fab20 --- /dev/null +++ b/src/gpu/glsl/GrGLSL.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrGLSL.h" +#include "SkString.h" + +bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) { + switch (gen) { + case k110_GrGLSLGeneration: + return false; + case k130_GrGLSLGeneration: + case k140_GrGLSLGeneration: + case k150_GrGLSLGeneration: + case k330_GrGLSLGeneration: + case k310es_GrGLSLGeneration: + return true; + } + return false; +} + +void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor) { + if (mulFactor.isOnes()) { + *outAppend = SkString(); + } + + if (mulFactor.isZeros()) { + outAppend->appendf("%s = vec4(0);", vec4VarName); + } else { + outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str()); + } +} diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/glsl/GrGLSL.h index b338c991a6..efe31fe2dd 100644 --- a/src/gpu/gl/GrGLSL.h +++ b/src/gpu/glsl/GrGLSL.h @@ -8,14 +8,9 @@ #ifndef GrGLSL_DEFINED #define GrGLSL_DEFINED -#include "gl/GrGLInterface.h" -#include "GrColor.h" #include "GrTypesPriv.h" #include "SkString.h" -class GrGLContextInfo; -class GrGLShaderVar; - // Limited set of GLSL versions we build shaders for. Caller should round // down the GLSL version to one of these enums. enum GrGLSLGeneration { @@ -45,25 +40,9 @@ enum GrGLSLGeneration { k310es_GrGLSLGeneration, }; -/** - * Gets the most recent GLSL Generation compatible with the OpenGL context. - */ -bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation); - bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration); /** - * Returns a string to include at the beginning of a shader to declare the GLSL - * version. - */ -const char* GrGetGLSLVersionDecl(const GrGLContextInfo&); - -/** - * Adds a line of GLSL code to declare the default precision for float types. - */ -void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision, GrGLStandard, SkString* out); - -/** * Gets the name of the function that should be used to sample a 2D texture. Coord type is used * to indicate whether the texture is sampled using projective textured (kVec3f) or not (kVec2f). */ diff --git a/src/gpu/glsl/GrGLSLCaps.cpp b/src/gpu/glsl/GrGLSLCaps.cpp new file mode 100755 index 0000000000..cb72864347 --- /dev/null +++ b/src/gpu/glsl/GrGLSLCaps.cpp @@ -0,0 +1,47 @@ +/* + * 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" + +//////////////////////////////////////////////////////////////////////////////////////////// + +GrGLSLCaps::GrGLSLCaps(const GrContextOptions& options) { + fDropsTileOnZeroDivide = false; + fFBFetchSupport = false; + fFBFetchNeedsCustomOutput = false; + fBindlessTextureSupport = false; + fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; + fFBFetchColorName = NULL; + fFBFetchExtensionString = NULL; +} + +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("Advanced blend equation interaction: %s\n", + kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]); + return r; +} + diff --git a/src/gpu/glsl/GrGLSLCaps.h b/src/gpu/glsl/GrGLSLCaps.h new file mode 100755 index 0000000000..3264535704 --- /dev/null +++ b/src/gpu/glsl/GrGLSLCaps.h @@ -0,0 +1,94 @@ +/* + * 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" + +class GrGLSLCaps : public GrShaderCaps { +public: + SK_DECLARE_INST_COUNT(GrGLSLCaps) + + /** + * 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* fbFetchColorName() const { return fFBFetchColorName; } + + const char* fbFetchExtensionString() const { return fFBFetchExtensionString; } + + bool dropsTileOnZeroDivide() const { return fDropsTileOnZeroDivide; } + + 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; + } + + GrGLSLGeneration generation() const { return fGLSLGeneration; } + + /** + * Returns a string containing the caps info. + */ + SkString dump() const override; + +private: + GrGLSLGeneration fGLSLGeneration; + + bool fDropsTileOnZeroDivide : 1; + bool fFBFetchSupport : 1; + bool fFBFetchNeedsCustomOutput : 1; + bool fBindlessTextureSupport : 1; + + const char* fFBFetchColorName; + const char* fFBFetchExtensionString; + + AdvBlendEqInteraction fAdvBlendEqInteraction; + + friend class GrGLCaps; // For initialization. + + typedef GrShaderCaps INHERITED; +}; + + +#endif diff --git a/src/gpu/gl/GrGLSL_impl.h b/src/gpu/glsl/GrGLSL_impl.h index bdd69cc76b..bdd69cc76b 100644 --- a/src/gpu/gl/GrGLSL_impl.h +++ b/src/gpu/glsl/GrGLSL_impl.h |