Deprecate handling power-of-two texture sampling separately.

NPOT texture sampling is slightly slower, but with OpenGL we were
already treating every mipmapped texture as NPOT due to requiring
padding at the 1x1 level for renderability. Seamless cube maps are
also NPOT due to the border. Furthermore, the vector shifts by scalar
required for POT texel address calculation would require 128-bit
values when we deprecate MMX.

Change-Id: Ie2e68f632bea7c6f3e599015c14be50392ea7e9a
Reviewed-on: https://swiftshader-review.googlesource.com/8248
Reviewed-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Renderer/Sampler.cpp b/src/Renderer/Sampler.cpp
index c6cec5e..93b3731 100644
--- a/src/Renderer/Sampler.cpp
+++ b/src/Renderer/Sampler.cpp
@@ -48,10 +48,6 @@
 			{
 				mipmap.buffer[face] = &zero;
 			}
-
-			mipmap.uFrac = 16;
-			mipmap.vFrac = 16;
-			mipmap.wFrac = 16;
 		}
 
 		externalTextureFormat = FORMAT_NULL;
@@ -97,7 +93,6 @@
 			state.addressingModeV = getAddressingModeV();
 			state.addressingModeW = getAddressingModeW();
 			state.mipmapFilter = mipmapFilter();
-			state.hasNPOTTexture = hasNPOTTexture();
 			state.sRGB = sRGB && Surface::isSRGBreadable(externalTextureFormat);
 			state.swizzleR = swizzleR;
 			state.swizzleG = swizzleG;
@@ -158,16 +153,7 @@
 					texture.depthLOD[3] = depth * exp2LOD;
 				}
 
-				if(!Surface::isFloatFormat(internalTextureFormat))
-				{
-					mipmap.uInt = logWidth;
-					mipmap.vInt = logHeight;
-					mipmap.wInt = logDepth;
-					mipmap.uFrac = 16 - logWidth;
-					mipmap.vFrac = 16 - logHeight;
-					mipmap.wFrac = 16 - logDepth;
-				}
-				else
+				if(Surface::isFloatFormat(internalTextureFormat))
 				{
 					mipmap.fWidth[0] = (float)width / 65536.0f;
 					mipmap.fWidth[1] = (float)width / 65536.0f;
@@ -239,8 +225,6 @@
 					mipmap.buffer[1] = (byte*)mipmap.buffer[0] + YSize;
 					mipmap.buffer[2] = (byte*)mipmap.buffer[1] + CSize;
 
-					texture.mipmap[1].uFrac = texture.mipmap[0].uFrac + 1;
-					texture.mipmap[1].vFrac = texture.mipmap[0].vFrac + 1;
 					texture.mipmap[1].width[0] = width / 2;
 					texture.mipmap[1].width[1] = width / 2;
 					texture.mipmap[1].width[2] = width / 2;
@@ -420,24 +404,6 @@
 		return MIPMAP_NONE;
 	}
 
-	bool Sampler::hasNPOTTexture() const
-	{
-		if(textureType == TEXTURE_NULL)
-		{
-			return false;
-		}
-
-		for(int i = 0; i < MIPMAP_LEVELS; i++)
-		{
-			if(texture.mipmap[i].width[0] != texture.mipmap[i].onePitchP[1])
-			{
-				return true;   // Shifting of the texture coordinates doesn't yield the correct address, so using multiply by pitch
-			}
-		}
-
-		return !isPow2(texture.mipmap[0].width[0]) || !isPow2(texture.mipmap[0].height[0]) || !isPow2(texture.mipmap[0].depth[0]);
-	}
-
 	TextureType Sampler::getTextureType() const
 	{
 		return textureType;
diff --git a/src/Renderer/Sampler.hpp b/src/Renderer/Sampler.hpp
index 56841a8..87c9d3f 100644
--- a/src/Renderer/Sampler.hpp
+++ b/src/Renderer/Sampler.hpp
@@ -24,25 +24,9 @@
 	{
 		const void *buffer[6];
 
-		union
-		{
-			struct
-			{
-				int64_t uInt;
-				int64_t vInt;
-				int64_t wInt;
-				int64_t uFrac;
-				int64_t vFrac;
-				int64_t wFrac;
-			};
-
-			struct
-			{
-				float4 fWidth;
-				float4 fHeight;
-				float4 fDepth;
-			};
-		};
+		float4 fWidth;
+		float4 fHeight;
+		float4 fDepth;
 
 		short uHalf[4];
 		short vHalf[4];
@@ -150,7 +134,6 @@
 			AddressingMode addressingModeV : BITS(ADDRESSING_LAST);
 			AddressingMode addressingModeW : BITS(ADDRESSING_LAST);
 			MipmapType mipmapFilter        : BITS(FILTER_LAST);
-			bool hasNPOTTexture            : 1;
 			bool sRGB                      : 1;
 			SwizzleType swizzleR           : BITS(SWIZZLE_LAST);
 			SwizzleType swizzleG           : BITS(SWIZZLE_LAST);
@@ -201,7 +184,6 @@
 
 	private:
 		MipmapType mipmapFilter() const;
-		bool hasNPOTTexture() const;
 		TextureType getTextureType() const;
 		FilterType getTextureFilter() const;
 		AddressingMode getAddressingModeU() const;
diff --git a/src/Shader/SamplerCore.cpp b/src/Shader/SamplerCore.cpp
index fe14710..d33acc3 100644
--- a/src/Shader/SamplerCore.cpp
+++ b/src/Shader/SamplerCore.cpp
@@ -820,19 +820,8 @@
 			if(!gather)   // Blend
 			{
 				// Fractions
-				UShort4 f0u = uuuu0;
-				UShort4 f0v = vvvv0;
-
-				if(!state.hasNPOTTexture)
-				{
-					f0u = f0u << *Pointer<Long1>(mipmap + OFFSET(Mipmap,uInt));   // .u
-					f0v = f0v << *Pointer<Long1>(mipmap + OFFSET(Mipmap,vInt));   // .v
-				}
-				else
-				{
-					f0u = f0u * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
-					f0v = f0v * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
-				}
+				UShort4 f0u = As<UShort4>(uuuu0) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
+				UShort4 f0v = As<UShort4>(vvvv0) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
 
 				UShort4 f1u = ~f0u;
 				UShort4 f1v = ~f0v;
@@ -1029,29 +1018,17 @@
 			}
 
 			// Fractions
-			UShort4 f[2][2][2];
-			Short4 fs[2][2][2];
-			UShort4 f0u;
-			UShort4 f0v;
-			UShort4 f0s;
-
-			if(!state.hasNPOTTexture)
-			{
-				f0u = As<UShort4>(u[0][0][0]) << *Pointer<Long1>(mipmap + OFFSET(Mipmap,uInt));
-				f0v = As<UShort4>(v[0][0][0]) << *Pointer<Long1>(mipmap + OFFSET(Mipmap,vInt));
-				f0s = As<UShort4>(s[0][0][0]) << *Pointer<Long1>(mipmap + OFFSET(Mipmap,wInt));
-			}
-			else
-			{
-				f0u = As<UShort4>(u[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
-				f0v = As<UShort4>(v[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
-				f0s = As<UShort4>(s[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,depth));
-			}
+			UShort4 f0u = As<UShort4>(u[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
+			UShort4 f0v = As<UShort4>(v[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
+			UShort4 f0s = As<UShort4>(s[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,depth));
 
 			UShort4 f1u = ~f0u;
 			UShort4 f1v = ~f0v;
 			UShort4 f1s = ~f0s;
 
+			UShort4 f[2][2][2];
+			Short4 fs[2][2][2];
+
 			f[1][1][1] = MulHigh(f1u, f1v);
 			f[0][1][1] = MulHigh(f0u, f1v);
 			f[1][0][1] = MulHigh(f1u, f0v);
@@ -1699,44 +1676,26 @@
 
 	void SamplerCore::computeIndices(Int index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, Vector4f &offset, const Pointer<Byte> &mipmap, SamplerFunction function)
 	{
-		Short4 uuu2;
-
 		bool texelFetch = (function == Fetch);
 		bool hasOffset = (function.option == Offset);
 
-		if(!state.hasNPOTTexture && !hasFloatTexture() && !hasOffset)
+		if(!texelFetch)
 		{
-			if(!texelFetch)
-			{
-				vvvv = As<UShort4>(vvvv) >> *Pointer<Long1>(mipmap + OFFSET(Mipmap, vFrac));
-			}
-			uuu2 = uuuu;
-			uuuu = As<Short4>(UnpackLow(uuuu, vvvv));
-			uuu2 = As<Short4>(UnpackHigh(uuu2, vvvv));
-			if(!texelFetch)
-			{
-				uuuu = As<Short4>(As<UInt2>(uuuu) >> *Pointer<Long1>(mipmap + OFFSET(Mipmap, uFrac)));
-				uuu2 = As<Short4>(As<UInt2>(uuu2) >> *Pointer<Long1>(mipmap + OFFSET(Mipmap, uFrac)));
-			}
+			uuuu = MulHigh(As<UShort4>(uuuu), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, width)));
+			vvvv = MulHigh(As<UShort4>(vvvv), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, height)));
 		}
-		else
+
+		if(hasOffset)
 		{
-			if(!texelFetch)
-			{
-				uuuu = MulHigh(As<UShort4>(uuuu), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, width)));
-				vvvv = MulHigh(As<UShort4>(vvvv), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, height)));
-			}
-			if(hasOffset)
-			{
-				uuuu = applyOffset(uuuu, offset.x, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, width))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeU);
-				vvvv = applyOffset(vvvv, offset.y, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, height))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeV);
-			}
-			uuu2 = uuuu;
-			uuuu = As<Short4>(UnpackLow(uuuu, vvvv));
-			uuu2 = As<Short4>(UnpackHigh(uuu2, vvvv));
-			uuuu = As<Short4>(MulAdd(uuuu, *Pointer<Short4>(mipmap + OFFSET(Mipmap,onePitchP))));
-			uuu2 = As<Short4>(MulAdd(uuu2, *Pointer<Short4>(mipmap + OFFSET(Mipmap,onePitchP))));
+			uuuu = applyOffset(uuuu, offset.x, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, width))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeU);
+			vvvv = applyOffset(vvvv, offset.y, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, height))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeV);
 		}
+		
+		Short4 uuu2 = uuuu;
+		uuuu = As<Short4>(UnpackLow(uuuu, vvvv));
+		uuu2 = As<Short4>(UnpackHigh(uuu2, vvvv));
+		uuuu = As<Short4>(MulAdd(uuuu, *Pointer<Short4>(mipmap + OFFSET(Mipmap,onePitchP))));
+		uuu2 = As<Short4>(MulAdd(uuu2, *Pointer<Short4>(mipmap + OFFSET(Mipmap,onePitchP))));
 
 		if((state.textureType == TEXTURE_3D) || (state.textureType == TEXTURE_2D_ARRAY))
 		{