FP32 linear filtering computation now available to most formats

All texture formats, except YUV or sRGB formats, now have access
to the floating point path for texture filtering. High precision
filtering can be enabled using:
glHint(GL_TEXTURE_FILTERING_HINT_CHROMIUM, GL_NICEST)

Bug swiftshader:76

Change-Id: Iabbe86d1bbf43070bfc5f61254c101a75c744401
Reviewed-on: https://swiftshader-review.googlesource.com/10808
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Shader/SamplerCore.cpp b/src/Shader/SamplerCore.cpp
index 55c1712..f0d482f 100644
--- a/src/Shader/SamplerCore.cpp
+++ b/src/Shader/SamplerCore.cpp
@@ -314,7 +314,9 @@
 		}
 		else
 		{
-			if(hasFloatTexture() || hasUnnormalizedIntegerTexture() || state.highPrecisionFiltering)   // FIXME: Mostly identical to integer sampling
+			// FIXME: YUV and sRGB are not supported by the floating point path
+			bool forceFloatFiltering = state.highPrecisionFiltering && !state.sRGB && !hasYuvFormat() && (state.textureFilter != FILTER_POINT);
+			if(hasFloatTexture() || hasUnnormalizedIntegerTexture() || forceFloatFiltering)   // FIXME: Mostly identical to integer sampling
 			{
 				Float4 uuuu = u;
 				Float4 vvvv = v;
@@ -353,6 +355,30 @@
 				}
 
 				sampleFloatFilter(texture, c, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function);
+
+				if(!hasFloatTexture() && !hasUnnormalizedIntegerTexture())
+				{
+					if(has16bitTextureFormat())
+					{
+						switch(state.textureFormat)
+						{
+						case FORMAT_R5G6B5:
+							c.x *= Float4(1.0f / 0xF800);
+							c.y *= Float4(1.0f / 0xFC00);
+							c.z *= Float4(1.0f / 0xF800);
+							break;
+						default:
+							ASSERT(false);
+						}
+					}
+					else
+					{
+						for(int component = 0; component < textureComponentCount(); component++)
+						{
+							c[component] *= Float4(hasUnsignedTextureComponent(component) ? 1.0f / 0xFFFF : 1.0f / 0x7FFF);
+						}
+					}
+				}
 			}
 			else
 			{