Wire up FS input to the shader

Bug: b/124177079
Change-Id: I8dac28d2c55ce1c4eb9a815bfad56ba917be32c5
Reviewed-on: https://swiftshader-review.googlesource.com/c/24593
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Device/PixelProcessor.cpp b/src/Device/PixelProcessor.cpp
index 6579a75..fcbee9f 100644
--- a/src/Device/PixelProcessor.cpp
+++ b/src/Device/PixelProcessor.cpp
@@ -709,44 +709,6 @@
 
 		const bool point = context->isDrawPoint();
 
-		/* TODO: bring back interpolants by some mechanism */
-//		for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
-//		{
-//			for(int component = 0; component < 4; component++)
-//			{
-//				const Shader::Semantic &semantic = context->pixelShader->getInput(interpolant, component);
-//
-//				if(semantic.active())
-//				{
-//					bool flat = point;
-//
-//					switch(semantic.usage)
-//					{
-//					case Shader::USAGE_TEXCOORD: flat = false;                  break;
-//					case Shader::USAGE_COLOR:    flat = semantic.flat || point; break;
-//					}
-//
-//					state.interpolant[interpolant].component |= 1 << component;
-//
-//					if(flat)
-//					{
-//						state.interpolant[interpolant].flat |= 1 << component;
-//					}
-//				}
-//			}
-//		}
-//
-//		if(state.centroid)
-//		{
-//			for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
-//			{
-//				for(int component = 0; component < 4; component++)
-//				{
-//					state.interpolant[interpolant].centroid = context->pixelShader->getInput(interpolant, 0).centroid;
-//				}
-//			}
-//		}
-
 		state.hash = state.computeHash();
 
 		return state;
diff --git a/src/Device/PixelProcessor.hpp b/src/Device/PixelProcessor.hpp
index 7a92dc5..268e127 100644
--- a/src/Device/PixelProcessor.hpp
+++ b/src/Device/PixelProcessor.hpp
@@ -83,15 +83,6 @@
 			VkLogicOp logicalOperation : BITS(VK_LOGIC_OP_END_RANGE);
 
 			Sampler::State sampler[TEXTURE_IMAGE_UNITS];
-
-			struct Interpolant
-			{
-				unsigned char component : 4;
-				unsigned char flat : 4;
-				bool centroid : 1;
-			};
-
-			Interpolant interpolant[MAX_FRAGMENT_INPUTS];
 		};
 
 		struct State : States
diff --git a/src/Device/Primitive.hpp b/src/Device/Primitive.hpp
index a6aaa43..1e085f7 100644
--- a/src/Device/Primitive.hpp
+++ b/src/Device/Primitive.hpp
@@ -47,14 +47,7 @@
 
 		union
 		{
-			struct
-			{
-				PlaneEquation C[2][4];
-				PlaneEquation T[8][4];
-				PlaneEquation f;
-			};
-
-			PlaneEquation V[MAX_FRAGMENT_INPUTS][4];
+			PlaneEquation V[MAX_INTERFACE_COMPONENTS];
 		};
 
 		float area;
diff --git a/src/Device/QuadRasterizer.cpp b/src/Device/QuadRasterizer.cpp
index 770bf28..bfd87e1 100644
--- a/src/Device/QuadRasterizer.cpp
+++ b/src/Device/QuadRasterizer.cpp
@@ -238,19 +238,15 @@
 					Dw = *Pointer<Float4>(primitive + OFFSET(Primitive,w.C), 16) + yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive,w.B), 16);
 				}
 
-				for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
+				for (int interpolant = 0; interpolant < MAX_INTERFACE_COMPONENTS; interpolant++)
 				{
-					for(int component = 0; component < 4; component++)
-					{
-						if(state.interpolant[interpolant].component & (1 << component))
-						{
-							Dv[interpolant][component] = *Pointer<Float4>(primitive + OFFSET(Primitive,V[interpolant][component].C), 16);
+					if (spirvShader->inputs[interpolant].Type == SpirvShader::ATTRIBTYPE_UNUSED)
+						continue;
 
-							if(!(state.interpolant[interpolant].flat & (1 << component)))
-							{
-								Dv[interpolant][component] += yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive,V[interpolant][component].B), 16);
-							}
-						}
+					Dv[interpolant] = *Pointer<Float4>(primitive + OFFSET(Primitive, V[interpolant].C), 16);
+					if (!spirvShader->inputs[interpolant].Flat)
+					{
+						Dv[interpolant] += yyyy * *Pointer<Float4>(primitive + OFFSET(Primitive, V[interpolant].B), 16);
 					}
 				}
 
diff --git a/src/Device/QuadRasterizer.hpp b/src/Device/QuadRasterizer.hpp
index b04deb9..456887d 100644
--- a/src/Device/QuadRasterizer.hpp
+++ b/src/Device/QuadRasterizer.hpp
@@ -35,7 +35,7 @@
 
 		Float4 Dz[4];
 		Float4 Dw;
-		Float4 Dv[MAX_FRAGMENT_INPUTS][4];
+		Float4 Dv[MAX_INTERFACE_COMPONENTS];
 		Float4 Df;
 
 		UInt occlusion;
diff --git a/src/Pipeline/PixelRoutine.cpp b/src/Pipeline/PixelRoutine.cpp
index 722bd33..9d9e445 100644
--- a/src/Pipeline/PixelRoutine.cpp
+++ b/src/Pipeline/PixelRoutine.cpp
@@ -30,20 +30,17 @@
 	extern bool forceClearRegisters;
 
 	PixelRoutine::PixelRoutine(const PixelProcessor::State &state, SpirvShader const *spirvShader)
-		: QuadRasterizer(state, spirvShader), v(true)	/* addressing */
+		: QuadRasterizer(state, spirvShader)	/* addressing */
 	{
-		if(forceClearRegisters)
+		spirvShader->emitEarly(&routine);
+
+		if (forceClearRegisters)
 		{
-			for(int i = 0; i < MAX_FRAGMENT_INPUTS; i++)
+			for (int i = 0; i < MAX_INTERFACE_COMPONENTS; i++)
 			{
-				v[i].x = Float4(0.0f);
-				v[i].y = Float4(0.0f);
-				v[i].z = Float4(0.0f);
-				v[i].w = Float4(0.0f);
+				(*routine.inputs)[i] = Float4(0.0f);
 			}
 		}
-
-		spirvShader->emitEarly(&routine);
 	}
 
 	PixelRoutine::~PixelRoutine()
@@ -144,21 +141,24 @@
 				}
 			}
 
-			// TODO: rethink what we want to do here for pull-mode interpolation
-			for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
+			for (int interpolant = 0; interpolant < MAX_INTERFACE_COMPONENTS; interpolant++)
 			{
-				for(int component = 0; component < 4; component++)
+				auto const & input = spirvShader->inputs[interpolant];
+				if (input.Type != SpirvShader::ATTRIBTYPE_UNUSED)
 				{
-					if(state.interpolant[interpolant].component & (1 << component))
+					if (input.Centroid)
 					{
-						if(!state.interpolant[interpolant].centroid)
-						{
-							v[interpolant][component] = interpolate(xxxx, Dv[interpolant][component], rhw, primitive + OFFSET(Primitive, V[interpolant][component]), (state.interpolant[interpolant].flat & (1 << component)) != 0, state.perspective, false);
-						}
-						else
-						{
-							v[interpolant][component] = interpolateCentroid(XXXX, YYYY, rhwCentroid, primitive + OFFSET(Primitive, V[interpolant][component]), (state.interpolant[interpolant].flat & (1 << component)) != 0, state.perspective);
-						}
+						(*routine.inputs)[interpolant] =
+								interpolateCentroid(XXXX, YYYY, rhwCentroid,
+													primitive + OFFSET(Primitive, V[interpolant]),
+													input.Flat, state.perspective);
+					}
+					else
+					{
+						(*routine.inputs)[interpolant] =
+								interpolate(xxxx, Dv[interpolant], rhw,
+											primitive + OFFSET(Primitive, V[interpolant]),
+											input.Flat, state.perspective, false);
 					}
 				}
 			}
diff --git a/src/Pipeline/PixelRoutine.hpp b/src/Pipeline/PixelRoutine.hpp
index 979f539..ed8cdb1 100644
--- a/src/Pipeline/PixelRoutine.hpp
+++ b/src/Pipeline/PixelRoutine.hpp
@@ -34,7 +34,6 @@
 		Float4 w;    // Used as is
 		Float4 rhw;  // Reciprocal w
 
-		RegisterArray<MAX_FRAGMENT_INPUTS> v;   // Varying registers
 		SpirvRoutine routine;
 
 		// Depth output