Implement support for YV12 texture sampling.

Bug 21572252

Change-Id: Iaf54b4d960dbc243c40f981e1c73c199481e2d28
Reviewed-on: https://swiftshader-review.googlesource.com/3930
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Renderer/Sampler.cpp b/src/Renderer/Sampler.cpp
index 9f26e4e..f4d5061 100644
--- a/src/Renderer/Sampler.cpp
+++ b/src/Renderer/Sampler.cpp
@@ -34,7 +34,7 @@
 	Sampler::Sampler()
 	{
 		// FIXME: Mipmap::init
-		static unsigned int zero = 0x00FF00FF;
+		static const unsigned int zero = 0x00FF00FF;
 
 		for(int level = 0; level < MIPMAP_LEVELS; level++)
 		{
@@ -210,6 +210,34 @@
 
 				mipmap.sliceP[0] = sliceP;
 				mipmap.sliceP[1] = sliceP;
+
+				if(internalTextureFormat == FORMAT_YV12_BT601 ||
+				   internalTextureFormat == FORMAT_YV12_BT709 ||
+				   internalTextureFormat == FORMAT_YV12_JFIF)
+				{
+					unsigned int YStride = align(width, 16);
+					unsigned int YSize = YStride * height;
+					unsigned int CStride = align(YStride / 2, 16);
+ 					unsigned int CSize = CStride * height / 2;
+
+					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;
+					texture.mipmap[1].width[3] = width / 2;
+					texture.mipmap[1].height[0] = height / 2;
+					texture.mipmap[1].height[1] = height / 2;
+					texture.mipmap[1].height[2] = height / 2;
+					texture.mipmap[1].height[3] = height / 2;
+					texture.mipmap[1].onePitchP[0] = 1;
+					texture.mipmap[1].onePitchP[1] = CStride;
+					texture.mipmap[1].onePitchP[2] = 1;
+					texture.mipmap[1].onePitchP[3] = CStride;
+				}
 			}
 		}