Fix using pitch for compressed format decoding.

For seamless cube maps the pitch (in pixels) differs from the width,
due to the border.

Also renamed identicalFormats() to identicalBuffers() since much more
than the format is compared to determine if the buffers should be
identical.

Bug swiftshader:45

Change-Id: I295557b2cb039615a624c106be3e74588463b102
Reviewed-on: https://swiftshader-review.googlesource.com/19668
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Renderer/Surface.cpp b/src/Renderer/Surface.cpp
index cc1c5a7..9c47f1c 100644
--- a/src/Renderer/Surface.cpp
+++ b/src/Renderer/Surface.cpp
@@ -1400,7 +1400,7 @@
 
 		if(!external.buffer)
 		{
-			if(internal.buffer && identicalFormats())
+			if(internal.buffer && identicalBuffers())
 			{
 				external.buffer = internal.buffer;
 			}
@@ -1452,7 +1452,7 @@
 
 		if(!internal.buffer)
 		{
-			if(external.buffer && identicalFormats())
+			if(external.buffer && identicalBuffers())
 			{
 				internal.buffer = external.buffer;
 			}
@@ -2311,7 +2311,7 @@
 					{
 						for(int i = 0; i < 4 && (x + i) < internal.width; i++)
 						{
-							dest[(x + i) + (y + j) * internal.width] = c[(unsigned int)(source->lut >> 2 * (i + j * 4)) % 4];
+							dest[(x + i) + (y + j) * internal.pitchP] = c[(unsigned int)(source->lut >> 2 * (i + j * 4)) % 4];
 						}
 					}
 
@@ -2361,7 +2361,7 @@
 							unsigned int a = (unsigned int)(source->a >> 4 * (i + j * 4)) & 0x0F;
 							unsigned int color = (c[(unsigned int)(source->lut >> 2 * (i + j * 4)) % 4] & 0x00FFFFFF) | ((a << 28) + (a << 24));
 
-							dest[(x + i) + (y + j) * internal.width] = color;
+							dest[(x + i) + (y + j) * internal.pitchP] = color;
 						}
 					}
 
@@ -2435,7 +2435,7 @@
 							unsigned int alpha = (unsigned int)a[(unsigned int)(source->alut >> (16 + 3 * (i + j * 4))) % 8] << 24;
 							unsigned int color = (c[(source->clut >> 2 * (i + j * 4)) % 4] & 0x00FFFFFF) | alpha;
 
-							dest[(x + i) + (y + j) * internal.width] = color;
+							dest[(x + i) + (y + j) * internal.pitchP] = color;
 						}
 					}
 
@@ -2491,7 +2491,7 @@
 					{
 						for(int i = 0; i < 4 && (x + i) < internal.width; i++)
 						{
-							dest[(x + i) + (y + j) * internal.width] = r[(unsigned int)(source->rlut >> (16 + 3 * (i + j * 4))) % 8];
+							dest[(x + i) + (y + j) * internal.pitchP] = r[(unsigned int)(source->rlut >> (16 + 3 * (i + j * 4))) % 8];
 						}
 					}
 
@@ -2574,7 +2574,7 @@
 							word r = X[(unsigned int)(source->xlut >> (16 + 3 * (i + j * 4))) % 8];
 							word g = Y[(unsigned int)(source->ylut >> (16 + 3 * (i + j * 4))) % 8];
 
-							dest[(x + i) + (y + j) * internal.width] = (g << 8) + r;
+							dest[(x + i) + (y + j) * internal.pitchP] = (g << 8) + r;
 						}
 					}
 
@@ -3729,7 +3729,7 @@
 		return resource;
 	}
 
-	bool Surface::identicalFormats() const
+	bool Surface::identicalBuffers() const
 	{
 		return external.format == internal.format &&
 		       external.width  == internal.width &&