Chromium Code Reviews| Index: src/gpu/glsl/GrGLSLVarying.cpp |
| diff --git a/src/gpu/glsl/GrGLSLVarying.cpp b/src/gpu/glsl/GrGLSLVarying.cpp |
| index ea52fbe7ab9cf1972b7ae82921c22ea9a8ce28de..7535bb971d33342b94766f2beffd0a2bda87f126 100644 |
| --- a/src/gpu/glsl/GrGLSLVarying.cpp |
| +++ b/src/gpu/glsl/GrGLSLVarying.cpp |
| @@ -10,10 +10,24 @@ |
| #include "glsl/GrGLSLProgramBuilder.h" |
| void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::Attribute* input, |
| - const char* output) { |
| + const char* output, GrSLPrecision precision) { |
| GrSLType type = GrVertexAttribTypeToSLType(input->fType); |
| GrGLSLVertToFrag v(type); |
| - this->addVarying(input->fName, &v); |
| + this->addVarying(input->fName, &v, precision); |
| + this->writePassThroughAttribute(input, output, v); |
| +} |
| + |
| +void GrGLSLVaryingHandler::addFlatPassThroughAttribute(const GrGeometryProcessor::Attribute* input, |
| + const char* output, |
| + GrSLPrecision precision) { |
| + GrSLType type = GrVertexAttribTypeToSLType(input->fType); |
| + GrGLSLVertToFrag v(type); |
| + this->addFlatVarying(input->fName, &v, precision); |
| + this->writePassThroughAttribute(input, output, v); |
| +} |
| + |
| +void GrGLSLVaryingHandler::writePassThroughAttribute(const GrGeometryProcessor::Attribute* input, |
| + const char* output, const GrGLSLVarying& v) { |
| fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName); |
| if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { |
| @@ -23,62 +37,34 @@ void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::At |
| fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn()); |
| } |
| -void GrGLSLVaryingHandler::addVarying(const char* name, |
| - GrGLSLVarying* varying, |
| - GrSLPrecision precision) { |
| +void GrGLSLVaryingHandler::internalAddVarying(const char* name, |
| + GrGLSLVarying* varying, |
| + GrSLPrecision precision, |
| + bool flat) { |
| + bool willUseGeoShader = fProgramBuilder->primitiveProcessor().willUseGeoShader(); |
| SkASSERT(varying); |
| + SkASSERT(varying->vsVarying() || willUseGeoShader); |
|
egdaniel
2016/02/12 03:55:07
if we add this assert, shouldn't we also have SkAS
Chris Dalton
2016/02/12 16:25:28
My idea behind that assert was that it made sure t
|
| + |
| + VaryingInfo& v = fVaryings.push_back(); |
|
egdaniel
2016/02/12 03:55:07
I don't necessarily dislike this VaryingInfo thing
Chris Dalton
2016/02/12 16:25:28
Yeah, you get a compile error if you use both (whi
egdaniel
2016/02/12 16:33:58
Just throwing in an idea off your comment. Would i
|
| + v.fType = varying->fType; |
| + v.fPrecision = precision; |
| + v.fIsFlat = flat; |
| + v.fVisibility = kNone_GrShaderFlags; |
| if (varying->vsVarying()) { |
| - this->addVertexVarying(name, precision, varying); |
| + v.fVisibility |= kVertex_GrShaderFlag; |
| + fProgramBuilder->nameVariable(&v.fVsOut, 'v', name); |
| + varying->fVsOut = v.fVsOut.c_str(); |
| } |
| - if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { |
| - this->addGeomVarying(name, precision, varying); |
| + if (willUseGeoShader) { |
| + v.fVisibility |= kGeometry_GrShaderFlag; |
| + fProgramBuilder->nameVariable(&v.fGsOut, 'g', name); |
| + varying->fGsIn = v.fVsOut.c_str(); |
| + varying->fGsOut = v.fGsOut.c_str(); |
| } |
| if (varying->fsVarying()) { |
| - this->addFragVarying(precision, varying); |
| - } |
| -} |
| - |
| -void GrGLSLVaryingHandler::addVertexVarying(const char* name, |
| - GrSLPrecision precision, |
| - GrGLSLVarying* v) { |
| - fVertexOutputs.push_back(); |
| - fVertexOutputs.back().setType(v->fType); |
| - fVertexOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier); |
| - fVertexOutputs.back().setPrecision(precision); |
| - fProgramBuilder->nameVariable(fVertexOutputs.back().accessName(), 'v', name); |
| - v->fVsOut = fVertexOutputs.back().getName().c_str(); |
| -} |
| -void GrGLSLVaryingHandler::addGeomVarying(const char* name, |
| - GrSLPrecision precision, |
| - GrGLSLVarying* v) { |
| - // if we have a GS take each varying in as an array |
| - // and output as non-array. |
| - if (v->vsVarying()) { |
| - fGeomInputs.push_back(); |
| - fGeomInputs.back().setType(v->fType); |
| - fGeomInputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingIn_TypeModifier); |
| - fGeomInputs.back().setPrecision(precision); |
| - fGeomInputs.back().setUnsizedArray(); |
| - *fGeomInputs.back().accessName() = v->fVsOut; |
| - v->fGsIn = v->fVsOut; |
| + v.fVisibility |= kFragment_GrShaderFlag; |
| + varying->fFsIn = (willUseGeoShader ? v.fGsOut : v.fVsOut).c_str(); |
| } |
| - |
| - if (v->fsVarying()) { |
| - fGeomOutputs.push_back(); |
| - fGeomOutputs.back().setType(v->fType); |
| - fGeomOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier); |
| - fGeomOutputs.back().setPrecision(precision); |
| - fProgramBuilder->nameVariable(fGeomOutputs.back().accessName(), 'g', name); |
| - v->fGsOut = fGeomOutputs.back().getName().c_str(); |
| - } |
| -} |
| - |
| -void GrGLSLVaryingHandler::addFragVarying(GrSLPrecision precision, GrGLSLVarying* v) { |
| - v->fFsIn = v->fGsOut ? v->fGsOut : v->fVsOut; |
| - fFragInputs.push_back().set(v->fType, |
| - GrGLSLShaderVar::kVaryingIn_TypeModifier, |
| - v->fFsIn, |
| - precision); |
| } |
| void GrGLSLVaryingHandler::emitAttributes(const GrGeometryProcessor& gp) { |
| @@ -105,7 +91,46 @@ void GrGLSLVaryingHandler::addAttribute(const GrShaderVar& var) { |
| fVertexInputs.push_back(var); |
| } |
| +void GrGLSLVaryingHandler::setNoPerspective() { |
| + const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
| + if (!caps.noperspectiveInterpolationSupport()) { |
| + return; |
| + } |
| + if (const char* extension = caps.noperspectiveInterpolationExtensionString()) { |
| + int bit = 1 << GrGLSLFragmentShaderBuilder::kNoPerspectiveInterpolation_GLSLPrivateFeature; |
| + fProgramBuilder->fVS.addFeature(bit, extension); |
| + if (fProgramBuilder->primitiveProcessor().willUseGeoShader()) { |
| + fProgramBuilder->fGS.addFeature(bit, extension); |
| + } |
| + fProgramBuilder->fFS.addFeature(bit, extension); |
| + } |
| + fDefaultInterpolationModifier = "noperspective"; |
| +} |
| + |
| void GrGLSLVaryingHandler::finalize() { |
| + for (int i = 0; i < fVaryings.count(); ++i) { |
| + const VaryingInfo& v = this->fVaryings[i]; |
| + const char* modifier = v.fIsFlat ? "flat" : fDefaultInterpolationModifier; |
| + if (v.fVisibility & kVertex_GrShaderFlag) { |
| + fVertexOutputs.push_back().set(v.fType, GrShaderVar::kVaryingOut_TypeModifier, v.fVsOut, |
| + v.fPrecision, nullptr, modifier); |
| + if (v.fVisibility & kGeometry_GrShaderFlag) { |
| + fGeomInputs.push_back().set(v.fType, GrShaderVar::kVaryingIn_TypeModifier, v.fVsOut, |
| + GrShaderVar::kUnsizedArray, v.fPrecision, nullptr, |
| + modifier); |
| + } |
| + } |
| + if (v.fVisibility & kFragment_GrShaderFlag) { |
| + const char* fsIn = v.fVsOut.c_str(); |
| + if (v.fVisibility & kGeometry_GrShaderFlag) { |
| + fGeomOutputs.push_back().set(v.fType, GrGLSLShaderVar::kVaryingOut_TypeModifier, |
| + v.fGsOut, v.fPrecision, nullptr, modifier); |
| + fsIn = v.fGsOut.c_str(); |
| + } |
| + fFragInputs.push_back().set(v.fType, GrShaderVar::kVaryingIn_TypeModifier, fsIn, |
| + v.fPrecision, nullptr, modifier); |
| + } |
| + } |
| this->onFinalize(); |
| } |