Sample location fix

The sample locations were reordered "for fragment offset
computation". The reordering was causing some sample location tests
to fail.

Fixes SwANGLE tests:
dEQP.GLES31/functional_texture_multisample_samples_*_sample_position

Bug: b/147387937 b/139793135
Change-Id: I1a62d96517f2be0d625b9e9f8082d6f9e4c6a3f2
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40508
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Pipeline/Constants.cpp b/src/Pipeline/Constants.cpp
index ab84e50..1f93ded 100644
--- a/src/Pipeline/Constants.cpp
+++ b/src/Pipeline/Constants.cpp
@@ -299,12 +299,8 @@
 		{
 			for(int i = 0; i < 4; i++)
 			{
-				// Reorder sample points for centroid computation
-				const float Xs[4] = { X[1][0], X[2][0], X[0][0], X[3][0] };
-				const float Ys[4] = { Y[1][0], Y[2][0], Y[0][0], Y[3][0] };
-
-				sampleX[q][c][i] = c & (1 << i) ? Xs[q] : 0.0f;
-				sampleY[q][c][i] = c & (1 << i) ? Ys[q] : 0.0f;
+				sampleX[q][c][i] = c & (1 << i) ? X[q][0] : 0.0f;
+				sampleY[q][c][i] = c & (1 << i) ? Y[q][0] : 0.0f;
 				weight[c][i] = c & (1 << i) ? 1.0f : 0.0f;
 			}
 		}
@@ -312,9 +308,8 @@
 
 	constexpr auto subPixB = vk::SUBPIXEL_PRECISION_BITS;
 
-	// Reorder sample points for fragment offset computation
-	const int Xf[4] = { toFixedPoint(X[2][0], subPixB), toFixedPoint(X[1][0], subPixB), toFixedPoint(X[3][0], subPixB), toFixedPoint(X[0][0], subPixB) };
-	const int Yf[4] = { toFixedPoint(Y[2][0], subPixB), toFixedPoint(Y[1][0], subPixB), toFixedPoint(Y[3][0], subPixB), toFixedPoint(Y[0][0], subPixB) };
+	const int Xf[4] = { toFixedPoint(X[0][0], subPixB), toFixedPoint(X[1][0], subPixB), toFixedPoint(X[2][0], subPixB), toFixedPoint(X[3][0], subPixB) };
+	const int Yf[4] = { toFixedPoint(Y[0][0], subPixB), toFixedPoint(Y[1][0], subPixB), toFixedPoint(Y[2][0], subPixB), toFixedPoint(Y[3][0], subPixB) };
 
 	memcpy(&this->Xf, &Xf, sizeof(Xf));
 	memcpy(&this->Yf, &Yf, sizeof(Yf));
diff --git a/src/Pipeline/Constants.hpp b/src/Pipeline/Constants.hpp
index 1680f30..88448e0 100644
--- a/src/Pipeline/Constants.hpp
+++ b/src/Pipeline/Constants.hpp
@@ -108,10 +108,10 @@
 	};
 
 	static constexpr float SampleLocationsY[4] = {
-		-(VkSampleLocations4[0][1] - 0.5f),
-		-(VkSampleLocations4[1][1] - 0.5f),
-		-(VkSampleLocations4[2][1] - 0.5f),
-		-(VkSampleLocations4[3][1] - 0.5f),
+		VkSampleLocations4[0][1] - 0.5f,
+		VkSampleLocations4[1][1] - 0.5f,
+		VkSampleLocations4[2][1] - 0.5f,
+		VkSampleLocations4[3][1] - 0.5f,
 	};
 
 	// Compute the yMin and yMax multisample offsets so that they are just
diff --git a/src/Pipeline/SetupRoutine.cpp b/src/Pipeline/SetupRoutine.cpp
index 84073e2..a34c489 100644
--- a/src/Pipeline/SetupRoutine.cpp
+++ b/src/Pipeline/SetupRoutine.cpp
@@ -202,8 +202,9 @@
 
 				if(state.enableMultiSampling)
 				{
-					Xq[i] = Xq[i] + *Pointer<Int>(constants + OFFSET(Constants, Xf) + q * sizeof(int));
-					Yq[i] = Yq[i] + *Pointer<Int>(constants + OFFSET(Constants, Yf) + q * sizeof(int));
+					// The subtraction here is because we're not moving the point, we're testing the edge against it
+					Xq[i] = Xq[i] - *Pointer<Int>(constants + OFFSET(Constants, Xf) + q * sizeof(int));
+					Yq[i] = Yq[i] - *Pointer<Int>(constants + OFFSET(Constants, Yf) + q * sizeof(int));
 				}
 
 				i++;