remove 4x4 downsample filter mode

Review URL: http://codereview.appspot.com/6267046/



git-svn-id: http://skia.googlecode.com/svn/trunk@4149 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-06-04 20:06:02 +00:00
parent a1e5795279
commit d2ae1fad78
7 changed files with 25 additions and 150 deletions

View File

@ -26,15 +26,6 @@ public:
* Blend between closest 4 src texels to sample position (tent filter)
*/
kBilinear_Filter,
/**
* Average of 4 bilinear filterings spaced +/- 1 texel from sample
* position in x and y. Intended for averaging 16 texels in a downsample
* pass. (rasterizing such that texture samples fall exactly halfway
* between texels in x and y spaced 4 texels apart.) Only supported
* on shader backends.
*/
k4x4Downsample_Filter,
kDefault_Filter = kNearest_Filter
};

View File

@ -80,11 +80,6 @@ inline void tex_matrix_name(int stage, GrStringBuilder* s) {
s->appendS32(stage);
}
inline void normalized_texel_size_name(int stage, GrStringBuilder* s) {
*s = "uTexelSize";
s->appendS32(stage);
}
inline void sampler_name(int stage, GrStringBuilder* s) {
*s = "uSampler";
s->appendS32(stage);
@ -1150,14 +1145,6 @@ void GrGLProgram::getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
GrAssert(kUnusedUniform != locations.fSamplerUni);
}
if (kUseUniform == locations.fNormalizedTexelSizeUni) {
GrStringBuilder texelSizeName;
normalized_texel_size_name(s, &texelSizeName);
GL_CALL_RET(locations.fNormalizedTexelSizeUni,
GetUniformLocation(progID, texelSizeName.c_str()));
GrAssert(kUnusedUniform != locations.fNormalizedTexelSizeUni);
}
if (kUseUniform == locations.fTexDomUni) {
GrStringBuilder texDomName;
tex_domain_name(s, &texDomName);
@ -1198,38 +1185,6 @@ void GrGLProgram::getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
// Stage code generation
//============================================================================
namespace {
void gen2x2FS(int stageNum,
GrGLShaderBuilder* segments,
GrGLProgram::StageUniLocations* locations,
const char* samplerName,
const char* texelSizeName,
const char* fsOutColor,
GrStringBuilder& texFunc) {
locations->fNormalizedTexelSizeUni = kUseUniform;
if (segments->fComplexCoord) {
// assign the coord to a var rather than compute 4x.
GrStringBuilder coordVar("tCoord");
coordVar.appendS32(stageNum);
segments->fFSCode.appendf("\t%s %s = %s;\n",
float_vector_type_str(segments->fCoordDims),
coordVar.c_str(), segments->fSampleCoords.c_str());
segments->fSampleCoords = coordVar;
}
GrAssert(2 == segments->fCoordDims);
GrStringBuilder accumVar("accum");
accumVar.appendS32(stageNum);
segments->fFSCode.appendf("\tvec4 %s = %s(%s, %s + vec2(-%s.x,-%s.y))%s;\n", accumVar.c_str(), texFunc.c_str(), samplerName, segments->fSampleCoords.c_str(), texelSizeName, texelSizeName, segments->fSwizzle.c_str());
segments->fFSCode.appendf("\t%s += %s(%s, %s + vec2(+%s.x,-%s.y))%s;\n", accumVar.c_str(), texFunc.c_str(), samplerName, segments->fSampleCoords.c_str(), texelSizeName, texelSizeName, segments->fSwizzle.c_str());
segments->fFSCode.appendf("\t%s += %s(%s, %s + vec2(-%s.x,+%s.y))%s;\n", accumVar.c_str(), texFunc.c_str(), samplerName, segments->fSampleCoords.c_str(), texelSizeName, texelSizeName, segments->fSwizzle.c_str());
segments->fFSCode.appendf("\t%s += %s(%s, %s + vec2(+%s.x,+%s.y))%s;\n", accumVar.c_str(), texFunc.c_str(), samplerName, segments->fSampleCoords.c_str(), texelSizeName, texelSizeName, segments->fSwizzle.c_str());
segments->fFSCode.appendf("\t%s = .25 * %s%s;\n", fsOutColor, accumVar.c_str(), segments->fModulate.c_str());
}
}
void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
int stageNum,
const GrGLProgram::StageDesc& desc,
@ -1281,15 +1236,6 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
samplerName.c_str());
locations->fSamplerUni = kUseUniform;
const char* texelSizeName = NULL;
if (StageDesc::k2x2_FetchMode == desc.fFetchMode) {
GrStringBuilder ntsName;
normalized_texel_size_name(stageNum, &ntsName);
texelSizeName = segments->addUniform(
GrGLShaderBuilder::kFragment_VariableLifetime,
kVec2f_GrSLType, ntsName.c_str()).getName().c_str();
}
const char *varyingVSName, *varyingFSName;
segments->addVarying(GrSLFloatVectorType(segments->fVaryingDims),
"Stage",
@ -1325,8 +1271,7 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
if (desc.fOptFlags & (StageDesc::kIdentityMatrix_OptFlagBit |
StageDesc::kNoPerspective_OptFlagBit)) {
sampleMode = GrGLShaderBuilder::kDefault_SamplerMode;
} else if (NULL == customStage &&
StageDesc::kSingle_FetchMode == desc.fFetchMode) {
} else if (NULL == customStage) {
sampleMode = GrGLShaderBuilder::kProj_SamplerMode;
}
segments->setupTextureAccess(sampleMode, stageNum);
@ -1358,40 +1303,31 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
// NOTE: GrGLProgramStages are now responsible for fetching
if (NULL == customStage) {
switch (desc.fFetchMode) {
case StageDesc::k2x2_FetchMode:
GrAssert(!(desc.fInConfigFlags & kMulByAlphaMask));
gen2x2FS(stageNum, segments, locations,
samplerName.c_str(), texelSizeName, fsOutColor,
segments->fTexFunc);
break;
default:
if (desc.fInConfigFlags & kMulByAlphaMask) {
// only one of the mul by alpha flags should be set
GrAssert(GrIsPow2(kMulByAlphaMask & desc.fInConfigFlags));
GrAssert(!(desc.fInConfigFlags &
StageDesc::kSmearAlpha_InConfigFlag));
GrAssert(!(desc.fInConfigFlags &
StageDesc::kSmearRed_InConfigFlag));
segments->fFSCode.appendf("\t%s = %s(%s, %s)%s;\n",
fsOutColor,
segments->fTexFunc.c_str(),
samplerName.c_str(),
segments->fSampleCoords.c_str(),
segments->fSwizzle.c_str());
if (desc.fInConfigFlags &
StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag) {
segments->fFSCode.appendf("\t%s = vec4(ceil(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n",
fsOutColor, fsOutColor, fsOutColor,
fsOutColor, segments->fModulate.c_str());
} else {
segments->fFSCode.appendf("\t%s = vec4(floor(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n",
fsOutColor, fsOutColor, fsOutColor,
fsOutColor, segments->fModulate.c_str());
}
if (desc.fInConfigFlags & kMulByAlphaMask) {
// only one of the mul by alpha flags should be set
GrAssert(GrIsPow2(kMulByAlphaMask & desc.fInConfigFlags));
GrAssert(!(desc.fInConfigFlags &
StageDesc::kSmearAlpha_InConfigFlag));
GrAssert(!(desc.fInConfigFlags &
StageDesc::kSmearRed_InConfigFlag));
segments->fFSCode.appendf("\t%s = %s(%s, %s)%s;\n",
fsOutColor,
segments->fTexFunc.c_str(),
samplerName.c_str(),
segments->fSampleCoords.c_str(),
segments->fSwizzle.c_str());
if (desc.fInConfigFlags &
StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag) {
segments->fFSCode.appendf("\t%s = vec4(ceil(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n",
fsOutColor, fsOutColor, fsOutColor,
fsOutColor, segments->fModulate.c_str());
} else {
segments->emitDefaultFetch(fsOutColor, samplerName.c_str());
segments->fFSCode.appendf("\t%s = vec4(floor(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n",
fsOutColor, fsOutColor, fsOutColor,
fsOutColor, segments->fModulate.c_str());
}
} else {
segments->emitDefaultFetch(fsOutColor, samplerName.c_str());
}
}

View File

@ -108,12 +108,6 @@ public:
kIsEnabled_OptFlagBit = 1 << 7
};
enum FetchMode {
kSingle_FetchMode,
k2x2_FetchMode,
kFetchModeCnt,
};
/**
Flags set based on a src texture's pixel config. The operations
described are performed after reading a texel.
@ -148,7 +142,7 @@ public:
/**
Multiply r,g,b by a after texture reads. This flag incompatible
with kSmearAlpha and may only be used with FetchMode kSingle.
with kSmearAlpha.
It is assumed the src texture has 8bit color components. After
reading the texture one version rounds up to the next multiple
@ -165,7 +159,6 @@ public:
uint8_t fOptFlags;
uint8_t fInConfigFlags; // bitfield of InConfigFlags values
uint8_t fFetchMode; // casts to enum FetchMode
/** Non-zero if user-supplied code will write the stage's
contribution to the fragment shader. */
@ -250,12 +243,10 @@ public:
struct StageUniLocations {
GrGLint fTextureMatrixUni;
GrGLint fNormalizedTexelSizeUni;
GrGLint fSamplerUni;
GrGLint fTexDomUni;
void reset() {
fTextureMatrixUni = kUnusedUniform;
fNormalizedTexelSizeUni = kUnusedUniform;
fSamplerUni = kUnusedUniform;
fTexDomUni = kUnusedUniform;
}

View File

@ -2064,7 +2064,6 @@ namespace {
unsigned gr_to_gl_filter(GrSamplerState::Filter filter) {
switch (filter) {
case GrSamplerState::kBilinear_Filter:
case GrSamplerState::k4x4Downsample_Filter:
return GR_GL_LINEAR;
case GrSamplerState::kNearest_Filter:
return GR_GL_NEAREST;

View File

@ -250,9 +250,6 @@ private:
// flushes the parameters for convolution
void flushConvolution(int stage);
// flushes the normalized texel size
void flushTexelSize(int stage);
// flushes the color matrix
void flushColorMatrix();

View File

@ -247,22 +247,6 @@ void GrGpuGL::flushTextureMatrixAndDomain(int s) {
}
}
void GrGpuGL::flushTexelSize(int s) {
const int& uni = fProgramData->fUniLocations.fStages[s].fNormalizedTexelSizeUni;
if (GrGLProgram::kUnusedUniform != uni) {
const GrGLTexture* texture =
static_cast<const GrGLTexture*>(this->getDrawState().getTexture(s));
if (texture->width() != fProgramData->fTextureWidth[s] ||
texture->height() != fProgramData->fTextureHeight[s]) {
float texelSize[] = {1.f / texture->width(),
1.f / texture->height()};
GL_CALL(Uniform2fv(uni, 1, texelSize));
fProgramData->fTextureWidth[s] = texture->width();
fProgramData->fTextureHeight[s] = texture->height();
}
}
}
void GrGpuGL::flushColorMatrix() {
const ProgramDesc& desc = fCurrentProgram.getDesc();
@ -452,8 +436,6 @@ bool GrGpuGL::flushGraphicsState(GrPrimitiveType type) {
this->flushTextureMatrixAndDomain(s);
this->flushTexelSize(s);
if (NULL != fProgramData->fCustomStage[s]) {
const GrSamplerState& sampler =
this->getDrawState().getSampler(s);
@ -761,21 +743,6 @@ void GrGpuGL::buildProgram(GrPrimitiveType type,
stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit;
}
switch (sampler.getFilter()) {
// these both can use a regular texture2D()
case GrSamplerState::kNearest_Filter:
case GrSamplerState::kBilinear_Filter:
stage.fFetchMode = StageDesc::kSingle_FetchMode;
break;
// performs 4 texture2D()s
case GrSamplerState::k4x4Downsample_Filter:
stage.fFetchMode = StageDesc::k2x2_FetchMode;
break;
default:
GrCrash("Unexpected filter!");
break;
}
if (sampler.hasTextureDomain()) {
GrAssert(GrSamplerState::kClamp_WrapMode ==
sampler.getWrapX() &&
@ -823,7 +790,6 @@ void GrGpuGL::buildProgram(GrPrimitiveType type,
} else {
stage.fOptFlags = 0;
stage.fInConfigFlags = 0;
stage.fFetchMode = (StageDesc::FetchMode) 0;
stage.fCustomStageKey = 0;
customStages[s] = NULL;
}

View File

@ -205,16 +205,11 @@ bool GrGpuGL::programUnitTest() {
stage.fOptFlags = STAGE_OPTS[random_int(&random, GR_ARRAY_COUNT(STAGE_OPTS))];
stage.fInConfigFlags = IN_CONFIG_FLAGS[random_int(&random, GR_ARRAY_COUNT(IN_CONFIG_FLAGS))];
stage.fFetchMode = random_int(&random, StageDesc::kFetchModeCnt);
stage.setEnabled(VertexUsesStage(s, pdesc.fVertexLayout));
static const uint32_t kMulByAlphaMask =
StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag |
StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag;
if (StageDesc::k2x2_FetchMode == stage.fFetchMode) {
stage.fInConfigFlags &= ~kMulByAlphaMask;
}
bool useCustomEffect = random_bool(&random);
if (useCustomEffect) {
customStages[s].reset(create_random_effect(&stage, &random));