Make the number of fragment inputs configurable.

Change-Id: I2c618c03d00718951907e81fcd600155751aac89
Reviewed-on: https://swiftshader-review.googlesource.com/5385
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/D3D9/Capabilities.hpp b/src/D3D9/Capabilities.hpp
index 1421c80..02e5d86 100644
--- a/src/D3D9/Capabilities.hpp
+++ b/src/D3D9/Capabilities.hpp
@@ -474,17 +474,20 @@
 		MAX_VERTEX_SHADER_CONST = 256,
 		MAX_PIXEL_SHADER_CONST = 224,
 		MAX_VERTEX_OUTPUTS = 12,
+		MAX_PIXEL_INPUTS = 10,
 	};
 
 	// Shader Model 3.0 requirements
 	META_ASSERT(MAX_VERTEX_SHADER_CONST >= 256);
 	META_ASSERT(MAX_PIXEL_SHADER_CONST == 224);
 	META_ASSERT(MAX_VERTEX_OUTPUTS == 12);
+	META_ASSERT(MAX_PIXEL_INPUTS == 10);
 
 	// Back-end minimum requirements
 	META_ASSERT(sw::VERTEX_UNIFORM_VECTORS >= MAX_VERTEX_SHADER_CONST);
 	META_ASSERT(sw::FRAGMENT_UNIFORM_VECTORS >= MAX_PIXEL_SHADER_CONST);
 	META_ASSERT(sw::MAX_VERTEX_OUTPUTS >= MAX_VERTEX_OUTPUTS);
+	META_ASSERT(sw::MAX_FRAGMENT_INPUTS >= MAX_PIXEL_INPUTS);
 }
 
 #endif   // D3D9_Capabilities_hpp
diff --git a/src/Main/Config.hpp b/src/Main/Config.hpp
index 7411080..b0839b5 100644
--- a/src/Main/Config.hpp
+++ b/src/Main/Config.hpp
@@ -88,6 +88,7 @@
 		FRAGMENT_UNIFORM_VECTORS = 224,
 		VERTEX_UNIFORM_VECTORS = 256,
 		MAX_VERTEX_OUTPUTS = 12,
+		MAX_FRAGMENT_INPUTS = 10,
 		MAX_FRAGMENT_UNIFORM_BLOCKS = 12,
 		MAX_VERTEX_UNIFORM_BLOCKS = 12,
 		MAX_UNIFORM_BUFFER_BINDINGS = MAX_FRAGMENT_UNIFORM_BLOCKS + MAX_VERTEX_UNIFORM_BLOCKS,   // Limited to 127 by SourceParameter.bufferIndex in Shader.hpp
diff --git a/src/OpenGL/compiler/OutputASM.cpp b/src/OpenGL/compiler/OutputASM.cpp
index b427b26..43ba172 100644
--- a/src/OpenGL/compiler/OutputASM.cpp
+++ b/src/OpenGL/compiler/OutputASM.cpp
@@ -2760,7 +2760,7 @@
 
 			if(pixelShader)
 			{
-				if((var + registerCount) > sw::PixelShader::MAX_INPUT_VARYINGS)
+				if((var + registerCount) > sw::MAX_FRAGMENT_INPUTS)
 				{
 					mContext.error(varying->getLine(), "Varyings packing failed: Too many varyings", "fragment shader");
 					return 0;
diff --git a/src/Renderer/PixelProcessor.cpp b/src/Renderer/PixelProcessor.cpp
index 0c90cbc..d8f1be2 100644
--- a/src/Renderer/PixelProcessor.cpp
+++ b/src/Renderer/PixelProcessor.cpp
@@ -1072,7 +1072,7 @@
 		}
 		else
 		{
-			for(int interpolant = 0; interpolant < 10; interpolant++)
+			for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
 			{
 				for(int component = 0; component < 4; component++)
 				{
@@ -1082,8 +1082,8 @@
 
 						switch(context->pixelShader->semantic[interpolant][component].usage)
 						{
-						case Shader::USAGE_TEXCOORD:	flat = point && !sprite;	break;
-						case Shader::USAGE_COLOR:		flat = flatShading;			break;
+						case Shader::USAGE_TEXCOORD: flat = point && !sprite; break;
+						case Shader::USAGE_COLOR:    flat = flatShading;      break;
 						}
 
 						state.interpolant[interpolant].component |= 1 << component;
@@ -1099,7 +1099,7 @@
 
 		if(state.centroid)
 		{
-			for(int interpolant = 0; interpolant < 10; interpolant++)
+			for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
 			{
 				for(int component = 0; component < 4; component++)
 				{
diff --git a/src/Renderer/PixelProcessor.hpp b/src/Renderer/PixelProcessor.hpp
index 88fd654..bfa3476 100644
--- a/src/Renderer/PixelProcessor.hpp
+++ b/src/Renderer/PixelProcessor.hpp
@@ -102,12 +102,11 @@
 				{
 					Interpolant color[2];
 					Interpolant texture[8];
+					Interpolant fog;
 				};
 
-				Interpolant interpolant[10];
+				Interpolant interpolant[MAX_FRAGMENT_INPUTS];
 			};
-
-			Interpolant fog;
 		};
 
 		struct State : States
@@ -271,7 +270,7 @@
 
 		virtual void setFillMode(FillMode fillMode);
 		virtual void setShadingMode(ShadingMode shadingMode);
-	
+
 		virtual void setAlphaBlendEnable(bool alphaBlendEnable);
 		virtual void setSourceBlendFactor(BlendFactor sourceBlendFactor);
 		virtual void setDestBlendFactor(BlendFactor destBlendFactor);
diff --git a/src/Renderer/Primitive.hpp b/src/Renderer/Primitive.hpp
index 83e3a77..872281d 100644
--- a/src/Renderer/Primitive.hpp
+++ b/src/Renderer/Primitive.hpp
@@ -51,13 +51,12 @@
 			{
 				PlaneEquation C[2][4];
 				PlaneEquation T[8][4];
+				PlaneEquation f;
 			};
 
-			PlaneEquation V[10][4];
+			PlaneEquation V[MAX_FRAGMENT_INPUTS][4];
 		};
 
-		PlaneEquation f;
-
 		float area;
 
 		// Masks for two-sided stencil
diff --git a/src/Renderer/QuadRasterizer.cpp b/src/Renderer/QuadRasterizer.cpp
index 5bc500f..691d325 100644
--- a/src/Renderer/QuadRasterizer.cpp
+++ b/src/Renderer/QuadRasterizer.cpp
@@ -237,7 +237,7 @@
 					Dw = *Pointer<Float4>(primitive + OFFSET(Primitive,w.C), 16) + yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive,w.B), 16);
 				}
 
-				for(int interpolant = 0; interpolant < 10; interpolant++)
+				for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
 				{
 					for(int component = 0; component < 4; component++)
 					{
diff --git a/src/Renderer/QuadRasterizer.hpp b/src/Renderer/QuadRasterizer.hpp
index 51d578d..5616112 100644
--- a/src/Renderer/QuadRasterizer.hpp
+++ b/src/Renderer/QuadRasterizer.hpp
@@ -36,7 +36,7 @@
 
 		Float4 Dz[4];
 		Float4 Dw;
-		Float4 Dv[10][4];
+		Float4 Dv[MAX_FRAGMENT_INPUTS][4];
 		Float4 Df;
 
 		UInt occlusion;
diff --git a/src/Renderer/SetupProcessor.cpp b/src/Renderer/SetupProcessor.cpp
index 6dccc8d..9075719 100644
--- a/src/Renderer/SetupProcessor.cpp
+++ b/src/Renderer/SetupProcessor.cpp
@@ -104,7 +104,7 @@
 			state.pointSizeRegister = Pts;
 		}
 
-		for(int interpolant = 0; interpolant < 10; interpolant++)
+		for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
 		{
 			for(int component = 0; component < 4; component++)
 			{
@@ -124,7 +124,7 @@
 
 		if(context->vertexShader && context->pixelShader)
 		{
-			for(int interpolant = 0; interpolant < 10; interpolant++)
+			for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
 			{
 				for(int component = 0; component < 4; component++)
 				{
@@ -158,7 +158,7 @@
 		}
 		else if(context->preTransformed && context->pixelShader)
 		{
-			for(int interpolant = 0; interpolant < 10; interpolant++)
+			for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
 			{
 				for(int component = 0; component < 4; component++)
 				{
diff --git a/src/Renderer/SetupProcessor.hpp b/src/Renderer/SetupProcessor.hpp
index 2ef9fdf..2750d4c 100644
--- a/src/Renderer/SetupProcessor.hpp
+++ b/src/Renderer/SetupProcessor.hpp
@@ -67,12 +67,11 @@
 				{
 					Gradient color[2][4];
 					Gradient texture[8][4];
+					Gradient fog;
 				};
 
-				Gradient gradient[10][4];
+				Gradient gradient[MAX_FRAGMENT_INPUTS][4];
 			};
-
-			Gradient fog;
 		};
 
 		struct State : States
diff --git a/src/Shader/PixelRoutine.cpp b/src/Shader/PixelRoutine.cpp
index b28a428..d55b2ed 100644
--- a/src/Shader/PixelRoutine.cpp
+++ b/src/Shader/PixelRoutine.cpp
@@ -34,7 +34,7 @@
 	{
 		if(!shader || shader->getVersion() < 0x0200 || forceClearRegisters)
 		{
-			for(int i = 0; i < 10; i++)
+			for(int i = 0; i < MAX_FRAGMENT_INPUTS; i++)
 			{
 				v[i].x = Float4(0.0f);
 				v[i].y = Float4(0.0f);
@@ -151,7 +151,7 @@
 				}
 			}
 
-			for(int interpolant = 0; interpolant < 10; interpolant++)
+			for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
 			{
 				for(int component = 0; component < 4; component++)
 				{
diff --git a/src/Shader/PixelRoutine.hpp b/src/Shader/PixelRoutine.hpp
index 89fe7ff..ba692c3 100644
--- a/src/Shader/PixelRoutine.hpp
+++ b/src/Shader/PixelRoutine.hpp
@@ -34,7 +34,7 @@
 		Float4 w;    // Used as is
 		Float4 rhw;  // Reciprocal w
 
-		RegisterArray<10> v;   // Varying registers
+		RegisterArray<MAX_FRAGMENT_INPUTS> v;   // Varying registers
 
 		// Depth output
 		Float4 oDepth;
diff --git a/src/Shader/PixelShader.cpp b/src/Shader/PixelShader.cpp
index 8cdfaff..d321fce 100644
--- a/src/Shader/PixelShader.cpp
+++ b/src/Shader/PixelShader.cpp
@@ -223,7 +223,7 @@
 				}
 			}
 
-			bool interpolant[MAX_INPUT_VARYINGS][4] = {{false}};   // Interpolants in use
+			bool interpolant[MAX_FRAGMENT_INPUTS][4] = {{false}};   // Interpolants in use
 
 			for(unsigned int i = 0; i < instruction.size(); i++)
 			{
@@ -655,7 +655,7 @@
 				}
 			}
 
-			for(int index = 0; index < MAX_INPUT_VARYINGS; index++)
+			for(int index = 0; index < MAX_FRAGMENT_INPUTS; index++)
 			{
 				for(int component = 0; component < 4; component++)
 				{
diff --git a/src/Shader/PixelShader.hpp b/src/Shader/PixelShader.hpp
index cb568a8..2fbde6b 100644
--- a/src/Shader/PixelShader.hpp
+++ b/src/Shader/PixelShader.hpp
@@ -16,6 +16,7 @@
 #define sw_PixelShader_hpp
 
 #include "Shader.hpp"
+#include "Main/Config.hpp"
 
 namespace sw
 {
@@ -37,8 +38,7 @@
 
 		virtual void analyze();
 
-		enum {MAX_INPUT_VARYINGS = 10};
-		Semantic semantic[MAX_INPUT_VARYINGS][4];   // FIXME: Private
+		Semantic semantic[MAX_FRAGMENT_INPUTS][4];   // FIXME: Private
 
 		bool vPosDeclared;
 		bool vFaceDeclared;
diff --git a/src/Shader/SetupRoutine.cpp b/src/Shader/SetupRoutine.cpp
index 630fbf4..ab7176b 100644
--- a/src/Shader/SetupRoutine.cpp
+++ b/src/Shader/SetupRoutine.cpp
@@ -455,7 +455,7 @@
 				*Pointer<Float4>(primitive + OFFSET(Primitive,z.C), 16) = C;
 			}
 
-			for(int interpolant = 0; interpolant < 10; interpolant++)
+			for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
 			{
 				for(int component = 0; component < 4; component++)
 				{