Remove the Clipper member from the Renderer class

Clipper was essentially a static class used from an object.
Changed it to actually being fully static and removed the
Clipper member from the Renderer class.

Change-Id: I146a9966317cfa9f73e679c7b471873cdd030122
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/30951
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Device/Clipper.cpp b/src/Device/Clipper.cpp
index 0bd04ab..43fa72b 100644
--- a/src/Device/Clipper.cpp
+++ b/src/Device/Clipper.cpp
@@ -16,46 +16,23 @@
 
 #include "Polygon.hpp"
 #include "Renderer.hpp"
-#include "Vulkan/VkDebug.hpp"
 
-namespace sw
+namespace
 {
-	unsigned int Clipper::computeClipFlags(const float4 &v)
+	inline void clipEdge(sw::float4 &Vo, const sw::float4 &Vi, const sw::float4 &Vj, float di, float dj)
 	{
-		return ((v.x > v.w)     ? CLIP_RIGHT  : 0) |
-		       ((v.y > v.w)     ? CLIP_TOP    : 0) |
-		       ((v.z > v.w)     ? CLIP_FAR    : 0) |
-		       ((v.x < -v.w)    ? CLIP_LEFT   : 0) |
-		       ((v.y < -v.w)    ? CLIP_BOTTOM : 0) |
-		       ((v.z < 0)       ? CLIP_NEAR   : 0) |
-		       Clipper::CLIP_FINITE;   // FIXME: xyz finite
+		float D = 1.0f / (dj - di);
+
+		Vo.x = (dj * Vi.x - di * Vj.x) * D;
+		Vo.y = (dj * Vi.y - di * Vj.y) * D;
+		Vo.z = (dj * Vi.z - di * Vj.z) * D;
+		Vo.w = (dj * Vi.w - di * Vj.w) * D;
 	}
 
-	bool Clipper::clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw)
+	void clipNear(sw::Polygon &polygon)
 	{
-		if(clipFlagsOr & CLIP_FRUSTUM)
-		{
-			if(clipFlagsOr & CLIP_NEAR)   clipNear(polygon);
-			if(polygon.n >= 3) {
-			if(clipFlagsOr & CLIP_FAR)    clipFar(polygon);
-			if(polygon.n >= 3) {
-			if(clipFlagsOr & CLIP_LEFT)   clipLeft(polygon);
-			if(polygon.n >= 3) {
-			if(clipFlagsOr & CLIP_RIGHT)  clipRight(polygon);
-			if(polygon.n >= 3) {
-			if(clipFlagsOr & CLIP_TOP)    clipTop(polygon);
-			if(polygon.n >= 3) {
-			if(clipFlagsOr & CLIP_BOTTOM) clipBottom(polygon);
-			}}}}}
-		}
-
-		return polygon.n >= 3;
-	}
-
-	void Clipper::clipNear(Polygon &polygon)
-	{
-		const float4 **V = polygon.P[polygon.i];
-		const float4 **T = polygon.P[polygon.i + 1];
+		const sw::float4 **V = polygon.P[polygon.i];
+		const sw::float4 **T = polygon.P[polygon.i + 1];
 
 		int t = 0;
 
@@ -90,10 +67,10 @@
 		polygon.i += 1;
 	}
 
-	void Clipper::clipFar(Polygon &polygon)
+	void clipFar(sw::Polygon &polygon)
 	{
-		const float4 **V = polygon.P[polygon.i];
-		const float4 **T = polygon.P[polygon.i + 1];
+		const sw::float4 **V = polygon.P[polygon.i];
+		const sw::float4 **T = polygon.P[polygon.i + 1];
 
 		int t = 0;
 
@@ -128,10 +105,10 @@
 		polygon.i += 1;
 	}
 
-	void Clipper::clipLeft(Polygon &polygon)
+	void clipLeft(sw::Polygon &polygon)
 	{
-		const float4 **V = polygon.P[polygon.i];
-		const float4 **T = polygon.P[polygon.i + 1];
+		const sw::float4 **V = polygon.P[polygon.i];
+		const sw::float4 **T = polygon.P[polygon.i + 1];
 
 		int t = 0;
 
@@ -166,10 +143,10 @@
 		polygon.i += 1;
 	}
 
-	void Clipper::clipRight(Polygon &polygon)
+	void clipRight(sw::Polygon &polygon)
 	{
-		const float4 **V = polygon.P[polygon.i];
-		const float4 **T = polygon.P[polygon.i + 1];
+		const sw::float4 **V = polygon.P[polygon.i];
+		const sw::float4 **T = polygon.P[polygon.i + 1];
 
 		int t = 0;
 
@@ -204,10 +181,10 @@
 		polygon.i += 1;
 	}
 
-	void Clipper::clipTop(Polygon &polygon)
+	void clipTop(sw::Polygon &polygon)
 	{
-		const float4 **V = polygon.P[polygon.i];
-		const float4 **T = polygon.P[polygon.i + 1];
+		const sw::float4 **V = polygon.P[polygon.i];
+		const sw::float4 **T = polygon.P[polygon.i + 1];
 
 		int t = 0;
 
@@ -242,10 +219,10 @@
 		polygon.i += 1;
 	}
 
-	void Clipper::clipBottom(Polygon &polygon)
+	void clipBottom(sw::Polygon &polygon)
 	{
-		const float4 **V = polygon.P[polygon.i];
-		const float4 **T = polygon.P[polygon.i + 1];
+		const sw::float4 **V = polygon.P[polygon.i];
+		const sw::float4 **T = polygon.P[polygon.i + 1];
 
 		int t = 0;
 
@@ -279,14 +256,39 @@
 		polygon.n = t;
 		polygon.i += 1;
 	}
+}
 
-	inline void Clipper::clipEdge(float4 &Vo, const float4 &Vi, const float4 &Vj, float di, float dj) const
+namespace sw
+{
+	unsigned int Clipper::ComputeClipFlags(const float4 &v)
 	{
-		float D = 1.0f / (dj - di);
+		return ((v.x > v.w)     ? CLIP_RIGHT  : 0) |
+		       ((v.y > v.w)     ? CLIP_TOP    : 0) |
+		       ((v.z > v.w)     ? CLIP_FAR    : 0) |
+		       ((v.x < -v.w)    ? CLIP_LEFT   : 0) |
+		       ((v.y < -v.w)    ? CLIP_BOTTOM : 0) |
+		       ((v.z < 0)       ? CLIP_NEAR   : 0) |
+		       Clipper::CLIP_FINITE;   // FIXME: xyz finite
+	}
 
-		Vo.x = (dj * Vi.x - di * Vj.x) * D;
-		Vo.y = (dj * Vi.y - di * Vj.y) * D;
-		Vo.z = (dj * Vi.z - di * Vj.z) * D;
-		Vo.w = (dj * Vi.w - di * Vj.w) * D;
+	bool Clipper::Clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw)
+	{
+		if(clipFlagsOr & CLIP_FRUSTUM)
+		{
+			if(clipFlagsOr & CLIP_NEAR)   clipNear(polygon);
+			if(polygon.n >= 3) {
+			if(clipFlagsOr & CLIP_FAR)    clipFar(polygon);
+			if(polygon.n >= 3) {
+			if(clipFlagsOr & CLIP_LEFT)   clipLeft(polygon);
+			if(polygon.n >= 3) {
+			if(clipFlagsOr & CLIP_RIGHT)  clipRight(polygon);
+			if(polygon.n >= 3) {
+			if(clipFlagsOr & CLIP_TOP)    clipTop(polygon);
+			if(polygon.n >= 3) {
+			if(clipFlagsOr & CLIP_BOTTOM) clipBottom(polygon);
+			}}}}}
+		}
+
+		return polygon.n >= 3;
 	}
 }
diff --git a/src/Device/Clipper.hpp b/src/Device/Clipper.hpp
index 4eaf940..0d111fd 100644
--- a/src/Device/Clipper.hpp
+++ b/src/Device/Clipper.hpp
@@ -15,18 +15,14 @@
 #ifndef sw_Clipper_hpp
 #define sw_Clipper_hpp
 
-#include "Plane.hpp"
-#include "System/Types.hpp"
-
 namespace sw
 {
-	struct Polygon;
 	struct DrawCall;
-	struct DrawData;
+	struct Polygon;
+	struct float4;
 
-	class Clipper
+	struct Clipper
 	{
-	public:
 		enum ClipFlags
 		{
 			// Indicates the vertex is outside the respective frustum plane
@@ -42,18 +38,8 @@
 			CLIP_FINITE = 1 << 7,   // All position coordinates are finite
 		};
 
-		unsigned int computeClipFlags(const float4 &v);
-		bool clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw);
-
-	private:
-		void clipNear(Polygon &polygon);
-		void clipFar(Polygon &polygon);
-		void clipLeft(Polygon &polygon);
-		void clipRight(Polygon &polygon);
-		void clipTop(Polygon &polygon);
-		void clipBottom(Polygon &polygon);
-
-		void clipEdge(float4 &Vo, const float4 &Vi, const float4 &Vj, float di, float dj) const;
+		static unsigned int ComputeClipFlags(const float4 &v);
+		static bool Clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw);
 	};
 }
 
diff --git a/src/Device/Renderer.cpp b/src/Device/Renderer.cpp
index 3a5a02f..712f748 100644
--- a/src/Device/Renderer.cpp
+++ b/src/Device/Renderer.cpp
@@ -203,8 +203,6 @@
 	{
 		setGlobalRenderingSettings(conventions, exactColorRounding);
 
-		clipper = new Clipper;
-
 		#if PERF_HUD
 			resetTimers();
 		#endif
@@ -264,9 +262,6 @@
 		terminateThreads();
 		sync->unlock();
 
-		delete clipper;
-		clipper = nullptr;
-
 		delete resumeApp;
 		resumeApp = nullptr;
 
@@ -996,7 +991,7 @@
 
 				if(clipFlagsOr != Clipper::CLIP_FINITE)
 				{
-					if(!clipper->clip(polygon, clipFlagsOr, draw))
+					if(!Clipper::Clip(polygon, clipFlagsOr, draw))
 					{
 						continue;
 					}
@@ -1116,19 +1111,19 @@
 
 			P[0].x += -dy0w;
 			P[0].y += +dx0h;
-			C[0] = clipper->computeClipFlags(P[0]);
+			C[0] = Clipper::ComputeClipFlags(P[0]);
 
 			P[1].x += -dy1w;
 			P[1].y += +dx1h;
-			C[1] = clipper->computeClipFlags(P[1]);
+			C[1] = Clipper::ComputeClipFlags(P[1]);
 
 			P[2].x += +dy1w;
 			P[2].y += -dx1h;
-			C[2] = clipper->computeClipFlags(P[2]);
+			C[2] = Clipper::ComputeClipFlags(P[2]);
 
 			P[3].x += +dy0w;
 			P[3].y += -dx0h;
-			C[3] = clipper->computeClipFlags(P[3]);
+			C[3] = Clipper::ComputeClipFlags(P[3]);
 
 			if((C[0] & C[1] & C[2] & C[3]) == Clipper::CLIP_FINITE)
 			{
@@ -1138,7 +1133,7 @@
 
 				if(clipFlagsOr != Clipper::CLIP_FINITE)
 				{
-					if(!clipper->clip(polygon, clipFlagsOr, draw))
+					if(!Clipper::Clip(polygon, clipFlagsOr, draw))
 					{
 						return false;
 					}
@@ -1168,28 +1163,28 @@
 			float dy1 = lineWidth * 0.5f * P1.w / H;
 
 			P[0].x += -dx0;
-			C[0] = clipper->computeClipFlags(P[0]);
+			C[0] = Clipper::ComputeClipFlags(P[0]);
 
 			P[1].y += +dy0;
-			C[1] = clipper->computeClipFlags(P[1]);
+			C[1] = Clipper::ComputeClipFlags(P[1]);
 
 			P[2].x += +dx0;
-			C[2] = clipper->computeClipFlags(P[2]);
+			C[2] = Clipper::ComputeClipFlags(P[2]);
 
 			P[3].y += -dy0;
-			C[3] = clipper->computeClipFlags(P[3]);
+			C[3] = Clipper::ComputeClipFlags(P[3]);
 
 			P[4].x += -dx1;
-			C[4] = clipper->computeClipFlags(P[4]);
+			C[4] = Clipper::ComputeClipFlags(P[4]);
 
 			P[5].y += +dy1;
-			C[5] = clipper->computeClipFlags(P[5]);
+			C[5] = Clipper::ComputeClipFlags(P[5]);
 
 			P[6].x += +dx1;
-			C[6] = clipper->computeClipFlags(P[6]);
+			C[6] = Clipper::ComputeClipFlags(P[6]);
 
 			P[7].y += -dy1;
-			C[7] = clipper->computeClipFlags(P[7]);
+			C[7] = Clipper::ComputeClipFlags(P[7]);
 
 			if((C[0] & C[1] & C[2] & C[3] & C[4] & C[5] & C[6] & C[7]) == Clipper::CLIP_FINITE)
 			{
@@ -1244,7 +1239,7 @@
 
 				if(clipFlagsOr != Clipper::CLIP_FINITE)
 				{
-					if(!clipper->clip(polygon, clipFlagsOr, draw))
+					if(!Clipper::Clip(polygon, clipFlagsOr, draw))
 					{
 						return false;
 					}
@@ -1281,19 +1276,19 @@
 
 		P[0].x -= X;
 		P[0].y += Y;
-		C[0] = clipper->computeClipFlags(P[0]);
+		C[0] = Clipper::ComputeClipFlags(P[0]);
 
 		P[1].x += X;
 		P[1].y += Y;
-		C[1] = clipper->computeClipFlags(P[1]);
+		C[1] = Clipper::ComputeClipFlags(P[1]);
 
 		P[2].x += X;
 		P[2].y -= Y;
-		C[2] = clipper->computeClipFlags(P[2]);
+		C[2] = Clipper::ComputeClipFlags(P[2]);
 
 		P[3].x -= X;
 		P[3].y -= Y;
-		C[3] = clipper->computeClipFlags(P[3]);
+		C[3] = Clipper::ComputeClipFlags(P[3]);
 
 		triangle.v1 = triangle.v0;
 		triangle.v2 = triangle.v0;
@@ -1309,7 +1304,7 @@
 
 			if(clipFlagsOr != Clipper::CLIP_FINITE)
 			{
-				if(!clipper->clip(polygon, clipFlagsOr, draw))
+				if(!Clipper::Clip(polygon, clipFlagsOr, draw))
 				{
 					return false;
 				}
diff --git a/src/Device/Renderer.hpp b/src/Device/Renderer.hpp
index 2c8c3be..8b1a6e0 100644
--- a/src/Device/Renderer.hpp
+++ b/src/Device/Renderer.hpp
@@ -36,7 +36,6 @@
 
 namespace sw
 {
-	class Clipper;
 	struct DrawCall;
 	class PixelShader;
 	class VertexShader;
@@ -248,7 +247,6 @@
 		void initializeThreads();
 		void terminateThreads();
 
-		Clipper *clipper;
 		VkViewport viewport;
 		VkRect2D scissor;
 		int clipFlags;