add a pre-kP evaluation function in c
This commit is contained in:
+24
-24
@@ -36,26 +36,26 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
{
|
{
|
||||||
|
|
||||||
private bool _isLookAtAvailable;
|
private bool _isLookAtAvailable;
|
||||||
internal Matrix44 _lookAt;
|
internal GraphicsMatrix _lookAt;
|
||||||
internal Matrix44 _projection;
|
internal GraphicsMatrix _projection;
|
||||||
internal Matrix44 cameraAtt;
|
internal GraphicsMatrix cameraAtt;
|
||||||
internal Matrix44 rotation;
|
internal GraphicsMatrix rotation;
|
||||||
internal Matrix44 rotationAtt;
|
internal GraphicsMatrix rotationAtt;
|
||||||
internal Radius _pitch;
|
internal Radius _pitch;
|
||||||
internal Radius _row;
|
internal Radius _row;
|
||||||
internal Radius _yaw;
|
internal Radius _yaw;
|
||||||
internal Uniform<Matrix44> convertedUniform;
|
internal Uniform<GraphicsMatrix> convertedUniform;
|
||||||
internal Vec3 _target, up;
|
internal Vec3 _target, up;
|
||||||
|
|
||||||
public Camera()
|
public Camera()
|
||||||
{
|
{
|
||||||
cameraAtt = Matrix44.Unit;
|
cameraAtt = GraphicsMatrix.Unit;
|
||||||
_target = Vec3.Zero;
|
_target = Vec3.Zero;
|
||||||
up = Vec3.Zero;
|
up = Vec3.Zero;
|
||||||
_isLookAtAvailable = false;
|
_isLookAtAvailable = false;
|
||||||
_lookAt = Matrix44.Unit;
|
_lookAt = GraphicsMatrix.Unit;
|
||||||
rotationAtt = Matrix44.Unit;
|
rotationAtt = GraphicsMatrix.Unit;
|
||||||
_projection = new Matrix44();
|
_projection = new GraphicsMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Camera(
|
public Camera(
|
||||||
@@ -65,24 +65,24 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
)
|
)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
rotationAtt = Matrix44.Unit;
|
rotationAtt = GraphicsMatrix.Unit;
|
||||||
cameraAtt = new Matrix44();
|
cameraAtt = new GraphicsMatrix();
|
||||||
SetViewDirection(position, target, up);
|
SetViewDirection(position, target, up);
|
||||||
_pitch = Radius.Zero;
|
_pitch = Radius.Zero;
|
||||||
_row = Radius.Zero;
|
_row = Radius.Zero;
|
||||||
_yaw = Radius.Zero;
|
_yaw = Radius.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix44 Projection => _projection;
|
public GraphicsMatrix Projection => _projection;
|
||||||
|
|
||||||
public Matrix44 View
|
public GraphicsMatrix View
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_isLookAtAvailable) {
|
if (_isLookAtAvailable) {
|
||||||
return _lookAt;
|
return _lookAt;
|
||||||
}
|
}
|
||||||
Matrix44 move = Matrix44.Unit;
|
GraphicsMatrix move = GraphicsMatrix.Unit;
|
||||||
move.column[3].vec -= cameraAtt.column[3].vec;
|
move.column[3].vec -= cameraAtt.column[3].vec;
|
||||||
_lookAt = rotationAtt.Transpose * move;
|
_lookAt = rotationAtt.Transpose * move;
|
||||||
_isLookAtAvailable = true;
|
_isLookAtAvailable = true;
|
||||||
@@ -90,7 +90,7 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix44 CameraMatrix()
|
public GraphicsMatrix CameraMatrix()
|
||||||
{
|
{
|
||||||
return Projection * View;
|
return Projection * View;
|
||||||
}
|
}
|
||||||
@@ -118,11 +118,11 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
params string[] uniformName
|
params string[] uniformName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (uniformName is null || uniformName.Length != 1) {
|
if ((uniformName is null) || (uniformName.Length != 1)) {
|
||||||
throw new ArgumentException(
|
throw new ArgumentException(
|
||||||
"Camera needs exactly one uniform.", nameof(uniformName));
|
"Camera needs exactly one uniform.", nameof(uniformName));
|
||||||
}
|
}
|
||||||
convertedUniform = source.GetUniform<Matrix44>(uniformName[0]);
|
convertedUniform = source.GetUniform<GraphicsMatrix>(uniformName[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveNear(
|
public void MoveNear(
|
||||||
@@ -208,15 +208,15 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
offsetX = offset.X,
|
offsetX = offset.X,
|
||||||
offsetY = offset.Y,
|
offsetY = offset.Y,
|
||||||
width = MathF.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
|
width = MathF.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
|
||||||
height = width * size.Y / size.X;
|
height = (width * size.Y) / size.X;
|
||||||
|
|
||||||
_projection.column[0].X = 2 * near / width;
|
_projection.column[0].X = (2 * near) / width;
|
||||||
_projection.column[1].Y = 2 * near / height;
|
_projection.column[1].Y = (2 * near) / height;
|
||||||
_projection.column[2].X = 2 * offsetX / width;
|
_projection.column[2].X = (2 * offsetX) / width;
|
||||||
_projection.column[2].Y = 2 * offsetY / height;
|
_projection.column[2].Y = (2 * offsetY) / height;
|
||||||
_projection.column[2].Z = (far + near) / (near - far);
|
_projection.column[2].Z = (far + near) / (near - far);
|
||||||
_projection.column[2].W = -1;
|
_projection.column[2].W = -1;
|
||||||
_projection.column[3].Z = 2 * near * far / (near - far);
|
_projection.column[3].Z = (2 * near * far) / (near - far);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Test(
|
public void Test(
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void SetUniformValue(
|
public void SetUniformValue(
|
||||||
[NotNull] Uniform<Matrix44> uniform,
|
[NotNull] Uniform<GraphicsMatrix> uniform,
|
||||||
Matrix44 mat
|
GraphicsMatrix mat
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, (byte)0, (float*)&mat);
|
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, (byte)0, (float*)&mat);
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
CustomizeDeinit();
|
CustomizeDeinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sealed override Uniform<Matrix44> NativeCameraUniform(
|
protected sealed override Uniform<GraphicsMatrix> NativeCameraUniform(
|
||||||
ShaderProgram source,
|
ShaderProgram source,
|
||||||
string name
|
string name
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -50,24 +50,13 @@ namespace StgSharp.Graphics
|
|||||||
private protected ViewPort primeArgs;
|
private protected ViewPort primeArgs;
|
||||||
internal TimeSpanProvider _timeProvider;
|
internal TimeSpanProvider _timeProvider;
|
||||||
|
|
||||||
public (int width, int height) Size
|
public (int width, int height) Size => (Width, Height);
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => (Width, Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract bool IsContextSharable { get; }
|
public abstract bool IsContextSharable { get; }
|
||||||
|
|
||||||
public int Height
|
public int Height => primeArgs.Height;
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => primeArgs.Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Width
|
public int Width => primeArgs.Width;
|
||||||
{
|
|
||||||
get => primeArgs.Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntPtr Monitor
|
public IntPtr Monitor
|
||||||
{
|
{
|
||||||
@@ -75,10 +64,7 @@ namespace StgSharp.Graphics
|
|||||||
internal set => primeArgs.Monitor = value;
|
internal set => primeArgs.Monitor = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name => primeArgs.Name;
|
||||||
{
|
|
||||||
get => primeArgs.Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ViewPort BindedViewPortContext
|
public ViewPort BindedViewPortContext
|
||||||
{
|
{
|
||||||
@@ -86,11 +72,7 @@ namespace StgSharp.Graphics
|
|||||||
internal set => primeArgs = value;
|
internal set => primeArgs = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal IntPtr CanvasHandle
|
internal IntPtr CanvasHandle => primeArgs.ViewPortHandle;
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => primeArgs.ViewPortHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal IntPtr ContextHandle
|
internal IntPtr ContextHandle
|
||||||
{
|
{
|
||||||
@@ -104,29 +86,13 @@ namespace StgSharp.Graphics
|
|||||||
internal set => nativeCamera = value;
|
internal set => nativeCamera = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float FramePassed
|
protected float FramePassed => _timeProvider.CurrentSpan;
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => _timeProvider.CurrentSpan;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int PassedFrames
|
protected int PassedFrames => _timeProvider.CurrentSpan;
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => _timeProvider.CurrentSpan;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected float TimePassed
|
protected float TimePassed => (float)_timeProvider.CurrentSecond;
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => (float)_timeProvider.CurrentSecond;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TimeSpanProvider TimeProvider
|
protected TimeSpanProvider TimeProvider => _timeProvider;
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => _timeProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the Size limit of current form
|
/// Set the Size limit of current form
|
||||||
@@ -188,9 +154,9 @@ namespace StgSharp.Graphics
|
|||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) uniform from a shader.
|
/// Get <see cref="Uniform{T}" />(TView is <see cref="GraphicsMatrix" />) uniform from a
|
||||||
/// This uniform will be used as projection matrix of this camera. Additionally, for
|
/// shader. This uniform will be used as projection matrix of this camera. Additionally,
|
||||||
/// multi- shader rendering, each shader requires a uniform, so do not ignore return
|
/// for multi- shader rendering, each shader requires a uniform, so do not ignore return
|
||||||
/// value of this method.
|
/// value of this method.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param _label="source">
|
/// <param _label="source">
|
||||||
@@ -200,12 +166,12 @@ namespace StgSharp.Graphics
|
|||||||
/// ContextName of projection camera named in shader
|
/// ContextName of projection camera named in shader
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) representing projection
|
/// <see cref="Uniform{T}" />(TView is <see cref="GraphicsMatrix" />) representing
|
||||||
/// matrix in shader program.
|
/// projection matrix in shader program.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
protected abstract Uniform<Matrix44> NativeCameraUniform(
|
protected abstract Uniform<GraphicsMatrix> NativeCameraUniform(
|
||||||
ShaderProgram source,
|
ShaderProgram source,
|
||||||
string name
|
string name
|
||||||
);
|
);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -36,12 +36,14 @@ namespace StgSharp.Geometries
|
|||||||
|
|
||||||
private bool globalCoordAvailable;
|
private bool globalCoordAvailable;
|
||||||
private CoordinationBase localCoordination;
|
private CoordinationBase localCoordination;
|
||||||
private Matrix44 coordMat;
|
private GraphicsMatrix coordMat;
|
||||||
|
|
||||||
public CoordinationBase(CoordinationBase localCoordination)
|
public CoordinationBase(
|
||||||
|
CoordinationBase localCoordination
|
||||||
|
)
|
||||||
{
|
{
|
||||||
this.localCoordination = localCoordination;
|
this.localCoordination = localCoordination;
|
||||||
coordMat = new Matrix44();
|
coordMat = new GraphicsMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Point LocalOrigin
|
public virtual Point LocalOrigin
|
||||||
@@ -68,11 +70,7 @@ namespace StgSharp.Geometries
|
|||||||
set => coordMat.column[3].XYZ = value;
|
set => coordMat.column[3].XYZ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ref Matrix44 CoordMat
|
protected ref GraphicsMatrix CoordMat => ref coordMat;
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => ref coordMat;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,15 @@ namespace StgSharp.Geometries
|
|||||||
public class PlainCoordinate : CoordinationBase
|
public class PlainCoordinate : CoordinationBase
|
||||||
{
|
{
|
||||||
|
|
||||||
public PlainCoordinate(CoordinationBase local, Point origin, Vec3 xAxis, Vec3 yAxis)
|
public PlainCoordinate(
|
||||||
|
CoordinationBase local,
|
||||||
|
Point origin,
|
||||||
|
Vec3 xAxis,
|
||||||
|
Vec3 yAxis
|
||||||
|
)
|
||||||
: base(local)
|
: base(local)
|
||||||
{
|
{
|
||||||
CoordMat = Matrix44.Unit;
|
CoordMat = GraphicsMatrix.Unit;
|
||||||
|
|
||||||
CoordMat.column[0] = new Vec4(xAxis, 0);
|
CoordMat.column[0] = new Vec4(xAxis, 0);
|
||||||
CoordMat.column[1] = new Vec4(yAxis, 0);
|
CoordMat.column[1] = new Vec4(yAxis, 0);
|
||||||
@@ -50,8 +55,10 @@ namespace StgSharp.Geometries
|
|||||||
LocalOrigin = origin;
|
LocalOrigin = origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlainCoordinate StandardPlainCoordination { get; } = new(null, new Point(0, 0, 0),
|
public static PlainCoordinate StandardPlainCoordination { get; } = new(null,
|
||||||
new Vec3(1, 0, 0), new Vec3(0, 1, 0));
|
new Point(0, 0, 0),
|
||||||
|
new Vec3(1, 0, 0),
|
||||||
|
new Vec3(0, 1, 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-47
@@ -1,6 +1,6 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Matrix44"
|
// file="GraphicsMatrix"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
@@ -38,8 +38,8 @@ using System.Runtime.Intrinsics.X86;
|
|||||||
|
|
||||||
namespace StgSharp.Mathematics.Graphics
|
namespace StgSharp.Mathematics.Graphics
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Explicit, Size = (16 * sizeof(float)), Pack = 16)]
|
[StructLayout(LayoutKind.Explicit, Size = 16 * sizeof(float), Pack = 16)]
|
||||||
public unsafe struct Matrix44 : IEquatable<Matrix44>
|
public unsafe struct GraphicsMatrix : IEquatable<GraphicsMatrix>
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0 * sizeof(float))] internal Column column;
|
[FieldOffset(0 * sizeof(float))] internal Column column;
|
||||||
@@ -47,7 +47,7 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
[FieldOffset(0)] internal ColumnSet4 mat;
|
[FieldOffset(0)] internal ColumnSet4 mat;
|
||||||
[FieldOffset(0)] internal MatrixKernel<float> kernel;
|
[FieldOffset(0)] internal MatrixKernel<float> kernel;
|
||||||
|
|
||||||
internal Matrix44(
|
internal GraphicsMatrix(
|
||||||
ColumnSet4 mat
|
ColumnSet4 mat
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -55,7 +55,7 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
this.mat = mat;
|
this.mat = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Matrix44(
|
internal GraphicsMatrix(
|
||||||
Vector4 vec0,
|
Vector4 vec0,
|
||||||
Vector4 vec1,
|
Vector4 vec1,
|
||||||
Vector4 vec2,
|
Vector4 vec2,
|
||||||
@@ -69,12 +69,12 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
mat.colum3 = vec3;
|
mat.colum3 = vec3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix44()
|
public GraphicsMatrix()
|
||||||
{
|
{
|
||||||
Unsafe.SkipInit(out this);
|
Unsafe.SkipInit(out this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe Matrix44(
|
public unsafe GraphicsMatrix(
|
||||||
float a00,
|
float a00,
|
||||||
float a01,
|
float a01,
|
||||||
float a02,
|
float a02,
|
||||||
@@ -116,7 +116,7 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return kernel[rowNum + 4 * columNum];
|
return kernel[rowNum + (4 * columNum)];
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -129,33 +129,34 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
kernel[rowNum + 4 * columNum] = value;
|
kernel[rowNum + (4 * columNum)] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix44 Transpose
|
public GraphicsMatrix Transpose
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
Matrix44 transpose = new();
|
GraphicsMatrix transpose = new();
|
||||||
InternalTranspose(ref transpose);
|
InternalTranspose(ref transpose);
|
||||||
return transpose;
|
return transpose;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Matrix44 Unit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
public static GraphicsMatrix Unit => new GraphicsMatrix(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,
|
public static GraphicsMatrix WNegativeUnit => new GraphicsMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0,
|
||||||
0, 0, -1);
|
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,
|
public static GraphicsMatrix XNegativeUnit => new GraphicsMatrix(-1, 0, 0, 0, 0, 1, 0, 0, 0,
|
||||||
0, 0, 1);
|
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,
|
public static GraphicsMatrix YNegativeUnit => new GraphicsMatrix(1, 0, 0, 0, 0, -1, 0, 0, 0,
|
||||||
0, 0, 1);
|
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,
|
public static GraphicsMatrix ZNegativeUnit => new GraphicsMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0,
|
||||||
0, 0, 1);
|
0, -1, 0, 0, 0, 0, 1);
|
||||||
|
|
||||||
public ReadOnlySpan<float> AsSpan()
|
public ReadOnlySpan<float> AsSpan()
|
||||||
{
|
{
|
||||||
@@ -166,11 +167,11 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
object? obj
|
object? obj
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return obj is Matrix44 x && Equals(x);
|
return (obj is GraphicsMatrix x) && Equals(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(
|
public bool Equals(
|
||||||
Matrix44 other
|
GraphicsMatrix other
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return mat.Equals(other.mat);
|
return mat.Equals(other.mat);
|
||||||
@@ -184,7 +185,7 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal unsafe void InternalTranspose(
|
internal unsafe void InternalTranspose(
|
||||||
ref Matrix44 transpose
|
ref GraphicsMatrix transpose
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const int f32 = 0;
|
const int f32 = 0;
|
||||||
@@ -196,46 +197,46 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe Matrix44 operator -(
|
public static unsafe GraphicsMatrix operator -(
|
||||||
Matrix44 left,
|
GraphicsMatrix left,
|
||||||
Matrix44 right
|
GraphicsMatrix right
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Matrix44 ret = new();
|
GraphicsMatrix ret = new();
|
||||||
int f32 = MatrixElementType.F32.IntrinsicNode;
|
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||||
NumericalModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Sub,
|
NumericalModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Sub,
|
||||||
(MatrixKernel*)&left,
|
(MatrixKernel*)&left.kernel,
|
||||||
(MatrixKernel*)&right,
|
(MatrixKernel*)&right.kernel,
|
||||||
(MatrixKernel*)&ret, 1);
|
(MatrixKernel*)&ret.kernel, 1);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator !=(
|
public static bool operator !=(
|
||||||
Matrix44 left,
|
GraphicsMatrix left,
|
||||||
Matrix44 right
|
GraphicsMatrix right
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return !(left == right);
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe Matrix44 operator *(
|
public static unsafe GraphicsMatrix operator *(
|
||||||
Matrix44 mat,
|
GraphicsMatrix mat,
|
||||||
float value
|
float value
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int f32 = MatrixElementType.F32.IntrinsicNode;
|
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||||
return new Matrix44(mat.mat.colum0 * value, mat.mat.colum1 * value,
|
return new GraphicsMatrix(mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||||
mat.mat.colum2 * value, mat.mat.colum3 * value);
|
mat.mat.colum2 * value, mat.mat.colum3 * value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Matrix44 operator *(
|
public static GraphicsMatrix operator *(
|
||||||
Matrix44 left,
|
GraphicsMatrix left,
|
||||||
Matrix44 right
|
GraphicsMatrix right
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Matrix44 ret = new();
|
GraphicsMatrix ret = new();
|
||||||
int f32 = MatrixElementType.F32.IntrinsicNode;
|
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||||
NumericalModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Fma,
|
NumericalModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Fma,
|
||||||
(MatrixKernel*)&left,
|
(MatrixKernel*)&left,
|
||||||
@@ -245,12 +246,12 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe Matrix44 operator +(
|
public static unsafe GraphicsMatrix operator +(
|
||||||
Matrix44 left,
|
GraphicsMatrix left,
|
||||||
Matrix44 right
|
GraphicsMatrix right
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Matrix44 ret = new();
|
GraphicsMatrix ret = new();
|
||||||
int f32 = MatrixElementType.F32.IntrinsicNode;
|
int f32 = MatrixElementType.F32.IntrinsicNode;
|
||||||
NumericalModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Add,
|
NumericalModule.GlobalContext.mat_sk[f32].Call(MatrixIntrinsicHandle.Add,
|
||||||
(MatrixKernel*)&left,
|
(MatrixKernel*)&left,
|
||||||
@@ -260,8 +261,8 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(
|
public static bool operator ==(
|
||||||
Matrix44 left,
|
GraphicsMatrix left,
|
||||||
Matrix44 right
|
GraphicsMatrix right
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return left.Equals(right);
|
return left.Equals(right);
|
||||||
@@ -122,17 +122,9 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec4 One
|
public static Vec4 One => new Vec4(1, 1, 1, 1);
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => new Vec4(1, 1, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vec4 Zero
|
public static Vec4 Zero => new Vec4(0, 0, 0, 0);
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => new Vec4(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Vec4 Add(
|
public static Vec4 Add(
|
||||||
@@ -152,7 +144,7 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
object obj
|
object obj
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return obj is Vec4 v && v == this;
|
return (obj is Vec4 v) && (v == this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec4 FromSpan(
|
public static Vec4 FromSpan(
|
||||||
@@ -212,11 +204,11 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Vec4 operator *(
|
public static Vec4 operator *(
|
||||||
Matrix44 mat,
|
GraphicsMatrix mat,
|
||||||
Vec4 vec
|
Vec4 vec
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Matrix44 transpose = mat.Transpose;
|
GraphicsMatrix transpose = mat.Transpose;
|
||||||
return new Vec4(Vector4.Dot(transpose.mat.colum0, vec.vec),
|
return new Vec4(Vector4.Dot(transpose.mat.colum0, vec.vec),
|
||||||
Vector4.Dot(transpose.mat.colum1, vec.vec),
|
Vector4.Dot(transpose.mat.colum1, vec.vec),
|
||||||
Vector4.Dot(transpose.mat.colum2, vec.vec),
|
Vector4.Dot(transpose.mat.colum2, vec.vec),
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
for (int i = 0; i < _numaMeasurements.Length; i++)
|
for (int i = 0; i < _numaMeasurements.Length; i++)
|
||||||
{
|
{
|
||||||
MatrixParallelThread[] numa = _numaThreads[i];
|
MatrixParallelThread[] numa = _numaThreads[i];
|
||||||
if ((numa is null) | (numa.Length == 0))
|
if ((numa is null) || (numa.Length == 0))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ using StgSharp.HighPerformance.ProcessorAbstraction;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
@@ -81,7 +80,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
contextMap = [];
|
contextMap = [];
|
||||||
int count = Environment.ProcessorCount;
|
int count = Environment.ProcessorCount;
|
||||||
SIMDID globalSimd = new SIMDID(0);
|
SIMDID globalSimd = new(0);
|
||||||
_retiredThreads = new(RESERVED_THREAD_COUNT);
|
_retiredThreads = new(RESERVED_THREAD_COUNT);
|
||||||
|
|
||||||
// init thread on all logical cores
|
// init thread on all logical cores
|
||||||
|
|||||||
@@ -140,6 +140,8 @@
|
|||||||
|
|
||||||
INTERNAL void f32_normalize(sn_vec_f32 * source, sn_vec_f32 * target);
|
INTERNAL void f32_normalize(sn_vec_f32 * source, sn_vec_f32 * target);
|
||||||
|
|
||||||
|
SN_MK_PROC_DECL_STD(float, sse, , k_quality);
|
||||||
|
|
||||||
SN_MK_PROC_DECL_STD(float, sse, , add);
|
SN_MK_PROC_DECL_STD(float, sse, , add);
|
||||||
SN_MK_PROC_DECL_STD(float, avx, , add);
|
SN_MK_PROC_DECL_STD(float, avx, , add);
|
||||||
SN_MK_PROC_DECL_STD(float, 512, , add);
|
SN_MK_PROC_DECL_STD(float, 512, , add);
|
||||||
|
|||||||
@@ -74,7 +74,6 @@
|
|||||||
|
|
||||||
#pragma region mem layout
|
#pragma region mem layout
|
||||||
|
|
||||||
#define _SN_MATPROC_LAYOUT_BUFFER 1
|
|
||||||
#define _SN_MATPROC_LAYOUT_TILE 1
|
#define _SN_MATPROC_LAYOUT_TILE 1
|
||||||
#define _SN_MATPROC_LAYOUT_KERNEL 1
|
#define _SN_MATPROC_LAYOUT_KERNEL 1
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
#include "sn_target.h"
|
||||||
|
#include <pmmintrin.h>
|
||||||
|
|
||||||
|
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||||
|
|
||||||
|
#include "sn_internal.h"
|
||||||
|
#include "sn_intrinsic.h"
|
||||||
|
#include "sn_intrinsic.std.h"
|
||||||
|
#include "sn_intrinsic.context.x86.h"
|
||||||
|
#include "sn_intrinsic.matkernel.h"
|
||||||
|
#include <emmintrin.h>
|
||||||
|
#include <immintrin.h>
|
||||||
|
|
||||||
|
SN_MK_PROC_DECL_STD(float, sse, , k_quality)
|
||||||
|
{
|
||||||
|
__mk_param_std(TILE, RIGHT_ANS_SCALAR, float);
|
||||||
|
}
|
||||||
|
|
||||||
|
INTERNAL SN_STD_TARGET_ATTR(sse, ) void kp_check_f32(mat_kernel *kernel)
|
||||||
|
{
|
||||||
|
typedef MAT_KERNEL(float) SN_MAT;
|
||||||
|
SN_MAT const *k = (SN_MAT const *)kernel;
|
||||||
|
float cross[4];
|
||||||
|
cross[0] = k->m[0][0];
|
||||||
|
cross[1] = k->m[1][1];
|
||||||
|
cross[2] = k->m[2][2];
|
||||||
|
cross[3] = k->m[3][3];
|
||||||
|
|
||||||
|
float evaluation[4];
|
||||||
|
|
||||||
|
register __m128 cross_vec = _mm_loadu_ps((float *)cross);
|
||||||
|
register __m128 abs_mask = _mm_castsi128_ps(_mm_set1_epi32(0x7fffffff));
|
||||||
|
cross_vec = _mm_and_ps(cross_vec, abs_mask);
|
||||||
|
register __m128 average_vec = _mm_hadd_ps(cross_vec, cross_vec);
|
||||||
|
average_vec = _mm_hadd_ps(average_vec, average_vec);
|
||||||
|
register __m128 quarter_vec = _mm_set1_ps(0.25f);
|
||||||
|
average_vec = _mm_mul_ps(average_vec, quarter_vec);
|
||||||
|
|
||||||
|
register __m128 stddev_vec = _mm_sub_ps(cross_vec, average_vec);
|
||||||
|
stddev_vec = _mm_mul_ps(stddev_vec, stddev_vec);
|
||||||
|
stddev_vec = _mm_hadd_ps(stddev_vec, stddev_vec);
|
||||||
|
stddev_vec = _mm_hadd_ps(stddev_vec, stddev_vec);
|
||||||
|
stddev_vec = _mm_mul_ps(stddev_vec, quarter_vec);
|
||||||
|
stddev_vec = _mm_sqrt_ps(stddev_vec);
|
||||||
|
|
||||||
|
evaluation[0] = _mm_cvtss_f32(average_vec);
|
||||||
|
evaluation[1] = _mm_cvtss_f32(stddev_vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user