Fix overwriting clip flags with varyings.

Previously the 12'th generic varying's w component would overwrite the
clipFlags member field.

Change-Id: I499979a2bbc653c0d95b35512a7a9e36667c2e4d
Reviewed-on: https://swiftshader-review.googlesource.com/5382
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/Renderer/Vertex.hpp b/src/Renderer/Vertex.hpp
index bc38da6..5c9e504 100644
--- a/src/Renderer/Vertex.hpp
+++ b/src/Renderer/Vertex.hpp
@@ -58,21 +58,11 @@
 		{
 			struct   // Fixed semantics
 			{
-				union   // Position
-				{
-					struct
-					{
-						float x;
-						float y;
-						float z;
-						float w;
-					};
-
-					struct
-					{
-						float4 P;
-					};
-				};
+				// Position
+				float x;
+				float y;
+				float z;
+				float w;
 
 				float4 C[2];   // Diffuse and specular color
 
@@ -80,21 +70,19 @@
 
 				float f;             // Fog
 				float pSize;         // Point size
-				unsigned char padding0[4];
-				unsigned char clipFlags;
-				unsigned char padding1[3];
 			};
 
 			float4 v[12];   // Generic components using semantic declaration
 		};
 
-		struct   // Projected coordinates
-		{
-			int X;
-			int Y;
-			float Z;
-			float W;
-		};
+		// Projected coordinates
+		int X;
+		int Y;
+		float Z;
+		float W;
+
+		int clipFlags;
+		int padding[3];
 	});
 
 	META_ASSERT((sizeof(Vertex) & 0x0000000F) == 0);
diff --git a/src/Shader/VertexRoutine.cpp b/src/Shader/VertexRoutine.cpp
index 626f710..0eced49 100644
--- a/src/Shader/VertexRoutine.cpp
+++ b/src/Shader/VertexRoutine.cpp
@@ -639,7 +639,7 @@
 			}
 		}
 
-		*Pointer<Int>(cacheLine + OFFSET(Vertex,clipFlags) + sizeof(Vertex) * 0) = (clipFlags >> 0)  & 0x0000000FF;   // FIXME: unsigned char Vertex::clipFlags
+		*Pointer<Int>(cacheLine + OFFSET(Vertex,clipFlags) + sizeof(Vertex) * 0) = (clipFlags >> 0)  & 0x0000000FF;
 		*Pointer<Int>(cacheLine + OFFSET(Vertex,clipFlags) + sizeof(Vertex) * 1) = (clipFlags >> 8)  & 0x0000000FF;
 		*Pointer<Int>(cacheLine + OFFSET(Vertex,clipFlags) + sizeof(Vertex) * 2) = (clipFlags >> 16) & 0x0000000FF;
 		*Pointer<Int>(cacheLine + OFFSET(Vertex,clipFlags) + sizeof(Vertex) * 3) = (clipFlags >> 24) & 0x0000000FF;
@@ -673,11 +673,11 @@
 		{
 			if(state.output[i].write)
 			{
-				*Pointer<Float4>(vertex + OFFSET(Vertex,v[i])) = *Pointer<Float4>(cache + OFFSET(Vertex,v[i]));
+				*Pointer<Int4>(vertex + OFFSET(Vertex,v[i]), 16) = *Pointer<Int4>(cache + OFFSET(Vertex,v[i]), 16);
 			}
 		}
 
+		*Pointer<Int4>(vertex + OFFSET(Vertex,X)) = *Pointer<Int4>(cache + OFFSET(Vertex,X));
 		*Pointer<Int>(vertex + OFFSET(Vertex,clipFlags)) = *Pointer<Int>(cache + OFFSET(Vertex,clipFlags));
-		*Pointer<Float4>(vertex + OFFSET(Vertex,X)) = *Pointer<Float4>(cache + OFFSET(Vertex,X));
 	}
 }