Daily update on 20250721-223448 by Nitload Youmu. Additional Message : Rename StgSHarp.C to StgSharp.Native. Add SDL to repo.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Shader.cs"
|
||||
// Project: StepVisualizer
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
@@ -124,9 +124,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void Compile( int index, string codeStream )
|
||||
{
|
||||
if( codeStream == null ) {
|
||||
throw new ArgumentNullException( nameof( codeStream ) );
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull( codeStream );
|
||||
GL.LoadShaderSource( handle[ index ], codeStream.AsSpan() );
|
||||
GL.CompileShader( handle[ index ] );
|
||||
CheckStatus( index, ShaderStatus.CompileStatus );
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace StgSharp.Internal.Intrinsic
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
internal unsafe struct IntrinsicContext
|
||||
{
|
||||
|
||||
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet2*, ColumnSet2*, void> add_mat_2;
|
||||
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, ColumnSet3*, void> add_mat_3;
|
||||
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, ColumnSet4*, void> add_mat_4;
|
||||
@@ -55,6 +56,7 @@ namespace StgSharp.Internal.Intrinsic
|
||||
public delegate* unmanaged[Cdecl]<ColumnSet4*, Vector4*, Vector4*, void> dot_41;
|
||||
public delegate* unmanaged[Cdecl]<ColumnSet4*, Vector4*, Vector4*, void> dot_42;
|
||||
public delegate* unmanaged[Cdecl]<ColumnSet4*, Vector4*, Vector4*, void> dot_43;
|
||||
public delegate* unmanaged[Cdecl]<int,ulong> factorial_simd;
|
||||
public delegate* unmanaged[Cdecl]<char*, int, int, int> index_pair;
|
||||
public delegate* unmanaged[Cdecl]<Vector4*, Vector4*, void> normalize_v3;
|
||||
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet2*, ColumnSet2*, void> sub_mat_2;
|
||||
|
||||
@@ -28,12 +28,28 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
|
||||
public const float E = 2.718281828f;
|
||||
public const double EDouble = System.Math.E;
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static float Exp( float x )
|
||||
{
|
||||
return MathF.Exp( x );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static double Exp( double x )
|
||||
{
|
||||
return System.Math.Exp( x );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the value of E ^ x;
|
||||
@@ -44,7 +60,7 @@ namespace StgSharp.Math
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public static unsafe float Exp( float x )
|
||||
public static unsafe float ExpSlow( float x )
|
||||
{
|
||||
if( x == 1 ) {
|
||||
return E;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Factorial.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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 in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Scaler
|
||||
{
|
||||
|
||||
private static readonly uint[] factorialResult = [1, 1, 2, 6, 24,120,720,5040,40320,362880,3628800,39916800,479001600];
|
||||
|
||||
public static unsafe ulong Factorial( int n )
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan( n, 0 );
|
||||
if( n < 13 ) {
|
||||
return factorialResult[ n ];
|
||||
}
|
||||
if( n < 30 ) {
|
||||
return InternalIO.Intrinsic.factorial_simd( n );
|
||||
}
|
||||
double
|
||||
dn = n,
|
||||
stir = Sqrt( 2 * PiDouble * dn ) * Pow( dn / EDouble, dn ),
|
||||
correction = Exp( 1 / ( 12 * dn ) );
|
||||
return ( ulong )( stir * correction );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,25 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe float Pow( float x, float y )
|
||||
{
|
||||
return System.MathF.Pow( x, y );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe double Pow( double x, double y )
|
||||
{
|
||||
return System.Math.Pow( x, y );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// calculate the value of x^y
|
||||
/// </summary>
|
||||
@@ -45,7 +59,7 @@ namespace StgSharp.Math
|
||||
/// <returns>
|
||||
/// Returns the value of x^y
|
||||
/// </returns>
|
||||
public static unsafe float Pow( float x, float y )
|
||||
public static unsafe float PowSlow( float x, float y )
|
||||
{
|
||||
/*
|
||||
* x^y = E ^ ( log( x ) * y )
|
||||
|
||||
@@ -38,32 +38,11 @@ namespace StgSharp.Math
|
||||
{
|
||||
|
||||
public const float Pi = 3.1415926f;
|
||||
|
||||
private static readonly float[] cosData = {
|
||||
1f, 0.987688341014302f, 0.951056517951169f, 0.891006527837756f, 0.809017000674805f, 0.707106790659974f, 0.587785265298989f, 0.453990516451646f, 0.309017014761716f, 0.156434488858737f, 2.67948965850537E-08f, -0.156434435928723f, -0.309016963794794f, -0.453990468702791f, -0.587785221943935f, -0.707106752766267f, -0.809016969175515f, -0.891006503508499f, -0.951056501391011f, -0.98768833263101f, -0.999999999999999f, -0.987688349397591f, -0.951056534511324f, -0.891006552167012f, -0.809017032174094f, -0.707106828553679f, -0.587785308654041f, -0.4539905642005f, -0.309017065728638f, -0.156434541788751f, -8.03846893110719E-08f, 0.156434382998709f, 0.309016912827872f, 0.453990420953934f, 0.58778517858888f, 0.707106714872559f, 0.809016937676222f, 0.891006479179238f, 0.951056484830851f, 0.987688324247716f,
|
||||
};
|
||||
|
||||
private static readonly float[] sinData = {
|
||||
0f, 0.15643446239373f, 0.309016989278255f, 0.453990492577218f, 0.587785243621462f, 0.707106771713121f, 0.80901698492516f, 0.891006515673128f, 0.951056509671091f, 0.987688336822657f, 1f, 0.987688345205947f, 0.951056526231247f, 0.891006540002384f, 0.80901701642445f, 0.707106809606826f, 0.587785286976515f, 0.453990540326073f, 0.309017040245177f, 0.156434515323744f, 5.35897931701074E-08f, -0.156434409463716f, -0.309016938311333f, -0.453990444828362f, -0.587785200266408f, -0.707106733819413f, -0.809016953425868f, -0.891006491343869f, -0.951056493110931f, -0.987688328439363f, -0.999999999999997f, -0.987688353589235f, -0.951056542791401f, -0.891006564331638f, -0.809017047923737f, -0.70710684750053f, -0.587785330331566f, -0.453990588074927f, -0.309017091212098f, -0.156434568253757f,
|
||||
};
|
||||
public const double PiDouble = System.Math.PI;
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe float Sin( float x )
|
||||
{
|
||||
/*
|
||||
float refer = x / 360.0f;
|
||||
refer -= (int)refer;
|
||||
|
||||
refer *= 40;
|
||||
int a = (int)refer; //大分度,查表
|
||||
refer -= a; //小分度,拟合
|
||||
|
||||
float refer2 = refer * refer;
|
||||
|
||||
|
||||
return (sinData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)))
|
||||
+ (cosData[a] * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)));
|
||||
*/
|
||||
return MathF.Sin( x );
|
||||
}
|
||||
|
||||
|
||||
@@ -38,62 +38,23 @@ namespace StgSharp.Math
|
||||
|
||||
public static unsafe float SeedSqrt( float x )
|
||||
{
|
||||
/*
|
||||
* 本方法采用分别对指数和小数处理的方法计算平方根
|
||||
* 将指数除以2即可获得结果的指数
|
||||
* (补充:指数最低位被加到小数位中以抵消一个多余的2 ^ 1的影响)
|
||||
* 小数部分则统一乘以2 ^ 16后由y = Sqrt(x)在1.5 * 2 ^ 16处的切线近似
|
||||
* 为简化操作,提高计算速度,切线左界被移动到远点
|
||||
* 在进一步简化操作后,计算精度达到0.5%,速度约为.Net库函数的3倍
|
||||
*/
|
||||
|
||||
if( x < 0 )
|
||||
{
|
||||
throw new ArgumentOutOfRangeException( "Input is smaller than zero!" );
|
||||
}
|
||||
if( x == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* 提取指数位并减半
|
||||
* 由于平方根仅对正数有效
|
||||
* 故不考虑正负号
|
||||
*/
|
||||
|
||||
if( x < 0 )
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
ArgumentOutOfRangeException.ThrowIfNegative( x );
|
||||
if( x <= 1e-12 ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//提取指数位并减去指数位中的127
|
||||
//由于平方根仅对正数有效
|
||||
//故不考虑正负号
|
||||
uint a = *( uint* )&x;
|
||||
uint f = a;
|
||||
f >>= 23;
|
||||
f /= 2;
|
||||
f += 64;
|
||||
|
||||
//提取小数位
|
||||
//由于平方根仅对正数有效
|
||||
//故不考虑正负号
|
||||
|
||||
a -= 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
||||
uint e = a << 8;
|
||||
e >>= 8;
|
||||
|
||||
//线性近似
|
||||
e *= 0b_1101_0001;
|
||||
e >>= 24;
|
||||
e += 0b_0000_0000_0001_0000_1010_1000_1110_0010;
|
||||
|
||||
//还原指数
|
||||
f <<= 23;
|
||||
e += f;
|
||||
|
||||
float result = *( float* )&e;
|
||||
result = ( result + ( x / result ) ) / 2;
|
||||
return ( result + ( x / result ) ) / 2;
|
||||
@@ -106,5 +67,11 @@ namespace StgSharp.Math
|
||||
/**/
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static double Sqrt( double x )
|
||||
{
|
||||
return System.Math.Sqrt( x );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,27 +28,18 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Scaler
|
||||
{
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static float Tan( float x )
|
||||
{
|
||||
float refer = x / 360.0f;
|
||||
refer -= ( int )refer;
|
||||
|
||||
refer *= 40;
|
||||
int a = ( int )refer; //大分度,查表
|
||||
refer -= a; //小分度,拟合
|
||||
|
||||
float refer2 = refer * refer;
|
||||
|
||||
float sin = ( 0.1570796327f * refer ) - ( 6.459640975e-4f * refer * refer2 );
|
||||
float cos = ( 1 - ( 0.0123370055f * refer2 ) ) + ( 2.536695709e-5f * refer2 * refer2 );
|
||||
|
||||
return ( ( sinData[ a ] * cos ) + ( cosData[ a ] * sin ) ) / ( ( cosData[ a ] * cos ) - ( sinData[
|
||||
a ] * sin ) );
|
||||
return MathF.Tan( x );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+74c01effe4cabbc9d0e2e87b0d295bb29d7c62ba")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c624a8ca38fb17f15f058e4007e9bb1570161c3c")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/74c01effe4cabbc9d0e2e87b0d295bb29d7c62ba/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/c624a8ca38fb17f15f058e4007e9bb1570161c3c/*"}}
|
||||
Reference in New Issue
Block a user