From: egdaniel Date: Tue, 9 Feb 2016 17:54:43 +0000 (-0800) Subject: Add some backend flexibility for shader declarations in ProgramBuilding. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~129^2~2148 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b80ec8b79c0a60a5a300870de838aa31bbc18cdd;p=platform%2Fupstream%2FlibSkiaSharp.git Add some backend flexibility for shader declarations in ProgramBuilding. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1682703003 Review URL: https://codereview.chromium.org/1682703003 --- diff --git a/src/gpu/gl/GrGLVaryingHandler.h b/src/gpu/gl/GrGLVaryingHandler.h index 50a87ad..fe8c3dc 100644 --- a/src/gpu/gl/GrGLVaryingHandler.h +++ b/src/gpu/gl/GrGLVaryingHandler.h @@ -24,6 +24,8 @@ public: GrSLPrecision fsPrecision = kDefault_GrSLPrecision); private: + void onFinalize() override {} + typedef GrGLProgramDataManager::VaryingInfo VaryingInfo; typedef GrGLProgramDataManager::VaryingInfoArray VaryingInfoArray; diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp index f97b854..7ec18a2 100644 --- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp @@ -216,6 +216,7 @@ void GrGLSLFragmentShaderBuilder::enableCustomOutput() { fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModifier, DeclaredColorOutputName()); + fProgramBuilder->finalizeFragmentOutputColor(fOutputs.back()); } } @@ -234,6 +235,7 @@ void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() { if (caps.mustDeclareFragmentShaderOutput()) { fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModifier, DeclaredSecondaryColorOutputName()); + fProgramBuilder->finalizeFragmentSecondaryColor(fOutputs.back()); } } diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h index 2249c3c..a277595 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.h +++ b/src/gpu/glsl/GrGLSLProgramBuilder.h @@ -69,6 +69,11 @@ public: virtual const GrGLSLUniformHandler* uniformHandler() const = 0; virtual GrGLSLVaryingHandler* varyingHandler() = 0; + // Used for backend customization of the output color and secondary color variables from the + // fragment processor. Only used if the outputs are explicitly declared in the shaders + virtual void finalizeFragmentOutputColor(GrGLSLShaderVar& outputColor) {} + virtual void finalizeFragmentSecondaryColor(GrGLSLShaderVar& outputColor) {} + // number of each input/output type in a single allocation block, used by many builders static const int kVarsPerBlock; diff --git a/src/gpu/glsl/GrGLSLVarying.cpp b/src/gpu/glsl/GrGLSLVarying.cpp index 279dd59..ea52fbe 100644 --- a/src/gpu/glsl/GrGLSLVarying.cpp +++ b/src/gpu/glsl/GrGLSLVarying.cpp @@ -105,6 +105,10 @@ void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) { fVertexInputs.push_back(var); } +void GrGLSLVaryingHandler::finalize() { + this->onFinalize(); +} + void GrGLSLVaryingHandler::appendDecls(const VarArray& vars, SkString* out) const { for (int i = 0; i < vars.count(); ++i) { vars[i].appendDecl(fProgramBuilder->glslCaps(), out); diff --git a/src/gpu/glsl/GrGLSLVarying.h b/src/gpu/glsl/GrGLSLVarying.h index 116ba09..2243197 100644 --- a/src/gpu/glsl/GrGLSLVarying.h +++ b/src/gpu/glsl/GrGLSLVarying.h @@ -79,6 +79,8 @@ public: , fFragOutputs(kVaryingsPerBlock) , fProgramBuilder(program) {} + virtual ~GrGLSLVaryingHandler() {} + typedef GrTAllocator VarArray; typedef GrGLSLProgramDataManager::VaryingHandle VaryingHandle; @@ -106,6 +108,10 @@ public: void emitAttributes(const GrGeometryProcessor& gp); + // This should be called once all attributes and varyings have been added to the + // GrGLSLVaryingHanlder and before getting/adding any of the declarations to the shaders. + void finalize(); + void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const; void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const; void getFragDecls(SkString* inputDecls, SkString* outputDecls) const; @@ -127,6 +133,8 @@ private: void addAttribute(const GrShaderVar& var); + virtual void onFinalize() = 0; + // helper function for get*Decls void appendDecls(const VarArray& vars, SkString* out) const;