Commit 05953ef0 by Alexis Hetu Committed by Alexis Hétu

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/+/30951Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 2e4f6e84
......@@ -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
}
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);
}}}}}
}
float D = 1.0f / (dj - di);
return polygon.n >= 3;
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;
}
void Clipper::clipNear(Polygon &polygon)
void clipNear(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;
......@@ -90,10 +67,10 @@ namespace sw
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 @@ namespace sw
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 @@ namespace sw
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 @@ namespace sw
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 @@ namespace sw
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 @@ namespace sw
polygon.n = t;
polygon.i += 1;
}
}
namespace sw
{
unsigned int Clipper::ComputeClipFlags(const float4 &v)
{
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
}
inline void Clipper::clipEdge(float4 &Vo, const float4 &Vi, const float4 &Vj, float di, float dj) const
bool Clipper::Clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw)
{
float D = 1.0f / (dj - di);
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);
}}}}}
}
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;
return polygon.n >= 3;
}
}
......@@ -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 @@ namespace sw
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);
};
}
......
......@@ -203,8 +203,6 @@ namespace sw
{
setGlobalRenderingSettings(conventions, exactColorRounding);
clipper = new Clipper;
#if PERF_HUD
resetTimers();
#endif
......@@ -264,9 +262,6 @@ namespace sw
terminateThreads();
sync->unlock();
delete clipper;
clipper = nullptr;
delete resumeApp;
resumeApp = nullptr;
......@@ -996,7 +991,7 @@ namespace sw
if(clipFlagsOr != Clipper::CLIP_FINITE)
{
if(!clipper->clip(polygon, clipFlagsOr, draw))
if(!Clipper::Clip(polygon, clipFlagsOr, draw))
{
continue;
}
......@@ -1116,19 +1111,19 @@ namespace sw
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 @@ namespace sw
if(clipFlagsOr != Clipper::CLIP_FINITE)
{
if(!clipper->clip(polygon, clipFlagsOr, draw))
if(!Clipper::Clip(polygon, clipFlagsOr, draw))
{
return false;
}
......@@ -1168,28 +1163,28 @@ namespace sw
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 @@ namespace sw
if(clipFlagsOr != Clipper::CLIP_FINITE)
{
if(!clipper->clip(polygon, clipFlagsOr, draw))
if(!Clipper::Clip(polygon, clipFlagsOr, draw))
{
return false;
}
......@@ -1281,19 +1276,19 @@ namespace sw
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 @@ namespace sw
if(clipFlagsOr != Clipper::CLIP_FINITE)
{
if(!clipper->clip(polygon, clipFlagsOr, draw))
if(!Clipper::Clip(polygon, clipFlagsOr, draw))
{
return false;
}
......
......@@ -36,7 +36,6 @@ namespace vk
namespace sw
{
class Clipper;
struct DrawCall;
class PixelShader;
class VertexShader;
......@@ -248,7 +247,6 @@ namespace sw
void initializeThreads();
void terminateThreads();
Clipper *clipper;
VkViewport viewport;
VkRect2D scissor;
int clipFlags;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment