Commit 3e3d8fea by Nicolas Capens Committed by Nicolas Capens

Remove sw::Vector, Point, and Matrix

These are unused by the Vulkan implementation. We have sw::float4 instead for vector data type needs. Bug: b/146224130 Change-Id: Icbb01e3ea82b760ad60f99c10e65c38e825ef12d Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39688 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent ff3d55c6
......@@ -23,15 +23,12 @@ swiftshader_source_set("Device_headers") {
"Config.hpp",
"Context.hpp",
"ETC_Decoder.hpp",
"Matrix.hpp",
"Memset.hpp",
"PixelProcessor.hpp",
"Plane.hpp",
"Point.hpp",
"QuadRasterizer.hpp",
"Renderer.hpp",
"SetupProcessor.hpp",
"Vector.hpp",
"VertexProcessor.hpp",
]
}
......@@ -45,14 +42,11 @@ swiftshader_source_set("Device") {
"Config.cpp",
"Context.cpp",
"ETC_Decoder.cpp",
"Matrix.cpp",
"PixelProcessor.cpp",
"Plane.cpp",
"Point.cpp",
"QuadRasterizer.cpp",
"Renderer.cpp",
"SetupProcessor.cpp",
"Vector.cpp",
"VertexProcessor.cpp",
]
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef Matrix_hpp
#define Matrix_hpp
#include "System/Types.hpp"
namespace sw {
struct Vector;
struct Point;
struct Matrix
{
Matrix();
Matrix(const int i);
Matrix(const float m[16]);
Matrix(const float m[4][4]);
Matrix(float m11, float m12, float m13,
float m21, float m22, float m23,
float m31, float m32, float m33);
Matrix(float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44);
Matrix(const Vector &v1, const Vector &v2, const Vector &v3); // Column vectors
Matrix &operator=(const Matrix &N);
// Row major order
float m[4][4];
static Matrix diag(float m11, float m22, float m33, float m44);
operator float *();
Matrix operator+() const;
Matrix operator-() const;
Matrix operator!() const; // Inverse
Matrix operator~() const; // Transpose
Matrix &operator+=(const Matrix &N);
Matrix &operator-=(const Matrix &N);
Matrix &operator*=(float s);
Matrix &operator*=(const Matrix &N);
Matrix &operator/=(float s);
float *operator[](int i); // Access element [row][col], starting with [0][0]
const float *operator[](int i) const;
float &operator()(int i, int j); // Access element (row, col), starting with (1, 1)
const float &operator()(int i, int j) const;
friend bool operator==(const Matrix &M, const Matrix &N);
friend bool operator!=(const Matrix &M, const Matrix &N);
friend Matrix operator+(const Matrix &M, const Matrix &N);
friend Matrix operator-(const Matrix &M, const Matrix &N);
friend Matrix operator*(float s, const Matrix &M);
friend Matrix operator*(const Matrix &M, const Matrix &N);
friend Matrix operator/(const Matrix &M, float s);
float4 operator*(const float4 &v) const;
static float det(const Matrix &M);
static float det(float m11);
static float det(float m11, float m12,
float m21, float m22);
static float det(float m11, float m12, float m13,
float m21, float m22, float m23,
float m31, float m32, float m33);
static float det(float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44);
static float det(const Vector &v1, const Vector &v2, const Vector &v3);
static float det3(const Matrix &M);
static float tr(const Matrix &M);
Matrix &orthogonalise(); // Gram-Schmidt orthogonalisation of 3x3 submatrix
static Matrix eulerRotate(const Vector &v);
static Matrix eulerRotate(float x, float y, float z);
static Matrix translate(const Vector &v);
static Matrix translate(float x, float y, float z);
static Matrix scale(const Vector &v);
static Matrix scale(float x, float y, float z);
static Matrix lookAt(const Vector &v);
static Matrix lookAt(float x, float y, float z);
};
} // namespace sw
#include "Vector.hpp"
namespace sw {
inline Matrix::Matrix()
{
}
inline Matrix::Matrix(const int i)
{
const float s = (float)i;
Matrix &M = *this;
M(1, 1) = s;
M(1, 2) = 0;
M(1, 3) = 0;
M(1, 4) = 0;
M(2, 1) = 0;
M(2, 2) = s;
M(2, 3) = 0;
M(2, 4) = 0;
M(3, 1) = 0;
M(3, 2) = 0;
M(3, 3) = s;
M(3, 4) = 0;
M(4, 1) = 0;
M(4, 2) = 0;
M(4, 3) = 0;
M(4, 4) = s;
}
inline Matrix::Matrix(const float m[16])
{
Matrix &M = *this;
M(1, 1) = m[0];
M(1, 2) = m[1];
M(1, 3) = m[2];
M(1, 4) = m[3];
M(2, 1) = m[4];
M(2, 2) = m[5];
M(2, 3) = m[6];
M(2, 4) = m[7];
M(3, 1) = m[8];
M(3, 2) = m[8];
M(3, 3) = m[10];
M(3, 4) = m[11];
M(4, 1) = m[12];
M(4, 2) = m[13];
M(4, 3) = m[14];
M(4, 4) = m[15];
}
inline Matrix::Matrix(const float m[4][4])
{
Matrix &M = *this;
M[0][0] = m[0][0];
M[0][1] = m[0][1];
M[0][2] = m[0][2];
M[0][3] = m[0][3];
M[1][0] = m[1][0];
M[1][1] = m[1][1];
M[1][2] = m[1][2];
M[1][3] = m[1][3];
M[2][0] = m[2][0];
M[2][1] = m[2][1];
M[2][2] = m[2][2];
M[2][3] = m[2][3];
M[3][0] = m[3][0];
M[3][1] = m[3][1];
M[3][2] = m[3][2];
M[3][3] = m[3][3];
}
inline Matrix::Matrix(float m11, float m12, float m13,
float m21, float m22, float m23,
float m31, float m32, float m33)
{
Matrix &M = *this;
M(1, 1) = m11;
M(1, 2) = m12;
M(1, 3) = m13;
M(1, 4) = 0;
M(2, 1) = m21;
M(2, 2) = m22;
M(2, 3) = m23;
M(2, 4) = 0;
M(3, 1) = m31;
M(3, 2) = m32;
M(3, 3) = m33;
M(3, 4) = 0;
M(4, 1) = 0;
M(4, 2) = 0;
M(4, 3) = 0;
M(4, 4) = 1;
}
inline Matrix::Matrix(float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44)
{
Matrix &M = *this;
M(1, 1) = m11;
M(1, 2) = m12;
M(1, 3) = m13;
M(1, 4) = m14;
M(2, 1) = m21;
M(2, 2) = m22;
M(2, 3) = m23;
M(2, 4) = m24;
M(3, 1) = m31;
M(3, 2) = m32;
M(3, 3) = m33;
M(3, 4) = m34;
M(4, 1) = m41;
M(4, 2) = m42;
M(4, 3) = m43;
M(4, 4) = m44;
}
inline Matrix::Matrix(const Vector &v1, const Vector &v2, const Vector &v3)
{
Matrix &M = *this;
M(1, 1) = v1.x;
M(1, 2) = v2.x;
M(1, 3) = v3.x;
M(1, 4) = 0;
M(2, 1) = v1.y;
M(2, 2) = v2.y;
M(2, 3) = v3.y;
M(2, 4) = 0;
M(3, 1) = v1.z;
M(3, 2) = v2.z;
M(3, 3) = v3.z;
M(3, 4) = 0;
M(4, 1) = 0;
M(4, 2) = 0;
M(4, 3) = 0;
M(4, 4) = 1;
}
inline Matrix &Matrix::operator=(const Matrix &N)
{
Matrix &M = *this;
M(1, 1) = N(1, 1);
M(1, 2) = N(1, 2);
M(1, 3) = N(1, 3);
M(1, 4) = N(1, 4);
M(2, 1) = N(2, 1);
M(2, 2) = N(2, 2);
M(2, 3) = N(2, 3);
M(2, 4) = N(2, 4);
M(3, 1) = N(3, 1);
M(3, 2) = N(3, 2);
M(3, 3) = N(3, 3);
M(3, 4) = N(3, 4);
M(4, 1) = N(4, 1);
M(4, 2) = N(4, 2);
M(4, 3) = N(4, 3);
M(4, 4) = N(4, 4);
return M;
}
inline float *Matrix::operator[](int i)
{
return m[i];
}
inline const float *Matrix::operator[](int i) const
{
return m[i];
}
inline float &Matrix::operator()(int i, int j)
{
return m[i - 1][j - 1];
}
inline const float &Matrix::operator()(int i, int j) const
{
return m[i - 1][j - 1];
}
} // namespace sw
#endif // Matrix_hpp
......@@ -14,8 +14,6 @@
#include "Plane.hpp"
#include "Matrix.hpp"
namespace sw {
Plane::Plane()
......@@ -38,24 +36,4 @@ Plane::Plane(const float ABCD[4])
D = ABCD[3];
}
Plane operator*(const Plane &p, const Matrix &T)
{
Matrix M = !T;
return Plane(p.A * M(1, 1) + p.B * M(1, 2) + p.C * M(1, 3) + p.D * M(1, 4),
p.A * M(2, 1) + p.B * M(2, 2) + p.C * M(2, 3) + p.D * M(2, 4),
p.A * M(3, 1) + p.B * M(3, 2) + p.C * M(3, 3) + p.D * M(3, 4),
p.A * M(4, 1) + p.B * M(4, 2) + p.C * M(4, 3) + p.D * M(4, 4));
}
Plane operator*(const Matrix &T, const Plane &p)
{
Matrix M = !T;
return Plane(M(1, 1) * p.A + M(2, 1) * p.B + M(3, 1) * p.C + M(4, 1) * p.D,
M(1, 2) * p.A + M(2, 2) * p.B + M(3, 2) * p.C + M(4, 2) * p.D,
M(1, 3) * p.A + M(2, 3) * p.B + M(3, 3) * p.C + M(4, 3) * p.D,
M(1, 4) * p.A + M(2, 4) * p.B + M(3, 4) * p.C + M(4, 4) * p.D);
}
} // namespace sw
......@@ -15,8 +15,6 @@
#ifndef Plane_hpp
#define Plane_hpp
#include "Vector.hpp"
namespace sw {
struct Matrix;
......@@ -31,9 +29,6 @@ struct Plane
Plane();
Plane(float A, float B, float C, float D); // Plane equation
Plane(const float ABCD[4]);
friend Plane operator*(const Plane &p, const Matrix &A); // Transform plane by matrix (post-multiply)
friend Plane operator*(const Matrix &A, const Plane &p); // Transform plane by matrix (pre-multiply)
};
} // namespace sw
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Point.hpp"
#include "Matrix.hpp"
namespace sw {
Point &Point::operator+=(const Vector &v)
{
x += v.x;
y += v.y;
z += v.z;
return *this;
}
Point &Point::operator-=(const Vector &v)
{
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
Point operator+(const Point &P, const Vector &v)
{
return Point(P.x + v.x, P.y + v.y, P.z + v.z);
}
Point operator-(const Point &P, const Vector &v)
{
return Point(P.x - v.x, P.y - v.y, P.z - v.z);
}
Vector operator-(const Point &P, const Point &Q)
{
return Vector(P.x - Q.x, P.y - Q.y, P.z - Q.z);
}
Point operator*(const Matrix &M, const Point &P)
{
return Point(M(1, 1) * P.x + M(1, 2) * P.y + M(1, 3) * P.z + M(1, 4),
M(2, 1) * P.x + M(2, 2) * P.y + M(2, 3) * P.z + M(2, 4),
M(3, 1) * P.x + M(3, 2) * P.y + M(3, 3) * P.z + M(3, 4));
}
Point operator*(const Point &P, const Matrix &M)
{
return Point(P.x * M(1, 1) + P.y * M(2, 1) + P.z * M(3, 1),
P.x * M(1, 2) + P.y * M(2, 2) + P.z * M(3, 2),
P.x * M(1, 3) + P.y * M(2, 3) + P.z * M(3, 3));
}
Point &operator*=(Point &P, const Matrix &M)
{
return P = P * M;
}
float Point::d(const Point &P) const
{
return Vector::N(*this - P);
}
float Point::d2(const Point &P) const
{
return Vector::N2(*this - P);
}
float Point::d(const Point &P, const Point &Q)
{
return Vector::N(P - Q);
}
float Point::d2(const Point &P, const Point &Q)
{
return Vector::N2(P - Q);
}
} // namespace sw
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef Point_hpp
#define Point_hpp
namespace sw {
struct Vector;
struct Matrix;
struct Point
{
Point();
Point(const int i);
Point(const Point &P);
Point(const Vector &v);
Point(float Px, float Py, float Pz);
Point &operator=(const Point &P);
union
{
float p[3];
struct
{
float x;
float y;
float z;
};
};
float &operator[](int i);
float &operator()(int i);
const float &operator[](int i) const;
const float &operator()(int i) const;
Point &operator+=(const Vector &v);
Point &operator-=(const Vector &v);
friend Point operator+(const Point &P, const Vector &v);
friend Point operator-(const Point &P, const Vector &v);
friend Vector operator-(const Point &P, const Point &Q);
friend Point operator*(const Matrix &M, const Point &P);
friend Point operator*(const Point &P, const Matrix &M);
friend Point &operator*=(Point &P, const Matrix &M);
float d(const Point &P) const; // Distance between two points
float d2(const Point &P) const; // Squared distance between two points
static float d(const Point &P, const Point &Q); // Distance between two points
static float d2(const Point &P, const Point &Q); // Squared distance between two points
};
} // namespace sw
#include "Vector.hpp"
namespace sw {
inline Point::Point()
{
}
inline Point::Point(const int i)
{
const float s = (float)i;
x = s;
y = s;
z = s;
}
inline Point::Point(const Point &P)
{
x = P.x;
y = P.y;
z = P.z;
}
inline Point::Point(const Vector &v)
{
x = v.x;
y = v.y;
z = v.z;
}
inline Point::Point(float P_x, float P_y, float P_z)
{
x = P_x;
y = P_y;
z = P_z;
}
inline Point &Point::operator=(const Point &P)
{
x = P.x;
y = P.y;
z = P.z;
return *this;
}
inline float &Point::operator()(int i)
{
return p[i];
}
inline float &Point::operator[](int i)
{
return p[i];
}
inline const float &Point::operator()(int i) const
{
return p[i];
}
inline const float &Point::operator[](int i) const
{
return p[i];
}
} // namespace sw
#endif // Point_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Vector.hpp"
#include "Matrix.hpp"
#include "System/Math.hpp"
namespace sw {
Vector Vector::operator+() const
{
return *this;
}
Vector Vector::operator-() const
{
return Vector(-x, -y, -z);
}
Vector &Vector::operator+=(const Vector &v)
{
x += v.x;
y += v.y;
z += v.z;
return *this;
}
Vector &Vector::operator-=(const Vector &v)
{
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
Vector &Vector::operator*=(float s)
{
x *= s;
y *= s;
z *= s;
return *this;
}
Vector &Vector::operator/=(float s)
{
float r = 1.0f / s;
return *this *= r;
}
bool operator==(const Vector &U, const Vector &v)
{
if(U.x == v.x && U.y == v.y && U.z == v.z)
return true;
else
return false;
}
bool operator!=(const Vector &U, const Vector &v)
{
if(U.x != v.x || U.y != v.y || U.z != v.z)
return true;
else
return false;
}
bool operator>(const Vector &u, const Vector &v)
{
if((u ^ 2) > (v ^ 2))
return true;
else
return false;
}
bool operator<(const Vector &u, const Vector &v)
{
if((u ^ 2) < (v ^ 2))
return true;
else
return false;
}
Vector operator+(const Vector &u, const Vector &v)
{
return Vector(u.x + v.x, u.y + v.y, u.z + v.z);
}
Vector operator-(const Vector &u, const Vector &v)
{
return Vector(u.x - v.x, u.y - v.y, u.z - v.z);
}
float operator*(const Vector &u, const Vector &v)
{
return u.x * v.x + u.y * v.y + u.z * v.z;
}
Vector operator*(float s, const Vector &v)
{
return Vector(s * v.x, s * v.y, s * v.z);
}
Vector operator*(const Vector &v, float s)
{
return Vector(v.x * s, v.y * s, v.z * s);
}
Vector operator/(const Vector &v, float s)
{
float r = 1.0f / s;
return Vector(v.x * r, v.y * r, v.z * r);
}
float operator^(const Vector &u, const Vector &v)
{
return acos(u / Vector::N(u) * v / Vector::N(v));
}
Vector operator%(const Vector &u, const Vector &v)
{
return Vector(u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x);
}
Vector operator*(const Matrix &M, const Vector &v)
{
return Vector(M(1, 1) * v.x + M(1, 2) * v.y + M(1, 3) * v.z,
M(2, 1) * v.x + M(2, 2) * v.y + M(2, 3) * v.z,
M(3, 1) * v.x + M(3, 2) * v.y + M(3, 3) * v.z);
}
Vector operator*(const Vector &v, const Matrix &M)
{
return Vector(v.x * M(1, 1) + v.y * M(2, 1) + v.z * M(3, 1) + M(4, 1),
v.x * M(1, 2) + v.y * M(2, 2) + v.z * M(3, 2) + M(4, 2),
v.x * M(1, 3) + v.y * M(2, 3) + v.z * M(3, 3) + M(4, 3));
}
Vector &operator*=(Vector &v, const Matrix &M)
{
return v = v * M;
}
float Vector::N(const Vector &v)
{
return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
float Vector::N2(const Vector &v)
{
return v.x * v.x + v.y * v.y + v.z * v.z;
}
Vector lerp(const Vector &u, const Vector &v, float t)
{
return Vector(u.x + t * (v.x - u.x),
u.y + t * (v.y - u.y),
u.z + t * (v.z - u.z));
}
} // namespace sw
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef Vector_hpp
#define Vector_hpp
namespace sw {
struct Point;
struct Matrix;
struct Plane;
struct Vector
{
Vector();
Vector(const int i);
Vector(const Vector &v);
Vector(const Point &p);
Vector(float v_x, float v_y, float v_z);
Vector &operator=(const Vector &v);
union
{
float v[3];
struct
{
float x;
float y;
float z;
};
};
float &operator[](int i);
float &operator()(int i);
const float &operator[](int i) const;
const float &operator()(int i) const;
Vector operator+() const;
Vector operator-() const;
Vector &operator+=(const Vector &v);
Vector &operator-=(const Vector &v);
Vector &operator*=(float s);
Vector &operator/=(float s);
friend bool operator==(const Vector &u, const Vector &v);
friend bool operator!=(const Vector &u, const Vector &v);
friend Vector operator+(const Vector &u, const Vector &v);
friend Vector operator-(const Vector &u, const Vector &v);
friend float operator*(const Vector &u, const Vector &v); // Dot product
friend Vector operator*(float s, const Vector &v);
friend Vector operator*(const Vector &v, float s);
friend Vector operator/(const Vector &v, float s);
friend float operator^(const Vector &u, const Vector &v); // Angle between vectors
friend Vector operator%(const Vector &u, const Vector &v); // Cross product
friend Vector operator*(const Matrix &M, const Vector &v);
friend Vector operator*(const Vector &v, const Matrix &M);
friend Vector &operator*=(Vector &v, const Matrix &M);
static float N(const Vector &v); // Norm
static float N2(const Vector &v); // Squared norm
static Vector mirror(const Vector &v, const Plane &p);
static Vector reflect(const Vector &v, const Plane &p);
static Vector lerp(const Vector &u, const Vector &v, float t);
};
} // namespace sw
/* Inline implementation */
#include "Point.hpp"
namespace sw {
inline Vector::Vector()
{
}
inline Vector::Vector(const int i)
{
const float s = (float)i;
x = s;
y = s;
z = s;
}
inline Vector::Vector(const Vector &v)
{
x = v.x;
y = v.y;
z = v.z;
}
inline Vector::Vector(const Point &P)
{
x = P.x;
y = P.y;
z = P.z;
}
inline Vector::Vector(float v_x, float v_y, float v_z)
{
x = v_x;
y = v_y;
z = v_z;
}
inline Vector &Vector::operator=(const Vector &v)
{
x = v.x;
y = v.y;
z = v.z;
return *this;
}
inline float &Vector::operator()(int i)
{
return v[i];
}
inline float &Vector::operator[](int i)
{
return v[i];
}
inline const float &Vector::operator()(int i) const
{
return v[i];
}
inline const float &Vector::operator[](int i) const
{
return v[i];
}
} // namespace sw
#endif // Vector_hpp
......@@ -16,7 +16,6 @@
#define sw_VertexProcessor_hpp
#include "Context.hpp"
#include "Matrix.hpp"
#include "Memset.hpp"
#include "RoutineCache.hpp"
#include "Vertex.hpp"
......
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