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: Nicolas Capens <nicolascapens@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Device/BUILD.gn b/src/Device/BUILD.gn index e46869b..7a874d7 100644 --- a/src/Device/BUILD.gn +++ b/src/Device/BUILD.gn
@@ -23,15 +23,12 @@ "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 @@ "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", ]
diff --git a/src/Device/Matrix.cpp b/src/Device/Matrix.cpp deleted file mode 100644 index b45facf..0000000 --- a/src/Device/Matrix.cpp +++ /dev/null
@@ -1,445 +0,0 @@ -// 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 "Matrix.hpp" - -#include "Point.hpp" -#include "System/Math.hpp" - -namespace sw { - -Matrix Matrix::diag(float m11, float m22, float m33, float m44) -{ - return Matrix(m11, 0, 0, 0, - 0, m22, 0, 0, - 0, 0, m33, 0, - 0, 0, 0, m44); -} - -Matrix::operator float *() -{ - return &(*this)(1, 1); -} - -Matrix Matrix::operator+() const -{ - return *this; -} - -Matrix Matrix::operator-() const -{ - const Matrix &M = *this; - - return Matrix(-M(1, 1), -M(1, 2), -M(1, 3), -M(1, 4), - -M(2, 1), -M(2, 2), -M(2, 3), -M(2, 4), - -M(3, 1), -M(3, 2), -M(3, 3), -M(3, 4), - -M(4, 1), -M(4, 2), -M(4, 3), -M(4, 4)); -} - -Matrix Matrix::operator!() const -{ - const Matrix &M = *this; - Matrix I; - - float M3344 = M(3, 3) * M(4, 4) - M(4, 3) * M(3, 4); - float M2344 = M(2, 3) * M(4, 4) - M(4, 3) * M(2, 4); - float M2334 = M(2, 3) * M(3, 4) - M(3, 3) * M(2, 4); - float M3244 = M(3, 2) * M(4, 4) - M(4, 2) * M(3, 4); - float M2244 = M(2, 2) * M(4, 4) - M(4, 2) * M(2, 4); - float M2234 = M(2, 2) * M(3, 4) - M(3, 2) * M(2, 4); - float M3243 = M(3, 2) * M(4, 3) - M(4, 2) * M(3, 3); - float M2243 = M(2, 2) * M(4, 3) - M(4, 2) * M(2, 3); - float M2233 = M(2, 2) * M(3, 3) - M(3, 2) * M(2, 3); - float M1344 = M(1, 3) * M(4, 4) - M(4, 3) * M(1, 4); - float M1334 = M(1, 3) * M(3, 4) - M(3, 3) * M(1, 4); - float M1244 = M(1, 2) * M(4, 4) - M(4, 2) * M(1, 4); - float M1234 = M(1, 2) * M(3, 4) - M(3, 2) * M(1, 4); - float M1243 = M(1, 2) * M(4, 3) - M(4, 2) * M(1, 3); - float M1233 = M(1, 2) * M(3, 3) - M(3, 2) * M(1, 3); - float M1324 = M(1, 3) * M(2, 4) - M(2, 3) * M(1, 4); - float M1224 = M(1, 2) * M(2, 4) - M(2, 2) * M(1, 4); - float M1223 = M(1, 2) * M(2, 3) - M(2, 2) * M(1, 3); - - // Adjoint Matrix - I(1, 1) = M(2, 2) * M3344 - M(3, 2) * M2344 + M(4, 2) * M2334; - I(2, 1) = -M(2, 1) * M3344 + M(3, 1) * M2344 - M(4, 1) * M2334; - I(3, 1) = M(2, 1) * M3244 - M(3, 1) * M2244 + M(4, 1) * M2234; - I(4, 1) = -M(2, 1) * M3243 + M(3, 1) * M2243 - M(4, 1) * M2233; - - I(1, 2) = -M(1, 2) * M3344 + M(3, 2) * M1344 - M(4, 2) * M1334; - I(2, 2) = M(1, 1) * M3344 - M(3, 1) * M1344 + M(4, 1) * M1334; - I(3, 2) = -M(1, 1) * M3244 + M(3, 1) * M1244 - M(4, 1) * M1234; - I(4, 2) = M(1, 1) * M3243 - M(3, 1) * M1243 + M(4, 1) * M1233; - - I(1, 3) = M(1, 2) * M2344 - M(2, 2) * M1344 + M(4, 2) * M1324; - I(2, 3) = -M(1, 1) * M2344 + M(2, 1) * M1344 - M(4, 1) * M1324; - I(3, 3) = M(1, 1) * M2244 - M(2, 1) * M1244 + M(4, 1) * M1224; - I(4, 3) = -M(1, 1) * M2243 + M(2, 1) * M1243 - M(4, 1) * M1223; - - I(1, 4) = -M(1, 2) * M2334 + M(2, 2) * M1334 - M(3, 2) * M1324; - I(2, 4) = M(1, 1) * M2334 - M(2, 1) * M1334 + M(3, 1) * M1324; - I(3, 4) = -M(1, 1) * M2234 + M(2, 1) * M1234 - M(3, 1) * M1224; - I(4, 4) = M(1, 1) * M2233 - M(2, 1) * M1233 + M(3, 1) * M1223; - - // Division by determinant - I /= M(1, 1) * I(1, 1) + - M(2, 1) * I(1, 2) + - M(3, 1) * I(1, 3) + - M(4, 1) * I(1, 4); - - return I; -} - -Matrix Matrix::operator~() const -{ - const Matrix &M = *this; - - return Matrix(M(1, 1), M(2, 1), M(3, 1), M(4, 1), - M(1, 2), M(2, 2), M(3, 2), M(4, 2), - M(1, 3), M(2, 3), M(3, 3), M(4, 3), - M(1, 4), M(2, 4), M(3, 4), M(4, 4)); -} - -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; -} - -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; -} - -Matrix &Matrix::operator*=(float s) -{ - Matrix &M = *this; - - M(1, 1) *= s; - M(1, 2) *= s; - M(1, 3) *= s; - M(1, 4) *= s; - M(2, 1) *= s; - M(2, 2) *= s; - M(2, 3) *= s; - M(2, 4) *= s; - M(3, 1) *= s; - M(3, 2) *= s; - M(3, 3) *= s; - M(3, 4) *= s; - M(4, 1) *= s; - M(4, 2) *= s; - M(4, 3) *= s; - M(4, 4) *= s; - - return M; -} - -Matrix &Matrix::operator*=(const Matrix &M) -{ - return *this = *this * M; -} - -Matrix &Matrix::operator/=(float s) -{ - float r = 1.0f / s; - - return *this *= r; -} - -bool operator==(const Matrix &M, const Matrix &N) -{ - if(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 true; - else - return false; -} - -bool operator!=(const Matrix &M, const Matrix &N) -{ - if(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 true; - else - return false; -} - -Matrix operator+(const Matrix &M, const Matrix &N) -{ - return Matrix(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)); -} - -Matrix operator-(const Matrix &M, const Matrix &N) -{ - return Matrix(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)); -} - -Matrix operator*(float s, const Matrix &M) -{ - return Matrix(s * M(1, 1), s * M(1, 2), s * M(1, 3), s * M(1, 4), - s * M(2, 1), s * M(2, 2), s * M(2, 3), s * M(2, 4), - s * M(3, 1), s * M(3, 2), s * M(3, 3), s * M(3, 4), - s * M(4, 1), s * M(4, 2), s * M(4, 3), s * M(4, 4)); -} - -Matrix operator*(const Matrix &M, float s) -{ - return Matrix(M(1, 1) * s, M(1, 2) * s, M(1, 3) * s, M(1, 4) * s, - M(2, 1) * s, M(2, 2) * s, M(2, 3) * s, M(2, 4) * s, - M(3, 1) * s, M(3, 2) * s, M(3, 3) * s, M(3, 4) * s, - M(4, 1) * s, M(4, 2) * s, M(4, 3) * s, M(4, 4) * s); -} - -Matrix operator*(const Matrix &M, const Matrix &N) -{ - return Matrix(M(1, 1) * N(1, 1) + M(1, 2) * N(2, 1) + M(1, 3) * N(3, 1) + M(1, 4) * N(4, 1), M(1, 1) * N(1, 2) + M(1, 2) * N(2, 2) + M(1, 3) * N(3, 2) + M(1, 4) * N(4, 2), M(1, 1) * N(1, 3) + M(1, 2) * N(2, 3) + M(1, 3) * N(3, 3) + M(1, 4) * N(4, 3), M(1, 1) * N(1, 4) + M(1, 2) * N(2, 4) + M(1, 3) * N(3, 4) + M(1, 4) * N(4, 4), - M(2, 1) * N(1, 1) + M(2, 2) * N(2, 1) + M(2, 3) * N(3, 1) + M(2, 4) * N(4, 1), M(2, 1) * N(1, 2) + M(2, 2) * N(2, 2) + M(2, 3) * N(3, 2) + M(2, 4) * N(4, 2), M(2, 1) * N(1, 3) + M(2, 2) * N(2, 3) + M(2, 3) * N(3, 3) + M(2, 4) * N(4, 3), M(2, 1) * N(1, 4) + M(2, 2) * N(2, 4) + M(2, 3) * N(3, 4) + M(2, 4) * N(4, 4), - M(3, 1) * N(1, 1) + M(3, 2) * N(2, 1) + M(3, 3) * N(3, 1) + M(3, 4) * N(4, 1), M(3, 1) * N(1, 2) + M(3, 2) * N(2, 2) + M(3, 3) * N(3, 2) + M(3, 4) * N(4, 2), M(3, 1) * N(1, 3) + M(3, 2) * N(2, 3) + M(3, 3) * N(3, 3) + M(3, 4) * N(4, 3), M(3, 1) * N(1, 4) + M(3, 2) * N(2, 4) + M(3, 3) * N(3, 4) + M(3, 4) * N(4, 4), - M(4, 1) * N(1, 1) + M(4, 2) * N(2, 1) + M(4, 3) * N(3, 1) + M(4, 4) * N(4, 1), M(4, 1) * N(1, 2) + M(4, 2) * N(2, 2) + M(4, 3) * N(3, 2) + M(4, 4) * N(4, 2), M(4, 1) * N(1, 3) + M(4, 2) * N(2, 3) + M(4, 3) * N(3, 3) + M(4, 4) * N(4, 3), M(4, 1) * N(1, 4) + M(4, 2) * N(2, 4) + M(4, 3) * N(3, 4) + M(4, 4) * N(4, 4)); -} - -Matrix operator/(const Matrix &M, float s) -{ - float r = 1.0f / s; - - return M * r; -} - -float4 Matrix::operator*(const float4 &v) const -{ - const Matrix &M = *this; - float Mx = M(1, 1) * v.x + M(1, 2) * v.y + M(1, 3) * v.z + M(1, 4) * v.w; - float My = M(2, 1) * v.x + M(2, 2) * v.y + M(2, 3) * v.z + M(2, 4) * v.w; - float Mz = M(3, 1) * v.x + M(3, 2) * v.y + M(3, 3) * v.z + M(3, 4) * v.w; - float Mw = M(4, 1) * v.x + M(4, 2) * v.y + M(4, 3) * v.z + M(4, 4) * v.w; - - return { Mx, My, Mz, Mw }; -} - -float Matrix::det(const Matrix &M) -{ - float M3344 = M(3, 3) * M(4, 4) - M(4, 3) * M(3, 4); - float M2344 = M(2, 3) * M(4, 4) - M(4, 3) * M(2, 4); - float M2334 = M(2, 3) * M(3, 4) - M(3, 3) * M(2, 4); - float M1344 = M(1, 3) * M(4, 4) - M(4, 3) * M(1, 4); - float M1334 = M(1, 3) * M(3, 4) - M(3, 3) * M(1, 4); - float M1324 = M(1, 3) * M(2, 4) - M(2, 3) * M(1, 4); - - return M(1, 1) * (M(2, 2) * M3344 - M(3, 2) * M2344 + M(4, 2) * M2334) - - M(2, 1) * (M(1, 2) * M3344 - M(3, 2) * M1344 + M(4, 2) * M1334) + - M(3, 1) * (M(1, 2) * M2344 - M(2, 2) * M1344 + M(4, 2) * M1324) - - M(4, 1) * (M(1, 2) * M2334 - M(2, 2) * M1334 + M(3, 2) * M1324); -} - -float Matrix::det(float m11) -{ - return m11; -} - -float Matrix::det(float m11, float m12, - float m21, float m22) -{ - return m11 * m22 - m12 * m21; -} - -float Matrix::det(float m11, float m12, float m13, - float m21, float m22, float m23, - float m31, float m32, float m33) -{ - return m11 * (m22 * m33 - m32 * m23) - - m21 * (m12 * m33 - m32 * m13) + - m31 * (m12 * m23 - m22 * m13); -} - -float Matrix::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) -{ - float M3344 = m33 * m44 - m43 * m34; - float M2344 = m23 * m44 - m43 * m24; - float M2334 = m23 * m34 - m33 * m24; - float M1344 = m13 * m44 - m43 * m14; - float M1334 = m13 * m34 - m33 * m14; - float M1324 = m13 * m24 - m23 * m14; - - return m11 * (m22 * M3344 - m32 * M2344 + m42 * M2334) - - m21 * (m12 * M3344 - m32 * M1344 + m42 * M1334) + - m31 * (m12 * M2344 - m22 * M1344 + m42 * M1324) - - m41 * (m12 * M2334 - m22 * M1334 + m32 * M1324); -} - -float Matrix::det(const Vector &v1, const Vector &v2, const Vector &v3) -{ - return v1 * (v2 % v3); -} - -float Matrix::det3(const Matrix &M) -{ - return M(1, 1) * (M(2, 2) * M(3, 3) - M(3, 2) * M(2, 3)) - - M(2, 1) * (M(1, 2) * M(3, 3) - M(3, 2) * M(1, 3)) + - M(3, 1) * (M(1, 2) * M(2, 3) - M(2, 2) * M(1, 3)); -} - -float Matrix::tr(const Matrix &M) -{ - return M(1, 1) + M(2, 2) + M(3, 3) + M(4, 4); -} - -Matrix &Matrix::orthogonalise() -{ - // NOTE: Numnerically instable, won't return exact the same result when already orhtogonal - - Matrix &M = *this; - - Vector v1(M(1, 1), M(2, 1), M(3, 1)); - Vector v2(M(1, 2), M(2, 2), M(3, 2)); - Vector v3(M(1, 3), M(2, 3), M(3, 3)); - - v2 -= v1 * (v1 * v2) / (v1 * v1); - v3 -= v1 * (v1 * v3) / (v1 * v1); - v3 -= v2 * (v2 * v3) / (v2 * v2); - - v1 /= Vector::N(v1); - v2 /= Vector::N(v2); - v3 /= Vector::N(v3); - - M(1, 1) = v1.x; - M(1, 2) = v2.x; - M(1, 3) = v3.x; - M(2, 1) = v1.y; - M(2, 2) = v2.y; - M(2, 3) = v3.y; - M(3, 1) = v1.z; - M(3, 2) = v2.z; - M(3, 3) = v3.z; - - return *this; -} - -Matrix Matrix::eulerRotate(const Vector &v) -{ - float cz = cos(v.z); - float sz = sin(v.z); - float cx = cos(v.x); - float sx = sin(v.x); - float cy = cos(v.y); - float sy = sin(v.y); - - float sxsy = sx * sy; - float sxcy = sx * cy; - - return Matrix(cy * cz - sxsy * sz, -cy * sz - sxsy * cz, -sy * cx, - cx * sz, cx * cz, -sx, - sy * cz + sxcy * sz, -sy * sz + sxcy * cz, cy * cx); -} - -Matrix Matrix::eulerRotate(float x, float y, float z) -{ - return eulerRotate(Vector(x, y, z)); -} - -Matrix Matrix::translate(const Vector &v) -{ - return Matrix(1, 0, 0, v.x, - 0, 1, 0, v.y, - 0, 0, 1, v.z, - 0, 0, 0, 1); -} - -Matrix Matrix::translate(float x, float y, float z) -{ - return translate(Vector(x, y, z)); -} - -Matrix Matrix::scale(const Vector &v) -{ - return Matrix(v.x, 0, 0, - 0, v.y, 0, - 0, 0, v.z); -} - -Matrix Matrix::scale(float x, float y, float z) -{ - return scale(Vector(x, y, z)); -} - -Matrix Matrix::lookAt(const Vector &v) -{ - Vector y = v; - y /= Vector::N(y); - - Vector x = y % Vector(0, 0, 1); - x /= Vector::N(x); - - Vector z = x % y; - z /= Vector::N(z); - - return ~Matrix(x, y, z); -} - -Matrix Matrix::lookAt(float x, float y, float z) -{ - return translate(Vector(x, y, z)); -} - -} // namespace sw
diff --git a/src/Device/Matrix.hpp b/src/Device/Matrix.hpp deleted file mode 100644 index d5a525a..0000000 --- a/src/Device/Matrix.hpp +++ /dev/null
@@ -1,303 +0,0 @@ -// 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
diff --git a/src/Device/Plane.cpp b/src/Device/Plane.cpp index 8a89546..2bfe0ef 100644 --- a/src/Device/Plane.cpp +++ b/src/Device/Plane.cpp
@@ -14,8 +14,6 @@ #include "Plane.hpp" -#include "Matrix.hpp" - namespace sw { Plane::Plane() @@ -38,24 +36,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
diff --git a/src/Device/Plane.hpp b/src/Device/Plane.hpp index 13da81a..bddff33 100644 --- a/src/Device/Plane.hpp +++ b/src/Device/Plane.hpp
@@ -15,8 +15,6 @@ #ifndef Plane_hpp #define Plane_hpp -#include "Vector.hpp" - namespace sw { struct Matrix; @@ -31,9 +29,6 @@ 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
diff --git a/src/Device/Point.cpp b/src/Device/Point.cpp deleted file mode 100644 index a93616d..0000000 --- a/src/Device/Point.cpp +++ /dev/null
@@ -1,93 +0,0 @@ -// 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
diff --git a/src/Device/Point.hpp b/src/Device/Point.hpp deleted file mode 100644 index 318b5c4..0000000 --- a/src/Device/Point.hpp +++ /dev/null
@@ -1,141 +0,0 @@ -// 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
diff --git a/src/Device/Vector.cpp b/src/Device/Vector.cpp deleted file mode 100644 index 681efc3..0000000 --- a/src/Device/Vector.cpp +++ /dev/null
@@ -1,176 +0,0 @@ -// 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
diff --git a/src/Device/Vector.hpp b/src/Device/Vector.hpp deleted file mode 100644 index a398943..0000000 --- a/src/Device/Vector.hpp +++ /dev/null
@@ -1,157 +0,0 @@ -// 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
diff --git a/src/Device/VertexProcessor.hpp b/src/Device/VertexProcessor.hpp index d72fd10..77117d9 100644 --- a/src/Device/VertexProcessor.hpp +++ b/src/Device/VertexProcessor.hpp
@@ -16,7 +16,6 @@ #define sw_VertexProcessor_hpp #include "Context.hpp" -#include "Matrix.hpp" #include "Memset.hpp" #include "RoutineCache.hpp" #include "Vertex.hpp"