store the page bits in U only
Store the 2 page index bits in bits 14 and 15 of U. This allows several simplifications. Change-Id: Ib3ce98f0f5a430849acc0e6f6f3ecfabdb3f038d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313896 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
1e87a9ab4a
commit
d80cb1fb72
@ -212,11 +212,9 @@ public:
|
||||
*/
|
||||
static std::pair<uint16_t, uint16_t> PackIndexInTexCoords(
|
||||
uint16_t u, uint16_t v, int pageIndex) {
|
||||
// Pack the two bits for the page index in bit 15 of u and v; u gets the high bit, and v
|
||||
// gets the low bit.
|
||||
// Pack the two bits of page in bits 14 and 15 of u.
|
||||
SkASSERT(0 <= pageIndex && pageIndex < 4);
|
||||
u |= (pageIndex & 0x2u) << 14;
|
||||
v |= pageIndex << 15;
|
||||
u |= pageIndex << 14;
|
||||
return std::make_pair(u, v);
|
||||
}
|
||||
|
||||
|
@ -24,31 +24,33 @@ static void append_index_uv_varyings(GrGLSLPrimitiveProcessor::EmitArgs& args,
|
||||
GrGLSLVarying* st) {
|
||||
using Interpolation = GrGLSLVaryingHandler::Interpolation;
|
||||
// This extracts the texture index and texel coordinates from the same variable
|
||||
// Packing structure: texel coordinates have the 2-bit texture page encoded in bit 15 of uv,
|
||||
// with the high bit of the page in u, and to low bit in v.
|
||||
// Packing structure: texel coordinates have the 2-bit texture page encoded in bits 14 & 15 of
|
||||
// the x coordinate.
|
||||
if (args.fShaderCaps->integerSupport()) {
|
||||
args.fVertBuilder->codeAppendf("int2 coords = int2(%s.x, %s.y);",
|
||||
inTexCoordsName, inTexCoordsName);
|
||||
args.fVertBuilder->codeAppend(
|
||||
"float2 unormTexCoords = float2(coords.x & 0x7FFF, coords.y & 0x7FFF);");
|
||||
if (numTextureSamplers <= 1) {
|
||||
args.fVertBuilder->codeAppend("int texIdx = 0;");
|
||||
args.fVertBuilder->codeAppendf(R"code(
|
||||
int texIdx = 0;
|
||||
float2 unormTexCoords = float2(%s.x, %s.y);
|
||||
)code", inTexCoordsName, inTexCoordsName);
|
||||
} else {
|
||||
args.fVertBuilder->codeAppend(
|
||||
"int texIdx = ((coords.x >> 14) & 0x2) + ((coords.y >> 15) & 0x1);");
|
||||
args.fVertBuilder->codeAppendf(R"code(
|
||||
int2 coords = int2(%s.x, %s.y);
|
||||
int texIdx = coords.x >> 14;
|
||||
float2 unormTexCoords = float2(coords.x & 0x3FFF, coords.y);
|
||||
)code", inTexCoordsName, inTexCoordsName);
|
||||
}
|
||||
} else {
|
||||
args.fVertBuilder->codeAppendf("float2 coord = float2(%s.x, %s.y);",
|
||||
inTexCoordsName, inTexCoordsName);
|
||||
args.fVertBuilder->codeAppend(R"code(
|
||||
float2 unitTexCoords = exp2(-15) * coord;
|
||||
float2 highBits = floor(unitTexCoords);
|
||||
float2 unormTexCoords = coord - exp2(15) * highBits;
|
||||
)code");
|
||||
if (numTextureSamplers <= 1) {
|
||||
args.fVertBuilder->codeAppend("float texIdx = 0;");
|
||||
args.fVertBuilder->codeAppendf(R"code(
|
||||
float texIdx = 0;
|
||||
float2 unormTexCoords = float2(%s.x, %s.y);
|
||||
)code", inTexCoordsName, inTexCoordsName);
|
||||
} else {
|
||||
args.fVertBuilder->codeAppend("float texIdx = highBits.x * 2.0 + highBits.y;");
|
||||
args.fVertBuilder->codeAppendf(R"code(
|
||||
float2 coord = float2(%s.x, %s.y);
|
||||
float texIdx = floor(coord.x * exp2(-14));
|
||||
float2 unormTexCoords = float2(coord.x - texIdx * exp2(14), coord.y);
|
||||
)code", inTexCoordsName, inTexCoordsName);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user