Make GrGLSLPrimitiveProcessor::emitTransforms take local coords as GrShaderVar.

Also remove unused position variable parameter.

Change-Id: I37f98a03ac1ca750810de13b08e3ffa11e41828c
Reviewed-on: https://skia-review.googlesource.com/81320
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2017-12-06 14:47:42 -05:00 committed by Skia Commit-Bot
parent e951e4a1dc
commit 04460ccee5
16 changed files with 100 additions and 60 deletions

View File

@ -231,6 +231,60 @@ static inline bool GrSLTypeIsFloatType(GrSLType type) {
return false;
}
/** If the type represents a single value or vector return the vector length, else -1. */
static inline int GrSLTypeVecLength(GrSLType type) {
switch (type) {
case kFloat_GrSLType:
case kHalf_GrSLType:
case kBool_GrSLType:
case kShort_GrSLType:
case kUShort_GrSLType:
case kInt_GrSLType:
case kUint_GrSLType:
return 1;
case kFloat2_GrSLType:
case kHalf2_GrSLType:
case kShort2_GrSLType:
case kUShort2_GrSLType:
case kInt2_GrSLType:
case kUint2_GrSLType:
return 2;
case kFloat3_GrSLType:
case kHalf3_GrSLType:
case kShort3_GrSLType:
case kUShort3_GrSLType:
case kInt3_GrSLType:
return 3;
case kFloat4_GrSLType:
case kHalf4_GrSLType:
case kShort4_GrSLType:
case kUShort4_GrSLType:
case kInt4_GrSLType:
return 4;
case kFloat2x2_GrSLType:
case kFloat3x3_GrSLType:
case kFloat4x4_GrSLType:
case kHalf2x2_GrSLType:
case kHalf3x3_GrSLType:
case kHalf4x4_GrSLType:
case kVoid_GrSLType:
case kTexture2DSampler_GrSLType:
case kITexture2DSampler_GrSLType:
case kTextureExternalSampler_GrSLType:
case kTexture2DRectSampler_GrSLType:
case kBufferSampler_GrSLType:
case kTexture2D_GrSLType:
case kSampler_GrSLType:
return -1;
}
SK_ABORT("Unexpected type");
return -1;
}
static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
switch (type) {
case kTexture2DSampler_GrSLType:

View File

@ -144,8 +144,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
gp.inLocalCoords()->fName,
gp.inLocalCoords()->asShaderVar(),
gp.localMatrix(),
args.fFPCoordTransformHandler);
} else {
@ -153,8 +152,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
gp.inPosition()->fName,
gp.inPosition()->asShaderVar(),
gp.localMatrix(),
args.fFPCoordTransformHandler);
}

View File

@ -45,7 +45,10 @@ public:
kPerVertex,
kPerInstance
};
GrShaderVar asShaderVar() const {
return GrShaderVar(fName, GrVertexAttribTypeToSLType(fType),
GrShaderVar::kIn_TypeModifier);
}
const char* fName;
GrVertexAttribType fType;
int fOffsetInRecord;

View File

@ -172,7 +172,7 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
proc.getInstanceAttrib(InstanceAttribs::kViewMatrix).fName,
proc.getInstanceAttrib(InstanceAttribs::kViewTranslate).fName);
this->emitTransforms(v, varyingHandler, uniHandler, gpArgs->fPositionVar, "pathcoord",
this->emitTransforms(v, varyingHandler, uniHandler, GrShaderVar("pathcoord", kFloat2_GrSLType),
args.fFPCoordTransformHandler);
// Fragment shader.

View File

@ -97,8 +97,7 @@ void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
gp.inPosition()->fName,
gp.inPosition()->asShaderVar(),
gp.localMatrix(),
args.fFPCoordTransformHandler);
@ -350,8 +349,7 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
gp.inPosition()->fName,
gp.inPosition()->asShaderVar(),
gp.localMatrix(),
args.fFPCoordTransformHandler);
@ -578,11 +576,9 @@ void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
gp.inPosition()->fName,
gp.inPosition()->asShaderVar(),
args.fFPCoordTransformHandler);
GrShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0);
GrShaderVar gF("gF", kFloat2_GrSLType, 0);
GrShaderVar func("func", kFloat_GrSLType, 0);

View File

@ -58,8 +58,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
btgp.inPosition()->fName,
btgp.inPosition()->asShaderVar(),
btgp.localMatrix(),
args.fFPCoordTransformHandler);

View File

@ -72,8 +72,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
dfTexEffect.inPosition()->fName,
dfTexEffect.inPosition()->asShaderVar(),
args.fFPCoordTransformHandler);
// add varyings
@ -365,8 +364,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
dfTexEffect.inPosition()->fName,
dfTexEffect.inPosition()->asShaderVar(),
args.fFPCoordTransformHandler);
} else {
// Setup position
@ -376,8 +374,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
dfTexEffect.inPosition()->fName,
dfTexEffect.inPosition()->asShaderVar(),
dfTexEffect.matrix(),
args.fFPCoordTransformHandler);
}
@ -633,8 +630,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
dfTexEffect.inPosition()->fName,
dfTexEffect.inPosition()->asShaderVar(),
args.fFPCoordTransformHandler);
// set up varyings

View File

@ -39,8 +39,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
rsgp.inPosition()->fName,
rsgp.inPosition()->asShaderVar(),
args.fFPCoordTransformHandler);
fragBuilder->codeAppend("half d = length(shadowParams.xy);");

View File

@ -43,10 +43,12 @@ void GrGLSLGeometryProcessor::emitCode(EmitArgs& args) {
void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb,
GrGLSLVaryingHandler* varyingHandler,
GrGLSLUniformHandler* uniformHandler,
const GrShaderVar& posVar,
const char* localCoords,
const GrShaderVar& localCoordsVar,
const SkMatrix& localMatrix,
FPCoordTransformHandler* handler) {
SkASSERT(GrSLTypeIsFloatType(localCoordsVar.getType()));
SkASSERT(2 == GrSLTypeVecLength(localCoordsVar.getType()));
int i = 0;
while (const GrCoordTransform* coordTransform = handler->nextCoordTransform()) {
SkString strUniName;
@ -75,9 +77,10 @@ void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb,
handler->specifyCoordsForCurrCoordTransform(SkString(v.fsIn()), varyingType);
if (kFloat2_GrSLType == varyingType) {
vb->codeAppendf("%s = (%s * float3(%s, 1)).xy;", v.vsOut(), uniName, localCoords);
vb->codeAppendf("%s = (%s * float3(%s, 1)).xy;", v.vsOut(), uniName,
localCoordsVar.c_str());
} else {
vb->codeAppendf("%s = %s * float3(%s, 1);", v.vsOut(), uniName, localCoords);
vb->codeAppendf("%s = %s * float3(%s, 1);", v.vsOut(), uniName, localCoordsVar.c_str());
}
++i;
}

View File

@ -28,26 +28,25 @@ protected:
const GrGLSLProgramDataManager& pdman,
FPCoordTransformIter*);
// Emit a uniform matrix for each coord transform.
void emitTransforms(GrGLSLVertexBuilder* vb,
GrGLSLVaryingHandler* varyingHandler,
GrGLSLUniformHandler* uniformHandler,
const GrShaderVar& posVar,
const char* localCoords,
FPCoordTransformHandler* handler) {
this->emitTransforms(vb, varyingHandler, uniformHandler,
posVar, localCoords, SkMatrix::I(), handler);
}
// Emit pre-transformed coords as a varying per coord-transform.
// Emit transformed local coords from the vertex shader as a uniform matrix and varying per
// coord-transform.
void emitTransforms(GrGLSLVertexBuilder*,
GrGLSLVaryingHandler*,
GrGLSLUniformHandler*,
const GrShaderVar& posVar,
const char* localCoords,
const GrShaderVar& localCoordsVar,
const SkMatrix& localMatrix,
FPCoordTransformHandler*);
// Version of above that assumes identity for the local matrix.
void emitTransforms(GrGLSLVertexBuilder* vb,
GrGLSLVaryingHandler* varyingHandler,
GrGLSLUniformHandler* uniformHandler,
const GrShaderVar& localCoordsVar,
FPCoordTransformHandler* handler) {
this->emitTransforms(vb, varyingHandler, uniformHandler, localCoordsVar, SkMatrix::I(),
handler);
}
struct GrGPArgs {
// Used to specify the output variable used by the GP to store its device position. It can
// either be a float2 or a float3 (in order to handle perspective). The subclass sets this

View File

@ -406,7 +406,7 @@ void GLSLInstanceProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLTypeString(args.fShaderCaps, positionType), backend->outShapeCoords());
gpArgs->fPositionVar.set(positionType, "deviceCoords");
this->emitTransforms(v, varyingHandler, uniHandler, gpArgs->fPositionVar, localCoords,
this->emitTransforms(v, varyingHandler, uniHandler, GrShaderVar(localCoords, kHalf2_GrSLType),
args.fFPCoordTransformHandler);
}

View File

@ -582,8 +582,7 @@ public:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
qe.fInPosition->fName,
qe.fInPosition->asShaderVar(),
qe.fLocalMatrix,
args.fFPCoordTransformHandler);

View File

@ -910,8 +910,7 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
dce.inPosition()->fName,
dce.inPosition()->asShaderVar(),
dce.localMatrix(),
args.fFPCoordTransformHandler);
@ -1114,8 +1113,7 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
de.inPosition()->fName,
de.inPosition()->asShaderVar(),
de.localMatrix(),
args.fFPCoordTransformHandler);

View File

@ -149,8 +149,8 @@ public:
qp.viewMatrix(), &fViewMatrixUniform);
// emit transforms
this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpArgs->fPositionVar,
qp.inPosition()->fName, SkMatrix::I(),
this->emitTransforms(vsBuilder, varyingHandler, uniformHandler,
qp.inPosition()->asShaderVar(), SkMatrix::I(),
args.fFPCoordTransformHandler);
GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder;

View File

@ -144,8 +144,7 @@ private:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
cgp.fInPosition->fName,
cgp.fInPosition->asShaderVar(),
cgp.fLocalMatrix,
args.fFPCoordTransformHandler);
@ -293,8 +292,7 @@ private:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
egp.fInPosition->fName,
egp.fInPosition->asShaderVar(),
egp.fLocalMatrix,
args.fFPCoordTransformHandler);
@ -437,8 +435,7 @@ private:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gpArgs->fPositionVar,
diegp.fInPosition->fName,
diegp.fInPosition->asShaderVar(),
args.fFPCoordTransformHandler);
// for outer curve

View File

@ -107,8 +107,7 @@ public:
this->emitTransforms(args.fVertBuilder,
args.fVaryingHandler,
args.fUniformHandler,
gpArgs->fPositionVar,
textureGP.fTextureCoords.fName,
textureGP.fTextureCoords.asShaderVar(),
args.fFPCoordTransformHandler);
if (args.fShaderCaps->preferFlatInterpolation()) {
args.fVaryingHandler->addFlatPassThroughAttribute(&textureGP.fColors,