diff options
author | 2017-11-20 12:36:16 -0500 | |
---|---|---|
committer | 2017-11-20 18:07:08 +0000 | |
commit | 999ec57291dc7cf1d8e3a745627670e6cadc1c12 (patch) | |
tree | 78b34ac300515da3103c730345d4f0390959fb97 /src/gpu/effects/GrAtlasedShaderHelpers.h | |
parent | 40dc8a71f5d55dd7ed4e64c883664efae6da70ca (diff) |
Use int when possible to calculate atlas indices in shaders.
On certain iOS devices half has a mantissa of only 10 bits, which is not
enough to perform the floating point trickery to get the lower bits
out of the "texture coordinates". Instead we use int if available, and
float if not available.
Also re-enables multitexturing for iOS and adds a sample which
stresses the issue.
Bug: skia:7285
Change-Id: I365532c7cbbcca7c7753af209bef46e05be49e11
Reviewed-on: https://skia-review.googlesource.com/71181
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/gpu/effects/GrAtlasedShaderHelpers.h')
-rw-r--r-- | src/gpu/effects/GrAtlasedShaderHelpers.h | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/gpu/effects/GrAtlasedShaderHelpers.h b/src/gpu/effects/GrAtlasedShaderHelpers.h index ad901411db..7fc321daa2 100644 --- a/src/gpu/effects/GrAtlasedShaderHelpers.h +++ b/src/gpu/effects/GrAtlasedShaderHelpers.h @@ -8,6 +8,7 @@ #ifndef GrAtlasedShaderHelpers_DEFINED #define GrAtlasedShaderHelpers_DEFINED +#include "GrShaderCaps.h" #include "glsl/GrGLSLPrimitiveProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" #include "glsl/GrGLSLVarying.h" @@ -22,17 +23,24 @@ static void append_index_uv_varyings(GrGLSLPrimitiveProcessor::EmitArgs& args, // 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 - args.fVertBuilder->codeAppendf("half2 indexTexCoords = half2(%s.x, %s.y);", - inTexCoordsName, inTexCoordsName); - args.fVertBuilder->codeAppend("half2 intCoords = floor(0.5*indexTexCoords);"); - args.fVertBuilder->codeAppend("half2 diff = indexTexCoords - 2.0*intCoords;"); - args.fVertBuilder->codeAppend("half texIdx = 2.0*diff.x + diff.y;"); + if (args.fShaderCaps->integerSupport()) { + args.fVertBuilder->codeAppendf("int2 signedCoords = int2(%s);", inTexCoordsName); + args.fVertBuilder->codeAppend("int texIdx = 2*(signedCoords.x & 0x1) + (signedCoords.y & 0x1);"); + args.fVertBuilder->codeAppend("signedCoords >>= 1;"); + args.fVertBuilder->codeAppend("float2 intCoords = float2(signedCoords);"); + } else { + args.fVertBuilder->codeAppendf("float2 indexTexCoords = float2(%s.x, %s.y);", + inTexCoordsName, inTexCoordsName); + args.fVertBuilder->codeAppend("float2 intCoords = floor(0.5*indexTexCoords);"); + args.fVertBuilder->codeAppend("float2 diff = indexTexCoords - 2.0*intCoords;"); + 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 = intCoords * %s;", uv->vsOut(), atlasSizeInvName); - args.fVaryingHandler->addVarying("TexIndex", texIdx); + args.fVaryingHandler->addFlatVarying("TexIndex", texIdx); args.fVertBuilder->codeAppendf("%s = texIdx;", texIdx->vsOut()); if (st) { |