From c02cb8a86ce801f471a8cf7bd46880648c48f089 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Mon, 20 Nov 2017 22:11:30 +0000 Subject: Revert "Use int when possible to calculate atlas indices in shaders." This reverts commit 999ec57291dc7cf1d8e3a745627670e6cadc1c12. Reason for revert: Causing issues with NexusPlayer Vulkan. Original change's description: > 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 > Commit-Queue: Jim Van Verth TBR=jvanverth@google.com,bsalomon@google.com,robertphillips@google.com Change-Id: I82801a73a2a8067588049b213f010ff25f4014f3 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:7285 Reviewed-on: https://skia-review.googlesource.com/74001 Reviewed-by: Jim Van Verth Commit-Queue: Jim Van Verth --- src/gpu/effects/GrAtlasedShaderHelpers.h | 20 ++++++-------------- src/gpu/effects/GrBitmapTextGeoProc.cpp | 3 +-- src/gpu/effects/GrDistanceFieldGeoProc.cpp | 9 +++------ 3 files changed, 10 insertions(+), 22 deletions(-) (limited to 'src/gpu/effects') diff --git a/src/gpu/effects/GrAtlasedShaderHelpers.h b/src/gpu/effects/GrAtlasedShaderHelpers.h index 7fc321daa2..ad901411db 100644 --- a/src/gpu/effects/GrAtlasedShaderHelpers.h +++ b/src/gpu/effects/GrAtlasedShaderHelpers.h @@ -8,7 +8,6 @@ #ifndef GrAtlasedShaderHelpers_DEFINED #define GrAtlasedShaderHelpers_DEFINED -#include "GrShaderCaps.h" #include "glsl/GrGLSLPrimitiveProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" #include "glsl/GrGLSLVarying.h" @@ -23,24 +22,17 @@ 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 - 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;"); - } + 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;"); // 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->addFlatVarying("TexIndex", texIdx); + args.fVaryingHandler->addVarying("TexIndex", texIdx); args.fVertBuilder->codeAppendf("%s = texIdx;", texIdx->vsOut()); if (st) { diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp index 4193f1d24c..d5f930fec4 100644 --- a/src/gpu/effects/GrBitmapTextGeoProc.cpp +++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp @@ -38,8 +38,7 @@ public: &atlasSizeInvName); GrGLSLVertToFrag uv(kFloat2_GrSLType); - GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType; - GrGLSLVertToFrag texIdx(texIdxType); + GrGLSLVertToFrag texIdx(kHalf_GrSLType); append_index_uv_varyings(args, btgp.inTextureCoords()->fName, atlasSizeInvName, &uv, &texIdx, nullptr); diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp index 3e9addef6d..aafabdeb60 100644 --- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp +++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp @@ -78,8 +78,7 @@ public: // add varyings GrGLSLVertToFrag uv(kFloat2_GrSLType); - GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType; - GrGLSLVertToFrag texIdx(texIdxType); + GrGLSLVertToFrag texIdx(kHalf_GrSLType); GrGLSLVertToFrag st(kFloat2_GrSLType); append_index_uv_varyings(args, dfTexEffect.inTextureCoords()->fName, atlasSizeInvName, &uv, &texIdx, &st); @@ -345,8 +344,7 @@ public: &atlasSizeInvName); GrGLSLVertToFrag uv(kFloat2_GrSLType); - GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType; - GrGLSLVertToFrag texIdx(texIdxType); + GrGLSLVertToFrag texIdx(kHalf_GrSLType); GrGLSLVertToFrag st(kFloat2_GrSLType); append_index_uv_varyings(args, dfTexEffect.inTextureCoords()->fName, atlasSizeInvName, &uv, &texIdx, &st); @@ -641,8 +639,7 @@ public: // set up varyings GrGLSLVertToFrag uv(kFloat2_GrSLType); - GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType; - GrGLSLVertToFrag texIdx(texIdxType); + GrGLSLVertToFrag texIdx(kHalf_GrSLType); GrGLSLVertToFrag st(kFloat2_GrSLType); append_index_uv_varyings(args, dfTexEffect.inTextureCoords()->fName, atlasSizeInvName, &uv, &texIdx, &st); -- cgit v1.2.3