Pass unclamped fragcoord.z to shader

The Vulkan spec is being clarified to explain that the FragCoord passed
to a shader should use the unclamped depth value and that only the depth
test and depth write should use clamped values.

Bug: b/184063472
Change-Id: Ic76c13512745abea2181475eff5147134a1bf147
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/54668
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Sean Risser <srisser@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Commit-Queue: Sean Risser <srisser@google.com>
diff --git a/src/Pipeline/PixelRoutine.cpp b/src/Pipeline/PixelRoutine.cpp
index 91d7fe5..3e6ba99 100644
--- a/src/Pipeline/PixelRoutine.cpp
+++ b/src/Pipeline/PixelRoutine.cpp
@@ -61,6 +61,7 @@
 
 	Int zMask[4];  // Depth mask
 	Int sMask[4];  // Stencil mask
+	Float4 unclampedZ[4];
 
 	bool sampleShadingEnabled = state.sampleShadingEnabled;
 	float minSampleShading = state.minSampleShading;
@@ -127,6 +128,7 @@
 					z[q] += *Pointer<Float4>(primitive + OFFSET(Primitive, zBias), 16);
 				}
 
+				unclampedZ[q] = z[q];
 				if(state.depthClamp)
 				{
 					z[q] = Min(Max(z[q], Float4(state.minDepthClamp)), Float4(state.maxDepthClamp));
@@ -233,7 +235,7 @@
 					}
 				}
 
-				setBuiltins(x, y, z, w, cMask, sampleId);
+				setBuiltins(x, y, unclampedZ, w, cMask, sampleId);
 
 				for(uint32_t i = 0; i < state.numClipDistances; i++)
 				{