Better L4 and array storage design
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Matrix44"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -26,7 +26,7 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Intrinsic;
|
||||
using StgSharp.Mathematics.Internal;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -34,6 +34,7 @@ using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
|
||||
namespace StgSharp.Mathematics.Graphics
|
||||
{
|
||||
@@ -46,13 +47,20 @@ namespace StgSharp.Mathematics.Graphics
|
||||
[FieldOffset(0)] internal ColumnSet4 mat;
|
||||
[FieldOffset(0)] internal MatrixKernel<float> kernel;
|
||||
|
||||
internal Matrix44(ColumnSet4 mat)
|
||||
internal Matrix44(
|
||||
ColumnSet4 mat
|
||||
)
|
||||
{
|
||||
Unsafe.SkipInit(out this);
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix44(Vector4 vec0, Vector4 vec1, Vector4 vec2, Vector4 vec3)
|
||||
internal Matrix44(
|
||||
Vector4 vec0,
|
||||
Vector4 vec1,
|
||||
Vector4 vec2,
|
||||
Vector4 vec3
|
||||
)
|
||||
{
|
||||
Unsafe.SkipInit(out this);
|
||||
mat.colum0 = vec0;
|
||||
@@ -82,7 +90,8 @@ namespace StgSharp.Mathematics.Graphics
|
||||
float a30,
|
||||
float a31,
|
||||
float a32,
|
||||
float a33)
|
||||
float a33
|
||||
)
|
||||
{
|
||||
Unsafe.SkipInit(out this);
|
||||
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
||||
@@ -91,7 +100,10 @@ namespace StgSharp.Mathematics.Graphics
|
||||
mat.colum3 = new Vector4(a03, a13, a23, a33);
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
public unsafe float this[
|
||||
int rowNum,
|
||||
int columNum
|
||||
]
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -133,84 +145,124 @@ namespace StgSharp.Mathematics.Graphics
|
||||
|
||||
public static Matrix44 Unit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
|
||||
public static Matrix44 WNegativeUnit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1);
|
||||
public static Matrix44 WNegativeUnit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, -1);
|
||||
|
||||
public static Matrix44 XNegativeUnit => new Matrix44(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
public static Matrix44 XNegativeUnit => new Matrix44(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 1);
|
||||
|
||||
public static Matrix44 YNegativeUnit => new Matrix44(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
public static Matrix44 YNegativeUnit => new Matrix44(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 1);
|
||||
|
||||
public static Matrix44 ZNegativeUnit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
|
||||
public static Matrix44 ZNegativeUnit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0,
|
||||
0, 0, 1);
|
||||
|
||||
public ReadOnlySpan<float> AsSpan()
|
||||
{
|
||||
return MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<ColumnSet4, float>(ref mat), 16);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
public override bool Equals(
|
||||
object? obj
|
||||
)
|
||||
{
|
||||
return obj is Matrix44 x && Equals(x);
|
||||
}
|
||||
|
||||
public bool Equals(Matrix44 other)
|
||||
public bool Equals(
|
||||
Matrix44 other
|
||||
)
|
||||
{
|
||||
return mat.Equals(other.mat);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(mat.colum0.GetHashCode(), mat.colum1.GetHashCode(), mat.colum2.GetHashCode(),
|
||||
mat.colum3.GetHashCode());
|
||||
return HashCode.Combine(mat.colum0.GetHashCode(), mat.colum1.GetHashCode(),
|
||||
mat.colum2.GetHashCode(), mat.colum3.GetHashCode());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void InternalTranspose(ref Matrix44 transpose)
|
||||
internal unsafe void InternalTranspose(
|
||||
ref Matrix44 transpose
|
||||
)
|
||||
{
|
||||
const int f32 = 0;
|
||||
fixed (MatrixKernel<float>* source = &this.kernel, target = &transpose.kernel) {
|
||||
MathematicsModule.GlobalContext.mat[f32].buffer_transpose(source, target);
|
||||
MathematicsModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Transpose,
|
||||
null, (MatrixKernel*)source,
|
||||
(MatrixKernel*)target, 0);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix44 operator -(Matrix44 left, Matrix44 right)
|
||||
public static unsafe Matrix44 operator -(
|
||||
Matrix44 left,
|
||||
Matrix44 right
|
||||
)
|
||||
{
|
||||
Matrix44 ret = new();
|
||||
const int f32 = 0;
|
||||
MathematicsModule.GlobalContext.mat[f32].buffer_sub(&left, &right, &ret, 1);
|
||||
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||
MathematicsModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Sub,
|
||||
(MatrixKernel*)&left,
|
||||
(MatrixKernel*)&right,
|
||||
(MatrixKernel*)&ret, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static bool operator !=(Matrix44 left, Matrix44 right)
|
||||
public static bool operator !=(
|
||||
Matrix44 left,
|
||||
Matrix44 right
|
||||
)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix44 operator *(Matrix44 mat, float value)
|
||||
public static unsafe Matrix44 operator *(
|
||||
Matrix44 mat,
|
||||
float value
|
||||
)
|
||||
{
|
||||
return new Matrix44(mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value);
|
||||
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||
return new Matrix44(mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value, mat.mat.colum3 * value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix44 operator *(Matrix44 left, Matrix44 right)
|
||||
public static Matrix44 operator *(
|
||||
Matrix44 left,
|
||||
Matrix44 right
|
||||
)
|
||||
{
|
||||
Matrix44 ret = new();
|
||||
int f32 = (int)MatrixElementType.F32;
|
||||
MathematicsModule.GlobalContext.mat[f32].kernel_fma(&left, &right, &ret);
|
||||
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||
MathematicsModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Fma,
|
||||
(MatrixKernel*)&left,
|
||||
(MatrixKernel*)&right,
|
||||
(MatrixKernel*)&ret, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix44 operator +(Matrix44 left, Matrix44 right)
|
||||
public static unsafe Matrix44 operator +(
|
||||
Matrix44 left,
|
||||
Matrix44 right
|
||||
)
|
||||
{
|
||||
Matrix44 ret = new();
|
||||
const int f32 = 0;
|
||||
MathematicsModule.GlobalContext.mat[f32].buffer_add(&left, &right, &ret, 1);
|
||||
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||
MathematicsModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Add,
|
||||
(MatrixKernel*)&left,
|
||||
(MatrixKernel*)&right,
|
||||
(MatrixKernel*)&ret, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static bool operator ==(Matrix44 left, Matrix44 right)
|
||||
public static bool operator ==(
|
||||
Matrix44 left,
|
||||
Matrix44 right
|
||||
)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user