Infrastructure for new Ganesh shader pipeline: base classes for GPU
implementation of user-defined effects.
http://codereview.appspot.com/6052047/
git-svn-id: http://skia.googlecode.com/svn/trunk@3726 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index f277647..16a60ce 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -87,29 +87,8 @@
s->appendS32(coordIdx);
}
-inline GrGLShaderVar::Type float_vector_type(int count) {
- GR_STATIC_ASSERT(GrGLShaderVar::kFloat_Type == 0);
- GR_STATIC_ASSERT(GrGLShaderVar::kVec2f_Type == 1);
- GR_STATIC_ASSERT(GrGLShaderVar::kVec3f_Type == 2);
- GR_STATIC_ASSERT(GrGLShaderVar::kVec4f_Type == 3);
- GrAssert(count > 0 && count <= 4);
- return (GrGLShaderVar::Type)(count - 1);
-}
-
inline const char* float_vector_type_str(int count) {
- return GrGLShaderVar::TypeString(float_vector_type(count));
-}
-
-inline const char* vector_homog_coord(int count) {
- static const char* HOMOGS[] = {"ERROR", "", ".y", ".z", ".w"};
- GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(HOMOGS));
- return HOMOGS[count];
-}
-
-inline const char* vector_nonhomog_coords(int count) {
- static const char* NONHOMOGS[] = {"ERROR", "", ".x", ".xy", ".xyz"};
- GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(NONHOMOGS));
- return NONHOMOGS[count];
+ return GrGLShaderVar::TypeString(GrSLFloatVectorType(count));
}
inline const char* vector_all_coords(int count) {
@@ -370,7 +349,7 @@
// Adds a var that is computed in the VS and read in FS.
// If there is a GS it will just pass it through.
-void append_varying(GrGLShaderVar::Type type,
+void append_varying(GrSLType type,
const char* name,
ShaderCodeSegments* segments,
const char** vsOutName = NULL,
@@ -416,7 +395,7 @@
// version of above that adds a stage number to the
// the var name (for uniqueness)
-void append_varying(GrGLShaderVar::Type type,
+void append_varying(GrSLType type,
const char* name,
int stageNum,
ShaderCodeSegments* segments,
@@ -434,7 +413,7 @@
GrStringBuilder* coverageVar,
ShaderCodeSegments* segments) const {
if (fProgramDesc.fEdgeAANumEdges > 0) {
- segments->fFSUnis.push_back().set(GrGLShaderVar::kVec3f_Type,
+ segments->fFSUnis.push_back().set(kVec3f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier,
EDGES_UNI_NAME,
fProgramDesc.fEdgeAANumEdges);
@@ -485,9 +464,9 @@
*coverageVar = "edgeAlpha";
} else if (layout & GrDrawTarget::kEdge_VertexLayoutBit) {
const char *vsName, *fsName;
- append_varying(GrGLShaderVar::kVec4f_Type, "Edge", segments,
+ append_varying(kVec4f_GrSLType, "Edge", segments,
&vsName, &fsName);
- segments->fVSAttrs.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments->fVSAttrs.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier, EDGE_ATTR_NAME);
segments->fVSCode.appendf("\t%s = " EDGE_ATTR_NAME ";\n", vsName);
if (GrDrawState::kHairLine_EdgeType == fProgramDesc.fVertexEdgeType) {
@@ -539,16 +518,16 @@
GrStringBuilder* inColor) {
switch (colorInput) {
case GrGLProgram::ProgramDesc::kAttribute_ColorInput: {
- segments->fVSAttrs.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments->fVSAttrs.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier,
COL_ATTR_NAME);
const char *vsName, *fsName;
- append_varying(GrGLShaderVar::kVec4f_Type, "Color", segments, &vsName, &fsName);
+ append_varying(kVec4f_GrSLType, "Color", segments, &vsName, &fsName);
segments->fVSCode.appendf("\t%s = " COL_ATTR_NAME ";\n", vsName);
*inColor = fsName;
} break;
case GrGLProgram::ProgramDesc::kUniform_ColorInput:
- segments->fFSUnis.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments->fFSUnis.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier,
COL_UNI_NAME);
programData->fUniLocations.fColorUni = kUseUniform;
@@ -567,11 +546,11 @@
void genAttributeCoverage(ShaderCodeSegments* segments,
GrStringBuilder* inOutCoverage) {
- segments->fVSAttrs.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments->fVSAttrs.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier,
COV_ATTR_NAME);
const char *vsName, *fsName;
- append_varying(GrGLShaderVar::kVec4f_Type, "Coverage",
+ append_varying(kVec4f_GrSLType, "Coverage",
segments, &vsName, &fsName);
segments->fVSCode.appendf("\t%s = " COV_ATTR_NAME ";\n", vsName);
if (inOutCoverage->size()) {
@@ -586,7 +565,7 @@
void genUniformCoverage(ShaderCodeSegments* segments,
GrGLProgram::CachedData* programData,
GrStringBuilder* inOutCoverage) {
- segments->fFSUnis.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments->fFSUnis.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier,
COV_UNI_NAME);
programData->fUniLocations.fCoverageUni = kUseUniform;
@@ -711,15 +690,15 @@
}
#if GR_GL_ATTRIBUTE_MATRICES
- segments.fVSAttrs.push_back().set(GrGLShaderVar::kMat33f_Type,
+ segments.fVSAttrs.push_back().set(kMat33f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier, VIEW_MATRIX_NAME);
programData->fUniLocations.fViewMatrixUni = kSetAsAttribute;
#else
- segments.fVSUnis.push_back().set(GrGLShaderVar::kMat33f_Type,
+ segments.fVSUnis.push_back().set(kMat33f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier, VIEW_MATRIX_NAME);
programData->fUniLocations.fViewMatrixUni = kUseUniform;
#endif
- segments.fVSAttrs.push_back().set(GrGLShaderVar::kVec2f_Type,
+ segments.fVSAttrs.push_back().set(kVec2f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier, POS_ATTR_NAME);
segments.fVSCode.append(
@@ -747,7 +726,7 @@
for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
if (GrDrawTarget::VertexUsesTexCoordIdx(t, layout)) {
tex_attr_name(t, texCoordAttrs + t);
- segments.fVSAttrs.push_back().set(GrGLShaderVar::kVec2f_Type,
+ segments.fVSAttrs.push_back().set(kVec2f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier,
texCoordAttrs[t].c_str());
}
@@ -807,7 +786,7 @@
}
}
if (needColorFilterUniform) {
- segments.fFSUnis.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments.fFSUnis.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier,
COL_FILTER_UNI_NAME);
programData->fUniLocations.fColorFilterUni = kUseUniform;
@@ -828,10 +807,10 @@
inColor = "filteredColor";
}
if (applyColorMatrix) {
- segments.fFSUnis.push_back().set(GrGLShaderVar::kMat44f_Type,
+ segments.fFSUnis.push_back().set(kMat44f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier,
COL_MATRIX_UNI_NAME);
- segments.fFSUnis.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments.fFSUnis.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier,
COL_MATRIX_VEC_UNI_NAME);
programData->fUniLocations.fColorMatrixUni = kUseUniform;
@@ -911,7 +890,7 @@
}
}
if (ProgramDesc::kNone_DualSrcOutput != fProgramDesc.fDualSrcOutput) {
- segments.fFSOutputs.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments.fFSOutputs.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kOut_TypeModifier,
dual_source_output_name());
bool outputIsZero = coverageIsZero;
@@ -1411,7 +1390,7 @@
int varyingDims, int coordDims) {
GrGLShaderVar* radial2FSParams = &segments->fFSUnis.push_back();
- radial2FSParams->setType(GrGLShaderVar::kFloat_Type);
+ radial2FSParams->setType(kFloat_GrSLType);
radial2FSParams->setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
radial2FSParams->setArrayCount(6);
radial2_param_name(stageNum, radial2FSParams->accessName());
@@ -1423,7 +1402,7 @@
// part of the quadratic as a varying.
if (varyingDims == coordDims) {
GrAssert(2 == coordDims);
- append_varying(GrGLShaderVar::kFloat_Type,
+ append_varying(kFloat_GrSLType,
"Radial2BCoeff",
stageNum,
segments,
@@ -1601,11 +1580,11 @@
const char* varyingVSName) {
//GrGLShaderVar* kernel = &segments->fFSUnis.push_back();
*kernel = &segments->fFSUnis.push_back();
- (*kernel)->setType(GrGLShaderVar::kFloat_Type);
+ (*kernel)->setType(kFloat_GrSLType);
(*kernel)->setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
(*kernel)->setArrayCount(desc.fKernelWidth);
GrGLShaderVar* imgInc = &segments->fFSUnis.push_back();
- imgInc->setType(GrGLShaderVar::kVec2f_Type);
+ imgInc->setType(kVec2f_GrSLType);
imgInc->setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
convolve_param_names(stageNum,
@@ -1669,7 +1648,7 @@
const char** imageIncrementName,
const char* varyingVSName) {
GrGLShaderVar* imgInc = &segments->fFSUnis.push_back();
- imgInc->setType(GrGLShaderVar::kVec2f_Type);
+ imgInc->setType(kVec2f_GrSLType);
imgInc->setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
image_increment_param_name(stageNum, imgInc->accessName());
@@ -1763,7 +1742,7 @@
locations->fTextureMatrixUni = kUseUniform;
#endif
tex_matrix_name(stageNum, mat->accessName());
- mat->setType(GrGLShaderVar::kMat33f_Type);
+ mat->setType(kMat33f_GrSLType);
matName = mat->getName().c_str();
if (desc.fOptFlags & StageDesc::kNoPerspective_OptFlagBit) {
@@ -1773,7 +1752,7 @@
}
}
- segments->fFSUnis.push_back().set(GrGLShaderVar::kSampler2D_Type,
+ segments->fFSUnis.push_back().set(kSampler2D_GrSLType,
GrGLShaderVar::kUniform_TypeModifier, "");
sampler_name(stageNum, segments->fFSUnis.back().accessName());
locations->fSamplerUni = kUseUniform;
@@ -1781,14 +1760,14 @@
const char* texelSizeName = NULL;
if (StageDesc::k2x2_FetchMode == desc.fFetchMode) {
- segments->fFSUnis.push_back().set(GrGLShaderVar::kVec2f_Type,
+ segments->fFSUnis.push_back().set(kVec2f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier, "");
normalized_texel_size_name(stageNum, segments->fFSUnis.back().accessName());
texelSizeName = segments->fFSUnis.back().getName().c_str();
}
const char *varyingVSName, *varyingFSName;
- append_varying(float_vector_type(varyingDims),
+ append_varying(GrSLFloatVectorType(varyingDims),
"Stage",
stageNum,
segments,
@@ -1849,12 +1828,12 @@
fsCoordName = "inCoord";
fsCoordName.appendS32(stageNum);
segments->fFSCode.appendf("\t%s %s = %s%s / %s%s;\n",
- GrGLShaderVar::TypeString(float_vector_type(coordDims)),
- fsCoordName.c_str(),
- varyingFSName,
- vector_nonhomog_coords(varyingDims),
- varyingFSName,
- vector_homog_coord(varyingDims));
+ GrGLShaderVar::TypeString(GrSLFloatVectorType(coordDims)),
+ fsCoordName.c_str(),
+ varyingFSName,
+ GrGLSLVectorNonhomogCoords(varyingDims),
+ varyingFSName,
+ GrGLSLVectorHomogCoord(varyingDims));
}
}
@@ -1918,7 +1897,7 @@
StageDesc::kCustomTextureDomain_OptFlagBit) {
GrStringBuilder texDomainName;
tex_domain_name(stageNum, &texDomainName);
- segments->fFSUnis.push_back().set(GrGLShaderVar::kVec4f_Type,
+ segments->fFSUnis.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kUniform_TypeModifier, texDomainName);
GrStringBuilder coordVar("clampCoord");
segments->fFSCode.appendf("\t%s %s = clamp(%s, %s.xy, %s.zw);\n",