Detect all texture sampling shader instructions.

Change-Id: If557db7db89659e6c2b043b21e5712fb34eafd8d
Reviewed-on: https://swiftshader-review.googlesource.com/4561
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Shader/PixelShader.cpp b/src/Shader/PixelShader.cpp
index f569342..2147fea 100644
--- a/src/Shader/PixelShader.cpp
+++ b/src/Shader/PixelShader.cpp
@@ -225,7 +225,7 @@
 			for(unsigned int i = 0; i < instruction.size(); i++)
 			{
 				if(instruction[i]->dst.type == Shader::PARAMETER_TEXTURE)
-				{	
+				{
 					int index = instruction[i]->dst.index + 2;
 					int mask = instruction[i]->dst.mask;
 
@@ -288,7 +288,7 @@
 						int index = instruction[i]->src[argument].index;
 						int swizzle = instruction[i]->src[argument].swizzle;
 						int mask = instruction[i]->dst.mask;
-						
+
 						if(instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE)
 						{
 							index += 2;
diff --git a/src/Shader/VertexRoutine.cpp b/src/Shader/VertexRoutine.cpp
index 96f48e6..74f1285 100644
--- a/src/Shader/VertexRoutine.cpp
+++ b/src/Shader/VertexRoutine.cpp
@@ -36,7 +36,7 @@
 
 	void VertexRoutine::generate()
 	{
-		const bool texldl = state.shaderContainsTexldl;
+		const bool textureSampling = state.textureSampling;
 
 		Pointer<Byte> cache = task + OFFSET(VertexTask,vertexCache);
 		Pointer<Byte> vertexCache = cache + OFFSET(VertexCache,vertex);
@@ -50,7 +50,7 @@
 		{
 			UInt index = *Pointer<UInt>(batch);
 			UInt tagIndex = index & 0x0000003C;
-			UInt indexQ = !texldl ? UInt(index & 0xFFFFFFFC) : index;   // FIXME: TEXLDL hack to have independent LODs, hurts performance.
+			UInt indexQ = !textureSampling ? UInt(index & 0xFFFFFFFC) : index;   // FIXME: TEXLDL hack to have independent LODs, hurts performance.
 
 			If(*Pointer<UInt>(tagCache + tagIndex) != indexQ)
 			{
@@ -131,14 +131,14 @@
 
 	Vector4f VertexRoutine::readStream(Pointer<Byte> &buffer, UInt &stride, const Stream &stream, const UInt &index)
 	{
-		const bool texldl = state.shaderContainsTexldl;
+		const bool textureSampling = state.textureSampling;
 
 		Vector4f v;
 
 		Pointer<Byte> source0 = buffer + index * stride;
-		Pointer<Byte> source1 = source0 + (!texldl ? stride : 0);
-		Pointer<Byte> source2 = source1 + (!texldl ? stride : 0);
-		Pointer<Byte> source3 = source2 + (!texldl ? stride : 0);
+		Pointer<Byte> source1 = source0 + (!textureSampling ? stride : 0);
+		Pointer<Byte> source2 = source1 + (!textureSampling ? stride : 0);
+		Pointer<Byte> source3 = source2 + (!textureSampling ? stride : 0);
 
 		switch(stream.type)
 		{
diff --git a/src/Shader/VertexShader.cpp b/src/Shader/VertexShader.cpp
index fab6b17..dc8bd06 100644
--- a/src/Shader/VertexShader.cpp
+++ b/src/Shader/VertexShader.cpp
@@ -141,9 +141,9 @@
 		return instructionCount;
 	}
 
-	bool VertexShader::containsTexldl() const
+	bool VertexShader::containsTextureSampling() const
 	{
-		return texldl;
+		return textureSampling;
 	}
 
 	void VertexShader::analyze()
@@ -151,7 +151,7 @@
 		analyzeInput();
 		analyzeOutput();
 		analyzeDirtyConstants();
-		analyzeTexldl();
+		analyzeTextureSampling();
 		analyzeDynamicBranching();
 		analyzeSamplers();
 		analyzeCallSites();
@@ -262,17 +262,15 @@
 		}
 	}
 
-	void VertexShader::analyzeTexldl()
+	void VertexShader::analyzeTextureSampling()
 	{
-		texldl = false;
+		textureSampling = false;
 
-		for(unsigned int i = 0; i < instruction.size(); i++)
+		for(unsigned int i = 0; i < instruction.size() && !textureSampling; i++)
 		{
-			if(instruction[i]->opcode == Shader::OPCODE_TEXLDL)
+			if(instruction[i]->src[1].type == PARAMETER_SAMPLER)
 			{
-				texldl = true;
-
-				break;
+				textureSampling = true;
 			}
 		}
 	}
diff --git a/src/Shader/VertexShader.hpp b/src/Shader/VertexShader.hpp
index 3d8f3fe..127d64c 100644
--- a/src/Shader/VertexShader.hpp
+++ b/src/Shader/VertexShader.hpp
@@ -25,8 +25,8 @@
 		virtual ~VertexShader();
 
 		static int validate(const unsigned long *const token);   // Returns number of instructions if valid
-		bool containsTexldl() const;
-		
+		bool containsTextureSampling() const;
+
 		virtual void analyze();
 
 		int positionRegister;     // FIXME: Private
@@ -43,9 +43,9 @@
 	private:
 		void analyzeInput();
 		void analyzeOutput();
-		void analyzeTexldl();
+		void analyzeTextureSampling();
 
-		bool texldl;
+		bool textureSampling;
 	};
 }