texgrad implementation

Related deqp tests: texturegrad, textureprojgrad

Change-Id: I17529ed426c29bc1dec48fb7ac939c29caeeaf07
Reviewed-on: https://swiftshader-review.googlesource.com/5420
Tested-by: Meng-Lin Wu <marleymoo@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index c076f05..4d4fd1d 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -22,4 +22,5 @@
  Keun Soo Yim <yim@google.com>

  John Sheu <sheu@google.com>

  Philippe Hamel <hamelphi@google.com>

- Daniel Toyama <kenjitoyama@google.com>
\ No newline at end of file
+ Daniel Toyama <kenjitoyama@google.com>

+ Meng-Lin Wu <marleymoo@google.com>
\ No newline at end of file
diff --git a/src/Shader/PixelProgram.cpp b/src/Shader/PixelProgram.cpp
index 1c0ffb9..abaff41 100644
--- a/src/Shader/PixelProgram.cpp
+++ b/src/Shader/PixelProgram.cpp
@@ -1120,7 +1120,7 @@
 
 	void PixelProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3)
 	{
-		UNIMPLEMENTED();
+		sampleTexture(dst, src1, src0.x, src0.y, src0.z, src0.w, src2, src3, false, Grad);
 	}
 
 	void PixelProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3, Vector4f &offset)
diff --git a/src/Shader/VertexProgram.cpp b/src/Shader/VertexProgram.cpp
index 24a6693..111abe2 100644
--- a/src/Shader/VertexProgram.cpp
+++ b/src/Shader/VertexProgram.cpp
@@ -1533,13 +1533,13 @@
 
 	void VertexProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1)
 	{
-		sampleTexture(dst, src1, src0.x, src0.y, src0.z, src0.w, Lod);
+		sampleTexture(dst, src1, src0.x, src0.y, src0.z, src0.w, a0, a0, Lod);
 	}
 
 	void VertexProgram::TEX(Vector4f &dst, Vector4f &src0, const Src &src1)
 	{
 		Float4 lod0 = Float4(0.0f);
-		sampleTexture(dst, src1, src0.x, src0.y, src0.z, lod0, Lod);
+		sampleTexture(dst, src1, src0.x, src0.y, src0.z, lod0, a0, a0, Lod);
 	}
 
 	void VertexProgram::TEXOFFSET(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3)
@@ -1564,7 +1564,8 @@
 
 	void VertexProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3)
 	{
-		UNIMPLEMENTED();
+		Float4 lod0 = Float4(0.0f);
+		sampleTexture(dst, src1, src0.x, src0.y, src0.z, lod0, src2, src3, Grad);
 	}
 
 	void VertexProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3, Vector4f &offset)
@@ -1584,14 +1585,14 @@
 		}
 	}
 
-	void VertexProgram::sampleTexture(Vector4f &c, const Src &s, Float4 &u, Float4 &v, Float4 &w, Float4 &q, SamplerMethod method)
+	void VertexProgram::sampleTexture(Vector4f &c, const Src &s, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, SamplerMethod method)
 	{
 		Vector4f tmp;
 
 		if(s.type == Shader::PARAMETER_SAMPLER && s.rel.type == Shader::PARAMETER_VOID)
 		{
-			Pointer<Byte> texture = data + OFFSET(DrawData,mipmap[TEXTURE_IMAGE_UNITS]) + s.index * sizeof(Texture);
-			sampler[s.index]->sampleTexture(texture, tmp, u, v, w, q, a0, a0, method);
+			Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + s.index * sizeof(Texture);
+			sampler[s.index]->sampleTexture(texture, tmp, u, v, w, q, dsx, dsy, method);
 		}
 		else
 		{
@@ -1603,8 +1604,8 @@
 				{
 					If(index == i)
 					{
-						Pointer<Byte> texture = data + OFFSET(DrawData,mipmap[TEXTURE_IMAGE_UNITS]) + i * sizeof(Texture);
-						sampler[i]->sampleTexture(texture, tmp, u, v, w, q, a0, a0, method);
+						Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + i * sizeof(Texture);
+						sampler[i]->sampleTexture(texture, tmp, u, v, w, q, dsx, dsy, method);
 						// FIXME: When the sampler states are the same, we could use one sampler and just index the texture
 					}
 				}
diff --git a/src/Shader/VertexProgram.hpp b/src/Shader/VertexProgram.hpp
index 54335c2..8101caf 100644
--- a/src/Shader/VertexProgram.hpp
+++ b/src/Shader/VertexProgram.hpp
@@ -116,7 +116,7 @@
 		void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, Vector4f &src4);
 		void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&);
 
-		void sampleTexture(Vector4f &c, const Src &s, Float4 &u, Float4 &v, Float4 &w, Float4 &q, SamplerMethod method);
+		void sampleTexture(Vector4f &c, const Src &s, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, SamplerMethod method);
 
 		SamplerCore *sampler[VERTEX_TEXTURE_IMAGE_UNITS];