Make the number of vertex outputs configurable.

Change-Id: I17ae53e5274232e9e3b482daac56d507788e822c
Reviewed-on: https://swiftshader-review.googlesource.com/5383
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Shader/SetupRoutine.cpp b/src/Shader/SetupRoutine.cpp
index 36753bd..630fbf4 100644
--- a/src/Shader/SetupRoutine.cpp
+++ b/src/Shader/SetupRoutine.cpp
@@ -144,7 +144,7 @@
 			If(m != 0 || Bool(!solidTriangle))   // Clipped triangle; reproject
 			{
 				Pointer<Byte> V = polygon + OFFSET(Polygon,P) + m * sizeof(void*) * 16;
-		
+
 				Int i = 0;
 
 				Do
@@ -166,9 +166,9 @@
 			// Vertical range
 			Int yMin = Y[0];
 			Int yMax = Y[0];
-		
+
 			Int i = 1;
-			
+
 			Do
 			{
 				yMin = Min(Y[i], yMin);
@@ -196,7 +196,7 @@
 
 			yMin = Max(yMin, *Pointer<Int>(data + OFFSET(DrawData,scissorY0)));
 			yMax = Min(yMax, *Pointer<Int>(data + OFFSET(DrawData,scissorY1)));
-		
+
 			For(Int q = 0, q < state.multiSample, q++)
 			{
 				Array<Int> Xq(16);
@@ -510,7 +510,7 @@
 				if(component == 1) i.z = 1.0f;
 				if(component == 2) i.z = 0.0f;
 				if(component == 3) i.z = 1.0f;
-				
+
 				i.w = 0;
 			}
 
@@ -597,7 +597,7 @@
 				Int ceil = -d >> 31;   // Ceiling division: remainder <= 0
 				x -= ceil;
 				d -= ceil & FDY12;
-				
+
 				Int Q = FDX12 / FDY12;   // Edge-step
 				Int R = FDX12 % FDY12;   // Error-step
 				Int floor = R >> 31;     // Flooring division: remainder >= 0
@@ -615,7 +615,7 @@
 					d += R;
 
 					Int overflow = -d >> 31;
-			
+
 					d -= D & overflow;
 					x -= overflow;
 
@@ -632,7 +632,7 @@
 			If(condition)
 			{
 				Pointer<Byte> vX;
-			
+
 				vX = v0;
 				v0 = v1;
 				v1 = v2;
@@ -652,7 +652,7 @@
 			If(condition)
 			{
 				Pointer<Byte> vX;
-			
+
 				vX = v2;
 				v2 = v1;
 				v1 = v0;
diff --git a/src/Shader/Shader.cpp b/src/Shader/Shader.cpp
index 46858c9..deb6180 100644
--- a/src/Shader/Shader.cpp
+++ b/src/Shader/Shader.cpp
@@ -119,7 +119,7 @@
 		predicate = false;
 		predicateNot = false;
 		predicateSwizzle = 0xE4;
-		
+
 		coissue = false;
 		samplerType = SAMPLER_UNKNOWN;
 		usage = USAGE_POSITION;
@@ -162,7 +162,7 @@
 					token++;
 					size--;
 				}
-				
+
 				token++;
 				size--;
 			}
@@ -173,7 +173,7 @@
 
 				predicateNot = (Modifier)((*token & 0x0F000000) >> 24) == MODIFIER_NOT;
 				predicateSwizzle = (unsigned char)((*token & 0x00FF0000) >> 16);
-				
+
 				token++;
 				size--;
 			}
@@ -201,11 +201,11 @@
 	std::string Shader::Instruction::string(ShaderType shaderType, unsigned short version) const
 	{
 		std::string instructionString;
-		
+
 		if(opcode != OPCODE_DCL)
 		{
 			instructionString += coissue ? "+ " : "";
-			
+
 			if(predicate)
 			{
 				instructionString += predicateNot ? "(!p0" : "(p0";
@@ -219,7 +219,7 @@
 			{
 				instructionString += " " + dst.string(shaderType, version) +
 				                           dst.relativeString() +
-				                           dst.maskString(); 
+				                           dst.maskString();
 			}
 
 			for(int i = 0; i < 4; i++)
@@ -229,8 +229,8 @@
 					instructionString += (dst.type != PARAMETER_VOID || i > 0) ? ", " : " ";
 					instructionString += src[i].preModifierString() +
 										 src[i].string(shaderType, version) +
-										 src[i].relativeString() + 
-										 src[i].postModifierString() + 
+										 src[i].relativeString() +
+										 src[i].postModifierString() +
 										 src[i].swizzleString();
 				}
 			}
@@ -351,10 +351,10 @@
 		{
 		case 0:		return "";
 		case 1:		return "_x2";
-		case 2:		return "_x4"; 
+		case 2:		return "_x4";
 		case 3:		return "_x8";
 		case -1:	return "_d2";
-		case -2:	return "_d4"; 
+		case -2:	return "_d4";
 		case -3:	return "_d8";
 		default:
 			return "";
@@ -630,7 +630,7 @@
 		src[i].rel.type = PARAMETER_VOID;
 		src[i].rel.swizzle = 0x00;
 		src[i].rel.scale = 1;
-		
+
 		switch(opcode)
 		{
 		case OPCODE_DEF:
@@ -1018,7 +1018,7 @@
 		else if(type != PARAMETER_RASTOUT && !(type == PARAMETER_ADDR && shaderType == SHADER_VERTEX) && type != PARAMETER_LOOP && type != PARAMETER_PREDICATE && type != PARAMETER_MISCTYPE)
 		{
 			buffer << index;
-			
+
 			return typeString(shaderType, version) + buffer.str();
 		}
 		else
@@ -1079,7 +1079,7 @@
 	{
 		return opcode == OPCODE_IF || opcode == OPCODE_IFC;
 	}
-	
+
 	bool Shader::Instruction::isCall() const
 	{
 		return opcode == OPCODE_CALL || opcode == OPCODE_CALLNZ;
@@ -1160,7 +1160,7 @@
 			token += 1 + tokenCount;
 		}
 	}
-	
+
 	int Shader::size(unsigned long opcode) const
 	{
 		return size(opcode, version);
@@ -1633,7 +1633,7 @@
 				{
 					containsLeave = true;
 				}
-				
+
 				if(instruction[i]->isBreak())
 				{
 					containsBreak = true;
diff --git a/src/Shader/VertexProgram.cpp b/src/Shader/VertexProgram.cpp
index 26608f4..24a6693 100644
--- a/src/Shader/VertexProgram.cpp
+++ b/src/Shader/VertexProgram.cpp
@@ -594,7 +594,7 @@
 	{
 		if(shader)
 		{
-			for(int i = 0; i < 12; i++)
+			for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
 			{
 				unsigned char usage = shader->output[i][0].usage;
 
@@ -1263,7 +1263,7 @@
 		loopRepDepth--;
 
 		llvm::BasicBlock *endBlock = loopRepEndBlock[loopRepDepth];
-		
+
 		Nucleus::createBr(loopRepEndBlock[loopRepDepth]);
 		Nucleus::setInsertBlock(endBlock);
 
diff --git a/src/Shader/VertexRoutine.cpp b/src/Shader/VertexRoutine.cpp
index 0eced49..1affb45 100644
--- a/src/Shader/VertexRoutine.cpp
+++ b/src/Shader/VertexRoutine.cpp
@@ -580,7 +580,7 @@
 	{
 		Vector4f v;
 
-		for(int i = 0; i < 12; i++)
+		for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
 		{
 			if(state.output[i].write)
 			{
@@ -669,7 +669,7 @@
 
 	void VertexRoutine::writeVertex(const Pointer<Byte> &vertex, Pointer<Byte> &cache)
 	{
-		for(int i = 0; i < 12; i++)
+		for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
 		{
 			if(state.output[i].write)
 			{
diff --git a/src/Shader/VertexRoutine.hpp b/src/Shader/VertexRoutine.hpp
index 71aeb5b..d97d8ed 100644
--- a/src/Shader/VertexRoutine.hpp
+++ b/src/Shader/VertexRoutine.hpp
@@ -49,7 +49,7 @@
 		Int clipFlags;
 
 		RegisterArray<16> v;   // Varying registers
-		RegisterArray<12> o;   // Output registers
+		RegisterArray<MAX_VERTEX_OUTPUTS> o;   // Output registers
 
 		const VertexProcessor::State &state;
 
diff --git a/src/Shader/VertexShader.cpp b/src/Shader/VertexShader.cpp
index cfbda0c..c488630 100644
--- a/src/Shader/VertexShader.cpp
+++ b/src/Shader/VertexShader.cpp
@@ -25,7 +25,7 @@
 	{
 		version = 0x0300;
 		positionRegister = Pos;
-		pointSizeRegister = -1;   // No vertex point size
+		pointSizeRegister = Unused;
 		instanceIdDeclared = false;
 
 		for(int i = 0; i < MAX_INPUT_ATTRIBUTES; i++)
@@ -57,7 +57,7 @@
 		parse(token);
 
 		positionRegister = Pos;
-		pointSizeRegister = -1;   // No vertex point size
+		pointSizeRegister = Unused;
 		instanceIdDeclared = false;
 
 		for(int i = 0; i < MAX_INPUT_ATTRIBUTES; i++)
diff --git a/src/Shader/VertexShader.hpp b/src/Shader/VertexShader.hpp
index f8760fb..2a76cd2 100644
--- a/src/Shader/VertexShader.hpp
+++ b/src/Shader/VertexShader.hpp
@@ -16,6 +16,7 @@
 #define sw_VertexShader_hpp
 
 #include "Shader.hpp"
+#include "Main/Config.hpp"
 
 namespace sw
 {
@@ -40,8 +41,7 @@
 		enum {MAX_INPUT_ATTRIBUTES = 16};
 		Semantic input[MAX_INPUT_ATTRIBUTES];       // FIXME: Private
 
-		enum {MAX_OUTPUT_VARYINGS = 12};
-		Semantic output[MAX_OUTPUT_VARYINGS][4];   // FIXME: Private
+		Semantic output[MAX_VERTEX_OUTPUTS][4];   // FIXME: Private
 
 	private:
 		void analyzeInput();