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/OpenGL/compiler/OutputASM.cpp b/src/OpenGL/compiler/OutputASM.cpp
index 14a42c9..76bedfa 100644
--- a/src/OpenGL/compiler/OutputASM.cpp
+++ b/src/OpenGL/compiler/OutputASM.cpp
@@ -1298,8 +1298,8 @@
 

 							if(textureFunction.proj)

 							{

-									Instruction *div = emit(sw::Shader::OPCODE_DIV, &proj, arg[1], arg[1]);

-									div->dst.mask = 0x3;

+								Instruction *div = emit(sw::Shader::OPCODE_DIV, &proj, arg[1], arg[1]);

+								div->dst.mask = 0x3;

 

 								switch(t->getNominalSize())

 								{

diff --git a/src/Renderer/VertexProcessor.cpp b/src/Renderer/VertexProcessor.cpp
index 5517820..80539dc 100644
--- a/src/Renderer/VertexProcessor.cpp
+++ b/src/Renderer/VertexProcessor.cpp
@@ -805,7 +805,7 @@
 		}
 
 		state.fixedFunction = !context->vertexShader && context->pixelShaderVersion() < 0x0300;
-		state.shaderContainsTexldl = context->vertexShader ? context->vertexShader->containsTexldl() : false;
+		state.textureSampling = context->vertexShader ? context->vertexShader->containsTextureSampling() : false;
 		state.positionRegister = context->vertexShader ? context->vertexShader->positionRegister : Pos;
 		state.pointSizeRegister = context->vertexShader ? context->vertexShader->pointSizeRegister : Pts;
 
diff --git a/src/Renderer/VertexProcessor.hpp b/src/Renderer/VertexProcessor.hpp
index 06dfa4e..d379304 100644
--- a/src/Renderer/VertexProcessor.hpp
+++ b/src/Renderer/VertexProcessor.hpp
@@ -46,10 +46,10 @@
 			uint64_t shaderID;

 

 			bool fixedFunction             : 1;

-			bool shaderContainsTexldl      : 1;

+			bool textureSampling           : 1;

 			unsigned int positionRegister  : 4;

 			unsigned int pointSizeRegister : 4;   // 0xF signifies no vertex point size

-				

+

 			unsigned int vertexBlendMatrixCount               : 3;

 			bool indexedVertexBlendEnable                     : 1;

 			bool vertexNormalActive                           : 1;

@@ -115,7 +115,7 @@
 				union

 				{

 					unsigned char clamp : 4;

-					

+

 					struct

 					{

 						unsigned char xClamp : 1;

@@ -145,7 +145,7 @@
 			float4 cameraTransformT[12][4];

 			float4 normalTransformT[12][4];

 			float4 textureTransform[8][4];

-			

+

 			float4 lightPosition[8];

 			float4 lightAmbient[8];

 			float4 lightSpecular[8];

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;
 	};
 }