Reland Reland "Remove use of integers for atlas indexing"
Bug: skia: Change-Id: Ie37b3fd6c8682b2d778b1dd0bc38976e6761524e Reviewed-on: https://skia-review.googlesource.com/c/172142 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
03115dc284
commit
0711094b91
@ -20,31 +20,19 @@ static void append_index_uv_varyings(GrGLSLPrimitiveProcessor::EmitArgs& args,
|
||||
GrGLSLVarying *uv,
|
||||
GrGLSLVarying *texIdx,
|
||||
GrGLSLVarying *st) {
|
||||
using Interpolation = GrGLSLVaryingHandler::Interpolation;
|
||||
|
||||
// This extracts the texture index and texel coordinates from the same variable
|
||||
// Packing structure: texel coordinates are multiplied by 2 (or shifted left 1)
|
||||
// texture index is stored as lower bits of both x and y
|
||||
if (args.fShaderCaps->integerSupport()) {
|
||||
args.fVertBuilder->codeAppendf("int2 signedCoords = int2(%s.x, %s.y);",
|
||||
inTexCoordsName, inTexCoordsName);
|
||||
args.fVertBuilder->codeAppend("int texIdx = 2*(signedCoords.x & 0x1) + (signedCoords.y & 0x1);");
|
||||
args.fVertBuilder->codeAppend("float2 unormTexCoords = float2(signedCoords.x/2, signedCoords.y/2);");
|
||||
} else {
|
||||
args.fVertBuilder->codeAppendf("float2 indexTexCoords = float2(%s.x, %s.y);",
|
||||
inTexCoordsName, inTexCoordsName);
|
||||
args.fVertBuilder->codeAppend("float2 unormTexCoords = floor(0.5*indexTexCoords);");
|
||||
args.fVertBuilder->codeAppend("float2 diff = indexTexCoords - 2.0*unormTexCoords;");
|
||||
args.fVertBuilder->codeAppend("float texIdx = 2.0*diff.x + diff.y;");
|
||||
}
|
||||
args.fVertBuilder->codeAppendf("float2 indexTexCoords = float2(%s.x, %s.y);",
|
||||
inTexCoordsName, inTexCoordsName);
|
||||
args.fVertBuilder->codeAppend("float2 unormTexCoords = floor(0.5*indexTexCoords);");
|
||||
args.fVertBuilder->codeAppend("float2 diff = indexTexCoords - 2.0*unormTexCoords;");
|
||||
args.fVertBuilder->codeAppend("float texIdx = 2.0*diff.x + diff.y;");
|
||||
|
||||
// Multiply by 1/atlasSize to get normalized texture coordinates
|
||||
args.fVaryingHandler->addVarying("TextureCoords", uv);
|
||||
args.fVertBuilder->codeAppendf("%s = unormTexCoords * %s;", uv->vsOut(), atlasSizeInvName);
|
||||
|
||||
args.fVaryingHandler->addVarying("TexIndex", texIdx, args.fShaderCaps->integerSupport()
|
||||
? Interpolation::kMustBeFlat
|
||||
: Interpolation::kCanBeFlat);
|
||||
args.fVaryingHandler->addVarying("TexIndex", texIdx);
|
||||
args.fVertBuilder->codeAppendf("%s = texIdx;", texIdx->vsOut());
|
||||
|
||||
if (st) {
|
||||
@ -58,15 +46,17 @@ static void append_multitexture_lookup(GrGLSLPrimitiveProcessor::EmitArgs& args,
|
||||
const GrGLSLVarying &texIdx,
|
||||
const char* coordName,
|
||||
const char* colorName) {
|
||||
// conditionally load from the indexed texture sampler
|
||||
for (int i = 0; i < numTextureSamplers-1; ++i) {
|
||||
args.fFragBuilder->codeAppendf("if (%s == %d) { %s = ", texIdx.fsIn(), i, colorName);
|
||||
// Conditionally load from the indexed texture sampler.
|
||||
// We treat an interval of values around each int as corresponding to that int
|
||||
// (basically round to int) to correct for floating point variation in the frag shader
|
||||
for (int i = numTextureSamplers-1; i > 0; --i) {
|
||||
args.fFragBuilder->codeAppendf("if (%s > %d - 0.5) { %s = ", texIdx.fsIn(), i, colorName);
|
||||
args.fFragBuilder->appendTextureLookup(args.fTexSamplers[i], coordName,
|
||||
kFloat2_GrSLType);
|
||||
args.fFragBuilder->codeAppend("; } else ");
|
||||
}
|
||||
args.fFragBuilder->codeAppendf("{ %s = ", colorName);
|
||||
args.fFragBuilder->appendTextureLookup(args.fTexSamplers[numTextureSamplers-1], coordName,
|
||||
args.fFragBuilder->appendTextureLookup(args.fTexSamplers[0], coordName,
|
||||
kFloat2_GrSLType);
|
||||
args.fFragBuilder->codeAppend("; }");
|
||||
}
|
||||
|
@ -40,8 +40,7 @@ public:
|
||||
&atlasSizeInvName);
|
||||
|
||||
GrGLSLVarying uv(kFloat2_GrSLType);
|
||||
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
|
||||
GrGLSLVarying texIdx(texIdxType);
|
||||
GrGLSLVarying texIdx(kFloat_GrSLType);
|
||||
append_index_uv_varyings(args, btgp.inTextureCoords().name(), atlasSizeInvName, &uv,
|
||||
&texIdx, nullptr);
|
||||
|
||||
|
@ -68,8 +68,7 @@ public:
|
||||
|
||||
// add varyings
|
||||
GrGLSLVarying uv(kFloat2_GrSLType);
|
||||
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
|
||||
GrGLSLVarying texIdx(texIdxType);
|
||||
GrGLSLVarying texIdx(kFloat_GrSLType);
|
||||
GrGLSLVarying st(kFloat2_GrSLType);
|
||||
append_index_uv_varyings(args, dfTexEffect.inTextureCoords().name(), atlasSizeInvName, &uv,
|
||||
&texIdx, &st);
|
||||
@ -230,7 +229,7 @@ GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(const GrShaderCaps& c
|
||||
} else {
|
||||
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
|
||||
}
|
||||
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType };
|
||||
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
|
||||
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
|
||||
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
|
||||
this->setVertexAttributes(&fInPosition, 3);
|
||||
@ -345,8 +344,7 @@ public:
|
||||
&atlasSizeInvName);
|
||||
|
||||
GrGLSLVarying uv(kFloat2_GrSLType);
|
||||
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
|
||||
GrGLSLVarying texIdx(texIdxType);
|
||||
GrGLSLVarying texIdx(kFloat_GrSLType);
|
||||
GrGLSLVarying st(kFloat2_GrSLType);
|
||||
append_index_uv_varyings(args, dfPathEffect.inTextureCoords().name(), atlasSizeInvName, &uv,
|
||||
&texIdx, &st);
|
||||
@ -648,8 +646,7 @@ public:
|
||||
|
||||
// set up varyings
|
||||
GrGLSLVarying uv(kFloat2_GrSLType);
|
||||
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
|
||||
GrGLSLVarying texIdx(texIdxType);
|
||||
GrGLSLVarying texIdx(kFloat_GrSLType);
|
||||
GrGLSLVarying st(kFloat2_GrSLType);
|
||||
append_index_uv_varyings(args, dfTexEffect.inTextureCoords().name(), atlasSizeInvName, &uv,
|
||||
&texIdx, &st);
|
||||
|
Loading…
Reference in New Issue
Block a user