Work around a GCC miscompilation issue.

Bug 18470793

Change-Id: Idac85c738810db112e7af56f5e1635c2ac6d325c
Reviewed-on: https://swiftshader-review.googlesource.com/1841
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/PixelProcessor.hpp b/src/Renderer/PixelProcessor.hpp
index e6c9c24..d68d051 100644
--- a/src/Renderer/PixelProcessor.hpp
+++ b/src/Renderer/PixelProcessor.hpp
@@ -97,11 +97,12 @@
 				{

 					Interpolant color[2];

 					Interpolant texture[8];

-					Interpolant fog;

 				};

 

 				Interpolant interpolant[10];

 			};

+

+			Interpolant fog;

 		};

 

 		struct State : States

diff --git a/src/Renderer/Primitive.hpp b/src/Renderer/Primitive.hpp
index 07621ab..ac37814 100644
--- a/src/Renderer/Primitive.hpp
+++ b/src/Renderer/Primitive.hpp
@@ -48,12 +48,13 @@
 			{

 				PlaneEquation C[2][4];

 				PlaneEquation T[8][4];

-				PlaneEquation f;

 			};

 

 			PlaneEquation V[10][4];

 		};

 

+		PlaneEquation f;

+

 		float area;

 

 		// Masks for two-sided stencil

diff --git a/src/Renderer/QuadRasterizer.cpp b/src/Renderer/QuadRasterizer.cpp
index d15c895..f189bd3 100644
--- a/src/Renderer/QuadRasterizer.cpp
+++ b/src/Renderer/QuadRasterizer.cpp
@@ -250,11 +250,9 @@
 					r.Dw = *Pointer<Float4>(r.primitive + OFFSET(Primitive,w.C), 16) + yyyy * *Pointer<Float4>(r.primitive + OFFSET(Primitive,w.B), 16);
 				}
 
-				for(int interpolant = 0; interpolant < 11; interpolant++)
+				for(int interpolant = 0; interpolant < 10; interpolant++)
 				{
-					int componentCount = interpolant < 10 ? 4 : 1;   // Fog only has one component
-
-					for(int component = 0; component < componentCount; component++)
+					for(int component = 0; component < 4; component++)
 					{
 						if(state.interpolant[interpolant].component & (1 << component))
 						{
@@ -268,6 +266,16 @@
 					}
 				}
 
+				if(state.fog.component)
+				{
+					r.Df = *Pointer<Float4>(r.primitive + OFFSET(Primitive,f.C), 16);
+
+					if(!state.fog.flat)
+					{
+						r.Df += yyyy * *Pointer<Float4>(r.primitive + OFFSET(Primitive,f.B), 16);
+					}
+				}
+
 				Short4 xLeft[4];
 				Short4 xRight[4];
 
diff --git a/src/Renderer/SetupProcessor.cpp b/src/Renderer/SetupProcessor.cpp
index b673dd7..03d3485 100644
--- a/src/Renderer/SetupProcessor.cpp
+++ b/src/Renderer/SetupProcessor.cpp
@@ -100,18 +100,20 @@
 			state.pointSizeRegister = Pts;
 		}
 
-		for(int interpolant = 0; interpolant < 11; interpolant++)
+		for(int interpolant = 0; interpolant < 10; interpolant++)
 		{
-			int componentCount = interpolant < 10 ? 4 : 1;   // Fog only has one component
-
-			for(int component = 0; component < componentCount; component++)
+			for(int component = 0; component < 4; component++)
 			{
-				state.gradient[interpolant][component].attribute = 0x3F;
+				state.gradient[interpolant][component].attribute = Unused;
 				state.gradient[interpolant][component].flat = false;
 				state.gradient[interpolant][component].wrap = false;
 			}
 		}
 
+		state.fog.attribute = Unused;
+		state.fog.flat = false;
+		state.fog.wrap = false;
+
 		const bool point = context->isDrawPoint(true);
 		const bool sprite = context->pointSpriteActive();
 		const bool flatShading = (context->shadingMode == SHADING_FLAT) || point;
diff --git a/src/Renderer/SetupProcessor.hpp b/src/Renderer/SetupProcessor.hpp
index 8220686..0d2c81a 100644
--- a/src/Renderer/SetupProcessor.hpp
+++ b/src/Renderer/SetupProcessor.hpp
@@ -52,7 +52,7 @@
 

 			struct Gradient

 			{

-				unsigned char attribute : 6;

+				unsigned char attribute : BITS(Unused);

 				bool flat               : 1;

 				bool wrap               : 1;

 			};

@@ -63,11 +63,12 @@
 				{

 					Gradient color[2][4];

 					Gradient texture[8][4];

-					Gradient fog;

 				};

 

 				Gradient gradient[10][4];

 			};

+

+			Gradient fog;

 		};

 

 		struct State : States

diff --git a/src/Renderer/Vertex.hpp b/src/Renderer/Vertex.hpp
index c34e276..129d258 100644
--- a/src/Renderer/Vertex.hpp
+++ b/src/Renderer/Vertex.hpp
@@ -18,11 +18,11 @@
 

 namespace sw

 {

-	enum Out   // Default vertex attribute semantic

+	enum Out   // Default vertex output semantic

 	{

 		Pos = 0,

-		D0 = 1,

-		D1 = 2,

+		D0 = 1,   // Diffuse

+		D1 = 2,   // Specular

 		T0 = 3,

 		T1 = 4,

 		T2 = 5,

@@ -31,8 +31,9 @@
 		T5 = 8,

 		T6 = 9,

 		T7 = 10,

-		Fog = 11,   // x component

-		Pts = Fog   // y component

+		Fog = 11,    // x component

+		Pts = Fog,   // y component

+		Unused

 	};

 

 	struct UVWQ

diff --git a/src/Shader/PixelRoutine.cpp b/src/Shader/PixelRoutine.cpp
index c866fb7..06eb37f 100644
--- a/src/Shader/PixelRoutine.cpp
+++ b/src/Shader/PixelRoutine.cpp
@@ -127,7 +127,7 @@
 				Long interpTime = Ticks();
 			#endif
 
-			Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive, yQuad), 16);
+			Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,yQuad), 16);
 
 			// Centroid locations
 			Float4 XXXX = Float4(0.0f);
diff --git a/src/Shader/SetupRoutine.cpp b/src/Shader/SetupRoutine.cpp
index 84c33d5..fcb1284 100644
--- a/src/Shader/SetupRoutine.cpp
+++ b/src/Shader/SetupRoutine.cpp
@@ -451,23 +451,26 @@
 				*Pointer<Float4>(primitive + OFFSET(Primitive,z.C), 16) = C;
 			}
 
-			for(int interpolant = 0; interpolant < 11; interpolant++)
+			for(int interpolant = 0; interpolant < 10; interpolant++)
 			{
-				int componentCount = interpolant < 10 ? 4 : 1;   // Fog only has one component
-
-				for(int component = 0; component < componentCount; component++)
+				for(int component = 0; component < 4; component++)
 				{
 					int attribute = state.gradient[interpolant][component].attribute;
 					bool flat = state.gradient[interpolant][component].flat;
 					bool wrap = state.gradient[interpolant][component].wrap;
 
-					if(attribute < 12)
+					if(attribute != Unused)
 					{
 						setupGradient(primitive, tri, w012, M, v0, v1, v2, OFFSET(Vertex,v[attribute][component]), OFFSET(Primitive,V[interpolant][component]), flat, sprite, state.perspective, wrap, component);
 					}
 				}
 			}
 
+			if(state.fog.attribute == Fog)
+			{
+				setupGradient(primitive, tri, w012, M, v0, v1, v2, OFFSET(Vertex,f), OFFSET(Primitive,f), state.fog.flat, false, state.perspective, false, 0);
+			}
+
 			Return(true);
 		}