Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
49f6264
[Core][Math] Remove SIMD variant for Vector2.
Mcgode Apr 11, 2026
b4c35d7
[Core][Math] Remove SIMD variant for Vector3.
Mcgode Apr 11, 2026
e2943b2
[Core][Math] Start adding custom SIMD abstraction layer
Mcgode Apr 12, 2026
71d39dd
[Core][Math] Add ReduceSum utility functions to SIMD abstraction layer
Mcgode Apr 12, 2026
1d9f97c
[Core][Math] Extend SIMD abstraction with matrix support (3x4, 4x4)
Mcgode Apr 12, 2026
c955f64
[Core][Math] Add const qualifiers to CoordinateSystem functions for i…
Mcgode Apr 12, 2026
f9214ec
[Core][Math] Add VectorUtils for streamlined SIMD vector conversions …
Mcgode Apr 12, 2026
e992e0f
[Core][Math] Simplify Vector4Base by removing SIMD operations and rel…
Mcgode Apr 12, 2026
5b8302f
[Core][Math] Remove SIMD optimizations and `SimdOptimal` abstraction …
Mcgode Apr 12, 2026
4c4a883
[Core][Math] Remove redundant Matrix33_UnitTests for simplified test …
Mcgode Apr 12, 2026
5105c0c
[Core][Math] Add transposed matrix loading functions to SIMD abstraction
Mcgode Apr 12, 2026
4fc9745
[Core][Math] Add SIMD Multiply function for matrix-vector multiplication
Mcgode Apr 12, 2026
c4157cb
[Core][Math] Simplify SIMD transposition using `_MM_TRANSPOSE4_PS` di…
Mcgode Apr 12, 2026
bc99bbd
[Core][Math] Add SIMD-based matrix inversion and utility functions
Mcgode Apr 12, 2026
5843f44
[Core][Math] Refactor Matrix44Base to simplify SIMD alignment and row…
Mcgode Apr 12, 2026
6f6a410
[Core][Math] Expand Matrix44_UnitTests to cover all storage layouts a…
Mcgode Apr 12, 2026
5585230
[Core][Math] Fixed SIMD matrix multiplication
Mcgode Apr 12, 2026
f1db84b
[Core][Math] Fix Matrix-Vector multiplication
Mcgode Apr 13, 2026
1938812
[Core][Math] Add unit tests for Matrix44 vector multiplication with c…
Mcgode Apr 13, 2026
72b7019
[Core][Math] Fix incorrect transposition in Matrix44 type conversion
Mcgode Apr 13, 2026
607f3a9
[Core][Math] Optimize Matrix44 multiplication by transposing for bett…
Mcgode Apr 13, 2026
569e8a2
[Core][Math] Add NEON-based 4x4 SIMD matrix inversion
Mcgode Apr 13, 2026
49ec7e9
[Core][Math] Reinstate and validate matrix-vector multiplication unit…
Mcgode Apr 13, 2026
a2aa2bd
[Core][Math] Fixed SIMD compilation for SSE
Mcgode Apr 21, 2026
ed0ca9a
[Core][Math] Refactor SIMD handling to check runtime support
Mcgode Apr 21, 2026
265a840
[Core][Platform] Add runtime SIMD detection for platform-specific imp…
Mcgode Apr 21, 2026
fd474fd
[Core][Memory] Fixed compilation
Mcgode Apr 21, 2026
db88546
[Core][Platform] Fixed compilation
Mcgode Apr 21, 2026
9d9a268
[Core][Math] Fix compilation for RotationConversion unit tests
Mcgode Apr 21, 2026
796f66d
[Core][Platform] Add FMA support to runtime SIMD detection
Mcgode Apr 21, 2026
13afb8a
[Core][Math] Fixed Matrix44 function not returning a reference
Mcgode Apr 21, 2026
fd8ea89
[Core][Math] Update SIMD operations to use runtime support checks for…
Mcgode Apr 21, 2026
3aaae4e
Add natvis visualization for Vector4Base in KryneEngine
Mcgode Apr 21, 2026
1a24b60
[Core][Math] Adjust Matrix44 inverse test to account for floating-poi…
Mcgode Apr 21, 2026
de99adf
[Core][Math] Optimize SSE2 matrix operations by replacing _mm_shuffle…
Mcgode Apr 21, 2026
14e2a6b
[Core][Math] Fixed 2x2 matrix multiplication
Mcgode Apr 21, 2026
5076c4e
[CI/CD] Re-enable all Core tests in Vulkan workflow
Mcgode Apr 21, 2026
0524466
[Core][Math] Add platform-specific include guard for <corecrt_math_de…
Mcgode Apr 21, 2026
6a3878e
[Core][Math] Fixed `ToMatrix44` to improve type safety and simplify u…
Mcgode Apr 21, 2026
e927740
[Samples][RenderGraphDemo] Fixed compilation
Mcgode Apr 21, 2026
3b01a32
[Core][Math] Fix preprocessor directive for WIN32 detection in Rotati…
Mcgode Apr 21, 2026
92605a3
[Core][Graphics][Vulkan] Fix array declaration for validation layer n…
Mcgode Apr 21, 2026
222abb2
[Core][Memory] Move IAllocator constructor implementation to Allocato…
Mcgode Apr 21, 2026
75950ce
[Core][Math] Fix gcc compilation
Mcgode Apr 21, 2026
bc93117
[Core][Math] Fix gcc compilation
Mcgode Apr 21, 2026
ed0e854
[External][EASTL] Set up external lib proper
Mcgode Apr 23, 2026
b7060b1
[External] Fix Linux compilation
Mcgode Apr 23, 2026
ba64c10
[Core][Math] Add SIMD support for u8x16 operations, including load, b…
Mcgode Apr 23, 2026
531e3ae
[Core][Memory] Refactor FlatHashMap to improve SIMD handling and cont…
Mcgode Apr 23, 2026
c59153d
[External] Removed xsimd dependency
Mcgode Apr 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/cmake-linux-vulkan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ jobs:

- name: Test
working-directory: ${{ env.BUILD_DIR }}/Tests/Core
# For now, we exclude Core_Math_UnitTests because it fails due to SIMD issues on x86. This needs to be fixed.
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure -E "Core_Math_UnitTests"
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure

test-modules:
runs-on: ubuntu-latest
Expand Down
11 changes: 9 additions & 2 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ set(MathSrc
Include/KryneEngine/Core/Math/Vector2.hpp
Include/KryneEngine/Core/Math/Vector3.hpp
Include/KryneEngine/Core/Math/Vector4.hpp
Include/KryneEngine/Core/Math/XSimdUtils.hpp
Include/KryneEngine/Core/Math/Hashing.hpp
Src/Math/Hashing.cpp
Include/KryneEngine/Core/Math/Quaternion.hpp
Expand All @@ -62,6 +61,13 @@ set(MathSrc
Include/KryneEngine/Core/Math/Float16.hpp
Src/Math/Float16.cpp
Include/KryneEngine/Core/Math/Color.hpp
Include/KryneEngine/Core/Math/Simd/SimdCommon.hpp
Include/KryneEngine/Core/Math/Simd/SimdTypes.hpp
Include/KryneEngine/Core/Math/Simd/SimdMemoryOperations.hpp
Include/KryneEngine/Core/Math/Simd/SimdArithmeticOperations.hpp
Include/KryneEngine/Core/Math/Simd/SimdMathOperations.hpp
Include/KryneEngine/Core/Math/Simd/SimdCompareOperations.hpp
Include/KryneEngine/Core/Math/Simd/VectorUtils.hpp
)

set(MemorySrc
Expand Down Expand Up @@ -211,6 +217,7 @@ elseif (GraphicsApi STREQUAL "MTL")
Src/Graphics/Metal/MetalArgumentBufferManager.cpp
Src/Graphics/Metal/MetalArgumentBufferManager.hpp
Src/Graphics/Metal/Helpers/RenderState.hpp
Include/KryneEngine/Core/Platform/Cpu.hpp
)
endif()

Expand All @@ -223,7 +230,7 @@ add_library(KryneEngine_Core
${ProfilingSrc}
${ThreadsSrc}
${WindowSrc})
target_link_libraries(KryneEngine_Core EASTL glfw glm Tracy::TracyClient moodycamel Boost::context xsimd)
target_link_libraries(KryneEngine_Core EASTL glfw glm Tracy::TracyClient moodycamel Boost::context)

if (GraphicsApi STREQUAL "VK")
message(STATUS "Finding and linking Vulkan lib")
Expand Down
14 changes: 7 additions & 7 deletions Core/Include/KryneEngine/Core/Math/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ namespace KryneEngine
// Based on https://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
[[nodiscard]] Color ToSrgb() const
{
const float3_simd rgb { m_value.r, m_value.g, m_value.b };
const float3 rgb { m_value.r, m_value.g, m_value.b };

const float3_simd s1 = rgb.Sqrt();
const float3_simd s2 = s1.Sqrt();
const float3_simd s3 = s2.Sqrt();
const float3 s1 = rgb.Sqrt();
const float3 s2 = s1.Sqrt();
const float3 s3 = s2.Sqrt();

const float3_simd srgb = s1 * 0.585122381 + s2 * 0.783140355 - s3 * 0.368262736;
const float3 srgb = s1 * 0.585122381 + s2 * 0.783140355 - s3 * 0.368262736;

return Color(float4(srgb, m_value.a));
}

// Based on https://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
[[nodiscard]] Color FromSrgb() const
{
const float3_simd srgb { m_value.r, m_value.g, m_value.b };
const float3 srgb { m_value.r, m_value.g, m_value.b };

const float3_simd rgb = srgb * (srgb * (srgb * 0.305306011 + 0.682171111) + 0.012522878);
const float3 rgb = srgb * (srgb * (srgb * 0.305306011 + 0.682171111) + 0.012522878);

return Color(float4(rgb, m_value.a));
}
Expand Down
15 changes: 8 additions & 7 deletions Core/Include/KryneEngine/Core/Math/CoordinateSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,39 @@ namespace KryneEngine::Math
RightHandedZUp,
};

constexpr bool IsLeftHanded(CoordinateSystem _system)
constexpr bool IsLeftHanded(const CoordinateSystem _system)
{
return _system == CoordinateSystem::LeftHandedYUp || _system == CoordinateSystem::LeftHandedZUp;
}

constexpr bool IsZUp(CoordinateSystem _system)
constexpr bool IsZUp(const CoordinateSystem _system)
{
return _system == CoordinateSystem::RightHandedZUp || _system == CoordinateSystem::LeftHandedZUp;
}

inline float3 UpVector(CoordinateSystem _system = KE_DEFAULT_COORDINATE_SYSTEM)
inline float3 UpVector(const CoordinateSystem _system = KE_DEFAULT_COORDINATE_SYSTEM)
{
return IsZUp(_system) ? float3(0.0f, 0.0f, 1.0f) : float3(0.0f, 1.0f, 0.0f);
}

inline float3 RightVector(CoordinateSystem _system = KE_DEFAULT_COORDINATE_SYSTEM)
inline float3 RightVector(const CoordinateSystem _system = KE_DEFAULT_COORDINATE_SYSTEM)
{
return float3 { 1.0f, 0.0f, 0.0f };
}

inline float3 ForwardVector(CoordinateSystem _system = KE_DEFAULT_COORDINATE_SYSTEM)
inline float3 ForwardVector(const CoordinateSystem _system = KE_DEFAULT_COORDINATE_SYSTEM)
{
switch (_system)
{
case CoordinateSystem::LeftHandedYUp:
return float3 { 0.0f, 0.0f, 1.0f };
case CoordinateSystem::RightHandedYUp:
return float3 { 0.0f, 0.0f, -1.0f };
case CoordinateSystem::RightHandedZUp:
return float3 { 0.0f, 1.0f, 0.0f };
case CoordinateSystem::LeftHandedZUp:
return float3 { 0.0f, -1.0f, 0.0f };
case CoordinateSystem::RightHandedZUp:
default:
return float3 { 0.0f, 1.0f, 0.0f };
};
}

Expand Down
42 changes: 21 additions & 21 deletions Core/Include/KryneEngine/Core/Math/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@

namespace KryneEngine
{
using float3x3 = Math::Matrix33Base<float, false, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using double3x3 = Math::Matrix33Base<double, false, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using float3x3_simd = Math::Matrix33Base<float, true, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using double3x3_simd = Math::Matrix33Base<double, true, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using float3x3 = Math::Matrix33Base<float, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using double3x3 = Math::Matrix33Base<double, KE_DEFAULT_MATRIX_ROW_MAJOR>;

using float4x4 = Math::Matrix44Base<float, false, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using double4x4 = Math::Matrix44Base<double, false, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using float4x4_simd = Math::Matrix44Base<float, true, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using double4x4_simd = Math::Matrix44Base<double, true, KE_DEFAULT_MATRIX_ROW_MAJOR>;
using float4x4 = Math::Matrix44Base<float, KE_DEFAULT_MATRIX_ROW_MAJOR, false>;
using double4x4 = Math::Matrix44Base<double, KE_DEFAULT_MATRIX_ROW_MAJOR, false>;
using float4x4_simd = Math::Matrix44Base<float, KE_DEFAULT_MATRIX_ROW_MAJOR, false>;
using double4x4_simd = Math::Matrix44Base<double, KE_DEFAULT_MATRIX_ROW_MAJOR, false>;

template<class T, bool SimdOptimal, bool RowMajor>
Math::Matrix44Base<T, SimdOptimal, RowMajor> ToMatrix44(const Math::Matrix33Base<T, SimdOptimal, RowMajor>& _matrix)
template<Math::Matrix44Type T>
T ToMatrix44(const Math::Matrix33Base<typename T::ScalarType, T::kRowMajorLayout>& _matrix)
{
return Math::Matrix44Base<T, SimdOptimal, RowMajor> {
Math::Vector4Base<T, SimdOptimal>{ _matrix.m_vectors[0], 0.f },
Math::Vector4Base<T, SimdOptimal>{ _matrix.m_vectors[1], 0.f },
Math::Vector4Base<T, SimdOptimal>{ _matrix.m_vectors[2], 0.f },
Math::Vector4Base<T, SimdOptimal>{ 0.0f, 0.0f, 0.0f, 1.0f }
using VectorType = T::VectorType;
return T {
VectorType{ _matrix.m_vectors[0], 0.f },
VectorType{ _matrix.m_vectors[1], 0.f },
VectorType{ _matrix.m_vectors[2], 0.f },
VectorType{ 0.0f, 0.0f, 0.0f, 1.0f }
};
}

template<class T, bool SimdOptimal, bool RowMajor>
Math::Matrix33Base<T, SimdOptimal, RowMajor> ToMatrix33(const Math::Matrix44Base<T, SimdOptimal, RowMajor>& _matrix)
template<class T, bool RowMajor, bool SimdAligned>
Math::Matrix33Base<T, RowMajor> ToMatrix33(const Math::Matrix44Base<T, RowMajor, SimdAligned>& _matrix)
{
return Math::Matrix33Base<T, SimdOptimal, RowMajor> {
Math::Vector3Base<T, SimdOptimal>{ _matrix.m_vectors[0].x, _matrix.m_vectors[0].y, _matrix.m_vectors[0].z },
Math::Vector3Base<T, SimdOptimal>{ _matrix.m_vectors[1].x, _matrix.m_vectors[1].y, _matrix.m_vectors[1].z },
Math::Vector3Base<T, SimdOptimal>{ _matrix.m_vectors[2].x, _matrix.m_vectors[2].y, _matrix.m_vectors[2].z }
using Matrix = Math::Matrix33Base<T, RowMajor>;
return Matrix {
Matrix::VectorType(_matrix.m_vectors[0].x, _matrix.m_vectors[0].y, _matrix.m_vectors[0].z),
Matrix::VectorType(_matrix.m_vectors[1].x, _matrix.m_vectors[1].y, _matrix.m_vectors[1].z),
Matrix::VectorType(_matrix.m_vectors[2].x, _matrix.m_vectors[2].y, _matrix.m_vectors[2].z)
};
}
}
43 changes: 23 additions & 20 deletions Core/Include/KryneEngine/Core/Math/Matrix33.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
#include <cstddef>
#include <EASTL/type_traits.h>

#include "KryneEngine/Core/Math/Vector3.hpp"
#include "KryneEngine/Core/Math/Vector4.hpp"

namespace KryneEngine::Math
{
template<class T, bool SimdOptimal, bool RowMajor>
template<class T, bool RowMajor>
struct Matrix33Base
{
using ScalarType = T;
static constexpr bool kSimdOptimal = SimdOptimal;
static constexpr bool kRowMajorLayout = RowMajor;

using VectorType = Vector3Base<T>;

Matrix33Base();
~Matrix33Base() = default;

Expand Down Expand Up @@ -52,23 +53,27 @@ namespace KryneEngine::Math
* @note Requires that the type `U` is implicitly convertible to the type `T` of
* the matrix through a constraint using `eastl::is_convertible_v<U, T>`.
*/
template<class U, bool VSimdOptimal>
template<class U>
requires eastl::is_convertible_v<U, T>
Matrix33Base(
const Vector3Base<U, VSimdOptimal>& _v1,
const Vector3Base<U, VSimdOptimal>& _v2,
const Vector3Base<U, VSimdOptimal>& _v3)
const Vector3Base<U>& _v1,
const Vector3Base<U>& _v2,
const Vector3Base<U>& _v3)
: m_vectors {
Vector3Base<T, SimdOptimal>{ _v1 },
Vector3Base<T, SimdOptimal>{ _v2 },
Vector3Base<T, SimdOptimal>{ _v3 }
VectorType { _v1 },
VectorType { _v2 },
VectorType { _v3 },
}
{}

template<class U, bool S>
template<class U>
requires eastl::is_convertible_v<U, T>
explicit Matrix33Base(const Matrix33Base<U, S, RowMajor>& _other)
: Matrix33Base(_other.m_vectors[0], _other.m_vectors[1], _other.m_vectors[2])
explicit Matrix33Base(const Matrix33Base<U, RowMajor>& _other)
: m_vectors {
VectorType(_other.m_vectors[0].x, _other.m_vectors[0].y, _other.m_vectors[0].z),
VectorType(_other.m_vectors[1].x, _other.m_vectors[1].y, _other.m_vectors[1].z),
VectorType(_other.m_vectors[2].x, _other.m_vectors[2].y, _other.m_vectors[2].z)
}
{}

[[nodiscard]] bool IsRowMajor() const { return RowMajor; }
Expand Down Expand Up @@ -110,7 +115,6 @@ namespace KryneEngine::Math
*
* @tparam U The type of the elements within the input matrix to be converted. This type must be convertible to the
* type of the elements of the target matrix `T`.
* @tparam OtherSimdOptimal Indicates whether the input matrix is optimized for SIMD operations.
*
* @param _other The input matrix to be converted to the target type and layout. This matrix must be in the opposite
* row-major/column-major layout relative to the target matrix.
Expand All @@ -120,23 +124,22 @@ namespace KryneEngine::Math
*
* @note The input matrix's type and layout constraints are enforced through a `requires` clause using `eastl::is_convertible_v<U, T>`.
*/
template <class U, bool OtherSimdOptimal>
template <class U>
requires eastl::is_convertible_v<U, T>
static Matrix33Base Convert(const Matrix33Base<U, OtherSimdOptimal, !RowMajor>& _other)
static Matrix33Base Convert(const Matrix33Base<U, !RowMajor>& _other)
{
Matrix33Base<U, OtherSimdOptimal, !RowMajor> transposed = _other;
Matrix33Base<U, !RowMajor> transposed = _other;
transposed.Transpose();
return Matrix33Base(transposed.m_vectors[0], transposed.m_vectors[1], transposed.m_vectors[2]);
}

Vector3Base<T, SimdOptimal> m_vectors[3];
VectorType m_vectors[3];
};

template<class T>
concept Matrix33Type = requires {
typename T::ScalarType;
T::kSimdOptimal;
T::kRowMajorLayout;
std::is_same_v<Matrix33Base<typename T::ScalarType, T::kSimdOptimal, T::kRowMajorLayout>, T>;
std::is_same_v<Matrix33Base<typename T::ScalarType, T::kRowMajorLayout>, T>;
};
}
Loading