Fix depth clamping during 'very' early depth test.

We perform depth testing before computing scanline invariants, as an
optimization. But it was not taking into account that the
fixed-function depth value may require clamping due to the depth bias.

Bug swiftshader:82

Change-Id: I6f8953f9d060c73b5fe209b8cbad70e7cb7588b4
Reviewed-on: https://swiftshader-review.googlesource.com/13088
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Renderer/QuadRasterizer.cpp b/src/Renderer/QuadRasterizer.cpp
index 2855e16..795e1ee 100644
--- a/src/Renderer/QuadRasterizer.cpp
+++ b/src/Renderer/QuadRasterizer.cpp
@@ -180,7 +180,7 @@
 
 					For(Int x = x0, x < x1, x += 2)
 					{
-						Float4 z = interpolate(xxxx, Dz[0], z, primitive + OFFSET(Primitive,z), false, false);
+						Float4 z = interpolate(xxxx, Dz[0], z, primitive + OFFSET(Primitive,z), false, false, state.depthClamp);
 
 						Float4 zValue;
 
@@ -316,7 +316,7 @@
 		Until(y >= yMax)
 	}
 
-	Float4 QuadRasterizer::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective)
+	Float4 QuadRasterizer::interpolate(Float4 &x, Float4 &D, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective, bool clamp)
 	{
 		Float4 interpolant = D;
 
@@ -330,6 +330,11 @@
 			}
 		}
 
+		if(clamp)
+		{
+			interpolant = Min(Max(interpolant, Float4(0.0f)), Float4(1.0f));
+		}
+
 		return interpolant;
 	}