Make GrPrimitiveProcessor::Attribute a class, hide data members.

Change-Id: I008881d79c82fdde6bb68fe2218e62ccc9c538dd
Reviewed-on: https://skia-review.googlesource.com/130600
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2018-05-29 15:33:06 -04:00 committed by Skia Commit-Bot
parent 8f480d91ee
commit 70132d0c73
22 changed files with 130 additions and 120 deletions

View File

@ -86,7 +86,7 @@ public:
varyingHandler->addVarying("color", &varying);
// There are several optional steps to process the color. Start with the attribute:
vertBuilder->codeAppendf("half4 color = %s;", gp.inColor()->fName);
vertBuilder->codeAppendf("half4 color = %s;", gp.inColor()->name());
// Linearize
if (gp.linearizeColor()) {
@ -102,10 +102,10 @@ public:
": pow((x + 0.055) / 1.055, 2.4);",
&srgbFuncName);
vertBuilder->codeAppendf("color = half4(%s(%s.r), %s(%s.g), %s(%s.b), %s.a);",
srgbFuncName.c_str(), gp.inColor()->fName,
srgbFuncName.c_str(), gp.inColor()->fName,
srgbFuncName.c_str(), gp.inColor()->fName,
gp.inColor()->fName);
srgbFuncName.c_str(), gp.inColor()->name(),
srgbFuncName.c_str(), gp.inColor()->name(),
srgbFuncName.c_str(), gp.inColor()->name(),
gp.inColor()->name());
}
// For SkColor, do a red/blue swap and premul
@ -135,7 +135,7 @@ public:
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.inPosition()->name(),
gp.viewMatrix(),
&fViewMatrixUniform);

View File

@ -40,23 +40,33 @@ class GrGLSLPrimitiveProcessor;
*/
class GrPrimitiveProcessor : public GrResourceIOProcessor, public GrProgramElement {
public:
struct Attribute {
class Attribute {
public:
enum class InputRate : bool {
kPerVertex,
kPerInstance
};
GrShaderVar asShaderVar() const {
return GrShaderVar(fName, GrVertexAttribTypeToSLType(fType),
GrShaderVar::kIn_TypeModifier);
}
bool isInitialized() const { return SkToBool(fName); }
Attribute() = default;
Attribute(const char* name, GrVertexAttribType type, int offset, InputRate rate)
constexpr Attribute() = default;
constexpr Attribute(const char* name, GrVertexAttribType type, int offset, InputRate rate)
: fName(name), fType(type), fOffsetInRecord(offset), fInputRate(rate) {}
const char* fName = nullptr;
GrVertexAttribType fType;
int fOffsetInRecord;
InputRate fInputRate;
bool isInitialized() const { return SkToBool(fName); }
const char* name() const { return fName; }
GrVertexAttribType type() const { return fType; }
int offsetInRecord() const { return fOffsetInRecord; }
InputRate inputRate() const { return fInputRate; }
GrShaderVar asShaderVar() const {
return {fName, GrVertexAttribTypeToSLType(fType), GrShaderVar::kIn_TypeModifier};
}
private:
const char* fName = nullptr;
GrVertexAttribType fType = kFloat_GrVertexAttribType;
int fOffsetInRecord = 0;
InputRate fInputRate = InputRate::kPerVertex;
};
GrPrimitiveProcessor(ClassID classID)

View File

@ -32,8 +32,8 @@ protected:
// The vertex shader simply forwards transposed x or y values to the geometry shader.
SkASSERT(1 == proc.numAttribs());
gpArgs->fPositionVar.set(GrVertexAttribTypeToSLType(proc.getAttrib(0).fType),
proc.getAttrib(0).fName);
gpArgs->fPositionVar.set(GrVertexAttribTypeToSLType(proc.getAttrib(0).type()),
proc.getAttrib(0).name());
// Geometry shader.
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
@ -62,7 +62,7 @@ protected:
Shader::CalcWind(proc, g, "pts", wind.c_str());
if (PrimitiveType::kWeightedTriangles == proc.fPrimitiveType) {
SkASSERT(3 == numInputPoints);
SkASSERT(kFloat4_GrVertexAttribType == proc.getAttrib(0).fType);
SkASSERT(kFloat4_GrVertexAttribType == proc.getAttrib(0).type());
g->codeAppendf("%s *= sk_in[0].sk_Position.w;", wind.c_str());
}

View File

@ -259,16 +259,16 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
int inputWidth = (4 == numInputPoints || proc.hasInputWeight()) ? 4 : 3;
const char* swizzle = (4 == inputWidth) ? "xyzw" : "xyz";
v->codeAppendf("float%ix2 pts = transpose(float2x%i(%s.%s, %s.%s));",
inputWidth, inputWidth, proc.getAttrib(kAttribIdx_X).fName, swizzle,
proc.getAttrib(kAttribIdx_Y).fName, swizzle);
v->codeAppendf("float%ix2 pts = transpose(float2x%i(%s.%s, %s.%s));", inputWidth, inputWidth,
proc.getAttrib(kAttribIdx_X).name(), swizzle,
proc.getAttrib(kAttribIdx_Y).name(), swizzle);
v->codeAppend ("half wind;");
Shader::CalcWind(proc, v, "pts", "wind");
if (PrimitiveType::kWeightedTriangles == proc.fPrimitiveType) {
SkASSERT(3 == numInputPoints);
SkASSERT(kFloat4_GrVertexAttribType == proc.getAttrib(kAttribIdx_X).fType);
v->codeAppendf("wind *= %s.w;", proc.getAttrib(kAttribIdx_X).fName);
SkASSERT(kFloat4_GrVertexAttribType == proc.getAttrib(kAttribIdx_X).type());
v->codeAppendf("wind *= %s.w;", proc.getAttrib(kAttribIdx_X).name());
}
float bloat = kAABloatRadius;
@ -284,12 +284,12 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
// Reverse all indices if the wind is counter-clockwise: [0, 1, 2] -> [2, 1, 0].
v->codeAppendf("int clockwise_indices = wind > 0 ? %s : 0x%x - %s;",
proc.getAttrib(kAttribIdx_VertexData).fName,
proc.getAttrib(kAttribIdx_VertexData).name(),
((fNumSides - 1) << kVertexData_LeftNeighborIdShift) |
((fNumSides - 1) << kVertexData_RightNeighborIdShift) |
(((1 << kVertexData_RightNeighborIdShift) - 1) ^ 3) |
(fNumSides - 1),
proc.getAttrib(kAttribIdx_VertexData).fName);
proc.getAttrib(kAttribIdx_VertexData).name());
// Here we generate conservative raster geometry for the input polygon. It is the convex
// hull of N pixel-size boxes, one centered on each the input points. Each corner has three
@ -321,8 +321,8 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
v->codeAppend ("float2 rightdir = right - corner;");
v->codeAppend ("rightdir = (float2(0) != rightdir) ? normalize(rightdir) : float2(1, 0);");
v->codeAppendf("if (0 != (%s & %i)) {", // Are we a corner?
proc.getAttrib(kAttribIdx_VertexData).fName, kVertexData_IsCornerBit);
v->codeAppendf("if (0 != (%s & %i)) {", // Are we a corner?
proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsCornerBit);
// In corner boxes, all 4 coverage values will not map linearly.
// Therefore it is important to align the box so its diagonal shared
@ -341,8 +341,8 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
// continue rotating 90 degrees clockwise until we reach the desired raster vertex for this
// invocation. Corners with less than 3 corresponding raster vertices will result in
// redundant vertices and degenerate triangles.
v->codeAppendf("int bloatidx = (%s >> %i) & 3;",
proc.getAttrib(kAttribIdx_VertexData).fName, kVertexData_BloatIdxShift);
v->codeAppendf("int bloatidx = (%s >> %i) & 3;", proc.getAttrib(kAttribIdx_VertexData).name(),
kVertexData_BloatIdxShift);
v->codeAppend ("switch (bloatidx) {");
v->codeAppend ( "case 3:");
// Only corners will have bloatidx=3, and corners always rotate.
@ -375,13 +375,13 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
Shader::CalcEdgeCoverageAtBloatVertex(v, "corner", "right", "bloatdir", "right_coverage");
v->codeAppend ("}");
v->codeAppendf("if (0 != (%s & %i)) {", // Are we an edge?
proc.getAttrib(kAttribIdx_VertexData).fName, kVertexData_IsEdgeBit);
v->codeAppendf("if (0 != (%s & %i)) {", // Are we an edge?
proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsEdgeBit);
v->codeAppend ( "coverage = left_coverage;");
v->codeAppend ("}");
v->codeAppendf("if (0 != (%s & %i)) {", // Invert coverage?
proc.getAttrib(kAttribIdx_VertexData).fName,
v->codeAppendf("if (0 != (%s & %i)) {", // Invert coverage?
proc.getAttrib(kAttribIdx_VertexData).name(),
kVertexData_InvertNegativeCoverageBit);
v->codeAppend ( "coverage = -1 - coverage;");
v->codeAppend ("}");
@ -390,8 +390,8 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
// Non-corner geometry should have zero effect from corner coverage.
v->codeAppend ("half2 corner_coverage = half2(0);");
v->codeAppendf("if (0 != (%s & %i)) {", // Are we a corner?
proc.getAttrib(kAttribIdx_VertexData).fName, kVertexData_IsCornerBit);
v->codeAppendf("if (0 != (%s & %i)) {", // Are we a corner?
proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsCornerBit);
// We use coverage=-1 to erase what the hull geometry wrote.
//
// In the context of curves, this effectively means "wind = -wind" and
@ -502,8 +502,8 @@ void GrCCCoverageProcessor::initVS(GrResourceProvider* rp) {
SkASSERT(kAttribIdx_Y == this->numAttribs());
this->addInstanceAttrib("Y", kFloat4_GrVertexAttribType);
SkASSERT(offsetof(QuadPointInstance, fX) == this->getAttrib(kAttribIdx_X).fOffsetInRecord);
SkASSERT(offsetof(QuadPointInstance, fY) == this->getAttrib(kAttribIdx_Y).fOffsetInRecord);
SkASSERT(offsetof(QuadPointInstance, fX) == this->getAttrib(kAttribIdx_X).offsetInRecord());
SkASSERT(offsetof(QuadPointInstance, fY) == this->getAttrib(kAttribIdx_Y).offsetInRecord());
SkASSERT(sizeof(QuadPointInstance) == this->getInstanceStride());
} else {
SkASSERT(kAttribIdx_X == this->numAttribs());
@ -512,8 +512,8 @@ void GrCCCoverageProcessor::initVS(GrResourceProvider* rp) {
SkASSERT(kAttribIdx_Y == this->numAttribs());
this->addInstanceAttrib("Y", kFloat3_GrVertexAttribType);
SkASSERT(offsetof(TriPointInstance, fX) == this->getAttrib(kAttribIdx_X).fOffsetInRecord);
SkASSERT(offsetof(TriPointInstance, fY) == this->getAttrib(kAttribIdx_Y).fOffsetInRecord);
SkASSERT(offsetof(TriPointInstance, fX) == this->getAttrib(kAttribIdx_X).offsetInRecord());
SkASSERT(offsetof(TriPointInstance, fY) == this->getAttrib(kAttribIdx_Y).offsetInRecord());
SkASSERT(sizeof(TriPointInstance) == this->getInstanceStride());
}

View File

@ -87,13 +87,13 @@ GrCCPathProcessor::GrCCPathProcessor(GrResourceProvider* resourceProvider,
this->addInstanceAttrib("color", kUByte4_norm_GrVertexAttribType);
SkASSERT(offsetof(Instance, fDevBounds) ==
this->getInstanceAttrib(InstanceAttribs::kDevBounds).fOffsetInRecord);
this->getInstanceAttrib(InstanceAttribs::kDevBounds).offsetInRecord());
SkASSERT(offsetof(Instance, fDevBounds45) ==
this->getInstanceAttrib(InstanceAttribs::kDevBounds45).fOffsetInRecord);
this->getInstanceAttrib(InstanceAttribs::kDevBounds45).offsetInRecord());
SkASSERT(offsetof(Instance, fAtlasOffset) ==
this->getInstanceAttrib(InstanceAttribs::kAtlasOffset).fOffsetInRecord);
this->getInstanceAttrib(InstanceAttribs::kAtlasOffset).offsetInRecord());
SkASSERT(offsetof(Instance, fColor) ==
this->getInstanceAttrib(InstanceAttribs::kColor).fOffsetInRecord);
this->getInstanceAttrib(InstanceAttribs::kColor).offsetInRecord());
SkASSERT(sizeof(Instance) == this->getInstanceStride());
GR_STATIC_ASSERT(4 == kNumInstanceAttribs);
@ -183,13 +183,13 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
//
// NOTE: "float2x2(float4)" is valid and equivalent to "float2x2(float4.xy, float4.zw)",
// however Intel compilers crash when we use the former syntax in this shader.
v->codeAppendf("float2x2 N = float2x2(%s.xy, %s.zw);",
proc.getEdgeNormsAttrib().fName, proc.getEdgeNormsAttrib().fName);
v->codeAppendf("float2x2 N = float2x2(%s.xy, %s.zw);", proc.getEdgeNormsAttrib().name(),
proc.getEdgeNormsAttrib().name());
// N[0] is the normal for the edge we are intersecting from the regular bounding box, pointing
// out of the octagon.
v->codeAppendf("float4 devbounds = %s;",
proc.getInstanceAttrib(InstanceAttribs::kDevBounds).fName);
proc.getInstanceAttrib(InstanceAttribs::kDevBounds).name());
v->codeAppend ("float2 refpt = (0 == sk_VertexID >> 2)"
"? float2(min(devbounds.x, devbounds.z), devbounds.y)"
": float2(max(devbounds.x, devbounds.z), devbounds.w);");
@ -198,8 +198,8 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// N[1] is the normal for the edge we are intersecting from the 45-degree bounding box, pointing
// out of the octagon.
v->codeAppendf("float2 refpt45 = (0 == ((sk_VertexID + 1) & (1 << 2))) ? %s.xy : %s.zw;",
proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).fName,
proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).fName);
proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).name(),
proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).name());
v->codeAppendf("refpt45 *= float2x2(.5,.5,-.5,.5);"); // transform back to device space.
v->codeAppendf("refpt45 += N[1] * %f;", kAABloatRadius); // bloat for AA.
@ -210,7 +210,7 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// Convert to atlas coordinates in order to do our texture lookup.
v->codeAppendf("float2 atlascoord = octocoord + float2(%s);",
proc.getInstanceAttrib(InstanceAttribs::kAtlasOffset).fName);
proc.getInstanceAttrib(InstanceAttribs::kAtlasOffset).name());
if (kTopLeft_GrSurfaceOrigin == proc.atlasProxy()->origin()) {
v->codeAppendf("%s.xy = atlascoord * %s;", texcoord.vsOut(), atlasAdjust);
} else {

View File

@ -62,13 +62,13 @@ public:
const SkMatrix& localMatrix() const { return fLocalMatrix; }
const Attribute& getInstanceAttrib(InstanceAttribs attribID) const {
const Attribute& attrib = this->getAttrib((int)attribID);
SkASSERT(Attribute::InputRate::kPerInstance == attrib.fInputRate);
SkASSERT(Attribute::InputRate::kPerInstance == attrib.inputRate());
return attrib;
}
const Attribute& getEdgeNormsAttrib() const {
SkASSERT(1 + kNumInstanceAttribs == this->numAttribs());
const Attribute& attrib = this->getAttrib(kNumInstanceAttribs);
SkASSERT(Attribute::InputRate::kPerVertex == attrib.fInputRate);
SkASSERT(Attribute::InputRate::kPerVertex == attrib.inputRate());
return attrib;
}

View File

@ -79,7 +79,7 @@ void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLVarying v(kFloat4_GrSLType);
varyingHandler->addVarying("ConicCoeffs", &v);
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName);
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
@ -89,7 +89,7 @@ void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.inPosition()->name(),
gp.viewMatrix(),
&fViewMatrixUniform);
@ -331,7 +331,7 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLVarying v(kHalf4_GrSLType);
varyingHandler->addVarying("HairQuadEdge", &v);
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName);
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
@ -341,7 +341,7 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.inPosition()->name(),
gp.viewMatrix(),
&fViewMatrixUniform);
@ -544,7 +544,7 @@ void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.inPosition()->name(),
gp.viewMatrix(),
&fViewMatrixUniform);

View File

@ -40,8 +40,8 @@ public:
GrGLSLVarying uv(kFloat2_GrSLType);
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
append_index_uv_varyings(args, btgp.inTextureCoords()->fName, atlasSizeInvName,
&uv, &texIdx, nullptr);
append_index_uv_varyings(args, btgp.inTextureCoords()->name(), atlasSizeInvName, &uv,
&texIdx, nullptr);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color

View File

@ -69,8 +69,8 @@ public:
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
GrGLSLVarying st(kFloat2_GrSLType);
append_index_uv_varyings(args, dfTexEffect.inTextureCoords()->fName, atlasSizeInvName,
&uv, &texIdx, &st);
append_index_uv_varyings(args, dfTexEffect.inTextureCoords()->name(), atlasSizeInvName, &uv,
&texIdx, &st);
bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask) ==
kUniformScale_DistanceFieldEffectMask;
@ -337,8 +337,8 @@ public:
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
GrGLSLVarying st(kFloat2_GrSLType);
append_index_uv_varyings(args, dfPathEffect.inTextureCoords()->fName, atlasSizeInvName, &uv,
&texIdx, &st);
append_index_uv_varyings(args, dfPathEffect.inTextureCoords()->name(), atlasSizeInvName,
&uv, &texIdx, &st);
// setup pass through color
varyingHandler->addPassThroughAttribute(dfPathEffect.inColor(), args.fOutputColor);
@ -348,7 +348,7 @@ public:
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
dfPathEffect.inPosition()->fName,
dfPathEffect.inPosition()->name(),
dfPathEffect.matrix(),
&fMatrixUniform);
@ -360,7 +360,7 @@ public:
args.fFPCoordTransformHandler);
} else {
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, dfPathEffect.inPosition()->fName);
this->writeOutputPosition(vertBuilder, gpArgs, dfPathEffect.inPosition()->name());
// emit transforms
this->emitTransforms(vertBuilder,
@ -629,8 +629,8 @@ public:
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
GrGLSLVarying st(kFloat2_GrSLType);
append_index_uv_varyings(args, dfTexEffect.inTextureCoords()->fName, atlasSizeInvName,
&uv, &texIdx, &st);
append_index_uv_varyings(args, dfTexEffect.inTextureCoords()->name(), atlasSizeInvName, &uv,
&texIdx, &st);
GrGLSLVarying delta(kFloat_GrSLType);
varyingHandler->addVarying("Delta", &delta);

View File

@ -33,7 +33,7 @@ public:
varyingHandler->addPassThroughAttribute(rsgp.inColor(), args.fOutputColor);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, rsgp.inPosition()->fName);
this->writeOutputPosition(vertBuilder, gpArgs, rsgp.inPosition()->name());
// emit transforms
this->emitTransforms(vertBuilder,

View File

@ -1889,10 +1889,10 @@ void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
for (int i = 0; i < numAttribs; ++i) {
using InputRate = GrPrimitiveProcessor::Attribute::InputRate;
const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(i);
const int divisor = InputRate::kPerInstance == attrib.fInputRate ? 1 : 0;
const int divisor = InputRate::kPerInstance == attrib.inputRate() ? 1 : 0;
const auto& binding = bindings[divisor];
attribState->set(this, i, binding.fBuffer, attrib.fType, binding.fStride,
binding.fBufferOffset + attrib.fOffsetInRecord, divisor);
attribState->set(this, i, binding.fBuffer, attrib.type(), binding.fStride,
binding.fBufferOffset + attrib.offsetInRecord(), divisor);
}
}

View File

@ -225,7 +225,7 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
if (!useNvpr) {
int vaCount = primProc.numAttribs();
for (int i = 0; i < vaCount; i++) {
GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).fName));
GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).name()));
}
}

View File

@ -13,10 +13,10 @@ void GrGLSLVaryingHandler::addPassThroughAttribute(const GrGeometryProcessor::At
const char* output,
Interpolation interpolation) {
SkASSERT(!fProgramBuilder->primitiveProcessor().willUseGeoShader());
GrSLType type = GrVertexAttribTypeToSLType(input->fType);
GrSLType type = GrVertexAttribTypeToSLType(input->type());
GrGLSLVarying v(type);
this->addVarying(input->fName, &v, interpolation);
fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), input->fName);
this->addVarying(input->name(), &v, interpolation);
fProgramBuilder->fVS.codeAppendf("%s = %s;", v.vsOut(), input->name());
fProgramBuilder->fFS.codeAppendf("%s = %s;", output, v.fsIn());
}
@ -70,10 +70,7 @@ void GrGLSLVaryingHandler::emitAttributes(const GrGeometryProcessor& gp) {
int vaCount = gp.numAttribs();
for (int i = 0; i < vaCount; i++) {
const GrGeometryProcessor::Attribute& attr = gp.getAttrib(i);
this->addAttribute(GrShaderVar(attr.fName,
GrVertexAttribTypeToSLType(attr.fType),
GrShaderVar::kIn_TypeModifier,
GrShaderVar::kNonArray));
this->addAttribute(attr.asShaderVar());
}
}

View File

@ -570,7 +570,7 @@ public:
GrGLSLVarying v(kHalf4_GrSLType);
varyingHandler->addVarying("QuadEdge", &v);
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.fInQuadEdge->fName);
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.fInQuadEdge->name());
// Setup pass through color
varyingHandler->addPassThroughAttribute(qe.fInColor, args.fOutputColor);
@ -578,7 +578,7 @@ public:
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, qe.fInPosition->fName);
this->writeOutputPosition(vertBuilder, gpArgs, qe.fInPosition->name());
// emit transforms
this->emitTransforms(vertBuilder,

View File

@ -912,19 +912,19 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// XY are dashPos, Z is dashInterval
GrGLSLVarying dashParams(kHalf3_GrSLType);
varyingHandler->addVarying("DashParam", &dashParams);
vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->fName);
vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->name());
// x refers to circle radius - 0.5, y refers to cicle's center x coord
GrGLSLVarying circleParams(kHalf2_GrSLType);
varyingHandler->addVarying("CircleParams", &circleParams);
vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams()->fName);
vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams()->name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, dce.inPosition()->fName);
this->writeOutputPosition(vertBuilder, gpArgs, dce.inPosition()->name());
// emit transforms
this->emitTransforms(vertBuilder,
@ -1114,20 +1114,20 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// XY refers to dashPos, Z is the dash interval length
GrGLSLVarying inDashParams(kFloat3_GrSLType);
varyingHandler->addVarying("DashParams", &inDashParams);
vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()->fName);
vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()->name());
// The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bottom - 0.5),
// respectively.
GrGLSLVarying inRectParams(kFloat4_GrSLType);
varyingHandler->addVarying("RectParams", &inRectParams);
vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()->fName);
vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()->name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, de.inPosition()->fName);
this->writeOutputPosition(vertBuilder, gpArgs, de.inPosition()->name());
// emit transforms
this->emitTransforms(vertBuilder,

View File

@ -64,7 +64,7 @@ public:
latticeGP.fColorSpaceXform.get());
args.fVaryingHandler->emitAttributes(latticeGP);
this->writeOutputPosition(args.fVertBuilder, gpArgs, latticeGP.fPositions.fName);
this->writeOutputPosition(args.fVertBuilder, gpArgs, latticeGP.fPositions.name());
this->emitTransforms(args.fVertBuilder,
args.fVaryingHandler,
args.fUniformHandler,

View File

@ -152,14 +152,14 @@ private:
// This is the cap radius in normalized space where the outer radius is 1 and
// circledEdge.w is the normalized inner radius.
vertBuilder->codeAppendf("%s = (1.0 - %s.w) / 2.0;", capRadius.vsOut(),
cgp.fInCircleEdge->fName);
cgp.fInCircleEdge->name());
}
// setup pass through color
varyingHandler->addPassThroughAttribute(cgp.fInColor, args.fOutputColor);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, cgp.fInPosition->fName);
this->writeOutputPosition(vertBuilder, gpArgs, cgp.fInPosition->name());
// emit transforms
this->emitTransforms(vertBuilder,
@ -314,7 +314,7 @@ private:
GrGLSLVarying lastIntervalLength(kHalf_GrSLType);
varyingHandler->addVarying("lastIntervalLength", &lastIntervalLength,
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
vertBuilder->codeAppendf("float4 dashParams = %s;", bcscgp.fInDashParams->fName);
vertBuilder->codeAppendf("float4 dashParams = %s;", bcscgp.fInDashParams->name());
// Our fragment shader works in on/off intervals as specified by dashParams.xy:
// x = length of on interval, y = length of on + off.
// There are two other parameters in dashParams.zw:
@ -380,7 +380,7 @@ private:
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, bcscgp.fInPosition->fName);
this->writeOutputPosition(vertBuilder, gpArgs, bcscgp.fInPosition->name());
// emit transforms
this->emitTransforms(vertBuilder,
@ -549,18 +549,18 @@ private:
GrGLSLVarying ellipseOffsets(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets", &ellipseOffsets);
vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(),
egp.fInEllipseOffset->fName);
egp.fInEllipseOffset->name());
GrGLSLVarying ellipseRadii(kHalf4_GrSLType);
varyingHandler->addVarying("EllipseRadii", &ellipseRadii);
vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), egp.fInEllipseRadii->fName);
vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), egp.fInEllipseRadii->name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// setup pass through color
varyingHandler->addPassThroughAttribute(egp.fInColor, args.fOutputColor);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, egp.fInPosition->fName);
this->writeOutputPosition(vertBuilder, gpArgs, egp.fInPosition->name());
// emit transforms
this->emitTransforms(vertBuilder,
@ -688,11 +688,13 @@ private:
GrGLSLVarying offsets0(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets0", &offsets0);
vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), diegp.fInEllipseOffsets0->fName);
vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(),
diegp.fInEllipseOffsets0->name());
GrGLSLVarying offsets1(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets1", &offsets1);
vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), diegp.fInEllipseOffsets1->fName);
vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(),
diegp.fInEllipseOffsets1->name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
varyingHandler->addPassThroughAttribute(diegp.fInColor, args.fOutputColor);
@ -701,7 +703,7 @@ private:
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
diegp.fInPosition->fName,
diegp.fInPosition->name(),
diegp.fViewMatrix,
&fViewMatrixUniform);

View File

@ -125,7 +125,7 @@ public:
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
b->add32(GrColorSpaceXform::XformKey(fColorSpaceXform.get()));
uint32_t x = this->usesCoverageEdgeAA() ? 0 : 1;
x |= kFloat3_GrVertexAttribType == fPositions.fType ? 0 : 2;
x |= kFloat3_GrVertexAttribType == fPositions.type() ? 0 : 2;
x |= fDomain.isInitialized() ? 4 : 0;
b->add32(x);
}
@ -148,7 +148,7 @@ public:
const auto& textureGP = args.fGP.cast<TextureGeometryProcessor>();
fColorSpaceXformHelper.emitCode(
args.fUniformHandler, textureGP.fColorSpaceXform.get());
if (kFloat2_GrVertexAttribType == textureGP.fPositions.fType) {
if (kFloat2_GrVertexAttribType == textureGP.fPositions.type()) {
args.fVaryingHandler->setNoPerspective();
}
args.fVaryingHandler->emitAttributes(textureGP);
@ -175,7 +175,7 @@ public:
}
if (textureGP.numTextureSamplers() > 1) {
// If this changes to float, reconsider Interpolation::kMustBeFlat.
SkASSERT(kInt_GrVertexAttribType == textureGP.fTextureIdx.fType);
SkASSERT(kInt_GrVertexAttribType == textureGP.fTextureIdx.type());
SkASSERT(args.fShaderCaps->integerSupport());
args.fFragBuilder->codeAppend("int texIdx;");
args.fVaryingHandler->addPassThroughAttribute(&textureGP.fTextureIdx, "texIdx",
@ -209,7 +209,7 @@ public:
if (!args.fShaderCaps->interpolantsAreInaccurate()) {
GrGLSLVarying aaDistVarying(kFloat4_GrSLType,
GrGLSLVarying::Scope::kVertToFrag);
if (kFloat3_GrVertexAttribType == textureGP.fPositions.fType) {
if (kFloat3_GrVertexAttribType == textureGP.fPositions.type()) {
args.fVaryingHandler->addVarying("aaDists", &aaDistVarying);
// The distance from edge equation e to homogenous point p=sk_Position
// is e.x*p.x/p.wx + e.y*p.y/p.w + e.z. However, we want screen space
@ -219,9 +219,9 @@ public:
args.fVertBuilder->codeAppendf(
R"(%s = float4(dot(aaEdge0, %s), dot(aaEdge1, %s),
dot(aaEdge2, %s), dot(aaEdge3, %s));)",
aaDistVarying.vsOut(), textureGP.fPositions.fName,
textureGP.fPositions.fName, textureGP.fPositions.fName,
textureGP.fPositions.fName);
aaDistVarying.vsOut(), textureGP.fPositions.name(),
textureGP.fPositions.name(), textureGP.fPositions.name(),
textureGP.fPositions.name());
mulByFragCoordW = true;
} else {
args.fVaryingHandler->addVarying("aaDists", &aaDistVarying);
@ -230,9 +230,9 @@ public:
dot(aaEdge1.xy, %s.xy) + aaEdge1.z,
dot(aaEdge2.xy, %s.xy) + aaEdge2.z,
dot(aaEdge3.xy, %s.xy) + aaEdge3.z);)",
aaDistVarying.vsOut(), textureGP.fPositions.fName,
textureGP.fPositions.fName, textureGP.fPositions.fName,
textureGP.fPositions.fName);
aaDistVarying.vsOut(), textureGP.fPositions.name(),
textureGP.fPositions.name(), textureGP.fPositions.name(),
textureGP.fPositions.name());
}
aaDistName = aaDistVarying.fsIn();
} else {

View File

@ -85,10 +85,10 @@ static void setup_vertex_input_state(const GrPrimitiveProcessor& primProc,
const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(attribIndex);
VkVertexInputAttributeDescription& vkAttrib = attributeDesc[attribIndex];
vkAttrib.location = attribIndex; // for now assume location = attribIndex
vkAttrib.binding = InputRate::kPerInstance == attrib.fInputRate ? instanceBinding
: vertexBinding;
vkAttrib.format = attrib_type_to_vkformat(attrib.fType);
vkAttrib.offset = attrib.fOffsetInRecord;
vkAttrib.binding =
InputRate::kPerInstance == attrib.inputRate() ? instanceBinding : vertexBinding;
vkAttrib.format = attrib_type_to_vkformat(attrib.type());
vkAttrib.offset = attrib.offsetInRecord();
}
}

View File

@ -330,15 +330,15 @@ class GLSLMeshTestProcessor : public GrGLSLGeometryProcessor {
GrGLSLVertexBuilder* v = args.fVertBuilder;
if (!mp.fInstanceLocation) {
v->codeAppendf("float2 vertex = %s;", mp.fVertex->fName);
v->codeAppendf("float2 vertex = %s;", mp.fVertex->name());
} else {
if (mp.fVertex) {
v->codeAppendf("float2 offset = %s;", mp.fVertex->fName);
v->codeAppendf("float2 offset = %s;", mp.fVertex->name());
} else {
v->codeAppend ("float2 offset = float2(sk_VertexID / 2, sk_VertexID % 2);");
}
v->codeAppendf("float2 vertex = %s + offset * %i;",
mp.fInstanceLocation->fName, kBoxSize);
v->codeAppendf("float2 vertex = %s + offset * %i;", mp.fInstanceLocation->name(),
kBoxSize);
}
gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertex");

View File

@ -90,7 +90,7 @@ class GLSLPipelineDynamicStateTestProcessor : public GrGLSLGeometryProcessor {
varyingHandler->addPassThroughAttribute(&mp.fColor, args.fOutputColor);
GrGLSLVertexBuilder* v = args.fVertBuilder;
v->codeAppendf("float2 vertex = %s;", mp.fVertex.fName);
v->codeAppendf("float2 vertex = %s;", mp.fVertex.name());
gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertex");
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;

View File

@ -73,7 +73,8 @@ private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const GP& gp = args.fGP.cast<GP>();
args.fVaryingHandler->emitAttributes(gp);
this->writeOutputPosition(args.fVertBuilder, gpArgs, gp.getAttrib(0).fName);
this->writeOutputPosition(args.fVertBuilder, gpArgs,
gp.getAttrib(0).name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputColor);
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);