From 1f50acff0dc09e50cc207846508d8e6459334b2a Mon Sep 17 00:00:00 2001 From: cdalton Date: Mon, 11 Apr 2016 11:30:50 -0700 Subject: Add appendPrecisionModifier method to GrGLSLShaderBuilder BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1881513002 Review URL: https://codereview.chromium.org/1881513002 --- src/gpu/glsl/GrGLSL.h | 17 +++++++++++++++++ src/gpu/glsl/GrGLSLShaderBuilder.cpp | 6 ++++++ src/gpu/glsl/GrGLSLShaderBuilder.h | 5 +++++ src/gpu/glsl/GrGLSLShaderVar.h | 22 +++------------------- 4 files changed, 31 insertions(+), 19 deletions(-) (limited to 'src/gpu/glsl') diff --git a/src/gpu/glsl/GrGLSL.h b/src/gpu/glsl/GrGLSL.h index 12c1f1fcc6..9f5f2b05b4 100644 --- a/src/gpu/glsl/GrGLSL.h +++ b/src/gpu/glsl/GrGLSL.h @@ -83,6 +83,23 @@ 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. */ diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp index 93b9f8a57a..795e5cb585 100644 --- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp @@ -35,6 +35,12 @@ void GrGLSLShaderBuilder::declAppend(const GrGLSLShaderVar& var) { this->codeAppendf("%s;", tempDecl.c_str()); } +void GrGLSLShaderBuilder::appendPrecisionModifier(GrSLPrecision precision) { + if (fProgramBuilder->glslCaps()->usesPrecisionModifiers()) { + this->codeAppendf("%s ", GrGLSLPrecisionString(precision)); + } +} + void GrGLSLShaderBuilder::emitFunction(GrSLType returnType, const char* name, int argCnt, diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.h b/src/gpu/glsl/GrGLSLShaderBuilder.h index 5b3a01f3e9..cddf7b2db4 100644 --- a/src/gpu/glsl/GrGLSLShaderBuilder.h +++ b/src/gpu/glsl/GrGLSLShaderBuilder.h @@ -93,6 +93,11 @@ public: */ void declAppend(const GrGLSLShaderVar& var); + /** + * Appends a precision qualifier followed by a space, if relevant for the GLSL version. + */ + void appendPrecisionModifier(GrSLPrecision); + /** Emits a helper function outside of main() in the fragment shader. */ void emitFunction(GrSLType returnType, const char* name, diff --git a/src/gpu/glsl/GrGLSLShaderVar.h b/src/gpu/glsl/GrGLSLShaderVar.h index a7d7479d39..9d162ecaa4 100644 --- a/src/gpu/glsl/GrGLSLShaderVar.h +++ b/src/gpu/glsl/GrGLSLShaderVar.h @@ -174,8 +174,9 @@ public: out->append(" "); } GrSLType effectiveType = this->getType(); - if (GrSLTypeAcceptsPrecision(effectiveType)) { - out->append(PrecisionString(glslCaps, fPrecision)); + if (glslCaps->usesPrecisionModifiers() && GrSLTypeAcceptsPrecision(effectiveType)) { + // Desktop GLSL has added precision qualifiers but they don't do anything. + out->appendf("%s ", GrGLSLPrecisionString(fPrecision)); } if (this->isArray()) { if (this->isUnsizedArray()) { @@ -210,23 +211,6 @@ public: fUseUniformFloatArrays ? "" : ".x"); } - static const char* PrecisionString(const GrGLSLCaps* glslCaps, GrSLPrecision p) { - // Desktop GLSL has added precision qualifiers but they don't do anything. - if (glslCaps->usesPrecisionModifiers()) { - switch (p) { - case kLow_GrSLPrecision: - return "lowp "; - case kMedium_GrSLPrecision: - return "mediump "; - case kHigh_GrSLPrecision: - return "highp "; - default: - SkFAIL("Unexpected precision type."); - } - } - return ""; - } - private: static const char* TypeModifierString(const GrGLSLCaps* glslCaps, TypeModifier t) { GrGLSLGeneration gen = glslCaps->generation(); -- cgit v1.2.3