diff options
-rw-r--r-- | bench/GLInstancedArraysBench.cpp | 20 | ||||
-rw-r--r-- | bench/GLVec4ScalarBench.cpp | 24 | ||||
-rw-r--r-- | bench/GLVertexAttributesBench.cpp | 20 | ||||
-rwxr-xr-x | src/gpu/gl/GrGLGLSL.cpp | 18 | ||||
-rwxr-xr-x | src/gpu/gl/GrGLGLSL.h | 5 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 6 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp | 11 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSL.cpp | 21 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSL.h | 9 |
9 files changed, 71 insertions, 63 deletions
diff --git a/bench/GLInstancedArraysBench.cpp b/bench/GLInstancedArraysBench.cpp index ea780f4c4c..4ef813c852 100644 --- a/bench/GLInstancedArraysBench.cpp +++ b/bench/GLInstancedArraysBench.cpp @@ -12,9 +12,9 @@ #if SK_SUPPORT_GPU #include "GLBench.h" #include "gl/GrGLContext.h" -#include "gl/GrGLGLSL.h" #include "gl/GrGLInterface.h" #include "gl/GrGLUtil.h" +#include "glsl/GrGLSL.h" #include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLShaderVar.h" @@ -107,7 +107,8 @@ private: /////////////////////////////////////////////////////////////////////////////////////////////////// GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { - const char* version = ctx->caps()->glslCaps()->versionDeclString(); + const GrGLSLCaps* glslCaps = ctx->caps()->glslCaps(); + const char* version = glslCaps->versionDeclString(); // setup vertex shader GrGLSLShaderVar aPosition("a_position", kVec2f_GrSLType, GrShaderVar::kAttribute_TypeModifier); @@ -115,11 +116,11 @@ GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { GrGLSLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_TypeModifier); SkString vshaderTxt(version); - aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + aPosition.appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); - aColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + aColor.appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); - oColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + oColor.appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); vshaderTxt.append( @@ -134,15 +135,14 @@ GrGLuint GLCpuPosInstancedArraysBench::setupShader(const GrGLContext* ctx) { // setup fragment shader GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier); SkString fshaderTxt(version); - GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->fStandard, - &fshaderTxt); + GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCaps, &fshaderTxt); oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); - oColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); + oColor.appendDecl(glslCaps, &fshaderTxt); fshaderTxt.append(";\n"); const char* fsOutName; - if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { - oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); + if (glslCaps->mustDeclareFragmentShaderOutput()) { + oFragColor.appendDecl(glslCaps, &fshaderTxt); fshaderTxt.append(";\n"); fsOutName = oFragColor.c_str(); } else { diff --git a/bench/GLVec4ScalarBench.cpp b/bench/GLVec4ScalarBench.cpp index 490b55ab52..e3837a7225 100644 --- a/bench/GLVec4ScalarBench.cpp +++ b/bench/GLVec4ScalarBench.cpp @@ -12,9 +12,9 @@ #if SK_SUPPORT_GPU #include "GLBench.h" #include "gl/GrGLContext.h" -#include "gl/GrGLGLSL.h" #include "gl/GrGLInterface.h" #include "gl/GrGLUtil.h" +#include "glsl/GrGLSL.h" #include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLShaderVar.h" @@ -93,7 +93,8 @@ private: /////////////////////////////////////////////////////////////////////////////////////////////////// GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { - const char* version = ctx->caps()->glslCaps()->versionDeclString(); + const GrGLSLCaps* glslCaps = ctx->caps()->glslCaps(); + const char* version = glslCaps->versionDeclString(); // this shader draws fNumStages overlapping circles of increasing opacity (coverage) and // decreasing size, with the center of each subsequent circle closer to the bottom-right @@ -106,13 +107,13 @@ GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { GrGLSLShaderVar oColor("o_color", kVec3f_GrSLType, GrShaderVar::kVaryingOut_TypeModifier); SkString vshaderTxt(version); - aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + aPosition.appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); - aColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + aColor.appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); - oPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + oPosition.appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); - oColor.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + oColor.appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); vshaderTxt.append( @@ -132,18 +133,17 @@ GrGLuint GLVec4ScalarBench::setupShader(const GrGLContext* ctx) { // next stage. GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier); SkString fshaderTxt(version); - GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->fStandard, - &fshaderTxt); + GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCaps, &fshaderTxt); oPosition.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); - oPosition.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); + oPosition.appendDecl(glslCaps, &fshaderTxt); fshaderTxt.append(";\n"); oColor.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); - oColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); + oColor.appendDecl(glslCaps, &fshaderTxt); fshaderTxt.append(";\n"); const char* fsOutName; - if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { - oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); + if (glslCaps->mustDeclareFragmentShaderOutput()) { + oFragColor.appendDecl(glslCaps, &fshaderTxt); fshaderTxt.append(";\n"); fsOutName = oFragColor.c_str(); } else { diff --git a/bench/GLVertexAttributesBench.cpp b/bench/GLVertexAttributesBench.cpp index 1051c31a9d..040ca18300 100644 --- a/bench/GLVertexAttributesBench.cpp +++ b/bench/GLVertexAttributesBench.cpp @@ -12,9 +12,9 @@ #if SK_SUPPORT_GPU #include "GLBench.h" #include "gl/GrGLContext.h" -#include "gl/GrGLGLSL.h" #include "gl/GrGLInterface.h" #include "gl/GrGLUtil.h" +#include "glsl/GrGLSL.h" #include "glsl/GrGLSLCaps.h" #include "glsl/GrGLSLShaderVar.h" #include <stdio.h> @@ -65,7 +65,8 @@ private: GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t attribs, uint32_t maxAttribs) { - const char* version = ctx->caps()->glslCaps()->versionDeclString(); + const GrGLSLCaps* glslCaps = ctx->caps()->glslCaps(); + const char* version = glslCaps->versionDeclString(); // setup vertex shader GrGLSLShaderVar aPosition("a_position", kVec4f_GrSLType, GrShaderVar::kAttribute_TypeModifier); @@ -73,7 +74,7 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a SkTArray<GrGLSLShaderVar> oVars; SkString vshaderTxt(version); - aPosition.appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + aPosition.appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); for (uint32_t i = 0; i < attribs; i++) { @@ -82,7 +83,7 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a aVars.push_back(GrGLSLShaderVar(aname.c_str(), kVec4f_GrSLType, GrShaderVar::kAttribute_TypeModifier)); - aVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + aVars.back().appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); } @@ -93,7 +94,7 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a oVars.push_back(GrGLSLShaderVar(oname.c_str(), kVec4f_GrSLType, GrShaderVar::kVaryingOut_TypeModifier)); - oVars.back().appendDecl(ctx->caps()->glslCaps(), &vshaderTxt); + oVars.back().appendDecl(glslCaps, &vshaderTxt); vshaderTxt.append(";\n"); } @@ -118,12 +119,11 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a // setup fragment shader GrGLSLShaderVar oFragColor("o_FragColor", kVec4f_GrSLType, GrShaderVar::kOut_TypeModifier); SkString fshaderTxt(version); - GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, gl->fStandard, - &fshaderTxt); + GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, *glslCaps, &fshaderTxt); const char* fsOutName; - if (ctx->caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { - oFragColor.appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); + if (glslCaps->mustDeclareFragmentShaderOutput()) { + oFragColor.appendDecl(glslCaps, &fshaderTxt); fshaderTxt.append(";\n"); fsOutName = oFragColor.c_str(); } else { @@ -132,7 +132,7 @@ GrGLuint GLVertexAttributesBench::setupShader(const GrGLContext* ctx, uint32_t a for (uint32_t i = 0; i < maxAttribs; i++) { oVars[i].setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); - oVars[i].appendDecl(ctx->caps()->glslCaps(), &fshaderTxt); + oVars[i].appendDecl(glslCaps, &fshaderTxt); fshaderTxt.append(";\n"); } diff --git a/src/gpu/gl/GrGLGLSL.cpp b/src/gpu/gl/GrGLGLSL.cpp index 4d2bf9794b..98a2386161 100755 --- a/src/gpu/gl/GrGLGLSL.cpp +++ b/src/gpu/gl/GrGLGLSL.cpp @@ -48,21 +48,3 @@ bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation } } -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) { - case kHigh_GrSLPrecision: - out->append("precision highp float;\n"); - break; - case kMedium_GrSLPrecision: - out->append("precision mediump float;\n"); - break; - case kLow_GrSLPrecision: - out->append("precision lowp float;\n"); - break; - default: - SkFAIL("Unknown precision value."); - } - } -} diff --git a/src/gpu/gl/GrGLGLSL.h b/src/gpu/gl/GrGLGLSL.h index fa2b6ae153..31e2de7d74 100755 --- a/src/gpu/gl/GrGLGLSL.h +++ b/src/gpu/gl/GrGLGLSL.h @@ -21,10 +21,5 @@ class GrGLContextInfo; */ bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation); -/** - * 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 ce02fe8ea9..feeac933dd 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -18,6 +18,7 @@ #include "GrTypes.h" #include "GrVertices.h" #include "builders/GrGLShaderStringBuilder.h" +#include "glsl/GrGLSL.h" #include "glsl/GrGLSLCaps.h" #include "SkStrokeRec.h" #include "SkTemplates.h" @@ -2952,8 +2953,9 @@ void GrGLGpu::createCopyProgram() { ); SkString fshaderTxt(version); - GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, this->glStandard(), - &fshaderTxt); + GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, + *this->glCaps().glslCaps(), + &fshaderTxt); vTexCoord.setTypeModifier(GrShaderVar::kVaryingIn_TypeModifier); vTexCoord.appendDecl(this->glCaps().glslCaps(), &fshaderTxt); fshaderTxt.append(";"); diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp index d31482a4bb..73098547a8 100644 --- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp @@ -8,7 +8,7 @@ #include "GrGLFragmentShaderBuilder.h" #include "GrGLProgramBuilder.h" #include "gl/GrGLGpu.h" -#include "gl/GrGLGLSL.h" +#include "glsl/GrGLSL.h" #include "glsl/GrGLSLCaps.h" #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) @@ -267,17 +267,16 @@ const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) { - GrGLGpu* gpu = fProgramBuilder->gpu(); this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString(); - GrGLAppendGLSLDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, - gpu->glStandard(), - &this->precisionQualifier()); + GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, + *fProgramBuilder->glslCaps(), + &this->precisionQualifier()); this->compileAndAppendLayoutQualifiers(); fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility, &this->uniforms()); this->appendDecls(fInputs, &this->inputs()); // We shouldn't have declared outputs on 1.10 - SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty()); + SkASSERT(k110_GrGLSLGeneration != fProgramBuilder->gpu()->glslGeneration() || fOutputs.empty()); this->appendDecls(fOutputs, &this->outputs()); return this->finalize(programId, GR_GL_FRAGMENT_SHADER, shaderIds); } diff --git a/src/gpu/glsl/GrGLSL.cpp b/src/gpu/glsl/GrGLSL.cpp index c77b7fab20..2de81ddd60 100644 --- a/src/gpu/glsl/GrGLSL.cpp +++ b/src/gpu/glsl/GrGLSL.cpp @@ -6,6 +6,7 @@ */ #include "GrGLSL.h" +#include "GrGLSLCaps.h" #include "SkString.h" bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) { @@ -22,6 +23,26 @@ bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration gen) { return false; } +void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p, + const GrGLSLCaps& glslCaps, + SkString* out) { + if (glslCaps.usesPrecisionModifiers()) { + switch (p) { + case kHigh_GrSLPrecision: + out->append("precision highp float;\n"); + break; + case kMedium_GrSLPrecision: + out->append("precision mediump float;\n"); + break; + case kLow_GrSLPrecision: + out->append("precision lowp float;\n"); + break; + default: + SkFAIL("Unknown precision value."); + } + } +} + void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor) { if (mulFactor.isOnes()) { *outAppend = SkString(); diff --git a/src/gpu/glsl/GrGLSL.h b/src/gpu/glsl/GrGLSL.h index 87b3d2daa4..a39f104fab 100644 --- a/src/gpu/glsl/GrGLSL.h +++ b/src/gpu/glsl/GrGLSL.h @@ -11,6 +11,8 @@ #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 { @@ -56,6 +58,13 @@ inline const char* GrGLSLTexture2DFunctionName(GrSLType coordType, GrGLSLGenerat } /** + * Adds a line of GLSL code to declare the default precision for float types. + */ +void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision, + const GrGLSLCaps& glslCaps, + SkString* out); + +/** * Converts a GrSLType to a string containing the name of the equivalent GLSL type. */ static inline const char* GrGLSLTypeString(GrSLType t) { |